I'm looking for a hook that can be used before WP reads the DB to authenticate the user's login credentials, but can't seem to find one anywhere. Does one exist?

I tried add_filter/action('authenticate', 'customcode', 30, 3), but this seems to execute as soon as the wp-login.php page is requested, rather than after the user hits login and the username/password is POST.

2 Answers 2


If you look at the code for wp-login.php both the login case and the default case run wp_signon(). The reason, so it seems to me, is to manage cases where a user already has a valid cookie for the site. So I don't think there is a hook that fires only upon login, but it is pretty easy to compensate. The first hook along that login path and before authentication is the action hook wp_authenticate not authenticate (though that is a valid hook).

function customcode($username, $password ) {
  if (!empty($username) && !empty($password)) {
    // your code
add_action('wp_authenticate', 'customcode', 30, 2);
  • Thanks.This kind of works too except any responses returned by the authenticate filters ends up overriding any returned by wp_authenticate so, not quite what I was looking for - just me phrasing the question wrong though =/
    – Ken
    Commented Nov 9, 2015 at 10:55

Ah, turns out add_filter/action('authenticate', 'customcode', 30, 3) was what I was looking for...

The problem was, I had the priority too low so whatever response I was creating with my custom code was over-ridden by the other filters.

So dumping global $wp_filter['authenticate'] I could see the following filters:

20, wp_authenticate_username_password
30, wp_authenticate_cookie
99, wp_authenticate_spam_check

By changing the priority to 100 (or higher), I could do the overriding instead and create the response I wanted for handling the login credentials submitted via the login page.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.