WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 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:
Milestone: Priority: normal
Severity: normal Version: 4.7
Component: General Keywords:
Focuses: Cc:

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
4 years ago

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

Duplicate of #35598.

#2 @stephenharris
4 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.