mirror of
git://develop.git.wordpress.org/
synced 2025-03-24 22:10:02 +01:00
Widgets: Revert [51705].
While the new name is much better, it doesn't fully tell what will happen when invoked nor does it fully solve the root problems. Why? The function is doing too much. And naming is hard. Props azaozz, desrosj, andraganescu, zieladam, hellofromTonya. See #53811. git-svn-id: https://develop.svn.wordpress.org/trunk@51791 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
50d7248e1e
commit
1d0e4441c1
@ -1773,7 +1773,7 @@ function upgrade_330() {
|
||||
|
||||
// Intentional fall-through to upgrade to the next version.
|
||||
case 2:
|
||||
$sidebars_widgets = sync_registered_widgets();
|
||||
$sidebars_widgets = retrieve_widgets();
|
||||
$sidebars_widgets['array_version'] = 3;
|
||||
update_option( 'sidebars_widgets', $sidebars_widgets );
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ register_sidebar(
|
||||
)
|
||||
);
|
||||
|
||||
sync_registered_widgets();
|
||||
retrieve_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.
|
||||
|
||||
// sync_registered_widgets() looks at the global $sidebars_widgets.
|
||||
// retrieve_widgets() looks at the global $sidebars_widgets.
|
||||
$sidebars_widgets = $this->old_sidebars_widgets;
|
||||
$sidebars_widgets = sync_registered_widgets( 'customize' );
|
||||
$sidebars_widgets = retrieve_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 sync_registered_widgets().
|
||||
* to supply initial $sidebars_widgets before they were overridden by retrieve_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 sync_registered_widgets() function is run when the Customizer initializes,
|
||||
* When switching themes, the retrieve_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 ) {
|
||||
sync_registered_widgets();
|
||||
retrieve_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 ) {
|
||||
sync_registered_widgets();
|
||||
retrieve_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 ) {
|
||||
sync_registered_widgets();
|
||||
retrieve_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 ) {
|
||||
sync_registered_widgets();
|
||||
retrieve_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;
|
||||
|
||||
/*
|
||||
* sync_registered_widgets() contains logic to move "hidden" or "lost" widgets to the
|
||||
* retrieve_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();
|
||||
|
||||
sync_registered_widgets();
|
||||
retrieve_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;
|
||||
|
||||
/*
|
||||
* sync_registered_widgets() contains logic to move "hidden" or "lost" widgets to the
|
||||
* retrieve_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();
|
||||
|
||||
sync_registered_widgets();
|
||||
retrieve_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 sync_registered_widgets() is called when initializing a theme in the Customizer,
|
||||
* Since retrieve_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.
|
||||
*/
|
||||
|
@ -1251,30 +1251,13 @@ function _wp_sidebars_changed() {
|
||||
$sidebars_widgets = wp_get_sidebars_widgets();
|
||||
}
|
||||
|
||||
sync_registered_widgets( true );
|
||||
retrieve_widgets( true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not use, deprecated.
|
||||
*
|
||||
* Use sync_registered_widgets() instead.
|
||||
* Look for "lost" widgets, this has to run at least on each theme change.
|
||||
*
|
||||
* @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
|
||||
@ -1284,7 +1267,7 @@ function retrieve_widgets( $theme_changed = false ) {
|
||||
* of 'customize' defers updates for the Customizer.
|
||||
* @return array Updated sidebars widgets.
|
||||
*/
|
||||
function sync_registered_widgets( $theme_changed = false ) {
|
||||
function retrieve_widgets( $theme_changed = false ) {
|
||||
global $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets;
|
||||
|
||||
$registered_sidebars_keys = array_keys( $wp_registered_sidebars );
|
||||
|
@ -843,9 +843,9 @@ class Tests_Widgets extends WP_UnitTestCase {
|
||||
/**
|
||||
* Tests for when 'sidebars_widgets' theme mod is populated.
|
||||
*
|
||||
* @covers ::sync_registered_widgets
|
||||
* @covers ::retrieve_widgets
|
||||
*/
|
||||
function test_sync_registered_widgets_with_theme_mod() {
|
||||
function test_retrieve_widgets_with_theme_mod() {
|
||||
global $sidebars_widgets, $_wp_sidebars_widgets;
|
||||
|
||||
wp_widgets_init();
|
||||
@ -873,7 +873,7 @@ class Tests_Widgets extends WP_UnitTestCase {
|
||||
'wp_inactive_widgets' => array(),
|
||||
);
|
||||
|
||||
$result = sync_registered_widgets( true );
|
||||
$result = retrieve_widgets( true );
|
||||
|
||||
$this->assertIsArray( $result );
|
||||
$this->assertSame( $result, $sidebars_widgets );
|
||||
@ -906,9 +906,9 @@ class Tests_Widgets extends WP_UnitTestCase {
|
||||
/**
|
||||
* Tests for when sidebars widgets matches registered sidebars.
|
||||
*
|
||||
* @covers ::sync_registered_widgets
|
||||
* @covers ::retrieve_widgets
|
||||
*/
|
||||
function test_sync_registered_widgets_with_sidebars_widgets_matching_registered_sidebars() {
|
||||
function test_retrieve_widgets_with_sidebars_widgets_matching_registered_sidebars() {
|
||||
global $sidebars_widgets;
|
||||
|
||||
wp_widgets_init();
|
||||
@ -921,7 +921,7 @@ class Tests_Widgets extends WP_UnitTestCase {
|
||||
'wp_inactive_widgets' => array(),
|
||||
);
|
||||
|
||||
$result = sync_registered_widgets( true );
|
||||
$result = retrieve_widgets( true );
|
||||
|
||||
// $sidebars_widgets matches registered sidebars.
|
||||
$this->assertIsArray( $result );
|
||||
@ -944,9 +944,9 @@ class Tests_Widgets extends WP_UnitTestCase {
|
||||
/**
|
||||
* Tests for when sidebars widgets doesn't match registered sidebars.
|
||||
*
|
||||
* @covers ::sync_registered_widgets
|
||||
* @covers ::retrieve_widgets
|
||||
*/
|
||||
function test_sync_registered_widgets_with_sidebars_widgets_not_matching_registered_sidebars() {
|
||||
function test_retrieve_widgets_with_sidebars_widgets_not_matching_registered_sidebars() {
|
||||
global $sidebars_widgets, $_wp_sidebars_widgets;
|
||||
|
||||
wp_widgets_init();
|
||||
@ -960,7 +960,7 @@ class Tests_Widgets extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
// Theme changed.
|
||||
$result = sync_registered_widgets( true );
|
||||
$result = retrieve_widgets( true );
|
||||
|
||||
$_wp_sidebars_widgets = array();
|
||||
$this->assertIsArray( $result );
|
||||
@ -1002,7 +1002,7 @@ class Tests_Widgets extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
// Theme did not change.
|
||||
$result = sync_registered_widgets();
|
||||
$result = retrieve_widgets();
|
||||
|
||||
$_wp_sidebars_widgets = array();
|
||||
$this->assertIsArray( $result );
|
||||
@ -1036,9 +1036,9 @@ class Tests_Widgets extends WP_UnitTestCase {
|
||||
/**
|
||||
* Tests for Customizer mode.
|
||||
*
|
||||
* @covers ::sync_registered_widgets
|
||||
* @covers ::retrieve_widgets
|
||||
*/
|
||||
function test_sync_registered_widgets_for_customizer() {
|
||||
function test_retrieve_widgets_for_customizer() {
|
||||
global $sidebars_widgets, $_wp_sidebars_widgets;
|
||||
|
||||
wp_widgets_init();
|
||||
@ -1053,7 +1053,7 @@ class Tests_Widgets extends WP_UnitTestCase {
|
||||
);
|
||||
set_theme_mod( 'sidebars_widgets', $old_sidebars_widgets );
|
||||
|
||||
$result = sync_registered_widgets( 'customize' );
|
||||
$result = retrieve_widgets( 'customize' );
|
||||
|
||||
$_wp_sidebars_widgets = array();
|
||||
$this->assertIsArray( $result );
|
||||
@ -1082,7 +1082,7 @@ class Tests_Widgets extends WP_UnitTestCase {
|
||||
$this->assertNotEquals( $sidebars_widgets, wp_get_sidebars_widgets() );
|
||||
}
|
||||
|
||||
function test_sync_registered_widgets_with_single_widget() {
|
||||
function test_retrieve_widgets_with_single_widget() {
|
||||
global $sidebars_widgets;
|
||||
|
||||
wp_widgets_init();
|
||||
@ -1099,7 +1099,7 @@ class Tests_Widgets extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
// Theme changed.
|
||||
$result = sync_registered_widgets( true );
|
||||
$result = retrieve_widgets( true );
|
||||
|
||||
$this->assertContains( 'single', $result['wp_inactive_widgets'] );
|
||||
}
|
||||
@ -1107,9 +1107,9 @@ class Tests_Widgets extends WP_UnitTestCase {
|
||||
/**
|
||||
* Tests for orphaned widgets being moved into inactive widgets.
|
||||
*
|
||||
* @covers ::sync_registered_widgets
|
||||
* @covers ::retrieve_widgets
|
||||
*/
|
||||
function test_sync_registered_widgets_move_orphaned_widgets_to_inactive() {
|
||||
function test_retrieve_widgets_move_orphaned_widgets_to_inactive() {
|
||||
global $sidebars_widgets;
|
||||
|
||||
wp_widgets_init();
|
||||
@ -1122,7 +1122,7 @@ class Tests_Widgets extends WP_UnitTestCase {
|
||||
'orphaned_widgets_1' => array( 'calendar-1' ),
|
||||
);
|
||||
|
||||
sync_registered_widgets();
|
||||
retrieve_widgets();
|
||||
|
||||
$this->assertIsArray( $sidebars_widgets );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user