In this recipe, we demonstrate how to restrict signups by email, requiring members to use an approved email domain for their member registration. This is useful for Education, Corporate, or Association Memberships, rather than using an approvals-based process, where all of the members may be from the same company or group.
With this code in place, all members must use a valid email that matches your domain (a school, university, or corporate email account) in order to complete membership registration.
How The Code Works
Here’s a breakdown of how this code works to help developers and non-developers better understand all the ways you can customize Paid Memberships Pro.
- Email Validation: During registration, the code extracts the email address (
$_REQUEST['bemail']
), checks if it belongs to an allowed domain usingmy_checkForValidDomain()
, and displays an error message if not valid. - Checking the Domain: The code includes a custom function
my_getDomainFromEmail()
. This function isolates the domain part of the email address, only. - Domain Check: Using the custom
my_checkForValidDomain()
function, the code compares the extracted domain with a predefined list of valid domains (set on line 35), supporting wildcard matches (e.g.,*.gmail.com
).
If the email domain is allowed, registration continues; otherwise, the code restricts signup.
H
The Code Recipe: Restrict Signup by Email
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 the $valid_domains
array to include your approved list of domains. This is the list of email domains that will be allowed to register.
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.