From f0d44a3402f0d879863facd32ce0a7fe829d1c8e Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sun, 20 Dec 2020 15:09:06 +0000 Subject: [PATCH] Mail: Introduce a `pre_wp_mail` filter to allow short-circuiting the `wp_mail()` function without having to override the pluggable function. Props DvanKooten, swissspidy, SergeyBiryukov, jtsternberg, ericlewis, Mte90, birgire, ayeshrajans Fixes #35069 Built from https://develop.svn.wordpress.org/trunk@49844 git-svn-id: http://core.svn.wordpress.org/trunk@49563 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/pluggable.php | 38 ++++++++++++++++++++++++++++++++------ wp-includes/version.php | 2 +- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php index 0f984a7e58..7dee482170 100644 --- a/wp-includes/pluggable.php +++ b/wp-includes/pluggable.php @@ -161,12 +161,12 @@ if ( ! function_exists( 'wp_mail' ) ) : * * @global PHPMailer\PHPMailer\PHPMailer $phpmailer * - * @param string|array $to Array or comma-separated list of email addresses to send message. - * @param string $subject Email subject - * @param string $message Message contents - * @param string|array $headers Optional. Additional headers. - * @param string|array $attachments Optional. Paths to files to attach. - * @return bool Whether the email contents were sent successfully. + * @param string|string[] $to Array or comma-separated list of email addresses to send message. + * @param string $subject Email subject. + * @param string $message Message contents. + * @param string|string[] $headers Optional. Additional headers. + * @param string|string[] $attachments Optional. Paths to files to attach. + * @return bool Whether the email was sent successfully. */ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) { // Compact the input, apply the filters, and extract them back out. @@ -188,6 +188,32 @@ if ( ! function_exists( 'wp_mail' ) ) : */ $atts = apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ); + /** + * Filters whether to preempt sending an email. + * + * Returning a non-null value will short-circuit {@see wp_mail()}, returning + * that value instead. A boolean return value should be used to indicate whether + * the email was successfully sent. + * + * @since 5.7.0 + * + * @param null|bool $return Short-circuit return value. + * @param array $atts { + * Array of the `wp_mail()` arguments. + * + * @type string|string[] $to Array or comma-separated list of email addresses to send message. + * @type string $subject Email subject. + * @type string $message Message contents. + * @type string|string[] $headers Additional headers. + * @type string|string[] $attachments Paths to files to attach. + * } + */ + $pre_wp_mail = apply_filters( 'pre_wp_mail', null, $atts ); + + if ( null !== $pre_wp_mail ) { + return $pre_wp_mail; + } + if ( isset( $atts['to'] ) ) { $to = $atts['to']; } diff --git a/wp-includes/version.php b/wp-includes/version.php index ff1704784b..a34a9299ff 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.7-alpha-49843'; +$wp_version = '5.7-alpha-49844'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.