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, )
Parameters
- $settings
(array)(Required)Settings to process.
- $origins
(array)(Required)List of origins to process.
Return
(array) Returns the modified $declarations.
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; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.9.0 | Added the $origins parameter. |
5.8.0 | Introduced. |