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() |
180 | 180 | */ |
181 | 181 | $atts = apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ); |
182 | 182 | |
| 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 | |
183 | 201 | if ( isset( $atts['to'] ) ) { |
184 | 202 | $to = $atts['to']; |
185 | 203 | } |
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() { |
407 | 407 | $this->assertEquals( 'wp_mail_failed', $call_args[0]->get_error_code() ); |
408 | 408 | $this->assertEquals( $expected_error_data, $call_args[0]->get_error_data() ); |
409 | 409 | } |
| 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 | } |
410 | 425 | } |