Skip to content

Instantly share code, notes, and snippets.

@topmask
Last active October 27, 2021 05:37
Show Gist options
  • Save topmask/02369ef56a29f96798981edf361d3a9e to your computer and use it in GitHub Desktop.
Save topmask/02369ef56a29f96798981edf361d3a9e to your computer and use it in GitHub Desktop.
Disable bad robots register
function add_security_question_fields() {
$num1=rand(1,9);
$num2=rand(2,9);
echo "<p><label for='math' class='small'>Captcha:$num1 + $num2 = ? </label><input type='text' name='sum' class='input' value='' size='25'>"
."<input type='hidden' name='num1' value='$num1'>"
."<input type='hidden' name='num2' value='$num2'></p>";}
add_action('register_form','add_security_question_fields');
add_action( 'register_post', 'add_security_question_validate', 10, 3 );
function add_security_question_validate( $sanitized_user_login, $user_email, $errors){
$sum=$_POST['sum'];
switch($sum){
case $_POST['num1']+$_POST['num2']:break;
case null:wp_die('Error: Please enter the verification code!');break;
default:wp_die('Error: wrong verification code, please try again!');}}
add_action( 'add_security_question','register_form' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment