WordPress.org

Make WordPress Core


Ignore:
Timestamp:
08/25/2019 09:31:43 PM (7 weeks ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-walker-nav-menu-edit.php

    r45697 r45891  
    7272
    7373        $original_title = false;
     74
    7475        if ( 'taxonomy' == $item->type ) {
    75             $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
    76             if ( is_wp_error( $original_title ) ) {
    77                 $original_title = false;
     76            $original_object = get_term( (int) $item->object_id, $item->object );
     77            if ( $original_object && ! is_wp_error( $original_title ) ) {
     78                $original_title = $original_object->name;
    7879            }
    7980        } elseif ( 'post_type' == $item->type ) {
    8081            $original_object = get_post( $item->object_id );
    81             $original_title  = get_the_title( $original_object->ID );
     82            if ( $original_object ) {
     83                $original_title = get_the_title( $original_object->ID );
     84            }
    8285        } elseif ( 'post_type_archive' == $item->type ) {
    8386            $original_object = get_post_type_object( $item->object );
Note: See TracChangeset for help on using the changeset viewer.