• Resolved ronenlan

    (@ronenlan)


    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

    (@wpeverestsupportrep)

    Hi @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

    (@ronenlan)

    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

    (@ronenlan)

    Hey @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.