Make WordPress Core

Changeset 55059

Timestamp:
01/12/2023 11:23:01 PM (19 months ago)
Author:
azaozz
Message:

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.

File:
1 edited

Legend:

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

    r55005 r55059  
    199199    $menu_items_with_children = array();
    200200    foreach ( (array) $menu_items as $menu_item ) {
    201         // Fix invalid `menu_item_parent`. See: https://core.trac.wordpress.org/ticket/56926.
    202         if ( (int) $menu_item->ID === (int) $menu_item->menu_item_parent ) {
     201        /*
     202         * Fix invalid `menu_item_parent`. See: https://core.trac.wordpress.org/ticket/56926.
     203         * Compare as strings. Plugins may change the ID to string.
     204         * To avoid modifying the object, use `strval()` rather than casting to (string).
     205         */
     206        if ( strval( $menu_item->ID ) === strval( $menu_item->menu_item_parent ) ) {
    203207            $menu_item->menu_item_parent = 0;
    204208        }
Note: See TracChangeset for help on using the changeset viewer.