diff --git a/lib/load.php b/lib/load.php index 0f951eab2ae58c..d9c81b7ae3251b 100644 --- a/lib/load.php +++ b/lib/load.php @@ -9,8 +9,6 @@ die( 'Silence is golden.' ); } -global $wp_version; - require_once __DIR__ . '/init.php'; require_once __DIR__ . '/upgrade.php'; @@ -75,7 +73,10 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/rest-api.php'; } -if ( version_compare( $wp_version, '5.8-alpha', '<' ) ) { +// We can't use class_exists( 'WP_Widget_Block' ) because core loads widgets +// *after* plugins, so test for wp_use_widgets_block_editor() which we know +// implies the existence of WP_Widget_Block. +if ( ! function_exists( 'wp_use_widgets_block_editor' ) ) { require_once __DIR__ . '/class-wp-widget-block.php'; } diff --git a/lib/widgets-customize.php b/lib/widgets-customize.php index 475a2c58d12520..24b546d5948750 100644 --- a/lib/widgets-customize.php +++ b/lib/widgets-customize.php @@ -5,8 +5,6 @@ * @package gutenberg */ -global $wp_version; - /** * Gutenberg's Customize Register. * @@ -169,7 +167,9 @@ function gutenberg_widgets_customize_load_block_editor_scripts_and_styles( $is_b return $is_block_editor_screen; } -if ( version_compare( $wp_version, '5.8-alpha', '<' ) ) { +// Test for wp_use_widgets_block_editor(), as the existence of this in core +// implies that the Customizer already supports the widgets block editor. +if ( ! function_exists( 'wp_use_widgets_block_editor' ) ) { add_action( 'customize_register', 'gutenberg_widgets_customize_register' ); add_filter( 'widget_customizer_setting_args', 'gutenberg_widgets_customize_add_unstable_instance', 10, 2 ); add_action( 'customize_controls_enqueue_scripts', 'gutenberg_customize_widgets_init' );