class-cron.php
1.03 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit();
}
/**
* Cron class
*/
class Learndash_WooCommerce_Cron {
/**
* Hook functions
*/
public function __construct() {
add_filter( 'cron_schedules', array( $this, 'add_cron_schedule' ) );
add_action( 'admin_init', array( $this, 'register_cron' ) );
register_deactivation_hook( LEARNDASH_WOOCOMMERCE_FILE, array( $this, 'deregister_hook' ) );
}
/**
* Add cron schedule
*
* @param array $schedules Cron schedules
*/
public function add_cron_schedule( $schedules ) {
$schedules['per_minute'] = array(
'interval' => MINUTE_IN_SECONDS,
'display' => __( 'Once per Minute', 'learndash-woocommerce' ),
);
return $schedules;
}
/**
* Register cron hook
*/
public function register_cron() {
if ( ! wp_next_scheduled( 'learndash_woocommerce_cron' ) ) {
wp_schedule_event( time(), 'per_minute', 'learndash_woocommerce_cron' );
}
}
public function deregister_hook() {
wp_clear_scheduled_hook( 'learndash_woocommerce_cron' );
}
}
new Learndash_WooCommerce_Cron();