How to auto login a user
-
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'] ); exit; } } // end auto_login()
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘How to auto login a user’ is closed to new replies.