How to register new cron schedule

To register new cron schedule we need to hook in cron_schedules filter and add new array into arrays of schedules. To prevent from overwriting schedule with same name we check if array with specific key already exists in schedules array. If not we add new array with keys:

  • interval – time in second between cron job beginning.
  • display – schedule description.
function my_cron_schedules($schedules){

	if(!isset($schedules["fifteen_minutes"])){
		$schedules["fifteen_minutes"] = array(
			'interval' => 15*60, //must be in seconds
			'display' => __('Once every 15 minutes'));
	}

	return $schedules;
}

add_filter('cron_schedules','my_cron_schedules');