Make WordPress Core


Ignore:
Timestamp:
08/31/2021 07:57:20 PM (3 years ago)
Author:
hellofromTonya
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/widgets.php

    r51568 r51705  
    844844     * Tests for when 'sidebars_widgets' theme mod is populated.
    845845     *
    846      * @covers ::retrieve_widgets
    847      */
    848     function test_retrieve_widgets_with_theme_mod() {
     846     * @covers ::sync_registered_widgets
     847     */
     848    function test_sync_registered_widgets_with_theme_mod() {
    849849        global $sidebars_widgets, $_wp_sidebars_widgets;
    850850
     
    874874        );
    875875
    876         $result = retrieve_widgets( true );
     876        $result = sync_registered_widgets( true );
    877877
    878878        $this->assertIsArray( $result );
     
    907907     * Tests for when sidebars widgets matches registered sidebars.
    908908     *
    909      * @covers ::retrieve_widgets
    910      */
    911     function test_retrieve_widgets_with_sidebars_widgets_matching_registered_sidebars() {
     909     * @covers ::sync_registered_widgets
     910     */
     911    function test_sync_registered_widgets_with_sidebars_widgets_matching_registered_sidebars() {
    912912        global $sidebars_widgets;
    913913
     
    922922        );
    923923
    924         $result = retrieve_widgets( true );
     924        $result = sync_registered_widgets( true );
    925925
    926926        // $sidebars_widgets matches registered sidebars.
     
    945945     * Tests for when sidebars widgets doesn't match registered sidebars.
    946946     *
    947      * @covers ::retrieve_widgets
    948      */
    949     function test_retrieve_widgets_with_sidebars_widgets_not_matching_registered_sidebars() {
     947     * @covers ::sync_registered_widgets
     948     */
     949    function test_sync_registered_widgets_with_sidebars_widgets_not_matching_registered_sidebars() {
    950950        global $sidebars_widgets, $_wp_sidebars_widgets;
    951951
     
    961961
    962962        // Theme changed.
    963         $result = retrieve_widgets( true );
     963        $result = sync_registered_widgets( true );
    964964
    965965        $_wp_sidebars_widgets = array();
     
    10031003
    10041004        // Theme did not change.
    1005         $result = retrieve_widgets();
     1005        $result = sync_registered_widgets();
    10061006
    10071007        $_wp_sidebars_widgets = array();
     
    10371037     * Tests for Customizer mode.
    10381038     *
    1039      * @covers ::retrieve_widgets
    1040      */
    1041     function test_retrieve_widgets_for_customizer() {
     1039     * @covers ::sync_registered_widgets
     1040     */
     1041    function test_sync_registered_widgets_for_customizer() {
    10421042        global $sidebars_widgets, $_wp_sidebars_widgets;
    10431043
     
    10541054        set_theme_mod( 'sidebars_widgets', $old_sidebars_widgets );
    10551055
    1056         $result = retrieve_widgets( 'customize' );
     1056        $result = sync_registered_widgets( 'customize' );
    10571057
    10581058        $_wp_sidebars_widgets = array();
     
    10831083    }
    10841084
    1085     function test_retrieve_widgets_with_single_widget() {
     1085    function test_sync_registered_widgets_with_single_widget() {
    10861086        global $sidebars_widgets;
    10871087
     
    11001100
    11011101        // Theme changed.
    1102         $result = retrieve_widgets( true );
     1102        $result = sync_registered_widgets( true );
    11031103
    11041104        $this->assertContains( 'single', $result['wp_inactive_widgets'] );
     
    11081108     * Tests for orphaned widgets being moved into inactive widgets.
    11091109     *
    1110      * @covers ::retrieve_widgets
    1111      */
    1112     function test_retrieve_widgets_move_orphaned_widgets_to_inactive() {
     1110     * @covers ::sync_registered_widgets
     1111     */
     1112    function test_sync_registered_widgets_move_orphaned_widgets_to_inactive() {
    11131113        global $sidebars_widgets;
    11141114
     
    11231123        );
    11241124
    1125         retrieve_widgets();
     1125        sync_registered_widgets();
    11261126
    11271127        $this->assertIsArray( $sidebars_widgets );
Note: See TracChangeset for help on using the changeset viewer.