[wp-trac] [WordPress Trac] #28140: Position for first menu item on menu is 0 when it should be 1

WordPress Trac noreply at wordpress.org
Sun Oct 1 18:52:04 UTC 2017


#28140: Position for first menu item on menu is 0 when it should be 1
--------------------------------------+-----------------------------
 Reporter:  danielbachhuber           |       Owner:
     Type:  defect (bug)              |      Status:  new
 Priority:  normal                    |   Milestone:  Future Release
Component:  Menus                     |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+-----------------------------
Changes (by birgire):

 * keywords:  needs-unit-tests has-patch => has-patch has-unit-tests


Comment:

 The position of menu items is stored as {{{0,2,3, ...}}} in the
 {{{menu_order}}} field of the {{{wp_posts}}} table, as @danielbachhuber
 mentioned.

 We note that it's not possible to test this behavior directly with
 {{{wp_get_nav_menu_items()}}}, because the position ({{{menu_order}}}) is
 adjusted from {{{0,2,3,...}}} to {{{1,2,3,...}}} with this part of that
 function:

 {{{
 $i = 1;
 foreach ( $items as $k => $item ) {
     $items[$k]->{$args['output_key']} = $i++;
 }

 }}}

 where {{{$args['output_key']}}} is {{{menu_order}}}.

 See here:

 https://core.trac.wordpress.org/browser/tags/4.8.2/src/wp-includes/nav-
 menu.php#L657-L660

 In [attachment:28140.3.patch] we

  - Adjust the patch in [attachment:28140.2.diff] with {{{1 == (int) $args
 ['menu-item-position']}}} instead of {{{0 == (int) $args['menu-item-
 position']}}}
 - Add a test to check if the position (menu_order) of two newly added menu
 items is 1 and then 2.
 - Add a test to check if the position (menu_order) from
 {{{wp_get_nav_menu_items()}}} is 1 and 2.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/28140#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list