Passed
Pull Request — master (#419)
by Brian
04:17
created
includes/class-getpaid-daily-maintenance.php 1 patch
Spacing   +21 added lines, -21 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,18 +15,18 @@  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' ) );
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.