In this tutorial, I will show you how to enhance the registration process in the Voxel WordPress theme by blocking specific email domains(as given by Voxel in the latest update) and usernames. This can be a valuable addition to your website’s security and user management. I’ll guide you through the process of adding this functionality to your child theme’s function file.
Step 1: Prepare Your Child Theme
Before making any changes, make sure you have a child theme set up. This will ensure that your customizations won’t be lost when you update the Voxel theme. If you don’t have a child theme, you can create one using the official WordPress guide or just copy the provided one by Voxel.
Step 2: Open Your Child Theme’s Function File
In your child theme’s directory, locate the functions.php
file and open it for editing. If the file doesn’t exist, create it.
Step 3: Add the Custom Filter
Inside your functions.php
file, add the following code:
add_filter( 'voxel/registration-errors', function( $errors, $username, $email, $role ) {
if ( ! is_email( $email ) ) {
return $errors;
}
$email_domain = substr( $email, strrpos( $email, '@' ) + 1 );
$block_domains = [
'domain1.com',
'domain2.com',
// Add more domains to block here
];
// Check for blocked email domains
foreach ( $block_domains as $domain_partial ) {
if ( stripos( $email_domain, $domain_partial ) !== false ) {
$errors->add( 'email_error', 'Blocked domain.' );
}
}
// Check for blocked usernames
$blocked_usernames = [
'admin', // Add other usernames to block here
];
if ( in_array( $username, $blocked_usernames ) ) {
$errors->add( 'username_error', 'Blocked username.' );
}
return $errors;
}, 10, 4 );
This code adds a filter to the registration process, checking for blocked email domains and usernames.
Step 4: Customize the Blocking Rules
You can customize the list of blocked email domains and usernames by editing the $block_domains
and $blocked_usernames
arrays in the code. Add or remove domains and usernames as needed.
Step 5: Save and Test
Save your functions.php
file, and now your enhanced registration process is ready. Test it by attempting to register with blocked usernames or email domains. Users should receive appropriate error messages.
Here is an example list of disposable email providers you could ban:
imailfree.cc
thepacbook.com
1secmail.org
10minutemail.com
guerrillamail.com
mailinator.com
yopmail.com
yopmail.fr
maildrop.cc
dispostable.com
throwawaymail.com
getnada.com
example.com
throwaway-email.com
jetable.org
mailnesia.com
mytrashmail.com
mintemail.com
sharklasers.com
fakemailgenerator.net
moakt.com
getairmail.com
mailcatch.com
discard.email
tempinbox.com
inboxbear.com
meltmail.com
mailinator2.com
kasmail.com
Pros of Avoiding Third-Party Plugins:
In this tutorial, I’ve shown you how to enhance the registration process in the Voxel WordPress theme by blocking specific usernames and email domains. This can help you maintain a more secure and spam-“free” user base while avoiding the need for third-party plugins. Remember to keep your child theme up to date and periodically review your blocking rules for any necessary adjustments.
If you do not have Voxel yet, you can support me by getting it through this link: Get Voxel
And check out my other Voxel related blog posts!
If you like my tutorials and snippets, and want to motivate me, or just say thanks,
feel free to support me by buying me a tea (as I do not drink coffee) :)
This website may contain affiliate links. If you click on a link and make a purchase, I may earn a small commission at no additional cost to you. This helps support the time and effort put into maintaining this website. I only recommend products and services I genuinely believe will be helpful to you. Thank you for your support!