Skip to content
Snippets Groups Projects
Commit b6190bdd authored by Piotr Potrebka's avatar Piotr Potrebka
Browse files

feat: email styles

parent 43426991
No related branches found
No related tags found
1 merge request!2Devel
Pipeline #156484 passed with stages
in 55 seconds
...@@ -23,12 +23,19 @@ class Mailer { ...@@ -23,12 +23,19 @@ class Mailer {
*/ */
private $renderer; private $renderer;
/**
* @var array
*/
private $attributes;
/** /**
* @param array $dirs * @param array $dirs
*/ */
public function __construct( public function __construct(
array $dirs = [] array $dirs = [],
array $attributes = []
) { ) {
$this->attributes = $attributes;
$this->set_renderer( $this->init_renderer( $dirs ) ); $this->set_renderer( $this->init_renderer( $dirs ) );
} }
...@@ -73,8 +80,11 @@ class Mailer { ...@@ -73,8 +80,11 @@ class Mailer {
} }
/** @return void */ /** @return void */
public function send() { public function send( $include = [] ) {
foreach ( $this->get_emails() as $email ) { foreach ( $this->get_emails() as $email ) {
if ( ! empty( $include ) && ! in_array( $email->get_id(), $include, true ) ) {
continue;
}
if ( $email->get_is_enable() ) { if ( $email->get_is_enable() ) {
add_filter( add_filter(
'wp_mail_from', 'wp_mail_from',
...@@ -131,9 +141,15 @@ class Mailer { ...@@ -131,9 +141,15 @@ class Mailer {
} }
protected function get_email_template( EmailInterface $email ): string { 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->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 ); return $this->css_inline( $output );
} }
...@@ -144,7 +160,15 @@ class Mailer { ...@@ -144,7 +160,15 @@ class Mailer {
* @return mixed|string * @return mixed|string
*/ */
protected function css_inline( string $content ): 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 ); return HTML::style_inline( $content, $styles );
} }
......
...@@ -9,11 +9,11 @@ if ( ! defined( 'ABSPATH' ) ) { ...@@ -9,11 +9,11 @@ if ( ! defined( 'ABSPATH' ) ) {
} }
// Load colors. // Load colors.
$bg = $params['bg'] ?? '#f9f9f9'; $bg = $params['bg'];
$body = $params['body'] ?? '#ffffff'; $body = $params['body'];
$base = $params['base'] ?? '#d15291'; $base = $params['primary'];
$base_text = Template::light_or_dark( $base, '#171717', '#ffffff' ); $base_text = Template::light_or_dark( $base, '#171717', '#ffffff' );
$text = $params['text'] ?? '#303030'; $text = $params['text'];
// Pick a contrasting color for links. // Pick a contrasting color for links.
$link_color = Template::is_hex_light( $base ) ? $base : $base_text; $link_color = Template::is_hex_light( $base ) ? $base : $base_text;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment