WordPress.org

Make WordPress Core

Ticket #35069: 35069.3.diff

File 35069.3.diff, 1.6 KB (added by swissspidy, 6 years ago)
  • src/wp-includes/pluggable.php

    diff --git src/wp-includes/pluggable.php src/wp-includes/pluggable.php
    index 8e24100..fc952c2 100644
    function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() 
    229229         */
    230230        $atts = apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) );
    231231
     232        /**
     233         * Filter whether to preempt sending an email.
     234         *
     235         * Passing a truthy value will effectively short-circuit {@see wp_mail()},
     236         * returning that value instead.
     237         *
     238         * @since 4.5.0
     239         *
     240         * @param bool  $return Short-circuit return value.
     241         * @param array $args   A compacted array of wp_mail() arguments, including the "to" email,
     242         *                      subject, message, headers, and attachments values.
     243         */
     244        $pre_wp_mail = apply_filters( 'pre_wp_mail', false, $atts );
     245
     246        if ( false !== $pre_wp_mail ) {
     247                return $pre_wp_mail;
     248        }
     249
    232250        if ( isset( $atts['to'] ) ) {
    233251                $to = $atts['to'];
    234252        }
  • tests/phpunit/tests/mail.php

    diff --git tests/phpunit/tests/mail.php tests/phpunit/tests/mail.php
    index c8a435b..389f793 100644
    class Tests_Mail extends WP_UnitTestCase { 
    302302
    303303                $this->assertNotContains( 'quoted-printable', $GLOBALS['phpmailer']->mock_sent[0]['header'] );
    304304        }
     305
     306        /**
     307         * @ticket 35069
     308         */
     309        public function test_wp_mail_bail_early() {
     310                $this->assertTrue( wp_mail( WP_TESTS_EMAIL, 'Foo', 'Bar' ) );
     311
     312                add_filter( 'pre_wp_mail', '__return_null' );
     313                $this->assertNull( wp_mail( WP_TESTS_EMAIL, 'Foo', 'Bar' ) );
     314                remove_filter( 'pre_wp_mail', '__return_null' );
     315        }
    305316}