WP_Style_Engine::get_css_var_value()
Util: Generates a CSS var string, e.g. var(--wp--preset--color--background) from a preset string such as var:preset|space|50.
Method of the class: WP_Style_Engine{}
No Hooks.
Return
String
. The CSS var, or an empty string if no match for slug found.
Usage
$result = WP_Style_Engine::get_css_var_value( $style_value, $css_vars );
- $style_value(string) (required)
- A single CSS preset value.
- $css_vars(string[]) (required)
- An associate array of CSS var patterns used to generate the var string.
Changelog
Since 6.1.0 | Introduced. |
WP_Style_Engine::get_css_var_value() WP Style Engine::get css var value code WP 6.5.2
protected static function get_css_var_value( $style_value, $css_vars ) { foreach ( $css_vars as $property_key => $css_var_pattern ) { $slug = static::get_slug_from_preset_value( $style_value, $property_key ); if ( static::is_valid_style_value( $slug ) ) { $var = strtr( $css_var_pattern, array( '$slug' => $slug ) ); return "var($var)"; } } return ''; }