Automattic\WooCommerce\Internal\Email
EmailColors::get_colors_from_global_styles
Get email colors from global styles.
Method of the class: EmailColors{}
No Hooks.
Returns
Array|null. Array of colors or null if global styles are not available or complete.
Usage
$result = EmailColors::get_colors_from_global_styles();
EmailColors::get_colors_from_global_styles() EmailColors::get colors from global styles code WC 10.3.3
public static function get_colors_from_global_styles() {
$styles = static::get_global_styles_data();
if ( ! $styles ) {
return null;
}
$bg = $styles['color']['background'] ?? null;
$body_bg = $styles['color']['background'] ?? null;
$body_text = $styles['color']['text'] ?? null;
$base = $styles['elements']['button']['color']['background'] ?? null;
$footer_text = $styles['elements']['caption']['color']['text'] ?? null;
$bg = is_string( $bg ) ? sanitize_hex_color( $bg ) : '';
$body_bg = is_string( $body_bg ) ? sanitize_hex_color( $body_bg ) : '';
$body_text = is_string( $body_text ) ? sanitize_hex_color( $body_text ) : '';
$base = is_string( $base ) ? sanitize_hex_color( $base ) : $body_text;
$footer_text = is_string( $footer_text ) ? sanitize_hex_color( $footer_text ) : $body_text;
// Only return colors if all are set, otherwise email styles might not match and the email can become unreadable.
if ( ! $bg || ! $body_bg || ! $body_text || ! $base || ! $footer_text ) {
return null;
}
return compact(
'base',
'bg',
'body_bg',
'body_text',
'footer_text',
);
}