Make WordPress Core


Ignore:
Timestamp:
08/05/2024 06:58:49 PM (18 months ago)
Author:
SergeyBiryukov
Message:

Menus: Check if taxonomy term exists in wp_update_nav_menu_item().

When inserting a term from a non-existing taxonomy as a nav item, the post_title property should be empty, and the function should not throw a fatal error for wp_specialchars_decode().

Includes bringing some consistency to similar checks for post types and post type archives in the same code fragment.

Follow-up to [14283], [14450], [35382], [36095].

Props dd32, narenin, mukesh27, SergeyBiryukov.
Fixes #61799.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/nav-menu.php

    r58119 r58854  
    492492
    493493        $original_title = '';
     494
    494495        if ( 'taxonomy' === $args['menu-item-type'] ) {
    495             $original_parent = get_term_field( 'parent', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' );
    496             $original_title  = get_term_field( 'name', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' );
     496            $original_object = get_term( $args['menu-item-object-id'], $args['menu-item-object'] );
     497
     498            if ( $original_object instanceof WP_Term ) {
     499                $original_parent = get_term_field( 'parent', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' );
     500                $original_title  = get_term_field( 'name', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' );
     501            }
    497502        } elseif ( 'post_type' === $args['menu-item-type'] ) {
    498 
    499503            $original_object = get_post( $args['menu-item-object-id'] );
    500             $original_parent = (int) $original_object->post_parent;
    501             $original_title  = $original_object->post_title;
     504
     505            if ( $original_object instanceof WP_Post ) {
     506                $original_parent = (int) $original_object->post_parent;
     507                $original_title  = $original_object->post_title;
     508            }
    502509        } elseif ( 'post_type_archive' === $args['menu-item-type'] ) {
    503510            $original_object = get_post_type_object( $args['menu-item-object'] );
    504             if ( $original_object ) {
     511
     512            if ( $original_object instanceof WP_Post_Type ) {
    505513                $original_title = $original_object->labels->archives;
    506514            }
Note: See TracChangeset for help on using the changeset viewer.