diff --git a/wp-includes/class-wp-theme-json.php b/wp-includes/class-wp-theme-json.php index 735163553e..174f50c8f0 100644 --- a/wp-includes/class-wp-theme-json.php +++ b/wp-includes/class-wp-theme-json.php @@ -589,8 +589,15 @@ class WP_Theme_JSON { $this->theme_json = WP_Theme_JSON_Schema::migrate( $theme_json ); $valid_block_names = array_keys( static::get_blocks_metadata() ); $valid_element_names = array_keys( static::ELEMENTS ); - $theme_json = static::sanitize( $this->theme_json, $valid_block_names, $valid_element_names ); - $this->theme_json = static::maybe_opt_in_into_settings( $theme_json ); + $valid_variations = array(); + foreach ( self::get_blocks_metadata() as $block_name => $block_meta ) { + if ( ! isset( $block_meta['styleVariations'] ) ) { + continue; + } + $valid_variations[ $block_name ] = array_keys( $block_meta['styleVariations'] ); + } + $theme_json = static::sanitize( $this->theme_json, $valid_block_names, $valid_element_names, $valid_variations ); + $this->theme_json = static::maybe_opt_in_into_settings( $theme_json ); // Internally, presets are keyed by origin. $nodes = static::get_setting_nodes( $this->theme_json ); @@ -668,9 +675,10 @@ class WP_Theme_JSON { * @param array $input Structure to sanitize. * @param array $valid_block_names List of valid block names. * @param array $valid_element_names List of valid element names. + * @param array $valid_variations List of valid variations per block. * @return array The sanitized output. */ - protected static function sanitize( $input, $valid_block_names, $valid_element_names ) { + protected static function sanitize( $input, $valid_block_names, $valid_element_names, $valid_variations ) { $output = array(); @@ -728,9 +736,13 @@ class WP_Theme_JSON { $style_variation_names = array(); if ( ! empty( $input['styles']['blocks'][ $block ]['variations'] ) && - is_array( $input['styles']['blocks'][ $block ]['variations'] ) + is_array( $input['styles']['blocks'][ $block ]['variations'] ) && + isset( $valid_variations[ $block ] ) ) { - $style_variation_names = array_keys( $input['styles']['blocks'][ $block ]['variations'] ); + $style_variation_names = array_intersect( + array_keys( $input['styles']['blocks'][ $block ]['variations'] ), + $valid_variations[ $block ] + ); } $schema_styles_variations = array(); @@ -2852,8 +2864,15 @@ class WP_Theme_JSON { $valid_block_names = array_keys( static::get_blocks_metadata() ); $valid_element_names = array_keys( static::ELEMENTS ); + $valid_variations = array(); + foreach ( self::get_blocks_metadata() as $block_name => $block_meta ) { + if ( ! isset( $block_meta['styleVariations'] ) ) { + continue; + } + $valid_variations[ $block_name ] = array_keys( $block_meta['styleVariations'] ); + } - $theme_json = static::sanitize( $theme_json, $valid_block_names, $valid_element_names ); + $theme_json = static::sanitize( $theme_json, $valid_block_names, $valid_element_names, $valid_variations ); $blocks_metadata = static::get_blocks_metadata(); $style_nodes = static::get_style_nodes( $theme_json, $blocks_metadata ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 0bc14a6a62..c935a10807 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3-alpha-55911'; +$wp_version = '6.3-alpha-55912'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.