Automattic\WooCommerce\Blocks\Utils

StyleAttributesUtils::get_link_color_class_and_style()public staticWC 1.0

Get class and style for link-color from attributes.

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

Хуков нет.

Возвращает

(Массив. | null)

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

$result = StyleAttributesUtils::get_link_color_class_and_style( $attributes );
$attributes(массив) (обязательный)
Block attributes.

Код StyleAttributesUtils::get_link_color_class_and_style() WC 7.1.0

public static function get_link_color_class_and_style( $attributes ) {

	if ( ! isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
		return null;
	};

	$link_color = $attributes['style']['elements']['link']['color']['text'];

	// 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.
	$index_named_link_color = strrpos( $link_color, '|' );

	if ( ! empty( $index_named_link_color ) ) {
		$parsed_named_link_color = substr( $link_color, $index_named_link_color + 1 );
		return array(
			'class' => null,
			'style' => sprintf( 'color: %s;', self::get_preset_value( $parsed_named_link_color ) ),
			'value' => self::get_preset_value( $parsed_named_link_color ),
		);
	} else {
		return array(
			'class' => null,
			'style' => sprintf( 'color: %s;', $link_color ),
			'value' => $link_color,
		);
	}
}