Why does is_user_logged_in() return false after redirect from another site?


I am developing a WordPress site that redirects to an external payment gateway after a user registers for the site. After the user makes a payment the user is redirected to a page to complete their sign up.

Here is the code used for the redirect:

$login_data = array();
$login_data['user_login'] = $email;
$login_data['user_password'] = $password;
$login_data['remember'] = true;
$user = wp_signon($login_data);
    wp_set_current_user( $user->ID, $email );
    wp_set_auth_cookie( $user->ID, true, false );

The user is redirected and fills out the payment form. Upon success the user is redirected to a landing page. If they are not logged in they are shown a dialog for non logged in users.
Here is the code on that page:

  $user = wp_get_current_user();
  //code for logged in users
  //message for non logged in users 

If I go to the account page it is shown that the user is logged in. But when redirected from a different site is_user_logged_in() returns false.
Any insight into this issue would be much appreciated.

, , frank Collins 3 years 2019-11-18T20:14:53-05:00 0 Answers 119 views 0

Leave an answer