WP_Theme_JSON::compute_style_properties( array $styles, array $settings = array(), array $properties = null )

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, )


Top ↑

Parameters

$styles

(array) (Required) Styles to process.

$settings

(array) (Optional) Theme settings.

Default value: array()

$properties

(array) (Optional) Properties metadata.

Default value: null


Top ↑

Return

(array) Returns the modified $declarations.


Top ↑

Source

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

	protected static function compute_style_properties( $styles, $settings = array(), $properties = null ) {
		if ( null === $properties ) {
			$properties = static::PROPERTIES_METADATA;
		}

		$declarations = array();
		if ( empty( $styles ) ) {
			return $declarations;
		}

		foreach ( $properties as $css_property => $value_path ) {
			$value = static::get_property_value( $styles, $value_path );

			// Look up protected properties, keyed by value path.
			// Skip protected properties that are explicitly set to `null`.
			if ( is_array( $value_path ) ) {
				$path_string = implode( '.', $value_path );
				if (
					array_key_exists( $path_string, static::PROTECTED_PROPERTIES ) &&
					_wp_array_get( $settings, static::PROTECTED_PROPERTIES[ $path_string ], null ) === null
				) {
					continue;
				}
			}

			// 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;
			}

			$declarations[] = array(
				'name'  => $css_property,
				'value' => $value,
			);
		}

		return $declarations;
	}


Top ↑

Changelog

Changelog
Version Description
5.9.0 Added the $settings and $properties parameters.
5.8.0 Introduced.

Top ↑

User Contributed Notes

You must log in before being able to contribute a note or feedback.