Mail: Set a better error code when triggering `wp_mail_failed`.

This error code is now... wait for it... `wp_mail_failed`. Previously, this would have been the originating PHPMailer error code, which could be `0`, which would then fail (pass?) the `empty()` check in the `WP_Error` constructor, thereby rendering the error object fairly useless. The PHPMailer error code is now located within the `WP_Error` data.

props Kau-Boy, stephenharris.
fixes #35598.

Built from https://develop.svn.wordpress.org/trunk@39086


git-svn-id: http://core.svn.wordpress.org/trunk@39028 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Helen Hou-Sandí 2016-11-02 04:27:34 +00:00
parent ba039f7546
commit dab566d973
2 changed files with 4 additions and 3 deletions

View File

@ -472,16 +472,17 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
} catch ( phpmailerException $e ) { } catch ( phpmailerException $e ) {
$mail_error_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' ); $mail_error_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
$mail_error_data['phpmailer_exception_code'] = $e->getCode();
/** /**
* Fires after a phpmailerException is caught. * Fires after a phpmailerException is caught.
* *
* @since 4.4.0 * @since 4.4.0
* *
* @param WP_Error $error A WP_Error object with the phpmailerException code, message, and an array * @param WP_Error $error A WP_Error object with the phpmailerException message, and an array
* containing the mail recipient, subject, message, headers, and attachments. * containing the mail recipient, subject, message, headers, and attachments.
*/ */
do_action( 'wp_mail_failed', new WP_Error( $e->getCode(), $e->getMessage(), $mail_error_data ) ); do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_error_data ) );
return false; return false;
} }

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.7-beta1-39085'; $wp_version = '4.7-beta1-39086';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.