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.


git-svn-id: https://develop.svn.wordpress.org/trunk@40665 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Peter Wilson 2017-05-14 03:37:45 +00:00
parent 8ba881647c
commit aba08a1bf5
1 changed files with 6 additions and 5 deletions

View File

@ -59,6 +59,9 @@ class Walker_Nav_Menu extends Walker {
}
$indent = str_repeat( $t, $depth );
// Default class.
$classes = array( 'sub-menu' );
/**
* Filters the CSS class(es) applied to a menu list element.
*
@ -68,12 +71,10 @@ class Walker_Nav_Menu extends Walker {
* @param stdClass $args An object of `wp_nav_menu()` arguments.
* @param int $depth Depth of menu item. Used for padding.
*/
$class_names = join( ' ', apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth ) );
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
$classes = array( 'sub-menu' );
$classes = apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth );
$class_names = join( ' ', $classes );
$output .= "{$n}{$indent}<ul class='" . esc_attr( $class_names ) . "'>{$n}";
$output .= "{$n}{$indent}<ul $class_names>{$n}";
}
/**