Okay
  Public Ticket #173725
WP-login
Closed

Comments

  • Evil started the conversation
    Hey brian, Help me to remove the redirection to wp-login.php if user input an invalid username or password.
  •  326
    Brian replied

    Hmm, I'm not exactly sure how to stop WordPress from doing that. You see, I just have a normal WP login form and all the functionality of it is built into WordPress - it's not actually theme functionality. So you'd either need to figure out a mod or use a plugin to change the way this works. Basically I guess you'd be looking for something that lets you specify where WordPress redirects the user on invalid login attempts. Check out WordPress support. I'll update if I find anything on my end as well...

  • Evil replied

    I found the solution :D

    add this to flavor/functions.php

    add_action( 'wp_login_failed', 'custom_login_failed' );
    function custom_login_failed( $username )
    {
        $referrer = wp_get_referer();
    
        if ( $referrer && ! strstr($referrer, 'wp-login') && ! strstr($referrer,'wp-admin') )
        {
            wp_redirect( add_query_arg('login', 'failed', $referrer) );
            exit;
        }
    }
  • Evil replied

     add this also to flavor/functions.php

    to disable redirect to wp-login If user tried to login with blank username/password.

    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>: Invalid username or incorrect password.'));
    
            return $error;
        }
    }

     

  •  326
    Brian replied

    Awesome thanks so much for sharing this! I'm sure it will help others who want to do the same thing.