Make WordPress Core

Ticket #38028: wp-mail.38028.diff

File wp-mail.38028.diff, 2.8 KB (added by markcallen, 8 years ago)

Retrieve password email triggered through action

  • src/wp-login.php

    diff --git src/wp-login.php src/wp-login.php
    index 5266dd7..bf38c36 100644
    function retrieve_password() { 
    320320                return $errors;
    321321        }
    322322
    323         // Redefining user_login ensures we return the right case in the email.
    324         $user_login = $user_data->user_login;
    325         $user_email = $user_data->user_email;
    326323        $key = get_password_reset_key( $user_data );
    327324
    328325        if ( is_wp_error( $key ) ) {
    329326                return $key;
    330327        }
    331328
    332         $message = __('Someone has requested a password reset for the following account:') . "\r\n\r\n";
    333         $message .= network_home_url( '/' ) . "\r\n\r\n";
    334         $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
    335         $message .= __('If this was a mistake, just ignore this email and nothing will happen.') . "\r\n\r\n";
    336         $message .= __('To reset your password, visit the following address:') . "\r\n\r\n";
    337         $message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login') . ">\r\n";
     329        do_action( 'wp_mail_retrieve_password', $user_data, $key );
     330        return true;
    338331
    339         if ( is_multisite() ) {
    340                 $blogname = get_current_site()->site_name;
    341         } else {
     332}
     333
     334add_action( 'wp_mail_retrieve_password', 'send_retrieve_password_email', 10, 2 );
     335
     336function send_retrieve_password_email( $user_data, $key ) {
     337
     338        $user_login = $user_data->user_login;
     339        $user_email = $user_data->user_email;
     340
     341        $message  = __('Someone has requested a password reset for the following account:') . "\r\n\r\n";
     342        $message .= network_home_url( '/' ) . "\r\n\r\n";
     343        $message .= sprintf( __( 'Username: %s' ), $user_login ) . "\r\n\r\n";
     344        $message .= __( 'If this was a mistake, just ignore this email and nothing will happen.' ) . "\r\n\r\n";
     345        $message .= __( 'To reset your password, visit the following address:') . "\r\n\r\n";
     346        $message .= '<' . network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) . ">\r\n";
     347
     348        if ( is_multisite() )
     349                $blogname = $GLOBALS['current_site']->site_name;
     350        else
    342351                /*
    343352                 * The blogname option is escaped with esc_html on the way into the database
    344353                 * in sanitize_option we want to reverse this for the plain text arena of emails.
    345354                 */
    346                 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    347         }
     355                $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
    348356
    349         $title = sprintf( __('[%s] Password Reset'), $blogname );
     357        $title = sprintf( __( '[%s] Password Reset' ), $blogname );
    350358
    351359        /**
    352360         * Filters the subject of the password reset email.
    function retrieve_password() { 
    376384        if ( $message && !wp_mail( $user_email, wp_specialchars_decode( $title ), $message ) )
    377385                wp_die( __('The email could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function.') );
    378386
    379         return true;
    380387}
    381388
    382389//