WordPress.org

Make WordPress Core

Ticket #15214: add-parent-menu-item-class.diff

File add-parent-menu-item-class.diff, 1.5 KB (added by chrisbliss18, 5 years ago)
  • wp-includes/classes.php

    diff --git wp-includes/classes.php wp-includes/classes.php
    index 7de27f6..8a9eaeb 100644
    class Walker { 
    10501050                //display this element 
    10511051                if ( is_array( $args[0] ) ) 
    10521052                        $args[0]['has_children'] = ! empty( $children_elements[$element->$id_field] ); 
     1053                else if ( is_object( $args[0] ) ) 
     1054                        $args[0]->has_children = ! empty( $children_elements[$element->$id_field] ); 
    10531055                $cb_args = array_merge( array(&$output, $element, $depth), $args); 
    10541056                call_user_func_array(array(&$this, 'start_el'), $cb_args); 
    10551057 
    class Walker_Page extends Walker { 
    13971399                } elseif ( $page->ID == get_option('page_for_posts') ) { 
    13981400                        $css_class[] = 'current_page_parent'; 
    13991401                } 
     1402                if ( $args['has_children'] ) 
     1403                        $css_class[] = 'page_item_with_children'; 
    14001404 
    14011405                $css_class = implode(' ', apply_filters('page_css_class', $css_class, $page)); 
    14021406 
  • wp-includes/nav-menu-template.php

    diff --git wp-includes/nav-menu-template.php wp-includes/nav-menu-template.php
    index 399900e..ef687cc 100644
    class Walker_Nav_Menu extends Walker { 
    7272 
    7373                $classes = empty( $item->classes ) ? array() : (array) $item->classes; 
    7474                $classes[] = 'menu-item-' . $item->ID; 
     75                if ( $args->has_children ) 
     76                        $classes[] = 'menu-item-with-sub-menu'; 
    7577 
    7678                $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) ); 
    7779                $class_names = ' class="' . esc_attr( $class_names ) . '"';