Initialise hooks early

[MAILPOET-2307]
This commit is contained in:
Pavel Dohnal
2019-09-10 12:47:54 +02:00
committed by Jack Kitterhing
parent 198b04fe24
commit 952b9d7dd4
4 changed files with 11 additions and 2 deletions

View File

@ -85,6 +85,9 @@ class Hooks {
$this->setupSubscriptionEvents();
$this->setupWooCommerceSubscriptionEvents();
$this->setupPostNotifications();
}
function initEarlyHooks() {
$this->setupMailer();
}
@ -189,6 +192,10 @@ class Hooks {
$this->wordpress_mailer_replacer,
'replaceWordPressMailer',
]);
$this->wp->addAction('lostpassword_post', [
$this->wordpress_mailer_replacer,
'replaceWordPressMailer',
]);
}
function setupWooCommerceSubscriptionEvents() {

View File

@ -158,6 +158,7 @@ class Initializer {
new DeferredAdminNotices,
'printAndClean',
]);
$this->hooks->initEarlyHooks();
}
function checkRequirements() {

View File

@ -38,7 +38,7 @@ class WordPressMailer extends \PHPMailer {
if ($result['response']) {
return true;
} else {
throw new \phpmailerException($result['error']);
throw new \phpmailerException($result['error']->getMessage());
}
}

View File

@ -8,6 +8,7 @@ if (!class_exists('PHPMailer')) {
}
use MailPoet\Mailer\Mailer;
use MailPoet\Mailer\MailerError;
class WordpressMailerTest extends \MailPoetTest {
@ -95,7 +96,7 @@ class WordpressMailerTest extends \MailPoetTest {
$mailer
->expects($this->once())
->method('send')
->willReturn(['response' => false, 'error' => 'Big Error']);
->willReturn(['response' => false, 'error' => new MailerError('send', 1, 'Big Error')]);
$wpMailer = new WordPressMailer($mailer);
$wpMailer->addAddress('email@example.com');
$wpMailer->Body = 'body';