Opened 13 years ago
Last modified 6 years ago
#18232 new defect (bug)
wp_nav_menu - Setting walker parameter affects fallback_cb
Reported by: | bryanjwatson | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.2 |
Component: | Menus | Keywords: | has-patch needs-testing needs-refresh |
Focuses: | Cc: |
Description
When using the walker parameter with wp_nav_menu and there is no menu present, wp_nav_menu falls back by default (set with fallback_cb) to wp_page_menu. It appears that the set walker also affects wp_page_menu, which in most cases breaks the output.
wp_nav_menu usage:
<?php wp_nav_menu(array('walker'=> new Walker_Nav_Menu)); ?>
Output when no menu is present (falling back on wp_page_menu):
// Formatted for readability <div class="menu"> <ul> <li id="menu-item-1" class="menu-item-1"><a></a></li> <li id="menu-item-2" class="menu-item-2"><a></a></li> <li id="menu-item-3" class="menu-item-3"><a></a></li> </ul> </div>
Expected output:
// Formatted for readability <div class="menu"> <ul> <li class="page_item page-item-1"><a href="/first/" title="First">First</a></li> <li class="page_item page-item-2"><a href="/second/" title="Second">Second</a></li> <li class="page_item page-item-3"><a href="/third/" title="Third">Third</a></li> </ul> </div>
As you can see, the output from wp_page_menu is getting filtered through the walker, but since the walker was designed for menus specifically, it renders the default output from wp_page_menu useless (empty tags..etc).
Attachments (2)
Change History (9)
#2
@
13 years ago
- Keywords needs-testing added
- Summary changed from wp_nav_menu - Setting walker parameter affects fallback_cb (wp_page_menu) to wp_nav_menu - Setting walker parameter affects fallback_cb
Note: See
TracTickets for help on using
tickets.
Simple patch, but unfortunately it does not account for the scenario when a function other than wp_page_menu is set as the fallback_cb parameter.
For example, this would still break:
I believe the issue resides in the fact that the fallback function is inheriting the $args passed to wp_nav_menu.
Solution: Stop the $args inheritance on the fallback function, and create a new wp_nav_menu parameter to provide custom fallback args if needed. See patch 18232_v2.