Automattic\WooCommerce\Blocks\Utils

StyleAttributesUtils::get_background_color_class_and_style()public staticWC 1.0

Get class and style for background-color from attributes.

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

Хуков нет.

Возвращает

(Массив. | null)

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

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

Код StyleAttributesUtils::get_background_color_class_and_style() WC 6.8.0

public static function get_background_color_class_and_style( $attributes ) {

	$background_color = $attributes['backgroundColor'] ?? '';

	$custom_background_color = $attributes['style']['color']['background'] ?? '';

	if ( ! $background_color && '' === $custom_background_color ) {
		return null;
	};

	if ( $background_color ) {
		return array(
			'class' => sprintf( 'has-background has-%s-background-color', $background_color ),
			'style' => null,
			'value' => self::get_preset_value( $background_color ),
		);
	} elseif ( '' !== $custom_background_color ) {
		return array(
			'class' => null,
			'style' => sprintf( 'background-color: %s;', $custom_background_color ),
			'value' => $custom_background_color,
		);
	}
	return null;
}