wp_typography_get_preset_inline_style_value

函式
wp_typography_get_preset_inline_style_value ( $style_value, $css_property )
引數
  • (string) $style_value A raw style value for a single typography feature from a block's style attribute.
    Required:
  • (string) $css_property Slug for the CSS property the inline style sets.
    Required:
返回值
  • (string) A CSS inline style value.
定義位置
相關方法
wp_typography_get_css_variable_inline_stylewp_get_typography_font_size_valuewp_maybe_inline_styleswp_add_inline_stylerest_get_best_type_for_value
引入
6.1.0
棄用
-

wp_typography_get_preset_inline_style_value: 這個函式用來獲取一個預設的內聯樣式的值。它接受預設的內聯風格名稱作為引數並返回其值。

為一個排版特徵生成一個內聯樣式值,例如文字裝飾、文字轉換和字型樣式。

注意: 這個函式是為了向後相容。
* 它對於解析包含預設排版樣式的舊塊是必要的。
* 它主要取代了被棄用的`wp_typography_get_css_variable_inline_style()`,但跳過了編譯CSS宣告,因為樣式引擎接管了這個角色。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_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 WordPress/gutenberg#27555.
* A preset CSS variable is the style.
* Gets 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 ) );
// Return the actual CSS inline style value,
// e.g. `var(--wp--preset--text-decoration--underline);`.
return sprintf( 'var(--wp--preset--%s--%s);', $css_property, $slug );
}
function wp_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 WordPress/gutenberg#27555. * A preset CSS variable is the style. * Gets 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 ) ); // Return the actual CSS inline style value, // e.g. `var(--wp--preset--text-decoration--underline);`. return sprintf( 'var(--wp--preset--%s--%s);', $css_property, $slug ); }
function wp_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 WordPress/gutenberg#27555.
	 * A preset CSS variable is the style.
	 * Gets 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 ) );

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

常見問題

FAQs
檢視更多 >