Opened 10 years ago
Closed 10 years ago
#37293 closed defect (bug) (fixed)
Customizer nav menu section in PHP is unable to represent placeholders
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 4.6 | Priority: | normal |
| Severity: | normal | Version: | 4.3 |
| Component: | Customize | Keywords: | has-patch commit |
| Focuses: | Cc: |
Description
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:
<?php $exported['menu_id'] = intval( preg_replace( '/^nav_menu\[(\d+)\]/', '$1', $this->id ) );
Attachments (1)
Change History (4)
Note: See
TracTickets for help on using
tickets.
In 37981: