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

feat: email styles

parent b6190bdd
No related branches found
No related tags found
1 merge request!2Devel
Pipeline #156492 passed with stages
in 1 minute and 1 second
......@@ -26,17 +26,30 @@ class Mailer {
/**
* @var array
*/
private $attributes;
private $template_attributes;
/**
* @var string
*/
private $from;
/**
* @var string
*/
private $from_name;
/**
* @param array $dirs
* @param array $template_attributes
*/
public function __construct(
array $dirs = [],
array $attributes = []
array $template_attributes = []
) {
$this->attributes = $attributes;
$this->template_attributes = $template_attributes;
$this->set_renderer( $this->init_renderer( $dirs ) );
$this->set_from( get_bloginfo( 'admin_email' ) );
$this->set_from_name( get_bloginfo( 'name', 'display' ) );
}
/**
......@@ -79,6 +92,38 @@ class Mailer {
return $this->emails;
}
/**
* @param string $from
*
* @return void
*/
public function set_from( string $from ) {
$this->from = $from;
}
/**
* @return string
*/
public function get_from(): string {
return $this->from;
}
/**
* @param string $from_name
*
* @return void
*/
public function set_from_name( string $from_name ) {
$this->from_name = $from_name;
}
/**
* @return string
*/
public function get_from_name(): string {
return $this->from_name;
}
/** @return void */
public function send( $include = [] ) {
foreach ( $this->get_emails() as $email ) {
......@@ -88,22 +133,14 @@ class Mailer {
if ( $email->get_is_enable() ) {
add_filter(
'wp_mail_from',
$from_cb = static function ( $from ) use ( $email ) {
if ( ! empty( $email->get_from() ) ) {
return $email->get_from();
}
return $from;
$from_cb = static function ( $from ) {
return $this->get_from();
}
);
add_filter(
'wp_mail_from_name',
$from_name_cb = static function ( $from_name ) use ( $email ) {
if ( ! empty( $email->get_from_name() ) ) {
return $email->get_from_name();
}
return $from_name;
$from_name_cb = static function ( $from_name ) {
return $this->get_from_name();
}
);
add_action( 'wp_mail_failed', [ $this, 'catch_error' ] );
......@@ -144,12 +181,12 @@ class Mailer {
$output = $this->renderer->render(
'html/email-header',
[
'heading' => $this->attributes['heading'] ?? $email->get_heading(),
'logo' => $this->attributes['logo']
'heading' => $this->template_attributes['heading'] ?? $email->get_heading(),
'logo' => $this->template_attributes['logo']
]
);
$output .= $this->renderer->render( 'html/' . $email->get_id(), [ 'content' => $email->get_content() ] );
$output .= $this->renderer->render( 'html/email-footer', [ 'footer' => $this->attributes['footer'] ] );
$output .= $this->renderer->render( 'html/email-footer', [ 'footer' => $this->template_attributes['footer'] ] );
return $this->css_inline( $output );
}
......@@ -163,10 +200,10 @@ class Mailer {
$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',
'primary' => $this->template_attributes['primary'] ?? '#d15291',
'text' => $this->template_attributes['text'] ?? '#303030',
'bg' => $this->template_attributes['bg'] ?? '#f9f9f9',
'body' => $this->template_attributes['body'] ?? '#ffffff',
]
);
......
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