Custom Number Countdown
// Scheduled Action Hook
function do_decrement( ) {
$options = get_option($this->plugin_name . '-options');
if ((int)$options['gcpc_timer_countdown'] > 0) {
$options['gcpc_timer_countdown'] = (int)$options['gcpc_timer_countdown'] - 1;
update_option($this->plugin_name . '-options', $options);
}
}
// Custom Cron Recurrences
function gcpc_schedule_cron_recurrence( $schedules ) {
$schedules['gcpc_custom_timer_interval'] = array(
'display' => __( 'Customized by timer_interval option', 'textdomain' ),
'interval' => 300,
);
return $schedules;
}
add_filter( 'cron_schedules', 'gcpc_schedule_cron_custom_recurrence' );
// Schedule Cron Job Event
function gcpc_schedule_cron() {
if ( ! wp_next_scheduled( 'do_decrement' ) ) {
wp_schedule_event( time(), 'gcpc_custom_timer_interval', 'do_decrement' );
}
}
add_action( 'wp', 'gcpc_schedule_cron' );