[wp-trac] [WordPress Trac] #37293: Customizer nav menu section is not compatible with

WordPress Trac noreply at wordpress.org
Wed Jul 6 05:23:23 UTC 2016


#37293: Customizer nav menu section is not compatible with
--------------------------+-----------------
 Reporter:  westonruter   |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  4.6
Component:  Customize     |    Version:  4.3
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------
 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:

 {{{#!js
 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`):

 {{{#!php
 $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
 <?php
 $exported['menu_id'] = intval( preg_replace( '/^nav_menu\[(\d+)\]/', '$1',
 $this->id ) );
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/37293>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list