From 2fdcec76a6fa87be2637602264f2f9ad76ae4d0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Tue, 18 Jun 2024 04:03:50 +0200 Subject: [PATCH 01/15] Revert "Revert test data for `WithSlug` variation (#62579)" (#62587) * Revert "Revert test data for `WithSlug` variation (#62579)" This reverts commit 2917269cf70405990ab4b1cd3f961a714dc5f5f6. * Clear up test caching Co-authored-by: oandregal Co-authored-by: andrewserong Co-authored-by: aaronrobertshaw Co-authored-by: tellthemachines Co-authored-by: ramonjd --- .../block-style-variations-test.php | 83 +++++++++++++++++++ phpunit/class-wp-theme-json-resolver-test.php | 12 +++ .../block-style-variation-with-slug.json | 12 +++ 3 files changed, 107 insertions(+) create mode 100644 phpunit/data/themedir1/block-theme/styles/block-style-variation-with-slug.json diff --git a/phpunit/block-supports/block-style-variations-test.php b/phpunit/block-supports/block-style-variations-test.php index 870a76a4fb4a4..cfe82c7ab52f4 100644 --- a/phpunit/block-supports/block-style-variations-test.php +++ b/phpunit/block-supports/block-style-variations-test.php @@ -9,6 +9,41 @@ */ class WP_Block_Supports_Block_Style_Variations_Test extends WP_UnitTestCase { + /** + * Administrator ID. + * + * @var int + */ + protected static $administrator_id; + + /** + * WP_Theme_JSON_Resolver_Gutenberg::$blocks_cache property. + * + * @var ReflectionProperty + */ + private static $property_blocks_cache; + + /** + * Original value of the WP_Theme_JSON_Resolver_Gutenberg::$blocks_cache property. + * + * @var array + */ + private static $property_blocks_cache_orig_value; + + /** + * WP_Theme_JSON_Resolver_Gutenberg::$core property. + * + * @var ReflectionProperty + */ + private static $property_core; + + /** + * Original value of the WP_Theme_JSON_Resolver_Gutenberg::$core property. + * + * @var WP_Theme_JSON_Gutenberg + */ + private static $property_core_orig_value; + /** * Theme root directory. * @@ -23,6 +58,31 @@ class WP_Block_Supports_Block_Style_Variations_Test extends WP_UnitTestCase { */ private $orig_theme_dir; + public static function set_up_before_class() { + parent::set_up_before_class(); + + self::$administrator_id = self::factory()->user->create( + array( + 'role' => 'administrator', + 'user_email' => 'administrator@example.com', + ) + ); + + static::$property_blocks_cache = new ReflectionProperty( WP_Theme_JSON_Resolver_Gutenberg::class, 'blocks_cache' ); + static::$property_blocks_cache->setAccessible( true ); + static::$property_blocks_cache_orig_value = static::$property_blocks_cache->getValue(); + + static::$property_core = new ReflectionProperty( WP_Theme_JSON_Resolver_Gutenberg::class, 'core' ); + static::$property_core->setAccessible( true ); + static::$property_core_orig_value = static::$property_core->getValue(); + } + + public static function tear_down_after_class() { + static::$property_blocks_cache->setValue( null, static::$property_blocks_cache_orig_value ); + static::$property_core->setValue( null, static::$property_core_orig_value ); + parent::tear_down_after_class(); + } + public function set_up() { parent::set_up(); $this->theme_root = realpath( dirname( __DIR__ ) . '/data/themedir1' ); @@ -94,6 +154,22 @@ public function test_add_registered_block_styles_to_theme_data() { ), ); + /* + * This style is to be deliberately overwritten by the theme.json partial + * See `phpunit/data/themedir1/block-theme/styles/block-style-variation-with-slug.json`. + */ + register_block_style( + 'core/group', + array( + 'name' => 'WithSlug', + 'style_data' => array( + 'color' => array( + 'background' => 'whitesmoke', + 'text' => 'black', + ), + ), + ) + ); register_block_style( 'core/group', array( @@ -106,6 +182,12 @@ public function test_add_registered_block_styles_to_theme_data() { $group_styles = $theme_json['styles']['blocks']['core/group'] ?? array(); $expected = array( 'variations' => array( + 'WithSlug' => array( + 'color' => array( + 'background' => 'aliceblue', + 'text' => 'midnightblue', + ), + ), 'my-variation' => $variation_styles_data, /* @@ -129,6 +211,7 @@ public function test_add_registered_block_styles_to_theme_data() { ); unregister_block_style( 'core/group', 'my-variation' ); + unregister_block_style( 'core/group', 'WithSlug' ); $this->assertSameSetsWithIndex( $group_styles, $expected ); } diff --git a/phpunit/class-wp-theme-json-resolver-test.php b/phpunit/class-wp-theme-json-resolver-test.php index 50e1d9d846899..6333c3d1dd776 100644 --- a/phpunit/class-wp-theme-json-resolver-test.php +++ b/phpunit/class-wp-theme-json-resolver-test.php @@ -1118,6 +1118,18 @@ public function data_get_style_variations() { ), ), ), + array( + 'blockTypes' => array( 'core/group', 'core/columns' ), + 'version' => 3, + 'slug' => 'WithSlug', + 'title' => 'With Slug', + 'styles' => array( + 'color' => array( + 'background' => 'aliceblue', + 'text' => 'midnightblue', + ), + ), + ), ), ), ); diff --git a/phpunit/data/themedir1/block-theme/styles/block-style-variation-with-slug.json b/phpunit/data/themedir1/block-theme/styles/block-style-variation-with-slug.json new file mode 100644 index 0000000000000..d938a8a0db833 --- /dev/null +++ b/phpunit/data/themedir1/block-theme/styles/block-style-variation-with-slug.json @@ -0,0 +1,12 @@ +{ + "version": 3, + "blockTypes": [ "core/group", "core/columns" ], + "slug": "WithSlug", + "title": "With Slug", + "styles": { + "color": { + "background": "aliceblue", + "text": "midnightblue" + } + } +} From e6361421120dee5110ca0d52c6687f0a292b1863 Mon Sep 17 00:00:00 2001 From: Aki Hamano <54422211+t-hamano@users.noreply.github.com> Date: Tue, 18 Jun 2024 11:18:22 +0900 Subject: [PATCH 02/15] env: Ignore `\$schema` key in environment config parsing (#62626) * env: Ignore `\$schema` key in environment config parsing * Add changelog Co-authored-by: t-hamano Co-authored-by: sirreal --- packages/env/CHANGELOG.md | 4 ++++ packages/env/lib/config/parse-config.js | 5 +++++ packages/env/lib/config/test/parse-config.js | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/packages/env/CHANGELOG.md b/packages/env/CHANGELOG.md index 06e5d513f1c78..e443e6fb5ec04 100644 --- a/packages/env/CHANGELOG.md +++ b/packages/env/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Enhancement + +- Ignore `$schema` key in environment config parsing ([#62626](https://github.com/WordPress/gutenberg/pull/62626)). + ## 10.1.0 (2024-06-15) ## 10.0.0 (2024-05-31) diff --git a/packages/env/lib/config/parse-config.js b/packages/env/lib/config/parse-config.js index 30125951b1ac8..1fc7e94925149 100644 --- a/packages/env/lib/config/parse-config.js +++ b/packages/env/lib/config/parse-config.js @@ -417,6 +417,11 @@ async function parseEnvironmentConfig( continue; } + // The $schema key is a special key that is used to validate the configuration. + if ( key === '$schema' ) { + continue; + } + // We should also check root-only options for the root config // because these aren't part of the above defaults but are // configuration options that we will parse. diff --git a/packages/env/lib/config/test/parse-config.js b/packages/env/lib/config/test/parse-config.js index c1b01df9d8d88..38e4db9860cb3 100644 --- a/packages/env/lib/config/test/parse-config.js +++ b/packages/env/lib/config/test/parse-config.js @@ -254,6 +254,26 @@ describe( 'parseConfig', () => { } ); } ); + it( 'should ignore `$schema` key', async () => { + readRawConfigFile.mockImplementation( async ( configFile ) => { + if ( configFile === '/test/gutenberg/.wp-env.json' ) { + return { + $schema: 'test', + }; + } + + if ( configFile === '/test/gutenberg/.wp-env.override.json' ) { + return {}; + } + + throw new Error( 'Invalid File: ' + configFile ); + } ); + + const parsed = await parseConfig( '/test/gutenberg', '/cache' ); + + expect( parsed ).toEqual( DEFAULT_CONFIG ); + } ); + it( 'should override with environment variables', async () => { process.env.WP_ENV_PORT = 123; process.env.WP_ENV_TESTS_PORT = 456; From c4e90245465fc08ec332475a4f8fa5cf0eab2a38 Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Tue, 18 Jun 2024 12:42:57 +1000 Subject: [PATCH 03/15] Update Private API opt-in string for WP 6.6. (#62635) Co-authored-by: peterwilsoncc Co-authored-by: talldan --- docs/contributors/code/coding-guidelines.md | 2 +- packages/block-directory/src/lock-unlock.js | 2 +- packages/block-editor/src/lock-unlock.js | 2 +- packages/block-library/src/lock-unlock.js | 2 +- packages/blocks/src/lock-unlock.js | 2 +- packages/commands/src/lock-unlock.js | 2 +- packages/components/src/lock-unlock.js | 2 +- packages/core-commands/src/lock-unlock.js | 2 +- packages/core-data/src/private-apis.js | 2 +- packages/customize-widgets/src/lock-unlock.js | 2 +- packages/data/src/lock-unlock.js | 2 +- packages/dataviews/src/lock-unlock.ts | 2 +- packages/edit-post/src/lock-unlock.js | 2 +- packages/edit-site/src/lock-unlock.js | 2 +- packages/edit-widgets/src/lock-unlock.js | 2 +- packages/editor/src/lock-unlock.js | 2 +- packages/format-library/src/lock-unlock.js | 2 +- packages/interface/lock-unlock.js | 2 +- packages/patterns/src/lock-unlock.js | 2 +- packages/preferences/src/lock-unlock.js | 2 +- packages/private-apis/README.md | 5 +++-- packages/private-apis/src/implementation.js | 2 +- packages/private-apis/src/test/index.js | 2 +- packages/reusable-blocks/src/lock-unlock.js | 2 +- packages/router/src/lock-unlock.js | 2 +- 25 files changed, 27 insertions(+), 26 deletions(-) diff --git a/docs/contributors/code/coding-guidelines.md b/docs/contributors/code/coding-guidelines.md index d89df5876e380..b76d77b3040e6 100644 --- a/docs/contributors/code/coding-guidelines.md +++ b/docs/contributors/code/coding-guidelines.md @@ -162,7 +162,7 @@ do so by opting-in to `@wordpress/private-apis`: import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis'; export const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/block-editor' // Name of the package calling __dangerousOptInToUnstableAPIsOnlyForCoreModules, // (not the name of the package whose APIs you want to access) ); diff --git a/packages/block-directory/src/lock-unlock.js b/packages/block-directory/src/lock-unlock.js index a6cc2fe3440f6..79b82edbc0fc7 100644 --- a/packages/block-directory/src/lock-unlock.js +++ b/packages/block-directory/src/lock-unlock.js @@ -5,6 +5,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri export const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/block-directory' ); diff --git a/packages/block-editor/src/lock-unlock.js b/packages/block-editor/src/lock-unlock.js index 433a61a12aec0..51929a5920b11 100644 --- a/packages/block-editor/src/lock-unlock.js +++ b/packages/block-editor/src/lock-unlock.js @@ -5,6 +5,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri export const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/block-editor' ); diff --git a/packages/block-library/src/lock-unlock.js b/packages/block-library/src/lock-unlock.js index 3c18e76b798cd..cc8ef7a811fff 100644 --- a/packages/block-library/src/lock-unlock.js +++ b/packages/block-library/src/lock-unlock.js @@ -5,6 +5,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri export const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/block-library' ); diff --git a/packages/blocks/src/lock-unlock.js b/packages/blocks/src/lock-unlock.js index 0a98fcfb19d29..2ed55b6ba6adb 100644 --- a/packages/blocks/src/lock-unlock.js +++ b/packages/blocks/src/lock-unlock.js @@ -5,6 +5,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri export const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/blocks' ); diff --git a/packages/commands/src/lock-unlock.js b/packages/commands/src/lock-unlock.js index e11bd687d8742..ffff128cdb91b 100644 --- a/packages/commands/src/lock-unlock.js +++ b/packages/commands/src/lock-unlock.js @@ -5,6 +5,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri export const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/commands' ); diff --git a/packages/components/src/lock-unlock.js b/packages/components/src/lock-unlock.js index 1525ece158072..7749a249cd02a 100644 --- a/packages/components/src/lock-unlock.js +++ b/packages/components/src/lock-unlock.js @@ -5,6 +5,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri export const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/components' ); diff --git a/packages/core-commands/src/lock-unlock.js b/packages/core-commands/src/lock-unlock.js index 6f0712a8069fd..de47c0eeb8155 100644 --- a/packages/core-commands/src/lock-unlock.js +++ b/packages/core-commands/src/lock-unlock.js @@ -5,6 +5,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri export const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/core-commands' ); diff --git a/packages/core-data/src/private-apis.js b/packages/core-data/src/private-apis.js index 53f0dc2dfa133..91bf30792c970 100644 --- a/packages/core-data/src/private-apis.js +++ b/packages/core-data/src/private-apis.js @@ -5,6 +5,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri export const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/core-data' ); diff --git a/packages/customize-widgets/src/lock-unlock.js b/packages/customize-widgets/src/lock-unlock.js index 01d57a2835d5d..92ef5147b1713 100644 --- a/packages/customize-widgets/src/lock-unlock.js +++ b/packages/customize-widgets/src/lock-unlock.js @@ -5,6 +5,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri export const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/customize-widgets' ); diff --git a/packages/data/src/lock-unlock.js b/packages/data/src/lock-unlock.js index b5b1f9cbed5a5..99596d756f66e 100644 --- a/packages/data/src/lock-unlock.js +++ b/packages/data/src/lock-unlock.js @@ -5,6 +5,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri export const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/data' ); diff --git a/packages/dataviews/src/lock-unlock.ts b/packages/dataviews/src/lock-unlock.ts index 18318773cefef..d1533da413cfc 100644 --- a/packages/dataviews/src/lock-unlock.ts +++ b/packages/dataviews/src/lock-unlock.ts @@ -5,6 +5,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri export const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/dataviews' ); diff --git a/packages/edit-post/src/lock-unlock.js b/packages/edit-post/src/lock-unlock.js index bf65b262d9f48..6ef97785cd0a6 100644 --- a/packages/edit-post/src/lock-unlock.js +++ b/packages/edit-post/src/lock-unlock.js @@ -5,6 +5,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri export const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/edit-post' ); diff --git a/packages/edit-site/src/lock-unlock.js b/packages/edit-site/src/lock-unlock.js index 5c335db46b9d4..5d1a87670c52f 100644 --- a/packages/edit-site/src/lock-unlock.js +++ b/packages/edit-site/src/lock-unlock.js @@ -5,6 +5,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri export const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/edit-site' ); diff --git a/packages/edit-widgets/src/lock-unlock.js b/packages/edit-widgets/src/lock-unlock.js index 003e53788068c..1c401a0ccd4da 100644 --- a/packages/edit-widgets/src/lock-unlock.js +++ b/packages/edit-widgets/src/lock-unlock.js @@ -5,6 +5,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri export const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/edit-widgets' ); diff --git a/packages/editor/src/lock-unlock.js b/packages/editor/src/lock-unlock.js index 12df6f4711b23..a507ffe95e11d 100644 --- a/packages/editor/src/lock-unlock.js +++ b/packages/editor/src/lock-unlock.js @@ -4,6 +4,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis'; export const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/editor' ); diff --git a/packages/format-library/src/lock-unlock.js b/packages/format-library/src/lock-unlock.js index f7512caa4b746..e0effa2b829ee 100644 --- a/packages/format-library/src/lock-unlock.js +++ b/packages/format-library/src/lock-unlock.js @@ -5,6 +5,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri export const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/format-library' ); diff --git a/packages/interface/lock-unlock.js b/packages/interface/lock-unlock.js index b6e29bb71c7c0..1e5bb39ed18c6 100644 --- a/packages/interface/lock-unlock.js +++ b/packages/interface/lock-unlock.js @@ -5,6 +5,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri export const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/interface' ); diff --git a/packages/patterns/src/lock-unlock.js b/packages/patterns/src/lock-unlock.js index d727871d71439..2e9ca804023ed 100644 --- a/packages/patterns/src/lock-unlock.js +++ b/packages/patterns/src/lock-unlock.js @@ -4,6 +4,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis'; export const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/patterns' ); diff --git a/packages/preferences/src/lock-unlock.js b/packages/preferences/src/lock-unlock.js index 981f244881ed0..9556c83135e58 100644 --- a/packages/preferences/src/lock-unlock.js +++ b/packages/preferences/src/lock-unlock.js @@ -4,6 +4,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis'; export const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/preferences' ); diff --git a/packages/private-apis/README.md b/packages/private-apis/README.md index 163ef630d0feb..b95fb0d7bd3eb 100644 --- a/packages/private-apis/README.md +++ b/packages/private-apis/README.md @@ -12,7 +12,7 @@ Every `@wordpress` package wanting to privately access or expose experimental AP import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis'; export const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/block-editor' // Name of the package calling __dangerousOptInToUnstableAPIsOnlyForCoreModules, // (not the name of the package whose APIs you want to access) ); @@ -22,7 +22,7 @@ Each package may only opt in once. The function name communicates that plugins a The function will throw an error if the following conditions are not met: -1. The first argument must exactly match the required consent string: `'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.'`. +1. The first argument must exactly match the required consent string: `'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.'`. 2. The second argument must be a known `@wordpress` package that hasn't yet opted into `@wordpress/private-apis` Once the opt-in is complete, the obtained `lock()` and `unlock()` utilities enable hiding `__experimental` APIs from the naked eye: @@ -120,3 +120,4 @@ The final string in this list is the current version. 1. I know using unstable features means my plugin or theme will inevitably break on the next WordPress release. 2. I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress. +3. I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress. diff --git a/packages/private-apis/src/implementation.js b/packages/private-apis/src/implementation.js index bea820226fe33..c268e46f669cb 100644 --- a/packages/private-apis/src/implementation.js +++ b/packages/private-apis/src/implementation.js @@ -56,7 +56,7 @@ const registeredPrivateApis = []; * CHANGE MAY OCCUR IN EITHER A MAJOR OR MINOR RELEASE. */ const requiredConsent = - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.'; + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.'; /** @type {boolean} */ let allowReRegistration; diff --git a/packages/private-apis/src/test/index.js b/packages/private-apis/src/test/index.js index d91f7d3bcdafe..51d1b6a3afba0 100644 --- a/packages/private-apis/src/test/index.js +++ b/packages/private-apis/src/test/index.js @@ -16,7 +16,7 @@ beforeEach( () => { } ); const requiredConsent = - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.'; + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.'; describe( '__dangerousOptInToUnstableAPIsOnlyForCoreModules', () => { it( 'Should require a consent string', () => { diff --git a/packages/reusable-blocks/src/lock-unlock.js b/packages/reusable-blocks/src/lock-unlock.js index c0bc2d1529f7d..4f63798515580 100644 --- a/packages/reusable-blocks/src/lock-unlock.js +++ b/packages/reusable-blocks/src/lock-unlock.js @@ -4,6 +4,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis'; export const { unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/reusable-blocks' ); diff --git a/packages/router/src/lock-unlock.js b/packages/router/src/lock-unlock.js index d7f4e92b4a542..e7323bd0270ea 100644 --- a/packages/router/src/lock-unlock.js +++ b/packages/router/src/lock-unlock.js @@ -5,6 +5,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri export const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', + 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/router' ); From 54586ee6af2cd0beaa0596d5824f35208af300ac Mon Sep 17 00:00:00 2001 From: Ella <4710635+ellatrix@users.noreply.github.com> Date: Tue, 18 Jun 2024 04:54:04 +0200 Subject: [PATCH 04/15] Performance: run block variation hook only for matches (#62617) Co-authored-by: ellatrix Co-authored-by: aaronrobertshaw --- .../src/hooks/block-style-variation.js | 25 ++++++++++++++++--- packages/block-editor/src/hooks/utils.js | 4 ++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/packages/block-editor/src/hooks/block-style-variation.js b/packages/block-editor/src/hooks/block-style-variation.js index 3ad8896e73561..336db687558f5 100644 --- a/packages/block-editor/src/hooks/block-style-variation.js +++ b/packages/block-editor/src/hooks/block-style-variation.js @@ -17,6 +17,23 @@ import { useStyleOverride } from './utils'; import { store as blockEditorStore } from '../store'; import { globalStylesDataKey } from '../store/private-keys'; +const VARIATION_PREFIX = 'is-style-'; + +function getVariationMatches( className ) { + if ( ! className ) { + return []; + } + return className.split( /\s+/ ).reduce( ( matches, name ) => { + if ( name.startsWith( VARIATION_PREFIX ) ) { + const match = name.slice( VARIATION_PREFIX.length ); + if ( match !== 'default' ) { + matches.push( match ); + } + } + return matches; + }, [] ); +} + /** * Get the first block style variation that has been registered from the class string. * @@ -28,14 +45,13 @@ import { globalStylesDataKey } from '../store/private-keys'; function getVariationNameFromClass( className, registeredStyles = [] ) { // The global flag affects how capturing groups work in JS. So the regex // below will only return full CSS classes not just the variation name. - const matches = className?.match( /\bis-style-(?!default)(\S+)\b/g ); + const matches = getVariationMatches( className ); if ( ! matches ) { return null; } - for ( const variationClass of matches ) { - const variation = variationClass.substring( 9 ); // Remove 'is-style-' prefix. + for ( const variation of matches ) { if ( registeredStyles.some( ( style ) => style.name === variation ) ) { return variation; } @@ -94,7 +110,7 @@ function useBlockProps( { name, className, clientId } ) { const registeredStyles = getBlockStyles( name ); const variation = getVariationNameFromClass( className, registeredStyles ); - const variationClass = `is-style-${ variation }-${ clientId }`; + const variationClass = `${ VARIATION_PREFIX }${ variation }-${ clientId }`; const { settings, styles } = useBlockStyleVariation( name, @@ -153,5 +169,6 @@ function useBlockProps( { name, className, clientId } ) { export default { hasSupport: () => true, attributeKeys: [ 'className' ], + isMatch: ( { className } ) => getVariationMatches( className ).length > 0, useBlockProps, }; diff --git a/packages/block-editor/src/hooks/utils.js b/packages/block-editor/src/hooks/utils.js index 4338262300c61..d4eb7df553d3c 100644 --- a/packages/block-editor/src/hooks/utils.js +++ b/packages/block-editor/src/hooks/utils.js @@ -582,6 +582,7 @@ export function createBlockListBlockFilter( features ) { hasSupport, attributeKeys = [], useBlockProps, + isMatch, } = feature; const neededProps = {}; @@ -595,7 +596,8 @@ export function createBlockListBlockFilter( features ) { // Skip rendering if none of the needed attributes are // set. ! Object.keys( neededProps ).length || - ! hasSupport( props.name ) + ! hasSupport( props.name ) || + ( isMatch && ! isMatch( neededProps ) ) ) { return null; } From f45aa20bcf97fe261506ccb434418c84cbf21045 Mon Sep 17 00:00:00 2001 From: Ramon Date: Tue, 18 Jun 2024 14:50:23 +1000 Subject: [PATCH 05/15] Theme JSON resolver: read theme.json files from the styles/ folder only once (#62638) Cache reading theme.json files from styles/ folder. Co-authored-by: ramonjd Co-authored-by: aaronrobertshaw --- lib/class-wp-theme-json-resolver-gutenberg.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/class-wp-theme-json-resolver-gutenberg.php b/lib/class-wp-theme-json-resolver-gutenberg.php index 507876af4952a..f027e79d21047 100644 --- a/lib/class-wp-theme-json-resolver-gutenberg.php +++ b/lib/class-wp-theme-json-resolver-gutenberg.php @@ -761,7 +761,7 @@ public static function get_style_variations( $scope = 'theme' ) { } ksort( $variation_files ); foreach ( $variation_files as $path => $file ) { - $decoded_file = wp_json_file_decode( $path, array( 'associative' => true ) ); + $decoded_file = self::read_json_file( $path ); if ( is_array( $decoded_file ) && static::style_variation_has_scope( $decoded_file, $scope ) ) { $translated = static::translate( $decoded_file, wp_get_theme()->get( 'TextDomain' ) ); $variation = ( new WP_Theme_JSON_Gutenberg( $translated ) )->get_raw_data(); From c222a5fcde01fc1678bc2b918853340381393dc9 Mon Sep 17 00:00:00 2001 From: Ramon Date: Tue, 18 Jun 2024 14:52:17 +1000 Subject: [PATCH 06/15] Tests: simplify test set up in `WP_Block_Supports_Block_Style_Variations_Test` (#62637) * Clean all JSON caches, including WP_Theme_JSON_Resolver_Gutenberg::clean_cached_data(), after test suite runs, not just after any tests * LINT THE UNIVERSE THEN SET IT ON FIRE * Test reverting cache reset from tear_down_after_class() Co-authored-by: ramonjd Co-authored-by: aaronrobertshaw --- .../block-style-variations-test.php | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/phpunit/block-supports/block-style-variations-test.php b/phpunit/block-supports/block-style-variations-test.php index cfe82c7ab52f4..d7b2b98b75f5c 100644 --- a/phpunit/block-supports/block-style-variations-test.php +++ b/phpunit/block-supports/block-style-variations-test.php @@ -58,31 +58,6 @@ class WP_Block_Supports_Block_Style_Variations_Test extends WP_UnitTestCase { */ private $orig_theme_dir; - public static function set_up_before_class() { - parent::set_up_before_class(); - - self::$administrator_id = self::factory()->user->create( - array( - 'role' => 'administrator', - 'user_email' => 'administrator@example.com', - ) - ); - - static::$property_blocks_cache = new ReflectionProperty( WP_Theme_JSON_Resolver_Gutenberg::class, 'blocks_cache' ); - static::$property_blocks_cache->setAccessible( true ); - static::$property_blocks_cache_orig_value = static::$property_blocks_cache->getValue(); - - static::$property_core = new ReflectionProperty( WP_Theme_JSON_Resolver_Gutenberg::class, 'core' ); - static::$property_core->setAccessible( true ); - static::$property_core_orig_value = static::$property_core->getValue(); - } - - public static function tear_down_after_class() { - static::$property_blocks_cache->setValue( null, static::$property_blocks_cache_orig_value ); - static::$property_core->setValue( null, static::$property_core_orig_value ); - parent::tear_down_after_class(); - } - public function set_up() { parent::set_up(); $this->theme_root = realpath( dirname( __DIR__ ) . '/data/themedir1' ); From 880cf3eeccc5b0aafd02af0f0a963b7ab8e98539 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Tue, 18 Jun 2024 16:26:58 +1000 Subject: [PATCH 07/15] Section Styles: Switch away from using init for variation registration (#62640) Co-authored-by: oandregal Co-authored-by: aaronrobertshaw Co-authored-by: andrewserong Co-authored-by: ellatrix --- backport-changelog/6.6/6844.md | 3 + lib/block-supports/block-style-variations.php | 59 ------------------- ...est-global-styles-controller-gutenberg.php | 22 ++----- ...class-wp-theme-json-resolver-gutenberg.php | 12 ++++ .../block-style-variations-test.php | 9 +-- 5 files changed, 26 insertions(+), 79 deletions(-) create mode 100644 backport-changelog/6.6/6844.md diff --git a/backport-changelog/6.6/6844.md b/backport-changelog/6.6/6844.md new file mode 100644 index 0000000000000..f735d96b9a051 --- /dev/null +++ b/backport-changelog/6.6/6844.md @@ -0,0 +1,3 @@ +https://github.com/WordPress/wordpress-develop/pull/6844 + +* https://github.com/WordPress/gutenberg/pull/62640 diff --git a/lib/block-supports/block-style-variations.php b/lib/block-supports/block-style-variations.php index 13a7d4dce18c3..4adefa0f4e440 100644 --- a/lib/block-supports/block-style-variations.php +++ b/lib/block-supports/block-style-variations.php @@ -475,62 +475,3 @@ function gutenberg_register_block_style_variations_from_theme_json_data( $variat } } } - -/** - * Register shared block style variations defined by the theme. - * - * These can come in three forms: - * - the theme's theme.json - * - the theme's partials (standalone files in `/styles` that only define block style variations) - * - the user's theme.json (for example, theme style variations the user selected) - * - * @access private - */ -function gutenberg_register_block_style_variations_from_theme() { - /* - * Skip any registration of styles if no theme.json or variation partials are present. - * - * Given the possibility of hybrid themes, this check can't rely on if the theme - * is a block theme or not. Instead: - * - If there is a primary theme.json, continue. - * - If there is a partials directory, continue. - * - The only variations to be registered from the global styles user origin, - * are those that have been copied in from the selected theme style variation. - * For a theme style variation to be selected it would have to have a partial - * theme.json file covered by the previous check. - */ - $has_partials_directory = is_dir( get_stylesheet_directory() . '/styles' ) || is_dir( get_template_directory() . '/styles' ); - if ( ! wp_theme_has_theme_json() && ! $has_partials_directory ) { - return; - } - - // Partials from `/styles`. - $variations_partials = WP_Theme_JSON_Resolver_Gutenberg::get_style_variations( 'block' ); - gutenberg_register_block_style_variations_from_theme_json_data( $variations_partials ); - - /* - * Pull the data from the specific origin instead of the merged data. - * This is because, for 6.6, we only support registering block style variations - * for the 'theme' and 'custom' origins but not for 'default' (core theme.json) - * or 'custom' (theme.json in a block). - * - * When/If we add support for every origin, we should switch to using the public API - * instead, e.g.: wp_get_global_styles( array( 'blocks', 'variations' ) ). - */ - - // theme.json of the theme. - $theme_json_theme = WP_Theme_JSON_Resolver_Gutenberg::get_theme_data(); - $variations_theme = $theme_json_theme->get_data()['styles']['blocks']['variations'] ?? array(); - gutenberg_register_block_style_variations_from_theme_json_data( $variations_theme ); - - // User data linked for this theme. - $theme_json_user = WP_Theme_JSON_Resolver_Gutenberg::get_user_data(); - $variations_user = $theme_json_user->get_data()['styles']['blocks']['variations'] ?? array(); - gutenberg_register_block_style_variations_from_theme_json_data( $variations_user ); -} - -// Remove core init action registering variations. -if ( function_exists( 'wp_register_block_style_variations_from_theme' ) ) { - remove_action( 'init', 'wp_register_block_style_variations_from_theme' ); -} -add_action( 'init', 'gutenberg_register_block_style_variations_from_theme' ); diff --git a/lib/class-wp-rest-global-styles-controller-gutenberg.php b/lib/class-wp-rest-global-styles-controller-gutenberg.php index aadcb2fd7de1e..c933a18a4fa59 100644 --- a/lib/class-wp-rest-global-styles-controller-gutenberg.php +++ b/lib/class-wp-rest-global-styles-controller-gutenberg.php @@ -331,22 +331,12 @@ protected function prepare_item_for_database( $request ) { $config['styles'] = $existing_config['styles']; } - /* - * If the incoming request is going to create a new variation - * that is not yet registered, we register it here. - * This is because the variations are registered on init, - * but we want this endpoint to return the new variation immediately: - * if we don't register it, it'll be stripped out of the response - * just in this request (subsequent ones will be ok). - * Take the variations defined in styles.blocks.variations from the incoming request - * that are not part of the $existing_config. - */ - if ( isset( $request['styles']['blocks']['variations'] ) ) { - $existing_variations = isset( $existing_config['styles']['blocks']['variations'] ) ? $existing_config['styles']['blocks']['variations'] : array(); - $new_variations = array_diff_key( $request['styles']['blocks']['variations'], $existing_variations ); - if ( ! empty( $new_variations ) ) { - gutenberg_register_block_style_variations_from_theme_json_data( $new_variations ); - } + // Register theme-defined variations. + WP_Theme_JSON_Resolver_Gutenberg::get_theme_data(); + + // Register user-defined variations. + if ( isset( $request['styles']['blocks']['variations'] ) && ! empty( $config['styles']['blocks']['variations'] ) ) { + gutenberg_register_block_style_variations_from_theme_json_data( $config['styles']['blocks']['variations'] ); } if ( isset( $request['settings'] ) ) { diff --git a/lib/class-wp-theme-json-resolver-gutenberg.php b/lib/class-wp-theme-json-resolver-gutenberg.php index f027e79d21047..6a8d2558d1c85 100644 --- a/lib/class-wp-theme-json-resolver-gutenberg.php +++ b/lib/class-wp-theme-json-resolver-gutenberg.php @@ -247,6 +247,14 @@ public static function get_theme_data( $deprecated = array(), $options = array() $theme_json_data = array( 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA ); } + // Register variations defined by the theme. + $variations = $theme_json_data['styles']['blocks']['variations'] ?? array(); + gutenberg_register_block_style_variations_from_theme_json_data( $variations ); + + // Register variations defined by theme partials (theme.json files in the styles directory). + $variations = static::get_style_variations( 'block' ); + gutenberg_register_block_style_variations_from_theme_json_data( $variations ); + /** * Filters the data provided by the theme for global styles and settings. * @@ -539,6 +547,10 @@ public static function get_user_data() { } } + // Register variations defined by the user. + $variations = $config['styles']['blocks']['variations'] ?? array(); + gutenberg_register_block_style_variations_from_theme_json_data( $variations ); + /** This filter is documented in wp-includes/class-wp-theme-json-resolver.php */ $theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data_Gutenberg( $config, 'custom' ) ); static::$user = $theme_json->get_theme_json(); diff --git a/phpunit/block-supports/block-style-variations-test.php b/phpunit/block-supports/block-style-variations-test.php index d7b2b98b75f5c..ca84d3a93ec4e 100644 --- a/phpunit/block-supports/block-style-variations-test.php +++ b/phpunit/block-supports/block-style-variations-test.php @@ -98,10 +98,11 @@ public function filter_set_theme_root() { public function test_add_registered_block_styles_to_theme_data() { switch_theme( 'block-theme' ); - // Trigger block style registration that occurs on `init` action. - // do_action( 'init' ) could be used here however this direct call - // means only the updates being tested are performed. - gutenberg_register_block_style_variations_from_theme(); + // Register theme-defined variations. + WP_Theme_JSON_Resolver_Gutenberg::get_theme_data(); + + // Register user-defined variations. + WP_Theme_JSON_Resolver_Gutenberg::get_user_data(); $variation_styles_data = array( 'color' => array( From e7b19b857228190307200b5ae9623d28d253db36 Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Tue, 18 Jun 2024 14:31:41 +0800 Subject: [PATCH 08/15] Revert change that removes the social link block when pressing backspace in the URL Popover (#61344) Co-authored-by: talldan Co-authored-by: ntsekouras Co-authored-by: alexstine --- .../block-library/src/social-link/edit.js | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/packages/block-library/src/social-link/edit.js b/packages/block-library/src/social-link/edit.js index d0444b79298e7..e70c66e458063 100644 --- a/packages/block-library/src/social-link/edit.js +++ b/packages/block-library/src/social-link/edit.js @@ -6,15 +6,11 @@ import clsx from 'clsx'; /** * WordPress dependencies */ -import { DELETE, BACKSPACE } from '@wordpress/keycodes'; -import { useDispatch } from '@wordpress/data'; - import { InspectorControls, URLPopover, URLInput, useBlockProps, - store as blockEditorStore, } from '@wordpress/block-editor'; import { useState } from '@wordpress/element'; import { @@ -36,9 +32,7 @@ const SocialLinkURLPopover = ( { setAttributes, setPopover, popoverAnchor, - clientId, } ) => { - const { removeBlock } = useDispatch( blockEditorStore ); return ( { - if ( - !! url || - event.defaultPrevented || - ! [ BACKSPACE, DELETE ].includes( - event.keyCode - ) - ) { - return; - } - removeBlock( clientId ); - } } />