Make WordPress Core


Ignore:
Timestamp:
12/20/2020 03:07:23 PM (6 years ago)
Author:
johnbillion
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/pluggable.php

    r49692 r49844  
    162162         * @global PHPMailer\PHPMailer\PHPMailer $phpmailer
    163163         *
    164          * @param string|array $to          Array or comma-separated list of email addresses to send message.
    165          * @param string       $subject     Email subject
    166          * @param string       $message     Message contents
    167          * @param string|array $headers     Optional. Additional headers.
    168          * @param string|array $attachments Optional. Paths to files to attach.
    169          * @return bool Whether the email contents were sent successfully.
     164         * @param string|string[] $to          Array or comma-separated list of email addresses to send message.
     165         * @param string          $subject     Email subject.
     166         * @param string          $message     Message contents.
     167         * @param string|string[] $headers     Optional. Additional headers.
     168         * @param string|string[] $attachments Optional. Paths to files to attach.
     169         * @return bool Whether the email was sent successfully.
    170170         */
    171171        function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
     
    188188                 */
    189189                $atts = apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) );
     190
     191                /**
     192                 * Filters whether to preempt sending an email.
     193                 *
     194                 * Returning a non-null value will short-circuit {@see wp_mail()}, returning
     195                 * that value instead. A boolean return value should be used to indicate whether
     196                 * the email was successfully sent.
     197                 *
     198                 * @since 5.7.0
     199                 *
     200                 * @param null|bool $return Short-circuit return value.
     201                 * @param array     $atts {
     202                 *     Array of the `wp_mail()` arguments.
     203                 *
     204                 *     @type string|string[] $to          Array or comma-separated list of email addresses to send message.
     205                 *     @type string          $subject     Email subject.
     206                 *     @type string          $message     Message contents.
     207                 *     @type string|string[] $headers     Additional headers.
     208                 *     @type string|string[] $attachments Paths to files to attach.
     209                 * }
     210                 */
     211                $pre_wp_mail = apply_filters( 'pre_wp_mail', null, $atts );
     212
     213                if ( null !== $pre_wp_mail ) {
     214                        return $pre_wp_mail;
     215                }
    190216
    191217                if ( isset( $atts['to'] ) ) {
Note: See TracChangeset for help on using the changeset viewer.