Make WordPress Core


Ignore:
Timestamp:
06/30/2021 10:40:21 AM (3 years ago)
Author:
SergeyBiryukov
Message:

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.
Fixes #53557.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php

    r51248 r51277  
    290290     * @since 5.8.0
    291291     *
    292      * @global array $wp_registered_widget_updates The registered widget update functions.
     292     * @global array             $wp_registered_widget_updates The registered widget update functions.
     293     * @global WP_Widget_Factory $wp_widget_factory
    293294     *
    294295     * @param WP_REST_Request $request Full details about the request.
     
    296297     */
    297298    public function delete_item( $request ) {
    298         global $wp_registered_widget_updates;
     299        global $wp_registered_widget_updates, $wp_widget_factory;
    299300
    300301        retrieve_widgets();
     
    344345            $_POST    = $original_post;
    345346            $_REQUEST = $original_request;
     347
     348            $widget_object = $wp_widget_factory->get_widget_object( $id_base );
     349
     350            if ( $widget_object ) {
     351                /*
     352                 * WP_Widget sets `updated = true` after an update to prevent more than one widget
     353                 * from being saved per request. This isn't what we want in the REST API, though,
     354                 * as we support batch requests.
     355                 */
     356                $widget_object->updated = false;
     357            }
    346358
    347359            wp_assign_widget_to_sidebar( $widget_id, '' );
     
    521533            $widget_object->_register_one( $number );
    522534
    523             // WP_Widget sets updated = true after an update to prevent more
    524             // than one widget from being saved per request. This isn't what we
    525             // want in the REST API, though, as we support batch requests.
     535            /*
     536             * WP_Widget sets `updated = true` after an update to prevent more than one widget
     537             * from being saved per request. This isn't what we want in the REST API, though,
     538             * as we support batch requests.
     539             */
    526540            $widget_object->updated = false;
    527541        }
Note: See TracChangeset for help on using the changeset viewer.