WP_Theme_JSON::get_property_value( array $styles, array $path, array $theme_json = null ): string|array

In this article

Returns the style property for the given path.

Description

It also converts references to a path to the value stored at that location, e.g.
{ "ref": "style.color.background" } => "#fff".

Parameters

$stylesarrayrequired
Styles subtree.
$patharrayrequired
Which property to process.
$theme_jsonarrayoptional
Theme JSON array.

Default:null

Return

string|array Style property value.

Source

			strtolower( _wp_to_kebab_case( $property ) )
		);

		if ( is_array( $value ) ) {
			$new_prefix        = $new_key . $token;
			$flattened_subtree = static::flatten_tree( $value, $new_prefix, $token );
			foreach ( $flattened_subtree as $subtree_key => $subtree_value ) {
				$result[ $subtree_key ] = $subtree_value;
			}
		} else {
			$result[ $new_key ] = $value;
		}
	}
	return $result;
}

/**
 * Given a styles array, it extracts the style properties
 * and adds them to the $declarations array following the format:
 *
 *     array(
 *       'name'  => 'property_name',
 *       'value' => 'property_value,
 *     )
 *
 * @since 5.8.0
 * @since 5.9.0 Added the `$settings` and `$properties` parameters.
 * @since 6.1.0 Added `$theme_json`, `$selector`, and `$use_root_padding` parameters.
 * @since 6.5.0 Output a `min-height: unset` rule when `aspect-ratio` is set.
 *
 * @param array   $styles Styles to process.
 * @param array   $settings Theme settings.
 * @param array   $properties Properties metadata.
 * @param array   $theme_json Theme JSON array.
 * @param string  $selector The style block selector.
 * @param boolean $use_root_padding Whether to add custom properties at root level.
 * @return array  Returns the modified $declarations.
 */
protected static function compute_style_properties( $styles, $settings = array(), $properties = null, $theme_json = null, $selector = null, $use_root_padding = null ) {
	if ( null === $properties ) {
		$properties = static::PROPERTIES_METADATA;
	}

	$declarations = array();
	if ( empty( $styles ) ) {

Changelog

VersionDescription
6.3.0It no longer converts the internal format "var:preset|color|secondary" to the standard form "–wp–preset–color–secondary".
This is already done by the sanitize method, so every property will be in the standard form.
6.1.0Added the $theme_json parameter.
5.9.0Added support for values of array type, which are returned as is.
5.8.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.