Make WordPress Core

Opened 13 years ago

Closed 13 years ago

#25238 closed defect (bug) (fixed)

Ensure parity between JS and PHP calculation of theme customizer control IDs

Reported by: westonruter Owned by: nacin
Priority: normal Milestone: 3.7
Component: Customize Version: 3.5
Severity: normal Keywords: has-patch
Cc: Focuses:

Description

Do global search/replace for customize control selector

In WP_Customize_Conrol::render(), the $id for a control is constructed via:

      $id    = 'customize-control-' . str_replace( '[', '-', str_replace( ']', '', $this->id ) );

The PHP str_replace function does a global replacement. In JavaScript, however, if you call the string.replace() with a string as the pattern argument instead of a RegExp, it will do a single replacement instead of a global one. Therefore, RegExp literals with the g flag must be supplied to ensure that the ID calculated in JS matches the ID calculated in PHP.

If a setting is registered for a multidimensional array, for example myplugin[foo][bar][baz], then the field in the Customizer will fail to pick up changes because it is not able to find the control's container element via the selector.

Attachments (1)

customize-controls.js.patch (577 bytes ) - added by westonruter 13 years ago.
Use RegExp with global flag instead of strings for replacement patterns

Download all attachments as: .zip

Change History (7)

@westonruter
13 years ago

Use RegExp with global flag instead of strings for replacement patterns

#1 @SergeyBiryukov
13 years ago

  • Component ThemesAppearance
  • Summary Ensure parity between JS and PHP calculation of theem customizer control IDsEnsure parity between JS and PHP calculation of theme customizer control IDs

#2 @SergeyBiryukov
13 years ago

  • Keywords has-patch added
  • Milestone Awaiting Review3.7

#3 @westonruter
13 years ago

Just wanted to mention that the patch for this bug is a dependency for the new Widget Customizer plugin: https://github.com/x-team/wp-widget-customizer

#4 @fjarrett
13 years ago

  • Cc fjarrett@… added

#5 @johnregan3
13 years ago

  • Cc john.m.regan@… added

#6 @nacin
13 years ago

  • Owner set to nacin
  • Resolutionfixed
  • Status newclosed

In 25680:

Ensure we globally replace [ and ] in customizer control IDs, to match the PHP.

props westonruter.
fixes #25238.

Note: See TracTickets for help on using tickets.