[wp-trac] [WordPress Trac] #14768: Incorrect wp_nav_menu behavior when theme_location is set but no menus exist/assigned
WordPress Trac
wp-trac at lists.automattic.com
Thu Sep 2 22:00:12 UTC 2010
#14768: Incorrect wp_nav_menu behavior when theme_location is set but no menus
exist/assigned
--------------------------+-------------------------------------------------
Reporter: almostdaniel | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Menus | Version: 3.0.1
Severity: normal | Keywords: wp_nav_menu, theme_location
--------------------------+-------------------------------------------------
The Codex Function Reference for '''wp_nav_menu''' states:
{{{
Given a theme_location parameter, the function displays the menu assigned
to that location, or nothing if no such location exists or no menu is
assigned to it.
}}}
In my theme functions.php, I have registered two nav menu locations:
{{{
register_nav_menus( array(
'primary' => __( 'Primary Navigation' ),
'secondary' => __( 'Secondary Navigation' ),
) );
}}}
In my theme header.php, I call for the location menus:
{{{
wp_nav_menu( array( 'container' => 'div', 'container_id' => 'index-nav',
'theme_location' => 'secondary' ) );
wp_nav_menu( array( 'container' => 'div', 'container_id' => 'toc-nav',
'theme_location' => 'primary' ) );
}}}
I do not have any menus created or assigned to those locations. However,
based on the Codex, I expect that nothing will be displayed.
However, the '''wp_nav_menu''' functions are falling back to the callback
function, '''wp_page_menu'''. That decision is made in this part of the
'''wp_nav_menu''' function:
{{{
// If no menu was found or if the menu has no items and no
location was requested, call the fallback_cb if it exists
if ( ( !$menu || is_wp_error($menu) || ( isset($menu_items) &&
empty($menu_items) && !$args->theme_location ) )
&& ( function_exists($args->fallback_cb) || is_callable(
$args->fallback_cb ) ) ) {
}}}
This logic overrides the statement in the Codex. If by this point no menu
has been found (and it won't be, because each of the checks before get
overrided by there being a {{{$args->theme_location}}} set), I
automatically use the callback function–no matter if I have specified a
theme_location or not. This is due to the first OR parameter "{{{!$menu ||
...}}}". The only way my theme_location specification prevents this is if
a menu ''was'' found. But that's impossible because theme_location
prevents it from being found.
I think the pattern from the previous checks should be carried on to this
final check. Not sure if this would break some other logic, but it would
at least match the Codex description.
{{{
// If no menu was found or if the menu has no items, and no
location was requested, call the fallback_cb if it exists
if ( ( !$menu || is_wp_error($menu) || ( isset($menu_items) &&
empty($menu_items) ) )
&& ( function_exists($args->fallback_cb) || is_callable(
$args->fallback_cb ) )
&& !$args->theme_location) {
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/14768>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list