Custom Authentication Filter WordPress – Displays Error Message Before Login Attempt

I’m still new to wordpress and php thru extensive google searches i couldn’t figure out a solution to the following problem:

I want to wirte a plugin that hooks in the standard wordpress authentication and only allows useres to login if their email is stored in my db (checking this via soap webservice).
The code and the authentication is working, the only problem is that the error message shows before a login attempt is done and I have no idea how to get rid of that.
Here is the plugin so far:

Read More
add_filter( 'authenticate', 'is_user_member', 102, 3);


 function is_user_member($user, $username, $password){

        $client = new SoapClient("wsdlurl");

        if($user->user_email != NULL){
            $res = $client->EmailMandatorCheck(array('email' => $user->user_email));    
        }

        if(!$res->EmailMandatorCheckResult){
            $user = new WP_Error('denied',__("Sorry"));
        }

        return $user;
}

Thanks

Related posts

1 comment

  1. I’ve found the solution, i was using the wrong filter
    ‘authenticate’ – is triggered before the form is validated (captcha e.g.)
    ‘wp_authenticate_user’ – is triggered after the form is validated

    With changing the filter, it works as inteded.

Comments are closed.