Automattic\WooCommerce\Blocks\Utils
StyleAttributesUtils::get_link_color_class_and_style
Get class and style for link-color from attributes.
Method of the class: StyleAttributesUtils{}
No Hooks.
Returns
Array.
Usage
$result = StyleAttributesUtils::get_link_color_class_and_style( $attributes );
- $attributes(array) (required)
- Block attributes.
StyleAttributesUtils::get_link_color_class_and_style() StyleAttributesUtils::get link color class and style code WC 10.8.1
public static function get_link_color_class_and_style( $attributes ) {
$link_color = self::array_get_value_by_path( $attributes, 'style.elements.link.color.text' );
if ( empty( $link_color ) ) {
return self::EMPTY_STYLE;
}
// If the link color is selected from the theme color picker, the value of $link_color is var:preset|color|slug.
// If the link color is selected from the core color picker, the value of $link_color is an hex value.
// When the link color is a string var:preset|color|slug we parsed it for get the slug, otherwise we use the hex value.
if ( strstr( $link_color, '|' ) ) {
$link_color_parts = explode( '|', $link_color );
$link_color = self::get_preset_value( end( $link_color_parts ) );
}
return array(
'class' => 'has-link-color',
'style' => sprintf( 'color: %s;', $link_color ),
'value' => $link_color,
);
}