How to Change User Email for User Registration Addon

Introduction

Do you want to change the email for users that is sent out by the User Registration addon from WPForms? We can show you how easily this can be done by using a filter. In this article, we’ll show you how to change the email sent out with the User Registration addon.

Creating the form

We’ll begin by creating a user registration form. If you need help in creating this specific form, please review this documentation.

Next, click on the Settings tab inside the form builder and select User Registration tab to enable a few settings.

Enable account info or activation email

In the image above, you can see two options highlighted and enabled.

If you check either of these options, the email will include the username, password, and a link to the site’s login URL.

An email is sent to your users who register through your form. This email will contain the login information and, if enabled, activation details. When the User Activation Method is checked, the same email will also include some additional details based on the selection chosen. Let’s take a look at each of those options below.

  • User Email: There will be brief instructions and an activation link at the end of the email.
  • Manual Approval: The end of the email will let the user know that the administrator will need to manually approve their request.

WPForms user activation email

Adding the snippet to change user email

For our example, we don’t want to exclude the password in our email, so we’re going to add this code snippet.

If you need help in how to add snippets to your site, please see this tutorial.

/**
 * Change user email for the User Registration addon.
 *
 * @link https://wpforms.com/developers/change-user-email-for-user-registration-addon/
 */
function wpf_dev_user_registration_user_email( $email ) {

	$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );

	// Set the email subject line
	$email['subject']  = sprintf( __( '[%s] Your account info' ), $blogname );

	// The primary part of the email message consists of providing the user
	// with their username, password, and login URL.
	$email['message'] = sprintf( __( 'Username: %s' ), $email['user']->user_login ) . "\r\n";
	$email['message'] .= wp_login_url() . "\r\n\r\n";

	// Add more details if to the email message if user activation is enabled
	if ( $email['activation'] ) {

		// Append "Activation Required" to the existing email subject line
		$email['subject'] .= __( ' (Activation Required)', 'wpforms_user_registration' );

		// If activation method is User Email
		if ( 'user' == $email['activation']  ) {
			$email['message'] .= __( 'IMPORTANT: You must activate your account before you can login. Please visit the link below.', 'wpforms_user_registration' ) . "\r\n";
			$email['message'] .= $email['link'];
		// If activation method is Manual Approval
		} else {
			$email['message'] .= __( 'Site administrator must activate your account before you can login.', 'wpforms_user_registration' ) . "\r\n";
		}
	}

	return $email;
}
add_filter( 'wpforms_user_registration_email_user', 'wpf_dev_user_registration_user_email', 10, 1 );

And that’s it! Using the code above, the email notification will no longer contain the password inside the email notification. Would you like to further customize your email confirmations? Have a look at our article on How to Hide Image Choices in Notification Emails.

Filter reference: wpforms_user_registration_email_user

FAQ

Q: Where do I add this code?

A: For any tips on adding custom JavaScript, PHP or even CSS, please review our Tutorials section. There you’ll find a complete list on helpful how to’s for adding CSS, PHP or Javascript.

Q: What if I want to remove the username and password from the email?

A: If you only want to provide the login link, use this code snippet instead.

/**
 * Change user email for the User Registration addon.
 *
 * @link https://wpforms.com/developers/change-user-email-for-user-registration-addon/
 */
function wpf_dev_user_registration_user_email( $email ) {
 
    $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
 
    // Set the email subject line
    $email['subject']  = sprintf( __( '[%s] Your registration has been approved!' ), $blogname );
 
    // The primary part of the email message consists of providing the user
    // with their username, password, and login URL.
    $email['message'] = sprintf( __( 'The username and password has been removed from this email for security reasons, but you can use the following link to login.' ));
    $email['message'] .= wp_login_url() . "\r\n\r\n";
 
    // Add more details if to the email message if user activation is enabled
    if ( $email['activation'] ) {
 
        // Append "Activation Required" to the existing email subject line
        $email['subject'] .= __( ' (Activation Required)', 'wpforms_user_registration' );
 
        // If activation method is User Email
        if ( 'user' == $email['activation']  ) {
            $email['message'] .= __( 'IMPORTANT: You must activate your account before you can login. Please visit the link below.', 'wpforms_user_registration' ) . "\r\n";
            $email['message'] .= $email['link'];
        // If activation method is Manual Approval
        } else {
            $email['message'] .= __( 'Site administrator must activate your account before you can login.', 'wpforms_user_registration' ) . "\r\n";
        }
    }
 
    return $email;
}
add_filter( 'wpforms_user_registration_email_user', 'wpf_dev_user_registration_user_email', 10, 1 );