diff --git a/src/wp-includes/class-wp-theme-json-resolver.php b/src/wp-includes/class-wp-theme-json-resolver.php index 44db8364f1092..3ad5ecf0c4dde 100644 --- a/src/wp-includes/class-wp-theme-json-resolver.php +++ b/src/wp-includes/class-wp-theme-json-resolver.php @@ -312,6 +312,17 @@ public static function get_theme_data( $deprecated = array(), $options = array() } $theme_support_data['settings']['color']['defaultGradients'] = $default_gradients; + if ( ! isset( $theme_support_data['settings']['shadow'] ) ) { + $theme_support_data['settings']['shadow'] = array(); + } + /* + * Shadow presets are explicitly disabled for classic themes until a + * decision is made for whether the default presets should match the + * other presets or if they should be disabled by default in classic + * themes. See https://github.com/WordPress/gutenberg/issues/59989. + */ + $theme_support_data['settings']['shadow']['defaultPresets'] = false; + // Allow themes to enable link color setting via theme_support. if ( current_theme_supports( 'link-color' ) ) { $theme_support_data['settings']['color']['link'] = true; diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 2a4303b5a308f..d754da957a76a 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -658,7 +658,7 @@ public static function get_element_class_name( $element ) { * @since 6.0.0 * @since 6.2.0 Added `dimensions.minHeight` and `position.sticky`. * @since 6.4.0 Added `background.backgroundImage`. - * @since 6.5.0 Added `background.backgroundSize`, `dimensions.aspectRatio`, and `shadow.defaultPresets`. + * @since 6.5.0 Added `background.backgroundSize` and `dimensions.aspectRatio`. * @var array */ const APPEARANCE_TOOLS_OPT_INS = array( @@ -679,7 +679,6 @@ public static function get_element_class_name( $element ) { array( 'spacing', 'margin' ), array( 'spacing', 'padding' ), array( 'typography', 'lineHeight' ), - array( 'shadow', 'defaultPresets' ), ); /** diff --git a/src/wp-includes/theme.json b/src/wp-includes/theme.json index 3ce416d62e7b2..d9ed47816c95c 100644 --- a/src/wp-includes/theme.json +++ b/src/wp-includes/theme.json @@ -191,7 +191,7 @@ "text": true }, "shadow": { - "defaultPresets": false, + "defaultPresets": true, "presets": [ { "name": "Natural", diff --git a/tests/phpunit/data/themedir1/block-theme/theme.json b/tests/phpunit/data/themedir1/block-theme/theme.json index 212ef5df78f7e..fb24069fb6429 100644 --- a/tests/phpunit/data/themedir1/block-theme/theme.json +++ b/tests/phpunit/data/themedir1/block-theme/theme.json @@ -49,6 +49,20 @@ "padding": true, "blockGap": true }, + "shadow": { + "presets": [ + { + "name": "Natural", + "slug": "natural", + "shadow": "2px 2px 3px #000" + }, + { + "name": "Test", + "slug": "test", + "shadow": "2px 2px 3px #000" + } + ] + }, "blocks": { "core/paragraph": { "color": { diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php index f38b7f21dbee9..3a72c72981beb 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -293,9 +293,6 @@ public function test_get_settings_appearance_true_opts_in() { 'typography' => array( 'lineHeight' => true, ), - 'shadow' => array( - 'defaultPresets' => true, - ), 'blocks' => array( 'core/paragraph' => array( 'typography' => array( @@ -334,9 +331,6 @@ public function test_get_settings_appearance_true_opts_in() { 'typography' => array( 'lineHeight' => false, ), - 'shadow' => array( - 'defaultPresets' => true, - ), ), ), ); diff --git a/tests/phpunit/tests/theme/wpThemeJsonResolver.php b/tests/phpunit/tests/theme/wpThemeJsonResolver.php index 0e91e27bc2e45..15e3a9a71dea6 100644 --- a/tests/phpunit/tests/theme/wpThemeJsonResolver.php +++ b/tests/phpunit/tests/theme/wpThemeJsonResolver.php @@ -201,6 +201,22 @@ public function test_translations_are_applied() { 'padding' => true, 'blockGap' => true, ), + 'shadow' => array( + 'presets' => array( + 'theme' => array( + array( + 'name' => 'Natural', + 'slug' => 'natural', + 'shadow' => '2px 2px 3px #000', + ), + array( + 'name' => 'Test', + 'slug' => 'test', + 'shadow' => '2px 2px 3px #000', + ), + ), + ), + ), 'blocks' => array( 'core/paragraph' => array( 'color' => array( @@ -559,6 +575,22 @@ public function test_merges_child_theme_json_into_parent_theme_json() { ), ), ), + 'shadow' => array( + 'presets' => array( + 'theme' => array( + array( + 'name' => 'Natural', + 'slug' => 'natural', + 'shadow' => '2px 2px 3px #000', + ), + array( + 'name' => 'Test', + 'slug' => 'test', + 'shadow' => '2px 2px 3px #000', + ), + ), + ), + ), 'spacing' => array( 'blockGap' => true, 'units' => array( 'rem' ), @@ -1070,4 +1102,78 @@ public function test_get_style_variations_returns_all_variations() { $actual_settings ); } + + /** + * @ticket 60815 + */ + public function test_theme_shadow_presets_do_not_override_default_shadow_presets() { + switch_theme( 'block-theme' ); + + $theme_json_resolver = new WP_Theme_JSON_Resolver(); + $theme_json = $theme_json_resolver->get_merged_data(); + $actual_settings = $theme_json->get_settings()['shadow']['presets']; + + $expected_settings = array( + 'default' => array( + array( + 'name' => 'Natural', + 'shadow' => '6px 6px 9px rgba(0, 0, 0, 0.2)', + 'slug' => 'natural', + ), + array( + 'name' => 'Deep', + 'shadow' => '12px 12px 50px rgba(0, 0, 0, 0.4)', + 'slug' => 'deep', + ), + array( + 'name' => 'Sharp', + 'shadow' => '6px 6px 0px rgba(0, 0, 0, 0.2)', + 'slug' => 'sharp', + ), + array( + 'name' => 'Outlined', + 'shadow' => '6px 6px 0px -3px rgba(255, 255, 255, 1), 6px 6px rgba(0, 0, 0, 1)', + 'slug' => 'outlined', + ), + array( + 'name' => 'Crisp', + 'shadow' => '6px 6px 0px rgba(0, 0, 0, 1)', + 'slug' => 'crisp', + ), + ), + 'theme' => array( + array( + 'name' => 'Test', + 'shadow' => '2px 2px 3px #000', + 'slug' => 'test', + ), + ), + ); + + wp_recursive_ksort( $actual_settings ); + wp_recursive_ksort( $expected_settings ); + + $this->assertSame( + $expected_settings, + $actual_settings + ); + } + + /** + * @ticket 60815 + */ + public function test_shadow_default_presets_value_for_block_and_classic_themes() { + $theme_json_resolver = new WP_Theme_JSON_Resolver(); + $theme_json = $theme_json_resolver->get_merged_data(); + + $default_presets_for_classic = $theme_json->get_settings()['shadow']['defaultPresets']; + $this->assertFalse( $default_presets_for_classic ); + + switch_theme( 'block-theme' ); + $theme_json_resolver = new WP_Theme_JSON_Resolver(); + $theme_json = $theme_json_resolver->get_merged_data(); + + $default_presets_for_block = $theme_json->get_settings()['shadow']['defaultPresets']; + $this->assertTrue( $default_presets_for_block ); + } }