0

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 {
        wp_set_current_user($user->ID);
        wp_set_auth_cookie($user->ID);
        do_action( 'wp_login', $user_name);
        if (!session_id()) {
            session_start();
            $_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?

1
  • 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. Commented Feb 6, 2017 at 16:20

1 Answer 1

0

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 and acknowledge you have read our privacy policy.

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