Make WordPress Core

Opened 6 years ago

Last modified 12 months ago

#28618 new enhancement

Allow PHPMailer class to be reliably overriden

Reported by: leewillis77 Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.0
Component: Mail Keywords: has-patch
Focuses: Cc:


The WordPress unit test suite currently overrides the global $phpmailer variable with its own MockMailer class. (See https://core.trac.wordpress.org/browser/trunk/tests/phpunit/includes/bootstrap.php#L48)

This achieves the desired effect, but is potentially unreliable.

If the global $phpmailer object gets unset, or overridden (For example by a buggy, or otherwise badly behaving plugin), then the code in wp-includes/pluggable.php will create a new instance of PHPMailer without any way for code to override that - see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/pluggable.php#L264

The end result would be that a site that shouldn't be sending emails will potentially become one that will.

Potential patch attached. This includes the change to pluggable.php to filter the object after creation, and addition to the test suite to use it.

Attachments (1)

28618.diff (1.8 KB) - added by leewillis77 6 years ago.

Download all attachments as: .zip

Change History (3)

6 years ago

#1 @nacin
6 years ago

  • Milestone changed from Awaiting Review to Future Release

I don't hate this, so that's good. :) Will want some other feedback.

Another option: Note that this object does basically nothing on construct so we could probably just always construct it and work around it in our tests some other way.

#2 @chriscct7
5 years ago

  • Keywords has-patch added

Patch still applies but per comment:1 needs adjustment

Note: See TracTickets for help on using tickets.