From 4666f2fd393a3803fadae4a5aea3cf6e32973d9b Mon Sep 17 00:00:00 2001 From: Konstantin Obenland Date: Mon, 2 Oct 2017 18:10:06 +0000 Subject: [PATCH] Widgets: Revert format of `sidebars_widgets`. Restores the data format of the `sidebars_widgets` theme mod to its pre [41555] format. It can trigger PHP warnings after switching themes if that mod has not been removed previously. Fixes #39693. git-svn-id: https://develop.svn.wordpress.org/trunk@41673 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/theme.php | 2 +- src/wp-includes/widgets.php | 1 + tests/phpunit/tests/widgets.php | 11 +++++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php index 89eab5f790..6909d0fe2e 100644 --- a/src/wp-includes/theme.php +++ b/src/wp-includes/theme.php @@ -690,7 +690,7 @@ function switch_theme( $stylesheet ) { } if ( is_array( $_sidebars_widgets ) ) { - set_theme_mod( 'sidebars_widgets', $_sidebars_widgets ); + set_theme_mod( 'sidebars_widgets', array( 'time' => time(), 'data' => $_sidebars_widgets ) ); } $nav_menu_locations = get_theme_mod( 'nav_menu_locations' ); diff --git a/src/wp-includes/widgets.php b/src/wp-includes/widgets.php index 37e8a01c52..6f5954d322 100644 --- a/src/wp-includes/widgets.php +++ b/src/wp-includes/widgets.php @@ -1286,6 +1286,7 @@ function wp_map_sidebars_widgets( $existing_sidebars_widgets ) { // Sidebars_widgets settings from when this theme was previously active. $old_sidebars_widgets = get_theme_mod( 'sidebars_widgets' ); + $old_sidebars_widgets = $old_sidebars_widgets['data']; if ( is_array( $old_sidebars_widgets ) ) { diff --git a/tests/phpunit/tests/widgets.php b/tests/phpunit/tests/widgets.php index a56caefb95..c37dcc08a0 100644 --- a/tests/phpunit/tests/widgets.php +++ b/tests/phpunit/tests/widgets.php @@ -713,10 +713,13 @@ class Tests_Widgets extends WP_UnitTestCase { // Test restoring sidebars widgets when previously activated. set_theme_mod( 'sidebars_widgets', array( - 'sidebar-1' => array( 'tag_cloud-1' ), - 'sidebar-2' => array(), - 'sidebar-3' => array( 'unregistered_widget-1', 'text-1', 'media_image-1' ), - 'orphaned_widgets_1' => array( 'media_video-2' ), + 'time' => time(), + 'data' => array( + 'sidebar-1' => array( 'tag_cloud-1' ), + 'sidebar-2' => array(), + 'sidebar-3' => array( 'unregistered_widget-1', 'text-1', 'media_image-1' ), + 'orphaned_widgets_1' => array( 'media_video-2' ), + ), ) ); $sidebars_widgets = array(