
How to Prevent Spam User Registration on WordPress
- November 11, 2016
- Leave a comment
Sometimes, you may face spam user registration on your WordPress website. Reason being that user registration have been turned on and no security was implemented on the registration form. Meanwhile if any spam registration robot attacks on your website, it will register thousands of fake users in a very short time.
To prevent spam user registration on your WordPress website, you can implement end-point email address verification (that will check the existence of that particular email address). To make this check more strong, use the following verify e-mail class:
http://www.phpclasses.org/browse/package/6650/download/zip.html
WordPress provides a pre_user_email filter. Before the insertion of user data into Database, hook this filter by using pt_verify_email_address function.
Now create inc directory in your Theme and upload class.verifyEmail.php file in it. Add the following code into your Theme’s functions.php file and you are done:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?php // Hook filter to verify email address add_filter( 'pre_user_email', 'pt_verify_email_address' ); // function to process email address function pt_verify_email_address( $email ){ include_once 'inc/class.verifyEmail.php'; // include file $vmail = new verifyEmail(); $vmail->setStreamTimeoutWait(20); $vmail->Debug= false; $vmail->setEmailFrom('noreply@yourdomain.com'); // put your domain name here $status = false; if ($vmail->check($email)) { $status = true; } if( $status === false ){ new WP_Error( 'invalid', __( "You have provided invalid email address!", "my_textdomain" ) ); // put your code here, or redirect with error messages wp_safe_redirect( home_url() ); exit; } return $email; } ?> |
User Comments