WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 7 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
Milestone: 3.7 Priority: normal
Severity: normal Version: 3.5
Component: Customize Keywords: has-patch
Focuses: Cc:

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 7 years ago.
Use RegExp with global flag instead of strings for replacement patterns

Download all attachments as: .zip

Change History (7)

@westonruter
7 years ago

Use RegExp with global flag instead of strings for replacement patterns

#1 @SergeyBiryukov
7 years ago

  • Component changed from Themes to Appearance
  • Summary changed from Ensure parity between JS and PHP calculation of theem customizer control IDs to Ensure parity between JS and PHP calculation of theme customizer control IDs

#2 @SergeyBiryukov
7 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 3.7

#3 @westonruter
7 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
7 years ago

  • Cc fjarrett@… added

#5 @johnregan3
7 years ago

  • Cc john.m.regan@… added

#6 @nacin
7 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

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.