Title: WP_Theme_JSON::compute_preset_vars
Published: July 20, 2021
Last modified: May 20, 2026

---

# WP_Theme_JSON::compute_preset_vars( array $settings, string[] $origins ): array

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_theme_json/compute_preset_vars/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_theme_json/compute_preset_vars/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_theme_json/compute_preset_vars/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_theme_json/compute_preset_vars/?output_format=md#source)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_theme_json/compute_preset_vars/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_theme_json/compute_preset_vars/?output_format=md#wp--skip-link--target)

Given the block settings, extracts the CSS Custom Properties for the presets and
adds them to the $declarations array following the format:

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_theme_json/compute_preset_vars/?output_format=md#description)󠁿

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

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_theme_json/compute_preset_vars/?output_format=md#parameters)󠁿

 `$settings`arrayrequired

Settings to process.

`$origins`string[]required

List of origins to process.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_theme_json/compute_preset_vars/?output_format=md#return)󠁿

 array The modified $declarations.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_theme_json/compute_preset_vars/?output_format=md#source)󠁿

    ```php
    protected static function compute_preset_vars( $settings, $origins ) {
    	$declarations = array();
    	foreach ( static::PRESETS_METADATA as $preset_metadata ) {
    		if ( empty( $preset_metadata['css_vars'] ) ) {
    			continue;
    		}
    		$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;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/class-wp-theme-json.php#L2265)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/class-wp-theme-json.php#L2265-L2281)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_theme_json/compute_preset_vars/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Added the `$origins` parameter. | 
| [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_theme_json%2Fcompute_preset_vars%2F)
before being able to contribute a note or feedback.