Automattic\WooCommerce\Blocks\Utils

StyleAttributesUtils::get_text_color_class_and_style()public staticWC 1.0

Get class and style for text-color from attributes.

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

Хуков нет.

Возвращает

(Массив. | null)

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

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

Код StyleAttributesUtils::get_text_color_class_and_style() WC 7.3.0

public static function get_text_color_class_and_style( $attributes ) {

	$text_color = $attributes['textColor'] ?? '';

	$custom_text_color = $attributes['style']['color']['text'] ?? '';

	if ( ! $text_color && ! $custom_text_color ) {
		return null;
	}

	if ( $text_color ) {
		return array(
			'class' => sprintf( 'has-text-color has-%s-color', $text_color ),
			'style' => null,
			'value' => self::get_preset_value( $text_color ),
		);
	} elseif ( $custom_text_color ) {
		return array(
			'class' => null,
			'style' => sprintf( 'color: %s;', $custom_text_color ),
			'value' => $custom_text_color,
		);
	}
	return null;
}