WordPress.org

Make WordPress Core

Opened 10 months ago

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

Download all attachments as: .zip

Change History (7)

westonruter10 months ago

Use RegExp with global flag instead of strings for replacement patterns

comment:1 SergeyBiryukov10 months 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

comment:2 SergeyBiryukov10 months ago

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

comment:3 westonruter10 months 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

comment:4 fjarrett10 months ago

  • Cc fjarrett@… added

comment:5 johnregan310 months ago

  • Cc john.m.regan@… added

comment:6 nacin9 months 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.