Opened 10 years ago
Last modified 4 years ago
#28618 new enhancement
Allow PHPMailer class to be reliably overriden
Reported by: | leewillis77 | Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 4.0 |
Component: | Keywords: | has-patch | |
Focuses: | Cc: |
Description
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)
Change History (5)
#3
@
4 years ago
- Keywords needs-refresh added
- Milestone set to Future Release
28618.diff needs to be refreshed, and the comments above still need to be addressed.
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.