Remove the username field and allow email only registration

By default, the Restrict Content Pro registration form has two separate fields:

  1. Username
  2. Email

This tutorial will show you how to remove the username field and allow registration with email only. Members will be able to login with their email address directly instead of remembering a separate username.

Step 1: remove the username form field

Add this custom CSS snippet to Appearance > Customize > Additional CSS to hide the username field:

#rcp_user_login_wrap {
    display: none;
}

Step 2: set the email as the username

Just removing the field isn't enough, because RCP is expecting a username to be entered and will throw an error if it's not filled out. To combat this, we need to remove the "Username is empty" error message and assign the email as the username. To do that, add this code to your child theme's functions.php file or to a custom plugin:

<?php
/**
 * This will remove the username requirement on the registration form
 * and use the email address as the username.
 */
function jp_rcp_user_registration_data( $user ) {
	rcp_errors()->remove( 'username_empty' );
	$user['login'] = $user['email'];
	return $user;
}

add_filter( 'rcp_user_registration_data', 'jp_rcp_user_registration_data' );