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, )
Parameters
- $styles
(array)(Required)Styles to process.
- $settings
(array)(Optional)Theme settings.
Default value: array()
- $properties
(array)(Optional)Properties metadata.
Default value: null
Return
(array) Returns the modified $declarations.
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; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.9.0 | Added the $settings and $properties parameters. |
5.8.0 | Introduced. |