public function override_sidebars_widgets_for_theme_switch() { global $sidebars_widgets;
if ( $this->manager->
doing_ajax() ||
$this->manager->
is_theme_active() ) { return;
} $this->old_sidebars_widgets =
wp_get_sidebars_widgets();
add_filter( 'customize_value_old_sidebars_widgets_data', array
( $this, 'filter_customize_value_old_sidebars_widgets_data'
) );
$this->manager->
set_post_value( 'old_sidebars_widgets_data',
$this->old_sidebars_widgets
); // Override any value cached in changeset.
// retrieve_widgets() looks at the global $sidebars_widgets.
$sidebars_widgets =
$this->old_sidebars_widgets;
$sidebars_widgets =
retrieve_widgets( 'customize'
);
add_filter( 'option_sidebars_widgets', array
( $this, 'filter_option_sidebars_widgets_for_theme_switch'
), 1
);
// Reset global cache var used by wp_get_sidebars_widgets().
unset( $GLOBALS['_wp_sidebars_widgets'
] );
} /**
* Filters old_sidebars_widgets_data Customizer setting.
*
* When switching themes, filter the Customizer setting old_sidebars_widgets_data
* to supply initial $sidebars_widgets before they were overridden by retrieve_widgets().
* The value for old_sidebars_widgets_data gets set in the old theme's sidebars_widgets
* theme_mod.
*
* @since 3.9.0
*
* @see WP_Customize_Widgets::handle_theme_switch()
*
* @param array $old_sidebars_widgets
* @return array
*/