How to Change User Email for User Registration Addon

Overview

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.

An email is sent to your users who register through your form. This email will contain the login information and, if enabled, activation details.

Enable account info or activation email

In the image above, you can see 2 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.

In addition, 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

Setup

So let’s say you wanted to exclude the password from the email that is sent out for security purposes.

In order to do that, you would need to copy and paste the PHP code to your site.

/**
 * Change user email for the User Registration addon.
 *
 * @link https://wpforms.com/developers/change-user-email-for-user-registration-addon/
 *
 * @param  array $email
 * @return array
 */
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 username and password 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 ) . "rn";
	$email['message'] .= wp_login_url() . "rnrn";

	// 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 you account before you can login. Please visit the link below.', 'wpforms_user_registration' ) . "rn";
			$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' ) . "rn";
		}
	}

	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 created under the registration form. 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

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.