Some membership sites need to limit signups to users with an approved email domain. For example, you might only want members with a company, university, or organization email address to register.

This recipe restricts membership checkout in Paid Memberships Pro to a list of approved email domains that you define.

Featured Image for Restrict Membership Signup by Email Domain

Do You Need This Recipe?

This recipe is useful if:

  • You want new members to register with an email address from an approved company, school, or organization domain.
  • You want to allow an entire domain (school.edu) or every subdomain under it (*.school.edu) instead of listing addresses one at a time.
  • You want the restriction to apply to specific membership levels only, leaving others open to any email address.

A few related approaches may fit better depending on your goal. To block specific domains rather than allow a set list, use the companion recipe on excluding email domains from signup. For a manual review step instead of an automated rule, the Approval Process for Membership Add On is a better fit. And to vet members of a Group rather than individual signups (say, a company buying seats for its team), see Restrict Group Child Checkout to Email Domain of Group Leader.

About the Code Recipe

This recipe uses the pmpro_registration_checks filter to validate a user’s email domain during checkout and blocks registrations from unapproved domains.

The callback receives one argument, $continue_registration (bool), which is true by default. It checks the submitted email address’s domain against your allowlist and returns false to stop the checkout if the domain is not approved.

Note: $valid_domains (inside my_check_for_valid_domain()) is your allowlist of approved domains. It includes support for any wildcard subdomains like *.school.edu.

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.

How to Customize This Code Recipe

  • Change the allowed domains: Update the $valid_domains array on line 70 with your organization’s approved domains. Prefix an entry with *. to allow that domain and all of its subdomains.
  • Restrict specific levels only: Remove the two backward slashes directly before the $restricted_levels array on line 32 to uncomment it, and edit level IDs in $restricted_levels to the IDs you want to validate email domains for. Leave the array empty $restricted_levels = array(); to apply to every level.
  • Change the error message: Edit the 'Please enter a valid email address' text passed to pmpro_setMessage() on line 51 to match your site’s voice.


Was this article helpful?
YesNo

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.

Featured Image for Membership Site Development Course: The Basics