WordPress.org

Make WordPress Core

Ticket #35069: 35069.4.diff

File 35069.4.diff, 1.7 KB (added by Mte90, 4 years ago)

use null

  • src/wp-includes/pluggable.php

    diff --git src/wp-includes/pluggable.php src/wp-includes/pluggable.php
    index c4e271518b..1b36b52cfe 100644
    function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() 
    183183         */
    184184        $atts = apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) );
    185185
     186        /**
     187         * Filter whether to preempt sending an email.
     188         *
     189         * Passing a truthy value will effectively short-circuit {@see wp_mail()},
     190         * returning that value instead.
     191         *
     192         * @since 4.5.0
     193         *
     194         * @param bool  $return Short-circuit return value.
     195         * @param array $args   A compacted array of wp_mail() arguments, including the "to" email,
     196         *                      subject, message, headers, and attachments values.
     197         */
     198        $pre_wp_mail = apply_filters( 'pre_wp_mail', null, $atts );
     199
     200        if ( ! is_null ( $pre_wp_mail ) ) {
     201                return $pre_wp_mail;
     202        }
     203
    186204        if ( isset( $atts['to'] ) ) {
    187205                $to = $atts['to'];
    188206        }
  • tests/phpunit/tests/mail.php

    diff --git tests/phpunit/tests/mail.php tests/phpunit/tests/mail.php
    index 1522594b0d..a4a8fb2d1d 100644
    class Tests_Mail extends WP_UnitTestCase { 
    392392                $this->assertEquals( 'wp_mail_failed', $call_args[0]->get_error_code() );
    393393                $this->assertEquals( $expected_error_data, $call_args[0]->get_error_data() );
    394394        }
     395
     396        /**
     397         * @ticket 35069
     398         */
     399        public function test_wp_mail_bail_early() {
     400                $this->assertTrue( wp_mail( WP_TESTS_EMAIL, 'Foo', 'Bar' ) );
     401
     402                add_filter( 'pre_wp_mail', '__return_null' );
     403                $this->assertNull( wp_mail( WP_TESTS_EMAIL, 'Foo', 'Bar' ) );
     404                remove_filter( 'pre_wp_mail', '__return_null' );
     405        }
    395406}