Make WordPress Core

08/31/2021 07:57:20 PM (2 years ago)

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.

1 edited


  • trunk/src/wp-includes/class-wp-customize-widgets.php

    r51700 r51705  
    276276        $this->manager->set_post_value( 'old_sidebars_widgets_data', $this->old_sidebars_widgets ); // Override any value cached in changeset.
    278         // retrieve_widgets() looks at the global $sidebars_widgets.
     278        // sync_registered_widgets() looks at the global $sidebars_widgets.
    279279        $sidebars_widgets = $this->old_sidebars_widgets;
    280         $sidebars_widgets = retrieve_widgets( 'customize' );
     280        $sidebars_widgets = sync_registered_widgets( 'customize' );
    281281        add_filter( 'option_sidebars_widgets', array( $this, 'filter_option_sidebars_widgets_for_theme_switch' ), 1 );
    282282        // Reset global cache var used by wp_get_sidebars_widgets().
    288288     *
    289289     * When switching themes, filter the Customizer setting old_sidebars_widgets_data
    290      * to supply initial $sidebars_widgets before they were overridden by retrieve_widgets().
     290     * to supply initial $sidebars_widgets before they were overridden by sync_registered_widgets().
    291291     * The value for old_sidebars_widgets_data gets set in the old theme's sidebars_widgets
    292292     * theme_mod.
    306306     * Filters sidebars_widgets option for theme switch.
    307307     *
    308      * When switching themes, the retrieve_widgets() function is run when the Customizer initializes,
     308     * When switching themes, the sync_registered_widgets() function is run when the Customizer initializes,
    309309     * and then the new sidebars_widgets here get supplied as the default value for the sidebars_widgets
    310310     * option.
Note: See TracChangeset for help on using the changeset viewer.