From 88309aa27e8eeb89a06142f8986a0ef7360bad2e Mon Sep 17 00:00:00 2001 From: desrosj Date: Wed, 14 Jul 2021 16:45:58 +0000 Subject: [PATCH] Widgets: Prevent widgets unintentionally being moved to the inactive sidebar. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Built from https://develop.svn.wordpress.org/trunk@51432 git-svn-id: http://core.svn.wordpress.org/trunk@51043 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../class-wp-rest-widgets-controller.php | 24 +++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php index dced990fcd..3b425a6b8b 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php @@ -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']; diff --git a/wp-includes/version.php b/wp-includes/version.php index 3a59606970..32bee113b3 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-51431'; +$wp_version = '5.9-alpha-51432'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.