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.

git-svn-id: https://develop.svn.wordpress.org/trunk@55059 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz
2023-01-12 23:23:01 +00:00
parent 771a0c9f58
commit 515d3fe69f
+6 -2
View File
@@ -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;
}