I'm new to php. I'm trying to write a simple plugin that calls the api and returns a JSON response.
When I write the same code outside function, I get a JSON response. But the issue is when I use the function below, it doesn't return any value.. The page seems blank
Here is my function
function getDOTD(){
try{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $baseUrl."offers/v1/dotd/json");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Fk-Affiliate-Id:'.get_option('affiliate_id'),'Fk-Affiliate-Token:'.get_option('affiliate_token')));
$result = curl_exec($curl);
curl_close($curl);
print($result);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n"; abort;
}
}
i have also tried to use return instead of print() but that too didn't worked. this is how i call my function -
print(getDOTD());
Any help appreciated... TIA :)
print($result);toreturn $result;die();right afterprint($result);to see if it's actually getting any result. Also dovar_dump($baseUrl);inside the function.function getDOTD($baseUrl)instead.