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

Typography block supports: sync with 6.1 backport #43928

Merged
merged 1 commit into from
Dec 19, 2022
Merged
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
35 changes: 22 additions & 13 deletions lib/block-supports/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,27 +168,34 @@ function gutenberg_apply_typography_support( $block_type, $block_attributes ) {
}

/**
* Note: this method is for backwards compatibility.
* It mostly replaces `gutenberg_typography_get_css_variable_inline_style()`.
*
* Generates an inline style value for a typography feature e.g. text decoration,
* text transform, and font style.
*
* @param string $style_value A raw style value for a single typography feature from a block's style attribute.
* @param string $css_property Slug for the CSS property the inline style sets.
* Note: This function is for backwards compatibility.
* * It is necessary to parse older blocks whose typography styles contain presets.
* * It mostly replaces the deprecated `wp_typography_get_css_variable_inline_style()`,
* but skips compiling a CSS declaration as the style engine takes over this role.
*
* @link https://github.com/wordpress/gutenberg/pull/27555
*
* @since 6.1.0
*
* @return string? A CSS inline style value.
* @param string $style_value A raw style value for a single typography feature from a block's style attribute.
* @param string $css_property Slug for the CSS property the inline style sets.
* @return string A CSS inline style value.
*/
function gutenberg_typography_get_preset_inline_style_value( $style_value, $css_property ) {
// If the style value is not a preset CSS variable go no further.
if ( empty( $style_value ) || ! str_contains( $style_value, "var:preset|{$css_property}|" ) ) {
return $style_value;
}

// For backwards compatibility.
// Presets were removed in https://github.com/WordPress/gutenberg/pull/27555.
// We have a preset CSS variable as the style.
// Get the style value from the string and return CSS style.
/*
* For backwards compatibility.
* Presets were removed in WordPress/gutenberg#27555.
* We have a preset CSS variable as the style.
* Get the style value from the string and return CSS style.
*/
$index_to_splice = strrpos( $style_value, '|' ) + 1;
$slug = _wp_to_kebab_case( substr( $style_value, $index_to_splice ) );

Expand All @@ -197,14 +204,16 @@ function gutenberg_typography_get_preset_inline_style_value( $style_value, $css_
}

/**
* Deprecated.
* This method is no longer used and will have to be deprecated in Core.
* This method is no longer used and has been deprecated in Core since 6.1.0.
*
* It can be deleted once migrated to the next WordPress version.
* It can be deleted once Gutenberg's minimum supported WordPress version is >= 6.1
*
* Generates an inline style for a typography feature e.g. text decoration,
* text transform, and font style.
*
* @since 5.8.0
* @deprecated 6.1.0
*
* @param array $attributes Block's attributes.
* @param string $feature Key for the feature within the typography styles.
* @param string $css_property Slug for the CSS property the inline style sets.
Expand Down