Passed
Push — master ( acf0a7...72aaeb )
by Brian
04:02
created
includes/data-stores/class-getpaid-subscription-data-store.php 2 patches
Indentation   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit;
8
+    exit;
9 9
 }
10 10
 
11 11
 /**
@@ -15,198 +15,198 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Subscription_Data_Store {
17 17
 
18
-	/**
19
-	 * A map of database fields to data types.
20
-	 *
21
-	 * @since 1.0.19
22
-	 * @var array
23
-	 */
24
-	protected $database_fields_to_data_type = array(
25
-		'id'                => '%d',
26
-		'customer_id'       => '%d',
27
-		'frequency'         => '%d',
28
-		'period'            => '%s',
29
-		'initial_amount'    => '%s',
30
-		'recurring_amount'  => '%s',
31
-		'bill_times'        => '%d',
32
-		'transaction_id'    => '%s',
33
-		'parent_payment_id' => '%d',
34
-		'product_id'        => '%d',
35
-		'created'           => '%s',
36
-		'expiration'        => '%s',
37
-		'trial_period'      => '%s',
38
-		'status'            => '%s',
39
-		'profile_id'        => '%s',
40
-	);
41
-
42
-	/*
18
+    /**
19
+     * A map of database fields to data types.
20
+     *
21
+     * @since 1.0.19
22
+     * @var array
23
+     */
24
+    protected $database_fields_to_data_type = array(
25
+        'id'                => '%d',
26
+        'customer_id'       => '%d',
27
+        'frequency'         => '%d',
28
+        'period'            => '%s',
29
+        'initial_amount'    => '%s',
30
+        'recurring_amount'  => '%s',
31
+        'bill_times'        => '%d',
32
+        'transaction_id'    => '%s',
33
+        'parent_payment_id' => '%d',
34
+        'product_id'        => '%d',
35
+        'created'           => '%s',
36
+        'expiration'        => '%s',
37
+        'trial_period'      => '%s',
38
+        'status'            => '%s',
39
+        'profile_id'        => '%s',
40
+    );
41
+
42
+    /*
43 43
 	|--------------------------------------------------------------------------
44 44
 	| CRUD Methods
45 45
 	|--------------------------------------------------------------------------
46 46
 	*/
47 47
 
48
-	/**
49
-	 * Method to create a new subscription in the database.
50
-	 *
51
-	 * @param WPInv_Subscription $subscription Subscription object.
52
-	 */
53
-	public function create( &$subscription ) {
54
-		global $wpdb;
55
-
56
-		$values  = array();
57
-		$formats = array();
58
-
59
-		$fields = $this->database_fields_to_data_type;
60
-		unset( $fields['id'] );
61
-
62
-		foreach ( $fields as $key => $format ) {
63
-			$method       = "get_$key";
64
-			$values[$key] = $subscription->$method( 'edit' );
65
-			$formats[]    = $format;
66
-		}
67
-
68
-		$result = $wpdb->insert( $wpdb->prefix . 'wpinv_subscriptions', $values, $formats );
69
-
70
-		if ( $result ) {
71
-			$subscription->set_id( $wpdb->insert_id );
72
-			$subscription->apply_changes();
73
-			$subscription->clear_cache();
74
-			update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id() );
75
-			do_action( 'getpaid_new_subscription', $subscription );
76
-			return true;
77
-		}
78
-
79
-		return false;
80
-	}
81
-
82
-	/**
83
-	 * Method to read a subscription from the database.
84
-	 *
85
-	 * @param WPInv_Subscription $subscription Subscription object.
86
-	 *
87
-	 */
88
-	public function read( &$subscription ) {
89
-		global $wpdb;
90
-
91
-		$subscription->set_defaults();
92
-
93
-		if ( ! $subscription->get_id() ) {
94
-			$subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
95
-			$subscription->set_id( 0 );
96
-			return false;
97
-		}
98
-
99
-		// Maybe retrieve from the cache.
100
-		$raw_subscription = wp_cache_get( $subscription->get_id(), 'getpaid_subscriptions' );
101
-
102
-		// If not found, retrieve from the db.
103
-		if ( false === $raw_subscription ) {
104
-
105
-			$raw_subscription = $wpdb->get_row(
106
-				$wpdb->prepare(
107
-					"SELECT * FROM {$wpdb->prefix}wpinv_subscriptions WHERE id = %d",
108
-					$subscription->get_id()
109
-				)
110
-			);
111
-
112
-			// Update the cache with our data
113
-			wp_cache_set( $subscription->get_id(), $raw_subscription, 'getpaid_subscriptions' );
114
-
115
-		}
116
-
117
-		if ( ! $raw_subscription ) {
118
-			$subscription->set_id( 0 );
119
-			$subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
120
-			return false;
121
-		}
122
-
123
-		foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) {
124
-			$method     = "set_$key";
125
-			$subscription->$method( $raw_subscription->$key );
126
-		}
127
-
128
-		$subscription->set_object_read( true );
129
-		do_action( 'getpaid_read_subscription', $subscription );
130
-
131
-	}
132
-
133
-	/**
134
-	 * Method to update a subscription in the database.
135
-	 *
136
-	 * @param WPInv_Subscription $subscription Subscription object.
137
-	 */
138
-	public function update( &$subscription ) {
139
-		global $wpdb;
140
-
141
-		$changes = $subscription->get_changes();
142
-		$values  = array();
143
-		$formats = array();
144
-
145
-		foreach ( $this->database_fields_to_data_type as $key => $format ) {
146
-			if ( array_key_exists( $key, $changes ) ) {
147
-				$method       = "get_$key";
148
-				$values[$key] = $subscription->$method( 'edit' );
149
-				$formats[]    = $format;
150
-			}
151
-		}
152
-
153
-		if ( empty( $values ) ) {
154
-			return;
155
-		}
156
-
157
-		$wpdb->update(
158
-			$wpdb->prefix . 'wpinv_subscriptions',
159
-			$values,
160
-			array(
161
-				'id' => $subscription->get_id(),
162
-			),
163
-			$formats,
164
-			'%d'
165
-		);
166
-
167
-		// Apply the changes.
168
-		$subscription->apply_changes();
169
-
170
-		// Delete cache.
171
-		$subscription->clear_cache();
172
-
173
-		update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id() );
174
-		update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id() );
175
-
176
-		// Fire a hook.
177
-		do_action( 'getpaid_update_subscription', $subscription );
178
-
179
-	}
180
-
181
-	/**
182
-	 * Method to delete a subscription from the database.
183
-	 *
184
-	 * @param WPInv_Subscription $subscription
185
-	 */
186
-	public function delete( &$subscription ) {
187
-		global $wpdb;
188
-
189
-		$wpdb->query(
190
-			$wpdb->prepare(
191
-				"DELETE FROM {$wpdb->prefix}wpinv_subscriptions
48
+    /**
49
+     * Method to create a new subscription in the database.
50
+     *
51
+     * @param WPInv_Subscription $subscription Subscription object.
52
+     */
53
+    public function create( &$subscription ) {
54
+        global $wpdb;
55
+
56
+        $values  = array();
57
+        $formats = array();
58
+
59
+        $fields = $this->database_fields_to_data_type;
60
+        unset( $fields['id'] );
61
+
62
+        foreach ( $fields as $key => $format ) {
63
+            $method       = "get_$key";
64
+            $values[$key] = $subscription->$method( 'edit' );
65
+            $formats[]    = $format;
66
+        }
67
+
68
+        $result = $wpdb->insert( $wpdb->prefix . 'wpinv_subscriptions', $values, $formats );
69
+
70
+        if ( $result ) {
71
+            $subscription->set_id( $wpdb->insert_id );
72
+            $subscription->apply_changes();
73
+            $subscription->clear_cache();
74
+            update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id() );
75
+            do_action( 'getpaid_new_subscription', $subscription );
76
+            return true;
77
+        }
78
+
79
+        return false;
80
+    }
81
+
82
+    /**
83
+     * Method to read a subscription from the database.
84
+     *
85
+     * @param WPInv_Subscription $subscription Subscription object.
86
+     *
87
+     */
88
+    public function read( &$subscription ) {
89
+        global $wpdb;
90
+
91
+        $subscription->set_defaults();
92
+
93
+        if ( ! $subscription->get_id() ) {
94
+            $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
95
+            $subscription->set_id( 0 );
96
+            return false;
97
+        }
98
+
99
+        // Maybe retrieve from the cache.
100
+        $raw_subscription = wp_cache_get( $subscription->get_id(), 'getpaid_subscriptions' );
101
+
102
+        // If not found, retrieve from the db.
103
+        if ( false === $raw_subscription ) {
104
+
105
+            $raw_subscription = $wpdb->get_row(
106
+                $wpdb->prepare(
107
+                    "SELECT * FROM {$wpdb->prefix}wpinv_subscriptions WHERE id = %d",
108
+                    $subscription->get_id()
109
+                )
110
+            );
111
+
112
+            // Update the cache with our data
113
+            wp_cache_set( $subscription->get_id(), $raw_subscription, 'getpaid_subscriptions' );
114
+
115
+        }
116
+
117
+        if ( ! $raw_subscription ) {
118
+            $subscription->set_id( 0 );
119
+            $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
120
+            return false;
121
+        }
122
+
123
+        foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) {
124
+            $method     = "set_$key";
125
+            $subscription->$method( $raw_subscription->$key );
126
+        }
127
+
128
+        $subscription->set_object_read( true );
129
+        do_action( 'getpaid_read_subscription', $subscription );
130
+
131
+    }
132
+
133
+    /**
134
+     * Method to update a subscription in the database.
135
+     *
136
+     * @param WPInv_Subscription $subscription Subscription object.
137
+     */
138
+    public function update( &$subscription ) {
139
+        global $wpdb;
140
+
141
+        $changes = $subscription->get_changes();
142
+        $values  = array();
143
+        $formats = array();
144
+
145
+        foreach ( $this->database_fields_to_data_type as $key => $format ) {
146
+            if ( array_key_exists( $key, $changes ) ) {
147
+                $method       = "get_$key";
148
+                $values[$key] = $subscription->$method( 'edit' );
149
+                $formats[]    = $format;
150
+            }
151
+        }
152
+
153
+        if ( empty( $values ) ) {
154
+            return;
155
+        }
156
+
157
+        $wpdb->update(
158
+            $wpdb->prefix . 'wpinv_subscriptions',
159
+            $values,
160
+            array(
161
+                'id' => $subscription->get_id(),
162
+            ),
163
+            $formats,
164
+            '%d'
165
+        );
166
+
167
+        // Apply the changes.
168
+        $subscription->apply_changes();
169
+
170
+        // Delete cache.
171
+        $subscription->clear_cache();
172
+
173
+        update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id() );
174
+        update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id() );
175
+
176
+        // Fire a hook.
177
+        do_action( 'getpaid_update_subscription', $subscription );
178
+
179
+    }
180
+
181
+    /**
182
+     * Method to delete a subscription from the database.
183
+     *
184
+     * @param WPInv_Subscription $subscription
185
+     */
186
+    public function delete( &$subscription ) {
187
+        global $wpdb;
188
+
189
+        $wpdb->query(
190
+            $wpdb->prepare(
191
+                "DELETE FROM {$wpdb->prefix}wpinv_subscriptions
192 192
 				WHERE id = %d",
193
-				$subscription->get_id()
194
-			)
195
-		);
193
+                $subscription->get_id()
194
+            )
195
+        );
196 196
 
197
-		delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id' );
198
-		delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id' );
197
+        delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id' );
198
+        delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id' );
199 199
 
200
-		// Delete cache.
201
-		$subscription->clear_cache();
200
+        // Delete cache.
201
+        $subscription->clear_cache();
202 202
 
203
-		// Fire a hook.
204
-		do_action( 'getpaid_delete_subscription', $subscription );
203
+        // Fire a hook.
204
+        do_action( 'getpaid_delete_subscription', $subscription );
205 205
 
206
-		$subscription->set_id( 0 );
207
-	}
206
+        $subscription->set_id( 0 );
207
+    }
208 208
 
209
-	/*
209
+    /*
210 210
 	|--------------------------------------------------------------------------
211 211
 	| Additional Methods
212 212
 	|--------------------------------------------------------------------------
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * GetPaid_Subscription_Data_Store class file.
5 5
  *
6 6
  */
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
 	exit;
9 9
 }
10 10
 
@@ -50,29 +50,29 @@  discard block
 block discarded – undo
50 50
 	 *
51 51
 	 * @param WPInv_Subscription $subscription Subscription object.
52 52
 	 */
53
-	public function create( &$subscription ) {
53
+	public function create(&$subscription) {
54 54
 		global $wpdb;
55 55
 
56 56
 		$values  = array();
57 57
 		$formats = array();
58 58
 
59 59
 		$fields = $this->database_fields_to_data_type;
60
-		unset( $fields['id'] );
60
+		unset($fields['id']);
61 61
 
62
-		foreach ( $fields as $key => $format ) {
62
+		foreach ($fields as $key => $format) {
63 63
 			$method       = "get_$key";
64
-			$values[$key] = $subscription->$method( 'edit' );
64
+			$values[$key] = $subscription->$method('edit');
65 65
 			$formats[]    = $format;
66 66
 		}
67 67
 
68
-		$result = $wpdb->insert( $wpdb->prefix . 'wpinv_subscriptions', $values, $formats );
68
+		$result = $wpdb->insert($wpdb->prefix . 'wpinv_subscriptions', $values, $formats);
69 69
 
70
-		if ( $result ) {
71
-			$subscription->set_id( $wpdb->insert_id );
70
+		if ($result) {
71
+			$subscription->set_id($wpdb->insert_id);
72 72
 			$subscription->apply_changes();
73 73
 			$subscription->clear_cache();
74
-			update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id() );
75
-			do_action( 'getpaid_new_subscription', $subscription );
74
+			update_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id());
75
+			do_action('getpaid_new_subscription', $subscription);
76 76
 			return true;
77 77
 		}
78 78
 
@@ -85,22 +85,22 @@  discard block
 block discarded – undo
85 85
 	 * @param WPInv_Subscription $subscription Subscription object.
86 86
 	 *
87 87
 	 */
88
-	public function read( &$subscription ) {
88
+	public function read(&$subscription) {
89 89
 		global $wpdb;
90 90
 
91 91
 		$subscription->set_defaults();
92 92
 
93
-		if ( ! $subscription->get_id() ) {
94
-			$subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
95
-			$subscription->set_id( 0 );
93
+		if (!$subscription->get_id()) {
94
+			$subscription->last_error = __('Invalid subscription ID.', 'invoicing');
95
+			$subscription->set_id(0);
96 96
 			return false;
97 97
 		}
98 98
 
99 99
 		// Maybe retrieve from the cache.
100
-		$raw_subscription = wp_cache_get( $subscription->get_id(), 'getpaid_subscriptions' );
100
+		$raw_subscription = wp_cache_get($subscription->get_id(), 'getpaid_subscriptions');
101 101
 
102 102
 		// If not found, retrieve from the db.
103
-		if ( false === $raw_subscription ) {
103
+		if (false === $raw_subscription) {
104 104
 
105 105
 			$raw_subscription = $wpdb->get_row(
106 106
 				$wpdb->prepare(
@@ -110,23 +110,23 @@  discard block
 block discarded – undo
110 110
 			);
111 111
 
112 112
 			// Update the cache with our data
113
-			wp_cache_set( $subscription->get_id(), $raw_subscription, 'getpaid_subscriptions' );
113
+			wp_cache_set($subscription->get_id(), $raw_subscription, 'getpaid_subscriptions');
114 114
 
115 115
 		}
116 116
 
117
-		if ( ! $raw_subscription ) {
118
-			$subscription->set_id( 0 );
119
-			$subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
117
+		if (!$raw_subscription) {
118
+			$subscription->set_id(0);
119
+			$subscription->last_error = __('Invalid subscription ID.', 'invoicing');
120 120
 			return false;
121 121
 		}
122 122
 
123
-		foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) {
124
-			$method     = "set_$key";
125
-			$subscription->$method( $raw_subscription->$key );
123
+		foreach (array_keys($this->database_fields_to_data_type) as $key) {
124
+			$method = "set_$key";
125
+			$subscription->$method($raw_subscription->$key);
126 126
 		}
127 127
 
128
-		$subscription->set_object_read( true );
129
-		do_action( 'getpaid_read_subscription', $subscription );
128
+		$subscription->set_object_read(true);
129
+		do_action('getpaid_read_subscription', $subscription);
130 130
 
131 131
 	}
132 132
 
@@ -135,22 +135,22 @@  discard block
 block discarded – undo
135 135
 	 *
136 136
 	 * @param WPInv_Subscription $subscription Subscription object.
137 137
 	 */
138
-	public function update( &$subscription ) {
138
+	public function update(&$subscription) {
139 139
 		global $wpdb;
140 140
 
141 141
 		$changes = $subscription->get_changes();
142 142
 		$values  = array();
143 143
 		$formats = array();
144 144
 
145
-		foreach ( $this->database_fields_to_data_type as $key => $format ) {
146
-			if ( array_key_exists( $key, $changes ) ) {
145
+		foreach ($this->database_fields_to_data_type as $key => $format) {
146
+			if (array_key_exists($key, $changes)) {
147 147
 				$method       = "get_$key";
148
-				$values[$key] = $subscription->$method( 'edit' );
148
+				$values[$key] = $subscription->$method('edit');
149 149
 				$formats[]    = $format;
150 150
 			}
151 151
 		}
152 152
 
153
-		if ( empty( $values ) ) {
153
+		if (empty($values)) {
154 154
 			return;
155 155
 		}
156 156
 
@@ -170,11 +170,11 @@  discard block
 block discarded – undo
170 170
 		// Delete cache.
171 171
 		$subscription->clear_cache();
172 172
 
173
-		update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id() );
174
-		update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id() );
173
+		update_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id());
174
+		update_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id());
175 175
 
176 176
 		// Fire a hook.
177
-		do_action( 'getpaid_update_subscription', $subscription );
177
+		do_action('getpaid_update_subscription', $subscription);
178 178
 
179 179
 	}
180 180
 
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 	 *
184 184
 	 * @param WPInv_Subscription $subscription
185 185
 	 */
186
-	public function delete( &$subscription ) {
186
+	public function delete(&$subscription) {
187 187
 		global $wpdb;
188 188
 
189 189
 		$wpdb->query(
@@ -194,16 +194,16 @@  discard block
 block discarded – undo
194 194
 			)
195 195
 		);
196 196
 
197
-		delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id' );
198
-		delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id' );
197
+		delete_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id');
198
+		delete_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscription_id');
199 199
 
200 200
 		// Delete cache.
201 201
 		$subscription->clear_cache();
202 202
 
203 203
 		// Fire a hook.
204
-		do_action( 'getpaid_delete_subscription', $subscription );
204
+		do_action('getpaid_delete_subscription', $subscription);
205 205
 
206
-		$subscription->set_id( 0 );
206
+		$subscription->set_id(0);
207 207
 	}
208 208
 
209 209
 	/*
Please login to merge, or discard this patch.
includes/subscription-functions.php 2 patches
Indentation   +279 added lines, -279 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
  */
51 51
 function getpaid_get_invoice_subscription_group( $invoice_id, $subscription_id ) {
52 52
     $subscription_groups = getpaid_get_invoice_subscription_groups( $invoice_id );
53
-	$matching_group      = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
53
+    $matching_group      = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
54 54
     return reset( $matching_group );
55 55
 }
56 56
 
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
  * @return WPInv_Subscription|false
63 63
  */
64 64
 function getpaid_get_subscription( $subscription ) {
65
-	$subscription = new WPInv_Subscription( $subscription );
66
-	return $subscription->exists() ? $subscription : false;
65
+    $subscription = new WPInv_Subscription( $subscription );
66
+    return $subscription->exists() ? $subscription : false;
67 67
 }
68 68
 
69 69
 /**
@@ -77,28 +77,28 @@  discard block
 block discarded – undo
77 77
  */
78 78
 function getpaid_get_subscriptions( $args = array(), $return = 'results' ) {
79 79
 
80
-	// Do not retrieve all fields if we just want the count.
81
-	if ( 'count' == $return ) {
82
-		$args['fields'] = 'id';
83
-		$args['number'] = 1;
84
-	}
80
+    // Do not retrieve all fields if we just want the count.
81
+    if ( 'count' == $return ) {
82
+        $args['fields'] = 'id';
83
+        $args['number'] = 1;
84
+    }
85 85
 
86
-	// Do not count all matches if we just want the results.
87
-	if ( 'results' == $return ) {
88
-		$args['count_total'] = false;
89
-	}
86
+    // Do not count all matches if we just want the results.
87
+    if ( 'results' == $return ) {
88
+        $args['count_total'] = false;
89
+    }
90 90
 
91
-	$query = new GetPaid_Subscriptions_Query( $args );
91
+    $query = new GetPaid_Subscriptions_Query( $args );
92 92
 
93
-	if ( 'results' == $return ) {
94
-		return $query->get_results();
95
-	}
93
+    if ( 'results' == $return ) {
94
+        return $query->get_results();
95
+    }
96 96
 
97
-	if ( 'count' == $return ) {
98
-		return $query->get_total();
99
-	}
97
+    if ( 'count' == $return ) {
98
+        return $query->get_total();
99
+    }
100 100
 
101
-	return $query;
101
+    return $query;
102 102
 }
103 103
 
104 104
 /**
@@ -108,18 +108,18 @@  discard block
 block discarded – undo
108 108
  */
109 109
 function getpaid_get_subscription_statuses() {
110 110
 
111
-	return apply_filters(
112
-		'getpaid_get_subscription_statuses',
113
-		array(
114
-			'pending'    => __( 'Pending', 'invoicing' ),
115
-			'trialling'  => __( 'Trialing', 'invoicing' ),
116
-			'active'     => __( 'Active', 'invoicing' ),
117
-			'failing'    => __( 'Failing', 'invoicing' ),
118
-			'expired'    => __( 'Expired', 'invoicing' ),
119
-			'completed'  => __( 'Complete', 'invoicing' ),
120
-			'cancelled'  => __( 'Cancelled', 'invoicing' ),
121
-		)
122
-	);
111
+    return apply_filters(
112
+        'getpaid_get_subscription_statuses',
113
+        array(
114
+            'pending'    => __( 'Pending', 'invoicing' ),
115
+            'trialling'  => __( 'Trialing', 'invoicing' ),
116
+            'active'     => __( 'Active', 'invoicing' ),
117
+            'failing'    => __( 'Failing', 'invoicing' ),
118
+            'expired'    => __( 'Expired', 'invoicing' ),
119
+            'completed'  => __( 'Complete', 'invoicing' ),
120
+            'cancelled'  => __( 'Cancelled', 'invoicing' ),
121
+        )
122
+    );
123 123
 
124 124
 }
125 125
 
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
  * @return string
130 130
  */
131 131
 function getpaid_get_subscription_status_label( $status ) {
132
-	$statuses = getpaid_get_subscription_statuses();
133
-	return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
132
+    $statuses = getpaid_get_subscription_statuses();
133
+    return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
134 134
 }
135 135
 
136 136
 /**
@@ -140,18 +140,18 @@  discard block
 block discarded – undo
140 140
  */
141 141
 function getpaid_get_subscription_status_classes() {
142 142
 
143
-	return apply_filters(
144
-		'getpaid_get_subscription_status_classes',
145
-		array(
146
-			'pending'    => 'badge-dark',
147
-			'trialling'  => 'badge-info',
148
-			'active'     => 'badge-success',
149
-			'failing'    => 'badge-warning',
150
-			'expired'    => 'badge-danger',
151
-			'completed'  => 'badge-primary',
152
-			'cancelled'  => 'badge-secondary',
153
-		)
154
-	);
143
+    return apply_filters(
144
+        'getpaid_get_subscription_status_classes',
145
+        array(
146
+            'pending'    => 'badge-dark',
147
+            'trialling'  => 'badge-info',
148
+            'active'     => 'badge-success',
149
+            'failing'    => 'badge-warning',
150
+            'expired'    => 'badge-danger',
151
+            'completed'  => 'badge-primary',
152
+            'cancelled'  => 'badge-secondary',
153
+        )
154
+    );
155 155
 
156 156
 }
157 157
 
@@ -162,15 +162,15 @@  discard block
 block discarded – undo
162 162
  */
163 163
 function getpaid_get_subscription_status_counts( $args = array() ) {
164 164
 
165
-	$statuses = array_keys( getpaid_get_subscription_statuses() );
166
-	$counts   = array();
165
+    $statuses = array_keys( getpaid_get_subscription_statuses() );
166
+    $counts   = array();
167 167
 
168
-	foreach ( $statuses as $status ) {
169
-		$_args             = wp_parse_args( "status=$status", $args );
170
-		$counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
171
-	}
168
+    foreach ( $statuses as $status ) {
169
+        $_args             = wp_parse_args( "status=$status", $args );
170
+        $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
171
+    }
172 172
 
173
-	return $counts;
173
+    return $counts;
174 174
 
175 175
 }
176 176
 
@@ -181,32 +181,32 @@  discard block
 block discarded – undo
181 181
  */
182 182
 function getpaid_get_subscription_periods() {
183 183
 
184
-	return apply_filters(
185
-		'getpaid_get_subscription_periods',
186
-		array(
184
+    return apply_filters(
185
+        'getpaid_get_subscription_periods',
186
+        array(
187 187
 
188
-			'day'   => array(
189
-				'singular' => __( '%s day', 'invoicing' ),
190
-				'plural'   => __( '%d days', 'invoicing' ),
191
-			),
188
+            'day'   => array(
189
+                'singular' => __( '%s day', 'invoicing' ),
190
+                'plural'   => __( '%d days', 'invoicing' ),
191
+            ),
192 192
 
193
-			'week'   => array(
194
-				'singular' => __( '%s week', 'invoicing' ),
195
-				'plural'   => __( '%d weeks', 'invoicing' ),
196
-			),
193
+            'week'   => array(
194
+                'singular' => __( '%s week', 'invoicing' ),
195
+                'plural'   => __( '%d weeks', 'invoicing' ),
196
+            ),
197 197
 
198
-			'month'   => array(
199
-				'singular' => __( '%s month', 'invoicing' ),
200
-				'plural'   => __( '%d months', 'invoicing' ),
201
-			),
198
+            'month'   => array(
199
+                'singular' => __( '%s month', 'invoicing' ),
200
+                'plural'   => __( '%d months', 'invoicing' ),
201
+            ),
202 202
 
203
-			'year'   => array(
204
-				'singular' => __( '%s year', 'invoicing' ),
205
-				'plural'   => __( '%d years', 'invoicing' ),
206
-			),
203
+            'year'   => array(
204
+                'singular' => __( '%s year', 'invoicing' ),
205
+                'plural'   => __( '%d years', 'invoicing' ),
206
+            ),
207 207
 
208
-		)
209
-	);
208
+        )
209
+    );
210 210
 
211 211
 }
212 212
 
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
  * @return int
218 218
  */
219 219
 function getpaid_get_subscription_trial_period_interval( $trial_period ) {
220
-	return (int) preg_replace( '/[^0-9]/', '', $trial_period );
220
+    return (int) preg_replace( '/[^0-9]/', '', $trial_period );
221 221
 }
222 222
 
223 223
 /**
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
  * @return string
228 228
  */
229 229
 function getpaid_get_subscription_trial_period_period( $trial_period ) {
230
-	return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
230
+    return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
231 231
 }
232 232
 
233 233
 /**
@@ -238,8 +238,8 @@  discard block
 block discarded – undo
238 238
  * @return string
239 239
  */
240 240
 function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) {
241
-	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
242
-	return strtolower( sanitize_text_field( $label ) );
241
+    $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
242
+    return strtolower( sanitize_text_field( $label ) );
243 243
 }
244 244
 
245 245
 /**
@@ -250,22 +250,22 @@  discard block
 block discarded – undo
250 250
  */
251 251
 function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) {
252 252
 
253
-	$periods = getpaid_get_subscription_periods();
254
-	$period  = strtolower( $period );
253
+    $periods = getpaid_get_subscription_periods();
254
+    $period  = strtolower( $period );
255 255
 
256
-	if ( isset( $periods[ $period ] ) ) {
257
-		return sprintf( $periods[ $period ]['singular'], $singular_prefix );
258
-	}
256
+    if ( isset( $periods[ $period ] ) ) {
257
+        return sprintf( $periods[ $period ]['singular'], $singular_prefix );
258
+    }
259 259
 
260
-	// Backwards compatibility.
261
-	foreach ( $periods as $key => $data ) {
262
-		if ( strpos( $key, $period ) === 0 ) {
263
-			return sprintf( $data['singular'], $singular_prefix );
264
-		}
265
-	}
260
+    // Backwards compatibility.
261
+    foreach ( $periods as $key => $data ) {
262
+        if ( strpos( $key, $period ) === 0 ) {
263
+            return sprintf( $data['singular'], $singular_prefix );
264
+        }
265
+    }
266 266
 
267
-	// Invalid string.
268
-	return '';
267
+    // Invalid string.
268
+    return '';
269 269
 }
270 270
 
271 271
 /**
@@ -277,22 +277,22 @@  discard block
 block discarded – undo
277 277
  */
278 278
 function getpaid_get_plural_subscription_period_label( $period, $interval ) {
279 279
 
280
-	$periods = getpaid_get_subscription_periods();
281
-	$period  = strtolower( $period );
280
+    $periods = getpaid_get_subscription_periods();
281
+    $period  = strtolower( $period );
282 282
 
283
-	if ( isset( $periods[ $period ] ) ) {
284
-		return sprintf( $periods[ $period ]['plural'], $interval );
285
-	}
283
+    if ( isset( $periods[ $period ] ) ) {
284
+        return sprintf( $periods[ $period ]['plural'], $interval );
285
+    }
286 286
 
287
-	// Backwards compatibility.
288
-	foreach ( $periods as $key => $data ) {
289
-		if ( strpos( $key, $period ) === 0 ) {
290
-			return sprintf( $data['plural'], $interval );
291
-		}
292
-	}
287
+    // Backwards compatibility.
288
+    foreach ( $periods as $key => $data ) {
289
+        if ( strpos( $key, $period ) === 0 ) {
290
+            return sprintf( $data['plural'], $interval );
291
+        }
292
+    }
293 293
 
294
-	// Invalid string.
295
-	return '';
294
+    // Invalid string.
295
+    return '';
296 296
 }
297 297
 
298 298
 /**
@@ -303,101 +303,101 @@  discard block
 block discarded – undo
303 303
  */
304 304
 function getpaid_get_formatted_subscription_amount( $subscription ) {
305 305
 
306
-	$initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
307
-	$recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
308
-	$period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
309
-	$bill_times = $subscription->get_bill_times();
306
+    $initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
307
+    $recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
308
+    $period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
309
+    $bill_times = $subscription->get_bill_times();
310 310
 
311
-	if ( ! empty( $bill_times ) ) {
312
-		$bill_times = $subscription->get_frequency() * $bill_times;
313
-		$bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
314
-	}
311
+    if ( ! empty( $bill_times ) ) {
312
+        $bill_times = $subscription->get_frequency() * $bill_times;
313
+        $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
314
+    }
315 315
 
316
-	// Trial periods.
317
-	if ( $subscription->has_trial_period() ) {
316
+    // Trial periods.
317
+    if ( $subscription->has_trial_period() ) {
318 318
 
319
-		$trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
320
-		$trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
319
+        $trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
320
+        $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
321 321
 
322
-		if ( empty( $bill_times ) ) {
322
+        if ( empty( $bill_times ) ) {
323 323
 
324
-			return sprintf(
324
+            return sprintf(
325 325
 
326
-				// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
327
-				_x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
328
-				$initial,
329
-				getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
330
-				$recurring,
331
-				$period
326
+                // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
327
+                _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
328
+                $initial,
329
+                getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
330
+                $recurring,
331
+                $period
332 332
 	
333
-			);
333
+            );
334 334
 
335
-		}
335
+        }
336 336
 
337
-		return sprintf(
337
+        return sprintf(
338 338
 
339
-			// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times
340
-			_x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ),
341
-			$initial,
342
-			getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
343
-			$recurring,
344
-			$period,
345
-			$bill_times
346
-		);
339
+            // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times
340
+            _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ),
341
+            $initial,
342
+            getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
343
+            $recurring,
344
+            $period,
345
+            $bill_times
346
+        );
347 347
 
348
-	}
348
+    }
349 349
 
350
-	if ( $initial != $recurring ) {
350
+    if ( $initial != $recurring ) {
351 351
 
352
-		if ( empty( $bill_times ) ) {
352
+        if ( empty( $bill_times ) ) {
353 353
 
354
-			return sprintf(
354
+            return sprintf(
355 355
 
356
-				// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
357
-				_x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
358
-				$initial,
359
-				$recurring,
360
-				$period
356
+                // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
357
+                _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
358
+                $initial,
359
+                $recurring,
360
+                $period
361 361
 	
362
-			);
362
+            );
363 363
 
364
-		}
364
+        }
365 365
 
366
-		return sprintf(
366
+        return sprintf(
367 367
 
368
-			// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
369
-			_x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ),
370
-			$initial,
371
-			$recurring,
372
-			$period,
373
-			$bill_times
368
+            // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
369
+            _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ),
370
+            $initial,
371
+            $recurring,
372
+            $period,
373
+            $bill_times
374 374
 
375
-		);
375
+        );
376 376
 
377
-	}
377
+    }
378 378
 
379
-	if ( empty( $bill_times ) ) {
379
+    if ( empty( $bill_times ) ) {
380 380
 
381
-		return sprintf(
381
+        return sprintf(
382 382
 
383
-			// translators: $1: is the recurring amount, $2: is the recurring period
384
-			_x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
385
-			$initial,
386
-			$period
383
+            // translators: $1: is the recurring amount, $2: is the recurring period
384
+            _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
385
+            $initial,
386
+            $period
387 387
 	
388
-		);
388
+        );
389 389
 
390
-	}
390
+    }
391 391
 
392
-	return sprintf(
392
+    return sprintf(
393 393
 
394
-		// translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
395
-		_x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
396
-		$bill_times,
397
-		$initial,
398
-		$period
394
+        // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
395
+        _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
396
+        $bill_times,
397
+        $initial,
398
+        $period
399 399
 
400
-	);
400
+    );
401 401
 
402 402
 }
403 403
 
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
  * @return WPInv_Subscription|bool
409 409
  */
410 410
 function getpaid_get_invoice_subscription( $invoice ) {
411
-	return getpaid_subscriptions()->get_invoice_subscription( $invoice );
411
+    return getpaid_subscriptions()->get_invoice_subscription( $invoice );
412 412
 }
413 413
 
414 414
 /**
@@ -417,10 +417,10 @@  discard block
 block discarded – undo
417 417
  * @param WPInv_Invoice $invoice
418 418
  */
419 419
 function getpaid_activate_invoice_subscription( $invoice ) {
420
-	$subscription = getpaid_get_invoice_subscription( $invoice );
421
-	if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
422
-		$subscription->activate();
423
-	}
420
+    $subscription = getpaid_get_invoice_subscription( $invoice );
421
+    if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
422
+        $subscription->activate();
423
+    }
424 424
 }
425 425
 
426 426
 /**
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
  * @return WPInv_Subscriptions
430 430
  */
431 431
 function getpaid_subscriptions() {
432
-	return getpaid()->get( 'subscriptions' );
432
+    return getpaid()->get( 'subscriptions' );
433 433
 }
434 434
 
435 435
 /**
@@ -448,15 +448,15 @@  discard block
 block discarded – undo
448 448
         return false;
449 449
     }
450 450
 
451
-	// Fetch the invoice subscription.
452
-	$subscription = getpaid_get_subscriptions(
453
-		array(
454
-			'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(),
455
-			'number'     => 1,
456
-		)
457
-	);
451
+    // Fetch the invoice subscription.
452
+    $subscription = getpaid_get_subscriptions(
453
+        array(
454
+            'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(),
455
+            'number'     => 1,
456
+        )
457
+    );
458 458
 
459
-	return empty( $subscription ) ? false : $subscription[0];
459
+    return empty( $subscription ) ? false : $subscription[0];
460 460
 
461 461
 }
462 462
 
@@ -473,48 +473,48 @@  discard block
 block discarded – undo
473 473
  */
474 474
 function getpaid_get_recurring_item_key( $cart_item ) {
475 475
 
476
-	$cart_key     = 'renews_';
477
-	$interval     = $cart_item->get_recurring_interval();
478
-	$period       = $cart_item->get_recurring_period( true );
479
-	$length       = $cart_item->get_recurring_limit() * $interval;
480
-	$trial_period = $cart_item->get_trial_period( true );
481
-	$trial_length = $cart_item->get_trial_interval();
482
-
483
-	// First start with the billing interval and period
484
-	switch ( $interval ) {
485
-		case 1 :
486
-			if ( 'day' == $period ) {
487
-				$cart_key .= 'daily';
488
-			} else {
489
-				$cart_key .= sprintf( '%sly', $period );
490
-			}
491
-			break;
492
-		case 2 :
493
-			$cart_key .= sprintf( 'every_2nd_%s', $period );
494
-			break;
495
-		case 3 :
496
-			$cart_key .= sprintf( 'every_3rd_%s', $period );
497
-		break;
498
-		default:
499
-			$cart_key .= sprintf( 'every_%dth_%s', $interval, $period );
500
-			break;
501
-	}
502
-
503
-	// Maybe add the optional maximum billing periods...
504
-	if ( $length > 0 ) {
505
-		$cart_key .= '_for_';
506
-		$cart_key .= sprintf( '%d_%s', $length, $period );
507
-		if ( $length > 1 ) {
508
-			$cart_key .= 's';
509
-		}
510
-	}
511
-
512
-	// And an optional free trial.
513
-	if ( $cart_item->has_free_trial() ) {
514
-		$cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period );
515
-	}
516
-
517
-	return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item );
476
+    $cart_key     = 'renews_';
477
+    $interval     = $cart_item->get_recurring_interval();
478
+    $period       = $cart_item->get_recurring_period( true );
479
+    $length       = $cart_item->get_recurring_limit() * $interval;
480
+    $trial_period = $cart_item->get_trial_period( true );
481
+    $trial_length = $cart_item->get_trial_interval();
482
+
483
+    // First start with the billing interval and period
484
+    switch ( $interval ) {
485
+        case 1 :
486
+            if ( 'day' == $period ) {
487
+                $cart_key .= 'daily';
488
+            } else {
489
+                $cart_key .= sprintf( '%sly', $period );
490
+            }
491
+            break;
492
+        case 2 :
493
+            $cart_key .= sprintf( 'every_2nd_%s', $period );
494
+            break;
495
+        case 3 :
496
+            $cart_key .= sprintf( 'every_3rd_%s', $period );
497
+        break;
498
+        default:
499
+            $cart_key .= sprintf( 'every_%dth_%s', $interval, $period );
500
+            break;
501
+    }
502
+
503
+    // Maybe add the optional maximum billing periods...
504
+    if ( $length > 0 ) {
505
+        $cart_key .= '_for_';
506
+        $cart_key .= sprintf( '%d_%s', $length, $period );
507
+        if ( $length > 1 ) {
508
+            $cart_key .= 's';
509
+        }
510
+    }
511
+
512
+    // And an optional free trial.
513
+    if ( $cart_item->has_free_trial() ) {
514
+        $cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period );
515
+    }
516
+
517
+    return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item );
518 518
 }
519 519
 
520 520
 /**
@@ -525,17 +525,17 @@  discard block
 block discarded – undo
525 525
  */
526 526
 function getpaid_get_subscription_groups( $invoice ) {
527 527
 
528
-	// Generate subscription groups.
529
-	$subscription_groups = array();
530
-	foreach ( $invoice->get_items() as $item ) {
528
+    // Generate subscription groups.
529
+    $subscription_groups = array();
530
+    foreach ( $invoice->get_items() as $item ) {
531 531
 
532
-		if ( $item->is_recurring() ) {
533
-			$subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item;
534
-		}
532
+        if ( $item->is_recurring() ) {
533
+            $subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item;
534
+        }
535 535
 
536
-	}
536
+    }
537 537
 
538
-	return $subscription_groups;
538
+    return $subscription_groups;
539 539
 }
540 540
 
541 541
 /**
@@ -549,57 +549,57 @@  discard block
 block discarded – undo
549 549
  */
550 550
 function getpaid_calculate_subscription_totals( $invoice ) {
551 551
 
552
-	// Generate subscription groups.
553
-	$subscription_groups = getpaid_get_subscription_groups( $invoice );
552
+    // Generate subscription groups.
553
+    $subscription_groups = getpaid_get_subscription_groups( $invoice );
554 554
 
555
-	// Now let's calculate the totals for each group of subscriptions
556
-	$subscription_totals = array();
555
+    // Now let's calculate the totals for each group of subscriptions
556
+    $subscription_totals = array();
557 557
 
558
-	foreach ( $subscription_groups as $subscription_key => $items ) {
558
+    foreach ( $subscription_groups as $subscription_key => $items ) {
559 559
 
560
-		if ( empty( $subscription_totals[ $subscription_key ] ) ) {
560
+        if ( empty( $subscription_totals[ $subscription_key ] ) ) {
561 561
 
562
-			$subscription_totals[ $subscription_key ] = array(
563
-				'initial_total'   => 0,
564
-				'recurring_total' => 0,
565
-				'items'           => array(),
566
-				'trialling'       => false,
567
-			);
562
+            $subscription_totals[ $subscription_key ] = array(
563
+                'initial_total'   => 0,
564
+                'recurring_total' => 0,
565
+                'items'           => array(),
566
+                'trialling'       => false,
567
+            );
568 568
 
569
-		}
569
+        }
570 570
 
571
-		/**
572
-		 * Get the totals of the group.
573
-		 * @var GetPaid_Form_Item $item
574
-		 */
575
-		foreach ( $items as $item ) {
571
+        /**
572
+         * Get the totals of the group.
573
+         * @var GetPaid_Form_Item $item
574
+         */
575
+        foreach ( $items as $item ) {
576 576
 
577
-			$subscription_totals[ $subscription_key ]['items'][$item->get_id()]  = $item->prepare_data_for_saving();
578
-			$subscription_totals[ $subscription_key ]['item_id']                 = $item->get_id();
579
-			$subscription_totals[ $subscription_key ]['period']                  = $item->get_recurring_period( true );
580
-			$subscription_totals[ $subscription_key ]['interval']                = $item->get_recurring_interval();
581
-			$subscription_totals[ $subscription_key ]['initial_total']          += $item->get_sub_total();
582
-			$subscription_totals[ $subscription_key ]['recurring_total']        += $item->get_recurring_sub_total();
583
-			$subscription_totals[ $subscription_key ]['recurring_limit']         = $item->get_recurring_limit();
577
+            $subscription_totals[ $subscription_key ]['items'][$item->get_id()]  = $item->prepare_data_for_saving();
578
+            $subscription_totals[ $subscription_key ]['item_id']                 = $item->get_id();
579
+            $subscription_totals[ $subscription_key ]['period']                  = $item->get_recurring_period( true );
580
+            $subscription_totals[ $subscription_key ]['interval']                = $item->get_recurring_interval();
581
+            $subscription_totals[ $subscription_key ]['initial_total']          += $item->get_sub_total();
582
+            $subscription_totals[ $subscription_key ]['recurring_total']        += $item->get_recurring_sub_total();
583
+            $subscription_totals[ $subscription_key ]['recurring_limit']         = $item->get_recurring_limit();
584 584
 
585
-			// Calculate the next renewal date.
586
-			$period       = $item->get_recurring_period( true );
587
-			$interval     = $item->get_recurring_interval();
585
+            // Calculate the next renewal date.
586
+            $period       = $item->get_recurring_period( true );
587
+            $interval     = $item->get_recurring_interval();
588 588
 
589
-			// If the subscription item has a trial period...
590
-			if ( $item->has_free_trial() ) {
591
-				$period   = $item->get_trial_period( true );
592
-				$interval = $item->get_trial_interval();
593
-				$subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period;
594
-			}
589
+            // If the subscription item has a trial period...
590
+            if ( $item->has_free_trial() ) {
591
+                $period   = $item->get_trial_period( true );
592
+                $interval = $item->get_trial_interval();
593
+                $subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period;
594
+            }
595 595
 
596
-			$subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) );
596
+            $subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) );
597 597
 
598
-		}
598
+        }
599 599
 
600
-	}
600
+    }
601 601
 
602
-	return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice );
602
+    return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice );
603 603
 }
604 604
 
605 605
 /**
@@ -610,15 +610,15 @@  discard block
 block discarded – undo
610 610
  */
611 611
 function getpaid_should_group_subscriptions( $invoice ) {
612 612
 
613
-	$recurring_items = 0;
613
+    $recurring_items = 0;
614 614
 
615
-	foreach ( $invoice->get_items() as $item ) {
615
+    foreach ( $invoice->get_items() as $item ) {
616 616
 
617
-		if ( $item->is_recurring() ) {
618
-			$recurring_items ++;
619
-		}
617
+        if ( $item->is_recurring() ) {
618
+            $recurring_items ++;
619
+        }
620 620
 
621
-	}
621
+    }
622 622
 
623
-	return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice );
623
+    return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice );
624 624
 }
Please login to merge, or discard this patch.
Spacing   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -13,18 +13,18 @@  discard block
 block discarded – undo
13 13
  * @return      WPInv_Subscription[]|WPInv_Subscription|false
14 14
  * @since       2.3.0
15 15
  */
16
-function getpaid_get_invoice_subscriptions( $invoice ) {
16
+function getpaid_get_invoice_subscriptions($invoice) {
17 17
 
18 18
     // Retrieve subscription groups.
19
-    $subscription_ids = wp_list_pluck( getpaid_get_invoice_subscription_groups( $invoice->get_id() ), 'subscription_id' );
19
+    $subscription_ids = wp_list_pluck(getpaid_get_invoice_subscription_groups($invoice->get_id()), 'subscription_id');
20 20
 
21 21
     // No subscription groups, normal subscription.
22
-    if ( empty( $subscription_ids ) ) {
23
-        return getpaid_subscriptions()->get_invoice_subscription( $invoice );
22
+    if (empty($subscription_ids)) {
23
+        return getpaid_subscriptions()->get_invoice_subscription($invoice);
24 24
     }
25 25
 
26 26
     // Subscription groups.
27
-    return array_filter( array_map( 'getpaid_get_subscription', $subscription_ids ) );
27
+    return array_filter(array_map('getpaid_get_subscription', $subscription_ids));
28 28
 
29 29
 }
30 30
 
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
  * @return      array
36 36
  * @since       2.3.0
37 37
  */
38
-function getpaid_get_invoice_subscription_groups( $invoice_id ) {
39
-    $subscription_groups = get_post_meta( $invoice_id, 'getpaid_subscription_groups', true );
40
-    return empty( $subscription_groups ) ? array() : $subscription_groups;
38
+function getpaid_get_invoice_subscription_groups($invoice_id) {
39
+    $subscription_groups = get_post_meta($invoice_id, 'getpaid_subscription_groups', true);
40
+    return empty($subscription_groups) ? array() : $subscription_groups;
41 41
 }
42 42
 
43 43
 /**
@@ -48,10 +48,10 @@  discard block
 block discarded – undo
48 48
  * @return      array|false
49 49
  * @since       2.3.0
50 50
  */
51
-function getpaid_get_invoice_subscription_group( $invoice_id, $subscription_id ) {
52
-    $subscription_groups = getpaid_get_invoice_subscription_groups( $invoice_id );
53
-	$matching_group      = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
54
-    return reset( $matching_group );
51
+function getpaid_get_invoice_subscription_group($invoice_id, $subscription_id) {
52
+    $subscription_groups = getpaid_get_invoice_subscription_groups($invoice_id);
53
+	$matching_group = wp_list_filter($subscription_groups, compact('subscription_id'));
54
+    return reset($matching_group);
55 55
 }
56 56
 
57 57
 /**
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
  * @since       2.3.0
62 62
  * @return WPInv_Subscription|false
63 63
  */
64
-function getpaid_get_subscription( $subscription ) {
65
-	$subscription = new WPInv_Subscription( $subscription );
64
+function getpaid_get_subscription($subscription) {
65
+	$subscription = new WPInv_Subscription($subscription);
66 66
 	return $subscription->exists() ? $subscription : false;
67 67
 }
68 68
 
@@ -75,26 +75,26 @@  discard block
 block discarded – undo
75 75
  *
76 76
  * @return int|array|WPInv_Subscription[]|GetPaid_Subscriptions_Query
77 77
  */
78
-function getpaid_get_subscriptions( $args = array(), $return = 'results' ) {
78
+function getpaid_get_subscriptions($args = array(), $return = 'results') {
79 79
 
80 80
 	// Do not retrieve all fields if we just want the count.
81
-	if ( 'count' == $return ) {
81
+	if ('count' == $return) {
82 82
 		$args['fields'] = 'id';
83 83
 		$args['number'] = 1;
84 84
 	}
85 85
 
86 86
 	// Do not count all matches if we just want the results.
87
-	if ( 'results' == $return ) {
87
+	if ('results' == $return) {
88 88
 		$args['count_total'] = false;
89 89
 	}
90 90
 
91
-	$query = new GetPaid_Subscriptions_Query( $args );
91
+	$query = new GetPaid_Subscriptions_Query($args);
92 92
 
93
-	if ( 'results' == $return ) {
93
+	if ('results' == $return) {
94 94
 		return $query->get_results();
95 95
 	}
96 96
 
97
-	if ( 'count' == $return ) {
97
+	if ('count' == $return) {
98 98
 		return $query->get_total();
99 99
 	}
100 100
 
@@ -111,13 +111,13 @@  discard block
 block discarded – undo
111 111
 	return apply_filters(
112 112
 		'getpaid_get_subscription_statuses',
113 113
 		array(
114
-			'pending'    => __( 'Pending', 'invoicing' ),
115
-			'trialling'  => __( 'Trialing', 'invoicing' ),
116
-			'active'     => __( 'Active', 'invoicing' ),
117
-			'failing'    => __( 'Failing', 'invoicing' ),
118
-			'expired'    => __( 'Expired', 'invoicing' ),
119
-			'completed'  => __( 'Complete', 'invoicing' ),
120
-			'cancelled'  => __( 'Cancelled', 'invoicing' ),
114
+			'pending'    => __('Pending', 'invoicing'),
115
+			'trialling'  => __('Trialing', 'invoicing'),
116
+			'active'     => __('Active', 'invoicing'),
117
+			'failing'    => __('Failing', 'invoicing'),
118
+			'expired'    => __('Expired', 'invoicing'),
119
+			'completed'  => __('Complete', 'invoicing'),
120
+			'cancelled'  => __('Cancelled', 'invoicing'),
121 121
 		)
122 122
 	);
123 123
 
@@ -128,9 +128,9 @@  discard block
 block discarded – undo
128 128
  *
129 129
  * @return string
130 130
  */
131
-function getpaid_get_subscription_status_label( $status ) {
131
+function getpaid_get_subscription_status_label($status) {
132 132
 	$statuses = getpaid_get_subscription_statuses();
133
-	return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
133
+	return isset($statuses[$status]) ? $statuses[$status] : ucfirst(sanitize_text_field($status));
134 134
 }
135 135
 
136 136
 /**
@@ -160,14 +160,14 @@  discard block
 block discarded – undo
160 160
  *
161 161
  * @return array
162 162
  */
163
-function getpaid_get_subscription_status_counts( $args = array() ) {
163
+function getpaid_get_subscription_status_counts($args = array()) {
164 164
 
165
-	$statuses = array_keys( getpaid_get_subscription_statuses() );
165
+	$statuses = array_keys(getpaid_get_subscription_statuses());
166 166
 	$counts   = array();
167 167
 
168
-	foreach ( $statuses as $status ) {
169
-		$_args             = wp_parse_args( "status=$status", $args );
170
-		$counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
168
+	foreach ($statuses as $status) {
169
+		$_args             = wp_parse_args("status=$status", $args);
170
+		$counts[$status] = getpaid_get_subscriptions($_args, 'count');
171 171
 	}
172 172
 
173 173
 	return $counts;
@@ -186,23 +186,23 @@  discard block
 block discarded – undo
186 186
 		array(
187 187
 
188 188
 			'day'   => array(
189
-				'singular' => __( '%s day', 'invoicing' ),
190
-				'plural'   => __( '%d days', 'invoicing' ),
189
+				'singular' => __('%s day', 'invoicing'),
190
+				'plural'   => __('%d days', 'invoicing'),
191 191
 			),
192 192
 
193 193
 			'week'   => array(
194
-				'singular' => __( '%s week', 'invoicing' ),
195
-				'plural'   => __( '%d weeks', 'invoicing' ),
194
+				'singular' => __('%s week', 'invoicing'),
195
+				'plural'   => __('%d weeks', 'invoicing'),
196 196
 			),
197 197
 
198 198
 			'month'   => array(
199
-				'singular' => __( '%s month', 'invoicing' ),
200
-				'plural'   => __( '%d months', 'invoicing' ),
199
+				'singular' => __('%s month', 'invoicing'),
200
+				'plural'   => __('%d months', 'invoicing'),
201 201
 			),
202 202
 
203 203
 			'year'   => array(
204
-				'singular' => __( '%s year', 'invoicing' ),
205
-				'plural'   => __( '%d years', 'invoicing' ),
204
+				'singular' => __('%s year', 'invoicing'),
205
+				'plural'   => __('%d years', 'invoicing'),
206 206
 			),
207 207
 
208 208
 		)
@@ -216,8 +216,8 @@  discard block
 block discarded – undo
216 216
  * @param string $trial_period
217 217
  * @return int
218 218
  */
219
-function getpaid_get_subscription_trial_period_interval( $trial_period ) {
220
-	return (int) preg_replace( '/[^0-9]/', '', $trial_period );
219
+function getpaid_get_subscription_trial_period_interval($trial_period) {
220
+	return (int) preg_replace('/[^0-9]/', '', $trial_period);
221 221
 }
222 222
 
223 223
 /**
@@ -226,8 +226,8 @@  discard block
 block discarded – undo
226 226
  * @param string $trial_period
227 227
  * @return string
228 228
  */
229
-function getpaid_get_subscription_trial_period_period( $trial_period ) {
230
-	return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
229
+function getpaid_get_subscription_trial_period_period($trial_period) {
230
+	return preg_replace('/[^a-z]/', '', strtolower($trial_period));
231 231
 }
232 232
 
233 233
 /**
@@ -237,9 +237,9 @@  discard block
 block discarded – undo
237 237
  * @param int $interval
238 238
  * @return string
239 239
  */
240
-function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) {
241
-	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
242
-	return strtolower( sanitize_text_field( $label ) );
240
+function getpaid_get_subscription_period_label($period, $interval = 1, $singular_prefix = '1') {
241
+	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label($period, $interval) : getpaid_get_singular_subscription_period_label($period, $singular_prefix);
242
+	return strtolower(sanitize_text_field($label));
243 243
 }
244 244
 
245 245
 /**
@@ -248,19 +248,19 @@  discard block
 block discarded – undo
248 248
  * @param string $period
249 249
  * @return string
250 250
  */
251
-function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) {
251
+function getpaid_get_singular_subscription_period_label($period, $singular_prefix = '1') {
252 252
 
253 253
 	$periods = getpaid_get_subscription_periods();
254
-	$period  = strtolower( $period );
254
+	$period  = strtolower($period);
255 255
 
256
-	if ( isset( $periods[ $period ] ) ) {
257
-		return sprintf( $periods[ $period ]['singular'], $singular_prefix );
256
+	if (isset($periods[$period])) {
257
+		return sprintf($periods[$period]['singular'], $singular_prefix);
258 258
 	}
259 259
 
260 260
 	// Backwards compatibility.
261
-	foreach ( $periods as $key => $data ) {
262
-		if ( strpos( $key, $period ) === 0 ) {
263
-			return sprintf( $data['singular'], $singular_prefix );
261
+	foreach ($periods as $key => $data) {
262
+		if (strpos($key, $period) === 0) {
263
+			return sprintf($data['singular'], $singular_prefix);
264 264
 		}
265 265
 	}
266 266
 
@@ -275,19 +275,19 @@  discard block
 block discarded – undo
275 275
  * @param int $interval
276 276
  * @return string
277 277
  */
278
-function getpaid_get_plural_subscription_period_label( $period, $interval ) {
278
+function getpaid_get_plural_subscription_period_label($period, $interval) {
279 279
 
280 280
 	$periods = getpaid_get_subscription_periods();
281
-	$period  = strtolower( $period );
281
+	$period  = strtolower($period);
282 282
 
283
-	if ( isset( $periods[ $period ] ) ) {
284
-		return sprintf( $periods[ $period ]['plural'], $interval );
283
+	if (isset($periods[$period])) {
284
+		return sprintf($periods[$period]['plural'], $interval);
285 285
 	}
286 286
 
287 287
 	// Backwards compatibility.
288
-	foreach ( $periods as $key => $data ) {
289
-		if ( strpos( $key, $period ) === 0 ) {
290
-			return sprintf( $data['plural'], $interval );
288
+	foreach ($periods as $key => $data) {
289
+		if (strpos($key, $period) === 0) {
290
+			return sprintf($data['plural'], $interval);
291 291
 		}
292 292
 	}
293 293
 
@@ -301,32 +301,32 @@  discard block
 block discarded – undo
301 301
  * @param WPInv_Subscription $subscription
302 302
  * @return string
303 303
  */
304
-function getpaid_get_formatted_subscription_amount( $subscription ) {
304
+function getpaid_get_formatted_subscription_amount($subscription) {
305 305
 
306
-	$initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
307
-	$recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
308
-	$period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
306
+	$initial    = wpinv_price($subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency());
307
+	$recurring  = wpinv_price($subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency());
308
+	$period     = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), '');
309 309
 	$bill_times = $subscription->get_bill_times();
310 310
 
311
-	if ( ! empty( $bill_times ) ) {
311
+	if (!empty($bill_times)) {
312 312
 		$bill_times = $subscription->get_frequency() * $bill_times;
313
-		$bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
313
+		$bill_times = getpaid_get_subscription_period_label($subscription->get_period(), $bill_times);
314 314
 	}
315 315
 
316 316
 	// Trial periods.
317
-	if ( $subscription->has_trial_period() ) {
317
+	if ($subscription->has_trial_period()) {
318 318
 
319
-		$trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
320
-		$trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
319
+		$trial_period   = getpaid_get_subscription_trial_period_period($subscription->get_trial_period());
320
+		$trial_interval = getpaid_get_subscription_trial_period_interval($subscription->get_trial_period());
321 321
 
322
-		if ( empty( $bill_times ) ) {
322
+		if (empty($bill_times)) {
323 323
 
324 324
 			return sprintf(
325 325
 
326 326
 				// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
327
-				_x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
327
+				_x('%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing'),
328 328
 				$initial,
329
-				getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
329
+				getpaid_get_subscription_period_label($trial_period, $trial_interval),
330 330
 				$recurring,
331 331
 				$period
332 332
 	
@@ -337,9 +337,9 @@  discard block
 block discarded – undo
337 337
 		return sprintf(
338 338
 
339 339
 			// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times
340
-			_x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ),
340
+			_x('%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing'),
341 341
 			$initial,
342
-			getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
342
+			getpaid_get_subscription_period_label($trial_period, $trial_interval),
343 343
 			$recurring,
344 344
 			$period,
345 345
 			$bill_times
@@ -347,14 +347,14 @@  discard block
 block discarded – undo
347 347
 
348 348
 	}
349 349
 
350
-	if ( $initial != $recurring ) {
350
+	if ($initial != $recurring) {
351 351
 
352
-		if ( empty( $bill_times ) ) {
352
+		if (empty($bill_times)) {
353 353
 
354 354
 			return sprintf(
355 355
 
356 356
 				// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
357
-				_x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
357
+				_x('Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing'),
358 358
 				$initial,
359 359
 				$recurring,
360 360
 				$period
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
 		return sprintf(
367 367
 
368 368
 			// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
369
-			_x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ),
369
+			_x('Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing'),
370 370
 			$initial,
371 371
 			$recurring,
372 372
 			$period,
@@ -376,12 +376,12 @@  discard block
 block discarded – undo
376 376
 
377 377
 	}
378 378
 
379
-	if ( empty( $bill_times ) ) {
379
+	if (empty($bill_times)) {
380 380
 
381 381
 		return sprintf(
382 382
 
383 383
 			// translators: $1: is the recurring amount, $2: is the recurring period
384
-			_x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
384
+			_x('%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing'),
385 385
 			$initial,
386 386
 			$period
387 387
 	
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 	return sprintf(
393 393
 
394 394
 		// translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
395
-		_x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
395
+		_x('%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing'),
396 396
 		$bill_times,
397 397
 		$initial,
398 398
 		$period
@@ -407,8 +407,8 @@  discard block
 block discarded – undo
407 407
  * @param WPInv_Invoice $invoice
408 408
  * @return WPInv_Subscription|bool
409 409
  */
410
-function getpaid_get_invoice_subscription( $invoice ) {
411
-	return getpaid_subscriptions()->get_invoice_subscription( $invoice );
410
+function getpaid_get_invoice_subscription($invoice) {
411
+	return getpaid_subscriptions()->get_invoice_subscription($invoice);
412 412
 }
413 413
 
414 414
 /**
@@ -416,9 +416,9 @@  discard block
 block discarded – undo
416 416
  *
417 417
  * @param WPInv_Invoice $invoice
418 418
  */
419
-function getpaid_activate_invoice_subscription( $invoice ) {
420
-	$subscription = getpaid_get_invoice_subscription( $invoice );
421
-	if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
419
+function getpaid_activate_invoice_subscription($invoice) {
420
+	$subscription = getpaid_get_invoice_subscription($invoice);
421
+	if (is_a($subscription, 'WPInv_Subscription')) {
422 422
 		$subscription->activate();
423 423
 	}
424 424
 }
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
  * @return WPInv_Subscriptions
430 430
  */
431 431
 function getpaid_subscriptions() {
432
-	return getpaid()->get( 'subscriptions' );
432
+	return getpaid()->get('subscriptions');
433 433
 }
434 434
 
435 435
 /**
@@ -438,13 +438,13 @@  discard block
 block discarded – undo
438 438
  * @since 2.3.0
439 439
  * @return WPInv_Subscription|bool
440 440
  */
441
-function wpinv_get_invoice_subscription( $invoice ) {
441
+function wpinv_get_invoice_subscription($invoice) {
442 442
 
443 443
     // Retrieve the invoice.
444
-    $invoice = new WPInv_Invoice( $invoice );
444
+    $invoice = new WPInv_Invoice($invoice);
445 445
 
446 446
     // Ensure it is a recurring invoice.
447
-    if ( ! $invoice->is_recurring() ) {
447
+    if (!$invoice->is_recurring()) {
448 448
         return false;
449 449
     }
450 450
 
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
 		)
457 457
 	);
458 458
 
459
-	return empty( $subscription ) ? false : $subscription[0];
459
+	return empty($subscription) ? false : $subscription[0];
460 460
 
461 461
 }
462 462
 
@@ -471,50 +471,50 @@  discard block
 block discarded – undo
471 471
  * @param GetPaid_Form_Item|WPInv_Item $cart_item
472 472
  * @return string
473 473
  */
474
-function getpaid_get_recurring_item_key( $cart_item ) {
474
+function getpaid_get_recurring_item_key($cart_item) {
475 475
 
476 476
 	$cart_key     = 'renews_';
477 477
 	$interval     = $cart_item->get_recurring_interval();
478
-	$period       = $cart_item->get_recurring_period( true );
478
+	$period       = $cart_item->get_recurring_period(true);
479 479
 	$length       = $cart_item->get_recurring_limit() * $interval;
480
-	$trial_period = $cart_item->get_trial_period( true );
480
+	$trial_period = $cart_item->get_trial_period(true);
481 481
 	$trial_length = $cart_item->get_trial_interval();
482 482
 
483 483
 	// First start with the billing interval and period
484
-	switch ( $interval ) {
484
+	switch ($interval) {
485 485
 		case 1 :
486
-			if ( 'day' == $period ) {
486
+			if ('day' == $period) {
487 487
 				$cart_key .= 'daily';
488 488
 			} else {
489
-				$cart_key .= sprintf( '%sly', $period );
489
+				$cart_key .= sprintf('%sly', $period);
490 490
 			}
491 491
 			break;
492 492
 		case 2 :
493
-			$cart_key .= sprintf( 'every_2nd_%s', $period );
493
+			$cart_key .= sprintf('every_2nd_%s', $period);
494 494
 			break;
495 495
 		case 3 :
496
-			$cart_key .= sprintf( 'every_3rd_%s', $period );
496
+			$cart_key .= sprintf('every_3rd_%s', $period);
497 497
 		break;
498 498
 		default:
499
-			$cart_key .= sprintf( 'every_%dth_%s', $interval, $period );
499
+			$cart_key .= sprintf('every_%dth_%s', $interval, $period);
500 500
 			break;
501 501
 	}
502 502
 
503 503
 	// Maybe add the optional maximum billing periods...
504
-	if ( $length > 0 ) {
504
+	if ($length > 0) {
505 505
 		$cart_key .= '_for_';
506
-		$cart_key .= sprintf( '%d_%s', $length, $period );
507
-		if ( $length > 1 ) {
506
+		$cart_key .= sprintf('%d_%s', $length, $period);
507
+		if ($length > 1) {
508 508
 			$cart_key .= 's';
509 509
 		}
510 510
 	}
511 511
 
512 512
 	// And an optional free trial.
513
-	if ( $cart_item->has_free_trial() ) {
514
-		$cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period );
513
+	if ($cart_item->has_free_trial()) {
514
+		$cart_key .= sprintf('_after_a_%d_%s_trial', $trial_length, $trial_period);
515 515
 	}
516 516
 
517
-	return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item );
517
+	return apply_filters('getpaid_get_recurring_item_key', $cart_key, $cart_item);
518 518
 }
519 519
 
520 520
 /**
@@ -523,14 +523,14 @@  discard block
 block discarded – undo
523 523
  * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice
524 524
  * @return array
525 525
  */
526
-function getpaid_get_subscription_groups( $invoice ) {
526
+function getpaid_get_subscription_groups($invoice) {
527 527
 
528 528
 	// Generate subscription groups.
529 529
 	$subscription_groups = array();
530
-	foreach ( $invoice->get_items() as $item ) {
530
+	foreach ($invoice->get_items() as $item) {
531 531
 
532
-		if ( $item->is_recurring() ) {
533
-			$subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item;
532
+		if ($item->is_recurring()) {
533
+			$subscription_groups[getpaid_get_recurring_item_key($item)][] = $item;
534 534
 		}
535 535
 
536 536
 	}
@@ -547,19 +547,19 @@  discard block
 block discarded – undo
547 547
  * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice
548 548
  * @return array
549 549
  */
550
-function getpaid_calculate_subscription_totals( $invoice ) {
550
+function getpaid_calculate_subscription_totals($invoice) {
551 551
 
552 552
 	// Generate subscription groups.
553
-	$subscription_groups = getpaid_get_subscription_groups( $invoice );
553
+	$subscription_groups = getpaid_get_subscription_groups($invoice);
554 554
 
555 555
 	// Now let's calculate the totals for each group of subscriptions
556 556
 	$subscription_totals = array();
557 557
 
558
-	foreach ( $subscription_groups as $subscription_key => $items ) {
558
+	foreach ($subscription_groups as $subscription_key => $items) {
559 559
 
560
-		if ( empty( $subscription_totals[ $subscription_key ] ) ) {
560
+		if (empty($subscription_totals[$subscription_key])) {
561 561
 
562
-			$subscription_totals[ $subscription_key ] = array(
562
+			$subscription_totals[$subscription_key] = array(
563 563
 				'initial_total'   => 0,
564 564
 				'recurring_total' => 0,
565 565
 				'items'           => array(),
@@ -572,34 +572,34 @@  discard block
 block discarded – undo
572 572
 		 * Get the totals of the group.
573 573
 		 * @var GetPaid_Form_Item $item
574 574
 		 */
575
-		foreach ( $items as $item ) {
575
+		foreach ($items as $item) {
576 576
 
577
-			$subscription_totals[ $subscription_key ]['items'][$item->get_id()]  = $item->prepare_data_for_saving();
578
-			$subscription_totals[ $subscription_key ]['item_id']                 = $item->get_id();
579
-			$subscription_totals[ $subscription_key ]['period']                  = $item->get_recurring_period( true );
580
-			$subscription_totals[ $subscription_key ]['interval']                = $item->get_recurring_interval();
581
-			$subscription_totals[ $subscription_key ]['initial_total']          += $item->get_sub_total();
582
-			$subscription_totals[ $subscription_key ]['recurring_total']        += $item->get_recurring_sub_total();
583
-			$subscription_totals[ $subscription_key ]['recurring_limit']         = $item->get_recurring_limit();
577
+			$subscription_totals[$subscription_key]['items'][$item->get_id()]  = $item->prepare_data_for_saving();
578
+			$subscription_totals[$subscription_key]['item_id']                 = $item->get_id();
579
+			$subscription_totals[$subscription_key]['period']                  = $item->get_recurring_period(true);
580
+			$subscription_totals[$subscription_key]['interval']                = $item->get_recurring_interval();
581
+			$subscription_totals[$subscription_key]['initial_total']          += $item->get_sub_total();
582
+			$subscription_totals[$subscription_key]['recurring_total']        += $item->get_recurring_sub_total();
583
+			$subscription_totals[$subscription_key]['recurring_limit']         = $item->get_recurring_limit();
584 584
 
585 585
 			// Calculate the next renewal date.
586
-			$period       = $item->get_recurring_period( true );
586
+			$period       = $item->get_recurring_period(true);
587 587
 			$interval     = $item->get_recurring_interval();
588 588
 
589 589
 			// If the subscription item has a trial period...
590
-			if ( $item->has_free_trial() ) {
591
-				$period   = $item->get_trial_period( true );
590
+			if ($item->has_free_trial()) {
591
+				$period   = $item->get_trial_period(true);
592 592
 				$interval = $item->get_trial_interval();
593
-				$subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period;
593
+				$subscription_totals[$subscription_key]['trialling'] = $interval . ' ' . $period;
594 594
 			}
595 595
 
596
-			$subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) );
596
+			$subscription_totals[$subscription_key]['renews_on'] = date('Y-m-d H:i:s', strtotime("+$interval $period", current_time('timestamp')));
597 597
 
598 598
 		}
599 599
 
600 600
 	}
601 601
 
602
-	return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice );
602
+	return apply_filters('getpaid_calculate_subscription_totals', $subscription_totals, $invoice);
603 603
 }
604 604
 
605 605
 /**
@@ -608,17 +608,17 @@  discard block
 block discarded – undo
608 608
  * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice
609 609
  * @return array
610 610
  */
611
-function getpaid_should_group_subscriptions( $invoice ) {
611
+function getpaid_should_group_subscriptions($invoice) {
612 612
 
613 613
 	$recurring_items = 0;
614 614
 
615
-	foreach ( $invoice->get_items() as $item ) {
615
+	foreach ($invoice->get_items() as $item) {
616 616
 
617
-		if ( $item->is_recurring() ) {
618
-			$recurring_items ++;
617
+		if ($item->is_recurring()) {
618
+			$recurring_items++;
619 619
 		}
620 620
 
621 621
 	}
622 622
 
623
-	return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice );
623
+	return apply_filters('getpaid_should_group_subscriptions', $recurring_items > 1, $invoice);
624 624
 }
Please login to merge, or discard this patch.
includes/class-wpinv-subscriptions.php 1 patch
Spacing   +167 added lines, -167 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
  * Main Subscriptions class.
10 10
  *
@@ -14,31 +14,31 @@  discard block
 block discarded – undo
14 14
     /**
15 15
 	 * Class constructor.
16 16
 	 */
17
-    public function __construct(){
17
+    public function __construct() {
18 18
 
19 19
         // Fire gateway specific hooks when a subscription changes.
20
-        add_action( 'getpaid_subscription_status_changed', array( $this, 'process_subscription_status_change' ), 10, 3 );
20
+        add_action('getpaid_subscription_status_changed', array($this, 'process_subscription_status_change'), 10, 3);
21 21
 
22 22
         // De-activate a subscription whenever the invoice changes payment statuses.
23
-        add_action( 'getpaid_invoice_status_wpi-refunded', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 );
24
-        add_action( 'getpaid_invoice_status_wpi-failed', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 );
25
-        add_action( 'getpaid_invoice_status_wpi-cancelled', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 );
26
-        add_action( 'getpaid_invoice_status_wpi-pending', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 );
23
+        add_action('getpaid_invoice_status_wpi-refunded', array($this, 'maybe_deactivate_invoice_subscription'), 20);
24
+        add_action('getpaid_invoice_status_wpi-failed', array($this, 'maybe_deactivate_invoice_subscription'), 20);
25
+        add_action('getpaid_invoice_status_wpi-cancelled', array($this, 'maybe_deactivate_invoice_subscription'), 20);
26
+        add_action('getpaid_invoice_status_wpi-pending', array($this, 'maybe_deactivate_invoice_subscription'), 20);
27 27
 
28 28
         // Handles subscription cancelations.
29
-        add_action( 'getpaid_authenticated_action_subscription_cancel', array( $this, 'user_cancel_single_subscription' ) );
29
+        add_action('getpaid_authenticated_action_subscription_cancel', array($this, 'user_cancel_single_subscription'));
30 30
 
31 31
         // Create a subscription whenever an invoice is created, (and update it when it is updated).
32
-        add_action( 'getpaid_new_invoice', array( $this, 'maybe_create_invoice_subscription' ), 5 );
33
-        add_action( 'getpaid_update_invoice', array( $this, 'maybe_update_invoice_subscription' ), 5 );
32
+        add_action('getpaid_new_invoice', array($this, 'maybe_create_invoice_subscription'), 5);
33
+        add_action('getpaid_update_invoice', array($this, 'maybe_update_invoice_subscription'), 5);
34 34
 
35 35
         // Handles admin subscription update actions.
36
-        add_action( 'getpaid_authenticated_admin_action_update_single_subscription', array( $this, 'admin_update_single_subscription' ) );
37
-        add_action( 'getpaid_authenticated_admin_action_subscription_manual_renew', array( $this, 'admin_renew_single_subscription' ) );
38
-        add_action( 'getpaid_authenticated_admin_action_subscription_manual_delete', array( $this, 'admin_delete_single_subscription' ) );
36
+        add_action('getpaid_authenticated_admin_action_update_single_subscription', array($this, 'admin_update_single_subscription'));
37
+        add_action('getpaid_authenticated_admin_action_subscription_manual_renew', array($this, 'admin_renew_single_subscription'));
38
+        add_action('getpaid_authenticated_admin_action_subscription_manual_delete', array($this, 'admin_delete_single_subscription'));
39 39
     
40 40
         // Filter invoice item row actions.
41
-        add_action( 'getpaid-invoice-page-line-item-actions', array( $this, 'filter_invoice_line_item_actions' ), 10, 3 );
41
+        add_action('getpaid-invoice-page-line-item-actions', array($this, 'filter_invoice_line_item_actions'), 10, 3);
42 42
     }
43 43
 
44 44
     /**
@@ -47,19 +47,19 @@  discard block
 block discarded – undo
47 47
      * @param WPInv_Invoice $invoice
48 48
      * @return WPInv_Subscription|bool
49 49
      */
50
-    public function get_invoice_subscription( $invoice ) {
50
+    public function get_invoice_subscription($invoice) {
51 51
         $subscription_id = $invoice->get_subscription_id();
52 52
 
53 53
         // Fallback to the parent invoice if the child invoice has no subscription id.
54
-        if ( empty( $subscription_id ) && $invoice->is_renewal() ) {
54
+        if (empty($subscription_id) && $invoice->is_renewal()) {
55 55
             $subscription_id = $invoice->get_parent_payment()->get_subscription_id();
56 56
         }
57 57
 
58 58
         // Fetch the subscription.
59
-        $subscription = new WPInv_Subscription( $subscription_id );
59
+        $subscription = new WPInv_Subscription($subscription_id);
60 60
 
61 61
         // Return subscription or use a fallback for backwards compatibility.
62
-        return $subscription->exists() ? $subscription : wpinv_get_invoice_subscription( $invoice );
62
+        return $subscription->exists() ? $subscription : wpinv_get_invoice_subscription($invoice);
63 63
     }
64 64
 
65 65
     /**
@@ -67,21 +67,21 @@  discard block
 block discarded – undo
67 67
      * 
68 68
      * @param WPInv_Invoice $invoice
69 69
      */
70
-    public function maybe_deactivate_invoice_subscription( $invoice ) {
70
+    public function maybe_deactivate_invoice_subscription($invoice) {
71 71
 
72
-        $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
72
+        $subscriptions = getpaid_get_invoice_subscriptions($invoice);
73 73
 
74
-        if ( empty( $subscriptions ) ) {
74
+        if (empty($subscriptions)) {
75 75
             return;
76 76
         }
77 77
 
78
-        if ( ! is_array( $subscriptions ) ) {
79
-            $subscriptions = array( $subscriptions );
78
+        if (!is_array($subscriptions)) {
79
+            $subscriptions = array($subscriptions);
80 80
         }
81 81
 
82
-        foreach ( $subscriptions as $subscription ) {
83
-            if ( $subscription->is_active() ) {
84
-                $subscription->set_status( 'pending' );
82
+        foreach ($subscriptions as $subscription) {
83
+            if ($subscription->is_active()) {
84
+                $subscription->set_status('pending');
85 85
                 $subscription->save();
86 86
             }
87 87
         }
@@ -95,15 +95,15 @@  discard block
 block discarded – undo
95 95
      * @param string $from
96 96
      * @param string $to
97 97
 	 */
98
-    public function process_subscription_status_change( $subscription, $from, $to ) {
98
+    public function process_subscription_status_change($subscription, $from, $to) {
99 99
 
100 100
         $gateway = $subscription->get_gateway();
101 101
 
102
-        if ( ! empty( $gateway ) ) {
103
-            $gateway = sanitize_key( $gateway );
104
-            $from    = sanitize_key( $from );
105
-            $to      = sanitize_key( $to );
106
-            do_action( "getpaid_{$gateway}_subscription_$to", $subscription, $from );
102
+        if (!empty($gateway)) {
103
+            $gateway = sanitize_key($gateway);
104
+            $from    = sanitize_key($from);
105
+            $to      = sanitize_key($to);
106
+            do_action("getpaid_{$gateway}_subscription_$to", $subscription, $from);
107 107
         }
108 108
 
109 109
     }
@@ -116,8 +116,8 @@  discard block
 block discarded – undo
116 116
      * @deprecated
117 117
      * @return mixed|string|void
118 118
      */
119
-    public static function wpinv_get_pretty_subscription_frequency( $period, $frequency_count = 1 ) {
120
-        return getpaid_get_subscription_period_label( $period, $frequency_count );
119
+    public static function wpinv_get_pretty_subscription_frequency($period, $frequency_count = 1) {
120
+        return getpaid_get_subscription_period_label($period, $frequency_count);
121 121
     }
122 122
 
123 123
     /**
@@ -127,33 +127,33 @@  discard block
 block discarded – undo
127 127
      * @since       1.0.0
128 128
      * @return      void
129 129
      */
130
-    public function user_cancel_single_subscription( $data ) {
130
+    public function user_cancel_single_subscription($data) {
131 131
 
132 132
         // Ensure there is a subscription to cancel.
133
-        if ( empty( $data['subscription'] ) ) {
133
+        if (empty($data['subscription'])) {
134 134
             return;
135 135
         }
136 136
 
137
-        $subscription = new WPInv_Subscription( (int) $data['subscription'] );
137
+        $subscription = new WPInv_Subscription((int) $data['subscription']);
138 138
 
139 139
         // Ensure that it exists and that it belongs to the current user.
140
-        if ( ! $subscription->exists() || $subscription->get_customer_id() != get_current_user_id() ) {
141
-            wpinv_set_error( 'invalid_subscription', __( 'You do not have permission to cancel this subscription', 'invoicing' ) );
140
+        if (!$subscription->exists() || $subscription->get_customer_id() != get_current_user_id()) {
141
+            wpinv_set_error('invalid_subscription', __('You do not have permission to cancel this subscription', 'invoicing'));
142 142
 
143 143
         // Can it be cancelled.
144
-        } else if ( ! $subscription->can_cancel() ) {
145
-            wpinv_set_error( 'cannot_cancel', __( 'This subscription cannot be cancelled as it is not active.', 'invoicing' ) );
144
+        } else if (!$subscription->can_cancel()) {
145
+            wpinv_set_error('cannot_cancel', __('This subscription cannot be cancelled as it is not active.', 'invoicing'));
146 146
 
147 147
         // Cancel it.
148 148
         } else {
149 149
 
150 150
             $subscription->cancel();
151
-            wpinv_set_error( 'cancelled', __( 'This subscription has been cancelled.', 'invoicing' ), 'info' );
151
+            wpinv_set_error('cancelled', __('This subscription has been cancelled.', 'invoicing'), 'info');
152 152
         }
153 153
 
154
-        $redirect = remove_query_arg( array( 'getpaid-action', 'getpaid-nonce' ) );
154
+        $redirect = remove_query_arg(array('getpaid-action', 'getpaid-nonce'));
155 155
 
156
-        wp_safe_redirect( $redirect );
156
+        wp_safe_redirect($redirect);
157 157
         exit;
158 158
 
159 159
     }
@@ -165,41 +165,41 @@  discard block
 block discarded – undo
165 165
      * @param       WPInv_Invoice $invoice
166 166
      * @since       1.0.0
167 167
      */
168
-    public function maybe_create_invoice_subscription( $invoice ) {
168
+    public function maybe_create_invoice_subscription($invoice) {
169 169
         global $getpaid_subscriptions_skip_invoice_update;
170 170
 
171 171
         // Abort if it is not recurring.
172
-        if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_free() || ! $invoice->is_recurring() || $invoice->is_renewal() ) {
172
+        if (!$invoice->is_type('invoice') || $invoice->is_free() || !$invoice->is_recurring() || $invoice->is_renewal()) {
173 173
             return;
174 174
         }
175 175
 
176 176
         // Either group the subscriptions or only process a single suscription.
177
-        if ( getpaid_should_group_subscriptions( $invoice ) ) {
177
+        if (getpaid_should_group_subscriptions($invoice)) {
178 178
 
179 179
             $subscription_groups = array();
180 180
             $is_first            = true;
181 181
 
182
-            foreach ( getpaid_calculate_subscription_totals( $invoice ) as $group_key => $totals ) {
183
-                $subscription_groups[ $group_key ] = $this->create_invoice_subscription_group( $totals, $invoice, 0, $is_first );
182
+            foreach (getpaid_calculate_subscription_totals($invoice) as $group_key => $totals) {
183
+                $subscription_groups[$group_key] = $this->create_invoice_subscription_group($totals, $invoice, 0, $is_first);
184 184
 
185
-                if ( $is_first ) {
185
+                if ($is_first) {
186 186
                     $getpaid_subscriptions_skip_invoice_update = true;
187
-                    $invoice->set_subscription_id( $subscription_groups[ $group_key ]['subscription_id'] );
187
+                    $invoice->set_subscription_id($subscription_groups[$group_key]['subscription_id']);
188 188
                     $invoice->save();
189 189
                     $getpaid_subscriptions_skip_invoice_update = false;
190 190
                 }
191 191
     
192
-                $is_first                          = false;
192
+                $is_first = false;
193 193
             }
194 194
 
195 195
             // Cache subscription groups.
196
-            update_post_meta( $invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups );
196
+            update_post_meta($invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups);
197 197
             return true;
198 198
 
199 199
         }
200 200
 
201 201
         $subscription = new WPInv_Subscription();
202
-        return $this->update_invoice_subscription( $subscription, $invoice );
202
+        return $this->update_invoice_subscription($subscription, $invoice);
203 203
 
204 204
     }
205 205
 
@@ -214,41 +214,41 @@  discard block
 block discarded – undo
214 214
      *
215 215
      * @since       2.3.0
216 216
      */
217
-    public function create_invoice_subscription_group( $totals, $invoice, $subscription_id = 0, $is_first = false ) {
217
+    public function create_invoice_subscription_group($totals, $invoice, $subscription_id = 0, $is_first = false) {
218 218
 
219
-        $subscription = new WPInv_Subscription( (int) $subscription_id );
219
+        $subscription = new WPInv_Subscription((int) $subscription_id);
220 220
         $initial_amt  = $totals['initial_total'];
221 221
 
222 222
         // Maybe add non-recurring items.
223
-        if ( $is_first ) {
224
-            foreach ( $invoice->get_items() as $item ) {
225
-                if ( ! $item->is_recurring() ) {
223
+        if ($is_first) {
224
+            foreach ($invoice->get_items() as $item) {
225
+                if (!$item->is_recurring()) {
226 226
                     $initial_amt += $item->get_sub_total();
227 227
                 }
228 228
             }
229 229
         }
230 230
 
231
-        $subscription->set_customer_id( $invoice->get_customer_id() );
232
-        $subscription->set_parent_invoice_id( $invoice->get_id() );
233
-        $subscription->set_initial_amount( $initial_amt );
234
-        $subscription->set_recurring_amount( $totals['recurring_total'] );
235
-        $subscription->set_date_created( current_time( 'mysql' ) );
236
-        $subscription->set_status( $invoice->is_paid() ? 'active' : 'pending' );
237
-        $subscription->set_product_id( $totals['item_id'] );
238
-        $subscription->set_period( $totals['period'] );
239
-        $subscription->set_frequency( $totals['interval'] );
240
-        $subscription->set_bill_times( $totals['recurring_limit'] );
241
-        $subscription->set_next_renewal_date( $totals['renews_on'] );
231
+        $subscription->set_customer_id($invoice->get_customer_id());
232
+        $subscription->set_parent_invoice_id($invoice->get_id());
233
+        $subscription->set_initial_amount($initial_amt);
234
+        $subscription->set_recurring_amount($totals['recurring_total']);
235
+        $subscription->set_date_created(current_time('mysql'));
236
+        $subscription->set_status($invoice->is_paid() ? 'active' : 'pending');
237
+        $subscription->set_product_id($totals['item_id']);
238
+        $subscription->set_period($totals['period']);
239
+        $subscription->set_frequency($totals['interval']);
240
+        $subscription->set_bill_times($totals['recurring_limit']);
241
+        $subscription->set_next_renewal_date($totals['renews_on']);
242 242
 
243 243
         // Trial periods.
244
-        if ( ! empty( $totals['trialling'] ) ) {
245
-            $subscription->set_trial_period( $totals['trialling'] );
246
-            $subscription->set_status( 'trialling' );
244
+        if (!empty($totals['trialling'])) {
245
+            $subscription->set_trial_period($totals['trialling']);
246
+            $subscription->set_status('trialling');
247 247
 
248 248
         // If initial amount is free, treat it as a free trial even if the subscription item does not have a free trial.
249
-        } else if ( empty( $totals['initial_total'] ) ) {
250
-            $subscription->set_trial_period( $totals['interval'] . ' ' . $totals['period'] );
251
-            $subscription->set_status( 'trialling' );
249
+        } else if (empty($totals['initial_total'])) {
250
+            $subscription->set_trial_period($totals['interval'] . ' ' . $totals['period']);
251
+            $subscription->set_status('trialling');
252 252
         }
253 253
 
254 254
         $subscription->save();
@@ -265,87 +265,87 @@  discard block
 block discarded – undo
265 265
      * @param       WPInv_Invoice $invoice
266 266
      * @since       1.0.19
267 267
      */
268
-    public function maybe_update_invoice_subscription( $invoice ) {
268
+    public function maybe_update_invoice_subscription($invoice) {
269 269
         global $getpaid_subscriptions_skip_invoice_update;
270 270
 
271 271
         // Avoid infinite loops.
272
-        if ( ! empty( $getpaid_subscriptions_skip_invoice_update ) ) {
272
+        if (!empty($getpaid_subscriptions_skip_invoice_update)) {
273 273
             return;
274 274
         }
275 275
 
276 276
         // Do not process renewals.
277
-        if ( $invoice->is_renewal() ) {
277
+        if ($invoice->is_renewal()) {
278 278
             return;
279 279
         }
280 280
 
281 281
         // Delete existing subscriptions if available and the invoice is not recurring.
282
-        if ( ! $invoice->is_recurring() ) {
283
-            $this->delete_invoice_subscriptions( $invoice );
282
+        if (!$invoice->is_recurring()) {
283
+            $this->delete_invoice_subscriptions($invoice);
284 284
             return;
285 285
         }
286 286
 
287 287
         // Fetch existing subscriptions.
288
-        $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
288
+        $subscriptions = getpaid_get_invoice_subscriptions($invoice);
289 289
 
290 290
         // Create new ones if no existing subscriptions.
291
-        if ( empty( $subscriptions ) ) {
292
-            return $this->maybe_create_invoice_subscription( $invoice );
291
+        if (empty($subscriptions)) {
292
+            return $this->maybe_create_invoice_subscription($invoice);
293 293
         }
294 294
 
295 295
         // Abort if an invoice is paid and already has a subscription.
296
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
296
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
297 297
             return;
298 298
         }
299 299
 
300
-        $is_grouped   = is_array( $subscriptions );
301
-        $should_group = getpaid_should_group_subscriptions( $invoice );
300
+        $is_grouped   = is_array($subscriptions);
301
+        $should_group = getpaid_should_group_subscriptions($invoice);
302 302
 
303 303
         // Ensure that the subscriptions are only grouped if there are more than 1 recurring items.
304
-        if ( $is_grouped != $should_group ) {
305
-            $this->delete_invoice_subscriptions( $invoice );
306
-            delete_post_meta( $invoice->get_id(), 'getpaid_subscription_groups' );
307
-            return $this->maybe_create_invoice_subscription( $invoice );
304
+        if ($is_grouped != $should_group) {
305
+            $this->delete_invoice_subscriptions($invoice);
306
+            delete_post_meta($invoice->get_id(), 'getpaid_subscription_groups');
307
+            return $this->maybe_create_invoice_subscription($invoice);
308 308
         }
309 309
 
310 310
         // If there is only one recurring item...
311
-        if ( ! $is_grouped ) {
312
-            return $this->update_invoice_subscription( $subscriptions, $invoice );
311
+        if (!$is_grouped) {
312
+            return $this->update_invoice_subscription($subscriptions, $invoice);
313 313
         }
314 314
 
315 315
         // Process subscription groups.
316
-        $current_groups      = getpaid_get_invoice_subscription_groups( $invoice->get_id() );
316
+        $current_groups      = getpaid_get_invoice_subscription_groups($invoice->get_id());
317 317
         $subscription_groups = array();
318 318
         $is_first            = true;
319 319
 
320 320
         // Create new subscription groups.
321
-        foreach ( getpaid_calculate_subscription_totals( $invoice ) as $group_key => $totals ) {
322
-            $subscription_id                   = isset( $current_groups[ $group_key ] ) ? $current_groups[ $group_key ]['subscription_id'] : 0;
323
-            $subscription_groups[ $group_key ] = $this->create_invoice_subscription_group( $totals, $invoice, $subscription_id, $is_first );
321
+        foreach (getpaid_calculate_subscription_totals($invoice) as $group_key => $totals) {
322
+            $subscription_id                   = isset($current_groups[$group_key]) ? $current_groups[$group_key]['subscription_id'] : 0;
323
+            $subscription_groups[$group_key] = $this->create_invoice_subscription_group($totals, $invoice, $subscription_id, $is_first);
324 324
 
325
-            if ( $is_first && $invoice->get_subscription_id() !== $subscription_groups[ $group_key ]['subscription_id'] ) {
325
+            if ($is_first && $invoice->get_subscription_id() !== $subscription_groups[$group_key]['subscription_id']) {
326 326
                 $getpaid_subscriptions_skip_invoice_update = true;
327
-                $invoice->set_subscription_id( $subscription_groups[ $group_key ]['subscription_id'] );
327
+                $invoice->set_subscription_id($subscription_groups[$group_key]['subscription_id']);
328 328
                 $invoice->save();
329 329
                 $getpaid_subscriptions_skip_invoice_update = false;
330 330
             }
331 331
 
332
-            $is_first                          = false;
332
+            $is_first = false;
333 333
         }
334 334
 
335 335
         // Delete non-existent subscription groups.
336
-        foreach ( $current_groups as $group_key => $data ) {
337
-            if ( ! isset( $subscription_groups[ $group_key ] ) ) {
338
-                $subscription = new WPInv_Subscription( (int) $data['subscription_id'] );
336
+        foreach ($current_groups as $group_key => $data) {
337
+            if (!isset($subscription_groups[$group_key])) {
338
+                $subscription = new WPInv_Subscription((int) $data['subscription_id']);
339 339
 
340
-                if ( $subscription->exists() ) {
341
-                    $subscription->delete( true );
340
+                if ($subscription->exists()) {
341
+                    $subscription->delete(true);
342 342
                 }
343 343
 
344 344
             }
345 345
         }
346 346
 
347 347
         // Cache subscription groups.
348
-        update_post_meta( $invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups );
348
+        update_post_meta($invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups);
349 349
         return true;
350 350
 
351 351
     }
@@ -355,20 +355,20 @@  discard block
 block discarded – undo
355 355
      *
356 356
      * @param WPInv_Invoice $invoice
357 357
      */
358
-    public function delete_invoice_subscriptions( $invoice ) {
358
+    public function delete_invoice_subscriptions($invoice) {
359 359
 
360
-        $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
360
+        $subscriptions = getpaid_get_invoice_subscriptions($invoice);
361 361
 
362
-        if ( empty( $subscriptions ) ) {
362
+        if (empty($subscriptions)) {
363 363
             return;
364 364
         }
365 365
 
366
-        if ( ! is_array( $subscriptions ) ) {
367
-            $subscriptions = array( $subscriptions );
366
+        if (!is_array($subscriptions)) {
367
+            $subscriptions = array($subscriptions);
368 368
         }
369 369
 
370
-        foreach ( $subscriptions as $subscription ) {
371
-            $subscription->delete( true );
370
+        foreach ($subscriptions as $subscription) {
371
+            $subscription->delete(true);
372 372
         }
373 373
 
374 374
     }
@@ -381,57 +381,57 @@  discard block
 block discarded – undo
381 381
      * @param       WPInv_Invoice $invoice
382 382
      * @since       1.0.19
383 383
      */
384
-    public function update_invoice_subscription( $subscription, $invoice ) {
384
+    public function update_invoice_subscription($subscription, $invoice) {
385 385
 
386 386
         // Delete the subscription if an invoice is free or nolonger recurring.
387
-        if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_free() || ! $invoice->is_recurring() ) {
387
+        if (!$invoice->is_type('invoice') || $invoice->is_free() || !$invoice->is_recurring()) {
388 388
             return $subscription->delete();
389 389
         }
390 390
 
391
-        $subscription->set_customer_id( $invoice->get_customer_id() );
392
-        $subscription->set_parent_invoice_id( $invoice->get_id() );
393
-        $subscription->set_initial_amount( $invoice->get_initial_total() );
394
-        $subscription->set_recurring_amount( $invoice->get_recurring_total() );
395
-        $subscription->set_date_created( current_time( 'mysql' ) );
396
-        $subscription->set_status( $invoice->is_paid() ? 'active' : 'pending' );
391
+        $subscription->set_customer_id($invoice->get_customer_id());
392
+        $subscription->set_parent_invoice_id($invoice->get_id());
393
+        $subscription->set_initial_amount($invoice->get_initial_total());
394
+        $subscription->set_recurring_amount($invoice->get_recurring_total());
395
+        $subscription->set_date_created(current_time('mysql'));
396
+        $subscription->set_status($invoice->is_paid() ? 'active' : 'pending');
397 397
 
398 398
         // Get the recurring item and abort if it does not exist.
399
-        $subscription_item = $invoice->get_recurring( true );
400
-        if ( ! $subscription_item->get_id() ) {
399
+        $subscription_item = $invoice->get_recurring(true);
400
+        if (!$subscription_item->get_id()) {
401 401
             $invoice->set_subscription_id(0);
402 402
             $invoice->save();
403 403
             return $subscription->delete();
404 404
         }
405 405
 
406
-        $subscription->set_product_id( $subscription_item->get_id() );
407
-        $subscription->set_period( $subscription_item->get_recurring_period( true ) );
408
-        $subscription->set_frequency( $subscription_item->get_recurring_interval() );
409
-        $subscription->set_bill_times( $subscription_item->get_recurring_limit() );
406
+        $subscription->set_product_id($subscription_item->get_id());
407
+        $subscription->set_period($subscription_item->get_recurring_period(true));
408
+        $subscription->set_frequency($subscription_item->get_recurring_interval());
409
+        $subscription->set_bill_times($subscription_item->get_recurring_limit());
410 410
 
411 411
         // Calculate the next renewal date.
412
-        $period       = $subscription_item->get_recurring_period( true );
412
+        $period       = $subscription_item->get_recurring_period(true);
413 413
         $interval     = $subscription_item->get_recurring_interval();
414 414
 
415 415
         // If the subscription item has a trial period...
416
-        if ( $subscription_item->has_free_trial() ) {
417
-            $period   = $subscription_item->get_trial_period( true );
416
+        if ($subscription_item->has_free_trial()) {
417
+            $period   = $subscription_item->get_trial_period(true);
418 418
             $interval = $subscription_item->get_trial_interval();
419
-            $subscription->set_trial_period( $interval . ' ' . $period );
420
-            $subscription->set_status( 'trialling' );
419
+            $subscription->set_trial_period($interval . ' ' . $period);
420
+            $subscription->set_status('trialling');
421 421
         }
422 422
 
423 423
         // If initial amount is free, treat it as a free trial even if the subscription item does not have a free trial.
424
-        if ( $invoice->has_free_trial() ) {
425
-            $subscription->set_trial_period( $interval . ' ' . $period );
426
-            $subscription->set_status( 'trialling' );
424
+        if ($invoice->has_free_trial()) {
425
+            $subscription->set_trial_period($interval . ' ' . $period);
426
+            $subscription->set_status('trialling');
427 427
         }
428 428
 
429 429
         // Calculate the next renewal date.
430
-        $expiration = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", strtotime( $subscription->get_date_created() ) ) );
430
+        $expiration = date('Y-m-d H:i:s', strtotime("+$interval $period", strtotime($subscription->get_date_created())));
431 431
 
432
-        $subscription->set_next_renewal_date( $expiration );
432
+        $subscription->set_next_renewal_date($expiration);
433 433
         $subscription->save();
434
-        $invoice->set_subscription_id( $subscription->get_id() );
434
+        $invoice->set_subscription_id($subscription->get_id());
435 435
         return $subscription->get_id();
436 436
 
437 437
     }
@@ -442,27 +442,27 @@  discard block
 block discarded – undo
442 442
      * @param       array $data
443 443
      * @since       1.0.19
444 444
      */
445
-    public function admin_update_single_subscription( $args ) {
445
+    public function admin_update_single_subscription($args) {
446 446
 
447 447
         // Ensure the subscription exists and that a status has been given.
448
-        if ( empty( $args['subscription_id'] ) ) {
448
+        if (empty($args['subscription_id'])) {
449 449
             return;
450 450
         }
451 451
 
452 452
         // Retrieve the subscriptions.
453
-        $subscription = new WPInv_Subscription( $args['subscription_id'] );
453
+        $subscription = new WPInv_Subscription($args['subscription_id']);
454 454
 
455
-        if ( $subscription->get_id() ) {
455
+        if ($subscription->get_id()) {
456 456
 
457 457
             $subscription->set_props(
458 458
                 array(
459
-                    'status'     => isset( $args['subscription_status'] ) ? $args['subscription_status'] : null,
460
-                    'profile_id' => isset( $args['wpinv_subscription_profile_id'] ) ? $args['wpinv_subscription_profile_id'] : null,
459
+                    'status'     => isset($args['subscription_status']) ? $args['subscription_status'] : null,
460
+                    'profile_id' => isset($args['wpinv_subscription_profile_id']) ? $args['wpinv_subscription_profile_id'] : null,
461 461
                 )
462 462
             );
463 463
 
464 464
             $subscription->save();
465
-            getpaid_admin()->show_info( __( 'Subscription updated', 'invoicing' ) );
465
+            getpaid_admin()->show_info(__('Subscription updated', 'invoicing'));
466 466
 
467 467
         }
468 468
 
@@ -474,27 +474,27 @@  discard block
 block discarded – undo
474 474
      * @param       array $data
475 475
      * @since       1.0.19
476 476
      */
477
-    public function admin_renew_single_subscription( $args ) {
477
+    public function admin_renew_single_subscription($args) {
478 478
 
479 479
         // Ensure the subscription exists and that a status has been given.
480
-        if ( empty( $args['id'] ) ) {
480
+        if (empty($args['id'])) {
481 481
             return;
482 482
         }
483 483
 
484 484
         // Retrieve the subscriptions.
485
-        $subscription = new WPInv_Subscription( $args['id'] );
485
+        $subscription = new WPInv_Subscription($args['id']);
486 486
 
487
-        if ( $subscription->get_id() ) {
487
+        if ($subscription->get_id()) {
488 488
 
489
-            do_action( 'getpaid_admin_renew_subscription', $subscription );
489
+            do_action('getpaid_admin_renew_subscription', $subscription);
490 490
 
491
-            $args = array( 'transaction_id', $subscription->get_parent_invoice()->generate_key( 'renewal_' ) );
491
+            $args = array('transaction_id', $subscription->get_parent_invoice()->generate_key('renewal_'));
492 492
 
493
-            if ( ! $subscription->add_payment( $args ) ) {
494
-                getpaid_admin()->show_error( __( 'We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing' ) );
493
+            if (!$subscription->add_payment($args)) {
494
+                getpaid_admin()->show_error(__('We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing'));
495 495
             } else {
496 496
                 $subscription->renew();
497
-                getpaid_admin()->show_info( __( 'This subscription has been renewed and extended.', 'invoicing' ) );
497
+                getpaid_admin()->show_info(__('This subscription has been renewed and extended.', 'invoicing'));
498 498
             } 
499 499
 
500 500
             wp_safe_redirect(
@@ -517,20 +517,20 @@  discard block
 block discarded – undo
517 517
      * @param       array $data
518 518
      * @since       1.0.19
519 519
      */
520
-    public function admin_delete_single_subscription( $args ) {
520
+    public function admin_delete_single_subscription($args) {
521 521
 
522 522
         // Ensure the subscription exists and that a status has been given.
523
-        if ( empty( $args['id'] ) ) {
523
+        if (empty($args['id'])) {
524 524
             return;
525 525
         }
526 526
 
527 527
         // Retrieve the subscriptions.
528
-        $subscription = new WPInv_Subscription( $args['id'] );
528
+        $subscription = new WPInv_Subscription($args['id']);
529 529
 
530
-        if ( $subscription->delete() ) {
531
-            getpaid_admin()->show_info( __( 'This subscription has been deleted.', 'invoicing' ) );
530
+        if ($subscription->delete()) {
531
+            getpaid_admin()->show_info(__('This subscription has been deleted.', 'invoicing'));
532 532
         } else {
533
-            getpaid_admin()->show_error( __( 'We are unable to delete this subscription. Please try again.', 'invoicing' ) );
533
+            getpaid_admin()->show_error(__('We are unable to delete this subscription. Please try again.', 'invoicing'));
534 534
         }
535 535
     
536 536
         $redirected = wp_safe_redirect(
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
             )
544 544
         );
545 545
 
546
-        if ( $redirected ) {
546
+        if ($redirected) {
547 547
             exit;
548 548
         }
549 549
 
@@ -556,10 +556,10 @@  discard block
 block discarded – undo
556 556
      * @param WPInv_Item $item
557 557
      * @param WPInv_Invoice $invoice
558 558
      */
559
-    public function filter_invoice_line_item_actions( $actions, $item, $invoice ) {
559
+    public function filter_invoice_line_item_actions($actions, $item, $invoice) {
560 560
 
561 561
         // Fetch item subscription.
562
-        $args  = array(
562
+        $args = array(
563 563
             'invoice_in'  => $invoice->is_parent() ? $invoice->get_id() : $invoice->get_parent_id(),
564 564
             'product_in'  => $item->get_id(),
565 565
             'number'      => 1,
@@ -567,13 +567,13 @@  discard block
 block discarded – undo
567 567
             'fields'      => 'id',
568 568
         );
569 569
 
570
-        $subscription = new GetPaid_Subscriptions_Query( $args );
570
+        $subscription = new GetPaid_Subscriptions_Query($args);
571 571
         $subscription = $subscription->get_results();
572 572
 
573 573
         // In case we found a match...
574
-        if ( ! empty( $subscription ) ) {
575
-            $url                     = esc_url( add_query_arg( 'subscription', (int) $subscription[0], get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) );
576
-            $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>';
574
+        if (!empty($subscription)) {
575
+            $url                     = esc_url(add_query_arg('subscription', (int) $subscription[0], get_permalink((int) wpinv_get_option('invoice_subscription_page'))));
576
+            $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __('Manage Subscription', 'invoicing') . '</a>';
577 577
         }
578 578
 
579 579
         return $actions;
Please login to merge, or discard this patch.
includes/admin/class-wpinv-subscriptions-list-table.php 2 patches
Indentation   +402 added lines, -402 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 if ( ! defined( 'ABSPATH' ) ) exit;
7 7
 
8 8
 if ( ! class_exists( 'WP_List_Table' ) ) {
9
-	include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
9
+    include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
10 10
 }
11 11
 
12 12
 /**
@@ -14,406 +14,406 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class WPInv_Subscriptions_List_Table extends WP_List_Table {
16 16
 
17
-	/**
18
-	 * URL of this page
19
-	 *
20
-	 * @var   string
21
-	 * @since 1.0.19
22
-	 */
23
-	public $base_url;
24
-
25
-	/**
26
-	 * Query
27
-	 *
28
-	 * @var   GetPaid_Subscriptions_Query
29
-	 * @since 1.0.19
30
-	 */
31
-	public $query;
32
-
33
-	/**
34
-	 * Total subscriptions
35
-	 *
36
-	 * @var   string
37
-	 * @since 1.0.0
38
-	 */
39
-	public $total_count;
40
-
41
-	/**
42
-	 * Current status subscriptions
43
-	 *
44
-	 * @var   string
45
-	 * @since 1.0.0
46
-	 */
47
-	public $current_total_count;
48
-
49
-	/**
50
-	 * Status counts
51
-	 *
52
-	 * @var   array
53
-	 * @since 1.0.19
54
-	 */
55
-	public $status_counts;
56
-
57
-	/**
58
-	 * Number of results to show per page
59
-	 *
60
-	 * @var   int
61
-	 * @since 1.0.0
62
-	 */
63
-	public $per_page = 10;
64
-
65
-	/**
66
-	 *  Constructor function.
67
-	 */
68
-	public function __construct() {
69
-
70
-		parent::__construct(
71
-			array(
72
-				'singular' => 'subscription',
73
-				'plural'   => 'subscriptions',
74
-			)
75
-		);
76
-
77
-		$this->process_bulk_action();
78
-
79
-		$this->prepare_query();
80
-
81
-		$this->base_url = remove_query_arg( 'status' );
82
-
83
-	}
84
-
85
-	/**
86
-	 *  Prepares the display query
87
-	 */
88
-	public function prepare_query() {
89
-
90
-		// Prepare query args.
91
-		$query = array(
92
-			'number'  => $this->per_page,
93
-			'paged'   => $this->get_paged(),
94
-			'status'  => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all',
95
-			'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id',
96
-			'order'   => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC',
97
-		);
98
-
99
-		// Prepare class properties.
100
-		$this->query               = new GetPaid_Subscriptions_Query( $query );
101
-		$this->total_count         = $this->query->get_total();
102
-		$this->current_total_count = $this->query->get_total();
103
-		$this->items               = $this->query->get_results();
104
-		$this->status_counts       = getpaid_get_subscription_status_counts( $query );
105
-
106
-		if ( 'all' != $query['status'] ) {
107
-			unset( $query['status'] );
108
-			$this->total_count   = getpaid_get_subscriptions( $query, 'count' );
109
-		}
110
-
111
-	}
112
-
113
-	/**
114
-	 * Gets the list of views available on this table.
115
-	 *
116
-	 * The format is an associative array:
117
-	 * - `'id' => 'link'`
118
-	 *
119
-	 * @since 1.0.0
120
-	 *
121
-	 * @return array
122
-	 */
123
-	public function get_views() {
124
-
125
-		$current  = isset( $_GET['status'] ) ? $_GET['status'] : 'all';
126
-		$views    = array(
127
-
128
-			'all' => sprintf(
129
-				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
130
-				esc_url( add_query_arg( 'status', false, $this->base_url ) ),
131
-				$current === 'all' ? ' class="current"' : '',
132
-				__('All','invoicing' ),
133
-				$this->total_count
134
-			)
135
-
136
-		);
137
-
138
-		foreach ( array_filter( $this->status_counts ) as $status => $count ) {
139
-
140
-			$views[ $status ] = sprintf(
141
-				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
142
-				esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ),
143
-				$current === $status ? ' class="current"' : '',
144
-				sanitize_text_field( getpaid_get_subscription_status_label( $status ) ),
145
-				$count
146
-			);
147
-
148
-		}
149
-
150
-		return $views;
151
-
152
-	}
153
-
154
-	/**
155
-	 * Render most columns
156
-	 *
157
-	 * @access      private
158
-	 * @since       1.0.0
159
-	 * @return      string
160
-	 */
161
-	public function column_default( $item, $column_name ) {
162
-		return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name );
163
-	}
164
-
165
-	/**
166
-	 * This is how checkbox column renders.
167
-	 *
168
-	 * @param WPInv_Subscription $item
169
-	 * @return string
170
-	 */
171
-	public function column_cb( $item ) {
172
-		return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) );
173
-	}
174
-
175
-	/**
176
-	 * Status column
177
-	 *
178
-	 * @param WPInv_Subscription $item
179
-	 * @since       1.0.0
180
-	 * @return      string
181
-	 */
182
-	public function column_status( $item ) {
183
-		return $item->get_status_label_html();
184
-	}
185
-
186
-	/**
187
-	 * Subscription column
188
-	 *
189
-	 * @param WPInv_Subscription $item
190
-	 * @since       1.0.0
191
-	 * @return      string
192
-	 */
193
-	public function column_subscription( $item ) {
194
-
195
-		$username = __( '(Missing User)', 'invoicing' );
196
-
197
-		$user = get_userdata( $item->get_customer_id() );
198
-		if ( $user ) {
199
-
200
-			$username = sprintf(
201
-				'<a href="user-edit.php?user_id=%s">%s</a>',
202
-				absint( $user->ID ),
203
-				! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
204
-			);
205
-
206
-		}
207
-
208
-		// translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name
209
-		$column_content = sprintf(
210
-			_x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ),
211
-			'<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">',
212
-			'<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>',
213
-			$username
214
-		);
215
-
216
-		$row_actions = array();
217
-
218
-		// View subscription.
219
-		$view_url    = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ));
220
-		$row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>';
221
-
222
-		// View invoice.
223
-		$invoice = get_post( $item->get_parent_invoice_id() );
224
-
225
-		if ( ! empty( $invoice ) ) {
226
-			$invoice_url            = get_edit_post_link( $invoice );
227
-			$row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>';
228
-		}
229
-
230
-		$delete_url            = esc_url(
231
-			wp_nonce_url(
232
-				add_query_arg(
233
-					array(
234
-						'getpaid-admin-action' => 'subscription_manual_delete',
235
-						'id'                   => $item->get_id(),
236
-					)
237
-				),
238
-				'getpaid-nonce',
239
-				'getpaid-nonce'
240
-			)
241
-		);
242
-		$row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>';
243
-
244
-		$row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) );
245
-
246
-		return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions;
247
-	}
248
-
249
-	/**
250
-	 * Renewal date column
251
-	 *
252
-	 * @param WPInv_Subscription $item
253
-	 * @since       1.0.0
254
-	 * @return      string
255
-	 */
256
-	public function column_renewal_date( $item ) {
257
-		return getpaid_format_date_value( $item->get_expiration() );
258
-	}
259
-
260
-	/**
261
-	 * Start date column
262
-	 *
263
-	 * @param WPInv_Subscription $item
264
-	 * @since       1.0.0
265
-	 * @return      string
266
-	 */
267
-	public function column_start_date( $item ) {
268
-		return getpaid_format_date_value( $item->get_date_created() );
269
-	}
270
-
271
-	/**
272
-	 * Amount column
273
-	 *
274
-	 * @param WPInv_Subscription $item
275
-	 * @since       1.0.19
276
-	 * @return      string
277
-	 */
278
-	public function column_amount( $item ) {
279
-		$amount = getpaid_get_formatted_subscription_amount( $item );
280
-		return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>";
281
-	}
282
-
283
-	/**
284
-	 * Billing Times column
285
-	 *
286
-	 * @param WPInv_Subscription $item
287
-	 * @since       1.0.0
288
-	 * @return      string
289
-	 */
290
-	public function column_renewals( $item ) {
291
-		$max_bills = $item->get_bill_times();
292
-		return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
293
-	}
294
-
295
-	/**
296
-	 * Product ID column
297
-	 *
298
-	 * @param WPInv_Subscription $item
299
-	 * @since       1.0.0
300
-	 * @return      string
301
-	 */
302
-	public function column_item( $item ) {
303
-		$subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() );
304
-
305
-		if ( empty( $subscription_group ) ) {
306
-			return $this->generate_item_markup( $item->get_product_id() );
307
-		}
308
-
309
-		$markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
310
-		return implode( ' | ', $markup );
311
-
312
-	}
313
-
314
-	/**
315
-	 * Generates the items markup.
316
-	 *
317
-	 * @param int $item_id
318
-	 * @since       1.0.0
319
-	 * @return      string
320
-	 */
321
-	public function generate_item_markup( $item_id ) {
322
-		$item = get_post( $item_id );
323
-
324
-		if ( ! empty( $item ) ) {
325
-			$link = get_edit_post_link( $item );
326
-			$link = esc_url( $link );
327
-			$name = esc_html( get_the_title( $item ) );
328
-			return "<a href='$link'>$name</a>";
329
-		} else {
330
-			return sprintf( __( 'Item #%s', 'invoicing' ), $item_id );
331
-		}
332
-
333
-	}
334
-
335
-	/**
336
-	 * Retrieve the current page number
337
-	 *
338
-	 * @return      int
339
-	 */
340
-	public function get_paged() {
341
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
342
-	}
343
-
344
-	/**
345
-	 * Setup the final data for the table
346
-	 *
347
-	 */
348
-	public function prepare_items() {
349
-
350
-		$columns  = $this->get_columns();
351
-		$hidden   = array();
352
-		$sortable = $this->get_sortable_columns();
353
-
354
-		$this->_column_headers = array( $columns, $hidden, $sortable );
355
-
356
-		$this->set_pagination_args(
357
-			array(
358
-			'total_items' => $this->current_total_count,
359
-			'per_page'    => $this->per_page,
360
-			'total_pages' => ceil( $this->current_total_count / $this->per_page )
361
-			)
362
-		);
363
-	}
364
-
365
-	/**
366
-	 * Table columns
367
-	 *
368
-	 * @return array
369
-	 */
370
-	public function get_columns(){
371
-		$columns = array(
372
-			'cb'                => '<input type="checkbox" />',
373
-			'subscription'      => __( 'Subscription', 'invoicing' ),
374
-			'start_date'        => __( 'Start Date', 'invoicing' ),
375
-			'renewal_date'      => __( 'Next Payment', 'invoicing' ),
376
-			'renewals'          => __( 'Payments', 'invoicing' ),
377
-			'item'              => __( 'Items', 'invoicing' ),
378
-			'status'            => __( 'Status', 'invoicing' ),
379
-		);
380
-
381
-		return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns );
382
-	}
383
-
384
-	/**
385
-	 * Sortable table columns.
386
-	 *
387
-	 * @return array
388
-	 */
389
-	public function get_sortable_columns() {
390
-		$sortable = array(
391
-			'subscription' => array( 'id', true ),
392
-			'start_date'   => array( 'created', true ),
393
-			'renewal_date' => array( 'expiration', true ),
394
-			'renewals'     => array( 'bill_times', true ),
395
-			'item'         => array( 'product_id', true ),
396
-			'status'       => array( 'status', true ),
397
-		);
398
-
399
-		return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable );
400
-	}
401
-
402
-	/**
403
-	 * Whether the table has items to display or not
404
-	 *
405
-	 * @return bool
406
-	 */
407
-	public function has_items() {
408
-		return ! empty( $this->current_total_count );
409
-	}
410
-
411
-	/**
412
-	 * Processes bulk actions.
413
-	 *
414
-	 */
415
-	public function process_bulk_action() {
416
-
417
-	}
17
+    /**
18
+     * URL of this page
19
+     *
20
+     * @var   string
21
+     * @since 1.0.19
22
+     */
23
+    public $base_url;
24
+
25
+    /**
26
+     * Query
27
+     *
28
+     * @var   GetPaid_Subscriptions_Query
29
+     * @since 1.0.19
30
+     */
31
+    public $query;
32
+
33
+    /**
34
+     * Total subscriptions
35
+     *
36
+     * @var   string
37
+     * @since 1.0.0
38
+     */
39
+    public $total_count;
40
+
41
+    /**
42
+     * Current status subscriptions
43
+     *
44
+     * @var   string
45
+     * @since 1.0.0
46
+     */
47
+    public $current_total_count;
48
+
49
+    /**
50
+     * Status counts
51
+     *
52
+     * @var   array
53
+     * @since 1.0.19
54
+     */
55
+    public $status_counts;
56
+
57
+    /**
58
+     * Number of results to show per page
59
+     *
60
+     * @var   int
61
+     * @since 1.0.0
62
+     */
63
+    public $per_page = 10;
64
+
65
+    /**
66
+     *  Constructor function.
67
+     */
68
+    public function __construct() {
69
+
70
+        parent::__construct(
71
+            array(
72
+                'singular' => 'subscription',
73
+                'plural'   => 'subscriptions',
74
+            )
75
+        );
76
+
77
+        $this->process_bulk_action();
78
+
79
+        $this->prepare_query();
80
+
81
+        $this->base_url = remove_query_arg( 'status' );
82
+
83
+    }
84
+
85
+    /**
86
+     *  Prepares the display query
87
+     */
88
+    public function prepare_query() {
89
+
90
+        // Prepare query args.
91
+        $query = array(
92
+            'number'  => $this->per_page,
93
+            'paged'   => $this->get_paged(),
94
+            'status'  => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all',
95
+            'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id',
96
+            'order'   => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC',
97
+        );
98
+
99
+        // Prepare class properties.
100
+        $this->query               = new GetPaid_Subscriptions_Query( $query );
101
+        $this->total_count         = $this->query->get_total();
102
+        $this->current_total_count = $this->query->get_total();
103
+        $this->items               = $this->query->get_results();
104
+        $this->status_counts       = getpaid_get_subscription_status_counts( $query );
105
+
106
+        if ( 'all' != $query['status'] ) {
107
+            unset( $query['status'] );
108
+            $this->total_count   = getpaid_get_subscriptions( $query, 'count' );
109
+        }
110
+
111
+    }
112
+
113
+    /**
114
+     * Gets the list of views available on this table.
115
+     *
116
+     * The format is an associative array:
117
+     * - `'id' => 'link'`
118
+     *
119
+     * @since 1.0.0
120
+     *
121
+     * @return array
122
+     */
123
+    public function get_views() {
124
+
125
+        $current  = isset( $_GET['status'] ) ? $_GET['status'] : 'all';
126
+        $views    = array(
127
+
128
+            'all' => sprintf(
129
+                '<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
130
+                esc_url( add_query_arg( 'status', false, $this->base_url ) ),
131
+                $current === 'all' ? ' class="current"' : '',
132
+                __('All','invoicing' ),
133
+                $this->total_count
134
+            )
135
+
136
+        );
137
+
138
+        foreach ( array_filter( $this->status_counts ) as $status => $count ) {
139
+
140
+            $views[ $status ] = sprintf(
141
+                '<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
142
+                esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ),
143
+                $current === $status ? ' class="current"' : '',
144
+                sanitize_text_field( getpaid_get_subscription_status_label( $status ) ),
145
+                $count
146
+            );
147
+
148
+        }
149
+
150
+        return $views;
151
+
152
+    }
153
+
154
+    /**
155
+     * Render most columns
156
+     *
157
+     * @access      private
158
+     * @since       1.0.0
159
+     * @return      string
160
+     */
161
+    public function column_default( $item, $column_name ) {
162
+        return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name );
163
+    }
164
+
165
+    /**
166
+     * This is how checkbox column renders.
167
+     *
168
+     * @param WPInv_Subscription $item
169
+     * @return string
170
+     */
171
+    public function column_cb( $item ) {
172
+        return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) );
173
+    }
174
+
175
+    /**
176
+     * Status column
177
+     *
178
+     * @param WPInv_Subscription $item
179
+     * @since       1.0.0
180
+     * @return      string
181
+     */
182
+    public function column_status( $item ) {
183
+        return $item->get_status_label_html();
184
+    }
185
+
186
+    /**
187
+     * Subscription column
188
+     *
189
+     * @param WPInv_Subscription $item
190
+     * @since       1.0.0
191
+     * @return      string
192
+     */
193
+    public function column_subscription( $item ) {
194
+
195
+        $username = __( '(Missing User)', 'invoicing' );
196
+
197
+        $user = get_userdata( $item->get_customer_id() );
198
+        if ( $user ) {
199
+
200
+            $username = sprintf(
201
+                '<a href="user-edit.php?user_id=%s">%s</a>',
202
+                absint( $user->ID ),
203
+                ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
204
+            );
205
+
206
+        }
207
+
208
+        // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name
209
+        $column_content = sprintf(
210
+            _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ),
211
+            '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">',
212
+            '<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>',
213
+            $username
214
+        );
215
+
216
+        $row_actions = array();
217
+
218
+        // View subscription.
219
+        $view_url    = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ));
220
+        $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>';
221
+
222
+        // View invoice.
223
+        $invoice = get_post( $item->get_parent_invoice_id() );
224
+
225
+        if ( ! empty( $invoice ) ) {
226
+            $invoice_url            = get_edit_post_link( $invoice );
227
+            $row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>';
228
+        }
229
+
230
+        $delete_url            = esc_url(
231
+            wp_nonce_url(
232
+                add_query_arg(
233
+                    array(
234
+                        'getpaid-admin-action' => 'subscription_manual_delete',
235
+                        'id'                   => $item->get_id(),
236
+                    )
237
+                ),
238
+                'getpaid-nonce',
239
+                'getpaid-nonce'
240
+            )
241
+        );
242
+        $row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>';
243
+
244
+        $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) );
245
+
246
+        return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions;
247
+    }
248
+
249
+    /**
250
+     * Renewal date column
251
+     *
252
+     * @param WPInv_Subscription $item
253
+     * @since       1.0.0
254
+     * @return      string
255
+     */
256
+    public function column_renewal_date( $item ) {
257
+        return getpaid_format_date_value( $item->get_expiration() );
258
+    }
259
+
260
+    /**
261
+     * Start date column
262
+     *
263
+     * @param WPInv_Subscription $item
264
+     * @since       1.0.0
265
+     * @return      string
266
+     */
267
+    public function column_start_date( $item ) {
268
+        return getpaid_format_date_value( $item->get_date_created() );
269
+    }
270
+
271
+    /**
272
+     * Amount column
273
+     *
274
+     * @param WPInv_Subscription $item
275
+     * @since       1.0.19
276
+     * @return      string
277
+     */
278
+    public function column_amount( $item ) {
279
+        $amount = getpaid_get_formatted_subscription_amount( $item );
280
+        return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>";
281
+    }
282
+
283
+    /**
284
+     * Billing Times column
285
+     *
286
+     * @param WPInv_Subscription $item
287
+     * @since       1.0.0
288
+     * @return      string
289
+     */
290
+    public function column_renewals( $item ) {
291
+        $max_bills = $item->get_bill_times();
292
+        return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
293
+    }
294
+
295
+    /**
296
+     * Product ID column
297
+     *
298
+     * @param WPInv_Subscription $item
299
+     * @since       1.0.0
300
+     * @return      string
301
+     */
302
+    public function column_item( $item ) {
303
+        $subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() );
304
+
305
+        if ( empty( $subscription_group ) ) {
306
+            return $this->generate_item_markup( $item->get_product_id() );
307
+        }
308
+
309
+        $markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
310
+        return implode( ' | ', $markup );
311
+
312
+    }
313
+
314
+    /**
315
+     * Generates the items markup.
316
+     *
317
+     * @param int $item_id
318
+     * @since       1.0.0
319
+     * @return      string
320
+     */
321
+    public function generate_item_markup( $item_id ) {
322
+        $item = get_post( $item_id );
323
+
324
+        if ( ! empty( $item ) ) {
325
+            $link = get_edit_post_link( $item );
326
+            $link = esc_url( $link );
327
+            $name = esc_html( get_the_title( $item ) );
328
+            return "<a href='$link'>$name</a>";
329
+        } else {
330
+            return sprintf( __( 'Item #%s', 'invoicing' ), $item_id );
331
+        }
332
+
333
+    }
334
+
335
+    /**
336
+     * Retrieve the current page number
337
+     *
338
+     * @return      int
339
+     */
340
+    public function get_paged() {
341
+        return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
342
+    }
343
+
344
+    /**
345
+     * Setup the final data for the table
346
+     *
347
+     */
348
+    public function prepare_items() {
349
+
350
+        $columns  = $this->get_columns();
351
+        $hidden   = array();
352
+        $sortable = $this->get_sortable_columns();
353
+
354
+        $this->_column_headers = array( $columns, $hidden, $sortable );
355
+
356
+        $this->set_pagination_args(
357
+            array(
358
+            'total_items' => $this->current_total_count,
359
+            'per_page'    => $this->per_page,
360
+            'total_pages' => ceil( $this->current_total_count / $this->per_page )
361
+            )
362
+        );
363
+    }
364
+
365
+    /**
366
+     * Table columns
367
+     *
368
+     * @return array
369
+     */
370
+    public function get_columns(){
371
+        $columns = array(
372
+            'cb'                => '<input type="checkbox" />',
373
+            'subscription'      => __( 'Subscription', 'invoicing' ),
374
+            'start_date'        => __( 'Start Date', 'invoicing' ),
375
+            'renewal_date'      => __( 'Next Payment', 'invoicing' ),
376
+            'renewals'          => __( 'Payments', 'invoicing' ),
377
+            'item'              => __( 'Items', 'invoicing' ),
378
+            'status'            => __( 'Status', 'invoicing' ),
379
+        );
380
+
381
+        return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns );
382
+    }
383
+
384
+    /**
385
+     * Sortable table columns.
386
+     *
387
+     * @return array
388
+     */
389
+    public function get_sortable_columns() {
390
+        $sortable = array(
391
+            'subscription' => array( 'id', true ),
392
+            'start_date'   => array( 'created', true ),
393
+            'renewal_date' => array( 'expiration', true ),
394
+            'renewals'     => array( 'bill_times', true ),
395
+            'item'         => array( 'product_id', true ),
396
+            'status'       => array( 'status', true ),
397
+        );
398
+
399
+        return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable );
400
+    }
401
+
402
+    /**
403
+     * Whether the table has items to display or not
404
+     *
405
+     * @return bool
406
+     */
407
+    public function has_items() {
408
+        return ! empty( $this->current_total_count );
409
+    }
410
+
411
+    /**
412
+     * Processes bulk actions.
413
+     *
414
+     */
415
+    public function process_bulk_action() {
416
+
417
+    }
418 418
 
419 419
 }
Please login to merge, or discard this patch.
Spacing   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -3,9 +3,9 @@  discard block
 block discarded – undo
3 3
  * Displays a list of all subscriptions rules
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) exit;
6
+if (!defined('ABSPATH')) exit;
7 7
 
8
-if ( ! class_exists( 'WP_List_Table' ) ) {
8
+if (!class_exists('WP_List_Table')) {
9 9
 	include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
10 10
 }
11 11
 
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 
79 79
 		$this->prepare_query();
80 80
 
81
-		$this->base_url = remove_query_arg( 'status' );
81
+		$this->base_url = remove_query_arg('status');
82 82
 
83 83
 	}
84 84
 
@@ -91,21 +91,21 @@  discard block
 block discarded – undo
91 91
 		$query = array(
92 92
 			'number'  => $this->per_page,
93 93
 			'paged'   => $this->get_paged(),
94
-			'status'  => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all',
95
-			'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id',
96
-			'order'   => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC',
94
+			'status'  => (isset($_GET['status']) && array_key_exists($_GET['status'], getpaid_get_subscription_statuses())) ? $_GET['status'] : 'all',
95
+			'orderby' => (isset($_GET['orderby'])) ? $_GET['orderby'] : 'id',
96
+			'order'   => (isset($_GET['order'])) ? $_GET['order'] : 'DESC',
97 97
 		);
98 98
 
99 99
 		// Prepare class properties.
100
-		$this->query               = new GetPaid_Subscriptions_Query( $query );
100
+		$this->query               = new GetPaid_Subscriptions_Query($query);
101 101
 		$this->total_count         = $this->query->get_total();
102 102
 		$this->current_total_count = $this->query->get_total();
103 103
 		$this->items               = $this->query->get_results();
104
-		$this->status_counts       = getpaid_get_subscription_status_counts( $query );
104
+		$this->status_counts       = getpaid_get_subscription_status_counts($query);
105 105
 
106
-		if ( 'all' != $query['status'] ) {
107
-			unset( $query['status'] );
108
-			$this->total_count   = getpaid_get_subscriptions( $query, 'count' );
106
+		if ('all' != $query['status']) {
107
+			unset($query['status']);
108
+			$this->total_count = getpaid_get_subscriptions($query, 'count');
109 109
 		}
110 110
 
111 111
 	}
@@ -122,26 +122,26 @@  discard block
 block discarded – undo
122 122
 	 */
123 123
 	public function get_views() {
124 124
 
125
-		$current  = isset( $_GET['status'] ) ? $_GET['status'] : 'all';
125
+		$current  = isset($_GET['status']) ? $_GET['status'] : 'all';
126 126
 		$views    = array(
127 127
 
128 128
 			'all' => sprintf(
129 129
 				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
130
-				esc_url( add_query_arg( 'status', false, $this->base_url ) ),
130
+				esc_url(add_query_arg('status', false, $this->base_url)),
131 131
 				$current === 'all' ? ' class="current"' : '',
132
-				__('All','invoicing' ),
132
+				__('All', 'invoicing'),
133 133
 				$this->total_count
134 134
 			)
135 135
 
136 136
 		);
137 137
 
138
-		foreach ( array_filter( $this->status_counts ) as $status => $count ) {
138
+		foreach (array_filter($this->status_counts) as $status => $count) {
139 139
 
140
-			$views[ $status ] = sprintf(
140
+			$views[$status] = sprintf(
141 141
 				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
142
-				esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ),
142
+				esc_url(add_query_arg('status', urlencode($status), $this->base_url)),
143 143
 				$current === $status ? ' class="current"' : '',
144
-				sanitize_text_field( getpaid_get_subscription_status_label( $status ) ),
144
+				sanitize_text_field(getpaid_get_subscription_status_label($status)),
145 145
 				$count
146 146
 			);
147 147
 
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
 	 * @since       1.0.0
159 159
 	 * @return      string
160 160
 	 */
161
-	public function column_default( $item, $column_name ) {
162
-		return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name );
161
+	public function column_default($item, $column_name) {
162
+		return apply_filters("getpaid_subscriptions_table_column_$column_name", $item->$column_name);
163 163
 	}
164 164
 
165 165
 	/**
@@ -168,8 +168,8 @@  discard block
 block discarded – undo
168 168
 	 * @param WPInv_Subscription $item
169 169
 	 * @return string
170 170
 	 */
171
-	public function column_cb( $item ) {
172
-		return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) );
171
+	public function column_cb($item) {
172
+		return sprintf('<input type="checkbox" name="id[]" value="%s" />', esc_html($item->get_id()));
173 173
 	}
174 174
 
175 175
 	/**
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	 * @since       1.0.0
180 180
 	 * @return      string
181 181
 	 */
182
-	public function column_status( $item ) {
182
+	public function column_status($item) {
183 183
 		return $item->get_status_label_html();
184 184
 	}
185 185
 
@@ -190,44 +190,44 @@  discard block
 block discarded – undo
190 190
 	 * @since       1.0.0
191 191
 	 * @return      string
192 192
 	 */
193
-	public function column_subscription( $item ) {
193
+	public function column_subscription($item) {
194 194
 
195
-		$username = __( '(Missing User)', 'invoicing' );
195
+		$username = __('(Missing User)', 'invoicing');
196 196
 
197
-		$user = get_userdata( $item->get_customer_id() );
198
-		if ( $user ) {
197
+		$user = get_userdata($item->get_customer_id());
198
+		if ($user) {
199 199
 
200 200
 			$username = sprintf(
201 201
 				'<a href="user-edit.php?user_id=%s">%s</a>',
202
-				absint( $user->ID ),
203
-				! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
202
+				absint($user->ID),
203
+				!empty($user->display_name) ? sanitize_text_field($user->display_name) : sanitize_email($user->user_email)
204 204
 			);
205 205
 
206 206
 		}
207 207
 
208 208
 		// translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name
209 209
 		$column_content = sprintf(
210
-			_x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ),
211
-			'<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">',
212
-			'<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>',
210
+			_x('%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing'),
211
+			'<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . absint($item->get_id()))) . '">',
212
+			'<strong>' . esc_attr($item->get_id()) . '</strong>', '</a>',
213 213
 			$username
214 214
 		);
215 215
 
216 216
 		$row_actions = array();
217 217
 
218 218
 		// View subscription.
219
-		$view_url    = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ));
220
-		$row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>';
219
+		$view_url    = esc_url(add_query_arg('id', $item->get_id(), admin_url('admin.php?page=wpinv-subscriptions')));
220
+		$row_actions['view'] = '<a href="' . $view_url . '">' . __('View Subscription', 'invoicing') . '</a>';
221 221
 
222 222
 		// View invoice.
223
-		$invoice = get_post( $item->get_parent_invoice_id() );
223
+		$invoice = get_post($item->get_parent_invoice_id());
224 224
 
225
-		if ( ! empty( $invoice ) ) {
226
-			$invoice_url            = get_edit_post_link( $invoice );
227
-			$row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>';
225
+		if (!empty($invoice)) {
226
+			$invoice_url            = get_edit_post_link($invoice);
227
+			$row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __('View Invoice', 'invoicing') . '</a>';
228 228
 		}
229 229
 
230
-		$delete_url            = esc_url(
230
+		$delete_url = esc_url(
231 231
 			wp_nonce_url(
232 232
 				add_query_arg(
233 233
 					array(
@@ -239,11 +239,11 @@  discard block
 block discarded – undo
239 239
 				'getpaid-nonce'
240 240
 			)
241 241
 		);
242
-		$row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>';
242
+		$row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __('Delete Subscription', 'invoicing') . '</a>';
243 243
 
244
-		$row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) );
244
+		$row_actions = $this->row_actions(apply_filters('getpaid_subscription_table_row_actions', $row_actions, $item));
245 245
 
246
-		return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions;
246
+		return "<strong>$column_content</strong>" . $this->column_amount($item) . $row_actions;
247 247
 	}
248 248
 
249 249
 	/**
@@ -253,8 +253,8 @@  discard block
 block discarded – undo
253 253
 	 * @since       1.0.0
254 254
 	 * @return      string
255 255
 	 */
256
-	public function column_renewal_date( $item ) {
257
-		return getpaid_format_date_value( $item->get_expiration() );
256
+	public function column_renewal_date($item) {
257
+		return getpaid_format_date_value($item->get_expiration());
258 258
 	}
259 259
 
260 260
 	/**
@@ -264,8 +264,8 @@  discard block
 block discarded – undo
264 264
 	 * @since       1.0.0
265 265
 	 * @return      string
266 266
 	 */
267
-	public function column_start_date( $item ) {
268
-		return getpaid_format_date_value( $item->get_date_created() );
267
+	public function column_start_date($item) {
268
+		return getpaid_format_date_value($item->get_date_created());
269 269
 	}
270 270
 
271 271
 	/**
@@ -275,8 +275,8 @@  discard block
 block discarded – undo
275 275
 	 * @since       1.0.19
276 276
 	 * @return      string
277 277
 	 */
278
-	public function column_amount( $item ) {
279
-		$amount = getpaid_get_formatted_subscription_amount( $item );
278
+	public function column_amount($item) {
279
+		$amount = getpaid_get_formatted_subscription_amount($item);
280 280
 		return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>";
281 281
 	}
282 282
 
@@ -287,9 +287,9 @@  discard block
 block discarded – undo
287 287
 	 * @since       1.0.0
288 288
 	 * @return      string
289 289
 	 */
290
-	public function column_renewals( $item ) {
290
+	public function column_renewals($item) {
291 291
 		$max_bills = $item->get_bill_times();
292
-		return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
292
+		return $item->get_times_billed() . ' / ' . (empty($max_bills) ? "&infin;" : $max_bills);
293 293
 	}
294 294
 
295 295
 	/**
@@ -299,15 +299,15 @@  discard block
 block discarded – undo
299 299
 	 * @since       1.0.0
300 300
 	 * @return      string
301 301
 	 */
302
-	public function column_item( $item ) {
303
-		$subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() );
302
+	public function column_item($item) {
303
+		$subscription_group = getpaid_get_invoice_subscription_group($item->get_parent_invoice_id(), $item->get_id());
304 304
 
305
-		if ( empty( $subscription_group ) ) {
306
-			return $this->generate_item_markup( $item->get_product_id() );
305
+		if (empty($subscription_group)) {
306
+			return $this->generate_item_markup($item->get_product_id());
307 307
 		}
308 308
 
309
-		$markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
310
-		return implode( ' | ', $markup );
309
+		$markup = array_map(array($this, 'generate_item_markup'), array_keys($subscription_group['items']));
310
+		return implode(' | ', $markup);
311 311
 
312 312
 	}
313 313
 
@@ -318,16 +318,16 @@  discard block
 block discarded – undo
318 318
 	 * @since       1.0.0
319 319
 	 * @return      string
320 320
 	 */
321
-	public function generate_item_markup( $item_id ) {
322
-		$item = get_post( $item_id );
321
+	public function generate_item_markup($item_id) {
322
+		$item = get_post($item_id);
323 323
 
324
-		if ( ! empty( $item ) ) {
325
-			$link = get_edit_post_link( $item );
326
-			$link = esc_url( $link );
327
-			$name = esc_html( get_the_title( $item ) );
324
+		if (!empty($item)) {
325
+			$link = get_edit_post_link($item);
326
+			$link = esc_url($link);
327
+			$name = esc_html(get_the_title($item));
328 328
 			return "<a href='$link'>$name</a>";
329 329
 		} else {
330
-			return sprintf( __( 'Item #%s', 'invoicing' ), $item_id );
330
+			return sprintf(__('Item #%s', 'invoicing'), $item_id);
331 331
 		}
332 332
 
333 333
 	}
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 	 * @return      int
339 339
 	 */
340 340
 	public function get_paged() {
341
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
341
+		return isset($_GET['paged']) ? absint($_GET['paged']) : 1;
342 342
 	}
343 343
 
344 344
 	/**
@@ -351,13 +351,13 @@  discard block
 block discarded – undo
351 351
 		$hidden   = array();
352 352
 		$sortable = $this->get_sortable_columns();
353 353
 
354
-		$this->_column_headers = array( $columns, $hidden, $sortable );
354
+		$this->_column_headers = array($columns, $hidden, $sortable);
355 355
 
356 356
 		$this->set_pagination_args(
357 357
 			array(
358 358
 			'total_items' => $this->current_total_count,
359 359
 			'per_page'    => $this->per_page,
360
-			'total_pages' => ceil( $this->current_total_count / $this->per_page )
360
+			'total_pages' => ceil($this->current_total_count / $this->per_page)
361 361
 			)
362 362
 		);
363 363
 	}
@@ -367,18 +367,18 @@  discard block
 block discarded – undo
367 367
 	 *
368 368
 	 * @return array
369 369
 	 */
370
-	public function get_columns(){
370
+	public function get_columns() {
371 371
 		$columns = array(
372 372
 			'cb'                => '<input type="checkbox" />',
373
-			'subscription'      => __( 'Subscription', 'invoicing' ),
374
-			'start_date'        => __( 'Start Date', 'invoicing' ),
375
-			'renewal_date'      => __( 'Next Payment', 'invoicing' ),
376
-			'renewals'          => __( 'Payments', 'invoicing' ),
377
-			'item'              => __( 'Items', 'invoicing' ),
378
-			'status'            => __( 'Status', 'invoicing' ),
373
+			'subscription'      => __('Subscription', 'invoicing'),
374
+			'start_date'        => __('Start Date', 'invoicing'),
375
+			'renewal_date'      => __('Next Payment', 'invoicing'),
376
+			'renewals'          => __('Payments', 'invoicing'),
377
+			'item'              => __('Items', 'invoicing'),
378
+			'status'            => __('Status', 'invoicing'),
379 379
 		);
380 380
 
381
-		return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns );
381
+		return apply_filters('manage_getpaid_subscriptions_table_columns', $columns);
382 382
 	}
383 383
 
384 384
 	/**
@@ -388,15 +388,15 @@  discard block
 block discarded – undo
388 388
 	 */
389 389
 	public function get_sortable_columns() {
390 390
 		$sortable = array(
391
-			'subscription' => array( 'id', true ),
392
-			'start_date'   => array( 'created', true ),
393
-			'renewal_date' => array( 'expiration', true ),
394
-			'renewals'     => array( 'bill_times', true ),
395
-			'item'         => array( 'product_id', true ),
396
-			'status'       => array( 'status', true ),
391
+			'subscription' => array('id', true),
392
+			'start_date'   => array('created', true),
393
+			'renewal_date' => array('expiration', true),
394
+			'renewals'     => array('bill_times', true),
395
+			'item'         => array('product_id', true),
396
+			'status'       => array('status', true),
397 397
 		);
398 398
 
399
-		return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable );
399
+		return apply_filters('manage_getpaid_subscriptions_sortable_table_columns', $sortable);
400 400
 	}
401 401
 
402 402
 	/**
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
 	 * @return bool
406 406
 	 */
407 407
 	public function has_items() {
408
-		return ! empty( $this->current_total_count );
408
+		return !empty($this->current_total_count);
409 409
 	}
410 410
 
411 411
 	/**
Please login to merge, or discard this patch.
includes/admin/class-getpaid-metaboxes.php 2 patches
Indentation   +231 added lines, -231 removed lines patch added patch discarded remove patch
@@ -12,267 +12,267 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Metaboxes {
14 14
 
15
-	/**
16
-	 * Only save metaboxes once.
17
-	 *
18
-	 * @var boolean
19
-	 */
20
-	private static $saved_meta_boxes = false;
21
-
22 15
     /**
23
-	 * Hook in methods.
24
-	 */
25
-	public static function init() {
26
-
27
-		// Register metaboxes.
28
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
29
-
30
-		// Remove metaboxes.
31
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
32
-
33
-		// Rename metaboxes.
34
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
35
-
36
-		// Save metaboxes.
37
-		add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
-	}
16
+     * Only save metaboxes once.
17
+     *
18
+     * @var boolean
19
+     */
20
+    private static $saved_meta_boxes = false;
39 21
 
40
-	/**
41
-	 * Register core metaboxes.
42
-	 */
43
-	public static function add_meta_boxes( $post_type, $post ) {
44
-
45
-		// For invoices...
46
-		self::add_invoice_meta_boxes( $post_type, $post );
22
+    /**
23
+     * Hook in methods.
24
+     */
25
+    public static function init() {
47 26
 
48
-		// For payment forms.
49
-		self::add_payment_form_meta_boxes( $post_type );
27
+        // Register metaboxes.
28
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
50 29
 
51
-		// For invoice items.
52
-		self::add_item_meta_boxes( $post_type );
30
+        // Remove metaboxes.
31
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
53 32
 
54
-		// For invoice discounts.
55
-		if ( $post_type == 'wpi_discount' ) {
56
-			add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
57
-		}
33
+        // Rename metaboxes.
34
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
58 35
 
59
-	}
36
+        // Save metaboxes.
37
+        add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
+    }
60 39
 
61
-	/**
62
-	 * Register core metaboxes.
63
-	 */
64
-	protected static function add_payment_form_meta_boxes( $post_type ) {
40
+    /**
41
+     * Register core metaboxes.
42
+     */
43
+    public static function add_meta_boxes( $post_type, $post ) {
65 44
 
66
-		// For payment forms.
67
-		if ( $post_type == 'wpi_payment_form' ) {
45
+        // For invoices...
46
+        self::add_invoice_meta_boxes( $post_type, $post );
68 47
 
69
-			// Design payment form.
70
-			add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
48
+        // For payment forms.
49
+        self::add_payment_form_meta_boxes( $post_type );
71 50
 
72
-			// Payment form information.
73
-			add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
51
+        // For invoice items.
52
+        self::add_item_meta_boxes( $post_type );
74 53
 
75
-		}
54
+        // For invoice discounts.
55
+        if ( $post_type == 'wpi_discount' ) {
56
+            add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
57
+        }
76 58
 
77
-	}
59
+    }
78 60
 
79
-	/**
80
-	 * Register core metaboxes.
81
-	 */
82
-	protected static function add_item_meta_boxes( $post_type ) {
61
+    /**
62
+     * Register core metaboxes.
63
+     */
64
+    protected static function add_payment_form_meta_boxes( $post_type ) {
83 65
 
84
-		if ( $post_type == 'wpi_item' ) {
66
+        // For payment forms.
67
+        if ( $post_type == 'wpi_payment_form' ) {
85 68
 
86
-			// Item details.
87
-			add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
69
+            // Design payment form.
70
+            add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
88 71
 
89
-			// If taxes are enabled, register the tax metabox.
90
-			if ( wpinv_use_taxes() ) {
91
-				add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
92
-			}
72
+            // Payment form information.
73
+            add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
93 74
 
94
-			// Item info.
95
-			add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
75
+        }
96 76
 
97
-		}
77
+    }
98 78
 
99
-	}
79
+    /**
80
+     * Register core metaboxes.
81
+     */
82
+    protected static function add_item_meta_boxes( $post_type ) {
100 83
 
101
-	/**
102
-	 * Register invoice metaboxes.
103
-	 */
104
-	protected static function add_invoice_meta_boxes( $post_type, $post ) {
84
+        if ( $post_type == 'wpi_item' ) {
105 85
 
106
-		// For invoices...
107
-		if ( getpaid_is_invoice_post_type( $post_type ) ) {
108
-			$invoice = new WPInv_Invoice( $post );
86
+            // Item details.
87
+            add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
109 88
 
110
-			// Resend invoice.
111
-			if ( ! $invoice->is_draft() ) {
89
+            // If taxes are enabled, register the tax metabox.
90
+            if ( wpinv_use_taxes() ) {
91
+                add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
92
+            }
112 93
 
113
-				add_meta_box(
114
-					'wpinv-mb-resend-invoice',
115
-					sprintf(
116
-						__( 'Resend %s', 'invoicing' ),
117
-						ucfirst( $invoice->get_invoice_quote_type() )
118
-					),
119
-					'GetPaid_Meta_Box_Resend_Invoice::output',
120
-					$post_type,
121
-					'side',
122
-					'low'
123
-				);
94
+            // Item info.
95
+            add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
124 96
 
125
-			}
97
+        }
126 98
 
127
-			// Subscriptions.
128
-			$subscription = getpaid_get_invoice_subscription( $invoice );
129
-			if ( ! empty( $subscription ) && $subscription->exists() ) {
130
-				add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
131
-				add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
132
-			}
133
-
134
-			// Invoice details.
135
-			add_meta_box(
136
-				'wpinv-details',
137
-				sprintf(
138
-					__( '%s Details', 'invoicing' ),
139
-					ucfirst( $invoice->get_invoice_quote_type() )
140
-				),
141
-				'GetPaid_Meta_Box_Invoice_Details::output',
142
-				$post_type,
143
-				'side'
144
-			);
145
-
146
-			// Payment details.
147
-			if ( ! $invoice->is_draft() ) {
148
-				add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
149
-			}
99
+    }
150 100
 
151
-			// Billing details.
152
-			add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
101
+    /**
102
+     * Register invoice metaboxes.
103
+     */
104
+    protected static function add_invoice_meta_boxes( $post_type, $post ) {
105
+
106
+        // For invoices...
107
+        if ( getpaid_is_invoice_post_type( $post_type ) ) {
108
+            $invoice = new WPInv_Invoice( $post );
109
+
110
+            // Resend invoice.
111
+            if ( ! $invoice->is_draft() ) {
112
+
113
+                add_meta_box(
114
+                    'wpinv-mb-resend-invoice',
115
+                    sprintf(
116
+                        __( 'Resend %s', 'invoicing' ),
117
+                        ucfirst( $invoice->get_invoice_quote_type() )
118
+                    ),
119
+                    'GetPaid_Meta_Box_Resend_Invoice::output',
120
+                    $post_type,
121
+                    'side',
122
+                    'low'
123
+                );
124
+
125
+            }
126
+
127
+            // Subscriptions.
128
+            $subscription = getpaid_get_invoice_subscription( $invoice );
129
+            if ( ! empty( $subscription ) && $subscription->exists() ) {
130
+                add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
131
+                add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
132
+            }
133
+
134
+            // Invoice details.
135
+            add_meta_box(
136
+                'wpinv-details',
137
+                sprintf(
138
+                    __( '%s Details', 'invoicing' ),
139
+                    ucfirst( $invoice->get_invoice_quote_type() )
140
+                ),
141
+                'GetPaid_Meta_Box_Invoice_Details::output',
142
+                $post_type,
143
+                'side'
144
+            );
145
+
146
+            // Payment details.
147
+            if ( ! $invoice->is_draft() ) {
148
+                add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
149
+            }
150
+
151
+            // Billing details.
152
+            add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
153 153
 			
154
-			// Invoice items.
155
-			add_meta_box(
156
-				'wpinv-items',
157
-				sprintf(
158
-					__( '%s Items', 'invoicing' ),
159
-					ucfirst( $invoice->get_invoice_quote_type() )
160
-				),
161
-				'GetPaid_Meta_Box_Invoice_Items::output',
162
-				$post_type,
163
-				'normal',
164
-				'high'
165
-			);
154
+            // Invoice items.
155
+            add_meta_box(
156
+                'wpinv-items',
157
+                sprintf(
158
+                    __( '%s Items', 'invoicing' ),
159
+                    ucfirst( $invoice->get_invoice_quote_type() )
160
+                ),
161
+                'GetPaid_Meta_Box_Invoice_Items::output',
162
+                $post_type,
163
+                'normal',
164
+                'high'
165
+            );
166 166
 			
167
-			// Invoice notes.
168
-			add_meta_box(
169
-				'wpinv-notes',
170
-				sprintf(
171
-					__( '%s Notes', 'invoicing' ),
172
-					ucfirst( $invoice->get_invoice_quote_type() )
173
-				),
174
-				'WPInv_Meta_Box_Notes::output',
175
-				$post_type,
176
-				'side',
177
-				'low'
178
-			);
179
-
180
-			// Shipping Address.
181
-			if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) {
182
-				add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
183
-			}
184
-
185
-			// Payment form information.
186
-			if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) {
187
-				add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
188
-			}
189
-
190
-		}
191
-
192
-	}
193
-
194
-	/**
195
-	 * Remove some metaboxes.
196
-	 */
197
-	public static function remove_meta_boxes() {
198
-		remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
199
-	}
200
-
201
-	/**
202
-	 * Rename other metaboxes.
203
-	 */
204
-	public static function rename_meta_boxes() {
167
+            // Invoice notes.
168
+            add_meta_box(
169
+                'wpinv-notes',
170
+                sprintf(
171
+                    __( '%s Notes', 'invoicing' ),
172
+                    ucfirst( $invoice->get_invoice_quote_type() )
173
+                ),
174
+                'WPInv_Meta_Box_Notes::output',
175
+                $post_type,
176
+                'side',
177
+                'low'
178
+            );
179
+
180
+            // Shipping Address.
181
+            if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) {
182
+                add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
183
+            }
184
+
185
+            // Payment form information.
186
+            if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) {
187
+                add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
188
+            }
189
+
190
+        }
191
+
192
+    }
193
+
194
+    /**
195
+     * Remove some metaboxes.
196
+     */
197
+    public static function remove_meta_boxes() {
198
+        remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
199
+    }
200
+
201
+    /**
202
+     * Rename other metaboxes.
203
+     */
204
+    public static function rename_meta_boxes() {
205 205
 		
206
-	}
207
-
208
-	/**
209
-	 * Check if we're saving, then trigger an action based on the post type.
210
-	 *
211
-	 * @param  int    $post_id Post ID.
212
-	 * @param  object $post Post object.
213
-	 */
214
-	public static function save_meta_boxes( $post_id, $post ) {
215
-		$post_id = absint( $post_id );
216
-		$data    = wp_unslash( $_POST );
217
-
218
-		// Do not save for ajax requests.
219
-		if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
220
-			return;
221
-		}
222
-
223
-		// $post_id and $post are required
224
-		if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
225
-			return;
226
-		}
227
-
228
-		// Dont' save meta boxes for revisions or autosaves.
229
-		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
230
-			return;
231
-		}
232
-
233
-		// Check the nonce.
234
-		if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
235
-			return;
236
-		}
237
-
238
-		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
239
-		if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
240
-			return;
241
-		}
242
-
243
-		// Check user has permission to edit.
244
-		if ( ! current_user_can( 'edit_post', $post_id ) ) {
245
-			return;
246
-		}
247
-
248
-		if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
249
-
250
-			// We need this save event to run once to avoid potential endless loops.
251
-			self::$saved_meta_boxes = true;
252
-
253
-			return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
254
-
255
-		}
256
-
257
-		// Ensure this is our post type.
258
-		$post_types_map = array(
259
-			'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
260
-			'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
261
-			'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
262
-		);
263
-
264
-		// Is this our post type?
265
-		if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
266
-			return;
267
-		}
268
-
269
-		// We need this save event to run once to avoid potential endless loops.
270
-		self::$saved_meta_boxes = true;
206
+    }
207
+
208
+    /**
209
+     * Check if we're saving, then trigger an action based on the post type.
210
+     *
211
+     * @param  int    $post_id Post ID.
212
+     * @param  object $post Post object.
213
+     */
214
+    public static function save_meta_boxes( $post_id, $post ) {
215
+        $post_id = absint( $post_id );
216
+        $data    = wp_unslash( $_POST );
217
+
218
+        // Do not save for ajax requests.
219
+        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
220
+            return;
221
+        }
222
+
223
+        // $post_id and $post are required
224
+        if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
225
+            return;
226
+        }
227
+
228
+        // Dont' save meta boxes for revisions or autosaves.
229
+        if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
230
+            return;
231
+        }
232
+
233
+        // Check the nonce.
234
+        if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
235
+            return;
236
+        }
237
+
238
+        // Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
239
+        if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
240
+            return;
241
+        }
242
+
243
+        // Check user has permission to edit.
244
+        if ( ! current_user_can( 'edit_post', $post_id ) ) {
245
+            return;
246
+        }
247
+
248
+        if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
249
+
250
+            // We need this save event to run once to avoid potential endless loops.
251
+            self::$saved_meta_boxes = true;
252
+
253
+            return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
254
+
255
+        }
256
+
257
+        // Ensure this is our post type.
258
+        $post_types_map = array(
259
+            'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
260
+            'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
261
+            'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
262
+        );
263
+
264
+        // Is this our post type?
265
+        if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
266
+            return;
267
+        }
268
+
269
+        // We need this save event to run once to avoid potential endless loops.
270
+        self::$saved_meta_boxes = true;
271 271
 		
272
-		// Save the post.
273
-		$class = $post_types_map[ $post->post_type ];
274
-		$class::save( $post_id, $_POST, $post );
272
+        // Save the post.
273
+        $class = $post_types_map[ $post->post_type ];
274
+        $class::save( $post_id, $_POST, $post );
275 275
 
276
-	}
276
+    }
277 277
 
278 278
 }
Please login to merge, or discard this patch.
Spacing   +59 added lines, -59 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
  * Metaboxes Admin Class
@@ -25,35 +25,35 @@  discard block
 block discarded – undo
25 25
 	public static function init() {
26 26
 
27 27
 		// Register metaboxes.
28
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
28
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2);
29 29
 
30 30
 		// Remove metaboxes.
31
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
31
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30);
32 32
 
33 33
 		// Rename metaboxes.
34
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
34
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45);
35 35
 
36 36
 		// Save metaboxes.
37
-		add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
37
+		add_action('save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2);
38 38
 	}
39 39
 
40 40
 	/**
41 41
 	 * Register core metaboxes.
42 42
 	 */
43
-	public static function add_meta_boxes( $post_type, $post ) {
43
+	public static function add_meta_boxes($post_type, $post) {
44 44
 
45 45
 		// For invoices...
46
-		self::add_invoice_meta_boxes( $post_type, $post );
46
+		self::add_invoice_meta_boxes($post_type, $post);
47 47
 
48 48
 		// For payment forms.
49
-		self::add_payment_form_meta_boxes( $post_type );
49
+		self::add_payment_form_meta_boxes($post_type);
50 50
 
51 51
 		// For invoice items.
52
-		self::add_item_meta_boxes( $post_type );
52
+		self::add_item_meta_boxes($post_type);
53 53
 
54 54
 		// For invoice discounts.
55
-		if ( $post_type == 'wpi_discount' ) {
56
-			add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
55
+		if ($post_type == 'wpi_discount') {
56
+			add_meta_box('wpinv_discount_details', __('Discount Details', 'invoicing'), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high');
57 57
 		}
58 58
 
59 59
 	}
@@ -61,16 +61,16 @@  discard block
 block discarded – undo
61 61
 	/**
62 62
 	 * Register core metaboxes.
63 63
 	 */
64
-	protected static function add_payment_form_meta_boxes( $post_type ) {
64
+	protected static function add_payment_form_meta_boxes($post_type) {
65 65
 
66 66
 		// For payment forms.
67
-		if ( $post_type == 'wpi_payment_form' ) {
67
+		if ($post_type == 'wpi_payment_form') {
68 68
 
69 69
 			// Design payment form.
70
-			add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
70
+			add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal');
71 71
 
72 72
 			// Payment form information.
73
-			add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
73
+			add_meta_box('wpinv-payment-form-info', __('Details', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side');
74 74
 
75 75
 		}
76 76
 
@@ -79,20 +79,20 @@  discard block
 block discarded – undo
79 79
 	/**
80 80
 	 * Register core metaboxes.
81 81
 	 */
82
-	protected static function add_item_meta_boxes( $post_type ) {
82
+	protected static function add_item_meta_boxes($post_type) {
83 83
 
84
-		if ( $post_type == 'wpi_item' ) {
84
+		if ($post_type == 'wpi_item') {
85 85
 
86 86
 			// Item details.
87
-			add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
87
+			add_meta_box('wpinv_item_details', __('Item Details', 'invoicing'), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high');
88 88
 
89 89
 			// If taxes are enabled, register the tax metabox.
90
-			if ( wpinv_use_taxes() ) {
91
-				add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
90
+			if (wpinv_use_taxes()) {
91
+				add_meta_box('wpinv_item_vat', __('Tax', 'invoicing'), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high');
92 92
 			}
93 93
 
94 94
 			// Item info.
95
-			add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
95
+			add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core');
96 96
 
97 97
 		}
98 98
 
@@ -101,20 +101,20 @@  discard block
 block discarded – undo
101 101
 	/**
102 102
 	 * Register invoice metaboxes.
103 103
 	 */
104
-	protected static function add_invoice_meta_boxes( $post_type, $post ) {
104
+	protected static function add_invoice_meta_boxes($post_type, $post) {
105 105
 
106 106
 		// For invoices...
107
-		if ( getpaid_is_invoice_post_type( $post_type ) ) {
108
-			$invoice = new WPInv_Invoice( $post );
107
+		if (getpaid_is_invoice_post_type($post_type)) {
108
+			$invoice = new WPInv_Invoice($post);
109 109
 
110 110
 			// Resend invoice.
111
-			if ( ! $invoice->is_draft() ) {
111
+			if (!$invoice->is_draft()) {
112 112
 
113 113
 				add_meta_box(
114 114
 					'wpinv-mb-resend-invoice',
115 115
 					sprintf(
116
-						__( 'Resend %s', 'invoicing' ),
117
-						ucfirst( $invoice->get_invoice_quote_type() )
116
+						__('Resend %s', 'invoicing'),
117
+						ucfirst($invoice->get_invoice_quote_type())
118 118
 					),
119 119
 					'GetPaid_Meta_Box_Resend_Invoice::output',
120 120
 					$post_type,
@@ -125,18 +125,18 @@  discard block
 block discarded – undo
125 125
 			}
126 126
 
127 127
 			// Subscriptions.
128
-			$subscription = getpaid_get_invoice_subscription( $invoice );
129
-			if ( ! empty( $subscription ) && $subscription->exists() ) {
130
-				add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
131
-				add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
128
+			$subscription = getpaid_get_invoice_subscription($invoice);
129
+			if (!empty($subscription) && $subscription->exists()) {
130
+				add_meta_box('wpinv-mb-subscriptions', __('Subscription Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced');
131
+				add_meta_box('wpinv-mb-subscription-invoices', __('Related Payments', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced');
132 132
 			}
133 133
 
134 134
 			// Invoice details.
135 135
 			add_meta_box(
136 136
 				'wpinv-details',
137 137
 				sprintf(
138
-					__( '%s Details', 'invoicing' ),
139
-					ucfirst( $invoice->get_invoice_quote_type() )
138
+					__('%s Details', 'invoicing'),
139
+					ucfirst($invoice->get_invoice_quote_type())
140 140
 				),
141 141
 				'GetPaid_Meta_Box_Invoice_Details::output',
142 142
 				$post_type,
@@ -144,19 +144,19 @@  discard block
 block discarded – undo
144 144
 			);
145 145
 
146 146
 			// Payment details.
147
-			if ( ! $invoice->is_draft() ) {
148
-				add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
147
+			if (!$invoice->is_draft()) {
148
+				add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default');
149 149
 			}
150 150
 
151 151
 			// Billing details.
152
-			add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
152
+			add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high');
153 153
 			
154 154
 			// Invoice items.
155 155
 			add_meta_box(
156 156
 				'wpinv-items',
157 157
 				sprintf(
158
-					__( '%s Items', 'invoicing' ),
159
-					ucfirst( $invoice->get_invoice_quote_type() )
158
+					__('%s Items', 'invoicing'),
159
+					ucfirst($invoice->get_invoice_quote_type())
160 160
 				),
161 161
 				'GetPaid_Meta_Box_Invoice_Items::output',
162 162
 				$post_type,
@@ -168,8 +168,8 @@  discard block
 block discarded – undo
168 168
 			add_meta_box(
169 169
 				'wpinv-notes',
170 170
 				sprintf(
171
-					__( '%s Notes', 'invoicing' ),
172
-					ucfirst( $invoice->get_invoice_quote_type() )
171
+					__('%s Notes', 'invoicing'),
172
+					ucfirst($invoice->get_invoice_quote_type())
173 173
 				),
174 174
 				'WPInv_Meta_Box_Notes::output',
175 175
 				$post_type,
@@ -178,13 +178,13 @@  discard block
 block discarded – undo
178 178
 			);
179 179
 
180 180
 			// Shipping Address.
181
-			if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) {
182
-				add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
181
+			if (get_post_meta($invoice->get_id(), 'shipping_address', true)) {
182
+				add_meta_box('wpinv-invoice-shipping-details', __('Shipping Address', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high');
183 183
 			}
184 184
 
185 185
 			// Payment form information.
186
-			if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) {
187
-				add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
186
+			if (get_post_meta($invoice->get_id(), 'payment_form_data', true)) {
187
+				add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high');
188 188
 			}
189 189
 
190 190
 		}
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	 * Remove some metaboxes.
196 196
 	 */
197 197
 	public static function remove_meta_boxes() {
198
-		remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
198
+		remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal');
199 199
 	}
200 200
 
201 201
 	/**
@@ -211,46 +211,46 @@  discard block
 block discarded – undo
211 211
 	 * @param  int    $post_id Post ID.
212 212
 	 * @param  object $post Post object.
213 213
 	 */
214
-	public static function save_meta_boxes( $post_id, $post ) {
215
-		$post_id = absint( $post_id );
216
-		$data    = wp_unslash( $_POST );
214
+	public static function save_meta_boxes($post_id, $post) {
215
+		$post_id = absint($post_id);
216
+		$data    = wp_unslash($_POST);
217 217
 
218 218
 		// Do not save for ajax requests.
219
-		if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
219
+		if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
220 220
 			return;
221 221
 		}
222 222
 
223 223
 		// $post_id and $post are required
224
-		if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
224
+		if (empty($post_id) || empty($post) || self::$saved_meta_boxes) {
225 225
 			return;
226 226
 		}
227 227
 
228 228
 		// Dont' save meta boxes for revisions or autosaves.
229
-		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
229
+		if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
230 230
 			return;
231 231
 		}
232 232
 
233 233
 		// Check the nonce.
234
-		if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
234
+		if (empty($data['getpaid_meta_nonce']) || !wp_verify_nonce($data['getpaid_meta_nonce'], 'getpaid_meta_nonce')) {
235 235
 			return;
236 236
 		}
237 237
 
238 238
 		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
239
-		if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
239
+		if (empty($data['post_ID']) || absint($data['post_ID']) !== $post_id) {
240 240
 			return;
241 241
 		}
242 242
 
243 243
 		// Check user has permission to edit.
244
-		if ( ! current_user_can( 'edit_post', $post_id ) ) {
244
+		if (!current_user_can('edit_post', $post_id)) {
245 245
 			return;
246 246
 		}
247 247
 
248
-		if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
248
+		if (getpaid_is_invoice_post_type($post->post_type)) {
249 249
 
250 250
 			// We need this save event to run once to avoid potential endless loops.
251 251
 			self::$saved_meta_boxes = true;
252 252
 
253
-			return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
253
+			return GetPaid_Meta_Box_Invoice_Address::save($post_id);
254 254
 
255 255
 		}
256 256
 
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 		);
263 263
 
264 264
 		// Is this our post type?
265
-		if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
265
+		if (!isset($post_types_map[$post->post_type])) {
266 266
 			return;
267 267
 		}
268 268
 
@@ -270,8 +270,8 @@  discard block
 block discarded – undo
270 270
 		self::$saved_meta_boxes = true;
271 271
 		
272 272
 		// Save the post.
273
-		$class = $post_types_map[ $post->post_type ];
274
-		$class::save( $post_id, $_POST, $post );
273
+		$class = $post_types_map[$post->post_type];
274
+		$class::save($post_id, $_POST, $post);
275 275
 
276 276
 	}
277 277
 
Please login to merge, or discard this patch.