Passed
Pull Request — master (#785)
by
unknown
04:48
created
includes/class-wpinv-item.php 1 patch
Spacing   +241 added lines, -241 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -82,30 +82,30 @@  discard block
 block discarded – undo
82 82
 	 *
83 83
 	 * @param  int|object|WPInv_Item|WP_Post $item Item to read.
84 84
 	 */
85
-	public function __construct( $item = 0 ) {
86
-		parent::__construct( $item );
87
-
88
-		if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) {
89
-			$this->set_id( $item );
90
-		} elseif ( $item instanceof self ) {
91
-			$this->set_id( $item->get_id() );
92
-		} elseif ( ! empty( $item->ID ) ) {
93
-			$this->set_id( $item->ID );
94
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) {
95
-			$this->set_id( $item_id );
96
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) {
97
-			$this->set_id( $item_id );
85
+	public function __construct($item = 0) {
86
+		parent::__construct($item);
87
+
88
+		if (!empty($item) && is_numeric($item) && 'wpi_item' == get_post_type($item)) {
89
+			$this->set_id($item);
90
+		} elseif ($item instanceof self) {
91
+			$this->set_id($item->get_id());
92
+		} elseif (!empty($item->ID)) {
93
+			$this->set_id($item->ID);
94
+		} elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'custom_id')) {
95
+			$this->set_id($item_id);
96
+		} elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'name')) {
97
+			$this->set_id($item_id);
98 98
 		} else {
99
-			$this->set_object_read( true );
99
+			$this->set_object_read(true);
100 100
 		}
101 101
 
102 102
         // Load the datastore.
103
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
103
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
104 104
 
105
-		if ( $this->get_id() > 0 ) {
106
-            $this->post = get_post( $this->get_id() );
105
+		if ($this->get_id() > 0) {
106
+            $this->post = get_post($this->get_id());
107 107
             $this->ID   = $this->get_id();
108
-			$this->data_store->read( $this );
108
+			$this->data_store->read($this);
109 109
         }
110 110
 	}
111 111
 
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 	 * @param  string $context View or edit context.
132 132
 	 * @return int
133 133
 	 */
134
-	public function get_parent_id( $context = 'view' ) {
135
-		return (int) $this->get_prop( 'parent_id', $context );
134
+	public function get_parent_id($context = 'view') {
135
+		return (int) $this->get_prop('parent_id', $context);
136 136
     }
137 137
 
138 138
     /**
@@ -142,8 +142,8 @@  discard block
 block discarded – undo
142 142
 	 * @param  string $context View or edit context.
143 143
 	 * @return string
144 144
 	 */
145
-	public function get_status( $context = 'view' ) {
146
-		return $this->get_prop( 'status', $context );
145
+	public function get_status($context = 'view') {
146
+		return $this->get_prop('status', $context);
147 147
     }
148 148
 
149 149
     /**
@@ -153,8 +153,8 @@  discard block
 block discarded – undo
153 153
 	 * @param  string $context View or edit context.
154 154
 	 * @return string
155 155
 	 */
156
-	public function get_version( $context = 'view' ) {
157
-		return $this->get_prop( 'version', $context );
156
+	public function get_version($context = 'view') {
157
+		return $this->get_prop('version', $context);
158 158
     }
159 159
 
160 160
     /**
@@ -164,8 +164,8 @@  discard block
 block discarded – undo
164 164
 	 * @param  string $context View or edit context.
165 165
 	 * @return string
166 166
 	 */
167
-	public function get_date_created( $context = 'view' ) {
168
-		return $this->get_prop( 'date_created', $context );
167
+	public function get_date_created($context = 'view') {
168
+		return $this->get_prop('date_created', $context);
169 169
     }
170 170
 
171 171
     /**
@@ -175,11 +175,11 @@  discard block
 block discarded – undo
175 175
 	 * @param  string $context View or edit context.
176 176
 	 * @return string
177 177
 	 */
178
-	public function get_date_created_gmt( $context = 'view' ) {
179
-        $date = $this->get_date_created( $context );
178
+	public function get_date_created_gmt($context = 'view') {
179
+        $date = $this->get_date_created($context);
180 180
 
181
-        if ( $date ) {
182
-            $date = get_gmt_from_date( $date );
181
+        if ($date) {
182
+            $date = get_gmt_from_date($date);
183 183
         }
184 184
 		return $date;
185 185
     }
@@ -191,8 +191,8 @@  discard block
 block discarded – undo
191 191
 	 * @param  string $context View or edit context.
192 192
 	 * @return string
193 193
 	 */
194
-	public function get_date_modified( $context = 'view' ) {
195
-		return $this->get_prop( 'date_modified', $context );
194
+	public function get_date_modified($context = 'view') {
195
+		return $this->get_prop('date_modified', $context);
196 196
     }
197 197
 
198 198
     /**
@@ -202,11 +202,11 @@  discard block
 block discarded – undo
202 202
 	 * @param  string $context View or edit context.
203 203
 	 * @return string
204 204
 	 */
205
-	public function get_date_modified_gmt( $context = 'view' ) {
206
-        $date = $this->get_date_modified( $context );
205
+	public function get_date_modified_gmt($context = 'view') {
206
+        $date = $this->get_date_modified($context);
207 207
 
208
-        if ( $date ) {
209
-            $date = get_gmt_from_date( $date );
208
+        if ($date) {
209
+            $date = get_gmt_from_date($date);
210 210
         }
211 211
 		return $date;
212 212
     }
@@ -218,8 +218,8 @@  discard block
 block discarded – undo
218 218
 	 * @param  string $context View or edit context.
219 219
 	 * @return string
220 220
 	 */
221
-	public function get_name( $context = 'view' ) {
222
-		return $this->get_prop( 'name', $context );
221
+	public function get_name($context = 'view') {
222
+		return $this->get_prop('name', $context);
223 223
     }
224 224
 
225 225
     /**
@@ -229,8 +229,8 @@  discard block
 block discarded – undo
229 229
 	 * @param  string $context View or edit context.
230 230
 	 * @return string
231 231
 	 */
232
-	public function get_title( $context = 'view' ) {
233
-		return $this->get_name( $context );
232
+	public function get_title($context = 'view') {
233
+		return $this->get_name($context);
234 234
     }
235 235
 
236 236
     /**
@@ -240,8 +240,8 @@  discard block
 block discarded – undo
240 240
 	 * @param  string $context View or edit context.
241 241
 	 * @return string
242 242
 	 */
243
-	public function get_description( $context = 'view' ) {
244
-		return $this->get_prop( 'description', $context );
243
+	public function get_description($context = 'view') {
244
+		return $this->get_prop('description', $context);
245 245
     }
246 246
 
247 247
     /**
@@ -251,8 +251,8 @@  discard block
 block discarded – undo
251 251
 	 * @param  string $context View or edit context.
252 252
 	 * @return string
253 253
 	 */
254
-	public function get_excerpt( $context = 'view' ) {
255
-		return $this->get_description( $context );
254
+	public function get_excerpt($context = 'view') {
255
+		return $this->get_description($context);
256 256
     }
257 257
 
258 258
     /**
@@ -262,8 +262,8 @@  discard block
 block discarded – undo
262 262
 	 * @param  string $context View or edit context.
263 263
 	 * @return string
264 264
 	 */
265
-	public function get_summary( $context = 'view' ) {
266
-		return $this->get_description( $context );
265
+	public function get_summary($context = 'view') {
266
+		return $this->get_description($context);
267 267
     }
268 268
 
269 269
     /**
@@ -273,8 +273,8 @@  discard block
 block discarded – undo
273 273
 	 * @param  string $context View or edit context.
274 274
 	 * @return int
275 275
 	 */
276
-	public function get_author( $context = 'view' ) {
277
-		return (int) $this->get_prop( 'author', $context );
276
+	public function get_author($context = 'view') {
277
+		return (int) $this->get_prop('author', $context);
278 278
 	}
279 279
 
280 280
 	/**
@@ -284,8 +284,8 @@  discard block
 block discarded – undo
284 284
 	 * @param  string $context View or edit context.
285 285
 	 * @return int
286 286
 	 */
287
-	public function get_owner( $context = 'view' ) {
288
-		return $this->get_author( $context );
287
+	public function get_owner($context = 'view') {
288
+		return $this->get_author($context);
289 289
     }
290 290
 
291 291
     /**
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 	 * @param  string $context View or edit context.
296 296
 	 * @return float
297 297
 	 */
298
-	public function get_price( $context = 'view' ) {
299
-        return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) );
298
+	public function get_price($context = 'view') {
299
+        return wpinv_sanitize_amount($this->get_prop('price', $context));
300 300
 	}
301 301
 
302 302
 	/**
@@ -306,24 +306,24 @@  discard block
 block discarded – undo
306 306
 	 * @param  string $context View or edit context.
307 307
 	 * @return float
308 308
 	 */
309
-	public function get_initial_price( $context = 'view', $price_id = null ) {
309
+	public function get_initial_price($context = 'view', $price_id = null) {
310 310
         $price = 0;
311 311
 
312
-        if ( null === $price_id ) {
313
-            $price = (float) $this->get_price( $context );
312
+        if (null === $price_id) {
313
+            $price = (float) $this->get_price($context);
314 314
 
315
-            if ( $this->has_free_trial() ) {
315
+            if ($this->has_free_trial()) {
316 316
                 $price = 0;
317 317
             }
318 318
         } else {
319 319
             $prices = $this->get_variable_prices();
320 320
 
321
-            if ( isset( $prices[ $price_id ] ) ) {
322
-                $price = (float) $prices[ $price_id ]['amount'];
321
+            if (isset($prices[$price_id])) {
322
+                $price = (float) $prices[$price_id]['amount'];
323 323
             }
324 324
         }
325 325
 
326
-        return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) );
326
+        return wpinv_sanitize_amount(apply_filters('wpinv_get_initial_item_price', $price, $this));
327 327
     }
328 328
 
329 329
     /**
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
 	 * @return string
335 335
 	 */
336 336
     public function get_the_price() {
337
-        return wpinv_price( $this->get_price() );
337
+        return wpinv_price($this->get_price());
338 338
 	}
339 339
 
340 340
 	/**
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 	 * @return string
346 346
 	 */
347 347
     public function get_the_initial_price() {
348
-        return wpinv_price( $this->get_initial_price() );
348
+        return wpinv_price($this->get_initial_price());
349 349
     }
350 350
 
351 351
     /**
@@ -355,8 +355,8 @@  discard block
 block discarded – undo
355 355
 	 * @param  string $context View or edit context.
356 356
 	 * @return string
357 357
 	 */
358
-	public function get_vat_rule( $context = 'view' ) {
359
-        return $this->get_prop( 'vat_rule', $context );
358
+	public function get_vat_rule($context = 'view') {
359
+        return $this->get_prop('vat_rule', $context);
360 360
     }
361 361
 
362 362
     /**
@@ -366,8 +366,8 @@  discard block
 block discarded – undo
366 366
 	 * @param  string $context View or edit context.
367 367
 	 * @return string
368 368
 	 */
369
-	public function get_vat_class( $context = 'view' ) {
370
-        return $this->get_prop( 'vat_class', $context );
369
+	public function get_vat_class($context = 'view') {
370
+        return $this->get_prop('vat_class', $context);
371 371
     }
372 372
 
373 373
     /**
@@ -377,8 +377,8 @@  discard block
 block discarded – undo
377 377
 	 * @param  string $context View or edit context.
378 378
 	 * @return string
379 379
 	 */
380
-	public function get_type( $context = 'view' ) {
381
-        return $this->get_prop( 'type', $context );
380
+	public function get_type($context = 'view') {
381
+        return $this->get_prop('type', $context);
382 382
     }
383 383
 
384 384
     /**
@@ -388,8 +388,8 @@  discard block
 block discarded – undo
388 388
 	 * @param  string $context View or edit context.
389 389
 	 * @return string
390 390
 	 */
391
-	public function get_custom_id( $context = 'view' ) {
392
-        return $this->get_prop( 'custom_id', $context );
391
+	public function get_custom_id($context = 'view') {
392
+        return $this->get_prop('custom_id', $context);
393 393
     }
394 394
 
395 395
     /**
@@ -399,8 +399,8 @@  discard block
 block discarded – undo
399 399
 	 * @param  string $context View or edit context.
400 400
 	 * @return string
401 401
 	 */
402
-	public function get_custom_name( $context = 'view' ) {
403
-        return $this->get_prop( 'custom_name', $context );
402
+	public function get_custom_name($context = 'view') {
403
+        return $this->get_prop('custom_name', $context);
404 404
     }
405 405
 
406 406
     /**
@@ -410,8 +410,8 @@  discard block
 block discarded – undo
410 410
 	 * @param  string $context View or edit context.
411 411
 	 * @return string
412 412
 	 */
413
-	public function get_custom_singular_name( $context = 'view' ) {
414
-        return $this->get_prop( 'custom_singular_name', $context );
413
+	public function get_custom_singular_name($context = 'view') {
414
+        return $this->get_prop('custom_singular_name', $context);
415 415
     }
416 416
 
417 417
     /**
@@ -421,8 +421,8 @@  discard block
 block discarded – undo
421 421
 	 * @param  string $context View or edit context.
422 422
 	 * @return int
423 423
 	 */
424
-	public function get_is_editable( $context = 'view' ) {
425
-        return (int) $this->get_prop( 'is_editable', $context );
424
+	public function get_is_editable($context = 'view') {
425
+        return (int) $this->get_prop('is_editable', $context);
426 426
     }
427 427
 
428 428
     /**
@@ -432,8 +432,8 @@  discard block
 block discarded – undo
432 432
 	 * @param  string $context View or edit context.
433 433
 	 * @return int
434 434
 	 */
435
-	public function get_editable( $context = 'view' ) {
436
-		return $this->get_is_editable( $context );
435
+	public function get_editable($context = 'view') {
436
+		return $this->get_is_editable($context);
437 437
     }
438 438
 
439 439
     /**
@@ -443,8 +443,8 @@  discard block
 block discarded – undo
443 443
 	 * @param  string $context View or edit context.
444 444
 	 * @return int
445 445
 	 */
446
-	public function get_is_dynamic_pricing( $context = 'view' ) {
447
-        return (int) $this->get_prop( 'is_dynamic_pricing', $context );
446
+	public function get_is_dynamic_pricing($context = 'view') {
447
+        return (int) $this->get_prop('is_dynamic_pricing', $context);
448 448
     }
449 449
 
450 450
     /**
@@ -454,8 +454,8 @@  discard block
 block discarded – undo
454 454
 	 * @param  string $context View or edit context.
455 455
 	 * @return float
456 456
 	 */
457
-	public function get_minimum_price( $context = 'view' ) {
458
-        return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) );
457
+	public function get_minimum_price($context = 'view') {
458
+        return wpinv_sanitize_amount($this->get_prop('minimum_price', $context));
459 459
     }
460 460
 
461 461
     /**
@@ -465,8 +465,8 @@  discard block
 block discarded – undo
465 465
      * @param  string $context View or edit context.
466 466
      * @return int
467 467
      */
468
-    public function get_is_multi_price_mode( $context = 'view' ) {
469
-        return (bool) $this->get_prop( 'is_multi_price_mode', $context );
468
+    public function get_is_multi_price_mode($context = 'view') {
469
+        return (bool) $this->get_prop('is_multi_price_mode', $context);
470 470
     }
471 471
 
472 472
     /**
@@ -487,8 +487,8 @@  discard block
 block discarded – undo
487 487
      * @param  string $context View or edit context.
488 488
      * @return int
489 489
      */
490
-    public function get_has_variable_pricing( $context = 'view' ) {
491
-        return (bool) $this->get_prop( 'has_variable_pricing', $context );
490
+    public function get_has_variable_pricing($context = 'view') {
491
+        return (bool) $this->get_prop('has_variable_pricing', $context);
492 492
     }
493 493
 
494 494
     /**
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
      * @return int
500 500
      */
501 501
     public function has_variable_pricing() {
502
-        return $this->get_has_variable_pricing( 'view' );
502
+        return $this->get_has_variable_pricing('view');
503 503
     }
504 504
 
505 505
     /**
@@ -509,20 +509,20 @@  discard block
 block discarded – undo
509 509
      * @since 2.8.9
510 510
      * @return int              The Price ID to select by default
511 511
      */
512
-    public function get_default_price_id( $context = 'view' ) {
513
-        if ( ! $this->has_variable_pricing() ) {
512
+    public function get_default_price_id($context = 'view') {
513
+        if (!$this->has_variable_pricing()) {
514 514
             return false;
515 515
         }
516 516
 
517 517
         $prices = $this->get_variable_prices();
518 518
 
519
-        $default_price_id = (int) $this->get_prop( 'default_price_id', $context );
519
+        $default_price_id = (int) $this->get_prop('default_price_id', $context);
520 520
 
521
-        if ( '' === $default_price_id || ! isset( $prices[ $default_price_id ] ) ) {
522
-            $default_price_id = current( array_keys( $prices ) );
521
+        if ('' === $default_price_id || !isset($prices[$default_price_id])) {
522
+            $default_price_id = current(array_keys($prices));
523 523
         }
524 524
 
525
-        return  absint( $default_price_id );
525
+        return  absint($default_price_id);
526 526
     }
527 527
 
528 528
     /**
@@ -534,8 +534,8 @@  discard block
 block discarded – undo
534 534
     public function get_variable_prices() {
535 535
         $prices = array();
536 536
 
537
-        if ( true === $this->has_variable_pricing() ) {
538
-            $prices = $this->get_prop( 'variable_prices', 'view' );
537
+        if (true === $this->has_variable_pricing()) {
538
+            $prices = $this->get_prop('variable_prices', 'view');
539 539
         }
540 540
 
541 541
         return $prices;
@@ -548,8 +548,8 @@  discard block
 block discarded – undo
548 548
 	 * @param  string $context View or edit context.
549 549
 	 * @return int
550 550
 	 */
551
-	public function get_is_recurring( $context = 'view' ) {
552
-        return (int) $this->get_prop( 'is_recurring', $context );
551
+	public function get_is_recurring($context = 'view') {
552
+        return (int) $this->get_prop('is_recurring', $context);
553 553
 	}
554 554
 
555 555
 	/**
@@ -559,9 +559,9 @@  discard block
 block discarded – undo
559 559
 	 * @param  string $context View or edit context.
560 560
 	 * @return float
561 561
 	 */
562
-	public function get_recurring_price( $context = 'view' ) {
563
-		$price = $this->get_price( $context );
564
-        return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) );
562
+	public function get_recurring_price($context = 'view') {
563
+		$price = $this->get_price($context);
564
+        return wpinv_sanitize_amount(apply_filters('wpinv_get_recurring_item_price', $price, $this->ID));
565 565
 	}
566 566
 
567 567
 	/**
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
 	 * @return string
573 573
 	 */
574 574
     public function get_the_recurring_price() {
575
-        return wpinv_price( $this->get_recurring_price() );
575
+        return wpinv_price($this->get_recurring_price());
576 576
 	}
577 577
 
578 578
 	/**
@@ -593,15 +593,15 @@  discard block
 block discarded – undo
593 593
 		$period   = $this->get_recurring_period();
594 594
 		$interval = $this->get_recurring_interval();
595 595
 
596
-		if ( $this->has_free_trial() ) {
596
+		if ($this->has_free_trial()) {
597 597
 			$period   = $this->get_trial_period();
598 598
 			$interval = $this->get_trial_interval();
599 599
 		}
600 600
 
601
-		$period       = $periods[ $period ];
602
-		$interval     = empty( $interval ) ? 1 : $interval;
603
-		$next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
604
-        return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this );
601
+		$period       = $periods[$period];
602
+		$interval     = empty($interval) ? 1 : $interval;
603
+		$next_renewal = strtotime("+$interval $period", current_time('timestamp'));
604
+        return apply_filters('wpinv_get_first_renewal_date', $next_renewal, $this);
605 605
     }
606 606
 
607 607
     /**
@@ -611,14 +611,14 @@  discard block
 block discarded – undo
611 611
 	 * @param  bool $full Return abbreviation or in full.
612 612
 	 * @return string
613 613
 	 */
614
-	public function get_recurring_period( $full = false ) {
615
-        $period = $this->get_prop( 'recurring_period', 'view' );
614
+	public function get_recurring_period($full = false) {
615
+        $period = $this->get_prop('recurring_period', 'view');
616 616
 
617
-        if ( $full && ! is_bool( $full ) ) {
617
+        if ($full && !is_bool($full)) {
618 618
             $full = false;
619 619
         }
620 620
 
621
-        return getpaid_sanitize_recurring_period( $period, $full );
621
+        return getpaid_sanitize_recurring_period($period, $full);
622 622
     }
623 623
 
624 624
     /**
@@ -628,9 +628,9 @@  discard block
 block discarded – undo
628 628
 	 * @param  string $context View or edit context.
629 629
 	 * @return int
630 630
 	 */
631
-	public function get_recurring_interval( $context = 'view' ) {
632
-		$interval = absint( $this->get_prop( 'recurring_interval', $context ) );
633
-		return max( 1, $interval );
631
+	public function get_recurring_interval($context = 'view') {
632
+		$interval = absint($this->get_prop('recurring_interval', $context));
633
+		return max(1, $interval);
634 634
     }
635 635
 
636 636
     /**
@@ -640,8 +640,8 @@  discard block
 block discarded – undo
640 640
 	 * @param  string $context View or edit context.
641 641
 	 * @return int
642 642
 	 */
643
-	public function get_recurring_limit( $context = 'view' ) {
644
-        return (int) $this->get_prop( 'recurring_limit', $context );
643
+	public function get_recurring_limit($context = 'view') {
644
+        return (int) $this->get_prop('recurring_limit', $context);
645 645
     }
646 646
 
647 647
     /**
@@ -651,8 +651,8 @@  discard block
 block discarded – undo
651 651
 	 * @param  string $context View or edit context.
652 652
 	 * @return int
653 653
 	 */
654
-	public function get_is_free_trial( $context = 'view' ) {
655
-        return (int) $this->get_prop( 'is_free_trial', $context );
654
+	public function get_is_free_trial($context = 'view') {
655
+        return (int) $this->get_prop('is_free_trial', $context);
656 656
     }
657 657
 
658 658
     /**
@@ -662,8 +662,8 @@  discard block
 block discarded – undo
662 662
 	 * @param  string $context View or edit context.
663 663
 	 * @return int
664 664
 	 */
665
-	public function get_free_trial( $context = 'view' ) {
666
-        return $this->get_is_free_trial( $context );
665
+	public function get_free_trial($context = 'view') {
666
+        return $this->get_is_free_trial($context);
667 667
     }
668 668
 
669 669
     /**
@@ -673,14 +673,14 @@  discard block
 block discarded – undo
673 673
 	 * @param  bool $full Return abbreviation or in full.
674 674
 	 * @return string
675 675
 	 */
676
-	public function get_trial_period( $full = false ) {
677
-        $period = $this->get_prop( 'trial_period', 'view' );
676
+	public function get_trial_period($full = false) {
677
+        $period = $this->get_prop('trial_period', 'view');
678 678
 
679
-        if ( $full && ! is_bool( $full ) ) {
679
+        if ($full && !is_bool($full)) {
680 680
             $full = false;
681 681
         }
682 682
 
683
-        return getpaid_sanitize_recurring_period( $period, $full );
683
+        return getpaid_sanitize_recurring_period($period, $full);
684 684
     }
685 685
 
686 686
     /**
@@ -690,8 +690,8 @@  discard block
 block discarded – undo
690 690
 	 * @param  string $context View or edit context.
691 691
 	 * @return int
692 692
 	 */
693
-	public function get_trial_interval( $context = 'view' ) {
694
-        return (int) $this->get_prop( 'trial_interval', $context );
693
+	public function get_trial_interval($context = 'view') {
694
+        return (int) $this->get_prop('trial_interval', $context);
695 695
 	}
696 696
 
697 697
 	/**
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
 	 * @return string
702 702
 	 */
703 703
 	public function get_edit_url() {
704
-        return get_edit_post_link( $this->get_id(), 'edit' );
704
+        return get_edit_post_link($this->get_id(), 'edit');
705 705
 	}
706 706
 
707 707
 	/**
@@ -715,35 +715,35 @@  discard block
 block discarded – undo
715 715
 	 * @since 1.0.15
716 716
 	 * @return int
717 717
 	 */
718
-	public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
718
+	public static function get_item_id_by_field($value, $field = 'custom_id', $type = '') {
719 719
 
720 720
 		// Trim the value.
721
-		$value = sanitize_text_field( $value );
722
-		if ( empty( $value ) ) {
721
+		$value = sanitize_text_field($value);
722
+		if (empty($value)) {
723 723
 			return 0;
724 724
 		}
725 725
 
726 726
         // Valid fields.
727
-        $fields = array( 'custom_id', 'name', 'slug' );
727
+        $fields = array('custom_id', 'name', 'slug');
728 728
 
729 729
 		// Ensure a field has been passed.
730
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
730
+		if (empty($field) || !in_array($field, $fields)) {
731 731
 			return 0;
732 732
 		}
733 733
 
734
-		if ( $field == 'name' ) {
734
+		if ($field == 'name') {
735 735
 			$field = 'slug';
736 736
 		}
737 737
 
738 738
 		// Maybe retrieve from the cache.
739
-		$item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" );
740
-		if ( ! empty( $item_id ) ) {
739
+		$item_id = wp_cache_get($value, "getpaid_{$type}_item_{$field}s_to_item_ids");
740
+		if (!empty($item_id)) {
741 741
 			return $item_id;
742 742
 		}
743 743
 
744 744
 		// Fetch from the db.
745 745
 		$items = array();
746
-		if ( $field == 'slug' ) {
746
+		if ($field == 'slug') {
747 747
 			$items = get_posts(
748 748
 				array(
749 749
 					'post_type'      => 'wpi_item',
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
 			);
755 755
 		}
756 756
 
757
-		if ( $field == 'custom_id' ) {
757
+		if ($field == 'custom_id') {
758 758
 			$items = get_posts(
759 759
 				array(
760 760
 					'post_type'      => 'wpi_item',
@@ -774,12 +774,12 @@  discard block
 block discarded – undo
774 774
 			);
775 775
 		}
776 776
 
777
-		if ( empty( $items ) ) {
777
+		if (empty($items)) {
778 778
 			return 0;
779 779
 		}
780 780
 
781 781
 		// Update the cache with our data
782
-		wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
782
+		wp_cache_set($value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids");
783 783
 
784 784
 		return $items[0]->ID;
785 785
     }
@@ -787,19 +787,19 @@  discard block
 block discarded – undo
787 787
     /**
788 788
      * Margic method for retrieving a property.
789 789
      */
790
-    public function __get( $key ) {
790
+    public function __get($key) {
791 791
 
792 792
         // Check if we have a helper method for that.
793
-        if ( method_exists( $this, 'get_' . $key ) ) {
794
-            return call_user_func( array( $this, 'get_' . $key ) );
793
+        if (method_exists($this, 'get_' . $key)) {
794
+            return call_user_func(array($this, 'get_' . $key));
795 795
         }
796 796
 
797 797
         // Check if the key is in the associated $post object.
798
-        if ( ! empty( $this->post ) && isset( $this->post->$key ) ) {
798
+        if (!empty($this->post) && isset($this->post->$key)) {
799 799
             return $this->post->$key;
800 800
         }
801 801
 
802
-        return $this->get_prop( $key );
802
+        return $this->get_prop($key);
803 803
     }
804 804
 
805 805
     /*
@@ -817,11 +817,11 @@  discard block
 block discarded – undo
817 817
 	 *
818 818
 	 * @since 1.0.19
819 819
 	 */
820
-	public function set_parent_id( $value ) {
821
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
820
+	public function set_parent_id($value) {
821
+		if ($value && ($value === $this->get_id() || !get_post($value))) {
822 822
 			return;
823 823
 		}
824
-		$this->set_prop( 'parent_id', absint( $value ) );
824
+		$this->set_prop('parent_id', absint($value));
825 825
 	}
826 826
 
827 827
     /**
@@ -831,10 +831,10 @@  discard block
 block discarded – undo
831 831
 	 * @param  string $status New status.
832 832
 	 * @return array details of change.
833 833
 	 */
834
-	public function set_status( $status ) {
834
+	public function set_status($status) {
835 835
         $old_status = $this->get_status();
836 836
 
837
-        $this->set_prop( 'status', $status );
837
+        $this->set_prop('status', $status);
838 838
 
839 839
 		return array(
840 840
 			'from' => $old_status,
@@ -847,8 +847,8 @@  discard block
 block discarded – undo
847 847
 	 *
848 848
 	 * @since 1.0.19
849 849
 	 */
850
-	public function set_version( $value ) {
851
-		$this->set_prop( 'version', $value );
850
+	public function set_version($value) {
851
+		$this->set_prop('version', $value);
852 852
     }
853 853
 
854 854
     /**
@@ -858,11 +858,11 @@  discard block
 block discarded – undo
858 858
 	 * @param string $value Value to set.
859 859
      * @return bool Whether or not the date was set.
860 860
 	 */
861
-	public function set_date_created( $value ) {
862
-        $date = strtotime( $value );
861
+	public function set_date_created($value) {
862
+        $date = strtotime($value);
863 863
 
864
-        if ( $date ) {
865
-            $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) );
864
+        if ($date) {
865
+            $this->set_prop('date_created', date('Y-m-d H:i:s', $date));
866 866
             return true;
867 867
         }
868 868
 
@@ -876,11 +876,11 @@  discard block
 block discarded – undo
876 876
 	 * @param string $value Value to set.
877 877
      * @return bool Whether or not the date was set.
878 878
 	 */
879
-	public function set_date_modified( $value ) {
880
-        $date = strtotime( $value );
879
+	public function set_date_modified($value) {
880
+        $date = strtotime($value);
881 881
 
882
-        if ( $date ) {
883
-            $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) );
882
+        if ($date) {
883
+            $this->set_prop('date_modified', date('Y-m-d H:i:s', $date));
884 884
             return true;
885 885
         }
886 886
 
@@ -893,9 +893,9 @@  discard block
 block discarded – undo
893 893
 	 * @since 1.0.19
894 894
 	 * @param  string $value New name.
895 895
 	 */
896
-	public function set_name( $value ) {
897
-        $name = sanitize_text_field( $value );
898
-		$this->set_prop( 'name', $name );
896
+	public function set_name($value) {
897
+        $name = sanitize_text_field($value);
898
+		$this->set_prop('name', $name);
899 899
     }
900 900
 
901 901
     /**
@@ -904,8 +904,8 @@  discard block
 block discarded – undo
904 904
 	 * @since 1.0.19
905 905
 	 * @param  string $value New name.
906 906
 	 */
907
-	public function set_title( $value ) {
908
-		$this->set_name( $value );
907
+	public function set_title($value) {
908
+		$this->set_name($value);
909 909
     }
910 910
 
911 911
     /**
@@ -914,9 +914,9 @@  discard block
 block discarded – undo
914 914
 	 * @since 1.0.19
915 915
 	 * @param  string $value New description.
916 916
 	 */
917
-	public function set_description( $value ) {
918
-		$description = wp_kses_post( wp_unslash( $value ) );
919
-		return $this->set_prop( 'description', $description );
917
+	public function set_description($value) {
918
+		$description = wp_kses_post(wp_unslash($value));
919
+		return $this->set_prop('description', $description);
920 920
     }
921 921
 
922 922
     /**
@@ -925,8 +925,8 @@  discard block
 block discarded – undo
925 925
 	 * @since 1.0.19
926 926
 	 * @param  string $value New description.
927 927
 	 */
928
-	public function set_excerpt( $value ) {
929
-		$this->set_description( $value );
928
+	public function set_excerpt($value) {
929
+		$this->set_description($value);
930 930
     }
931 931
 
932 932
     /**
@@ -935,8 +935,8 @@  discard block
 block discarded – undo
935 935
 	 * @since 1.0.19
936 936
 	 * @param  string $value New description.
937 937
 	 */
938
-	public function set_summary( $value ) {
939
-		$this->set_description( $value );
938
+	public function set_summary($value) {
939
+		$this->set_description($value);
940 940
     }
941 941
 
942 942
     /**
@@ -945,8 +945,8 @@  discard block
 block discarded – undo
945 945
 	 * @since 1.0.19
946 946
 	 * @param  int $value New author.
947 947
 	 */
948
-	public function set_author( $value ) {
949
-		$this->set_prop( 'author', (int) $value );
948
+	public function set_author($value) {
949
+		$this->set_prop('author', (int) $value);
950 950
 	}
951 951
 
952 952
 	/**
@@ -955,8 +955,8 @@  discard block
 block discarded – undo
955 955
 	 * @since 1.0.19
956 956
 	 * @param  int $value New author.
957 957
 	 */
958
-	public function set_owner( $value ) {
959
-		$this->set_author( $value );
958
+	public function set_owner($value) {
959
+		$this->set_author($value);
960 960
     }
961 961
 
962 962
     /**
@@ -965,8 +965,8 @@  discard block
 block discarded – undo
965 965
 	 * @since 1.0.19
966 966
 	 * @param  float $value New price.
967 967
 	 */
968
-	public function set_price( $value ) {
969
-        $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) );
968
+	public function set_price($value) {
969
+        $this->set_prop('price', (float) wpinv_sanitize_amount($value));
970 970
     }
971 971
 
972 972
     /**
@@ -975,8 +975,8 @@  discard block
 block discarded – undo
975 975
 	 * @since 1.0.19
976 976
 	 * @param  string $value new rule.
977 977
 	 */
978
-	public function set_vat_rule( $value ) {
979
-        $this->set_prop( 'vat_rule', $value );
978
+	public function set_vat_rule($value) {
979
+        $this->set_prop('vat_rule', $value);
980 980
     }
981 981
 
982 982
     /**
@@ -985,8 +985,8 @@  discard block
 block discarded – undo
985 985
 	 * @since 1.0.19
986 986
 	 * @param  string $value new class.
987 987
 	 */
988
-	public function set_vat_class( $value ) {
989
-        $this->set_prop( 'vat_class', $value );
988
+	public function set_vat_class($value) {
989
+        $this->set_prop('vat_class', $value);
990 990
     }
991 991
 
992 992
     /**
@@ -996,13 +996,13 @@  discard block
 block discarded – undo
996 996
 	 * @param  string $value new item type.
997 997
 	 * @return string
998 998
 	 */
999
-	public function set_type( $value ) {
999
+	public function set_type($value) {
1000 1000
 
1001
-        if ( empty( $value ) ) {
1001
+        if (empty($value)) {
1002 1002
             $value = 'custom';
1003 1003
         }
1004 1004
 
1005
-        $this->set_prop( 'type', $value );
1005
+        $this->set_prop('type', $value);
1006 1006
     }
1007 1007
 
1008 1008
     /**
@@ -1011,8 +1011,8 @@  discard block
 block discarded – undo
1011 1011
 	 * @since 1.0.19
1012 1012
 	 * @param  string $value new custom id.
1013 1013
 	 */
1014
-	public function set_custom_id( $value ) {
1015
-        $this->set_prop( 'custom_id', $value );
1014
+	public function set_custom_id($value) {
1015
+        $this->set_prop('custom_id', $value);
1016 1016
     }
1017 1017
 
1018 1018
     /**
@@ -1021,8 +1021,8 @@  discard block
 block discarded – undo
1021 1021
 	 * @since 1.0.19
1022 1022
 	 * @param  string $value new custom name.
1023 1023
 	 */
1024
-	public function set_custom_name( $value ) {
1025
-        $this->set_prop( 'custom_name', $value );
1024
+	public function set_custom_name($value) {
1025
+        $this->set_prop('custom_name', $value);
1026 1026
     }
1027 1027
 
1028 1028
     /**
@@ -1031,8 +1031,8 @@  discard block
 block discarded – undo
1031 1031
 	 * @since 1.0.19
1032 1032
 	 * @param  string $value new custom singular name.
1033 1033
 	 */
1034
-	public function set_custom_singular_name( $value ) {
1035
-        $this->set_prop( 'custom_singular_name', $value );
1034
+	public function set_custom_singular_name($value) {
1035
+        $this->set_prop('custom_singular_name', $value);
1036 1036
     }
1037 1037
 
1038 1038
     /**
@@ -1041,8 +1041,8 @@  discard block
 block discarded – undo
1041 1041
 	 * @since 1.0.19
1042 1042
 	 * @param  int|bool $value whether or not the item is editable.
1043 1043
 	 */
1044
-	public function set_is_editable( $value ) {
1045
-		$this->set_prop( 'is_editable', (int) $value );
1044
+	public function set_is_editable($value) {
1045
+		$this->set_prop('is_editable', (int) $value);
1046 1046
     }
1047 1047
 
1048 1048
     /**
@@ -1051,8 +1051,8 @@  discard block
 block discarded – undo
1051 1051
 	 * @since 1.0.19
1052 1052
 	 * @param  int|bool $value whether or not dynamic pricing is allowed.
1053 1053
 	 */
1054
-	public function set_is_dynamic_pricing( $value ) {
1055
-        $this->set_prop( 'is_dynamic_pricing', (int) $value );
1054
+	public function set_is_dynamic_pricing($value) {
1055
+        $this->set_prop('is_dynamic_pricing', (int) $value);
1056 1056
     }
1057 1057
 
1058 1058
     /**
@@ -1061,8 +1061,8 @@  discard block
 block discarded – undo
1061 1061
 	 * @since 1.0.19
1062 1062
 	 * @param  float $value minimum price.
1063 1063
 	 */
1064
-	public function set_minimum_price( $value ) {
1065
-        $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) );
1064
+	public function set_minimum_price($value) {
1065
+        $this->set_prop('minimum_price', (float) wpinv_sanitize_amount($value));
1066 1066
     }
1067 1067
 
1068 1068
     /**
@@ -1071,8 +1071,8 @@  discard block
 block discarded – undo
1071 1071
 	 * @since 1.0.19
1072 1072
 	 * @param  int|bool $value whether or not dynamic pricing is allowed.
1073 1073
 	 */
1074
-	public function set_is_multi_price_mode( $value ) {
1075
-        $this->set_prop( 'is_multi_price_mode', (int) $value );
1074
+	public function set_is_multi_price_mode($value) {
1075
+        $this->set_prop('is_multi_price_mode', (int) $value);
1076 1076
     }
1077 1077
 
1078 1078
     /**
@@ -1081,8 +1081,8 @@  discard block
 block discarded – undo
1081 1081
 	 * @since 1.0.19
1082 1082
 	 * @param  int|bool $value whether or not dynamic pricing is allowed.
1083 1083
 	 */
1084
-	public function set_has_variable_pricing( $value ) {
1085
-        $this->set_prop( 'has_variable_pricing', (int) $value );
1084
+	public function set_has_variable_pricing($value) {
1085
+        $this->set_prop('has_variable_pricing', (int) $value);
1086 1086
     }
1087 1087
 
1088 1088
     /**
@@ -1091,8 +1091,8 @@  discard block
 block discarded – undo
1091 1091
 	 * @since 1.0.19
1092 1092
 	 * @param  int $value default price ID.
1093 1093
 	 */
1094
-	public function set_default_price_id( $value ) {
1095
-        return $this->set_prop( 'default_price_id', (int) $value );
1094
+	public function set_default_price_id($value) {
1095
+        return $this->set_prop('default_price_id', (int) $value);
1096 1096
     }
1097 1097
 
1098 1098
     /**
@@ -1101,23 +1101,23 @@  discard block
 block discarded – undo
1101 1101
 	 * @since 1.0.19
1102 1102
 	 * @param  int $prices variable prices.
1103 1103
 	 */
1104
-	public function set_variable_prices( $prices ) {
1105
-        if ( ! is_array( $prices ) ) {
1104
+	public function set_variable_prices($prices) {
1105
+        if (!is_array($prices)) {
1106 1106
             $prices = array();
1107 1107
         }
1108 1108
 
1109
-        foreach ( $prices as $id => $price ) {
1110
-            if ( empty( $price['amount'] ) && empty( $price['name'] ) ) {
1111
-                unset( $prices[ $id ] );
1109
+        foreach ($prices as $id => $price) {
1110
+            if (empty($price['amount']) && empty($price['name'])) {
1111
+                unset($prices[$id]);
1112 1112
                 continue;
1113
-            } elseif ( empty( $price['amount'] ) ) {
1113
+            } elseif (empty($price['amount'])) {
1114 1114
                 $price['amount'] = 0;
1115 1115
             }
1116 1116
 
1117
-            $prices[ $id ]['amount'] = getpaid_standardize_amount( $price['amount'] );
1117
+            $prices[$id]['amount'] = getpaid_standardize_amount($price['amount']);
1118 1118
         }
1119 1119
 
1120
-        return $this->set_prop( 'variable_prices', $prices );
1120
+        return $this->set_prop('variable_prices', $prices);
1121 1121
     }
1122 1122
 
1123 1123
     /**
@@ -1126,8 +1126,8 @@  discard block
 block discarded – undo
1126 1126
 	 * @since 1.0.19
1127 1127
 	 * @param  int|bool $value whether or not dynamic pricing is allowed.
1128 1128
 	 */
1129
-	public function set_is_recurring( $value ) {
1130
-        $this->set_prop( 'is_recurring', (int) $value );
1129
+	public function set_is_recurring($value) {
1130
+        $this->set_prop('is_recurring', (int) $value);
1131 1131
     }
1132 1132
 
1133 1133
     /**
@@ -1136,8 +1136,8 @@  discard block
 block discarded – undo
1136 1136
 	 * @since 1.0.19
1137 1137
 	 * @param  string $value new period.
1138 1138
 	 */
1139
-	public function set_recurring_period( $value ) {
1140
-        $this->set_prop( 'recurring_period', $value );
1139
+	public function set_recurring_period($value) {
1140
+        $this->set_prop('recurring_period', $value);
1141 1141
     }
1142 1142
 
1143 1143
     /**
@@ -1146,8 +1146,8 @@  discard block
 block discarded – undo
1146 1146
 	 * @since 1.0.19
1147 1147
 	 * @param  int $value recurring interval.
1148 1148
 	 */
1149
-	public function set_recurring_interval( $value ) {
1150
-        return $this->set_prop( 'recurring_interval', (int) $value );
1149
+	public function set_recurring_interval($value) {
1150
+        return $this->set_prop('recurring_interval', (int) $value);
1151 1151
     }
1152 1152
 
1153 1153
     /**
@@ -1156,8 +1156,8 @@  discard block
 block discarded – undo
1156 1156
 	 * @param  int $value The recurring limit.
1157 1157
 	 * @return int
1158 1158
 	 */
1159
-	public function set_recurring_limit( $value ) {
1160
-        $this->set_prop( 'recurring_limit', (int) $value );
1159
+	public function set_recurring_limit($value) {
1160
+        $this->set_prop('recurring_limit', (int) $value);
1161 1161
     }
1162 1162
 
1163 1163
     /**
@@ -1166,8 +1166,8 @@  discard block
 block discarded – undo
1166 1166
 	 * @since 1.0.19
1167 1167
 	 * @param  int|bool $value whether or not it has a free trial.
1168 1168
 	 */
1169
-	public function set_is_free_trial( $value ) {
1170
-        $this->set_prop( 'is_free_trial', (int) $value );
1169
+	public function set_is_free_trial($value) {
1170
+        $this->set_prop('is_free_trial', (int) $value);
1171 1171
     }
1172 1172
 
1173 1173
     /**
@@ -1176,8 +1176,8 @@  discard block
 block discarded – undo
1176 1176
 	 * @since 1.0.19
1177 1177
 	 * @param  string $value trial period.
1178 1178
 	 */
1179
-	public function set_trial_period( $value ) {
1180
-        $this->set_prop( 'trial_period', $value );
1179
+	public function set_trial_period($value) {
1180
+        $this->set_prop('trial_period', $value);
1181 1181
     }
1182 1182
 
1183 1183
     /**
@@ -1186,8 +1186,8 @@  discard block
 block discarded – undo
1186 1186
 	 * @since 1.0.19
1187 1187
 	 * @param  int $value trial interval.
1188 1188
 	 */
1189
-	public function set_trial_interval( $value ) {
1190
-        $this->set_prop( 'trial_interval', $value );
1189
+	public function set_trial_interval($value) {
1190
+        $this->set_prop('trial_interval', $value);
1191 1191
     }
1192 1192
 
1193 1193
     /**
@@ -1196,11 +1196,11 @@  discard block
 block discarded – undo
1196 1196
      * @deprecated
1197 1197
 	 * @return int item id
1198 1198
      */
1199
-    public function create( $data = array() ) {
1199
+    public function create($data = array()) {
1200 1200
 
1201 1201
 		// Set the properties.
1202
-		if ( is_array( $data ) ) {
1203
-			$this->set_props( $data );
1202
+		if (is_array($data)) {
1203
+			$this->set_props($data);
1204 1204
 		}
1205 1205
 
1206 1206
 		// Save the item.
@@ -1213,8 +1213,8 @@  discard block
 block discarded – undo
1213 1213
      * @deprecated
1214 1214
 	 * @return int item id
1215 1215
      */
1216
-    public function update( $data = array() ) {
1217
-        return $this->create( $data );
1216
+    public function update($data = array()) {
1217
+        return $this->create($data);
1218 1218
     }
1219 1219
 
1220 1220
     /*
@@ -1254,7 +1254,7 @@  discard block
 block discarded – undo
1254 1254
 	 */
1255 1255
     public function has_free_trial() {
1256 1256
         $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
1257
-        return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this );
1257
+        return (bool) apply_filters('wpinv_item_has_free_trial', $has_trial, $this->ID, $this);
1258 1258
     }
1259 1259
 
1260 1260
     /**
@@ -1264,8 +1264,8 @@  discard block
 block discarded – undo
1264 1264
 	 * @return bool
1265 1265
 	 */
1266 1266
     public function is_free() {
1267
-        $is_free   = $this->get_price() == 0;
1268
-        return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this );
1267
+        $is_free = $this->get_price() == 0;
1268
+        return (bool) apply_filters('wpinv_is_free_item', $is_free, $this->ID, $this);
1269 1269
     }
1270 1270
 
1271 1271
     /**
@@ -1274,9 +1274,9 @@  discard block
 block discarded – undo
1274 1274
 	 * @param array|string $status Status to check.
1275 1275
 	 * @return bool
1276 1276
 	 */
1277
-	public function has_status( $status ) {
1278
-		$has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1279
-		return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1277
+	public function has_status($status) {
1278
+		$has_status = (is_array($status) && in_array($this->get_status(), $status, true)) || $this->get_status() === $status;
1279
+		return (bool) apply_filters('getpaid_item_has_status', $has_status, $this, $status);
1280 1280
     }
1281 1281
 
1282 1282
     /**
@@ -1285,9 +1285,9 @@  discard block
 block discarded – undo
1285 1285
 	 * @param array|string $type Type to check.
1286 1286
 	 * @return bool
1287 1287
 	 */
1288
-	public function is_type( $type ) {
1289
-		$is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1290
-		return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1288
+	public function is_type($type) {
1289
+		$is_type = (is_array($type) && in_array($this->get_type(), $type, true)) || $this->get_type() === $type;
1290
+		return (bool) apply_filters('getpaid_item_is_type', $is_type, $this, $type);
1291 1291
 	}
1292 1292
 
1293 1293
     /**
@@ -1298,7 +1298,7 @@  discard block
 block discarded – undo
1298 1298
 	 */
1299 1299
     public function is_editable() {
1300 1300
         $is_editable = $this->get_is_editable();
1301
-        return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this );
1301
+        return (bool) apply_filters('wpinv_item_is_editable', $is_editable, $this->ID, $this);
1302 1302
 	}
1303 1303
 
1304 1304
 	/**
@@ -1317,11 +1317,11 @@  discard block
 block discarded – undo
1317 1317
     public function can_purchase() {
1318 1318
         $can_purchase = $this->exists();
1319 1319
 
1320
-        if ( ! current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) {
1320
+        if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') {
1321 1321
             $can_purchase = false;
1322 1322
         }
1323 1323
 
1324
-        return (bool) apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this );
1324
+        return (bool) apply_filters('wpinv_can_purchase_item', $can_purchase, $this);
1325 1325
     }
1326 1326
 
1327 1327
     /**
@@ -1331,6 +1331,6 @@  discard block
 block discarded – undo
1331 1331
 	 * @return bool
1332 1332
 	 */
1333 1333
     public function supports_dynamic_pricing() {
1334
-        return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
1334
+        return (bool) apply_filters('wpinv_item_supports_dynamic_pricing', true, $this);
1335 1335
     }
1336 1336
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-form-item.php 1 patch
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
 	 * @param  string $context View or edit context.
103 103
 	 * @return string
104 104
 	 */
105
-	public function get_name( $context = 'view' ) {
106
-		$name = parent::get_name( $context );
107
-		return $name . wpinv_get_item_suffix( $this );
105
+	public function get_name($context = 'view') {
106
+		$name = parent::get_name($context);
107
+		return $name . wpinv_get_item_suffix($this);
108 108
 	}
109 109
 
110 110
 	/**
@@ -114,8 +114,8 @@  discard block
 block discarded – undo
114 114
 	 * @param  string $context View or edit context.
115 115
 	 * @return string
116 116
 	 */
117
-	public function get_raw_name( $context = 'view' ) {
118
-		return parent::get_name( $context );
117
+	public function get_raw_name($context = 'view') {
118
+		return parent::get_name($context);
119 119
 	}
120 120
 
121 121
 	/**
@@ -125,13 +125,13 @@  discard block
 block discarded – undo
125 125
 	 * @param  string $context View or edit context.
126 126
 	 * @return string
127 127
 	 */
128
-	public function get_description( $context = 'view' ) {
128
+	public function get_description($context = 'view') {
129 129
 
130
-		if ( isset( $this->custom_description ) ) {
130
+		if (isset($this->custom_description)) {
131 131
 			return $this->custom_description;
132 132
 		}
133 133
 
134
-		return parent::get_description( $context );
134
+		return parent::get_description($context);
135 135
 	}
136 136
 
137 137
 	/**
@@ -141,8 +141,8 @@  discard block
 block discarded – undo
141 141
 	 * @param  string $context View or edit context.
142 142
 	 * @return float
143 143
 	 */
144
-	public function get_sub_total( $context = 'view', $price_id = null ) {
145
-		return $this->get_quantity( $context ) * $this->get_initial_price( $context, $price_id );
144
+	public function get_sub_total($context = 'view', $price_id = null) {
145
+		return $this->get_quantity($context) * $this->get_initial_price($context, $price_id);
146 146
 	}
147 147
 
148 148
 	/**
@@ -152,10 +152,10 @@  discard block
 block discarded – undo
152 152
 	 * @param  string $context View or edit context.
153 153
 	 * @return float
154 154
 	 */
155
-	public function get_recurring_sub_total( $context = 'view' ) {
155
+	public function get_recurring_sub_total($context = 'view') {
156 156
 
157
-		if ( $this->is_recurring() ) {
158
-			return $this->get_quantity( $context ) * $this->get_price( $context );
157
+		if ($this->is_recurring()) {
158
+			return $this->get_quantity($context) * $this->get_price($context);
159 159
 		}
160 160
 
161 161
 		return 0;
@@ -164,8 +164,8 @@  discard block
 block discarded – undo
164 164
 	/**
165 165
 	 * @deprecated
166 166
 	 */
167
-	public function get_qantity( $context = 'view' ) {
168
-		return $this->get_quantity( $context );
167
+	public function get_qantity($context = 'view') {
168
+		return $this->get_quantity($context);
169 169
 	}
170 170
 
171 171
 	/**
@@ -175,11 +175,11 @@  discard block
 block discarded – undo
175 175
 	 * @param  string $context View or edit context.
176 176
 	 * @return float
177 177
 	 */
178
-	public function get_quantity( $context = 'view' ) {
178
+	public function get_quantity($context = 'view') {
179 179
 		$quantity = (float) $this->quantity;
180 180
 
181
-		if ( 'view' === $context ) {
182
-			return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this );
181
+		if ('view' === $context) {
182
+			return apply_filters('getpaid_payment_form_item_quantity', $quantity, $this);
183 183
 		}
184 184
 
185 185
 		return $quantity;
@@ -192,11 +192,11 @@  discard block
 block discarded – undo
192 192
 	 * @param  string $context View or edit context.
193 193
 	 * @return meta
194 194
 	 */
195
-	public function get_item_meta( $context = 'view' ) {
195
+	public function get_item_meta($context = 'view') {
196 196
 		$meta = $this->meta;
197 197
 
198
-		if ( 'view' === $context ) {
199
-			return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this );
198
+		if ('view' === $context) {
199
+			return apply_filters('getpaid_payment_form_item_meta', $meta, $this);
200 200
 		}
201 201
 
202 202
 		return $meta;
@@ -209,11 +209,11 @@  discard block
 block discarded – undo
209 209
 	 * @param  string $context View or edit context.
210 210
 	 * @return bool
211 211
 	 */
212
-	public function get_allow_quantities( $context = 'view' ) {
212
+	public function get_allow_quantities($context = 'view') {
213 213
 		$allow_quantities = (bool) $this->allow_quantities;
214 214
 
215
-		if ( 'view' === $context ) {
216
-			return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this );
215
+		if ('view' === $context) {
216
+			return apply_filters('getpaid_payment_form_item_allow_quantities', $allow_quantities, $this);
217 217
 		}
218 218
 
219 219
 		return $allow_quantities;
@@ -226,11 +226,11 @@  discard block
 block discarded – undo
226 226
 	 * @param  string $context View or edit context.
227 227
 	 * @return bool
228 228
 	 */
229
-	public function get_is_required( $context = 'view' ) {
229
+	public function get_is_required($context = 'view') {
230 230
 		$is_required = (bool) $this->is_required;
231 231
 
232
-		if ( 'view' === $context ) {
233
-			return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this );
232
+		if ('view' === $context) {
233
+			return apply_filters('getpaid_payment_form_item_is_required', $is_required, $this);
234 234
 		}
235 235
 
236 236
 		return $is_required;
@@ -243,11 +243,11 @@  discard block
 block discarded – undo
243 243
 	 * @param  string $context View or edit context.
244 244
 	 * @return int
245 245
 	 */
246
-	public function get_price_id( $context = 'view' ) {
246
+	public function get_price_id($context = 'view') {
247 247
 		$price_id = (int) $this->price_id;
248 248
 
249
-		if ( 'view' === $context ) {
250
-			return apply_filters( 'getpaid_payment_form_item_price_id', $price_id, $this );
249
+		if ('view' === $context) {
250
+			return apply_filters('getpaid_payment_form_item_price_id', $price_id, $this);
251 251
 		}
252 252
 
253 253
 		return $price_id;
@@ -259,11 +259,11 @@  discard block
 block discarded – undo
259 259
 	 * @since 1.0.19
260 260
 	 * @return array
261 261
 	 */
262
-	public function prepare_data_for_use( $required = null ) {
262
+	public function prepare_data_for_use($required = null) {
263 263
 
264
-		$required = is_null( $required ) ? $this->is_required() : $required;
264
+		$required = is_null($required) ? $this->is_required() : $required;
265 265
 		return array(
266
-			'title'            => wp_strip_all_tags( $this->get_name() ),
266
+			'title'            => wp_strip_all_tags($this->get_name()),
267 267
 			'id'               => $this->get_id(),
268 268
 			'price'            => $this->get_price(),
269 269
 			'recurring'        => $this->is_recurring(),
@@ -280,30 +280,30 @@  discard block
 block discarded – undo
280 280
 	 * @since 1.0.19
281 281
 	 * @return array
282 282
 	 */
283
-	public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) {
283
+	public function prepare_data_for_invoice_edit_ajax($currency = '', $is_renewal = false) {
284 284
 
285
-		$description = getpaid_item_recurring_price_help_text( $this, $currency );
285
+		$description = getpaid_item_recurring_price_help_text($this, $currency);
286 286
 
287
-		if ( $description ) {
287
+		if ($description) {
288 288
 			$description = "<div class='getpaid-subscription-help-text'>$description</div>";
289 289
 		}
290 290
 
291
-		$price    = ! $is_renewal ? $this->get_price() : $this->get_recurring_price();
292
-		$subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total();
291
+		$price    = !$is_renewal ? $this->get_price() : $this->get_recurring_price();
292
+		$subtotal = !$is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total();
293 293
 		return array(
294 294
 			'id'     => $this->get_id(),
295 295
 			'texts'  => array(
296
-				'item-name'        => sanitize_text_field( $this->get_name() ),
297
-				'item-description' => wp_kses_post( $this->get_description() ) . $description,
298
-				'item-quantity'    => floatval( $this->get_quantity() ),
299
-				'item-price'       => wpinv_price( $price, $currency ),
300
-				'item-total'       => wpinv_price( $subtotal, $currency ),
296
+				'item-name'        => sanitize_text_field($this->get_name()),
297
+				'item-description' => wp_kses_post($this->get_description()) . $description,
298
+				'item-quantity'    => floatval($this->get_quantity()),
299
+				'item-price'       => wpinv_price($price, $currency),
300
+				'item-total'       => wpinv_price($subtotal, $currency),
301 301
 			),
302 302
 			'inputs' => array(
303 303
 				'item-id'          => $this->get_id(),
304
-				'item-name'        => sanitize_text_field( $this->get_name() ),
305
-				'item-description' => wp_kses_post( $this->get_description() ),
306
-				'item-quantity'    => floatval( $this->get_quantity() ),
304
+				'item-name'        => sanitize_text_field($this->get_name()),
305
+				'item-description' => wp_kses_post($this->get_description()),
306
+				'item-quantity'    => floatval($this->get_quantity()),
307 307
 				'item-price'       => $price,
308 308
 			),
309 309
 		);
@@ -320,16 +320,16 @@  discard block
 block discarded – undo
320 320
 		return array(
321 321
 			'post_id'          => $this->invoice_id,
322 322
 			'item_id'          => $this->get_id(),
323
-			'item_name'        => sanitize_text_field( $this->get_raw_name( 'edit' ) ),
324
-			'item_description' => $this->get_description( 'edit' ),
323
+			'item_name'        => sanitize_text_field($this->get_raw_name('edit')),
324
+			'item_description' => $this->get_description('edit'),
325 325
 			'tax'              => $this->item_tax,
326
-			'item_price'       => $this->get_price( 'edit' ),
327
-			'quantity'         => (float) $this->get_quantity( 'edit' ),
326
+			'item_price'       => $this->get_price('edit'),
327
+			'quantity'         => (float) $this->get_quantity('edit'),
328 328
 			'discount'         => $this->item_discount,
329
-			'subtotal'         => $this->get_sub_total( 'edit' ),
330
-			'price'            => $this->get_sub_total( 'edit' ) + $this->item_tax - $this->item_discount,
331
-			'price_id'         => (int) $this->get_price_id( 'edit' ),
332
-			'meta'             => $this->get_item_meta( 'edit' ),
329
+			'subtotal'         => $this->get_sub_total('edit'),
330
+			'price'            => $this->get_sub_total('edit') + $this->item_tax - $this->item_discount,
331
+			'price_id'         => (int) $this->get_price_id('edit'),
332
+			'meta'             => $this->get_item_meta('edit'),
333 333
 		);
334 334
 	}
335 335
 
@@ -349,9 +349,9 @@  discard block
 block discarded – undo
349 349
 	 * @since 1.0.19
350 350
 	 * @param  float $quantity The item quantity.
351 351
 	 */
352
-	public function set_quantity( $quantity ) {
352
+	public function set_quantity($quantity) {
353 353
 
354
-		if ( ! is_numeric( $quantity ) ) {
354
+		if (!is_numeric($quantity)) {
355 355
 			$quantity = 1;
356 356
 		}
357 357
 
@@ -364,9 +364,9 @@  discard block
 block discarded – undo
364 364
 	 * @since 1.0.19
365 365
 	 * @param  float $price_id The item price ID.
366 366
 	 */
367
-	public function set_price_id( $price_id ) {
367
+	public function set_price_id($price_id) {
368 368
 
369
-		if ( ! is_numeric( $price_id ) ) {
369
+		if (!is_numeric($price_id)) {
370 370
 			$price_id = $this->get_default_price_id();
371 371
 		}
372 372
 
@@ -379,8 +379,8 @@  discard block
 block discarded – undo
379 379
 	 * @since 1.0.19
380 380
 	 * @param  array $meta The item meta data.
381 381
 	 */
382
-	public function set_item_meta( $meta ) {
383
-		$this->meta = maybe_unserialize( $meta );
382
+	public function set_item_meta($meta) {
383
+		$this->meta = maybe_unserialize($meta);
384 384
 	}
385 385
 
386 386
 	/**
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
 	 * @since 1.0.19
390 390
 	 * @param  bool $allow_quantities
391 391
 	 */
392
-	public function set_allow_quantities( $allow_quantities ) {
392
+	public function set_allow_quantities($allow_quantities) {
393 393
 		$this->allow_quantities = (bool) $allow_quantities;
394 394
 	}
395 395
 
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
 	 * @since 1.0.19
400 400
 	 * @param  bool $is_required
401 401
 	 */
402
-	public function set_is_required( $is_required ) {
402
+	public function set_is_required($is_required) {
403 403
 		$this->is_required = (bool) $is_required;
404 404
 	}
405 405
 
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
 	 * @since 1.0.19
410 410
 	 * @param  string $description
411 411
 	 */
412
-	public function set_custom_description( $description ) {
412
+	public function set_custom_description($description) {
413 413
 		$this->custom_description = $description;
414 414
 	}
415 415
 
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
      *
419 419
 	 * @return int item id
420 420
      */
421
-    public function save( $data = array() ) {
421
+    public function save($data = array()) {
422 422
         return $this->get_id();
423 423
 	}
424 424
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-checkout.php 1 patch
Spacing   +139 added lines, -139 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
  * Main Checkout Class.
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 *
23 23
 	 * @param GetPaid_Payment_Form_Submission $submission
24 24
 	 */
25
-	public function __construct( $submission ) {
25
+	public function __construct($submission) {
26 26
 		$this->payment_form_submission = $submission;
27 27
 	}
28 28
 
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
38 38
 		// Prepare the invoice.
39 39
 		$items    = $this->get_submission_items();
40 40
 		$invoice  = $this->get_submission_invoice();
41
-		$invoice  = $this->process_submission_invoice( $invoice, $items );
41
+		$invoice  = $this->process_submission_invoice($invoice, $items);
42 42
 		$prepared = $this->prepare_submission_data_for_saving();
43 43
 
44
-		$this->prepare_billing_info( $invoice );
44
+		$this->prepare_billing_info($invoice);
45 45
 
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
46
+		$shipping = $this->prepare_shipping_info($invoice);
47 47
 
48 48
 		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
49
+		$invoice->set_is_viewed(true);
50 50
 		$invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+		do_action('getpaid_checkout_invoice_updated', $invoice);
54 54
 
55 55
 		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
56
+		$this->post_process_submission($invoice, $prepared, $shipping);
57 57
 	}
58 58
 
59 59
 	/**
@@ -66,34 +66,34 @@  discard block
 block discarded – undo
66 66
 		$data       = $submission->get_data();
67 67
 
68 68
 		// Do we have an error?
69
-        if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
69
+        if (!empty($submission->last_error)) {
70
+			wp_send_json_error($submission->last_error);
71 71
         }
72 72
 
73 73
 		// We need a billing email.
74
-        if ( ! $submission->has_billing_email() ) {
75
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
74
+        if (!$submission->has_billing_email()) {
75
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
76 76
 		}
77 77
 
78 78
 		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
79
+		if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) {
80
+			wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing'));
81 81
 		}
82 82
 
83 83
 		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
84
+		if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) {
85
+			wp_send_json_error(__('The selected payment gateway is not active', 'invoicing'));
86 86
 		}
87 87
 
88 88
 		// Clear any existing errors.
89 89
 		wpinv_clear_errors();
90 90
 
91 91
 		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
92
+		do_action('getpaid_checkout_error_checks', $submission);
93 93
 
94 94
 		// Do we have any errors?
95
-        if ( wpinv_get_errors() ) {
96
-            wp_send_json_error( getpaid_get_errors_html() );
95
+        if (wpinv_get_errors()) {
96
+            wp_send_json_error(getpaid_get_errors_html());
97 97
 		}
98 98
 
99 99
 	} 
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 		$items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111
-        if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112
-            wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
111
+        if (empty($items) && !$this->payment_form_submission->has_fees()) {
112
+            wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing'));
113 113
 		}
114 114
 
115 115
 		return $items;
@@ -123,17 +123,17 @@  discard block
 block discarded – undo
123 123
 	protected function get_submission_invoice() {
124 124
 		$submission = $this->payment_form_submission;
125 125
 
126
-		if ( ! $submission->has_invoice() ) {
126
+		if (!$submission->has_invoice()) {
127 127
 			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
128
+			$invoice->set_created_via('payment_form');
129 129
 			return $invoice;
130 130
         }
131 131
 
132 132
 		$invoice = $submission->get_invoice();
133 133
 
134 134
 		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
135
+		if ($invoice->is_paid() || $invoice->is_refunded()) {
136
+			wp_send_json_error(__('This invoice has already been paid for.', 'invoicing'));
137 137
 		}
138 138
 
139 139
 		return $invoice;
@@ -146,34 +146,34 @@  discard block
 block discarded – undo
146 146
 	 * @param GetPaid_Form_Item[] $items
147 147
 	 * @return WPInv_Invoice
148 148
 	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
149
+	protected function process_submission_invoice($invoice, $items) {
150 150
 
151 151
 		$submission = $this->payment_form_submission;
152 152
 
153 153
 		// Set-up the invoice details.
154
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
-		$invoice->set_user_id( $this->get_submission_customer() );
156
-		$invoice->set_submission_id( $submission->id );
157
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
158
-        $invoice->set_items( $items );
159
-        $invoice->set_fees( $submission->get_fees() );
160
-        $invoice->set_taxes( $submission->get_taxes() );
161
-		$invoice->set_discounts( $submission->get_discounts() );
162
-		$invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
163
-		$invoice->set_currency( $submission->get_currency() );
164
-
165
-		if ( $submission->has_shipping() ) {
166
-			$invoice->set_shipping( $submission->get_shipping() );
154
+		$invoice->set_email(sanitize_email($submission->get_billing_email()));
155
+		$invoice->set_user_id($this->get_submission_customer());
156
+		$invoice->set_submission_id($submission->id);
157
+		$invoice->set_payment_form(absint($submission->get_payment_form()->get_id()));
158
+        $invoice->set_items($items);
159
+        $invoice->set_fees($submission->get_fees());
160
+        $invoice->set_taxes($submission->get_taxes());
161
+		$invoice->set_discounts($submission->get_discounts());
162
+		$invoice->set_gateway($submission->get_field('wpi-gateway'));
163
+		$invoice->set_currency($submission->get_currency());
164
+
165
+		if ($submission->has_shipping()) {
166
+			$invoice->set_shipping($submission->get_shipping());
167 167
 		}
168 168
 
169
-		$address_confirmed = $submission->get_field( 'confirm-address' );
170
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
169
+		$address_confirmed = $submission->get_field('confirm-address');
170
+		$invoice->set_address_confirmed(!empty($address_confirmed));
171 171
 
172
-		if ( $submission->has_discount_code() ) {
173
-            $invoice->set_discount_code( $submission->get_discount_code() );
172
+		if ($submission->has_discount_code()) {
173
+            $invoice->set_discount_code($submission->get_discount_code());
174 174
 		}
175 175
 
176
-		getpaid_maybe_add_default_address( $invoice );
176
+		getpaid_maybe_add_default_address($invoice);
177 177
 		return $invoice;
178 178
 	}
179 179
 
@@ -186,34 +186,34 @@  discard block
 block discarded – undo
186 186
 		$submission = $this->payment_form_submission;
187 187
 
188 188
 		// If this is an existing invoice...
189
-		if ( $submission->has_invoice() ) {
189
+		if ($submission->has_invoice()) {
190 190
 			return $submission->get_invoice()->get_user_id();
191 191
 		}
192 192
 
193 193
 		// (Maybe) create the user.
194 194
         $user = get_current_user_id();
195 195
 
196
-        if ( empty( $user ) ) {
197
-            $user = get_user_by( 'email', $submission->get_billing_email() );
196
+        if (empty($user)) {
197
+            $user = get_user_by('email', $submission->get_billing_email());
198 198
         }
199 199
 
200
-        if ( empty( $user ) ) {
201
-			$name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) );
202
-			$name = implode( '', array_filter( $name ) );
203
-            $user = wpinv_create_user( $submission->get_billing_email(), $name );
200
+        if (empty($user)) {
201
+			$name = array($submission->get_field('wpinv_first_name', 'billing'), $submission->get_field('wpinv_last_name', 'billing'));
202
+			$name = implode('', array_filter($name));
203
+            $user = wpinv_create_user($submission->get_billing_email(), $name);
204 204
 
205 205
 			// (Maybe) send new user notification.
206
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
207
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
208
-				wp_send_new_user_notifications( $user, 'user' );
206
+			$should_send_notification = wpinv_get_option('disable_new_user_emails');
207
+			if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification), $user)) {
208
+				wp_send_new_user_notifications($user, 'user');
209 209
 			}
210 210
 		}
211 211
 
212
-        if ( is_wp_error( $user ) ) {
213
-            wp_send_json_error( $user->get_error_message() );
212
+        if (is_wp_error($user)) {
213
+            wp_send_json_error($user->get_error_message());
214 214
         }
215 215
 
216
-        if ( is_numeric( $user ) ) {
216
+        if (is_numeric($user)) {
217 217
             return $user;
218 218
 		}
219 219
 
@@ -237,72 +237,72 @@  discard block
 block discarded – undo
237 237
 		);
238 238
 
239 239
         // Raw submission details.
240
-		$data     = $submission->get_data();
240
+		$data = $submission->get_data();
241 241
 
242 242
 		// Loop through the submitted details.
243
-        foreach ( $submission->get_payment_form()->get_elements() as $field ) {
243
+        foreach ($submission->get_payment_form()->get_elements() as $field) {
244 244
 
245 245
 			// Skip premade fields.
246
-            if ( ! empty( $field['premade'] ) ) {
246
+            if (!empty($field['premade'])) {
247 247
                 continue;
248 248
             }
249 249
 
250 250
 			// Ensure address is provided.
251
-			if ( 'address' === $field['type'] ) {
252
-                $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
251
+			if ('address' === $field['type']) {
252
+                $address_type = isset($field['address_type']) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
253 253
 
254
-				foreach ( $field['fields'] as $address_field ) {
254
+				foreach ($field['fields'] as $address_field) {
255 255
 
256
-					if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
257
-						wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
256
+					if (!empty($address_field['visible']) && !empty($address_field['required']) && '' === trim($_POST[$address_type][$address_field['name']])) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
257
+						wp_send_json_error(__('Please fill all required fields.', 'invoicing'));
258 258
 					}
259 259
                 }
260 260
             }
261 261
 
262 262
             // If it is required and not set, abort.
263
-            if ( ! $submission->is_required_field_set( $field ) ) {
264
-                wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
263
+            if (!$submission->is_required_field_set($field)) {
264
+                wp_send_json_error(__('Please fill all required fields.', 'invoicing'));
265 265
             }
266 266
 
267 267
             // Handle misc fields.
268
-            if ( isset( $data[ $field['id'] ] ) ) {
268
+            if (isset($data[$field['id']])) {
269 269
 
270 270
 				// Uploads.
271
-				if ( 'file_upload' === $field['type'] ) {
272
-					$max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
271
+				if ('file_upload' === $field['type']) {
272
+					$max_file_num = empty($field['max_file_num']) ? 1 : absint($field['max_file_num']);
273 273
 
274
-					if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
275
-						wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
274
+					if (count($data[$field['id']]) > $max_file_num) {
275
+						wp_send_json_error(__('Maximum number of allowed files exceeded.', 'invoicing'));
276 276
 					}
277 277
 
278 278
 					$value = array();
279 279
 
280
-					foreach ( $data[ $field['id'] ] as $url => $name ) {
280
+					foreach ($data[$field['id']] as $url => $name) {
281 281
 						$value[] = sprintf(
282 282
 							'<a href="%s" target="_blank">%s</a>',
283
-							esc_url_raw( $url ),
284
-							esc_html( $name )
283
+							esc_url_raw($url),
284
+							esc_html($name)
285 285
 						);
286 286
 					}
287 287
 
288
-					$value = implode( ' | ', $value );
288
+					$value = implode(' | ', $value);
289 289
 
290
-				} elseif ( 'checkbox' === $field['type'] ) {
291
-					$value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
290
+				} elseif ('checkbox' === $field['type']) {
291
+					$value = !empty($data[$field['id']]) ? __('Yes', 'invoicing') : __('No', 'invoicing');
292 292
 				} else {
293
-					$value = wp_kses_post( $data[ $field['id'] ] );
293
+					$value = wp_kses_post($data[$field['id']]);
294 294
 				}
295 295
 
296 296
                 $label = $field['id'];
297 297
 
298
-                if ( isset( $field['label'] ) ) {
298
+                if (isset($field['label'])) {
299 299
                     $label = $field['label'];
300 300
                 }
301 301
 
302
-				if ( ! empty( $field['add_meta'] ) ) {
303
-					$prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
302
+				if (!empty($field['add_meta'])) {
303
+					$prepared['meta'][wpinv_clean($label)] = wp_kses_post_deep($value);
304 304
 				}
305
-				$prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
305
+				$prepared['all'][wpinv_clean($label)] = wp_kses_post_deep($value);
306 306
 
307 307
             }
308 308
 		}
@@ -318,30 +318,30 @@  discard block
 block discarded – undo
318 318
 	 * @param WPInv_Invoice $invoice
319 319
 	 * @param string $type
320 320
      */
321
-    public function prepare_address_details( $invoice, $type = 'billing' ) {
321
+    public function prepare_address_details($invoice, $type = 'billing') {
322 322
 
323 323
 		$data     = $this->payment_form_submission->get_data();
324
-		$type     = sanitize_key( $type );
324
+		$type     = sanitize_key($type);
325 325
 		$address  = array();
326 326
 		$prepared = array();
327 327
 
328
-		if ( ! empty( $data[ $type ] ) ) {
329
-			$address = $data[ $type ];
328
+		if (!empty($data[$type])) {
329
+			$address = $data[$type];
330 330
 		}
331 331
 
332 332
 		// Clean address details.
333
-		foreach ( $address as $key => $value ) {
334
-			$key             = sanitize_key( $key );
335
-			$key             = str_replace( 'wpinv_', '', $key );
336
-			$value           = wpinv_clean( $value );
337
-			$prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
333
+		foreach ($address as $key => $value) {
334
+			$key             = sanitize_key($key);
335
+			$key             = str_replace('wpinv_', '', $key);
336
+			$value           = wpinv_clean($value);
337
+			$prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice);
338 338
 		}
339 339
 
340 340
 		// Filter address details.
341
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
341
+		$prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice);
342 342
 
343 343
 		// Remove non-whitelisted values.
344
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
344
+		return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY);
345 345
 
346 346
 	}
347 347
 
@@ -351,12 +351,12 @@  discard block
 block discarded – undo
351 351
 	 * @return array
352 352
 	 * @param WPInv_Invoice $invoice
353 353
      */
354
-    protected function prepare_billing_info( &$invoice ) {
354
+    protected function prepare_billing_info(&$invoice) {
355 355
 
356
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
356
+		$billing_address = $this->prepare_address_details($invoice, 'billing');
357 357
 
358 358
 		// Update the invoice with the billing details.
359
-		$invoice->set_props( $billing_address );
359
+		$invoice->set_props($billing_address);
360 360
 
361 361
 	}
362 362
 
@@ -366,15 +366,15 @@  discard block
 block discarded – undo
366 366
 	 * @return array
367 367
 	 * @param WPInv_Invoice $invoice
368 368
      */
369
-    protected function prepare_shipping_info( $invoice ) {
369
+    protected function prepare_shipping_info($invoice) {
370 370
 
371 371
 		$data = $this->payment_form_submission->get_data();
372 372
 
373
-		if ( empty( $data['same-shipping-address'] ) ) {
374
-			return $this->prepare_address_details( $invoice, 'shipping' );
373
+		if (empty($data['same-shipping-address'])) {
374
+			return $this->prepare_address_details($invoice, 'shipping');
375 375
 		}
376 376
 
377
-		return $this->prepare_address_details( $invoice, 'billing' );
377
+		return $this->prepare_address_details($invoice, 'billing');
378 378
 
379 379
 	}
380 380
 
@@ -385,45 +385,45 @@  discard block
 block discarded – undo
385 385
 	 * @param array $prepared_payment_form_data
386 386
 	 * @param array $shipping
387 387
 	 */
388
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
388
+	protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) {
389 389
 
390 390
 		// Ensure the invoice exists.
391
-        if ( ! $invoice->exists() ) {
392
-            wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
391
+        if (!$invoice->exists()) {
392
+            wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing'));
393 393
         }
394 394
 
395 395
 		// Save payment form data.
396
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
397
-        delete_post_meta( $invoice->get_id(), 'payment_form_data' );
398
-		delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
399
-		if ( ! empty( $prepared_payment_form_data ) ) {
396
+		$prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice);
397
+        delete_post_meta($invoice->get_id(), 'payment_form_data');
398
+		delete_post_meta($invoice->get_id(), 'additional_meta_data');
399
+		if (!empty($prepared_payment_form_data)) {
400 400
 
401
-			if ( ! empty( $prepared_payment_form_data['all'] ) ) {
402
-				update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
401
+			if (!empty($prepared_payment_form_data['all'])) {
402
+				update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all']);
403 403
 			}
404 404
 
405
-			if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
406
-				update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
405
+			if (!empty($prepared_payment_form_data['meta'])) {
406
+				update_post_meta($invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta']);
407 407
 			}
408 408
 		}
409 409
 
410 410
 		// Save payment form data.
411
-		$shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
412
-        if ( ! empty( $shipping ) ) {
413
-            update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
411
+		$shipping = apply_filters('getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission);
412
+        if (!empty($shipping)) {
413
+            update_post_meta($invoice->get_id(), 'shipping_address', $shipping);
414 414
 		}
415 415
 
416 416
 		// Backwards compatibility.
417
-        add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
417
+        add_filter('wp_redirect', array($this, 'send_redirect_response'));
418 418
 
419 419
 		try {
420
-			$this->process_payment( $invoice );
421
-		} catch ( Exception $e ) {
422
-			wpinv_set_error( 'payment_error', $e->getMessage() );
420
+			$this->process_payment($invoice);
421
+		} catch (Exception $e) {
422
+			wpinv_set_error('payment_error', $e->getMessage());
423 423
 		}
424 424
 
425 425
         // If we are here, there was an error.
426
-		wpinv_send_back_to_checkout( $invoice );
426
+		wpinv_send_back_to_checkout($invoice);
427 427
 
428 428
 	}
429 429
 
@@ -432,41 +432,41 @@  discard block
 block discarded – undo
432 432
 	 *
433 433
 	 * @param WPInv_Invoice $invoice
434 434
 	 */
435
-	protected function process_payment( $invoice ) {
435
+	protected function process_payment($invoice) {
436 436
 
437 437
 		// Clear any checkout errors.
438 438
 		wpinv_clear_errors();
439 439
 
440 440
 		// No need to send free invoices to the gateway.
441
-		if ( $invoice->is_free() ) {
442
-			$this->process_free_payment( $invoice );
441
+		if ($invoice->is_free()) {
442
+			$this->process_free_payment($invoice);
443 443
 		}
444 444
 
445 445
 		$submission = $this->payment_form_submission;
446 446
 
447 447
 		// Fires before sending to the gateway.
448
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
448
+		do_action('getpaid_checkout_before_gateway', $invoice, $submission);
449 449
 
450 450
 		// Allow the sumission data to be modified before it is sent to the gateway.
451 451
 		$submission_data    = $submission->get_data();
452
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
453
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
452
+		$submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice);
453
+		$submission_data    = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice);
454 454
 
455 455
 		// Validate the currency.
456
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
457
-			wpinv_set_error( 'invalid_currency' );
456
+		if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) {
457
+			wpinv_set_error('invalid_currency');
458 458
 		}
459 459
 
460 460
 		// Check to see if we have any errors.
461
-		if ( wpinv_get_errors() ) {
462
-			wpinv_send_back_to_checkout( $invoice );
461
+		if (wpinv_get_errors()) {
462
+			wpinv_send_back_to_checkout($invoice);
463 463
 		}
464 464
 
465 465
 		// Send info to the gateway for payment processing
466
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
466
+		do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission);
467 467
 
468 468
 		// Backwards compatibility.
469
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
469
+		wpinv_send_to_gateway($submission_gateway, $invoice);
470 470
 
471 471
 	}
472 472
 
@@ -475,12 +475,12 @@  discard block
 block discarded – undo
475 475
 	 *
476 476
 	 * @param WPInv_Invoice $invoice
477 477
 	 */
478
-	protected function process_free_payment( $invoice ) {
478
+	protected function process_free_payment($invoice) {
479 479
 
480
-		$invoice->set_gateway( 'none' );
481
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
480
+		$invoice->set_gateway('none');
481
+		$invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true);
482 482
 		$invoice->mark_paid();
483
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
483
+		wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
484 484
 
485 485
 	}
486 486
 
@@ -488,9 +488,9 @@  discard block
 block discarded – undo
488 488
      * Sends a redrect response to payment details.
489 489
      *
490 490
      */
491
-    public function send_redirect_response( $url ) {
492
-        $url = rawurlencode( $url );
493
-        wp_send_json_success( $url );
491
+    public function send_redirect_response($url) {
492
+        $url = rawurlencode($url);
493
+        wp_send_json_success($url);
494 494
     }
495 495
 
496 496
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-items.php 1 patch
Spacing   +67 added lines, -67 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 itemss class
@@ -23,7 +23,7 @@  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
 		$data         = $submission->get_data();
29 29
 		$payment_form = $submission->get_payment_form();
@@ -32,59 +32,59 @@  discard block
 block discarded – undo
32 32
 
33 33
 		// Prepare the selected items.
34 34
 		$selected_items = array();
35
-		if ( ! empty( $data['getpaid-items'] ) ) {
36
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
35
+		if (!empty($data['getpaid-items'])) {
36
+			$selected_items = wpinv_clean($data['getpaid-items']);
37 37
 
38
-            if ( is_array( $submission->get_field( 'getpaid-variable-items' ) ) ) {
39
-                $selected_prices = $submission->get_field( 'getpaid-variable-items' );
38
+            if (is_array($submission->get_field('getpaid-variable-items'))) {
39
+                $selected_prices = $submission->get_field('getpaid-variable-items');
40 40
 
41 41
                 $selected_items = array_filter(
42 42
                     $selected_items,
43
-                    function ( $item ) use ( $selected_prices ) {
44
-                        return isset( $item['price_id'] ) && in_array( (int) $item['price_id'], $selected_prices );
43
+                    function($item) use ($selected_prices) {
44
+                        return isset($item['price_id']) && in_array((int) $item['price_id'], $selected_prices);
45 45
                     }
46 46
                 );
47 47
             }
48 48
 
49
-			if ( ! empty( $invoice ) && $submission->is_initial_fetch() ) {
50
-				foreach ( $invoice->get_items() as $invoice_item ) {
51
-                    if ( ! $invoice_item->has_variable_pricing() && isset( $selected_items[ $invoice_item->get_id() ] ) ) {
52
-                        $selected_items[ $invoice_item->get_id() ]['quantity'] = $invoice_item->get_quantity();
53
-                        $selected_items[ $invoice_item->get_id() ]['price']    = $invoice_item->get_price();
49
+			if (!empty($invoice) && $submission->is_initial_fetch()) {
50
+				foreach ($invoice->get_items() as $invoice_item) {
51
+                    if (!$invoice_item->has_variable_pricing() && isset($selected_items[$invoice_item->get_id()])) {
52
+                        $selected_items[$invoice_item->get_id()]['quantity'] = $invoice_item->get_quantity();
53
+                        $selected_items[$invoice_item->get_id()]['price']    = $invoice_item->get_price();
54 54
 
55
-                        $force_prices[ $invoice_item->get_id() ] = $invoice_item->get_price();
55
+                        $force_prices[$invoice_item->get_id()] = $invoice_item->get_price();
56 56
                     }
57 57
 				}
58 58
 			}
59 59
 		}
60 60
 
61 61
 		// (Maybe) set form items.
62
-		if ( isset( $data['getpaid-form-items'] ) ) {
62
+		if (isset($data['getpaid-form-items'])) {
63 63
 
64 64
 			// Confirm items key.
65
-			$form_items = wpinv_clean( $data['getpaid-form-items'] );
66
-			if ( ! isset( $data['getpaid-form-items-key'] ) || md5( NONCE_KEY . AUTH_KEY . $form_items ) !== $data['getpaid-form-items-key'] ) {
67
-				throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) );
65
+			$form_items = wpinv_clean($data['getpaid-form-items']);
66
+			if (!isset($data['getpaid-form-items-key']) || md5(NONCE_KEY . AUTH_KEY . $form_items) !== $data['getpaid-form-items-key']) {
67
+				throw new Exception(__('We could not validate the form items. Please reload the page and try again.', 'invoicing'));
68 68
 			}
69 69
 
70
-			$items    = array();
70
+			$items = array();
71 71
             $item_ids = array();
72 72
 
73
-            foreach ( getpaid_convert_items_to_array( $form_items ) as $item_id => $qty ) {
74
-                if ( ! in_array( $item_id, $item_ids ) ) {
75
-                    $item = new GetPaid_Form_Item( $item_id );
73
+            foreach (getpaid_convert_items_to_array($form_items) as $item_id => $qty) {
74
+                if (!in_array($item_id, $item_ids)) {
75
+                    $item = new GetPaid_Form_Item($item_id);
76 76
 
77
-                    if ( ! $item->has_variable_pricing() ) {
78
-                        $item->set_quantity( $qty );
77
+                    if (!$item->has_variable_pricing()) {
78
+                        $item->set_quantity($qty);
79 79
 
80
-                        if ( empty( $qty ) ) {
81
-                            $item->set_allow_quantities( true );
82
-                            $item->set_is_required( false );
80
+                        if (empty($qty)) {
81
+                            $item->set_allow_quantities(true);
82
+                            $item->set_is_required(false);
83 83
                         }
84 84
 
85
-                        if ( ! $item->user_can_set_their_price() && isset( $force_prices[ $item_id ] ) ) {
86
-                            $item->set_is_dynamic_pricing( true );
87
-                            $item->set_minimum_price( 0 );
85
+                        if (!$item->user_can_set_their_price() && isset($force_prices[$item_id])) {
86
+                            $item->set_is_dynamic_pricing(true);
87
+                            $item->set_minimum_price(0);
88 88
                         }
89 89
                     }
90 90
 
@@ -93,22 +93,22 @@  discard block
 block discarded – undo
93 93
                 }
94 94
             }
95 95
 
96
-            if ( ! $payment_form->is_default() ) {
96
+            if (!$payment_form->is_default()) {
97 97
 
98
-                foreach ( $payment_form->get_items() as $item ) {
99
-                    if ( ! in_array( $item->get_id(), $item_ids ) ) {
98
+                foreach ($payment_form->get_items() as $item) {
99
+                    if (!in_array($item->get_id(), $item_ids)) {
100 100
                         $item_ids[] = $item->get_id();
101 101
                         $items[]    = $item;
102 102
                     }
103 103
                 }
104 104
 			}
105 105
 
106
-            $payment_form->set_items( $items );
106
+            $payment_form->set_items($items);
107 107
 		}
108 108
 
109 109
 		// Process each individual item.
110
-		foreach ( $payment_form->get_items() as $item ) {
111
-			$this->process_item( $item, $selected_items, $submission );
110
+		foreach ($payment_form->get_items() as $item) {
111
+			$this->process_item($item, $selected_items, $submission);
112 112
 		}
113 113
 	}
114 114
 
@@ -119,83 +119,83 @@  discard block
 block discarded – undo
119 119
 	 * @param array $selected_items
120 120
 	 * @param GetPaid_Payment_Form_Submission $submission
121 121
 	 */
122
-	public function process_item( $item, $selected_items, $submission ) {
122
+	public function process_item($item, $selected_items, $submission) {
123 123
 
124
-        if ( $item->has_variable_pricing() ) {
124
+        if ($item->has_variable_pricing()) {
125 125
 
126 126
             $selected_items = array_filter(
127 127
                 $selected_items,
128
-                function ( $selected_item ) use ( $item ) {
128
+                function($selected_item) use ($item) {
129 129
                     return (int) $selected_item['item_id'] === (int) $item->get_id();
130 130
                 }
131 131
             );
132 132
 
133
-            if ( ! $item->is_required() && ! count( $selected_items ) ) {
133
+            if (!$item->is_required() && !count($selected_items)) {
134 134
                 return;
135 135
             }
136 136
 
137 137
             $price_options = $item->get_variable_prices();
138
-            $price = current( $selected_items );
138
+            $price = current($selected_items);
139 139
 
140
-            $item->set_price_id( $price['price_id'] );
141
-            $item->set_quantity( $price['quantity'] );
140
+            $item->set_price_id($price['price_id']);
141
+            $item->set_quantity($price['quantity']);
142 142
 
143
-            $price = isset( $price_options[ $price['price_id'] ] ) ? $price_options[ $price['price_id'] ] : $price;
144
-            $item->set_price( (float) $price['amount'] );
143
+            $price = isset($price_options[$price['price_id']]) ? $price_options[$price['price_id']] : $price;
144
+            $item->set_price((float) $price['amount']);
145 145
 
146
-            if ( isset( $price['is-recurring'] ) && 'yes' === $price['is-recurring'] ) {
147
-                if ( isset( $price['trial-interval'], $price['trial-period'] ) && $price['trial-interval'] > 0 ) {
146
+            if (isset($price['is-recurring']) && 'yes' === $price['is-recurring']) {
147
+                if (isset($price['trial-interval'], $price['trial-period']) && $price['trial-interval'] > 0) {
148 148
                     $trial_interval = (int) $price['trial-interval'];
149 149
                     $trial_period = $price['trial-period'];
150 150
 
151
-                    $item->set_is_free_trial( 1 );
152
-                    $item->set_trial_interval( $trial_interval );
153
-                    $item->set_trial_period( $trial_period );
151
+                    $item->set_is_free_trial(1);
152
+                    $item->set_trial_interval($trial_interval);
153
+                    $item->set_trial_period($trial_period);
154 154
                 }
155 155
 
156
-                if ( isset( $price['recurring-interval'], $price['recurring-period'] ) && $price['recurring-interval'] > 0 ) {
156
+                if (isset($price['recurring-interval'], $price['recurring-period']) && $price['recurring-interval'] > 0) {
157 157
                     $recurring_interval = (int) $price['recurring-interval'];
158 158
                     $recurring_period = $price['recurring-period'];
159
-                    $recurring_limit = isset( $price['recurring-limit'] ) ? (int) $price['recurring-limit'] : 0;
159
+                    $recurring_limit = isset($price['recurring-limit']) ? (int) $price['recurring-limit'] : 0;
160 160
 
161
-                    $item->set_is_recurring( 1 );
162
-                    $item->set_recurring_interval( $recurring_interval );
163
-                    $item->set_recurring_period( $recurring_period );
164
-                    $item->set_recurring_limit( $recurring_limit );
161
+                    $item->set_is_recurring(1);
162
+                    $item->set_recurring_interval($recurring_interval);
163
+                    $item->set_recurring_period($recurring_period);
164
+                    $item->set_recurring_limit($recurring_limit);
165 165
                 }
166 166
             }
167 167
         } else {
168 168
 		    // Abort if this is an optional item and it has not been selected.
169
-            if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
169
+            if (!$item->is_required() && !isset($selected_items[$item->get_id()])) {
170 170
                 return;
171 171
             }
172 172
 
173 173
             // (maybe) let customers change the quantities and prices.
174
-            if ( isset( $selected_items[ $item->get_id() ] ) ) {
174
+            if (isset($selected_items[$item->get_id()])) {
175 175
 
176 176
                 // Maybe change the quantities.
177
-                if ( $item->allows_quantities() ) {
178
-                    $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] );
177
+                if ($item->allows_quantities()) {
178
+                    $item->set_quantity((float) $selected_items[$item->get_id()]['quantity']);
179 179
                 }
180 180
 
181 181
                 // Maybe change the price.
182
-                if ( $item->user_can_set_their_price() ) {
183
-                    $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
182
+                if ($item->user_can_set_their_price()) {
183
+                    $price = (float) wpinv_sanitize_amount($selected_items[$item->get_id()]['price']);
184 184
 
185
-                    if ( $item->get_minimum_price() > $price ) {
186
-                        throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) );
185
+                    if ($item->get_minimum_price() > $price) {
186
+                        throw new Exception(sprintf(__('The minimum allowed amount is %s', 'invoicing'), getpaid_unstandardize_amount($item->get_minimum_price())));
187 187
                     }
188 188
 
189
-                    $item->set_price( $price );
189
+                    $item->set_price($price);
190 190
                 }
191 191
             }
192 192
         }
193 193
 
194
-		if ( 0 == $item->get_quantity() ) {
194
+		if (0 == $item->get_quantity()) {
195 195
 			return;
196 196
 		}
197 197
 
198 198
 		// Save the item.
199
-		$this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission );
199
+		$this->items[] = apply_filters('getpaid_payment_form_submission_processed_item', $item, $submission);
200 200
 	}
201 201
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission.php 1 patch
Spacing   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -146,8 +146,8 @@  discard block
 block discarded – undo
146 146
 		$this->state   = wpinv_get_default_state();
147 147
 
148 148
 		// Do we have an actual submission?
149
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
150
-			$this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) );
149
+		if (isset($_POST['getpaid_payment_form_submission'])) {
150
+			$this->load_data(wp_kses_post_deep(wp_unslash($_POST)));
151 151
 		}
152 152
 	}
153 153
 
@@ -156,16 +156,16 @@  discard block
 block discarded – undo
156 156
 	 *
157 157
 	 * @param array $data
158 158
 	 */
159
-	public function load_data( $data ) {
159
+	public function load_data($data) {
160 160
 
161 161
 		// Allow plugins to filter the data.
162
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
162
+		$data       = apply_filters('getpaid_submission_data', $data, $this);
163 163
 
164 164
 		// Cache it...
165 165
 		$this->data = $data;
166 166
 
167 167
 		// Then generate a unique id from the data.
168
-		$this->id   = md5( wp_json_encode( $data ) );
168
+		$this->id   = md5(wp_json_encode($data));
169 169
 
170 170
 		// Finally, process the submission.
171 171
 		try {
@@ -175,29 +175,29 @@  discard block
 block discarded – undo
175 175
 			$processors = apply_filters(
176 176
 				'getpaid_payment_form_submission_processors',
177 177
 				array(
178
-					array( $this, 'process_payment_form' ),
179
-					array( $this, 'process_invoice' ),
180
-					array( $this, 'process_fees' ),
181
-					array( $this, 'process_items' ),
182
-					array( $this, 'process_discount' ),
183
-					array( $this, 'process_taxes' ),
178
+					array($this, 'process_payment_form'),
179
+					array($this, 'process_invoice'),
180
+					array($this, 'process_fees'),
181
+					array($this, 'process_items'),
182
+					array($this, 'process_discount'),
183
+					array($this, 'process_taxes'),
184 184
 				),
185 185
 				$this
186 186
 			);
187 187
 
188
-			foreach ( $processors as $processor ) {
189
-				call_user_func_array( $processor, array( &$this ) );
188
+			foreach ($processors as $processor) {
189
+				call_user_func_array($processor, array(&$this));
190 190
 			}
191
-		} catch ( GetPaid_Payment_Exception $e ) {
191
+		} catch (GetPaid_Payment_Exception $e) {
192 192
 			$this->last_error      = $e->getMessage();
193 193
 			$this->last_error_code = $e->getErrorCode();
194
-		} catch ( Exception $e ) {
194
+		} catch (Exception $e) {
195 195
 			$this->last_error      = $e->getMessage();
196 196
 			$this->last_error_code = $e->getCode();
197 197
 		}
198 198
 
199 199
 		// Fired when we are done processing a submission.
200
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
200
+		do_action_ref_array('getpaid_process_submission', array(&$this));
201 201
 	}
202 202
 
203 203
 	/*
@@ -217,18 +217,18 @@  discard block
 block discarded – undo
217 217
 	public function process_payment_form() {
218 218
 
219 219
 		// Every submission needs an active payment form.
220
-		if ( empty( $this->data['form_id'] ) ) {
221
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
220
+		if (empty($this->data['form_id'])) {
221
+			throw new Exception(__('Missing payment form', 'invoicing'));
222 222
 		}
223 223
 
224 224
 		// Fetch the payment form.
225
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
225
+		$this->payment_form = new GetPaid_Payment_Form($this->data['form_id']);
226 226
 
227
-		if ( ! $this->payment_form->is_active() ) {
228
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
227
+		if (!$this->payment_form->is_active()) {
228
+			throw new Exception(__('Payment form not active', 'invoicing'));
229 229
 		}
230 230
 
231
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
231
+		do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this));
232 232
 	}
233 233
 
234 234
     /**
@@ -258,64 +258,64 @@  discard block
 block discarded – undo
258 258
 	public function process_invoice() {
259 259
 
260 260
 		// Abort if there is no invoice.
261
-		if ( empty( $this->data['invoice_id'] ) ) {
261
+		if (empty($this->data['invoice_id'])) {
262 262
 
263 263
 			// Check if we are resuming a payment.
264
-			if ( empty( $this->data['maybe_use_invoice'] ) ) {
264
+			if (empty($this->data['maybe_use_invoice'])) {
265 265
 				return;
266 266
 			}
267 267
 
268
-			$invoice = wpinv_get_invoice( $this->data['maybe_use_invoice'] );
269
-			if ( empty( $invoice ) || ! $invoice->has_status( 'draft, auto-draft, wpi-pending' ) ) {
268
+			$invoice = wpinv_get_invoice($this->data['maybe_use_invoice']);
269
+			if (empty($invoice) || !$invoice->has_status('draft, auto-draft, wpi-pending')) {
270 270
 				return;
271 271
 			}
272 272
 		}
273 273
 
274 274
 		// If the submission is for an existing invoice, ensure that it exists
275 275
 		// and that it is not paid for.
276
-		if ( empty( $invoice ) ) {
277
-			$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
276
+		if (empty($invoice)) {
277
+			$invoice = wpinv_get_invoice($this->data['invoice_id']);
278 278
 		}
279 279
 
280
-        if ( empty( $invoice ) ) {
281
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
280
+        if (empty($invoice)) {
281
+			throw new Exception(__('Invalid invoice', 'invoicing'));
282 282
 		}
283 283
 
284
-		if ( $invoice->is_paid() ) {
285
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
284
+		if ($invoice->is_paid()) {
285
+			throw new Exception(__('This invoice is already paid for.', 'invoicing'));
286 286
 		}
287 287
 
288 288
 		$this->payment_form->invoice = $invoice;
289
-		if ( ! $this->payment_form->is_default() ) {
289
+		if (!$this->payment_form->is_default()) {
290 290
 
291 291
 			$items    = array();
292 292
 			$item_ids = array();
293 293
 
294
-			foreach ( $invoice->get_items() as $item ) {
295
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
294
+			foreach ($invoice->get_items() as $item) {
295
+				if (!in_array($item->get_id(), $item_ids)) {
296 296
 					$item_ids[] = $item->get_id();
297 297
 					$items[]    = $item;
298 298
 				}
299 299
 			}
300 300
 
301
-			foreach ( $this->payment_form->get_items() as $item ) {
302
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
301
+			foreach ($this->payment_form->get_items() as $item) {
302
+				if (!in_array($item->get_id(), $item_ids)) {
303 303
 					$item_ids[] = $item->get_id();
304 304
 					$items[]    = $item;
305 305
 				}
306 306
 			}
307 307
 
308
-			$this->payment_form->set_items( $items );
308
+			$this->payment_form->set_items($items);
309 309
 
310 310
 		} else {
311
-			$this->payment_form->set_items( $invoice->get_items() );
311
+			$this->payment_form->set_items($invoice->get_items());
312 312
 		}
313 313
 
314 314
 		$this->country = $invoice->get_country();
315 315
 		$this->state   = $invoice->get_state();
316 316
 		$this->invoice = $invoice;
317 317
 
318
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
318
+		do_action_ref_array('getpaid_submissions_process_invoice', array(&$this));
319 319
 	}
320 320
 
321 321
 	/**
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
 	 * @return bool
336 336
 	 */
337 337
 	public function has_invoice() {
338
-		return ! empty( $this->invoice );
338
+		return !empty($this->invoice);
339 339
 	}
340 340
 
341 341
 	/*
@@ -354,13 +354,13 @@  discard block
 block discarded – undo
354 354
 	 */
355 355
 	public function process_items() {
356 356
 
357
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
357
+		$processor = new GetPaid_Payment_Form_Submission_Items($this);
358 358
 
359
-		foreach ( $processor->items as $item ) {
360
-			$this->add_item( $item );
359
+		foreach ($processor->items as $item) {
360
+			$this->add_item($item);
361 361
 		}
362 362
 
363
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
363
+		do_action_ref_array('getpaid_submissions_process_items', array(&$this));
364 364
 	}
365 365
 
366 366
 	/**
@@ -369,20 +369,20 @@  discard block
 block discarded – undo
369 369
 	 * @since 1.0.19
370 370
 	 * @param GetPaid_Form_Item $item
371 371
 	 */
372
-	public function add_item( $item ) {
372
+	public function add_item($item) {
373 373
 
374 374
 		// Make sure that it is available for purchase.
375
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
375
+		if (!$item->can_purchase() || isset($this->items[$item->get_id()])) {
376 376
 			return;
377 377
 		}
378 378
 
379 379
 		// Each submission can only contain one recurring item.
380
-		if ( $item->is_recurring() ) {
380
+		if ($item->is_recurring()) {
381 381
 			$this->has_recurring = $item->get_id();
382 382
 		}
383 383
 
384 384
 		// Update the items and totals.
385
-		$this->items[ $item->get_id() ]         = $item;
385
+		$this->items[$item->get_id()]         = $item;
386 386
 		$this->totals['subtotal']['initial']   += $item->get_sub_total();
387 387
 		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
388 388
 	}
@@ -395,17 +395,17 @@  discard block
 block discarded – undo
395 395
 	 *
396 396
 	 * @since 1.0.19
397 397
 	 */
398
-	public function remove_item( $item_id ) {
398
+	public function remove_item($item_id) {
399 399
 
400
-		if ( isset( $this->items[ $item_id ] ) ) {
401
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
402
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
400
+		if (isset($this->items[$item_id])) {
401
+			$this->totals['subtotal']['initial']   -= $this->items[$item_id]->get_sub_total();
402
+			$this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total();
403 403
 
404
-			if ( $this->items[ $item_id ]->is_recurring() ) {
404
+			if ($this->items[$item_id]->is_recurring()) {
405 405
 				$this->has_recurring = 0;
406 406
 			}
407 407
 
408
-			unset( $this->items[ $item_id ] );
408
+			unset($this->items[$item_id]);
409 409
 		}
410 410
 	}
411 411
 
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
 	 */
417 417
 	public function get_subtotal() {
418 418
 
419
-		if ( wpinv_prices_include_tax() ) {
419
+		if (wpinv_prices_include_tax()) {
420 420
 			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
421 421
 		}
422 422
 
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
 	 */
431 431
 	public function get_recurring_subtotal() {
432 432
 
433
-		if ( wpinv_prices_include_tax() ) {
433
+		if (wpinv_prices_include_tax()) {
434 434
 			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
435 435
 		}
436 436
 
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 	 * @return bool
455 455
 	 */
456 456
 	public function has_subscription_group() {
457
-		return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
457
+		return $this->has_recurring && getpaid_should_group_subscriptions($this) && 1 == count(getpaid_get_subscription_groups($this));
458 458
 	}
459 459
 
460 460
 	/**
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
 	 * @return bool
465 465
 	 */
466 466
 	public function has_multiple_subscription_groups() {
467
-		return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
467
+		return $this->has_recurring && 1 < count(getpaid_get_subscription_groups($this));
468 468
 	}
469 469
 
470 470
 	/*
@@ -484,39 +484,39 @@  discard block
 block discarded – undo
484 484
 	public function process_taxes() {
485 485
 
486 486
 		// Abort if we're not using taxes.
487
-		if ( ! $this->use_taxes() ) {
487
+		if (!$this->use_taxes()) {
488 488
 			return;
489 489
 		}
490 490
 
491 491
 		// If a custom country && state has been passed in, use it to calculate taxes.
492
-		$country = $this->get_field( 'wpinv_country', 'billing' );
493
-		if ( ! empty( $country ) ) {
492
+		$country = $this->get_field('wpinv_country', 'billing');
493
+		if (!empty($country)) {
494 494
 			$this->country = $country;
495 495
 		}
496 496
 
497
-		$state = $this->get_field( 'wpinv_state', 'billing' );
498
-		if ( ! empty( $state ) ) {
497
+		$state = $this->get_field('wpinv_state', 'billing');
498
+		if (!empty($state)) {
499 499
 			$this->state = $state;
500 500
 		}
501 501
 
502 502
 		// Confirm if the provided country and the ip country are similar.
503
-		$address_confirmed = $this->get_field( 'confirm-address' );
504
-		if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
505
-			throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
503
+		$address_confirmed = $this->get_field('confirm-address');
504
+		if (isset($_POST['billing']['country']) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) {
505
+			throw new Exception(__('The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing'));
506 506
 		}
507 507
 
508 508
 		// Abort if the country is not taxable.
509
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
509
+		if (!wpinv_is_country_taxable($this->country)) {
510 510
 			return;
511 511
 		}
512 512
 
513
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
513
+		$processor = new GetPaid_Payment_Form_Submission_Taxes($this);
514 514
 
515
-		foreach ( $processor->taxes as $tax ) {
516
-			$this->add_tax( $tax );
515
+		foreach ($processor->taxes as $tax) {
516
+			$this->add_tax($tax);
517 517
 		}
518 518
 
519
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
519
+		do_action_ref_array('getpaid_submissions_process_taxes', array(&$this));
520 520
 	}
521 521
 
522 522
 	/**
@@ -525,16 +525,16 @@  discard block
 block discarded – undo
525 525
 	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
526 526
 	 * @since 1.0.19
527 527
 	 */
528
-	public function add_tax( $tax ) {
528
+	public function add_tax($tax) {
529 529
 
530
-		if ( wpinv_round_tax_per_tax_rate() ) {
531
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
532
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
530
+		if (wpinv_round_tax_per_tax_rate()) {
531
+			$tax['initial_tax']   = wpinv_round_amount($tax['initial_tax']);
532
+			$tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']);
533 533
 		}
534 534
 
535
-		$this->taxes[ $tax['name'] ]         = $tax;
536
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
537
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
535
+		$this->taxes[$tax['name']]         = $tax;
536
+		$this->totals['taxes']['initial']   += wpinv_sanitize_amount($tax['initial_tax']);
537
+		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']);
538 538
 	}
539 539
 
540 540
 	/**
@@ -542,12 +542,12 @@  discard block
 block discarded – undo
542 542
 	 *
543 543
 	 * @since 1.0.19
544 544
 	 */
545
-	public function remove_tax( $tax_name ) {
545
+	public function remove_tax($tax_name) {
546 546
 
547
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
548
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
549
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
550
-			unset( $this->taxes[ $tax_name ] );
547
+		if (isset($this->taxes[$tax_name])) {
548
+			$this->totals['taxes']['initial']   -= $this->taxes[$tax_name]['initial_tax'];
549
+			$this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax'];
550
+			unset($this->taxes[$tax_name]);
551 551
 		}
552 552
 	}
553 553
 
@@ -560,11 +560,11 @@  discard block
 block discarded – undo
560 560
 
561 561
 		$use_taxes = wpinv_use_taxes();
562 562
 
563
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
563
+		if ($this->has_invoice() && !$this->invoice->is_taxable()) {
564 564
 			$use_taxes = false;
565 565
 		}
566 566
 
567
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
567
+		return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this);
568 568
 	}
569 569
 
570 570
 	/**
@@ -612,13 +612,13 @@  discard block
 block discarded – undo
612 612
 
613 613
 		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
614 614
 		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
615
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
615
+		$processor        = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total);
616 616
 
617
-		foreach ( $processor->discounts as $discount ) {
618
-			$this->add_discount( $discount );
617
+		foreach ($processor->discounts as $discount) {
618
+			$this->add_discount($discount);
619 619
 		}
620 620
 
621
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
621
+		do_action_ref_array('getpaid_submissions_process_discounts', array(&$this));
622 622
 	}
623 623
 
624 624
 	/**
@@ -627,10 +627,10 @@  discard block
 block discarded – undo
627 627
 	 * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
628 628
 	 * @since 1.0.19
629 629
 	 */
630
-	public function add_discount( $discount ) {
631
-		$this->discounts[ $discount['name'] ]   = $discount;
632
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
633
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
630
+	public function add_discount($discount) {
631
+		$this->discounts[$discount['name']]   = $discount;
632
+		$this->totals['discount']['initial']   += wpinv_sanitize_amount($discount['initial_discount']);
633
+		$this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']);
634 634
 	}
635 635
 
636 636
 	/**
@@ -638,12 +638,12 @@  discard block
 block discarded – undo
638 638
 	 *
639 639
 	 * @since 1.0.19
640 640
 	 */
641
-	public function remove_discount( $name ) {
641
+	public function remove_discount($name) {
642 642
 
643
-		if ( isset( $this->discounts[ $name ] ) ) {
644
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
645
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
646
-			unset( $this->discounts[ $name ] );
643
+		if (isset($this->discounts[$name])) {
644
+			$this->totals['discount']['initial']   -= $this->discounts[$name]['initial_discount'];
645
+			$this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount'];
646
+			unset($this->discounts[$name]);
647 647
 		}
648 648
 	}
649 649
 
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
 	 * @return bool
655 655
 	 */
656 656
 	public function has_discount_code() {
657
-		return ! empty( $this->discounts['discount_code'] );
657
+		return !empty($this->discounts['discount_code']);
658 658
 	}
659 659
 
660 660
 	/**
@@ -711,13 +711,13 @@  discard block
 block discarded – undo
711 711
 	 */
712 712
 	public function process_fees() {
713 713
 
714
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
714
+		$fees_processor = new GetPaid_Payment_Form_Submission_Fees($this);
715 715
 
716
-		foreach ( $fees_processor->fees as $fee ) {
717
-			$this->add_fee( $fee );
716
+		foreach ($fees_processor->fees as $fee) {
717
+			$this->add_fee($fee);
718 718
 		}
719 719
 
720
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
720
+		do_action_ref_array('getpaid_submissions_process_fees', array(&$this));
721 721
 	}
722 722
 
723 723
 	/**
@@ -726,17 +726,17 @@  discard block
 block discarded – undo
726 726
 	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
727 727
 	 * @since 1.0.19
728 728
 	 */
729
-	public function add_fee( $fee ) {
729
+	public function add_fee($fee) {
730 730
 
731
-		if ( $fee['name'] == 'shipping' ) {
732
-			$this->totals['shipping']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
733
-			$this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
731
+		if ($fee['name'] == 'shipping') {
732
+			$this->totals['shipping']['initial']   += wpinv_sanitize_amount($fee['initial_fee']);
733
+			$this->totals['shipping']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']);
734 734
 			return;
735 735
 		}
736 736
 
737
-		$this->fees[ $fee['name'] ]         = $fee;
738
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
739
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
737
+		$this->fees[$fee['name']]         = $fee;
738
+		$this->totals['fees']['initial']   += wpinv_sanitize_amount($fee['initial_fee']);
739
+		$this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']);
740 740
 	}
741 741
 
742 742
 	/**
@@ -744,15 +744,15 @@  discard block
 block discarded – undo
744 744
 	 *
745 745
 	 * @since 1.0.19
746 746
 	 */
747
-	public function remove_fee( $name ) {
747
+	public function remove_fee($name) {
748 748
 
749
-		if ( isset( $this->fees[ $name ] ) ) {
750
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
751
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
752
-			unset( $this->fees[ $name ] );
749
+		if (isset($this->fees[$name])) {
750
+			$this->totals['fees']['initial']   -= $this->fees[$name]['initial_fee'];
751
+			$this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee'];
752
+			unset($this->fees[$name]);
753 753
 		}
754 754
 
755
-		if ( 'shipping' == $name ) {
755
+		if ('shipping' == $name) {
756 756
 			$this->totals['shipping']['initial']   = 0;
757 757
 			$this->totals['shipping']['recurring'] = 0;
758 758
 		}
@@ -792,7 +792,7 @@  discard block
 block discarded – undo
792 792
 	 * @since 1.0.19
793 793
 	 */
794 794
 	public function has_fees() {
795
-		return count( $this->fees ) !== 0;
795
+		return count($this->fees) !== 0;
796 796
 	}
797 797
 
798 798
 	/*
@@ -828,7 +828,7 @@  discard block
 block discarded – undo
828 828
 	 * @since 1.0.19
829 829
 	 */
830 830
 	public function has_shipping() {
831
-		return apply_filters( 'getpaid_payment_form_has_shipping', false, $this );
831
+		return apply_filters('getpaid_payment_form_has_shipping', false, $this);
832 832
 	}
833 833
 
834 834
 	/**
@@ -838,7 +838,7 @@  discard block
 block discarded – undo
838 838
 	 * @since 1.0.19
839 839
 	 */
840 840
 	public function is_initial_fetch() {
841
-		return isset( $this->data['initial_state'] ) && empty( $this->data['initial_state'] );
841
+		return isset($this->data['initial_state']) && empty($this->data['initial_state']);
842 842
 	}
843 843
 
844 844
 	/**
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
 	 */
849 849
 	public function get_total() {
850 850
 		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount();
851
-		return max( $total, 0 );
851
+		return max($total, 0);
852 852
 	}
853 853
 
854 854
 	/**
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
 	 */
859 859
 	public function get_recurring_total() {
860 860
 		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount();
861
-		return max( $total, 0 );
861
+		return max($total, 0);
862 862
 	}
863 863
 
864 864
 	/**
@@ -870,12 +870,12 @@  discard block
 block discarded – undo
870 870
 		$initial   = $this->get_total();
871 871
 		$recurring = $this->get_recurring_total();
872 872
 
873
-		if ( $this->has_recurring == 0 ) {
873
+		if ($this->has_recurring == 0) {
874 874
 			$recurring = 0;
875 875
 		}
876 876
 
877 877
 		$collect = $initial > 0 || $recurring > 0;
878
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this );
878
+		return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this);
879 879
 	}
880 880
 
881 881
 	/**
@@ -884,7 +884,7 @@  discard block
 block discarded – undo
884 884
 	 * @since 1.0.19
885 885
 	 */
886 886
 	public function get_billing_email() {
887
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this );
887
+		return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this);
888 888
 	}
889 889
 
890 890
 	/**
@@ -894,7 +894,7 @@  discard block
 block discarded – undo
894 894
 	 */
895 895
 	public function has_billing_email() {
896 896
 		$billing_email = $this->get_billing_email();
897
-		return ! empty( $billing_email ) && is_email( $billing_email );
897
+		return !empty($billing_email) && is_email($billing_email);
898 898
 	}
899 899
 
900 900
 	/**
@@ -924,8 +924,8 @@  discard block
 block discarded – undo
924 924
 	 * @since 1.0.19
925 925
 	 * @return mixed|null
926 926
 	 */
927
-	public function get_field( $field, $sub_array_key = null ) {
928
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
927
+	public function get_field($field, $sub_array_key = null) {
928
+		return getpaid_get_array_field($this->data, $field, $sub_array_key);
929 929
 	}
930 930
 
931 931
 	/**
@@ -933,8 +933,8 @@  discard block
 block discarded – undo
933 933
 	 *
934 934
 	 * @since 1.0.19
935 935
 	 */
936
-	public function is_required_field_set( $field ) {
937
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
936
+	public function is_required_field_set($field) {
937
+		return empty($field['required']) || !empty($this->data[$field['id']]);
938 938
 	}
939 939
 
940 940
 	/**
@@ -942,7 +942,7 @@  discard block
 block discarded – undo
942 942
 	 *
943 943
 	 * @since 1.0.19
944 944
 	 */
945
-	public function format_amount( $amount ) {
946
-		return wpinv_price( $amount, $this->get_currency() );
945
+	public function format_amount($amount) {
946
+		return wpinv_price($amount, $this->get_currency());
947 947
 	}
948 948
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 1 patch
Spacing   +84 added lines, -84 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,29 +23,29 @@  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 36
 		$payment_form = $submission->get_payment_form();
37
-		if ( ! empty( $payment_form->invoice ) ) {
37
+		if (!empty($payment_form->invoice)) {
38 38
 			$this->response['invoice'] = $payment_form->invoice->get_id();
39 39
 		}
40 40
 
41
-		$this->add_totals( $submission );
42
-		$this->add_texts( $submission );
43
-		$this->add_items( $submission );
44
-		$this->add_fees( $submission );
45
-		$this->add_discounts( $submission );
46
-		$this->add_taxes( $submission );
47
-		$this->add_gateways( $submission );
48
-		$this->add_data( $submission );
41
+		$this->add_totals($submission);
42
+		$this->add_texts($submission);
43
+		$this->add_items($submission);
44
+		$this->add_fees($submission);
45
+		$this->add_discounts($submission);
46
+		$this->add_taxes($submission);
47
+		$this->add_gateways($submission);
48
+		$this->add_data($submission);
49 49
 	}
50 50
 
51 51
 	/**
@@ -53,30 +53,30 @@  discard block
 block discarded – undo
53 53
 	 *
54 54
 	 * @param GetPaid_Payment_Form_Submission $submission
55 55
 	 */
56
-	public function add_totals( $submission ) {
56
+	public function add_totals($submission) {
57 57
 
58 58
 		$this->response = array_merge(
59 59
 			$this->response,
60 60
 			array(
61 61
 
62 62
 				'totals'      => array(
63
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
64
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
65
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
66
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
67
-					'total'     => $submission->format_amount( $submission->get_total() ),
68
-					'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
63
+					'subtotal'  => $submission->format_amount($submission->get_subtotal()),
64
+					'discount'  => $submission->format_amount($submission->get_discount()),
65
+					'fees'      => $submission->format_amount($submission->get_fee()),
66
+					'tax'       => $submission->format_amount($submission->get_tax()),
67
+					'total'     => $submission->format_amount($submission->get_total()),
68
+					'raw_total' => html_entity_decode(sanitize_text_field($submission->format_amount($submission->get_total())), ENT_QUOTES),
69 69
 				),
70 70
 
71 71
 				'recurring'   => array(
72
-					'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ),
73
-					'discount' => $submission->format_amount( $submission->get_recurring_discount() ),
74
-					'fees'     => $submission->format_amount( $submission->get_recurring_fee() ),
75
-					'tax'      => $submission->format_amount( $submission->get_recurring_tax() ),
76
-					'total'    => $submission->format_amount( $submission->get_recurring_total() ),
72
+					'subtotal' => $submission->format_amount($submission->get_recurring_subtotal()),
73
+					'discount' => $submission->format_amount($submission->get_recurring_discount()),
74
+					'fees'     => $submission->format_amount($submission->get_recurring_fee()),
75
+					'tax'      => $submission->format_amount($submission->get_recurring_tax()),
76
+					'total'    => $submission->format_amount($submission->get_recurring_total()),
77 77
 				),
78 78
 
79
-				'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ),
79
+				'initial_amt' => wpinv_round_amount($submission->get_total(), null, true),
80 80
 				'currency'    => $submission->get_currency(),
81 81
 
82 82
 			)
@@ -88,53 +88,53 @@  discard block
 block discarded – undo
88 88
 	 *
89 89
 	 * @param GetPaid_Payment_Form_Submission $submission
90 90
 	 */
91
-	public function add_texts( $submission ) {
91
+	public function add_texts($submission) {
92 92
 
93
-		$payable = $submission->format_amount( $submission->get_total() );
94
-		$groups  = getpaid_get_subscription_groups( $submission );
93
+		$payable = $submission->format_amount($submission->get_total());
94
+		$groups  = getpaid_get_subscription_groups($submission);
95 95
 
96
-		if ( $submission->has_recurring && 2 > count( $groups ) ) {
96
+		if ($submission->has_recurring && 2 > count($groups)) {
97 97
 
98
-			$recurring = new WPInv_Item( $submission->has_recurring );
99
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
100
-			$main_item = reset( $groups );
98
+			$recurring = new WPInv_Item($submission->has_recurring);
99
+			$period    = getpaid_get_subscription_period_label($recurring->get_recurring_period(true), $recurring->get_recurring_interval(), '');
100
+			$main_item = reset($groups);
101 101
 
102
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
102
+			if ($submission->get_total() == $submission->get_recurring_total()) {
103 103
 				$payable = "$payable / $period";
104
-			} elseif ( $main_item ) {
104
+			} elseif ($main_item) {
105 105
 
106
-				$main_item = reset( $main_item );
106
+				$main_item = reset($main_item);
107 107
 
108 108
 				// Calculate the next renewal date.
109
-				$_period      = $main_item->get_recurring_period( true );
109
+				$_period      = $main_item->get_recurring_period(true);
110 110
 				$_interval    = $main_item->get_recurring_interval();
111 111
 
112 112
 				// If the subscription item has a trial period...
113
-				if ( $main_item->has_free_trial() ) {
114
-					$_period   = $main_item->get_trial_period( true );
113
+				if ($main_item->has_free_trial()) {
114
+					$_period   = $main_item->get_trial_period(true);
115 115
 					$_interval = $main_item->get_trial_interval();
116 116
 				}
117 117
 
118 118
 				$payable = sprintf(
119
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
120
-					$submission->format_amount( $submission->get_total() ),
121
-					$submission->format_amount( $submission->get_recurring_total() ),
119
+					__('%1$s (renews at %2$s / %3$s)', 'invoicing'),
120
+					$submission->format_amount($submission->get_total()),
121
+					$submission->format_amount($submission->get_recurring_total()),
122 122
 					$period
123 123
 				);
124 124
 
125 125
 				$payable .= sprintf(
126 126
 					'<small class="text-muted form-text">%s</small>',
127 127
 					sprintf(
128
-						__( 'First renewal on %s', 'invoicing' ),
129
-						getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) )
128
+						__('First renewal on %s', 'invoicing'),
129
+						getpaid_format_date(date('Y-m-d H:i:s', strtotime("+$_interval $_period", current_time('timestamp'))))
130 130
 					)
131 131
 				);
132 132
 
133 133
 			} else {
134 134
 				$payable = sprintf(
135
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
136
-					$submission->format_amount( $submission->get_total() ),
137
-					$submission->format_amount( $submission->get_recurring_total() ),
135
+					__('%1$s (renews at %2$s / %3$s)', 'invoicing'),
136
+					$submission->format_amount($submission->get_total()),
137
+					$submission->format_amount($submission->get_recurring_total()),
138 138
 					$period
139 139
 				);
140 140
 			}
@@ -144,20 +144,20 @@  discard block
 block discarded – undo
144 144
 			'.getpaid-checkout-total-payable' => $payable,
145 145
 		);
146 146
 
147
-		foreach ( $submission->get_items() as $item ) {
147
+		foreach ($submission->get_items() as $item) {
148 148
             $item_id = $item->has_variable_pricing() ? $item->get_price_id() : $item->get_id();
149 149
 
150
-			$initial_price                                         = $submission->format_amount( $item->get_sub_total() - $item->item_discount );
151
-			$recurring_price                                       = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount );
152
-			$texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
153
-			$texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) );
150
+			$initial_price                                         = $submission->format_amount($item->get_sub_total() - $item->item_discount);
151
+			$recurring_price                                       = $submission->format_amount($item->get_recurring_sub_total() - $item->recurring_item_discount);
152
+			$texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text($item, $submission->get_currency(), $initial_price, $recurring_price);
153
+			$texts[".item-$item_id .getpaid-mobile-item-subtotal"] = sprintf(__('Subtotal: %s', 'invoicing'), $submission->format_amount($item->get_sub_total()));
154 154
 
155
-			if ( $item->get_quantity() == 1 ) {
156
-				$texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = '';
155
+			if ($item->get_quantity() == 1) {
156
+				$texts[".item-$item_id .getpaid-mobile-item-subtotal"] = '';
157 157
 			}
158 158
         }
159 159
 
160
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
160
+		$this->response = array_merge($this->response, array('texts' => $texts));
161 161
 	}
162 162
 
163 163
 	/**
@@ -165,21 +165,21 @@  discard block
 block discarded – undo
165 165
 	 *
166 166
 	 * @param GetPaid_Payment_Form_Submission $submission
167 167
 	 */
168
-	public function add_items( $submission ) {
168
+	public function add_items($submission) {
169 169
 
170 170
 		// Add items.
171 171
 		$items          = array();
172 172
 		$selected_items = array();
173 173
 
174
-        foreach ( $submission->get_items() as $item ) {
174
+        foreach ($submission->get_items() as $item) {
175 175
             $item_id = $item->has_variable_pricing() ? $item->get_price_id() : $item->get_id();
176
-			$items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() );
176
+			$items["$item_id"] = $submission->format_amount($item->get_sub_total());
177 177
 
178
-			$selected_items[ "$item_id" ] = array(
178
+			$selected_items["$item_id"] = array(
179 179
 				'quantity'  => $item->get_quantity(),
180 180
 				'price'     => $item->get_price(),
181 181
                 'price_id'  => (int) $item_id,
182
-				'price_fmt' => $submission->format_amount( $item->get_price() ),
182
+				'price_fmt' => $submission->format_amount($item->get_price()),
183 183
 			);
184 184
 		}
185 185
 
@@ -197,17 +197,17 @@  discard block
 block discarded – undo
197 197
 	 *
198 198
 	 * @param GetPaid_Payment_Form_Submission $submission
199 199
 	 */
200
-	public function add_fees( $submission ) {
200
+	public function add_fees($submission) {
201 201
 
202 202
 		$fees = array();
203 203
 
204
-        foreach ( $submission->get_fees() as $name => $data ) {
205
-			$fees[ $name ] = $submission->format_amount( $data['initial_fee'] );
204
+        foreach ($submission->get_fees() as $name => $data) {
205
+			$fees[$name] = $submission->format_amount($data['initial_fee']);
206 206
 		}
207 207
 
208 208
 		$this->response = array_merge(
209 209
 			$this->response,
210
-			array( 'fees' => $fees )
210
+			array('fees' => $fees)
211 211
 		);
212 212
 	}
213 213
 
@@ -216,17 +216,17 @@  discard block
 block discarded – undo
216 216
 	 *
217 217
 	 * @param GetPaid_Payment_Form_Submission $submission
218 218
 	 */
219
-	public function add_discounts( $submission ) {
219
+	public function add_discounts($submission) {
220 220
 
221 221
 		$discounts = array();
222 222
 
223
-        foreach ( $submission->get_discounts() as $name => $data ) {
224
-			$discounts[ $name ] = $submission->format_amount( $data['initial_discount'] );
223
+        foreach ($submission->get_discounts() as $name => $data) {
224
+			$discounts[$name] = $submission->format_amount($data['initial_discount']);
225 225
 		}
226 226
 
227 227
 		$this->response = array_merge(
228 228
 			$this->response,
229
-			array( 'discounts' => $discounts )
229
+			array('discounts' => $discounts)
230 230
 		);
231 231
 	}
232 232
 
@@ -235,20 +235,20 @@  discard block
 block discarded – undo
235 235
 	 *
236 236
 	 * @param GetPaid_Payment_Form_Submission $submission
237 237
 	 */
238
-	public function add_taxes( $submission ) {
238
+	public function add_taxes($submission) {
239 239
 
240 240
 		$taxes  = array();
241 241
 		$markup = '';
242
-        foreach ( $submission->get_taxes() as $name => $data ) {
243
-			$name           = sanitize_text_field( $name );
244
-			$amount         = $submission->format_amount( $data['initial_tax'] );
245
-			$taxes[ $name ] = $amount;
242
+        foreach ($submission->get_taxes() as $name => $data) {
243
+			$name           = sanitize_text_field($name);
244
+			$amount         = $submission->format_amount($data['initial_tax']);
245
+			$taxes[$name] = $amount;
246 246
 			$markup        .= "<small class='form-text'>$name : $amount</small>";
247 247
 		}
248 248
 
249 249
 		$this->response = array_merge(
250 250
 			$this->response,
251
-			array( 'taxes' => $taxes )
251
+			array('taxes' => $taxes)
252 252
 		);
253 253
 	}
254 254
 
@@ -257,27 +257,27 @@  discard block
 block discarded – undo
257 257
 	 *
258 258
 	 * @param GetPaid_Payment_Form_Submission $submission
259 259
 	 */
260
-	public function add_gateways( $submission ) {
260
+	public function add_gateways($submission) {
261 261
 
262
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
262
+		$gateways = array_keys(wpinv_get_enabled_payment_gateways());
263 263
 
264
-		if ( $this->response['has_recurring'] ) {
264
+		if ($this->response['has_recurring']) {
265 265
 
266
-			foreach ( $gateways as $i => $gateway ) {
266
+			foreach ($gateways as $i => $gateway) {
267 267
 
268 268
 				if (
269
-					! getpaid_payment_gateway_supports( $gateway, 'subscription' )
270
-					|| ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) )
271
-					|| ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) {
272
-					unset( $gateways[ $i ] );
269
+					!getpaid_payment_gateway_supports($gateway, 'subscription')
270
+					|| ($this->response['has_subscription_group'] && !getpaid_payment_gateway_supports($gateway, 'single_subscription_group'))
271
+					|| ($this->response['has_multiple_subscription_groups'] && !getpaid_payment_gateway_supports($gateway, 'multiple_subscription_groups')) ) {
272
+					unset($gateways[$i]);
273 273
 				}
274 274
             }
275 275
         }
276 276
 
277
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
277
+		$gateways = apply_filters('getpaid_submission_gateways', $gateways, $submission);
278 278
 		$this->response = array_merge(
279 279
 			$this->response,
280
-			array( 'gateways' => $gateways )
280
+			array('gateways' => $gateways)
281 281
 		);
282 282
 	}
283 283
 
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 	 *
287 287
 	 * @param GetPaid_Payment_Form_Submission $submission
288 288
 	 */
289
-	public function add_data( $submission ) {
289
+	public function add_data($submission) {
290 290
 
291 291
 		$this->response = array_merge(
292 292
 			$this->response,
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form.php 1 patch
Spacing   +158 added lines, -158 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -72,28 +72,28 @@  discard block
 block discarded – undo
72 72
 	 *
73 73
 	 * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74 74
 	 */
75
-	public function __construct( $form = 0 ) {
76
-		parent::__construct( $form );
75
+	public function __construct($form = 0) {
76
+		parent::__construct($form);
77 77
 
78
-		if ( is_numeric( $form ) && $form > 0 ) {
79
-			$this->set_id( $form );
80
-		} elseif ( $form instanceof self ) {
78
+		if (is_numeric($form) && $form > 0) {
79
+			$this->set_id($form);
80
+		} elseif ($form instanceof self) {
81 81
 
82
-			$this->set_id( $form->get_id() );
82
+			$this->set_id($form->get_id());
83 83
 			$this->invoice = $form->invoice;
84 84
 
85
-		} elseif ( ! empty( $form->ID ) ) {
86
-			$this->set_id( $form->ID );
85
+		} elseif (!empty($form->ID)) {
86
+			$this->set_id($form->ID);
87 87
 		} else {
88
-			$this->set_object_read( true );
88
+			$this->set_object_read(true);
89 89
 		}
90 90
 
91 91
         // Load the datastore.
92
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
92
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
93 93
 
94
-		if ( $this->get_id() > 0 ) {
95
-            $this->post = get_post( $this->get_id() );
96
-			$this->data_store->read( $this );
94
+		if ($this->get_id() > 0) {
95
+            $this->post = get_post($this->get_id());
96
+			$this->data_store->read($this);
97 97
         }
98 98
 	}
99 99
 
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
 	 * @param  string $context View or edit context.
120 120
 	 * @return string
121 121
 	 */
122
-	public function get_version( $context = 'view' ) {
123
-		return $this->get_prop( 'version', $context );
122
+	public function get_version($context = 'view') {
123
+		return $this->get_prop('version', $context);
124 124
     }
125 125
 
126 126
     /**
@@ -130,8 +130,8 @@  discard block
 block discarded – undo
130 130
 	 * @param  string $context View or edit context.
131 131
 	 * @return string
132 132
 	 */
133
-	public function get_date_created( $context = 'view' ) {
134
-		return $this->get_prop( 'date_created', $context );
133
+	public function get_date_created($context = 'view') {
134
+		return $this->get_prop('date_created', $context);
135 135
     }
136 136
 
137 137
     /**
@@ -141,11 +141,11 @@  discard block
 block discarded – undo
141 141
 	 * @param  string $context View or edit context.
142 142
 	 * @return string
143 143
 	 */
144
-	public function get_date_created_gmt( $context = 'view' ) {
145
-        $date = $this->get_date_created( $context );
144
+	public function get_date_created_gmt($context = 'view') {
145
+        $date = $this->get_date_created($context);
146 146
 
147
-        if ( $date ) {
148
-            $date = get_gmt_from_date( $date );
147
+        if ($date) {
148
+            $date = get_gmt_from_date($date);
149 149
         }
150 150
 		return $date;
151 151
     }
@@ -157,8 +157,8 @@  discard block
 block discarded – undo
157 157
 	 * @param  string $context View or edit context.
158 158
 	 * @return string
159 159
 	 */
160
-	public function get_date_modified( $context = 'view' ) {
161
-		return $this->get_prop( 'date_modified', $context );
160
+	public function get_date_modified($context = 'view') {
161
+		return $this->get_prop('date_modified', $context);
162 162
     }
163 163
 
164 164
     /**
@@ -168,11 +168,11 @@  discard block
 block discarded – undo
168 168
 	 * @param  string $context View or edit context.
169 169
 	 * @return string
170 170
 	 */
171
-	public function get_date_modified_gmt( $context = 'view' ) {
172
-        $date = $this->get_date_modified( $context );
171
+	public function get_date_modified_gmt($context = 'view') {
172
+        $date = $this->get_date_modified($context);
173 173
 
174
-        if ( $date ) {
175
-            $date = get_gmt_from_date( $date );
174
+        if ($date) {
175
+            $date = get_gmt_from_date($date);
176 176
         }
177 177
 		return $date;
178 178
     }
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
 	 * @param  string $context View or edit context.
185 185
 	 * @return string
186 186
 	 */
187
-	public function get_name( $context = 'view' ) {
188
-		return $this->get_prop( 'name', $context );
187
+	public function get_name($context = 'view') {
188
+		return $this->get_prop('name', $context);
189 189
     }
190 190
 
191 191
     /**
@@ -195,8 +195,8 @@  discard block
 block discarded – undo
195 195
 	 * @param  string $context View or edit context.
196 196
 	 * @return string
197 197
 	 */
198
-	public function get_title( $context = 'view' ) {
199
-		return $this->get_name( $context );
198
+	public function get_title($context = 'view') {
199
+		return $this->get_name($context);
200 200
 	}
201 201
 
202 202
     /**
@@ -206,8 +206,8 @@  discard block
 block discarded – undo
206 206
 	 * @param  string $context View or edit context.
207 207
 	 * @return int
208 208
 	 */
209
-	public function get_author( $context = 'view' ) {
210
-		return (int) $this->get_prop( 'author', $context );
209
+	public function get_author($context = 'view') {
210
+		return (int) $this->get_prop('author', $context);
211 211
     }
212 212
 
213 213
     /**
@@ -217,21 +217,21 @@  discard block
 block discarded – undo
217 217
 	 * @param  string $context View or edit context.
218 218
 	 * @return array
219 219
 	 */
220
-	public function get_elements( $context = 'view' ) {
221
-		$elements = $this->get_prop( 'elements', $context );
220
+	public function get_elements($context = 'view') {
221
+		$elements = $this->get_prop('elements', $context);
222 222
 
223
-		if ( empty( $elements ) || ! is_array( $elements ) ) {
224
-            return wpinv_get_data( 'sample-payment-form' );
223
+		if (empty($elements) || !is_array($elements)) {
224
+            return wpinv_get_data('sample-payment-form');
225 225
 		}
226 226
 
227 227
 		// Ensure that all required elements exist.
228 228
 		$_elements = array();
229
-		foreach ( $elements as $element ) {
229
+		foreach ($elements as $element) {
230 230
 
231
-			if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
231
+			if ($element['type'] == 'pay_button' && !$this->has_element_type('gateway_select')) {
232 232
 
233 233
 				$_elements[] = array(
234
-					'text'    => __( 'Select Payment Method', 'invoicing' ),
234
+					'text'    => __('Select Payment Method', 'invoicing'),
235 235
 					'id'      => 'gtscicd',
236 236
 					'name'    => 'gtscicd',
237 237
 					'type'    => 'gateway_select',
@@ -256,22 +256,22 @@  discard block
 block discarded – undo
256 256
 	 * @param  string $return objects or arrays.
257 257
 	 * @return GetPaid_Form_Item[]
258 258
 	 */
259
-	public function get_items( $context = 'view', $return = 'objects' ) {
260
-		$items = $this->get_prop( 'items', $context );
259
+	public function get_items($context = 'view', $return = 'objects') {
260
+		$items = $this->get_prop('items', $context);
261 261
 
262
-		if ( empty( $items ) || ! is_array( $items ) ) {
263
-            $items = wpinv_get_data( 'sample-payment-form-items' );
262
+		if (empty($items) || !is_array($items)) {
263
+            $items = wpinv_get_data('sample-payment-form-items');
264 264
 		}
265 265
 
266 266
 		// Convert the items.
267 267
 		$prepared = array();
268 268
 
269
-		foreach ( $items as $key => $value ) {
269
+		foreach ($items as $key => $value) {
270 270
 
271 271
 			// Form items.
272
-			if ( $value instanceof GetPaid_Form_Item ) {
272
+			if ($value instanceof GetPaid_Form_Item) {
273 273
 
274
-				if ( $value->can_purchase() ) {
274
+				if ($value->can_purchase()) {
275 275
 					$prepared[] = $value;
276 276
 				}
277 277
 
@@ -280,16 +280,16 @@  discard block
 block discarded – undo
280 280
 			}
281 281
 
282 282
 			// $item_id => $quantity (buy buttons)
283
-			if ( is_numeric( $key ) && is_numeric( $value ) ) {
284
-				$item = new GetPaid_Form_Item( $key );
283
+			if (is_numeric($key) && is_numeric($value)) {
284
+				$item = new GetPaid_Form_Item($key);
285 285
 
286
-				if ( $item->can_purchase() ) {
286
+				if ($item->can_purchase()) {
287 287
 
288 288
 					$value = (float) $value;
289
-					$item->set_quantity( $value );
290
-					if ( 0 == $value ) {
291
-						$item->set_quantity( 1 );
292
-						$item->set_allow_quantities( true );
289
+					$item->set_quantity($value);
290
+					if (0 == $value) {
291
+						$item->set_quantity(1);
292
+						$item->set_allow_quantities(true);
293 293
 					}
294 294
 
295 295
 					$prepared[] = $item;
@@ -299,33 +299,33 @@  discard block
 block discarded – undo
299 299
 			}
300 300
 
301 301
 			// Items saved via payment forms editor.
302
-			if ( is_array( $value ) && isset( $value['id'] ) ) {
302
+			if (is_array($value) && isset($value['id'])) {
303 303
 
304
-				$item = new GetPaid_Form_Item( $value['id'] );
304
+				$item = new GetPaid_Form_Item($value['id']);
305 305
 
306
-				if ( ! $item->can_purchase() ) {
306
+				if (!$item->can_purchase()) {
307 307
 					continue;
308 308
 				}
309 309
 
310 310
 				// Sub-total (Cart items).
311
-				if ( isset( $value['subtotal'] ) ) {
312
-					$item->set_price( $value['subtotal'] );
311
+				if (isset($value['subtotal'])) {
312
+					$item->set_price($value['subtotal']);
313 313
 				}
314 314
 
315
-				if ( isset( $value['quantity'] ) ) {
316
-					$item->set_quantity( $value['quantity'] );
315
+				if (isset($value['quantity'])) {
316
+					$item->set_quantity($value['quantity']);
317 317
 				}
318 318
 
319
-				if ( isset( $value['allow_quantities'] ) ) {
320
-					$item->set_allow_quantities( $value['allow_quantities'] );
319
+				if (isset($value['allow_quantities'])) {
320
+					$item->set_allow_quantities($value['allow_quantities']);
321 321
 				}
322 322
 
323
-				if ( isset( $value['required'] ) ) {
324
-					$item->set_is_required( $value['required'] );
323
+				if (isset($value['required'])) {
324
+					$item->set_is_required($value['required']);
325 325
 				}
326 326
 
327
-				if ( isset( $value['description'] ) ) {
328
-					$item->set_custom_description( $value['description'] );
327
+				if (isset($value['description'])) {
328
+					$item->set_custom_description($value['description']);
329 329
 				}
330 330
 
331 331
 				$prepared[] = $item;
@@ -334,14 +334,14 @@  discard block
 block discarded – undo
334 334
 			}
335 335
 
336 336
 			// $item_id => array( 'price' => 10 ) (item variations)
337
-			if ( is_numeric( $key ) && is_array( $value ) ) {
338
-				$item = new GetPaid_Form_Item( $key );
337
+			if (is_numeric($key) && is_array($value)) {
338
+				$item = new GetPaid_Form_Item($key);
339 339
 
340
-				if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
341
-					$item->set_price( $value['price'] );
340
+				if (isset($value['price']) && $item->user_can_set_their_price()) {
341
+					$item->set_price($value['price']);
342 342
 				}
343 343
 
344
-				if ( $item->can_purchase() ) {
344
+				if ($item->can_purchase()) {
345 345
 					$prepared[] = $item;
346 346
 				}
347 347
 
@@ -349,12 +349,12 @@  discard block
 block discarded – undo
349 349
 			}
350 350
 		}
351 351
 
352
-		if ( 'objects' == $return && 'view' == $context ) {
352
+		if ('objects' == $return && 'view' == $context) {
353 353
 			return $prepared;
354 354
 		}
355 355
 
356 356
 		$items = array();
357
-		foreach ( $prepared as $item ) {
357
+		foreach ($prepared as $item) {
358 358
 			$items[] = $item->prepare_data_for_use();
359 359
 		}
360 360
 
@@ -368,14 +368,14 @@  discard block
 block discarded – undo
368 368
 	 * @param  int $item_id The item id to return.
369 369
 	 * @return GetPaid_Form_Item|bool
370 370
 	 */
371
-	public function get_item( $item_id ) {
371
+	public function get_item($item_id) {
372 372
 
373
-		if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
373
+		if (empty($item_id) || !is_numeric($item_id)) {
374 374
 			return false;
375 375
 		}
376 376
 
377
-		foreach ( $this->get_items() as $item ) {
378
-			if ( $item->get_id() == (int) $item_id ) {
377
+		foreach ($this->get_items() as $item) {
378
+			if ($item->get_id() == (int) $item_id) {
379 379
 				return $item;
380 380
 			}
381 381
 		}
@@ -390,15 +390,15 @@  discard block
 block discarded – undo
390 390
 	 * @param  string $element_type The element type to return.
391 391
 	 * @return array|bool
392 392
 	 */
393
-	public function get_element_type( $element_type ) {
393
+	public function get_element_type($element_type) {
394 394
 
395
-		if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
395
+		if (empty($element_type) || !is_scalar($element_type)) {
396 396
 			return false;
397 397
 		}
398 398
 
399
-		foreach ( $this->get_prop( 'elements' ) as $element ) {
399
+		foreach ($this->get_prop('elements') as $element) {
400 400
 
401
-			if ( $element['type'] === $element_type ) {
401
+			if ($element['type'] === $element_type) {
402 402
 				return $element;
403 403
 			}
404 404
 		}
@@ -413,8 +413,8 @@  discard block
 block discarded – undo
413 413
 	 * @param  string $context View or edit context.
414 414
 	 * @return float
415 415
 	 */
416
-	public function get_earned( $context = 'view' ) {
417
-		return $this->get_prop( 'earned', $context );
416
+	public function get_earned($context = 'view') {
417
+		return $this->get_prop('earned', $context);
418 418
 	}
419 419
 
420 420
 	/**
@@ -424,8 +424,8 @@  discard block
 block discarded – undo
424 424
 	 * @param  string $context View or edit context.
425 425
 	 * @return float
426 426
 	 */
427
-	public function get_refunded( $context = 'view' ) {
428
-		return $this->get_prop( 'refunded', $context );
427
+	public function get_refunded($context = 'view') {
428
+		return $this->get_prop('refunded', $context);
429 429
 	}
430 430
 
431 431
 	/**
@@ -435,8 +435,8 @@  discard block
 block discarded – undo
435 435
 	 * @param  string $context View or edit context.
436 436
 	 * @return float
437 437
 	 */
438
-	public function get_cancelled( $context = 'view' ) {
439
-		return $this->get_prop( 'cancelled', $context );
438
+	public function get_cancelled($context = 'view') {
439
+		return $this->get_prop('cancelled', $context);
440 440
 	}
441 441
 
442 442
 	/**
@@ -446,8 +446,8 @@  discard block
 block discarded – undo
446 446
 	 * @param  string $context View or edit context.
447 447
 	 * @return float
448 448
 	 */
449
-	public function get_failed( $context = 'view' ) {
450
-		return $this->get_prop( 'failed', $context );
449
+	public function get_failed($context = 'view') {
450
+		return $this->get_prop('failed', $context);
451 451
 	}
452 452
 
453 453
 	/**
@@ -458,8 +458,8 @@  discard block
 block discarded – undo
458 458
 	 * @return string
459 459
 	 */
460 460
 	public function get_currency() {
461
-		$currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
462
-		return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
461
+		$currency = empty($this->invoice) ? wpinv_get_currency() : $this->invoice->get_currency();
462
+		return apply_filters('getpaid-payment-form-currency', $currency, $this);
463 463
 	}
464 464
 
465 465
     /*
@@ -477,8 +477,8 @@  discard block
 block discarded – undo
477 477
 	 *
478 478
 	 * @since 1.0.19
479 479
 	 */
480
-	public function set_version( $value ) {
481
-		$this->set_prop( 'version', $value );
480
+	public function set_version($value) {
481
+		$this->set_prop('version', $value);
482 482
     }
483 483
 
484 484
     /**
@@ -488,11 +488,11 @@  discard block
 block discarded – undo
488 488
 	 * @param string $value Value to set.
489 489
      * @return bool Whether or not the date was set.
490 490
 	 */
491
-	public function set_date_created( $value ) {
492
-        $date = strtotime( $value );
491
+	public function set_date_created($value) {
492
+        $date = strtotime($value);
493 493
 
494
-        if ( $date ) {
495
-            $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) );
494
+        if ($date) {
495
+            $this->set_prop('date_created', date('Y-m-d H:i:s', $date));
496 496
             return true;
497 497
         }
498 498
 
@@ -506,11 +506,11 @@  discard block
 block discarded – undo
506 506
 	 * @param string $value Value to set.
507 507
      * @return bool Whether or not the date was set.
508 508
 	 */
509
-	public function set_date_modified( $value ) {
510
-        $date = strtotime( $value );
509
+	public function set_date_modified($value) {
510
+        $date = strtotime($value);
511 511
 
512
-        if ( $date ) {
513
-            $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) );
512
+        if ($date) {
513
+            $this->set_prop('date_modified', date('Y-m-d H:i:s', $date));
514 514
             return true;
515 515
         }
516 516
 
@@ -523,8 +523,8 @@  discard block
 block discarded – undo
523 523
 	 * @since 1.0.19
524 524
 	 * @param  string $value New name.
525 525
 	 */
526
-	public function set_name( $value ) {
527
-		$this->set_prop( 'name', sanitize_text_field( $value ) );
526
+	public function set_name($value) {
527
+		$this->set_prop('name', sanitize_text_field($value));
528 528
     }
529 529
 
530 530
     /**
@@ -533,8 +533,8 @@  discard block
 block discarded – undo
533 533
 	 * @since 1.0.19
534 534
 	 * @param  string $value New name.
535 535
 	 */
536
-	public function set_title( $value ) {
537
-		$this->set_name( $value );
536
+	public function set_title($value) {
537
+		$this->set_name($value);
538 538
     }
539 539
 
540 540
     /**
@@ -543,8 +543,8 @@  discard block
 block discarded – undo
543 543
 	 * @since 1.0.19
544 544
 	 * @param  int $value New author.
545 545
 	 */
546
-	public function set_author( $value ) {
547
-		$this->set_prop( 'author', (int) $value );
546
+	public function set_author($value) {
547
+		$this->set_prop('author', (int) $value);
548 548
 	}
549 549
 
550 550
 	/**
@@ -554,9 +554,9 @@  discard block
 block discarded – undo
554 554
 	 * @sinve 2.3.4 Array values sanitized.
555 555
 	 * @param  array $value Form elements.
556 556
 	 */
557
-	public function set_elements( $value ) {
558
-		if ( is_array( $value ) ) {
559
-			$this->set_prop( 'elements', wp_kses_post_deep( $value ) );
557
+	public function set_elements($value) {
558
+		if (is_array($value)) {
559
+			$this->set_prop('elements', wp_kses_post_deep($value));
560 560
 		}
561 561
 	}
562 562
 
@@ -567,36 +567,36 @@  discard block
 block discarded – undo
567 567
 	 *
568 568
 	 * @return mixed
569 569
 	 */
570
-	public function sanitize_array_values( $value ) {
570
+	public function sanitize_array_values($value) {
571 571
 
572 572
 		// sanitize
573
-		if ( ! empty( $value ) ) {
573
+		if (!empty($value)) {
574 574
 
575
-			foreach ( $value as $key => $val_arr ) {
575
+			foreach ($value as $key => $val_arr) {
576 576
 
577
-				if ( is_array( $val_arr ) ) {
577
+				if (is_array($val_arr)) {
578 578
 					// check if we have sub array items.
579 579
 					$sub_arr = array();
580
-					foreach ( $val_arr as $key2 => $val2 ) {
581
-						if ( is_array( $val2 ) ) {
582
-							$sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 );
583
-							unset( $val_arr[ $key ][ $key2 ] );
580
+					foreach ($val_arr as $key2 => $val2) {
581
+						if (is_array($val2)) {
582
+							$sub_arr[$key2] = $this->sanitize_array_values($val2);
583
+							unset($val_arr[$key][$key2]);
584 584
 						}
585 585
 					}
586 586
 
587 587
 					// we allow some html in description so we sanitize it separately.
588
-					$help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : '';
588
+					$help_text = !empty($val_arr['description']) ? wp_kses_post($val_arr['description']) : '';
589 589
 
590 590
 					// sanitize array elements
591
-					$value[ $key ] = array_map( 'sanitize_text_field', $val_arr );
591
+					$value[$key] = array_map('sanitize_text_field', $val_arr);
592 592
 
593 593
 					// add back the description if set
594
-					if ( isset( $val_arr['description'] ) ) {
595
-                        $value[ $key ]['description'] = $help_text;}
594
+					if (isset($val_arr['description'])) {
595
+                        $value[$key]['description'] = $help_text; }
596 596
 
597 597
 					// add back sub array items after its been sanitized.
598
-					if ( ! empty( $sub_arr ) ) {
599
-						$value[ $key ] = array_merge( $value[ $key ], $sub_arr );
598
+					if (!empty($sub_arr)) {
599
+						$value[$key] = array_merge($value[$key], $sub_arr);
600 600
 					}
601 601
 				}
602 602
             }
@@ -611,9 +611,9 @@  discard block
 block discarded – undo
611 611
 	 * @since 1.0.19
612 612
 	 * @param  array $value Form elements.
613 613
 	 */
614
-	public function set_items( $value ) {
615
-		if ( is_array( $value ) ) {
616
-			$this->set_prop( 'items', $value );
614
+	public function set_items($value) {
615
+		if (is_array($value)) {
616
+			$this->set_prop('items', $value);
617 617
 		}
618 618
 	}
619 619
 
@@ -623,9 +623,9 @@  discard block
 block discarded – undo
623 623
 	 * @since 1.0.19
624 624
 	 * @param  float $value Amount earned.
625 625
 	 */
626
-	public function set_earned( $value ) {
627
-		$value = max( (float) $value, 0 );
628
-		$this->set_prop( 'earned', $value );
626
+	public function set_earned($value) {
627
+		$value = max((float) $value, 0);
628
+		$this->set_prop('earned', $value);
629 629
 	}
630 630
 
631 631
 	/**
@@ -634,9 +634,9 @@  discard block
 block discarded – undo
634 634
 	 * @since 1.0.19
635 635
 	 * @param  float $value Amount refunded.
636 636
 	 */
637
-	public function set_refunded( $value ) {
638
-		$value = max( (float) $value, 0 );
639
-		$this->set_prop( 'refunded', $value );
637
+	public function set_refunded($value) {
638
+		$value = max((float) $value, 0);
639
+		$this->set_prop('refunded', $value);
640 640
 	}
641 641
 
642 642
 	/**
@@ -645,9 +645,9 @@  discard block
 block discarded – undo
645 645
 	 * @since 1.0.19
646 646
 	 * @param  float $value Amount cancelled.
647 647
 	 */
648
-	public function set_cancelled( $value ) {
649
-		$value = max( (float) $value, 0 );
650
-		$this->set_prop( 'cancelled', $value );
648
+	public function set_cancelled($value) {
649
+		$value = max((float) $value, 0);
650
+		$this->set_prop('cancelled', $value);
651 651
 	}
652 652
 
653 653
 	/**
@@ -656,9 +656,9 @@  discard block
 block discarded – undo
656 656
 	 * @since 1.0.19
657 657
 	 * @param  float $value Amount cancelled.
658 658
 	 */
659
-	public function set_failed( $value ) {
660
-		$value = max( (float) $value, 0 );
661
-		$this->set_prop( 'failed', $value );
659
+	public function set_failed($value) {
660
+		$value = max((float) $value, 0);
661
+		$this->set_prop('failed', $value);
662 662
 	}
663 663
 
664 664
     /**
@@ -667,11 +667,11 @@  discard block
 block discarded – undo
667 667
      * @deprecated
668 668
 	 * @return int item id
669 669
      */
670
-    public function create( $data = array() ) {
670
+    public function create($data = array()) {
671 671
 
672 672
 		// Set the properties.
673
-		if ( is_array( $data ) ) {
674
-			$this->set_props( $data );
673
+		if (is_array($data)) {
674
+			$this->set_props($data);
675 675
 		}
676 676
 
677 677
 		// Save the item.
@@ -684,8 +684,8 @@  discard block
 block discarded – undo
684 684
      * @deprecated
685 685
 	 * @return int item id
686 686
      */
687
-    public function update( $data = array() ) {
688
-        return $this->create( $data );
687
+    public function update($data = array()) {
688
+        return $this->create($data);
689 689
     }
690 690
 
691 691
     /*
@@ -705,7 +705,7 @@  discard block
 block discarded – undo
705 705
 	 */
706 706
     public function is_default() {
707 707
         $is_default = $this->get_id() == wpinv_get_default_payment_form();
708
-        return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this );
708
+        return (bool) apply_filters('wpinv_is_default_payment_form', $is_default, $this->get_id(), $this);
709 709
 	}
710 710
 
711 711
     /**
@@ -717,11 +717,11 @@  discard block
 block discarded – undo
717 717
     public function is_active() {
718 718
         $is_active = 0 !== (int) $this->get_id();
719 719
 
720
-        if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) {
720
+        if ($is_active && !current_user_can('edit_post', $this->get_id()) && $this->get_status() != 'publish') {
721 721
             $is_active = false;
722 722
         }
723 723
 
724
-        return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this );
724
+        return (bool) apply_filters('wpinv_is_payment_form_active', $is_active, $this);
725 725
 	}
726 726
 
727 727
 	/**
@@ -730,8 +730,8 @@  discard block
 block discarded – undo
730 730
 	 * @since 1.0.19
731 731
 	 * @return bool
732 732
 	 */
733
-    public function has_item( $item_id ) {
734
-        return false !== $this->get_item( $item_id );
733
+    public function has_item($item_id) {
734
+        return false !== $this->get_item($item_id);
735 735
 	}
736 736
 
737 737
 	/**
@@ -740,8 +740,8 @@  discard block
 block discarded – undo
740 740
 	 * @since 1.0.19
741 741
 	 * @return bool
742 742
 	 */
743
-    public function has_element_type( $element_type ) {
744
-        return false !== $this->get_element_type( $element_type );
743
+    public function has_element_type($element_type) {
744
+        return false !== $this->get_element_type($element_type);
745 745
 	}
746 746
 
747 747
 	/**
@@ -752,13 +752,13 @@  discard block
 block discarded – undo
752 752
 	 */
753 753
     public function is_recurring() {
754 754
 
755
-		if ( ! empty( $this->invoice ) ) {
755
+		if (!empty($this->invoice)) {
756 756
 			return $this->invoice->is_recurring();
757 757
 		}
758 758
 
759
-		foreach ( $this->get_items() as $item ) {
759
+		foreach ($this->get_items() as $item) {
760 760
 
761
-			if ( $item->is_recurring() ) {
761
+			if ($item->is_recurring()) {
762 762
 				return true;
763 763
 			}
764 764
         }
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
 	 *
772 772
 	 * @since 1.0.19
773 773
 	 */
774
-    public function get_html( $extra_markup = '' ) {
774
+    public function get_html($extra_markup = '') {
775 775
 
776 776
 		// Return the HTML.
777 777
 		return wpinv_get_template_html(
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
 	 *
789 789
 	 * @since 1.0.19
790 790
 	 */
791
-    public function display( $extra_markup = '' ) {
791
+    public function display($extra_markup = '') {
792 792
 		wpinv_get_template(
793 793
 			'payment-forms/form.php',
794 794
 			array(
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 1 patch
Spacing   +339 added lines, -339 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * WPInv_Ajax class.
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
 	 * Hook in ajax handlers.
18 18
 	 */
19 19
 	public static function init() {
20
-		add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
-		add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
20
+		add_action('init', array(__CLASS__, 'define_ajax'), 0);
21
+		add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
22 22
 		self::add_ajax_events();
23 23
     }
24 24
 
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 	 */
28 28
 	public static function define_ajax() {
29 29
 
30
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
-			getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
-			getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
-			if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
-				/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
30
+		if (!empty($_GET['wpinv-ajax'])) {
31
+			getpaid_maybe_define_constant('DOING_AJAX', true);
32
+			getpaid_maybe_define_constant('WPInv_DOING_AJAX', true);
33
+			if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
34
+				/** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0);
35 35
 			}
36 36
 			$GLOBALS['wpdb']->hide_errors();
37 37
 		}
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
 	 * @since 1.0.18
45 45
 	 */
46 46
 	private static function wpinv_ajax_headers() {
47
-		if ( ! headers_sent() ) {
47
+		if (!headers_sent()) {
48 48
 			send_origin_headers();
49 49
 			send_nosniff_header();
50 50
 			nocache_headers();
51
-			header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
-			header( 'X-Robots-Tag: noindex' );
53
-			status_header( 200 );
51
+			header('Content-Type: text/html; charset=' . get_option('blog_charset'));
52
+			header('X-Robots-Tag: noindex');
53
+			status_header(200);
54 54
 		}
55 55
     }
56 56
 
@@ -60,16 +60,16 @@  discard block
 block discarded – undo
60 60
 	public static function do_wpinv_ajax() {
61 61
 		global $wp_query;
62 62
 
63
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
-			$wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
63
+		if (!empty($_GET['wpinv-ajax'])) {
64
+			$wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax'])));
65 65
 		}
66 66
 
67
-		$action = $wp_query->get( 'wpinv-ajax' );
67
+		$action = $wp_query->get('wpinv-ajax');
68 68
 
69
-		if ( $action ) {
69
+		if ($action) {
70 70
 			self::wpinv_ajax_headers();
71
-			$action = sanitize_text_field( $action );
72
-			do_action( 'wpinv_ajax_' . $action );
71
+			$action = sanitize_text_field($action);
72
+			do_action('wpinv_ajax_' . $action);
73 73
 			wp_die();
74 74
 		}
75 75
 
@@ -106,36 +106,36 @@  discard block
 block discarded – undo
106 106
             'file_upload'                   => true,
107 107
         );
108 108
 
109
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
110
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
111
-            add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
109
+        foreach ($ajax_events as $ajax_event => $nopriv) {
110
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
111
+            add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
112 112
 
113
-            if ( $nopriv ) {
114
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
115
-                add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
116
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
113
+            if ($nopriv) {
114
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
115
+                add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
116
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
117 117
             }
118 118
         }
119 119
     }
120 120
 
121 121
     public static function add_note() {
122
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
122
+        check_ajax_referer('add-invoice-note', '_nonce');
123 123
 
124
-        $post_id   = absint( $_POST['post_id'] );
125
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
126
-        $note_type = sanitize_text_field( $_POST['note_type'] );
124
+        $post_id   = absint($_POST['post_id']);
125
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
126
+        $note_type = sanitize_text_field($_POST['note_type']);
127 127
 
128
-        if ( ! wpinv_current_user_can( 'invoice_add_note', array( 'invoice_id' => $post_id, 'note_type' => $note_type ) ) ) {
128
+        if (!wpinv_current_user_can('invoice_add_note', array('invoice_id' => $post_id, 'note_type' => $note_type))) {
129 129
             die( -1 );
130 130
         }
131 131
 
132 132
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
133 133
 
134
-        if ( $post_id > 0 ) {
135
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
134
+        if ($post_id > 0) {
135
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
136 136
 
137
-            if ( $note_id > 0 && ! is_wp_error( $note_id ) ) {
138
-                wpinv_get_invoice_note_line_item( $note_id );
137
+            if ($note_id > 0 && !is_wp_error($note_id)) {
138
+                wpinv_get_invoice_note_line_item($note_id);
139 139
             }
140 140
         }
141 141
 
@@ -143,16 +143,16 @@  discard block
 block discarded – undo
143 143
     }
144 144
 
145 145
     public static function delete_note() {
146
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
146
+        check_ajax_referer('delete-invoice-note', '_nonce');
147 147
 
148
-        $note_id = (int)$_POST['note_id'];
148
+        $note_id = (int) $_POST['note_id'];
149 149
 
150
-        if ( ! wpinv_current_user_can( 'invoice_delete_note', array( 'note_id' => $note_id ) ) ) {
150
+        if (!wpinv_current_user_can('invoice_delete_note', array('note_id' => $note_id))) {
151 151
             die( -1 );
152 152
         }
153 153
 
154
-        if ( $note_id > 0 ) {
155
-            wp_delete_comment( $note_id, true );
154
+        if ($note_id > 0) {
155
+            wp_delete_comment($note_id, true);
156 156
         }
157 157
 
158 158
         die();
@@ -169,35 +169,35 @@  discard block
 block discarded – undo
169 169
      */
170 170
     public static function get_billing_details() {
171 171
         // Verify nonce.
172
-        check_ajax_referer( 'wpinv-nonce' );
172
+        check_ajax_referer('wpinv-nonce');
173 173
 
174 174
         // Do we have a user id?
175 175
         $user_id = (int) $_GET['user_id'];
176
-        $invoice_id = ! empty( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
176
+        $invoice_id = !empty($_REQUEST['post_id']) ? (int) $_REQUEST['post_id'] : 0;
177 177
 
178
-        if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
178
+        if (empty($user_id) || !is_numeric($user_id)) {
179 179
             die( -1 );
180 180
         }
181 181
 
182 182
         // Can the user manage the plugin?
183
-        if ( ! wpinv_current_user_can( 'invoice_get_billing_details', array( 'user_id' => $user_id, 'invoice_id' => $invoice_id ) ) ) {
183
+        if (!wpinv_current_user_can('invoice_get_billing_details', array('user_id' => $user_id, 'invoice_id' => $invoice_id))) {
184 184
             die( -1 );
185 185
         }
186 186
 
187 187
         // Fetch the billing details.
188
-        $billing_details    = wpinv_get_user_address( $user_id );
189
-        $billing_details    = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id );
188
+        $billing_details    = wpinv_get_user_address($user_id);
189
+        $billing_details    = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id);
190 190
 
191 191
         // unset the user id and email.
192
-        $to_ignore = array( 'user_id', 'email' );
192
+        $to_ignore = array('user_id', 'email');
193 193
 
194
-        foreach ( $to_ignore as $key ) {
195
-            if ( isset( $billing_details[ $key ] ) ) {
196
-                unset( $billing_details[ $key ] );
194
+        foreach ($to_ignore as $key) {
195
+            if (isset($billing_details[$key])) {
196
+                unset($billing_details[$key]);
197 197
             }
198 198
         }
199 199
 
200
-        wp_send_json_success( $billing_details );
200
+        wp_send_json_success($billing_details);
201 201
 
202 202
     }
203 203
 
@@ -206,54 +206,54 @@  discard block
 block discarded – undo
206 206
      */
207 207
     public static function check_new_user_email() {
208 208
         // Verify nonce.
209
-        check_ajax_referer( 'wpinv-nonce' );
209
+        check_ajax_referer('wpinv-nonce');
210 210
 
211
-        $invoice_id = ! empty( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : 0;
211
+        $invoice_id = !empty($_REQUEST['post_id']) ? absint($_REQUEST['post_id']) : 0;
212 212
 
213
-        if ( empty( $invoice_id ) ) {
213
+        if (empty($invoice_id)) {
214 214
             die( -1 );
215 215
         }
216 216
 
217 217
         // Can the user manage the plugin?
218
-        if ( ! wpinv_current_user_can( 'invoice_check_new_user_email', array( 'invoice_id' => $invoice_id ) ) ) {
218
+        if (!wpinv_current_user_can('invoice_check_new_user_email', array('invoice_id' => $invoice_id))) {
219 219
             die( -1 );
220 220
         }
221 221
 
222 222
         // We need an email address.
223
-        if ( empty( $_GET['email'] ) ) {
224
-            esc_html_e( "Provide the new user's email address", 'invoicing' );
223
+        if (empty($_GET['email'])) {
224
+            esc_html_e("Provide the new user's email address", 'invoicing');
225 225
             exit;
226 226
         }
227 227
 
228 228
         // Ensure the email is valid.
229
-        $email = sanitize_email( $_GET['email'] );
230
-        if ( ! is_email( $email ) ) {
231
-            esc_html_e( 'Invalid email address', 'invoicing' );
229
+        $email = sanitize_email($_GET['email']);
230
+        if (!is_email($email)) {
231
+            esc_html_e('Invalid email address', 'invoicing');
232 232
             exit;
233 233
         }
234 234
 
235 235
         // And it does not exist.
236
-        $id = email_exists( $email );
237
-        if ( $id ) {
238
-            wp_send_json_success( compact( 'id' ) );
236
+        $id = email_exists($email);
237
+        if ($id) {
238
+            wp_send_json_success(compact('id'));
239 239
         }
240 240
 
241
-        wp_send_json_success( true );
241
+        wp_send_json_success(true);
242 242
     }
243 243
 
244 244
     public static function run_tool() {
245
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
245
+        check_ajax_referer('wpinv-nonce', '_nonce');
246 246
 
247
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
247
+        if (!wpinv_current_user_can_manage_invoicing()) {
248 248
             die( -1 );
249 249
         }
250 250
 
251
-        $tool = sanitize_text_field( $_POST['tool'] );
251
+        $tool = sanitize_text_field($_POST['tool']);
252 252
 
253
-        do_action( 'wpinv_run_tool' );
253
+        do_action('wpinv_run_tool');
254 254
 
255
-        if ( ! empty( $tool ) ) {
256
-            do_action( 'wpinv_tool_' . $tool );
255
+        if (!empty($tool)) {
256
+            do_action('wpinv_tool_' . $tool);
257 257
         }
258 258
     }
259 259
 
@@ -264,11 +264,11 @@  discard block
 block discarded – undo
264 264
         global $getpaid_force_checkbox;
265 265
 
266 266
         // Is the request set up correctly?
267
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) {
267
+		if (empty($_GET['form']) && empty($_GET['item']) && empty($_GET['invoice'])) {
268 268
 			aui()->alert(
269 269
 				array(
270 270
 					'type'    => 'warning',
271
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
271
+					'content' => __('No payment form or item provided', 'invoicing'),
272 272
                 ),
273 273
                 true
274 274
             );
@@ -276,29 +276,29 @@  discard block
 block discarded – undo
276 276
         }
277 277
 
278 278
         // Payment form or button?
279
-		if ( ! empty( $_GET['form'] ) ) {
280
-            $form = sanitize_text_field( urldecode( $_GET['form'] ) );
279
+		if (!empty($_GET['form'])) {
280
+            $form = sanitize_text_field(urldecode($_GET['form']));
281 281
 
282
-            if ( false !== strpos( $form, '|' ) ) {
283
-                $form_pos = strpos( $form, '|' );
284
-                $_items   = getpaid_convert_items_to_array( substr( $form, $form_pos + 1 ) );
285
-                $form     = substr( $form, 0, $form_pos );
282
+            if (false !== strpos($form, '|')) {
283
+                $form_pos = strpos($form, '|');
284
+                $_items   = getpaid_convert_items_to_array(substr($form, $form_pos + 1));
285
+                $form     = substr($form, 0, $form_pos);
286 286
 
287 287
                 // Retrieve appropriate payment form.
288
-                $payment_form = new GetPaid_Payment_Form( $form );
289
-                $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
288
+                $payment_form = new GetPaid_Payment_Form($form);
289
+                $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form());
290 290
 
291 291
                 $items    = array();
292 292
                 $item_ids = array();
293 293
 
294
-                foreach ( $_items as $item_id => $qty ) {
295
-                    if ( ! in_array( $item_id, $item_ids ) ) {
296
-                        $item = new GetPaid_Form_Item( $item_id );
297
-                        $item->set_quantity( $qty );
294
+                foreach ($_items as $item_id => $qty) {
295
+                    if (!in_array($item_id, $item_ids)) {
296
+                        $item = new GetPaid_Form_Item($item_id);
297
+                        $item->set_quantity($qty);
298 298
 
299
-                        if ( 0 == $qty ) {
300
-                            $item->set_allow_quantities( true );
301
-                            $item->set_is_required( false );
299
+                        if (0 == $qty) {
300
+                            $item->set_allow_quantities(true);
301
+                            $item->set_is_required(false);
302 302
                             $getpaid_force_checkbox = true;
303 303
                         }
304 304
 
@@ -307,33 +307,33 @@  discard block
 block discarded – undo
307 307
                     }
308 308
                 }
309 309
 
310
-                if ( ! $payment_form->is_default() ) {
310
+                if (!$payment_form->is_default()) {
311 311
 
312
-                    foreach ( $payment_form->get_items() as $item ) {
313
-                        if ( ! in_array( $item->get_id(), $item_ids ) ) {
312
+                    foreach ($payment_form->get_items() as $item) {
313
+                        if (!in_array($item->get_id(), $item_ids)) {
314 314
                             $item_ids[] = $item->get_id();
315 315
                             $items[]    = $item;
316 316
                         }
317 317
                     }
318 318
                 }
319 319
 
320
-                $payment_form->set_items( $items );
320
+                $payment_form->set_items($items);
321 321
 
322
-                $extra_items     = esc_attr( getpaid_convert_items_to_string( $_items ) );
323
-                $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items );
322
+                $extra_items     = esc_attr(getpaid_convert_items_to_string($_items));
323
+                $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items);
324 324
                 $extra_items     = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />";
325 325
                 $extra_items    .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />";
326
-                $payment_form->display( $extra_items );
326
+                $payment_form->display($extra_items);
327 327
                 $getpaid_force_checkbox = false;
328 328
 
329 329
             } else {
330
-                getpaid_display_payment_form( $form );
330
+                getpaid_display_payment_form($form);
331 331
             }
332
-        } elseif ( ! empty( $_GET['invoice'] ) ) {
333
-		    getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) );
332
+        } elseif (!empty($_GET['invoice'])) {
333
+		    getpaid_display_invoice_payment_form((int) urldecode($_GET['invoice']));
334 334
         } else {
335
-			$items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) );
336
-		    getpaid_display_item_payment_form( $items );
335
+			$items = getpaid_convert_items_to_array(sanitize_text_field(urldecode($_GET['item'])));
336
+		    getpaid_display_item_payment_form($items);
337 337
         }
338 338
 
339 339
         exit;
@@ -348,14 +348,14 @@  discard block
 block discarded – undo
348 348
     public static function payment_form() { 
349 349
 
350 350
         // ... form fields...
351
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
352
-            esc_html_e( 'Error: Reload the page and try again.', 'invoicing' );
351
+        if (empty($_POST['getpaid_payment_form_submission'])) {
352
+            esc_html_e('Error: Reload the page and try again.', 'invoicing');
353 353
             exit;
354 354
         }
355 355
 
356 356
         // Process the payment form.
357
-        $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' );
358
-        $checkout       = new $checkout_class( new GetPaid_Payment_Form_Submission() );
357
+        $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout');
358
+        $checkout       = new $checkout_class(new GetPaid_Payment_Form_Submission());
359 359
         $checkout->process_checkout();
360 360
 
361 361
         exit;
@@ -368,55 +368,55 @@  discard block
 block discarded – undo
368 368
      */
369 369
     public static function get_payment_form_states_field() {
370 370
 
371
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
371
+        if (empty($_GET['country']) || empty($_GET['form'])) {
372 372
             exit;
373 373
         }
374 374
 
375
-        $elements = getpaid_get_payment_form_elements( (int) $_GET['form'] );
375
+        $elements = getpaid_get_payment_form_elements((int) $_GET['form']);
376 376
 
377
-        if ( empty( $elements ) ) {
377
+        if (empty($elements)) {
378 378
             exit;
379 379
         }
380 380
 
381 381
         $address_fields = array();
382
-        foreach ( $elements as $element ) {
383
-            if ( 'address' === $element['type'] ) {
382
+        foreach ($elements as $element) {
383
+            if ('address' === $element['type']) {
384 384
                 $address_fields = $element;
385 385
                 break;
386 386
             }
387 387
         }
388 388
 
389
-        if ( empty( $address_fields ) ) {
389
+        if (empty($address_fields)) {
390 390
             exit;
391 391
         }
392 392
 
393
-        foreach ( $address_fields['fields'] as $address_field ) {
393
+        foreach ($address_fields['fields'] as $address_field) {
394 394
 
395
-            if ( 'wpinv_state' == $address_field['name'] ) {
395
+            if ('wpinv_state' == $address_field['name']) {
396 396
 
397
-                $wrap_class  = getpaid_get_form_element_grid_class( $address_field );
398
-                $wrap_class  = esc_attr( "$wrap_class getpaid-address-field-wrapper" );
399
-                $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] );
400
-                $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] );
401
-                $value       = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : '';
402
-                $label       = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] );
397
+                $wrap_class  = getpaid_get_form_element_grid_class($address_field);
398
+                $wrap_class  = esc_attr("$wrap_class getpaid-address-field-wrapper");
399
+                $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']);
400
+                $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']);
401
+                $value       = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : '';
402
+                $label       = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']);
403 403
 
404
-                if ( ! empty( $address_field['required'] ) ) {
404
+                if (!empty($address_field['required'])) {
405 405
                     $label .= "<span class='text-danger'> *</span>";
406 406
                 }
407 407
 
408 408
                 $html = getpaid_get_states_select_markup(
409
-                    sanitize_text_field( $_GET['country'] ),
409
+                    sanitize_text_field($_GET['country']),
410 410
                     $value,
411 411
                     $placeholder,
412 412
                     $label,
413 413
                     $description,
414
-                    ! empty( $address_field['required'] ),
414
+                    !empty($address_field['required']),
415 415
                     $wrap_class,
416
-                    sanitize_text_field( $_GET['name'] )
416
+                    sanitize_text_field($_GET['name'])
417 417
                 );
418 418
 
419
-                wp_send_json_success( $html );
419
+                wp_send_json_success($html);
420 420
                 exit;
421 421
 
422 422
             }
@@ -430,68 +430,68 @@  discard block
 block discarded – undo
430 430
      */
431 431
     public static function recalculate_invoice_totals() {
432 432
         // Verify nonce.
433
-        check_ajax_referer( 'wpinv-nonce' );
433
+        check_ajax_referer('wpinv-nonce');
434 434
 
435
-        $invoice_id = ! empty( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0;
435
+        $invoice_id = !empty($_POST['post_id']) ? absint($_POST['post_id']) : 0;
436 436
 
437
-        if ( empty( $invoice_id ) ) {
437
+        if (empty($invoice_id)) {
438 438
             die( -1 );
439 439
         }
440 440
 
441 441
         // Can the user manage the plugin?
442
-        if ( ! wpinv_current_user_can( 'invoice_recalculate_totals', array( 'invoice_id' => $invoice_id ) ) ) {
442
+        if (!wpinv_current_user_can('invoice_recalculate_totals', array('invoice_id' => $invoice_id))) {
443 443
             die( -1 );
444 444
         }
445 445
 
446 446
         // Fetch the invoice.
447
-        $invoice = new WPInv_Invoice( $invoice_id );
447
+        $invoice = new WPInv_Invoice($invoice_id);
448 448
 
449 449
         // Ensure it exists.
450
-        if ( ! $invoice->get_id() ) {
450
+        if (!$invoice->get_id()) {
451 451
             exit;
452 452
         }
453 453
 
454 454
         // Maybe set the country, state, currency.
455
-        foreach ( array( 'country', 'state', 'currency', 'vat_number', 'discount_code' ) as $key ) {
456
-            if ( isset( $_POST[ $key ] ) ) {
455
+        foreach (array('country', 'state', 'currency', 'vat_number', 'discount_code') as $key) {
456
+            if (isset($_POST[$key])) {
457 457
                 $method = "set_$key";
458
-                $invoice->$method( sanitize_text_field( $_POST[ $key ] ) );
458
+                $invoice->$method(sanitize_text_field($_POST[$key]));
459 459
             }
460 460
         }
461 461
 
462 462
         // Maybe disable taxes.
463
-        $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) );
463
+        $invoice->set_disable_taxes(!empty($_POST['taxes']));
464 464
 
465 465
         // Discount code.
466
-        if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
467
-            $discount = new WPInv_Discount( $invoice->get_discount_code() );
468
-            if ( $discount->exists() ) {
469
-                $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
466
+        if (!$invoice->is_paid() && !$invoice->is_refunded()) {
467
+            $discount = new WPInv_Discount($invoice->get_discount_code());
468
+            if ($discount->exists()) {
469
+                $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
470 470
             } else {
471
-                $invoice->remove_discount( 'discount_code' );
471
+                $invoice->remove_discount('discount_code');
472 472
             }
473 473
         }
474 474
 
475 475
         // Recalculate totals.
476 476
         $invoice->recalculate_total();
477 477
 
478
-        $total        = wpinv_price( $invoice->get_total(), $invoice->get_currency() );
479
-        $suscriptions = getpaid_get_invoice_subscriptions( $invoice );
480
-        if ( is_a( $suscriptions, 'WPInv_Subscription' ) && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) {
481
-            $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() );
482
-            $total          .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>';
478
+        $total        = wpinv_price($invoice->get_total(), $invoice->get_currency());
479
+        $suscriptions = getpaid_get_invoice_subscriptions($invoice);
480
+        if (is_a($suscriptions, 'WPInv_Subscription') && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) {
481
+            $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency());
482
+            $total          .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>';
483 483
         }
484 484
 
485 485
         $totals = array(
486
-            'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ),
487
-            'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ),
488
-            'tax'      => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ),
486
+            'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()),
487
+            'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()),
488
+            'tax'      => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()),
489 489
             'total'    => $total,
490 490
         );
491 491
 
492
-        $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice );
492
+        $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice);
493 493
 
494
-        wp_send_json_success( compact( 'totals' ) );
494
+        wp_send_json_success(compact('totals'));
495 495
     }
496 496
 
497 497
     /**
@@ -499,35 +499,35 @@  discard block
 block discarded – undo
499 499
      */
500 500
     public static function get_invoice_items() {
501 501
         // Verify nonce.
502
-        check_ajax_referer( 'wpinv-nonce' );
502
+        check_ajax_referer('wpinv-nonce');
503 503
 
504
-        $invoice_id = ! empty( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0;
504
+        $invoice_id = !empty($_POST['post_id']) ? absint($_POST['post_id']) : 0;
505 505
 
506
-        if ( empty( $invoice_id ) ) {
506
+        if (empty($invoice_id)) {
507 507
             exit;
508 508
         }
509 509
 
510 510
         // Can the user manage the plugin?
511
-        if ( ! wpinv_current_user_can( 'invoice_get_items', array( 'invoice_id' => $invoice_id ) ) ) {
511
+        if (!wpinv_current_user_can('invoice_get_items', array('invoice_id' => $invoice_id))) {
512 512
             exit;
513 513
         }
514 514
 
515 515
         // Fetch the invoice.
516
-        $invoice = new WPInv_Invoice( $invoice_id );
516
+        $invoice = new WPInv_Invoice($invoice_id);
517 517
 
518 518
         // Ensure it exists.
519
-        if ( ! $invoice->get_id() ) {
519
+        if (!$invoice->get_id()) {
520 520
             exit;
521 521
         }
522 522
 
523 523
         // Return an array of invoice items.
524 524
         $items = array();
525 525
 
526
-        foreach ( $invoice->get_items() as $item ) {
527
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency(), $invoice->is_renewal() );
526
+        foreach ($invoice->get_items() as $item) {
527
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal());
528 528
         }
529 529
 
530
-        wp_send_json_success( compact( 'items' ) );
530
+        wp_send_json_success(compact('items'));
531 531
     }
532 532
 
533 533
     /**
@@ -535,57 +535,57 @@  discard block
 block discarded – undo
535 535
      */
536 536
     public static function edit_invoice_item() {
537 537
         // Verify nonce.
538
-        check_ajax_referer( 'wpinv-nonce' );
538
+        check_ajax_referer('wpinv-nonce');
539 539
 
540 540
         // We need an invoice and item details.
541
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) {
541
+        if (empty($_POST['post_id']) || empty($_POST['data'])) {
542 542
             exit;
543 543
         }
544 544
 
545
-        $invoice_id = absint( $_POST['post_id'] );
545
+        $invoice_id = absint($_POST['post_id']);
546 546
 
547
-        if ( empty( $invoice_id ) ) {
547
+        if (empty($invoice_id)) {
548 548
             exit;
549 549
         }
550 550
 
551 551
         // Can the user manage the plugin?
552
-        if ( ! wpinv_current_user_can( 'invoice_edit_item', array( 'invoice_id' => $invoice_id ) ) ) {
552
+        if (!wpinv_current_user_can('invoice_edit_item', array('invoice_id' => $invoice_id))) {
553 553
             exit;
554 554
         }
555 555
 
556 556
         // Fetch the invoice.
557
-        $invoice = new WPInv_Invoice( $invoice_id );
557
+        $invoice = new WPInv_Invoice($invoice_id);
558 558
 
559 559
         // Ensure it exists and its not been paid for.
560
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
560
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
561 561
             exit;
562 562
         }
563 563
 
564 564
         // Format the data.
565
-        $data = wp_kses_post_deep( wp_unslash( wp_list_pluck( $_POST['data'], 'value', 'field' ) ) );
565
+        $data = wp_kses_post_deep(wp_unslash(wp_list_pluck($_POST['data'], 'value', 'field')));
566 566
 
567 567
         // Ensure that we have an item id.
568
-        if ( empty( $data['id'] ) ) {
568
+        if (empty($data['id'])) {
569 569
             exit;
570 570
         }
571 571
 
572 572
         // Abort if the invoice does not have the specified item.
573
-        $item = $invoice->get_item( (int) $data['id'] );
573
+        $item = $invoice->get_item((int) $data['id']);
574 574
 
575
-        if ( empty( $item ) ) {
575
+        if (empty($item)) {
576 576
             exit;
577 577
         }
578 578
 
579 579
         // Update the item.
580
-        $item->set_price( getpaid_standardize_amount( $data['price'] ) );
581
-        $item->set_name( sanitize_text_field( $data['name'] ) );
582
-        $item->set_description( wp_kses_post( $data['description'] ) );
583
-        $item->set_quantity( floatval( $data['quantity'] ) );
580
+        $item->set_price(getpaid_standardize_amount($data['price']));
581
+        $item->set_name(sanitize_text_field($data['name']));
582
+        $item->set_description(wp_kses_post($data['description']));
583
+        $item->set_quantity(floatval($data['quantity']));
584 584
 
585 585
         // Add it to the invoice.
586
-        $error = $invoice->add_item( $item );
586
+        $error = $invoice->add_item($item);
587 587
         $alert = false;
588
-        if ( is_wp_error( $error ) ) {
588
+        if (is_wp_error($error)) {
589 589
             $alert = $error->get_error_message();
590 590
         }
591 591
 
@@ -598,11 +598,11 @@  discard block
 block discarded – undo
598 598
         // Return an array of invoice items.
599 599
         $items = array();
600 600
 
601
-        foreach ( $invoice->get_items() as $item ) {
602
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
601
+        foreach ($invoice->get_items() as $item) {
602
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
603 603
         }
604 604
 
605
-        wp_send_json_success( compact( 'items', 'alert' ) );
605
+        wp_send_json_success(compact('items', 'alert'));
606 606
     }
607 607
 
608 608
     /**
@@ -610,63 +610,63 @@  discard block
 block discarded – undo
610 610
      */
611 611
     public static function create_invoice_item() {
612 612
         // Verify nonce.
613
-        check_ajax_referer( 'wpinv-nonce' );
613
+        check_ajax_referer('wpinv-nonce');
614 614
 
615 615
         // We need an invoice and item details.
616
-        if ( empty( $_POST['invoice_id'] ) || empty( $_POST['_wpinv_quick'] ) ) {
616
+        if (empty($_POST['invoice_id']) || empty($_POST['_wpinv_quick'])) {
617 617
             exit;
618 618
         }
619 619
 
620
-        $invoice_id = absint( $_POST['invoice_id'] );
620
+        $invoice_id = absint($_POST['invoice_id']);
621 621
 
622
-        if ( empty( $invoice_id ) ) {
622
+        if (empty($invoice_id)) {
623 623
             exit;
624 624
         }
625 625
 
626
-        if ( ! wpinv_current_user_can( 'invoice_create_item', array( 'invoice_id' => $invoice_id ) ) ) {
626
+        if (!wpinv_current_user_can('invoice_create_item', array('invoice_id' => $invoice_id))) {
627 627
             exit;
628 628
         }
629 629
 
630 630
         // Fetch the invoice.
631
-        $invoice = new WPInv_Invoice( $invoice_id );
631
+        $invoice = new WPInv_Invoice($invoice_id);
632 632
 
633 633
         // Ensure it exists and its not been paid for.
634
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
634
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
635 635
             exit;
636 636
         }
637 637
 
638 638
         // Format the data.
639
-        $data = wp_kses_post_deep( wp_unslash( $_POST['_wpinv_quick'] ) );
639
+        $data = wp_kses_post_deep(wp_unslash($_POST['_wpinv_quick']));
640 640
 
641 641
         $item = new WPInv_Item();
642
-        $item->set_price( getpaid_standardize_amount( $data['price'] ) );
643
-        $item->set_name( sanitize_text_field( $data['name'] ) );
644
-        $item->set_description( wp_kses_post( $data['description'] ) );
645
-        $item->set_type( sanitize_text_field( $data['type'] ) );
646
-        $item->set_vat_rule( sanitize_text_field( $data['vat_rule'] ) );
647
-        $item->set_vat_class( sanitize_text_field( $data['vat_class'] ) );
648
-        $item->set_status( 'publish' );
642
+        $item->set_price(getpaid_standardize_amount($data['price']));
643
+        $item->set_name(sanitize_text_field($data['name']));
644
+        $item->set_description(wp_kses_post($data['description']));
645
+        $item->set_type(sanitize_text_field($data['type']));
646
+        $item->set_vat_rule(sanitize_text_field($data['vat_rule']));
647
+        $item->set_vat_class(sanitize_text_field($data['vat_class']));
648
+        $item->set_status('publish');
649 649
         $item->save();
650 650
 
651
-        if ( ! $item->exists() ) {
652
-            $alert = __( 'Could not create invoice item. Please try again.', 'invoicing' );
653
-            wp_send_json_success( compact( 'alert' ) );
651
+        if (!$item->exists()) {
652
+            $alert = __('Could not create invoice item. Please try again.', 'invoicing');
653
+            wp_send_json_success(compact('alert'));
654 654
         }
655 655
 
656
-        if ( ! empty( $data['one-time'] ) ) {
657
-            update_post_meta( $item->get_id(), '_wpinv_one_time', 'yes' );
656
+        if (!empty($data['one-time'])) {
657
+            update_post_meta($item->get_id(), '_wpinv_one_time', 'yes');
658 658
         }
659 659
 
660
-        $item = new GetPaid_Form_Item( $item->get_id() );
661
-        $item->set_quantity( floatval( $data['qty'] ) );
660
+        $item = new GetPaid_Form_Item($item->get_id());
661
+        $item->set_quantity(floatval($data['qty']));
662 662
 
663 663
         // Add it to the invoice.
664
-        $error = $invoice->add_item( $item );
664
+        $error = $invoice->add_item($item);
665 665
         $alert = false;
666 666
 
667
-        if ( is_wp_error( $error ) ) {
667
+        if (is_wp_error($error)) {
668 668
             $alert = $error->get_error_message();
669
-            wp_send_json_success( compact( 'alert' ) );
669
+            wp_send_json_success(compact('alert'));
670 670
          }
671 671
 
672 672
         // Update totals.
@@ -679,9 +679,9 @@  discard block
 block discarded – undo
679 679
         $invoice->recalculate_total();
680 680
         $invoice->save();
681 681
         ob_start();
682
-        GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice );
682
+        GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice);
683 683
         $row = ob_get_clean();
684
-        wp_send_json_success( compact( 'row' ) );
684
+        wp_send_json_success(compact('row'));
685 685
     }
686 686
 
687 687
     /**
@@ -689,37 +689,37 @@  discard block
 block discarded – undo
689 689
      */
690 690
     public static function remove_invoice_item() {
691 691
         // Verify nonce.
692
-        check_ajax_referer( 'wpinv-nonce' );
692
+        check_ajax_referer('wpinv-nonce');
693 693
 
694 694
         // We need an invoice and item.
695
-        $invoice_id = ! empty( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0;
696
-        $item_id = ! empty( $_POST['item_id'] ) ? absint( $_POST['item_id'] ) : 0;
695
+        $invoice_id = !empty($_POST['post_id']) ? absint($_POST['post_id']) : 0;
696
+        $item_id = !empty($_POST['item_id']) ? absint($_POST['item_id']) : 0;
697 697
 
698
-        if ( empty( $invoice_id ) || empty( $item_id ) ) {
698
+        if (empty($invoice_id) || empty($item_id)) {
699 699
             exit;
700 700
         }
701 701
 
702 702
         // Can the user manage the plugin?
703
-        if ( ! wpinv_current_user_can( 'invoice_remove_item', array( 'invoice_id' => $invoice_id, 'item_id' => $item_id ) ) ) {
703
+        if (!wpinv_current_user_can('invoice_remove_item', array('invoice_id' => $invoice_id, 'item_id' => $item_id))) {
704 704
             exit;
705 705
         }
706 706
 
707 707
         // Fetch the invoice.
708
-        $invoice = new WPInv_Invoice( $invoice_id );
708
+        $invoice = new WPInv_Invoice($invoice_id);
709 709
 
710 710
         // Ensure it exists and its not been paid for.
711
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
711
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
712 712
             exit;
713 713
         }
714 714
 
715 715
         // Abort if the invoice does not have the specified item.
716
-        $item = $invoice->get_item( $item_id );
716
+        $item = $invoice->get_item($item_id);
717 717
 
718
-        if ( empty( $item ) ) {
718
+        if (empty($item)) {
719 719
             exit;
720 720
         }
721 721
 
722
-        $invoice->remove_item( $item_id );
722
+        $invoice->remove_item($item_id);
723 723
 
724 724
         // Update totals.
725 725
         $invoice->recalculate_total();
@@ -730,11 +730,11 @@  discard block
 block discarded – undo
730 730
         // Return an array of invoice items.
731 731
         $items = array();
732 732
 
733
-        foreach ( $invoice->get_items() as $item ) {
734
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
733
+        foreach ($invoice->get_items() as $item) {
734
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
735 735
         }
736 736
 
737
-        wp_send_json_success( compact( 'items' ) );
737
+        wp_send_json_success(compact('items'));
738 738
     }
739 739
 
740 740
     /**
@@ -742,69 +742,69 @@  discard block
 block discarded – undo
742 742
      */
743 743
     public static function recalculate_full_prices() {
744 744
         // Verify nonce.
745
-        check_ajax_referer( 'wpinv-nonce' );
745
+        check_ajax_referer('wpinv-nonce');
746 746
 
747
-        $invoice_id = ! empty( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0;
747
+        $invoice_id = !empty($_POST['post_id']) ? absint($_POST['post_id']) : 0;
748 748
 
749
-        if ( empty( $invoice_id ) ) {
749
+        if (empty($invoice_id)) {
750 750
             exit;
751 751
         }
752 752
 
753
-        if ( ! wpinv_current_user_can( 'invoice_recalculate_full_prices', array( 'invoice_id' => $invoice_id ) ) ) {
753
+        if (!wpinv_current_user_can('invoice_recalculate_full_prices', array('invoice_id' => $invoice_id))) {
754 754
             exit;
755 755
         }
756 756
 
757 757
         // Fetch the invoice.
758
-        $invoice = new WPInv_Invoice( $invoice_id );
758
+        $invoice = new WPInv_Invoice($invoice_id);
759 759
         $alert   = false;
760 760
 
761 761
         // Ensure it exists and its not been paid for.
762
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
762
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
763 763
             exit;
764 764
         }
765 765
 
766
-        $invoice->set_items( array() );
766
+        $invoice->set_items(array());
767 767
 
768
-        if ( ! empty( $_POST['getpaid_items'] ) ) {
768
+        if (!empty($_POST['getpaid_items'])) {
769 769
 
770
-            foreach ( wp_kses_post_deep( wp_unslash( $_POST['getpaid_items'] ) ) as $item_id => $args ) {
771
-                $item = new GetPaid_Form_Item( $item_id );
770
+            foreach (wp_kses_post_deep(wp_unslash($_POST['getpaid_items'])) as $item_id => $args) {
771
+                $item = new GetPaid_Form_Item($item_id);
772 772
 
773
-                if ( $item->exists() ) {
774
-                    $item->set_price( getpaid_standardize_amount( $args['price'] ) );
775
-                    $item->set_quantity( floatval( $args['quantity'] ) );
776
-                    $item->set_name( sanitize_text_field( $args['name'] ) );
777
-                    $item->set_description( wp_kses_post( $args['description'] ) );
778
-                    $invoice->add_item( $item );
773
+                if ($item->exists()) {
774
+                    $item->set_price(getpaid_standardize_amount($args['price']));
775
+                    $item->set_quantity(floatval($args['quantity']));
776
+                    $item->set_name(sanitize_text_field($args['name']));
777
+                    $item->set_description(wp_kses_post($args['description']));
778
+                    $invoice->add_item($item);
779 779
                 }
780 780
             }
781 781
         }
782 782
 
783
-        $invoice->set_disable_taxes( ! empty( $_POST['disable_taxes'] ) );
783
+        $invoice->set_disable_taxes(!empty($_POST['disable_taxes']));
784 784
 
785 785
         // Maybe set the country, state, currency.
786
-        foreach ( array( 'wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code' ) as $key ) {
787
-            if ( isset( $_POST[ $key ] ) ) {
788
-                $_key   = str_replace( 'wpinv_', '', $key );
786
+        foreach (array('wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code') as $key) {
787
+            if (isset($_POST[$key])) {
788
+                $_key   = str_replace('wpinv_', '', $key);
789 789
                 $method = "set_$_key";
790
-                $invoice->$method( sanitize_text_field( $_POST[ $key ] ) );
790
+                $invoice->$method(sanitize_text_field($_POST[$key]));
791 791
             }
792 792
         }
793 793
 
794
-        $discount = new WPInv_Discount( $invoice->get_discount_code() );
795
-        if ( $discount->exists() ) {
796
-            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
794
+        $discount = new WPInv_Discount($invoice->get_discount_code());
795
+        if ($discount->exists()) {
796
+            $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
797 797
         } else {
798
-            $invoice->remove_discount( 'discount_code' );
798
+            $invoice->remove_discount('discount_code');
799 799
         }
800 800
 
801 801
         // Save the invoice.
802 802
         $invoice->recalculate_total();
803 803
         $invoice->save();
804 804
         ob_start();
805
-        GetPaid_Meta_Box_Invoice_Items::output( get_post( $invoice->get_id() ), $invoice );
805
+        GetPaid_Meta_Box_Invoice_Items::output(get_post($invoice->get_id()), $invoice);
806 806
         $table = ob_get_clean();
807
-        wp_send_json_success( compact( 'table' ) );
807
+        wp_send_json_success(compact('table'));
808 808
     }
809 809
 
810 810
     /**
@@ -812,47 +812,47 @@  discard block
 block discarded – undo
812 812
      */
813 813
     public static function admin_add_invoice_item() {
814 814
         // Verify nonce.
815
-        check_ajax_referer( 'wpinv-nonce' );
815
+        check_ajax_referer('wpinv-nonce');
816 816
 
817 817
         // We need an invoice and item.
818
-        $invoice_id = ! empty( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0;
819
-        $item_id = ! empty( $_POST['item_id'] ) ? absint( $_POST['item_id'] ) : 0;
818
+        $invoice_id = !empty($_POST['post_id']) ? absint($_POST['post_id']) : 0;
819
+        $item_id = !empty($_POST['item_id']) ? absint($_POST['item_id']) : 0;
820 820
 
821
-        if ( empty( $invoice_id ) || empty( $item_id ) ) {
821
+        if (empty($invoice_id) || empty($item_id)) {
822 822
             exit;
823 823
         }
824 824
 
825 825
         // Can the user manage the plugin?
826
-        if ( ! wpinv_current_user_can( 'invoice_add_item', array( 'invoice_id' => $invoice_id, 'item_id' => $item_id ) ) ) {
826
+        if (!wpinv_current_user_can('invoice_add_item', array('invoice_id' => $invoice_id, 'item_id' => $item_id))) {
827 827
             exit;
828 828
         }
829 829
 
830 830
         // Fetch the invoice.
831
-        $invoice = new WPInv_Invoice( $invoice_id );
831
+        $invoice = new WPInv_Invoice($invoice_id);
832 832
         $alert   = false;
833 833
 
834 834
         // Ensure it exists and its not been paid for.
835
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
835
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
836 836
             exit;
837 837
         }
838 838
 
839 839
         // Add the item.
840
-        $item  = new GetPaid_Form_Item( $item_id );
840
+        $item  = new GetPaid_Form_Item($item_id);
841 841
 
842
-        $error = $invoice->add_item( $item );
842
+        $error = $invoice->add_item($item);
843 843
 
844
-        if ( is_wp_error( $error ) ) {
844
+        if (is_wp_error($error)) {
845 845
             $alert = $error->get_error_message();
846
-            wp_send_json_success( compact( 'alert' ) );
846
+            wp_send_json_success(compact('alert'));
847 847
         }
848 848
 
849 849
         // Save the invoice.
850 850
         $invoice->recalculate_total();
851 851
         $invoice->save();
852 852
         ob_start();
853
-        GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice );
853
+        GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice);
854 854
         $row = ob_get_clean();
855
-        wp_send_json_success( compact( 'row' ) );
855
+        wp_send_json_success(compact('row'));
856 856
     }
857 857
 
858 858
     /**
@@ -860,42 +860,42 @@  discard block
 block discarded – undo
860 860
      */
861 861
     public static function add_invoice_items() {
862 862
         // Verify nonce.
863
-        check_ajax_referer( 'wpinv-nonce' );
863
+        check_ajax_referer('wpinv-nonce');
864 864
 
865
-        $invoice_id = ! empty( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0;
865
+        $invoice_id = !empty($_POST['post_id']) ? absint($_POST['post_id']) : 0;
866 866
 
867 867
         // We need an invoice and items.
868
-        if ( empty( $invoice_id ) || empty( $_POST['items'] ) ) {
868
+        if (empty($invoice_id) || empty($_POST['items'])) {
869 869
             exit;
870 870
         }
871 871
 
872 872
         // Can the user manage the plugin?
873
-        if ( ! wpinv_current_user_can( 'invoice_add_items', array( 'invoice_id' => $invoice_id ) ) ) {
873
+        if (!wpinv_current_user_can('invoice_add_items', array('invoice_id' => $invoice_id))) {
874 874
             exit;
875 875
         }
876 876
 
877 877
         // Fetch the invoice.
878
-        $invoice = new WPInv_Invoice( $invoice_id );
878
+        $invoice = new WPInv_Invoice($invoice_id);
879 879
         $alert   = false;
880 880
 
881 881
         // Ensure it exists and its not been paid for.
882
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
882
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
883 883
             exit;
884 884
         }
885 885
 
886 886
         // Add the items.
887
-        foreach ( wp_kses_post_deep( wp_unslash( $_POST['items'] ) ) as $data ) {
887
+        foreach (wp_kses_post_deep(wp_unslash($_POST['items'])) as $data) {
888 888
 
889
-            $item = new GetPaid_Form_Item( (int) $data['id'] );
889
+            $item = new GetPaid_Form_Item((int) $data['id']);
890 890
 
891
-            if ( is_numeric( $data['qty'] ) && (float) $data['qty'] > 0 ) {
892
-                $item->set_quantity( floatval( $data['qty'] ) );
891
+            if (is_numeric($data['qty']) && (float) $data['qty'] > 0) {
892
+                $item->set_quantity(floatval($data['qty']));
893 893
             }
894 894
 
895
-            if ( $item->get_id() > 0 ) {
896
-                $error = $invoice->add_item( $item );
895
+            if ($item->get_id() > 0) {
896
+                $error = $invoice->add_item($item);
897 897
 
898
-                if ( is_wp_error( $error ) ) {
898
+                if (is_wp_error($error)) {
899 899
                     $alert = $error->get_error_message();
900 900
                 }
901 901
 }
@@ -908,11 +908,11 @@  discard block
 block discarded – undo
908 908
         // Return an array of invoice items.
909 909
         $items = array();
910 910
 
911
-        foreach ( $invoice->get_items() as $item ) {
912
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
911
+        foreach ($invoice->get_items() as $item) {
912
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
913 913
         }
914 914
 
915
-        wp_send_json_success( compact( 'items', 'alert' ) );
915
+        wp_send_json_success(compact('items', 'alert'));
916 916
     }
917 917
 
918 918
     /**
@@ -920,16 +920,16 @@  discard block
 block discarded – undo
920 920
      */
921 921
     public static function get_invoicing_items() {
922 922
         // Verify nonce.
923
-        check_ajax_referer( 'wpinv-nonce' );
923
+        check_ajax_referer('wpinv-nonce');
924 924
 
925 925
         // Can the user manage the plugin?
926
-        if ( ! wpinv_current_user_can( 'get_invoicing_items' ) ) {
926
+        if (!wpinv_current_user_can('get_invoicing_items')) {
927 927
             exit;
928 928
         }
929 929
 
930 930
         // We need a search term.
931
-        if ( empty( $_GET['search'] ) ) {
932
-            wp_send_json_success( array() );
931
+        if (empty($_GET['search'])) {
932
+            wp_send_json_success(array());
933 933
         }
934 934
 
935 935
         // Retrieve items.
@@ -938,8 +938,8 @@  discard block
 block discarded – undo
938 938
             'orderby'        => 'title',
939 939
             'order'          => 'ASC',
940 940
             'posts_per_page' => -1,
941
-            'post_status'    => array( 'publish' ),
942
-            's'              => sanitize_text_field( urldecode( $_GET['search'] ) ),
941
+            'post_status'    => array('publish'),
942
+            's'              => sanitize_text_field(urldecode($_GET['search'])),
943 943
             'meta_query'     => array(
944 944
                 array(
945 945
                     'key'     => '_wpinv_type',
@@ -953,25 +953,25 @@  discard block
 block discarded – undo
953 953
             ),
954 954
         );
955 955
 
956
-        if ( ! empty( $_GET['ignore'] ) ) {
957
-            $item_args['exclude'] = wp_parse_id_list( sanitize_text_field( $_GET['ignore'] ) );
956
+        if (!empty($_GET['ignore'])) {
957
+            $item_args['exclude'] = wp_parse_id_list(sanitize_text_field($_GET['ignore']));
958 958
         }
959 959
 
960
-        $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) );
960
+        $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args));
961 961
         $data  = array();
962 962
 
963
-        $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( (int) $_GET['post_id'] ) );
963
+        $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type((int) $_GET['post_id']));
964 964
 
965
-        foreach ( $items as $item ) {
966
-            $item      = new GetPaid_Form_Item( $item );
965
+        foreach ($items as $item) {
966
+            $item = new GetPaid_Form_Item($item);
967 967
             $data[] = array(
968 968
                 'id'        => (int) $item->get_id(),
969
-                'text'      => strip_tags( $item->get_name() ),
970
-                'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '',
969
+                'text'      => strip_tags($item->get_name()),
970
+                'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '',
971 971
             );
972 972
         }
973 973
 
974
-        wp_send_json_success( $data );
974
+        wp_send_json_success($data);
975 975
 
976 976
     }
977 977
 
@@ -980,40 +980,40 @@  discard block
 block discarded – undo
980 980
      */
981 981
     public static function get_customers() {
982 982
         // Verify nonce.
983
-        check_ajax_referer( 'wpinv-nonce' );
983
+        check_ajax_referer('wpinv-nonce');
984 984
 
985
-        $invoice_id = ! empty( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
985
+        $invoice_id = !empty($_REQUEST['post_id']) ? (int) $_REQUEST['post_id'] : 0;
986 986
 
987 987
         // Can the user manage the plugin?
988
-        if ( ! wpinv_current_user_can( 'invoice_get_customers', array( 'invoice_id' => $invoice_id ) ) ) {
988
+        if (!wpinv_current_user_can('invoice_get_customers', array('invoice_id' => $invoice_id))) {
989 989
             die( -1 );
990 990
         }
991 991
 
992 992
         // We need a search term.
993
-        if ( empty( $_GET['search'] ) ) {
994
-            wp_send_json_success( array() );
993
+        if (empty($_GET['search'])) {
994
+            wp_send_json_success(array());
995 995
         }
996 996
 
997 997
         // Retrieve customers.
998 998
 
999 999
         $customer_args = array(
1000
-            'fields'         => array( 'ID', 'user_email', 'display_name' ),
1000
+            'fields'         => array('ID', 'user_email', 'display_name'),
1001 1001
             'orderby'        => 'display_name',
1002
-            'search'         => '*' . sanitize_text_field( $_GET['search'] ) . '*',
1003
-            'search_columns' => array( 'user_login', 'user_email', 'display_name' ),
1002
+            'search'         => '*' . sanitize_text_field($_GET['search']) . '*',
1003
+            'search_columns' => array('user_login', 'user_email', 'display_name'),
1004 1004
         );
1005 1005
 
1006
-        $customers = get_users( apply_filters( 'getpaid_ajax_invoice_customers_query_args', $customer_args ) );
1006
+        $customers = get_users(apply_filters('getpaid_ajax_invoice_customers_query_args', $customer_args));
1007 1007
         $data      = array();
1008 1008
 
1009
-        foreach ( $customers as $customer ) {
1009
+        foreach ($customers as $customer) {
1010 1010
             $data[] = array(
1011 1011
                 'id'   => (int) $customer->ID,
1012
-                'text' => strip_tags( sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ) ),
1012
+                'text' => strip_tags(sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email)),
1013 1013
             );
1014 1014
         }
1015 1015
 
1016
-        wp_send_json_success( $data );
1016
+        wp_send_json_success($data);
1017 1017
 
1018 1018
     }
1019 1019
 
@@ -1023,25 +1023,25 @@  discard block
 block discarded – undo
1023 1023
     public static function get_aui_states_field() {
1024 1024
 
1025 1025
         // We need a country.
1026
-        if ( empty( $_GET['country'] ) ) {
1026
+        if (empty($_GET['country'])) {
1027 1027
             exit;
1028 1028
         }
1029 1029
 
1030
-        $states = wpinv_get_country_states( sanitize_text_field( $_GET['country'] ) );
1031
-        $state  = isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : wpinv_get_default_state();
1032
-        $name   = isset( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : 'wpinv_state';
1033
-        $class  = isset( $_GET['class'] ) ? sanitize_text_field( $_GET['class'] ) : 'form-control-sm';
1030
+        $states = wpinv_get_country_states(sanitize_text_field($_GET['country']));
1031
+        $state  = isset($_GET['state']) ? sanitize_text_field($_GET['state']) : wpinv_get_default_state();
1032
+        $name   = isset($_GET['name']) ? sanitize_text_field($_GET['name']) : 'wpinv_state';
1033
+        $class  = isset($_GET['class']) ? sanitize_text_field($_GET['class']) : 'form-control-sm';
1034 1034
 
1035
-        if ( empty( $states ) ) {
1035
+        if (empty($states)) {
1036 1036
 
1037 1037
             $html = aui()->input(
1038 1038
                 array(
1039 1039
                     'type'        => 'text',
1040 1040
                     'id'          => 'wpinv_state',
1041 1041
                     'name'        => $name,
1042
-                    'label'       => __( 'State', 'invoicing' ),
1042
+                    'label'       => __('State', 'invoicing'),
1043 1043
                     'label_type'  => 'vertical',
1044
-                    'placeholder' => __( 'State', 'invoicing' ),
1044
+                    'placeholder' => __('State', 'invoicing'),
1045 1045
                     'class'       => $class,
1046 1046
                     'value'       => $state,
1047 1047
                 )
@@ -1053,9 +1053,9 @@  discard block
 block discarded – undo
1053 1053
                 array(
1054 1054
                     'id'               => 'wpinv_state',
1055 1055
                     'name'             => $name,
1056
-                    'label'            => __( 'State', 'invoicing' ),
1056
+                    'label'            => __('State', 'invoicing'),
1057 1057
                     'label_type'       => 'vertical',
1058
-                    'placeholder'      => __( 'Select a state', 'invoicing' ),
1058
+                    'placeholder'      => __('Select a state', 'invoicing'),
1059 1059
                     'class'            => $class,
1060 1060
                     'value'            => $state,
1061 1061
                     'options'          => $states,
@@ -1069,7 +1069,7 @@  discard block
 block discarded – undo
1069 1069
         wp_send_json_success(
1070 1070
             array(
1071 1071
                 'html'   => $html,
1072
-                'select' => ! empty( $states ),
1072
+                'select' => !empty($states),
1073 1073
             )
1074 1074
         );
1075 1075
 
@@ -1083,8 +1083,8 @@  discard block
 block discarded – undo
1083 1083
     public static function payment_form_refresh_prices() {
1084 1084
 
1085 1085
         // ... form fields...
1086
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
1087
-            esc_html_e( 'Error: Reload the page and try again.', 'invoicing' );
1086
+        if (empty($_POST['getpaid_payment_form_submission'])) {
1087
+            esc_html_e('Error: Reload the page and try again.', 'invoicing');
1088 1088
             exit;
1089 1089
         }
1090 1090
 
@@ -1092,7 +1092,7 @@  discard block
 block discarded – undo
1092 1092
         $submission = new GetPaid_Payment_Form_Submission();
1093 1093
 
1094 1094
         // Do we have an error?
1095
-        if ( ! empty( $submission->last_error ) ) {
1095
+        if (!empty($submission->last_error)) {
1096 1096
             wp_send_json_error(
1097 1097
                 array(
1098 1098
                     'code'  => $submission->last_error_code,
@@ -1102,12 +1102,12 @@  discard block
 block discarded – undo
1102 1102
         }
1103 1103
 
1104 1104
         // Prepare the response.
1105
-        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission );
1105
+        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission);
1106 1106
 
1107 1107
         // Filter the response.
1108
-        $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission );
1108
+        $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission);
1109 1109
 
1110
-        wp_send_json_success( $response );
1110
+        wp_send_json_success($response);
1111 1111
     }
1112 1112
 
1113 1113
     /**
@@ -1119,63 +1119,63 @@  discard block
 block discarded – undo
1119 1119
 	public static function file_upload() {
1120 1120
 
1121 1121
         // Check nonce.
1122
-        check_ajax_referer( 'getpaid_form_nonce' );
1122
+        check_ajax_referer('getpaid_form_nonce');
1123 1123
 
1124
-        if ( empty( $_POST['form_id'] ) || empty( $_POST['field_name'] ) || empty( $_FILES['file'] ) ) {
1125
-            wp_die( esc_html_e( 'Bad Request', 'invoicing' ), 400 );
1124
+        if (empty($_POST['form_id']) || empty($_POST['field_name']) || empty($_FILES['file'])) {
1125
+            wp_die(esc_html_e('Bad Request', 'invoicing'), 400);
1126 1126
         }
1127 1127
 
1128 1128
         // Fetch form.
1129
-        $form = new GetPaid_Payment_Form( intval( $_POST['form_id'] ) );
1129
+        $form = new GetPaid_Payment_Form(intval($_POST['form_id']));
1130 1130
 
1131
-        if ( ! $form->is_active() ) {
1132
-            wp_send_json_error( __( 'Payment form not active', 'invoicing' ) );
1131
+        if (!$form->is_active()) {
1132
+            wp_send_json_error(__('Payment form not active', 'invoicing'));
1133 1133
         }
1134 1134
 
1135 1135
         // Fetch appropriate field.
1136
-        $upload_field = current( wp_list_filter( $form->get_elements(), array( 'id' => sanitize_text_field( $_POST['field_name'] ) ) ) );
1137
-        if ( empty( $upload_field ) ) {
1138
-            wp_send_json_error( __( 'Invalid upload field.', 'invoicing' ) );
1136
+        $upload_field = current(wp_list_filter($form->get_elements(), array('id' => sanitize_text_field($_POST['field_name']))));
1137
+        if (empty($upload_field)) {
1138
+            wp_send_json_error(__('Invalid upload field.', 'invoicing'));
1139 1139
         }
1140 1140
 
1141 1141
         // Prepare allowed file types.
1142
-        $file_types = isset( $upload_field['file_types'] ) ? $upload_field['file_types'] : array( 'jpg|jpeg|jpe', 'gif', 'png' );
1142
+        $file_types = isset($upload_field['file_types']) ? $upload_field['file_types'] : array('jpg|jpeg|jpe', 'gif', 'png');
1143 1143
         $all_types  = getpaid_get_allowed_mime_types();
1144 1144
         $mime_types = array();
1145 1145
 
1146
-        foreach ( $file_types as $file_type ) {
1147
-            if ( isset( $all_types[ $file_type ] ) ) {
1148
-                $mime_types[] = $all_types[ $file_type ];
1146
+        foreach ($file_types as $file_type) {
1147
+            if (isset($all_types[$file_type])) {
1148
+                $mime_types[] = $all_types[$file_type];
1149 1149
             }
1150 1150
         }
1151 1151
 
1152
-        if ( ! in_array( $_FILES['file']['type'], $mime_types ) ) {
1153
-            wp_send_json_error( __( 'Unsupported file type.', 'invoicing' ) );
1152
+        if (!in_array($_FILES['file']['type'], $mime_types)) {
1153
+            wp_send_json_error(__('Unsupported file type.', 'invoicing'));
1154 1154
         }
1155 1155
 
1156 1156
         // Upload file.
1157
-        $file_name = explode( '.', strtolower( $_FILES['file']['name'] ) );
1158
-        $file_name = uniqid( 'getpaid-' ) . '.' . array_pop( $file_name );
1157
+        $file_name = explode('.', strtolower($_FILES['file']['name']));
1158
+        $file_name = uniqid('getpaid-') . '.' . array_pop($file_name);
1159 1159
 
1160 1160
         $uploaded = wp_upload_bits(
1161 1161
             $file_name,
1162 1162
             null,
1163
-            file_get_contents( $_FILES['file']['tmp_name'] )
1163
+            file_get_contents($_FILES['file']['tmp_name'])
1164 1164
         );
1165 1165
 
1166
-        if ( ! empty( $uploaded['error'] ) ) {
1167
-            wp_send_json_error( $uploaded['error'] );
1166
+        if (!empty($uploaded['error'])) {
1167
+            wp_send_json_error($uploaded['error']);
1168 1168
         }
1169 1169
 
1170 1170
         // Retrieve response.
1171 1171
         $response = sprintf(
1172 1172
             '<input type="hidden" name="%s[%s]" value="%s" />',
1173
-            esc_attr( sanitize_text_field( $_POST['field_name'] ) ),
1174
-            esc_url( $uploaded['url'] ),
1175
-            esc_attr( sanitize_text_field( strtolower( $_FILES['file']['name'] ) ) )
1173
+            esc_attr(sanitize_text_field($_POST['field_name'])),
1174
+            esc_url($uploaded['url']),
1175
+            esc_attr(sanitize_text_field(strtolower($_FILES['file']['name'])))
1176 1176
         );
1177 1177
 
1178
-        wp_send_json_success( $response );
1178
+        wp_send_json_success($response);
1179 1179
 
1180 1180
 	}
1181 1181
 
Please login to merge, or discard this patch.
includes/invoice-functions.php 1 patch
Spacing   +375 added lines, -375 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Retrieves the current invoice.
@@ -14,15 +14,15 @@  discard block
 block discarded – undo
14 14
 function getpaid_get_current_invoice_id() {
15 15
 
16 16
     // Ensure that we have an invoice key.
17
-    if ( empty( $_GET['invoice_key'] ) ) {
17
+    if (empty($_GET['invoice_key'])) {
18 18
         return 0;
19 19
     }
20 20
 
21 21
     // Retrieve an invoice using the key.
22
-    $invoice = new WPInv_Invoice( sanitize_text_field( $_GET['invoice_key'] ) );
22
+    $invoice = new WPInv_Invoice(sanitize_text_field($_GET['invoice_key']));
23 23
 
24 24
     // Compare the invoice key and the parsed key.
25
-    if ( $invoice->get_id() != 0 && $invoice->get_key() == sanitize_text_field( $_GET['invoice_key'] ) ) {
25
+    if ($invoice->get_id() != 0 && $invoice->get_key() == sanitize_text_field($_GET['invoice_key'])) {
26 26
         return $invoice->get_id();
27 27
     }
28 28
 
@@ -32,42 +32,42 @@  discard block
 block discarded – undo
32 32
 /**
33 33
  * Checks if the current user cna view an invoice.
34 34
  */
35
-function wpinv_user_can_view_invoice( $invoice ) {
36
-    $invoice = new WPInv_Invoice( $invoice );
35
+function wpinv_user_can_view_invoice($invoice) {
36
+    $invoice = new WPInv_Invoice($invoice);
37 37
 
38 38
     // Abort if the invoice does not exist.
39
-    if ( 0 == $invoice->get_id() ) {
39
+    if (0 == $invoice->get_id()) {
40 40
         return false;
41 41
     }
42 42
 
43 43
     // Don't allow trash, draft status
44
-    if ( $invoice->is_draft() ) {
44
+    if ($invoice->is_draft()) {
45 45
         return false;
46 46
     }
47 47
 
48 48
     // If users are not required to login to check out, compare the invoice keys.
49
-    if ( ! wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && sanitize_text_field( $_GET['invoice_key'] ) == $invoice->get_key() ) {
49
+    if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && sanitize_text_field($_GET['invoice_key']) == $invoice->get_key()) {
50 50
         return true;
51 51
     }
52 52
 
53 53
     // Always enable for admins..
54
-    if ( wpinv_current_user_can( 'view_invoice', array( 'invoice' => $invoice ) ) || current_user_can( 'view_invoices', $invoice->get_id() ) ) { // Admin user
54
+    if (wpinv_current_user_can('view_invoice', array('invoice' => $invoice)) || current_user_can('view_invoices', $invoice->get_id())) { // Admin user
55 55
         return true;
56 56
     }
57 57
 
58 58
     // Else, ensure that this is their invoice.
59
-    if ( is_user_logged_in() && $invoice->get_user_id() == get_current_user_id() ) {
59
+    if (is_user_logged_in() && $invoice->get_user_id() == get_current_user_id()) {
60 60
         return true;
61 61
     }
62 62
 
63
-    return apply_filters( 'wpinv_current_user_can_view_invoice', false, $invoice );
63
+    return apply_filters('wpinv_current_user_can_view_invoice', false, $invoice);
64 64
 }
65 65
 
66 66
 /**
67 67
  * Checks if the current user cna view an invoice receipt.
68 68
  */
69
-function wpinv_can_view_receipt( $invoice ) {
70
-	return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice );
69
+function wpinv_can_view_receipt($invoice) {
70
+	return (bool) apply_filters('wpinv_can_view_receipt', wpinv_user_can_view_invoice($invoice), $invoice);
71 71
 }
72 72
 
73 73
 /**
@@ -77,16 +77,16 @@  discard block
 block discarded – undo
77 77
  */
78 78
 function getpaid_get_invoice_post_types() {
79 79
     $post_types = array(
80
-        'wpi_quote'   => __( 'Quote', 'invoicing' ),
81
-        'wpi_invoice' => __( 'Invoice', 'invoicing' ),
80
+        'wpi_quote'   => __('Quote', 'invoicing'),
81
+        'wpi_invoice' => __('Invoice', 'invoicing'),
82 82
     );
83 83
 
84 84
     // Ensure the quotes addon is installed.
85
-    if ( ! defined( 'WPINV_QUOTES_VERSION' ) ) {
86
-        unset( $post_types['wpi_quote'] );
85
+    if (!defined('WPINV_QUOTES_VERSION')) {
86
+        unset($post_types['wpi_quote']);
87 87
     }
88 88
 
89
-    return apply_filters( 'getpaid_invoice_post_types', $post_types );
89
+    return apply_filters('getpaid_invoice_post_types', $post_types);
90 90
 }
91 91
 
92 92
 /**
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
  *
96 96
  * @param string $post_type The post type to check for.
97 97
  */
98
-function getpaid_is_invoice_post_type( $post_type ) {
99
-    return is_scalar( $post_type ) && ! empty( $post_type ) && array_key_exists( $post_type, getpaid_get_invoice_post_types() );
98
+function getpaid_is_invoice_post_type($post_type) {
99
+    return is_scalar($post_type) && !empty($post_type) && array_key_exists($post_type, getpaid_get_invoice_post_types());
100 100
 }
101 101
 
102 102
 /**
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
107 107
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
108 108
  */
109
-function wpinv_create_invoice( $data = array(), $deprecated = null, $wp_error = false ) {
109
+function wpinv_create_invoice($data = array(), $deprecated = null, $wp_error = false) {
110 110
     $data['invoice_id'] = 0;
111
-    return wpinv_insert_invoice( $data, $wp_error );
111
+    return wpinv_insert_invoice($data, $wp_error);
112 112
 }
113 113
 
114 114
 /**
@@ -118,35 +118,35 @@  discard block
 block discarded – undo
118 118
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
119 119
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
120 120
  */
121
-function wpinv_update_invoice( $data = array(), $wp_error = false ) {
121
+function wpinv_update_invoice($data = array(), $wp_error = false) {
122 122
 
123 123
     // Backwards compatibility.
124
-    if ( ! empty( $data['ID'] ) ) {
124
+    if (!empty($data['ID'])) {
125 125
         $data['invoice_id'] = $data['ID'];
126 126
     }
127 127
 
128 128
     // Do we have an invoice id?
129
-    if ( empty( $data['invoice_id'] ) ) {
130
-        return $wp_error ? new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) ) : 0;
129
+    if (empty($data['invoice_id'])) {
130
+        return $wp_error ? new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing')) : 0;
131 131
     }
132 132
 
133 133
     // Retrieve the invoice.
134
-    $invoice = wpinv_get_invoice( $data['invoice_id'] );
134
+    $invoice = wpinv_get_invoice($data['invoice_id']);
135 135
 
136 136
     // And abort if it does not exist.
137
-    if ( empty( $invoice ) ) {
138
-        return $wp_error ? new WP_Error( 'missing_invoice', __( 'Invoice not found.', 'invoicing' ) ) : 0;
137
+    if (empty($invoice)) {
138
+        return $wp_error ? new WP_Error('missing_invoice', __('Invoice not found.', 'invoicing')) : 0;
139 139
     }
140 140
 
141 141
     // Do not update totals for paid / refunded invoices.
142
-    if ( $invoice->is_paid() || $invoice->is_refunded() ) {
142
+    if ($invoice->is_paid() || $invoice->is_refunded()) {
143 143
 
144
-        if ( ! empty( $data['items'] ) || ! empty( $data['cart_details'] ) ) {
145
-            return $wp_error ? new WP_Error( 'paid_invoice', __( 'You can not update cart items for invoices that have already been paid for.', 'invoicing' ) ) : 0;
144
+        if (!empty($data['items']) || !empty($data['cart_details'])) {
145
+            return $wp_error ? new WP_Error('paid_invoice', __('You can not update cart items for invoices that have already been paid for.', 'invoicing')) : 0;
146 146
         }
147 147
 }
148 148
 
149
-    return wpinv_insert_invoice( $data, $wp_error );
149
+    return wpinv_insert_invoice($data, $wp_error);
150 150
 
151 151
 }
152 152
 
@@ -157,62 +157,62 @@  discard block
 block discarded – undo
157 157
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
158 158
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
159 159
  */
160
-function wpinv_insert_invoice( $data = array(), $wp_error = false ) {
160
+function wpinv_insert_invoice($data = array(), $wp_error = false) {
161 161
 
162 162
     // Ensure that we have invoice data.
163
-    if ( empty( $data ) ) {
163
+    if (empty($data)) {
164 164
         return false;
165 165
     }
166 166
 
167 167
     // The invoice id will be provided when updating an invoice.
168
-    $data['invoice_id'] = ! empty( $data['invoice_id'] ) ? (int) $data['invoice_id'] : false;
168
+    $data['invoice_id'] = !empty($data['invoice_id']) ? (int) $data['invoice_id'] : false;
169 169
 
170 170
     // Retrieve the invoice.
171
-    $invoice = new WPInv_Invoice( $data['invoice_id'] );
171
+    $invoice = new WPInv_Invoice($data['invoice_id']);
172 172
 
173 173
     // Do we have an error?
174
-    if ( ! empty( $invoice->last_error ) ) {
175
-        return $wp_error ? new WP_Error( 'invalid_invoice_id', $invoice->last_error ) : 0;
174
+    if (!empty($invoice->last_error)) {
175
+        return $wp_error ? new WP_Error('invalid_invoice_id', $invoice->last_error) : 0;
176 176
     }
177 177
 
178 178
     // Backwards compatibility (billing address).
179
-    if ( ! empty( $data['user_info'] ) ) {
179
+    if (!empty($data['user_info'])) {
180 180
 
181
-        foreach ( $data['user_info'] as $key => $value ) {
181
+        foreach ($data['user_info'] as $key => $value) {
182 182
 
183
-            if ( $key == 'discounts' ) {
183
+            if ($key == 'discounts') {
184 184
                 $value = (array) $value;
185
-                $data['discount_code'] = empty( $value ) ? null : $value[0];
185
+                $data['discount_code'] = empty($value) ? null : $value[0];
186 186
             } else {
187
-                $data[ $key ] = $value;
187
+                $data[$key] = $value;
188 188
             }
189 189
 }
190 190
 }
191 191
 
192 192
     // Backwards compatibility.
193
-    if ( ! empty( $data['payment_details'] ) ) {
193
+    if (!empty($data['payment_details'])) {
194 194
 
195
-        foreach ( $data['payment_details'] as $key => $value ) {
196
-            $data[ $key ] = $value;
195
+        foreach ($data['payment_details'] as $key => $value) {
196
+            $data[$key] = $value;
197 197
         }
198 198
 }
199 199
 
200 200
     // Set up the owner of the invoice.
201
-    $user_id = ! empty( $data['user_id'] ) ? wpinv_clean( $data['user_id'] ) : get_current_user_id();
201
+    $user_id = !empty($data['user_id']) ? wpinv_clean($data['user_id']) : get_current_user_id();
202 202
 
203 203
     // Make sure the user exists.
204
-    if ( ! get_userdata( $user_id ) ) {
205
-        return $wp_error ? new WP_Error( 'wpinv_invalid_user', __( 'There is no user with that ID.', 'invoicing' ) ) : 0;
204
+    if (!get_userdata($user_id)) {
205
+        return $wp_error ? new WP_Error('wpinv_invalid_user', __('There is no user with that ID.', 'invoicing')) : 0;
206 206
     }
207 207
 
208
-    $address = wpinv_get_user_address( $user_id );
208
+    $address = wpinv_get_user_address($user_id);
209 209
 
210
-    foreach ( $address as $key => $value ) {
210
+    foreach ($address as $key => $value) {
211 211
 
212
-        if ( $value == '' ) {
213
-            $address[ $key ] = null;
212
+        if ($value == '') {
213
+            $address[$key] = null;
214 214
         } else {
215
-            $address[ $key ] = wpinv_clean( $value );
215
+            $address[$key] = wpinv_clean($value);
216 216
         }
217 217
 }
218 218
 
@@ -221,105 +221,105 @@  discard block
 block discarded – undo
221 221
         array(
222 222
 
223 223
             // Basic info.
224
-            'template'          => isset( $data['template'] ) ? wpinv_clean( $data['template'] ) : null,
225
-            'email_cc'          => isset( $data['email_cc'] ) ? wpinv_clean( $data['email_cc'] ) : null,
226
-            'date_created'      => isset( $data['created_date'] ) ? wpinv_clean( $data['created_date'] ) : null,
227
-            'due_date'          => isset( $data['due_date'] ) ? wpinv_clean( $data['due_date'] ) : null,
228
-            'date_completed'    => isset( $data['date_completed'] ) ? wpinv_clean( $data['date_completed'] ) : null,
229
-            'number'            => isset( $data['number'] ) ? wpinv_clean( $data['number'] ) : null,
230
-            'key'               => isset( $data['key'] ) ? wpinv_clean( $data['key'] ) : null,
231
-            'status'            => isset( $data['status'] ) ? wpinv_clean( $data['status'] ) : null,
232
-            'post_type'         => isset( $data['post_type'] ) ? wpinv_clean( $data['post_type'] ) : null,
233
-            'user_ip'           => isset( $data['ip'] ) ? wpinv_clean( $data['ip'] ) : wpinv_get_ip(),
234
-            'parent_id'         => isset( $data['parent'] ) ? intval( $data['parent'] ) : null,
235
-            'mode'              => isset( $data['mode'] ) ? wpinv_clean( $data['mode'] ) : null,
236
-            'description'       => isset( $data['description'] ) ? wp_kses_post( $data['description'] ) : null,
224
+            'template'          => isset($data['template']) ? wpinv_clean($data['template']) : null,
225
+            'email_cc'          => isset($data['email_cc']) ? wpinv_clean($data['email_cc']) : null,
226
+            'date_created'      => isset($data['created_date']) ? wpinv_clean($data['created_date']) : null,
227
+            'due_date'          => isset($data['due_date']) ? wpinv_clean($data['due_date']) : null,
228
+            'date_completed'    => isset($data['date_completed']) ? wpinv_clean($data['date_completed']) : null,
229
+            'number'            => isset($data['number']) ? wpinv_clean($data['number']) : null,
230
+            'key'               => isset($data['key']) ? wpinv_clean($data['key']) : null,
231
+            'status'            => isset($data['status']) ? wpinv_clean($data['status']) : null,
232
+            'post_type'         => isset($data['post_type']) ? wpinv_clean($data['post_type']) : null,
233
+            'user_ip'           => isset($data['ip']) ? wpinv_clean($data['ip']) : wpinv_get_ip(),
234
+            'parent_id'         => isset($data['parent']) ? intval($data['parent']) : null,
235
+            'mode'              => isset($data['mode']) ? wpinv_clean($data['mode']) : null,
236
+            'description'       => isset($data['description']) ? wp_kses_post($data['description']) : null,
237 237
 
238 238
             // Payment info.
239
-            'disable_taxes'     => ! empty( $data['disable_taxes'] ),
240
-            'currency'          => isset( $data['currency'] ) ? wpinv_clean( $data['currency'] ) : wpinv_get_currency(),
241
-            'gateway'           => isset( $data['gateway'] ) ? wpinv_clean( $data['gateway'] ) : null,
242
-            'transaction_id'    => isset( $data['transaction_id'] ) ? wpinv_clean( $data['transaction_id'] ) : null,
243
-            'discount_code'     => isset( $data['discount_code'] ) ? wpinv_clean( $data['discount_code'] ) : null,
244
-            'payment_form'      => isset( $data['payment_form'] ) ? intval( $data['payment_form'] ) : null,
245
-            'submission_id'     => isset( $data['submission_id'] ) ? wpinv_clean( $data['submission_id'] ) : null,
246
-            'subscription_id'   => isset( $data['subscription_id'] ) ? wpinv_clean( $data['subscription_id'] ) : null,
247
-            'is_viewed'         => isset( $data['is_viewed'] ) ? wpinv_clean( $data['is_viewed'] ) : null,
248
-            'fees'              => isset( $data['fees'] ) ? wpinv_clean( $data['fees'] ) : null,
249
-            'discounts'         => isset( $data['discounts'] ) ? wpinv_clean( $data['discounts'] ) : null,
250
-            'taxes'             => isset( $data['taxes'] ) ? wpinv_clean( $data['taxes'] ) : null,
239
+            'disable_taxes'     => !empty($data['disable_taxes']),
240
+            'currency'          => isset($data['currency']) ? wpinv_clean($data['currency']) : wpinv_get_currency(),
241
+            'gateway'           => isset($data['gateway']) ? wpinv_clean($data['gateway']) : null,
242
+            'transaction_id'    => isset($data['transaction_id']) ? wpinv_clean($data['transaction_id']) : null,
243
+            'discount_code'     => isset($data['discount_code']) ? wpinv_clean($data['discount_code']) : null,
244
+            'payment_form'      => isset($data['payment_form']) ? intval($data['payment_form']) : null,
245
+            'submission_id'     => isset($data['submission_id']) ? wpinv_clean($data['submission_id']) : null,
246
+            'subscription_id'   => isset($data['subscription_id']) ? wpinv_clean($data['subscription_id']) : null,
247
+            'is_viewed'         => isset($data['is_viewed']) ? wpinv_clean($data['is_viewed']) : null,
248
+            'fees'              => isset($data['fees']) ? wpinv_clean($data['fees']) : null,
249
+            'discounts'         => isset($data['discounts']) ? wpinv_clean($data['discounts']) : null,
250
+            'taxes'             => isset($data['taxes']) ? wpinv_clean($data['taxes']) : null,
251 251
 
252 252
             // Billing details.
253 253
             'user_id'           => $data['user_id'],
254
-            'first_name'        => isset( $data['first_name'] ) ? wpinv_clean( $data['first_name'] ) : $address['first_name'],
255
-            'last_name'         => isset( $data['last_name'] ) ? wpinv_clean( $data['last_name'] ) : $address['last_name'],
256
-            'address'           => isset( $data['address'] ) ? wpinv_clean( $data['address'] ) : $address['address'],
257
-            'vat_number'        => isset( $data['vat_number'] ) ? wpinv_clean( $data['vat_number'] ) : $address['vat_number'],
258
-            'company'           => isset( $data['company'] ) ? wpinv_clean( $data['company'] ) : $address['company'],
259
-            'zip'               => isset( $data['zip'] ) ? wpinv_clean( $data['zip'] ) : $address['zip'],
260
-            'state'             => isset( $data['state'] ) ? wpinv_clean( $data['state'] ) : $address['state'],
261
-            'city'              => isset( $data['city'] ) ? wpinv_clean( $data['city'] ) : $address['city'],
262
-            'country'           => isset( $data['country'] ) ? wpinv_clean( $data['country'] ) : $address['country'],
263
-            'phone'             => isset( $data['phone'] ) ? wpinv_clean( $data['phone'] ) : $address['phone'],
264
-            'address_confirmed' => ! empty( $data['address_confirmed'] ),
254
+            'first_name'        => isset($data['first_name']) ? wpinv_clean($data['first_name']) : $address['first_name'],
255
+            'last_name'         => isset($data['last_name']) ? wpinv_clean($data['last_name']) : $address['last_name'],
256
+            'address'           => isset($data['address']) ? wpinv_clean($data['address']) : $address['address'],
257
+            'vat_number'        => isset($data['vat_number']) ? wpinv_clean($data['vat_number']) : $address['vat_number'],
258
+            'company'           => isset($data['company']) ? wpinv_clean($data['company']) : $address['company'],
259
+            'zip'               => isset($data['zip']) ? wpinv_clean($data['zip']) : $address['zip'],
260
+            'state'             => isset($data['state']) ? wpinv_clean($data['state']) : $address['state'],
261
+            'city'              => isset($data['city']) ? wpinv_clean($data['city']) : $address['city'],
262
+            'country'           => isset($data['country']) ? wpinv_clean($data['country']) : $address['country'],
263
+            'phone'             => isset($data['phone']) ? wpinv_clean($data['phone']) : $address['phone'],
264
+            'address_confirmed' => !empty($data['address_confirmed']),
265 265
 
266 266
         )
267 267
     );
268 268
 
269 269
     // Backwards compatibililty.
270
-    if ( ! empty( $data['cart_details'] ) && is_array( $data['cart_details'] ) ) {
270
+    if (!empty($data['cart_details']) && is_array($data['cart_details'])) {
271 271
         $data['items'] = array();
272 272
 
273
-        foreach ( $data['cart_details'] as $_item ) {
273
+        foreach ($data['cart_details'] as $_item) {
274 274
 
275 275
             // Ensure that we have an item id.
276
-            if ( empty( $_item['id'] ) ) {
276
+            if (empty($_item['id'])) {
277 277
                 continue;
278 278
             }
279 279
 
280 280
             // Retrieve the item.
281
-            $item = new GetPaid_Form_Item( $_item['id'] );
281
+            $item = new GetPaid_Form_Item($_item['id']);
282 282
 
283 283
             // Ensure that it is purchasable.
284
-            if ( ! $item->can_purchase() ) {
284
+            if (!$item->can_purchase()) {
285 285
                 continue;
286 286
             }
287 287
 
288 288
             // Set quantity.
289
-            if ( ! empty( $_item['quantity'] ) && is_numeric( $_item['quantity'] ) ) {
290
-                $item->set_quantity( $_item['quantity'] );
289
+            if (!empty($_item['quantity']) && is_numeric($_item['quantity'])) {
290
+                $item->set_quantity($_item['quantity']);
291 291
             }
292 292
 
293 293
             // Set price.
294
-            if ( isset( $_item['item_price'] ) ) {
295
-                $item->set_price( $_item['item_price'] );
294
+            if (isset($_item['item_price'])) {
295
+                $item->set_price($_item['item_price']);
296 296
             }
297 297
 
298
-            if ( isset( $_item['custom_price'] ) ) {
299
-                $item->set_price( $_item['custom_price'] );
298
+            if (isset($_item['custom_price'])) {
299
+                $item->set_price($_item['custom_price']);
300 300
             }
301 301
 
302
-            if ( isset( $_item['price_id'] ) ) {
303
-                $item->set_price_id( $_item['price_id'] );
302
+            if (isset($_item['price_id'])) {
303
+                $item->set_price_id($_item['price_id']);
304 304
             }
305 305
 
306 306
             // Set name.
307
-            if ( ! empty( $_item['name'] ) ) {
308
-                $item->set_name( $_item['name'] );
307
+            if (!empty($_item['name'])) {
308
+                $item->set_name($_item['name']);
309 309
             }
310 310
 
311 311
             // Set description.
312
-            if ( isset( $_item['description'] ) ) {
313
-                $item->set_custom_description( $_item['description'] );
312
+            if (isset($_item['description'])) {
313
+                $item->set_custom_description($_item['description']);
314 314
             }
315 315
 
316 316
             // Set meta.
317
-            if ( isset( $_item['meta'] ) && is_array( $_item['meta'] ) ) {
317
+            if (isset($_item['meta']) && is_array($_item['meta'])) {
318 318
 
319
-                $item->set_item_meta( $_item['meta'] );
319
+                $item->set_item_meta($_item['meta']);
320 320
 
321
-                if ( isset( $_item['meta']['description'] ) ) {
322
-                    $item->set_custom_description( $_item['meta']['description'] );
321
+                if (isset($_item['meta']['description'])) {
322
+                    $item->set_custom_description($_item['meta']['description']);
323 323
                 }
324 324
             }
325 325
 
@@ -329,14 +329,14 @@  discard block
 block discarded – undo
329 329
     }
330 330
 
331 331
     // Add invoice items.
332
-    if ( ! empty( $data['items'] ) && is_array( $data['items'] ) ) {
332
+    if (!empty($data['items']) && is_array($data['items'])) {
333 333
 
334
-        $invoice->set_items( array() );
334
+        $invoice->set_items(array());
335 335
 
336
-        foreach ( $data['items'] as $item ) {
336
+        foreach ($data['items'] as $item) {
337 337
 
338
-            if ( is_object( $item ) && is_a( $item, 'GetPaid_Form_Item' ) && $item->can_purchase() ) {
339
-                $invoice->add_item( $item );
338
+            if (is_object($item) && is_a($item, 'GetPaid_Form_Item') && $item->can_purchase()) {
339
+                $invoice->add_item($item);
340 340
             }
341 341
         }
342 342
     }
@@ -345,30 +345,30 @@  discard block
 block discarded – undo
345 345
     $invoice->recalculate_total();
346 346
     $invoice->save();
347 347
 
348
-    if ( ! $invoice->get_id() ) {
349
-        return $wp_error ? new WP_Error( 'wpinv_insert_invoice_error', __( 'An error occured when saving your invoice.', 'invoicing' ) ) : 0;
348
+    if (!$invoice->get_id()) {
349
+        return $wp_error ? new WP_Error('wpinv_insert_invoice_error', __('An error occured when saving your invoice.', 'invoicing')) : 0;
350 350
     }
351 351
 
352 352
     // Add private note.
353
-    if ( ! empty( $data['private_note'] ) ) {
354
-        $invoice->add_note( $data['private_note'] );
353
+    if (!empty($data['private_note'])) {
354
+        $invoice->add_note($data['private_note']);
355 355
     }
356 356
 
357 357
     // User notes.
358
-    if ( ! empty( $data['user_note'] ) ) {
359
-        $invoice->add_note( $data['user_note'], true );
358
+    if (!empty($data['user_note'])) {
359
+        $invoice->add_note($data['user_note'], true);
360 360
     }
361 361
 
362 362
     // Created via.
363
-    if ( isset( $data['created_via'] ) ) {
364
-        update_post_meta( $invoice->get_id(), 'wpinv_created_via', $data['created_via'] );
363
+    if (isset($data['created_via'])) {
364
+        update_post_meta($invoice->get_id(), 'wpinv_created_via', $data['created_via']);
365 365
     }
366 366
 
367 367
     // Backwards compatiblity.
368
-    if ( $invoice->is_quote() ) {
368
+    if ($invoice->is_quote()) {
369 369
 
370
-        if ( isset( $data['valid_until'] ) ) {
371
-            update_post_meta( $invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until'] );
370
+        if (isset($data['valid_until'])) {
371
+            update_post_meta($invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until']);
372 372
         }
373 373
 }
374 374
 
@@ -382,20 +382,20 @@  discard block
 block discarded – undo
382 382
  * @param $bool $deprecated
383 383
  * @return WPInv_Invoice|null
384 384
  */
385
-function wpinv_get_invoice( $invoice = 0, $deprecated = false ) {
385
+function wpinv_get_invoice($invoice = 0, $deprecated = false) {
386 386
 
387 387
     // If we are retrieving the invoice from the cart...
388
-    if ( $deprecated && empty( $invoice ) ) {
388
+    if ($deprecated && empty($invoice)) {
389 389
         $invoice = (int) getpaid_get_current_invoice_id();
390 390
     }
391 391
 
392 392
     // Retrieve the invoice.
393
-    if ( ! is_a( $invoice, 'WPInv_Invoice' ) ) {
394
-        $invoice = new WPInv_Invoice( $invoice );
393
+    if (!is_a($invoice, 'WPInv_Invoice')) {
394
+        $invoice = new WPInv_Invoice($invoice);
395 395
     }
396 396
 
397 397
     // Check if it exists.
398
-    if ( $invoice->exists() ) {
398
+    if ($invoice->exists()) {
399 399
         return $invoice;
400 400
     }
401 401
 
@@ -408,15 +408,15 @@  discard block
 block discarded – undo
408 408
  * @param array $args Args to search for.
409 409
  * @return WPInv_Invoice[]|int[]|object
410 410
  */
411
-function wpinv_get_invoices( $args ) {
411
+function wpinv_get_invoices($args) {
412 412
 
413 413
     // Prepare args.
414 414
     $args = wp_parse_args(
415 415
         $args,
416 416
         array(
417
-            'status' => array_keys( wpinv_get_invoice_statuses() ),
417
+            'status' => array_keys(wpinv_get_invoice_statuses()),
418 418
             'type'   => 'wpi_invoice',
419
-            'limit'  => get_option( 'posts_per_page' ),
419
+            'limit'  => get_option('posts_per_page'),
420 420
             'return' => 'objects',
421 421
         )
422 422
     );
@@ -434,24 +434,24 @@  discard block
 block discarded – undo
434 434
         'post__in'       => 'include',
435 435
     );
436 436
 
437
-    foreach ( $map_legacy as $to => $from ) {
438
-        if ( isset( $args[ $from ] ) ) {
439
-            $args[ $to ] = $args[ $from ];
440
-            unset( $args[ $from ] );
437
+    foreach ($map_legacy as $to => $from) {
438
+        if (isset($args[$from])) {
439
+            $args[$to] = $args[$from];
440
+            unset($args[$from]);
441 441
         }
442 442
     }
443 443
 
444 444
     // Backwards compatibility.
445
-    if ( ! empty( $args['email'] ) && empty( $args['user'] ) ) {
445
+    if (!empty($args['email']) && empty($args['user'])) {
446 446
         $args['user'] = $args['email'];
447
-        unset( $args['email'] );
447
+        unset($args['email']);
448 448
     }
449 449
 
450 450
     // Handle cases where the user is set as an email.
451
-    if ( ! empty( $args['author'] ) && is_email( $args['author'] ) ) {
452
-        $user = get_user_by( 'email', $args['user'] );
451
+    if (!empty($args['author']) && is_email($args['author'])) {
452
+        $user = get_user_by('email', $args['user']);
453 453
 
454
-        if ( $user ) {
454
+        if ($user) {
455 455
             $args['author'] = $user->user_email;
456 456
         }
457 457
 }
@@ -461,31 +461,31 @@  discard block
 block discarded – undo
461 461
 
462 462
     // Show all posts.
463 463
     $paginate = true;
464
-    if ( isset( $args['paginate'] ) ) {
464
+    if (isset($args['paginate'])) {
465 465
 
466 466
         $paginate = $args['paginate'];
467
-        $args['no_found_rows'] = empty( $args['paginate'] );
468
-        unset( $args['paginate'] );
467
+        $args['no_found_rows'] = empty($args['paginate']);
468
+        unset($args['paginate']);
469 469
 
470 470
     }
471 471
 
472 472
     // Whether to return objects or fields.
473 473
     $return = $args['return'];
474
-    unset( $args['return'] );
474
+    unset($args['return']);
475 475
 
476 476
     // Get invoices.
477
-    $invoices = new WP_Query( apply_filters( 'wpinv_get_invoices_args', $args ) );
477
+    $invoices = new WP_Query(apply_filters('wpinv_get_invoices_args', $args));
478 478
 
479 479
     // Prepare the results.
480
-    if ( 'objects' === $return ) {
481
-        $results = array_map( 'wpinv_get_invoice', $invoices->posts );
482
-    } elseif ( 'self' === $return ) {
480
+    if ('objects' === $return) {
481
+        $results = array_map('wpinv_get_invoice', $invoices->posts);
482
+    } elseif ('self' === $return) {
483 483
         return $invoices;
484 484
     } else {
485 485
         $results = $invoices->posts;
486 486
     }
487 487
 
488
-    if ( $paginate ) {
488
+    if ($paginate) {
489 489
         return (object) array(
490 490
             'invoices'      => $results,
491 491
             'total'         => $invoices->found_posts,
@@ -503,8 +503,8 @@  discard block
 block discarded – undo
503 503
  * @param string $transaction_id The transaction id to check.
504 504
  * @return int Invoice id on success or 0 on failure
505 505
  */
506
-function wpinv_get_id_by_transaction_id( $transaction_id ) {
507
-    return WPInv_Invoice::get_invoice_id_by_field( $transaction_id, 'transaction_id' );
506
+function wpinv_get_id_by_transaction_id($transaction_id) {
507
+    return WPInv_Invoice::get_invoice_id_by_field($transaction_id, 'transaction_id');
508 508
 }
509 509
 
510 510
 /**
@@ -513,8 +513,8 @@  discard block
 block discarded – undo
513 513
  * @param string $invoice_number The invoice number to check.
514 514
  * @return int Invoice id on success or 0 on failure
515 515
  */
516
-function wpinv_get_id_by_invoice_number( $invoice_number ) {
517
-    return WPInv_Invoice::get_invoice_id_by_field( $invoice_number, 'number' );
516
+function wpinv_get_id_by_invoice_number($invoice_number) {
517
+    return WPInv_Invoice::get_invoice_id_by_field($invoice_number, 'number');
518 518
 }
519 519
 
520 520
 /**
@@ -523,8 +523,8 @@  discard block
 block discarded – undo
523 523
  * @param string $invoice_key The invoice key to check.
524 524
  * @return int Invoice id on success or 0 on failure
525 525
  */
526
-function wpinv_get_invoice_id_by_key( $invoice_key ) {
527
-    return WPInv_Invoice::get_invoice_id_by_field( $invoice_key, 'key' );
526
+function wpinv_get_invoice_id_by_key($invoice_key) {
527
+    return WPInv_Invoice::get_invoice_id_by_field($invoice_key, 'key');
528 528
 }
529 529
 
530 530
 /**
@@ -534,19 +534,19 @@  discard block
 block discarded – undo
534 534
  * @param string $type Optionally filter by type i.e customer|system
535 535
  * @return array|null
536 536
  */
537
-function wpinv_get_invoice_notes( $invoice = 0, $type = '' ) {
537
+function wpinv_get_invoice_notes($invoice = 0, $type = '') {
538 538
 
539 539
     // Prepare the invoice.
540
-    $invoice = wpinv_get_invoice( $invoice );
541
-    if ( empty( $invoice ) ) {
540
+    $invoice = wpinv_get_invoice($invoice);
541
+    if (empty($invoice)) {
542 542
         return null;
543 543
     }
544 544
 
545 545
     // Fetch notes.
546
-    $notes = getpaid_notes()->get_invoice_notes( $invoice->get_id(), $type );
546
+    $notes = getpaid_notes()->get_invoice_notes($invoice->get_id(), $type);
547 547
 
548 548
     // Filter the notes.
549
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice->get_id(), $type );
549
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice->get_id(), $type);
550 550
 }
551 551
 
552 552
 /**
@@ -554,10 +554,10 @@  discard block
 block discarded – undo
554 554
  *
555 555
  * @param string $post_type
556 556
  */
557
-function wpinv_get_user_invoices_columns( $post_type = 'wpi_invoice' ) {
557
+function wpinv_get_user_invoices_columns($post_type = 'wpi_invoice') {
558 558
 
559
-    $label   = getpaid_get_post_type_label( $post_type, false );
560
-    $label   = empty( $label ) ? __( 'Invoice', 'invoicing' ) : sanitize_text_field( $label );
559
+    $label   = getpaid_get_post_type_label($post_type, false);
560
+    $label   = empty($label) ? __('Invoice', 'invoicing') : sanitize_text_field($label);
561 561
     $columns = array(
562 562
 
563 563
 		'invoice-number'  => array(
@@ -566,22 +566,22 @@  discard block
 block discarded – undo
566 566
 		),
567 567
 
568 568
 		'created-date'    => array(
569
-			'title' => __( 'Created Date', 'invoicing' ),
569
+			'title' => __('Created Date', 'invoicing'),
570 570
 			'class' => 'text-left',
571 571
 		),
572 572
 
573 573
 		'payment-date'    => array(
574
-			'title' => __( 'Payment Date', 'invoicing' ),
574
+			'title' => __('Payment Date', 'invoicing'),
575 575
 			'class' => 'text-left',
576 576
 		),
577 577
 
578 578
 		'invoice-status'  => array(
579
-			'title' => __( 'Status', 'invoicing' ),
579
+			'title' => __('Status', 'invoicing'),
580 580
 			'class' => 'text-center',
581 581
 		),
582 582
 
583 583
 		'invoice-total'   => array(
584
-			'title' => __( 'Total', 'invoicing' ),
584
+			'title' => __('Total', 'invoicing'),
585 585
 			'class' => 'text-right',
586 586
 		),
587 587
 
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
 
593 593
 	);
594 594
 
595
-    return apply_filters( 'wpinv_user_invoices_columns', $columns, $post_type );
595
+    return apply_filters('wpinv_user_invoices_columns', $columns, $post_type);
596 596
 }
597 597
 
598 598
 /**
@@ -602,59 +602,59 @@  discard block
 block discarded – undo
602 602
 
603 603
     // Find the invoice.
604 604
     $invoice_id = getpaid_get_current_invoice_id();
605
-    $invoice = new WPInv_Invoice( $invoice_id );
605
+    $invoice = new WPInv_Invoice($invoice_id);
606 606
 
607 607
     // Abort if non was found.
608
-    if ( empty( $invoice_id ) || $invoice->is_draft() ) {
608
+    if (empty($invoice_id) || $invoice->is_draft()) {
609 609
 
610 610
         return aui()->alert(
611 611
             array(
612 612
                 'type'    => 'warning',
613
-                'content' => __( 'We could not find your invoice', 'invoicing' ),
613
+                'content' => __('We could not find your invoice', 'invoicing'),
614 614
             )
615 615
         );
616 616
 
617 617
     }
618 618
 
619 619
     // Can the user view this invoice?
620
-    if ( ! wpinv_can_view_receipt( $invoice_id ) ) {
620
+    if (!wpinv_can_view_receipt($invoice_id)) {
621 621
 
622 622
         return aui()->alert(
623 623
             array(
624 624
                 'type'    => 'warning',
625
-                'content' => __( 'You are not allowed to view this receipt', 'invoicing' ),
625
+                'content' => __('You are not allowed to view this receipt', 'invoicing'),
626 626
             )
627 627
         );
628 628
 
629 629
     }
630 630
 
631 631
     // Load the template.
632
-    return wpinv_get_template_html( 'invoice-receipt.php', compact( 'invoice' ) );
632
+    return wpinv_get_template_html('invoice-receipt.php', compact('invoice'));
633 633
 
634 634
 }
635 635
 
636 636
 /**
637 637
  * Displays the invoice history.
638 638
  */
639
-function getpaid_invoice_history( $user_id = 0, $post_type = 'wpi_invoice' ) {
639
+function getpaid_invoice_history($user_id = 0, $post_type = 'wpi_invoice') {
640 640
 
641 641
     // Ensure that we have a user id.
642
-    if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
642
+    if (empty($user_id) || !is_numeric($user_id)) {
643 643
         $user_id = get_current_user_id();
644 644
     }
645 645
 
646
-    $label = getpaid_get_post_type_label( $post_type );
647
-    $label = empty( $label ) ? __( 'Invoices', 'invoicing' ) : sanitize_text_field( $label );
646
+    $label = getpaid_get_post_type_label($post_type);
647
+    $label = empty($label) ? __('Invoices', 'invoicing') : sanitize_text_field($label);
648 648
 
649 649
     // View user id.
650
-    if ( empty( $user_id ) ) {
650
+    if (empty($user_id)) {
651 651
 
652 652
         return aui()->alert(
653 653
             array(
654 654
                 'type'    => 'warning',
655 655
                 'content' => sprintf(
656
-                    __( 'You must be logged in to view your %s.', 'invoicing' ),
657
-                    strtolower( $label )
656
+                    __('You must be logged in to view your %s.', 'invoicing'),
657
+                    strtolower($label)
658 658
                 ),
659 659
             )
660 660
         );
@@ -664,22 +664,22 @@  discard block
 block discarded – undo
664 664
     // Fetch invoices.
665 665
     $invoices = wpinv_get_invoices(
666 666
         array(
667
-            'page'     => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1,
667
+            'page'     => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1,
668 668
             'user'     => $user_id,
669 669
             'paginate' => true,
670 670
             'type'     => $post_type,
671
-            'status'   => array_keys( wpinv_get_invoice_statuses( false, false, $post_type ) ),
671
+            'status'   => array_keys(wpinv_get_invoice_statuses(false, false, $post_type)),
672 672
         )
673 673
     );
674 674
 
675
-    if ( empty( $invoices->total ) ) {
675
+    if (empty($invoices->total)) {
676 676
 
677 677
         return aui()->alert(
678 678
             array(
679 679
                 'type'    => 'info',
680 680
                 'content' => sprintf(
681
-                    __( 'No %s found.', 'invoicing' ),
682
-                    strtolower( $label )
681
+                    __('No %s found.', 'invoicing'),
682
+                    strtolower($label)
683 683
                 ),
684 684
             )
685 685
         );
@@ -687,38 +687,38 @@  discard block
 block discarded – undo
687 687
     }
688 688
 
689 689
     // Load the template.
690
-    return wpinv_get_template_html( 'invoice-history.php', compact( 'invoices', 'post_type' ) );
690
+    return wpinv_get_template_html('invoice-history.php', compact('invoices', 'post_type'));
691 691
 
692 692
 }
693 693
 
694 694
 /**
695 695
  * Formats an invoice number given an invoice type.
696 696
  */
697
-function wpinv_format_invoice_number( $number, $type = '' ) {
697
+function wpinv_format_invoice_number($number, $type = '') {
698 698
 
699 699
     // Allow other plugins to overide this.
700
-    $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type );
701
-    if ( null !== $check ) {
700
+    $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type);
701
+    if (null !== $check) {
702 702
         return $check;
703 703
     }
704 704
 
705 705
     // Ensure that we have a numeric number.
706
-    if ( ! is_numeric( $number ) ) {
706
+    if (!is_numeric($number)) {
707 707
         return $number;
708 708
     }
709 709
 
710 710
     // Format the number.
711
-    $padd             = absint( (int) wpinv_get_option( 'invoice_number_padd', 5 ) );
712
-    $prefix           = sanitize_text_field( (string) wpinv_get_option( 'invoice_number_prefix', 'INV-' ) );
713
-    $prefix           = sanitize_text_field( apply_filters( 'getpaid_invoice_type_prefix', $prefix, $type ) );
714
-    $postfix          = sanitize_text_field( (string) wpinv_get_option( 'invoice_number_postfix' ) );
715
-    $postfix          = sanitize_text_field( apply_filters( 'getpaid_invoice_type_postfix', $postfix, $type ) );
716
-    $formatted_number = zeroise( absint( $number ), $padd );
711
+    $padd             = absint((int) wpinv_get_option('invoice_number_padd', 5));
712
+    $prefix           = sanitize_text_field((string) wpinv_get_option('invoice_number_prefix', 'INV-'));
713
+    $prefix           = sanitize_text_field(apply_filters('getpaid_invoice_type_prefix', $prefix, $type));
714
+    $postfix          = sanitize_text_field((string) wpinv_get_option('invoice_number_postfix'));
715
+    $postfix          = sanitize_text_field(apply_filters('getpaid_invoice_type_postfix', $postfix, $type));
716
+    $formatted_number = zeroise(absint($number), $padd);
717 717
 
718 718
     // Add the prefix and post fix.
719 719
     $formatted_number = $prefix . $formatted_number . $postfix;
720 720
 
721
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
721
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
722 722
 }
723 723
 
724 724
 /**
@@ -727,58 +727,58 @@  discard block
 block discarded – undo
727 727
  * @param string $type.
728 728
  * @return int|null|bool
729 729
  */
730
-function wpinv_get_next_invoice_number( $type = '' ) {
730
+function wpinv_get_next_invoice_number($type = '') {
731 731
 
732 732
     // Allow plugins to overide this.
733
-    $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type );
734
-    if ( null !== $check ) {
733
+    $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type);
734
+    if (null !== $check) {
735 735
         return $check;
736 736
     }
737 737
 
738 738
     // Ensure sequential invoice numbers is active.
739
-    if ( ! wpinv_sequential_number_active() ) {
739
+    if (!wpinv_sequential_number_active()) {
740 740
         return false;
741 741
     }
742 742
 
743 743
     // Retrieve the current number and the start number.
744
-    $number = (int) get_option( 'wpinv_last_invoice_number', 0 );
745
-    $start  = absint( (int) wpinv_get_option( 'invoice_sequence_start', 1 ) );
744
+    $number = (int) get_option('wpinv_last_invoice_number', 0);
745
+    $start  = absint((int) wpinv_get_option('invoice_sequence_start', 1));
746 746
 
747 747
     // Ensure that we are starting at a positive integer.
748
-    $start  = max( $start, 1 );
748
+    $start  = max($start, 1);
749 749
 
750 750
     // If this is the first invoice, use the start number.
751
-    $number = max( $start, $number );
751
+    $number = max($start, $number);
752 752
 
753 753
     // Format the invoice number.
754
-    $formatted_number = wpinv_format_invoice_number( $number, $type );
754
+    $formatted_number = wpinv_format_invoice_number($number, $type);
755 755
 
756 756
     // Ensure that this number is unique.
757
-    $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $formatted_number, 'number' );
757
+    $invoice_id = WPInv_Invoice::get_invoice_id_by_field($formatted_number, 'number');
758 758
 
759 759
     // We found a match. Nice.
760
-    if ( empty( $invoice_id ) ) {
761
-        update_option( 'wpinv_last_invoice_number', $number );
762
-        return apply_filters( 'wpinv_get_next_invoice_number', $number );
760
+    if (empty($invoice_id)) {
761
+        update_option('wpinv_last_invoice_number', $number);
762
+        return apply_filters('wpinv_get_next_invoice_number', $number);
763 763
     }
764 764
 
765
-    update_option( 'wpinv_last_invoice_number', $number + 1 );
766
-    return wpinv_get_next_invoice_number( $type );
765
+    update_option('wpinv_last_invoice_number', $number + 1);
766
+    return wpinv_get_next_invoice_number($type);
767 767
 
768 768
 }
769 769
 
770 770
 /**
771 771
  * The prefix used for invoice paths.
772 772
  */
773
-function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) {
774
-    return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type );
773
+function wpinv_post_name_prefix($post_type = 'wpi_invoice') {
774
+    return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type);
775 775
 }
776 776
 
777
-function wpinv_generate_post_name( $post_ID ) {
778
-    $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) );
779
-    $post_name = sanitize_title( $prefix . $post_ID );
777
+function wpinv_generate_post_name($post_ID) {
778
+    $prefix = wpinv_post_name_prefix(get_post_type($post_ID));
779
+    $post_name = sanitize_title($prefix . $post_ID);
780 780
 
781
-    return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix );
781
+    return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix);
782 782
 }
783 783
 
784 784
 /**
@@ -786,8 +786,8 @@  discard block
 block discarded – undo
786 786
  *
787 787
  * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object.
788 788
  */
789
-function wpinv_is_invoice_viewed( $invoice ) {
790
-    $invoice = new WPInv_Invoice( $invoice );
789
+function wpinv_is_invoice_viewed($invoice) {
790
+    $invoice = new WPInv_Invoice($invoice);
791 791
     return (bool) $invoice->get_is_viewed();
792 792
 }
793 793
 
@@ -796,17 +796,17 @@  discard block
 block discarded – undo
796 796
  *
797 797
  * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object.
798 798
  */
799
-function getpaid_maybe_mark_invoice_as_viewed( $invoice ) {
800
-    $invoice = new WPInv_Invoice( $invoice );
799
+function getpaid_maybe_mark_invoice_as_viewed($invoice) {
800
+    $invoice = new WPInv_Invoice($invoice);
801 801
 
802
-    if ( get_current_user_id() == $invoice->get_user_id() && ! $invoice->get_is_viewed() ) {
803
-        $invoice->set_is_viewed( true );
802
+    if (get_current_user_id() == $invoice->get_user_id() && !$invoice->get_is_viewed()) {
803
+        $invoice->set_is_viewed(true);
804 804
         $invoice->save();
805 805
     }
806 806
 
807 807
 }
808
-add_action( 'wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed' );
809
-add_action( 'wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed' );
808
+add_action('wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed');
809
+add_action('wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed');
810 810
 
811 811
 /**
812 812
  * Processes an invoice refund.
@@ -815,26 +815,26 @@  discard block
 block discarded – undo
815 815
  * @param array $status_transition
816 816
  * @todo: descrease customer/store earnings
817 817
  */
818
-function getpaid_maybe_process_refund( $invoice, $status_transition ) {
818
+function getpaid_maybe_process_refund($invoice, $status_transition) {
819 819
 
820
-    if ( empty( $status_transition['from'] ) || ! in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
820
+    if (empty($status_transition['from']) || !in_array($status_transition['from'], array('publish', 'wpi-processing', 'wpi-renewal'))) {
821 821
         return;
822 822
     }
823 823
 
824 824
     $discount_code = $invoice->get_discount_code();
825
-    if ( ! empty( $discount_code ) ) {
826
-        $discount = wpinv_get_discount_obj( $discount_code );
825
+    if (!empty($discount_code)) {
826
+        $discount = wpinv_get_discount_obj($discount_code);
827 827
 
828
-        if ( $discount->exists() ) {
828
+        if ($discount->exists()) {
829 829
             $discount->increase_usage( -1 );
830 830
         }
831 831
 }
832 832
 
833
-    do_action( 'wpinv_pre_refund_invoice', $invoice, $invoice->get_id() );
834
-    do_action( 'wpinv_refund_invoice', $invoice, $invoice->get_id() );
835
-    do_action( 'wpinv_post_refund_invoice', $invoice, $invoice->get_id() );
833
+    do_action('wpinv_pre_refund_invoice', $invoice, $invoice->get_id());
834
+    do_action('wpinv_refund_invoice', $invoice, $invoice->get_id());
835
+    do_action('wpinv_post_refund_invoice', $invoice, $invoice->get_id());
836 836
 }
837
-add_action( 'getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 2 );
837
+add_action('getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 2);
838 838
 
839 839
 
840 840
 /**
@@ -842,47 +842,47 @@  discard block
 block discarded – undo
842 842
  *
843 843
  * @param int $invoice_id
844 844
  */
845
-function getpaid_process_invoice_payment( $invoice_id ) {
845
+function getpaid_process_invoice_payment($invoice_id) {
846 846
 
847 847
     // Fetch the invoice.
848
-    $invoice = new WPInv_Invoice( $invoice_id );
848
+    $invoice = new WPInv_Invoice($invoice_id);
849 849
 
850 850
     // We only want to do this once.
851
-    if ( 1 == get_post_meta( $invoice->get_id(), 'wpinv_processed_payment', true ) ) {
851
+    if (1 == get_post_meta($invoice->get_id(), 'wpinv_processed_payment', true)) {
852 852
         return;
853 853
     }
854 854
 
855
-    update_post_meta( $invoice->get_id(), 'wpinv_processed_payment', 1 );
855
+    update_post_meta($invoice->get_id(), 'wpinv_processed_payment', 1);
856 856
 
857 857
     // Fires when processing a payment.
858
-    do_action( 'getpaid_process_payment', $invoice );
858
+    do_action('getpaid_process_payment', $invoice);
859 859
 
860 860
     // Fire an action for each invoice item.
861
-    foreach ( $invoice->get_items() as $item ) {
862
-        do_action( 'getpaid_process_item_payment', $item, $invoice );
861
+    foreach ($invoice->get_items() as $item) {
862
+        do_action('getpaid_process_item_payment', $item, $invoice);
863 863
     }
864 864
 
865 865
     // Increase discount usage.
866 866
     $discount_code = $invoice->get_discount_code();
867
-    if ( ! empty( $discount_code ) && ! $invoice->is_renewal() ) {
868
-        $discount = wpinv_get_discount_obj( $discount_code );
867
+    if (!empty($discount_code) && !$invoice->is_renewal()) {
868
+        $discount = wpinv_get_discount_obj($discount_code);
869 869
 
870
-        if ( $discount->exists() ) {
870
+        if ($discount->exists()) {
871 871
             $discount->increase_usage();
872 872
         }
873 873
 }
874 874
 
875 875
     // Record reverse vat.
876
-    if ( 'invoice' === $invoice->get_type() && wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) {
876
+    if ('invoice' === $invoice->get_type() && wpinv_use_taxes() && !$invoice->get_disable_taxes()) {
877 877
 
878 878
         $taxes = $invoice->get_total_tax();
879
-        if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) {
880
-            $invoice->add_note( __( 'VAT was reverse charged', 'invoicing' ), false, false, true );
879
+        if (empty($taxes) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction($invoice->get_country())) {
880
+            $invoice->add_note(__('VAT was reverse charged', 'invoicing'), false, false, true);
881 881
         }
882 882
 }
883 883
 
884 884
 }
885
-add_action( 'getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment' );
885
+add_action('getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment');
886 886
 
887 887
 /**
888 888
  * Returns an array of invoice item columns
@@ -890,13 +890,13 @@  discard block
 block discarded – undo
890 890
  * @param int|WPInv_Invoice $invoice
891 891
  * @return array
892 892
  */
893
-function getpaid_invoice_item_columns( $invoice ) {
893
+function getpaid_invoice_item_columns($invoice) {
894 894
 
895 895
     // Prepare the invoice.
896
-    $invoice = new WPInv_Invoice( $invoice );
896
+    $invoice = new WPInv_Invoice($invoice);
897 897
 
898 898
     // Abort if there is no invoice.
899
-    if ( 0 == $invoice->get_id() ) {
899
+    if (0 == $invoice->get_id()) {
900 900
         return array();
901 901
     }
902 902
 
@@ -904,52 +904,52 @@  discard block
 block discarded – undo
904 904
     $columns = apply_filters(
905 905
         'getpaid_invoice_item_columns',
906 906
         array(
907
-            'name'     => __( 'Item', 'invoicing' ),
908
-            'price'    => __( 'Price', 'invoicing' ),
909
-            'tax_rate' => __( 'Tax Rate', 'invoicing' ),
910
-            'quantity' => __( 'Quantity', 'invoicing' ),
911
-            'subtotal' => __( 'Item Subtotal', 'invoicing' ),
907
+            'name'     => __('Item', 'invoicing'),
908
+            'price'    => __('Price', 'invoicing'),
909
+            'tax_rate' => __('Tax Rate', 'invoicing'),
910
+            'quantity' => __('Quantity', 'invoicing'),
911
+            'subtotal' => __('Item Subtotal', 'invoicing'),
912 912
         ),
913 913
         $invoice
914 914
     );
915 915
 
916 916
     // Quantities.
917
-    if ( isset( $columns['quantity'] ) ) {
917
+    if (isset($columns['quantity'])) {
918 918
 
919
-        if ( 'hours' == $invoice->get_template() ) {
920
-            $columns['quantity'] = __( 'Hours', 'invoicing' );
919
+        if ('hours' == $invoice->get_template()) {
920
+            $columns['quantity'] = __('Hours', 'invoicing');
921 921
         }
922 922
 
923
-        if ( ! wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template() ) {
924
-            unset( $columns['quantity'] );
923
+        if (!wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template()) {
924
+            unset($columns['quantity']);
925 925
         }
926 926
     }
927 927
 
928 928
     // Price.
929
-    if ( isset( $columns['price'] ) ) {
929
+    if (isset($columns['price'])) {
930 930
 
931
-        if ( 'amount' == $invoice->get_template() ) {
932
-            $columns['price'] = __( 'Amount', 'invoicing' );
931
+        if ('amount' == $invoice->get_template()) {
932
+            $columns['price'] = __('Amount', 'invoicing');
933 933
         }
934 934
 
935
-        if ( 'hours' == $invoice->get_template() ) {
936
-            $columns['price'] = __( 'Rate', 'invoicing' );
935
+        if ('hours' == $invoice->get_template()) {
936
+            $columns['price'] = __('Rate', 'invoicing');
937 937
         }
938 938
 }
939 939
 
940 940
     // Sub total.
941
-    if ( isset( $columns['subtotal'] ) ) {
941
+    if (isset($columns['subtotal'])) {
942 942
 
943
-        if ( 'amount' == $invoice->get_template() ) {
944
-            unset( $columns['subtotal'] );
943
+        if ('amount' == $invoice->get_template()) {
944
+            unset($columns['subtotal']);
945 945
         }
946 946
 }
947 947
 
948 948
     // Tax rates.
949
-    if ( isset( $columns['tax_rate'] ) ) {
949
+    if (isset($columns['tax_rate'])) {
950 950
 
951
-        if ( 0 == $invoice->get_total_tax() ) {
952
-            unset( $columns['tax_rate'] );
951
+        if (0 == $invoice->get_total_tax()) {
952
+            unset($columns['tax_rate']);
953 953
         }
954 954
     }
955 955
 
@@ -962,53 +962,53 @@  discard block
 block discarded – undo
962 962
  * @param int|WPInv_Invoice $invoice
963 963
  * @return array
964 964
  */
965
-function getpaid_invoice_totals_rows( $invoice ) {
965
+function getpaid_invoice_totals_rows($invoice) {
966 966
 
967 967
     // Prepare the invoice.
968
-    $invoice = new WPInv_Invoice( $invoice );
968
+    $invoice = new WPInv_Invoice($invoice);
969 969
 
970 970
     // Abort if there is no invoice.
971
-    if ( 0 == $invoice->get_id() ) {
971
+    if (0 == $invoice->get_id()) {
972 972
         return array();
973 973
     }
974 974
 
975 975
     $totals = apply_filters(
976 976
         'getpaid_invoice_totals_rows',
977 977
         array(
978
-            'subtotal' => __( 'Subtotal', 'invoicing' ),
979
-            'shipping' => __( 'Shipping', 'invoicing' ),
980
-            'tax'      => __( 'Tax', 'invoicing' ),
981
-            'fee'      => __( 'Fee', 'invoicing' ),
982
-            'discount' => __( 'Discount', 'invoicing' ),
983
-            'total'    => __( 'Total', 'invoicing' ),
978
+            'subtotal' => __('Subtotal', 'invoicing'),
979
+            'shipping' => __('Shipping', 'invoicing'),
980
+            'tax'      => __('Tax', 'invoicing'),
981
+            'fee'      => __('Fee', 'invoicing'),
982
+            'discount' => __('Discount', 'invoicing'),
983
+            'total'    => __('Total', 'invoicing'),
984 984
         ),
985 985
         $invoice
986 986
     );
987 987
 
988
-    if ( ! $invoice->has_shipping() ) {
989
-        unset( $totals['shipping'] );
988
+    if (!$invoice->has_shipping()) {
989
+        unset($totals['shipping']);
990 990
     }
991 991
 
992
-    if ( ( $invoice->get_disable_taxes() || ! wpinv_use_taxes() ) && isset( $totals['tax'] ) ) {
993
-        unset( $totals['tax'] );
992
+    if (($invoice->get_disable_taxes() || !wpinv_use_taxes()) && isset($totals['tax'])) {
993
+        unset($totals['tax']);
994 994
     }
995 995
 
996 996
     // If we have taxes, display individual taxes.
997
-    if ( isset( $totals['tax'] ) && wpinv_display_individual_tax_rates() ) {
997
+    if (isset($totals['tax']) && wpinv_display_individual_tax_rates()) {
998 998
 
999 999
         $new_totals = array();
1000
-        foreach ( $totals as $key => $label ) {
1000
+        foreach ($totals as $key => $label) {
1001 1001
 
1002
-            if ( 'tax' !== $key ) {
1003
-                $new_totals[ $key ] = $label;
1002
+            if ('tax' !== $key) {
1003
+                $new_totals[$key] = $label;
1004 1004
                 continue;
1005 1005
             }
1006 1006
 
1007
-            $taxes = array_keys( $invoice->get_taxes() );
1008
-            if ( ! empty( $taxes ) ) {
1007
+            $taxes = array_keys($invoice->get_taxes());
1008
+            if (!empty($taxes)) {
1009 1009
 
1010
-                foreach ( $taxes as $tax ) {
1011
-                    $new_totals[ 'tax__' . $tax ] = $tax;
1010
+                foreach ($taxes as $tax) {
1011
+                    $new_totals['tax__' . $tax] = $tax;
1012 1012
                 }
1013 1013
             }
1014 1014
         }
@@ -1016,12 +1016,12 @@  discard block
 block discarded – undo
1016 1016
         $totals = $new_totals;
1017 1017
     }
1018 1018
 
1019
-    if ( 0 == $invoice->get_total_fees() && isset( $totals['fee'] ) ) {
1020
-        unset( $totals['fee'] );
1019
+    if (0 == $invoice->get_total_fees() && isset($totals['fee'])) {
1020
+        unset($totals['fee']);
1021 1021
     }
1022 1022
 
1023
-    if ( 0 == $invoice->get_total_discount() && isset( $totals['discount'] ) ) {
1024
-        unset( $totals['discount'] );
1023
+    if (0 == $invoice->get_total_discount() && isset($totals['discount'])) {
1024
+        unset($totals['discount']);
1025 1025
     }
1026 1026
 
1027 1027
     return $totals;
@@ -1032,47 +1032,47 @@  discard block
 block discarded – undo
1032 1032
  *
1033 1033
  * @param WPInv_Invoice $invoice
1034 1034
  */
1035
-function getpaid_new_invoice( $invoice ) {
1035
+function getpaid_new_invoice($invoice) {
1036 1036
 
1037
-    if ( ! $invoice->get_status() ) {
1037
+    if (!$invoice->get_status()) {
1038 1038
         return;
1039 1039
     }
1040 1040
 
1041 1041
     // Add an invoice created note.
1042 1042
     $invoice->add_note(
1043 1043
         sprintf(
1044
-            __( '%1$s created with the status "%2$s".', 'invoicing' ),
1045
-            ucfirst( $invoice->get_invoice_quote_type() ),
1046
-            wpinv_status_nicename( $invoice->get_status(), $invoice )
1044
+            __('%1$s created with the status "%2$s".', 'invoicing'),
1045
+            ucfirst($invoice->get_invoice_quote_type()),
1046
+            wpinv_status_nicename($invoice->get_status(), $invoice)
1047 1047
         )
1048 1048
     );
1049 1049
 
1050 1050
 }
1051
-add_action( 'getpaid_new_invoice', 'getpaid_new_invoice' );
1051
+add_action('getpaid_new_invoice', 'getpaid_new_invoice');
1052 1052
 
1053 1053
 /**
1054 1054
  * This function updates invoice caches.
1055 1055
  *
1056 1056
  * @param WPInv_Invoice $invoice
1057 1057
  */
1058
-function getpaid_update_invoice_caches( $invoice ) {
1058
+function getpaid_update_invoice_caches($invoice) {
1059 1059
 
1060 1060
     // Cache invoice number.
1061
-    wp_cache_set( $invoice->get_number(), $invoice->get_id(), 'getpaid_invoice_numbers_to_invoice_ids' );
1061
+    wp_cache_set($invoice->get_number(), $invoice->get_id(), 'getpaid_invoice_numbers_to_invoice_ids');
1062 1062
 
1063 1063
     // Cache invoice key.
1064
-    wp_cache_set( $invoice->get_key(), $invoice->get_id(), 'getpaid_invoice_keys_to_invoice_ids' );
1064
+    wp_cache_set($invoice->get_key(), $invoice->get_id(), 'getpaid_invoice_keys_to_invoice_ids');
1065 1065
 
1066 1066
     // (Maybe) cache transaction id.
1067 1067
     $transaction_id = $invoice->get_transaction_id();
1068 1068
 
1069
-    if ( ! empty( $transaction_id ) ) {
1070
-        wp_cache_set( $transaction_id, $invoice->get_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' );
1069
+    if (!empty($transaction_id)) {
1070
+        wp_cache_set($transaction_id, $invoice->get_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids');
1071 1071
     }
1072 1072
 
1073 1073
 }
1074
-add_action( 'getpaid_new_invoice', 'getpaid_update_invoice_caches', 5 );
1075
-add_action( 'getpaid_update_invoice', 'getpaid_update_invoice_caches', 5 );
1074
+add_action('getpaid_new_invoice', 'getpaid_update_invoice_caches', 5);
1075
+add_action('getpaid_update_invoice', 'getpaid_update_invoice_caches', 5);
1076 1076
 
1077 1077
 /**
1078 1078
  * Duplicates an invoice.
@@ -1082,7 +1082,7 @@  discard block
 block discarded – undo
1082 1082
  * @param  WPInv_Invoice $old_invoice The invoice to duplicate
1083 1083
  * @return WPInv_Invoice The new invoice.
1084 1084
  */
1085
-function getpaid_duplicate_invoice( $old_invoice ) {
1085
+function getpaid_duplicate_invoice($old_invoice) {
1086 1086
 
1087 1087
     // Create the new invoice.
1088 1088
     $invoice = new WPInv_Invoice();
@@ -1142,136 +1142,136 @@  discard block
 block discarded – undo
1142 1142
  * @param WPInv_Invoice $invoice
1143 1143
  * @return array
1144 1144
  */
1145
-function getpaid_get_invoice_meta( $invoice ) {
1145
+function getpaid_get_invoice_meta($invoice) {
1146 1146
 
1147 1147
     // Load the invoice meta.
1148 1148
     $meta = array(
1149 1149
 
1150 1150
         'number'         => array(
1151 1151
             'label' => sprintf(
1152
-                __( '%s Number', 'invoicing' ),
1153
-                ucfirst( $invoice->get_invoice_quote_type() )
1152
+                __('%s Number', 'invoicing'),
1153
+                ucfirst($invoice->get_invoice_quote_type())
1154 1154
             ),
1155
-            'value' => sanitize_text_field( $invoice->get_number() ),
1155
+            'value' => sanitize_text_field($invoice->get_number()),
1156 1156
         ),
1157 1157
 
1158 1158
         'status'         => array(
1159 1159
             'label' => sprintf(
1160
-                __( '%s Status', 'invoicing' ),
1161
-                ucfirst( $invoice->get_invoice_quote_type() )
1160
+                __('%s Status', 'invoicing'),
1161
+                ucfirst($invoice->get_invoice_quote_type())
1162 1162
             ),
1163 1163
             'value' => $invoice->get_status_label_html(),
1164 1164
         ),
1165 1165
 
1166 1166
         'date'           => array(
1167 1167
             'label' => sprintf(
1168
-                __( '%s Date', 'invoicing' ),
1169
-                ucfirst( $invoice->get_invoice_quote_type() )
1168
+                __('%s Date', 'invoicing'),
1169
+                ucfirst($invoice->get_invoice_quote_type())
1170 1170
             ),
1171
-            'value' => getpaid_format_date( $invoice->get_created_date() ),
1171
+            'value' => getpaid_format_date($invoice->get_created_date()),
1172 1172
         ),
1173 1173
 
1174 1174
         'date_paid'      => array(
1175
-            'label' => __( 'Paid On', 'invoicing' ),
1176
-            'value' => getpaid_format_date( $invoice->get_completed_date() ),
1175
+            'label' => __('Paid On', 'invoicing'),
1176
+            'value' => getpaid_format_date($invoice->get_completed_date()),
1177 1177
         ),
1178 1178
 
1179 1179
         'gateway'        => array(
1180
-            'label' => __( 'Payment Method', 'invoicing' ),
1181
-            'value' => sanitize_text_field( $invoice->get_gateway_title() ),
1180
+            'label' => __('Payment Method', 'invoicing'),
1181
+            'value' => sanitize_text_field($invoice->get_gateway_title()),
1182 1182
         ),
1183 1183
 
1184 1184
         'transaction_id' => array(
1185
-            'label' => __( 'Transaction ID', 'invoicing' ),
1186
-            'value' => sanitize_text_field( $invoice->get_transaction_id() ),
1185
+            'label' => __('Transaction ID', 'invoicing'),
1186
+            'value' => sanitize_text_field($invoice->get_transaction_id()),
1187 1187
         ),
1188 1188
 
1189 1189
         'due_date'       => array(
1190
-            'label' => __( 'Due Date', 'invoicing' ),
1191
-            'value' => getpaid_format_date( $invoice->get_due_date() ),
1190
+            'label' => __('Due Date', 'invoicing'),
1191
+            'value' => getpaid_format_date($invoice->get_due_date()),
1192 1192
         ),
1193 1193
 
1194 1194
         'vat_number'     => array(
1195
-            'label' => __( 'VAT Number', 'invoicing' ),
1196
-            'value' => sanitize_text_field( $invoice->get_vat_number() ),
1195
+            'label' => __('VAT Number', 'invoicing'),
1196
+            'value' => sanitize_text_field($invoice->get_vat_number()),
1197 1197
         ),
1198 1198
 
1199 1199
     );
1200 1200
 
1201
-    $additional_meta = get_post_meta( $invoice->get_id(), 'additional_meta_data', true );
1201
+    $additional_meta = get_post_meta($invoice->get_id(), 'additional_meta_data', true);
1202 1202
 
1203
-    if ( ! empty( $additional_meta ) ) {
1203
+    if (!empty($additional_meta)) {
1204 1204
 
1205
-        foreach ( $additional_meta as $label => $value ) {
1206
-            $meta[ sanitize_key( $label ) ] = array(
1207
-                'label' => esc_html( $label ),
1208
-                'value' => esc_html( $value ),
1205
+        foreach ($additional_meta as $label => $value) {
1206
+            $meta[sanitize_key($label)] = array(
1207
+                'label' => esc_html($label),
1208
+                'value' => esc_html($value),
1209 1209
             );
1210 1210
         }
1211 1211
 }
1212 1212
     // If it is not paid, remove the date of payment.
1213
-    if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
1214
-        unset( $meta['date_paid'] );
1215
-        unset( $meta['transaction_id'] );
1213
+    if (!$invoice->is_paid() && !$invoice->is_refunded()) {
1214
+        unset($meta['date_paid']);
1215
+        unset($meta['transaction_id']);
1216 1216
     }
1217 1217
 
1218
-    if ( ! $invoice->is_paid() || 'none' == $invoice->get_gateway() ) {
1219
-        unset( $meta['gateway'] );
1218
+    if (!$invoice->is_paid() || 'none' == $invoice->get_gateway()) {
1219
+        unset($meta['gateway']);
1220 1220
     }
1221 1221
 
1222 1222
     // Only display the due date if due dates are enabled.
1223
-    if ( ! $invoice->needs_payment() || ! wpinv_get_option( 'overdue_active' ) ) {
1224
-        unset( $meta['due_date'] );
1223
+    if (!$invoice->needs_payment() || !wpinv_get_option('overdue_active')) {
1224
+        unset($meta['due_date']);
1225 1225
     }
1226 1226
 
1227 1227
     // Only display the vat number if taxes are enabled.
1228
-    if ( ! wpinv_use_taxes() ) {
1229
-        unset( $meta['vat_number'] );
1228
+    if (!wpinv_use_taxes()) {
1229
+        unset($meta['vat_number']);
1230 1230
     }
1231 1231
 
1232 1232
     // Link to the parent invoice.
1233
-    if ( $invoice->get_parent_id() > 0 ) {
1233
+    if ($invoice->get_parent_id() > 0) {
1234 1234
 
1235 1235
         $meta['parent'] = array(
1236 1236
 
1237 1237
             'label' => sprintf(
1238
-                __( 'Parent %s', 'invoicing' ),
1239
-                ucfirst( $invoice->get_invoice_quote_type() )
1238
+                __('Parent %s', 'invoicing'),
1239
+                ucfirst($invoice->get_invoice_quote_type())
1240 1240
             ),
1241 1241
 
1242
-            'value' => wpinv_invoice_link( $invoice->get_parent_id() ),
1242
+            'value' => wpinv_invoice_link($invoice->get_parent_id()),
1243 1243
 
1244 1244
         );
1245 1245
 
1246 1246
     }
1247 1247
 
1248
-    if ( $invoice->is_recurring() ) {
1248
+    if ($invoice->is_recurring()) {
1249 1249
 
1250
-        $subscription = getpaid_get_invoice_subscriptions( $invoice );
1251
-        if ( ! empty( $subscription ) && ! is_array( $subscription ) && $subscription->exists() ) {
1250
+        $subscription = getpaid_get_invoice_subscriptions($invoice);
1251
+        if (!empty($subscription) && !is_array($subscription) && $subscription->exists()) {
1252 1252
 
1253 1253
             // Display the renewal date.
1254
-            if ( $subscription->is_active() && 'cancelled' != $subscription->get_status() ) {
1254
+            if ($subscription->is_active() && 'cancelled' != $subscription->get_status()) {
1255 1255
 
1256 1256
                 $meta['renewal_date'] = array(
1257
-                    'label' => __( 'Renews On', 'invoicing' ),
1258
-                    'value' => getpaid_format_date( $subscription->get_expiration() ) .
1257
+                    'label' => __('Renews On', 'invoicing'),
1258
+                    'value' => getpaid_format_date($subscription->get_expiration()) .
1259 1259
                     sprintf(
1260 1260
                         ' <a class="small" href="%s">%s<a>',
1261 1261
                         $subscription->get_view_url(),
1262
-                        __( '(View Subscription)', 'invoicing' )
1262
+                        __('(View Subscription)', 'invoicing')
1263 1263
                     ),
1264 1264
                 );
1265 1265
 
1266 1266
             }
1267 1267
 
1268
-            if ( $invoice->is_parent() ) {
1268
+            if ($invoice->is_parent()) {
1269 1269
 
1270 1270
                 // Display the recurring amount.
1271 1271
                 $meta['recurring_total'] = array(
1272 1272
 
1273
-                    'label' => __( 'Recurring Amount', 'invoicing' ),
1274
-                    'value' => wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ),
1273
+                    'label' => __('Recurring Amount', 'invoicing'),
1274
+                    'value' => wpinv_price($subscription->get_recurring_amount(), $invoice->get_currency()),
1275 1275
 
1276 1276
                 );
1277 1277
 
@@ -1282,13 +1282,13 @@  discard block
 block discarded – undo
1282 1282
     // Add the invoice total to the meta.
1283 1283
     $meta['invoice_total'] = array(
1284 1284
 
1285
-        'label' => __( 'Total Amount', 'invoicing' ),
1286
-        'value' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ),
1285
+        'label' => __('Total Amount', 'invoicing'),
1286
+        'value' => wpinv_price($invoice->get_total(), $invoice->get_currency()),
1287 1287
 
1288 1288
     );
1289 1289
 
1290 1290
     // Provide a way for third party plugins to filter the meta.
1291
-    $meta = apply_filters( 'getpaid_invoice_meta_data', $meta, $invoice );
1291
+    $meta = apply_filters('getpaid_invoice_meta_data', $meta, $invoice);
1292 1292
 
1293 1293
     return $meta;
1294 1294
 
@@ -1327,12 +1327,12 @@  discard block
 block discarded – undo
1327 1327
  * @param GetPaid_Form_Item $item
1328 1328
  * @return float
1329 1329
  */
1330
-function getpaid_get_invoice_tax_rate( $invoice, $item ) {
1330
+function getpaid_get_invoice_tax_rate($invoice, $item) {
1331 1331
 
1332
-    $rates   = getpaid_get_item_tax_rates( $item, $invoice->get_country(), $invoice->get_state() );
1333
-	$rates   = getpaid_filter_item_tax_rates( $item, $rates );
1334
-    $rates   = wp_list_pluck( $rates, 'rate' );
1332
+    $rates   = getpaid_get_item_tax_rates($item, $invoice->get_country(), $invoice->get_state());
1333
+	$rates = getpaid_filter_item_tax_rates($item, $rates);
1334
+    $rates   = wp_list_pluck($rates, 'rate');
1335 1335
 
1336
-    return array_sum( $rates );
1336
+    return array_sum($rates);
1337 1337
 
1338 1338
 }
Please login to merge, or discard this patch.