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


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

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


Top ↑

Changelog

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

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.