wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren
wp_normalize_state_preset_vars › WordPress Function
Seit7.1.0
Veraltetn/v
› wp_normalize_state_preset_vars ( $value )
| Parameter: |
|
| Gibt zurück: |
|
| Definiert in: |
|
| 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.Quellcode
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 ) . ')';
}