From b6190bdd28246bca544f0783d03778902bdc0df8 Mon Sep 17 00:00:00 2001 From: Piotr Potrebka <piotr.potrebka@wpdesk.net> Date: Thu, 9 Feb 2023 08:00:31 +0100 Subject: [PATCH] feat: email styles --- src/Mailer.php | 34 ++++++++++++++++++++++++++++----- templates/html/email-styles.php | 8 ++++---- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/Mailer.php b/src/Mailer.php index e1a239a..8e2cc68 100644 --- a/src/Mailer.php +++ b/src/Mailer.php @@ -23,12 +23,19 @@ class Mailer { */ private $renderer; + /** + * @var array + */ + private $attributes; + /** * @param array $dirs */ public function __construct( - array $dirs = [] + array $dirs = [], + array $attributes = [] ) { + $this->attributes = $attributes; $this->set_renderer( $this->init_renderer( $dirs ) ); } @@ -73,8 +80,11 @@ class Mailer { } /** @return void */ - public function send() { + public function send( $include = [] ) { foreach ( $this->get_emails() as $email ) { + if ( ! empty( $include ) && ! in_array( $email->get_id(), $include, true ) ) { + continue; + } if ( $email->get_is_enable() ) { add_filter( 'wp_mail_from', @@ -131,9 +141,15 @@ class Mailer { } protected function get_email_template( EmailInterface $email ): string { - $output = $this->renderer->render( 'html/email-header', [ 'heading' => $email->get_heading(), 'logo' => '' ] ); + $output = $this->renderer->render( + 'html/email-header', + [ + 'heading' => $this->attributes['heading'] ?? $email->get_heading(), + 'logo' => $this->attributes['logo'] + ] + ); $output .= $this->renderer->render( 'html/' . $email->get_id(), [ 'content' => $email->get_content() ] ); - $output .= $this->renderer->render( 'html/email-footer', [ 'footer' => '' ] ); + $output .= $this->renderer->render( 'html/email-footer', [ 'footer' => $this->attributes['footer'] ] ); return $this->css_inline( $output ); } @@ -144,7 +160,15 @@ class Mailer { * @return mixed|string */ protected function css_inline( string $content ): string { - $styles = $this->renderer->render( 'html/email-styles', [] ); + $styles = $this->renderer->render( + 'html/email-styles', + [ + 'primary' => $this->attributes['primary'] ?? '#d15291', + 'text' => $this->attributes['text'] ?? '#303030', + 'bg' => $this->attributes['bg'] ?? '#f9f9f9', + 'body' => $this->attributes['body'] ?? '#ffffff', + ] + ); return HTML::style_inline( $content, $styles ); } diff --git a/templates/html/email-styles.php b/templates/html/email-styles.php index 6f43399..450345c 100644 --- a/templates/html/email-styles.php +++ b/templates/html/email-styles.php @@ -9,11 +9,11 @@ if ( ! defined( 'ABSPATH' ) ) { } // Load colors. -$bg = $params['bg'] ?? '#f9f9f9'; -$body = $params['body'] ?? '#ffffff'; -$base = $params['base'] ?? '#d15291'; +$bg = $params['bg']; +$body = $params['body']; +$base = $params['primary']; $base_text = Template::light_or_dark( $base, '#171717', '#ffffff' ); -$text = $params['text'] ?? '#303030'; +$text = $params['text']; // Pick a contrasting color for links. $link_color = Template::is_hex_light( $base ) ? $base : $base_text; -- GitLab