[wp-trac] [WordPress Trac] #47838: Typo in class-walker-nav-menu-checklist.php

WordPress Trac noreply at wordpress.org
Thu Oct 3 14:27:29 UTC 2019


#47838: Typo in class-walker-nav-menu-checklist.php
-------------------------------------------------+-------------------------
 Reporter:  yanngarcia                           |       Owner:
                                                 |  SergeyBiryukov
     Type:  defect (bug)                         |      Status:  reviewing
 Priority:  normal                               |   Milestone:  5.3
Component:  Menus                                |     Version:  trunk
 Severity:  minor                                |  Resolution:
 Keywords:  has-patch dev-feedback needs-dev-    |     Focuses:
  note                                           |  administration
-------------------------------------------------+-------------------------
Changes (by davidbaumwald):

 * keywords:  has-patch 2nd-opinion dev-feedback => has-patch dev-feedback
     needs-dev-note


Comment:

 After some digging into this with @desrosj, we found the following:
 1. When adding items to a menu, each post in the list has a checkbox.
 Each post list item also has  hidden fields of data related to that post.
 2. When the "Add To Menu" button is clicked, The JavaScript method
 `getItemData` is run on each hidden field to create an array of data for
 that post based on these hidden fields.
 3. Eventually, `api.addItemToMenu` is called for each item requested to be
 added to the menu.  This passes the array of data about each menu item to
 the AJAX request.
 4. The AJAX action is `add-menu-item` which passes the array of data about
 the item to the Core function `wp_save_nav_menu_items`.
 5. This function is looking for a key of `menu-item-attr-title`.
 6. Data is then passed to another Core function,
 `wp_update_nav_menu_item`, to save the menu item post in the DB.  This
 function is also referencing the `menu-item-attr-title` array key.
 7. The `post_excerpt` is set to whatever is passed.

 **TL;DR** - The value of the hidden field `name="menu-item[XXX][menu-item-
 attr-title]"` is intended to be the post excerpt.  That value is passed
 through to the eventual `nav_menu_item` post when it's saved to a menu.
 However, it's never going to pass through this value because functions are
 looking for the key `menu-item-attr-title`, not `menu-item-attr_title`.
 This bug has been unnoticed most liekly because there's not yet been a
 use-case for using the post excerpt on a menu item.

 In looking at the top three plugins that reference the existing key name,
 all three seem to have propagated the typo in their plugins by simply
 using the `Walker_Nav_Menu_Checklist` as a template for a custom walker
 similar in function.

 The fix will need a small call out on the miscellaneous dev note for 5.3.

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


More information about the wp-trac mailing list