Refresh $sidebars_widgets before calling retrieve_widgets in WP_REST_Widgets_Controller a safe, RC-friendly way #1498
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Solves WordPress/gutenberg#33335, https://core.trac.wordpress.org/ticket/53657
Calling
wp_get_sidebars_widgets()
is required, becauseretrieve_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 a previous call toWP_REST_Widgets_Controller::create_item()
– onlyglobal $_wp_sidebars_widgets
has been changed. So, as far asretrieve_widgets()
is concerned, the last created widget isn't assigned to any sidebar and so it is mistakenly moved to thewp_inactive_widgets
sidebar.This fix is a temporary one so that we may ship WordPress 5.8 without that bug. I will also propose another PR to address the fundamental root cause of the problem here. For more context, see WordPress/gutenberg#33335
Test plan
/wp-admin/widgets.php
without this PR appliedBroken state generated on attempt 1
Valid state generated on attempt 1
and doesn't report problems regardless of how long you keep waiting