REST API: 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.

Props walbo, hellofromTonya, noisysocks.
Fixes #53489.

Built from https://develop.svn.wordpress.org/trunk@51235


git-svn-id: http://core.svn.wordpress.org/trunk@50844 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
TimothyBlynJacobs 2021-06-25 13:18:58 +00:00
parent 4b17d6b3e9
commit dc710243a3
2 changed files with 6 additions and 2 deletions

View File

@ -98,8 +98,10 @@ class WP_REST_Sidebars_Controller extends WP_REST_Controller {
* @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 ) {
@ -135,6 +137,8 @@ class WP_REST_Sidebars_Controller extends WP_REST_Controller {
* @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 ) {

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.8-beta3-51234';
$wp_version = '5.8-beta3-51235';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.