From a95b39b53bc7050ca54d2ebe329a06d0d3f9f139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petter=20Walb=C3=B8=20Johnsg=C3=A5rd?= Date: Fri, 25 Jun 2021 20:45:20 +0200 Subject: [PATCH] Widgets: Retrieve latest widgets before loading sidebars This fixes issues where sidebars would be unexpectedly missing from the new widgets screen. Running retrieve_widgets syncs sidebars that were registered after the last theme switch. --- lib/class-wp-rest-sidebars-controller.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/class-wp-rest-sidebars-controller.php b/lib/class-wp-rest-sidebars-controller.php index 5023fb9156d83..4a2c290310df3 100644 --- a/lib/class-wp-rest-sidebars-controller.php +++ b/lib/class-wp-rest-sidebars-controller.php @@ -116,8 +116,10 @@ public function get_items_permissions_check( $request ) { // phpcs:ignore Variab * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */ public function get_items( $request ) { + retrieve_widgets(); + $data = array(); - foreach ( (array) wp_get_sidebars_widgets() as $id => $widgets ) { + foreach ( wp_get_sidebars_widgets() as $id => $widgets ) { $sidebar = $this->get_sidebar( $id ); if ( ! $sidebar ) { @@ -153,6 +155,8 @@ public function get_item_permissions_check( $request ) { // phpcs:ignore Variabl * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */ public function get_item( $request ) { + retrieve_widgets(); + $sidebar = $this->get_sidebar( $request['id'] ); if ( ! $sidebar ) {