Widgets: Rename and soft deprecate retrieve_widgets().

The original name `retrieve_widgets()` was unclear as it suggested it was a getter, i.e. getting the widgets. This function does more than get: finds orphaned widgets, assigns them to the inactive sidebar, and updates the database.

The new name is `sync_registered_widgets()` which better represents what happens when this function is invoked.

The original `retrieve_widgets()` function is soft deprecated to avoid unnecessary code churn downstream for developers that support more than the latest version of WordPress.

Follow-up to [18630].

Props zieladam, timothyblynjacobs, andraganescu, hellofromTonya.
See #53811.

git-svn-id: https://develop.svn.wordpress.org/trunk@51705 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Tonya Mork
2021-08-31 19:57:20 +00:00
parent 1bbc5a4737
commit b7a495d337
8 changed files with 53 additions and 36 deletions

View File

@@ -1251,13 +1251,30 @@ function _wp_sidebars_changed() {
$sidebars_widgets = wp_get_sidebars_widgets();
}
retrieve_widgets( true );
sync_registered_widgets( true );
}
/**
* Look for "lost" widgets, this has to run at least on each theme change.
* Do not use, deprecated.
*
* Use sync_registered_widgets() instead.
*
* @since 2.8.0
* @deprecated 5.8.1 Use sync_registered_widgets()
* @see sync_registered_widgets()
*
* @param string|bool $theme_changed
* @return array
*/
function retrieve_widgets( $theme_changed = false ) {
return sync_registered_widgets( $theme_changed );
}
/**
* Looks for "lost" widgets and Updates widgets-to-sidebars allocation.
* This has to run at least on each theme change.
*
* @since 5.8.1
*
* @global array $wp_registered_sidebars Registered sidebars.
* @global array $sidebars_widgets
@@ -1267,7 +1284,7 @@ function _wp_sidebars_changed() {
* of 'customize' defers updates for the Customizer.
* @return array Updated sidebars widgets.
*/
function retrieve_widgets( $theme_changed = false ) {
function sync_registered_widgets( $theme_changed = false ) {
global $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets;
$registered_sidebars_keys = array_keys( $wp_registered_sidebars );