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?