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
+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(