Method to Execute at Certain Interval
function informant_main_action(){
die('working');
}
Custom Schedule for Cron Job
function my_cron_definer($schedules){
$schedules['weekly'] = array('interval'=> 120, //604800
'display'=> __('Once Every week')
);
return $schedules;
}
add_filter('cron_schedules','my_cron_definer');
Register schedule on plugin activation
register_activation_hook( __FILE__, 'informant_run_on_activation' );
function informant_run_on_activation(){
if(!wp_next_scheduled('informantweeklynewsletter')){
wp_schedule_event(time(), 'weekly', 'informantweeklynewsletter');
}
}
Calling my method to be executed on custom event
add_action('informantweeklynewsletter','informant_main_action');
I have installed a plugin Cron Gui for viewing scheduled cronjob and it is listing my event correctly as i put the recurrence for every two minutes the cron gui shows the correct result i.e its updating the time +2 minutes.
But my method informant_main_action()
is not working. Whats the mistake i am making. ?
Thanks
To test cron use something like mail().....try hourly to test and then your weekly one. Its a good idea to destroy the event on plugin de-activation (there is also a theme de-activation hook, look it up if you need it) so you can de-activate the plugin if you need to make changes without changing the hook name.