-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: PHPMailer namespace in MailerListener #85
base: 2.x
Are you sure you want to change the base?
Conversation
Thanks @frugan-dev Do you know in which WP version the change happened? Maybe we could do something like: if (
($mailer instanceof \PHPMailer)
|| ($mailer instanceof \PHPMailer\PHPMailer\PHPMailer)
) {
} To support both use cases. And it is really bncesary to replace |
It seem to be WordPress 5.5, where PHPMailer has been updated to version 6: https://make.wordpress.org/core/2020/07/01/external-library-updates-in-wordpress-5-5-call-for-testing/ |
Yes, I think we need a more gradual approach, that also supports WP versions prior to 5.5, but that always gradually aims to avoid magic numbers (see https://github.com/povils/phpmnd). Also because in my opinion, it would be useful to be able to customize the debug level, perhaps with a constant like For example something like this (namespace plus, namespace minus): use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
if ($mailer instanceof \PHPMailer || $mailer instanceof PHPMailer) {
$mailer->SMTPDebug = \defined('WONOLOG_PHPMAILER_SMTP_DEBUG_LEVEL') ? \constant('WONOLOG_PHPMAILER_SMTP_DEBUG_LEVEL') : (class_exists('\PHPMailer\PHPMailer\SMTP') ? SMTP::DEBUG_SERVER : 2);
$mailer->Debugoutput = static function (string $message) use ($updater): void {
$updater->update(new Debug($message, Channels::HTTP));
};
} |
Yes I confirm! |
Thanks for the investigation @frugan-dev I'm not sure I want to add a constant for this. In version 2, most constant-based configurations were removed in favor of code-based configurations. What about adding a constructor parameter to set the PHPMailer debug level? This way, one could do the following: add_action(
'wonolog.setup',
function (Inpsyde\Wonolog\Configurator $config) {
$config
->disableDefaultHookListeners(MailerListener::class)
->addActionListener(new MailerListener(phpmailerDebugLevel: SMTP::DEBUG_LOWLEVEL))
}
); |
Ok as you prefer, LGTM! |
@see https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes/PHPMailer/PHPMailer.php#L22