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: | westonruter | Owned by: | westonruter |
|---|---|---|---|
| Priority: | normal | Milestone: | 4.6 |
| Component: | Customize | Version: | 4.3 |
| Severity: | normal | Keywords: | has-patch commit |
| Cc: | Focuses: |
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 ) );
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
In 37981: