This post covers two ways to control the allowed format and structure of usernames for new members.
Allow Members to Use an Email Address as Their Username
If your site doesn’t have a need for public or frontend-facing usernames, you may want to simplify checkout by setting a user’s email address as their username. With the vast number of sites we are all members of, it has become extremely difficult to remember what username I created where. It’s much easier to remember your login credentials when using an email address as your login name.
During a default membership checkout, users are prompted to create a “Username” and enter their “Email Address”. This code recipe will take the information inserted in the Email Address field of the Membership Checkout page and use it as the member’s username.
The Code Recipe
Reformat Usernames to Use Allowed Characters After Checkout
This code recipe will convert a member’s username to match your specific rules. In this example, we convert all characters to lowercase and replace any spaces found in the username with underscores. If a member inputs a username like “John Doe”, then this will be changed to “john_doe”.
One of our members recently had a support request related to the format of usernames. Their request was for appearance reasons, but there are other cases where you would like usernames to follow stricter guidelines. For example, if you are using a single sign on bridge to integrate your members with a third-party application, you may need to match the requirements of usernames for that external site.
This code can also be useful in cases where the member’s username appears in other features of your site, such as on a BuddyPress profile.
The Code Recipe
Adding the Recipe to Your Website
You can add this recipe to your site by creating a custom plugin or using the Code Snippets plugin available for free in the WordPress repository. Read this companion article for step-by-step directions on either method.
More Username-Related Articles to Explore
- Membership Checkout Optimization: 3 Ways to Reduce Form Fields at Checkout
- How to prevent users from using their email address as a username in your membership site.
- How to offer email only signups for streamlined membership registration and checkout