Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#37293 closed defect (bug) (fixed)

Customizer nav menu section in PHP is unable to represent placeholders

Reported by: westonruter's profile westonruter Owned by: westonruter's profile westonruter
Milestone: 4.6 Priority: normal
Severity: normal Version: 4.3
Component: Customize Keywords: has-patch commit
Focuses: Cc:


When loading the Customizer with a pre-populated state containing a placeholder (yet-to-be-saved) nav menu, a JS error is thrown when the section is attempted to be expanded:

Uncaught TypeError: Cannot read property 'reflowMenuItems' of undefined

The code that throws the error is:

api.control( 'nav_menu[' + String( section.params.menu_id ) + ']' ).reflowMenuItems();

The problem here is that menu_id is not getting set properly in WP_Customize_Nav_Menu_Section::json() when the menu ID is a placeholder (like -9349073479):

$exported['menu_id'] = intval( preg_replace( '/^nav_menu\[(\d+)\]/', '$1', $this->id ) );

Since the pattern doesn't match, the menu_id gets set to 0 which then causes a JS error.

The fix is simple: to allow the number to be negative:

$exported['menu_id'] = intval( preg_replace( '/^nav_menu\[(\d+)\]/', '$1', $this->id ) );

Attachments (1)

37293.0.diff (677 bytes) - added by westonruter 8 years ago.

Download all attachments as: .zip

Change History (4)

#1 @westonruter
8 years ago

  • Summary changed from Customizer nav menu section is not compatible with to Customizer nav menu section in PHP is unable to represent placeholders

8 years ago

#2 @westonruter
8 years ago

  • Keywords has-patch commit added
  • Owner set to westonruter
  • Status changed from new to accepted

#3 @westonruter
8 years ago

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

In 37981:

Customize: Ensure that WP_Customize_Nav_Menu_Section is able to represent a placeholder nav menu.

Placeholder nav menus (ones that have yet to be saved into the DB) have negative integer IDs.

Fixes #37293.
Props valendesigns, stubgo, westonruter.

Note: See TracTickets for help on using tickets.