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.
Built from https://develop.svn.wordpress.org/trunk@58854


git-svn-id: http://core.svn.wordpress.org/trunk@58250 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2024-08-05 19:00:19 +00:00
parent ae993cf8e2
commit 1a2b5794da
2 changed files with 16 additions and 8 deletions

View File

@ -491,17 +491,25 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item
$args['menu-item-url'] = '';
$original_title = '';
if ( 'taxonomy' === $args['menu-item-type'] ) {
$original_parent = get_term_field( 'parent', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' );
$original_title = get_term_field( 'name', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' );
} elseif ( 'post_type' === $args['menu-item-type'] ) {
if ( 'taxonomy' === $args['menu-item-type'] ) {
$original_object = get_term( $args['menu-item-object-id'], $args['menu-item-object'] );
if ( $original_object instanceof WP_Term ) {
$original_parent = get_term_field( 'parent', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' );
$original_title = get_term_field( 'name', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' );
}
} elseif ( 'post_type' === $args['menu-item-type'] ) {
$original_object = get_post( $args['menu-item-object-id'] );
$original_parent = (int) $original_object->post_parent;
$original_title = $original_object->post_title;
if ( $original_object instanceof WP_Post ) {
$original_parent = (int) $original_object->post_parent;
$original_title = $original_object->post_title;
}
} elseif ( 'post_type_archive' === $args['menu-item-type'] ) {
$original_object = get_post_type_object( $args['menu-item-object'] );
if ( $original_object ) {
if ( $original_object instanceof WP_Post_Type ) {
$original_title = $original_object->labels->archives;
}
}

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.7-alpha-58853';
$wp_version = '6.7-alpha-58854';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.