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”.

About the Code Recipe

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.

We also see many members using their email address as their username. To protect a user’s contact information, you may want to extend this recipe to convert the @ symbol so that a user’s email address isn’t displayed publicly.

The Code Recipe

This code recipe requires a Plus Account or higher.

View Membership Options


Tagged . Bookmark the . Last updated: .