From e829dd2e797eea003df4bd553aff64ae7f9c733d Mon Sep 17 00:00:00 2001 From: Grant Kinney Date: Tue, 30 Jul 2024 16:58:30 -0500 Subject: [PATCH] Adds experimental blocks flag for blocks that may not be ready for general use --- lib/experimental/editor-settings.php | 18 +++++++++++++++++- lib/experiments-page.php | 12 ++++++++++++ phpunit/bootstrap.php | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/experimental/editor-settings.php b/lib/experimental/editor-settings.php index 065264fd124e8c..c34984baa0a619 100644 --- a/lib/experimental/editor-settings.php +++ b/lib/experimental/editor-settings.php @@ -43,12 +43,28 @@ function gutenberg_enable_experiments() { /** * Sets a global JS variable used to trigger the availability of form & input blocks. + * + * @deprecated 19.0.0 Use gutenberg_enable_block_experiments(). */ function gutenberg_enable_form_input_blocks() { + _deprecated_function( __FUNCTION__, 'Gutenberg 19.0.0', 'gutenberg_enable_block_experiments' ); +} + +/** + * Sets global JS variables used to enable various block experiments. + */ +function gutenberg_enable_block_experiments() { $gutenberg_experiments = get_option( 'gutenberg-experiments' ); + + // Experimental form blocks. if ( $gutenberg_experiments && array_key_exists( 'gutenberg-form-blocks', $gutenberg_experiments ) ) { wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableFormBlocks = true', 'before' ); } + + // General experimental blocks that are not in the default block library. + if ( $gutenberg_experiments && array_key_exists( 'gutenberg-block-experiments', $gutenberg_experiments ) ) { + wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableBlockExperiments = true', 'before' ); + } } -add_action( 'admin_init', 'gutenberg_enable_form_input_blocks' ); +add_action( 'admin_init', 'gutenberg_enable_block_experiments' ); diff --git a/lib/experiments-page.php b/lib/experiments-page.php index acb095b47fde30..b27f6fc2726a2a 100644 --- a/lib/experiments-page.php +++ b/lib/experiments-page.php @@ -79,6 +79,18 @@ function gutenberg_initialize_experiments_settings() { ) ); + add_settings_field( + 'gutenberg-block-experiments', + __( 'Experimental blocks', 'gutenberg' ), + 'gutenberg_display_experiment_field', + 'gutenberg-experiments', + 'gutenberg_experiments_section', + array( + 'label' => __( 'Enable experimental blocks.

(Warning: these blocks may have significant changes during development that cause validation errors and display issues.)

', 'gutenberg' ), + 'id' => 'gutenberg-block-experiments', + ) + ); + add_settings_field( 'gutenberg-form-blocks', __( 'Form and input blocks ', 'gutenberg' ), diff --git a/phpunit/bootstrap.php b/phpunit/bootstrap.php index 295d02978f120f..55319a752b61e6 100644 --- a/phpunit/bootstrap.php +++ b/phpunit/bootstrap.php @@ -95,6 +95,7 @@ function fail_if_died( $message ) { 'gutenberg-widget-experiments' => '1', 'gutenberg-full-site-editing' => 1, 'gutenberg-form-blocks' => 1, + 'gutenberg-block-experiments' => 1, ), );