From f37107741ff1f80a983d3824ab552a122e449885 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Fri, 22 Nov 2019 12:36:46 +0100 Subject: [PATCH 01/11] Extensions: allow fetching a different subset of extensions This will allow one to get a different list of extensions based on different parameters: - plugin active - constant - filter --- class.jetpack-gutenberg.php | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/class.jetpack-gutenberg.php b/class.jetpack-gutenberg.php index aa8f9e50a6adc..4c63b3eaabf9c 100644 --- a/class.jetpack-gutenberg.php +++ b/class.jetpack-gutenberg.php @@ -717,4 +717,61 @@ public static function block_classes( $slug = '', $attr, $extra = array() ) { return implode( ' ', $classes ); } + + /** + * Determine whether a site should use the default set of blocks, or a custom set. + * Possible variations are currently beta, experimental, and production. + * + * @since 8.1.0 + * + * @return string $block_varation production|beta|experimental + */ + public function blocks_variation() { + if ( Constants::is_true( 'JETPACK_BETA_BLOCKS' ) ) { + return 'beta'; + } + + /* + * Switch to experimental blocks if you use Gutenberg, the FSE plugin, or the constant. + */ + if ( + Constants::is_true( 'JETPACK_EXPERIMENTAL_BLOCKS' ) + || Jetpack::is_plugin_active( 'gutenberg/gutenberg.php' ) + || Jetpack::is_plugin_active( 'full-site-editing/full-site-editing-plugin.php' ) + ) { + return 'experimental'; + } + + /** + * Allow customizing the variation of blocks in use on a site. + * + * @since 8.1.0 + * + * @param string $block_variation Can be beta, experimental, and production. Defaults to production. + */ + return apply_filters( 'jetpack_blocks_variation', 'production' ); + } + + /** + * Get a list of extensions available for the variation you chose. + * + * @since 8.1.0 + * + * @param obj $preset_extensions_manifest List of extensions available in Jetpack. + * @param string $blocks_variation Subset of blocks. production|beta|experimental. + * @param array $additional_extensions Array of other extensions to add to our variation (preexisting set). + * + * @return array $preset_extensions Array of extensions for that variation + */ + public function get_extensions_preset_for_variation( $preset_extensions_manifest, $blocks_variation, $additional_extensions = array() ) { + $preset_extensions = isset( $preset_extensions_manifest->{ $blocks_variation } ) + ? (array) $preset_extensions_manifest->{ $blocks_variation } + : array(); + + if ( ! empty( $additional_extensions ) ) { + $preset_extensions = array_unique( array_merge( $preset_extensions, $additional_extensions ) ); + } + + return $preset_extensions; + } } From 23bfd93ced13e0fe942400c737675ce850d7b053 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Fri, 22 Nov 2019 12:37:43 +0100 Subject: [PATCH 02/11] Load a different extensions bundle based on your block variation --- class.jetpack-gutenberg.php | 43 ++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/class.jetpack-gutenberg.php b/class.jetpack-gutenberg.php index 4c63b3eaabf9c..143dcd15970de 100644 --- a/class.jetpack-gutenberg.php +++ b/class.jetpack-gutenberg.php @@ -348,11 +348,28 @@ public static function get_preset( $preset ) { public static function get_jetpack_gutenberg_extensions_whitelist() { $preset_extensions_manifest = self::preset_exists( 'index' ) ? self::get_preset( 'index' ) : (object) array(); - $preset_extensions = isset( $preset_extensions_manifest->production ) ? (array) $preset_extensions_manifest->production : array(); + $blocks_variation = self::blocks_variation(); + $preset_extensions = isset( $preset_extensions_manifest->production ) + ? (array) $preset_extensions_manifest->production + : array(); - if ( Constants::is_true( 'JETPACK_BETA_BLOCKS' ) ) { - $beta_extensions = isset( $preset_extensions_manifest->beta ) ? (array) $preset_extensions_manifest->beta : array(); - return array_unique( array_merge( $preset_extensions, $beta_extensions ) ); + if ( 'production' === $blocks_variation ) { + $preset_extensions = self::get_extensions_preset_for_variation( $preset_extensions_manifest, $blocks_variation ); + } + + if ( 'experimental' === $blocks_variation ) { + $preset_extensions = self::get_extensions_preset_for_variation( $preset_extensions_manifest, $blocks_variation, $preset_extensions ); + } + + /* + * If you've chosen to see Beta blocks, + * we want to make all blocks available to you: + * - Production + * - Experimental + * - Beta + */ + if ( 'beta' === $blocks_variation ) { + $preset_extensions = self::get_extensions_preset_for_variation( $preset_extensions_manifest, $blocks_variation, $preset_extensions ); } return $preset_extensions; @@ -585,14 +602,20 @@ public static function enqueue_block_editor_assets() { wp_enqueue_script( 'jp-tracks', '//stats.wp.com/w.js', array(), gmdate( 'YW' ), true ); } - $rtl = is_rtl() ? '.rtl' : ''; - $beta = Constants::is_true( 'JETPACK_BETA_BLOCKS' ) ? '-beta' : ''; - $blocks_dir = self::get_blocks_directory(); + $rtl = is_rtl() ? '.rtl' : ''; + $blocks_dir = self::get_blocks_directory(); + $blocks_variation = self::blocks_variation(); + + if ( 'production' !== $blocks_variation ) { + $blocks_env = '-' . esc_attr( $blocks_variation ); + } else { + $blocks_env = ''; + } - $editor_script = plugins_url( "{$blocks_dir}editor{$beta}.js", JETPACK__PLUGIN_FILE ); - $editor_style = plugins_url( "{$blocks_dir}editor{$beta}{$rtl}.css", JETPACK__PLUGIN_FILE ); + $editor_script = plugins_url( "{$blocks_dir}editor{$blocks_env}.js", JETPACK__PLUGIN_FILE ); + $editor_style = plugins_url( "{$blocks_dir}editor{$blocks_env}{$rtl}.css", JETPACK__PLUGIN_FILE ); - $editor_deps_path = JETPACK__PLUGIN_DIR . $blocks_dir . "editor{$beta}.asset.php"; + $editor_deps_path = JETPACK__PLUGIN_DIR . $blocks_dir . "editor{$blocks_env}.asset.php"; $editor_deps = array( 'wp-polyfill' ); if ( file_exists( $editor_deps_path ) ) { $asset_manifest = include $editor_deps_path; From 8cf336bfeafd48e2040198524693a4c7ab0d29e1 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Fri, 22 Nov 2019 12:38:11 +0100 Subject: [PATCH 03/11] Update readme to mention new experimental blocks variation --- extensions/README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/extensions/README.md b/extensions/README.md index b677df79e8e7c..ee5a830e9e2af 100644 --- a/extensions/README.md +++ b/extensions/README.md @@ -59,6 +59,13 @@ Generally, all new extensions should start out as a beta. - Once you've successfully beta tested your new extension, you can open new PR to make your extension live! - Simply move the extension's slug out of the beta array and into the production array in `extensions/index.json`. +### Experimental Extensions + +We also offer an "experimental" state for extensions. Those extensions will be made available to anyone: +- Running the Gutenberg plugin, or; +- Running the FSE plugin, or; +- having the `JETPACK_EXPERIMENTAL_BLOCKS` constant defined in `wp-config.php`. + ### Testing Run `yarn test-extensions [--watch]` to run tests written in [Jest](https://jestjs.io/en/). From fb33c1f9dcc58f36e0954574c5a959c8069c772a Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Fri, 22 Nov 2019 12:39:09 +0100 Subject: [PATCH 04/11] Fix typo in extension scaffolding command --- class.jetpack-cli.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class.jetpack-cli.php b/class.jetpack-cli.php index 653d0f93bbb57..132978db7d6d8 100644 --- a/class.jetpack-cli.php +++ b/class.jetpack-cli.php @@ -1939,7 +1939,7 @@ function( $keyword ) { if ( empty( $files_written ) ) { WP_CLI::log( esc_html__( 'No files were created', 'jetpack' ) ); } else { - // Load index.json and insert the slug of the new block in the production array + // Load index.json and insert the slug of the new block in the beta array. $block_list_path = JETPACK__PLUGIN_DIR . 'extensions/index.json'; $block_list = $wp_filesystem->get_contents( $block_list_path ); if ( empty( $block_list ) ) { From 07f04296635aeb83dd9203283e0d4d3af54e0617 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Fri, 22 Nov 2019 12:39:38 +0100 Subject: [PATCH 05/11] Update block builder to build 3 bundles instead of 2 We now build 3 bundles: - The default production bundle with just the production blocks. - The experimental bundle with production blocks as well as experimental blocks. - The beta bundle with all the blocks: production, experimental, and beta. --- webpack.config.extensions.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/webpack.config.extensions.js b/webpack.config.extensions.js index 4bb2b9f1fce29..2b375633c0af1 100644 --- a/webpack.config.extensions.js +++ b/webpack.config.extensions.js @@ -33,12 +33,15 @@ function blockScripts( type, inputDir, presetBlocks ) { const presetPath = path.join( __dirname, 'extensions', 'index.json' ); const presetIndex = require( presetPath ); -const presetBlocks = _.get( presetIndex, [ 'production' ], [] ); -const presetBetaBlocks = _.get( presetIndex, [ 'beta' ], [] ); -const allPresetBlocks = [ ...presetBlocks, ...presetBetaBlocks ]; +const presetProductionBlocks = _.get( presetIndex, [ 'production' ], [] ); +const presetExperimentalBlocks = [ + ...presetProductionBlocks, + ..._.get( presetIndex, [ 'experimental' ], [] ), +]; +const presetBetaBlocks = [ ...presetExperimentalBlocks, ..._.get( presetIndex, [ 'beta' ], [] ) ]; // Helps split up each block into its own folder view script -const viewBlocksScripts = allPresetBlocks.reduce( ( viewBlocks, block ) => { +const viewBlocksScripts = presetBetaBlocks.reduce( ( viewBlocks, block ) => { const viewScriptPath = path.join( __dirname, 'extensions', 'blocks', block, 'view.js' ); if ( fs.existsSync( viewScriptPath ) ) { viewBlocks[ block + '/view' ] = [ viewSetup, ...[ viewScriptPath ] ]; @@ -46,16 +49,22 @@ const viewBlocksScripts = allPresetBlocks.reduce( ( viewBlocks, block ) => { return viewBlocks; }, {} ); -// Combines all the different blocks into one editor.js script +// Combines all the different production blocks into one editor.js script const editorScript = [ editorSetup, - ...blockScripts( 'editor', path.join( __dirname, 'extensions' ), presetBlocks ), + ...blockScripts( 'editor', path.join( __dirname, 'extensions' ), presetProductionBlocks ), +]; + +// Combines all the different Experimental blocks into one editor.js script +const editorExperimentalScript = [ + editorSetup, + ...blockScripts( 'editor', path.join( __dirname, 'extensions' ), presetExperimentalBlocks ), ]; // Combines all the different blocks into one editor-beta.js script const editorBetaScript = [ editorSetup, - ...blockScripts( 'editor', path.join( __dirname, 'extensions' ), allPresetBlocks ), + ...blockScripts( 'editor', path.join( __dirname, 'extensions' ), presetBetaBlocks ), ]; const extensionsWebpackConfig = getBaseWebpackConfig( @@ -63,6 +72,7 @@ const extensionsWebpackConfig = getBaseWebpackConfig( { entry: { editor: editorScript, + 'editor-experimental': editorExperimentalScript, 'editor-beta': editorBetaScript, ...viewBlocksScripts, }, From 7c52d16901d21707c9cebb79812b35ef70b35e97 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Fri, 22 Nov 2019 13:09:26 +0100 Subject: [PATCH 06/11] Make sure we whitelist all necessary blocks - When using the experimental variation, we need both prod and experimental blocks. - When using beta blocks, we need all blocks. --- class.jetpack-gutenberg.php | 67 ++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/class.jetpack-gutenberg.php b/class.jetpack-gutenberg.php index 143dcd15970de..fb7b8a7ffa126 100644 --- a/class.jetpack-gutenberg.php +++ b/class.jetpack-gutenberg.php @@ -346,33 +346,12 @@ public static function get_preset( $preset ) { * @return array A list of blocks: eg [ 'publicize', 'markdown' ] */ public static function get_jetpack_gutenberg_extensions_whitelist() { - $preset_extensions_manifest = self::preset_exists( 'index' ) ? self::get_preset( 'index' ) : (object) array(); + $preset_extensions_manifest = self::preset_exists( 'index' ) + ? self::get_preset( 'index' ) + : (object) array(); + $blocks_variation = self::blocks_variation(); - $blocks_variation = self::blocks_variation(); - $preset_extensions = isset( $preset_extensions_manifest->production ) - ? (array) $preset_extensions_manifest->production - : array(); - - if ( 'production' === $blocks_variation ) { - $preset_extensions = self::get_extensions_preset_for_variation( $preset_extensions_manifest, $blocks_variation ); - } - - if ( 'experimental' === $blocks_variation ) { - $preset_extensions = self::get_extensions_preset_for_variation( $preset_extensions_manifest, $blocks_variation, $preset_extensions ); - } - - /* - * If you've chosen to see Beta blocks, - * we want to make all blocks available to you: - * - Production - * - Experimental - * - Beta - */ - if ( 'beta' === $blocks_variation ) { - $preset_extensions = self::get_extensions_preset_for_variation( $preset_extensions_manifest, $blocks_variation, $preset_extensions ); - } - - return $preset_extensions; + return self::get_extensions_preset_for_variation( $preset_extensions_manifest, $blocks_variation ); } /** @@ -749,7 +728,7 @@ public static function block_classes( $slug = '', $attr, $extra = array() ) { * * @return string $block_varation production|beta|experimental */ - public function blocks_variation() { + public static function blocks_variation() { if ( Constants::is_true( 'JETPACK_BETA_BLOCKS' ) ) { return 'beta'; } @@ -782,17 +761,43 @@ public function blocks_variation() { * * @param obj $preset_extensions_manifest List of extensions available in Jetpack. * @param string $blocks_variation Subset of blocks. production|beta|experimental. - * @param array $additional_extensions Array of other extensions to add to our variation (preexisting set). * * @return array $preset_extensions Array of extensions for that variation */ - public function get_extensions_preset_for_variation( $preset_extensions_manifest, $blocks_variation, $additional_extensions = array() ) { + public static function get_extensions_preset_for_variation( $preset_extensions_manifest, $blocks_variation ) { $preset_extensions = isset( $preset_extensions_manifest->{ $blocks_variation } ) ? (array) $preset_extensions_manifest->{ $blocks_variation } : array(); - if ( ! empty( $additional_extensions ) ) { - $preset_extensions = array_unique( array_merge( $preset_extensions, $additional_extensions ) ); + /* + * Experimental and Beta blocks need the production blocks as well. + */ + if ( + 'experimental' === $blocks_variation + || 'beta' === $blocks_variation + ) { + $production_extensions = isset( $preset_extensions_manifest->production ) + ? (array) $preset_extensions_manifest->production + : array(); + + $preset_extensions = array_unique( array_merge( $preset_extensions, $production_extensions ) ); + } + + /* + * Beta blocks need the experimental blocks as well. + * + * If you've chosen to see Beta blocks, + * we want to make all blocks available to you: + * - Production + * - Experimental + * - Beta + */ + if ( 'beta' === $blocks_variation ) { + $production_extensions = isset( $preset_extensions_manifest->experimental ) + ? (array) $preset_extensions_manifest->experimental + : array(); + + $preset_extensions = array_unique( array_merge( $preset_extensions, $production_extensions ) ); } return $preset_extensions; From 36bb004dc7e1318131a83834908bf046b1c6e491 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Fri, 22 Nov 2019 13:34:32 +0100 Subject: [PATCH 07/11] Add new variation option to scaffold block CLI tool --- class.jetpack-cli.php | 22 +++++++++++++++------- extensions/README.md | 5 ++++- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/class.jetpack-cli.php b/class.jetpack-cli.php index 132978db7d6d8..dd1a21035e3b6 100644 --- a/class.jetpack-cli.php +++ b/class.jetpack-cli.php @@ -1809,15 +1809,17 @@ private function partner_provision_error( $error ) { * --slug: Specific slug to identify the block that overrides the one generated based on the title. * --description: Allows to provide a text description of the block. * --keywords: Provide up to three keywords separated by comma so users can find this block when they search in Gutenberg's inserter. + * --variation: Allows to decide whether the block should be a production block, experimental, or beta. Defaults to Beta when arg not provided. * * ## BLOCK TYPE EXAMPLES * * wp jetpack scaffold block "Cool Block" * wp jetpack scaffold block "Amazing Rock" --slug="good-music" --description="Rock the best music on your site" * wp jetpack scaffold block "Jukebox" --keywords="music, audio, media" + * wp jetpack scaffold block "Jukebox" --variation="experimental" * * @subcommand scaffold block - * @synopsis [--slug] [--description] [--keywords] + * @synopsis <type> <title> [--slug] [--description] [--keywords] [--variation] * * @param array $args Positional parameters, when strings are passed, wrap them in quotes. * @param array $assoc_args Associative parameters like --slug="nice-block". @@ -1853,6 +1855,11 @@ public function block( $args, $assoc_args ) { ? $assoc_args['slug'] : sanitize_title( $title ); + $variation_options = array( 'production', 'experimental', 'beta' ); + $variation = ( isset( $assoc_args['variation'] ) && in_array( $assoc_args['variation'], $variation_options, true ) ) + ? $assoc_args['variation'] + : 'beta'; + if ( preg_match( '#^jetpack/#', $slug ) ) { $slug = preg_replace( '#^jetpack/#', '', $slug ); } @@ -1939,15 +1946,15 @@ function( $keyword ) { if ( empty( $files_written ) ) { WP_CLI::log( esc_html__( 'No files were created', 'jetpack' ) ); } else { - // Load index.json and insert the slug of the new block in the beta array. + // Load index.json and insert the slug of the new block in its block variation array. $block_list_path = JETPACK__PLUGIN_DIR . 'extensions/index.json'; $block_list = $wp_filesystem->get_contents( $block_list_path ); if ( empty( $block_list ) ) { /* translators: %s is the path to the file with the block list */ WP_CLI::error( sprintf( esc_html__( 'Error fetching contents of %s', 'jetpack' ), $block_list_path ) ); } elseif ( false === stripos( $block_list, $slug ) ) { - $new_block_list = json_decode( $block_list ); - $new_block_list->beta[] = $slug; + $new_block_list = json_decode( $block_list ); + $new_block_list->{ $variation }[] = $slug; // Format the JSON to match our coding standards. $new_block_list_formatted = wp_json_encode( $new_block_list, JSON_PRETTY_PRINT ) . "\n"; @@ -1973,16 +1980,17 @@ function ( $matches ) { esc_html__( 'Successfully created block %1$s with slug %2$s', 'jetpack' ) . ' 🎉' . "\n" . "--------------------------------------------------------------------------------------------------------------------\n" . /* translators: the placeholder is a directory path */ - esc_html__( 'The files were created at %s', 'jetpack' ) . "\n" . + esc_html__( 'The files were created at %3$s', 'jetpack' ) . "\n" . esc_html__( 'To start using the block, build the blocks with yarn run build-extensions', 'jetpack' ) . "\n" . /* translators: the placeholder is a file path */ - esc_html__( 'The block slug has been added to the beta list at %s', 'jetpack' ) . "\n" . + esc_html__( 'The block slug has been added to the %4$s list at %5$s', 'jetpack' ) . "\n" . esc_html__( 'To load the block, add the constant JETPACK_BETA_BLOCKS as true to your wp-config.php file', 'jetpack' ) . "\n" . /* translators: the placeholder is a URL */ - "\n" . esc_html__( 'Read more at %s', 'jetpack' ) . "\n", + "\n" . esc_html__( 'Read more at %6$s', 'jetpack' ) . "\n", $title, $slug, $path, + $variation, $block_list_path, 'https://github.com/Automattic/jetpack/blob/master/extensions/README.md#develop-new-blocks' ) . '--------------------------------------------------------------------------------------------------------------------' diff --git a/extensions/README.md b/extensions/README.md index ee5a830e9e2af..17ad615bd7c05 100644 --- a/extensions/README.md +++ b/extensions/README.md @@ -76,7 +76,7 @@ Note that adding [Jest snapshot tests](https://jestjs.io/docs/en/snapshot-testin We have a command in WP-CLI that allows to scaffold Jetpack blocks. Its syntax is as follows: -`wp jetpack scaffold <type> <title> [--slug] [--description] [--keywords]` +`wp jetpack scaffold <type> <title> [--slug] [--description] [--keywords] [--variation]` **Currently the only `type` is `block`.** @@ -86,6 +86,7 @@ We have a command in WP-CLI that allows to scaffold Jetpack blocks. Its syntax i - **--slug**: Specific slug to identify the block that overrides the one generated base don the title. - **--description**: Allows to provide a text description of the block. - **--keywords**: Provide up to three keywords separated by a comma so users when they search for a block in the editor. +- **--variation**: Allows to decide whether the block should be a production block, experimental, or beta. Defaults to Beta when arg not provided. ### Files @@ -109,6 +110,8 @@ Since it's added to the beta array, you need to load the beta blocks as explaine `wp jetpack scaffold block "Jukebox" --keywords="music, audio, media"` +`wp jetpack scaffold block "Jukebox" --variation="experimental"` + ### Can I use Jurassic Ninja to test blocks? Yes! Just like any other changes in Jetpack, also blocks work in Jurassic Ninja. From ce966f401f798019992cb7e3cdb3e8c35074113d Mon Sep 17 00:00:00 2001 From: Jeremy Herve <jeremy@jeremy.hu> Date: Mon, 25 Nov 2019 10:12:37 +0100 Subject: [PATCH 08/11] Only load experimental blocks when using the constant. see https://github.com/Automattic/jetpack/pull/14104/files#r349585798 --- class.jetpack-gutenberg.php | 8 ++------ extensions/README.md | 5 +---- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/class.jetpack-gutenberg.php b/class.jetpack-gutenberg.php index fb7b8a7ffa126..66cf162f0d323 100644 --- a/class.jetpack-gutenberg.php +++ b/class.jetpack-gutenberg.php @@ -734,13 +734,9 @@ public static function blocks_variation() { } /* - * Switch to experimental blocks if you use Gutenberg, the FSE plugin, or the constant. + * Switch to experimental blocks if you use the JETPACK_EXPERIMENTAL_BLOCKS constant. */ - if ( - Constants::is_true( 'JETPACK_EXPERIMENTAL_BLOCKS' ) - || Jetpack::is_plugin_active( 'gutenberg/gutenberg.php' ) - || Jetpack::is_plugin_active( 'full-site-editing/full-site-editing-plugin.php' ) - ) { + if ( Constants::is_true( 'JETPACK_EXPERIMENTAL_BLOCKS' ) ) { return 'experimental'; } diff --git a/extensions/README.md b/extensions/README.md index 17ad615bd7c05..caf507267ebed 100644 --- a/extensions/README.md +++ b/extensions/README.md @@ -61,10 +61,7 @@ Generally, all new extensions should start out as a beta. ### Experimental Extensions -We also offer an "experimental" state for extensions. Those extensions will be made available to anyone: -- Running the Gutenberg plugin, or; -- Running the FSE plugin, or; -- having the `JETPACK_EXPERIMENTAL_BLOCKS` constant defined in `wp-config.php`. +We also offer an "experimental" state for extensions. Those extensions will be made available to anyone having the `JETPACK_EXPERIMENTAL_BLOCKS` constant defined in `wp-config.php`. ### Testing From 258350b3308d121096e55e43dec1d9f35177aa33 Mon Sep 17 00:00:00 2001 From: Jeremy Herve <jeremy@jeremy.hu> Date: Tue, 17 Dec 2019 09:45:17 +0100 Subject: [PATCH 09/11] Allow filter to overwrite any block variation See https://github.com/Automattic/jetpack/pull/14104#discussion_r358504591 --- class.jetpack-gutenberg.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/class.jetpack-gutenberg.php b/class.jetpack-gutenberg.php index 66cf162f0d323..93e6da63779b5 100644 --- a/class.jetpack-gutenberg.php +++ b/class.jetpack-gutenberg.php @@ -729,15 +729,18 @@ public static function block_classes( $slug = '', $attr, $extra = array() ) { * @return string $block_varation production|beta|experimental */ public static function blocks_variation() { + // Default to production blocks. + $block_varation = 'production'; + if ( Constants::is_true( 'JETPACK_BETA_BLOCKS' ) ) { - return 'beta'; + $block_varation = 'beta'; } /* * Switch to experimental blocks if you use the JETPACK_EXPERIMENTAL_BLOCKS constant. */ if ( Constants::is_true( 'JETPACK_EXPERIMENTAL_BLOCKS' ) ) { - return 'experimental'; + $block_varation = 'experimental'; } /** @@ -747,7 +750,7 @@ public static function blocks_variation() { * * @param string $block_variation Can be beta, experimental, and production. Defaults to production. */ - return apply_filters( 'jetpack_blocks_variation', 'production' ); + return apply_filters( 'jetpack_blocks_variation', $block_varation ); } /** From be04755d1d653fccde69937a432a1ae700ff6915 Mon Sep 17 00:00:00 2001 From: Jeremy Herve <jeremy@jeremy.hu> Date: Thu, 19 Dec 2019 16:48:34 +0100 Subject: [PATCH 10/11] Display different success message depending on block variation See https://github.com/Automattic/jetpack/pull/14104#discussion_r359640613 --- class.jetpack-cli.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/class.jetpack-cli.php b/class.jetpack-cli.php index dd1a21035e3b6..3a0b7c57b4685 100644 --- a/class.jetpack-cli.php +++ b/class.jetpack-cli.php @@ -1974,6 +1974,16 @@ function ( $matches ) { } } + if ( 'beta' === $variation || 'experimental' === $variation ) { + $block_constant = sprintf( + /* translators: the placeholder is a constant name */ + esc_html__( 'To load the block, add the constant %1$s as true to your wp-config.php file', 'jetpack' ), + ( 'beta' === $variation ? 'JETPACK_BETA_BLOCKS' : 'JETPACK_EXPERIMENTAL_BLOCKS' ) + ); + } else { + $block_constant = ''; + } + WP_CLI::success( sprintf( /* translators: the placeholders are a human readable title, and a series of words separated by dashes */ @@ -1984,14 +1994,15 @@ function ( $matches ) { esc_html__( 'To start using the block, build the blocks with yarn run build-extensions', 'jetpack' ) . "\n" . /* translators: the placeholder is a file path */ esc_html__( 'The block slug has been added to the %4$s list at %5$s', 'jetpack' ) . "\n" . - esc_html__( 'To load the block, add the constant JETPACK_BETA_BLOCKS as true to your wp-config.php file', 'jetpack' ) . "\n" . + '%6$s' . "\n" . /* translators: the placeholder is a URL */ - "\n" . esc_html__( 'Read more at %6$s', 'jetpack' ) . "\n", + "\n" . esc_html__( 'Read more at %7$s', 'jetpack' ) . "\n", $title, $slug, $path, $variation, $block_list_path, + $block_constant, 'https://github.com/Automattic/jetpack/blob/master/extensions/README.md#develop-new-blocks' ) . '--------------------------------------------------------------------------------------------------------------------' ); From 8f12adb4c3c30b7879c1a7057603c509924a80e7 Mon Sep 17 00:00:00 2001 From: Jeremy Herve <jeremy@jeremy.hu> Date: Thu, 19 Dec 2019 16:49:09 +0100 Subject: [PATCH 11/11] Clarify contents of experimental bundle in comments and readme See https://github.com/Automattic/jetpack/pull/14104#discussion_r359642958 --- extensions/README.md | 5 ++++- webpack.config.extensions.js | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/extensions/README.md b/extensions/README.md index caf507267ebed..ec3259155d7a3 100644 --- a/extensions/README.md +++ b/extensions/README.md @@ -55,13 +55,16 @@ Generally, all new extensions should start out as a beta. - Before you develop, remember to add your extension's slug to the beta array in `extensions/index.json`. - In the `wp-config.php` for your Docker environment (`docker/wordpress/wp-config.php`) or in your custom mu-plugins file (`docker/mu-plugins/yourfile.php`), enable beta extensions with the following snippet: `define( 'JETPACK_BETA_BLOCKS', true );` +- When you use this constant, you'll get all blocks: Beta blocks, Experimental blocks, and Production blocks. - In the WordPress.com environment, Automatticians will be able to see beta extensions with no further configuration - Once you've successfully beta tested your new extension, you can open new PR to make your extension live! - Simply move the extension's slug out of the beta array and into the production array in `extensions/index.json`. ### Experimental Extensions -We also offer an "experimental" state for extensions. Those extensions will be made available to anyone having the `JETPACK_EXPERIMENTAL_BLOCKS` constant defined in `wp-config.php`. +We also offer an "experimental" state for extensions. Those extensions will be made available to anyone having the `JETPACK_EXPERIMENTAL_BLOCKS` constant defined in `wp-config.php`. When you use this constant, you'll get Experimental blocks as well as Production blocks. + +Experimental extensions are usually considered ready for production, but are served only to sites requesting them. ### Testing diff --git a/webpack.config.extensions.js b/webpack.config.extensions.js index 2b375633c0af1..704c058de32d1 100644 --- a/webpack.config.extensions.js +++ b/webpack.config.extensions.js @@ -38,6 +38,7 @@ const presetExperimentalBlocks = [ ...presetProductionBlocks, ..._.get( presetIndex, [ 'experimental' ], [] ), ]; +// Beta Blocks include all blocks: beta, experimental, and production blocks. const presetBetaBlocks = [ ...presetExperimentalBlocks, ..._.get( presetIndex, [ 'beta' ], [] ) ]; // Helps split up each block into its own folder view script