wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren
wp_get_color_classes_and_styles › WordPress Function
Seit7.3.0
Veraltetn/v
› wp_get_color_classes_and_styles ( $block_attributes )
| Parameter: |
|
| Gibt zurück: |
|
| Definiert in: |
|
| Codex: |
Returns color classes and inline styles for block attributes, like the JS `getColorClassesAndStyles()`. Does not check block support or skipped serialization.
Quellcode
function wp_get_color_classes_and_styles( $block_attributes ) {
if ( ! is_array( $block_attributes ) ) {
return array();
}
$color_block_styles = array();
$preset_attributes = array(
'text' => array( 'textColor', 'color' ),
'background' => array( 'backgroundColor', 'color' ),
'gradient' => array( 'gradient', 'gradient' ),
);
foreach ( $preset_attributes as $feature => list( $preset_attribute, $preset_type ) ) {
$preset_slug = $block_attributes[ $preset_attribute ] ?? null;
// Preset slugs are strings in theme.json and the editor.
$preset_value = is_string( $preset_slug ) && '' !== $preset_slug ? "var:preset|{$preset_type}|{$preset_slug}" : null;
$custom_value = $block_attributes['style']['color'][ $feature ] ?? null;
$color_block_styles[ $feature ] = $preset_value ?? $custom_value;
}
$attributes = array();
$styles = wp_style_engine_get_styles( array( 'color' => $color_block_styles ), array( 'convert_vars_to_classnames' => true ) );
if ( ! empty( $styles['classnames'] ) ) {
$attributes['class'] = $styles['classnames'];
}
if ( ! empty( $styles['css'] ) ) {
$attributes['style'] = $styles['css'];
}
return $attributes;
}