From a16ac64012932645094053e073024130d7b14336 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Wed, 10 Jul 2013 05:14:43 +0000 Subject: [PATCH] If a nav menu has no items, wait until after the wp_nav_menu_items filter before deciding whether to print nothing. see [21868] for original commit. see #21576. see #24035 for trunk. git-svn-id: http://core.svn.wordpress.org/trunk@24634 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/nav-menu-template.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/wp-includes/nav-menu-template.php b/wp-includes/nav-menu-template.php index be54bbe5e0..0ac14c328f 100644 --- a/wp-includes/nav-menu-template.php +++ b/wp-includes/nav-menu-template.php @@ -179,17 +179,17 @@ function wp_nav_menu( $args = array() ) { /* * If no menu was found: - * - Fallback (if one was specified), or bail. + * - Fall back (if one was specified), or bail. * * If no menu items were found: - * - Fallback, but only if no theme location was specified. + * - Fall back, but only if no theme location was specified. * - Otherwise, bail. */ if ( ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) && !$args->theme_location ) ) && $args->fallback_cb && is_callable( $args->fallback_cb ) ) return call_user_func( $args->fallback_cb, (array) $args ); - if ( !$menu || is_wp_error( $menu ) || empty( $menu_items ) ) + if ( ! $menu || is_wp_error( $menu ) ) return false; $nav_menu = $items = ''; @@ -239,6 +239,10 @@ function wp_nav_menu( $args = array() ) { $items = apply_filters( 'wp_nav_menu_items', $items, $args ); $items = apply_filters( "wp_nav_menu_{$menu->slug}_items", $items, $args ); + // Don't print any markup if there are no items at this point. + if ( empty( $items ) ) + return false; + $nav_menu .= sprintf( $args->items_wrap, esc_attr( $wrap_id ), esc_attr( $wrap_class ), $items ); unset( $items );