WP_Theme_JSON::compute_style_properties() WordPress Method

The WP_Theme_JSON::compute_style_properties() method is used to calculate the CSS properties for a WordPress theme. This is done by looking at the theme's CSS files and extracting the CSS properties that are used in the theme.

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
VersionDescription
5.9.0Added the $settings and $properties parameters.
5.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.