I have made an API call using wp_remote_post
and retrieved the values using wp_remote_retrieve_body
. But the problem is the response body is protected by WordPress. I have tried using reflection method and subclass methods to retrieve the data but failed.
Below code, I have used to make API call and retrieve data.
$response = wp_remote_post ( 'https://apiurl.com?APIKEY='."$api_key".'', $args );
$response = json_decode(wp_remote_retrieve_body($response), true);
class my_request_utility {
protected $response;
public function test() {
var_dump(get_object_vars($this->response));
}
}
$my_array = new my_request_utility;
var_dump(get_object_vars($my_array));
$my_array->test();
$currencyData = wp_remote_retrieve_body( $currency );
$responceData = $my_array;
$str = '';
foreach ($responceData->MenuList as $Item)
{
$str .= '<table width="100%" height="auto" border="0px solid #FFFFFF">
<tr>
<td width="80%" class="cat">'.$Item['Name'].'</td>
<td width="20%" align="center" class="cat">
<a target="_blank" href="'.$ulr.'">ORDER</a>
</td>
</tr>';
foreach($Item['Item'] as $Value)
{
$str .= '<tr>
<td class="item" width="80%">'.$Value['Price'].'</td>
<td class="item" align="center" width="20%"><b>'.$Value['Price'].'</b></td>
</tr>';
}
$str .= '</table>';
}
Now I am Getting these Errors.
get_object_vars() expects parameter 1 to be object, null given
Undefined property: my_request_utility::$MenuList
Invalid argument supplied for foreach()
Please Help me. I have been trying for three days with different methods but failing.