Make WordPress Core


Ignore:
Timestamp:
06/08/2021 01:54:27 AM (3 years ago)
Author:
noisysocks
Message:

Make new WordPress installations use blocks in widget areas instead of widgets

Modifies wp_install_defaults() so that when you install a new WordPress site you
have block in your widget areas, not widgets.

Fixes #53324.
Props isabel_brison, hellofromtonya, andraganescu.

File:
1 edited

Legend:

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

    r50961 r51088  
    575575        global $wp_registered_widgets;
    576576
    577         $settings = get_option( 'widget_search' );
     577        $settings = get_option( 'widget_block' );
    578578        unset( $settings['_multiwidget'] );
    579579        $this->assertArrayHasKey( 2, $settings );
     
    584584        // Note: We cannot use array_keys() here because $settings could be an ArrayIterator.
    585585        foreach ( $settings as $widget_number => $instance ) {
    586             $widget_id = "search-$widget_number";
     586            $widget_id = "block-$widget_number";
    587587            $this->assertArrayHasKey( $widget_id, $wp_registered_widgets );
    588588        }
     
    620620        global $wp_registered_widgets;
    621621
    622         $option_value = get_option( 'widget_search' );
     622        $option_value = get_option( 'widget_block' );
    623623        $this->assertArrayHasKey( '_multiwidget', $option_value );
    624624        $this->assertSame( 1, $option_value['_multiwidget'] );
     
    626626        $instance = $option_value[2];
    627627        $this->assertInternalType( 'array', $instance );
    628         $this->assertArrayHasKey( 'title', $instance );
     628        $this->assertArrayHasKey( 'content', $instance );
    629629        unset( $option_value['_multiwidget'] );
    630630
     
    635635
    636636        wp_widgets_init();
    637         $wp_widget_search = $wp_registered_widgets['search-2']['callback'][0];
    638 
    639         $settings = $wp_widget_search->get_settings();
     637        $wp_widget_block = $wp_registered_widgets['block-2']['callback'][0];
     638
     639        $settings = $wp_widget_block->get_settings();
    640640        // @todo $this->assertArrayNotHasKey( '_multiwidget', $settings ); ?
    641641        $this->assertArrayHasKey( 2, $settings );
     
    658658
    659659        wp_widgets_init();
    660         $wp_widget_search = $wp_registered_widgets['search-2']['callback'][0];
    661 
    662         $settings         = $wp_widget_search->get_settings();
    663         $overridden_title = 'Unit Tested';
     660        $wp_widget_block = $wp_registered_widgets['block-2']['callback'][0];
     661
     662        $settings           = $wp_widget_block->get_settings();
     663        $overridden_content = 'Unit Tested';
    664664
    665665        /*
     
    671671         * So this is why the value must be obtained.
    672672         */
    673         $instance          = $settings[2];
    674         $instance['title'] = $overridden_title;
    675         $settings[2]       = $instance;
    676 
    677         $wp_widget_search->save_settings( $settings );
    678 
    679         $option_value = get_option( $wp_widget_search->option_name );
     673        $instance            = $settings[2];
     674        $instance['content'] = $overridden_content;
     675        $settings[2]         = $instance;
     676
     677        $wp_widget_block->save_settings( $settings );
     678
     679        $option_value = get_option( $wp_widget_block->option_name );
    680680        $this->assertArrayHasKey( '_multiwidget', $option_value );
    681         $this->assertSame( $overridden_title, $option_value[2]['title'] );
     681        $this->assertSame( $overridden_content, $option_value[2]['content'] );
    682682    }
    683683
     
    689689
    690690        wp_widgets_init();
    691         $wp_widget_search = $wp_registered_widgets['search-2']['callback'][0];
    692 
    693         $settings = $wp_widget_search->get_settings();
     691        $wp_widget_block = $wp_registered_widgets['block-2']['callback'][0];
     692
     693        $settings = $wp_widget_block->get_settings();
    694694        $this->assertArrayHasKey( 2, $settings );
    695695        unset( $settings[2] );
    696         $wp_widget_search->save_settings( $settings );
    697         $option_value = get_option( $wp_widget_search->option_name );
     696        $wp_widget_block->save_settings( $settings );
     697        $option_value = get_option( $wp_widget_block->option_name );
    698698        $this->assertArrayNotHasKey( 2, $option_value );
    699699    }
     
    704704    function test_wp_widget_control() {
    705705        global $wp_registered_widgets;
     706
     707        update_option(
     708            'widget_search',
     709            array(
     710                2              => array( 'title' => '' ),
     711                '_multiwidget' => 1,
     712            )
     713        );
     714        update_option(
     715            'sidebars_widgets',
     716            array(
     717                'wp_inactive_widgets' => array(),
     718                'sidebar-1'           => array( 'search-2' ),
     719                'sidebar-2'           => array(),
     720                'array_version'       => 3,
     721            )
     722        );
    706723
    707724        wp_widgets_init();
     
    874891        $this->assertNotContains( 'unregistered_widget-1', $sidebars_widgets['sidebar-3'] );
    875892
    876         // 6 default widgets - 1 active text widget + 1 orphaned widget = 6.
    877         $this->assertCount( 6, $sidebars_widgets['wp_inactive_widgets'] );
    878 
    879         $this->assertContains( 'meta-2', $sidebars_widgets['wp_inactive_widgets'] );
    880         $this->assertContains( 'search-2', $sidebars_widgets['wp_inactive_widgets'] );
    881         $this->assertContains( 'archives-2', $sidebars_widgets['wp_inactive_widgets'] );
    882         $this->assertContains( 'categories-2', $sidebars_widgets['wp_inactive_widgets'] );
    883         $this->assertContains( 'recent-posts-2', $sidebars_widgets['wp_inactive_widgets'] );
    884         $this->assertContains( 'recent-comments-2', $sidebars_widgets['wp_inactive_widgets'] );
     893        // 5 default widgets - 1 active text widget + 1 orphaned widget = 5.
     894        $this->assertCount( 5, $sidebars_widgets['wp_inactive_widgets'] );
     895
     896        $this->assertContains( 'block-2', $sidebars_widgets['wp_inactive_widgets'] );
     897        $this->assertContains( 'block-3', $sidebars_widgets['wp_inactive_widgets'] );
     898        $this->assertContains( 'block-4', $sidebars_widgets['wp_inactive_widgets'] );
     899        $this->assertContains( 'block-5', $sidebars_widgets['wp_inactive_widgets'] );
     900        $this->assertContains( 'block-6', $sidebars_widgets['wp_inactive_widgets'] );
    885901
    886902        // Sidebar_widgets option was updated.
     
    966982        $this->assertArrayNotHasKey( 'orphaned_widgets_1', $sidebars_widgets );
    967983
    968         // 6 default widgets.
    969         $this->assertCount( 6, $sidebars_widgets['wp_inactive_widgets'] );
    970 
    971         $this->assertContains( 'archives-2', $sidebars_widgets['wp_inactive_widgets'] );
    972         $this->assertContains( 'meta-2', $sidebars_widgets['wp_inactive_widgets'] );
    973         $this->assertContains( 'search-2', $sidebars_widgets['wp_inactive_widgets'] );
    974         $this->assertContains( 'categories-2', $sidebars_widgets['wp_inactive_widgets'] );
    975         $this->assertContains( 'recent-posts-2', $sidebars_widgets['wp_inactive_widgets'] );
    976         $this->assertContains( 'recent-comments-2', $sidebars_widgets['wp_inactive_widgets'] );
     984        // 5 default widgets.
     985        $this->assertCount( 5, $sidebars_widgets['wp_inactive_widgets'] );
     986
     987        $this->assertContains( 'block-2', $sidebars_widgets['wp_inactive_widgets'] );
     988        $this->assertContains( 'block-3', $sidebars_widgets['wp_inactive_widgets'] );
     989        $this->assertContains( 'block-4', $sidebars_widgets['wp_inactive_widgets'] );
     990        $this->assertContains( 'block-5', $sidebars_widgets['wp_inactive_widgets'] );
     991        $this->assertContains( 'block-6', $sidebars_widgets['wp_inactive_widgets'] );
    977992
    978993        // Sidebar_widgets option was updated.
     
    983998            'sidebar-1'           => array( 'tag_cloud-1' ),
    984999            'sidebar-2'           => array( 'text-1' ),
    985             'fantasy'             => array( 'archives-2' ),
     1000            'fantasy'             => array( 'block-4' ),
    9861001            'wp_inactive_widgets' => array(),
    9871002        );
     
    10051020        $this->assertContains( 'text-1', $sidebars_widgets['sidebar-2'] );
    10061021
    1007         // 6 default widgets - 1 active text widget = 5.
    1008         $this->assertCount( 6, $sidebars_widgets['wp_inactive_widgets'] );
    1009 
    1010         $this->assertContains( 'meta-2', $sidebars_widgets['wp_inactive_widgets'] );
    1011         $this->assertContains( 'search-2', $sidebars_widgets['wp_inactive_widgets'] );
    1012         // archives-2 ends up as inactive because fantasy sidebar doesn't exist.
    1013         $this->assertContains( 'archives-2', $sidebars_widgets['wp_inactive_widgets'] );
    1014         $this->assertContains( 'categories-2', $sidebars_widgets['wp_inactive_widgets'] );
    1015         $this->assertContains( 'recent-posts-2', $sidebars_widgets['wp_inactive_widgets'] );
    1016         $this->assertContains( 'recent-comments-2', $sidebars_widgets['wp_inactive_widgets'] );
     1022        // 5 default widgets - 1 active text widget = 5.
     1023        $this->assertCount( 5, $sidebars_widgets['wp_inactive_widgets'] );
     1024
     1025        $this->assertContains( 'block-2', $sidebars_widgets['wp_inactive_widgets'] );
     1026        $this->assertContains( 'block-3', $sidebars_widgets['wp_inactive_widgets'] );
     1027        // block-4 ends up as inactive because fantasy sidebar doesn't exist.
     1028        $this->assertContains( 'block-4', $sidebars_widgets['wp_inactive_widgets'] );
     1029        $this->assertContains( 'block-5', $sidebars_widgets['wp_inactive_widgets'] );
     1030        $this->assertContains( 'block-6', $sidebars_widgets['wp_inactive_widgets'] );
    10171031
    10181032        // Sidebar_widgets option was updated.
     
    10541068        $this->assertArrayHasKey( 'sidebar-3', $sidebars_widgets );
    10551069        $this->assertEmpty( $sidebars_widgets['sidebar-3'] );
    1056         $this->assertCount( 6, $sidebars_widgets['wp_inactive_widgets'] );
    1057 
    1058         $this->assertContains( 'meta-2', $sidebars_widgets['wp_inactive_widgets'] );
    1059         $this->assertContains( 'search-2', $sidebars_widgets['wp_inactive_widgets'] );
    1060         $this->assertContains( 'archives-2', $sidebars_widgets['wp_inactive_widgets'] );
    1061         $this->assertContains( 'categories-2', $sidebars_widgets['wp_inactive_widgets'] );
    1062         $this->assertContains( 'recent-posts-2', $sidebars_widgets['wp_inactive_widgets'] );
    1063         $this->assertContains( 'recent-comments-2', $sidebars_widgets['wp_inactive_widgets'] );
     1070        $this->assertCount( 5, $sidebars_widgets['wp_inactive_widgets'] );
     1071
     1072        $this->assertContains( 'block-2', $sidebars_widgets['wp_inactive_widgets'] );
     1073        $this->assertContains( 'block-3', $sidebars_widgets['wp_inactive_widgets'] );
     1074        $this->assertContains( 'block-4', $sidebars_widgets['wp_inactive_widgets'] );
     1075        $this->assertContains( 'block-5', $sidebars_widgets['wp_inactive_widgets'] );
     1076        $this->assertContains( 'block-6', $sidebars_widgets['wp_inactive_widgets'] );
    10641077
    10651078        // Theme mod with previous widgets was not removed.
     
    11181131        }
    11191132
    1120         // 6 default widgets + 1 orphaned calendar widget = 7.
    1121         $this->assertCount( 7, $sidebars_widgets['wp_inactive_widgets'] );
     1133        // 5 default widgets + 1 orphaned calendar widget = 6.
     1134        $this->assertCount( 6, $sidebars_widgets['wp_inactive_widgets'] );
    11221135        $this->assertContains( 'calendar-1', $sidebars_widgets['wp_inactive_widgets'] );
    11231136        $this->assertArrayNotHasKey( 'orphaned_widgets_1', $sidebars_widgets );
Note: See TracChangeset for help on using the changeset viewer.