WP_Theme_JSON::compute_theme_vars() WordPress Method

The WP_Theme_JSON::compute_theme_vars() method is used to compute the theme variables for a given theme. This is done by parsing the theme's JSON file and extracting the necessary information. The method then returns an array of theme variables, which can be used by the caller to modify the theme's appearance.

WP_Theme_JSON::compute_theme_vars( array $settings ) #

Given an array of settings, it extracts the CSS Custom Properties for the custom values and adds them to the $declarations array following the format:


Description

array( ‘name’ => ‘property_name’, ‘value’ => ‘property_value, )


Top ↑

Parameters

$settings

(array)(Required)Settings to process.


Top ↑

Return

(array) Returns the modified $declarations.


Top ↑

Source

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

	protected static function compute_theme_vars( $settings ) {
		$declarations  = array();
		$custom_values = _wp_array_get( $settings, array( 'custom' ), array() );
		$css_vars      = static::flatten_tree( $custom_values );
		foreach ( $css_vars as $key => $value ) {
			$declarations[] = array(
				'name'  => '--wp--custom--' . $key,
				'value' => $value,
			);
		}

		return $declarations;
	}


Top ↑

Changelog

Changelog
VersionDescription
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.