From 0cde12a8a67dac81212d47da0d52b1e88e7f9431 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Fri, 18 Oct 2024 12:35:56 +0530 Subject: [PATCH 1/3] Performance assessment for get_valid_block_style_variations() --- src/wp-includes/class-wp-theme-json.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 8603a4cbbd169..2ab8ab77db2da 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -759,9 +759,10 @@ public function __construct( $theme_json = array( 'version' => self::LATEST_SCHE } $this->theme_json = WP_Theme_JSON_Schema::migrate( $theme_json, $origin ); - $valid_block_names = array_keys( static::get_blocks_metadata() ); + $blocks_metadata = static::get_blocks_metadata(); + $valid_block_names = array_keys( $blocks_metadata ); $valid_element_names = array_keys( static::ELEMENTS ); - $valid_variations = static::get_valid_block_style_variations(); + $valid_variations = static::get_valid_block_style_variations( $blocks_metadata ); $this->theme_json = static::unwrap_shared_block_style_variations( $this->theme_json, $valid_variations ); $this->theme_json = static::sanitize( $this->theme_json, $valid_block_names, $valid_element_names, $valid_variations ); $this->theme_json = static::maybe_opt_in_into_settings( $this->theme_json ); @@ -3478,9 +3479,10 @@ public static function remove_insecure_properties( $theme_json, $origin = 'theme $theme_json = WP_Theme_JSON_Schema::migrate( $theme_json, $origin ); - $valid_block_names = array_keys( static::get_blocks_metadata() ); + $blocks_metadata = static::get_blocks_metadata(); + $valid_block_names = array_keys( $blocks_metadata ); $valid_element_names = array_keys( static::ELEMENTS ); - $valid_variations = static::get_valid_block_style_variations(); + $valid_variations = static::get_valid_block_style_variations( $blocks_metadata ); $theme_json = static::sanitize( $theme_json, $valid_block_names, $valid_element_names, $valid_variations ); @@ -4527,12 +4529,15 @@ function ( $matches ) use ( $variation_class ) { * Collects valid block style variations keyed by block type. * * @since 6.6.0 + * @since n.e.x.t Added the `$blocks_metadata` parameter. * + * @param array $blocks_metadata Optional list of selectors per block. * @return array Valid block style variations by block type. */ - protected static function get_valid_block_style_variations() { + protected static function get_valid_block_style_variations( $blocks_metadata = array() ) { $valid_variations = array(); - foreach ( self::get_blocks_metadata() as $block_name => $block_meta ) { + $blocks_metadata = empty( $blocks_metadata ) ? static::get_blocks_metadata() : $blocks_metadata; + foreach ( $blocks_metadata as $block_name => $block_meta ) { if ( ! isset( $block_meta['styleVariations'] ) ) { continue; } From 50ea7428645bddce59b798b3f857e418e0c0b703 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Thu, 24 Oct 2024 12:46:49 +0530 Subject: [PATCH 2/3] Add version number --- src/wp-includes/class-wp-theme-json.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index f3d49aec19b16..b2daa79ec94af 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -4533,7 +4533,7 @@ function ( $matches ) use ( $variation_class ) { * Collects valid block style variations keyed by block type. * * @since 6.6.0 - * @since n.e.x.t Added the `$blocks_metadata` parameter. + * @since 6.8.0 Added the `$blocks_metadata` parameter. * * @param array $blocks_metadata Optional list of selectors per block. * @return array Valid block style variations by block type. From 2e149fd7c19739b960d13fe34b60e5fb0f76ddad Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Fri, 25 Oct 2024 09:03:16 +0530 Subject: [PATCH 3/3] Accept docblock suggestion Co-authored-by: Felix Arntz --- src/wp-includes/class-wp-theme-json.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index b2daa79ec94af..134917670b980 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -4535,7 +4535,7 @@ function ( $matches ) use ( $variation_class ) { * @since 6.6.0 * @since 6.8.0 Added the `$blocks_metadata` parameter. * - * @param array $blocks_metadata Optional list of selectors per block. + * @param array $blocks_metadata Optional. List of metadata per block. Default is the metadata for all blocks. * @return array Valid block style variations by block type. */ protected static function get_valid_block_style_variations( $blocks_metadata = array() ) {