New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trac 39693: Fix missing assignment of widgets on theme switch #251

Open
wants to merge 10 commits into
base: master
from
@@ -707,7 +707,10 @@ function switch_theme( $stylesheet ) {
$_sidebars_widgets = null;
if ( 'wp_ajax_customize_save' === current_action() ) {
$_sidebars_widgets = $wp_customize->post_value( $wp_customize->get_setting( 'old_sidebars_widgets_data' ) );
$old_sidebars_widgets_data_setting = $wp_customize->get_setting( 'old_sidebars_widgets_data' );
if ( $old_sidebars_widgets_data_setting ) {
$_sidebars_widgets = $wp_customize->post_value( $old_sidebars_widgets_data_setting );
}
} elseif ( is_array( $sidebars_widgets ) ) {
$_sidebars_widgets = $sidebars_widgets;
}
@@ -919,11 +919,15 @@ function wp_get_sidebars_widgets( $deprecated = true ) {
* @since 2.2.0
* @access private
*
* @global array $_wp_sidebars_widgets
* @param array $sidebars_widgets Sidebar widgets and their settings.
*/
function wp_set_sidebars_widgets( $sidebars_widgets ) {
if ( !isset( $sidebars_widgets['array_version'] ) )
global $_wp_sidebars_widgets;
$_wp_sidebars_widgets = null; // Clear cached value used in wp_get_sidebars_widgets().
if ( ! isset( $sidebars_widgets['array_version'] ) ) {
$sidebars_widgets['array_version'] = 3;
}
update_option( 'sidebars_widgets', $sidebars_widgets );
}
@@ -1107,7 +1111,7 @@ function _wp_sidebars_changed() {
*
* @param string|bool $theme_changed Whether the theme was changed as a boolean. A value
* of 'customize' defers updates for the Customizer.
* @return array
* @return array Updated sidebars widgets.
*/
function retrieve_widgets( $theme_changed = false ) {
global $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets;
@@ -1143,7 +1147,7 @@ function retrieve_widgets( $theme_changed = false ) {
// Discard invalid, theme-specific widgets from sidebars.
$sidebars_widgets = _wp_remove_unregistered_widgets( $sidebars_widgets, $registered_widgets_ids );
$sidebars_widgets = _wp_map_sidebars( $sidebars_widgets );
$sidebars_widgets = wp_map_sidebars_widgets( $sidebars_widgets );
// Find hidden/lost multi-widget instances.
$shown_widgets = call_user_func_array( 'array_merge', $sidebars_widgets );
@@ -1173,7 +1177,7 @@ function retrieve_widgets( $theme_changed = false ) {
* @param array $old_sidebars_widgets List of sidebars and their widget instance IDs.
* @return array Mapped sidebars widgets.
*/
function _wp_map_sidebars( $old_sidebars_widgets ) {
function wp_map_sidebars_widgets( $old_sidebars_widgets ) {
global $wp_registered_sidebars;
$new_sidebars_widgets = array();
@@ -1219,9 +1223,9 @@ function _wp_map_sidebars( $old_sidebars_widgets ) {
* from within the same group, make an educated guess and map it.
*/
$common_slug_groups = array(
array( 'sidebar', 'primary', 'main', 'right' ),
array( 'sidebar-1', 'sidebar', 'primary', 'main', 'right' ),
array( 'second', 'left' ),
array( 'footer', 'bottom' ),
array( 'sidebar-2', 'footer', 'bottom' ),
array( 'header', 'top' ),
);
@@ -961,15 +961,15 @@ public function test__wp_remove_unregistered_widgets() {
/**
* Two themes with one sidebar each should just map, switching to a theme not previously-active.
*
* @covers _wp_map_sidebars()
* @covers wp_map_sidebars_widgets()
*/
public function test_one_sidebar_each() {
$this->register_sidebars( array( 'primary' ) );
$prev_theme_sidebars = array(
'unique-slug' => 1,
);
$new_next_theme_sidebars = _wp_map_sidebars( $prev_theme_sidebars );
$new_next_theme_sidebars = wp_map_sidebars_widgets( $prev_theme_sidebars );
$expected_sidebars = array(
'primary' => 1,
@@ -980,7 +980,7 @@ public function test_one_sidebar_each() {
/**
* Sidebars with the same name should map, switching to a theme not previously-active.
*
* @covers _wp_map_sidebars()
* @covers wp_map_sidebars_widgets()
*/
public function test_sidebars_with_same_slug() {
$this->register_sidebars( array( 'primary', 'secondary' ) );
@@ -989,15 +989,15 @@ public function test_sidebars_with_same_slug() {
'secondary' => 2,
);
$new_next_theme_sidebars = _wp_map_sidebars( $prev_theme_sidebars );
$new_next_theme_sidebars = wp_map_sidebars_widgets( $prev_theme_sidebars );
$this->assertEquals( $prev_theme_sidebars, $new_next_theme_sidebars );
}
/**
* Make educated guesses on theme sidebars.
*
* @covers _wp_map_sidebars()
* @covers wp_map_sidebars_widgets()
*/
public function test_sidebar_guessing() {
$this->register_sidebars( array( 'primary', 'secondary' ) );
@@ -1007,7 +1007,7 @@ public function test_sidebar_guessing() {
'footer' => array(),
);
$new_next_theme_sidebars = _wp_map_sidebars( $prev_theme_sidebars );
$new_next_theme_sidebars = wp_map_sidebars_widgets( $prev_theme_sidebars );
$expected_sidebars = array(
'primary' => array(),
@@ -1019,7 +1019,7 @@ public function test_sidebar_guessing() {
/**
* Make sure two sidebars that fall in the same group don't get the same menu assigned.
*
* @covers _wp_map_sidebars()
* @covers wp_map_sidebars_widgets()
*/
public function test_sidebar_guessing_one_menu_per_group() {
$this->register_sidebars( array( 'primary' ) );
@@ -1028,7 +1028,7 @@ public function test_sidebar_guessing_one_menu_per_group() {
'secondary' => array(),
);
$new_next_theme_sidebars = _wp_map_sidebars( $prev_theme_sidebars );
$new_next_theme_sidebars = wp_map_sidebars_widgets( $prev_theme_sidebars );
$expected_sidebars = array(
'main' => array(),
@@ -1039,7 +1039,7 @@ public function test_sidebar_guessing_one_menu_per_group() {
/**
* Make sure two sidebars that fall in the same group get menus assigned from the same group.
*
* @covers _wp_map_sidebars()
* @covers wp_map_sidebars_widgets()
*/
public function test_sidebar_guessing_one_menu_per_sidebar() {
$this->register_sidebars( array( 'primary', 'main' ) );
@@ -1049,7 +1049,7 @@ public function test_sidebar_guessing_one_menu_per_sidebar() {
'top-menu' => array(),
);
$new_next_theme_sidebars = _wp_map_sidebars( $prev_theme_sidebars );
$new_next_theme_sidebars = wp_map_sidebars_widgets( $prev_theme_sidebars );
$expected_sidebars = array(
'main' => array(),
ProTip! Use n and p to navigate between commits in a pull request.