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:
parent
8ba881647c
commit
aba08a1bf5
|
@ -59,6 +59,9 @@ class Walker_Nav_Menu extends Walker {
|
||||||
}
|
}
|
||||||
$indent = str_repeat( $t, $depth );
|
$indent = str_repeat( $t, $depth );
|
||||||
|
|
||||||
|
// Default class.
|
||||||
|
$classes = array( 'sub-menu' );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filters the CSS class(es) applied to a menu list element.
|
* 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 stdClass $args An object of `wp_nav_menu()` arguments.
|
||||||
* @param int $depth Depth of menu item. Used for padding.
|
* @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' );
|
$output .= "{$n}{$indent}<ul $class_names>{$n}";
|
||||||
$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}";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue