wp_typography_get_css_variable_inline_style

函数
wp_typography_get_css_variable_inline_style ( $attributes, $feature, $css_property )
Access
Private
参数
  • (array) $attributes Block's attributes.
    Required:
  • (string) $feature Key for the feature within the typography styles.
    Required:
  • (string) $css_property Slug for the CSS property the inline style sets.
    Required:
返回值
  • (string) CSS inline style.
相关
  • wp_style_engine_get_styles()
定义位置
相关方法
wp_typography_get_preset_inline_style_valuewp_maybe_inline_styleswp_get_typography_value_and_unitwp_get_typography_font_size_valueget_typography_classes_for_block_core_search
引入
5.8.0
弃用
6.1.0

wp_typography_get_css_variable_inline_style: 这个函数用来获取一个CSS变量的内联风格值。它接受CSS变量名称作为参数并返回其值。

为一个排版特征生成一个内联样式,例如文本装饰、文本转换和字体样式。

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 ( strpos( $style_value, "var:preset|{$css_property}|" ) === false ) {
		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 );
}

常见问题

FAQs
查看更多 >