wpseek.com
A WordPress-centric search engine for devs and theme authors
wp_normalize_state_preset_vars › WordPress Function
Since7.1.0
Deprecatedn/a
› wp_normalize_state_preset_vars ( $value )
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
| Codex: |
Converts internal preset references to CSS custom property references.
State styles are emitted as CSS rules and cannot rely on preset classnames. Convertingvar:preset|color|contrast to
var(--wp--preset--color--contrast) ensures preset values are emitted as
declarations by the style engine.Source
function wp_normalize_state_preset_vars( $value ) {
if ( is_array( $value ) ) {
foreach ( $value as $key => $nested_value ) {
$value[ $key ] = wp_normalize_state_preset_vars( $nested_value );
}
return $value;
}
if ( ! is_string( $value ) || ! str_starts_with( $value, 'var:preset|' ) ) {
return $value;
}
$parts = explode( '|', substr( $value, strlen( 'var:' ) ) );
/*
* The slug is kebab-cased when the preset's custom property is generated,
* so a reference has to be converted the same way or it points at a
* property that does not exist (`--wp--preset--font-size--3xl` for a preset
* generated as `--wp--preset--font-size--3-xl`). Mirrors
* `WP_Theme_JSON::convert_custom_properties()` and the JavaScript style
* engine's `getCSSValueFromRawStyle()`.
*/
if ( 3 === count( $parts ) ) {
$parts[2] = _wp_to_kebab_case( $parts[2] );
}
return 'var(--wp--' . implode( '--', $parts ) . ')';
}