I am creating a login, that pops up a window, takes in credentials and closes when successfully logged in. The code is for a plugin.

I have read and tried everything in user-is-not-logged-in and in authenticate-user-guidance. The users appears to be logged in, in the pop-up window. However in the main window, the no user is logged in.

    // $user_name and $user_pass are from the form
    $creds = array(
        'user_login'    => $user_name,
        'user_password' => $user_pass,
        'remember'      => true

    $user = wp_signon( $creds, false );

    if ( is_wp_error( $user ) ) echo $user->get_error_message();
    else {
        do_action( 'wp_login', $user_name);
        if (!session_id()) {
            $_SESSION['access_token'] = $secret->access_token;
            $_SESSION['refresh_token'] = $secret->refresh_token;
        //once main window has this user logged, refresh it and close popup
        //print '<script>window.opener.location.reload();window.close();</script>';
        print "$user->user_login : $user->display_name : $user->user_email";
        print (is_user_logged_in())? 'IS LOGGED ALL IN' : 'DOES NOT WORK AT ALL';

This outputs IS LOGGED ALL IN in the popup window (along with the user info).

What am I missing?

  • I have moved this section of the code to the main window. Now it mimics the linked questions. Still, is_user_logged_in() shows true, but trying to access user profile redirects me to login page. – contemplator Feb 6 '17 at 16:20

After trying so many things, I tried to redirect after authenticating. However I kept getting the error "Cannot modify header information - headers already sent".

I read on the solution and moved the entire function to this location and it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.