Spammers are everywhere and in weDevs, every single day a lots of spammers are registering. Among of them “.pl” domains are mostly used. Enough is enough, so why not block them? Thats why wrote a function that will check the users email address and will find the country level domain (only the last part of the email address). If it finds in the blocked list, it will not allow the user to register in the site. Simple enough.
[php]
/**
* Block selected top level domains from registering in your site
*
* @param object $errors WP_Error class
* @return object errors
*/
function wedevs_block_user_registration_by_email( $errors ) {
$email = $_POST[‘user_email’];
$ext = substr( strrchr( $email, ‘.’ ), 1 ); // get last part of dot in email
$blocked_domains = array( ‘pl’ );
if ( in_array( $ext, $blocked_domains ) ) {
$errors->add( ’email_blocked’, __( ‘You are blocked from registration.’, ‘dlp’ ) );
}
return $errors;
}
add_filter( ‘registration_errors’, ‘wedevs_block_user_registration_by_email’ );
[/php]
Its show up syntax error line number 8 to your code.
May be you should change the quote.
I don’t see a problem with this idea. I’d add .ru and make the argument an array. You could turn this into a plugin pretty fast.
Sweet.
The option is already an array, just need to add one more element
$blocked_domains = array( 'pl', 'ru' );
Interesting, I didn’t notice many spammers from Poland. In fact, most spammers on my sites have a gmail account or from within russian (ru) domains…
A reliable (but not widely known) anti-spam solution is using hidden empty form fields. See for example http://robmalon.com/hidden-form-fields-to-prevent-bot-spam/
I don’t know, but there were lots of registration I was getting. So I had to stop it somehow 😉
thanks
Hey, I think your blog might be having browser compatibility issues.
When I look at your blog in Chrome, it looks fine but when opening in Internet Explorer, it has some overlapping.
I just wanted to give you a quick heads up! Other then that, excellent blog!
This Post Is very harmful. Thanks For Admin .
Where should the code be pasted?
Doesn’t work at all….. pasted the code into my child theme’s functions.php and it Just locks up the entire web site and the pages don’t get served…. Don’t know what the error is, but it’s clear that there is one in the above code.
May be some unwanted characters got copied and it happens often when you copy from the formatted source code.
No not at all… I just checked what is in my functions.php against what is shown above in your source code and it matches exactly, no additional or incorrect characters at all. It just won’t work. Something not right with it somewhere. But I’m not sure what it is. here is exactly what is in my functions.php file.
*****************************************************************************
function wedevs_block_user_registration_by_email( $errors ) {
$email = $_POST[‘user_email’];
$ext = substr( strrchr( $email, ‘.’ ), 1 ); // get last part of dot in email
$blocked_domains = array( ‘pl’ );
if ( in_array( $ext, $blocked_domains ) ) {
$errors->add( ’email_blocked’, __( ‘You are blocked from registration.’, ‘dlp’ ) );
}
return $errors;
}
add_filter( ‘registration_errors’, ‘wedevs_block_user_registration_by_email’ );
********************************************************************************
If you can see any error in that please do let me know. I can’t see anything obvious.
not sure how much this matters but I noticed that your ‘ symbol is different then the ‘ symbol above in the sample code at the top of page (which worked okay in our blog)