Skip to content
Open
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
16 changes: 16 additions & 0 deletions src/wp-includes/block-supports/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function wp_register_typography_support( $block_type ) {
$has_text_decoration_support = $typography_supports['__experimentalTextDecoration'] ?? false;
$has_text_transform_support = $typography_supports['__experimentalTextTransform'] ?? false;
$has_text_indent_support = $typography_supports['textIndent'] ?? false;
$has_text_shadow_support = $typography_supports['textShadow'] ?? false;
$has_writing_mode_support = $typography_supports['__experimentalWritingMode'] ?? false;

$has_typography_support = $has_font_family_support
Expand All @@ -50,6 +51,7 @@ function wp_register_typography_support( $block_type ) {
|| $has_text_decoration_support
|| $has_text_transform_support
|| $has_text_indent_support
|| $has_text_shadow_support
|| $has_writing_mode_support;

if ( ! $block_type->attributes ) {
Expand All @@ -73,6 +75,12 @@ function wp_register_typography_support( $block_type ) {
'type' => 'string',
);
}

if ( $has_text_shadow_support && ! array_key_exists( 'textShadow', $block_type->attributes ) ) {
$block_type->attributes['textShadow'] = array(
'type' => 'string',
);
}
}

/**
Expand Down Expand Up @@ -115,6 +123,7 @@ function wp_apply_typography_support( $block_type, $block_attributes ) {
$has_text_decoration_support = $typography_supports['__experimentalTextDecoration'] ?? false;
$has_text_transform_support = $typography_supports['__experimentalTextTransform'] ?? false;
$has_text_indent_support = $typography_supports['textIndent'] ?? false;
$has_text_shadow_support = $typography_supports['textShadow'] ?? false;
$has_writing_mode_support = $typography_supports['__experimentalWritingMode'] ?? false;

// Whether to skip individual block support features.
Expand All @@ -129,6 +138,7 @@ function wp_apply_typography_support( $block_type, $block_attributes ) {
$should_skip_text_transform = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textTransform' );
$should_skip_letter_spacing = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'letterSpacing' );
$should_skip_text_indent = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textIndent' );
$should_skip_text_shadow = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textShadow' );
$should_skip_writing_mode = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'writingMode' );

$typography_block_styles = array();
Expand Down Expand Up @@ -232,6 +242,12 @@ function wp_apply_typography_support( $block_type, $block_attributes ) {
$typography_block_styles['textIndent'] = $block_attributes['style']['typography']['textIndent'] ?? null;
}

if ( $has_text_shadow_support && ! $should_skip_text_shadow ) {
$preset_text_shadow = array_key_exists( 'textShadow', $block_attributes ) ? "var:preset|text-shadow|{$block_attributes['textShadow']}" : null;
$custom_text_shadow = $block_attributes['style']['typography']['textShadow'] ?? null;
$typography_block_styles['textShadow'] = $preset_text_shadow ? $preset_text_shadow : $custom_text_shadow;
}

$attributes = array();
$classnames = array();
$styles = wp_style_engine_get_styles(
Expand Down
47 changes: 31 additions & 16 deletions src/wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class WP_Theme_JSON {
* Updated the 'prevent_override' value for font size presets to use 'typography.defaultFontSizes'
* and spacing size presets to use `spacing.defaultSpacingSizes`.
* @since 6.9.0 Added `border.radiusSizes`.
* @since 7.2.0 Added `typography.textShadowPresets`.
* @var array
*/
const PRESETS_METADATA = array(
Expand Down Expand Up @@ -188,6 +189,15 @@ class WP_Theme_JSON {
'classes' => array( '.has-$slug-font-family' => 'font-family' ),
'properties' => array( 'font-family' ),
),
array(
'path' => array( 'typography', 'textShadowPresets' ),
'prevent_override' => array( 'typography', 'defaultTextShadowPresets' ),
'use_default_names' => false,
'value_key' => 'textShadow',
'css_vars' => '--wp--preset--text-shadow--$slug',
'classes' => array( '.has-$slug-text-shadow' => 'text-shadow' ),
'properties' => array( 'text-shadow' ),
),
array(
'path' => array( 'spacing', 'spacingSizes' ),
'prevent_override' => array( 'spacing', 'defaultSpacingSizes' ),
Expand Down Expand Up @@ -419,6 +429,8 @@ class WP_Theme_JSON {
* Added support for `typography.textIndent`.
* @since 7.1.0 Added `viewport` property.
* Added support for `background.gradient`, `dimensions.minWidth` and `blockVisibility.allowEditing`.
* @since 7.2.0 Added support for `typography.textShadow`, `typography.textShadowPresets`,
* and `typography.defaultTextShadowPresets`.
* @var array
*/
const VALID_SETTINGS = array(
Expand Down Expand Up @@ -496,22 +508,25 @@ class WP_Theme_JSON {
'defaultPresets' => null,
),
'typography' => array(
'fluid' => null,
'customFontSize' => null,
'defaultFontSizes' => null,
'dropCap' => null,
'fontFamilies' => null,
'fontSizes' => null,
'fontStyle' => null,
'fontWeight' => null,
'letterSpacing' => null,
'lineHeight' => null,
'textAlign' => null,
'textColumns' => null,
'textDecoration' => null,
'textIndent' => null,
'textTransform' => null,
'writingMode' => null,
'fluid' => null,
'customFontSize' => null,
'defaultFontSizes' => null,
'dropCap' => null,
'fontFamilies' => null,
'fontSizes' => null,
'fontStyle' => null,
'fontWeight' => null,
'letterSpacing' => null,
'lineHeight' => null,
'textAlign' => null,
'textColumns' => null,
'textDecoration' => null,
'textIndent' => null,
'textTransform' => null,
'textShadow' => null,
'defaultTextShadowPresets' => null,
'textShadowPresets' => null,
'writingMode' => null,
),
'viewport' => array(
'mobile' => null,
Expand Down
13 changes: 13 additions & 0 deletions src/wp-includes/style-engine/class-wp-style-engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* background.backgroundRepeat and dimensions.aspectRatio.
* @since 6.7.0 Added support for typography.writingMode.
* @since 7.0.0 Added support for typography.textIndent.
* @since 7.2.0 Added support for typography.textShadow.
*/
#[AllowDynamicProperties]
final class WP_Style_Engine {
Expand Down Expand Up @@ -350,6 +351,18 @@ final class WP_Style_Engine {
),
'path' => array( 'typography', 'textIndent' ),
),
'textShadow' => array(
'property_keys' => array(
'default' => 'text-shadow',
),
'css_vars' => array(
'text-shadow' => '--wp--preset--text-shadow--$slug',
),
'path' => array( 'typography', 'textShadow' ),
'classnames' => array(
'has-$slug-text-shadow' => 'text-shadow',
),
),
'textTransform' => array(
'property_keys' => array(
'default' => 'text-transform',
Expand Down
33 changes: 33 additions & 0 deletions tests/phpunit/tests/block-supports/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,39 @@ public function test_should_generate_classname_for_font_family() {
$this->assertSame( $expected, $actual );
}

/**
* Tests that a classname is generated for a text shadow preset.
*
* @covers ::wp_apply_typography_support
*/
public function test_should_generate_classname_for_text_shadow() {
$this->test_block_name = 'test/text-shadow-with-class';
register_block_type(
$this->test_block_name,
array(
'api_version' => 3,
'attributes' => array(
'style' => array(
'type' => 'object',
),
),
'supports' => array(
'typography' => array(
'textShadow' => true,
),
),
)
);
$registry = WP_Block_Type_Registry::get_instance();
$block_type = $registry->get_registered( $this->test_block_name );
$block_atts = array( 'textShadow' => 'light' );

$actual = wp_apply_typography_support( $block_type, $block_atts );
$expected = array( 'class' => 'has-light-text-shadow' );

$this->assertSame( $expected, $actual );
}

/**
* Tests generating font size values, including fluid formulae, from fontSizes preset.
*
Expand Down
Loading