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

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

		$discard = array_search( $duplicate, array_column( $declarations, 'name' ), true );
		if ( is_numeric( $discard ) ) {
			array_splice( $declarations, $discard, 1 );
		}
	}

	return $declarations;
}

/**
 * Returns the style property for the given path.
 *
 * It also converts references to a path to the value
 * stored at that location, e.g.
 * { "ref": "style.color.background" } => "#fff".
 *
 * @since 5.8.0
 * @since 5.9.0 Added support for values of array type, which are returned as is.
 * @since 6.1.0 Added the `$theme_json` parameter.
 * @since 6.3.0 It 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.
 *
 * @param array $styles Styles subtree.
 * @param array $path   Which property to process.
 * @param array $theme_json Theme JSON array.
 * @return string|array Style property value.
 */
protected static function get_property_value( $styles, $path, $theme_json = null ) {
	$value = _wp_array_get( $styles, $path, '' );

	if ( '' === $value || null === $value ) {
		// No need to process the value further.
		return '';
	}

	/*
	 * This converts references to a path to the value at that path
	 * where the values is an array with a "ref" key, pointing to a path.
	 * For example: { "ref": "style.color.background" } => "#fff".
	 */
	if ( is_array( $value ) && isset( $value['ref'] ) ) {
		$value_path = explode( '.', $value['ref'] );
		$ref_value  = _wp_array_get( $theme_json, $value_path );

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.