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".


Top ↑

Parameters

$styles

(array) (Required) Styles subtree.

$path

(array) (Required) Which property to process.


Top ↑

Return

(string|array) Style property value.


Top ↑

Source

File: wp-includes/class-wp-theme-json.php

	private 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;
	}


Top ↑

Changelog

Changelog
Version Description
5.9.0 Added support for values of array type, which are returned as is.
5.8.0 Introduced.

Top ↑

User Contributed Notes

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