mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
REST API: Ensure a sidebar's widgets property is a list.
When a widget is removed from a sidebar, if it was removed from the middle of the list, the widgets property would become an object with numeric keys. The sidebars controller now forces the widgets property to be a list. Props walbo. Fixes #53612. git-svn-id: https://develop.svn.wordpress.org/trunk@51377 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
8c413885bd
commit
c283bf2bb6
@ -304,7 +304,7 @@ class WP_REST_Sidebars_Controller extends WP_REST_Controller {
|
||||
}
|
||||
);
|
||||
|
||||
$sidebar['widgets'] = $widgets;
|
||||
$sidebar['widgets'] = array_values( $widgets );
|
||||
}
|
||||
|
||||
$schema = $this->get_item_schema();
|
||||
|
||||
@ -75,7 +75,7 @@ class WP_Test_REST_Sidebars_Controller extends WP_Test_REST_Controller_Testcase
|
||||
}
|
||||
|
||||
private function setup_widget( $option_name, $number, $settings ) {
|
||||
update_option(
|
||||
$this->setup_widgets(
|
||||
$option_name,
|
||||
array(
|
||||
$number => $settings,
|
||||
@ -83,6 +83,10 @@ class WP_Test_REST_Sidebars_Controller extends WP_Test_REST_Controller_Testcase
|
||||
);
|
||||
}
|
||||
|
||||
private function setup_widgets( $option_name, $settings ) {
|
||||
update_option( $option_name, $settings );
|
||||
}
|
||||
|
||||
private function setup_sidebar( $id, $attrs = array(), $widgets = array() ) {
|
||||
global $wp_registered_sidebars;
|
||||
update_option(
|
||||
@ -490,6 +494,54 @@ class WP_Test_REST_Sidebars_Controller extends WP_Test_REST_Controller_Testcase
|
||||
$this->assertNotContains( 'text-1', rest_do_request( '/wp/v2/sidebars/sidebar-1' )->get_data()['widgets'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 53612
|
||||
*/
|
||||
public function test_batch_remove_widgets_from_existing_sidebar() {
|
||||
wp_widgets_init();
|
||||
|
||||
$this->setup_widgets(
|
||||
'widget_text',
|
||||
array(
|
||||
2 => array( 'text' => 'Text widget' ),
|
||||
3 => array( 'text' => 'Text widget' ),
|
||||
4 => array( 'text' => 'Text widget' ),
|
||||
5 => array( 'text' => 'Text widget' ),
|
||||
6 => array( 'text' => 'Text widget' ),
|
||||
)
|
||||
);
|
||||
|
||||
$this->setup_sidebar(
|
||||
'sidebar-1',
|
||||
array(
|
||||
'name' => 'Test sidebar',
|
||||
),
|
||||
array( 'text-2', 'text-3', 'text-4', 'text-5', 'text-6' )
|
||||
);
|
||||
|
||||
$request = new WP_REST_Request( 'POST', '/batch/v1' );
|
||||
$request->set_body_params(
|
||||
array(
|
||||
'requests' => array(
|
||||
array(
|
||||
'method' => 'DELETE',
|
||||
'path' => '/wp/v2/widgets/text-2?force=1',
|
||||
),
|
||||
array(
|
||||
'method' => 'DELETE',
|
||||
'path' => '/wp/v2/widgets/text-3?force=1',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
rest_get_server()->dispatch( $request );
|
||||
|
||||
$this->assertSame(
|
||||
array( 'text-4', 'text-5', 'text-6' ),
|
||||
rest_do_request( '/wp/v2/sidebars/sidebar-1' )->get_data()['widgets']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 41683
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user