Editor: disable shadow.defaultPresets for classic themes.

With this change default shadow presets are never shown for classic themes, and classic themes have no options for adding custom ones.
This essentially reverts [57717] and [57827] / [57828], which had unintended consequences.

Props ajlende, oandregal, madhudollu, swissspidy, get_dave, andrewserong, desrosj.
Fixes #60815.

git-svn-id: https://develop.svn.wordpress.org/trunk@57885 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Pascal Birchler 2024-03-27 15:58:46 +00:00
parent 5dff254d49
commit 9bf06950a1
6 changed files with 133 additions and 9 deletions

View File

@ -312,6 +312,17 @@ class WP_Theme_JSON_Resolver {
}
$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;

View File

@ -658,7 +658,7 @@ class WP_Theme_JSON {
* @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 @@ class WP_Theme_JSON {
array( 'spacing', 'margin' ),
array( 'spacing', 'padding' ),
array( 'typography', 'lineHeight' ),
array( 'shadow', 'defaultPresets' ),
);
/**

View File

@ -191,7 +191,7 @@
"text": true
},
"shadow": {
"defaultPresets": false,
"defaultPresets": true,
"presets": [
{
"name": "Natural",

View File

@ -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": {

View File

@ -293,9 +293,6 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
'typography' => array(
'lineHeight' => true,
),
'shadow' => array(
'defaultPresets' => true,
),
'blocks' => array(
'core/paragraph' => array(
'typography' => array(
@ -334,9 +331,6 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
'typography' => array(
'lineHeight' => false,
),
'shadow' => array(
'defaultPresets' => true,
),
),
),
);

View File

@ -201,6 +201,22 @@ class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase {
'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 @@ class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase {
),
),
),
'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 @@ class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase {
$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 );
}
}