From aba08a1bf5e956a0c8572197e35b3bf28eb30971 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Sun, 14 May 2017 03:37:45 +0000 Subject: [PATCH] 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 --- src/wp-includes/class-walker-nav-menu.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/class-walker-nav-menu.php b/src/wp-includes/class-walker-nav-menu.php index c97188b473..83dbfed45c 100644 --- a/src/wp-includes/class-walker-nav-menu.php +++ b/src/wp-includes/class-walker-nav-menu.php @@ -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}