WordPress.org

Make WordPress Core

Ticket #23834: 23834.diff

File 23834.diff, 1.1 KB (added by hotchkissconsulting, 7 years ago)
  • wp-includes/nav-menu-template.php

    diff --git wp-includes/nav-menu-template.php wp-includes/nav-menu-template.php
    index 0ac14c3..906cad6 100644
    function wp_nav_menu( $args = array() ) { 
    208208        // Set up the $menu_item variables
    209209        _wp_menu_item_classes_by_context( $menu_items );
    210210
    211         $sorted_menu_items = array();
    212         foreach ( (array) $menu_items as $key => $menu_item )
    213                 $sorted_menu_items[$menu_item->menu_order] = $menu_item;
     211        $sorted_menu_items = $menu_item_parents = array();
     212        foreach ( (array) $menu_items as $menu_item ) {
     213                $sorted_menu_items[ $menu_item->menu_order ] = $menu_item;
     214                if ( $menu_item->menu_item_parent )
     215                        $menu_item_parents[ $menu_item->menu_item_parent ] = true;
     216        }
     217
     218        //Add in the menu-item-parent class
     219        if ( $menu_item_parents ) {
     220                foreach ( $sorted_menu_items as &$menu_item ) {
     221                        if ( array_key_exists( $menu_item->ID, $menu_item_parents ) )
     222                                $menu_item->classes[] = 'menu-item-parent';
     223                }
     224        }
    214225
    215         unset($menu_items);
     226        unset( $menu_items, $menu_item );
    216227
    217228        $sorted_menu_items = apply_filters( 'wp_nav_menu_objects', $sorted_menu_items, $args );
    218229