Make WordPress Core

Ticket #23291: 23291.3.diff

File 23291.3.diff, 5.0 KB (added by iandunn, 11 years ago)

Changed $return = 'bool' | 'wp_error' to $wp_error = true | false

  • wp-admin/includes/upgrade.php

     
    276276http://wordpress.org/
    277277"), $blog_url, $name, $password);
    278278
    279         @wp_mail($email, __('New WordPress Site'), $message);
     279        wp_mail( $email, __( 'New WordPress Site' ), $message );
    280280}
    281281endif;
    282282
  • wp-includes/pluggable.php

     
    209209 * @param string $message Message contents
    210210 * @param string|array $headers Optional. Additional headers.
    211211 * @param string|array $attachments Optional. Files to attach.
    212  * @return bool Whether the email contents were sent successfully.
     212 * @param string $wp_error Optional. false to return boolean false on error, true to return a WP_Error object. Defaults to false.
     213 * @return bool|WP_Error Boolean true if the email was sent successfully. Boolean false or WP_Error if sending failed. WP_Error if email was sent, but with errors.
    213214 */
    214 function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
     215function wp_mail( $to, $subject, $message, $headers = '', $attachments = array(), $wp_error = false ) {
     216        $errors = new WP_Error();
     217       
    215218        // Compact the input, apply the filters, and extract them back out
    216219        extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) );
    217220
     
    356359                        }
    357360                        $phpmailer->AddAddress( $recipient, $recipient_name);
    358361                } catch ( phpmailerException $e ) {
     362                        $errors->add( 'mailer_add_address', $e->getMessage() );
    359363                        continue;
    360364                }
    361365        }
     
    378382                                }
    379383                                $phpmailer->AddCc( $recipient, $recipient_name );
    380384                        } catch ( phpmailerException $e ) {
     385                                $errors->add( 'mailer_add_cc', $e->getMessage() );
    381386                                continue;
    382387                        }
    383388                }
     
    396401                                }
    397402                                $phpmailer->AddBcc( $recipient, $recipient_name );
    398403                        } catch ( phpmailerException $e ) {
     404                                $errors->add( 'mailer_add_bcc', $e->getMessage() );
    399405                                continue;
    400406                        }
    401407                }
     
    439445                        try {
    440446                                $phpmailer->AddAttachment($attachment);
    441447                        } catch ( phpmailerException $e ) {
     448                                $errors->add( 'mailer_add_attachment', $e->getMessage() );
    442449                                continue;
    443450                        }
    444451                }
     
    450457        try {
    451458                $phpmailer->Send();
    452459        } catch ( phpmailerException $e ) {
    453                 return false;
     460                $errors->add( 'mailer_send', $e->getMessage() );
     461               
     462                if ( true == $wp_error )
     463                        return $errors;
     464                else
     465                        return false;
    454466        }
    455467
    456         return true;
     468        if ( true == $wp_error && count( $errors->get_error_codes() > 0 ) )
     469                return $errors;
     470        else
     471                return true;
    457472}
    458473endif;
    459474
     
    10751090        $subject = apply_filters('comment_notification_subject', $subject, $comment_id);
    10761091        $message_headers = apply_filters('comment_notification_headers', $message_headers, $comment_id);
    10771092
    1078         @wp_mail( $author->user_email, $subject, $notify_message, $message_headers );
     1093        wp_mail( $author->user_email, $subject, $notify_message, $message_headers );
    10791094
    10801095        return true;
    10811096}
     
    11581173        $message_headers = apply_filters('comment_moderation_headers', $message_headers);
    11591174
    11601175        foreach ( $email_to as $email )
    1161                 @wp_mail($email, $subject, $notify_message, $message_headers);
     1176                wp_mail( $email, $subject, $notify_message, $message_headers );
    11621177
    11631178        return true;
    11641179}
     
    12081223        $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
    12091224        $message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
    12101225
    1211         @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message);
     1226        wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] New User Registration' ), $blogname ), $message );
    12121227
    12131228        if ( empty($plaintext_pass) )
    12141229                return;
  • wp-login.php

     
    247247        $title = apply_filters('retrieve_password_title', $title);
    248248        $message = apply_filters('retrieve_password_message', $message, $key);
    249249
    250         if ( $message && !wp_mail($user_email, $title, $message) )
    251                 wp_die( __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function...') );
     250        if ( $message ) {
     251                $mail_status = wp_mail( $user_email, $title, $message, '', array(), true );
     252               
     253                // mailer_send indicates the messages wasn't sent. Other error codes indicate the message was sent even though errors occurred.
     254                if ( is_wp_error( $mail_status ) && in_array( 'mailer_send', $mail_status->get_error_codes() ) ) {
     255                        $mail_error_messages = implode( ". ", $mail_status->get_error_messages() );
     256                        wp_die( __( 'The e-mail could not be sent.' ) . "<br />\n" . sprintf( __( '<strong>ERROR</strong>: %s' ), $mail_error_messages ) );
     257                }
     258        }
     259        else {
     260                $errors->add( 'message_empty', __( '<strong>ERROR</strong>: Message was empty.' ) );
     261                return $errors;
     262        }
    252263
    253264        return true;
    254265}