[wp-trac] [WordPress Trac] #24587: Walker_Page and Walker_Nav_Menu not compatible

WordPress Trac noreply at wordpress.org
Sun Jun 16 20:00:06 UTC 2013


#24587: Walker_Page and Walker_Nav_Menu not compatible
--------------------------+-----------------------------
 Reporter:  geardev       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Menus         |    Version:
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 Assume the following scenario: A developer decides to use a nav menu but
 wants to use a custom walker. He copy-pastes all the code in the
 `Walker_Nav_Menu` class and creates his own walker with it. But he doesn't
 assign a menu in the backend. Now this happens:

 * `wp_nav_menu` is called
 * The menu can't be found, therefore `wp_page_menu` is used
 * The `Walker_Nav_Menu`, that was passed to `wp_nav_menu`, is used to
 display the elements

 But there are two problems.

 The `$args` variable is converted to an object in `wp-includes/nav-menu-
 template.php` on line 145 by `wp_nav_menu`. Problem is, the `wp_page_menu`
 keeps the array instead and passes it to the nav menu walker, which needs
 the object. This will result in a few errors:
   * Notice: Trying to get property of non-object in wp-includes/nav-menu-
 template.php on line 88
   * Notice: Trying to get property of non-object in wp-includes/nav-menu-
 template.php on line 90
   * Notice: Trying to get property of non-object in wp-includes/nav-menu-
 template.php on line 90
   * Notice: Trying to get property of non-object in wp-includes/nav-menu-
 template.php on line 92
 If you use this code snippet in an empty theme:
 {{{
 #!php
 <?php wp_nav_menu( array(
         'theme_location' => 'non-existing-menu',
         'walker'         => new Walker_Nav_Menu
 ) );
 }}}

 Additionally, the `WP_Post` object is different. For a nav menu, the
 walker uses `$item->title`, which doesn't exist in the page walker.
 Therefore all `<li>`'s are empty.

 One should either standardize the Walker system, or implement checks in
 the default Walker_Nav_Menu to provide a solid starting point for other
 developers.

--
Ticket URL: <http://core.trac.wordpress.org/ticket/24587>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list