Menus: In wp_setup_nav_menu_item() and Walker_Nav_Menu_Edit::start_el(), check if the post or term associated with the menu item still exists to avoid a PHP notice.

If the associated post or term no longer exists, mark the menu item as invalid.

Props mehulkaklotar, kamrankhorsandi, cristiano.zanca, SergeyBiryukov.
Fixes #31703.

git-svn-id: https://develop.svn.wordpress.org/trunk@45891 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2019-08-25 21:31:43 +00:00
parent 7ef2679ec7
commit 252e14ac27
2 changed files with 38 additions and 19 deletions

View File

@@ -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 ) {