diff --git a/src/wp-includes/class-wp-customize-widgets.php b/src/wp-includes/class-wp-customize-widgets.php index 5b3e702ec6..52d174f362 100644 --- a/src/wp-includes/class-wp-customize-widgets.php +++ b/src/wp-includes/class-wp-customize-widgets.php @@ -1064,7 +1064,7 @@ final class WP_Customize_Widgets { * @return array */ public function preview_sidebars_widgets( $sidebars_widgets ) { - $sidebars_widgets = get_option( 'sidebars_widgets' ); + $sidebars_widgets = get_option( 'sidebars_widgets', array() ); unset( $sidebars_widgets['array_version'] ); return $sidebars_widgets; diff --git a/tests/phpunit/tests/customize/widgets.php b/tests/phpunit/tests/customize/widgets.php index 721f804cf6..c0836d39e5 100644 --- a/tests/phpunit/tests/customize/widgets.php +++ b/tests/phpunit/tests/customize/widgets.php @@ -98,6 +98,21 @@ class Tests_WP_Customize_Widgets extends WP_UnitTestCase { $this->assertEquals( $this->manager, $this->manager->widgets->manager ); } + /** + * Test registering sidebars without an extant sidebars_widgets option. + * + * @see WP_Customize_Widgets::customize_register() + * @see WP_Customize_Widgets::preview_sidebars_widgets() + * @ticket 36660 + */ + function test_customize_register_with_deleted_sidebars() { + $sidebar_id = 'sidebar-1'; + delete_option( 'sidebars_widgets' ); + register_sidebar( array( 'id' => $sidebar_id ) ); + $this->manager->widgets->customize_register(); + $this->assertEquals( array_fill_keys( array( 'wp_inactive_widgets', $sidebar_id ), array() ), wp_get_sidebars_widgets() ); + } + /** * Tests WP_Customize_Widgets::get_selective_refreshable_widgets(). *