From 5989bc82bab79a799a622eb8e965bc0e6f4a735f Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 28 Apr 2016 18:19:15 +0000 Subject: [PATCH] Customize: Remove format placeholders from widget templates and selectors, fixing a jQuery selector syntax error and the broken highlight/shift-click behaviors. The issues occur in themes that register sidebars that reference a single format placeholder (`%1$s` and `%2$s`) multiple times, such as in the `id` and `class` attributes for `$before_widget`. Props martin.krcho, westonruter. Fixes #36473. git-svn-id: https://develop.svn.wordpress.org/trunk@37322 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/customize-preview-widgets.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/js/customize-preview-widgets.js b/src/wp-includes/js/customize-preview-widgets.js index b22087b64a..6702bffe7d 100644 --- a/src/wp-includes/js/customize-preview-widgets.js +++ b/src/wp-includes/js/customize-preview-widgets.js @@ -372,7 +372,7 @@ wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( } widgetContainerElement = $( - sidebarPartial.params.sidebarArgs.before_widget.replace( '%1$s', widgetId ).replace( '%2$s', 'widget' ) + + sidebarPartial.params.sidebarArgs.before_widget.replace( /%1\$s/g, widgetId ).replace( /%2\$s/g, 'widget' ) + sidebarPartial.params.sidebarArgs.after_widget ); @@ -511,7 +511,7 @@ wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( $.each( self.registeredSidebars, function( i, sidebar ) { var widgetTpl = [ - sidebar.before_widget.replace( '%1$s', '' ).replace( '%2$s', '' ), + sidebar.before_widget, sidebar.before_title, sidebar.after_title, sidebar.after_widget @@ -524,13 +524,15 @@ wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( widgetSelector = emptyWidget.prop( 'tagName' ); widgetClasses = emptyWidget.prop( 'className' ); + // Remove class names that incorporate the string formatting placeholders %1$s and %2$s. + widgetClasses = widgetClasses.replace( /\S*%[12]\$s\S*/g, '' ); + widgetClasses = widgetClasses.replace( /^\s+|\s+$/g, '' ); + // Prevent a rare case when before_widget, before_title, after_title and after_widget is empty. if ( ! widgetClasses ) { return; } - widgetClasses = widgetClasses.replace( /^\s+|\s+$/g, '' ); - if ( widgetClasses ) { widgetSelector += '.' + widgetClasses.split( /\s+/ ).join( '.' ); }