Passed
Push — master ( a15c21...706a80 )
by Stiofan
04:34
created
includes/subscription-functions.php 2 patches
Indentation   +307 added lines, -307 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
 
@@ -63,11 +63,11 @@  discard block
 block discarded – undo
63 63
  */
64 64
 function getpaid_get_subscription( $subscription ) {
65 65
 
66
-	if ( ! is_a( $subscription, 'WPInv_Subscription' ) ) {
67
-		$subscription = new WPInv_Subscription( $subscription );
68
-	}
66
+    if ( ! is_a( $subscription, 'WPInv_Subscription' ) ) {
67
+        $subscription = new WPInv_Subscription( $subscription );
68
+    }
69 69
 
70
-	return $subscription->exists() ? $subscription : false;
70
+    return $subscription->exists() ? $subscription : false;
71 71
 }
72 72
 
73 73
 /**
@@ -81,28 +81,28 @@  discard block
 block discarded – undo
81 81
  */
82 82
 function getpaid_get_subscriptions( $args = array(), $return = 'results' ) {
83 83
 
84
-	// Do not retrieve all fields if we just want the count.
85
-	if ( 'count' == $return ) {
86
-		$args['fields'] = 'id';
87
-		$args['number'] = 1;
88
-	}
84
+    // Do not retrieve all fields if we just want the count.
85
+    if ( 'count' == $return ) {
86
+        $args['fields'] = 'id';
87
+        $args['number'] = 1;
88
+    }
89 89
 
90
-	// Do not count all matches if we just want the results.
91
-	if ( 'results' == $return ) {
92
-		$args['count_total'] = false;
93
-	}
90
+    // Do not count all matches if we just want the results.
91
+    if ( 'results' == $return ) {
92
+        $args['count_total'] = false;
93
+    }
94 94
 
95
-	$query = new GetPaid_Subscriptions_Query( $args );
95
+    $query = new GetPaid_Subscriptions_Query( $args );
96 96
 
97
-	if ( 'results' == $return ) {
98
-		return $query->get_results();
99
-	}
97
+    if ( 'results' == $return ) {
98
+        return $query->get_results();
99
+    }
100 100
 
101
-	if ( 'count' == $return ) {
102
-		return $query->get_total();
103
-	}
101
+    if ( 'count' == $return ) {
102
+        return $query->get_total();
103
+    }
104 104
 
105
-	return $query;
105
+    return $query;
106 106
 }
107 107
 
108 108
 /**
@@ -112,18 +112,18 @@  discard block
 block discarded – undo
112 112
  */
113 113
 function getpaid_get_subscription_statuses() {
114 114
 
115
-	return apply_filters(
116
-		'getpaid_get_subscription_statuses',
117
-		array(
118
-			'pending'    => __( 'Pending', 'invoicing' ),
119
-			'trialling'  => __( 'Trialing', 'invoicing' ),
120
-			'active'     => __( 'Active', 'invoicing' ),
121
-			'failing'    => __( 'Failing', 'invoicing' ),
122
-			'expired'    => __( 'Expired', 'invoicing' ),
123
-			'completed'  => __( 'Complete', 'invoicing' ),
124
-			'cancelled'  => __( 'Cancelled', 'invoicing' ),
125
-		)
126
-	);
115
+    return apply_filters(
116
+        'getpaid_get_subscription_statuses',
117
+        array(
118
+            'pending'    => __( 'Pending', 'invoicing' ),
119
+            'trialling'  => __( 'Trialing', 'invoicing' ),
120
+            'active'     => __( 'Active', 'invoicing' ),
121
+            'failing'    => __( 'Failing', 'invoicing' ),
122
+            'expired'    => __( 'Expired', 'invoicing' ),
123
+            'completed'  => __( 'Complete', 'invoicing' ),
124
+            'cancelled'  => __( 'Cancelled', 'invoicing' ),
125
+        )
126
+    );
127 127
 
128 128
 }
129 129
 
@@ -133,8 +133,8 @@  discard block
 block discarded – undo
133 133
  * @return string
134 134
  */
135 135
 function getpaid_get_subscription_status_label( $status ) {
136
-	$statuses = getpaid_get_subscription_statuses();
137
-	return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
136
+    $statuses = getpaid_get_subscription_statuses();
137
+    return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
138 138
 }
139 139
 
140 140
 /**
@@ -144,18 +144,18 @@  discard block
 block discarded – undo
144 144
  */
145 145
 function getpaid_get_subscription_status_classes() {
146 146
 
147
-	return apply_filters(
148
-		'getpaid_get_subscription_status_classes',
149
-		array(
150
-			'pending'    => 'badge-dark',
151
-			'trialling'  => 'badge-info',
152
-			'active'     => 'badge-success',
153
-			'failing'    => 'badge-warning',
154
-			'expired'    => 'badge-danger',
155
-			'completed'  => 'badge-primary',
156
-			'cancelled'  => 'badge-secondary',
157
-		)
158
-	);
147
+    return apply_filters(
148
+        'getpaid_get_subscription_status_classes',
149
+        array(
150
+            'pending'    => 'badge-dark',
151
+            'trialling'  => 'badge-info',
152
+            'active'     => 'badge-success',
153
+            'failing'    => 'badge-warning',
154
+            'expired'    => 'badge-danger',
155
+            'completed'  => 'badge-primary',
156
+            'cancelled'  => 'badge-secondary',
157
+        )
158
+    );
159 159
 
160 160
 }
161 161
 
@@ -166,15 +166,15 @@  discard block
 block discarded – undo
166 166
  */
167 167
 function getpaid_get_subscription_status_counts( $args = array() ) {
168 168
 
169
-	$statuses = array_keys( getpaid_get_subscription_statuses() );
170
-	$counts   = array();
169
+    $statuses = array_keys( getpaid_get_subscription_statuses() );
170
+    $counts   = array();
171 171
 
172
-	foreach ( $statuses as $status ) {
173
-		$_args             = wp_parse_args( "status=$status", $args );
174
-		$counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
175
-	}
172
+    foreach ( $statuses as $status ) {
173
+        $_args             = wp_parse_args( "status=$status", $args );
174
+        $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
175
+    }
176 176
 
177
-	return $counts;
177
+    return $counts;
178 178
 
179 179
 }
180 180
 
@@ -185,32 +185,32 @@  discard block
 block discarded – undo
185 185
  */
186 186
 function getpaid_get_subscription_periods() {
187 187
 
188
-	return apply_filters(
189
-		'getpaid_get_subscription_periods',
190
-		array(
188
+    return apply_filters(
189
+        'getpaid_get_subscription_periods',
190
+        array(
191 191
 
192
-			'day'   => array(
193
-				'singular' => __( '%s day', 'invoicing' ),
194
-				'plural'   => __( '%d days', 'invoicing' ),
195
-			),
192
+            'day'   => array(
193
+                'singular' => __( '%s day', 'invoicing' ),
194
+                'plural'   => __( '%d days', 'invoicing' ),
195
+            ),
196 196
 
197
-			'week'   => array(
198
-				'singular' => __( '%s week', 'invoicing' ),
199
-				'plural'   => __( '%d weeks', 'invoicing' ),
200
-			),
197
+            'week'   => array(
198
+                'singular' => __( '%s week', 'invoicing' ),
199
+                'plural'   => __( '%d weeks', 'invoicing' ),
200
+            ),
201 201
 
202
-			'month'   => array(
203
-				'singular' => __( '%s month', 'invoicing' ),
204
-				'plural'   => __( '%d months', 'invoicing' ),
205
-			),
202
+            'month'   => array(
203
+                'singular' => __( '%s month', 'invoicing' ),
204
+                'plural'   => __( '%d months', 'invoicing' ),
205
+            ),
206 206
 
207
-			'year'   => array(
208
-				'singular' => __( '%s year', 'invoicing' ),
209
-				'plural'   => __( '%d years', 'invoicing' ),
210
-			),
207
+            'year'   => array(
208
+                'singular' => __( '%s year', 'invoicing' ),
209
+                'plural'   => __( '%d years', 'invoicing' ),
210
+            ),
211 211
 
212
-		)
213
-	);
212
+        )
213
+    );
214 214
 
215 215
 }
216 216
 
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
  * @return int
222 222
  */
223 223
 function getpaid_get_subscription_trial_period_interval( $trial_period ) {
224
-	return (int) preg_replace( '/[^0-9]/', '', $trial_period );
224
+    return (int) preg_replace( '/[^0-9]/', '', $trial_period );
225 225
 }
226 226
 
227 227
 /**
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
  * @return string
232 232
  */
233 233
 function getpaid_get_subscription_trial_period_period( $trial_period ) {
234
-	return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
234
+    return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
235 235
 }
236 236
 
237 237
 /**
@@ -242,8 +242,8 @@  discard block
 block discarded – undo
242 242
  * @return string
243 243
  */
244 244
 function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) {
245
-	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
246
-	return strtolower( sanitize_text_field( $label ) );
245
+    $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
246
+    return strtolower( sanitize_text_field( $label ) );
247 247
 }
248 248
 
249 249
 /**
@@ -254,22 +254,22 @@  discard block
 block discarded – undo
254 254
  */
255 255
 function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) {
256 256
 
257
-	$periods = getpaid_get_subscription_periods();
258
-	$period  = strtolower( $period );
257
+    $periods = getpaid_get_subscription_periods();
258
+    $period  = strtolower( $period );
259 259
 
260
-	if ( isset( $periods[ $period ] ) ) {
261
-		return sprintf( $periods[ $period ]['singular'], $singular_prefix );
262
-	}
260
+    if ( isset( $periods[ $period ] ) ) {
261
+        return sprintf( $periods[ $period ]['singular'], $singular_prefix );
262
+    }
263 263
 
264
-	// Backwards compatibility.
265
-	foreach ( $periods as $key => $data ) {
266
-		if ( strpos( $key, $period ) === 0 ) {
267
-			return sprintf( $data['singular'], $singular_prefix );
268
-		}
269
-	}
264
+    // Backwards compatibility.
265
+    foreach ( $periods as $key => $data ) {
266
+        if ( strpos( $key, $period ) === 0 ) {
267
+            return sprintf( $data['singular'], $singular_prefix );
268
+        }
269
+    }
270 270
 
271
-	// Invalid string.
272
-	return '';
271
+    // Invalid string.
272
+    return '';
273 273
 }
274 274
 
275 275
 /**
@@ -281,22 +281,22 @@  discard block
 block discarded – undo
281 281
  */
282 282
 function getpaid_get_plural_subscription_period_label( $period, $interval ) {
283 283
 
284
-	$periods = getpaid_get_subscription_periods();
285
-	$period  = strtolower( $period );
284
+    $periods = getpaid_get_subscription_periods();
285
+    $period  = strtolower( $period );
286 286
 
287
-	if ( isset( $periods[ $period ] ) ) {
288
-		return sprintf( $periods[ $period ]['plural'], $interval );
289
-	}
287
+    if ( isset( $periods[ $period ] ) ) {
288
+        return sprintf( $periods[ $period ]['plural'], $interval );
289
+    }
290 290
 
291
-	// Backwards compatibility.
292
-	foreach ( $periods as $key => $data ) {
293
-		if ( strpos( $key, $period ) === 0 ) {
294
-			return sprintf( $data['plural'], $interval );
295
-		}
296
-	}
291
+    // Backwards compatibility.
292
+    foreach ( $periods as $key => $data ) {
293
+        if ( strpos( $key, $period ) === 0 ) {
294
+            return sprintf( $data['plural'], $interval );
295
+        }
296
+    }
297 297
 
298
-	// Invalid string.
299
-	return '';
298
+    // Invalid string.
299
+    return '';
300 300
 }
301 301
 
302 302
 /**
@@ -307,101 +307,101 @@  discard block
 block discarded – undo
307 307
  */
308 308
 function getpaid_get_formatted_subscription_amount( $subscription ) {
309 309
 
310
-	$initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
311
-	$recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
312
-	$period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
313
-	$bill_times = $subscription->get_bill_times();
310
+    $initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
311
+    $recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
312
+    $period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
313
+    $bill_times = $subscription->get_bill_times();
314 314
 
315
-	if ( ! empty( $bill_times ) ) {
316
-		$bill_times = $subscription->get_frequency() * $bill_times;
317
-		$bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
318
-	}
315
+    if ( ! empty( $bill_times ) ) {
316
+        $bill_times = $subscription->get_frequency() * $bill_times;
317
+        $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
318
+    }
319 319
 
320
-	// Trial periods.
321
-	if ( $subscription->has_trial_period() ) {
320
+    // Trial periods.
321
+    if ( $subscription->has_trial_period() ) {
322 322
 
323
-		$trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
324
-		$trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
323
+        $trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
324
+        $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
325 325
 
326
-		if ( empty( $bill_times ) ) {
326
+        if ( empty( $bill_times ) ) {
327 327
 
328
-			return sprintf(
328
+            return sprintf(
329 329
 
330
-				// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
331
-				_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' ),
332
-				$initial,
333
-				getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
334
-				$recurring,
335
-				$period
330
+                // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
331
+                _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' ),
332
+                $initial,
333
+                getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
334
+                $recurring,
335
+                $period
336 336
 	
337
-			);
337
+            );
338 338
 
339
-		}
339
+        }
340 340
 
341
-		return sprintf(
341
+        return sprintf(
342 342
 
343
-			// 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
344
-			_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' ),
345
-			$initial,
346
-			getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
347
-			$recurring,
348
-			$period,
349
-			$bill_times
350
-		);
343
+            // 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
344
+            _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' ),
345
+            $initial,
346
+            getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
347
+            $recurring,
348
+            $period,
349
+            $bill_times
350
+        );
351 351
 
352
-	}
352
+    }
353 353
 
354
-	if ( $initial != $recurring ) {
354
+    if ( $initial != $recurring ) {
355 355
 
356
-		if ( empty( $bill_times ) ) {
356
+        if ( empty( $bill_times ) ) {
357 357
 
358
-			return sprintf(
358
+            return sprintf(
359 359
 
360
-				// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
361
-				_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' ),
362
-				$initial,
363
-				$recurring,
364
-				$period
360
+                // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
361
+                _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' ),
362
+                $initial,
363
+                $recurring,
364
+                $period
365 365
 	
366
-			);
366
+            );
367 367
 
368
-		}
368
+        }
369 369
 
370
-		return sprintf(
370
+        return sprintf(
371 371
 
372
-			// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
373
-			_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' ),
374
-			$initial,
375
-			$recurring,
376
-			$period,
377
-			$bill_times
372
+            // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
373
+            _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' ),
374
+            $initial,
375
+            $recurring,
376
+            $period,
377
+            $bill_times
378 378
 
379
-		);
379
+        );
380 380
 
381
-	}
381
+    }
382 382
 
383
-	if ( empty( $bill_times ) ) {
383
+    if ( empty( $bill_times ) ) {
384 384
 
385
-		return sprintf(
385
+        return sprintf(
386 386
 
387
-			// translators: $1: is the recurring amount, $2: is the recurring period
388
-			_x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
389
-			$initial,
390
-			$period
387
+            // translators: $1: is the recurring amount, $2: is the recurring period
388
+            _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
389
+            $initial,
390
+            $period
391 391
 	
392
-		);
392
+        );
393 393
 
394
-	}
394
+    }
395 395
 
396
-	return sprintf(
396
+    return sprintf(
397 397
 
398
-		// translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
399
-		_x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
400
-		$bill_times,
401
-		$initial,
402
-		$period
398
+        // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
399
+        _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
400
+        $bill_times,
401
+        $initial,
402
+        $period
403 403
 
404
-	);
404
+    );
405 405
 
406 406
 }
407 407
 
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
  * @return WPInv_Subscription|false
413 413
  */
414 414
 function getpaid_get_invoice_subscription( $invoice ) {
415
-	return getpaid_subscriptions()->get_invoice_subscription( $invoice );
415
+    return getpaid_subscriptions()->get_invoice_subscription( $invoice );
416 416
 }
417 417
 
418 418
 /**
@@ -421,10 +421,10 @@  discard block
 block discarded – undo
421 421
  * @param WPInv_Invoice $invoice
422 422
  */
423 423
 function getpaid_activate_invoice_subscription( $invoice ) {
424
-	$subscription = getpaid_get_invoice_subscription( $invoice );
425
-	if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
426
-		$subscription->activate();
427
-	}
424
+    $subscription = getpaid_get_invoice_subscription( $invoice );
425
+    if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
426
+        $subscription->activate();
427
+    }
428 428
 }
429 429
 
430 430
 /**
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
  * @return WPInv_Subscriptions
434 434
  */
435 435
 function getpaid_subscriptions() {
436
-	return getpaid()->get( 'subscriptions' );
436
+    return getpaid()->get( 'subscriptions' );
437 437
 }
438 438
 
439 439
 /**
@@ -452,15 +452,15 @@  discard block
 block discarded – undo
452 452
         return false;
453 453
     }
454 454
 
455
-	// Fetch the invoice subscription.
456
-	$subscription = getpaid_get_subscriptions(
457
-		array(
458
-			'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(),
459
-			'number'     => 1,
460
-		)
461
-	);
455
+    // Fetch the invoice subscription.
456
+    $subscription = getpaid_get_subscriptions(
457
+        array(
458
+            'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(),
459
+            'number'     => 1,
460
+        )
461
+    );
462 462
 
463
-	return empty( $subscription ) ? false : $subscription[0];
463
+    return empty( $subscription ) ? false : $subscription[0];
464 464
 
465 465
 }
466 466
 
@@ -477,48 +477,48 @@  discard block
 block discarded – undo
477 477
  */
478 478
 function getpaid_get_recurring_item_key( $cart_item ) {
479 479
 
480
-	$cart_key     = 'renews_';
481
-	$interval     = $cart_item->get_recurring_interval();
482
-	$period       = $cart_item->get_recurring_period( true );
483
-	$length       = $cart_item->get_recurring_limit() * $interval;
484
-	$trial_period = $cart_item->get_trial_period( true );
485
-	$trial_length = $cart_item->get_trial_interval();
486
-
487
-	// First start with the billing interval and period
488
-	switch ( $interval ) {
489
-		case 1 :
490
-			if ( 'day' == $period ) {
491
-				$cart_key .= 'daily';
492
-			} else {
493
-				$cart_key .= sprintf( '%sly', $period );
494
-			}
495
-			break;
496
-		case 2 :
497
-			$cart_key .= sprintf( 'every_2nd_%s', $period );
498
-			break;
499
-		case 3 :
500
-			$cart_key .= sprintf( 'every_3rd_%s', $period );
501
-		break;
502
-		default:
503
-			$cart_key .= sprintf( 'every_%dth_%s', $interval, $period );
504
-			break;
505
-	}
506
-
507
-	// Maybe add the optional maximum billing periods...
508
-	if ( $length > 0 ) {
509
-		$cart_key .= '_for_';
510
-		$cart_key .= sprintf( '%d_%s', $length, $period );
511
-		if ( $length > 1 ) {
512
-			$cart_key .= 's';
513
-		}
514
-	}
515
-
516
-	// And an optional free trial.
517
-	if ( $cart_item->has_free_trial() ) {
518
-		$cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period );
519
-	}
520
-
521
-	return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item );
480
+    $cart_key     = 'renews_';
481
+    $interval     = $cart_item->get_recurring_interval();
482
+    $period       = $cart_item->get_recurring_period( true );
483
+    $length       = $cart_item->get_recurring_limit() * $interval;
484
+    $trial_period = $cart_item->get_trial_period( true );
485
+    $trial_length = $cart_item->get_trial_interval();
486
+
487
+    // First start with the billing interval and period
488
+    switch ( $interval ) {
489
+        case 1 :
490
+            if ( 'day' == $period ) {
491
+                $cart_key .= 'daily';
492
+            } else {
493
+                $cart_key .= sprintf( '%sly', $period );
494
+            }
495
+            break;
496
+        case 2 :
497
+            $cart_key .= sprintf( 'every_2nd_%s', $period );
498
+            break;
499
+        case 3 :
500
+            $cart_key .= sprintf( 'every_3rd_%s', $period );
501
+        break;
502
+        default:
503
+            $cart_key .= sprintf( 'every_%dth_%s', $interval, $period );
504
+            break;
505
+    }
506
+
507
+    // Maybe add the optional maximum billing periods...
508
+    if ( $length > 0 ) {
509
+        $cart_key .= '_for_';
510
+        $cart_key .= sprintf( '%d_%s', $length, $period );
511
+        if ( $length > 1 ) {
512
+            $cart_key .= 's';
513
+        }
514
+    }
515
+
516
+    // And an optional free trial.
517
+    if ( $cart_item->has_free_trial() ) {
518
+        $cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period );
519
+    }
520
+
521
+    return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item );
522 522
 }
523 523
 
524 524
 /**
@@ -529,17 +529,17 @@  discard block
 block discarded – undo
529 529
  */
530 530
 function getpaid_get_subscription_groups( $invoice ) {
531 531
 
532
-	// Generate subscription groups.
533
-	$subscription_groups = array();
534
-	foreach ( $invoice->get_items() as $item ) {
532
+    // Generate subscription groups.
533
+    $subscription_groups = array();
534
+    foreach ( $invoice->get_items() as $item ) {
535 535
 
536
-		if ( $item->is_recurring() ) {
537
-			$subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item;
538
-		}
536
+        if ( $item->is_recurring() ) {
537
+            $subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item;
538
+        }
539 539
 
540
-	}
540
+    }
541 541
 
542
-	return $subscription_groups;
542
+    return $subscription_groups;
543 543
 }
544 544
 
545 545
 /**
@@ -553,57 +553,57 @@  discard block
 block discarded – undo
553 553
  */
554 554
 function getpaid_calculate_subscription_totals( $invoice ) {
555 555
 
556
-	// Generate subscription groups.
557
-	$subscription_groups = getpaid_get_subscription_groups( $invoice );
556
+    // Generate subscription groups.
557
+    $subscription_groups = getpaid_get_subscription_groups( $invoice );
558 558
 
559
-	// Now let's calculate the totals for each group of subscriptions
560
-	$subscription_totals = array();
559
+    // Now let's calculate the totals for each group of subscriptions
560
+    $subscription_totals = array();
561 561
 
562
-	foreach ( $subscription_groups as $subscription_key => $items ) {
562
+    foreach ( $subscription_groups as $subscription_key => $items ) {
563 563
 
564
-		if ( empty( $subscription_totals[ $subscription_key ] ) ) {
564
+        if ( empty( $subscription_totals[ $subscription_key ] ) ) {
565 565
 
566
-			$subscription_totals[ $subscription_key ] = array(
567
-				'initial_total'   => 0,
568
-				'recurring_total' => 0,
569
-				'items'           => array(),
570
-				'trialling'       => false,
571
-			);
566
+            $subscription_totals[ $subscription_key ] = array(
567
+                'initial_total'   => 0,
568
+                'recurring_total' => 0,
569
+                'items'           => array(),
570
+                'trialling'       => false,
571
+            );
572 572
 
573
-		}
573
+        }
574 574
 
575
-		/**
576
-		 * Get the totals of the group.
577
-		 * @var GetPaid_Form_Item $item
578
-		 */
579
-		foreach ( $items as $item ) {
575
+        /**
576
+         * Get the totals of the group.
577
+         * @var GetPaid_Form_Item $item
578
+         */
579
+        foreach ( $items as $item ) {
580 580
 
581
-			$subscription_totals[ $subscription_key ]['items'][$item->get_id()]  = $item->prepare_data_for_saving();
582
-			$subscription_totals[ $subscription_key ]['item_id']                 = $item->get_id();
583
-			$subscription_totals[ $subscription_key ]['period']                  = $item->get_recurring_period( true );
584
-			$subscription_totals[ $subscription_key ]['interval']                = $item->get_recurring_interval();
585
-			$subscription_totals[ $subscription_key ]['initial_total']          += $item->get_sub_total() + $item->item_tax - $item->item_discount;
586
-			$subscription_totals[ $subscription_key ]['recurring_total']        += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount;
587
-			$subscription_totals[ $subscription_key ]['recurring_limit']         = $item->get_recurring_limit();
581
+            $subscription_totals[ $subscription_key ]['items'][$item->get_id()]  = $item->prepare_data_for_saving();
582
+            $subscription_totals[ $subscription_key ]['item_id']                 = $item->get_id();
583
+            $subscription_totals[ $subscription_key ]['period']                  = $item->get_recurring_period( true );
584
+            $subscription_totals[ $subscription_key ]['interval']                = $item->get_recurring_interval();
585
+            $subscription_totals[ $subscription_key ]['initial_total']          += $item->get_sub_total() + $item->item_tax - $item->item_discount;
586
+            $subscription_totals[ $subscription_key ]['recurring_total']        += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount;
587
+            $subscription_totals[ $subscription_key ]['recurring_limit']         = $item->get_recurring_limit();
588 588
 
589
-			// Calculate the next renewal date.
590
-			$period       = $item->get_recurring_period( true );
591
-			$interval     = $item->get_recurring_interval();
589
+            // Calculate the next renewal date.
590
+            $period       = $item->get_recurring_period( true );
591
+            $interval     = $item->get_recurring_interval();
592 592
 
593
-			// If the subscription item has a trial period...
594
-			if ( $item->has_free_trial() ) {
595
-				$period   = $item->get_trial_period( true );
596
-				$interval = $item->get_trial_interval();
597
-				$subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period;
598
-			}
593
+            // If the subscription item has a trial period...
594
+            if ( $item->has_free_trial() ) {
595
+                $period   = $item->get_trial_period( true );
596
+                $interval = $item->get_trial_interval();
597
+                $subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period;
598
+            }
599 599
 
600
-			$subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) );
600
+            $subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) );
601 601
 
602
-		}
602
+        }
603 603
 
604
-	}
604
+    }
605 605
 
606
-	return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice );
606
+    return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice );
607 607
 }
608 608
 
609 609
 /**
@@ -614,17 +614,17 @@  discard block
 block discarded – undo
614 614
  */
615 615
 function getpaid_should_group_subscriptions( $invoice ) {
616 616
 
617
-	$recurring_items = 0;
617
+    $recurring_items = 0;
618 618
 
619
-	foreach ( $invoice->get_items() as $item ) {
619
+    foreach ( $invoice->get_items() as $item ) {
620 620
 
621
-		if ( $item->is_recurring() ) {
622
-			$recurring_items ++;
623
-		}
621
+        if ( $item->is_recurring() ) {
622
+            $recurring_items ++;
623
+        }
624 624
 
625
-	}
625
+    }
626 626
 
627
-	return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice );
627
+    return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice );
628 628
 }
629 629
 
630 630
 /**
@@ -635,40 +635,40 @@  discard block
 block discarded – undo
635 635
  * @return int
636 636
  */
637 637
 function getpaid_count_subscription_invoices( $parent_invoice_id, $subscription_id = false ) {
638
-	global $wpdb;
638
+    global $wpdb;
639 639
 
640
-	$parent_invoice_id = (int) $parent_invoice_id;
640
+    $parent_invoice_id = (int) $parent_invoice_id;
641 641
 
642
-	if ( false === $subscription_id || ! (bool) get_post_meta( $parent_invoice_id, '_wpinv_subscription_id', true ) ) {
642
+    if ( false === $subscription_id || ! (bool) get_post_meta( $parent_invoice_id, '_wpinv_subscription_id', true ) ) {
643 643
 
644
-		return (int) $wpdb->get_var(
645
-			$wpdb->prepare(
646
-				"SELECT COUNT(ID) FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
647
-				$parent_invoice_id,
648
-				$parent_invoice_id
649
-			)
650
-		);
644
+        return (int) $wpdb->get_var(
645
+            $wpdb->prepare(
646
+                "SELECT COUNT(ID) FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
647
+                $parent_invoice_id,
648
+                $parent_invoice_id
649
+            )
650
+        );
651 651
 
652
-	}
652
+    }
653 653
 	
654
-	$invoice_ids = $wpdb->get_col(
655
-		$wpdb->prepare(
656
-			"SELECT ID FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
657
-			$parent_invoice_id,
658
-			$parent_invoice_id
659
-		)
660
-	);
654
+    $invoice_ids = $wpdb->get_col(
655
+        $wpdb->prepare(
656
+            "SELECT ID FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
657
+            $parent_invoice_id,
658
+            $parent_invoice_id
659
+        )
660
+    );
661 661
 
662
-	$count = 0;
662
+    $count = 0;
663 663
 
664
-	foreach ( wp_parse_id_list( $invoice_ids ) as $invoice_id ) {
664
+    foreach ( wp_parse_id_list( $invoice_ids ) as $invoice_id ) {
665 665
 
666
-		if ( $invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta( $invoice_id, '_wpinv_subscription_id', true ) ) {
667
-			$count ++;
668
-			continue;
669
-		}
666
+        if ( $invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta( $invoice_id, '_wpinv_subscription_id', true ) ) {
667
+            $count ++;
668
+            continue;
669
+        }
670 670
 
671
-	}
671
+    }
672 672
 
673
-	return $count;
673
+    return $count;
674 674
 }
Please login to merge, or discard this patch.
Spacing   +143 added lines, -143 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,10 +61,10 @@  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 ) {
64
+function getpaid_get_subscription($subscription) {
65 65
 
66
-	if ( ! is_a( $subscription, 'WPInv_Subscription' ) ) {
67
-		$subscription = new WPInv_Subscription( $subscription );
66
+	if (!is_a($subscription, 'WPInv_Subscription')) {
67
+		$subscription = new WPInv_Subscription($subscription);
68 68
 	}
69 69
 
70 70
 	return $subscription->exists() ? $subscription : false;
@@ -79,26 +79,26 @@  discard block
 block discarded – undo
79 79
  *
80 80
  * @return int|array|WPInv_Subscription[]|GetPaid_Subscriptions_Query
81 81
  */
82
-function getpaid_get_subscriptions( $args = array(), $return = 'results' ) {
82
+function getpaid_get_subscriptions($args = array(), $return = 'results') {
83 83
 
84 84
 	// Do not retrieve all fields if we just want the count.
85
-	if ( 'count' == $return ) {
85
+	if ('count' == $return) {
86 86
 		$args['fields'] = 'id';
87 87
 		$args['number'] = 1;
88 88
 	}
89 89
 
90 90
 	// Do not count all matches if we just want the results.
91
-	if ( 'results' == $return ) {
91
+	if ('results' == $return) {
92 92
 		$args['count_total'] = false;
93 93
 	}
94 94
 
95
-	$query = new GetPaid_Subscriptions_Query( $args );
95
+	$query = new GetPaid_Subscriptions_Query($args);
96 96
 
97
-	if ( 'results' == $return ) {
97
+	if ('results' == $return) {
98 98
 		return $query->get_results();
99 99
 	}
100 100
 
101
-	if ( 'count' == $return ) {
101
+	if ('count' == $return) {
102 102
 		return $query->get_total();
103 103
 	}
104 104
 
@@ -115,13 +115,13 @@  discard block
 block discarded – undo
115 115
 	return apply_filters(
116 116
 		'getpaid_get_subscription_statuses',
117 117
 		array(
118
-			'pending'    => __( 'Pending', 'invoicing' ),
119
-			'trialling'  => __( 'Trialing', 'invoicing' ),
120
-			'active'     => __( 'Active', 'invoicing' ),
121
-			'failing'    => __( 'Failing', 'invoicing' ),
122
-			'expired'    => __( 'Expired', 'invoicing' ),
123
-			'completed'  => __( 'Complete', 'invoicing' ),
124
-			'cancelled'  => __( 'Cancelled', 'invoicing' ),
118
+			'pending'    => __('Pending', 'invoicing'),
119
+			'trialling'  => __('Trialing', 'invoicing'),
120
+			'active'     => __('Active', 'invoicing'),
121
+			'failing'    => __('Failing', 'invoicing'),
122
+			'expired'    => __('Expired', 'invoicing'),
123
+			'completed'  => __('Complete', 'invoicing'),
124
+			'cancelled'  => __('Cancelled', 'invoicing'),
125 125
 		)
126 126
 	);
127 127
 
@@ -132,9 +132,9 @@  discard block
 block discarded – undo
132 132
  *
133 133
  * @return string
134 134
  */
135
-function getpaid_get_subscription_status_label( $status ) {
135
+function getpaid_get_subscription_status_label($status) {
136 136
 	$statuses = getpaid_get_subscription_statuses();
137
-	return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
137
+	return isset($statuses[$status]) ? $statuses[$status] : ucfirst(sanitize_text_field($status));
138 138
 }
139 139
 
140 140
 /**
@@ -164,14 +164,14 @@  discard block
 block discarded – undo
164 164
  *
165 165
  * @return array
166 166
  */
167
-function getpaid_get_subscription_status_counts( $args = array() ) {
167
+function getpaid_get_subscription_status_counts($args = array()) {
168 168
 
169
-	$statuses = array_keys( getpaid_get_subscription_statuses() );
169
+	$statuses = array_keys(getpaid_get_subscription_statuses());
170 170
 	$counts   = array();
171 171
 
172
-	foreach ( $statuses as $status ) {
173
-		$_args             = wp_parse_args( "status=$status", $args );
174
-		$counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
172
+	foreach ($statuses as $status) {
173
+		$_args             = wp_parse_args("status=$status", $args);
174
+		$counts[$status] = getpaid_get_subscriptions($_args, 'count');
175 175
 	}
176 176
 
177 177
 	return $counts;
@@ -190,23 +190,23 @@  discard block
 block discarded – undo
190 190
 		array(
191 191
 
192 192
 			'day'   => array(
193
-				'singular' => __( '%s day', 'invoicing' ),
194
-				'plural'   => __( '%d days', 'invoicing' ),
193
+				'singular' => __('%s day', 'invoicing'),
194
+				'plural'   => __('%d days', 'invoicing'),
195 195
 			),
196 196
 
197 197
 			'week'   => array(
198
-				'singular' => __( '%s week', 'invoicing' ),
199
-				'plural'   => __( '%d weeks', 'invoicing' ),
198
+				'singular' => __('%s week', 'invoicing'),
199
+				'plural'   => __('%d weeks', 'invoicing'),
200 200
 			),
201 201
 
202 202
 			'month'   => array(
203
-				'singular' => __( '%s month', 'invoicing' ),
204
-				'plural'   => __( '%d months', 'invoicing' ),
203
+				'singular' => __('%s month', 'invoicing'),
204
+				'plural'   => __('%d months', 'invoicing'),
205 205
 			),
206 206
 
207 207
 			'year'   => array(
208
-				'singular' => __( '%s year', 'invoicing' ),
209
-				'plural'   => __( '%d years', 'invoicing' ),
208
+				'singular' => __('%s year', 'invoicing'),
209
+				'plural'   => __('%d years', 'invoicing'),
210 210
 			),
211 211
 
212 212
 		)
@@ -220,8 +220,8 @@  discard block
 block discarded – undo
220 220
  * @param string $trial_period
221 221
  * @return int
222 222
  */
223
-function getpaid_get_subscription_trial_period_interval( $trial_period ) {
224
-	return (int) preg_replace( '/[^0-9]/', '', $trial_period );
223
+function getpaid_get_subscription_trial_period_interval($trial_period) {
224
+	return (int) preg_replace('/[^0-9]/', '', $trial_period);
225 225
 }
226 226
 
227 227
 /**
@@ -230,8 +230,8 @@  discard block
 block discarded – undo
230 230
  * @param string $trial_period
231 231
  * @return string
232 232
  */
233
-function getpaid_get_subscription_trial_period_period( $trial_period ) {
234
-	return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
233
+function getpaid_get_subscription_trial_period_period($trial_period) {
234
+	return preg_replace('/[^a-z]/', '', strtolower($trial_period));
235 235
 }
236 236
 
237 237
 /**
@@ -241,9 +241,9 @@  discard block
 block discarded – undo
241 241
  * @param int $interval
242 242
  * @return string
243 243
  */
244
-function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) {
245
-	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
246
-	return strtolower( sanitize_text_field( $label ) );
244
+function getpaid_get_subscription_period_label($period, $interval = 1, $singular_prefix = '1') {
245
+	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label($period, $interval) : getpaid_get_singular_subscription_period_label($period, $singular_prefix);
246
+	return strtolower(sanitize_text_field($label));
247 247
 }
248 248
 
249 249
 /**
@@ -252,19 +252,19 @@  discard block
 block discarded – undo
252 252
  * @param string $period
253 253
  * @return string
254 254
  */
255
-function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) {
255
+function getpaid_get_singular_subscription_period_label($period, $singular_prefix = '1') {
256 256
 
257 257
 	$periods = getpaid_get_subscription_periods();
258
-	$period  = strtolower( $period );
258
+	$period  = strtolower($period);
259 259
 
260
-	if ( isset( $periods[ $period ] ) ) {
261
-		return sprintf( $periods[ $period ]['singular'], $singular_prefix );
260
+	if (isset($periods[$period])) {
261
+		return sprintf($periods[$period]['singular'], $singular_prefix);
262 262
 	}
263 263
 
264 264
 	// Backwards compatibility.
265
-	foreach ( $periods as $key => $data ) {
266
-		if ( strpos( $key, $period ) === 0 ) {
267
-			return sprintf( $data['singular'], $singular_prefix );
265
+	foreach ($periods as $key => $data) {
266
+		if (strpos($key, $period) === 0) {
267
+			return sprintf($data['singular'], $singular_prefix);
268 268
 		}
269 269
 	}
270 270
 
@@ -279,19 +279,19 @@  discard block
 block discarded – undo
279 279
  * @param int $interval
280 280
  * @return string
281 281
  */
282
-function getpaid_get_plural_subscription_period_label( $period, $interval ) {
282
+function getpaid_get_plural_subscription_period_label($period, $interval) {
283 283
 
284 284
 	$periods = getpaid_get_subscription_periods();
285
-	$period  = strtolower( $period );
285
+	$period  = strtolower($period);
286 286
 
287
-	if ( isset( $periods[ $period ] ) ) {
288
-		return sprintf( $periods[ $period ]['plural'], $interval );
287
+	if (isset($periods[$period])) {
288
+		return sprintf($periods[$period]['plural'], $interval);
289 289
 	}
290 290
 
291 291
 	// Backwards compatibility.
292
-	foreach ( $periods as $key => $data ) {
293
-		if ( strpos( $key, $period ) === 0 ) {
294
-			return sprintf( $data['plural'], $interval );
292
+	foreach ($periods as $key => $data) {
293
+		if (strpos($key, $period) === 0) {
294
+			return sprintf($data['plural'], $interval);
295 295
 		}
296 296
 	}
297 297
 
@@ -305,32 +305,32 @@  discard block
 block discarded – undo
305 305
  * @param WPInv_Subscription $subscription
306 306
  * @return string
307 307
  */
308
-function getpaid_get_formatted_subscription_amount( $subscription ) {
308
+function getpaid_get_formatted_subscription_amount($subscription) {
309 309
 
310
-	$initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
311
-	$recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
312
-	$period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
310
+	$initial    = wpinv_price($subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency());
311
+	$recurring  = wpinv_price($subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency());
312
+	$period     = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), '');
313 313
 	$bill_times = $subscription->get_bill_times();
314 314
 
315
-	if ( ! empty( $bill_times ) ) {
315
+	if (!empty($bill_times)) {
316 316
 		$bill_times = $subscription->get_frequency() * $bill_times;
317
-		$bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
317
+		$bill_times = getpaid_get_subscription_period_label($subscription->get_period(), $bill_times);
318 318
 	}
319 319
 
320 320
 	// Trial periods.
321
-	if ( $subscription->has_trial_period() ) {
321
+	if ($subscription->has_trial_period()) {
322 322
 
323
-		$trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
324
-		$trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
323
+		$trial_period   = getpaid_get_subscription_trial_period_period($subscription->get_trial_period());
324
+		$trial_interval = getpaid_get_subscription_trial_period_interval($subscription->get_trial_period());
325 325
 
326
-		if ( empty( $bill_times ) ) {
326
+		if (empty($bill_times)) {
327 327
 
328 328
 			return sprintf(
329 329
 
330 330
 				// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
331
-				_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' ),
331
+				_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'),
332 332
 				$initial,
333
-				getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
333
+				getpaid_get_subscription_period_label($trial_period, $trial_interval),
334 334
 				$recurring,
335 335
 				$period
336 336
 	
@@ -341,9 +341,9 @@  discard block
 block discarded – undo
341 341
 		return sprintf(
342 342
 
343 343
 			// 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
344
-			_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' ),
344
+			_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'),
345 345
 			$initial,
346
-			getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
346
+			getpaid_get_subscription_period_label($trial_period, $trial_interval),
347 347
 			$recurring,
348 348
 			$period,
349 349
 			$bill_times
@@ -351,14 +351,14 @@  discard block
 block discarded – undo
351 351
 
352 352
 	}
353 353
 
354
-	if ( $initial != $recurring ) {
354
+	if ($initial != $recurring) {
355 355
 
356
-		if ( empty( $bill_times ) ) {
356
+		if (empty($bill_times)) {
357 357
 
358 358
 			return sprintf(
359 359
 
360 360
 				// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
361
-				_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' ),
361
+				_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'),
362 362
 				$initial,
363 363
 				$recurring,
364 364
 				$period
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 		return sprintf(
371 371
 
372 372
 			// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
373
-			_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' ),
373
+			_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'),
374 374
 			$initial,
375 375
 			$recurring,
376 376
 			$period,
@@ -380,12 +380,12 @@  discard block
 block discarded – undo
380 380
 
381 381
 	}
382 382
 
383
-	if ( empty( $bill_times ) ) {
383
+	if (empty($bill_times)) {
384 384
 
385 385
 		return sprintf(
386 386
 
387 387
 			// translators: $1: is the recurring amount, $2: is the recurring period
388
-			_x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
388
+			_x('%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing'),
389 389
 			$initial,
390 390
 			$period
391 391
 	
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
 	return sprintf(
397 397
 
398 398
 		// translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
399
-		_x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
399
+		_x('%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing'),
400 400
 		$bill_times,
401 401
 		$initial,
402 402
 		$period
@@ -411,8 +411,8 @@  discard block
 block discarded – undo
411 411
  * @param WPInv_Invoice $invoice
412 412
  * @return WPInv_Subscription|false
413 413
  */
414
-function getpaid_get_invoice_subscription( $invoice ) {
415
-	return getpaid_subscriptions()->get_invoice_subscription( $invoice );
414
+function getpaid_get_invoice_subscription($invoice) {
415
+	return getpaid_subscriptions()->get_invoice_subscription($invoice);
416 416
 }
417 417
 
418 418
 /**
@@ -420,9 +420,9 @@  discard block
 block discarded – undo
420 420
  *
421 421
  * @param WPInv_Invoice $invoice
422 422
  */
423
-function getpaid_activate_invoice_subscription( $invoice ) {
424
-	$subscription = getpaid_get_invoice_subscription( $invoice );
425
-	if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
423
+function getpaid_activate_invoice_subscription($invoice) {
424
+	$subscription = getpaid_get_invoice_subscription($invoice);
425
+	if (is_a($subscription, 'WPInv_Subscription')) {
426 426
 		$subscription->activate();
427 427
 	}
428 428
 }
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
  * @return WPInv_Subscriptions
434 434
  */
435 435
 function getpaid_subscriptions() {
436
-	return getpaid()->get( 'subscriptions' );
436
+	return getpaid()->get('subscriptions');
437 437
 }
438 438
 
439 439
 /**
@@ -442,13 +442,13 @@  discard block
 block discarded – undo
442 442
  * @since 2.3.0
443 443
  * @return WPInv_Subscription|bool
444 444
  */
445
-function wpinv_get_invoice_subscription( $invoice ) {
445
+function wpinv_get_invoice_subscription($invoice) {
446 446
 
447 447
     // Retrieve the invoice.
448
-    $invoice = new WPInv_Invoice( $invoice );
448
+    $invoice = new WPInv_Invoice($invoice);
449 449
 
450 450
     // Ensure it is a recurring invoice.
451
-    if ( ! $invoice->is_recurring() ) {
451
+    if (!$invoice->is_recurring()) {
452 452
         return false;
453 453
     }
454 454
 
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
 		)
461 461
 	);
462 462
 
463
-	return empty( $subscription ) ? false : $subscription[0];
463
+	return empty($subscription) ? false : $subscription[0];
464 464
 
465 465
 }
466 466
 
@@ -475,50 +475,50 @@  discard block
 block discarded – undo
475 475
  * @param GetPaid_Form_Item|WPInv_Item $cart_item
476 476
  * @return string
477 477
  */
478
-function getpaid_get_recurring_item_key( $cart_item ) {
478
+function getpaid_get_recurring_item_key($cart_item) {
479 479
 
480 480
 	$cart_key     = 'renews_';
481 481
 	$interval     = $cart_item->get_recurring_interval();
482
-	$period       = $cart_item->get_recurring_period( true );
482
+	$period       = $cart_item->get_recurring_period(true);
483 483
 	$length       = $cart_item->get_recurring_limit() * $interval;
484
-	$trial_period = $cart_item->get_trial_period( true );
484
+	$trial_period = $cart_item->get_trial_period(true);
485 485
 	$trial_length = $cart_item->get_trial_interval();
486 486
 
487 487
 	// First start with the billing interval and period
488
-	switch ( $interval ) {
488
+	switch ($interval) {
489 489
 		case 1 :
490
-			if ( 'day' == $period ) {
490
+			if ('day' == $period) {
491 491
 				$cart_key .= 'daily';
492 492
 			} else {
493
-				$cart_key .= sprintf( '%sly', $period );
493
+				$cart_key .= sprintf('%sly', $period);
494 494
 			}
495 495
 			break;
496 496
 		case 2 :
497
-			$cart_key .= sprintf( 'every_2nd_%s', $period );
497
+			$cart_key .= sprintf('every_2nd_%s', $period);
498 498
 			break;
499 499
 		case 3 :
500
-			$cart_key .= sprintf( 'every_3rd_%s', $period );
500
+			$cart_key .= sprintf('every_3rd_%s', $period);
501 501
 		break;
502 502
 		default:
503
-			$cart_key .= sprintf( 'every_%dth_%s', $interval, $period );
503
+			$cart_key .= sprintf('every_%dth_%s', $interval, $period);
504 504
 			break;
505 505
 	}
506 506
 
507 507
 	// Maybe add the optional maximum billing periods...
508
-	if ( $length > 0 ) {
508
+	if ($length > 0) {
509 509
 		$cart_key .= '_for_';
510
-		$cart_key .= sprintf( '%d_%s', $length, $period );
511
-		if ( $length > 1 ) {
510
+		$cart_key .= sprintf('%d_%s', $length, $period);
511
+		if ($length > 1) {
512 512
 			$cart_key .= 's';
513 513
 		}
514 514
 	}
515 515
 
516 516
 	// And an optional free trial.
517
-	if ( $cart_item->has_free_trial() ) {
518
-		$cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period );
517
+	if ($cart_item->has_free_trial()) {
518
+		$cart_key .= sprintf('_after_a_%d_%s_trial', $trial_length, $trial_period);
519 519
 	}
520 520
 
521
-	return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item );
521
+	return apply_filters('getpaid_get_recurring_item_key', $cart_key, $cart_item);
522 522
 }
523 523
 
524 524
 /**
@@ -527,14 +527,14 @@  discard block
 block discarded – undo
527 527
  * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice
528 528
  * @return array
529 529
  */
530
-function getpaid_get_subscription_groups( $invoice ) {
530
+function getpaid_get_subscription_groups($invoice) {
531 531
 
532 532
 	// Generate subscription groups.
533 533
 	$subscription_groups = array();
534
-	foreach ( $invoice->get_items() as $item ) {
534
+	foreach ($invoice->get_items() as $item) {
535 535
 
536
-		if ( $item->is_recurring() ) {
537
-			$subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item;
536
+		if ($item->is_recurring()) {
537
+			$subscription_groups[getpaid_get_recurring_item_key($item)][] = $item;
538 538
 		}
539 539
 
540 540
 	}
@@ -551,19 +551,19 @@  discard block
 block discarded – undo
551 551
  * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice
552 552
  * @return array
553 553
  */
554
-function getpaid_calculate_subscription_totals( $invoice ) {
554
+function getpaid_calculate_subscription_totals($invoice) {
555 555
 
556 556
 	// Generate subscription groups.
557
-	$subscription_groups = getpaid_get_subscription_groups( $invoice );
557
+	$subscription_groups = getpaid_get_subscription_groups($invoice);
558 558
 
559 559
 	// Now let's calculate the totals for each group of subscriptions
560 560
 	$subscription_totals = array();
561 561
 
562
-	foreach ( $subscription_groups as $subscription_key => $items ) {
562
+	foreach ($subscription_groups as $subscription_key => $items) {
563 563
 
564
-		if ( empty( $subscription_totals[ $subscription_key ] ) ) {
564
+		if (empty($subscription_totals[$subscription_key])) {
565 565
 
566
-			$subscription_totals[ $subscription_key ] = array(
566
+			$subscription_totals[$subscription_key] = array(
567 567
 				'initial_total'   => 0,
568 568
 				'recurring_total' => 0,
569 569
 				'items'           => array(),
@@ -576,34 +576,34 @@  discard block
 block discarded – undo
576 576
 		 * Get the totals of the group.
577 577
 		 * @var GetPaid_Form_Item $item
578 578
 		 */
579
-		foreach ( $items as $item ) {
579
+		foreach ($items as $item) {
580 580
 
581
-			$subscription_totals[ $subscription_key ]['items'][$item->get_id()]  = $item->prepare_data_for_saving();
582
-			$subscription_totals[ $subscription_key ]['item_id']                 = $item->get_id();
583
-			$subscription_totals[ $subscription_key ]['period']                  = $item->get_recurring_period( true );
584
-			$subscription_totals[ $subscription_key ]['interval']                = $item->get_recurring_interval();
585
-			$subscription_totals[ $subscription_key ]['initial_total']          += $item->get_sub_total() + $item->item_tax - $item->item_discount;
586
-			$subscription_totals[ $subscription_key ]['recurring_total']        += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount;
587
-			$subscription_totals[ $subscription_key ]['recurring_limit']         = $item->get_recurring_limit();
581
+			$subscription_totals[$subscription_key]['items'][$item->get_id()]  = $item->prepare_data_for_saving();
582
+			$subscription_totals[$subscription_key]['item_id']                 = $item->get_id();
583
+			$subscription_totals[$subscription_key]['period']                  = $item->get_recurring_period(true);
584
+			$subscription_totals[$subscription_key]['interval']                = $item->get_recurring_interval();
585
+			$subscription_totals[$subscription_key]['initial_total']          += $item->get_sub_total() + $item->item_tax - $item->item_discount;
586
+			$subscription_totals[$subscription_key]['recurring_total']        += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount;
587
+			$subscription_totals[$subscription_key]['recurring_limit']         = $item->get_recurring_limit();
588 588
 
589 589
 			// Calculate the next renewal date.
590
-			$period       = $item->get_recurring_period( true );
590
+			$period       = $item->get_recurring_period(true);
591 591
 			$interval     = $item->get_recurring_interval();
592 592
 
593 593
 			// If the subscription item has a trial period...
594
-			if ( $item->has_free_trial() ) {
595
-				$period   = $item->get_trial_period( true );
594
+			if ($item->has_free_trial()) {
595
+				$period   = $item->get_trial_period(true);
596 596
 				$interval = $item->get_trial_interval();
597
-				$subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period;
597
+				$subscription_totals[$subscription_key]['trialling'] = $interval . ' ' . $period;
598 598
 			}
599 599
 
600
-			$subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) );
600
+			$subscription_totals[$subscription_key]['renews_on'] = date('Y-m-d H:i:s', strtotime("+$interval $period", current_time('timestamp')));
601 601
 
602 602
 		}
603 603
 
604 604
 	}
605 605
 
606
-	return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice );
606
+	return apply_filters('getpaid_calculate_subscription_totals', $subscription_totals, $invoice);
607 607
 }
608 608
 
609 609
 /**
@@ -612,19 +612,19 @@  discard block
 block discarded – undo
612 612
  * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice
613 613
  * @return array
614 614
  */
615
-function getpaid_should_group_subscriptions( $invoice ) {
615
+function getpaid_should_group_subscriptions($invoice) {
616 616
 
617 617
 	$recurring_items = 0;
618 618
 
619
-	foreach ( $invoice->get_items() as $item ) {
619
+	foreach ($invoice->get_items() as $item) {
620 620
 
621
-		if ( $item->is_recurring() ) {
622
-			$recurring_items ++;
621
+		if ($item->is_recurring()) {
622
+			$recurring_items++;
623 623
 		}
624 624
 
625 625
 	}
626 626
 
627
-	return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice );
627
+	return apply_filters('getpaid_should_group_subscriptions', $recurring_items > 1, $invoice);
628 628
 }
629 629
 
630 630
 /**
@@ -634,12 +634,12 @@  discard block
 block discarded – undo
634 634
  * @param int|false $subscription_id
635 635
  * @return int
636 636
  */
637
-function getpaid_count_subscription_invoices( $parent_invoice_id, $subscription_id = false ) {
637
+function getpaid_count_subscription_invoices($parent_invoice_id, $subscription_id = false) {
638 638
 	global $wpdb;
639 639
 
640 640
 	$parent_invoice_id = (int) $parent_invoice_id;
641 641
 
642
-	if ( false === $subscription_id || ! (bool) get_post_meta( $parent_invoice_id, '_wpinv_subscription_id', true ) ) {
642
+	if (false === $subscription_id || !(bool) get_post_meta($parent_invoice_id, '_wpinv_subscription_id', true)) {
643 643
 
644 644
 		return (int) $wpdb->get_var(
645 645
 			$wpdb->prepare(
@@ -661,10 +661,10 @@  discard block
 block discarded – undo
661 661
 
662 662
 	$count = 0;
663 663
 
664
-	foreach ( wp_parse_id_list( $invoice_ids ) as $invoice_id ) {
664
+	foreach (wp_parse_id_list($invoice_ids) as $invoice_id) {
665 665
 
666
-		if ( $invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta( $invoice_id, '_wpinv_subscription_id', true ) ) {
667
-			$count ++;
666
+		if ($invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta($invoice_id, '_wpinv_subscription_id', true)) {
667
+			$count++;
668 668
 			continue;
669 669
 		}
670 670
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-taxes.php 2 patches
Indentation   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -12,230 +12,230 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Taxes {
14 14
 
15
-	/**
16
-	 * Submission taxes.
17
-	 * @var array
18
-	 */
19
-	public $taxes = array();
20
-
21
-	/**
22
-	 * Whether or not we should skip the taxes.
23
-	 * @var bool
24
-	 */
25
-	protected $skip_taxes = false;
15
+    /**
16
+     * Submission taxes.
17
+     * @var array
18
+     */
19
+    public $taxes = array();
20
+
21
+    /**
22
+     * Whether or not we should skip the taxes.
23
+     * @var bool
24
+     */
25
+    protected $skip_taxes = false;
26 26
 
27 27
     /**
28
-	 * Class constructor
29
-	 *
30
-	 * @param GetPaid_Payment_Form_Submission $submission
31
-	 */
32
-	public function __construct( $submission ) {
33
-
34
-		// Validate VAT number.
35
-		$this->validate_vat( $submission );
36
-
37
-		if ( $this->skip_taxes ) {
38
-			return;
39
-		}
40
-
41
-		foreach ( $submission->get_items() as $item ) {
42
-			$this->process_item_tax( $item, $submission );
43
-		}
44
-
45
-		// Process any existing invoice taxes.
46
-		if ( $submission->has_invoice() ) {
47
-			$this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes );
48
-		}
49
-
50
-	}
51
-
52
-	/**
53
-	 * Maybe process tax.
54
-	 *
55
-	 * @since 1.0.19
56
-	 * @param GetPaid_Form_Item $item
57
-	 * @param GetPaid_Payment_Form_Submission $submission
58
-	 */
59
-	public function process_item_tax( $item, $submission ) {
60
-
61
-		$rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
62
-		$rates    = getpaid_filter_item_tax_rates( $item, $rates );
63
-		$taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
64
-		$r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
65
-
66
-		foreach ( $taxes as $name => $amount ) {
67
-			$recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
68
-			$tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
69
-
70
-			$item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] );
71
-
72
-			if ( ! isset( $this->taxes[ $name ] ) ) {
73
-				$this->taxes[ $name ] = $tax;
74
-				continue;
75
-			}
76
-
77
-			$this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
78
-			$this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
79
-
80
-		}
81
-
82
-	}
83
-
84
-	/**
85
-	 * Checks if the submission has a digital item.
86
-	 *
87
-	 * @param GetPaid_Payment_Form_Submission $submission
88
-	 * @since 1.0.19
89
-	 * @return bool
90
-	 */
91
-	public function has_digital_item( $submission ) {
92
-
93
-		foreach ( $submission->get_items() as $item ) {
94
-
95
-			if ( 'digital' == $item->get_vat_rule() ) {
96
-				return true;
97
-			}
98
-
99
-		}
100
-
101
-		return false;
102
-	}
103
-
104
-	/**
105
-	 * Checks if this is an eu store.
106
-	 *
107
-	 * @since 1.0.19
108
-	 * @return bool
109
-	 */
110
-	public static function is_eu_store() {
111
-		return self::is_eu_country( wpinv_get_default_country() );
112
-	}
113
-
114
-	/**
115
-	 * Checks if this is an eu country.
116
-	 *
117
-	 * @param string $country
118
-	 * @since 1.0.19
119
-	 * @return bool
120
-	 */
121
-	public static function is_eu_country( $country ) {
122
-		return getpaid_is_eu_state( $country );
123
-	}
124
-
125
-	/**
126
-	 * Checks if this is an eu purchase.
127
-	 *
128
-	 * @param string $customer_country
129
-	 * @since 1.0.19
130
-	 * @return bool
131
-	 */
132
-	public static function is_eu_transaction( $customer_country ) {
133
-		return self::is_eu_country( $customer_country ) && self::is_eu_store();
134
-	}
135
-
136
-	/**
137
-	 * Retrieves the vat number.
138
-	 *
139
-	 * @param GetPaid_Payment_Form_Submission $submission
140
-	 * @since 1.0.19
141
-	 * @return string
142
-	 */
143
-	public function get_vat_number( $submission ) {
144
-
145
-		// Retrieve from the posted number.
146
-		$vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
147
-		if ( ! is_null( $vat_number ) ) {
148
-			return wpinv_clean( $vat_number );
149
-		}
150
-
151
-		return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
152
-	}
153
-
154
-	/**
155
-	 * Retrieves the company.
156
-	 *
157
-	 * @param GetPaid_Payment_Form_Submission $submission
158
-	 * @since 1.0.19
159
-	 * @return string
160
-	 */
161
-	public function get_company( $submission ) {
162
-
163
-		// Retrieve from the posted data.
164
-		$company = $submission->get_field( 'wpinv_company', 'billing' );
165
-		if ( ! empty( $company ) ) {
166
-			return wpinv_clean( $company );
167
-		}
168
-
169
-		// Retrieve from the invoice.
170
-		return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
171
-	}
172
-
173
-	/**
174
-	 * Checks if we require a VAT number.
175
-	 *
176
-	 * @param bool $ip_in_eu Whether the customer IP is from the EU
177
-	 * @param bool $country_in_eu Whether the customer country is from the EU
178
-	 * @since 1.0.19
179
-	 * @return string
180
-	 */
181
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
182
-
183
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
184
-		$prevent_b2c = ! empty( $prevent_b2c );
185
-		$is_eu       = $ip_in_eu || $country_in_eu;
186
-
187
-		return $prevent_b2c && $is_eu;
188
-	}
189
-
190
-	/**
191
-	 * Validate VAT data.
192
-	 *
193
-	 * @param GetPaid_Payment_Form_Submission $submission
194
-	 * @since 1.0.19
195
-	 */
196
-	public function validate_vat( $submission ) {
197
-
198
-		$in_eu = $this->is_eu_transaction( $submission->country );
199
-
200
-		// Abort if we are not validating vat numbers.
201
-		if ( ! $in_eu ) {
28
+     * Class constructor
29
+     *
30
+     * @param GetPaid_Payment_Form_Submission $submission
31
+     */
32
+    public function __construct( $submission ) {
33
+
34
+        // Validate VAT number.
35
+        $this->validate_vat( $submission );
36
+
37
+        if ( $this->skip_taxes ) {
202 38
             return;
203
-		}
39
+        }
40
+
41
+        foreach ( $submission->get_items() as $item ) {
42
+            $this->process_item_tax( $item, $submission );
43
+        }
44
+
45
+        // Process any existing invoice taxes.
46
+        if ( $submission->has_invoice() ) {
47
+            $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes );
48
+        }
49
+
50
+    }
51
+
52
+    /**
53
+     * Maybe process tax.
54
+     *
55
+     * @since 1.0.19
56
+     * @param GetPaid_Form_Item $item
57
+     * @param GetPaid_Payment_Form_Submission $submission
58
+     */
59
+    public function process_item_tax( $item, $submission ) {
60
+
61
+        $rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
62
+        $rates    = getpaid_filter_item_tax_rates( $item, $rates );
63
+        $taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
64
+        $r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
65
+
66
+        foreach ( $taxes as $name => $amount ) {
67
+            $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
68
+            $tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
69
+
70
+            $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] );
71
+
72
+            if ( ! isset( $this->taxes[ $name ] ) ) {
73
+                $this->taxes[ $name ] = $tax;
74
+                continue;
75
+            }
76
+
77
+            $this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
78
+            $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
79
+
80
+        }
81
+
82
+    }
83
+
84
+    /**
85
+     * Checks if the submission has a digital item.
86
+     *
87
+     * @param GetPaid_Payment_Form_Submission $submission
88
+     * @since 1.0.19
89
+     * @return bool
90
+     */
91
+    public function has_digital_item( $submission ) {
92
+
93
+        foreach ( $submission->get_items() as $item ) {
94
+
95
+            if ( 'digital' == $item->get_vat_rule() ) {
96
+                return true;
97
+            }
98
+
99
+        }
204 100
 
205
-		// Prepare variables.
206
-		$vat_number  = $this->get_vat_number( $submission );
207
-		$ip_country  = getpaid_get_ip_country();
101
+        return false;
102
+    }
103
+
104
+    /**
105
+     * Checks if this is an eu store.
106
+     *
107
+     * @since 1.0.19
108
+     * @return bool
109
+     */
110
+    public static function is_eu_store() {
111
+        return self::is_eu_country( wpinv_get_default_country() );
112
+    }
113
+
114
+    /**
115
+     * Checks if this is an eu country.
116
+     *
117
+     * @param string $country
118
+     * @since 1.0.19
119
+     * @return bool
120
+     */
121
+    public static function is_eu_country( $country ) {
122
+        return getpaid_is_eu_state( $country );
123
+    }
124
+
125
+    /**
126
+     * Checks if this is an eu purchase.
127
+     *
128
+     * @param string $customer_country
129
+     * @since 1.0.19
130
+     * @return bool
131
+     */
132
+    public static function is_eu_transaction( $customer_country ) {
133
+        return self::is_eu_country( $customer_country ) && self::is_eu_store();
134
+    }
135
+
136
+    /**
137
+     * Retrieves the vat number.
138
+     *
139
+     * @param GetPaid_Payment_Form_Submission $submission
140
+     * @since 1.0.19
141
+     * @return string
142
+     */
143
+    public function get_vat_number( $submission ) {
144
+
145
+        // Retrieve from the posted number.
146
+        $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
147
+        if ( ! is_null( $vat_number ) ) {
148
+            return wpinv_clean( $vat_number );
149
+        }
150
+
151
+        return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
152
+    }
153
+
154
+    /**
155
+     * Retrieves the company.
156
+     *
157
+     * @param GetPaid_Payment_Form_Submission $submission
158
+     * @since 1.0.19
159
+     * @return string
160
+     */
161
+    public function get_company( $submission ) {
162
+
163
+        // Retrieve from the posted data.
164
+        $company = $submission->get_field( 'wpinv_company', 'billing' );
165
+        if ( ! empty( $company ) ) {
166
+            return wpinv_clean( $company );
167
+        }
168
+
169
+        // Retrieve from the invoice.
170
+        return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
171
+    }
172
+
173
+    /**
174
+     * Checks if we require a VAT number.
175
+     *
176
+     * @param bool $ip_in_eu Whether the customer IP is from the EU
177
+     * @param bool $country_in_eu Whether the customer country is from the EU
178
+     * @since 1.0.19
179
+     * @return string
180
+     */
181
+    public function requires_vat( $ip_in_eu, $country_in_eu ) {
182
+
183
+        $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
184
+        $prevent_b2c = ! empty( $prevent_b2c );
185
+        $is_eu       = $ip_in_eu || $country_in_eu;
186
+
187
+        return $prevent_b2c && $is_eu;
188
+    }
189
+
190
+    /**
191
+     * Validate VAT data.
192
+     *
193
+     * @param GetPaid_Payment_Form_Submission $submission
194
+     * @since 1.0.19
195
+     */
196
+    public function validate_vat( $submission ) {
197
+
198
+        $in_eu = $this->is_eu_transaction( $submission->country );
199
+
200
+        // Abort if we are not validating vat numbers.
201
+        if ( ! $in_eu ) {
202
+            return;
203
+        }
204
+
205
+        // Prepare variables.
206
+        $vat_number  = $this->get_vat_number( $submission );
207
+        $ip_country  = getpaid_get_ip_country();
208 208
         $is_eu       = $this->is_eu_country( $submission->country );
209 209
         $is_ip_eu    = $this->is_eu_country( $ip_country );
210 210
 
211
-		// Maybe abort early for initial fetches.
212
-		if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
213
-			return;
214
-		}
211
+        // Maybe abort early for initial fetches.
212
+        if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
213
+            return;
214
+        }
215 215
 
216
-		// If we're preventing business to consumer purchases,
217
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
216
+        // If we're preventing business to consumer purchases,
217
+        if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
218 218
 
219
-			// Ensure that a vat number has been specified.
220
-			throw new Exception(
221
-				__( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' )
222
-			);
219
+            // Ensure that a vat number has been specified.
220
+            throw new Exception(
221
+                __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' )
222
+            );
223 223
 
224
-		}
224
+        }
225 225
 
226
-		if ( empty( $vat_number ) ) {
227
-			return;
228
-		}
226
+        if ( empty( $vat_number ) ) {
227
+            return;
228
+        }
229 229
 
230
-		if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
231
-			throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) );
232
-		}
230
+        if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
231
+            throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) );
232
+        }
233 233
 
234
-		if (  wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
235
-			return;
236
-		}
234
+        if (  wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
235
+            return;
236
+        }
237 237
 
238
-		$this->skip_taxes = true;
239
-	}
238
+        $this->skip_taxes = true;
239
+    }
240 240
 
241 241
 }
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 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
  * Payment form submission taxes class
@@ -29,22 +29,22 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @param GetPaid_Payment_Form_Submission $submission
31 31
 	 */
32
-	public function __construct( $submission ) {
32
+	public function __construct($submission) {
33 33
 
34 34
 		// Validate VAT number.
35
-		$this->validate_vat( $submission );
35
+		$this->validate_vat($submission);
36 36
 
37
-		if ( $this->skip_taxes ) {
37
+		if ($this->skip_taxes) {
38 38
 			return;
39 39
 		}
40 40
 
41
-		foreach ( $submission->get_items() as $item ) {
42
-			$this->process_item_tax( $item, $submission );
41
+		foreach ($submission->get_items() as $item) {
42
+			$this->process_item_tax($item, $submission);
43 43
 		}
44 44
 
45 45
 		// Process any existing invoice taxes.
46
-		if ( $submission->has_invoice() ) {
47
-			$this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes );
46
+		if ($submission->has_invoice()) {
47
+			$this->taxes = array_replace($submission->get_invoice()->get_taxes(), $this->taxes);
48 48
 		}
49 49
 
50 50
 	}
@@ -56,26 +56,26 @@  discard block
 block discarded – undo
56 56
 	 * @param GetPaid_Form_Item $item
57 57
 	 * @param GetPaid_Payment_Form_Submission $submission
58 58
 	 */
59
-	public function process_item_tax( $item, $submission ) {
59
+	public function process_item_tax($item, $submission) {
60 60
 
61
-		$rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
62
-		$rates    = getpaid_filter_item_tax_rates( $item, $rates );
63
-		$taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
64
-		$r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
61
+		$rates    = getpaid_get_item_tax_rates($item, $submission->country, $submission->state);
62
+		$rates    = getpaid_filter_item_tax_rates($item, $rates);
63
+		$taxes    = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, false), $rates);
64
+		$r_taxes  = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, true), $rates);
65 65
 
66
-		foreach ( $taxes as $name => $amount ) {
67
-			$recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
68
-			$tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
66
+		foreach ($taxes as $name => $amount) {
67
+			$recurring = isset($r_taxes[$name]) ? $r_taxes[$name] : 0;
68
+			$tax       = getpaid_prepare_item_tax($item, $name, $amount, $recurring);
69 69
 
70
-			$item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] );
70
+			$item->item_tax += wpinv_sanitize_amount($tax['initial_tax']);
71 71
 
72
-			if ( ! isset( $this->taxes[ $name ] ) ) {
73
-				$this->taxes[ $name ] = $tax;
72
+			if (!isset($this->taxes[$name])) {
73
+				$this->taxes[$name] = $tax;
74 74
 				continue;
75 75
 			}
76 76
 
77
-			$this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
78
-			$this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
77
+			$this->taxes[$name]['initial_tax']   += $tax['initial_tax'];
78
+			$this->taxes[$name]['recurring_tax'] += $tax['recurring_tax'];
79 79
 
80 80
 		}
81 81
 
@@ -88,11 +88,11 @@  discard block
 block discarded – undo
88 88
 	 * @since 1.0.19
89 89
 	 * @return bool
90 90
 	 */
91
-	public function has_digital_item( $submission ) {
91
+	public function has_digital_item($submission) {
92 92
 
93
-		foreach ( $submission->get_items() as $item ) {
93
+		foreach ($submission->get_items() as $item) {
94 94
 
95
-			if ( 'digital' == $item->get_vat_rule() ) {
95
+			if ('digital' == $item->get_vat_rule()) {
96 96
 				return true;
97 97
 			}
98 98
 
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 	 * @return bool
109 109
 	 */
110 110
 	public static function is_eu_store() {
111
-		return self::is_eu_country( wpinv_get_default_country() );
111
+		return self::is_eu_country(wpinv_get_default_country());
112 112
 	}
113 113
 
114 114
 	/**
@@ -118,8 +118,8 @@  discard block
 block discarded – undo
118 118
 	 * @since 1.0.19
119 119
 	 * @return bool
120 120
 	 */
121
-	public static function is_eu_country( $country ) {
122
-		return getpaid_is_eu_state( $country );
121
+	public static function is_eu_country($country) {
122
+		return getpaid_is_eu_state($country);
123 123
 	}
124 124
 
125 125
 	/**
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
 	 * @since 1.0.19
130 130
 	 * @return bool
131 131
 	 */
132
-	public static function is_eu_transaction( $customer_country ) {
133
-		return self::is_eu_country( $customer_country ) && self::is_eu_store();
132
+	public static function is_eu_transaction($customer_country) {
133
+		return self::is_eu_country($customer_country) && self::is_eu_store();
134 134
 	}
135 135
 
136 136
 	/**
@@ -140,12 +140,12 @@  discard block
 block discarded – undo
140 140
 	 * @since 1.0.19
141 141
 	 * @return string
142 142
 	 */
143
-	public function get_vat_number( $submission ) {
143
+	public function get_vat_number($submission) {
144 144
 
145 145
 		// Retrieve from the posted number.
146
-		$vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
147
-		if ( ! is_null( $vat_number ) ) {
148
-			return wpinv_clean( $vat_number );
146
+		$vat_number = $submission->get_field('wpinv_vat_number', 'billing');
147
+		if (!is_null($vat_number)) {
148
+			return wpinv_clean($vat_number);
149 149
 		}
150 150
 
151 151
 		return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
@@ -158,12 +158,12 @@  discard block
 block discarded – undo
158 158
 	 * @since 1.0.19
159 159
 	 * @return string
160 160
 	 */
161
-	public function get_company( $submission ) {
161
+	public function get_company($submission) {
162 162
 
163 163
 		// Retrieve from the posted data.
164
-		$company = $submission->get_field( 'wpinv_company', 'billing' );
165
-		if ( ! empty( $company ) ) {
166
-			return wpinv_clean( $company );
164
+		$company = $submission->get_field('wpinv_company', 'billing');
165
+		if (!empty($company)) {
166
+			return wpinv_clean($company);
167 167
 		}
168 168
 
169 169
 		// Retrieve from the invoice.
@@ -178,10 +178,10 @@  discard block
 block discarded – undo
178 178
 	 * @since 1.0.19
179 179
 	 * @return string
180 180
 	 */
181
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
181
+	public function requires_vat($ip_in_eu, $country_in_eu) {
182 182
 
183
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
184
-		$prevent_b2c = ! empty( $prevent_b2c );
183
+		$prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase');
184
+		$prevent_b2c = !empty($prevent_b2c);
185 185
 		$is_eu       = $ip_in_eu || $country_in_eu;
186 186
 
187 187
 		return $prevent_b2c && $is_eu;
@@ -193,45 +193,45 @@  discard block
 block discarded – undo
193 193
 	 * @param GetPaid_Payment_Form_Submission $submission
194 194
 	 * @since 1.0.19
195 195
 	 */
196
-	public function validate_vat( $submission ) {
196
+	public function validate_vat($submission) {
197 197
 
198
-		$in_eu = $this->is_eu_transaction( $submission->country );
198
+		$in_eu = $this->is_eu_transaction($submission->country);
199 199
 
200 200
 		// Abort if we are not validating vat numbers.
201
-		if ( ! $in_eu ) {
201
+		if (!$in_eu) {
202 202
             return;
203 203
 		}
204 204
 
205 205
 		// Prepare variables.
206
-		$vat_number  = $this->get_vat_number( $submission );
206
+		$vat_number  = $this->get_vat_number($submission);
207 207
 		$ip_country  = getpaid_get_ip_country();
208
-        $is_eu       = $this->is_eu_country( $submission->country );
209
-        $is_ip_eu    = $this->is_eu_country( $ip_country );
208
+        $is_eu       = $this->is_eu_country($submission->country);
209
+        $is_ip_eu    = $this->is_eu_country($ip_country);
210 210
 
211 211
 		// Maybe abort early for initial fetches.
212
-		if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
212
+		if ($submission->is_initial_fetch() && empty($vat_number)) {
213 213
 			return;
214 214
 		}
215 215
 
216 216
 		// If we're preventing business to consumer purchases,
217
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
217
+		if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) {
218 218
 
219 219
 			// Ensure that a vat number has been specified.
220 220
 			throw new Exception(
221
-				__( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' )
221
+				__('Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing')
222 222
 			);
223 223
 
224 224
 		}
225 225
 
226
-		if ( empty( $vat_number ) ) {
226
+		if (empty($vat_number)) {
227 227
 			return;
228 228
 		}
229 229
 
230
-		if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
231
-			throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) );
230
+		if (wpinv_should_validate_vat_number() && !wpinv_validate_vat_number($vat_number, $submission->country)) {
231
+			throw new Exception(__('Your VAT number is invalid', 'invoicing'));
232 232
 		}
233 233
 
234
-		if (  wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
234
+		if (wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option('vat_same_country_rule', 'vat_too')) {
235 235
 			return;
236 236
 		}
237 237
 
Please login to merge, or discard this patch.
includes/wpinv-payment-functions.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -239,7 +239,7 @@
 block discarded – undo
239 239
         do_action( 'getpaid_checkout_invoice_exception', $invoice );
240 240
     }
241 241
 
242
-	// Do we have any errors?
242
+    // Do we have any errors?
243 243
     if ( wpinv_get_errors() ) {
244 244
         $response['data'] = getpaid_get_errors_html( true, false );
245 245
     } else {
Please login to merge, or discard this patch.
Spacing   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -1,155 +1,155 @@  discard block
 block discarded – undo
1 1
 <?php
2
-function wpinv_is_subscription_payment( $invoice = '' ) {
3
-    if ( empty( $invoice ) ) {
2
+function wpinv_is_subscription_payment($invoice = '') {
3
+    if (empty($invoice)) {
4 4
         return false;
5 5
     }
6 6
     
7
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
8
-        $invoice = wpinv_get_invoice( $invoice );
7
+    if (!is_object($invoice) && is_scalar($invoice)) {
8
+        $invoice = wpinv_get_invoice($invoice);
9 9
     }
10 10
     
11
-    if ( empty( $invoice ) ) {
11
+    if (empty($invoice)) {
12 12
         return false;
13 13
     }
14 14
         
15
-    if ( $invoice->is_renewal() ) {
15
+    if ($invoice->is_renewal()) {
16 16
         return true;
17 17
     }
18 18
 
19 19
     return false;
20 20
 }
21 21
 
22
-function wpinv_payment_link_transaction_id( $invoice = '' ) {
23
-    if ( empty( $invoice ) ) {
22
+function wpinv_payment_link_transaction_id($invoice = '') {
23
+    if (empty($invoice)) {
24 24
         return false;
25 25
     }
26 26
     
27
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
28
-        $invoice = wpinv_get_invoice( $invoice );
27
+    if (!is_object($invoice) && is_scalar($invoice)) {
28
+        $invoice = wpinv_get_invoice($invoice);
29 29
     }
30 30
     
31
-    if ( empty( $invoice ) ) {
31
+    if (empty($invoice)) {
32 32
         return false;
33 33
     }
34 34
 
35
-    return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice );
35
+    return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice);
36 36
 }
37 37
 
38
-function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) {
39
-    $interval   = (int)$interval > 0 ? (int)$interval : 1;
38
+function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) {
39
+    $interval   = (int) $interval > 0 ? (int) $interval : 1;
40 40
     
41
-    if ( $trial_interval > 0 && !empty( $trial_period ) ) {
42
-        $amount = __( 'Free', 'invoicing' );
41
+    if ($trial_interval > 0 && !empty($trial_period)) {
42
+        $amount = __('Free', 'invoicing');
43 43
         $interval = $trial_interval;
44 44
         $period = $trial_period;
45 45
     }
46 46
     
47 47
     $description = '';
48
-    switch ( $period ) {
48
+    switch ($period) {
49 49
         case 'D' :
50 50
         case 'day' :
51
-            $description = wp_sprintf( _n( '%s for the first day.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval );
51
+            $description = wp_sprintf(_n('%s for the first day.', '%s for the first %d days.', $interval, 'invoicing'), $amount, $interval);
52 52
             break;
53 53
         case 'W' :
54 54
         case 'week' :
55
-            $description = wp_sprintf( _n( '%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval );
55
+            $description = wp_sprintf(_n('%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing'), $amount, $interval);
56 56
             break;
57 57
         case 'M' :
58 58
         case 'month' :
59
-            $description = wp_sprintf( _n( '%s for the first month.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval );
59
+            $description = wp_sprintf(_n('%s for the first month.', '%s for the first %d months.', $interval, 'invoicing'), $amount, $interval);
60 60
             break;
61 61
         case 'Y' :
62 62
         case 'year' :
63
-            $description = wp_sprintf( _n( '%s for the first year.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval );
63
+            $description = wp_sprintf(_n('%s for the first year.', '%s for the first %d years.', $interval, 'invoicing'), $amount, $interval);
64 64
             break;
65 65
     }
66 66
 
67
-    return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval  );
67
+    return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval);
68 68
 }
69 69
 
70
-function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) {
71
-    $interval   = (int)$interval > 0 ? (int)$interval : 1;
72
-    $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0;
70
+function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) {
71
+    $interval   = (int) $interval > 0 ? (int) $interval : 1;
72
+    $bill_times = (int) $bill_times > 0 ? (int) $bill_times : 0;
73 73
     
74 74
     $description = '';
75
-    switch ( $period ) {
75
+    switch ($period) {
76 76
         case 'D' :
77 77
         case 'day' :            
78
-            if ( (int)$bill_times > 0 ) {
79
-                if ( $interval > 1 ) {
80
-                    if ( $bill_times > 1 ) {
81
-                        $description = wp_sprintf( __( '%s for each %d days, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
78
+            if ((int) $bill_times > 0) {
79
+                if ($interval > 1) {
80
+                    if ($bill_times > 1) {
81
+                        $description = wp_sprintf(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
82 82
                     } else {
83
-                        $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval );
83
+                        $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval);
84 84
                     }
85 85
                 } else {
86
-                    $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
86
+                    $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
87 87
                 }
88 88
             } else {
89
-                $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval );
89
+                $description = wp_sprintf(_n('%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval);
90 90
             }
91 91
             break;
92 92
         case 'W' :
93 93
         case 'week' :            
94
-            if ( (int)$bill_times > 0 ) {
95
-                if ( $interval > 1 ) {
96
-                    if ( $bill_times > 1 ) {
97
-                        $description = wp_sprintf( __( '%s for each %d weeks, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
94
+            if ((int) $bill_times > 0) {
95
+                if ($interval > 1) {
96
+                    if ($bill_times > 1) {
97
+                        $description = wp_sprintf(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
98 98
                     } else {
99
-                        $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval );
99
+                        $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval);
100 100
                     }
101 101
                 } else {
102
-                    $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
102
+                    $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
103 103
                 }
104 104
             } else {
105
-                $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval );
105
+                $description = wp_sprintf(_n('%s for each week.', '%s for each %d weeks.', $interval, 'invoicing'), $amount, $interval);
106 106
             }
107 107
             break;
108 108
         case 'M' :
109 109
         case 'month' :            
110
-            if ( (int)$bill_times > 0 ) {
111
-                if ( $interval > 1 ) {
112
-                    if ( $bill_times > 1 ) {
113
-                        $description = wp_sprintf( __( '%s for each %d months, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
110
+            if ((int) $bill_times > 0) {
111
+                if ($interval > 1) {
112
+                    if ($bill_times > 1) {
113
+                        $description = wp_sprintf(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
114 114
                     } else {
115
-                        $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval );
115
+                        $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval);
116 116
                     }
117 117
                 } else {
118
-                    $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
118
+                    $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
119 119
                 }
120 120
             } else {
121
-                $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval );
121
+                $description = wp_sprintf(_n('%s for each month.', '%s for each %d months.', $interval, 'invoicing'), $amount, $interval);
122 122
             }
123 123
             break;
124 124
         case 'Y' :
125 125
         case 'year' :            
126
-            if ( (int)$bill_times > 0 ) {
127
-                if ( $interval > 1 ) {
128
-                    if ( $bill_times > 1 ) {
129
-                        $description = wp_sprintf( __( '%s for each %d years, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
126
+            if ((int) $bill_times > 0) {
127
+                if ($interval > 1) {
128
+                    if ($bill_times > 1) {
129
+                        $description = wp_sprintf(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
130 130
                     } else {
131
-                        $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval );
131
+                        $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval);
132 132
                     }
133 133
                 } else {
134
-                    $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
134
+                    $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
135 135
                 }
136 136
             } else {
137
-                $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval );
137
+                $description = wp_sprintf(_n('%s for each year.', '%s for each %d years.', $interval, 'invoicing'), $amount, $interval);
138 138
             }
139 139
             break;
140 140
     }
141 141
 
142
-    return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
142
+    return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
143 143
 }
144 144
 
145
-function wpinv_subscription_payment_desc( $invoice ) {
146
-    if ( empty( $invoice ) ) {
145
+function wpinv_subscription_payment_desc($invoice) {
146
+    if (empty($invoice)) {
147 147
         return NULL;
148 148
     }
149 149
 
150 150
     $description = '';
151
-    if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) {
152
-        if ( $item->has_free_trial() ) {
151
+    if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) {
152
+        if ($item->has_free_trial()) {
153 153
             $trial_period = $item->get_trial_period();
154 154
             $trial_interval = $item->get_trial_interval();
155 155
         } else {
@@ -157,40 +157,40 @@  discard block
 block discarded – undo
157 157
             $trial_interval = 0;
158 158
         }
159 159
         
160
-        $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() );
160
+        $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency());
161 161
     }
162 162
     
163
-    return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice );
163
+    return apply_filters('wpinv_subscription_payment_desc', $description, $invoice);
164 164
 }
165 165
 
166
-function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) {
167
-    $initial_total      = wpinv_round_amount( $initial );
168
-    $recurring_total    = wpinv_round_amount( $recurring );
166
+function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') {
167
+    $initial_total      = wpinv_round_amount($initial);
168
+    $recurring_total    = wpinv_round_amount($recurring);
169 169
     
170
-    if ( $trial_interval > 0 && !empty( $trial_period ) ) {
170
+    if ($trial_interval > 0 && !empty($trial_period)) {
171 171
         // Free trial
172 172
     } else {
173
-        if ( $bill_times == 1 ) {
173
+        if ($bill_times == 1) {
174 174
             $recurring_total = $initial_total;
175
-        } else if ( $bill_times > 1 && $initial_total != $recurring_total ) {
175
+        } else if ($bill_times > 1 && $initial_total != $recurring_total) {
176 176
             $bill_times--;
177 177
         }
178 178
     }
179 179
     
180
-    $initial_amount     = wpinv_price( $initial_total, $currency );
181
-    $recurring_amount   = wpinv_price( $recurring_total, $currency );
180
+    $initial_amount     = wpinv_price($initial_total, $currency);
181
+    $recurring_amount   = wpinv_price($recurring_total, $currency);
182 182
     
183
-    $recurring          = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
183
+    $recurring          = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
184 184
         
185
-    if ( $initial_total != $recurring_total ) {
186
-        $initial        = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval );
185
+    if ($initial_total != $recurring_total) {
186
+        $initial        = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval);
187 187
         
188
-        $description    = wp_sprintf( __( '%s Then %s', 'invoicing' ), $initial, $recurring );
188
+        $description    = wp_sprintf(__('%s Then %s', 'invoicing'), $initial, $recurring);
189 189
     } else {
190 190
         $description    = $recurring;
191 191
     }
192 192
     
193
-    return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency );
193
+    return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency);
194 194
 }
195 195
 
196 196
 /**
@@ -200,27 +200,27 @@  discard block
 block discarded – undo
200 200
  * @param string $card_number Card number.
201 201
  * @return string
202 202
  */
203
-function getpaid_get_card_name( $card_number ) {
203
+function getpaid_get_card_name($card_number) {
204 204
 
205 205
     // Known regexes.
206 206
     $regexes = array(
207
-        '/^4/'                     => __( 'Visa', 'invoicing' ),
208
-        '/^5[1-5]/'                => __( 'Mastercard', 'invoicing' ),
209
-        '/^3[47]/'                 => __( 'Amex', 'invoicing' ),
210
-        '/^3(?:0[0-5]|[68])/'      => __( 'Diners Club', 'invoicing' ),
211
-        '/^6(?:011|5)/'            => __( 'Discover', 'invoicing' ),
212
-        '/^(?:2131|1800|35\d{3})/' => __( 'JCB', 'invoicing' ),
207
+        '/^4/'                     => __('Visa', 'invoicing'),
208
+        '/^5[1-5]/'                => __('Mastercard', 'invoicing'),
209
+        '/^3[47]/'                 => __('Amex', 'invoicing'),
210
+        '/^3(?:0[0-5]|[68])/'      => __('Diners Club', 'invoicing'),
211
+        '/^6(?:011|5)/'            => __('Discover', 'invoicing'),
212
+        '/^(?:2131|1800|35\d{3})/' => __('JCB', 'invoicing'),
213 213
     );
214 214
 
215 215
     // Confirm if one matches.
216
-    foreach ( $regexes as $regex => $card ) {
217
-        if ( preg_match ( $regex, $card_number ) >= 1 ) {
216
+    foreach ($regexes as $regex => $card) {
217
+        if (preg_match($regex, $card_number) >= 1) {
218 218
             return $card;
219 219
         }
220 220
     }
221 221
 
222 222
     // None matched.
223
-    return __( 'Card', 'invoicing' );
223
+    return __('Card', 'invoicing');
224 224
 
225 225
 }
226 226
 
@@ -229,23 +229,23 @@  discard block
 block discarded – undo
229 229
  * 
230 230
  * @param WPInv_Invoice|int|null $invoice
231 231
  */
232
-function wpinv_send_back_to_checkout( $invoice = null ) {
233
-    $response = array( 'success' => false );
234
-    $invoice  = wpinv_get_invoice( $invoice );
232
+function wpinv_send_back_to_checkout($invoice = null) {
233
+    $response = array('success' => false);
234
+    $invoice  = wpinv_get_invoice($invoice);
235 235
 
236 236
     // Was an invoice created?
237
-    if ( ! empty( $invoice ) ) {
238
-        $invoice             = is_scalar( $invoice ) ? new WPInv_Invoice( $invoice ) : $invoice;
237
+    if (!empty($invoice)) {
238
+        $invoice             = is_scalar($invoice) ? new WPInv_Invoice($invoice) : $invoice;
239 239
         $response['invoice'] = $invoice->get_id();
240
-        do_action( 'getpaid_checkout_invoice_exception', $invoice );
240
+        do_action('getpaid_checkout_invoice_exception', $invoice);
241 241
     }
242 242
 
243 243
 	// Do we have any errors?
244
-    if ( wpinv_get_errors() ) {
245
-        $response['data'] = getpaid_get_errors_html( true, false );
244
+    if (wpinv_get_errors()) {
245
+        $response['data'] = getpaid_get_errors_html(true, false);
246 246
     } else {
247
-        $response['data'] = __( 'An error occured while processing your payment. Please try again.', 'invoicing' );
247
+        $response['data'] = __('An error occured while processing your payment. Please try again.', 'invoicing');
248 248
     }
249 249
 
250
-    wp_send_json( $response );
250
+    wp_send_json($response);
251 251
 }
Please login to merge, or discard this patch.
includes/admin/class-wpinv-admin-menus.php 2 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -24,14 +24,14 @@
 block discarded – undo
24 24
     }
25 25
 
26 26
     /**
27
-	 * Highlights sub menus.
28
-	 */
29
-	public function set_admin_menu_class() {
30
-		global $current_screen, $parent_file, $submenu_file;
27
+     * Highlights sub menus.
28
+     */
29
+    public function set_admin_menu_class() {
30
+        global $current_screen, $parent_file, $submenu_file;
31 31
 
32 32
         if ( ! empty( $current_screen->id ) && in_array( $current_screen->id , array( 'wpi_discount', 'wpi_payment_form', 'wpi_invoice' ) ) ) {
33
-			$parent_file = 'wpinv';
34
-			$submenu_file = 'edit.php?post_type=' . $current_screen->id;
33
+            $parent_file = 'wpinv';
34
+            $submenu_file = 'edit.php?post_type=' . $current_screen->id;
35 35
         }
36 36
 
37 37
     }
Please login to merge, or discard this patch.
Spacing   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Setup menus in WP admin.
4 4
  */
5 5
 
6
-defined( 'ABSPATH' ) || exit;
6
+defined('ABSPATH') || exit;
7 7
 
8 8
 /**
9 9
  * WC_Admin_Menus Class.
@@ -13,14 +13,14 @@  discard block
 block discarded – undo
13 13
      * Hook in tabs.
14 14
      */
15 15
     public function __construct() {
16
-        add_action( 'admin_head', array( $this, 'set_admin_menu_class' ) );
17
-        add_action( 'admin_menu', array( $this, 'admin_menu' ), 10 );
18
-        add_action( 'admin_menu', array( $this, 'add_customers_menu' ), 18 );
19
-        add_action( 'admin_menu', array( $this, 'add_subscriptions_menu' ), 40 );
20
-        add_action( 'admin_menu', array( $this, 'add_addons_menu' ), 100 );
21
-        add_action( 'admin_menu', array( $this, 'add_settings_menu' ), 60 );
22
-        add_action( 'admin_menu', array( $this, 'remove_admin_submenus' ), 10 );
23
-        add_action( 'admin_head-nav-menus.php', array( $this, 'add_nav_menu_meta_boxes' ) );
16
+        add_action('admin_head', array($this, 'set_admin_menu_class'));
17
+        add_action('admin_menu', array($this, 'admin_menu'), 10);
18
+        add_action('admin_menu', array($this, 'add_customers_menu'), 18);
19
+        add_action('admin_menu', array($this, 'add_subscriptions_menu'), 40);
20
+        add_action('admin_menu', array($this, 'add_addons_menu'), 100);
21
+        add_action('admin_menu', array($this, 'add_settings_menu'), 60);
22
+        add_action('admin_menu', array($this, 'remove_admin_submenus'), 10);
23
+        add_action('admin_head-nav-menus.php', array($this, 'add_nav_menu_meta_boxes'));
24 24
     }
25 25
 
26 26
     /**
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	public function set_admin_menu_class() {
30 30
 		global $current_screen, $parent_file, $submenu_file;
31 31
 
32
-        if ( ! empty( $current_screen->id ) && in_array( $current_screen->id , array( 'wpi_discount', 'wpi_payment_form', 'wpi_invoice' ) ) ) {
32
+        if (!empty($current_screen->id) && in_array($current_screen->id, array('wpi_discount', 'wpi_payment_form', 'wpi_invoice'))) {
33 33
 			$parent_file = 'wpinv';
34 34
 			$submenu_file = 'edit.php?post_type=' . $current_screen->id;
35 35
         }
@@ -38,14 +38,14 @@  discard block
 block discarded – undo
38 38
 
39 39
     public function admin_menu() {
40 40
 
41
-        $capability = apply_filters( 'invoicing_capability', wpinv_get_capability() );
41
+        $capability = apply_filters('invoicing_capability', wpinv_get_capability());
42 42
         add_menu_page(
43
-            __( 'GetPaid', 'invoicing' ),
44
-            __( 'GetPaid', 'invoicing' ),
43
+            __('GetPaid', 'invoicing'),
44
+            __('GetPaid', 'invoicing'),
45 45
             $capability,
46 46
             'wpinv',
47 47
             null,
48
-            'data:image/svg+xml;base64,' . base64_encode( file_get_contents( WPINV_PLUGIN_DIR . 'assets/images/GetPaid.svg' ) ),
48
+            'data:image/svg+xml;base64,' . base64_encode(file_get_contents(WPINV_PLUGIN_DIR . 'assets/images/GetPaid.svg')),
49 49
             '54.123460'
50 50
         );
51 51
 
@@ -57,11 +57,11 @@  discard block
 block discarded – undo
57 57
     public function add_customers_menu() {
58 58
         add_submenu_page(
59 59
             'wpinv',
60
-            __( 'Customers', 'invoicing' ),
61
-            __( 'Customers', 'invoicing' ),
60
+            __('Customers', 'invoicing'),
61
+            __('Customers', 'invoicing'),
62 62
             wpinv_get_capability(),
63 63
             'wpinv-customers',
64
-            array( $this, 'customers_page' )
64
+            array($this, 'customers_page')
65 65
         );
66 66
     }
67 67
 
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
     public function add_subscriptions_menu() {
72 72
         add_submenu_page(
73 73
             'wpinv',
74
-            __( 'Subscriptions', 'invoicing' ),
75
-            __( 'Subscriptions', 'invoicing' ),
74
+            __('Subscriptions', 'invoicing'),
75
+            __('Subscriptions', 'invoicing'),
76 76
             wpinv_get_capability(),
77 77
             'wpinv-subscriptions',
78 78
             'wpinv_subscriptions_page'
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
      * Displays the customers page.
84 84
      */
85 85
     public function customers_page() {
86
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-customers-table.php' );
86
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-customers-table.php');
87 87
         ?>
88 88
         <div class="wrap wpi-customers-wrap">
89 89
             <style>
@@ -91,12 +91,12 @@  discard block
 block discarded – undo
91 91
                     width: 30%;
92 92
                 }
93 93
             </style>
94
-            <h1><?php echo esc_html( __( 'Customers', 'invoicing' ) ); ?>&nbsp;<a href="<?php echo wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'download_customers' ), 'getpaid-nonce', 'getpaid-nonce' ); ?>" class="page-title-action"><?php _e( 'Export', 'invoicing' ); ?></a></h1>
94
+            <h1><?php echo esc_html(__('Customers', 'invoicing')); ?>&nbsp;<a href="<?php echo wp_nonce_url(add_query_arg('getpaid-admin-action', 'download_customers'), 'getpaid-nonce', 'getpaid-nonce'); ?>" class="page-title-action"><?php _e('Export', 'invoicing'); ?></a></h1>
95 95
             <form method="post">
96 96
             <?php
97 97
                 $table = new WPInv_Customers_Table();
98 98
                 $table->prepare_items();
99
-                $table->search_box( __( 'Search Customers', 'invoicing' ), 'search-customers' );
99
+                $table->search_box(__('Search Customers', 'invoicing'), 'search-customers');
100 100
                 $table->display();
101 101
             ?>
102 102
             </form>
@@ -110,16 +110,16 @@  discard block
 block discarded – undo
110 110
     public function add_settings_menu() {
111 111
         add_submenu_page(
112 112
             'wpinv',
113
-            __( 'Invoice Settings', 'invoicing' ),
114
-            __( 'Settings', 'invoicing' ),
115
-            apply_filters( 'invoicing_capability', wpinv_get_capability() ),
113
+            __('Invoice Settings', 'invoicing'),
114
+            __('Settings', 'invoicing'),
115
+            apply_filters('invoicing_capability', wpinv_get_capability()),
116 116
             'wpinv-settings',
117
-            array( $this, 'options_page' )
117
+            array($this, 'options_page')
118 118
         );
119 119
     }
120 120
 
121
-    public function add_addons_menu(){
122
-        if ( !apply_filters( 'wpi_show_addons_page', true ) ) {
121
+    public function add_addons_menu() {
122
+        if (!apply_filters('wpi_show_addons_page', true)) {
123 123
             return;
124 124
         }
125 125
 
@@ -129,80 +129,80 @@  discard block
 block discarded – undo
129 129
             __('Extensions', 'invoicing'),
130 130
             'manage_options',
131 131
             'wpi-addons',
132
-            array( $this, 'addons_page' )
132
+            array($this, 'addons_page')
133 133
         );
134 134
     }
135 135
 
136
-    public function addons_page(){
136
+    public function addons_page() {
137 137
         $addon_obj = new WPInv_Admin_Addons();
138 138
         $addon_obj->output();
139 139
     }
140 140
 
141 141
     function options_page() {
142
-        $page       = isset( $_GET['page'] )                ? strtolower( $_GET['page'] )               : false;
142
+        $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
143 143
 
144
-        if ( $page !== 'wpinv-settings' ) {
144
+        if ($page !== 'wpinv-settings') {
145 145
             return;
146 146
         }
147 147
 
148 148
         $settings_tabs = wpinv_get_settings_tabs();
149 149
         $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs;
150
-        $active_tab    = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general';
151
-        $sections      = wpinv_get_settings_tab_sections( $active_tab );
150
+        $active_tab    = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general';
151
+        $sections      = wpinv_get_settings_tab_sections($active_tab);
152 152
         $key           = 'main';
153 153
 
154
-        if ( is_array( $sections ) ) {
155
-            $key = key( $sections );
154
+        if (is_array($sections)) {
155
+            $key = key($sections);
156 156
         }
157 157
 
158 158
         add_thickbox();
159 159
 
160
-        $registered_sections = wpinv_get_settings_tab_sections( $active_tab );
161
-        $section             = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key;
160
+        $registered_sections = wpinv_get_settings_tab_sections($active_tab);
161
+        $section             = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key;
162 162
         ob_start();
163 163
         ?>
164 164
         <div class="wrap">
165 165
             <h1 class="nav-tab-wrapper">
166 166
                 <?php
167
-                foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) {
168
-                    $tab_url = add_query_arg( array(
167
+                foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) {
168
+                    $tab_url = add_query_arg(array(
169 169
                         'settings-updated' => false,
170 170
                         'tab' => $tab_id,
171
-                    ) );
171
+                    ));
172 172
 
173 173
                     // Remove the section from the tabs so we always end up at the main section
174
-                    $tab_url = remove_query_arg( 'section', $tab_url );
175
-                    $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
174
+                    $tab_url = remove_query_arg('section', $tab_url);
175
+                    $tab_url = remove_query_arg('wpi_sub', $tab_url);
176 176
 
177 177
                     $active = $active_tab == $tab_id ? ' nav-tab-active' : '';
178 178
 
179
-                    echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">';
180
-                    echo esc_html( $tab_name );
179
+                    echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">';
180
+                    echo esc_html($tab_name);
181 181
                     echo '</a>';
182 182
                 }
183 183
                 ?>
184 184
             </h1>
185 185
             <?php
186
-            $number_of_sections = count( $sections );
186
+            $number_of_sections = count($sections);
187 187
             $number = 0;
188
-            if ( $number_of_sections > 1 ) {
188
+            if ($number_of_sections > 1) {
189 189
                 echo '<div><ul class="subsubsub">';
190
-                foreach( $sections as $section_id => $section_name ) {
190
+                foreach ($sections as $section_id => $section_name) {
191 191
                     echo '<li>';
192 192
                     $number++;
193
-                    $tab_url = add_query_arg( array(
193
+                    $tab_url = add_query_arg(array(
194 194
                         'settings-updated' => false,
195 195
                         'tab' => $active_tab,
196 196
                         'section' => $section_id
197
-                    ) );
198
-                    $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
197
+                    ));
198
+                    $tab_url = remove_query_arg('wpi_sub', $tab_url);
199 199
                     $class = '';
200
-                    if ( $section == $section_id ) {
200
+                    if ($section == $section_id) {
201 201
                         $class = 'current';
202 202
                     }
203
-                    echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>';
203
+                    echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>';
204 204
 
205
-                    if ( $number != $number_of_sections ) {
205
+                    if ($number != $number_of_sections) {
206 206
                         echo ' | ';
207 207
                     }
208 208
                     echo '</li>';
@@ -214,20 +214,20 @@  discard block
 block discarded – undo
214 214
                 <form method="post" action="options.php">
215 215
                     <table class="form-table">
216 216
                         <?php
217
-                        settings_fields( 'wpinv_settings' );
217
+                        settings_fields('wpinv_settings');
218 218
 
219
-                        if ( 'main' === $section ) {
220
-                            do_action( 'wpinv_settings_tab_top', $active_tab );
219
+                        if ('main' === $section) {
220
+                            do_action('wpinv_settings_tab_top', $active_tab);
221 221
                         }
222 222
 
223
-                        do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section );
224
-                        do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section );
225
-                        do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section );
226
-                        do_action( 'getpaid_settings_tab_bottom', $active_tab, $section );
223
+                        do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section);
224
+                        do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section);
225
+                        do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section);
226
+                        do_action('getpaid_settings_tab_bottom', $active_tab, $section);
227 227
 
228 228
                         // For backwards compatibility
229
-                        if ( 'main' === $section ) {
230
-                            do_action( 'wpinv_settings_tab_bottom', $active_tab );
229
+                        if ('main' === $section) {
230
+                            do_action('wpinv_settings_tab_bottom', $active_tab);
231 231
                         }
232 232
                         ?>
233 233
                     </table>
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
     }
242 242
 
243 243
     public function remove_admin_submenus() {
244
-        remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' );
244
+        remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice');
245 245
     }
246 246
 
247 247
     /**
@@ -251,8 +251,8 @@  discard block
 block discarded – undo
251 251
 
252 252
         add_meta_box(
253 253
             'wpinv_endpoints_nav_link',
254
-            __( 'GetPaid endpoints', 'invoicing' ),
255
-            array( $this, 'nav_menu_links' ),
254
+            __('GetPaid endpoints', 'invoicing'),
255
+            array($this, 'nav_menu_links'),
256 256
             'nav-menus',
257 257
             'side',
258 258
             'low'
@@ -267,12 +267,12 @@  discard block
 block discarded – undo
267 267
         $endpoints = $this->get_menu_items();
268 268
         ?>
269 269
         <div id="invoicing-endpoints" class="posttypediv">
270
-            <?php if ( ! empty( $endpoints['pages'] ) ) : ?>
270
+            <?php if (!empty($endpoints['pages'])) : ?>
271 271
                 <div id="tabs-panel-invoicing-endpoints" class="tabs-panel tabs-panel-active">
272 272
                     <ul id="invoicing-endpoints-checklist" class="categorychecklist form-no-clear">
273 273
                         <?php
274
-                            $walker = new Walker_Nav_Menu_Checklist( array() );
275
-                            echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $endpoints['pages'] ), 0, (object) array( 'walker' => $walker ) );
274
+                            $walker = new Walker_Nav_Menu_Checklist(array());
275
+                            echo walk_nav_menu_tree(array_map('wp_setup_nav_menu_item', $endpoints['pages']), 0, (object) array('walker' => $walker));
276 276
                         ?>
277 277
                     </ul>
278 278
                 </div>
@@ -281,11 +281,11 @@  discard block
 block discarded – undo
281 281
             <p class="button-controls wp-clearfix" data-items-type="invoicing-endpoints">
282 282
                 <span class="list-controls hide-if-no-js">
283 283
                     <input type="checkbox" id="invoicing-endpoints-tab" class="select-all">
284
-                    <label for="invoicing-endpoints-tab"><?php _e( 'Select all', 'invoicing' ); ?></label>
284
+                    <label for="invoicing-endpoints-tab"><?php _e('Select all', 'invoicing'); ?></label>
285 285
                 </span>
286 286
 
287 287
                 <span class="add-to-menu">
288
-                    <input type="submit" class="button submit-add-to-menu right" value="<?php esc_attr_e( 'Add to menu', 'invoicing' ); ?>" name="add-invoicing-endpoints-item" id="submit-invoicing-endpoints">
288
+                    <input type="submit" class="button submit-add-to-menu right" value="<?php esc_attr_e('Add to menu', 'invoicing'); ?>" name="add-invoicing-endpoints-item" id="submit-invoicing-endpoints">
289 289
                     <span class="spinner"></span>
290 290
                 </span>
291 291
             </p>
@@ -298,35 +298,35 @@  discard block
 block discarded – undo
298 298
      *
299 299
      * @return array.
300 300
      */
301
-    public function get_menu_items(){
301
+    public function get_menu_items() {
302 302
         $items = array();
303 303
 
304 304
         $pages = array(
305 305
             array(
306
-                'id'    => wpinv_get_option( 'invoice_history_page' ),
307
-                'label' => __( 'My Invoices', 'invoicing' ),
306
+                'id'    => wpinv_get_option('invoice_history_page'),
307
+                'label' => __('My Invoices', 'invoicing'),
308 308
             ),
309 309
             array(
310
-                'id'    => wpinv_get_option( 'invoice_subscription_page' ),
311
-                'label' => __( 'My Subscriptions', 'invoicing' ),
310
+                'id'    => wpinv_get_option('invoice_subscription_page'),
311
+                'label' => __('My Subscriptions', 'invoicing'),
312 312
             )
313 313
         );
314 314
 
315
-        foreach ( apply_filters( 'getpaid_menu_pages', $pages ) as $page ) {
315
+        foreach (apply_filters('getpaid_menu_pages', $pages) as $page) {
316 316
 
317
-            if ( (int) $page['id'] > 0 ) {
317
+            if ((int) $page['id'] > 0) {
318 318
 
319 319
                 $item                   = new stdClass();
320 320
                 $item->object_id        = (int) $page['id'];
321 321
                 $item->db_id            = 0;
322
-                $item->object           =  'page';
322
+                $item->object           = 'page';
323 323
                 $item->menu_item_parent = 0;
324 324
                 $item->type             = 'post_type';
325
-                $item->title            = sanitize_text_field( $page['label'] );
326
-                $item->url              = get_permalink( (int) $page['id'] );
325
+                $item->title            = sanitize_text_field($page['label']);
326
+                $item->url              = get_permalink((int) $page['id']);
327 327
                 $item->target           = '';
328 328
                 $item->attr_title       = '';
329
-                $item->classes          = array( 'wpinv-menu-item' );
329
+                $item->classes          = array('wpinv-menu-item');
330 330
                 $item->xfn              = '';
331 331
 
332 332
                 $items['pages'][]       = $item;
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
 
336 336
         }
337 337
 
338
-        return apply_filters( 'wpinv_menu_items', $items );
338
+        return apply_filters('wpinv_menu_items', $items);
339 339
     }
340 340
 
341 341
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-post-types-admin.php 2 patches
Indentation   +653 added lines, -653 removed lines patch added patch discarded remove patch
@@ -13,648 +13,648 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Post_Types_Admin {
14 14
 
15 15
     /**
16
-	 * Hook in methods.
17
-	 */
18
-	public static function init() {
19
-
20
-		// Init metaboxes.
21
-		GetPaid_Metaboxes::init();
22
-
23
-		// Filter the post updated messages.
24
-		add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
25
-
26
-		// Filter post actions.
27
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
28
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 );
29
-
30
-		// Invoice table columns.
31
-		add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
32
-		add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
33
-
34
-		// Items table columns.
35
-		add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
36
-		add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
37
-		add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
38
-		add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
39
-		add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
40
-		add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
41
-
42
-		// Payment forms columns.
43
-		add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
44
-		add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
45
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
46
-
47
-		// Discount table columns.
48
-		add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
49
-		add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 );
50
-
51
-		// Deleting posts.
52
-		add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
53
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
54
-
55
-		add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 );
56
-	}
57
-
58
-	/**
59
-	 * Post updated messages.
60
-	 */
61
-	public static function post_updated_messages( $messages ) {
62
-		global $post;
63
-
64
-		$messages['wpi_discount'] = array(
65
-			0   => '',
66
-			1   => __( 'Discount updated.', 'invoicing' ),
67
-			2   => __( 'Custom field updated.', 'invoicing' ),
68
-			3   => __( 'Custom field deleted.', 'invoicing' ),
69
-			4   => __( 'Discount updated.', 'invoicing' ),
70
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
71
-			6   => __( 'Discount updated.', 'invoicing' ),
72
-			7   => __( 'Discount saved.', 'invoicing' ),
73
-			8   => __( 'Discount submitted.', 'invoicing' ),
74
-			9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
75
-			10  => __( 'Discount draft updated.', 'invoicing' ),
76
-		);
77
-
78
-		$messages['wpi_payment_form'] = array(
79
-			0   => '',
80
-			1   => __( 'Payment Form updated.', 'invoicing' ),
81
-			2   => __( 'Custom field updated.', 'invoicing' ),
82
-			3   => __( 'Custom field deleted.', 'invoicing' ),
83
-			4   => __( 'Payment Form updated.', 'invoicing' ),
84
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
85
-			6   => __( 'Payment Form updated.', 'invoicing' ),
86
-			7   => __( 'Payment Form saved.', 'invoicing' ),
87
-			8   => __( 'Payment Form submitted.', 'invoicing' ),
88
-			9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
89
-			10  => __( 'Payment Form draft updated.', 'invoicing' ),
90
-		);
91
-
92
-		return $messages;
93
-
94
-	}
95
-
96
-	/**
97
-	 * Post row actions.
98
-	 */
99
-	public static function post_row_actions( $actions, $post ) {
100
-
101
-		$post = get_post( $post );
102
-
103
-		// We do not want to edit the default payment form.
104
-		if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
105
-			unset( $actions['trash'] );
106
-			unset( $actions['inline hide-if-no-js'] );
107
-		}
108
-
109
-		return $actions;
110
-	}
111
-
112
-	/**
16
+     * Hook in methods.
17
+     */
18
+    public static function init() {
19
+
20
+        // Init metaboxes.
21
+        GetPaid_Metaboxes::init();
22
+
23
+        // Filter the post updated messages.
24
+        add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
25
+
26
+        // Filter post actions.
27
+        add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
28
+        add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 );
29
+
30
+        // Invoice table columns.
31
+        add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
32
+        add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
33
+
34
+        // Items table columns.
35
+        add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
36
+        add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
37
+        add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
38
+        add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
39
+        add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
40
+        add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
41
+
42
+        // Payment forms columns.
43
+        add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
44
+        add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
45
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
46
+
47
+        // Discount table columns.
48
+        add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
49
+        add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 );
50
+
51
+        // Deleting posts.
52
+        add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
53
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
54
+
55
+        add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 );
56
+    }
57
+
58
+    /**
59
+     * Post updated messages.
60
+     */
61
+    public static function post_updated_messages( $messages ) {
62
+        global $post;
63
+
64
+        $messages['wpi_discount'] = array(
65
+            0   => '',
66
+            1   => __( 'Discount updated.', 'invoicing' ),
67
+            2   => __( 'Custom field updated.', 'invoicing' ),
68
+            3   => __( 'Custom field deleted.', 'invoicing' ),
69
+            4   => __( 'Discount updated.', 'invoicing' ),
70
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
71
+            6   => __( 'Discount updated.', 'invoicing' ),
72
+            7   => __( 'Discount saved.', 'invoicing' ),
73
+            8   => __( 'Discount submitted.', 'invoicing' ),
74
+            9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
75
+            10  => __( 'Discount draft updated.', 'invoicing' ),
76
+        );
77
+
78
+        $messages['wpi_payment_form'] = array(
79
+            0   => '',
80
+            1   => __( 'Payment Form updated.', 'invoicing' ),
81
+            2   => __( 'Custom field updated.', 'invoicing' ),
82
+            3   => __( 'Custom field deleted.', 'invoicing' ),
83
+            4   => __( 'Payment Form updated.', 'invoicing' ),
84
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
85
+            6   => __( 'Payment Form updated.', 'invoicing' ),
86
+            7   => __( 'Payment Form saved.', 'invoicing' ),
87
+            8   => __( 'Payment Form submitted.', 'invoicing' ),
88
+            9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
89
+            10  => __( 'Payment Form draft updated.', 'invoicing' ),
90
+        );
91
+
92
+        return $messages;
93
+
94
+    }
95
+
96
+    /**
97
+     * Post row actions.
98
+     */
99
+    public static function post_row_actions( $actions, $post ) {
100
+
101
+        $post = get_post( $post );
102
+
103
+        // We do not want to edit the default payment form.
104
+        if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
105
+            unset( $actions['trash'] );
106
+            unset( $actions['inline hide-if-no-js'] );
107
+        }
108
+
109
+        return $actions;
110
+    }
111
+
112
+    /**
113 113
      * Remove bulk edit option from admin side quote listing
114 114
      *
115 115
      * @since    1.0.0
116 116
      * @param array $actions post actions
117
-	 * @param WP_Post $post
117
+     * @param WP_Post $post
118 118
      * @return array $actions actions without edit option
119 119
      */
120 120
     public static function filter_invoice_row_actions( $actions, $post ) {
121 121
 
122 122
         if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
123 123
 
124
-			$actions = array();
125
-			$invoice = new WPInv_Invoice( $post );
126
-
127
-			$actions['edit'] =  sprintf(
128
-				'<a href="%1$s">%2$s</a>',
129
-				esc_url( get_edit_post_link( $invoice->get_id() ) ),
130
-				esc_html( __( 'Edit', 'invoicing' ) )
131
-			);
132
-
133
-			if ( ! $invoice->is_draft() ) {
134
-
135
-				$actions['view'] =  sprintf(
136
-					'<a href="%1$s">%2$s</a>',
137
-					esc_url( $invoice->get_view_url() ),
138
-					sprintf(
139
-						esc_html( __( 'View %s', 'invoicing' ) ),
140
-						getpaid_get_post_type_label( $invoice->get_post_type(), false )
141
-					)
142
-				);
143
-
144
-				$actions['send'] =  sprintf(
145
-					'<a href="%1$s">%2$s</a>',
146
-					esc_url(
147
-						wp_nonce_url(
148
-							add_query_arg(
149
-								array(
150
-									'getpaid-admin-action' => 'send_invoice',
151
-									'invoice_id'           => $invoice->get_id()
152
-								)
153
-							),
154
-							'getpaid-nonce',
155
-							'getpaid-nonce'
156
-						)
157
-					),
158
-					esc_html( __( 'Send to Customer', 'invoicing' ) )
159
-				);
160
-
161
-			}
124
+            $actions = array();
125
+            $invoice = new WPInv_Invoice( $post );
126
+
127
+            $actions['edit'] =  sprintf(
128
+                '<a href="%1$s">%2$s</a>',
129
+                esc_url( get_edit_post_link( $invoice->get_id() ) ),
130
+                esc_html( __( 'Edit', 'invoicing' ) )
131
+            );
132
+
133
+            if ( ! $invoice->is_draft() ) {
134
+
135
+                $actions['view'] =  sprintf(
136
+                    '<a href="%1$s">%2$s</a>',
137
+                    esc_url( $invoice->get_view_url() ),
138
+                    sprintf(
139
+                        esc_html( __( 'View %s', 'invoicing' ) ),
140
+                        getpaid_get_post_type_label( $invoice->get_post_type(), false )
141
+                    )
142
+                );
143
+
144
+                $actions['send'] =  sprintf(
145
+                    '<a href="%1$s">%2$s</a>',
146
+                    esc_url(
147
+                        wp_nonce_url(
148
+                            add_query_arg(
149
+                                array(
150
+                                    'getpaid-admin-action' => 'send_invoice',
151
+                                    'invoice_id'           => $invoice->get_id()
152
+                                )
153
+                            ),
154
+                            'getpaid-nonce',
155
+                            'getpaid-nonce'
156
+                        )
157
+                    ),
158
+                    esc_html( __( 'Send to Customer', 'invoicing' ) )
159
+                );
160
+
161
+            }
162 162
 
163 163
         }
164 164
 
165 165
         return $actions;
166
-	}
167
-
168
-	/**
169
-	 * Returns an array of invoice table columns.
170
-	 */
171
-	public static function invoice_columns( $columns ) {
172
-
173
-		$columns = array(
174
-			'cb'                => $columns['cb'],
175
-			'number'            => __( 'Invoice', 'invoicing' ),
176
-			'customer'          => __( 'Customer', 'invoicing' ),
177
-			'invoice_date'      => __( 'Created', 'invoicing' ),
178
-			'payment_date'      => __( 'Completed', 'invoicing' ),
179
-			'amount'            => __( 'Amount', 'invoicing' ),
180
-			'recurring'         => __( 'Recurring', 'invoicing' ),
181
-			'status'            => __( 'Status', 'invoicing' ),
182
-		);
183
-
184
-		return apply_filters( 'wpi_invoice_table_columns', $columns );
185
-	}
186
-
187
-	/**
188
-	 * Displays invoice table columns.
189
-	 */
190
-	public static function display_invoice_columns( $column_name, $post_id ) {
191
-
192
-		$invoice = new WPInv_Invoice( $post_id );
193
-
194
-		switch ( $column_name ) {
195
-
196
-			case 'invoice_date' :
197
-				$date_time = esc_attr( $invoice->get_created_date() );
198
-				$date      = getpaid_format_date_value( $date_time, "&mdash;", true );
199
-				echo "<span title='$date_time'>$date</span>";
200
-				break;
201
-
202
-			case 'payment_date' :
203
-
204
-				if ( $invoice->is_paid() ) {
205
-					$date_time = esc_attr( $invoice->get_completed_date() );
206
-					$date      = getpaid_format_date_value( $date_time, "&mdash;", true );
207
-					echo "<span title='$date_time'>$date</span>";
208
-				} else {
209
-					echo "&mdash;";
210
-				}
166
+    }
167
+
168
+    /**
169
+     * Returns an array of invoice table columns.
170
+     */
171
+    public static function invoice_columns( $columns ) {
172
+
173
+        $columns = array(
174
+            'cb'                => $columns['cb'],
175
+            'number'            => __( 'Invoice', 'invoicing' ),
176
+            'customer'          => __( 'Customer', 'invoicing' ),
177
+            'invoice_date'      => __( 'Created', 'invoicing' ),
178
+            'payment_date'      => __( 'Completed', 'invoicing' ),
179
+            'amount'            => __( 'Amount', 'invoicing' ),
180
+            'recurring'         => __( 'Recurring', 'invoicing' ),
181
+            'status'            => __( 'Status', 'invoicing' ),
182
+        );
183
+
184
+        return apply_filters( 'wpi_invoice_table_columns', $columns );
185
+    }
186
+
187
+    /**
188
+     * Displays invoice table columns.
189
+     */
190
+    public static function display_invoice_columns( $column_name, $post_id ) {
191
+
192
+        $invoice = new WPInv_Invoice( $post_id );
193
+
194
+        switch ( $column_name ) {
195
+
196
+            case 'invoice_date' :
197
+                $date_time = esc_attr( $invoice->get_created_date() );
198
+                $date      = getpaid_format_date_value( $date_time, "&mdash;", true );
199
+                echo "<span title='$date_time'>$date</span>";
200
+                break;
201
+
202
+            case 'payment_date' :
203
+
204
+                if ( $invoice->is_paid() ) {
205
+                    $date_time = esc_attr( $invoice->get_completed_date() );
206
+                    $date      = getpaid_format_date_value( $date_time, "&mdash;", true );
207
+                    echo "<span title='$date_time'>$date</span>";
208
+                } else {
209
+                    echo "&mdash;";
210
+                }
211 211
 				
212
-				break;
212
+                break;
213 213
 
214
-			case 'amount' :
214
+            case 'amount' :
215 215
 
216
-				$amount = $invoice->get_total();
217
-				$formated_amount = wpinv_price( $amount, $invoice->get_currency() );
216
+                $amount = $invoice->get_total();
217
+                $formated_amount = wpinv_price( $amount, $invoice->get_currency() );
218 218
 
219
-				if ( $invoice->is_refunded() ) {
220
-					$refunded_amount = wpinv_price( 0, $invoice->get_currency() );
221
-					echo "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>";
222
-				} else {
219
+                if ( $invoice->is_refunded() ) {
220
+                    $refunded_amount = wpinv_price( 0, $invoice->get_currency() );
221
+                    echo "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>";
222
+                } else {
223 223
 
224
-					$discount = $invoice->get_total_discount();
224
+                    $discount = $invoice->get_total_discount();
225 225
 
226
-					if ( ! empty( $discount ) ) {
227
-						$new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() );
228
-						echo "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>";
229
-					} else {
230
-						echo $formated_amount;
231
-					}
226
+                    if ( ! empty( $discount ) ) {
227
+                        $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() );
228
+                        echo "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>";
229
+                    } else {
230
+                        echo $formated_amount;
231
+                    }
232 232
 
233
-				}
233
+                }
234 234
 
235
-				break;
235
+                break;
236 236
 
237
-			case 'status' :
238
-				$status       = sanitize_text_field( $invoice->get_status() );
239
-				$status_label = sanitize_text_field( $invoice->get_status_nicename() );
237
+            case 'status' :
238
+                $status       = sanitize_text_field( $invoice->get_status() );
239
+                $status_label = sanitize_text_field( $invoice->get_status_nicename() );
240 240
 
241
-				// If it is paid, show the gateway title.
242
-				if ( $invoice->is_paid() ) {
243
-					$gateway = sanitize_text_field( $invoice->get_gateway_title() );
244
-					$gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
241
+                // If it is paid, show the gateway title.
242
+                if ( $invoice->is_paid() ) {
243
+                    $gateway = sanitize_text_field( $invoice->get_gateway_title() );
244
+                    $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
245 245
 
246
-					echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
247
-				} else {
248
-					echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
249
-				}
246
+                    echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
247
+                } else {
248
+                    echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
249
+                }
250 250
 
251
-				// If it is not paid, display the overdue and view status.
252
-				if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
251
+                // If it is not paid, display the overdue and view status.
252
+                if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
253 253
 
254
-					// Invoice view status.
255
-					if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
256
-						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
257
-					} else {
258
-						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
259
-					}
254
+                    // Invoice view status.
255
+                    if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
256
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
257
+                    } else {
258
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
259
+                    }
260 260
 
261
-					// Display the overview status.
262
-					if ( wpinv_get_option( 'overdue_active' ) ) {
263
-						$due_date = $invoice->get_due_date();
264
-						$fomatted = getpaid_format_date( $due_date );
261
+                    // Display the overview status.
262
+                    if ( wpinv_get_option( 'overdue_active' ) ) {
263
+                        $due_date = $invoice->get_due_date();
264
+                        $fomatted = getpaid_format_date( $due_date );
265 265
 
266
-						if ( ! empty( $fomatted ) ) {
267
-							$date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
268
-							echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
269
-						}
270
-					}
266
+                        if ( ! empty( $fomatted ) ) {
267
+                            $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
268
+                            echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
269
+                        }
270
+                    }
271 271
 
272
-				}
272
+                }
273 273
 
274
-				break;
274
+                break;
275 275
 
276
-			case 'recurring':
276
+            case 'recurring':
277 277
 
278
-				if ( $invoice->is_recurring() ) {
279
-					echo '<i class="fa fa-check" style="color:#43850a;"></i>';
280
-				} else {
281
-					echo '<i class="fa fa-times" style="color:#616161;"></i>';
282
-				}
283
-				break;
278
+                if ( $invoice->is_recurring() ) {
279
+                    echo '<i class="fa fa-check" style="color:#43850a;"></i>';
280
+                } else {
281
+                    echo '<i class="fa fa-times" style="color:#616161;"></i>';
282
+                }
283
+                break;
284 284
 
285
-			case 'number' :
285
+            case 'number' :
286 286
 
287
-				$edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
288
-				$invoice_number  = sanitize_text_field( $invoice->get_number() );
289
-				$invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
287
+                $edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
288
+                $invoice_number  = sanitize_text_field( $invoice->get_number() );
289
+                $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
290 290
 
291
-				echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
291
+                echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
292 292
 
293
-				break;
293
+                break;
294 294
 
295
-			case 'customer' :
295
+            case 'customer' :
296 296
 	
297
-				$customer_name = $invoice->get_user_full_name();
297
+                $customer_name = $invoice->get_user_full_name();
298 298
 	
299
-				if ( empty( $customer_name ) ) {
300
-					$customer_name = $invoice->get_email();
301
-				}
299
+                if ( empty( $customer_name ) ) {
300
+                    $customer_name = $invoice->get_email();
301
+                }
302 302
 	
303
-				if ( ! empty( $customer_name ) ) {
304
-					$customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
305
-					$view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
306
-					echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
307
-				} else {
308
-					echo '<div>&mdash;</div>';
309
-				}
303
+                if ( ! empty( $customer_name ) ) {
304
+                    $customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
305
+                    $view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
306
+                    echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
307
+                } else {
308
+                    echo '<div>&mdash;</div>';
309
+                }
310 310
 
311
-				break;
311
+                break;
312 312
 
313
-		}
313
+        }
314 314
 
315
-	}
315
+    }
316 316
 
317
-	/**
318
-	 * Returns an array of payment forms table columns.
319
-	 */
320
-	public static function payment_form_columns( $columns ) {
317
+    /**
318
+     * Returns an array of payment forms table columns.
319
+     */
320
+    public static function payment_form_columns( $columns ) {
321 321
 
322
-		$columns = array(
323
-			'cb'                => $columns['cb'],
324
-			'title'             => __( 'Name', 'invoicing' ),
325
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
326
-			'earnings'          => __( 'Revenue', 'invoicing' ),
327
-			'refunds'           => __( 'Refunded', 'invoicing' ),
328
-			'items'             => __( 'Items', 'invoicing' ),
329
-			'date'              => __( 'Date', 'invoicing' ),
330
-		);
322
+        $columns = array(
323
+            'cb'                => $columns['cb'],
324
+            'title'             => __( 'Name', 'invoicing' ),
325
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
326
+            'earnings'          => __( 'Revenue', 'invoicing' ),
327
+            'refunds'           => __( 'Refunded', 'invoicing' ),
328
+            'items'             => __( 'Items', 'invoicing' ),
329
+            'date'              => __( 'Date', 'invoicing' ),
330
+        );
331 331
 
332
-		return apply_filters( 'wpi_payment_form_table_columns', $columns );
332
+        return apply_filters( 'wpi_payment_form_table_columns', $columns );
333 333
 
334
-	}
334
+    }
335 335
 
336
-	/**
337
-	 * Displays payment form table columns.
338
-	 */
339
-	public static function display_payment_form_columns( $column_name, $post_id ) {
336
+    /**
337
+     * Displays payment form table columns.
338
+     */
339
+    public static function display_payment_form_columns( $column_name, $post_id ) {
340 340
 
341
-		// Retrieve the payment form.
342
-		$form = new GetPaid_Payment_Form( $post_id );
341
+        // Retrieve the payment form.
342
+        $form = new GetPaid_Payment_Form( $post_id );
343 343
 
344
-		switch ( $column_name ) {
344
+        switch ( $column_name ) {
345 345
 
346
-			case 'earnings' :
347
-				echo wpinv_price( $form->get_earned() );
348
-				break;
346
+            case 'earnings' :
347
+                echo wpinv_price( $form->get_earned() );
348
+                break;
349 349
 
350
-			case 'refunds' :
351
-				echo wpinv_price( $form->get_refunded() );
352
-				break;
350
+            case 'refunds' :
351
+                echo wpinv_price( $form->get_refunded() );
352
+                break;
353 353
 
354
-			case 'refunds' :
355
-				echo wpinv_price( $form->get_refunded() );
356
-				break;
354
+            case 'refunds' :
355
+                echo wpinv_price( $form->get_refunded() );
356
+                break;
357 357
 
358
-			case 'shortcode' :
358
+            case 'shortcode' :
359 359
 
360
-				if ( $form->is_default() ) {
361
-					echo '&mdash;';
362
-				} else {
363
-					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
364
-				}
360
+                if ( $form->is_default() ) {
361
+                    echo '&mdash;';
362
+                } else {
363
+                    echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
364
+                }
365 365
 
366
-				break;
366
+                break;
367 367
 
368
-			case 'items' :
368
+            case 'items' :
369 369
 
370
-				$items = $form->get_items();
370
+                $items = $form->get_items();
371 371
 
372
-				if ( $form->is_default() || empty( $items ) ) {
373
-					echo '&mdash;';
374
-					return;
375
-				}
372
+                if ( $form->is_default() || empty( $items ) ) {
373
+                    echo '&mdash;';
374
+                    return;
375
+                }
376 376
 
377
-				$_items = array();
377
+                $_items = array();
378 378
 
379
-				foreach ( $items as $item ) {
380
-					$url = $item->get_edit_url();
379
+                foreach ( $items as $item ) {
380
+                    $url = $item->get_edit_url();
381 381
 
382
-					if ( empty( $url ) ) {
383
-						$_items[] = sanitize_text_field( $item->get_name() );
384
-					} else {
385
-						$_items[] = sprintf(
386
-							'<a href="%s">%s</a>',
387
-							esc_url( $url ),
388
-							sanitize_text_field( $item->get_name() )
389
-						);
390
-					}
382
+                    if ( empty( $url ) ) {
383
+                        $_items[] = sanitize_text_field( $item->get_name() );
384
+                    } else {
385
+                        $_items[] = sprintf(
386
+                            '<a href="%s">%s</a>',
387
+                            esc_url( $url ),
388
+                            sanitize_text_field( $item->get_name() )
389
+                        );
390
+                    }
391 391
 
392
-				}
392
+                }
393 393
 
394
-				echo implode( '<br>', $_items );
394
+                echo implode( '<br>', $_items );
395 395
 
396
-				break;
396
+                break;
397 397
 
398
-		}
398
+        }
399 399
 
400
-	}
400
+    }
401 401
 
402
-	/**
403
-	 * Filters post states.
404
-	 */
405
-	public static function filter_payment_form_state( $post_states, $post ) {
402
+    /**
403
+     * Filters post states.
404
+     */
405
+    public static function filter_payment_form_state( $post_states, $post ) {
406 406
 
407
-		if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
408
-			$post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
409
-		}
407
+        if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
408
+            $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
409
+        }
410 410
 	
411
-		return $post_states;
412
-
413
-	}
414
-
415
-	/**
416
-	 * Returns an array of coupon table columns.
417
-	 */
418
-	public static function discount_columns( $columns ) {
419
-
420
-		$columns = array(
421
-			'cb'                => $columns['cb'],
422
-			'title'             => __( 'Name', 'invoicing' ),
423
-			'code'              => __( 'Code', 'invoicing' ),
424
-			'amount'            => __( 'Amount', 'invoicing' ),
425
-			'usage'             => __( 'Usage / Limit', 'invoicing' ),
426
-			'start_date'        => __( 'Start Date', 'invoicing' ),
427
-			'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
428
-		);
429
-
430
-		return apply_filters( 'wpi_discount_table_columns', $columns );
431
-	}
432
-
433
-	/**
434
-	 * Filters post states.
435
-	 */
436
-	public static function filter_discount_state( $post_states, $post ) {
437
-
438
-		if ( 'wpi_discount' == $post->post_type ) {
439
-
440
-			$discount = new WPInv_Discount( $post );
441
-
442
-			$status = $discount->is_expired() ? 'expired' : $discount->get_status();
443
-
444
-			if ( $status != 'publish' ) {
445
-				return array(
446
-					'discount_status' => wpinv_discount_status( $status ),
447
-				);
448
-			}
449
-
450
-			return array();
451
-
452
-		}
453
-
454
-		return $post_states;
455
-
456
-	}
457
-
458
-	/**
459
-	 * Returns an array of items table columns.
460
-	 */
461
-	public static function item_columns( $columns ) {
462
-
463
-		$columns = array(
464
-			'cb'                => $columns['cb'],
465
-			'title'             => __( 'Name', 'invoicing' ),
466
-			'price'             => __( 'Price', 'invoicing' ),
467
-			'vat_rule'          => __( 'VAT rule', 'invoicing' ),
468
-			'vat_class'         => __( 'VAT class', 'invoicing' ),
469
-			'type'              => __( 'Type', 'invoicing' ),
470
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
471
-		);
472
-
473
-		if ( ! wpinv_use_taxes() ) {
474
-			unset( $columns['vat_rule'] );
475
-			unset( $columns['vat_class'] );
476
-		}
477
-
478
-		return apply_filters( 'wpi_item_table_columns', $columns );
479
-	}
480
-
481
-	/**
482
-	 * Returns an array of sortable items table columns.
483
-	 */
484
-	public static function sortable_item_columns( $columns ) {
485
-
486
-		return array_merge(
487
-			$columns,
488
-			array(
489
-				'price'     => 'price',
490
-				'vat_rule'  => 'vat_rule',
491
-				'vat_class' => 'vat_class',
492
-				'type'      => 'type',
493
-			)
494
-		);
495
-
496
-	}
497
-
498
-	/**
499
-	 * Displays items table columns.
500
-	 */
501
-	public static function display_item_columns( $column_name, $post_id ) {
411
+        return $post_states;
412
+
413
+    }
414
+
415
+    /**
416
+     * Returns an array of coupon table columns.
417
+     */
418
+    public static function discount_columns( $columns ) {
419
+
420
+        $columns = array(
421
+            'cb'                => $columns['cb'],
422
+            'title'             => __( 'Name', 'invoicing' ),
423
+            'code'              => __( 'Code', 'invoicing' ),
424
+            'amount'            => __( 'Amount', 'invoicing' ),
425
+            'usage'             => __( 'Usage / Limit', 'invoicing' ),
426
+            'start_date'        => __( 'Start Date', 'invoicing' ),
427
+            'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
428
+        );
429
+
430
+        return apply_filters( 'wpi_discount_table_columns', $columns );
431
+    }
432
+
433
+    /**
434
+     * Filters post states.
435
+     */
436
+    public static function filter_discount_state( $post_states, $post ) {
437
+
438
+        if ( 'wpi_discount' == $post->post_type ) {
439
+
440
+            $discount = new WPInv_Discount( $post );
441
+
442
+            $status = $discount->is_expired() ? 'expired' : $discount->get_status();
443
+
444
+            if ( $status != 'publish' ) {
445
+                return array(
446
+                    'discount_status' => wpinv_discount_status( $status ),
447
+                );
448
+            }
449
+
450
+            return array();
451
+
452
+        }
453
+
454
+        return $post_states;
455
+
456
+    }
457
+
458
+    /**
459
+     * Returns an array of items table columns.
460
+     */
461
+    public static function item_columns( $columns ) {
462
+
463
+        $columns = array(
464
+            'cb'                => $columns['cb'],
465
+            'title'             => __( 'Name', 'invoicing' ),
466
+            'price'             => __( 'Price', 'invoicing' ),
467
+            'vat_rule'          => __( 'VAT rule', 'invoicing' ),
468
+            'vat_class'         => __( 'VAT class', 'invoicing' ),
469
+            'type'              => __( 'Type', 'invoicing' ),
470
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
471
+        );
472
+
473
+        if ( ! wpinv_use_taxes() ) {
474
+            unset( $columns['vat_rule'] );
475
+            unset( $columns['vat_class'] );
476
+        }
477
+
478
+        return apply_filters( 'wpi_item_table_columns', $columns );
479
+    }
480
+
481
+    /**
482
+     * Returns an array of sortable items table columns.
483
+     */
484
+    public static function sortable_item_columns( $columns ) {
485
+
486
+        return array_merge(
487
+            $columns,
488
+            array(
489
+                'price'     => 'price',
490
+                'vat_rule'  => 'vat_rule',
491
+                'vat_class' => 'vat_class',
492
+                'type'      => 'type',
493
+            )
494
+        );
495
+
496
+    }
497
+
498
+    /**
499
+     * Displays items table columns.
500
+     */
501
+    public static function display_item_columns( $column_name, $post_id ) {
502 502
  
503
-		$item = new WPInv_Item( $post_id );
503
+        $item = new WPInv_Item( $post_id );
504 504
 
505
-		switch ( $column_name ) {
505
+        switch ( $column_name ) {
506 506
 
507
-			case 'price' :
507
+            case 'price' :
508 508
 
509
-				if ( ! $item->is_recurring() ) {
510
-					echo $item->get_the_price();
511
-					break;
512
-				}
509
+                if ( ! $item->is_recurring() ) {
510
+                    echo $item->get_the_price();
511
+                    break;
512
+                }
513 513
 
514
-				$price = wp_sprintf(
515
-					__( '%s / %s', 'invoicing' ),
516
-					$item->get_the_price(),
517
-					getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
518
-				);
514
+                $price = wp_sprintf(
515
+                    __( '%s / %s', 'invoicing' ),
516
+                    $item->get_the_price(),
517
+                    getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
518
+                );
519 519
 
520
-				if ( $item->get_the_price() == $item->get_the_initial_price() ) {
521
-					echo $price;
522
-					break;
523
-				}
520
+                if ( $item->get_the_price() == $item->get_the_initial_price() ) {
521
+                    echo $price;
522
+                    break;
523
+                }
524 524
 
525
-				echo $item->get_the_initial_price();
525
+                echo $item->get_the_initial_price();
526 526
 
527
-				echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
528
-				break;
527
+                echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
528
+                break;
529 529
 
530
-			case 'vat_rule' :
531
-				echo getpaid_get_tax_rule_label( $item->get_vat_rule() );
532
-				break;
530
+            case 'vat_rule' :
531
+                echo getpaid_get_tax_rule_label( $item->get_vat_rule() );
532
+                break;
533 533
 
534
-			case 'vat_class' :
535
-				echo getpaid_get_tax_class_label( $item->get_vat_class() );
536
-				break;
534
+            case 'vat_class' :
535
+                echo getpaid_get_tax_class_label( $item->get_vat_class() );
536
+                break;
537 537
 
538
-			case 'shortcode' :
539
-				echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
540
-				break;
538
+            case 'shortcode' :
539
+                echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
540
+                break;
541 541
 
542
-			case 'type' :
543
-				echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
544
-				break;
542
+            case 'type' :
543
+                echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
544
+                break;
545 545
 
546
-		}
546
+        }
547 547
 
548
-	}
548
+    }
549 549
 
550
-	/**
551
-	 * Lets users filter items using taxes.
552
-	 */
553
-	public static function add_item_filters( $post_type ) {
550
+    /**
551
+     * Lets users filter items using taxes.
552
+     */
553
+    public static function add_item_filters( $post_type ) {
554 554
 
555
-		// Abort if we're not dealing with items.
556
-		if ( $post_type != 'wpi_item' ) {
557
-			return;
558
-		}
555
+        // Abort if we're not dealing with items.
556
+        if ( $post_type != 'wpi_item' ) {
557
+            return;
558
+        }
559 559
 
560
-		// Filter by vat rules.
561
-		if ( wpinv_use_taxes() ) {
560
+        // Filter by vat rules.
561
+        if ( wpinv_use_taxes() ) {
562 562
 	
563
-			// Sanitize selected vat rule.
564
-			$vat_rule   = '';
565
-			$vat_rules  = getpaid_get_tax_rules();
566
-			if ( isset( $_GET['vat_rule'] ) ) {
567
-				$vat_rule   =  $_GET['vat_rule'];
568
-			}
569
-
570
-			// Filter by VAT rule.
571
-			echo wpinv_html_select(
572
-				array(
573
-					'options'          => array_merge(
574
-						array(
575
-							'' => __( 'All VAT rules', 'invoicing' )
576
-						),
577
-						$vat_rules
578
-					),
579
-					'name'             => 'vat_rule',
580
-					'id'               => 'vat_rule',
581
-					'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
582
-					'show_option_all'  => false,
583
-					'show_option_none' => false,
584
-				)
585
-			);
586
-
587
-			// Filter by VAT class.
563
+            // Sanitize selected vat rule.
564
+            $vat_rule   = '';
565
+            $vat_rules  = getpaid_get_tax_rules();
566
+            if ( isset( $_GET['vat_rule'] ) ) {
567
+                $vat_rule   =  $_GET['vat_rule'];
568
+            }
569
+
570
+            // Filter by VAT rule.
571
+            echo wpinv_html_select(
572
+                array(
573
+                    'options'          => array_merge(
574
+                        array(
575
+                            '' => __( 'All VAT rules', 'invoicing' )
576
+                        ),
577
+                        $vat_rules
578
+                    ),
579
+                    'name'             => 'vat_rule',
580
+                    'id'               => 'vat_rule',
581
+                    'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
582
+                    'show_option_all'  => false,
583
+                    'show_option_none' => false,
584
+                )
585
+            );
586
+
587
+            // Filter by VAT class.
588 588
 	
589
-			// Sanitize selected vat rule.
590
-			$vat_class   = '';
591
-			$vat_classes = getpaid_get_tax_classes();
592
-			if ( isset( $_GET['vat_class'] ) ) {
593
-				$vat_class   =  $_GET['vat_class'];
594
-			}
595
-
596
-			echo wpinv_html_select(
597
-				array(
598
-					'options'          => array_merge(
599
-						array(
600
-							'' => __( 'All VAT classes', 'invoicing' )
601
-						),
602
-						$vat_classes
603
-					),
604
-					'name'             => 'vat_class',
605
-					'id'               => 'vat_class',
606
-					'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
607
-					'show_option_all'  => false,
608
-					'show_option_none' => false,
609
-				)
610
-			);
611
-
612
-		}
613
-
614
-		// Filter by item type.
615
-		$type   = '';
616
-		if ( isset( $_GET['type'] ) ) {
617
-			$type   =  $_GET['type'];
618
-		}
619
-
620
-		echo wpinv_html_select(
621
-			array(
622
-				'options'          => array_merge(
623
-					array(
624
-						'' => __( 'All item types', 'invoicing' )
625
-					),
626
-					wpinv_get_item_types()
627
-				),
628
-				'name'             => 'type',
629
-				'id'               => 'type',
630
-				'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
631
-				'show_option_all'  => false,
632
-				'show_option_none' => false,
633
-			)
634
-		);
635
-
636
-	}
637
-
638
-	/**
639
-	 * Filters the item query.
640
-	 */
641
-	public static function filter_item_query( $query ) {
642
-
643
-		// modify the query only if it admin and main query.
644
-		if ( ! ( is_admin() && $query->is_main_query() ) ){ 
645
-			return $query;
646
-		}
647
-
648
-		// we want to modify the query for our items.
649
-		if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){
650
-			return $query;
651
-		}
652
-
653
-		if ( empty( $query->query_vars['meta_query'] ) ) {
654
-			$query->query_vars['meta_query'] = array();
655
-		}
656
-
657
-		// Filter vat rule type
589
+            // Sanitize selected vat rule.
590
+            $vat_class   = '';
591
+            $vat_classes = getpaid_get_tax_classes();
592
+            if ( isset( $_GET['vat_class'] ) ) {
593
+                $vat_class   =  $_GET['vat_class'];
594
+            }
595
+
596
+            echo wpinv_html_select(
597
+                array(
598
+                    'options'          => array_merge(
599
+                        array(
600
+                            '' => __( 'All VAT classes', 'invoicing' )
601
+                        ),
602
+                        $vat_classes
603
+                    ),
604
+                    'name'             => 'vat_class',
605
+                    'id'               => 'vat_class',
606
+                    'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
607
+                    'show_option_all'  => false,
608
+                    'show_option_none' => false,
609
+                )
610
+            );
611
+
612
+        }
613
+
614
+        // Filter by item type.
615
+        $type   = '';
616
+        if ( isset( $_GET['type'] ) ) {
617
+            $type   =  $_GET['type'];
618
+        }
619
+
620
+        echo wpinv_html_select(
621
+            array(
622
+                'options'          => array_merge(
623
+                    array(
624
+                        '' => __( 'All item types', 'invoicing' )
625
+                    ),
626
+                    wpinv_get_item_types()
627
+                ),
628
+                'name'             => 'type',
629
+                'id'               => 'type',
630
+                'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
631
+                'show_option_all'  => false,
632
+                'show_option_none' => false,
633
+            )
634
+        );
635
+
636
+    }
637
+
638
+    /**
639
+     * Filters the item query.
640
+     */
641
+    public static function filter_item_query( $query ) {
642
+
643
+        // modify the query only if it admin and main query.
644
+        if ( ! ( is_admin() && $query->is_main_query() ) ){ 
645
+            return $query;
646
+        }
647
+
648
+        // we want to modify the query for our items.
649
+        if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){
650
+            return $query;
651
+        }
652
+
653
+        if ( empty( $query->query_vars['meta_query'] ) ) {
654
+            $query->query_vars['meta_query'] = array();
655
+        }
656
+
657
+        // Filter vat rule type
658 658
         if ( ! empty( $_GET['vat_rule'] ) ) {
659 659
             $query->query_vars['meta_query'][] = array(
660 660
                 'key'     => '_wpinv_vat_rule',
@@ -679,97 +679,97 @@  discard block
 block discarded – undo
679 679
                 'value'   => sanitize_text_field( $_GET['type'] ),
680 680
                 'compare' => '='
681 681
             );
682
-		}
683
-
684
-	}
685
-
686
-	/**
687
-	 * Reorders items.
688
-	 */
689
-	public static function reorder_items( $vars ) {
690
-		global $typenow;
691
-
692
-		if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
693
-			return $vars;
694
-		}
695
-
696
-		// By item type.
697
-		if ( 'type' == $vars['orderby'] ) {
698
-			return array_merge(
699
-				$vars,
700
-				array(
701
-					'meta_key' => '_wpinv_type',
702
-					'orderby'  => 'meta_value'
703
-				)
704
-			);
705
-		}
706
-
707
-		// By vat class.
708
-		if ( 'vat_class' == $vars['orderby'] ) {
709
-			return array_merge(
710
-				$vars,
711
-				array(
712
-					'meta_key' => '_wpinv_vat_class',
713
-					'orderby'  => 'meta_value'
714
-				)
715
-			);
716
-		}
717
-
718
-		// By vat rule.
719
-		if ( 'vat_rule' == $vars['orderby'] ) {
720
-			return array_merge(
721
-				$vars,
722
-				array(
723
-					'meta_key' => '_wpinv_vat_rule',
724
-					'orderby'  => 'meta_value'
725
-				)
726
-			);
727
-		}
728
-
729
-		// By price.
730
-		if ( 'price' == $vars['orderby'] ) {
731
-			return array_merge(
732
-				$vars,
733
-				array(
734
-					'meta_key' => '_wpinv_price',
735
-					'orderby'  => 'meta_value_num'
736
-				)
737
-			);
738
-		}
739
-
740
-		return $vars;
741
-
742
-	}
743
-
744
-	/**
745
-	 * Fired when deleting a post.
746
-	 */
747
-	public static function delete_post( $post_id ) {
748
-
749
-		switch ( get_post_type( $post_id ) ) {
750
-
751
-			case 'wpi_item' :
752
-				do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
753
-				break;
754
-
755
-			case 'wpi_payment_form' :
756
-				do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
757
-				break;
758
-
759
-			case 'wpi_discount' :
760
-				do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
761
-				break;
762
-
763
-			case 'wpi_invoice' :
764
-				$invoice = new WPInv_Invoice( $post_id );
765
-				do_action( "getpaid_before_delete_invoice", $invoice );
766
-				$invoice->get_data_store()->delete_items( $invoice );
767
-				$invoice->get_data_store()->delete_special_fields( $invoice );
768
-				break;
769
-		}
770
-	}
771
-
772
-	/**
682
+        }
683
+
684
+    }
685
+
686
+    /**
687
+     * Reorders items.
688
+     */
689
+    public static function reorder_items( $vars ) {
690
+        global $typenow;
691
+
692
+        if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
693
+            return $vars;
694
+        }
695
+
696
+        // By item type.
697
+        if ( 'type' == $vars['orderby'] ) {
698
+            return array_merge(
699
+                $vars,
700
+                array(
701
+                    'meta_key' => '_wpinv_type',
702
+                    'orderby'  => 'meta_value'
703
+                )
704
+            );
705
+        }
706
+
707
+        // By vat class.
708
+        if ( 'vat_class' == $vars['orderby'] ) {
709
+            return array_merge(
710
+                $vars,
711
+                array(
712
+                    'meta_key' => '_wpinv_vat_class',
713
+                    'orderby'  => 'meta_value'
714
+                )
715
+            );
716
+        }
717
+
718
+        // By vat rule.
719
+        if ( 'vat_rule' == $vars['orderby'] ) {
720
+            return array_merge(
721
+                $vars,
722
+                array(
723
+                    'meta_key' => '_wpinv_vat_rule',
724
+                    'orderby'  => 'meta_value'
725
+                )
726
+            );
727
+        }
728
+
729
+        // By price.
730
+        if ( 'price' == $vars['orderby'] ) {
731
+            return array_merge(
732
+                $vars,
733
+                array(
734
+                    'meta_key' => '_wpinv_price',
735
+                    'orderby'  => 'meta_value_num'
736
+                )
737
+            );
738
+        }
739
+
740
+        return $vars;
741
+
742
+    }
743
+
744
+    /**
745
+     * Fired when deleting a post.
746
+     */
747
+    public static function delete_post( $post_id ) {
748
+
749
+        switch ( get_post_type( $post_id ) ) {
750
+
751
+            case 'wpi_item' :
752
+                do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
753
+                break;
754
+
755
+            case 'wpi_payment_form' :
756
+                do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
757
+                break;
758
+
759
+            case 'wpi_discount' :
760
+                do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
761
+                break;
762
+
763
+            case 'wpi_invoice' :
764
+                $invoice = new WPInv_Invoice( $post_id );
765
+                do_action( "getpaid_before_delete_invoice", $invoice );
766
+                $invoice->get_data_store()->delete_items( $invoice );
767
+                $invoice->get_data_store()->delete_special_fields( $invoice );
768
+                break;
769
+        }
770
+    }
771
+
772
+    /**
773 773
      * Add a post display state for special GetPaid pages in the page list table.
774 774
      *
775 775
      * @param array   $post_states An array of post display states.
@@ -783,22 +783,22 @@  discard block
 block discarded – undo
783 783
             $post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' );
784 784
         }
785 785
 
786
-		foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) {
786
+        foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) {
787 787
 
788
-			if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) {
789
-				$post_states["getpaid_{$post_type}_history_page"] = sprintf(
790
-					__( 'GetPaid %s History Page', 'invoicing' ),
791
-					$label
792
-				);
793
-			}
788
+            if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) {
789
+                $post_states["getpaid_{$post_type}_history_page"] = sprintf(
790
+                    __( 'GetPaid %s History Page', 'invoicing' ),
791
+                    $label
792
+                );
793
+            }
794 794
 
795
-		}
795
+        }
796 796
 		
797
-		if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) {
797
+        if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) {
798 798
             $post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscription Page', 'invoicing' );
799 799
         }
800 800
 
801
-		if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) {
801
+        if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) {
802 802
             $post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' );
803 803
         }
804 804
 
Please login to merge, or discard this patch.
Spacing   +216 added lines, -216 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
  * Post types Admin Class
@@ -21,72 +21,72 @@  discard block
 block discarded – undo
21 21
 		GetPaid_Metaboxes::init();
22 22
 
23 23
 		// Filter the post updated messages.
24
-		add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
24
+		add_filter('post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages');
25 25
 
26 26
 		// Filter post actions.
27
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
28
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 );
27
+		add_filter('post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2);
28
+		add_filter('post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2);
29 29
 
30 30
 		// Invoice table columns.
31
-		add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
32
-		add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
31
+		add_filter('manage_wpi_invoice_posts_columns', array(__CLASS__, 'invoice_columns'), 100);
32
+		add_action('manage_wpi_invoice_posts_custom_column', array(__CLASS__, 'display_invoice_columns'), 10, 2);
33 33
 
34 34
 		// Items table columns.
35
-		add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
36
-		add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
37
-		add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
38
-		add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
39
-		add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
40
-		add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
35
+		add_filter('manage_wpi_item_posts_columns', array(__CLASS__, 'item_columns'), 100);
36
+		add_filter('manage_edit-wpi_item_sortable_columns', array(__CLASS__, 'sortable_item_columns'), 20);
37
+		add_action('manage_wpi_item_posts_custom_column', array(__CLASS__, 'display_item_columns'), 10, 2);
38
+		add_action('restrict_manage_posts', array(__CLASS__, 'add_item_filters'), 100);
39
+		add_action('parse_query', array(__CLASS__, 'filter_item_query'), 100);
40
+		add_action('request', array(__CLASS__, 'reorder_items'), 100);
41 41
 
42 42
 		// Payment forms columns.
43
-		add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
44
-		add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
45
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
43
+		add_filter('manage_wpi_payment_form_posts_columns', array(__CLASS__, 'payment_form_columns'), 100);
44
+		add_action('manage_wpi_payment_form_posts_custom_column', array(__CLASS__, 'display_payment_form_columns'), 10, 2);
45
+		add_filter('display_post_states', array(__CLASS__, 'filter_payment_form_state'), 10, 2);
46 46
 
47 47
 		// Discount table columns.
48
-		add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
49
-		add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 );
48
+		add_filter('manage_wpi_discount_posts_columns', array(__CLASS__, 'discount_columns'), 100);
49
+		add_filter('bulk_actions-edit-wpi_discount', '__return_empty_array', 100);
50 50
 
51 51
 		// Deleting posts.
52
-		add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
53
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
52
+		add_action('delete_post', array(__CLASS__, 'delete_post'));
53
+		add_filter('display_post_states', array(__CLASS__, 'filter_discount_state'), 10, 2);
54 54
 
55
-		add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 );
55
+		add_filter('display_post_states', array(__CLASS__, 'add_display_post_states'), 10, 2);
56 56
 	}
57 57
 
58 58
 	/**
59 59
 	 * Post updated messages.
60 60
 	 */
61
-	public static function post_updated_messages( $messages ) {
61
+	public static function post_updated_messages($messages) {
62 62
 		global $post;
63 63
 
64 64
 		$messages['wpi_discount'] = array(
65 65
 			0   => '',
66
-			1   => __( 'Discount updated.', 'invoicing' ),
67
-			2   => __( 'Custom field updated.', 'invoicing' ),
68
-			3   => __( 'Custom field deleted.', 'invoicing' ),
69
-			4   => __( 'Discount updated.', 'invoicing' ),
70
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
71
-			6   => __( 'Discount updated.', 'invoicing' ),
72
-			7   => __( 'Discount saved.', 'invoicing' ),
73
-			8   => __( 'Discount submitted.', 'invoicing' ),
74
-			9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
75
-			10  => __( 'Discount draft updated.', 'invoicing' ),
66
+			1   => __('Discount updated.', 'invoicing'),
67
+			2   => __('Custom field updated.', 'invoicing'),
68
+			3   => __('Custom field deleted.', 'invoicing'),
69
+			4   => __('Discount updated.', 'invoicing'),
70
+			5   => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
71
+			6   => __('Discount updated.', 'invoicing'),
72
+			7   => __('Discount saved.', 'invoicing'),
73
+			8   => __('Discount submitted.', 'invoicing'),
74
+			9   => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
75
+			10  => __('Discount draft updated.', 'invoicing'),
76 76
 		);
77 77
 
78 78
 		$messages['wpi_payment_form'] = array(
79 79
 			0   => '',
80
-			1   => __( 'Payment Form updated.', 'invoicing' ),
81
-			2   => __( 'Custom field updated.', 'invoicing' ),
82
-			3   => __( 'Custom field deleted.', 'invoicing' ),
83
-			4   => __( 'Payment Form updated.', 'invoicing' ),
84
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
85
-			6   => __( 'Payment Form updated.', 'invoicing' ),
86
-			7   => __( 'Payment Form saved.', 'invoicing' ),
87
-			8   => __( 'Payment Form submitted.', 'invoicing' ),
88
-			9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
89
-			10  => __( 'Payment Form draft updated.', 'invoicing' ),
80
+			1   => __('Payment Form updated.', 'invoicing'),
81
+			2   => __('Custom field updated.', 'invoicing'),
82
+			3   => __('Custom field deleted.', 'invoicing'),
83
+			4   => __('Payment Form updated.', 'invoicing'),
84
+			5   => isset($_GET['revision']) ? wp_sprintf(__('Payment Form restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
85
+			6   => __('Payment Form updated.', 'invoicing'),
86
+			7   => __('Payment Form saved.', 'invoicing'),
87
+			8   => __('Payment Form submitted.', 'invoicing'),
88
+			9   => wp_sprintf(__('Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
89
+			10  => __('Payment Form draft updated.', 'invoicing'),
90 90
 		);
91 91
 
92 92
 		return $messages;
@@ -96,14 +96,14 @@  discard block
 block discarded – undo
96 96
 	/**
97 97
 	 * Post row actions.
98 98
 	 */
99
-	public static function post_row_actions( $actions, $post ) {
99
+	public static function post_row_actions($actions, $post) {
100 100
 
101
-		$post = get_post( $post );
101
+		$post = get_post($post);
102 102
 
103 103
 		// We do not want to edit the default payment form.
104
-		if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
105
-			unset( $actions['trash'] );
106
-			unset( $actions['inline hide-if-no-js'] );
104
+		if ('wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form()) {
105
+			unset($actions['trash']);
106
+			unset($actions['inline hide-if-no-js']);
107 107
 		}
108 108
 
109 109
 		return $actions;
@@ -117,31 +117,31 @@  discard block
 block discarded – undo
117 117
 	 * @param WP_Post $post
118 118
      * @return array $actions actions without edit option
119 119
      */
120
-    public static function filter_invoice_row_actions( $actions, $post ) {
120
+    public static function filter_invoice_row_actions($actions, $post) {
121 121
 
122
-        if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
122
+        if (getpaid_is_invoice_post_type($post->post_type)) {
123 123
 
124 124
 			$actions = array();
125
-			$invoice = new WPInv_Invoice( $post );
125
+			$invoice = new WPInv_Invoice($post);
126 126
 
127
-			$actions['edit'] =  sprintf(
127
+			$actions['edit'] = sprintf(
128 128
 				'<a href="%1$s">%2$s</a>',
129
-				esc_url( get_edit_post_link( $invoice->get_id() ) ),
130
-				esc_html( __( 'Edit', 'invoicing' ) )
129
+				esc_url(get_edit_post_link($invoice->get_id())),
130
+				esc_html(__('Edit', 'invoicing'))
131 131
 			);
132 132
 
133
-			if ( ! $invoice->is_draft() ) {
133
+			if (!$invoice->is_draft()) {
134 134
 
135
-				$actions['view'] =  sprintf(
135
+				$actions['view'] = sprintf(
136 136
 					'<a href="%1$s">%2$s</a>',
137
-					esc_url( $invoice->get_view_url() ),
137
+					esc_url($invoice->get_view_url()),
138 138
 					sprintf(
139
-						esc_html( __( 'View %s', 'invoicing' ) ),
140
-						getpaid_get_post_type_label( $invoice->get_post_type(), false )
139
+						esc_html(__('View %s', 'invoicing')),
140
+						getpaid_get_post_type_label($invoice->get_post_type(), false)
141 141
 					)
142 142
 				);
143 143
 
144
-				$actions['send'] =  sprintf(
144
+				$actions['send'] = sprintf(
145 145
 					'<a href="%1$s">%2$s</a>',
146 146
 					esc_url(
147 147
 						wp_nonce_url(
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 							'getpaid-nonce'
156 156
 						)
157 157
 					),
158
-					esc_html( __( 'Send to Customer', 'invoicing' ) )
158
+					esc_html(__('Send to Customer', 'invoicing'))
159 159
 				);
160 160
 
161 161
 			}
@@ -168,42 +168,42 @@  discard block
 block discarded – undo
168 168
 	/**
169 169
 	 * Returns an array of invoice table columns.
170 170
 	 */
171
-	public static function invoice_columns( $columns ) {
171
+	public static function invoice_columns($columns) {
172 172
 
173 173
 		$columns = array(
174 174
 			'cb'                => $columns['cb'],
175
-			'number'            => __( 'Invoice', 'invoicing' ),
176
-			'customer'          => __( 'Customer', 'invoicing' ),
177
-			'invoice_date'      => __( 'Created', 'invoicing' ),
178
-			'payment_date'      => __( 'Completed', 'invoicing' ),
179
-			'amount'            => __( 'Amount', 'invoicing' ),
180
-			'recurring'         => __( 'Recurring', 'invoicing' ),
181
-			'status'            => __( 'Status', 'invoicing' ),
175
+			'number'            => __('Invoice', 'invoicing'),
176
+			'customer'          => __('Customer', 'invoicing'),
177
+			'invoice_date'      => __('Created', 'invoicing'),
178
+			'payment_date'      => __('Completed', 'invoicing'),
179
+			'amount'            => __('Amount', 'invoicing'),
180
+			'recurring'         => __('Recurring', 'invoicing'),
181
+			'status'            => __('Status', 'invoicing'),
182 182
 		);
183 183
 
184
-		return apply_filters( 'wpi_invoice_table_columns', $columns );
184
+		return apply_filters('wpi_invoice_table_columns', $columns);
185 185
 	}
186 186
 
187 187
 	/**
188 188
 	 * Displays invoice table columns.
189 189
 	 */
190
-	public static function display_invoice_columns( $column_name, $post_id ) {
190
+	public static function display_invoice_columns($column_name, $post_id) {
191 191
 
192
-		$invoice = new WPInv_Invoice( $post_id );
192
+		$invoice = new WPInv_Invoice($post_id);
193 193
 
194
-		switch ( $column_name ) {
194
+		switch ($column_name) {
195 195
 
196 196
 			case 'invoice_date' :
197
-				$date_time = esc_attr( $invoice->get_created_date() );
198
-				$date      = getpaid_format_date_value( $date_time, "&mdash;", true );
197
+				$date_time = esc_attr($invoice->get_created_date());
198
+				$date      = getpaid_format_date_value($date_time, "&mdash;", true);
199 199
 				echo "<span title='$date_time'>$date</span>";
200 200
 				break;
201 201
 
202 202
 			case 'payment_date' :
203 203
 
204
-				if ( $invoice->is_paid() ) {
205
-					$date_time = esc_attr( $invoice->get_completed_date() );
206
-					$date      = getpaid_format_date_value( $date_time, "&mdash;", true );
204
+				if ($invoice->is_paid()) {
205
+					$date_time = esc_attr($invoice->get_completed_date());
206
+					$date      = getpaid_format_date_value($date_time, "&mdash;", true);
207 207
 					echo "<span title='$date_time'>$date</span>";
208 208
 				} else {
209 209
 					echo "&mdash;";
@@ -214,17 +214,17 @@  discard block
 block discarded – undo
214 214
 			case 'amount' :
215 215
 
216 216
 				$amount = $invoice->get_total();
217
-				$formated_amount = wpinv_price( $amount, $invoice->get_currency() );
217
+				$formated_amount = wpinv_price($amount, $invoice->get_currency());
218 218
 
219
-				if ( $invoice->is_refunded() ) {
220
-					$refunded_amount = wpinv_price( 0, $invoice->get_currency() );
219
+				if ($invoice->is_refunded()) {
220
+					$refunded_amount = wpinv_price(0, $invoice->get_currency());
221 221
 					echo "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>";
222 222
 				} else {
223 223
 
224 224
 					$discount = $invoice->get_total_discount();
225 225
 
226
-					if ( ! empty( $discount ) ) {
227
-						$new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() );
226
+					if (!empty($discount)) {
227
+						$new_amount = wpinv_price($amount + $discount, $invoice->get_currency());
228 228
 						echo "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>";
229 229
 					} else {
230 230
 						echo $formated_amount;
@@ -235,13 +235,13 @@  discard block
 block discarded – undo
235 235
 				break;
236 236
 
237 237
 			case 'status' :
238
-				$status       = sanitize_text_field( $invoice->get_status() );
239
-				$status_label = sanitize_text_field( $invoice->get_status_nicename() );
238
+				$status       = sanitize_text_field($invoice->get_status());
239
+				$status_label = sanitize_text_field($invoice->get_status_nicename());
240 240
 
241 241
 				// If it is paid, show the gateway title.
242
-				if ( $invoice->is_paid() ) {
243
-					$gateway = sanitize_text_field( $invoice->get_gateway_title() );
244
-					$gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
242
+				if ($invoice->is_paid()) {
243
+					$gateway = sanitize_text_field($invoice->get_gateway_title());
244
+					$gateway = wp_sprintf(esc_attr__('Paid via %s', 'invoicing'), $gateway);
245 245
 
246 246
 					echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
247 247
 				} else {
@@ -249,22 +249,22 @@  discard block
 block discarded – undo
249 249
 				}
250 250
 
251 251
 				// If it is not paid, display the overdue and view status.
252
-				if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
252
+				if (!$invoice->is_paid() && !$invoice->is_refunded()) {
253 253
 
254 254
 					// Invoice view status.
255
-					if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
256
-						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
255
+					if (wpinv_is_invoice_viewed($invoice->get_id())) {
256
+						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="' . esc_attr__('Viewed by Customer', 'invoicing') . '"></i>';
257 257
 					} else {
258
-						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
258
+						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__('Not Viewed by Customer', 'invoicing') . '"></i>';
259 259
 					}
260 260
 
261 261
 					// Display the overview status.
262
-					if ( wpinv_get_option( 'overdue_active' ) ) {
262
+					if (wpinv_get_option('overdue_active')) {
263 263
 						$due_date = $invoice->get_due_date();
264
-						$fomatted = getpaid_format_date( $due_date );
264
+						$fomatted = getpaid_format_date($due_date);
265 265
 
266
-						if ( ! empty( $fomatted ) ) {
267
-							$date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
266
+						if (!empty($fomatted)) {
267
+							$date = wp_sprintf(__('Due %s', 'invoicing'), $fomatted);
268 268
 							echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
269 269
 						}
270 270
 					}
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 
276 276
 			case 'recurring':
277 277
 
278
-				if ( $invoice->is_recurring() ) {
278
+				if ($invoice->is_recurring()) {
279 279
 					echo '<i class="fa fa-check" style="color:#43850a;"></i>';
280 280
 				} else {
281 281
 					echo '<i class="fa fa-times" style="color:#616161;"></i>';
@@ -284,9 +284,9 @@  discard block
 block discarded – undo
284 284
 
285 285
 			case 'number' :
286 286
 
287
-				$edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
288
-				$invoice_number  = sanitize_text_field( $invoice->get_number() );
289
-				$invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
287
+				$edit_link       = esc_url(get_edit_post_link($invoice->get_id()));
288
+				$invoice_number  = sanitize_text_field($invoice->get_number());
289
+				$invoice_details = esc_attr__('View Invoice Details', 'invoicing');
290 290
 
291 291
 				echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
292 292
 
@@ -296,13 +296,13 @@  discard block
 block discarded – undo
296 296
 	
297 297
 				$customer_name = $invoice->get_user_full_name();
298 298
 	
299
-				if ( empty( $customer_name ) ) {
299
+				if (empty($customer_name)) {
300 300
 					$customer_name = $invoice->get_email();
301 301
 				}
302 302
 	
303
-				if ( ! empty( $customer_name ) ) {
304
-					$customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
305
-					$view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
303
+				if (!empty($customer_name)) {
304
+					$customer_details = esc_attr__('View Customer Details', 'invoicing');
305
+					$view_link        = esc_url(add_query_arg('user_id', $invoice->get_user_id(), admin_url('user-edit.php')));
306 306
 					echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
307 307
 				} else {
308 308
 					echo '<div>&mdash;</div>';
@@ -317,50 +317,50 @@  discard block
 block discarded – undo
317 317
 	/**
318 318
 	 * Returns an array of payment forms table columns.
319 319
 	 */
320
-	public static function payment_form_columns( $columns ) {
320
+	public static function payment_form_columns($columns) {
321 321
 
322 322
 		$columns = array(
323 323
 			'cb'                => $columns['cb'],
324
-			'title'             => __( 'Name', 'invoicing' ),
325
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
326
-			'earnings'          => __( 'Revenue', 'invoicing' ),
327
-			'refunds'           => __( 'Refunded', 'invoicing' ),
328
-			'items'             => __( 'Items', 'invoicing' ),
329
-			'date'              => __( 'Date', 'invoicing' ),
324
+			'title'             => __('Name', 'invoicing'),
325
+			'shortcode'         => __('Shortcode', 'invoicing'),
326
+			'earnings'          => __('Revenue', 'invoicing'),
327
+			'refunds'           => __('Refunded', 'invoicing'),
328
+			'items'             => __('Items', 'invoicing'),
329
+			'date'              => __('Date', 'invoicing'),
330 330
 		);
331 331
 
332
-		return apply_filters( 'wpi_payment_form_table_columns', $columns );
332
+		return apply_filters('wpi_payment_form_table_columns', $columns);
333 333
 
334 334
 	}
335 335
 
336 336
 	/**
337 337
 	 * Displays payment form table columns.
338 338
 	 */
339
-	public static function display_payment_form_columns( $column_name, $post_id ) {
339
+	public static function display_payment_form_columns($column_name, $post_id) {
340 340
 
341 341
 		// Retrieve the payment form.
342
-		$form = new GetPaid_Payment_Form( $post_id );
342
+		$form = new GetPaid_Payment_Form($post_id);
343 343
 
344
-		switch ( $column_name ) {
344
+		switch ($column_name) {
345 345
 
346 346
 			case 'earnings' :
347
-				echo wpinv_price( $form->get_earned() );
347
+				echo wpinv_price($form->get_earned());
348 348
 				break;
349 349
 
350 350
 			case 'refunds' :
351
-				echo wpinv_price( $form->get_refunded() );
351
+				echo wpinv_price($form->get_refunded());
352 352
 				break;
353 353
 
354 354
 			case 'refunds' :
355
-				echo wpinv_price( $form->get_refunded() );
355
+				echo wpinv_price($form->get_refunded());
356 356
 				break;
357 357
 
358 358
 			case 'shortcode' :
359 359
 
360
-				if ( $form->is_default() ) {
360
+				if ($form->is_default()) {
361 361
 					echo '&mdash;';
362 362
 				} else {
363
-					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
363
+					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr($form->get_id()) . ']" style="width: 100%;" readonly/>';
364 364
 				}
365 365
 
366 366
 				break;
@@ -369,29 +369,29 @@  discard block
 block discarded – undo
369 369
 
370 370
 				$items = $form->get_items();
371 371
 
372
-				if ( $form->is_default() || empty( $items ) ) {
372
+				if ($form->is_default() || empty($items)) {
373 373
 					echo '&mdash;';
374 374
 					return;
375 375
 				}
376 376
 
377 377
 				$_items = array();
378 378
 
379
-				foreach ( $items as $item ) {
379
+				foreach ($items as $item) {
380 380
 					$url = $item->get_edit_url();
381 381
 
382
-					if ( empty( $url ) ) {
383
-						$_items[] = sanitize_text_field( $item->get_name() );
382
+					if (empty($url)) {
383
+						$_items[] = sanitize_text_field($item->get_name());
384 384
 					} else {
385 385
 						$_items[] = sprintf(
386 386
 							'<a href="%s">%s</a>',
387
-							esc_url( $url ),
388
-							sanitize_text_field( $item->get_name() )
387
+							esc_url($url),
388
+							sanitize_text_field($item->get_name())
389 389
 						);
390 390
 					}
391 391
 
392 392
 				}
393 393
 
394
-				echo implode( '<br>', $_items );
394
+				echo implode('<br>', $_items);
395 395
 
396 396
 				break;
397 397
 
@@ -402,10 +402,10 @@  discard block
 block discarded – undo
402 402
 	/**
403 403
 	 * Filters post states.
404 404
 	 */
405
-	public static function filter_payment_form_state( $post_states, $post ) {
405
+	public static function filter_payment_form_state($post_states, $post) {
406 406
 
407
-		if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
408
-			$post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
407
+		if ('wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID) {
408
+			$post_states['default_form'] = __('Default Payment Form', 'invoicing');
409 409
 		}
410 410
 	
411 411
 		return $post_states;
@@ -415,35 +415,35 @@  discard block
 block discarded – undo
415 415
 	/**
416 416
 	 * Returns an array of coupon table columns.
417 417
 	 */
418
-	public static function discount_columns( $columns ) {
418
+	public static function discount_columns($columns) {
419 419
 
420 420
 		$columns = array(
421 421
 			'cb'                => $columns['cb'],
422
-			'title'             => __( 'Name', 'invoicing' ),
423
-			'code'              => __( 'Code', 'invoicing' ),
424
-			'amount'            => __( 'Amount', 'invoicing' ),
425
-			'usage'             => __( 'Usage / Limit', 'invoicing' ),
426
-			'start_date'        => __( 'Start Date', 'invoicing' ),
427
-			'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
422
+			'title'             => __('Name', 'invoicing'),
423
+			'code'              => __('Code', 'invoicing'),
424
+			'amount'            => __('Amount', 'invoicing'),
425
+			'usage'             => __('Usage / Limit', 'invoicing'),
426
+			'start_date'        => __('Start Date', 'invoicing'),
427
+			'expiry_date'       => __('Expiry Date', 'invoicing'),
428 428
 		);
429 429
 
430
-		return apply_filters( 'wpi_discount_table_columns', $columns );
430
+		return apply_filters('wpi_discount_table_columns', $columns);
431 431
 	}
432 432
 
433 433
 	/**
434 434
 	 * Filters post states.
435 435
 	 */
436
-	public static function filter_discount_state( $post_states, $post ) {
436
+	public static function filter_discount_state($post_states, $post) {
437 437
 
438
-		if ( 'wpi_discount' == $post->post_type ) {
438
+		if ('wpi_discount' == $post->post_type) {
439 439
 
440
-			$discount = new WPInv_Discount( $post );
440
+			$discount = new WPInv_Discount($post);
441 441
 
442 442
 			$status = $discount->is_expired() ? 'expired' : $discount->get_status();
443 443
 
444
-			if ( $status != 'publish' ) {
444
+			if ($status != 'publish') {
445 445
 				return array(
446
-					'discount_status' => wpinv_discount_status( $status ),
446
+					'discount_status' => wpinv_discount_status($status),
447 447
 				);
448 448
 			}
449 449
 
@@ -458,30 +458,30 @@  discard block
 block discarded – undo
458 458
 	/**
459 459
 	 * Returns an array of items table columns.
460 460
 	 */
461
-	public static function item_columns( $columns ) {
461
+	public static function item_columns($columns) {
462 462
 
463 463
 		$columns = array(
464 464
 			'cb'                => $columns['cb'],
465
-			'title'             => __( 'Name', 'invoicing' ),
466
-			'price'             => __( 'Price', 'invoicing' ),
467
-			'vat_rule'          => __( 'VAT rule', 'invoicing' ),
468
-			'vat_class'         => __( 'VAT class', 'invoicing' ),
469
-			'type'              => __( 'Type', 'invoicing' ),
470
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
465
+			'title'             => __('Name', 'invoicing'),
466
+			'price'             => __('Price', 'invoicing'),
467
+			'vat_rule'          => __('VAT rule', 'invoicing'),
468
+			'vat_class'         => __('VAT class', 'invoicing'),
469
+			'type'              => __('Type', 'invoicing'),
470
+			'shortcode'         => __('Shortcode', 'invoicing'),
471 471
 		);
472 472
 
473
-		if ( ! wpinv_use_taxes() ) {
474
-			unset( $columns['vat_rule'] );
475
-			unset( $columns['vat_class'] );
473
+		if (!wpinv_use_taxes()) {
474
+			unset($columns['vat_rule']);
475
+			unset($columns['vat_class']);
476 476
 		}
477 477
 
478
-		return apply_filters( 'wpi_item_table_columns', $columns );
478
+		return apply_filters('wpi_item_table_columns', $columns);
479 479
 	}
480 480
 
481 481
 	/**
482 482
 	 * Returns an array of sortable items table columns.
483 483
 	 */
484
-	public static function sortable_item_columns( $columns ) {
484
+	public static function sortable_item_columns($columns) {
485 485
 
486 486
 		return array_merge(
487 487
 			$columns,
@@ -498,49 +498,49 @@  discard block
 block discarded – undo
498 498
 	/**
499 499
 	 * Displays items table columns.
500 500
 	 */
501
-	public static function display_item_columns( $column_name, $post_id ) {
501
+	public static function display_item_columns($column_name, $post_id) {
502 502
  
503
-		$item = new WPInv_Item( $post_id );
503
+		$item = new WPInv_Item($post_id);
504 504
 
505
-		switch ( $column_name ) {
505
+		switch ($column_name) {
506 506
 
507 507
 			case 'price' :
508 508
 
509
-				if ( ! $item->is_recurring() ) {
509
+				if (!$item->is_recurring()) {
510 510
 					echo $item->get_the_price();
511 511
 					break;
512 512
 				}
513 513
 
514 514
 				$price = wp_sprintf(
515
-					__( '%s / %s', 'invoicing' ),
515
+					__('%s / %s', 'invoicing'),
516 516
 					$item->get_the_price(),
517
-					getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
517
+					getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), '')
518 518
 				);
519 519
 
520
-				if ( $item->get_the_price() == $item->get_the_initial_price() ) {
520
+				if ($item->get_the_price() == $item->get_the_initial_price()) {
521 521
 					echo $price;
522 522
 					break;
523 523
 				}
524 524
 
525 525
 				echo $item->get_the_initial_price();
526 526
 
527
-				echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
527
+				echo '<span class="meta">' . wp_sprintf(__('then %s', 'invoicing'), $price) . '</span>';
528 528
 				break;
529 529
 
530 530
 			case 'vat_rule' :
531
-				echo getpaid_get_tax_rule_label( $item->get_vat_rule() );
531
+				echo getpaid_get_tax_rule_label($item->get_vat_rule());
532 532
 				break;
533 533
 
534 534
 			case 'vat_class' :
535
-				echo getpaid_get_tax_class_label( $item->get_vat_class() );
535
+				echo getpaid_get_tax_class_label($item->get_vat_class());
536 536
 				break;
537 537
 
538 538
 			case 'shortcode' :
539
-				echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
539
+				echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr($item->get_id()) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
540 540
 				break;
541 541
 
542 542
 			case 'type' :
543
-				echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
543
+				echo wpinv_item_type($item->get_id()) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
544 544
 				break;
545 545
 
546 546
 		}
@@ -550,21 +550,21 @@  discard block
 block discarded – undo
550 550
 	/**
551 551
 	 * Lets users filter items using taxes.
552 552
 	 */
553
-	public static function add_item_filters( $post_type ) {
553
+	public static function add_item_filters($post_type) {
554 554
 
555 555
 		// Abort if we're not dealing with items.
556
-		if ( $post_type != 'wpi_item' ) {
556
+		if ($post_type != 'wpi_item') {
557 557
 			return;
558 558
 		}
559 559
 
560 560
 		// Filter by vat rules.
561
-		if ( wpinv_use_taxes() ) {
561
+		if (wpinv_use_taxes()) {
562 562
 	
563 563
 			// Sanitize selected vat rule.
564 564
 			$vat_rule   = '';
565 565
 			$vat_rules  = getpaid_get_tax_rules();
566
-			if ( isset( $_GET['vat_rule'] ) ) {
567
-				$vat_rule   =  $_GET['vat_rule'];
566
+			if (isset($_GET['vat_rule'])) {
567
+				$vat_rule = $_GET['vat_rule'];
568 568
 			}
569 569
 
570 570
 			// Filter by VAT rule.
@@ -572,13 +572,13 @@  discard block
 block discarded – undo
572 572
 				array(
573 573
 					'options'          => array_merge(
574 574
 						array(
575
-							'' => __( 'All VAT rules', 'invoicing' )
575
+							'' => __('All VAT rules', 'invoicing')
576 576
 						),
577 577
 						$vat_rules
578 578
 					),
579 579
 					'name'             => 'vat_rule',
580 580
 					'id'               => 'vat_rule',
581
-					'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
581
+					'selected'         => in_array($vat_rule, array_keys($vat_rules)) ? $vat_rule : '',
582 582
 					'show_option_all'  => false,
583 583
 					'show_option_none' => false,
584 584
 				)
@@ -589,21 +589,21 @@  discard block
 block discarded – undo
589 589
 			// Sanitize selected vat rule.
590 590
 			$vat_class   = '';
591 591
 			$vat_classes = getpaid_get_tax_classes();
592
-			if ( isset( $_GET['vat_class'] ) ) {
593
-				$vat_class   =  $_GET['vat_class'];
592
+			if (isset($_GET['vat_class'])) {
593
+				$vat_class = $_GET['vat_class'];
594 594
 			}
595 595
 
596 596
 			echo wpinv_html_select(
597 597
 				array(
598 598
 					'options'          => array_merge(
599 599
 						array(
600
-							'' => __( 'All VAT classes', 'invoicing' )
600
+							'' => __('All VAT classes', 'invoicing')
601 601
 						),
602 602
 						$vat_classes
603 603
 					),
604 604
 					'name'             => 'vat_class',
605 605
 					'id'               => 'vat_class',
606
-					'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
606
+					'selected'         => in_array($vat_class, array_keys($vat_classes)) ? $vat_class : '',
607 607
 					'show_option_all'  => false,
608 608
 					'show_option_none' => false,
609 609
 				)
@@ -612,22 +612,22 @@  discard block
 block discarded – undo
612 612
 		}
613 613
 
614 614
 		// Filter by item type.
615
-		$type   = '';
616
-		if ( isset( $_GET['type'] ) ) {
617
-			$type   =  $_GET['type'];
615
+		$type = '';
616
+		if (isset($_GET['type'])) {
617
+			$type = $_GET['type'];
618 618
 		}
619 619
 
620 620
 		echo wpinv_html_select(
621 621
 			array(
622 622
 				'options'          => array_merge(
623 623
 					array(
624
-						'' => __( 'All item types', 'invoicing' )
624
+						'' => __('All item types', 'invoicing')
625 625
 					),
626 626
 					wpinv_get_item_types()
627 627
 				),
628 628
 				'name'             => 'type',
629 629
 				'id'               => 'type',
630
-				'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
630
+				'selected'         => in_array($type, wpinv_item_types()) ? $type : '',
631 631
 				'show_option_all'  => false,
632 632
 				'show_option_none' => false,
633 633
 			)
@@ -638,45 +638,45 @@  discard block
 block discarded – undo
638 638
 	/**
639 639
 	 * Filters the item query.
640 640
 	 */
641
-	public static function filter_item_query( $query ) {
641
+	public static function filter_item_query($query) {
642 642
 
643 643
 		// modify the query only if it admin and main query.
644
-		if ( ! ( is_admin() && $query->is_main_query() ) ){ 
644
+		if (!(is_admin() && $query->is_main_query())) { 
645 645
 			return $query;
646 646
 		}
647 647
 
648 648
 		// we want to modify the query for our items.
649
-		if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){
649
+		if (empty($query->query['post_type']) || 'wpi_item' != $query->query['post_type']) {
650 650
 			return $query;
651 651
 		}
652 652
 
653
-		if ( empty( $query->query_vars['meta_query'] ) ) {
653
+		if (empty($query->query_vars['meta_query'])) {
654 654
 			$query->query_vars['meta_query'] = array();
655 655
 		}
656 656
 
657 657
 		// Filter vat rule type
658
-        if ( ! empty( $_GET['vat_rule'] ) ) {
658
+        if (!empty($_GET['vat_rule'])) {
659 659
             $query->query_vars['meta_query'][] = array(
660 660
                 'key'     => '_wpinv_vat_rule',
661
-                'value'   => sanitize_text_field( $_GET['vat_rule'] ),
661
+                'value'   => sanitize_text_field($_GET['vat_rule']),
662 662
                 'compare' => '='
663 663
             );
664 664
         }
665 665
 
666 666
         // Filter vat class
667
-        if ( ! empty( $_GET['vat_class'] ) ) {
667
+        if (!empty($_GET['vat_class'])) {
668 668
             $query->query_vars['meta_query'][] = array(
669 669
                 'key'     => '_wpinv_vat_class',
670
-                'value'   => sanitize_text_field( $_GET['vat_class'] ),
670
+                'value'   => sanitize_text_field($_GET['vat_class']),
671 671
                 'compare' => '='
672 672
             );
673 673
         }
674 674
 
675 675
         // Filter item type
676
-        if ( ! empty( $_GET['type'] ) ) {
676
+        if (!empty($_GET['type'])) {
677 677
             $query->query_vars['meta_query'][] = array(
678 678
                 'key'     => '_wpinv_type',
679
-                'value'   => sanitize_text_field( $_GET['type'] ),
679
+                'value'   => sanitize_text_field($_GET['type']),
680 680
                 'compare' => '='
681 681
             );
682 682
 		}
@@ -686,15 +686,15 @@  discard block
 block discarded – undo
686 686
 	/**
687 687
 	 * Reorders items.
688 688
 	 */
689
-	public static function reorder_items( $vars ) {
689
+	public static function reorder_items($vars) {
690 690
 		global $typenow;
691 691
 
692
-		if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
692
+		if ('wpi_item' !== $typenow || empty($vars['orderby'])) {
693 693
 			return $vars;
694 694
 		}
695 695
 
696 696
 		// By item type.
697
-		if ( 'type' == $vars['orderby'] ) {
697
+		if ('type' == $vars['orderby']) {
698 698
 			return array_merge(
699 699
 				$vars,
700 700
 				array(
@@ -705,7 +705,7 @@  discard block
 block discarded – undo
705 705
 		}
706 706
 
707 707
 		// By vat class.
708
-		if ( 'vat_class' == $vars['orderby'] ) {
708
+		if ('vat_class' == $vars['orderby']) {
709 709
 			return array_merge(
710 710
 				$vars,
711 711
 				array(
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
 		}
717 717
 
718 718
 		// By vat rule.
719
-		if ( 'vat_rule' == $vars['orderby'] ) {
719
+		if ('vat_rule' == $vars['orderby']) {
720 720
 			return array_merge(
721 721
 				$vars,
722 722
 				array(
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
 		}
728 728
 
729 729
 		// By price.
730
-		if ( 'price' == $vars['orderby'] ) {
730
+		if ('price' == $vars['orderby']) {
731 731
 			return array_merge(
732 732
 				$vars,
733 733
 				array(
@@ -744,27 +744,27 @@  discard block
 block discarded – undo
744 744
 	/**
745 745
 	 * Fired when deleting a post.
746 746
 	 */
747
-	public static function delete_post( $post_id ) {
747
+	public static function delete_post($post_id) {
748 748
 
749
-		switch ( get_post_type( $post_id ) ) {
749
+		switch (get_post_type($post_id)) {
750 750
 
751 751
 			case 'wpi_item' :
752
-				do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
752
+				do_action("getpaid_before_delete_item", new WPInv_Item($post_id));
753 753
 				break;
754 754
 
755 755
 			case 'wpi_payment_form' :
756
-				do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
756
+				do_action("getpaid_before_delete_payment_form", new GetPaid_Payment_Form($post_id));
757 757
 				break;
758 758
 
759 759
 			case 'wpi_discount' :
760
-				do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
760
+				do_action("getpaid_before_delete_discount", new WPInv_Discount($post_id));
761 761
 				break;
762 762
 
763 763
 			case 'wpi_invoice' :
764
-				$invoice = new WPInv_Invoice( $post_id );
765
-				do_action( "getpaid_before_delete_invoice", $invoice );
766
-				$invoice->get_data_store()->delete_items( $invoice );
767
-				$invoice->get_data_store()->delete_special_fields( $invoice );
764
+				$invoice = new WPInv_Invoice($post_id);
765
+				do_action("getpaid_before_delete_invoice", $invoice);
766
+				$invoice->get_data_store()->delete_items($invoice);
767
+				$invoice->get_data_store()->delete_special_fields($invoice);
768 768
 				break;
769 769
 		}
770 770
 	}
@@ -777,29 +777,29 @@  discard block
 block discarded – undo
777 777
      *
778 778
      * @return mixed
779 779
      */
780
-    public static function add_display_post_states( $post_states, $post ) {
780
+    public static function add_display_post_states($post_states, $post) {
781 781
 
782
-        if ( wpinv_get_option( 'success_page', 0 ) == $post->ID ) {
783
-            $post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' );
782
+        if (wpinv_get_option('success_page', 0) == $post->ID) {
783
+            $post_states['getpaid_success_page'] = __('GetPaid Receipt Page', 'invoicing');
784 784
         }
785 785
 
786
-		foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) {
786
+		foreach (getpaid_get_invoice_post_types() as $post_type => $label) {
787 787
 
788
-			if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) {
788
+			if (wpinv_get_option("{$post_type}_history_page", 0) == $post->ID) {
789 789
 				$post_states["getpaid_{$post_type}_history_page"] = sprintf(
790
-					__( 'GetPaid %s History Page', 'invoicing' ),
790
+					__('GetPaid %s History Page', 'invoicing'),
791 791
 					$label
792 792
 				);
793 793
 			}
794 794
 
795 795
 		}
796 796
 		
797
-		if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) {
798
-            $post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscription Page', 'invoicing' );
797
+		if (wpinv_get_option('invoice_subscription_page', 0) == $post->ID) {
798
+            $post_states['getpaid_invoice_subscription_page'] = __('GetPaid Subscription Page', 'invoicing');
799 799
         }
800 800
 
801
-		if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) {
802
-            $post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' );
801
+		if (wpinv_get_option('checkout_page', 0) == $post->ID) {
802
+            $post_states['getpaid_checkout_page'] = __('GetPaid Checkout Page', 'invoicing');
803 803
         }
804 804
 
805 805
         return $post_states;
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 2 patches
Indentation   +261 added lines, -261 removed lines patch added patch discarded remove patch
@@ -12,288 +12,288 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Refresh_Prices {
14 14
 
15
-	/**
16
-	 * Contains the response for refreshing prices.
17
-	 * @var array
18
-	 */
19
-	public $response = array();
15
+    /**
16
+     * Contains the response for refreshing prices.
17
+     * @var array
18
+     */
19
+    public $response = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$this->response = array(
29
-			'submission_id'                    => $submission->id,
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $this->response = array(
29
+            'submission_id'                    => $submission->id,
30 30
             'has_recurring'                    => $submission->has_recurring,
31
-			'has_subscription_group'           => $submission->has_subscription_group(),
32
-			'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(),
31
+            'has_subscription_group'           => $submission->has_subscription_group(),
32
+            'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(),
33 33
             'is_free'                          => ! $submission->should_collect_payment_details(),
34
-		);
35
-
36
-		$this->add_totals( $submission );
37
-		$this->add_texts( $submission );
38
-		$this->add_items( $submission );
39
-		$this->add_fees( $submission );
40
-		$this->add_discounts( $submission );
41
-		$this->add_taxes( $submission );
42
-		$this->add_gateways( $submission );
43
-		$this->add_data( $submission );
44
-
45
-	}
46
-
47
-	/**
48
-	 * Adds totals to a response for submission refresh prices.
49
-	 *
50
-	 * @param GetPaid_Payment_Form_Submission $submission
51
-	 */
52
-	public function add_totals( $submission ) {
53
-
54
-		$this->response = array_merge(
55
-			$this->response,
56
-			array(
57
-
58
-				'totals'        => array(
59
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
60
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
61
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
62
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
63
-					'total'     => $submission->format_amount( $submission->get_total() ),
64
-					'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
65
-				),
66
-
67
-				'recurring'     => array(
68
-					'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
69
-					'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
70
-					'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
71
-					'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
72
-					'total'     => $submission->format_amount( $submission->get_recurring_total() ),
73
-				),
74
-
75
-				'initial_amt'   => wpinv_round_amount( $submission->get_total(), null, true ),
76
-				'currency'      => $submission->get_currency(),
77
-
78
-			)
79
-		);
80
-
81
-	}
82
-
83
-	/**
84
-	 * Adds texts to a response for submission refresh prices.
85
-	 *
86
-	 * @param GetPaid_Payment_Form_Submission $submission
87
-	 */
88
-	public function add_texts( $submission ) {
89
-
90
-		$payable = $submission->format_amount( $submission->get_total() );
91
-		$groups  = getpaid_get_subscription_groups( $submission );
92
-
93
-		if ( $submission->has_recurring && 2 > count( $groups ) ) {
94
-
95
-			$recurring = new WPInv_Item( $submission->has_recurring );
96
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
97
-			$main_item = reset( $groups );
98
-
99
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
100
-				$payable = "$payable / $period";
101
-			} else if ( $main_item ) {
102
-
103
-				$main_item = reset( $main_item );
104
-
105
-				// Calculate the next renewal date.
106
-				$_period      = $main_item->get_recurring_period( true );
107
-				$_interval    = $main_item->get_recurring_interval();
108
-
109
-				// If the subscription item has a trial period...
110
-				if ( $main_item->has_free_trial() ) {
111
-					$_period   = $main_item->get_trial_period( true );
112
-					$_interval = $main_item->get_trial_interval();
113
-				}
114
-
115
-				$payable = sprintf(
116
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
117
-					$submission->format_amount( $submission->get_total() ),
118
-					$submission->format_amount( $submission->get_recurring_total() ),
119
-					$period
120
-				);
121
-
122
-				$payable .= sprintf(
123
-					'<small class="text-muted form-text">%s</small>',
124
-					sprintf(
125
-						__( 'First renewal on %s', 'invoicing' ),
126
-						getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) )
127
-					)
128
-				);
129
-
130
-			} else {
131
-				$payable = sprintf(
132
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
133
-					$submission->format_amount( $submission->get_total() ),
134
-					$submission->format_amount( $submission->get_recurring_total() ),
135
-					$period
136
-				);
137
-			}
138
-
139
-		}
140
-
141
-		$texts = array(
142
-			'.getpaid-checkout-total-payable' => $payable,
143
-		);
144
-
145
-		foreach ( $submission->get_items() as $item ) {
146
-			$item_id                                               = $item->get_id();
147
-			$initial_price                                         = $submission->format_amount( $item->get_sub_total() - $item->item_discount );
148
-			$recurring_price                                       = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount );
149
-			$texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
150
-		}
151
-
152
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
153
-
154
-	}
155
-
156
-	/**
157
-	 * Adds items to a response for submission refresh prices.
158
-	 *
159
-	 * @param GetPaid_Payment_Form_Submission $submission
160
-	 */
161
-	public function add_items( $submission ) {
162
-
163
-		// Add items.
164
-		$items = array();
34
+        );
35
+
36
+        $this->add_totals( $submission );
37
+        $this->add_texts( $submission );
38
+        $this->add_items( $submission );
39
+        $this->add_fees( $submission );
40
+        $this->add_discounts( $submission );
41
+        $this->add_taxes( $submission );
42
+        $this->add_gateways( $submission );
43
+        $this->add_data( $submission );
44
+
45
+    }
46
+
47
+    /**
48
+     * Adds totals to a response for submission refresh prices.
49
+     *
50
+     * @param GetPaid_Payment_Form_Submission $submission
51
+     */
52
+    public function add_totals( $submission ) {
53
+
54
+        $this->response = array_merge(
55
+            $this->response,
56
+            array(
57
+
58
+                'totals'        => array(
59
+                    'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
60
+                    'discount'  => $submission->format_amount( $submission->get_discount() ),
61
+                    'fees'      => $submission->format_amount( $submission->get_fee() ),
62
+                    'tax'       => $submission->format_amount( $submission->get_tax() ),
63
+                    'total'     => $submission->format_amount( $submission->get_total() ),
64
+                    'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
65
+                ),
66
+
67
+                'recurring'     => array(
68
+                    'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
69
+                    'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
70
+                    'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
71
+                    'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
72
+                    'total'     => $submission->format_amount( $submission->get_recurring_total() ),
73
+                ),
74
+
75
+                'initial_amt'   => wpinv_round_amount( $submission->get_total(), null, true ),
76
+                'currency'      => $submission->get_currency(),
77
+
78
+            )
79
+        );
80
+
81
+    }
82
+
83
+    /**
84
+     * Adds texts to a response for submission refresh prices.
85
+     *
86
+     * @param GetPaid_Payment_Form_Submission $submission
87
+     */
88
+    public function add_texts( $submission ) {
89
+
90
+        $payable = $submission->format_amount( $submission->get_total() );
91
+        $groups  = getpaid_get_subscription_groups( $submission );
92
+
93
+        if ( $submission->has_recurring && 2 > count( $groups ) ) {
94
+
95
+            $recurring = new WPInv_Item( $submission->has_recurring );
96
+            $period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
97
+            $main_item = reset( $groups );
98
+
99
+            if ( $submission->get_total() == $submission->get_recurring_total() ) {
100
+                $payable = "$payable / $period";
101
+            } else if ( $main_item ) {
102
+
103
+                $main_item = reset( $main_item );
104
+
105
+                // Calculate the next renewal date.
106
+                $_period      = $main_item->get_recurring_period( true );
107
+                $_interval    = $main_item->get_recurring_interval();
108
+
109
+                // If the subscription item has a trial period...
110
+                if ( $main_item->has_free_trial() ) {
111
+                    $_period   = $main_item->get_trial_period( true );
112
+                    $_interval = $main_item->get_trial_interval();
113
+                }
114
+
115
+                $payable = sprintf(
116
+                    __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
117
+                    $submission->format_amount( $submission->get_total() ),
118
+                    $submission->format_amount( $submission->get_recurring_total() ),
119
+                    $period
120
+                );
121
+
122
+                $payable .= sprintf(
123
+                    '<small class="text-muted form-text">%s</small>',
124
+                    sprintf(
125
+                        __( 'First renewal on %s', 'invoicing' ),
126
+                        getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) )
127
+                    )
128
+                );
129
+
130
+            } else {
131
+                $payable = sprintf(
132
+                    __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
133
+                    $submission->format_amount( $submission->get_total() ),
134
+                    $submission->format_amount( $submission->get_recurring_total() ),
135
+                    $period
136
+                );
137
+            }
138
+
139
+        }
140
+
141
+        $texts = array(
142
+            '.getpaid-checkout-total-payable' => $payable,
143
+        );
165 144
 
166 145
         foreach ( $submission->get_items() as $item ) {
167
-			$item_id           = $item->get_id();
168
-			$items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
169
-		}
146
+            $item_id                                               = $item->get_id();
147
+            $initial_price                                         = $submission->format_amount( $item->get_sub_total() - $item->item_discount );
148
+            $recurring_price                                       = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount );
149
+            $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
150
+        }
170 151
 
171
-		$this->response = array_merge(
172
-			$this->response,
173
-			array( 'items' => $items )
174
-		);
152
+        $this->response = array_merge( $this->response, array( 'texts' => $texts ) );
175 153
 
176
-	}
154
+    }
177 155
 
178
-	/**
179
-	 * Adds fees to a response for submission refresh prices.
180
-	 *
181
-	 * @param GetPaid_Payment_Form_Submission $submission
182
-	 */
183
-	public function add_fees( $submission ) {
156
+    /**
157
+     * Adds items to a response for submission refresh prices.
158
+     *
159
+     * @param GetPaid_Payment_Form_Submission $submission
160
+     */
161
+    public function add_items( $submission ) {
184 162
 
185
-		$fees = array();
163
+        // Add items.
164
+        $items = array();
165
+
166
+        foreach ( $submission->get_items() as $item ) {
167
+            $item_id           = $item->get_id();
168
+            $items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
169
+        }
170
+
171
+        $this->response = array_merge(
172
+            $this->response,
173
+            array( 'items' => $items )
174
+        );
175
+
176
+    }
177
+
178
+    /**
179
+     * Adds fees to a response for submission refresh prices.
180
+     *
181
+     * @param GetPaid_Payment_Form_Submission $submission
182
+     */
183
+    public function add_fees( $submission ) {
184
+
185
+        $fees = array();
186 186
 
187 187
         foreach ( $submission->get_fees() as $name => $data ) {
188
-			$fees[$name] = $submission->format_amount( $data['initial_fee'] );
189
-		}
188
+            $fees[$name] = $submission->format_amount( $data['initial_fee'] );
189
+        }
190 190
 
191
-		$this->response = array_merge(
192
-			$this->response,
193
-			array( 'fees' => $fees )
194
-		);
191
+        $this->response = array_merge(
192
+            $this->response,
193
+            array( 'fees' => $fees )
194
+        );
195 195
 
196
-	}
196
+    }
197 197
 
198
-	/**
199
-	 * Adds discounts to a response for submission refresh prices.
200
-	 *
201
-	 * @param GetPaid_Payment_Form_Submission $submission
202
-	 */
203
-	public function add_discounts( $submission ) {
198
+    /**
199
+     * Adds discounts to a response for submission refresh prices.
200
+     *
201
+     * @param GetPaid_Payment_Form_Submission $submission
202
+     */
203
+    public function add_discounts( $submission ) {
204 204
 
205
-		$discounts = array();
205
+        $discounts = array();
206 206
 
207 207
         foreach ( $submission->get_discounts() as $name => $data ) {
208
-			$discounts[$name] = $submission->format_amount( $data['initial_discount'] );
209
-		}
210
-
211
-		$this->response = array_merge(
212
-			$this->response,
213
-			array( 'discounts' => $discounts )
214
-		);
208
+            $discounts[$name] = $submission->format_amount( $data['initial_discount'] );
209
+        }
215 210
 
216
-	}
211
+        $this->response = array_merge(
212
+            $this->response,
213
+            array( 'discounts' => $discounts )
214
+        );
217 215
 
218
-	/**
219
-	 * Adds taxes to a response for submission refresh prices.
220
-	 *
221
-	 * @param GetPaid_Payment_Form_Submission $submission
222
-	 */
223
-	public function add_taxes( $submission ) {
216
+    }
224 217
 
225
-		$taxes  = array();
226
-		$markup = '';
218
+    /**
219
+     * Adds taxes to a response for submission refresh prices.
220
+     *
221
+     * @param GetPaid_Payment_Form_Submission $submission
222
+     */
223
+    public function add_taxes( $submission ) {
224
+
225
+        $taxes  = array();
226
+        $markup = '';
227 227
         foreach ( $submission->get_taxes() as $name => $data ) {
228
-			$name          = sanitize_text_field( $name );
229
-			$amount        = $submission->format_amount( $data['initial_tax'] );
230
-			$taxes[$name]  = $amount;
231
-			$markup       .= "<small class='form-text'>$name : $amount</small>";
232
-		}
233
-
234
-		if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) {
235
-			$this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
236
-		}
237
-
238
-		$this->response = array_merge(
239
-			$this->response,
240
-			array( 'taxes' => $taxes )
241
-		);
242
-
243
-	}
244
-
245
-	/**
246
-	 * Adds gateways to a response for submission refresh prices.
247
-	 *
248
-	 * @param GetPaid_Payment_Form_Submission $submission
249
-	 */
250
-	public function add_gateways( $submission ) {
251
-
252
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
253
-
254
-		if ( $this->response['has_recurring'] ) {
255
-
256
-			foreach ( $gateways as $i => $gateway ) {
257
-
258
-				if (
259
-					! getpaid_payment_gateway_supports( $gateway, 'subscription' )
260
-					|| ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) )
261
-					|| ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) {
262
-					unset( $gateways[ $i ] );
263
-				}
264
-
265
-			}
266
-
267
-		}
268
-
269
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
270
-		$this->response = array_merge(
271
-			$this->response,
272
-			array( 'gateways' => $gateways )
273
-		);
274
-
275
-	}
276
-
277
-	/**
278
-	 * Adds data to a response for submission refresh prices.
279
-	 *
280
-	 * @param GetPaid_Payment_Form_Submission $submission
281
-	 */
282
-	public function add_data( $submission ) {
283
-
284
-		$this->response = array_merge(
285
-			$this->response,
286
-			array(
287
-				'js_data' => apply_filters(
288
-					'getpaid_submission_js_data',
289
-					array(
290
-						'is_recurring' => $this->response['has_recurring'],
291
-					),
292
-					$submission
293
-				)
294
-			)
295
-		);
296
-
297
-	}
228
+            $name          = sanitize_text_field( $name );
229
+            $amount        = $submission->format_amount( $data['initial_tax'] );
230
+            $taxes[$name]  = $amount;
231
+            $markup       .= "<small class='form-text'>$name : $amount</small>";
232
+        }
233
+
234
+        if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) {
235
+            $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
236
+        }
237
+
238
+        $this->response = array_merge(
239
+            $this->response,
240
+            array( 'taxes' => $taxes )
241
+        );
242
+
243
+    }
244
+
245
+    /**
246
+     * Adds gateways to a response for submission refresh prices.
247
+     *
248
+     * @param GetPaid_Payment_Form_Submission $submission
249
+     */
250
+    public function add_gateways( $submission ) {
251
+
252
+        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
253
+
254
+        if ( $this->response['has_recurring'] ) {
255
+
256
+            foreach ( $gateways as $i => $gateway ) {
257
+
258
+                if (
259
+                    ! getpaid_payment_gateway_supports( $gateway, 'subscription' )
260
+                    || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) )
261
+                    || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) {
262
+                    unset( $gateways[ $i ] );
263
+                }
264
+
265
+            }
266
+
267
+        }
268
+
269
+        $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
270
+        $this->response = array_merge(
271
+            $this->response,
272
+            array( 'gateways' => $gateways )
273
+        );
274
+
275
+    }
276
+
277
+    /**
278
+     * Adds data to a response for submission refresh prices.
279
+     *
280
+     * @param GetPaid_Payment_Form_Submission $submission
281
+     */
282
+    public function add_data( $submission ) {
283
+
284
+        $this->response = array_merge(
285
+            $this->response,
286
+            array(
287
+                'js_data' => apply_filters(
288
+                    'getpaid_submission_js_data',
289
+                    array(
290
+                        'is_recurring' => $this->response['has_recurring'],
291
+                    ),
292
+                    $submission
293
+                )
294
+            )
295
+        );
296
+
297
+    }
298 298
 
299 299
 }
Please login to merge, or discard this patch.
Spacing   +79 added lines, -79 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
  * Payment form submission refresh prices class
@@ -23,24 +23,24 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @param GetPaid_Payment_Form_Submission $submission
25 25
 	 */
26
-	public function __construct( $submission ) {
26
+	public function __construct($submission) {
27 27
 
28 28
 		$this->response = array(
29 29
 			'submission_id'                    => $submission->id,
30 30
             'has_recurring'                    => $submission->has_recurring,
31 31
 			'has_subscription_group'           => $submission->has_subscription_group(),
32 32
 			'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(),
33
-            'is_free'                          => ! $submission->should_collect_payment_details(),
33
+            'is_free'                          => !$submission->should_collect_payment_details(),
34 34
 		);
35 35
 
36
-		$this->add_totals( $submission );
37
-		$this->add_texts( $submission );
38
-		$this->add_items( $submission );
39
-		$this->add_fees( $submission );
40
-		$this->add_discounts( $submission );
41
-		$this->add_taxes( $submission );
42
-		$this->add_gateways( $submission );
43
-		$this->add_data( $submission );
36
+		$this->add_totals($submission);
37
+		$this->add_texts($submission);
38
+		$this->add_items($submission);
39
+		$this->add_fees($submission);
40
+		$this->add_discounts($submission);
41
+		$this->add_taxes($submission);
42
+		$this->add_gateways($submission);
43
+		$this->add_data($submission);
44 44
 
45 45
 	}
46 46
 
@@ -49,30 +49,30 @@  discard block
 block discarded – undo
49 49
 	 *
50 50
 	 * @param GetPaid_Payment_Form_Submission $submission
51 51
 	 */
52
-	public function add_totals( $submission ) {
52
+	public function add_totals($submission) {
53 53
 
54 54
 		$this->response = array_merge(
55 55
 			$this->response,
56 56
 			array(
57 57
 
58 58
 				'totals'        => array(
59
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
60
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
61
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
62
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
63
-					'total'     => $submission->format_amount( $submission->get_total() ),
64
-					'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
59
+					'subtotal'  => $submission->format_amount($submission->get_subtotal()),
60
+					'discount'  => $submission->format_amount($submission->get_discount()),
61
+					'fees'      => $submission->format_amount($submission->get_fee()),
62
+					'tax'       => $submission->format_amount($submission->get_tax()),
63
+					'total'     => $submission->format_amount($submission->get_total()),
64
+					'raw_total' => html_entity_decode(sanitize_text_field($submission->format_amount($submission->get_total())), ENT_QUOTES),
65 65
 				),
66 66
 
67 67
 				'recurring'     => array(
68
-					'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
69
-					'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
70
-					'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
71
-					'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
72
-					'total'     => $submission->format_amount( $submission->get_recurring_total() ),
68
+					'subtotal'  => $submission->format_amount($submission->get_recurring_subtotal()),
69
+					'discount'  => $submission->format_amount($submission->get_recurring_discount()),
70
+					'fees'      => $submission->format_amount($submission->get_recurring_fee()),
71
+					'tax'       => $submission->format_amount($submission->get_recurring_tax()),
72
+					'total'     => $submission->format_amount($submission->get_recurring_total()),
73 73
 				),
74 74
 
75
-				'initial_amt'   => wpinv_round_amount( $submission->get_total(), null, true ),
75
+				'initial_amt'   => wpinv_round_amount($submission->get_total(), null, true),
76 76
 				'currency'      => $submission->get_currency(),
77 77
 
78 78
 			)
@@ -85,53 +85,53 @@  discard block
 block discarded – undo
85 85
 	 *
86 86
 	 * @param GetPaid_Payment_Form_Submission $submission
87 87
 	 */
88
-	public function add_texts( $submission ) {
88
+	public function add_texts($submission) {
89 89
 
90
-		$payable = $submission->format_amount( $submission->get_total() );
91
-		$groups  = getpaid_get_subscription_groups( $submission );
90
+		$payable = $submission->format_amount($submission->get_total());
91
+		$groups  = getpaid_get_subscription_groups($submission);
92 92
 
93
-		if ( $submission->has_recurring && 2 > count( $groups ) ) {
93
+		if ($submission->has_recurring && 2 > count($groups)) {
94 94
 
95
-			$recurring = new WPInv_Item( $submission->has_recurring );
96
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
97
-			$main_item = reset( $groups );
95
+			$recurring = new WPInv_Item($submission->has_recurring);
96
+			$period    = getpaid_get_subscription_period_label($recurring->get_recurring_period(true), $recurring->get_recurring_interval(), '');
97
+			$main_item = reset($groups);
98 98
 
99
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
99
+			if ($submission->get_total() == $submission->get_recurring_total()) {
100 100
 				$payable = "$payable / $period";
101
-			} else if ( $main_item ) {
101
+			} else if ($main_item) {
102 102
 
103
-				$main_item = reset( $main_item );
103
+				$main_item = reset($main_item);
104 104
 
105 105
 				// Calculate the next renewal date.
106
-				$_period      = $main_item->get_recurring_period( true );
106
+				$_period      = $main_item->get_recurring_period(true);
107 107
 				$_interval    = $main_item->get_recurring_interval();
108 108
 
109 109
 				// If the subscription item has a trial period...
110
-				if ( $main_item->has_free_trial() ) {
111
-					$_period   = $main_item->get_trial_period( true );
110
+				if ($main_item->has_free_trial()) {
111
+					$_period   = $main_item->get_trial_period(true);
112 112
 					$_interval = $main_item->get_trial_interval();
113 113
 				}
114 114
 
115 115
 				$payable = sprintf(
116
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
117
-					$submission->format_amount( $submission->get_total() ),
118
-					$submission->format_amount( $submission->get_recurring_total() ),
116
+					__('%1$s (renews at %2$s / %3$s)', 'invoicing'),
117
+					$submission->format_amount($submission->get_total()),
118
+					$submission->format_amount($submission->get_recurring_total()),
119 119
 					$period
120 120
 				);
121 121
 
122 122
 				$payable .= sprintf(
123 123
 					'<small class="text-muted form-text">%s</small>',
124 124
 					sprintf(
125
-						__( 'First renewal on %s', 'invoicing' ),
126
-						getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) )
125
+						__('First renewal on %s', 'invoicing'),
126
+						getpaid_format_date(date('Y-m-d H:i:s', strtotime("+$_interval $_period", current_time('timestamp'))))
127 127
 					)
128 128
 				);
129 129
 
130 130
 			} else {
131 131
 				$payable = sprintf(
132
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
133
-					$submission->format_amount( $submission->get_total() ),
134
-					$submission->format_amount( $submission->get_recurring_total() ),
132
+					__('%1$s (renews at %2$s / %3$s)', 'invoicing'),
133
+					$submission->format_amount($submission->get_total()),
134
+					$submission->format_amount($submission->get_recurring_total()),
135 135
 					$period
136 136
 				);
137 137
 			}
@@ -142,14 +142,14 @@  discard block
 block discarded – undo
142 142
 			'.getpaid-checkout-total-payable' => $payable,
143 143
 		);
144 144
 
145
-		foreach ( $submission->get_items() as $item ) {
145
+		foreach ($submission->get_items() as $item) {
146 146
 			$item_id                                               = $item->get_id();
147
-			$initial_price                                         = $submission->format_amount( $item->get_sub_total() - $item->item_discount );
148
-			$recurring_price                                       = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount );
149
-			$texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
147
+			$initial_price                                         = $submission->format_amount($item->get_sub_total() - $item->item_discount);
148
+			$recurring_price                                       = $submission->format_amount($item->get_recurring_sub_total() - $item->recurring_item_discount);
149
+			$texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text($item, $submission->get_currency(), $initial_price, $recurring_price);
150 150
 		}
151 151
 
152
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
152
+		$this->response = array_merge($this->response, array('texts' => $texts));
153 153
 
154 154
 	}
155 155
 
@@ -158,19 +158,19 @@  discard block
 block discarded – undo
158 158
 	 *
159 159
 	 * @param GetPaid_Payment_Form_Submission $submission
160 160
 	 */
161
-	public function add_items( $submission ) {
161
+	public function add_items($submission) {
162 162
 
163 163
 		// Add items.
164 164
 		$items = array();
165 165
 
166
-        foreach ( $submission->get_items() as $item ) {
166
+        foreach ($submission->get_items() as $item) {
167 167
 			$item_id           = $item->get_id();
168
-			$items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
168
+			$items["$item_id"] = $submission->format_amount($item->get_sub_total());
169 169
 		}
170 170
 
171 171
 		$this->response = array_merge(
172 172
 			$this->response,
173
-			array( 'items' => $items )
173
+			array('items' => $items)
174 174
 		);
175 175
 
176 176
 	}
@@ -180,17 +180,17 @@  discard block
 block discarded – undo
180 180
 	 *
181 181
 	 * @param GetPaid_Payment_Form_Submission $submission
182 182
 	 */
183
-	public function add_fees( $submission ) {
183
+	public function add_fees($submission) {
184 184
 
185 185
 		$fees = array();
186 186
 
187
-        foreach ( $submission->get_fees() as $name => $data ) {
188
-			$fees[$name] = $submission->format_amount( $data['initial_fee'] );
187
+        foreach ($submission->get_fees() as $name => $data) {
188
+			$fees[$name] = $submission->format_amount($data['initial_fee']);
189 189
 		}
190 190
 
191 191
 		$this->response = array_merge(
192 192
 			$this->response,
193
-			array( 'fees' => $fees )
193
+			array('fees' => $fees)
194 194
 		);
195 195
 
196 196
 	}
@@ -200,17 +200,17 @@  discard block
 block discarded – undo
200 200
 	 *
201 201
 	 * @param GetPaid_Payment_Form_Submission $submission
202 202
 	 */
203
-	public function add_discounts( $submission ) {
203
+	public function add_discounts($submission) {
204 204
 
205 205
 		$discounts = array();
206 206
 
207
-        foreach ( $submission->get_discounts() as $name => $data ) {
208
-			$discounts[$name] = $submission->format_amount( $data['initial_discount'] );
207
+        foreach ($submission->get_discounts() as $name => $data) {
208
+			$discounts[$name] = $submission->format_amount($data['initial_discount']);
209 209
 		}
210 210
 
211 211
 		$this->response = array_merge(
212 212
 			$this->response,
213
-			array( 'discounts' => $discounts )
213
+			array('discounts' => $discounts)
214 214
 		);
215 215
 
216 216
 	}
@@ -220,24 +220,24 @@  discard block
 block discarded – undo
220 220
 	 *
221 221
 	 * @param GetPaid_Payment_Form_Submission $submission
222 222
 	 */
223
-	public function add_taxes( $submission ) {
223
+	public function add_taxes($submission) {
224 224
 
225 225
 		$taxes  = array();
226 226
 		$markup = '';
227
-        foreach ( $submission->get_taxes() as $name => $data ) {
228
-			$name          = sanitize_text_field( $name );
229
-			$amount        = $submission->format_amount( $data['initial_tax'] );
227
+        foreach ($submission->get_taxes() as $name => $data) {
228
+			$name          = sanitize_text_field($name);
229
+			$amount        = $submission->format_amount($data['initial_tax']);
230 230
 			$taxes[$name]  = $amount;
231 231
 			$markup       .= "<small class='form-text'>$name : $amount</small>";
232 232
 		}
233 233
 
234
-		if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) {
234
+		if (wpinv_display_individual_tax_rates() && !empty($taxes)) {
235 235
 			$this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
236 236
 		}
237 237
 
238 238
 		$this->response = array_merge(
239 239
 			$this->response,
240
-			array( 'taxes' => $taxes )
240
+			array('taxes' => $taxes)
241 241
 		);
242 242
 
243 243
 	}
@@ -247,29 +247,29 @@  discard block
 block discarded – undo
247 247
 	 *
248 248
 	 * @param GetPaid_Payment_Form_Submission $submission
249 249
 	 */
250
-	public function add_gateways( $submission ) {
250
+	public function add_gateways($submission) {
251 251
 
252
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
252
+		$gateways = array_keys(wpinv_get_enabled_payment_gateways());
253 253
 
254
-		if ( $this->response['has_recurring'] ) {
254
+		if ($this->response['has_recurring']) {
255 255
 
256
-			foreach ( $gateways as $i => $gateway ) {
256
+			foreach ($gateways as $i => $gateway) {
257 257
 
258 258
 				if (
259
-					! getpaid_payment_gateway_supports( $gateway, 'subscription' )
260
-					|| ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) )
261
-					|| ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) {
262
-					unset( $gateways[ $i ] );
259
+					!getpaid_payment_gateway_supports($gateway, 'subscription')
260
+					|| ($this->response['has_subscription_group'] && !getpaid_payment_gateway_supports($gateway, 'single_subscription_group'))
261
+					|| ($this->response['has_multiple_subscription_groups'] && !getpaid_payment_gateway_supports($gateway, 'multiple_subscription_groups')) ) {
262
+					unset($gateways[$i]);
263 263
 				}
264 264
 
265 265
 			}
266 266
 
267 267
 		}
268 268
 
269
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
269
+		$gateways = apply_filters('getpaid_submission_gateways', $gateways, $submission);
270 270
 		$this->response = array_merge(
271 271
 			$this->response,
272
-			array( 'gateways' => $gateways )
272
+			array('gateways' => $gateways)
273 273
 		);
274 274
 
275 275
 	}
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 	 *
280 280
 	 * @param GetPaid_Payment_Form_Submission $submission
281 281
 	 */
282
-	public function add_data( $submission ) {
282
+	public function add_data($submission) {
283 283
 
284 284
 		$this->response = array_merge(
285 285
 			$this->response,
Please login to merge, or discard this patch.
templates/payment-forms-admin/edit/pay_button.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -7,45 +7,45 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 ?>
13 13
 
14 14
 <div class='form-group'>
15 15
     <label class="d-block">
16
-        <span><?php esc_html_e( 'Button Text', 'invoicing' ); ?></span>
16
+        <span><?php esc_html_e('Button Text', 'invoicing'); ?></span>
17 17
         <input v-model='active_form_element.label' class='form-control' type="text"/>
18
-        <small class="form-text text-muted"><?php _e( '%price% will be replaced by the total payable amount', 'invoicing' ); ?></small>
18
+        <small class="form-text text-muted"><?php _e('%price% will be replaced by the total payable amount', 'invoicing'); ?></small>
19 19
     </label>
20 20
 </div>
21 21
 
22 22
 <div class='form-group'>
23 23
     <label class="d-block">
24
-        <span><?php esc_html_e( 'Free Checkout Text', 'invoicing' ); ?></span>
24
+        <span><?php esc_html_e('Free Checkout Text', 'invoicing'); ?></span>
25 25
         <input v-model='active_form_element.free' class='form-control' type="text"/>
26
-        <small class="form-text text-muted"><?php _e( 'The text to display if the total payable amount is zero', 'invoicing' ); ?></small>
26
+        <small class="form-text text-muted"><?php _e('The text to display if the total payable amount is zero', 'invoicing'); ?></small>
27 27
     </label>
28 28
 </div>
29 29
 
30 30
 <div class='form-group'>
31 31
     <label class="d-block">
32
-        <span><?php esc_html_e( 'Help Text', 'invoicing' ); ?></span>
33
-        <textarea placeholder='<?php esc_attr_e( 'Add some help text for this field', 'invoicing' ); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea>
34
-        <small class="form-text text-muted"><?php _e( 'HTML is allowed', 'invoicing' ); ?></small>
32
+        <span><?php esc_html_e('Help Text', 'invoicing'); ?></span>
33
+        <textarea placeholder='<?php esc_attr_e('Add some help text for this field', 'invoicing'); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea>
34
+        <small class="form-text text-muted"><?php _e('HTML is allowed', 'invoicing'); ?></small>
35 35
     </label>
36 36
 </div>
37 37
 
38 38
 <div class='form-group'>
39
-    <label :for="active_form_element.id + '_edit_type'"><?php esc_html_e( 'Button Type', 'invoicing' ) ?></label>
39
+    <label :for="active_form_element.id + '_edit_type'"><?php esc_html_e('Button Type', 'invoicing') ?></label>
40 40
     <select class='form-control custom-select' :id="active_form_element.id + '_edit_type'" v-model='active_form_element.class'>
41
-        <option value='btn-primary'><?php esc_html_e( 'Primary', 'invoicing' ); ?></option>
42
-        <option value='btn-secondary'><?php esc_html_e( 'Secondary', 'invoicing' ); ?></option>
43
-        <option value='btn-success'><?php esc_html_e( 'Success', 'invoicing' ); ?></option>
44
-        <option value='btn-danger'><?php esc_html_e( 'Danger', 'invoicing' ); ?></option>
45
-        <option value='btn-warning'><?php esc_html_e( 'Warning', 'invoicing' ); ?></option>
46
-        <option value='btn-info'><?php esc_html_e( 'Info', 'invoicing' ); ?></option>
47
-        <option value='btn-light'><?php esc_html_e( 'Light', 'invoicing' ); ?></option>
48
-        <option value='btn-dark'><?php esc_html_e( 'Dark', 'invoicing' ); ?></option>
49
-        <option value='btn-link'><?php esc_html_e( 'Link', 'invoicing' ); ?></option>
41
+        <option value='btn-primary'><?php esc_html_e('Primary', 'invoicing'); ?></option>
42
+        <option value='btn-secondary'><?php esc_html_e('Secondary', 'invoicing'); ?></option>
43
+        <option value='btn-success'><?php esc_html_e('Success', 'invoicing'); ?></option>
44
+        <option value='btn-danger'><?php esc_html_e('Danger', 'invoicing'); ?></option>
45
+        <option value='btn-warning'><?php esc_html_e('Warning', 'invoicing'); ?></option>
46
+        <option value='btn-info'><?php esc_html_e('Info', 'invoicing'); ?></option>
47
+        <option value='btn-light'><?php esc_html_e('Light', 'invoicing'); ?></option>
48
+        <option value='btn-dark'><?php esc_html_e('Dark', 'invoicing'); ?></option>
49
+        <option value='btn-link'><?php esc_html_e('Link', 'invoicing'); ?></option>
50 50
     </select>
51 51
 </div>
Please login to merge, or discard this patch.
templates/payment-forms-admin/edit/discount.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -7,28 +7,28 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 ?>
13 13
 
14 14
 <div class='form-group'>
15 15
     <label class="d-block">
16
-        <span><?php esc_html_e( 'Input Label', 'invoicing' ); ?></span>
16
+        <span><?php esc_html_e('Input Label', 'invoicing'); ?></span>
17 17
         <input v-model='active_form_element.input_label' class='form-control' type="text"/>
18 18
     </label>
19 19
 </div>
20 20
 
21 21
 <div class='form-group'>
22 22
     <label class="d-block">
23
-        <span><?php esc_html_e( 'Button Label', 'invoicing' ); ?></span>
23
+        <span><?php esc_html_e('Button Label', 'invoicing'); ?></span>
24 24
         <input v-model='active_form_element.button_label' class='form-control' type="text"/>
25 25
     </label>
26 26
 </div>
27 27
 
28 28
 <div class='form-group'>
29 29
     <label class="d-block">
30
-        <span><?php esc_html_e( 'Help Text', 'invoicing' ); ?></span>
31
-        <textarea placeholder='<?php esc_attr_e( 'Add some help text for this field', 'invoicing' ); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea>
32
-        <small class="form-text text-muted"><?php _e( 'HTML is allowed', 'invoicing' ); ?></small>
30
+        <span><?php esc_html_e('Help Text', 'invoicing'); ?></span>
31
+        <textarea placeholder='<?php esc_attr_e('Add some help text for this field', 'invoicing'); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea>
32
+        <small class="form-text text-muted"><?php _e('HTML is allowed', 'invoicing'); ?></small>
33 33
     </label>
34 34
 </div>
Please login to merge, or discard this patch.
templates/payment-forms-admin/edit/address.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 ?>
13 13
 
@@ -31,45 +31,45 @@  discard block
 block discarded – undo
31 31
 
32 32
                 <div class='form-group'>
33 33
                     <label class="d-block">
34
-                        <span><?php esc_html_e( 'Field Label', 'invoicing' ); ?></span>
34
+                        <span><?php esc_html_e('Field Label', 'invoicing'); ?></span>
35 35
                         <input v-model='field.label' class='form-control' type="text"/>
36 36
                     </label>
37 37
                 </div>
38 38
 
39 39
                 <div class='form-group'>
40 40
                     <label class="d-block">
41
-                        <span><?php esc_html_e( 'Placeholder text', 'invoicing' ); ?></span>
41
+                        <span><?php esc_html_e('Placeholder text', 'invoicing'); ?></span>
42 42
                         <input v-model='field.placeholder' class='form-control' type="text"/>
43 43
                     </label>
44 44
                 </div>
45 45
 
46 46
                 <div class='form-group'>
47 47
                     <label class="d-block">
48
-                        <span><?php esc_html_e( 'Width', 'invoicing' ) ?></span>
48
+                        <span><?php esc_html_e('Width', 'invoicing') ?></span>
49 49
                         <select class='form-control custom-select' v-model='field.grid_width'>
50
-                            <option value='full'><?php esc_html_e( 'Full Width', 'invoicing' ); ?></option>
51
-                            <option value='half'><?php esc_html_e( 'Half Width', 'invoicing' ); ?></option>
52
-                            <option value='third'><?php esc_html_e( '1/3 Width', 'invoicing' ); ?></option>
50
+                            <option value='full'><?php esc_html_e('Full Width', 'invoicing'); ?></option>
51
+                            <option value='half'><?php esc_html_e('Half Width', 'invoicing'); ?></option>
52
+                            <option value='third'><?php esc_html_e('1/3 Width', 'invoicing'); ?></option>
53 53
                         </select>
54 54
                     </label>
55 55
                 </div>
56 56
 
57 57
                 <div class='form-group'>
58 58
                     <label class="d-block">
59
-                        <span><?php esc_html_e( 'Help Text', 'invoicing' ); ?></span>
60
-                        <textarea placeholder='<?php esc_attr_e( 'Add some help text for this field', 'invoicing' ); ?>' v-model='field.description' class='form-control' rows='3'></textarea>
61
-                        <small class="form-text text-muted"><?php _e( 'HTML is allowed', 'invoicing' ); ?></small>
59
+                        <span><?php esc_html_e('Help Text', 'invoicing'); ?></span>
60
+                        <textarea placeholder='<?php esc_attr_e('Add some help text for this field', 'invoicing'); ?>' v-model='field.description' class='form-control' rows='3'></textarea>
61
+                        <small class="form-text text-muted"><?php _e('HTML is allowed', 'invoicing'); ?></small>
62 62
                     </label>
63 63
                 </div>
64 64
 
65 65
                 <div class='form-group form-check'>
66 66
                     <input :id="active_form_element.id + '_edit_required' + index" v-model='field.required' type='checkbox' class='form-check-input' />
67
-                    <label class='form-check-label' :for="active_form_element.id + '_edit_required' + index"><?php esc_html_e( 'Is required', 'invoicing' ); ?></label>
67
+                    <label class='form-check-label' :for="active_form_element.id + '_edit_required' + index"><?php esc_html_e('Is required', 'invoicing'); ?></label>
68 68
                 </div>
69 69
 
70 70
                 <div class='form-group form-check'>
71 71
                     <input :id="active_form_element.id + '_edit_visible' + index" v-model='field.visible' type='checkbox' class='form-check-input' />
72
-                    <label class='form-check-label' :for="active_form_element.id + '_edit_visible' + index"><?php esc_html_e( 'Is visible', 'invoicing' ); ?></label>
72
+                    <label class='form-check-label' :for="active_form_element.id + '_edit_visible' + index"><?php esc_html_e('Is visible', 'invoicing'); ?></label>
73 73
                 </div>
74 74
 
75 75
             </div>
@@ -82,18 +82,18 @@  discard block
 block discarded – undo
82 82
 
83 83
 <div class='form-group'>
84 84
     <label class="d-block">
85
-        <span><?php esc_html_e( 'Address Type', 'invoicing' ) ?><span>
85
+        <span><?php esc_html_e('Address Type', 'invoicing') ?><span>
86 86
         <select class='form-control custom-select' v-model='active_form_element.address_type'>
87
-            <option value='billing'><?php esc_html_e( 'Billing', 'invoicing' ); ?></option>
88
-            <option value='shipping'><?php esc_html_e( 'Shipping', 'invoicing' ); ?></option>
89
-            <option value='both'><?php esc_html_e( 'Both', 'invoicing' ); ?></option>
87
+            <option value='billing'><?php esc_html_e('Billing', 'invoicing'); ?></option>
88
+            <option value='shipping'><?php esc_html_e('Shipping', 'invoicing'); ?></option>
89
+            <option value='both'><?php esc_html_e('Both', 'invoicing'); ?></option>
90 90
         </select>
91 91
     </label>
92 92
 </div>
93 93
 
94 94
 <div class='form-group' v-if="active_form_element.address_type == 'both'">
95 95
     <label class="d-block">
96
-        <span><?php esc_html_e( 'Shipping Address Toggle', 'invoicing' ) ?><span>
96
+        <span><?php esc_html_e('Shipping Address Toggle', 'invoicing') ?><span>
97 97
         <input type="text" class='form-control custom-select' v-model='active_form_element.shipping_address_toggle' >
98 98
     </label>
99 99
 </div>
Please login to merge, or discard this patch.