diff --git a/wp-admin/includes/class-walker-nav-menu-edit.php b/wp-admin/includes/class-walker-nav-menu-edit.php index 9782618a7e..29f579ab93 100644 --- a/wp-admin/includes/class-walker-nav-menu-edit.php +++ b/wp-admin/includes/class-walker-nav-menu-edit.php @@ -71,14 +71,17 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu { ); $original_title = false; + if ( 'taxonomy' == $item->type ) { - $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' ); - if ( is_wp_error( $original_title ) ) { - $original_title = false; + $original_object = get_term( (int) $item->object_id, $item->object ); + if ( $original_object && ! is_wp_error( $original_title ) ) { + $original_title = $original_object->name; } } elseif ( 'post_type' == $item->type ) { $original_object = get_post( $item->object_id ); - $original_title = get_the_title( $original_object->ID ); + if ( $original_object ) { + $original_title = get_the_title( $original_object->ID ); + } } elseif ( 'post_type_archive' == $item->type ) { $original_object = get_post_type_object( $item->object ); if ( $original_object ) { diff --git a/wp-includes/nav-menu.php b/wp-includes/nav-menu.php index 98584eac8a..62bdbbf939 100644 --- a/wp-includes/nav-menu.php +++ b/wp-includes/nav-menu.php @@ -819,33 +819,40 @@ function wp_setup_nav_menu_item( $menu_item ) { $menu_item->_invalid = true; } - $menu_item->url = get_permalink( $menu_item->object_id ); - $original_object = get_post( $menu_item->object_id ); - /** This filter is documented in wp-includes/post-template.php */ - $original_title = apply_filters( 'the_title', $original_object->post_title, $original_object->ID ); + + if ( $original_object ) { + $menu_item->url = get_permalink( $original_object->ID ); + /** This filter is documented in wp-includes/post-template.php */ + $original_title = apply_filters( 'the_title', $original_object->post_title, $original_object->ID ); + } else { + $menu_item->url = ''; + $original_title = ''; + $menu_item->_invalid = true; + } if ( '' === $original_title ) { /* translators: %d: ID of a post */ - $original_title = sprintf( __( '#%d (no title)' ), $original_object->ID ); + $original_title = sprintf( __( '#%d (no title)' ), $menu_item->object_id ); } - $menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title; + $menu_item->title = ( '' === $menu_item->post_title ) ? $original_title : $menu_item->post_title; } elseif ( 'post_type_archive' == $menu_item->type ) { $object = get_post_type_object( $menu_item->object ); if ( $object ) { - $menu_item->title = '' == $menu_item->post_title ? $object->labels->archives : $menu_item->post_title; + $menu_item->title = ( '' === $menu_item->post_title ) ? $object->labels->archives : $menu_item->post_title; $post_type_description = $object->description; } else { - $menu_item->_invalid = true; $post_type_description = ''; + $menu_item->_invalid = true; } $menu_item->type_label = __( 'Post Type Archive' ); $post_content = wp_trim_words( $menu_item->post_content, 200 ); - $post_type_description = '' == $post_content ? $post_type_description : $post_content; + $post_type_description = ( '' === $post_content ) ? $post_type_description : $post_content; $menu_item->url = get_post_type_archive_link( $menu_item->object ); + } elseif ( 'taxonomy' == $menu_item->type ) { $object = get_taxonomy( $menu_item->object ); if ( $object ) { @@ -855,14 +862,23 @@ function wp_setup_nav_menu_item( $menu_item ) { $menu_item->_invalid = true; } - $term_url = get_term_link( (int) $menu_item->object_id, $menu_item->object ); - $menu_item->url = ! is_wp_error( $term_url ) ? $term_url : ''; + $original_object = get_term( (int) $menu_item->object_id, $menu_item->object ); - $original_title = get_term_field( 'name', $menu_item->object_id, $menu_item->object, 'raw' ); - if ( is_wp_error( $original_title ) ) { - $original_title = false; + if ( $original_object && ! is_wp_error( $original_object ) ) { + $menu_item->url = get_term_link( (int) $menu_item->object_id, $menu_item->object ); + $original_title = $original_object->name; + } else { + $menu_item->url = ''; + $original_title = ''; + $menu_item->_invalid = true; } - $menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title; + + if ( '' === $original_title ) { + /* translators: %d: ID of a term */ + $original_title = sprintf( __( '#%d (no title)' ), $menu_item->object_id ); + } + + $menu_item->title = ( '' === $menu_item->post_title ) ? $original_title : $menu_item->post_title; } else { $menu_item->type_label = __( 'Custom Link' ); diff --git a/wp-includes/version.php b/wp-includes/version.php index d58da358f5..ac67f4835a 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.3-alpha-45890'; +$wp_version = '5.3-alpha-45891'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.