Skip to content

Instantly share code, notes, and snippets.

@eirichmond
Created April 27, 2014 08:21
Show Gist options
  • Save eirichmond/11340415 to your computer and use it in GitHub Desktop.
Save eirichmond/11340415 to your computer and use it in GitHub Desktop.
Reduce bot registration for WordPress
//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