Customizer: Fix previewing and applying widgets when previewing another theme.

* Unset `wp_get_sidebars_widgets()`' non-admin cache var `$_wp_sidebars_widgets` in Customize theme preview.
* Add `WP_Customize_Setting::$dirty` so that settings can be initially-dirty when the Customizer loads.
* Mark `old_sidebars_widgets_data` setting initially-dirty.
* Mark all `sidebars_widgets` settings as initially-dirty during theme switch.

props westonruter.
see #31484.
Built from https://develop.svn.wordpress.org/trunk@31705


git-svn-id: http://core.svn.wordpress.org/trunk@31686 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2015-03-10 22:39:28 +00:00
parent 2ae3dfa119
commit b96a624cb9
6 changed files with 26 additions and 4 deletions

View File

@ -250,6 +250,7 @@ do_action( 'customize_controls_print_scripts' );
$settings['settings'][ $id ] = array( $settings['settings'][ $id ] = array(
'value' => $setting->js_value(), 'value' => $setting->js_value(),
'transport' => $setting->transport, 'transport' => $setting->transport,
'dirty' => $setting->dirty,
); );
} }

View File

@ -17,6 +17,7 @@
this.id = id; this.id = id;
this.transport = this.transport || 'refresh'; this.transport = this.transport || 'refresh';
this._dirty = options.dirty || false;
this.bind( this.preview ); this.bind( this.preview );
}, },
@ -2516,7 +2517,8 @@
$.each( api.settings.settings, function( id, data ) { $.each( api.settings.settings, function( id, data ) {
api.create( id, id, data.value, { api.create( id, id, data.value, {
transport: data.transport, transport: data.transport,
previewer: api.previewer previewer: api.previewer,
dirty: !! data.dirty
} ); } );
}); });

File diff suppressed because one or more lines are too long

View File

@ -60,6 +60,20 @@ class WP_Customize_Setting {
public $sanitize_callback = ''; public $sanitize_callback = '';
public $sanitize_js_callback = ''; public $sanitize_js_callback = '';
/**
* Whether or not the setting is initially dirty when created.
*
* This is used to ensure that a setting will be sent from the pane to the
* preview when loading the Customizer. Normally a setting only is synced to
* the preview if it has been changed. This allows the setting to be sent
* from the start.
*
* @since 4.2.0
* @access public
* @var bool
*/
public $dirty = false;
protected $id_data = array(); protected $id_data = array();
/** /**

View File

@ -216,6 +216,7 @@ final class WP_Customize_Widgets {
$sidebars_widgets = $this->old_sidebars_widgets; $sidebars_widgets = $this->old_sidebars_widgets;
$sidebars_widgets = retrieve_widgets( 'customize' ); $sidebars_widgets = retrieve_widgets( 'customize' );
add_filter( 'option_sidebars_widgets', array( $this, 'filter_option_sidebars_widgets_for_theme_switch' ), 1 ); add_filter( 'option_sidebars_widgets', array( $this, 'filter_option_sidebars_widgets_for_theme_switch' ), 1 );
unset( $GLOBALS['_wp_sidebars_widgets'] ); // reset global cache var used by wp_get_sidebars_widgets()
} }
/** /**
@ -332,6 +333,7 @@ final class WP_Customize_Widgets {
$setting_id = 'old_sidebars_widgets_data'; $setting_id = 'old_sidebars_widgets_data';
$setting_args = $this->get_setting_args( $setting_id, array( $setting_args = $this->get_setting_args( $setting_id, array(
'type' => 'global_variable', 'type' => 'global_variable',
'dirty' => true,
) ); ) );
$this->manager->add_setting( $setting_id, $setting_args ); $this->manager->add_setting( $setting_id, $setting_args );
} }
@ -356,6 +358,9 @@ final class WP_Customize_Widgets {
$setting_id = sprintf( 'sidebars_widgets[%s]', $sidebar_id ); $setting_id = sprintf( 'sidebars_widgets[%s]', $sidebar_id );
$setting_args = $this->get_setting_args( $setting_id ); $setting_args = $this->get_setting_args( $setting_id );
if ( ! $this->manager->get_setting( $setting_id ) ) { if ( ! $this->manager->get_setting( $setting_id ) ) {
if ( ! $this->manager->is_theme_active() ) {
$setting_args['dirty'] = true;
}
$this->manager->add_setting( $setting_id, $setting_args ); $this->manager->add_setting( $setting_id, $setting_args );
} }
$new_setting_ids[] = $setting_id; $new_setting_ids[] = $setting_id;

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.2-alpha-31704'; $wp_version = '4.2-alpha-31705';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.