From 21bfa322fff5eb51ab92c71661da05c735f8c459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Wed, 14 Jul 2021 16:21:14 +0200 Subject: [PATCH 1/2] Refresh $sidebars_widgets before calling retrieve_widgets in WP_REST_Widgets_Controller a safe, RC-friendly way. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is required, because retrieve_widgets() runs some logic to move "hidden/lost" widgets to wp_inactive_widgets sidebar. It does so based on the global $sidebars_widgets. Normally this is not a problem, but when processing batch requests, $sidebars_widgets isn't properly updated by WP_REST_Widgets_Controller::create_item() – only global $_wp_sidebars_widgets has been changed. So, as far as retrieve_widgets() is concerned, the last created widget isn't assigned to any sidebar and so it is moved to the wp_inactive_widgets sidebar. --- .../endpoints/class-wp-rest-widgets-controller.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php index dced990fcdd0f..88b0ab5a131e2 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php @@ -142,7 +142,7 @@ public function get_item_permissions_check( $request ) { return $this->permissions_check( $request ); } - /** + /**n create_item * Gets an individual widget. * * @since 5.8.0 @@ -236,6 +236,10 @@ public function update_item_permissions_check( $request ) { public function update_item( $request ) { global $wp_widget_factory; + // Calling wp_get_sidebars_widgets() here is a safe fix for https://github.com/WordPress/gutenberg/issues/33335 + // @TODO: Remove this after WP 5.8 RC1 in favor of updating retrieve_widgets and wp_set_sidebars_widgets + wp_get_sidebars_widgets(); + retrieve_widgets(); $widget_id = $request['id']; @@ -300,6 +304,10 @@ public function delete_item_permissions_check( $request ) { public function delete_item( $request ) { global $wp_widget_factory, $wp_registered_widget_updates; + // Calling wp_get_sidebars_widgets() here is a safe fix for https://github.com/WordPress/gutenberg/issues/33335 + // @TODO: Remove this after WP 5.8 RC1 in favor of updating retrieve_widgets and wp_set_sidebars_widgets + wp_get_sidebars_widgets(); + retrieve_widgets(); $widget_id = $request['id']; From b109b36c46e8bd6315e20b2ccb87d799fe7d1163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Wed, 14 Jul 2021 16:28:17 +0200 Subject: [PATCH 2/2] Remove dev artifact --- .../rest-api/endpoints/class-wp-rest-widgets-controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php index 88b0ab5a131e2..44b3db0dac6ce 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php @@ -142,7 +142,7 @@ public function get_item_permissions_check( $request ) { return $this->permissions_check( $request ); } - /**n create_item + /** * Gets an individual widget. * * @since 5.8.0