Make WordPress Core

Changeset 51439


Ignore:
Timestamp:
07/15/2021 03:41:49 PM (3 years ago)
Author:
desrosj
Message:

Widgets: Prevent widgets unintentionally being moved to the inactive sidebar.

This fixes a bug where widgets are unintentionally moved to the wp_inactive_widgets sidebar when batch updates occur through the REST API.

When batch requests are processed, only $_wp_sidebars_widgets is updated by previous calls to WP_REST_Widgets_Controller::create_item(). $sidebars_widgets is not aware of the new widget’s intended location, and retrieve_widgets() mistakenly flags the widget as inactive.

Calling wp_get_sidebars_widgets() before retrieve_widgets() ensures both global variables match and is intended as a temporary fix until the root cause of the problem can be fixed.

Props zieladam, htmgarcia, timothyblynjacobs.
Merges [51432] to the 5.8 branch.
Fixes #53657.

Location:
branches/5.8
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.8

  • branches/5.8/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php

    r51350 r51439  
    237237        global $wp_widget_factory;
    238238
     239        /*
     240         * retrieve_widgets() contains logic to move "hidden" or "lost" widgets to the
     241         * wp_inactive_widgets sidebar based on the contents of the $sidebars_widgets global.
     242         *
     243         * When batch requests are processed, this global is not properly updated by previous
     244         * calls, resulting in widgets incorrectly being moved to the wp_inactive_widgets
     245         * sidebar.
     246         *
     247         * See https://core.trac.wordpress.org/ticket/53657.
     248         */
     249        wp_get_sidebars_widgets();
     250
    239251        retrieve_widgets();
    240252
     
    300312    public function delete_item( $request ) {
    301313        global $wp_widget_factory, $wp_registered_widget_updates;
     314
     315        /*
     316         * retrieve_widgets() contains logic to move "hidden" or "lost" widgets to the
     317         * wp_inactive_widgets sidebar based on the contents of the $sidebars_widgets global.
     318         *
     319         * When batch requests are processed, this global is not properly updated by previous
     320         * calls, resulting in widgets incorrectly being moved to the wp_inactive_widgets
     321         * sidebar.
     322         *
     323         * See https://core.trac.wordpress.org/ticket/53657.
     324         */
     325        wp_get_sidebars_widgets();
    302326
    303327        retrieve_widgets();
Note: See TracChangeset for help on using the changeset viewer.