mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 15:50:09 +00:00
Widgets: Merge orphaned widgets on theme switch
Merges orphaned widgets into the inactive sidebar when switching themes. Props bpayton. See #39693. git-svn-id: https://develop.svn.wordpress.org/trunk@41594 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -961,6 +961,41 @@ class Tests_Widgets extends WP_UnitTestCase {
|
||||
$this->assertContains( 'single', $result['wp_inactive_widgets'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for orphaned widgets being moved into inactive widgets.
|
||||
*
|
||||
* @covers retrieve_widgets()
|
||||
*/
|
||||
function test_retrieve_widgets_move_orphaned_widgets_to_inactive() {
|
||||
global $sidebars_widgets;
|
||||
|
||||
wp_widgets_init();
|
||||
$this->register_sidebars( array( 'sidebar-1', 'sidebar-2', 'sidebar-3', 'wp_inactive_widgets' ) );
|
||||
|
||||
$sidebars_widgets = array(
|
||||
'sidebar-1' => array( 'tag_cloud-1' ),
|
||||
'sidebar-2' => array( 'text-1' ),
|
||||
'wp_inactive_widgets' => array( 'search-2', 'archives-2' ),
|
||||
'orphaned_widgets_1' => array( 'calendar-1' ),
|
||||
);
|
||||
|
||||
retrieve_widgets();
|
||||
|
||||
$this->assertInternalType( 'array', $sidebars_widgets );
|
||||
|
||||
foreach ( $sidebars_widgets as $widgets ) {
|
||||
$this->assertInternalType( 'array', $widgets );
|
||||
}
|
||||
|
||||
// 6 default widgets + 1 orphaned calendar widget = 7.
|
||||
$this->assertCount( 7, $sidebars_widgets['wp_inactive_widgets'] );
|
||||
$this->assertContains( 'calendar-1', $sidebars_widgets['wp_inactive_widgets'] );
|
||||
$this->assertArrayNotHasKey( 'orphaned_widgets_1', $sidebars_widgets );
|
||||
|
||||
// Sidebar_widgets option was updated.
|
||||
$this->assertEquals( $sidebars_widgets, wp_get_sidebars_widgets() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test _wp_remove_unregistered_widgets.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user