From 1a2b5794da5ab76fb945ba90abee37780be33488 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 5 Aug 2024 19:00:19 +0000 Subject: [PATCH] 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 --- wp-includes/nav-menu.php | 22 +++++++++++++++------- wp-includes/version.php | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/wp-includes/nav-menu.php b/wp-includes/nav-menu.php index a063835fda..d808c4e212 100644 --- a/wp-includes/nav-menu.php +++ b/wp-includes/nav-menu.php @@ -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; } } diff --git a/wp-includes/version.php b/wp-includes/version.php index 960dde55fd..b9eb5fe8f4 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.