Adds the widgets block editor to widgets.php and customize.php

Moves the widgets block editor from Gutenberg into WordPress Core.

- Adds @wordpress/edit-widgets, @wordpress/customize-widgets and
  @wordpress/widgets.
- Modifies wp-admin/widgets.php to branch between the old editor and new editor
  depending on wp_use_widgets_block_editor().
- Modifies WP_Customize_Widgets to branch between the old editor control and new
  editor control depending on wp_use_widgets_block_editor().

Fixes #51506.
Props isabel_brison, TimothyBlynJacobs, andraganescu, kevin940726, talldanwp.


git-svn-id: https://develop.svn.wordpress.org/trunk@50996 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Robert Anderson
2021-05-25 08:38:04 +00:00
parent bc48d7ae09
commit 00bc227eb8
16 changed files with 973 additions and 811 deletions
+1
View File
@@ -310,6 +310,7 @@ function _unhook_block_registration() {
remove_action( 'init', 'register_block_core_loginout' );
remove_action( 'init', 'register_block_core_latest_comments' );
remove_action( 'init', 'register_block_core_latest_posts' );
remove_action( 'init', 'register_block_core_legacy_widget', 20 );
remove_action( 'init', 'register_block_core_post_author' );
remove_action( 'init', 'register_block_core_post_content' );
remove_action( 'init', 'register_block_core_post_date' );
+24 -1
View File
@@ -159,7 +159,7 @@ class WP_Test_Block_Editor extends WP_UnitTestCase {
function test_get_default_block_editor_settings() {
$settings = get_default_block_editor_settings();
$this->assertCount( 16, $settings );
$this->assertCount( 17, $settings );
$this->assertFalse( $settings['alignWide'] );
$this->assertInternalType( 'array', $settings['allowedMimeTypes'] );
$this->assertTrue( $settings['allowedBlockTypes'] );
@@ -254,6 +254,29 @@ class WP_Test_Block_Editor extends WP_UnitTestCase {
$settings['imageSizes']
);
$this->assertInternalType( 'int', $settings['maxUploadFileSize'] );
$this->assertSameSets(
array(
'archives',
'block',
'calendar',
'categories',
'custom_html',
'media_audio',
'media_gallery',
'media_image',
'media_video',
'meta',
'nav_menu',
'pages',
'recent-comments',
'recent-posts',
'rss',
'search',
'tag_cloud',
'text',
),
$settings['widgetTypesToHideFromLegacyWidgetBlock']
);
}
/**
+23 -18
View File
@@ -25,6 +25,7 @@ class Tests_WP_Customize_Widgets extends WP_UnitTestCase {
require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
add_theme_support( 'customize-selective-refresh-widgets' );
add_action( 'widgets_init', array( $this, 'remove_widgets_block_editor' ) );
$user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
wp_set_current_user( $user_id );
$GLOBALS['wp_customize'] = new WP_Customize_Manager();
@@ -85,6 +86,10 @@ class Tests_WP_Customize_Widgets extends WP_UnitTestCase {
do_action( 'wp', $GLOBALS['wp'] );
}
function remove_widgets_block_editor() {
remove_theme_support( 'widgets-block-editor' );
}
/**
* Test WP_Customize_Widgets::__construct()
*/
@@ -258,31 +263,31 @@ class Tests_WP_Customize_Widgets extends WP_UnitTestCase {
add_filter( 'widget_customizer_setting_args', array( $this, 'filter_widget_customizer_setting_args' ), 10, 2 );
$default_args = array(
'type' => 'option',
'capability' => 'edit_theme_options',
'transport' => 'refresh',
'default' => array(),
'sanitize_callback' => array( $this->manager->widgets, 'sanitize_widget_instance' ),
'sanitize_js_callback' => array( $this->manager->widgets, 'sanitize_widget_js_instance' ),
'type' => 'option',
'capability' => 'edit_theme_options',
'transport' => 'refresh',
'default' => array(),
);
$args = $this->manager->widgets->get_setting_args( 'widget_foo[2]' );
foreach ( $default_args as $key => $default_value ) {
$this->assertSame( $default_value, $args[ $key ] );
}
$this->assertTrue( is_callable( $args['sanitize_callback'] ), 'sanitize_callback is callable' );
$this->asserttrue( is_callable( $args['sanitize_js_callback'] ), 'sanitize_js_callback is callable' );
$this->assertSame( 'WIDGET_FOO[2]', $args['uppercase_id_set_by_filter'] );
$default_args = array(
'type' => 'option',
'capability' => 'edit_theme_options',
'transport' => 'postMessage',
'default' => array(),
'sanitize_callback' => array( $this->manager->widgets, 'sanitize_widget_instance' ),
'sanitize_js_callback' => array( $this->manager->widgets, 'sanitize_widget_js_instance' ),
'type' => 'option',
'capability' => 'edit_theme_options',
'transport' => 'postMessage',
'default' => array(),
);
$args = $this->manager->widgets->get_setting_args( 'widget_search[2]' );
foreach ( $default_args as $key => $default_value ) {
$this->assertSame( $default_value, $args[ $key ] );
}
$this->assertTrue( is_callable( $args['sanitize_callback'] ), 'sanitize_callback is callable' );
$this->asserttrue( is_callable( $args['sanitize_js_callback'] ), 'sanitize_js_callback is callable' );
remove_theme_support( 'customize-selective-refresh-widgets' );
$args = $this->manager->widgets->get_setting_args( 'widget_search[2]' );
@@ -304,17 +309,17 @@ class Tests_WP_Customize_Widgets extends WP_UnitTestCase {
$this->assertSame( 'WIDGET_BAR[3]', $args['uppercase_id_set_by_filter'] );
$default_args = array(
'type' => 'option',
'capability' => 'edit_theme_options',
'transport' => 'postMessage',
'default' => array(),
'sanitize_callback' => array( $this->manager->widgets, 'sanitize_sidebar_widgets' ),
'sanitize_js_callback' => array( $this->manager->widgets, 'sanitize_sidebar_widgets_js_instance' ),
'type' => 'option',
'capability' => 'edit_theme_options',
'transport' => 'postMessage',
'default' => array(),
);
$args = $this->manager->widgets->get_setting_args( 'sidebars_widgets[sidebar-1]' );
foreach ( $default_args as $key => $default_value ) {
$this->assertSame( $default_value, $args[ $key ] );
}
$this->assertTrue( is_callable( $args['sanitize_callback'] ), 'sanitize_callback is callable' );
$this->asserttrue( is_callable( $args['sanitize_js_callback'] ), 'sanitize_js_callback is callable' );
$this->assertSame( 'SIDEBARS_WIDGETS[SIDEBAR-1]', $args['uppercase_id_set_by_filter'] );
$override_args = array(