I am trying to integrate a third party API (positionly.com) into a WordPress member site. I am using the following code to add a positionly level to the corresponding membershipmouse member level
$base_url = POSITIONLY_API_URL;$url = $base_url . '/accounts.json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
$headers = array (
"Connection: keep-alive",
"Accept: application/json",
"Token: " . POSITIONLY_TOKEN
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
$user_level = mm_member_data(array("name"=>"membershipId"));
$plan = '');
if($user_level = 2){
$plan = "ClickMinded Bronze";
} elseif ($user_level = 3){
$plan = "ClickMinded Silver";
}elseif($user_level = 4){
$plan = "ClickMinded Gold";
}
// assign membermouse custom field a value
$userdata['cf_1'] = $plan;
//sets the positionly values to equal the membermouse values
$post_params['owner_attributes[email]'] = $userdata['email'];
$post_params['owner_attributes[name]'] = $userdata['first_name'] . ' '.$userdata['last_name'];
$post_params['owner_attributes[password]'] = $user_password;
$post_params['owner_attributes[plan_name]'] = $userdata['cf_1'];
$post_string = http_build_query($post_params);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
$result=curl_exec ($ch);
curl_close ($ch);
// it breaks somewhere in here according to var_dump($result) the positionly plan always comes up as ClickMinded Silver
$json = json_decode($result);
if( $json->status == "ok" ){
add_user_meta($userdata['member_id'], 'positionly_token', $json->token);
add_user_meta($userdata['member_id'], 'positionly_id', $json->account->id);
add_user_meta($userdata['member_id'], 'positionly_plan', $json->account->plan));
Have been in touch with the support at positionly and membermouse.
Have looked through several articles here and elsewhere "using php with json". Such as Get value of JSON object in PHP variable Using PHP Variables in Javascript with JSON
I have tried json_encoding the $plan variable I have gone through each step with var_dump and get the correct $plan -> level but it will not transfer to the json results.
I am at a loss. Any suggestions would be much appreciated