For the last 2 hours I've trying to create a mu plugin that requires the user to answer a question first, so he can login in the website.
It is "What is the name of the white horse of Napoleon?", so the user replies "white" and it should work, by theory. The problem is that it seems it is not getting validated during the login. This is my code:
<?php
add_action( 'login_form', 'add_login_field' );
function add_login_field() { ?>
<p>
<label><?php _e('What is the name of the white horse of Napoleon?') ?><br />
<input type="text" name="user_proof" id="user_proof" class="input" size="25" tabindex="20" /></label>
</p>
<?php }
add_action( 'login_post', 'add_login_field_validate', 10, 3 );
function add_login_field_validate( $sanitized_user_login, $user_email, $errors) {
if (!isset($_POST[ 'user_proof' ]) || empty($_POST[ 'user_proof' ])) {
return $errors->add( 'proofempty', '<strong>ERROR</strong>: You did not answer the proof-of-humanship question.' );
} elseif ( strtolower( $_POST[ 'user_proof' ] ) != 'white' ) {
return $errors->add( 'prooffail', '<strong>ERROR</strong>: You did not answer the proof-of-humanship question correctly.' );
}
}
?>
I believe the problem is with the part:
add_action( 'login_post', 'add_login_field_validate', 10, 3 );
Can anyone give me a hand here?