Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable settings.shadow.defaultPresets for classic themes #6309

Closed
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
11 changes: 11 additions & 0 deletions src/wp-includes/class-wp-theme-json-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -679,7 +679,6 @@ public static function get_element_class_name( $element ) {
array( 'spacing', 'margin' ),
array( 'spacing', 'padding' ),
array( 'typography', 'lineHeight' ),
array( 'shadow', 'defaultPresets' ),
ajlende marked this conversation as resolved.
Show resolved Hide resolved
);

/**
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
"text": true
},
"shadow": {
"defaultPresets": false,
"defaultPresets": true,
"presets": [
{
"name": "Natural",
Expand Down
14 changes: 14 additions & 0 deletions tests/phpunit/data/themedir1/block-theme/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 0 additions & 6 deletions tests/phpunit/tests/theme/wpThemeJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -334,9 +331,6 @@ public function test_get_settings_appearance_true_opts_in() {
'typography' => array(
'lineHeight' => false,
),
'shadow' => array(
'defaultPresets' => true,
),
),
),
);
Expand Down
106 changes: 106 additions & 0 deletions tests/phpunit/tests/theme/wpThemeJsonResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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' ),
Expand Down Expand Up @@ -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 );
}
}
Loading