wppaste
WordPress

WP_Theme_JSON::compute_style_properties( array $styles, array $settings = array(), array $properties = null, array $theme_json = null, string $selector = null, boolean $use_root_padding = null ): array

Since
5.8.0, 5.9.0, 6.1.0, 6.5.0, 6.6.0, 6.7.0
Source
wp-includes/class-wp-theme-json.php:2395
Given a styles array, it extracts the style properties and adds them to the $declarations array following the format:

Description

array( 'name' => 'property_name', 'value' => 'property_value', )

Compatibility

WordPress
since 6.7.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$stylesarray
Styles to process.
$settingsarrayoptional
Theme settings.Default: array()
$propertiesarrayoptional
Properties metadata.Default: null
$theme_jsonarrayoptional
Theme JSON array.Default: null
$selectorstringoptional
The style block selector.Default: null
$use_root_paddingbooleanoptional
Whether to add custom properties at root level.Default: null

Return value

array
Returns the modified $declarations.

Performance profile

How much work a call to WP_Theme_JSON::compute_style_properties() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Light

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
9–20

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 126.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What one call costs · 1 distinct outcome

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Theme_JSON::compute_style_properties() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always9–20none

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev1269–2029
8.51269–2029
8.41269–202910 fewer instructions than PHP 8.3
8.31369–2029
8.21369–2029
8.11369–20291 fewer instruction than PHP 7.4
7.41379–2029

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 4

Source code

	protected static function compute_style_properties( $styles, $settings = array(), $properties = null, $theme_json = null, $selector = null, $use_root_padding = null ) {		if ( empty( $styles ) ) {			return array();		} 		if ( null === $properties ) {			$properties = static::PROPERTIES_METADATA;		}		$declarations             = array();		$root_variable_duplicates = array();		$root_style_length        = strlen( '--wp--style--root--' ); 		foreach ( $properties as $css_property => $value_path ) {			if ( ! is_array( $value_path ) ) {				continue;			} 			$is_root_style = str_starts_with( $css_property, '--wp--style--root--' );			if ( $is_root_style && ( static::ROOT_BLOCK_SELECTOR !== $selector || ! $use_root_padding ) ) {				continue;			} 			$value = static::get_property_value( $styles, $value_path, $theme_json ); 			/*			 * Root-level padding styles don't currently support strings with CSS shorthand values.			 * This may change: https://github.com/WordPress/gutenberg/issues/40132.			 */			if ( '--wp--style--root--padding' === $css_property && is_string( $value ) ) {				continue;			} 			if ( $is_root_style && $use_root_padding ) {				$root_variable_duplicates[] = substr( $css_property, $root_style_length );			} 			/*			 * Processes background image styles.			 * If the value is a URL, it will be converted to a CSS `url()` value.			 * For uploaded image (images with a database ID), apply size and position defaults,			 * equal to those applied in block supports in lib/background.php.			 */			if ( 'background-image' === $css_property && ! empty( $value ) ) {				$background_styles = wp_style_engine_get_styles(					array( 'background' => array( 'backgroundImage' => $value ) )				);				$value             = $background_styles['declarations'][ $css_property ];			}			if ( empty( $value ) && static::ROOT_BLOCK_SELECTOR !== $selector && ! empty( $styles['background']['backgroundImage']['id'] ) ) {				if ( 'background-size' === $css_property ) {					$value = 'cover';				}				// If the background size is set to `contain` and no position is set, set the position to `center`.				if ( 'background-position' === $css_property ) {					$background_size = $styles['background']['backgroundSize'] ?? null;					$value           = 'contain' === $background_size ? '50% 50%' : null;				}			} 			// Skip if empty and not "0" or value represents array of longhand values.			$has_missing_value = empty( $value ) && ! is_numeric( $value );			if ( $has_missing_value || is_array( $value ) ) {				continue;			} 			// Calculates fluid typography rules where available.			if ( 'font-size' === $css_property ) {				/*				 * wp_get_typography_font_size_value() will check				 * if fluid typography has been activated and also				 * whether the incoming value can be converted to a fluid value.				 * Values that already have a clamp() function will not pass the test,				 * and therefore the original $value will be returned.				 * Pass the current theme_json settings to override any global settings.				 */				$value = wp_get_typography_font_size_value( array( 'size' => $value ), $settings );			} 			if ( 'aspect-ratio' === $css_property ) {				// For aspect ratio to work, other dimensions rules must be unset.

Changelog

Introduced in 5.8.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.7.0
ref resolution of background properties, and assigning custom default values.from the docblock
6.6.0
Pass current theme JSON settings to wp_get_typography_font_size_value(), and process background properties.from the docblock
6.5.0
Output a min-height: unset rule when aspect-ratio is set.from the docblock
6.1.0
Added $theme_json, $selector, and $use_root_padding parameters.from the docblock
5.9.0
Added the $settings and $properties parameters.from the docblock
5.8.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/class-wp-theme-json.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.