Paid Memberships Pro has a number of ways that you can control the allowed format and structure of usernames for new members. In this recipe, we show you how to restrict certain words or strings in usernames.
This tutorial is especially useful if your membership site shows usernames in frontend features. For example, if your site has a community forum, directory, or connects to a third-party platform like Discord, you can use this code to preserve the quality of your membership by blocking unwanted terms in their displayed names.
About the Code Recipe
This recipe will allow you to set a list of terms that you do not want people to use in their membership account’s username.
When a username is submitted with one or more restricted words, checkout is blocked and a customizable error message is shown.
The Code Recipe (PHP)
Video: Coding with Sam Walkthrough
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.
Update line 44 to include the terms you want to block, separated by a vertical bar character. You can also customize line 29 to change the displayed error message if the term is used.
More Ways to Restrict User Registrations
Check out these additional tutorials with more ways to restrict user registration:
- Restrict Certain Words in Usernames
- Exclude Certain Email Domains from Membership Signup
- Limit the Number of Members by Membership Level
- Offer a Membership Level for a Limited Time
- Restrict Checkout for Users with a History of Refunds
- Restrict Membership Signup by Country
- Restrict Membership Signup by Email Domain
- Require a Discount Code to Checkout for a Certain Level
- Restrict Membership Checkout by Email or Username
Free Course: Membership Site Development—The Basics
Develop a deeper understanding of membership site development in this beginner-level course. Learn how to make your site work better, save yourself time and money, and improve your site's performance.