WordPress.org

Make WordPress Core

Opened 3 months ago

Closed 3 weeks ago

Last modified 8 days ago

#47838 closed defect (bug) (fixed)

Typo in class-walker-nav-menu-checklist.php

Reported by: yanngarcia Owned by: desrosj
Milestone: 5.3 Priority: normal
Severity: minor Version: trunk
Component: Menus Keywords: has-patch dev-feedback has-dev-note
Focuses: administration Cc:
PR Number:

Description

File: wp-admin\includes\class-walker-nav-menu-checklist.php:114

The name attribute of the "Title Attribute" hidden input ends with ...[menu-item-attr_title] and should ends with ...[menu-item-attr-title] (dash instead of underscore as expected in wp-admin\js\nav-menu.js and wp-admin\includes\nav-menu.php)

Found this typo by wanting to set a default title attribute to a menu item, using the filter 'wp_setup_nav_menu_item', but the input value is not sent/used because of the typo.

Attachments (1)

47838.patch (1.5 KB) - added by yanngarcia 3 months ago.
Typo fix

Download all attachments as: .zip

Change History (11)

@yanngarcia
3 months ago

Typo fix

#1 @SergeyBiryukov
3 months ago

  • Milestone changed from Awaiting Review to 5.3
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

This ticket was mentioned in Slack in #core by david.baumwald. View the logs.


3 weeks ago

#3 @davidbaumwald
3 weeks ago

  • Keywords dev-feedback added

This ticket was discussed in today's scrub. @ipstenu was kind enough to grab a report on impact of plugins referencing the class name here.

Matches  Plugin                      Active installs
=======  ======                      ===============
      1  easy-custom-sidebars                30,000+
      1  userswp                              6,000+
      1  widget-menuizer                        300+
      1  chapters                                60+
      2  defeed                                  10+
      2  widgets-in-menu                     10,000+
      4  mobiloud-mobile-app-plugin           1,000+
      1  buddypress                         200,000+
      1  advance-menu-manager                   700+
      2  menus-multisite-picker                   0+
      1  posterno                                10+
      1  ultimate-member-navigation-menu        200+
      4  wp-widget-in-navigation                600+

@ipstenu also asked about a phased approach for implementation of the fix, given the impact...

[I]s there a way to support both for 5.3 and then drop the typo in 5.4?

#4 @davidbaumwald
3 weeks ago

  • Keywords needs-dev-note added; 2nd-opinion removed

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.

#5 @davidbaumwald
3 weeks ago

  • Owner changed from SergeyBiryukov to desrosj

There appears to be no reference to the misspelled key anywhere else in the code base, including any CSS.

Given that that the original patch is still applying cleanly, this is being reassigned to @desrosj at his request for merging. This will still need the small call out to alert plugin devs of the update.

#6 @desrosj
3 weeks ago

Thanks, @davidbaumwald! Went back and it looks like this was introduced in [14248], so has been broken for some time.

#7 @desrosj
3 weeks ago

In 46380:

Menus: Fix typo in the class attribute for the hidden title field in Walker_Nav_Menu_Checklist.

Each item that Walker_Nav_Menu_Checklist displays is accompanied by several hidden <input/> fields that specify default values for each item when added to a menu. These values are passed in JavaScript to the AJAX call triggered when an item is added to a menu.

The hidden field for the title attribute field incorrectly had an underscore instead of a hyphen. Because of this, it was impossible to supply a default value for the Title Attribute field of a nav menu item.

Props yanngarcia, davidbaumwald.
See #47838.

#8 @desrosj
3 weeks ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

Accidentally did not include Fixes in [46380]. Closing out, dev note to follow.

#9 @SergeyBiryukov
3 weeks ago

In 46401:

Customize: Remove duplicate attr_title assignment in api.Menus.MenuItemControl.renderContent().

See #47838.

#10 @desrosj
8 days ago

  • Keywords has-dev-note added; needs-dev-note removed

Mentioned in the Miscellaneous Developer Focused Changes dev note for 5.3: https://make.wordpress.org/core/2019/10/15/miscellaneous-developer-focused-changes-in-5-3/

Note: See TracTickets for help on using tickets.