diff --git a/gutenberg.php b/gutenberg.php index d2eb01ecbd298..a9ca9f61e3336 100644 --- a/gutenberg.php +++ b/gutenberg.php @@ -45,17 +45,23 @@ function gutenberg_menu() { 'gutenberg' ); + if ( get_theme_support( '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,13 +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' ) ) { - register_widget( 'WP_Widget_Block' ); - } -} - -add_action( 'widgets_init', 'gutenberg_register_widgets' ); +add_theme_support( 'widgets-block-editor' ); diff --git a/lib/customizer.php b/lib/customizer.php index f665564517c12..754b8d284f325 100644 --- a/lib/customizer.php +++ b/lib/customizer.php @@ -55,10 +55,10 @@ function gutenberg_customize_register( $wp_customize ) { 'sanitize_callback' => 'gutenberg_customize_sanitize', ) ); - if ( gutenberg_is_experiment_enabled( 'gutenberg-widget-experiments' ) ) { + if ( get_theme_support( '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 +74,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 ( ! get_theme_support( '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 f7ae531dc3cc6..fc9b7c588fb33 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,7 @@ function gutenberg_display_experiment_section() { */ function gutenberg_experiments_editor_settings( $settings ) { $experiments_settings = array( - '__experimentalEnableLegacyWidgetBlock' => gutenberg_is_experiment_enabled( 'gutenberg-widget-experiments' ), + '__experimentalEnableLegacyWidgetBlock' => get_theme_support( 'widgets-block-editor' ), '__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 f6d3156950f38..540539f56ba59 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 7142cfffceb38..d2bf20f7518c2 100644 --- a/lib/rest-api.php +++ b/lib/rest-api.php @@ -136,7 +136,7 @@ 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' ) ) { + if ( get_theme_support( 'widgets-block-editor' ) ) { $widget_forms = new WP_REST_Widget_Utils_Controller(); $widget_forms->register_routes(); } @@ -194,7 +194,7 @@ function gutenberg_register_plugins_endpoint() { * Registers the Sidebars REST API routes. */ function gutenberg_register_sidebars_endpoint() { - if ( gutenberg_is_experiment_enabled( 'gutenberg-widget-experiments' ) ) { + if ( get_theme_support( 'widgets-block-editor' ) ) { $sidebars = new WP_REST_Sidebars_Controller(); $sidebars->register_routes(); } diff --git a/lib/widgets-page.php b/lib/widgets-page.php index 408dd217b6685..5ad008f13e822 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' ) { ?>