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

git-svn-id: https://develop.svn.wordpress.org/trunk@51432 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonathan Desrosiers 2021-07-14 16:44:59 +00:00
parent 9f760e96b4
commit 906c450e94

View File

@ -236,6 +236,18 @@ class WP_REST_Widgets_Controller extends WP_REST_Controller {
public function update_item( $request ) {
global $wp_widget_factory;
/*
* retrieve_widgets() contains logic to move "hidden" or "lost" widgets to the
* wp_inactive_widgets sidebar based on the contents of the $sidebars_widgets global.
*
* When batch requests are processed, this global is not properly updated by previous
* calls, resulting in widgets incorrectly being moved to the wp_inactive_widgets
* sidebar.
*
* See https://core.trac.wordpress.org/ticket/53657.
*/
wp_get_sidebars_widgets();
retrieve_widgets();
$widget_id = $request['id'];
@ -300,6 +312,18 @@ class WP_REST_Widgets_Controller extends WP_REST_Controller {
public function delete_item( $request ) {
global $wp_widget_factory, $wp_registered_widget_updates;
/*
* retrieve_widgets() contains logic to move "hidden" or "lost" widgets to the
* wp_inactive_widgets sidebar based on the contents of the $sidebars_widgets global.
*
* When batch requests are processed, this global is not properly updated by previous
* calls, resulting in widgets incorrectly being moved to the wp_inactive_widgets
* sidebar.
*
* See https://core.trac.wordpress.org/ticket/53657.
*/
wp_get_sidebars_widgets();
retrieve_widgets();
$widget_id = $request['id'];