Skip to content

Commit

Permalink
Widgets: Retrieve latest widgets before loading sidebars (#32997)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Petter Walbø Johnsgård committed Jul 13, 2021
1 parent c26c506 commit e2b5503
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/class-wp-rest-sidebars-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 ) {
Expand Down

0 comments on commit e2b5503

Please sign in to comment.