I have added an extra login field to the main wordpress login page. It is a checkbox which must be checked (to accept terms & conditions), otherwise the user cannot log in.
I have taken code from this question which has allowed me to add a custom checkbox to the login. However, trying to modify the code given to validate whether the checkbox has been checked, I cannot get to work.
function check_checkbox($user) {
$acceptance = $_POST['terms_acceptance'];
$user = get_user_by('login', $username );
if( !$user || !isset($acceptance) ){
remove_action('authenticate', 'wp_authenticate_username_password', 20);
$user = new WP_Error( 'denied', __("<strong>ERROR</strong>: You're unique identifier was invalid.") );
}
return null;
}
add_filter( 'wp_authenticate_user', 'check_checkbox', 10, 3 );
I have tried the 'authenticate' & 'wp_authenticate_user' filters as shown, but neither have worked for me.
Can anyone tell me what I'm doing wrong?