Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions backport-changelog/7.2/14190.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
https://github.com/WordPress/wordpress-develop/pull/14190

* https://github.com/WordPress/gutenberg/pull/84523
* https://github.com/WordPress/gutenberg/pull/84529
8 changes: 5 additions & 3 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -4456,11 +4456,13 @@ public function merge( $incoming ) {
$scale_path = array( 'settings', 'spacing', 'spacingScale', $origin );

// Apply the base spacing scale to the current layer.
$base_spacing_scale = _wp_array_get( $this->theme_json, $scale_path, array() );
$flattened_spacing_scale = array_replace( $flattened_spacing_scale, $base_spacing_scale );
$base_spacing_scale = _wp_array_get( $this->theme_json, $scale_path, array() );
if ( is_array( $base_spacing_scale ) ) {
$flattened_spacing_scale = array_replace( $flattened_spacing_scale, $base_spacing_scale );
}

$spacing_scale = _wp_array_get( $incoming_data, $scale_path, null );
if ( ! isset( $spacing_scale ) ) {
if ( ! is_array( $spacing_scale ) ) {
continue;
}

Expand Down
52 changes: 52 additions & 0 deletions phpunit/class-wp-theme-json-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5549,6 +5549,58 @@ public function data_get_stylesheet_ignores_values_of_unexpected_types() {
);
}

public function test_merge_does_not_generate_spacing_sizes_from_a_non_array_per_origin_spacing_scale() {
$theme_json = new WP_Theme_JSON_Gutenberg(
array(
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
'settings' => array(
'spacing' => array(
'spacingScale' => array(
'operator' => '*',
'increment' => 1.5,
'steps' => 3,
'mediumStep' => 1.5,
'unit' => 'rem',
),
),
),
),
'default'
);
$theme_json->merge(
new WP_Theme_JSON_Gutenberg(
array(
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
'settings' => array( 'spacing' => array( 'spacingScale' => array( 'theme' => '1.5' ) ) ),
)
)
);
$spacing_sizes = $theme_json->get_settings()['spacing']['spacingSizes'];

$this->assertSame( array(), $spacing_sizes['theme'], 'The theme layer with a non-array spacing scale should generate no sizes.' );
$this->assertSame(
array(
array(
'name' => 'Small',
'slug' => '40',
'size' => '1rem',
),
array(
'name' => 'Medium',
'slug' => '50',
'size' => '1.5rem',
),
array(
'name' => 'Large',
'slug' => '60',
'size' => '2.25rem',
),
),
$spacing_sizes['default'],
'The default layer sizes should be unaffected.'
);
}

/**
* @dataProvider data_get_styles_for_block_with_style_variations
*
Expand Down
Loading