Opened 14 years ago
Closed 9 years ago
#16594 closed enhancement (fixed)
inconsistency in wp_nav_menu_items
Reported by: | thomask | Owned by: | chriscct7 |
---|---|---|---|
Milestone: | 4.3 | Priority: | normal |
Severity: | normal | Version: | 3.0 |
Component: | Menus | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
Not sure if it is a bug: when I create a menu, e.g.
wp_nav_menu(array( 'theme_location' => 'footer' ));
and put there a menu (E.g. named "My menu") using nav-menu.php editor and then try to call wp_nav_menu_items filter to see all arguments, e.g.
add_filter('wp_nav_menu_items','my_test', 10, 2); function my_test($items, $args) { print_r ($args); }
the resulting object is
( [menu] => [container] => div [container_class] => [container_id] => [menu_class] => menu [menu_id] => [echo] => 1 [fallback_cb] => [before] => [after] => [link_before] => [link_after] => [items_wrap] => <ul id="%1$s" class="%2$s">%3$s</ul> [depth] => 0 [walker] => [theme_location] => menu )
But if I put the same "My menu" to the same place using widget, I got object with extended 'menu'
[menu] => stdClass Object ( [term_id] => 4 [name] => My menu [slug] => my-menu [term_group] => 0 [term_taxonomy_id] => 4 [taxonomy] => nav_menu [description] => [parent] => 0 [count] => 3 ) [container] => div [container_class] => [container_id] => [menu_class] => menu [menu_id] => [echo] => 1 [fallback_cb] => [before] => [after] => [link_before] => [link_after] => [items_wrap] => <ul id="%1$s" class="%2$s">%3$s</ul> [depth] => 0 [walker] => [theme_location] =>
I guess that they should be the same (except 'theme_location') - the problem is, that using the first scenario, i got no way to find "My menu" details - id, name, slug ... of the menu, so i even cannot filter by them in my functions (e.g. apply filter just for a specific menu).
Attachments (2)
Change History (15)
Note: See
TracTickets for help on using
tickets.
I think it is the expected behavior. For wp_nav_menu we pass 'theme_location' but in the widget we pass 'menu' object.
If you want to get the menu object in wp_nav_menu like in widget, you can try this
If it is not the expected behavior then adding
$args->menu = $menu;
in wp_nav_menu function in wp-includes/nav-menu-tempalte.php fixes it.