wp_normalize_state_preset_vars()
Converts internal preset references to CSS custom property references.
State styles are emitted as CSS rules and cannot rely on preset classnames. Converting var:preset|color|contrast to var(--wp--preset--color--contrast) ensures preset values are emitted as declarations by the style engine.
No Hooks.
Returns
mixed. Normalized style value.
Usage
wp_normalize_state_preset_vars( $value );
- $value(mixed) (required)
- Style value to normalize.
Changelog
| Since 7.1.0 | Introduced. |
wp_normalize_state_preset_vars() wp normalize state preset vars code WP 7.1.2
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;
}
$unwrapped_name = str_replace( '|', '--', substr( $value, strlen( 'var:' ) ) );
return "var(--wp--$unwrapped_name)";
}