Passed
Push — master ( fb57af...b04aef )
by Brian
05:32
created
includes/class-getpaid-daily-maintenance.php 1 patch
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Daily maintenance class.
@@ -15,20 +15,20 @@  discard block
 block discarded – undo
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' ) );
30
-		add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) );
31
-		add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) );
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
+		add_action('getpaid_daily_maintenance', array($this, 'check_renewing_subscriptions'));
31
+		add_action('getpaid_daily_maintenance', array($this, 'maybe_update_geoip_databases'));
32 32
 
33 33
 	}
34 34
 
@@ -38,9 +38,9 @@  discard block
 block discarded – undo
38 38
 	 */
39 39
 	public function maybe_create_scheduled_event() {
40 40
 
41
-		if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) {
42
-			$timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) );
43
-			wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' );
41
+		if (!wp_next_scheduled('getpaid_daily_maintenance')) {
42
+			$timestamp = strtotime('tomorrow 07:00:00', current_time('timestamp'));
43
+			wp_schedule_event($timestamp, 'daily', 'getpaid_daily_maintenance');
44 44
 		}
45 45
 
46 46
 	}
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
 	 */
52 52
 	public function maybe_clear_deprecated_events() {
53 53
 
54
-		if ( ! get_option( 'wpinv_cleared_old_events' ) ) {
55
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );
56
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' );
57
-			update_option( 'wpinv_cleared_old_events', 1 );
54
+		if (!get_option('wpinv_cleared_old_events')) {
55
+			wp_clear_scheduled_hook('wpinv_register_schedule_event_twicedaily');
56
+			wp_clear_scheduled_hook('wpinv_register_schedule_event_daily');
57
+			update_option('wpinv_cleared_old_events', 1);
58 58
 		}
59 59
 
60 60
 	}
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 *
65 65
 	 */
66 66
 	public function backwards_compat() {
67
-		do_action( 'wpinv_register_schedule_event_daily' );
67
+		do_action('wpinv_register_schedule_event_daily');
68 68
 	}
69 69
 
70 70
 	/**
@@ -74,29 +74,29 @@  discard block
 block discarded – undo
74 74
 	public function check_renewing_subscriptions() {
75 75
 
76 76
 		// Fetch subscriptions that expire today.
77
-		$args  = array(
77
+		$args = array(
78 78
 			'number'             => -1,
79 79
 			'count_total'        => false,
80 80
 			'status'             => 'trialling active',
81 81
 			'date_expires_query' => array(
82 82
 				array(
83
-					'year'          => date( 'Y', current_time( 'timestamp' ) ),
84
-					'month'         => date( 'n', current_time( 'timestamp' ) ),
85
-					'day'           => date( 'j', current_time( 'timestamp' ) ),
83
+					'year'          => date('Y', current_time('timestamp')),
84
+					'month'         => date('n', current_time('timestamp')),
85
+					'day'           => date('j', current_time('timestamp')),
86 86
 					'compare'       => '=',
87 87
 				),
88 88
 			),
89 89
 		);
90 90
 
91
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
91
+		$subscriptions = new GetPaid_Subscriptions_Query($args);
92 92
 
93
-		foreach ( $subscriptions->get_results() as $subscription ) {
93
+		foreach ($subscriptions->get_results() as $subscription) {
94 94
 
95 95
 			/** @var WPInv_Subscription $subscription */
96
-			if ( $subscription->is_last_renewal() ) {
96
+			if ($subscription->is_last_renewal()) {
97 97
 				$subscription->complete();
98 98
 			} else {
99
-				do_action( 'getpaid_should_renew_subscription', $subscription );
99
+				do_action('getpaid_should_renew_subscription', $subscription);
100 100
 			}
101 101
 
102 102
 		}
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	public function maybe_expire_subscriptions() {
111 111
 
112 112
 		// Fetch expired subscriptions (skips those that expire today).
113
-		$args  = array(
113
+		$args = array(
114 114
 			'number'             => -1,
115 115
 			'count_total'        => false,
116 116
 			'status'             => 'trialling active failing cancelled',
@@ -120,11 +120,11 @@  discard block
 block discarded – undo
120 120
 			),
121 121
 		);
122 122
 
123
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
123
+		$subscriptions = new GetPaid_Subscriptions_Query($args);
124 124
 
125
-		foreach ( $subscriptions->get_results() as $subscription ) {
126
-			if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) {
127
-				$subscription->set_status( 'expired' );
125
+		foreach ($subscriptions->get_results() as $subscription) {
126
+			if (apply_filters('getpaid_daily_maintenance_should_expire_subscription', false, $subscription)) {
127
+				$subscription->set_status('expired');
128 128
 				$subscription->save();
129 129
 			}
130 130
 		}
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 	 *
137 137
 	 */
138 138
 	public function log_cron_run() {
139
-		wpinv_error_log( 'GetPaid Daily Cron', false );
139
+		wpinv_error_log('GetPaid Daily Cron', false);
140 140
 	}
141 141
 
142 142
 	/**
@@ -144,11 +144,11 @@  discard block
 block discarded – undo
144 144
 	 *
145 145
 	 */
146 146
 	public function maybe_update_geoip_databases() {
147
-		$updated = get_transient( 'getpaid_updated_geoip_databases' );
147
+		$updated = get_transient('getpaid_updated_geoip_databases');
148 148
 
149
-		if ( false === $updated ) {
150
-			set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS );
151
-			do_action( 'getpaid_update_geoip_databases' );
149
+		if (false === $updated) {
150
+			set_transient('getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS);
151
+			do_action('getpaid_update_geoip_databases');
152 152
 		}
153 153
 
154 154
 	}
Please login to merge, or discard this patch.