/** * PIT - Cron schedule + Event * - Add custom daily schedule + schedule event */ add_action('init', '_pit_schedule_event_custom'); function _pit_schedule_event_custom() { /** * 1. Add custom daily schedule */ add_filter('cron_schedules', '_pit_daily_cron_schedule_custom'); function _pit_daily_cron_schedule_custom($schedules) { $schedules['_pit_daily'] = array( 'interval' => DAY_IN_SECONDS, 'display' => __('Every day', 'pilot-theme') ); return $schedules; } /** * 2. Add event "_pit_event_custom" at 6AM the next day */ $event_args = array(); $event_name = '_pit_event_custom'; $event_schedule = '_pit_daily'; $event_time = strtotime(date('d F Y 06h00') . '+1 day', time()); /** * If the event is not already scheduled, schedule it. */ if (!wp_next_scheduled($event_name, $event_args)) wp_schedule_event($event_time, $event_schedule, $event_name, $event_args); } /** * PIT - Event * - Your custom event code */ add_action('_pit_event_custom', '_pit_action_daily_custom', 10, 1); function _pit_action_daily_custom() { // Your code that do something here daily }