Title: hook wp_login_failed
Last modified: December 25, 2020

---

# hook wp_login_failed

 *  Resolved [ronenlan](https://wordpress.org/support/users/ronenlan/)
 * (@ronenlan)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/hook-wp_login_failed/)
 * Hey,
 * I am trying to hook action on “wp_login_failed”.
    Unfortunately it seems like
   it executes only if the user got the correct email but the wrong password.
 * Is it suppose to work like this?
 * How can I make it execute also when the user wrote incorrect email or didn’t 
   write one at all. Is there some other hook I should use?
 * Thanks in advance.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Saroj Shah](https://wordpress.org/support/users/wpeverestsupportrep/)
 * (@wpeverestsupportrep)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/hook-wp_login_failed/#post-13838000)
 * Hi [@ronenlan](https://wordpress.org/support/users/ronenlan/)
 * If you would like to to change how blank username/password is treated:
    Please
   use the following code in the functions.php of the active theme of your site.
 *     ```
       add_filter( 'authenticate', 'custom_authenticate_username_password', 30, 3);
       function custom_authenticate_username_password( $user, $username, $password )
       {
           if ( is_a($user, 'WP_User') ) { return $user; }
   
           if ( empty($username) || empty($password) )
           {
               $error = new WP_Error();
               $user  = new WP_Error('authentication_failed', __('<strong>ERROR</strong>: Empty EMAIL!!'));
   
               return $user;
           }
       }
       ```
   
 * And then your original redirect on wp_login_failed will work with blank username/
   password as well.
    Please let me know if you have any questions.
 * Regards!
 *  Thread Starter [ronenlan](https://wordpress.org/support/users/ronenlan/)
 * (@ronenlan)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/hook-wp_login_failed/#post-13849473)
 * Hey Saroj!
 * Thanks a lot for your answer.
 * Unfortunately, it’s still doesn’t work but there is also a problem with non-blank
   fields.
 * For example, if I try to login with an email address that ins’t associated to
   any account, the action is not firing as well.
 * This is the code I am using to catch ‘wp_login_failed’:
 *     ```
       //after unsuccessful login
       add_action('wp_login_failed', 'user_unsuccessful_login', 10, 2);
       function user_unsuccessful_login( $user_login,$error) {
         e()->track("User unsuccessfully tried to log in", array("Email" => $user_login, "Error" => $error->get_error_codes()));
       }
       ```
   
 * This code seems to execute only when the email address is correct and the password
   is not.
 * When the email is blank or not associated to any user account, the function isn’t
   called.
 * This happens also after adding the code you shared with me.
 * Thanks a lot in advance!
 *  Thread Starter [ronenlan](https://wordpress.org/support/users/ronenlan/)
 * (@ronenlan)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/hook-wp_login_failed/#post-13916646)
 * Hey [@wpeverestsupportrep](https://wordpress.org/support/users/wpeverestsupportrep/)
 * Can you please help me with that issue?
 * Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘hook wp_login_failed’ is closed to new replies.

 * ![](https://ps.w.org/user-registration/assets/icon-256x256.gif?rev=3284028)
 * [User Registration & Membership - Free & Paid Memberships, Subscriptions, Content Restriction, User Profile, Custom User Registration & Login Builder](https://wordpress.org/plugins/user-registration/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/user-registration/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/user-registration/)
 * [Active Topics](https://wordpress.org/support/plugin/user-registration/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/user-registration/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/user-registration/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [ronenlan](https://wordpress.org/support/users/ronenlan/)
 * Last activity: [5 years, 4 months ago](https://wordpress.org/support/topic/hook-wp_login_failed/#post-13916646)
 * Status: resolved