Add a lazy instantiation of Mailer in NewSubscriberNofiticationMailer
[MAILPOET-1823]
This commit is contained in:
committed by
M. Shull
parent
ccc300cd80
commit
1868d1e45f
@@ -3,6 +3,7 @@
|
|||||||
namespace MailPoet\Subscribers;
|
namespace MailPoet\Subscribers;
|
||||||
|
|
||||||
use MailPoet\Config\Renderer;
|
use MailPoet\Config\Renderer;
|
||||||
|
use MailPoet\Mailer\Mailer;
|
||||||
use MailPoet\Models\Segment;
|
use MailPoet\Models\Segment;
|
||||||
use MailPoet\Models\Subscriber;
|
use MailPoet\Models\Subscriber;
|
||||||
use MailPoet\WP\Functions;
|
use MailPoet\WP\Functions;
|
||||||
@@ -43,11 +44,7 @@ class NewSubscriberNotificationMailer {
|
|||||||
} else {
|
} else {
|
||||||
$this->wordpress_functions = new Functions();
|
$this->wordpress_functions = new Functions();
|
||||||
}
|
}
|
||||||
if ($mailer) {
|
|
||||||
$this->mailer = $mailer;
|
$this->mailer = $mailer;
|
||||||
} else {
|
|
||||||
$this->mailer = new \MailPoet\Mailer\Mailer(false, $this->constructSenderEmail());
|
|
||||||
}
|
|
||||||
$this->settings = new SettingsController();
|
$this->settings = new SettingsController();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,8 +60,9 @@ class NewSubscriberNotificationMailer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$this->mailer->getSenderNameAndAddress($this->constructSenderEmail());
|
|
||||||
$this->mailer->send($this->constructNewsletter($subscriber, $segments), $settings['address']);
|
$this->getMailer()->getSenderNameAndAddress($this->constructSenderEmail());
|
||||||
|
$this->getMailer()->send($this->constructNewsletter($subscriber, $segments), $settings['address']);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
if (WP_DEBUG) {
|
if (WP_DEBUG) {
|
||||||
throw $e;
|
throw $e;
|
||||||
@@ -88,6 +86,16 @@ class NewSubscriberNotificationMailer {
|
|||||||
return !(bool)$settings['enabled'];
|
return !(bool)$settings['enabled'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Mailer
|
||||||
|
*/
|
||||||
|
private function getMailer() {
|
||||||
|
if (!$this->mailer) {
|
||||||
|
$this->mailer = new Mailer(false, $this->constructSenderEmail());
|
||||||
|
}
|
||||||
|
return $this->mailer;
|
||||||
|
}
|
||||||
|
|
||||||
private function constructSenderEmail() {
|
private function constructSenderEmail() {
|
||||||
$url_parts = parse_url($this->wordpress_functions->homeUrl());
|
$url_parts = parse_url($this->wordpress_functions->homeUrl());
|
||||||
$site_name = strtolower($url_parts['host']);
|
$site_name = strtolower($url_parts['host']);
|
||||||
|
Reference in New Issue
Block a user