wp_typography_get_css_variable_inline_style()WP 5.8.0

Deprecated from version 6.1.0. It is no longer supported and can be removed in future releases. Use wp_style_engine_get_styles() introduced in 6.1.0 instead.

Generates an inline style for a typography feature e.g. text decoration, text transform, and font style.

Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.

No Hooks.

Return

String. CSS inline style.

Usage

wp_typography_get_css_variable_inline_style( $attributes, $feature, $css_property );
$attributes(array) (required)
Block's attributes.
$feature(string) (required)
Key for the feature within the typography styles.
$css_property(string) (required)
Slug for the CSS property the inline style sets.

Notes

Changelog

Since 5.8.0 Introduced.
Deprecated since 6.1.0 Use wp_style_engine_get_styles() introduced in 6.1.0.

wp_typography_get_css_variable_inline_style() code WP 6.5.2

function wp_typography_get_css_variable_inline_style( $attributes, $feature, $css_property ) {
	_deprecated_function( __FUNCTION__, '6.1.0', 'wp_style_engine_get_styles()' );

	// Retrieve current attribute value or skip if not found.
	$style_value = _wp_array_get( $attributes, array( 'style', 'typography', $feature ), false );
	if ( ! $style_value ) {
		return;
	}

	// If we don't have a preset CSS variable, we'll assume it's a regular CSS value.
	if ( ! str_contains( $style_value, "var:preset|{$css_property}|" ) ) {
		return sprintf( '%s:%s;', $css_property, $style_value );
	}

	/*
	 * 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            = substr( $style_value, $index_to_splice );

	// Return the actual CSS inline style e.g. `text-decoration:var(--wp--preset--text-decoration--underline);`.
	return sprintf( '%s:var(--wp--preset--%s--%s);', $css_property, $css_property, $slug );
}