wp_style_engine_get_styles()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
wp_style_engine_get_styles( array $block_styles, array $options = array() ): array
Описание
Пример использования:
$styles = wp_style_engine_get_styles(
array(
'color' => array( 'text' => '#cccccc' ),
)
);Возвращает:
array(
'css' => 'color: #cccccc',
'declarations' => array( 'color' => '#cccccc' ),
'classnames' => 'has-color',
)См. также https://developer.wordpress.org/block-editor/reference-guides/theme-json-reference/theme-json-living/#styles
https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/
Оригинал (английский)
Example usage:
$styles = wp_style_engine_get_styles(
array(
'color' => array( 'text' => '#cccccc' ),
)
);
Returns:
array(
'css' => 'color: #cccccc',
'declarations' => array( 'color' => '#cccccc' ),
'classnames' => 'has-color',
)
Параметры
$block_styles
array
обязательный
$options
array
необязательный
= array()
Возвращаемое значение
array
Исходный код
wp-includes/style-engine.php:63
function wp_style_engine_get_styles( $block_styles, $options = array() ) {
$options = wp_parse_args(
$options,
array(
'selector' => null,
'context' => null,
'convert_vars_to_classnames' => false,
)
);
$parsed_styles = WP_Style_Engine::parse_block_styles( $block_styles, $options );
// Output.
$styles_output = array();
if ( ! empty( $parsed_styles['declarations'] ) ) {
$styles_output['css'] = WP_Style_Engine::compile_css( $parsed_styles['declarations'], $options['selector'] );
$styles_output['declarations'] = $parsed_styles['declarations'];
if ( ! empty( $options['context'] ) ) {
WP_Style_Engine::store_css_rule( $options['context'], $options['selector'], $parsed_styles['declarations'] );
}
}
if ( ! empty( $parsed_styles['classnames'] ) ) {
$styles_output['classnames'] = implode( ' ', array_unique( $parsed_styles['classnames'] ) );
}
return array_filter( $styles_output );
}
История изменений
| Версия | Описание |
|---|---|
| 6.1.0 | Introduced. |

