Created
April 27, 2014 08:21
-
-
Save eirichmond/11340415 to your computer and use it in GitHub Desktop.
Reduce bot registration for WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//1. Add a new form element... | |
add_action('register_form','erwp_register_form'); | |
function erwp_register_form (){ | |
$spam = ( isset( $_POST['fooey'] ) ) ? $_POST['fooey']: ''; | |
?> | |
<input type="text" name="fooey" value="<?php echo esc_attr(stripslashes($spam)); ?>" style="display: none;" /> | |
<?php | |
} | |
//2. Add validation. In this case, we make sure fooey is empty. | |
add_filter('registration_errors', 'erwp_registration_errors', 10, 3); | |
function erwp_registration_errors ($errors, $sanitized_user_login, $user_email) { | |
if ( !empty( $_POST['fooey'] ) ) | |
$errors->add( 'spam_error', __('<strong>ERROR</strong>: Opps, this looks a bit spammy, please try again!','cheltsocial') ); | |
return $errors; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment