diff --git a/lib/class-wp-theme-json-gutenberg.php b/lib/class-wp-theme-json-gutenberg.php index 0d2520ff9682a..5447b95983dc1 100644 --- a/lib/class-wp-theme-json-gutenberg.php +++ b/lib/class-wp-theme-json-gutenberg.php @@ -871,6 +871,8 @@ protected static function sanitize( $input, $valid_block_names, $valid_element_n $schema['settings']['blocks'] = $schema_settings_blocks; $schema['settings']['typography']['fontFamilies'] = static::schema_in_root_and_per_origin( static::FONT_FAMILY_SCHEMA ); + // $schema['settings']['shadow'] = null; + // Remove anything that's not present in the schema. foreach ( array( 'styles', 'settings' ) as $subtree ) { if ( ! isset( $input[ $subtree ] ) ) { @@ -1075,7 +1077,13 @@ protected static function remove_keys_not_in_schema( $tree, $schema ) { } } } elseif ( is_array( $schema[ $key ] ) && ! is_array( $tree[ $key ] ) ) { - unset( $tree[ $key ] ); + // special case for shadow, it can either be boolean or object + if ( 'shadow' === $key && ! $tree[ $key ] ) { + // Do not unset + } else { + // If the schema is an array and the value is not, remove the key. + unset( $tree[ $key ] ); + } } } diff --git a/lib/class-wp-theme-json-resolver-gutenberg.php b/lib/class-wp-theme-json-resolver-gutenberg.php index ec0d2c6bb0181..65a134a7573fa 100644 --- a/lib/class-wp-theme-json-resolver-gutenberg.php +++ b/lib/class-wp-theme-json-resolver-gutenberg.php @@ -339,6 +339,9 @@ public static function get_theme_data( $deprecated = array(), $options = array() ); } + // Disable shadow support for themes without theme.json. + $theme_support_data['settings']['shadow'] = false; + // BEGIN EXPERIMENTAL. // Allow themes to enable appearance tools via theme_support. // This feature was backported for WordPress 6.2 as of https://core.trac.wordpress.org/ticket/56487 diff --git a/schemas/json/theme.json b/schemas/json/theme.json index 8ec1de58478b8..e73ef2309c4a1 100644 --- a/schemas/json/theme.json +++ b/schemas/json/theme.json @@ -72,38 +72,47 @@ "properties": { "shadow": { "description": "Settings related to shadows.", - "type": "object", - "properties": { - "defaultPresets": { - "description": "Allow users to choose shadows from the default shadow presets.", - "type": "boolean", - "default": true - }, - "presets": { - "description": "Shadow presets for the shadow picker.\nGenerates a single custom property (`--wp--preset--shadow--{slug}`) per preset value.", - "type": "array", - "items": { - "type": "object", - "properties": { - "name": { - "description": "Name of the shadow preset, translatable.", - "type": "string" - }, - "slug": { - "description": "Kebab-case unique identifier for the shadow preset.", - "type": "string" - }, - "shadow": { - "description": "CSS box-shadow value", - "type": "string" - } + "oneOf": [ + { "type": "boolean" }, + { + "type": "object", + "properties": { + "defaultPresets": { + "description": "Allow users to choose shadows from the default shadow presets.", + "type": "boolean", + "default": true }, - "required": [ "name", "slug", "shadow" ], - "additionalProperties": false - } + "presets": { + "description": "Shadow presets for the shadow picker.\nGenerates a single custom property (`--wp--preset--shadow--{slug}`) per preset value.", + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { + "description": "Name of the shadow preset, translatable.", + "type": "string" + }, + "slug": { + "description": "Kebab-case unique identifier for the shadow preset.", + "type": "string" + }, + "shadow": { + "description": "CSS box-shadow value", + "type": "string" + } + }, + "required": [ + "name", + "slug", + "shadow" + ], + "additionalProperties": false + } + } + }, + "additionalProperties": false } - }, - "additionalProperties": false + ] } } },