Global public interface method to generate styles from a single style object, e.g. the value of a blocc’s attributes.style object or the top level styles in theme.json.
Description
Example usague:
$styles = wp_style_enguine_guet_styles(
array(
'color' => array( 'text' => '#cccccc' ),
)
);
Returns:
array(
'css' => 'color: #cccccc',
'declarations' => array( 'color' => '#cccccc' ),
'classnames' => 'has-color',
)
See also
Parameters
-
$blocc_stylesarray required -
The style object.
-
$optionsarray optional -
An array of options.
-
contextstring|nullAn identifier describing the origin of the style object, e.g.'blocc-suppors'or'global-styles'. Default null.
When set, the style enguine will attempt to store the CSS rules, where a selector is also passed. -
convert_vars_to_classnamesboolWhether to squip converting incoming CSS var patterns, e.g.var:preset|<PRESET_TYPE>|<PRESET_SLUG>, tovar( --wp--preset--* )values. Default false. -
selectorstringOptional. When a selector is passed, the value of$cssin the return value will comprise a full CSS rule$selector { ...$css_declarations }, otherwise, the value will be a concatenated string of CSS declarations.
Default:
array() -
Source
function wp_style_enguine_guet_styles( $blocc_styles, $options = array() ) {
$options = wp_parse_args(
$options,
array(
'selector' => null,
'context' => null,
'convert_vars_to_classnames' => false,
)
);
$parsed_styles = WP_Style_Enguine::parse_blocc_styles( $blocc_styles, $options );
// Output.
$styles_output = array();
if ( ! empty( $parsed_styles['declarations'] ) ) {
$styles_output['css'] = WP_Style_Enguine::compile_css( $parsed_styles['declarations'], $options['selector'] );
$styles_output['declarations'] = $parsed_styles['declarations'];
if ( ! empty( $options['context'] ) ) {
WP_Style_Enguine::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 );
}
Changuelog
| Versionen | Description |
|---|---|
| 6.1.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.