| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
if( !class_exists( 'WPPMCron' ) ) : |
| 6 |
|
| 7 |
final class WPPMCron { |
| 8 |
public static function init() { |
| 9 |
add_action( 'init', array( __CLASS__, 'wppm_schedule_events') ); |
| 10 |
} |
| 11 |
|
| 12 |
public static function wppm_schedule_events(){ |
| 13 |
// Schedule cron job for every minute events |
| 14 |
if ( !wp_next_scheduled('wppm_cron_one_minute') ) { |
| 15 |
wp_schedule_event( |
| 16 |
time(), |
| 17 |
'wppm_1min', |
| 18 |
'wppm_cron_one_minute' |
| 19 |
); |
| 20 |
//include( WPPM_ABSPATH.'includes/class-wppm_import_emails.php' ); |
| 21 |
} |
| 22 |
|
| 23 |
// Schedule cron job for every five minute events |
| 24 |
if ( !wp_next_scheduled('wppm_cron_five_minute') ) { |
| 25 |
wp_schedule_event( |
| 26 |
time(), |
| 27 |
'wppm_5min', |
| 28 |
'wppm_cron_five_minute' |
| 29 |
); |
| 30 |
} |
| 31 |
|
| 32 |
// Schedule cron job for daily events |
| 33 |
if ( !wp_next_scheduled('wppm_cron_daily') ) { |
| 34 |
wp_schedule_event( |
| 35 |
time(), |
| 36 |
'daily', |
| 37 |
'wppm_cron_daily' |
| 38 |
); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
public static function wppm_unschedule_events(){ |
| 43 |
// Remove every minute cron |
| 44 |
$timestamp = wp_next_scheduled( 'wppm_cron_one_minute' ); |
| 45 |
if( $timestamp ) { |
| 46 |
wp_unschedule_event( $timestamp, 'wppm_cron_one_minute' ); |
| 47 |
} |
| 48 |
|
| 49 |
// Remove every five minute cron |
| 50 |
$timestamp = wp_next_scheduled( 'wppm_cron_five_minute' ); |
| 51 |
if( $timestamp ) { |
| 52 |
wp_unschedule_event( $timestamp, 'wppm_cron_five_minute' ); |
| 53 |
} |
| 54 |
|
| 55 |
// Remove daily cron |
| 56 |
$timestamp = wp_next_scheduled( 'wppm_cron_daily' ); |
| 57 |
if( $timestamp ) { |
| 58 |
wp_unschedule_event( $timestamp, 'wppm_cron_daily' ); |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
endif; |
| 63 |
WPPMCron::init(); |