Skip to content
Snippets Groups Projects

Devel

Merged Piotr Potrebka requested to merge devel into main
2 files
+ 33
9
Compare changes
  • Side-by-side
  • Inline

Files

+ 29
5
@@ -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 );
}
Loading