Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Allow themes to provide empty values for color.duotone and `spacing…
….units` and remove `layout.units` (#33280)
  • Loading branch information
nosolosw authored and youknowriad committed Jul 12, 2021
commit d6cbacad1a17dd5e9d052ba4cd7c54ae8831bb9c
4 changes: 2 additions & 2 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -1172,8 +1172,8 @@ public function merge( $incoming ) {
foreach ( $nodes as $metadata ) {
foreach ( $to_replace as $property_path ) {
$path = array_merge( $metadata['path'], $property_path );
$node = _wp_array_get( $incoming_data, $path, array() );
if ( ! empty( $node ) ) {
$node = _wp_array_get( $incoming_data, $path, null );
if ( isset( $node ) ) {
gutenberg_experimental_set( $this->theme_json, $path, $node );
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/hooks/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function LayoutPanel( { setAttributes, attributes } ) {
}, [] );

const units = useCustomUnits( {
availableUnits: useSetting( 'layout.units' ) || [
availableUnits: useSetting( 'spacing.units' ) || [
'%',
'px',
'em',
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/column/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function ColumnEdit( {
} );

const units = useCustomUnits( {
availableUnits: useSetting( 'layout.units' ) || [
availableUnits: useSetting( 'spacing.units' ) || [
'%',
'px',
'em',
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/column/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function ColumnEdit( {
const [ widthUnit, setWidthUnit ] = useState( valueUnit || '%' );

const units = useCustomUnits( {
availableUnits: useSetting( 'layout.units' ) || [
availableUnits: useSetting( 'spacing.units' ) || [
'%',
'px',
'em',
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/columns/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function ColumnsEditContainer( {
const { width } = sizes || {};

const units = useCustomUnits( {
availableUnits: useSetting( 'layout.units' ) || [
availableUnits: useSetting( 'spacing.units' ) || [
'%',
'px',
'em',
Expand Down
197 changes: 197 additions & 0 deletions phpunit/class-wp-theme-json-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,203 @@ public function test_merge_incoming_data() {
$this->assertEqualSetsWithIndex( $expected, $actual );
}

public function test_merge_incoming_data_empty_presets() {
$theme_json = new WP_Theme_JSON_Gutenberg(
array(
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
'settings' => array(
'color' => array(
'duotone' => array(
array(
'slug' => 'value',
'colors' => array( 'red', 'green' ),
),
),
'gradients' => array(
array(
'slug' => 'gradient',
'gradient' => 'gradient',
),
),
'palette' => array(
array(
'slug' => 'red',
'color' => 'red',
),
),
),
'spacing' => array(
'units' => array( 'px', 'em' ),
),
'typography' => array(
'fontSizes' => array(
array(
'slug' => 'size',
'value' => 'size',
),
),
),
),
)
);

$theme_json->merge(
new WP_Theme_JSON_Gutenberg(
array(
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
'settings' => array(
'color' => array(
'duotone' => array(),
'gradients' => array(),
'palette' => array(),
),
'spacing' => array(
'units' => array(),
),
'typography' => array(
'fontSizes' => array(),
),
),
)
)
);

$actual = $theme_json->get_raw_data();
$expected = array(
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
'settings' => array(
'color' => array(
'duotone' => array(),
'gradients' => array(
'theme' => array(),
),
'palette' => array(
'theme' => array(),
),
),
'spacing' => array(
'units' => array(),
),
'typography' => array(
'fontSizes' => array(
'theme' => array(),
),
),
),
);

$this->assertEqualSetsWithIndex( $expected, $actual );
}

public function test_merge_incoming_data_null_presets() {
$theme_json = new WP_Theme_JSON_Gutenberg(
array(
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
'settings' => array(
'color' => array(
'duotone' => array(
array(
'slug' => 'value',
'colors' => array( 'red', 'green' ),
),
),
'gradients' => array(
array(
'slug' => 'gradient',
'gradient' => 'gradient',
),
),
'palette' => array(
array(
'slug' => 'red',
'color' => 'red',
),
),
),
'spacing' => array(
'units' => array( 'px', 'em' ),
),
'typography' => array(
'fontSizes' => array(
array(
'slug' => 'size',
'value' => 'size',
),
),
),
),
)
);

$theme_json->merge(
new WP_Theme_JSON_Gutenberg(
array(
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
'settings' => array(
'color' => array(
'custom' => false,
),
'spacing' => array(
'customMargin' => false,
),
'typography' => array(
'customLineHeight' => false,
),
),
)
)
);

$actual = $theme_json->get_raw_data();
$expected = array(
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
'settings' => array(
'color' => array(
'custom' => false,
'duotone' => array(
array(
'slug' => 'value',
'colors' => array( 'red', 'green' ),
),
),
'gradients' => array(
'theme' => array(
array(
'slug' => 'gradient',
'gradient' => 'gradient',
),
),
),
'palette' => array(
'theme' => array(
array(
'slug' => 'red',
'color' => 'red',
),
),
),
),
'spacing' => array(
'customMargin' => false,
'units' => array( 'px', 'em' ),
),
'typography' => array(
'customLineHeight' => false,
'fontSizes' => array(
'theme' => array(
array(
'slug' => 'size',
'value' => 'size',
),
),
),
),
),
);

$this->assertEqualSetsWithIndex( $expected, $actual );
}

function test_remove_insecure_properties_removes_unsafe_styles() {
$actual = WP_Theme_JSON_Gutenberg::remove_insecure_properties(
array(
Expand Down