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.


git-svn-id: https://develop.svn.wordpress.org/trunk@51235 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Timothy Jacobs
2021-06-25 13:17:20 +00:00
parent 67fc415084
commit 1de9c692f3
3 changed files with 82 additions and 2 deletions
@@ -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 ) {