I'm sending user objetc from site A (wordpress) to site B (wordpress). Now when site B accept the user data, it should login the user into site B.
the user is logged in site B, I checked using is_user_logged_in() and wp_get_currect_user. but at this point the url still shows siteA/wp-admin/admin-post. But after this I need to redirect to site B and the user must get logged in. This is the part I fail. Even if I use javascript hack to redirect to site B, redirection works but user is not logged in.
please check my curl request and let me know.
site A
$opts = array(
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => false,
CURLOPT_TIMEOUT => 60,
CURLOPT_USERAGENT => 'from-site-a',
CURLOPT_SSL_VERIFYPEER => False,
CURLOPT_HTTPHEADER => array('Accept: application/json'),
CURLOPT_POST => 1,
// CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_POSTFIELDS => http_build_query($user),
CURLOPT_URL => $url
);
$ch = curl_init();
curl_setopt_array($ch, $opts);
$result = curl_exec($ch);
site B
$user = $_POST;
$a = get_user_by('login', $user['data']['user_login']);
wp_set_current_user( $a->data->ID );
wp_set_auth_cookie( $a->data->ID );
do_action('wp_login', $a->data->user_login, $a);
//wp_get_current_user();
$string = '<script type="text/javascript">';
$string .= 'window.location = "' . site_url() . '"';
$string .= '</script>';
echo $string;
exit;