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
This commit is contained in:
Andrew Nacin 2013-07-10 05:14:43 +00:00
parent 939ba6619a
commit a16ac64012

View File

@ -179,17 +179,17 @@ function wp_nav_menu( $args = array() ) {
/* /*
* If no menu was found: * 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: * 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. * - Otherwise, bail.
*/ */
if ( ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) && !$args->theme_location ) ) if ( ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) && !$args->theme_location ) )
&& $args->fallback_cb && is_callable( $args->fallback_cb ) ) && $args->fallback_cb && is_callable( $args->fallback_cb ) )
return call_user_func( $args->fallback_cb, (array) $args ); 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; return false;
$nav_menu = $items = ''; $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_items', $items, $args );
$items = apply_filters( "wp_nav_menu_{$menu->slug}_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 ); $nav_menu .= sprintf( $args->items_wrap, esc_attr( $wrap_id ), esc_attr( $wrap_class ), $items );
unset( $items ); unset( $items );