diff --git a/gutenberg.php b/gutenberg.php index e6a0c32099d909..24f77895cacca5 100644 --- a/gutenberg.php +++ b/gutenberg.php @@ -45,17 +45,23 @@ function gutenberg_menu() { 'gutenberg' ); + if ( gutenberg_use_widgets_block_editor() ) { + add_theme_page( + __( 'Widgets', 'gutenberg' ), + __( 'Widgets', 'gutenberg' ), + 'edit_theme_options', + 'gutenberg-widgets', + 'the_gutenberg_widgets' + ); + $submenu['themes.php'] = array_filter( + $submenu['themes.php'], + function( $current_menu_item ) { + return isset( $current_menu_item[2] ) && 'widgets.php' !== $current_menu_item[2]; + } + ); + } + if ( get_option( 'gutenberg-experiments' ) ) { - if ( array_key_exists( 'gutenberg-widget-experiments', get_option( 'gutenberg-experiments' ) ) ) { - add_submenu_page( - 'gutenberg', - __( 'Widgets (beta)', 'gutenberg' ), - __( 'Widgets (beta)', 'gutenberg' ), - 'edit_theme_options', - 'gutenberg-widgets', - 'the_gutenberg_widgets' - ); - } if ( array_key_exists( 'gutenberg-navigation', get_option( 'gutenberg-experiments' ) ) ) { add_submenu_page( 'gutenberg', @@ -101,7 +107,7 @@ function gutenberg_menu() { 'the_gutenberg_experiments' ); } -add_action( 'admin_menu', 'gutenberg_menu' ); +add_action( 'admin_menu', 'gutenberg_menu', 9 ); /** * Display a version notice and deactivate the Gutenberg plugin. @@ -182,45 +188,4 @@ function register_site_icon_url( $response ) { add_filter( 'rest_index', 'register_site_icon_url' ); -/** - * Registers the WP_Widget_Block widget - */ -function gutenberg_register_widgets() { - if ( ! gutenberg_is_experiment_enabled( 'gutenberg-widget-experiments' ) ) { - return; - } - - register_widget( 'WP_Widget_Block' ); - // By default every widget on widgets.php is wrapped with a
. - // This means that you can sometimes end up with invalid HTML, e.g. when - // one of the widgets is a Search block. - // - // To fix the problem, let's add a filter that moves the form below the actual - // widget content. - global $pagenow; - if ( 'widgets.php' === $pagenow ) { - add_filter( - 'dynamic_sidebar_params', - 'gutenberg_override_sidebar_params_for_block_widget' - ); - } -} - -/** - * Overrides dynamic_sidebar_params to make sure Blocks are not wrapped in tag. - * - * @param array $arg Dynamic sidebar params. - * @return array Updated dynamic sidebar params. - */ -function gutenberg_override_sidebar_params_for_block_widget( $arg ) { - if ( 'Block' === $arg[0]['widget_name'] ) { - $arg[0]['before_form'] = ''; - $arg[0]['before_widget_content'] = '
'; - $arg[0]['after_widget_content'] = '
'; - $arg[0]['after_form'] = '
'; - } - - return $arg; -} - -add_action( 'widgets_init', 'gutenberg_register_widgets' ); +add_theme_support( 'widgets-block-editor' ); diff --git a/lib/customizer.php b/lib/customizer.php index f665564517c12e..d2f24010c84c67 100644 --- a/lib/customizer.php +++ b/lib/customizer.php @@ -55,10 +55,11 @@ function gutenberg_customize_register( $wp_customize ) { 'sanitize_callback' => 'gutenberg_customize_sanitize', ) ); - if ( gutenberg_is_experiment_enabled( 'gutenberg-widget-experiments' ) ) { + + if ( gutenberg_use_widgets_block_editor() ) { $wp_customize->add_section( 'gutenberg_widget_blocks', - array( 'title' => __( 'Widget Blocks (Experimental)', 'gutenberg' ) ) + array( 'title' => __( 'Widget Blocks', 'gutenberg' ) ) ); $wp_customize->add_control( new WP_Customize_Widget_Blocks_Control( @@ -74,6 +75,25 @@ function gutenberg_customize_register( $wp_customize ) { } add_action( 'customize_register', 'gutenberg_customize_register' ); +/** + * Removes the core 'Widgets' panel from the Customizer if block based widgets are enabled. + * + * @param array $components Core Customizer components list. + * @return array (Maybe) modified components list. + */ +function gutenberg_remove_widgets_panel( $components ) { + if ( ! gutenberg_use_widgets_block_editor() ) { + return $components; + } + + $i = array_search( 'widgets', $components, true ); + if ( false !== $i ) { + unset( $components[ $i ] ); + } + return $components; +} +add_filter( 'customize_loaded_components', 'gutenberg_remove_widgets_panel' ); + /** * Filters the Customizer widget settings arguments. * This is needed because the Customizer registers settings for the raw registered widgets, without going through the `sidebars_widgets` filter. diff --git a/lib/experiments-page.php b/lib/experiments-page.php index f7ae531dc3cc60..19352ea578f8e8 100644 --- a/lib/experiments-page.php +++ b/lib/experiments-page.php @@ -40,17 +40,6 @@ function gutenberg_initialize_experiments_settings() { 'gutenberg_display_experiment_section', 'gutenberg-experiments' ); - add_settings_field( - 'gutenberg-widget-experiments', - __( 'Widgets', 'gutenberg' ), - 'gutenberg_display_experiment_field', - 'gutenberg-experiments', - 'gutenberg_experiments_section', - array( - 'label' => __( 'Enable Widgets screen and Legacy Widgets block', 'gutenberg' ), - 'id' => 'gutenberg-widget-experiments', - ) - ); add_settings_field( 'gutenberg-navigation', __( 'Navigation', 'gutenberg' ), @@ -131,7 +120,6 @@ function gutenberg_display_experiment_section() { */ function gutenberg_experiments_editor_settings( $settings ) { $experiments_settings = array( - '__experimentalEnableLegacyWidgetBlock' => gutenberg_is_experiment_enabled( 'gutenberg-widget-experiments' ), '__experimentalEnableFullSiteEditing' => gutenberg_is_experiment_enabled( 'gutenberg-full-site-editing' ), '__experimentalEnableFullSiteEditingDemo' => gutenberg_is_experiment_enabled( 'gutenberg-full-site-editing-demo' ), ); diff --git a/lib/load.php b/lib/load.php index f6d3156950f388..540539f56ba59a 100644 --- a/lib/load.php +++ b/lib/load.php @@ -29,13 +29,11 @@ function gutenberg_is_experiment_enabled( $name ) { /** * Start: Include for phase 2 */ - if ( gutenberg_is_experiment_enabled( 'gutenberg-widget-experiments' ) ) { - if ( ! class_exists( 'WP_REST_Widget_Utils_Controller' ) ) { - require dirname( __FILE__ ) . '/class-wp-rest-widget-utils-controller.php'; - } - if ( ! class_exists( 'WP_REST_Sidebars_Controller' ) ) { - require_once dirname( __FILE__ ) . '/class-wp-rest-sidebars-controller.php'; - } + if ( ! class_exists( 'WP_REST_Widget_Utils_Controller' ) ) { + require dirname( __FILE__ ) . '/class-wp-rest-widget-utils-controller.php'; + } + if ( ! class_exists( 'WP_REST_Sidebars_Controller' ) ) { + require_once dirname( __FILE__ ) . '/class-wp-rest-sidebars-controller.php'; } if ( ! class_exists( 'WP_REST_Block_Directory_Controller' ) ) { require dirname( __FILE__ ) . '/class-wp-rest-block-directory-controller.php'; @@ -89,12 +87,10 @@ function gutenberg_is_experiment_enabled( $name ) { if ( ! class_exists( 'WP_Block_List' ) ) { require dirname( __FILE__ ) . '/class-wp-block-list.php'; } -if ( gutenberg_is_experiment_enabled( 'gutenberg-widget-experiments' ) ) { - if ( ! class_exists( 'WP_Widget_Block' ) ) { - require_once dirname( __FILE__ ) . '/class-wp-widget-block.php'; - } - require_once dirname( __FILE__ ) . '/widgets-page.php'; +if ( ! class_exists( 'WP_Widget_Block' ) ) { + require_once dirname( __FILE__ ) . '/class-wp-widget-block.php'; } +require_once dirname( __FILE__ ) . '/widgets-page.php'; require dirname( __FILE__ ) . '/compat.php'; require dirname( __FILE__ ) . '/utils.php'; diff --git a/lib/rest-api.php b/lib/rest-api.php index 7142cfffceb384..e10f52805bcb43 100644 --- a/lib/rest-api.php +++ b/lib/rest-api.php @@ -136,10 +136,8 @@ function gutenberg_filter_rest_prepare_theme( $response, $theme, $request ) { * @since 5.0.0 */ function gutenberg_register_rest_widget_updater_routes() { - if ( gutenberg_is_experiment_enabled( 'gutenberg-widget-experiments' ) ) { - $widget_forms = new WP_REST_Widget_Utils_Controller(); - $widget_forms->register_routes(); - } + $widget_forms = new WP_REST_Widget_Utils_Controller(); + $widget_forms->register_routes(); } add_action( 'rest_api_init', 'gutenberg_register_rest_widget_updater_routes' ); @@ -194,10 +192,8 @@ function gutenberg_register_plugins_endpoint() { * Registers the Sidebars REST API routes. */ function gutenberg_register_sidebars_endpoint() { - if ( gutenberg_is_experiment_enabled( 'gutenberg-widget-experiments' ) ) { - $sidebars = new WP_REST_Sidebars_Controller(); - $sidebars->register_routes(); - } + $sidebars = new WP_REST_Sidebars_Controller(); + $sidebars->register_routes(); } add_action( 'rest_api_init', 'gutenberg_register_sidebars_endpoint' ); diff --git a/lib/widgets-page.php b/lib/widgets-page.php index 6b866f7d0785b7..fb024ef019794a 100644 --- a/lib/widgets-page.php +++ b/lib/widgets-page.php @@ -12,7 +12,7 @@ * * @param string $page The page name the function is being called for, `'gutenberg_customizer'` for the Customizer. */ -function the_gutenberg_widgets( $page = 'gutenberg_page_gutenberg-widgets' ) { +function the_gutenberg_widgets( $page = 'appearance_page_gutenberg-widgets' ) { ?>
is_block_editor() || - 'gutenberg_page_gutenberg-widgets' === $screen->id || + 'appearance_page_gutenberg-widgets' === $screen->id || ( function_exists( 'gutenberg_is_edit_site_page' ) && gutenberg_is_edit_site_page( $screen->id ) ) ); } +/** + * 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. + * + * @return boolean Whether or not to use the block editor to manage widgets. + */ +function gutenberg_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( + 'gutenberg_use_widgets_block_editor', + get_theme_support( 'widgets-block-editor' ) + ); +} + /** * Emulates the Widgets screen `admin_print_styles` when at the block editor * screen. @@ -261,3 +280,46 @@ function gutenberg_enqueue_widget_scripts() { } add_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_widget_scripts' ); + +/** + * Overrides dynamic_sidebar_params to make sure Blocks are not wrapped in
tag. + * + * @param array $arg Dynamic sidebar params. + * @return array Updated dynamic sidebar params. + */ +function gutenberg_override_sidebar_params_for_block_widget( $arg ) { + if ( 'Block' === $arg[0]['widget_name'] ) { + $arg[0]['before_form'] = ''; + $arg[0]['before_widget_content'] = '
'; + $arg[0]['after_widget_content'] = '
'; + $arg[0]['after_form'] = '
'; + } + + return $arg; +} + +/** + * Registers the WP_Widget_Block widget + */ +function gutenberg_register_widgets() { + if ( ! gutenberg_use_widgets_block_editor() ) { + return; + } + + register_widget( 'WP_Widget_Block' ); + // By default every widget on widgets.php is wrapped with a
. + // This means that you can sometimes end up with invalid HTML, e.g. when + // one of the widgets is a Search block. + // + // To fix the problem, let's add a filter that moves the form below the actual + // widget content. + global $pagenow; + if ( 'widgets.php' === $pagenow ) { + add_filter( + 'dynamic_sidebar_params', + 'gutenberg_override_sidebar_params_for_block_widget' + ); + } +} + +add_action( 'widgets_init', 'gutenberg_register_widgets' ); diff --git a/packages/block-editor/README.md b/packages/block-editor/README.md index 029e4ba72ad059..00e8b6fdb70057 100644 --- a/packages/block-editor/README.md +++ b/packages/block-editor/README.md @@ -494,7 +494,6 @@ _Properties_ - _titlePlaceholder_ `string`: Empty title placeholder - _codeEditingEnabled_ `boolean`: Whether or not the user can switch to the code editor - _\_\_experimentalCanUserUseUnfilteredHTML_ `boolean`: Whether the user should be able to use unfiltered HTML or the HTML should be filtered e.g., to remove elements considered insecure like iframes. -- _\_\_experimentalEnableLegacyWidgetBlock_ `boolean`: Whether the user has enabled the Legacy Widget Block - _\_\_experimentalBlockDirectory_ `boolean`: Whether the user has enabled the Block Directory - _\_\_experimentalEnableFullSiteEditing_ `boolean`: Whether the user has enabled Full Site Editing - _\_\_experimentalEnableFullSiteEditingDemo_ `boolean`: Whether the user has enabled Full Site Editing Demo Templates diff --git a/packages/block-editor/src/store/defaults.js b/packages/block-editor/src/store/defaults.js index 0ea72197adf76b..6b0605f2386e42 100644 --- a/packages/block-editor/src/store/defaults.js +++ b/packages/block-editor/src/store/defaults.js @@ -30,7 +30,6 @@ export const PREFERENCES_DEFAULTS = { * @property {string} titlePlaceholder Empty title placeholder * @property {boolean} codeEditingEnabled Whether or not the user can switch to the code editor * @property {boolean} __experimentalCanUserUseUnfilteredHTML Whether the user should be able to use unfiltered HTML or the HTML should be filtered e.g., to remove elements considered insecure like iframes. - * @property {boolean} __experimentalEnableLegacyWidgetBlock Whether the user has enabled the Legacy Widget Block * @property {boolean} __experimentalBlockDirectory Whether the user has enabled the Block Directory * @property {boolean} __experimentalEnableFullSiteEditing Whether the user has enabled Full Site Editing * @property {boolean} __experimentalEnableFullSiteEditingDemo Whether the user has enabled Full Site Editing Demo Templates @@ -152,7 +151,6 @@ export const SETTINGS_DEFAULTS = { availableLegacyWidgets: {}, hasPermissionsToManageWidgets: false, __experimentalCanUserUseUnfilteredHTML: false, - __experimentalEnableLegacyWidgetBlock: false, __experimentalBlockDirectory: false, __experimentalEnableFullSiteEditing: false, __experimentalEnableFullSiteEditingDemo: false, diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js index a8a67d21b20c28..d5719a23ca8915 100644 --- a/packages/block-library/src/index.js +++ b/packages/block-library/src/index.js @@ -189,14 +189,11 @@ export const registerCoreBlocks = () => { export const __experimentalRegisterExperimentalCoreBlocks = process.env.GUTENBERG_PHASE === 2 ? ( settings ) => { - const { - __experimentalEnableLegacyWidgetBlock, - __experimentalEnableFullSiteEditing, - } = settings; + const { __experimentalEnableFullSiteEditing } = settings; [ widgetArea, - __experimentalEnableLegacyWidgetBlock ? legacyWidget : null, + legacyWidget, navigation, navigationLink, diff --git a/packages/edit-widgets/src/components/header/index.js b/packages/edit-widgets/src/components/header/index.js index 24feb8b2a57574..a9d0e94e58e808 100644 --- a/packages/edit-widgets/src/components/header/index.js +++ b/packages/edit-widgets/src/components/header/index.js @@ -46,7 +46,7 @@ function Header( { isCustomizer } ) { { ! isCustomizer && (

- { __( 'Block Areas' ) } { __( '(experimental)' ) } + { __( 'Block Areas' ) }

) }
diff --git a/packages/edit-widgets/src/style.scss b/packages/edit-widgets/src/style.scss index 63cfa061dd70c2..8f86692579900d 100644 --- a/packages/edit-widgets/src/style.scss +++ b/packages/edit-widgets/src/style.scss @@ -11,7 +11,7 @@ html.wp-toolbar { background: $white; } -body.gutenberg_page_gutenberg-widgets { +body.appearance_page_gutenberg-widgets { @include wp-admin-reset( ".blocks-widgets-container" ); } diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index 7880e6f2bff9f5..b89eae25b5a70d 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -161,7 +161,6 @@ class EditorProvider extends Component { '__experimentalBlockPatterns', '__experimentalBlockPatternCategories', '__experimentalEnableCustomSpacing', - '__experimentalEnableLegacyWidgetBlock', '__experimentalEnableLinkColor', '__experimentalEnableFullSiteEditing', '__experimentalEnableFullSiteEditingDemo', diff --git a/test/integration/full-content/full-content.test.js b/test/integration/full-content/full-content.test.js index 02f638691a663d..86f5f5c10e271e 100644 --- a/test/integration/full-content/full-content.test.js +++ b/test/integration/full-content/full-content.test.js @@ -66,7 +66,6 @@ describe( 'full post content fixture', () => { ); unstable__bootstrapServerSideBlockDefinitions( blockDefinitions ); const settings = { - __experimentalEnableLegacyWidgetBlock: true, __experimentalEnableFullSiteEditing: true, }; // Load all hooks that modify blocks