Skip to content

Instantly share code, notes, and snippets.

@westonruter
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westonruter/c0b94561ec1adac966af to your computer and use it in GitHub Desktop.
Save westonruter/c0b94561ec1adac966af to your computer and use it in GitHub Desktop.
Monkey patch for #31484: Widgets appearing in Customizer preview during a theme preview may not correspond to controls in Widgets panel
/*global wp */
(function ( api ) {
/**
* Mark a sidebars_widgets setting as dirty.
*
* @param {wp.customize.Setting} setting
*/
var markAddedSidebarsWidgetsAsDirty = function ( setting ) {
if ( 0 === setting.id.indexOf( 'sidebars_widgets[' ) ) {
setting._dirty = true;
}
};
// Only mark settings initially added as dirty
api.bind( 'add', markAddedSidebarsWidgetsAsDirty );
api.bind( 'ready', function () {
api.unbind( 'add', markAddedSidebarsWidgetsAsDirty );
});
}( wp.customize ));
<?php
/**
* Plugin Name: Trac #31484 Monkey Patch
* Description: Fix: Widgets appearing in Customizer preview during a theme preview may not correspond to controls in Widgets panel.
* Plugin URI: https://gist.github.com/westonruter/c0b94561ec1adac966af
* Version: 0.1
* Author: XWP, Weston Ruter
* Author URI: https://xwp.co/
* License: GPLv2+
*/
/**
* Copyright (c) 2015 XWP (https://xwp.co/)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2 or, at
* your discretion, any later version, as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
function trac_31484_monkey_patch_enqueue_scripts() {
/**
* @var WP_Customize_Manager $wp_customize
*/
global $wp_customize;
// The fix is only needed when previewing a different theme
if ( $wp_customize->is_theme_active() ) {
return;
}
$handle = 'trac-31484-monkey-patch';
$src = plugin_dir_url( __FILE__ ) . 'trac-31484-monkey-patch.js';
$deps = array( 'customize-controls' );
wp_enqueue_script( $handle, $src, $deps );
}
add_action( 'customize_controls_enqueue_scripts', 'trac_31484_monkey_patch_enqueue_scripts' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment