WP_Theme_JSON::compute_preset_vars() WordPress Method

The compute_preset_vars() method is used to calculate the preset variables for a WordPress theme. This is done by looking at the theme's header file, and looking for the 'Preset Var' header. If this header is found, the method will attempt to calculate the value of the preset variable.

WP_Theme_JSON::compute_preset_vars( array $settings, array $origins ) #

Given the block settings, it extracts the CSS Custom Properties for the presets 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.

$origins

(array)(Required)List of origins to process.


Top ↑

Return

(array) Returns the modified $declarations.


Top ↑

Source

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

	protected static function compute_preset_vars( $settings, $origins ) {
		$declarations = array();
		foreach ( static::PRESETS_METADATA as $preset_metadata ) {
			$values_by_slug = static::get_settings_values_by_slug( $settings, $preset_metadata, $origins );
			foreach ( $values_by_slug as $slug => $value ) {
				$declarations[] = array(
					'name'  => static::replace_slug_in_string( $preset_metadata['css_vars'], $slug ),
					'value' => $value,
				);
			}
		}

		return $declarations;
	}

Top ↑

Changelog

Changelog
VersionDescription
5.9.0Added the $origins parameter.
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.