WP_Theme_JSON::compute_style_properties( array $styles )

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

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

Parameters

$styles

(array) (Required) Styles to process.

Return

(array) Returns the modified $declarations.

Source

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

private static function compute_style_properties( $styles ) {
		$declarations = array();
		if ( empty( $styles ) ) {
			return $declarations;
		}

		$properties = array();
		foreach ( self::PROPERTIES_METADATA as $name => $metadata ) {
			/*
			 * Some properties can be shorthand properties, meaning that
			 * they contain multiple values instead of a single one.
			 * An example of this is the padding property.
			 */
			if ( self::has_properties( $metadata ) ) {
				foreach ( $metadata['properties'] as $property ) {
					$properties[] = array(
						'name'  => $name . '-' . $property,
						'value' => array_merge( $metadata['value'], array( $property ) ),
					);
				}
			} else {
				$properties[] = array(
					'name'  => $name,
					'value' => $metadata['value'],
				);
			}
		}

		foreach ( $properties as $prop ) {
			$value = self::get_property_value( $styles, $prop['value'] );
			if ( empty( $value ) ) {
				continue;
			}

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

		return $declarations;
	}

Changelog

Version Description
5.8.0 Introduced.

© 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_theme_json/compute_style_properties