Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backport-changelog/7.2/14190.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/14190

* https://github.com/WordPress/gutenberg/pull/84523
14 changes: 9 additions & 5 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ public function __construct( $theme_json = array( 'version' => WP_Theme_JSON_Gut
// In addition to presets, spacingScale (which generates presets) is also keyed by origin.
$scale_path = array( 'settings', 'spacing', 'spacingScale' );
$spacing_scale = _wp_array_get( $this->theme_json, $scale_path, null );
if ( null !== $spacing_scale ) {
if ( is_array( $spacing_scale ) ) {
// If the spacingScale is not already keyed by origin.
if ( empty( array_intersect( array_keys( $spacing_scale ), static::VALID_ORIGINS ) ) ) {
_wp_array_set( $this->theme_json, $scale_path, array( $origin => $spacing_scale ) );
Expand Down Expand Up @@ -1185,7 +1185,10 @@ private static function unwrap_shared_block_style_variations( $theme_json, $vali
foreach ( $registered_variations as $variation_name ) {
$block_level_data = $new_theme_json['styles']['blocks'][ $block_type ]['variations'][ $variation_name ] ?? array();
$top_level_data = $variations[ $variation_name ] ?? array();
$merged_data = array_replace_recursive( $top_level_data, $block_level_data );
if ( ! is_array( $block_level_data ) || ! is_array( $top_level_data ) ) {
continue;
}
$merged_data = array_replace_recursive( $top_level_data, $block_level_data );
if ( ! empty( $merged_data ) ) {
_wp_array_set( $new_theme_json, array( 'styles', 'blocks', $block_type, 'variations', $variation_name ), $merged_data );
}
Expand Down Expand Up @@ -1460,7 +1463,7 @@ protected static function sanitize( $input, $valid_block_names, $valid_element_n
if ( ! empty( $input['blockTypes'] ) && is_array( $input['blockTypes'] ) ) {
$variation_pseudo_selectors = array();
foreach ( $input['blockTypes'] as $variation_block_type ) {
if ( isset( static::VALID_BLOCK_PSEUDO_SELECTORS[ $variation_block_type ] ) ) {
if ( is_string( $variation_block_type ) && isset( static::VALID_BLOCK_PSEUDO_SELECTORS[ $variation_block_type ] ) ) {
$variation_pseudo_selectors = array_merge(
$variation_pseudo_selectors,
static::VALID_BLOCK_PSEUDO_SELECTORS[ $variation_block_type ]
Expand Down Expand Up @@ -2080,7 +2083,7 @@ public function get_stylesheet( $types = array( 'variables', 'styles', 'presets'
public static function process_blocks_custom_css( $css, $selector ) {
$processed_css = '';

if ( empty( $css ) ) {
if ( empty( $css ) || ! is_string( $css ) ) {
Comment thread
ramonjd marked this conversation as resolved.
Resolved
return $processed_css;
}

Expand Down Expand Up @@ -3260,7 +3263,7 @@ protected static function get_property_value( $styles, $path, $theme_json = null
* to a path, this converts that path into the value at that path.
* For example: { "ref": "style.color.background" } => "#fff".
*/
if ( is_array( $value ) && isset( $value['ref'] ) ) {
if ( is_array( $value ) && isset( $value['ref'] ) && is_string( $value['ref'] ) ) {
$value_path = explode( '.', $value['ref'] );
$ref_value = _wp_array_get( $theme_json, $value_path, null );
// Background Image refs can refer to a string or an array containing a URL string.
Expand Down Expand Up @@ -5571,6 +5574,7 @@ private static function compute_spacing_sizes( $spacing_scale ) {
! isset( $spacing_scale['mediumStep'] ) ||
! is_numeric( $spacing_scale['mediumStep'] ) ||
! isset( $spacing_scale['unit'] ) ||
! is_string( $spacing_scale['unit'] ) ||
! isset( $spacing_scale['operator'] ) ||
( '+' !== $spacing_scale['operator'] && '*' !== $spacing_scale['operator'] ) ||
! isset( $spacing_scale['increment'] ) ||
Expand Down
70 changes: 70 additions & 0 deletions phpunit/class-wp-theme-json-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5493,6 +5493,62 @@ public function data_sanitize_with_invalid_style_variation() {
);
}

/**
* @dataProvider data_get_stylesheet_ignores_values_of_unexpected_types
*
* @param array $theme_json_data The theme.json data, without the version.
*/
public function test_get_stylesheet_ignores_values_of_unexpected_types( $theme_json_data ) {
$theme_json = new WP_Theme_JSON_Gutenberg(
array_merge( array( 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA ), $theme_json_data )
);

$this->assertIsString( $theme_json->get_stylesheet() );
}

/**
* Data provider.
*
* @return array
*/
public function data_get_stylesheet_ignores_values_of_unexpected_types() {
return array(
'element custom css as an object' => array(
array( 'styles' => array( 'elements' => array( 'link' => array( 'css' => array( 'color' => 'red' ) ) ) ) ),
),
'block custom css as a list' => array(
array( 'styles' => array( 'blocks' => array( 'core/paragraph' => array( 'css' => array( 'color: red;' ) ) ) ) ),
),
'ref as an array' => array(
array( 'styles' => array( 'color' => array( 'text' => array( 'ref' => array( 'styles', 'color' ) ) ) ) ),
),
'spacing scale as a string' => array(
array( 'settings' => array( 'spacing' => array( 'spacingScale' => '1.5' ) ) ),
),
'spacing scale unit as an array' => array(
array(
'settings' => array(
'spacing' => array(
'spacingScale' => array(
'operator' => '*',
'increment' => 1.5,
'steps' => 7,
'mediumStep' => 1.5,
'unit' => array( 'rem' ),
),
),
),
),
),
'shared style variation as a string' => array(
array( 'styles' => array( 'variations' => array( 'plain' => 'red' ) ) ),
),
'block types item as an array' => array(
array( 'blockTypes' => array( array( 'core/button' ) ) ),
),
);
}

/**
* @dataProvider data_get_styles_for_block_with_style_variations
*
Expand Down Expand Up @@ -7276,6 +7332,20 @@ public function data_process_blocks_custom_css() {
),
'expected' => '',
),
'css as an object' => array(
'input' => array(
'selector' => '.foo',
'css' => array( 'color' => 'red' ),
),
'expected' => '',
),
'css as a list of strings' => array(
'input' => array(
'selector' => '.foo',
'css' => array( 'color: red;' ),
),
'expected' => '',
),
'no nested selectors' => array(
'input' => array(
'selector' => '.foo',
Expand Down
Loading