mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-03 15:08:10 +01:00
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. Built from https://develop.svn.wordpress.org/trunk@51705 git-svn-id: http://core.svn.wordpress.org/trunk@51311 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
f405add8f0
commit
71977c215d
@ -1773,7 +1773,7 @@ function upgrade_330() {
|
||||
|
||||
// Intentional fall-through to upgrade to the next version.
|
||||
case 2:
|
||||
$sidebars_widgets = retrieve_widgets();
|
||||
$sidebars_widgets = sync_registered_widgets();
|
||||
$sidebars_widgets['array_version'] = 3;
|
||||
update_option( 'sidebars_widgets', $sidebars_widgets );
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ register_sidebar(
|
||||
)
|
||||
);
|
||||
|
||||
retrieve_widgets();
|
||||
sync_registered_widgets();
|
||||
|
||||
// We're saving a widget without JS.
|
||||
if ( isset( $_POST['savewidget'] ) || isset( $_POST['removewidget'] ) ) {
|
||||
|
@ -275,9 +275,9 @@ final class WP_Customize_Widgets {
|
||||
add_filter( 'customize_value_old_sidebars_widgets_data', array( $this, 'filter_customize_value_old_sidebars_widgets_data' ) );
|
||||
$this->manager->set_post_value( 'old_sidebars_widgets_data', $this->old_sidebars_widgets ); // Override any value cached in changeset.
|
||||
|
||||
// retrieve_widgets() looks at the global $sidebars_widgets.
|
||||
// sync_registered_widgets() looks at the global $sidebars_widgets.
|
||||
$sidebars_widgets = $this->old_sidebars_widgets;
|
||||
$sidebars_widgets = retrieve_widgets( 'customize' );
|
||||
$sidebars_widgets = sync_registered_widgets( 'customize' );
|
||||
add_filter( 'option_sidebars_widgets', array( $this, 'filter_option_sidebars_widgets_for_theme_switch' ), 1 );
|
||||
// Reset global cache var used by wp_get_sidebars_widgets().
|
||||
unset( $GLOBALS['_wp_sidebars_widgets'] );
|
||||
@ -287,7 +287,7 @@ final class WP_Customize_Widgets {
|
||||
* Filters old_sidebars_widgets_data Customizer setting.
|
||||
*
|
||||
* When switching themes, filter the Customizer setting old_sidebars_widgets_data
|
||||
* to supply initial $sidebars_widgets before they were overridden by retrieve_widgets().
|
||||
* to supply initial $sidebars_widgets before they were overridden by sync_registered_widgets().
|
||||
* The value for old_sidebars_widgets_data gets set in the old theme's sidebars_widgets
|
||||
* theme_mod.
|
||||
*
|
||||
@ -305,7 +305,7 @@ final class WP_Customize_Widgets {
|
||||
/**
|
||||
* Filters sidebars_widgets option for theme switch.
|
||||
*
|
||||
* When switching themes, the retrieve_widgets() function is run when the Customizer initializes,
|
||||
* When switching themes, the sync_registered_widgets() function is run when the Customizer initializes,
|
||||
* and then the new sidebars_widgets here get supplied as the default value for the sidebars_widgets
|
||||
* option.
|
||||
*
|
||||
|
@ -98,7 +98,7 @@ 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();
|
||||
sync_registered_widgets();
|
||||
|
||||
$data = array();
|
||||
foreach ( wp_get_sidebars_widgets() as $id => $widgets ) {
|
||||
@ -137,7 +137,7 @@ 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();
|
||||
sync_registered_widgets();
|
||||
|
||||
$sidebar = $this->get_sidebar( $request['id'] );
|
||||
|
||||
|
@ -109,7 +109,7 @@ class WP_REST_Widgets_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();
|
||||
sync_registered_widgets();
|
||||
|
||||
$prepared = array();
|
||||
|
||||
@ -151,7 +151,7 @@ class WP_REST_Widgets_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();
|
||||
sync_registered_widgets();
|
||||
|
||||
$widget_id = $request['id'];
|
||||
$sidebar_id = wp_find_widgets_sidebar( $widget_id );
|
||||
@ -237,7 +237,7 @@ class WP_REST_Widgets_Controller extends WP_REST_Controller {
|
||||
global $wp_widget_factory;
|
||||
|
||||
/*
|
||||
* retrieve_widgets() contains logic to move "hidden" or "lost" widgets to the
|
||||
* sync_registered_widgets() contains logic to move "hidden" or "lost" widgets to the
|
||||
* wp_inactive_widgets sidebar based on the contents of the $sidebars_widgets global.
|
||||
*
|
||||
* When batch requests are processed, this global is not properly updated by previous
|
||||
@ -248,7 +248,7 @@ class WP_REST_Widgets_Controller extends WP_REST_Controller {
|
||||
*/
|
||||
wp_get_sidebars_widgets();
|
||||
|
||||
retrieve_widgets();
|
||||
sync_registered_widgets();
|
||||
|
||||
$widget_id = $request['id'];
|
||||
$sidebar_id = wp_find_widgets_sidebar( $widget_id );
|
||||
@ -313,7 +313,7 @@ class WP_REST_Widgets_Controller extends WP_REST_Controller {
|
||||
global $wp_widget_factory, $wp_registered_widget_updates;
|
||||
|
||||
/*
|
||||
* retrieve_widgets() contains logic to move "hidden" or "lost" widgets to the
|
||||
* sync_registered_widgets() contains logic to move "hidden" or "lost" widgets to the
|
||||
* wp_inactive_widgets sidebar based on the contents of the $sidebars_widgets global.
|
||||
*
|
||||
* When batch requests are processed, this global is not properly updated by previous
|
||||
@ -324,7 +324,7 @@ class WP_REST_Widgets_Controller extends WP_REST_Controller {
|
||||
*/
|
||||
wp_get_sidebars_widgets();
|
||||
|
||||
retrieve_widgets();
|
||||
sync_registered_widgets();
|
||||
|
||||
$widget_id = $request['id'];
|
||||
$sidebar_id = wp_find_widgets_sidebar( $widget_id );
|
||||
|
@ -805,7 +805,7 @@ function switch_theme( $stylesheet ) {
|
||||
add_option( "theme_mods_$stylesheet", $default_theme_mods );
|
||||
} else {
|
||||
/*
|
||||
* Since retrieve_widgets() is called when initializing a theme in the Customizer,
|
||||
* Since sync_registered_widgets() is called when initializing a theme in the Customizer,
|
||||
* we need to remove the theme mods to avoid overwriting changes made via
|
||||
* the Customizer when accessing wp-admin/widgets.php.
|
||||
*/
|
||||
|
@ -13,7 +13,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.9-alpha-51704';
|
||||
$wp_version = '5.9-alpha-51705';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
@ -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 );
|
||||
|
Loading…
Reference in New Issue
Block a user