Skip to content

Commit

Permalink
Revert "Replace the widgets screen experiment with a theme support (W…
Browse files Browse the repository at this point in the history
…ordPress#24087)" (WordPress#24841)

This reverts commit 80777ae.
  • Loading branch information
noisysocks authored Aug 27, 2020
1 parent 7fef85b commit 4b28ce9
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 67 deletions.
39 changes: 21 additions & 18 deletions gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,17 @@ 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',
Expand Down Expand Up @@ -107,7 +101,7 @@ function( $current_menu_item ) {
'the_gutenberg_experiments'
);
}
add_action( 'admin_menu', 'gutenberg_menu', 9 );
add_action( 'admin_menu', 'gutenberg_menu' );

/**
* Display a version notice and deactivate the Gutenberg plugin.
Expand Down Expand Up @@ -188,4 +182,13 @@ function register_site_icon_url( $response ) {

add_filter( 'rest_index', 'register_site_icon_url' );

add_theme_support( 'widgets-block-editor' );
/**
* 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' );
23 changes: 2 additions & 21 deletions lib/customizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ function gutenberg_customize_register( $wp_customize ) {
'sanitize_callback' => 'gutenberg_customize_sanitize',
)
);
if ( get_theme_support( 'widgets-block-editor' ) ) {
if ( gutenberg_is_experiment_enabled( 'gutenberg-widget-experiments' ) ) {
$wp_customize->add_section(
'gutenberg_widget_blocks',
array( 'title' => __( 'Widget Blocks', 'gutenberg' ) )
array( 'title' => __( 'Widget Blocks (Experimental)', 'gutenberg' ) )
);
$wp_customize->add_control(
new WP_Customize_Widget_Blocks_Control(
Expand All @@ -74,25 +74,6 @@ 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.
Expand Down
13 changes: 12 additions & 1 deletion lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ 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' ),
Expand Down Expand Up @@ -120,7 +131,7 @@ function gutenberg_display_experiment_section() {
*/
function gutenberg_experiments_editor_settings( $settings ) {
$experiments_settings = array(
'__experimentalEnableLegacyWidgetBlock' => get_theme_support( 'widgets-block-editor' ),
'__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' ),
);
Expand Down
20 changes: 12 additions & 8 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ function gutenberg_is_experiment_enabled( $name ) {
/**
* Start: Include for phase 2
*/
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 ( 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_Block_Directory_Controller' ) ) {
require dirname( __FILE__ ) . '/class-wp-rest-block-directory-controller.php';
Expand Down Expand Up @@ -87,10 +89,12 @@ function gutenberg_is_experiment_enabled( $name ) {
if ( ! class_exists( 'WP_Block_List' ) ) {
require dirname( __FILE__ ) . '/class-wp-block-list.php';
}
if ( ! class_exists( 'WP_Widget_Block' ) ) {
require_once dirname( __FILE__ ) . '/class-wp-widget-block.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';
}
require_once dirname( __FILE__ ) . '/widgets-page.php';

require dirname( __FILE__ ) . '/compat.php';
require dirname( __FILE__ ) . '/utils.php';
Expand Down
4 changes: 2 additions & 2 deletions lib/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ( get_theme_support( 'widgets-block-editor' ) ) {
if ( gutenberg_is_experiment_enabled( 'gutenberg-widget-experiments' ) ) {
$widget_forms = new WP_REST_Widget_Utils_Controller();
$widget_forms->register_routes();
}
Expand Down Expand Up @@ -194,7 +194,7 @@ function gutenberg_register_plugins_endpoint() {
* Registers the Sidebars REST API routes.
*/
function gutenberg_register_sidebars_endpoint() {
if ( get_theme_support( 'widgets-block-editor' ) ) {
if ( gutenberg_is_experiment_enabled( 'gutenberg-widget-experiments' ) ) {
$sidebars = new WP_REST_Sidebars_Controller();
$sidebars->register_routes();
}
Expand Down
6 changes: 3 additions & 3 deletions lib/widgets-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 'appearance_page_gutenberg-widgets' ) {
function the_gutenberg_widgets( $page = 'gutenberg_page_gutenberg-widgets' ) {
?>
<div
id="widgets-editor"
Expand Down Expand Up @@ -41,11 +41,11 @@ function gutenberg_widgets_init( $hook ) {
wp_enqueue_style( 'wp-block-library-theme' );
return;
}
if ( ! in_array( $hook, array( 'appearance_page_gutenberg-widgets', 'gutenberg_customizer' ), true ) ) {
if ( ! in_array( $hook, array( 'gutenberg_page_gutenberg-widgets', 'gutenberg_customizer' ), true ) ) {
return;
}

$initializer_name = 'appearance_page_gutenberg-widgets' === $hook
$initializer_name = 'gutenberg_page_gutenberg-widgets' === $hook
? 'initialize'
: 'customizerInitialize';

Expand Down
13 changes: 1 addition & 12 deletions lib/widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function gutenberg_is_block_editor() {
return ! empty( $screen ) &&
(
$screen->is_block_editor() ||
'appearance_page_gutenberg-widgets' === $screen->id ||
'gutenberg_page_gutenberg-widgets' === $screen->id ||
( function_exists( 'gutenberg_is_edit_site_page' ) && gutenberg_is_edit_site_page( $screen->id ) )
);
}
Expand Down Expand Up @@ -261,14 +261,3 @@ function gutenberg_enqueue_widget_scripts() {
}

add_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_widget_scripts' );

/**
* Registers the WP_Widget_Block widget
*/
function gutenberg_register_widgets() {
if ( get_theme_support( 'widgets-block-editor' ) ) {
register_widget( 'WP_Widget_Block' );
}
}

add_action( 'widgets_init', 'gutenberg_register_widgets' );
2 changes: 1 addition & 1 deletion packages/edit-widgets/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function Header( { isCustomizer } ) {
</NavigableMenu>
{ ! isCustomizer && (
<h1 className="edit-widgets-header__title">
{ __( 'Block Areas' ) }
{ __( 'Block Areas' ) } { __( '(experimental)' ) }
</h1>
) }
<div className="edit-widgets-header__actions">
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-widgets/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ html.wp-toolbar {
background: $white;
}

body.appearance_page_gutenberg-widgets {
body.gutenberg_page_gutenberg-widgets {
@include wp-admin-reset( ".blocks-widgets-container" );
}

Expand Down

0 comments on commit 4b28ce9

Please sign in to comment.