Customize: Handle filtering `sidebars_widgets` when the underlying option is non-existent.

Fixes warning related to a non-array argument for `array_merge()` in `WP_Customize_Widgets::customize_register()`. 

See [37166].
See #36389.
Fixes #36660.


git-svn-id: https://develop.svn.wordpress.org/trunk@37352 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Weston Ruter 2016-05-02 23:41:18 +00:00
parent a76767e2ed
commit 0321612c4d
2 changed files with 16 additions and 1 deletions

View File

@ -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;

View File

@ -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().
*