I created a wordpress schedule event using the following code
add_filter('cron_schedules','cliv_cron_add_syncdays');
function cliv_cron_add_syncdays($schedules){
$schedules['syncdays'] = array(
'interval' => 15,
'display'=> 'Sync Days'
);
return $schedules;
}
add_action('init','cliv_create_recurring_schedule');
add_action('cron_action','cron_function');
function cron_function(){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,array("DATA SYNC"));
$result = curl_exec($ch);
curl_close($ch);
$response = json_decode($result, true);
mail("mymail@mail.com", "wp Cron test", $response);
}
function cliv_create_recurring_schedule(){
if(!wp_next_scheduled('cron_action'))
wp_schedule_event (time(), 'syncdays', 'cron_action');
}
if i call the cron_function() directly, everything works.
But if the function is run from cron, mail is received but without the data. ( i guess curl not working in this case).
Guys. can you help me out here please.