1

I'm building a plugin that allows oauth2 logins from providers (eg google). My code is setting the wordpress_logged_in_{$hash} cookie domain as /wp-admin, for some reason, whereas using the normal wordpress login the domain for that cookie is /. This means that when I log out, wordpress tries to clear the cookie with / domain. So for anybody using my plugin they will stay logged in. The code I'm using to programatically login the user is:

//get user
$user = get_userdata( $user_id );
if ( !$user || ( !get_class( $user ) == 'WP_User' ) )
    continue;
//login
wp_set_current_user( $user->data->ID, $user->data->user_login );
wp_set_auth_cookie( $user->data->ID );
do_action( 'wp_login', $user->data->user_login );
//redirect to admin page
wp_redirect( admin_url() );

My code should work, according to: http://kuttler.eu/code/log-in-a-wordpress-user-programmatically/ and https://stackoverflow.com/a/10041701

issue seems to be with wp_set_auth_cookie() - completely at a loss here so any help is appreciated, daithi

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.