From 0380c40190c8c2978d617779eb3226dc3bd3cf4b Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Thu, 12 Jan 2023 23:24:12 +0000 Subject: [PATCH] Menus: Compare `$menu_item->ID` and `$menu_item->menu_item_parent` as strings and avoid moidifying them. Plugins may change the ID to a string. Props Chouby, peterwilsoncc, Chrystl, manooweb, azaozz. Fixes #57169. Built from https://develop.svn.wordpress.org/trunk@55059 git-svn-id: http://core.svn.wordpress.org/trunk@54592 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/nav-menu-template.php | 8 ++++++-- wp-includes/version.php | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/wp-includes/nav-menu-template.php b/wp-includes/nav-menu-template.php index 135d35e130..50ed2d481e 100644 --- a/wp-includes/nav-menu-template.php +++ b/wp-includes/nav-menu-template.php @@ -198,8 +198,12 @@ function wp_nav_menu( $args = array() ) { $sorted_menu_items = array(); $menu_items_with_children = array(); foreach ( (array) $menu_items as $menu_item ) { - // Fix invalid `menu_item_parent`. See: https://core.trac.wordpress.org/ticket/56926. - if ( (int) $menu_item->ID === (int) $menu_item->menu_item_parent ) { + /* + * Fix invalid `menu_item_parent`. See: https://core.trac.wordpress.org/ticket/56926. + * Compare as strings. Plugins may change the ID to string. + * To avoid modifying the object, use `strval()` rather than casting to (string). + */ + if ( strval( $menu_item->ID ) === strval( $menu_item->menu_item_parent ) ) { $menu_item->menu_item_parent = 0; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 5747f990af..92a3107f70 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.2-alpha-55058'; +$wp_version = '6.2-alpha-55059'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.