WP_Theme_JSON::compute_style_properties()protected staticWP 5.8.0

Given a styles array, it extracts the style properties and adds them to the $declarations array following the format:

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

)

{} Это метод класса: WP_Theme_JSON{}

Хуков нет.

Возвращает

Массив. Returns the modified $declarations.

Использование

$result = WP_Theme_JSON::compute_style_properties( $styles, $settings, $properties );
$styles(массив) (обязательный)
Styles to process.
$settings(массив)
Theme settings.
По умолчанию: array()
$properties(массив)
Properties metadata.
По умолчанию: null

Список изменений

С версии 5.8.0 Введена.
С версии 5.9.0 Added the $settings and $properties parameters.

Код WP_Theme_JSON::compute_style_properties() WP 6.0.2

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