Prevent User Registration From Specific Domain

 In Security

Normally it is  a good idea to disable user registration  if you are not planing to use membership feature, because could lead spammers can attack your website with spam user registrations.

I used registration_errors hook in WordPress which filters the errors encountered when a new user is being registered. If any errors are present, WordPress will abort the user’s registration. This filter can also be used to create custom validation rules on user registration. This hook fires when the form is submitted but before user information is saved to the database. So I created custom rule to check user’s email domain and provide error if user’s email match blacklisted domain.

Here is the function you can dump in your theme’s functions.php file. The following function will prevent user registration if WordPress find “domain.Com” in user’s email address.


Nuno Sarmento
I am full-stack WordPress developer based in London with a wealth of theme development and support experience. I am great at problem solving and developing quick solutions. I specialise in custom WordPress theme development and bug fixing.
Recommended Posts

Leave a Comment

Start typing and press Enter to search