WordPress at a glance
function is not described

WP_Customize_Widgets::override_sidebars_widgets_for_theme_switch() public WP 3.9.0

Override sidebars_widgets for theme switch.

When switching a theme via the Customizer, supply any previously-configured sidebars_widgets from the target theme as the initial sidebars_widgets setting. Also store the old theme's existing settings so that they can be passed along for storing in the sidebars_widgets theme_mod when the theme gets switched.

It's a method of the class: WP_Customize_Widgets{}

No Hooks.

Return

Null. Nothing.

Usage

$WP_Customize_Widgets = new WP_Customize_Widgets();
$WP_Customize_Widgets->override_sidebars_widgets_for_theme_switch();

Notes

  • Global. Array. $sidebars_widgets
  • Global. Array. $_wp_sidebars_widgets

Changelog

Since 3.9.0 Introduced.

Code of WP_Customize_Widgets::override_sidebars_widgets_for_theme_switch() WP 5.5.1

<?php
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'] );
}