WordPress.org

Make WordPress Core

Changeset 40665


Ignore:
Timestamp:
05/14/2017 03:37:45 AM (3 years ago)
Author:
peterwilsoncc
Message:

Menus: Prevent empty class attribute following [40537].

Prevents an empty class attribute, class="", from appearing in the HTML if a developer removes all classes using the nav_menu_submenu_css_class filter.

Props Kopepasah.
Fixes #36163.

File:
1 edited

Legend:

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

    r40537 r40665  
    6060        $indent = str_repeat( $t, $depth );
    6161
     62        // Default class.
     63        $classes = array( 'sub-menu' );
     64
    6265        /**
    6366         * Filters the CSS class(es) applied to a menu list element.
     
    6972         * @param int      $depth   Depth of menu item. Used for padding.
    7073         */
    71 
    72         $classes = array( 'sub-menu' );
    73         $classes = apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth );
    74         $class_names = join( ' ', $classes );
    75 
    76         $output .= "{$n}{$indent}<ul class='" . esc_attr( $class_names ) . "'>{$n}";
     74        $class_names = join( ' ', apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth ) );
     75        $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
     76
     77        $output .= "{$n}{$indent}<ul $class_names>{$n}";
    7778    }
    7879
Note: See TracChangeset for help on using the changeset viewer.