WP_Style_Engine::parse_block_styles()public staticWP 6.1.0

Returns classnames and CSS based on the values in a styles object.

Return values are parsed based on the instructions in BLOCK_STYLE_DEFINITIONS_METADATA.

Метод класса: WP_Style_Engine{}

Хуков нет.

Возвращает

Массив.

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

$result = WP_Style_Engine::parse_block_styles( $block_styles, $options );
$block_styles(массив) (обязательный)
The style object.
$options(массив) (обязательный)

An array of options.

По умолчанию: empty array

  • convert_vars_to_classnames(true|false)
    Whether to skip converting incoming CSS var patterns, e.g. var:preset|<PRESET_TYPE>|<PRESET_SLUG>, to var( --wp--preset--* ) values.
    По умолчанию: false

  • selector(строка)
    Optional. When a selector is passed, the value of $css in the return value will comprise a full CSS rule $selector { ...$css_declarations }, otherwise, the value will be a concatenated string of CSS declarations.

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

С версии 6.1.0 Введена.

Код WP_Style_Engine::parse_block_styles() WP 6.5.2

public static function parse_block_styles( $block_styles, $options ) {
	$parsed_styles = array(
		'classnames'   => array(),
		'declarations' => array(),
	);
	if ( empty( $block_styles ) || ! is_array( $block_styles ) ) {
		return $parsed_styles;
	}

	// Collect CSS and classnames.
	foreach ( static::BLOCK_STYLE_DEFINITIONS_METADATA as $definition_group_key => $definition_group_style ) {
		if ( empty( $block_styles[ $definition_group_key ] ) ) {
			continue;
		}
		foreach ( $definition_group_style as $style_definition ) {
			$style_value = _wp_array_get( $block_styles, $style_definition['path'], null );

			if ( ! static::is_valid_style_value( $style_value ) ) {
				continue;
			}

			$parsed_styles['classnames']   = array_merge( $parsed_styles['classnames'], static::get_classnames( $style_value, $style_definition ) );
			$parsed_styles['declarations'] = array_merge( $parsed_styles['declarations'], static::get_css_declarations( $style_value, $style_definition, $options ) );
		}
	}

	return $parsed_styles;
}