Make WordPress Core


Ignore:
Timestamp:
11/11/2022 12:04:58 AM (4 years ago)
Author:
peterwilsoncc
Message:

Menus: Apply menu-item-has-children class in sub-menus.

Ensure the menu-item-has-children class is added to sub-menu items when wp_nav_menu() is called with the depth parameter specified to a non-zero value.

Follow up to [54478].

Props davidvongries, fpodhorsky, hellofromTonya, innovext, larsmqller, LeonidasMilossis, mattkeys, mukesh27, nuvoPoint, ocean90, outrankjames, petitphp, SergeyBiryukov, sippis, webmandesign.
Fixes #56946.
See #28620.

File:
1 edited

Legend:

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

    r54478 r54801  
    205205                        $menu_items_with_children[ $menu_item->menu_item_parent ] = 1;
    206206                }
    207 
    208                 // Calculate the depth of each menu item with children
    209                 foreach ( $menu_items_with_children as $menu_item_key => &$menu_item_depth ) {
    210                         $menu_item_parent = $menu_items_tree[ $menu_item_key ];
    211                         while ( $menu_item_parent ) {
    212                                 $menu_item_depth  = $menu_item_depth + 1;
    213                                 $menu_item_parent = $menu_items_tree[ $menu_item_parent ];
    214                         }
     207        }
     208
     209        // Calculate the depth of each menu item with children.
     210        foreach ( $menu_items_with_children as $menu_item_key => &$menu_item_depth ) {
     211                $menu_item_parent = $menu_items_tree[ $menu_item_key ];
     212                while ( $menu_item_parent ) {
     213                        $menu_item_depth  = $menu_item_depth + 1;
     214                        $menu_item_parent = $menu_items_tree[ $menu_item_parent ];
    215215                }
    216216        }
Note: See TracChangeset for help on using the changeset viewer.