Skip to content

Commit 8d5a38a

Browse files
authored
Allow themes to provide empty values for color.duotone and spacing.units and remove layout.units (#33280)
1 parent 7043eaa commit 8d5a38a

File tree

8 files changed

+205
-8
lines changed

8 files changed

+205
-8
lines changed

lib/class-wp-theme-json-gutenberg.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,8 +1086,8 @@ public function merge( $incoming ) {
10861086
foreach ( $nodes as $metadata ) {
10871087
foreach ( $to_replace as $property_path ) {
10881088
$path = array_merge( $metadata['path'], $property_path );
1089-
$node = _wp_array_get( $incoming_data, $path, array() );
1090-
if ( ! empty( $node ) ) {
1089+
$node = _wp_array_get( $incoming_data, $path, null );
1090+
if ( isset( $node ) ) {
10911091
gutenberg_experimental_set( $this->theme_json, $path, $node );
10921092
}
10931093
}

packages/block-editor/src/components/letter-spacing-control/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import useSetting from '../../components/use-setting';
2222
*/
2323
export default function LetterSpacingControl( { value, onChange } ) {
2424
const units = useCustomUnits( {
25-
availableUnits: useSetting( 'layout.units' ) || [ 'px', 'em', 'rem' ],
25+
availableUnits: useSetting( 'spacing.units' ) || [ 'px', 'em', 'rem' ],
2626
defaultValues: { px: '2', em: '.2', rem: '.2' },
2727
} );
2828
return (

packages/block-editor/src/hooks/border-width.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const BorderWidthEdit = ( props ) => {
4545
};
4646

4747
const units = useCustomUnits( {
48-
availableUnits: useSetting( 'layout.units' ) || [ 'px', 'em', 'rem' ],
48+
availableUnits: useSetting( 'spacing.units' ) || [ 'px', 'em', 'rem' ],
4949
} );
5050

5151
return (

packages/block-editor/src/hooks/layout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function LayoutPanel( { setAttributes, attributes } ) {
3939
}, [] );
4040

4141
const units = useCustomUnits( {
42-
availableUnits: useSetting( 'layout.units' ) || [
42+
availableUnits: useSetting( 'spacing.units' ) || [
4343
'%',
4444
'px',
4545
'em',

packages/block-library/src/column/edit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function ColumnEdit( {
3434
} );
3535

3636
const units = useCustomUnits( {
37-
availableUnits: useSetting( 'layout.units' ) || [
37+
availableUnits: useSetting( 'spacing.units' ) || [
3838
'%',
3939
'px',
4040
'em',

packages/block-library/src/column/edit.native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function ColumnEdit( {
6262
const [ widthUnit, setWidthUnit ] = useState( valueUnit || '%' );
6363

6464
const units = useCustomUnits( {
65-
availableUnits: useSetting( 'layout.units' ) || [
65+
availableUnits: useSetting( 'spacing.units' ) || [
6666
'%',
6767
'px',
6868
'em',

packages/block-library/src/columns/edit.native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function ColumnsEditContainer( {
107107
const { width } = sizes || {};
108108

109109
const units = useCustomUnits( {
110-
availableUnits: useSetting( 'layout.units' ) || [
110+
availableUnits: useSetting( 'spacing.units' ) || [
111111
'%',
112112
'px',
113113
'em',

phpunit/class-wp-theme-json-test.php

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,203 @@ public function test_merge_incoming_data() {
708708
$this->assertEqualSetsWithIndex( $expected, $actual );
709709
}
710710

711+
public function test_merge_incoming_data_empty_presets() {
712+
$theme_json = new WP_Theme_JSON_Gutenberg(
713+
array(
714+
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
715+
'settings' => array(
716+
'color' => array(
717+
'duotone' => array(
718+
array(
719+
'slug' => 'value',
720+
'colors' => array( 'red', 'green' ),
721+
),
722+
),
723+
'gradients' => array(
724+
array(
725+
'slug' => 'gradient',
726+
'gradient' => 'gradient',
727+
),
728+
),
729+
'palette' => array(
730+
array(
731+
'slug' => 'red',
732+
'color' => 'red',
733+
),
734+
),
735+
),
736+
'spacing' => array(
737+
'units' => array( 'px', 'em' ),
738+
),
739+
'typography' => array(
740+
'fontSizes' => array(
741+
array(
742+
'slug' => 'size',
743+
'value' => 'size',
744+
),
745+
),
746+
),
747+
),
748+
)
749+
);
750+
751+
$theme_json->merge(
752+
new WP_Theme_JSON_Gutenberg(
753+
array(
754+
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
755+
'settings' => array(
756+
'color' => array(
757+
'duotone' => array(),
758+
'gradients' => array(),
759+
'palette' => array(),
760+
),
761+
'spacing' => array(
762+
'units' => array(),
763+
),
764+
'typography' => array(
765+
'fontSizes' => array(),
766+
),
767+
),
768+
)
769+
)
770+
);
771+
772+
$actual = $theme_json->get_raw_data();
773+
$expected = array(
774+
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
775+
'settings' => array(
776+
'color' => array(
777+
'duotone' => array(),
778+
'gradients' => array(
779+
'theme' => array(),
780+
),
781+
'palette' => array(
782+
'theme' => array(),
783+
),
784+
),
785+
'spacing' => array(
786+
'units' => array(),
787+
),
788+
'typography' => array(
789+
'fontSizes' => array(
790+
'theme' => array(),
791+
),
792+
),
793+
),
794+
);
795+
796+
$this->assertEqualSetsWithIndex( $expected, $actual );
797+
}
798+
799+
public function test_merge_incoming_data_null_presets() {
800+
$theme_json = new WP_Theme_JSON_Gutenberg(
801+
array(
802+
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
803+
'settings' => array(
804+
'color' => array(
805+
'duotone' => array(
806+
array(
807+
'slug' => 'value',
808+
'colors' => array( 'red', 'green' ),
809+
),
810+
),
811+
'gradients' => array(
812+
array(
813+
'slug' => 'gradient',
814+
'gradient' => 'gradient',
815+
),
816+
),
817+
'palette' => array(
818+
array(
819+
'slug' => 'red',
820+
'color' => 'red',
821+
),
822+
),
823+
),
824+
'spacing' => array(
825+
'units' => array( 'px', 'em' ),
826+
),
827+
'typography' => array(
828+
'fontSizes' => array(
829+
array(
830+
'slug' => 'size',
831+
'value' => 'size',
832+
),
833+
),
834+
),
835+
),
836+
)
837+
);
838+
839+
$theme_json->merge(
840+
new WP_Theme_JSON_Gutenberg(
841+
array(
842+
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
843+
'settings' => array(
844+
'color' => array(
845+
'custom' => false,
846+
),
847+
'spacing' => array(
848+
'customMargin' => false,
849+
),
850+
'typography' => array(
851+
'customLineHeight' => false,
852+
),
853+
),
854+
)
855+
)
856+
);
857+
858+
$actual = $theme_json->get_raw_data();
859+
$expected = array(
860+
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
861+
'settings' => array(
862+
'color' => array(
863+
'custom' => false,
864+
'duotone' => array(
865+
array(
866+
'slug' => 'value',
867+
'colors' => array( 'red', 'green' ),
868+
),
869+
),
870+
'gradients' => array(
871+
'theme' => array(
872+
array(
873+
'slug' => 'gradient',
874+
'gradient' => 'gradient',
875+
),
876+
),
877+
),
878+
'palette' => array(
879+
'theme' => array(
880+
array(
881+
'slug' => 'red',
882+
'color' => 'red',
883+
),
884+
),
885+
),
886+
),
887+
'spacing' => array(
888+
'customMargin' => false,
889+
'units' => array( 'px', 'em' ),
890+
),
891+
'typography' => array(
892+
'customLineHeight' => false,
893+
'fontSizes' => array(
894+
'theme' => array(
895+
array(
896+
'slug' => 'size',
897+
'value' => 'size',
898+
),
899+
),
900+
),
901+
),
902+
),
903+
);
904+
905+
$this->assertEqualSetsWithIndex( $expected, $actual );
906+
}
907+
711908
function test_remove_insecure_properties_removes_unsafe_styles() {
712909
$actual = WP_Theme_JSON_Gutenberg::remove_insecure_properties(
713910
array(

0 commit comments

Comments
 (0)