Custom Welcome Email | WordPress

I want to replace the following message when creating a user in the dashboard as an administrator:

Username: xxx

To set your password, visit the following address:

https://development.xxx.com/wp-login.php?action=rpkey=FlFdsDeAveg2EN1HuqGB0Glogin=xxx%40gmail.com

https://development.xxx.com/wp-login.php

This is my non-working function:

/**
 * Custom Welcome Email
 * @author Archie M
 *
 */

add_filter( 'wpmu_signup_user_notification_subject', 'my_activation_subject', 10, 4 );

function my_activation_subject( $text ) {

    return 'Welcome to xxx! (Activation required)';
}

add_filter('wpmu_signup_user_notification_email', 'my_custom_email_message', 10, 4);

function my_custom_email_message($message, $user, $user_email, $key) {

//Here is the new message:

    $message = sprintf(__('Hi %s'), $user-display_name) . "\r\n\r\n";
    $message .= __('Your registration on xxx has been approved.') . "\r\n\r\n";
    $message .= __('To set your password, visit the following address:') . "\r\n\r\n";
    $message .= '' . network_site_url("wp-login.php?action=rpkey=$keylogin=" . rawurlencode($user-user_login), 'login') . "\r\n\r\n";

    return sprintf($message);

}

Where exactly am I missing the point?

Topic email Wordpress

Category Web


You can extend the $wp_new_user_notification_email as below:

$wp_new_user_notification_email = array(
        'to'      => $user->user_email,
        /* translators: Password change notification email subject. %s: Site title */
        'subject' => __( '[%s] Your username and password info' ),
        'message' => $message,
        'headers' => '',
    );

Amazing. I rewrote half of the default function to accomplish what I wanted. I am pretty sure that there is a solution out there:

add_filter( 'wp_new_user_notification_email' , 'edit_user_notification_email', 10, 3 );

function edit_user_notification_email( $wp_new_user_notification_email, $user, $user_email ) {

    global $wpdb, $wp_hasher;

    $key = wp_generate_password( 20, false );

    /** This action is documented in wp-login.php */
    do_action( 'retrieve_password_key', $user->user_login, $key );

    // Now insert the key, hashed, into the DB.
    if ( empty( $wp_hasher ) ) {
        require_once ABSPATH . WPINC . '/class-phpass.php';
        $wp_hasher = new PasswordHash( 8, true );
    }
    $hashed = time() . ':' . $wp_hasher->HashPassword( $key );
    $wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user->user_login ) );

    $switched_locale = switch_to_locale( get_user_locale( $user ) );


    // send message
    $message = sprintf(__('Hi %s'), $user->display_name) . "\r\n\r\n";
    $message .= __('Your registration on xxx.com has been approved.') . "\r\n\r\n";
    $message .= __('To set your password, visit the following address:') . "\r\n\r\n";
    $message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user->user_login), 'login') . ">\r\n\r\n";


    $wp_new_user_notification_email['message'] = $message;

    return $wp_new_user_notification_email;

}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.