Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#37894 closed defect (bug) (duplicate)

WP_Error::__construct ignoring $message and $data when raised from exceptions without a code

Reported by: zw7's profile zw7 Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7
Component: General Keywords:
Focuses: Cc:


I ran into this problem while debugging wp_mail function:
line 483 of wp-includes/pluggable.php

do_action( 'wp_mail_failed', new WP_Error( $e->getCode(), $e->getMessage(), $mail_error_data ) );

WP_Error::construct ignores $message and $data parameters if $code parameter is empty, however the whole phpmailer library throws exceptions without the code parameter, making the Exception::getCode() function return integer 0.

The problem could be solved by giving a custom error code in the wp_mail function, but i believe this is a general problem that could be raised by other sources, so we should also allow $code parameter in WP_Error constructor to be equal to 0

Something like

if ( empty($code) && $code !== 0 )

Change History (2)

#1 @stephenharris
8 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #35598.

#2 @stephenharris
8 years ago

Thanks for reporting this, this is a known issue, currently been tracked in

Note: See TracTickets for help on using tickets.