Make WordPress Core

Ticket #35069: 35069.6.patch

File 35069.6.patch, 1.8 KB (added by ayeshrajans, 5 years ago)

Rerolling the patch against 5.4 branch. Tests: https://travis-ci.org/Ayesh/wordpress-develop/builds/647197094 (passing)

  • src/wp-includes/pluggable.php

    diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php
    index 81db29542b..dc244186cc 100644
    a b function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() 
    180180                 */
    181181                $atts = apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) );
    182182
     183                /**
     184                * Filter whether to preempt sending an email.
     185                *
     186                * Passing a non-null value will effectively short-circuit {@see wp_mail()},
     187                * returning that value instead.
     188                *
     189                * @since 5.0.0
     190                *
     191                * @param null|bool $return Short-circuit return value.
     192                * @param array     $atts   A compacted array of `wp_mail()` arguments, including the "to" email,
     193                *                          subject, message, headers, and attachments values.
     194                */
     195                $pre_wp_mail = apply_filters( 'pre_wp_mail', null, $atts );
     196
     197                if ( null !== $pre_wp_mail ) {
     198                        return $pre_wp_mail;
     199                }
     200
    183201                if ( isset( $atts['to'] ) ) {
    184202                        $to = $atts['to'];
    185203                }
  • tests/phpunit/tests/mail.php

    diff --git a/tests/phpunit/tests/mail.php b/tests/phpunit/tests/mail.php
    index e2db915265..135ebbab9a 100644
    a b public function test_phpmailer_exception_thrown() { 
    407407                $this->assertEquals( 'wp_mail_failed', $call_args[0]->get_error_code() );
    408408                $this->assertEquals( $expected_error_data, $call_args[0]->get_error_data() );
    409409        }
     410
     411        /**
     412         * Test for bailing out of wp_mail() early.
     413         *
     414         * @ticket 35069
     415         */
     416        public function test_wp_mail_bail_early() {
     417                $this->assertTrue( wp_mail( WP_TESTS_EMAIL, 'Foo', 'Bar' ) );
     418
     419                add_filter( 'pre_wp_mail', '__return_false' );
     420                $result = wp_mail( WP_TESTS_EMAIL, 'Foo', 'Bar' );
     421                remove_filter( 'pre_wp_mail', '__return_false' );
     422
     423                $this->assertFalse( $result );
     424        }
    410425}