Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#37894 closed defect (bug) (duplicate)

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

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

Description

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 )
    return;

Change History (2)

#1 @stephenharris
10 years ago

  • Milestone Awaiting Review
  • Resolutionduplicate
  • Status newclosed

Duplicate of #35598.

#2 @stephenharris
10 years ago

Thanks for reporting this, this is a known issue, currently been tracked in https://core.trac.wordpress.org/ticket/35598

Note: See TracTickets for help on using tickets.