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

View File

@@ -1801,6 +1801,8 @@ function wp_widgets_init() {
register_widget( 'WP_Widget_Block' );
add_theme_support( 'widgets-block-editor' );
/**
* Fires after all default WordPress widgets have been registered.
*
@@ -1809,6 +1811,27 @@ function wp_widgets_init() {
do_action( 'widgets_init' );
}
/**
* Whether or not to use the block editor to manage widgets. Defaults to true
* unless a theme has removed support for widgets-block-editor or a plugin has
* filtered the return value of this function.
*
* @since 5.8.0
*
* @return boolean Whether or not to use the block editor to manage widgets.
*/
function wp_use_widgets_block_editor() {
/**
* Filters whether or not to use the block editor to manage widgets.
*
* @param boolean $use_widgets_block_editor Whether or not to use the block editor to manage widgets.
*/
return apply_filters(
'use_widgets_block_editor',
get_theme_support( 'widgets-block-editor' )
);
}
/**
* Converts a widget ID into its id_base and number components.
*
@@ -1971,3 +1994,16 @@ function wp_render_widget_control( $id ) {
return ob_get_clean();
}
// Needed until src/blocks/legacy-widget/index.php in @wordpress/block-library
// is updated to use the 'wp_' functions.
function gutenberg_find_widgets_sidebar( $widget_id ) {
return wp_find_widgets_sidebar( $widget_id );
}
function gutenberg_render_widget( $widget_id, $sidebar_id ) {
return wp_render_widget( $widget_id, $sidebar_id );
}
function gutenberg_get_widget_object( $id_base ) {
global $wp_widget_factory;
return $wp_widget_factory->get_widget_object( $id_base );
}