Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#53826 closed enhancement (fixed)

wp_mail_succeeded action in wp_mail()

Reported by: birgire Owned by: davidbaumwald
Priority: normal Milestone: 5.9
Component: Mail Version:
Severity: normal Keywords: has-patch commit has-dev-note
Cc: Focuses:

Description

To complement the wp_mail_failed action in wp_mail() we could add the wp_mail_succeeded action.

Here's a suggestion to use e.g.:

$status = $phpmailer->send();

if ( $status ) {

	$mail_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' );

	/**
	 * Fires after PHPMailer has successfully sent a mail.
	 *
	 * @since x.y.z
	 *
	 * @param array $mail_data An array containing the mail recipient, subject, message, headers, and attachments.
	 */
	do_action( 'wp_mail_succeeded', $mail_data );		
}

in wp_mail() instead of:

return $phpmailer->send();

ps: In BuddyPress we have e.g. both bp_send_email_failure and bp_send_email_success actions.

Attachments (1)

53826.diff (1.8 KB ) - added by davidbaumwald 5 years ago.
Added disclaimer, minor spelling corrections

Download all attachments as: .zip

Change History (13)

This ticket was mentioned in PR #1535 on WordPress/wordpress-develop by donmhico.


5 years ago
#1

  • Keywords has-patch added

This PR adds wp_mail_succeeded action.

Trac ticket: https://core.trac.wordpress.org/ticket/53826

#2 @birgire
5 years ago

@donmhico Thanks for the patch, it looks good.

#3 @SergeyBiryukov
5 years ago

  • Milestone Awaiting Review5.9

This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.


5 years ago

#5 @hellofromTonya
5 years ago

  • Milestone 5.9Future Release

Looking at the new action, 'wp_mail_succeeded', why is it in the catch and not the try? If it succeeds, it would not go into the catch.

Today is 5.9 feature freeze. With questions pending, punting this one to 6.0. As that milestone isn't available yet, setting it to Future Release. Once available, please feel free to move it into the milestone.

#6 @davidbaumwald
5 years ago

@hellofromTonya From what I can tell, the patch is good. The wp_mail_succeeded action is in the try section, and the wp_mail_failed action is in the catch.

Whether or not this can be pulled back in for 5.9 is another question, but did want to clear up the the current PR looks OK.

#7 @hellofromTonya
5 years ago

  • Keywords commit added
  • Milestone Future Release5.9

@davidbaumwald you're right. Picture me doing a facepalm (doh). Pulling it back in and marking for commit.

#8 @davidbaumwald
5 years ago

  • Owner set to davidbaumwald
  • Status newreviewing

@hellofromTonya Thanks! I'll pick this one up for review and commit.

@davidbaumwald
5 years ago

Added disclaimer, minor spelling corrections

#9 @davidbaumwald
5 years ago

  • Resolutionfixed
  • Status reviewingclosed

In 52083:

Mail: Add wp_mail_succeeded hook to wp_mail.

Adds a new wp_mail_succeeded action in wp_mail after the mail is sent. Also, adds a disclaimer to the hook's docblock, clarifying that the hook's firing doesn't necessarily mean the recipient received the mail, only that the mail was processed without any errors.

Props birgire, donmhico, johnbillion.
Fixes #53826.

dream-encode commented on PR #1535:


5 years ago
#10

Committed to core via changeset: https://core.trac.wordpress.org/changeset/52083

#11 @davidbaumwald
5 years ago

  • Keywords needs-dev-note added

Marking this with needs-dev-note for a small call-out on the Misc Dev note for the new filter.

#12 @audrasjb
5 years ago

  • Keywords has-dev-note added; needs-dev-note removed
Note: See TracTickets for help on using tickets.