• I have the following function for auto logging in a user. But every time I try it I get the wordpress login form.

    I can see that the cookie gets set. Is there anything I am missing?

    function auto_login( $user_login = null ) {
        if( !is_user_logged_in() ) {
            // get user's ID
            $user = get_user_by( 'login', $user_login );
            $user_id = $user->ID;
            // auto login to WordPress
            wp_set_current_user( $user_id, $user_login );
            wp_set_auth_cookie( $user_id );
            do_action( 'wp_login', $user_login, $user );
            // auto login to WordPress
            wp_redirect( $_GET['redirect_to'] );
    } // end auto_login()
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter frank tredici



    When I first login to a site in my Multisitre network, the following cookies get set:

    And I am taking to my Admin panel.

    Yet when I switch to another site in the network, I only get the following cookie and the WP login form appears and I cannot get past it.

    I do not get the other 4 cookies.

    Thread Starter frank tredici


    I am wondering if it has anything to do with the cookie attribute isHttpOnly?

    I can see that the cookie gets set on wp_set_auth_cookie(); do_action(); with attribute isHttpOnly = “true”, yet once the wp_redirect(); is executed (which is essentially back to itself) the cookie is destroyed.

    BTW, my script was working fine until I upgrade yesterday to WP v4.7.

    • This reply was modified 7 years, 6 months ago by frank tredici.
    Thread Starter frank tredici


    Any wordpress gurus out there?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to auto login a user’ is closed to new replies.