Firstly, define your custom cron job schedules.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | public function cron_schedules($schedules){ $prefix = 'cron_';// Avoid conflict with other crons. Example Reference: cron_30_mins $schedule_options = array( '30_mins' => array( 'display' => '30 Minutes', 'interval' => '1800' ), '1_hours' => array( 'display' => 'Hour', 'interval' => '3600' ), '2_hours' => array( 'display' => '2 Hours', 'interval' => '7200' ) ); /* Add each custom schedule into the cron job system. */ foreach($schedule_options as $schedule_key => $schedule){ $schedules[$prefix.$schedule_key] = array( 'interval' => $schedule['interval'], 'display' => __('Every '.$schedule['display']) ); } return $schedules; } add_filter('cron_schedules', array($this, 'cron_schedules')); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.