I'm trying to run a function on an hourly basis with wp_schedule_event. I'm using the following code:
/* Add FB Sync schedule */
register_activation_hook(__FILE__, 'cp_fb_schedule');
// Scheduled Action Hook
function cp_fb_scheduled_sync( ) {
// run the function
}
// Schedule Cron Job Event
function cp_fb_schedule() {
if ( ! wp_next_scheduled( 'cp_fb_scheduled_sync' ) ) {
wp_schedule_event( time(), 'hourly', 'cp_fb_scheduled_sync' );
}
}
add_action( 'wp', 'cp_fb_schedule' );
register_deactivation_hook(__FILE__, 'my_deactivation');
function my_deactivation() {
wp_clear_scheduled_hook('cp_fb_scheduled_sync');
}
I have checked with wp_next_scheduled and can see that the event is scheduled and the next one is due an hour after the last. So that appears to be working. The function I am trying to run works fine when I call it directly within a page (I've omitted the code here just so it's easier to read). It just doesn't run on schedule.
Can anyone work out what I'm doing wrong?
thanks