@@ -12,93 +12,93 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Daily_Maintenance { |
14 | 14 | |
15 | - /** |
|
16 | - * Class constructor. |
|
17 | - */ |
|
18 | - public function __construct(){ |
|
19 | - |
|
20 | - // Clear deprecated events. |
|
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | - |
|
23 | - // (Maybe) schedule a cron that runs daily. |
|
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | - |
|
26 | - // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | - |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * Schedules a cron to run every day at 7 a.m |
|
35 | - * |
|
36 | - */ |
|
37 | - public function maybe_create_scheduled_event() { |
|
38 | - |
|
39 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
40 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
41 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
42 | - } |
|
43 | - |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Clears deprecated events. |
|
48 | - * |
|
49 | - */ |
|
50 | - public function maybe_clear_deprecated_events() { |
|
51 | - |
|
52 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
53 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
54 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
55 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
56 | - } |
|
57 | - |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Fires the old hook for backwards compatibility. |
|
62 | - * |
|
63 | - */ |
|
64 | - public function backwards_compat() { |
|
65 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Expires expired subscriptions. |
|
70 | - * |
|
71 | - */ |
|
72 | - public function maybe_expire_subscriptions() { |
|
73 | - |
|
74 | - // Fetch expired subscriptions (skips those that expire today). |
|
75 | - $args = array( |
|
76 | - 'number' => -1, |
|
77 | - 'count_total' => false, |
|
78 | - 'status' => 'trialling active failing cancelled', |
|
79 | - 'date_expires_query' => array( |
|
80 | - 'before' => 'today', |
|
81 | - 'inclusive' => false, |
|
82 | - ), |
|
83 | - ); |
|
84 | - |
|
85 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
86 | - |
|
87 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
88 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) { |
|
89 | - $subscription->set_status( 'expired' ); |
|
90 | - $subscription->save(); |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Logs cron runs. |
|
98 | - * |
|
99 | - */ |
|
100 | - public function log_cron_run() { |
|
101 | - wpinv_error_log( "GetPaid Daily Cron" ); |
|
102 | - } |
|
15 | + /** |
|
16 | + * Class constructor. |
|
17 | + */ |
|
18 | + public function __construct(){ |
|
19 | + |
|
20 | + // Clear deprecated events. |
|
21 | + add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | + |
|
23 | + // (Maybe) schedule a cron that runs daily. |
|
24 | + add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | + |
|
26 | + // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | + add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | + add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | + |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * Schedules a cron to run every day at 7 a.m |
|
35 | + * |
|
36 | + */ |
|
37 | + public function maybe_create_scheduled_event() { |
|
38 | + |
|
39 | + if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
40 | + $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
41 | + wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
42 | + } |
|
43 | + |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Clears deprecated events. |
|
48 | + * |
|
49 | + */ |
|
50 | + public function maybe_clear_deprecated_events() { |
|
51 | + |
|
52 | + if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
53 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
54 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
55 | + update_option( 'wpinv_cleared_old_events', 1 ); |
|
56 | + } |
|
57 | + |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Fires the old hook for backwards compatibility. |
|
62 | + * |
|
63 | + */ |
|
64 | + public function backwards_compat() { |
|
65 | + do_action( 'wpinv_register_schedule_event_daily' ); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Expires expired subscriptions. |
|
70 | + * |
|
71 | + */ |
|
72 | + public function maybe_expire_subscriptions() { |
|
73 | + |
|
74 | + // Fetch expired subscriptions (skips those that expire today). |
|
75 | + $args = array( |
|
76 | + 'number' => -1, |
|
77 | + 'count_total' => false, |
|
78 | + 'status' => 'trialling active failing cancelled', |
|
79 | + 'date_expires_query' => array( |
|
80 | + 'before' => 'today', |
|
81 | + 'inclusive' => false, |
|
82 | + ), |
|
83 | + ); |
|
84 | + |
|
85 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
86 | + |
|
87 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
88 | + if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) { |
|
89 | + $subscription->set_status( 'expired' ); |
|
90 | + $subscription->save(); |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Logs cron runs. |
|
98 | + * |
|
99 | + */ |
|
100 | + public function log_cron_run() { |
|
101 | + wpinv_error_log( "GetPaid Daily Cron" ); |
|
102 | + } |
|
103 | 103 | |
104 | 104 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Daily maintenance class. |
@@ -15,18 +15,18 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * Class constructor. |
17 | 17 | */ |
18 | - public function __construct(){ |
|
18 | + public function __construct() { |
|
19 | 19 | |
20 | 20 | // Clear deprecated events. |
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
21 | + add_action('wp', array($this, 'maybe_clear_deprecated_events')); |
|
22 | 22 | |
23 | 23 | // (Maybe) schedule a cron that runs daily. |
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
24 | + add_action('wp', array($this, 'maybe_create_scheduled_event')); |
|
25 | 25 | |
26 | 26 | // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
27 | + add_action('getpaid_daily_maintenance', array($this, 'log_cron_run')); |
|
28 | + add_action('getpaid_daily_maintenance', array($this, 'backwards_compat')); |
|
29 | + add_action('getpaid_daily_maintenance', array($this, 'maybe_expire_subscriptions')); |
|
30 | 30 | |
31 | 31 | } |
32 | 32 | |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function maybe_create_scheduled_event() { |
38 | 38 | |
39 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
40 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
41 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
39 | + if (!wp_next_scheduled('getpaid_daily_maintenance')) { |
|
40 | + $timestamp = strtotime('tomorrow 07:00:00', current_time('timestamp')); |
|
41 | + wp_schedule_event($timestamp, 'daily', 'getpaid_daily_maintenance'); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | } |
@@ -49,10 +49,10 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function maybe_clear_deprecated_events() { |
51 | 51 | |
52 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
53 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
54 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
55 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
52 | + if (!get_option('wpinv_cleared_old_events')) { |
|
53 | + wp_clear_scheduled_hook('wpinv_register_schedule_event_twicedaily'); |
|
54 | + wp_clear_scheduled_hook('wpinv_register_schedule_event_daily'); |
|
55 | + update_option('wpinv_cleared_old_events', 1); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * |
63 | 63 | */ |
64 | 64 | public function backwards_compat() { |
65 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
65 | + do_action('wpinv_register_schedule_event_daily'); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | public function maybe_expire_subscriptions() { |
73 | 73 | |
74 | 74 | // Fetch expired subscriptions (skips those that expire today). |
75 | - $args = array( |
|
75 | + $args = array( |
|
76 | 76 | 'number' => -1, |
77 | 77 | 'count_total' => false, |
78 | 78 | 'status' => 'trialling active failing cancelled', |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | ), |
83 | 83 | ); |
84 | 84 | |
85 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
85 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
86 | 86 | |
87 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
88 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) { |
|
89 | - $subscription->set_status( 'expired' ); |
|
87 | + foreach ($subscriptions->get_results() as $subscription) { |
|
88 | + if (apply_filters('getpaid_daily_maintenance_should_expire_subscription', true, $subscription)) { |
|
89 | + $subscription->set_status('expired'); |
|
90 | 90 | $subscription->save(); |
91 | 91 | } |
92 | 92 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * |
99 | 99 | */ |
100 | 100 | public function log_cron_run() { |
101 | - wpinv_error_log( "GetPaid Daily Cron" ); |
|
101 | + wpinv_error_log("GetPaid Daily Cron"); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | } |