mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-14 22:56:19 +01:00
REST API: Allow multiple widgets to be deleted in a single batch request.
This resets the `WP_Widget::$updated` flag when deleting a widget, to avoid blocking all future updates in a request. Props noisysocks, andraganescu. Merges [51277] to the 5.8 branch. Fixes #53557. Built from https://develop.svn.wordpress.org/branches/5.8@51290 git-svn-id: http://core.svn.wordpress.org/branches/5.8@50899 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
e59db27f8c
commit
337cfb97c1
@ -289,13 +289,14 @@ class WP_REST_Widgets_Controller extends WP_REST_Controller {
|
||||
*
|
||||
* @since 5.8.0
|
||||
*
|
||||
* @global array $wp_registered_widget_updates The registered widget update functions.
|
||||
* @global array $wp_registered_widget_updates The registered widget update functions.
|
||||
* @global WP_Widget_Factory $wp_widget_factory
|
||||
*
|
||||
* @param WP_REST_Request $request Full details about the request.
|
||||
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
|
||||
*/
|
||||
public function delete_item( $request ) {
|
||||
global $wp_registered_widget_updates;
|
||||
global $wp_registered_widget_updates, $wp_widget_factory;
|
||||
|
||||
retrieve_widgets();
|
||||
|
||||
@ -344,6 +345,17 @@ class WP_REST_Widgets_Controller extends WP_REST_Controller {
|
||||
$_POST = $original_post;
|
||||
$_REQUEST = $original_request;
|
||||
|
||||
$widget_object = $wp_widget_factory->get_widget_object( $id_base );
|
||||
|
||||
if ( $widget_object ) {
|
||||
/*
|
||||
* WP_Widget sets `updated = true` after an update to prevent more than one widget
|
||||
* from being saved per request. This isn't what we want in the REST API, though,
|
||||
* as we support batch requests.
|
||||
*/
|
||||
$widget_object->updated = false;
|
||||
}
|
||||
|
||||
wp_assign_widget_to_sidebar( $widget_id, '' );
|
||||
|
||||
$response->set_data(
|
||||
@ -520,9 +532,11 @@ class WP_REST_Widgets_Controller extends WP_REST_Controller {
|
||||
$widget_object->_set( $number );
|
||||
$widget_object->_register_one( $number );
|
||||
|
||||
// WP_Widget sets updated = true after an update to prevent more
|
||||
// than one widget from being saved per request. This isn't what we
|
||||
// want in the REST API, though, as we support batch requests.
|
||||
/*
|
||||
* WP_Widget sets `updated = true` after an update to prevent more than one widget
|
||||
* from being saved per request. This isn't what we want in the REST API, though,
|
||||
* as we support batch requests.
|
||||
*/
|
||||
$widget_object->updated = false;
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.8-RC1-51275';
|
||||
$wp_version = '5.8-RC1-51290';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user