« first day (1411 days earlier)      last day (3548 days later) » 

3:06 AM
@StephenHarris thankfully wp_mail is pluggable, override that bitch :)
 
 
5 hours later…
7:42 AM
@toscho unit tests... right... :D
 
 
5 hours later…
12:32 PM
@userabuser no help in a distributed plug-in :(. If you want to add a string attachment and wp_mail(), you have to end up using globals :(.
 
@StephenHarris you can filter the PHPMailer object temporary
 
posted on August 27, 2014 by Helen Hou-Sandi

The first release candidate for WordPress 4.0 is now available! In RC 1, we’ve made refinements to what we’ve been working on for this release. Check out the Beta 1 announcement post for more details on those features. We hope to ship WordPress 4.0 next week, but we need your help to get there. If you […]

 
@toscho Do you mean access $phpmailer global, immediately prior to use?
There's the phpmailer_init action, but you have no context (without hacky use of globals)
 
add_filter( 'phpmailer_init', 'fix_phpmailer' );
wp_mail( 'foo@example.com', 'test', 'test' );
remove_filter( 'phpmailer_init', 'fix_phpmailer' );

function fix_phpmailer( PHPMailer $mail ) {
	$mail->addBCC( 'hello@example.com' );
}
 
@StephenHarris yeah fair point indeed :/
ah
 
12:40 PM
@toscho Yes, but you loose context in fix_phpmailer() that you would have when calling wp_mail(). (unless you use globals, class variables if using a class).
For the record, accessing $phpmailer prior to calling wp_mail() won't work either, as wp_mail() 'cleans' the object.
 
Then add a custom header to wp_mail() and inspect the headers in the init callback
 
@toscho mmm... that could work. I'd need to look into what ill-affects polluting the headers would have (if any), in case (for whatever) reason, cleaning up of the headers doesn't work. Thanks :)
 
you don’t have to use wp_mail(), you can use just a new PHPMailer instance
 
Is there any reason why WP stores phpmailer as a global, rather than creating a fresh instance for each e-mail? Is it costly to instantiate?
 
because globals are so good, WordPress cannot have enough of them
3
 
12:45 PM
@toscho You don't, but there are a lot of filters which plug-ins reply on in wp_mail(). Not using it breaks compatibility. Alternatively is to create a factory which does this set up on the phpmailer instance, but then I need to ensure that is in sync with WordPress core...
 
hm, what exactly is stopping you from creating the global PHPMailer instance before you use wp_mail()?
 
Might be the way to go though. I'm going to open a trac ticket and submit a patch to that affect. wp_mail() would then be reduced to a function which gets a new instance from the phpmailer factor, populates passed details (message/subject/recipients etc), and sends it.
@toscho wp_mail() calls $phpmailer->clearAttachments() -more generally it appears simply clean up the instance...
 
oh my
then create a child class, mock these methods
 
Understandable when you are leaving a global lying around. Wouldn't want to send last recipients email to the next recipient :). But why use a global here at all?
@toscho That seems hackiest solution yet..., clearAttachments() method which doesn't clear the attachments :).
 
keep in mind, all of this is PHP 4 code (do_action_ref_array()), and in PHP 4, new instances were slightly more expensive than in PHP 5.
 
12:55 PM
@toscho Ah ok, that would explain the use of a global. But that would only be the case if run in a php5 environment, no? So it doesn't need to stay like that.
 
old code, does too much,not enough unit tests, so nobody dares to touch it.
 
wp_mail() is pluggable too. So that global is there to stay even if it's just a clone.
 
 
4 hours later…
4:51 PM
SE network updates: Runnable code snippets are being tested on Meta Stack Overflow.
posted on August 25, 2014

Runnable code snippets are being tested on Meta Stack Overflow.

 

« first day (1411 days earlier)      last day (3548 days later) »