Showing the user’s username in registration email or activation page with BuddyPress [closed]

a) I would like the person’s username to be included in their activation email once they have registered.

e.g. Activation email would look like:
Thanks for registering! To complete the activation of your account please click the following link and log in using USERNAME and password you chose:
activation link url

Or if that is not possible.

b) If it is easier to display it on the page once the activation link has been clicked in the email, I would like to show the person’s username there.

e.g. Activation page:
Your account was activated successfully! You can now log in with the username USERNAME and password you provided when you signed up.

1 Answer
1

You can add the username to the activation e-mail by adding this code either to the bp-custom.php or to the theme’s functions.php file

add_filter('bp_core_signup_send_validation_email_message', 'add_username_to_activation_email',10,3);

function add_username_to_activation_email($msg, $u_id, $activation_url) {
    $username = $_POST['signup_username'];
    $msg .= sprintf( __("After successful activation, you can log in using your username (%1\$s) along with password you choose during registration process.", 'textdomain'), $username);
    return $msg;
}

EDIT: You are right, if the user used a space in his username, Buddypress will not show him an error and the registration process will continue. The next time user tries to log-in using his username with a space, the log-in process will fail. So we have to replace $username = $_POST['signup_username'] as follows:

add_filter('bp_core_signup_send_validation_email_message', 'add_username_to_activation_email',10,3);

function add_username_to_activation_email($msg, $u_id, $activation_url) {
    // $username = $_POST['signup_username'];
    $userinfo = get_userdata($u_id);
    $username = $userinfo->user_login;
    $msg .= sprintf( __("After successful activation, you can log in using your username (%1\$s) along with password you choose during registration process.", 'textdomain'), $username);
    return $msg;
}

Leave a Comment