I'm trying to trigger cron job from WordPress Plugin that I'm writing (It's gonna take all new Products and export them to CSV every day) so the problem is that when I'm put this code in functions.php all working great and the code is valid but from the plugin folder it's scheduled and I can see it (with Cron View Plug-in) but not executed.. I found another same questions but there was no answer.. It seems like it's not really been triggered or something is blocking it.. take a look at my code..
function csv_init(){
add_action('my_hourly_event', 'Download_CSV_with_args');
}
function starthere(){
// some code here
$file = $_SERVER['DOCUMENT_ROOT'].'/wp-content/csv_settings.php';
$content = serialize($args);
file_put_contents($file, $content);
wp_schedule_event( current_time( 'timestamp' ), 'hourly', 'my_hourly_event');
$schedule = wp_get_schedule( 'my_hourly_event' );
echo wp_next_scheduled( 'my_hourly_event' ).'<br>';
if ($schedule){
echo '<h3>The "'.$schedule.'" Cron Job is running..</h3>';
}else {
echo '<h3>There are no Cron Jobs that running..</h3>';
}
}
function Download_CSV_with_args() {
//execution of my code
}
Try to move
add_action
outside of a function: