WP_Theme_JSON::get_property_value() WordPress Method
The WP_Theme_JSON::get_property_value() method is used to retrieve the value of a property from a JSON-encoded string.
WP_Theme_JSON::get_property_value( array $styles, array $path ) #
Returns the style property for the given path.
Description
It also converts CSS Custom Property stored as "var:preset|color|secondary" to the form "–wp–preset–color–secondary".
Parameters
- $styles
(array)(Required)Styles subtree.
- $path
(array)(Required)Which property to process.
Return
(string|array) Style property value.
Source
File: wp-includes/class-wp-theme-json.php
protected static function get_property_value( $styles, $path ) { $value = _wp_array_get( $styles, $path, '' ); if ( '' === $value || is_array( $value ) ) { return $value; } $prefix = 'var:'; $prefix_len = strlen( $prefix ); $token_in = '|'; $token_out = '--'; if ( 0 === strncmp( $value, $prefix, $prefix_len ) ) { $unwrapped_name = str_replace( $token_in, $token_out, substr( $value, $prefix_len ) ); $value = "var(--wp--$unwrapped_name)"; } return $value; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.9.0 | Added support for values of array type, which are returned as is. |
5.8.0 | Introduced. |