Passed
Pull Request — master (#378)
by Brian
07:38 queued 02:10
created
includes/class-wpinv-invoice.php 1 patch
Spacing   +716 added lines, -716 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // MUST have WordPress.
4
-if ( !defined( 'WPINC' ) ) {
5
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
4
+if (!defined('WPINC')) {
5
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
6 6
 }
7 7
 
8 8
 /**
@@ -130,38 +130,38 @@  discard block
 block discarded – undo
130 130
 	 *
131 131
 	 * @param  int/string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, number or object to read.
132 132
 	 */
133
-    public function __construct( $invoice = false ) {
133
+    public function __construct($invoice = false) {
134 134
 
135
-        parent::__construct( $invoice );
135
+        parent::__construct($invoice);
136 136
 
137
-		if ( is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) {
138
-			$this->set_id( $invoice );
139
-		} elseif ( $invoice instanceof self ) {
140
-			$this->set_id( $invoice->get_id() );
141
-		} elseif ( ! empty( $invoice->ID ) ) {
142
-			$this->set_id( $invoice->ID );
143
-		} elseif ( is_array( $invoice ) ) {
144
-			$this->set_props( $invoice );
137
+		if (is_numeric($invoice) && getpaid_is_invoice_post_type(get_post_type($invoice))) {
138
+			$this->set_id($invoice);
139
+		} elseif ($invoice instanceof self) {
140
+			$this->set_id($invoice->get_id());
141
+		} elseif (!empty($invoice->ID)) {
142
+			$this->set_id($invoice->ID);
143
+		} elseif (is_array($invoice)) {
144
+			$this->set_props($invoice);
145 145
 
146
-			if ( isset( $invoice['ID'] ) ) {
147
-				$this->set_id( $invoice['ID'] );
146
+			if (isset($invoice['ID'])) {
147
+				$this->set_id($invoice['ID']);
148 148
 			}
149 149
 
150
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) {
151
-			$this->set_id( $invoice_id );
152
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) {
153
-			$this->set_id( $invoice_id );
150
+		} elseif (is_scalar($invoice) && $invoice_id = self::get_invoice_id_by_field($invoice, 'key')) {
151
+			$this->set_id($invoice_id);
152
+		} elseif (is_scalar($invoice) && $invoice_id = self::get_invoice_id_by_field($invoice, 'number')) {
153
+			$this->set_id($invoice_id);
154 154
 		} else {
155
-			$this->set_object_read( true );
155
+			$this->set_object_read(true);
156 156
 		}
157 157
 
158 158
         // Load the datastore.
159
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
159
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
160 160
 
161
-		if ( $this->get_id() > 0 ) {
162
-            $this->post = get_post( $this->get_id() );
161
+		if ($this->get_id() > 0) {
162
+            $this->post = get_post($this->get_id());
163 163
             $this->ID   = $this->get_id();
164
-			$this->data_store->read( $this );
164
+			$this->data_store->read($this);
165 165
         }
166 166
 
167 167
     }
@@ -176,42 +176,42 @@  discard block
 block discarded – undo
176 176
 	 * @since 1.0.15
177 177
 	 * @return int
178 178
 	 */
179
-	public static function get_invoice_id_by_field( $value, $field = 'key' ) {
179
+	public static function get_invoice_id_by_field($value, $field = 'key') {
180 180
         global $wpdb;
181 181
 
182 182
 		// Trim the value.
183
-		$value = trim( $value );
183
+		$value = trim($value);
184 184
 		
185
-		if ( empty( $value ) ) {
185
+		if (empty($value)) {
186 186
 			return 0;
187 187
 		}
188 188
 
189 189
         // Valid fields.
190
-        $fields = array( 'key', 'number' );
190
+        $fields = array('key', 'number');
191 191
 
192 192
 		// Ensure a field has been passed.
193
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
193
+		if (empty($field) || !in_array($field, $fields)) {
194 194
 			return 0;
195 195
 		}
196 196
 
197 197
 		// Maybe retrieve from the cache.
198
-		$invoice_id   = wp_cache_get( $field, "getpaid_invoice_{$field}s_to_ids" );
199
-		if ( ! empty( $invoice_id ) ) {
198
+		$invoice_id = wp_cache_get($field, "getpaid_invoice_{$field}s_to_ids");
199
+		if (!empty($invoice_id)) {
200 200
 			return $invoice_id;
201 201
 		}
202 202
 
203 203
         // Fetch from the db.
204 204
         $table       = $wpdb->prefix . 'getpaid_invoices';
205 205
         $invoice_id  = $wpdb->get_var(
206
-            $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
206
+            $wpdb->prepare("SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value)
207 207
         );
208 208
 
209
-		if ( empty( $invoice_id ) ) {
209
+		if (empty($invoice_id)) {
210 210
 			return 0;
211 211
 		}
212 212
 
213 213
 		// Update the cache with our data
214
-		wp_cache_set( $field, $invoice_id, "getpaid_invoice_{$field}s_to_ids" );
214
+		wp_cache_set($field, $invoice_id, "getpaid_invoice_{$field}s_to_ids");
215 215
 
216 216
 		return $invoice_id;
217 217
     }
@@ -219,8 +219,8 @@  discard block
 block discarded – undo
219 219
     /**
220 220
      * Checks if an invoice key is set.
221 221
      */
222
-    public function _isset( $key ) {
223
-        return isset( $this->data[$key] ) || method_exists( $this, "get_$key" );
222
+    public function _isset($key) {
223
+        return isset($this->data[$key]) || method_exists($this, "get_$key");
224 224
     }
225 225
 
226 226
     /*
@@ -245,8 +245,8 @@  discard block
 block discarded – undo
245 245
 	 * @param  string $context View or edit context.
246 246
 	 * @return int
247 247
 	 */
248
-	public function get_parent_id( $context = 'view' ) {
249
-		return (int) $this->get_prop( 'parent_id', $context );
248
+	public function get_parent_id($context = 'view') {
249
+		return (int) $this->get_prop('parent_id', $context);
250 250
     }
251 251
 
252 252
     /**
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 	 * @return WPInv_Invoice
257 257
 	 */
258 258
     public function get_parent_payment() {
259
-        return new WPInv_Invoice( $this->get_parent_id() );
259
+        return new WPInv_Invoice($this->get_parent_id());
260 260
     }
261 261
 
262 262
     /**
@@ -276,8 +276,8 @@  discard block
 block discarded – undo
276 276
 	 * @param  string $context View or edit context.
277 277
 	 * @return string
278 278
 	 */
279
-	public function get_status( $context = 'view' ) {
280
-		return $this->get_prop( 'status', $context );
279
+	public function get_status($context = 'view') {
280
+		return $this->get_prop('status', $context);
281 281
     }
282 282
 
283 283
     /**
@@ -287,15 +287,15 @@  discard block
 block discarded – undo
287 287
 	 * @return string
288 288
 	 */
289 289
     public function get_status_nicename() {
290
-        $statuses = wpinv_get_invoice_statuses( true, true, $this );
290
+        $statuses = wpinv_get_invoice_statuses(true, true, $this);
291 291
 
292
-        if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) {
292
+        if ($this->is_quote() && class_exists('Wpinv_Quotes_Shared')) {
293 293
             $statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses();
294 294
         }
295 295
 
296
-        $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status();
296
+        $status = isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : $this->get_status();
297 297
 
298
-        return apply_filters( 'wpinv_get_invoice_status_nicename', $status );
298
+        return apply_filters('wpinv_get_invoice_status_nicename', $status);
299 299
     }
300 300
 
301 301
     /**
@@ -305,27 +305,27 @@  discard block
 block discarded – undo
305 305
 	 * @param  string $context View or edit context.
306 306
 	 * @return string
307 307
 	 */
308
-	public function get_version( $context = 'view' ) {
309
-		return $this->get_prop( 'version', $context );
308
+	public function get_version($context = 'view') {
309
+		return $this->get_prop('version', $context);
310 310
 	}
311 311
 
312 312
 	/**
313 313
 	 * @deprecated
314 314
 	 */
315
-	public function get_invoice_date( $formatted = true ) {
315
+	public function get_invoice_date($formatted = true) {
316 316
         $date_completed = $this->get_date_completed();
317 317
         $invoice_date   = $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
318 318
 
319
-        if ( $invoice_date == '' ) {
319
+        if ($invoice_date == '') {
320 320
             $date_created   = $this->get_date_created();
321 321
             $invoice_date   = $date_created != '0000-00-00 00:00:00' ? $date_created : '';
322 322
         }
323 323
 
324
-        if ( $formatted && $invoice_date ) {
325
-            $invoice_date   = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );
324
+        if ($formatted && $invoice_date) {
325
+            $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date));
326 326
         }
327 327
 
328
-        return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->get_id(), $this );
328
+        return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->get_id(), $this);
329 329
     }
330 330
 
331 331
     /**
@@ -335,8 +335,8 @@  discard block
 block discarded – undo
335 335
 	 * @param  string $context View or edit context.
336 336
 	 * @return string
337 337
 	 */
338
-	public function get_date_created( $context = 'view' ) {
339
-		return $this->get_prop( 'date_created', $context );
338
+	public function get_date_created($context = 'view') {
339
+		return $this->get_prop('date_created', $context);
340 340
 	}
341 341
 	
342 342
 	/**
@@ -346,8 +346,8 @@  discard block
 block discarded – undo
346 346
 	 * @param  string $context View or edit context.
347 347
 	 * @return string
348 348
 	 */
349
-	public function get_created_date( $context = 'view' ) {
350
-		return $this->get_date_created( $context );
349
+	public function get_created_date($context = 'view') {
350
+		return $this->get_date_created($context);
351 351
     }
352 352
 
353 353
     /**
@@ -357,11 +357,11 @@  discard block
 block discarded – undo
357 357
 	 * @param  string $context View or edit context.
358 358
 	 * @return string
359 359
 	 */
360
-	public function get_date_created_gmt( $context = 'view' ) {
361
-        $date = $this->get_date_created( $context );
360
+	public function get_date_created_gmt($context = 'view') {
361
+        $date = $this->get_date_created($context);
362 362
 
363
-        if ( $date ) {
364
-            $date = get_gmt_from_date( $date );
363
+        if ($date) {
364
+            $date = get_gmt_from_date($date);
365 365
         }
366 366
 		return $date;
367 367
     }
@@ -373,8 +373,8 @@  discard block
 block discarded – undo
373 373
 	 * @param  string $context View or edit context.
374 374
 	 * @return string
375 375
 	 */
376
-	public function get_date_modified( $context = 'view' ) {
377
-		return $this->get_prop( 'date_modified', $context );
376
+	public function get_date_modified($context = 'view') {
377
+		return $this->get_prop('date_modified', $context);
378 378
 	}
379 379
 
380 380
 	/**
@@ -384,8 +384,8 @@  discard block
 block discarded – undo
384 384
 	 * @param  string $context View or edit context.
385 385
 	 * @return string
386 386
 	 */
387
-	public function get_modified_date( $context = 'view' ) {
388
-		return $this->get_date_modified( $context );
387
+	public function get_modified_date($context = 'view') {
388
+		return $this->get_date_modified($context);
389 389
     }
390 390
 
391 391
     /**
@@ -395,11 +395,11 @@  discard block
 block discarded – undo
395 395
 	 * @param  string $context View or edit context.
396 396
 	 * @return string
397 397
 	 */
398
-	public function get_date_modified_gmt( $context = 'view' ) {
399
-        $date = $this->get_date_modified( $context );
398
+	public function get_date_modified_gmt($context = 'view') {
399
+        $date = $this->get_date_modified($context);
400 400
 
401
-        if ( $date ) {
402
-            $date = get_gmt_from_date( $date );
401
+        if ($date) {
402
+            $date = get_gmt_from_date($date);
403 403
         }
404 404
 		return $date;
405 405
     }
@@ -411,8 +411,8 @@  discard block
 block discarded – undo
411 411
 	 * @param  string $context View or edit context.
412 412
 	 * @return string
413 413
 	 */
414
-	public function get_due_date( $context = 'view' ) {
415
-		return $this->get_prop( 'due_date', $context );
414
+	public function get_due_date($context = 'view') {
415
+		return $this->get_prop('due_date', $context);
416 416
     }
417 417
 
418 418
     /**
@@ -422,8 +422,8 @@  discard block
 block discarded – undo
422 422
 	 * @param  string $context View or edit context.
423 423
 	 * @return string
424 424
 	 */
425
-	public function get_date_due( $context = 'view' ) {
426
-		return $this->get_due_date( $context );
425
+	public function get_date_due($context = 'view') {
426
+		return $this->get_due_date($context);
427 427
     }
428 428
 
429 429
     /**
@@ -433,11 +433,11 @@  discard block
 block discarded – undo
433 433
 	 * @param  string $context View or edit context.
434 434
 	 * @return string
435 435
 	 */
436
-	public function get_due_date_gmt( $context = 'view' ) {
437
-        $date = $this->get_due_date( $context );
436
+	public function get_due_date_gmt($context = 'view') {
437
+        $date = $this->get_due_date($context);
438 438
 
439
-        if ( $date ) {
440
-            $date = get_gmt_from_date( $date );
439
+        if ($date) {
440
+            $date = get_gmt_from_date($date);
441 441
         }
442 442
 		return $date;
443 443
     }
@@ -449,8 +449,8 @@  discard block
 block discarded – undo
449 449
 	 * @param  string $context View or edit context.
450 450
 	 * @return string
451 451
 	 */
452
-	public function get_gmt_date_due( $context = 'view' ) {
453
-		return $this->get_due_date_gmt( $context );
452
+	public function get_gmt_date_due($context = 'view') {
453
+		return $this->get_due_date_gmt($context);
454 454
     }
455 455
 
456 456
     /**
@@ -460,8 +460,8 @@  discard block
 block discarded – undo
460 460
 	 * @param  string $context View or edit context.
461 461
 	 * @return string
462 462
 	 */
463
-	public function get_completed_date( $context = 'view' ) {
464
-		return $this->get_prop( 'completed_date', $context );
463
+	public function get_completed_date($context = 'view') {
464
+		return $this->get_prop('completed_date', $context);
465 465
     }
466 466
 
467 467
     /**
@@ -471,8 +471,8 @@  discard block
 block discarded – undo
471 471
 	 * @param  string $context View or edit context.
472 472
 	 * @return string
473 473
 	 */
474
-	public function get_date_completed( $context = 'view' ) {
475
-		return $this->get_completed_date( $context );
474
+	public function get_date_completed($context = 'view') {
475
+		return $this->get_completed_date($context);
476 476
     }
477 477
 
478 478
     /**
@@ -482,11 +482,11 @@  discard block
 block discarded – undo
482 482
 	 * @param  string $context View or edit context.
483 483
 	 * @return string
484 484
 	 */
485
-	public function get_completed_date_gmt( $context = 'view' ) {
486
-        $date = $this->get_completed_date( $context );
485
+	public function get_completed_date_gmt($context = 'view') {
486
+        $date = $this->get_completed_date($context);
487 487
 
488
-        if ( $date ) {
489
-            $date = get_gmt_from_date( $date );
488
+        if ($date) {
489
+            $date = get_gmt_from_date($date);
490 490
         }
491 491
 		return $date;
492 492
     }
@@ -498,8 +498,8 @@  discard block
 block discarded – undo
498 498
 	 * @param  string $context View or edit context.
499 499
 	 * @return string
500 500
 	 */
501
-	public function get_gmt_completed_date( $context = 'view' ) {
502
-		return $this->get_completed_date_gmt( $context );
501
+	public function get_gmt_completed_date($context = 'view') {
502
+		return $this->get_completed_date_gmt($context);
503 503
     }
504 504
 
505 505
     /**
@@ -509,12 +509,12 @@  discard block
 block discarded – undo
509 509
 	 * @param  string $context View or edit context.
510 510
 	 * @return string
511 511
 	 */
512
-	public function get_number( $context = 'view' ) {
513
-        $number = $this->get_prop( 'number', $context );
512
+	public function get_number($context = 'view') {
513
+        $number = $this->get_prop('number', $context);
514 514
 
515
-        if ( empty( $number ) ) {
515
+        if (empty($number)) {
516 516
             $number = $this->generate_number();
517
-            $this->set_number( $number );
517
+            $this->set_number($number);
518 518
         }
519 519
 
520 520
 		return $number;
@@ -527,12 +527,12 @@  discard block
 block discarded – undo
527 527
 	 * @param  string $context View or edit context.
528 528
 	 * @return string
529 529
 	 */
530
-	public function get_key( $context = 'view' ) {
531
-        $key = $this->get_prop( 'key', $context );
530
+	public function get_key($context = 'view') {
531
+        $key = $this->get_prop('key', $context);
532 532
 
533
-        if ( empty( $key ) ) {
534
-            $key = $this->generate_key( $this->post_type );
535
-            $this->set_key( $key );
533
+        if (empty($key)) {
534
+            $key = $this->generate_key($this->post_type);
535
+            $this->set_key($key);
536 536
         }
537 537
 
538 538
 		return $key;
@@ -545,23 +545,23 @@  discard block
 block discarded – undo
545 545
 	 * @param  string $context View or edit context.
546 546
 	 * @return string
547 547
 	 */
548
-	public function get_type( $context = 'view' ) {
549
-        return $this->get_prop( 'type', $context );
548
+	public function get_type($context = 'view') {
549
+        return $this->get_prop('type', $context);
550 550
 	}
551 551
 
552 552
 	/**
553 553
 	 * @deprecated
554 554
 	 */
555
-	public function get_invoice_quote_type( $post_id ) {
556
-        if ( empty( $post_id ) ) {
555
+	public function get_invoice_quote_type($post_id) {
556
+        if (empty($post_id)) {
557 557
             return '';
558 558
         }
559 559
 
560
-        $type = get_post_type( $post_id );
560
+        $type = get_post_type($post_id);
561 561
 
562
-        if ( 'wpi_invoice' === $type ) {
562
+        if ('wpi_invoice' === $type) {
563 563
             $post_type = __('Invoice', 'invoicing');
564
-        } else{
564
+        } else {
565 565
             $post_type = __('Quote', 'invoicing');
566 566
         }
567 567
 
@@ -575,8 +575,8 @@  discard block
 block discarded – undo
575 575
 	 * @param  string $context View or edit context.
576 576
 	 * @return string
577 577
 	 */
578
-	public function get_post_type( $context = 'view' ) {
579
-        return $this->get_prop( 'post_type', $context );
578
+	public function get_post_type($context = 'view') {
579
+        return $this->get_prop('post_type', $context);
580 580
     }
581 581
 
582 582
     /**
@@ -586,8 +586,8 @@  discard block
 block discarded – undo
586 586
 	 * @param  string $context View or edit context.
587 587
 	 * @return string
588 588
 	 */
589
-	public function get_mode( $context = 'view' ) {
590
-        return $this->get_prop( 'mode', $context );
589
+	public function get_mode($context = 'view') {
590
+        return $this->get_prop('mode', $context);
591 591
     }
592 592
 
593 593
     /**
@@ -597,12 +597,12 @@  discard block
 block discarded – undo
597 597
 	 * @param  string $context View or edit context.
598 598
 	 * @return string
599 599
 	 */
600
-	public function get_path( $context = 'view' ) {
601
-        $path = $this->get_prop( 'path', $context );
600
+	public function get_path($context = 'view') {
601
+        $path = $this->get_prop('path', $context);
602 602
 
603
-        if ( empty( $path ) ) {
604
-            $prefix = apply_filters( 'wpinv_post_name_prefix', 'inv-', $this->post_type );
605
-            $path   = sanitize_title( $prefix . $this->get_id() );
603
+        if (empty($path)) {
604
+            $prefix = apply_filters('wpinv_post_name_prefix', 'inv-', $this->post_type);
605
+            $path   = sanitize_title($prefix . $this->get_id());
606 606
         }
607 607
 
608 608
 		return $path;
@@ -615,10 +615,10 @@  discard block
 block discarded – undo
615 615
 	 * @param  string $context View or edit context.
616 616
 	 * @return string
617 617
 	 */
618
-	public function get_name( $context = 'view' ) {
619
-        $name = $this->get_prop( 'title', $context );
618
+	public function get_name($context = 'view') {
619
+        $name = $this->get_prop('title', $context);
620 620
 
621
-		return empty( $name ) ? $this->get_number( $context ) : $name;
621
+		return empty($name) ? $this->get_number($context) : $name;
622 622
     }
623 623
 
624 624
     /**
@@ -628,8 +628,8 @@  discard block
 block discarded – undo
628 628
 	 * @param  string $context View or edit context.
629 629
 	 * @return string
630 630
 	 */
631
-	public function get_title( $context = 'view' ) {
632
-		return $this->get_name( $context );
631
+	public function get_title($context = 'view') {
632
+		return $this->get_name($context);
633 633
     }
634 634
 
635 635
     /**
@@ -639,8 +639,8 @@  discard block
 block discarded – undo
639 639
 	 * @param  string $context View or edit context.
640 640
 	 * @return string
641 641
 	 */
642
-	public function get_description( $context = 'view' ) {
643
-		return $this->get_prop( 'description', $context );
642
+	public function get_description($context = 'view') {
643
+		return $this->get_prop('description', $context);
644 644
     }
645 645
 
646 646
     /**
@@ -650,8 +650,8 @@  discard block
 block discarded – undo
650 650
 	 * @param  string $context View or edit context.
651 651
 	 * @return string
652 652
 	 */
653
-	public function get_excerpt( $context = 'view' ) {
654
-		return $this->get_description( $context );
653
+	public function get_excerpt($context = 'view') {
654
+		return $this->get_description($context);
655 655
     }
656 656
 
657 657
     /**
@@ -661,8 +661,8 @@  discard block
 block discarded – undo
661 661
 	 * @param  string $context View or edit context.
662 662
 	 * @return string
663 663
 	 */
664
-	public function get_summary( $context = 'view' ) {
665
-		return $this->get_description( $context );
664
+	public function get_summary($context = 'view') {
665
+		return $this->get_description($context);
666 666
     }
667 667
 
668 668
     /**
@@ -672,25 +672,25 @@  discard block
 block discarded – undo
672 672
      * @param  string $context View or edit context.
673 673
 	 * @return array
674 674
 	 */
675
-    public function get_user_info( $context = 'view' ) {
675
+    public function get_user_info($context = 'view') {
676 676
 
677 677
         $user_info = array(
678
-            'user_id'    => $this->get_user_id( $context ),
679
-            'email'      => $this->get_email( $context ),
680
-            'first_name' => $this->get_first_name( $context ),
681
-            'last_name'  => $this->get_last_name( $context ),
682
-            'address'    => $this->get_address( $context ),
683
-            'phone'      => $this->get_phone( $context ),
684
-            'city'       => $this->get_city( $context ),
685
-            'country'    => $this->get_country( $context ),
686
-            'state'      => $this->get_state( $context ),
687
-            'zip'        => $this->get_zip( $context ),
688
-            'company'    => $this->get_company( $context ),
689
-            'vat_number' => $this->get_vat_number( $context ),
690
-            'discount'   => $this->get_discount_code( $context ),
678
+            'user_id'    => $this->get_user_id($context),
679
+            'email'      => $this->get_email($context),
680
+            'first_name' => $this->get_first_name($context),
681
+            'last_name'  => $this->get_last_name($context),
682
+            'address'    => $this->get_address($context),
683
+            'phone'      => $this->get_phone($context),
684
+            'city'       => $this->get_city($context),
685
+            'country'    => $this->get_country($context),
686
+            'state'      => $this->get_state($context),
687
+            'zip'        => $this->get_zip($context),
688
+            'company'    => $this->get_company($context),
689
+            'vat_number' => $this->get_vat_number($context),
690
+            'discount'   => $this->get_discount_code($context),
691 691
 		);
692 692
 
693
-		return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this );
693
+		return apply_filters('wpinv_user_info', $user_info, $this->get_id(), $this);
694 694
 
695 695
     }
696 696
 
@@ -701,8 +701,8 @@  discard block
 block discarded – undo
701 701
 	 * @param  string $context View or edit context.
702 702
 	 * @return int
703 703
 	 */
704
-	public function get_author( $context = 'view' ) {
705
-		return (int) $this->get_prop( 'author', $context );
704
+	public function get_author($context = 'view') {
705
+		return (int) $this->get_prop('author', $context);
706 706
     }
707 707
 
708 708
     /**
@@ -712,8 +712,8 @@  discard block
 block discarded – undo
712 712
 	 * @param  string $context View or edit context.
713 713
 	 * @return int
714 714
 	 */
715
-	public function get_user_id( $context = 'view' ) {
716
-		return $this->get_author( $context );
715
+	public function get_user_id($context = 'view') {
716
+		return $this->get_author($context);
717 717
     }
718 718
 
719 719
      /**
@@ -723,8 +723,8 @@  discard block
 block discarded – undo
723 723
 	 * @param  string $context View or edit context.
724 724
 	 * @return int
725 725
 	 */
726
-	public function get_customer_id( $context = 'view' ) {
727
-		return $this->get_author( $context );
726
+	public function get_customer_id($context = 'view') {
727
+		return $this->get_author($context);
728 728
     }
729 729
 
730 730
     /**
@@ -734,8 +734,8 @@  discard block
 block discarded – undo
734 734
 	 * @param  string $context View or edit context.
735 735
 	 * @return string
736 736
 	 */
737
-	public function get_ip( $context = 'view' ) {
738
-		return $this->get_prop( 'user_ip', $context );
737
+	public function get_ip($context = 'view') {
738
+		return $this->get_prop('user_ip', $context);
739 739
     }
740 740
 
741 741
     /**
@@ -745,8 +745,8 @@  discard block
 block discarded – undo
745 745
 	 * @param  string $context View or edit context.
746 746
 	 * @return string
747 747
 	 */
748
-	public function get_user_ip( $context = 'view' ) {
749
-		return $this->get_ip( $context );
748
+	public function get_user_ip($context = 'view') {
749
+		return $this->get_ip($context);
750 750
     }
751 751
 
752 752
      /**
@@ -756,8 +756,8 @@  discard block
 block discarded – undo
756 756
 	 * @param  string $context View or edit context.
757 757
 	 * @return string
758 758
 	 */
759
-	public function get_customer_ip( $context = 'view' ) {
760
-		return $this->get_ip( $context );
759
+	public function get_customer_ip($context = 'view') {
760
+		return $this->get_ip($context);
761 761
     }
762 762
 
763 763
     /**
@@ -767,8 +767,8 @@  discard block
 block discarded – undo
767 767
 	 * @param  string $context View or edit context.
768 768
 	 * @return string
769 769
 	 */
770
-	public function get_first_name( $context = 'view' ) {
771
-		return $this->get_prop( 'first_name', $context );
770
+	public function get_first_name($context = 'view') {
771
+		return $this->get_prop('first_name', $context);
772 772
     }
773 773
 
774 774
     /**
@@ -778,8 +778,8 @@  discard block
 block discarded – undo
778 778
 	 * @param  string $context View or edit context.
779 779
 	 * @return int
780 780
 	 */
781
-	public function get_user_first_name( $context = 'view' ) {
782
-		return $this->get_first_name( $context );
781
+	public function get_user_first_name($context = 'view') {
782
+		return $this->get_first_name($context);
783 783
     }
784 784
 
785 785
      /**
@@ -789,8 +789,8 @@  discard block
 block discarded – undo
789 789
 	 * @param  string $context View or edit context.
790 790
 	 * @return int
791 791
 	 */
792
-	public function get_customer_first_name( $context = 'view' ) {
793
-		return $this->get_first_name( $context );
792
+	public function get_customer_first_name($context = 'view') {
793
+		return $this->get_first_name($context);
794 794
     }
795 795
 
796 796
     /**
@@ -800,8 +800,8 @@  discard block
 block discarded – undo
800 800
 	 * @param  string $context View or edit context.
801 801
 	 * @return string
802 802
 	 */
803
-	public function get_last_name( $context = 'view' ) {
804
-		return $this->get_prop( 'last_name', $context );
803
+	public function get_last_name($context = 'view') {
804
+		return $this->get_prop('last_name', $context);
805 805
     }
806 806
 
807 807
     /**
@@ -811,8 +811,8 @@  discard block
 block discarded – undo
811 811
 	 * @param  string $context View or edit context.
812 812
 	 * @return int
813 813
 	 */
814
-	public function get_user_last_name( $context = 'view' ) {
815
-		return $this->get_last_name( $context );
814
+	public function get_user_last_name($context = 'view') {
815
+		return $this->get_last_name($context);
816 816
     }
817 817
 
818 818
     /**
@@ -822,8 +822,8 @@  discard block
 block discarded – undo
822 822
 	 * @param  string $context View or edit context.
823 823
 	 * @return int
824 824
 	 */
825
-	public function get_customer_last_name( $context = 'view' ) {
826
-		return $this->get_last_name( $context );
825
+	public function get_customer_last_name($context = 'view') {
826
+		return $this->get_last_name($context);
827 827
     }
828 828
 
829 829
     /**
@@ -833,8 +833,8 @@  discard block
 block discarded – undo
833 833
 	 * @param  string $context View or edit context.
834 834
 	 * @return string
835 835
 	 */
836
-	public function get_full_name( $context = 'view' ) {
837
-		return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) );
836
+	public function get_full_name($context = 'view') {
837
+		return trim($this->get_first_name($context) . ' ' . $this->get_last_name($context));
838 838
     }
839 839
 
840 840
     /**
@@ -844,8 +844,8 @@  discard block
 block discarded – undo
844 844
 	 * @param  string $context View or edit context.
845 845
 	 * @return int
846 846
 	 */
847
-	public function get_user_full_name( $context = 'view' ) {
848
-		return $this->get_full_name( $context );
847
+	public function get_user_full_name($context = 'view') {
848
+		return $this->get_full_name($context);
849 849
     }
850 850
 
851 851
     /**
@@ -855,8 +855,8 @@  discard block
 block discarded – undo
855 855
 	 * @param  string $context View or edit context.
856 856
 	 * @return int
857 857
 	 */
858
-	public function get_customer_full_name( $context = 'view' ) {
859
-		return $this->get_full_name( $context );
858
+	public function get_customer_full_name($context = 'view') {
859
+		return $this->get_full_name($context);
860 860
     }
861 861
 
862 862
     /**
@@ -866,8 +866,8 @@  discard block
 block discarded – undo
866 866
 	 * @param  string $context View or edit context.
867 867
 	 * @return string
868 868
 	 */
869
-	public function get_phone( $context = 'view' ) {
870
-		return $this->get_prop( 'phone', $context );
869
+	public function get_phone($context = 'view') {
870
+		return $this->get_prop('phone', $context);
871 871
     }
872 872
 
873 873
     /**
@@ -877,8 +877,8 @@  discard block
 block discarded – undo
877 877
 	 * @param  string $context View or edit context.
878 878
 	 * @return int
879 879
 	 */
880
-	public function get_phone_number( $context = 'view' ) {
881
-		return $this->get_phone( $context );
880
+	public function get_phone_number($context = 'view') {
881
+		return $this->get_phone($context);
882 882
     }
883 883
 
884 884
     /**
@@ -888,8 +888,8 @@  discard block
 block discarded – undo
888 888
 	 * @param  string $context View or edit context.
889 889
 	 * @return int
890 890
 	 */
891
-	public function get_user_phone( $context = 'view' ) {
892
-		return $this->get_phone( $context );
891
+	public function get_user_phone($context = 'view') {
892
+		return $this->get_phone($context);
893 893
     }
894 894
 
895 895
     /**
@@ -899,8 +899,8 @@  discard block
 block discarded – undo
899 899
 	 * @param  string $context View or edit context.
900 900
 	 * @return int
901 901
 	 */
902
-	public function get_customer_phone( $context = 'view' ) {
903
-		return $this->get_phone( $context );
902
+	public function get_customer_phone($context = 'view') {
903
+		return $this->get_phone($context);
904 904
     }
905 905
 
906 906
     /**
@@ -910,8 +910,8 @@  discard block
 block discarded – undo
910 910
 	 * @param  string $context View or edit context.
911 911
 	 * @return string
912 912
 	 */
913
-	public function get_email( $context = 'view' ) {
914
-		return $this->get_prop( 'email', $context );
913
+	public function get_email($context = 'view') {
914
+		return $this->get_prop('email', $context);
915 915
     }
916 916
 
917 917
     /**
@@ -921,8 +921,8 @@  discard block
 block discarded – undo
921 921
 	 * @param  string $context View or edit context.
922 922
 	 * @return string
923 923
 	 */
924
-	public function get_email_address( $context = 'view' ) {
925
-		return $this->get_email( $context );
924
+	public function get_email_address($context = 'view') {
925
+		return $this->get_email($context);
926 926
     }
927 927
 
928 928
     /**
@@ -932,8 +932,8 @@  discard block
 block discarded – undo
932 932
 	 * @param  string $context View or edit context.
933 933
 	 * @return int
934 934
 	 */
935
-	public function get_user_email( $context = 'view' ) {
936
-		return $this->get_email( $context );
935
+	public function get_user_email($context = 'view') {
936
+		return $this->get_email($context);
937 937
     }
938 938
 
939 939
     /**
@@ -943,8 +943,8 @@  discard block
 block discarded – undo
943 943
 	 * @param  string $context View or edit context.
944 944
 	 * @return int
945 945
 	 */
946
-	public function get_customer_email( $context = 'view' ) {
947
-		return $this->get_email( $context );
946
+	public function get_customer_email($context = 'view') {
947
+		return $this->get_email($context);
948 948
     }
949 949
 
950 950
     /**
@@ -954,9 +954,9 @@  discard block
 block discarded – undo
954 954
 	 * @param  string $context View or edit context.
955 955
 	 * @return string
956 956
 	 */
957
-	public function get_country( $context = 'view' ) {
958
-		$country = $this->get_prop( 'country', $context );
959
-		return empty( $country ) ? wpinv_get_default_country() : $country;
957
+	public function get_country($context = 'view') {
958
+		$country = $this->get_prop('country', $context);
959
+		return empty($country) ? wpinv_get_default_country() : $country;
960 960
     }
961 961
 
962 962
     /**
@@ -966,8 +966,8 @@  discard block
 block discarded – undo
966 966
 	 * @param  string $context View or edit context.
967 967
 	 * @return int
968 968
 	 */
969
-	public function get_user_country( $context = 'view' ) {
970
-		return $this->get_country( $context );
969
+	public function get_user_country($context = 'view') {
970
+		return $this->get_country($context);
971 971
     }
972 972
 
973 973
     /**
@@ -977,8 +977,8 @@  discard block
 block discarded – undo
977 977
 	 * @param  string $context View or edit context.
978 978
 	 * @return int
979 979
 	 */
980
-	public function get_customer_country( $context = 'view' ) {
981
-		return $this->get_country( $context );
980
+	public function get_customer_country($context = 'view') {
981
+		return $this->get_country($context);
982 982
     }
983 983
 
984 984
     /**
@@ -988,9 +988,9 @@  discard block
 block discarded – undo
988 988
 	 * @param  string $context View or edit context.
989 989
 	 * @return string
990 990
 	 */
991
-	public function get_state( $context = 'view' ) {
992
-		$state = $this->get_prop( 'state', $context );
993
-		return empty( $state ) ? wpinv_get_default_state() : $state;
991
+	public function get_state($context = 'view') {
992
+		$state = $this->get_prop('state', $context);
993
+		return empty($state) ? wpinv_get_default_state() : $state;
994 994
     }
995 995
 
996 996
     /**
@@ -1000,8 +1000,8 @@  discard block
 block discarded – undo
1000 1000
 	 * @param  string $context View or edit context.
1001 1001
 	 * @return int
1002 1002
 	 */
1003
-	public function get_user_state( $context = 'view' ) {
1004
-		return $this->get_state( $context );
1003
+	public function get_user_state($context = 'view') {
1004
+		return $this->get_state($context);
1005 1005
     }
1006 1006
 
1007 1007
     /**
@@ -1011,8 +1011,8 @@  discard block
 block discarded – undo
1011 1011
 	 * @param  string $context View or edit context.
1012 1012
 	 * @return int
1013 1013
 	 */
1014
-	public function get_customer_state( $context = 'view' ) {
1015
-		return $this->get_state( $context );
1014
+	public function get_customer_state($context = 'view') {
1015
+		return $this->get_state($context);
1016 1016
     }
1017 1017
 
1018 1018
     /**
@@ -1022,8 +1022,8 @@  discard block
 block discarded – undo
1022 1022
 	 * @param  string $context View or edit context.
1023 1023
 	 * @return string
1024 1024
 	 */
1025
-	public function get_city( $context = 'view' ) {
1026
-		return $this->get_prop( 'city', $context );
1025
+	public function get_city($context = 'view') {
1026
+		return $this->get_prop('city', $context);
1027 1027
     }
1028 1028
 
1029 1029
     /**
@@ -1033,8 +1033,8 @@  discard block
 block discarded – undo
1033 1033
 	 * @param  string $context View or edit context.
1034 1034
 	 * @return string
1035 1035
 	 */
1036
-	public function get_user_city( $context = 'view' ) {
1037
-		return $this->get_city( $context );
1036
+	public function get_user_city($context = 'view') {
1037
+		return $this->get_city($context);
1038 1038
     }
1039 1039
 
1040 1040
     /**
@@ -1044,8 +1044,8 @@  discard block
 block discarded – undo
1044 1044
 	 * @param  string $context View or edit context.
1045 1045
 	 * @return string
1046 1046
 	 */
1047
-	public function get_customer_city( $context = 'view' ) {
1048
-		return $this->get_city( $context );
1047
+	public function get_customer_city($context = 'view') {
1048
+		return $this->get_city($context);
1049 1049
     }
1050 1050
 
1051 1051
     /**
@@ -1055,8 +1055,8 @@  discard block
 block discarded – undo
1055 1055
 	 * @param  string $context View or edit context.
1056 1056
 	 * @return string
1057 1057
 	 */
1058
-	public function get_zip( $context = 'view' ) {
1059
-		return $this->get_prop( 'zip', $context );
1058
+	public function get_zip($context = 'view') {
1059
+		return $this->get_prop('zip', $context);
1060 1060
     }
1061 1061
 
1062 1062
     /**
@@ -1066,8 +1066,8 @@  discard block
 block discarded – undo
1066 1066
 	 * @param  string $context View or edit context.
1067 1067
 	 * @return string
1068 1068
 	 */
1069
-	public function get_user_zip( $context = 'view' ) {
1070
-		return $this->get_zip( $context );
1069
+	public function get_user_zip($context = 'view') {
1070
+		return $this->get_zip($context);
1071 1071
     }
1072 1072
 
1073 1073
     /**
@@ -1077,8 +1077,8 @@  discard block
 block discarded – undo
1077 1077
 	 * @param  string $context View or edit context.
1078 1078
 	 * @return string
1079 1079
 	 */
1080
-	public function get_customer_zip( $context = 'view' ) {
1081
-		return $this->get_zip( $context );
1080
+	public function get_customer_zip($context = 'view') {
1081
+		return $this->get_zip($context);
1082 1082
     }
1083 1083
 
1084 1084
     /**
@@ -1088,8 +1088,8 @@  discard block
 block discarded – undo
1088 1088
 	 * @param  string $context View or edit context.
1089 1089
 	 * @return string
1090 1090
 	 */
1091
-	public function get_company( $context = 'view' ) {
1092
-		return $this->get_prop( 'company', $context );
1091
+	public function get_company($context = 'view') {
1092
+		return $this->get_prop('company', $context);
1093 1093
     }
1094 1094
 
1095 1095
     /**
@@ -1099,8 +1099,8 @@  discard block
 block discarded – undo
1099 1099
 	 * @param  string $context View or edit context.
1100 1100
 	 * @return string
1101 1101
 	 */
1102
-	public function get_user_company( $context = 'view' ) {
1103
-		return $this->get_company( $context );
1102
+	public function get_user_company($context = 'view') {
1103
+		return $this->get_company($context);
1104 1104
     }
1105 1105
 
1106 1106
     /**
@@ -1110,8 +1110,8 @@  discard block
 block discarded – undo
1110 1110
 	 * @param  string $context View or edit context.
1111 1111
 	 * @return string
1112 1112
 	 */
1113
-	public function get_customer_company( $context = 'view' ) {
1114
-		return $this->get_company( $context );
1113
+	public function get_customer_company($context = 'view') {
1114
+		return $this->get_company($context);
1115 1115
     }
1116 1116
 
1117 1117
     /**
@@ -1121,8 +1121,8 @@  discard block
 block discarded – undo
1121 1121
 	 * @param  string $context View or edit context.
1122 1122
 	 * @return string
1123 1123
 	 */
1124
-	public function get_vat_number( $context = 'view' ) {
1125
-		return $this->get_prop( 'vat_number', $context );
1124
+	public function get_vat_number($context = 'view') {
1125
+		return $this->get_prop('vat_number', $context);
1126 1126
     }
1127 1127
 
1128 1128
     /**
@@ -1132,8 +1132,8 @@  discard block
 block discarded – undo
1132 1132
 	 * @param  string $context View or edit context.
1133 1133
 	 * @return string
1134 1134
 	 */
1135
-	public function get_user_vat_number( $context = 'view' ) {
1136
-		return $this->get_vat_number( $context );
1135
+	public function get_user_vat_number($context = 'view') {
1136
+		return $this->get_vat_number($context);
1137 1137
     }
1138 1138
 
1139 1139
     /**
@@ -1143,8 +1143,8 @@  discard block
 block discarded – undo
1143 1143
 	 * @param  string $context View or edit context.
1144 1144
 	 * @return string
1145 1145
 	 */
1146
-	public function get_customer_vat_number( $context = 'view' ) {
1147
-		return $this->get_vat_number( $context );
1146
+	public function get_customer_vat_number($context = 'view') {
1147
+		return $this->get_vat_number($context);
1148 1148
     }
1149 1149
 
1150 1150
     /**
@@ -1154,8 +1154,8 @@  discard block
 block discarded – undo
1154 1154
 	 * @param  string $context View or edit context.
1155 1155
 	 * @return string
1156 1156
 	 */
1157
-	public function get_vat_rate( $context = 'view' ) {
1158
-		return $this->get_prop( 'vat_rate', $context );
1157
+	public function get_vat_rate($context = 'view') {
1158
+		return $this->get_prop('vat_rate', $context);
1159 1159
     }
1160 1160
 
1161 1161
     /**
@@ -1165,8 +1165,8 @@  discard block
 block discarded – undo
1165 1165
 	 * @param  string $context View or edit context.
1166 1166
 	 * @return string
1167 1167
 	 */
1168
-	public function get_user_vat_rate( $context = 'view' ) {
1169
-		return $this->get_vat_rate( $context );
1168
+	public function get_user_vat_rate($context = 'view') {
1169
+		return $this->get_vat_rate($context);
1170 1170
     }
1171 1171
 
1172 1172
     /**
@@ -1176,8 +1176,8 @@  discard block
 block discarded – undo
1176 1176
 	 * @param  string $context View or edit context.
1177 1177
 	 * @return string
1178 1178
 	 */
1179
-	public function get_customer_vat_rate( $context = 'view' ) {
1180
-		return $this->get_vat_rate( $context );
1179
+	public function get_customer_vat_rate($context = 'view') {
1180
+		return $this->get_vat_rate($context);
1181 1181
     }
1182 1182
 
1183 1183
     /**
@@ -1187,8 +1187,8 @@  discard block
 block discarded – undo
1187 1187
 	 * @param  string $context View or edit context.
1188 1188
 	 * @return string
1189 1189
 	 */
1190
-	public function get_address( $context = 'view' ) {
1191
-		return $this->get_prop( 'address', $context );
1190
+	public function get_address($context = 'view') {
1191
+		return $this->get_prop('address', $context);
1192 1192
     }
1193 1193
 
1194 1194
     /**
@@ -1198,8 +1198,8 @@  discard block
 block discarded – undo
1198 1198
 	 * @param  string $context View or edit context.
1199 1199
 	 * @return string
1200 1200
 	 */
1201
-	public function get_user_address( $context = 'view' ) {
1202
-		return $this->get_address( $context );
1201
+	public function get_user_address($context = 'view') {
1202
+		return $this->get_address($context);
1203 1203
     }
1204 1204
 
1205 1205
     /**
@@ -1209,8 +1209,8 @@  discard block
 block discarded – undo
1209 1209
 	 * @param  string $context View or edit context.
1210 1210
 	 * @return string
1211 1211
 	 */
1212
-	public function get_customer_address( $context = 'view' ) {
1213
-		return $this->get_address( $context );
1212
+	public function get_customer_address($context = 'view') {
1213
+		return $this->get_address($context);
1214 1214
     }
1215 1215
 
1216 1216
     /**
@@ -1220,8 +1220,8 @@  discard block
 block discarded – undo
1220 1220
 	 * @param  string $context View or edit context.
1221 1221
 	 * @return bool
1222 1222
 	 */
1223
-	public function get_is_viewed( $context = 'view' ) {
1224
-		return (bool) $this->get_prop( 'is_viewed', $context );
1223
+	public function get_is_viewed($context = 'view') {
1224
+		return (bool) $this->get_prop('is_viewed', $context);
1225 1225
 	}
1226 1226
 
1227 1227
 	/**
@@ -1231,8 +1231,8 @@  discard block
 block discarded – undo
1231 1231
 	 * @param  string $context View or edit context.
1232 1232
 	 * @return bool
1233 1233
 	 */
1234
-	public function get_email_cc( $context = 'view' ) {
1235
-		return $this->get_prop( 'email_cc', $context );
1234
+	public function get_email_cc($context = 'view') {
1235
+		return $this->get_prop('email_cc', $context);
1236 1236
 	}
1237 1237
 
1238 1238
 	/**
@@ -1242,8 +1242,8 @@  discard block
 block discarded – undo
1242 1242
 	 * @param  string $context View or edit context.
1243 1243
 	 * @return bool
1244 1244
 	 */
1245
-	public function get_template( $context = 'view' ) {
1246
-		return $this->get_prop( 'template', $context );
1245
+	public function get_template($context = 'view') {
1246
+		return $this->get_prop('template', $context);
1247 1247
 	}
1248 1248
 
1249 1249
 	/**
@@ -1253,8 +1253,8 @@  discard block
 block discarded – undo
1253 1253
 	 * @param  string $context View or edit context.
1254 1254
 	 * @return bool
1255 1255
 	 */
1256
-	public function get_address_confirmed( $context = 'view' ) {
1257
-		return (bool) $this->get_prop( 'address_confirmed', $context );
1256
+	public function get_address_confirmed($context = 'view') {
1257
+		return (bool) $this->get_prop('address_confirmed', $context);
1258 1258
     }
1259 1259
 
1260 1260
     /**
@@ -1264,8 +1264,8 @@  discard block
 block discarded – undo
1264 1264
 	 * @param  string $context View or edit context.
1265 1265
 	 * @return bool
1266 1266
 	 */
1267
-	public function get_user_address_confirmed( $context = 'view' ) {
1268
-		return $this->get_address_confirmed( $context );
1267
+	public function get_user_address_confirmed($context = 'view') {
1268
+		return $this->get_address_confirmed($context);
1269 1269
     }
1270 1270
 
1271 1271
     /**
@@ -1275,8 +1275,8 @@  discard block
 block discarded – undo
1275 1275
 	 * @param  string $context View or edit context.
1276 1276
 	 * @return bool
1277 1277
 	 */
1278
-	public function get_customer_address_confirmed( $context = 'view' ) {
1279
-		return $this->get_address_confirmed( $context );
1278
+	public function get_customer_address_confirmed($context = 'view') {
1279
+		return $this->get_address_confirmed($context);
1280 1280
     }
1281 1281
 
1282 1282
     /**
@@ -1286,12 +1286,12 @@  discard block
 block discarded – undo
1286 1286
 	 * @param  string $context View or edit context.
1287 1287
 	 * @return float
1288 1288
 	 */
1289
-	public function get_subtotal( $context = 'view' ) {
1290
-        $subtotal = (float) $this->get_prop( 'subtotal', $context );
1289
+	public function get_subtotal($context = 'view') {
1290
+        $subtotal = (float) $this->get_prop('subtotal', $context);
1291 1291
 
1292 1292
         // Backwards compatibility.
1293
-        if ( is_bool( $context ) && $context ) {
1294
-            return wpinv_price( wpinv_format_amount( $subtotal ), $this->get_currency() );
1293
+        if (is_bool($context) && $context) {
1294
+            return wpinv_price(wpinv_format_amount($subtotal), $this->get_currency());
1295 1295
         }
1296 1296
 
1297 1297
         return $subtotal;
@@ -1304,8 +1304,8 @@  discard block
 block discarded – undo
1304 1304
 	 * @param  string $context View or edit context.
1305 1305
 	 * @return float
1306 1306
 	 */
1307
-	public function get_total_discount( $context = 'view' ) {
1308
-		return (float) $this->get_prop( 'total_discount', $context );
1307
+	public function get_total_discount($context = 'view') {
1308
+		return (float) $this->get_prop('total_discount', $context);
1309 1309
     }
1310 1310
 
1311 1311
     /**
@@ -1315,18 +1315,18 @@  discard block
 block discarded – undo
1315 1315
 	 * @param  string $context View or edit context.
1316 1316
 	 * @return float
1317 1317
 	 */
1318
-	public function get_total_tax( $context = 'view' ) {
1319
-		return (float) $this->get_prop( 'total_tax', $context );
1318
+	public function get_total_tax($context = 'view') {
1319
+		return (float) $this->get_prop('total_tax', $context);
1320 1320
 	}
1321 1321
 
1322 1322
 	/**
1323 1323
 	 * @deprecated
1324 1324
 	 */
1325
-	public function get_final_tax( $currency = false ) {
1325
+	public function get_final_tax($currency = false) {
1326 1326
 		$tax = $this->get_total_tax();
1327 1327
 
1328
-        if ( $currency ) {
1329
-			return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() );
1328
+        if ($currency) {
1329
+			return wpinv_price(wpinv_format_amount($tax, NULL, false), $this->get_currency());
1330 1330
         }
1331 1331
 
1332 1332
         return $tax;
@@ -1339,8 +1339,8 @@  discard block
 block discarded – undo
1339 1339
 	 * @param  string $context View or edit context.
1340 1340
 	 * @return float
1341 1341
 	 */
1342
-	public function get_total_fees( $context = 'view' ) {
1343
-		return (float) $this->get_prop( 'total_fees', $context );
1342
+	public function get_total_fees($context = 'view') {
1343
+		return (float) $this->get_prop('total_fees', $context);
1344 1344
     }
1345 1345
 
1346 1346
     /**
@@ -1350,8 +1350,8 @@  discard block
 block discarded – undo
1350 1350
 	 * @param  string $context View or edit context.
1351 1351
 	 * @return float
1352 1352
 	 */
1353
-	public function get_fees_total( $context = 'view' ) {
1354
-		return $this->get_total_fees( $context );
1353
+	public function get_fees_total($context = 'view') {
1354
+		return $this->get_total_fees($context);
1355 1355
     }
1356 1356
 
1357 1357
     /**
@@ -1362,7 +1362,7 @@  discard block
 block discarded – undo
1362 1362
 	 */
1363 1363
 	public function get_total() {
1364 1364
 		$total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total();
1365
-		return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this  );
1365
+		return apply_filters('getpaid_get_invoice_total_amount', $total, $this);
1366 1366
     }
1367 1367
 
1368 1368
     /**
@@ -1374,7 +1374,7 @@  discard block
 block discarded – undo
1374 1374
 	 */
1375 1375
     public function get_initial_total() {
1376 1376
 
1377
-		if ( empty( $this->totals ) ) {
1377
+		if (empty($this->totals)) {
1378 1378
 			$this->recalculate_total();
1379 1379
 		}
1380 1380
 
@@ -1384,11 +1384,11 @@  discard block
 block discarded – undo
1384 1384
 		$subtotal = $this->totals['subtotal']['initial'];
1385 1385
 		$total    = $tax + $fee - $discount + $subtotal;
1386 1386
 
1387
-		if ( 0 > $total ) {
1387
+		if (0 > $total) {
1388 1388
 			$total = 0;
1389 1389
 		}
1390 1390
 
1391
-        return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this );
1391
+        return apply_filters('wpinv_get_initial_invoice_total', $total, $this);
1392 1392
 	}
1393 1393
 
1394 1394
 	/**
@@ -1400,7 +1400,7 @@  discard block
 block discarded – undo
1400 1400
 	 */
1401 1401
     public function get_recurring_total() {
1402 1402
 
1403
-		if ( empty( $this->totals ) ) {
1403
+		if (empty($this->totals)) {
1404 1404
 			$this->recalculate_total();
1405 1405
 		}
1406 1406
 
@@ -1410,11 +1410,11 @@  discard block
 block discarded – undo
1410 1410
 		$subtotal = $this->totals['subtotal']['recurring'];
1411 1411
 		$total    = $tax + $fee - $discount + $subtotal;
1412 1412
 
1413
-		if ( 0 > $total ) {
1413
+		if (0 > $total) {
1414 1414
 			$total = 0;
1415 1415
 		}
1416 1416
 
1417
-        return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this );
1417
+        return apply_filters('wpinv_get_recurring_invoice_total', $total, $this);
1418 1418
 	}
1419 1419
 
1420 1420
 	/**
@@ -1425,10 +1425,10 @@  discard block
 block discarded – undo
1425 1425
 	 * @param string $currency Whether to include the currency.
1426 1426
      * @return float
1427 1427
 	 */
1428
-    public function get_recurring_details( $field = '', $currency = false ) {
1428
+    public function get_recurring_details($field = '', $currency = false) {
1429 1429
 
1430 1430
 		// Maybe recalculate totals.
1431
-		if ( empty( $this->totals ) ) {
1431
+		if (empty($this->totals)) {
1432 1432
 			$this->recalculate_total();
1433 1433
 		}
1434 1434
 
@@ -1448,8 +1448,8 @@  discard block
 block discarded – undo
1448 1448
 			$currency
1449 1449
 		);
1450 1450
 
1451
-        if ( isset( $data[$field] ) ) {
1452
-            return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
1451
+        if (isset($data[$field])) {
1452
+            return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]);
1453 1453
         }
1454 1454
 
1455 1455
         return $data;
@@ -1462,8 +1462,8 @@  discard block
 block discarded – undo
1462 1462
 	 * @param  string $context View or edit context.
1463 1463
 	 * @return array
1464 1464
 	 */
1465
-	public function get_fees( $context = 'view' ) {
1466
-		return wpinv_parse_list( $this->get_prop( 'fees', $context ) );
1465
+	public function get_fees($context = 'view') {
1466
+		return wpinv_parse_list($this->get_prop('fees', $context));
1467 1467
     }
1468 1468
 
1469 1469
     /**
@@ -1473,8 +1473,8 @@  discard block
 block discarded – undo
1473 1473
 	 * @param  string $context View or edit context.
1474 1474
 	 * @return array
1475 1475
 	 */
1476
-	public function get_discounts( $context = 'view' ) {
1477
-		return wpinv_parse_list( $this->get_prop( 'discounts', $context ) );
1476
+	public function get_discounts($context = 'view') {
1477
+		return wpinv_parse_list($this->get_prop('discounts', $context));
1478 1478
     }
1479 1479
 
1480 1480
     /**
@@ -1484,8 +1484,8 @@  discard block
 block discarded – undo
1484 1484
 	 * @param  string $context View or edit context.
1485 1485
 	 * @return array
1486 1486
 	 */
1487
-	public function get_taxes( $context = 'view' ) {
1488
-		return wpinv_parse_list( $this->get_prop( 'taxes', $context ) );
1487
+	public function get_taxes($context = 'view') {
1488
+		return wpinv_parse_list($this->get_prop('taxes', $context));
1489 1489
     }
1490 1490
 
1491 1491
     /**
@@ -1495,8 +1495,8 @@  discard block
 block discarded – undo
1495 1495
 	 * @param  string $context View or edit context.
1496 1496
 	 * @return GetPaid_Form_Item[]
1497 1497
 	 */
1498
-	public function get_items( $context = 'view' ) {
1499
-        return $this->get_prop( 'items', $context );
1498
+	public function get_items($context = 'view') {
1499
+        return $this->get_prop('items', $context);
1500 1500
     }
1501 1501
 
1502 1502
     /**
@@ -1506,8 +1506,8 @@  discard block
 block discarded – undo
1506 1506
 	 * @param  string $context View or edit context.
1507 1507
 	 * @return int
1508 1508
 	 */
1509
-	public function get_payment_form( $context = 'view' ) {
1510
-		return intval( $this->get_prop( 'payment_form', $context ) );
1509
+	public function get_payment_form($context = 'view') {
1510
+		return intval($this->get_prop('payment_form', $context));
1511 1511
     }
1512 1512
 
1513 1513
     /**
@@ -1517,8 +1517,8 @@  discard block
 block discarded – undo
1517 1517
 	 * @param  string $context View or edit context.
1518 1518
 	 * @return string
1519 1519
 	 */
1520
-	public function get_submission_id( $context = 'view' ) {
1521
-		return $this->get_prop( 'submission_id', $context );
1520
+	public function get_submission_id($context = 'view') {
1521
+		return $this->get_prop('submission_id', $context);
1522 1522
     }
1523 1523
 
1524 1524
     /**
@@ -1528,8 +1528,8 @@  discard block
 block discarded – undo
1528 1528
 	 * @param  string $context View or edit context.
1529 1529
 	 * @return string
1530 1530
 	 */
1531
-	public function get_discount_code( $context = 'view' ) {
1532
-		return $this->get_prop( 'discount_code', $context );
1531
+	public function get_discount_code($context = 'view') {
1532
+		return $this->get_prop('discount_code', $context);
1533 1533
     }
1534 1534
 
1535 1535
     /**
@@ -1539,8 +1539,8 @@  discard block
 block discarded – undo
1539 1539
 	 * @param  string $context View or edit context.
1540 1540
 	 * @return string
1541 1541
 	 */
1542
-	public function get_gateway( $context = 'view' ) {
1543
-		return $this->get_prop( 'gateway', $context );
1542
+	public function get_gateway($context = 'view') {
1543
+		return $this->get_prop('gateway', $context);
1544 1544
     }
1545 1545
 
1546 1546
     /**
@@ -1550,8 +1550,8 @@  discard block
 block discarded – undo
1550 1550
 	 * @return string
1551 1551
 	 */
1552 1552
     public function get_gateway_title() {
1553
-        $title =  wpinv_get_gateway_checkout_label( $this->get_gateway() );
1554
-        return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this );
1553
+        $title = wpinv_get_gateway_checkout_label($this->get_gateway());
1554
+        return apply_filters('wpinv_gateway_title', $title, $this->get_id(), $this);
1555 1555
     }
1556 1556
 
1557 1557
     /**
@@ -1561,8 +1561,8 @@  discard block
 block discarded – undo
1561 1561
 	 * @param  string $context View or edit context.
1562 1562
 	 * @return string
1563 1563
 	 */
1564
-	public function get_transaction_id( $context = 'view' ) {
1565
-		return $this->get_prop( 'transaction_id', $context );
1564
+	public function get_transaction_id($context = 'view') {
1565
+		return $this->get_prop('transaction_id', $context);
1566 1566
     }
1567 1567
 
1568 1568
     /**
@@ -1572,9 +1572,9 @@  discard block
 block discarded – undo
1572 1572
 	 * @param  string $context View or edit context.
1573 1573
 	 * @return string
1574 1574
 	 */
1575
-	public function get_currency( $context = 'view' ) {
1576
-        $currency = $this->get_prop( 'currency', $context );
1577
-        return empty( $currency ) ? wpinv_get_currency() : $currency;
1575
+	public function get_currency($context = 'view') {
1576
+        $currency = $this->get_prop('currency', $context);
1577
+        return empty($currency) ? wpinv_get_currency() : $currency;
1578 1578
     }
1579 1579
 
1580 1580
     /**
@@ -1584,8 +1584,8 @@  discard block
 block discarded – undo
1584 1584
 	 * @param  string $context View or edit context.
1585 1585
 	 * @return bool
1586 1586
 	 */
1587
-	public function get_disable_taxes( $context = 'view' ) {
1588
-        return (bool) $this->get_prop( 'disable_taxes', $context );
1587
+	public function get_disable_taxes($context = 'view') {
1588
+        return (bool) $this->get_prop('disable_taxes', $context);
1589 1589
     }
1590 1590
 
1591 1591
     /**
@@ -1595,12 +1595,12 @@  discard block
 block discarded – undo
1595 1595
 	 * @param  string $context View or edit context.
1596 1596
 	 * @return int
1597 1597
 	 */
1598
-    public function get_subscription_id( $context = 'view' ) {
1599
-        $subscription_id = $this->get_prop( 'subscription_id', $context );
1598
+    public function get_subscription_id($context = 'view') {
1599
+        $subscription_id = $this->get_prop('subscription_id', $context);
1600 1600
 
1601
-        if ( empty( $subscription_id ) && $this->is_renewal() ) {
1601
+        if (empty($subscription_id) && $this->is_renewal()) {
1602 1602
             $parent = $this->get_parent();
1603
-            return $parent->get_subscription_id( $context );
1603
+            return $parent->get_subscription_id($context);
1604 1604
         }
1605 1605
 
1606 1606
         return $subscription_id;
@@ -1613,20 +1613,20 @@  discard block
 block discarded – undo
1613 1613
 	 * @param  string $context View or edit context.
1614 1614
 	 * @return array
1615 1615
 	 */
1616
-    public function get_payment_meta( $context = 'view' ) {
1616
+    public function get_payment_meta($context = 'view') {
1617 1617
 
1618 1618
         return array(
1619
-            'price'        => $this->get_total( $context ),
1620
-            'date'         => $this->get_date_created( $context ),
1621
-            'user_email'   => $this->get_email( $context ),
1622
-            'invoice_key'  => $this->get_key( $context ),
1623
-            'currency'     => $this->get_currency( $context ),
1624
-            'items'        => $this->get_items( $context ),
1625
-            'user_info'    => $this->get_user_info( $context ),
1619
+            'price'        => $this->get_total($context),
1620
+            'date'         => $this->get_date_created($context),
1621
+            'user_email'   => $this->get_email($context),
1622
+            'invoice_key'  => $this->get_key($context),
1623
+            'currency'     => $this->get_currency($context),
1624
+            'items'        => $this->get_items($context),
1625
+            'user_info'    => $this->get_user_info($context),
1626 1626
             'cart_details' => $this->get_cart_details(),
1627
-            'status'       => $this->get_status( $context ),
1628
-            'fees'         => $this->get_fees( $context ),
1629
-            'taxes'        => $this->get_taxes( $context ),
1627
+            'status'       => $this->get_status($context),
1628
+            'fees'         => $this->get_fees($context),
1629
+            'taxes'        => $this->get_taxes($context),
1630 1630
         );
1631 1631
 
1632 1632
     }
@@ -1641,7 +1641,7 @@  discard block
 block discarded – undo
1641 1641
         $items        = $this->get_items();
1642 1642
         $cart_details = array();
1643 1643
 
1644
-        foreach ( $items as $item_id => $item ) {
1644
+        foreach ($items as $item_id => $item) {
1645 1645
             $cart_details[] = $item->prepare_data_for_saving();
1646 1646
         }
1647 1647
 
@@ -1653,11 +1653,11 @@  discard block
 block discarded – undo
1653 1653
 	 *
1654 1654
 	 * @return null|GetPaid_Form_Item
1655 1655
 	 */
1656
-	public function get_recurring( $object = false ) {
1656
+	public function get_recurring($object = false) {
1657 1657
 
1658 1658
 		// Are we returning an object?
1659
-        if ( $object ) {
1660
-            return $this->get_item( $this->recurring_item );
1659
+        if ($object) {
1660
+            return $this->get_item($this->recurring_item);
1661 1661
         }
1662 1662
 
1663 1663
         return $this->recurring_item;
@@ -1672,15 +1672,15 @@  discard block
 block discarded – undo
1672 1672
 	public function get_subscription_name() {
1673 1673
 
1674 1674
 		// Retrieve the recurring name
1675
-        $item = $this->get_recurring( true );
1675
+        $item = $this->get_recurring(true);
1676 1676
 
1677 1677
 		// Abort if it does not exist.
1678
-        if ( empty( $item ) ) {
1678
+        if (empty($item)) {
1679 1679
             return '';
1680 1680
         }
1681 1681
 
1682 1682
 		// Return the item name.
1683
-        return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this );
1683
+        return apply_filters('wpinv_invoice_get_subscription_name', $item->get_name(), $this);
1684 1684
 	}
1685 1685
 
1686 1686
 	/**
@@ -1690,9 +1690,9 @@  discard block
 block discarded – undo
1690 1690
 	 * @return string
1691 1691
 	 */
1692 1692
 	public function get_view_url() {
1693
-        $invoice_url = get_permalink( $this->get_id() );
1694
-		$invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
1695
-        return apply_filters( 'wpinv_get_view_url', $invoice_url, $this );
1693
+        $invoice_url = get_permalink($this->get_id());
1694
+		$invoice_url = add_query_arg('invoice_key', $this->get_key(), $invoice_url);
1695
+        return apply_filters('wpinv_get_view_url', $invoice_url, $this);
1696 1696
 	}
1697 1697
 
1698 1698
 	/**
@@ -1701,25 +1701,25 @@  discard block
 block discarded – undo
1701 1701
 	 * @since 1.0.19
1702 1702
 	 * @return string
1703 1703
 	 */
1704
-	public function get_checkout_payment_url( $deprecated = false, $secret = false ) {
1704
+	public function get_checkout_payment_url($deprecated = false, $secret = false) {
1705 1705
 
1706 1706
 		// Retrieve the checkout url.
1707 1707
         $pay_url = wpinv_get_checkout_uri();
1708 1708
 
1709 1709
 		// Maybe force ssl.
1710
-        if ( is_ssl() ) {
1711
-            $pay_url = str_replace( 'http:', 'https:', $pay_url );
1710
+        if (is_ssl()) {
1711
+            $pay_url = str_replace('http:', 'https:', $pay_url);
1712 1712
         }
1713 1713
 
1714 1714
 		// Add the invoice key.
1715
-		$pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url );
1715
+		$pay_url = add_query_arg('invoice_key', $this->get_key(), $pay_url);
1716 1716
 
1717 1717
 		// (Maybe?) add a secret
1718
-        if ( $secret ) {
1719
-            $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url );
1718
+        if ($secret) {
1719
+            $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key())), $pay_url);
1720 1720
         }
1721 1721
 
1722
-        return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret );
1722
+        return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret);
1723 1723
     }
1724 1724
 
1725 1725
     /**
@@ -1732,8 +1732,8 @@  discard block
 block discarded – undo
1732 1732
 	 * @param  string $context View or edit context.
1733 1733
 	 * @return mixed Value of the given invoice property (if set).
1734 1734
 	 */
1735
-	public function get( $key, $context = 'view' ) {
1736
-        return $this->get_prop( $key, $context );
1735
+	public function get($key, $context = 'view') {
1736
+        return $this->get_prop($key, $context);
1737 1737
 	}
1738 1738
 
1739 1739
     /*
@@ -1756,11 +1756,11 @@  discard block
 block discarded – undo
1756 1756
 	 * @param  mixed $value new value.
1757 1757
 	 * @return mixed Value of the given invoice property (if set).
1758 1758
 	 */
1759
-	public function set( $key, $value ) {
1759
+	public function set($key, $value) {
1760 1760
 
1761 1761
         $setter = "set_$key";
1762
-        if ( is_callable( array( $this, $setter ) ) ) {
1763
-            $this->{$setter}( $value );
1762
+        if (is_callable(array($this, $setter))) {
1763
+            $this->{$setter}($value);
1764 1764
         }
1765 1765
 
1766 1766
 	}
@@ -1774,35 +1774,35 @@  discard block
 block discarded – undo
1774 1774
 	 * @param bool   $manual_update Is this a manual status change?.
1775 1775
 	 * @return array details of change.
1776 1776
 	 */
1777
-	public function set_status( $new_status, $note = '', $manual_update = false ) {
1777
+	public function set_status($new_status, $note = '', $manual_update = false) {
1778 1778
 		$old_status = $this->get_status();
1779 1779
 
1780
-		$this->set_prop( 'status', $new_status );
1780
+		$this->set_prop('status', $new_status);
1781 1781
 
1782 1782
 		// If setting the status, ensure it's set to a valid status.
1783
-		if ( true === $this->object_read ) {
1783
+		if (true === $this->object_read) {
1784 1784
 
1785 1785
 			// Only allow valid new status.
1786
-			if ( ! array_key_exists( $new_status, wpinv_get_invoice_statuses( false, true ) ) ) {
1786
+			if (!array_key_exists($new_status, wpinv_get_invoice_statuses(false, true))) {
1787 1787
 				$new_status = 'wpi-pending';
1788 1788
 			}
1789 1789
 
1790 1790
 			// If the old status is set but unknown (e.g. draft) assume its pending for action usage.
1791
-			if ( $old_status && ! array_key_exists( $new_status, wpinv_get_invoice_statuses( false, true ) ) ) {
1791
+			if ($old_status && !array_key_exists($new_status, wpinv_get_invoice_statuses(false, true))) {
1792 1792
 				$old_status = 'wpi-pending';
1793 1793
 			}
1794 1794
 		}
1795 1795
 
1796
-		if ( true === $this->object_read && $old_status !== $new_status ) {
1796
+		if (true === $this->object_read && $old_status !== $new_status) {
1797 1797
 			$this->status_transition = array(
1798
-				'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
1798
+				'from'   => !empty($this->status_transition['from']) ? $this->status_transition['from'] : $old_status,
1799 1799
 				'to'     => $new_status,
1800 1800
 				'note'   => $note,
1801 1801
 				'manual' => (bool) $manual_update,
1802 1802
 			);
1803 1803
 
1804
-			if ( $manual_update ) {
1805
-				do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status );
1804
+			if ($manual_update) {
1805
+				do_action('getpaid_' . $this->object_type . '_edit_status', $this->get_id(), $new_status);
1806 1806
 			}
1807 1807
 
1808 1808
 			$this->maybe_set_date_paid();
@@ -1825,8 +1825,8 @@  discard block
 block discarded – undo
1825 1825
 	 */
1826 1826
 	public function maybe_set_date_paid() {
1827 1827
 
1828
-		if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) {
1829
-			$this->set_date_completed( current_time( 'mysql' ) );
1828
+		if (!$this->get_date_completed('edit') && $this->is_paid()) {
1829
+			$this->set_date_completed(current_time('mysql'));
1830 1830
 		}
1831 1831
 	}
1832 1832
 
@@ -1835,11 +1835,11 @@  discard block
 block discarded – undo
1835 1835
 	 *
1836 1836
 	 * @since 1.0.19
1837 1837
 	 */
1838
-	public function set_parent_id( $value ) {
1839
-		if ( $value && ( $value === $this->get_id() ) ) {
1838
+	public function set_parent_id($value) {
1839
+		if ($value && ($value === $this->get_id())) {
1840 1840
 			return;
1841 1841
 		}
1842
-		$this->set_prop( 'parent_id', absint( $value ) );
1842
+		$this->set_prop('parent_id', absint($value));
1843 1843
     }
1844 1844
 
1845 1845
     /**
@@ -1847,8 +1847,8 @@  discard block
 block discarded – undo
1847 1847
 	 *
1848 1848
 	 * @since 1.0.19
1849 1849
 	 */
1850
-	public function set_version( $value ) {
1851
-		$this->set_prop( 'version', $value );
1850
+	public function set_version($value) {
1851
+		$this->set_prop('version', $value);
1852 1852
     }
1853 1853
 
1854 1854
     /**
@@ -1858,15 +1858,15 @@  discard block
 block discarded – undo
1858 1858
 	 * @param string $value Value to set.
1859 1859
      * @return bool Whether or not the date was set.
1860 1860
 	 */
1861
-	public function set_date_created( $value ) {
1862
-        $date = strtotime( $value );
1861
+	public function set_date_created($value) {
1862
+        $date = strtotime($value);
1863 1863
 
1864
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
1865
-            $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) );
1864
+        if ($date && $value !== '0000-00-00 00:00:00') {
1865
+            $this->set_prop('date_created', date('Y-m-d H:i:s', $date));
1866 1866
             return true;
1867 1867
         }
1868 1868
 
1869
-        return $this->set_prop( 'date_created', '' );
1869
+        return $this->set_prop('date_created', '');
1870 1870
 
1871 1871
     }
1872 1872
 
@@ -1877,15 +1877,15 @@  discard block
 block discarded – undo
1877 1877
 	 * @param string $value Value to set.
1878 1878
      * @return bool Whether or not the date was set.
1879 1879
 	 */
1880
-	public function set_due_date( $value ) {
1881
-        $date = strtotime( $value );
1880
+	public function set_due_date($value) {
1881
+        $date = strtotime($value);
1882 1882
 
1883
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
1884
-            $this->set_prop( 'due_date', date( 'Y-m-d H:i:s', $date ) );
1883
+        if ($date && $value !== '0000-00-00 00:00:00') {
1884
+            $this->set_prop('due_date', date('Y-m-d H:i:s', $date));
1885 1885
             return true;
1886 1886
         }
1887 1887
 
1888
-		$this->set_prop( 'due_date', '' );
1888
+		$this->set_prop('due_date', '');
1889 1889
         return false;
1890 1890
 
1891 1891
     }
@@ -1896,8 +1896,8 @@  discard block
 block discarded – undo
1896 1896
 	 * @since 1.0.19
1897 1897
 	 * @param  string $value New name.
1898 1898
 	 */
1899
-	public function set_date_due( $value ) {
1900
-		$this->set_due_date( $value );
1899
+	public function set_date_due($value) {
1900
+		$this->set_due_date($value);
1901 1901
     }
1902 1902
 
1903 1903
     /**
@@ -1907,15 +1907,15 @@  discard block
 block discarded – undo
1907 1907
 	 * @param string $value Value to set.
1908 1908
      * @return bool Whether or not the date was set.
1909 1909
 	 */
1910
-	public function set_completed_date( $value ) {
1911
-        $date = strtotime( $value );
1910
+	public function set_completed_date($value) {
1911
+        $date = strtotime($value);
1912 1912
 
1913
-        if ( $date && $value !== '0000-00-00 00:00:00'  ) {
1914
-            $this->set_prop( 'completed_date', date( 'Y-m-d H:i:s', $date ) );
1913
+        if ($date && $value !== '0000-00-00 00:00:00') {
1914
+            $this->set_prop('completed_date', date('Y-m-d H:i:s', $date));
1915 1915
             return true;
1916 1916
         }
1917 1917
 
1918
-		$this->set_prop( 'completed_date', '' );
1918
+		$this->set_prop('completed_date', '');
1919 1919
         return false;
1920 1920
 
1921 1921
     }
@@ -1926,8 +1926,8 @@  discard block
 block discarded – undo
1926 1926
 	 * @since 1.0.19
1927 1927
 	 * @param  string $value New name.
1928 1928
 	 */
1929
-	public function set_date_completed( $value ) {
1930
-		$this->set_completed_date( $value );
1929
+	public function set_date_completed($value) {
1930
+		$this->set_completed_date($value);
1931 1931
     }
1932 1932
 
1933 1933
     /**
@@ -1937,15 +1937,15 @@  discard block
 block discarded – undo
1937 1937
 	 * @param string $value Value to set.
1938 1938
      * @return bool Whether or not the date was set.
1939 1939
 	 */
1940
-	public function set_date_modified( $value ) {
1941
-        $date = strtotime( $value );
1940
+	public function set_date_modified($value) {
1941
+        $date = strtotime($value);
1942 1942
 
1943
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
1944
-            $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) );
1943
+        if ($date && $value !== '0000-00-00 00:00:00') {
1944
+            $this->set_prop('date_modified', date('Y-m-d H:i:s', $date));
1945 1945
             return true;
1946 1946
         }
1947 1947
 
1948
-		$this->set_prop( 'date_modified', '' );
1948
+		$this->set_prop('date_modified', '');
1949 1949
         return false;
1950 1950
 
1951 1951
     }
@@ -1956,9 +1956,9 @@  discard block
 block discarded – undo
1956 1956
 	 * @since 1.0.19
1957 1957
 	 * @param  string $value New number.
1958 1958
 	 */
1959
-	public function set_number( $value ) {
1960
-        $number = sanitize_text_field( $value );
1961
-		$this->set_prop( 'number', $number );
1959
+	public function set_number($value) {
1960
+        $number = sanitize_text_field($value);
1961
+		$this->set_prop('number', $number);
1962 1962
     }
1963 1963
 
1964 1964
     /**
@@ -1967,9 +1967,9 @@  discard block
 block discarded – undo
1967 1967
 	 * @since 1.0.19
1968 1968
 	 * @param  string $value Type.
1969 1969
 	 */
1970
-	public function set_type( $value ) {
1971
-        $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) );
1972
-		$this->set_prop( 'type', $type );
1970
+	public function set_type($value) {
1971
+        $type = sanitize_text_field(str_replace('wpi_', '', $value));
1972
+		$this->set_prop('type', $type);
1973 1973
 	}
1974 1974
 
1975 1975
     /**
@@ -1978,10 +1978,10 @@  discard block
 block discarded – undo
1978 1978
 	 * @since 1.0.19
1979 1979
 	 * @param  string $value Post type.
1980 1980
 	 */
1981
-	public function set_post_type( $value ) {
1982
-        if ( getpaid_is_invoice_post_type( $value ) ) {
1983
-			$this->set_type( $value );
1984
-            $this->set_prop( 'post_type', $value );
1981
+	public function set_post_type($value) {
1982
+        if (getpaid_is_invoice_post_type($value)) {
1983
+			$this->set_type($value);
1984
+            $this->set_prop('post_type', $value);
1985 1985
         }
1986 1986
     }
1987 1987
 
@@ -1991,9 +1991,9 @@  discard block
 block discarded – undo
1991 1991
 	 * @since 1.0.19
1992 1992
 	 * @param  string $value New key.
1993 1993
 	 */
1994
-	public function set_key( $value ) {
1995
-        $key = sanitize_text_field( $value );
1996
-		$this->set_prop( 'key', $key );
1994
+	public function set_key($value) {
1995
+        $key = sanitize_text_field($value);
1996
+		$this->set_prop('key', $key);
1997 1997
     }
1998 1998
 
1999 1999
     /**
@@ -2002,9 +2002,9 @@  discard block
 block discarded – undo
2002 2002
 	 * @since 1.0.19
2003 2003
 	 * @param  string $value mode.
2004 2004
 	 */
2005
-	public function set_mode( $value ) {
2006
-        if ( ! in_array( $value, array( 'live', 'test' ) ) ) {
2007
-            $this->set_prop( 'value', $value );
2005
+	public function set_mode($value) {
2006
+        if (!in_array($value, array('live', 'test'))) {
2007
+            $this->set_prop('value', $value);
2008 2008
         }
2009 2009
     }
2010 2010
 
@@ -2014,8 +2014,8 @@  discard block
 block discarded – undo
2014 2014
 	 * @since 1.0.19
2015 2015
 	 * @param  string $value path.
2016 2016
 	 */
2017
-	public function set_path( $value ) {
2018
-        $this->set_prop( 'path', $value );
2017
+	public function set_path($value) {
2018
+        $this->set_prop('path', $value);
2019 2019
     }
2020 2020
 
2021 2021
     /**
@@ -2024,9 +2024,9 @@  discard block
 block discarded – undo
2024 2024
 	 * @since 1.0.19
2025 2025
 	 * @param  string $value New name.
2026 2026
 	 */
2027
-	public function set_name( $value ) {
2028
-        $name = sanitize_text_field( $value );
2029
-		$this->set_prop( 'name', $name );
2027
+	public function set_name($value) {
2028
+        $name = sanitize_text_field($value);
2029
+		$this->set_prop('name', $name);
2030 2030
     }
2031 2031
 
2032 2032
     /**
@@ -2035,8 +2035,8 @@  discard block
 block discarded – undo
2035 2035
 	 * @since 1.0.19
2036 2036
 	 * @param  string $value New name.
2037 2037
 	 */
2038
-	public function set_title( $value ) {
2039
-		$this->set_name( $value );
2038
+	public function set_title($value) {
2039
+		$this->set_name($value);
2040 2040
     }
2041 2041
 
2042 2042
     /**
@@ -2045,9 +2045,9 @@  discard block
 block discarded – undo
2045 2045
 	 * @since 1.0.19
2046 2046
 	 * @param  string $value New description.
2047 2047
 	 */
2048
-	public function set_description( $value ) {
2049
-        $description = wp_kses_post( $value );
2050
-		return $this->set_prop( 'description', $description );
2048
+	public function set_description($value) {
2049
+        $description = wp_kses_post($value);
2050
+		return $this->set_prop('description', $description);
2051 2051
     }
2052 2052
 
2053 2053
     /**
@@ -2056,8 +2056,8 @@  discard block
 block discarded – undo
2056 2056
 	 * @since 1.0.19
2057 2057
 	 * @param  string $value New description.
2058 2058
 	 */
2059
-	public function set_excerpt( $value ) {
2060
-		$this->set_description( $value );
2059
+	public function set_excerpt($value) {
2060
+		$this->set_description($value);
2061 2061
     }
2062 2062
 
2063 2063
     /**
@@ -2066,8 +2066,8 @@  discard block
 block discarded – undo
2066 2066
 	 * @since 1.0.19
2067 2067
 	 * @param  string $value New description.
2068 2068
 	 */
2069
-	public function set_summary( $value ) {
2070
-		$this->set_description( $value );
2069
+	public function set_summary($value) {
2070
+		$this->set_description($value);
2071 2071
     }
2072 2072
 
2073 2073
     /**
@@ -2076,12 +2076,12 @@  discard block
 block discarded – undo
2076 2076
 	 * @since 1.0.19
2077 2077
 	 * @param  int $value New author.
2078 2078
 	 */
2079
-	public function set_author( $value ) {
2080
-		$user = get_user_by( 'id', (int) $value );
2079
+	public function set_author($value) {
2080
+		$user = get_user_by('id', (int) $value);
2081 2081
 
2082
-		if ( $user && $user->ID ) {
2083
-			$this->set_prop( 'author', $user->ID );
2084
-			$this->set_prop( 'email', $user->user_email );
2082
+		if ($user && $user->ID) {
2083
+			$this->set_prop('author', $user->ID);
2084
+			$this->set_prop('email', $user->user_email);
2085 2085
 		}
2086 2086
 		
2087 2087
     }
@@ -2092,8 +2092,8 @@  discard block
 block discarded – undo
2092 2092
 	 * @since 1.0.19
2093 2093
 	 * @param  int $value New user id.
2094 2094
 	 */
2095
-	public function set_user_id( $value ) {
2096
-		$this->set_author( $value );
2095
+	public function set_user_id($value) {
2096
+		$this->set_author($value);
2097 2097
     }
2098 2098
 
2099 2099
     /**
@@ -2102,8 +2102,8 @@  discard block
 block discarded – undo
2102 2102
 	 * @since 1.0.19
2103 2103
 	 * @param  int $value New user id.
2104 2104
 	 */
2105
-	public function set_customer_id( $value ) {
2106
-		$this->set_author( $value );
2105
+	public function set_customer_id($value) {
2106
+		$this->set_author($value);
2107 2107
     }
2108 2108
 
2109 2109
     /**
@@ -2112,8 +2112,8 @@  discard block
 block discarded – undo
2112 2112
 	 * @since 1.0.19
2113 2113
 	 * @param  string $value ip address.
2114 2114
 	 */
2115
-	public function set_ip( $value ) {
2116
-		$this->set_prop( 'ip', $value );
2115
+	public function set_ip($value) {
2116
+		$this->set_prop('ip', $value);
2117 2117
     }
2118 2118
 
2119 2119
     /**
@@ -2122,8 +2122,8 @@  discard block
 block discarded – undo
2122 2122
 	 * @since 1.0.19
2123 2123
 	 * @param  string $value ip address.
2124 2124
 	 */
2125
-	public function set_user_ip( $value ) {
2126
-		$this->set_ip( $value );
2125
+	public function set_user_ip($value) {
2126
+		$this->set_ip($value);
2127 2127
     }
2128 2128
 
2129 2129
     /**
@@ -2132,8 +2132,8 @@  discard block
 block discarded – undo
2132 2132
 	 * @since 1.0.19
2133 2133
 	 * @param  string $value first name.
2134 2134
 	 */
2135
-	public function set_first_name( $value ) {
2136
-		$this->set_prop( 'first_name', $value );
2135
+	public function set_first_name($value) {
2136
+		$this->set_prop('first_name', $value);
2137 2137
     }
2138 2138
 
2139 2139
     /**
@@ -2142,8 +2142,8 @@  discard block
 block discarded – undo
2142 2142
 	 * @since 1.0.19
2143 2143
 	 * @param  string $value first name.
2144 2144
 	 */
2145
-	public function set_user_first_name( $value ) {
2146
-		$this->set_first_name( $value );
2145
+	public function set_user_first_name($value) {
2146
+		$this->set_first_name($value);
2147 2147
     }
2148 2148
 
2149 2149
     /**
@@ -2152,8 +2152,8 @@  discard block
 block discarded – undo
2152 2152
 	 * @since 1.0.19
2153 2153
 	 * @param  string $value first name.
2154 2154
 	 */
2155
-	public function set_customer_first_name( $value ) {
2156
-		$this->set_first_name( $value );
2155
+	public function set_customer_first_name($value) {
2156
+		$this->set_first_name($value);
2157 2157
     }
2158 2158
 
2159 2159
     /**
@@ -2162,8 +2162,8 @@  discard block
 block discarded – undo
2162 2162
 	 * @since 1.0.19
2163 2163
 	 * @param  string $value last name.
2164 2164
 	 */
2165
-	public function set_last_name( $value ) {
2166
-		$this->set_prop( 'last_name', $value );
2165
+	public function set_last_name($value) {
2166
+		$this->set_prop('last_name', $value);
2167 2167
     }
2168 2168
 
2169 2169
     /**
@@ -2172,8 +2172,8 @@  discard block
 block discarded – undo
2172 2172
 	 * @since 1.0.19
2173 2173
 	 * @param  string $value last name.
2174 2174
 	 */
2175
-	public function set_user_last_name( $value ) {
2176
-		$this->set_last_name( $value );
2175
+	public function set_user_last_name($value) {
2176
+		$this->set_last_name($value);
2177 2177
     }
2178 2178
 
2179 2179
     /**
@@ -2182,8 +2182,8 @@  discard block
 block discarded – undo
2182 2182
 	 * @since 1.0.19
2183 2183
 	 * @param  string $value last name.
2184 2184
 	 */
2185
-	public function set_customer_last_name( $value ) {
2186
-		$this->set_last_name( $value );
2185
+	public function set_customer_last_name($value) {
2186
+		$this->set_last_name($value);
2187 2187
     }
2188 2188
 
2189 2189
     /**
@@ -2192,8 +2192,8 @@  discard block
 block discarded – undo
2192 2192
 	 * @since 1.0.19
2193 2193
 	 * @param  string $value phone.
2194 2194
 	 */
2195
-	public function set_phone( $value ) {
2196
-		$this->set_prop( 'phone', $value );
2195
+	public function set_phone($value) {
2196
+		$this->set_prop('phone', $value);
2197 2197
     }
2198 2198
 
2199 2199
     /**
@@ -2202,8 +2202,8 @@  discard block
 block discarded – undo
2202 2202
 	 * @since 1.0.19
2203 2203
 	 * @param  string $value phone.
2204 2204
 	 */
2205
-	public function set_user_phone( $value ) {
2206
-		$this->set_phone( $value );
2205
+	public function set_user_phone($value) {
2206
+		$this->set_phone($value);
2207 2207
     }
2208 2208
 
2209 2209
     /**
@@ -2212,8 +2212,8 @@  discard block
 block discarded – undo
2212 2212
 	 * @since 1.0.19
2213 2213
 	 * @param  string $value phone.
2214 2214
 	 */
2215
-	public function set_customer_phone( $value ) {
2216
-		$this->set_phone( $value );
2215
+	public function set_customer_phone($value) {
2216
+		$this->set_phone($value);
2217 2217
     }
2218 2218
 
2219 2219
     /**
@@ -2222,8 +2222,8 @@  discard block
 block discarded – undo
2222 2222
 	 * @since 1.0.19
2223 2223
 	 * @param  string $value phone.
2224 2224
 	 */
2225
-	public function set_phone_number( $value ) {
2226
-		$this->set_phone( $value );
2225
+	public function set_phone_number($value) {
2226
+		$this->set_phone($value);
2227 2227
     }
2228 2228
 
2229 2229
     /**
@@ -2232,8 +2232,8 @@  discard block
 block discarded – undo
2232 2232
 	 * @since 1.0.19
2233 2233
 	 * @param  string $value email address.
2234 2234
 	 */
2235
-	public function set_email( $value ) {
2236
-		$this->set_prop( 'email', $value );
2235
+	public function set_email($value) {
2236
+		$this->set_prop('email', $value);
2237 2237
     }
2238 2238
 
2239 2239
     /**
@@ -2242,8 +2242,8 @@  discard block
 block discarded – undo
2242 2242
 	 * @since 1.0.19
2243 2243
 	 * @param  string $value email address.
2244 2244
 	 */
2245
-	public function set_user_email( $value ) {
2246
-		$this->set_email( $value );
2245
+	public function set_user_email($value) {
2246
+		$this->set_email($value);
2247 2247
     }
2248 2248
 
2249 2249
     /**
@@ -2252,8 +2252,8 @@  discard block
 block discarded – undo
2252 2252
 	 * @since 1.0.19
2253 2253
 	 * @param  string $value email address.
2254 2254
 	 */
2255
-	public function set_email_address( $value ) {
2256
-		$this->set_email( $value );
2255
+	public function set_email_address($value) {
2256
+		$this->set_email($value);
2257 2257
     }
2258 2258
 
2259 2259
     /**
@@ -2262,8 +2262,8 @@  discard block
 block discarded – undo
2262 2262
 	 * @since 1.0.19
2263 2263
 	 * @param  string $value email address.
2264 2264
 	 */
2265
-	public function set_customer_email( $value ) {
2266
-		$this->set_email( $value );
2265
+	public function set_customer_email($value) {
2266
+		$this->set_email($value);
2267 2267
     }
2268 2268
 
2269 2269
     /**
@@ -2272,8 +2272,8 @@  discard block
 block discarded – undo
2272 2272
 	 * @since 1.0.19
2273 2273
 	 * @param  string $value country.
2274 2274
 	 */
2275
-	public function set_country( $value ) {
2276
-		$this->set_prop( 'country', $value );
2275
+	public function set_country($value) {
2276
+		$this->set_prop('country', $value);
2277 2277
     }
2278 2278
 
2279 2279
     /**
@@ -2282,8 +2282,8 @@  discard block
 block discarded – undo
2282 2282
 	 * @since 1.0.19
2283 2283
 	 * @param  string $value country.
2284 2284
 	 */
2285
-	public function set_user_country( $value ) {
2286
-		$this->set_country( $value );
2285
+	public function set_user_country($value) {
2286
+		$this->set_country($value);
2287 2287
     }
2288 2288
 
2289 2289
     /**
@@ -2292,8 +2292,8 @@  discard block
 block discarded – undo
2292 2292
 	 * @since 1.0.19
2293 2293
 	 * @param  string $value country.
2294 2294
 	 */
2295
-	public function set_customer_country( $value ) {
2296
-		$this->set_country( $value );
2295
+	public function set_customer_country($value) {
2296
+		$this->set_country($value);
2297 2297
     }
2298 2298
 
2299 2299
     /**
@@ -2302,8 +2302,8 @@  discard block
 block discarded – undo
2302 2302
 	 * @since 1.0.19
2303 2303
 	 * @param  string $value state.
2304 2304
 	 */
2305
-	public function set_state( $value ) {
2306
-		$this->set_prop( 'state', $value );
2305
+	public function set_state($value) {
2306
+		$this->set_prop('state', $value);
2307 2307
     }
2308 2308
 
2309 2309
     /**
@@ -2312,8 +2312,8 @@  discard block
 block discarded – undo
2312 2312
 	 * @since 1.0.19
2313 2313
 	 * @param  string $value state.
2314 2314
 	 */
2315
-	public function set_user_state( $value ) {
2316
-		$this->set_state( $value );
2315
+	public function set_user_state($value) {
2316
+		$this->set_state($value);
2317 2317
     }
2318 2318
 
2319 2319
     /**
@@ -2322,8 +2322,8 @@  discard block
 block discarded – undo
2322 2322
 	 * @since 1.0.19
2323 2323
 	 * @param  string $value state.
2324 2324
 	 */
2325
-	public function set_customer_state( $value ) {
2326
-		$this->set_state( $value );
2325
+	public function set_customer_state($value) {
2326
+		$this->set_state($value);
2327 2327
     }
2328 2328
 
2329 2329
     /**
@@ -2332,8 +2332,8 @@  discard block
 block discarded – undo
2332 2332
 	 * @since 1.0.19
2333 2333
 	 * @param  string $value city.
2334 2334
 	 */
2335
-	public function set_city( $value ) {
2336
-		$this->set_prop( 'city', $value );
2335
+	public function set_city($value) {
2336
+		$this->set_prop('city', $value);
2337 2337
     }
2338 2338
 
2339 2339
     /**
@@ -2342,8 +2342,8 @@  discard block
 block discarded – undo
2342 2342
 	 * @since 1.0.19
2343 2343
 	 * @param  string $value city.
2344 2344
 	 */
2345
-	public function set_user_city( $value ) {
2346
-		$this->set_city( $value );
2345
+	public function set_user_city($value) {
2346
+		$this->set_city($value);
2347 2347
     }
2348 2348
 
2349 2349
     /**
@@ -2352,8 +2352,8 @@  discard block
 block discarded – undo
2352 2352
 	 * @since 1.0.19
2353 2353
 	 * @param  string $value city.
2354 2354
 	 */
2355
-	public function set_customer_city( $value ) {
2356
-		$this->set_city( $value );
2355
+	public function set_customer_city($value) {
2356
+		$this->set_city($value);
2357 2357
     }
2358 2358
 
2359 2359
     /**
@@ -2362,8 +2362,8 @@  discard block
 block discarded – undo
2362 2362
 	 * @since 1.0.19
2363 2363
 	 * @param  string $value zip.
2364 2364
 	 */
2365
-	public function set_zip( $value ) {
2366
-		$this->set_prop( 'zip', $value );
2365
+	public function set_zip($value) {
2366
+		$this->set_prop('zip', $value);
2367 2367
     }
2368 2368
 
2369 2369
     /**
@@ -2372,8 +2372,8 @@  discard block
 block discarded – undo
2372 2372
 	 * @since 1.0.19
2373 2373
 	 * @param  string $value zip.
2374 2374
 	 */
2375
-	public function set_user_zip( $value ) {
2376
-		$this->set_zip( $value );
2375
+	public function set_user_zip($value) {
2376
+		$this->set_zip($value);
2377 2377
     }
2378 2378
 
2379 2379
     /**
@@ -2382,8 +2382,8 @@  discard block
 block discarded – undo
2382 2382
 	 * @since 1.0.19
2383 2383
 	 * @param  string $value zip.
2384 2384
 	 */
2385
-	public function set_customer_zip( $value ) {
2386
-		$this->set_zip( $value );
2385
+	public function set_customer_zip($value) {
2386
+		$this->set_zip($value);
2387 2387
     }
2388 2388
 
2389 2389
     /**
@@ -2392,8 +2392,8 @@  discard block
 block discarded – undo
2392 2392
 	 * @since 1.0.19
2393 2393
 	 * @param  string $value company.
2394 2394
 	 */
2395
-	public function set_company( $value ) {
2396
-		$this->set_prop( 'company', $value );
2395
+	public function set_company($value) {
2396
+		$this->set_prop('company', $value);
2397 2397
     }
2398 2398
 
2399 2399
     /**
@@ -2402,8 +2402,8 @@  discard block
 block discarded – undo
2402 2402
 	 * @since 1.0.19
2403 2403
 	 * @param  string $value company.
2404 2404
 	 */
2405
-	public function set_user_company( $value ) {
2406
-		$this->set_company( $value );
2405
+	public function set_user_company($value) {
2406
+		$this->set_company($value);
2407 2407
     }
2408 2408
 
2409 2409
     /**
@@ -2412,8 +2412,8 @@  discard block
 block discarded – undo
2412 2412
 	 * @since 1.0.19
2413 2413
 	 * @param  string $value company.
2414 2414
 	 */
2415
-	public function set_customer_company( $value ) {
2416
-		$this->set_company( $value );
2415
+	public function set_customer_company($value) {
2416
+		$this->set_company($value);
2417 2417
     }
2418 2418
 
2419 2419
     /**
@@ -2422,8 +2422,8 @@  discard block
 block discarded – undo
2422 2422
 	 * @since 1.0.19
2423 2423
 	 * @param  string $value var number.
2424 2424
 	 */
2425
-	public function set_vat_number( $value ) {
2426
-		$this->set_prop( 'vat_number', $value );
2425
+	public function set_vat_number($value) {
2426
+		$this->set_prop('vat_number', $value);
2427 2427
     }
2428 2428
 
2429 2429
     /**
@@ -2432,8 +2432,8 @@  discard block
 block discarded – undo
2432 2432
 	 * @since 1.0.19
2433 2433
 	 * @param  string $value var number.
2434 2434
 	 */
2435
-	public function set_user_vat_number( $value ) {
2436
-		$this->set_vat_number( $value );
2435
+	public function set_user_vat_number($value) {
2436
+		$this->set_vat_number($value);
2437 2437
     }
2438 2438
 
2439 2439
     /**
@@ -2442,8 +2442,8 @@  discard block
 block discarded – undo
2442 2442
 	 * @since 1.0.19
2443 2443
 	 * @param  string $value var number.
2444 2444
 	 */
2445
-	public function set_customer_vat_number( $value ) {
2446
-		$this->set_vat_number( $value );
2445
+	public function set_customer_vat_number($value) {
2446
+		$this->set_vat_number($value);
2447 2447
     }
2448 2448
 
2449 2449
     /**
@@ -2452,8 +2452,8 @@  discard block
 block discarded – undo
2452 2452
 	 * @since 1.0.19
2453 2453
 	 * @param  string $value var rate.
2454 2454
 	 */
2455
-	public function set_vat_rate( $value ) {
2456
-		$this->set_prop( 'vat_rate', $value );
2455
+	public function set_vat_rate($value) {
2456
+		$this->set_prop('vat_rate', $value);
2457 2457
     }
2458 2458
 
2459 2459
     /**
@@ -2462,8 +2462,8 @@  discard block
 block discarded – undo
2462 2462
 	 * @since 1.0.19
2463 2463
 	 * @param  string $value var number.
2464 2464
 	 */
2465
-	public function set_user_vat_rate( $value ) {
2466
-		$this->set_vat_rate( $value );
2465
+	public function set_user_vat_rate($value) {
2466
+		$this->set_vat_rate($value);
2467 2467
     }
2468 2468
 
2469 2469
     /**
@@ -2472,8 +2472,8 @@  discard block
 block discarded – undo
2472 2472
 	 * @since 1.0.19
2473 2473
 	 * @param  string $value var number.
2474 2474
 	 */
2475
-	public function set_customer_vat_rate( $value ) {
2476
-		$this->set_vat_rate( $value );
2475
+	public function set_customer_vat_rate($value) {
2476
+		$this->set_vat_rate($value);
2477 2477
     }
2478 2478
 
2479 2479
     /**
@@ -2482,8 +2482,8 @@  discard block
 block discarded – undo
2482 2482
 	 * @since 1.0.19
2483 2483
 	 * @param  string $value address.
2484 2484
 	 */
2485
-	public function set_address( $value ) {
2486
-		$this->set_prop( 'address', $value );
2485
+	public function set_address($value) {
2486
+		$this->set_prop('address', $value);
2487 2487
     }
2488 2488
 
2489 2489
     /**
@@ -2492,8 +2492,8 @@  discard block
 block discarded – undo
2492 2492
 	 * @since 1.0.19
2493 2493
 	 * @param  string $value address.
2494 2494
 	 */
2495
-	public function set_user_address( $value ) {
2496
-		$this->set_address( $value );
2495
+	public function set_user_address($value) {
2496
+		$this->set_address($value);
2497 2497
     }
2498 2498
 
2499 2499
     /**
@@ -2502,8 +2502,8 @@  discard block
 block discarded – undo
2502 2502
 	 * @since 1.0.19
2503 2503
 	 * @param  string $value address.
2504 2504
 	 */
2505
-	public function set_customer_address( $value ) {
2506
-		$this->set_address( $value );
2505
+	public function set_customer_address($value) {
2506
+		$this->set_address($value);
2507 2507
     }
2508 2508
 
2509 2509
     /**
@@ -2512,8 +2512,8 @@  discard block
 block discarded – undo
2512 2512
 	 * @since 1.0.19
2513 2513
 	 * @param  int|bool $value confirmed.
2514 2514
 	 */
2515
-	public function set_is_viewed( $value ) {
2516
-		$this->set_prop( 'is_viewed', $value );
2515
+	public function set_is_viewed($value) {
2516
+		$this->set_prop('is_viewed', $value);
2517 2517
 	}
2518 2518
 
2519 2519
 	/**
@@ -2522,8 +2522,8 @@  discard block
 block discarded – undo
2522 2522
 	 * @since 1.0.19
2523 2523
 	 * @param  string $value email recipients.
2524 2524
 	 */
2525
-	public function set_email_cc( $value ) {
2526
-		$this->set_prop( 'email_cc', $value );
2525
+	public function set_email_cc($value) {
2526
+		$this->set_prop('email_cc', $value);
2527 2527
 	}
2528 2528
 
2529 2529
 	/**
@@ -2532,9 +2532,9 @@  discard block
 block discarded – undo
2532 2532
 	 * @since 1.0.19
2533 2533
 	 * @param  string $value email recipients.
2534 2534
 	 */
2535
-	public function set_template( $value ) {
2536
-		if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) {
2537
-			$this->set_prop( 'template', $value );
2535
+	public function set_template($value) {
2536
+		if (in_array($value, array('quantity', 'hours', 'amount'))) {
2537
+			$this->set_prop('template', $value);
2538 2538
 		}
2539 2539
 	}
2540 2540
 
@@ -2544,8 +2544,8 @@  discard block
 block discarded – undo
2544 2544
 	 * @since 1.0.19
2545 2545
 	 * @param  int|bool $value confirmed.
2546 2546
 	 */
2547
-	public function set_address_confirmed( $value ) {
2548
-		$this->set_prop( 'address_confirmed', $value );
2547
+	public function set_address_confirmed($value) {
2548
+		$this->set_prop('address_confirmed', $value);
2549 2549
     }
2550 2550
 
2551 2551
     /**
@@ -2554,8 +2554,8 @@  discard block
 block discarded – undo
2554 2554
 	 * @since 1.0.19
2555 2555
 	 * @param  int|bool $value confirmed.
2556 2556
 	 */
2557
-	public function set_user_address_confirmed( $value ) {
2558
-		$this->set_address_confirmed( $value );
2557
+	public function set_user_address_confirmed($value) {
2558
+		$this->set_address_confirmed($value);
2559 2559
     }
2560 2560
 
2561 2561
     /**
@@ -2564,8 +2564,8 @@  discard block
 block discarded – undo
2564 2564
 	 * @since 1.0.19
2565 2565
 	 * @param  int|bool $value confirmed.
2566 2566
 	 */
2567
-	public function set_customer_address_confirmed( $value ) {
2568
-		$this->set_address_confirmed( $value );
2567
+	public function set_customer_address_confirmed($value) {
2568
+		$this->set_address_confirmed($value);
2569 2569
     }
2570 2570
 
2571 2571
     /**
@@ -2574,8 +2574,8 @@  discard block
 block discarded – undo
2574 2574
 	 * @since 1.0.19
2575 2575
 	 * @param  float $value sub total.
2576 2576
 	 */
2577
-	public function set_subtotal( $value ) {
2578
-		$this->set_prop( 'subtotal', $value );
2577
+	public function set_subtotal($value) {
2578
+		$this->set_prop('subtotal', $value);
2579 2579
     }
2580 2580
 
2581 2581
     /**
@@ -2584,8 +2584,8 @@  discard block
 block discarded – undo
2584 2584
 	 * @since 1.0.19
2585 2585
 	 * @param  float $value discount total.
2586 2586
 	 */
2587
-	public function set_total_discount( $value ) {
2588
-		$this->set_prop( 'total_discount', $value );
2587
+	public function set_total_discount($value) {
2588
+		$this->set_prop('total_discount', $value);
2589 2589
     }
2590 2590
 
2591 2591
     /**
@@ -2594,8 +2594,8 @@  discard block
 block discarded – undo
2594 2594
 	 * @since 1.0.19
2595 2595
 	 * @param  float $value discount total.
2596 2596
 	 */
2597
-	public function set_discount( $value ) {
2598
-		$this->set_total_discount( $value );
2597
+	public function set_discount($value) {
2598
+		$this->set_total_discount($value);
2599 2599
     }
2600 2600
 
2601 2601
     /**
@@ -2604,8 +2604,8 @@  discard block
 block discarded – undo
2604 2604
 	 * @since 1.0.19
2605 2605
 	 * @param  float $value tax total.
2606 2606
 	 */
2607
-	public function set_total_tax( $value ) {
2608
-		$this->set_prop( 'total_tax', $value );
2607
+	public function set_total_tax($value) {
2608
+		$this->set_prop('total_tax', $value);
2609 2609
     }
2610 2610
 
2611 2611
     /**
@@ -2614,8 +2614,8 @@  discard block
 block discarded – undo
2614 2614
 	 * @since 1.0.19
2615 2615
 	 * @param  float $value tax total.
2616 2616
 	 */
2617
-	public function set_tax_total( $value ) {
2618
-		$this->set_total_tax( $value );
2617
+	public function set_tax_total($value) {
2618
+		$this->set_total_tax($value);
2619 2619
     }
2620 2620
 
2621 2621
     /**
@@ -2624,8 +2624,8 @@  discard block
 block discarded – undo
2624 2624
 	 * @since 1.0.19
2625 2625
 	 * @param  float $value fees total.
2626 2626
 	 */
2627
-	public function set_total_fees( $value ) {
2628
-		$this->set_prop( 'total_fees', $value );
2627
+	public function set_total_fees($value) {
2628
+		$this->set_prop('total_fees', $value);
2629 2629
     }
2630 2630
 
2631 2631
     /**
@@ -2634,8 +2634,8 @@  discard block
 block discarded – undo
2634 2634
 	 * @since 1.0.19
2635 2635
 	 * @param  float $value fees total.
2636 2636
 	 */
2637
-	public function set_fees_total( $value ) {
2638
-		$this->set_total_fees( $value );
2637
+	public function set_fees_total($value) {
2638
+		$this->set_total_fees($value);
2639 2639
     }
2640 2640
 
2641 2641
     /**
@@ -2644,18 +2644,18 @@  discard block
 block discarded – undo
2644 2644
 	 * @since 1.0.19
2645 2645
 	 * @param  array $value fees.
2646 2646
 	 */
2647
-	public function set_fees( $value ) {
2647
+	public function set_fees($value) {
2648 2648
 
2649
-        $this->set_prop( 'fees', array() );
2649
+        $this->set_prop('fees', array());
2650 2650
 
2651 2651
         // Ensure that we have an array.
2652
-        if ( ! is_array( $value ) ) {
2652
+        if (!is_array($value)) {
2653 2653
             return;
2654 2654
         }
2655 2655
 
2656
-        foreach ( $value as $name => $data ) {
2657
-            if ( isset( $data['amount'] ) ) {
2658
-                $this->add_fee( $name, $data['amount'], $data['recurring'] );
2656
+        foreach ($value as $name => $data) {
2657
+            if (isset($data['amount'])) {
2658
+                $this->add_fee($name, $data['amount'], $data['recurring']);
2659 2659
             }
2660 2660
         }
2661 2661
 
@@ -2667,8 +2667,8 @@  discard block
 block discarded – undo
2667 2667
 	 * @since 1.0.19
2668 2668
 	 * @param  array $value taxes.
2669 2669
 	 */
2670
-	public function set_taxes( $value ) {
2671
-		$this->set_prop( 'taxes', $value );
2670
+	public function set_taxes($value) {
2671
+		$this->set_prop('taxes', $value);
2672 2672
     }
2673 2673
 
2674 2674
     /**
@@ -2677,17 +2677,17 @@  discard block
 block discarded – undo
2677 2677
 	 * @since 1.0.19
2678 2678
 	 * @param  array $value discounts.
2679 2679
 	 */
2680
-	public function set_discounts( $value ) {
2681
-		$this->set_prop( 'discounts', array() );
2680
+	public function set_discounts($value) {
2681
+		$this->set_prop('discounts', array());
2682 2682
 
2683 2683
         // Ensure that we have an array.
2684
-        if ( ! is_array( $value ) ) {
2684
+        if (!is_array($value)) {
2685 2685
             return;
2686 2686
         }
2687 2687
 
2688
-        foreach ( $value as $name => $data ) {
2689
-            if ( isset( $data['amount'] ) ) {
2690
-                $this->add_discount( $name, $data['amount'], $data['recurring'] );
2688
+        foreach ($value as $name => $data) {
2689
+            if (isset($data['amount'])) {
2690
+                $this->add_discount($name, $data['amount'], $data['recurring']);
2691 2691
             }
2692 2692
         }
2693 2693
     }
@@ -2698,18 +2698,18 @@  discard block
 block discarded – undo
2698 2698
 	 * @since 1.0.19
2699 2699
 	 * @param  GetPaid_Form_Item[] $value items.
2700 2700
 	 */
2701
-	public function set_items( $value ) {
2701
+	public function set_items($value) {
2702 2702
 
2703 2703
         // Remove existing items.
2704
-        $this->set_prop( 'items', array() );
2704
+        $this->set_prop('items', array());
2705 2705
 
2706 2706
         // Ensure that we have an array.
2707
-        if ( ! is_array( $value ) ) {
2707
+        if (!is_array($value)) {
2708 2708
             return;
2709 2709
         }
2710 2710
 
2711
-        foreach ( $value as $item ) {
2712
-            $this->add_item( $item );
2711
+        foreach ($value as $item) {
2712
+            $this->add_item($item);
2713 2713
         }
2714 2714
 
2715 2715
     }
@@ -2720,8 +2720,8 @@  discard block
 block discarded – undo
2720 2720
 	 * @since 1.0.19
2721 2721
 	 * @param  int $value payment form.
2722 2722
 	 */
2723
-	public function set_payment_form( $value ) {
2724
-		$this->set_prop( 'payment_form', $value );
2723
+	public function set_payment_form($value) {
2724
+		$this->set_prop('payment_form', $value);
2725 2725
     }
2726 2726
 
2727 2727
     /**
@@ -2730,8 +2730,8 @@  discard block
 block discarded – undo
2730 2730
 	 * @since 1.0.19
2731 2731
 	 * @param  string $value submission id.
2732 2732
 	 */
2733
-	public function set_submission_id( $value ) {
2734
-		$this->set_prop( 'submission_id', $value );
2733
+	public function set_submission_id($value) {
2734
+		$this->set_prop('submission_id', $value);
2735 2735
     }
2736 2736
 
2737 2737
     /**
@@ -2740,8 +2740,8 @@  discard block
 block discarded – undo
2740 2740
 	 * @since 1.0.19
2741 2741
 	 * @param  string $value discount code.
2742 2742
 	 */
2743
-	public function set_discount_code( $value ) {
2744
-		$this->set_prop( 'discount_code', $value );
2743
+	public function set_discount_code($value) {
2744
+		$this->set_prop('discount_code', $value);
2745 2745
     }
2746 2746
 
2747 2747
     /**
@@ -2750,8 +2750,8 @@  discard block
 block discarded – undo
2750 2750
 	 * @since 1.0.19
2751 2751
 	 * @param  string $value gateway.
2752 2752
 	 */
2753
-	public function set_gateway( $value ) {
2754
-		$this->set_prop( 'gateway', $value );
2753
+	public function set_gateway($value) {
2754
+		$this->set_prop('gateway', $value);
2755 2755
     }
2756 2756
 
2757 2757
     /**
@@ -2760,8 +2760,8 @@  discard block
 block discarded – undo
2760 2760
 	 * @since 1.0.19
2761 2761
 	 * @param  string $value transaction id.
2762 2762
 	 */
2763
-	public function set_transaction_id( $value ) {
2764
-		$this->set_prop( 'transaction_id', $value );
2763
+	public function set_transaction_id($value) {
2764
+		$this->set_prop('transaction_id', $value);
2765 2765
     }
2766 2766
 
2767 2767
     /**
@@ -2770,8 +2770,8 @@  discard block
 block discarded – undo
2770 2770
 	 * @since 1.0.19
2771 2771
 	 * @param  string $value currency id.
2772 2772
 	 */
2773
-	public function set_currency( $value ) {
2774
-		$this->set_prop( 'currency', $value );
2773
+	public function set_currency($value) {
2774
+		$this->set_prop('currency', $value);
2775 2775
     }
2776 2776
 
2777 2777
 	/**
@@ -2780,8 +2780,8 @@  discard block
 block discarded – undo
2780 2780
 	 * @since 1.0.19
2781 2781
 	 * @param  bool $value value.
2782 2782
 	 */
2783
-	public function set_disable_taxes( $value ) {
2784
-		$this->set_prop( 'disable_taxes', (bool) $value );
2783
+	public function set_disable_taxes($value) {
2784
+		$this->set_prop('disable_taxes', (bool) $value);
2785 2785
 	}
2786 2786
 
2787 2787
     /**
@@ -2790,8 +2790,8 @@  discard block
 block discarded – undo
2790 2790
 	 * @since 1.0.19
2791 2791
 	 * @param  string $value subscription id.
2792 2792
 	 */
2793
-	public function set_subscription_id( $value ) {
2794
-		$this->set_prop( 'subscription_id', $value );
2793
+	public function set_subscription_id($value) {
2794
+		$this->set_prop('subscription_id', $value);
2795 2795
     }
2796 2796
 
2797 2797
     /*
@@ -2808,21 +2808,21 @@  discard block
 block discarded – undo
2808 2808
      */
2809 2809
     public function is_parent() {
2810 2810
         $parent = $this->get_parent_id();
2811
-        return apply_filters( 'wpinv_invoice_is_parent', empty( $parent ), $this );
2811
+        return apply_filters('wpinv_invoice_is_parent', empty($parent), $this);
2812 2812
     }
2813 2813
 
2814 2814
     /**
2815 2815
      * Checks if this is a renewal invoice.
2816 2816
      */
2817 2817
     public function is_renewal() {
2818
-        return ! $this->is_parent();
2818
+        return !$this->is_parent();
2819 2819
     }
2820 2820
 
2821 2821
     /**
2822 2822
      * Checks if this is a recurring invoice.
2823 2823
      */
2824 2824
     public function is_recurring() {
2825
-        return $this->is_renewal() || ! empty( $this->recurring_item );
2825
+        return $this->is_renewal() || !empty($this->recurring_item);
2826 2826
     }
2827 2827
 
2828 2828
     /**
@@ -2840,72 +2840,72 @@  discard block
 block discarded – undo
2840 2840
 
2841 2841
         $requires_vat = false;
2842 2842
 
2843
-        if ( $this->country ) {
2843
+        if ($this->country) {
2844 2844
             $wpi_country        = $this->country;
2845
-            $requires_vat       = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) );
2845
+            $requires_vat       = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this));
2846 2846
         }
2847 2847
 
2848
-        return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2848
+        return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this);
2849 2849
 	}
2850 2850
 
2851 2851
 	/**
2852 2852
 	 * Checks to see if the invoice requires payment.
2853 2853
 	 */
2854 2854
 	public function is_free() {
2855
-        $is_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 );
2855
+        $is_free = !((float) wpinv_round_amount($this->get_initial_total()) > 0);
2856 2856
 
2857
-		if ( $is_free && $this->is_recurring() ) {
2858
-			$is_free = ! ( (float) wpinv_round_amount( $this->get_recurring_total() ) > 0 );
2857
+		if ($is_free && $this->is_recurring()) {
2858
+			$is_free = !((float) wpinv_round_amount($this->get_recurring_total()) > 0);
2859 2859
 		}
2860 2860
 
2861
-        return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2861
+        return apply_filters('wpinv_invoice_is_free', $is_free, $this);
2862 2862
     }
2863 2863
 
2864 2864
     /**
2865 2865
      * Checks if the invoice is paid.
2866 2866
      */
2867 2867
     public function is_paid() {
2868
-        $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) );
2869
-        return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this );
2868
+        $is_paid = $this->has_status(array('publish', 'wpi-processing', 'wpi-renewal'));
2869
+        return apply_filters('wpinv_invoice_is_paid', $is_paid, $this);
2870 2870
 	}
2871 2871
 
2872 2872
 	/**
2873 2873
      * Checks if the invoice needs payment.
2874 2874
      */
2875 2875
 	public function needs_payment() {
2876
-		$needs_payment = ! $this->is_paid() && ! $this->is_free();
2877
-        return apply_filters( 'wpinv_needs_payment', $needs_payment, $this );
2876
+		$needs_payment = !$this->is_paid() && !$this->is_free();
2877
+        return apply_filters('wpinv_needs_payment', $needs_payment, $this);
2878 2878
     }
2879 2879
 
2880 2880
 	/**
2881 2881
      * Checks if the invoice is refunded.
2882 2882
      */
2883 2883
 	public function is_refunded() {
2884
-        $is_refunded = $this->has_status( 'wpi-refunded' );
2885
-        return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this );
2884
+        $is_refunded = $this->has_status('wpi-refunded');
2885
+        return apply_filters('wpinv_invoice_is_refunded', $is_refunded, $this);
2886 2886
 	}
2887 2887
 
2888 2888
 	/**
2889 2889
      * Checks if the invoice is draft.
2890 2890
      */
2891 2891
 	public function is_draft() {
2892
-        return $this->has_status( 'draft, auto-draft' );
2892
+        return $this->has_status('draft, auto-draft');
2893 2893
 	}
2894 2894
 
2895 2895
     /**
2896 2896
      * Checks if the invoice has a given status.
2897 2897
      */
2898
-    public function has_status( $status ) {
2899
-        $status = wpinv_parse_list( $status );
2900
-        return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status );
2898
+    public function has_status($status) {
2899
+        $status = wpinv_parse_list($status);
2900
+        return apply_filters('wpinv_has_status', in_array($this->get_status(), $status), $status);
2901 2901
 	}
2902 2902
 
2903 2903
 	/**
2904 2904
      * Checks if the invoice is of a given type.
2905 2905
      */
2906
-    public function is_type( $type ) {
2907
-        $type = wpinv_parse_list( $type );
2908
-        return in_array( $this->get_type(), $type );
2906
+    public function is_type($type) {
2907
+        $type = wpinv_parse_list($type);
2908
+        return in_array($this->get_type(), $type);
2909 2909
     }
2910 2910
 
2911 2911
     /**
@@ -2914,7 +2914,7 @@  discard block
 block discarded – undo
2914 2914
      * @since 1.0.15
2915 2915
      */
2916 2916
     public function is_quote() {
2917
-        return $this->has_status( 'wpi_quote' );
2917
+        return $this->has_status('wpi_quote');
2918 2918
     }
2919 2919
 
2920 2920
     /**
@@ -2937,8 +2937,8 @@  discard block
 block discarded – undo
2937 2937
      *
2938 2938
      */
2939 2939
 	public function is_initial_free() {
2940
-        $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 );
2941
-        return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this );
2940
+        $is_initial_free = !((float) wpinv_round_amount($this->get_initial_total()) > 0);
2941
+        return apply_filters('wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this);
2942 2942
     }
2943 2943
 	
2944 2944
 	/**
@@ -2948,11 +2948,11 @@  discard block
 block discarded – undo
2948 2948
     public function item_has_free_trial() {
2949 2949
 
2950 2950
         // Ensure we have a recurring item.
2951
-        if ( ! $this->is_recurring() ) {
2951
+        if (!$this->is_recurring()) {
2952 2952
             return false;
2953 2953
         }
2954 2954
 
2955
-        $item = new WPInv_Item( $this->recurring_item );
2955
+        $item = new WPInv_Item($this->recurring_item);
2956 2956
         return $item->has_free_trial();
2957 2957
 	}
2958 2958
 
@@ -2960,7 +2960,7 @@  discard block
 block discarded – undo
2960 2960
      * Check if the free trial is a result of a discount.
2961 2961
      */
2962 2962
     public function is_free_trial_from_discount() {
2963
-		return $this->has_free_trial() && ! $this->item_has_free_trial();
2963
+		return $this->has_free_trial() && !$this->item_has_free_trial();
2964 2964
 	}
2965 2965
 	
2966 2966
 	/**
@@ -2969,17 +2969,17 @@  discard block
 block discarded – undo
2969 2969
     public function discount_first_payment_only() {
2970 2970
 
2971 2971
 		$discount_code = $this->get_discount_code();
2972
-        if ( empty( $this->discount_code ) || ! $this->is_recurring() ) {
2972
+        if (empty($this->discount_code) || !$this->is_recurring()) {
2973 2973
             return true;
2974 2974
         }
2975 2975
 
2976
-        $discount = wpinv_get_discount_obj( $discount_code );
2976
+        $discount = wpinv_get_discount_obj($discount_code);
2977 2977
 
2978
-        if ( ! $discount || ! $discount->exists() ) {
2978
+        if (!$discount || !$discount->exists()) {
2979 2979
             return true;
2980 2980
         }
2981 2981
 
2982
-        return ! $discount->get_is_recurring();
2982
+        return !$discount->get_is_recurring();
2983 2983
     }
2984 2984
 
2985 2985
     /*
@@ -2997,18 +2997,18 @@  discard block
 block discarded – undo
2997 2997
      * @param GetPaid_Form_Item $item
2998 2998
      * @return WP_Error|Bool
2999 2999
      */
3000
-    public function add_item( $item ) {
3000
+    public function add_item($item) {
3001 3001
 
3002 3002
         // Make sure that it is available for purchase.
3003
-		if ( $item->get_id() > 0 && ! $item->can_purchase() ) {
3004
-			return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) );
3003
+		if ($item->get_id() > 0 && !$item->can_purchase()) {
3004
+			return new WP_Error('invalid_item', __('This item is not available for purchase', 'invoicing'));
3005 3005
         }
3006 3006
 
3007 3007
         // Do we have a recurring item?
3008
-		if ( $item->is_recurring() ) {
3008
+		if ($item->is_recurring()) {
3009 3009
 
3010 3010
 			// An invoice can only contain one recurring item.
3011
-			if ( ! empty( $this->recurring_item ) ) {
3011
+			if (!empty($this->recurring_item)) {
3012 3012
 				return false;
3013 3013
 			}
3014 3014
 
@@ -3020,9 +3020,9 @@  discard block
 block discarded – undo
3020 3020
 
3021 3021
         // Retrieve all items.
3022 3022
         $items = $this->get_items();
3023
-        $items[ $item->get_id() ] = $item;
3023
+        $items[$item->get_id()] = $item;
3024 3024
 
3025
-        $this->set_prop( 'items', $items );
3025
+        $this->set_prop('items', $items);
3026 3026
 		return true;
3027 3027
     }
3028 3028
 
@@ -3031,9 +3031,9 @@  discard block
 block discarded – undo
3031 3031
 	 *
3032 3032
 	 * @since 1.0.19
3033 3033
 	 */
3034
-	public function get_item( $item_id ) {
3034
+	public function get_item($item_id) {
3035 3035
         $items = $this->get_items();
3036
-		return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null;
3036
+		return (!empty($item_id) && isset($items[$item_id])) ? $items[$item_id] : null;
3037 3037
     }
3038 3038
 
3039 3039
     /**
@@ -3041,16 +3041,16 @@  discard block
 block discarded – undo
3041 3041
 	 *
3042 3042
 	 * @since 1.0.19
3043 3043
 	 */
3044
-	public function remove_item( $item_id ) {
3044
+	public function remove_item($item_id) {
3045 3045
         $items = $this->get_items();
3046 3046
 
3047
-        if ( $item_id == $this->recurring_item ) {
3047
+        if ($item_id == $this->recurring_item) {
3048 3048
             $this->recurring_item = null;
3049 3049
         }
3050 3050
 
3051
-        if ( isset( $items[ $item_id ] ) ) {
3052
-            unset( $items[ $item_id ] );
3053
-            $this->set_prop( 'items', $items );
3051
+        if (isset($items[$item_id])) {
3052
+            unset($items[$item_id]);
3053
+            $this->set_prop('items', $items);
3054 3054
         }
3055 3055
     }
3056 3056
 
@@ -3061,27 +3061,27 @@  discard block
 block discarded – undo
3061 3061
      * @param float $value
3062 3062
      * @return WP_Error|Bool
3063 3063
      */
3064
-    public function add_fee( $fee, $value, $recurring = false ) {
3064
+    public function add_fee($fee, $value, $recurring = false) {
3065 3065
 
3066
-        $amount = wpinv_sanitize_amount( $value );
3066
+        $amount = wpinv_sanitize_amount($value);
3067 3067
         $fees   = $this->get_fees();
3068 3068
 
3069
-        if ( isset( $fees[ $fee ] ) && isset( $fees[ $fee ]['amount'] ) ) {
3069
+        if (isset($fees[$fee]) && isset($fees[$fee]['amount'])) {
3070 3070
 
3071
-            $amount = $fees[ $fee ]['amount'] += $amount;
3072
-			$fees[ $fee ] = array(
3071
+            $amount = $fees[$fee]['amount'] += $amount;
3072
+			$fees[$fee] = array(
3073 3073
                 'amount'    => $amount,
3074 3074
                 'recurring' => (bool) $recurring,
3075 3075
             );
3076 3076
 
3077 3077
 		} else {
3078
-			$fees[ $fee ] = array(
3078
+			$fees[$fee] = array(
3079 3079
                 'amount'    => $amount,
3080 3080
                 'recurring' => (bool) $recurring,
3081 3081
             );
3082 3082
 		}
3083 3083
 
3084
-        $this->set_prop( 'fees', $fee );
3084
+        $this->set_prop('fees', $fee);
3085 3085
 
3086 3086
     }
3087 3087
 
@@ -3090,9 +3090,9 @@  discard block
 block discarded – undo
3090 3090
 	 *
3091 3091
 	 * @since 1.0.19
3092 3092
 	 */
3093
-	public function get_fee( $fee ) {
3093
+	public function get_fee($fee) {
3094 3094
         $fees = $this->get_fees();
3095
-		return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null;
3095
+		return isset($fees[$fee]) ? $fees[$fee] : null;
3096 3096
     }
3097 3097
 
3098 3098
     /**
@@ -3100,11 +3100,11 @@  discard block
 block discarded – undo
3100 3100
 	 *
3101 3101
 	 * @since 1.0.19
3102 3102
 	 */
3103
-	public function remove_fee( $fee ) {
3103
+	public function remove_fee($fee) {
3104 3104
         $fees = $this->get_fees();
3105
-        if ( isset( $fees[ $fee ] ) ) {
3106
-            unset( $fees[ $fee ] );
3107
-            $this->set_prop( 'fees', $fees );
3105
+        if (isset($fees[$fee])) {
3106
+            unset($fees[$fee]);
3107
+            $this->set_prop('fees', $fees);
3108 3108
         }
3109 3109
     }
3110 3110
 
@@ -3115,27 +3115,27 @@  discard block
 block discarded – undo
3115 3115
      * @param float $value
3116 3116
      * @return WP_Error|Bool
3117 3117
      */
3118
-    public function add_discount( $discount, $value, $recurring = false ) {
3118
+    public function add_discount($discount, $value, $recurring = false) {
3119 3119
 
3120
-        $amount    = wpinv_sanitize_amount( $value );
3120
+        $amount    = wpinv_sanitize_amount($value);
3121 3121
         $discounts = $this->get_discounts();
3122 3122
 
3123
-        if ( isset( $discounts[ $discount ] ) && isset( $discounts[ $discount ]['amount'] ) ) {
3123
+        if (isset($discounts[$discount]) && isset($discounts[$discount]['amount'])) {
3124 3124
 
3125
-            $amount = $discounts[ $discount ]['amount'] += $amount;
3126
-			$discounts[ $discount ] = array(
3125
+            $amount = $discounts[$discount]['amount'] += $amount;
3126
+			$discounts[$discount] = array(
3127 3127
                 'amount'    => $amount,
3128 3128
                 'recurring' => (bool) $recurring,
3129 3129
             );
3130 3130
 
3131 3131
 		} else {
3132
-			$discounts[ $discount ] = array(
3132
+			$discounts[$discount] = array(
3133 3133
                 'amount'    => $amount,
3134 3134
                 'recurring' => (bool) $recurring,
3135 3135
             );
3136 3136
 		}
3137 3137
 
3138
-        $this->set_prop( 'discounts', $discount );
3138
+        $this->set_prop('discounts', $discount);
3139 3139
 
3140 3140
     }
3141 3141
 
@@ -3144,15 +3144,15 @@  discard block
 block discarded – undo
3144 3144
 	 *
3145 3145
 	 * @since 1.0.19
3146 3146
 	 */
3147
-	public function get_discount( $discount = false ) {
3147
+	public function get_discount($discount = false) {
3148 3148
 
3149 3149
 		// Backwards compatibilty.
3150
-		if ( empty( $discount ) ) {
3150
+		if (empty($discount)) {
3151 3151
 			return $this->get_total_discount();
3152 3152
 		}
3153 3153
 
3154 3154
         $discounts = $this->get_discounts();
3155
-		return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null;
3155
+		return isset($discounts[$discount]) ? $discounts[$discount] : null;
3156 3156
     }
3157 3157
 
3158 3158
     /**
@@ -3160,11 +3160,11 @@  discard block
 block discarded – undo
3160 3160
 	 *
3161 3161
 	 * @since 1.0.19
3162 3162
 	 */
3163
-	public function remove_discount( $discount ) {
3163
+	public function remove_discount($discount) {
3164 3164
         $discounts = $this->get_discounts();
3165
-        if ( isset( $discounts[ $discount ] ) ) {
3166
-            unset( $discounts[ $discount ] );
3167
-            $this->set_prop( 'discounts', $discounts );
3165
+        if (isset($discounts[$discount])) {
3166
+            unset($discounts[$discount]);
3167
+            $this->set_prop('discounts', $discounts);
3168 3168
         }
3169 3169
     }
3170 3170
 
@@ -3174,31 +3174,31 @@  discard block
 block discarded – undo
3174 3174
      * @param string $tax
3175 3175
      * @param float $value
3176 3176
      */
3177
-    public function add_tax( $tax, $value, $recurring = true ) {
3177
+    public function add_tax($tax, $value, $recurring = true) {
3178 3178
 
3179
-        if ( ! $this->is_taxable() ) {
3179
+        if (!$this->is_taxable()) {
3180 3180
             return;
3181 3181
         }
3182 3182
 
3183
-        $amount    = wpinv_sanitize_amount( $value );
3183
+        $amount    = wpinv_sanitize_amount($value);
3184 3184
         $taxes     = $this->get_taxes();
3185 3185
 
3186
-        if ( isset( $taxes[ $tax ] ) && isset( $taxes[ $tax ]['amount'] ) ) {
3186
+        if (isset($taxes[$tax]) && isset($taxes[$tax]['amount'])) {
3187 3187
 
3188
-            $amount = $taxes[ $tax ]['amount'] += $amount;
3189
-			$taxes[ $tax ] = array(
3188
+            $amount = $taxes[$tax]['amount'] += $amount;
3189
+			$taxes[$tax] = array(
3190 3190
                 'amount'    => $amount,
3191 3191
                 'recurring' => (bool) $recurring,
3192 3192
             );
3193 3193
 
3194 3194
 		} else {
3195
-			$taxes[ $tax ] = array(
3195
+			$taxes[$tax] = array(
3196 3196
                 'amount'    => $amount,
3197 3197
                 'recurring' => (bool) $recurring,
3198 3198
             );
3199 3199
 		}
3200 3200
 
3201
-        $this->set_prop( 'taxes', $tax );
3201
+        $this->set_prop('taxes', $tax);
3202 3202
 
3203 3203
     }
3204 3204
 
@@ -3207,9 +3207,9 @@  discard block
 block discarded – undo
3207 3207
 	 *
3208 3208
 	 * @since 1.0.19
3209 3209
 	 */
3210
-	public function get_tax( $tax ) {
3210
+	public function get_tax($tax) {
3211 3211
         $taxes = $this->get_taxes();
3212
-		return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null;
3212
+		return isset($taxes[$tax]) ? $taxes[$tax] : null;
3213 3213
     }
3214 3214
 
3215 3215
     /**
@@ -3217,11 +3217,11 @@  discard block
 block discarded – undo
3217 3217
 	 *
3218 3218
 	 * @since 1.0.19
3219 3219
 	 */
3220
-	public function remove_tax( $tax ) {
3220
+	public function remove_tax($tax) {
3221 3221
         $taxes = $this->get_discounts();
3222
-        if ( isset( $taxes[ $tax ] ) ) {
3223
-            unset( $taxes[ $tax ] );
3224
-            $this->set_prop( 'taxes', $taxes );
3222
+        if (isset($taxes[$tax])) {
3223
+            unset($taxes[$tax]);
3224
+            $this->set_prop('taxes', $taxes);
3225 3225
         }
3226 3226
     }
3227 3227
 
@@ -3232,19 +3232,19 @@  discard block
 block discarded – undo
3232 3232
 	 * @return float The recalculated subtotal
3233 3233
 	 */
3234 3234
 	public function recalculate_subtotal() {
3235
-        $items     = $this->get_items();
3235
+        $items = $this->get_items();
3236 3236
 		$subtotal  = 0;
3237 3237
 		$recurring = 0;
3238 3238
 
3239
-        foreach ( $items as $item ) {
3239
+        foreach ($items as $item) {
3240 3240
 			$subtotal  += $item->get_sub_total();
3241 3241
 			$recurring += $item->get_recurring_sub_total();
3242 3242
         }
3243 3243
 
3244
-		if ( $this->is_renewal() ) {
3245
-			$this->set_subtotal( $recurring );
3244
+		if ($this->is_renewal()) {
3245
+			$this->set_subtotal($recurring);
3246 3246
 		} else {
3247
-			$this->set_subtotal( $subtotal );
3247
+			$this->set_subtotal($subtotal);
3248 3248
 		}
3249 3249
 
3250 3250
 		$this->totals['subtotal'] = array(
@@ -3266,9 +3266,9 @@  discard block
 block discarded – undo
3266 3266
 		$discount  = 0;
3267 3267
 		$recurring = 0;
3268 3268
 
3269
-        foreach ( $discounts as $data ) {
3269
+        foreach ($discounts as $data) {
3270 3270
 
3271
-			if ( $data['recurring'] ) {
3271
+			if ($data['recurring']) {
3272 3272
 				$recurring += $data['amount'];
3273 3273
 			} else {
3274 3274
 				$discount += $data['amount'];
@@ -3276,10 +3276,10 @@  discard block
 block discarded – undo
3276 3276
 
3277 3277
 		}
3278 3278
 
3279
-		if ( $this->is_renewal() ) {
3280
-			$this->set_total_discount( $recurring );
3279
+		if ($this->is_renewal()) {
3280
+			$this->set_total_discount($recurring);
3281 3281
 		} else {
3282
-			$this->set_total_discount( $discount );
3282
+			$this->set_total_discount($discount);
3283 3283
 		}
3284 3284
 
3285 3285
 		$this->totals['discount'] = array(
@@ -3298,13 +3298,13 @@  discard block
 block discarded – undo
3298 3298
 	 * @return float The recalculated tax
3299 3299
 	 */
3300 3300
 	public function recalculate_total_tax() {
3301
-        $taxes     = $this->get_taxes();
3301
+        $taxes = $this->get_taxes();
3302 3302
 		$tax       = 0;
3303 3303
 		$recurring = 0;
3304 3304
 
3305
-        foreach ( $taxes as $data ) {
3305
+        foreach ($taxes as $data) {
3306 3306
 
3307
-			if ( $data['recurring'] ) {
3307
+			if ($data['recurring']) {
3308 3308
 				$recurring += $data['amount'];
3309 3309
 			} else {
3310 3310
 				$tax += $data['amount'];
@@ -3312,10 +3312,10 @@  discard block
 block discarded – undo
3312 3312
 
3313 3313
 		}
3314 3314
 
3315
-		if ( $this->is_renewal() ) {
3316
-			$this->set_total_tax( $recurring );
3315
+		if ($this->is_renewal()) {
3316
+			$this->set_total_tax($recurring);
3317 3317
 		} else {
3318
-			$this->set_total_tax( $tax );
3318
+			$this->set_total_tax($tax);
3319 3319
 		}
3320 3320
 
3321 3321
 		$this->totals['tax'] = array(
@@ -3338,9 +3338,9 @@  discard block
 block discarded – undo
3338 3338
 		$fee       = 0;
3339 3339
 		$recurring = 0;
3340 3340
 
3341
-        foreach ( $fees as $data ) {
3341
+        foreach ($fees as $data) {
3342 3342
 
3343
-			if ( $data['recurring'] ) {
3343
+			if ($data['recurring']) {
3344 3344
 				$recurring += $data['amount'];
3345 3345
 			} else {
3346 3346
 				$fee += $data['amount'];
@@ -3348,10 +3348,10 @@  discard block
 block discarded – undo
3348 3348
 
3349 3349
 		}
3350 3350
 
3351
-        if ( $this->is_renewal() ) {
3352
-			$this->set_total_fees( $recurring );
3351
+        if ($this->is_renewal()) {
3352
+			$this->set_total_fees($recurring);
3353 3353
 		} else {
3354
-			$this->set_total_fees( $fee );
3354
+			$this->set_total_fees($fee);
3355 3355
 		}
3356 3356
 
3357 3357
 		$this->totals['fee'] = array(
@@ -3359,7 +3359,7 @@  discard block
 block discarded – undo
3359 3359
 			'recurring' => $recurring,
3360 3360
 		);
3361 3361
 
3362
-        $this->set_total_fees( $fee );
3362
+        $this->set_total_fees($fee);
3363 3363
         return $this->is_renewal() ? $recurring : $fee;
3364 3364
     }
3365 3365
 
@@ -3380,9 +3380,9 @@  discard block
 block discarded – undo
3380 3380
 	/**
3381 3381
 	 * @deprecated
3382 3382
 	 */
3383
-    public function recalculate_totals( $temp = false ) {
3384
-        $this->update_items( $temp );
3385
-        $this->save( true );
3383
+    public function recalculate_totals($temp = false) {
3384
+        $this->update_items($temp);
3385
+        $this->save(true);
3386 3386
         return $this;
3387 3387
     }
3388 3388
 
@@ -3399,33 +3399,33 @@  discard block
 block discarded – undo
3399 3399
      * @param string $note The note being added.
3400 3400
      *
3401 3401
      */
3402
-    public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
3402
+    public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) {
3403 3403
 
3404 3404
         // Bail if no note specified or this invoice is not yet saved.
3405
-        if ( ! $note || $this->get_id() == 0 ) {
3405
+        if (!$note || $this->get_id() == 0) {
3406 3406
             return false;
3407 3407
         }
3408 3408
 
3409
-        if ( ( ( is_user_logged_in() && wpinv_current_user_can_manage_invoicing() ) || $added_by_user ) && !$system ) {
3410
-            $user                 = get_user_by( 'id', get_current_user_id() );
3409
+        if (((is_user_logged_in() && wpinv_current_user_can_manage_invoicing()) || $added_by_user) && !$system) {
3410
+            $user                 = get_user_by('id', get_current_user_id());
3411 3411
             $comment_author       = $user->display_name;
3412 3412
             $comment_author_email = $user->user_email;
3413 3413
         } else {
3414 3414
             $comment_author       = 'System';
3415 3415
             $comment_author_email = 'system@';
3416
-            $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com';
3417
-            $comment_author_email = sanitize_email( $comment_author_email );
3416
+            $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com';
3417
+            $comment_author_email = sanitize_email($comment_author_email);
3418 3418
         }
3419 3419
 
3420
-        do_action( 'wpinv_pre_insert_invoice_note', $this->get_id(), $note, $customer_type );
3420
+        do_action('wpinv_pre_insert_invoice_note', $this->get_id(), $note, $customer_type);
3421 3421
 
3422
-        $note_id = wp_insert_comment( wp_filter_comment( array(
3422
+        $note_id = wp_insert_comment(wp_filter_comment(array(
3423 3423
             'comment_post_ID'      => $this->get_id(),
3424 3424
             'comment_content'      => $note,
3425 3425
             'comment_agent'        => 'GetPaid',
3426 3426
             'user_id'              => is_admin() ? get_current_user_id() : 0,
3427
-            'comment_date'         => current_time( 'mysql' ),
3428
-            'comment_date_gmt'     => current_time( 'mysql', 1 ),
3427
+            'comment_date'         => current_time('mysql'),
3428
+            'comment_date_gmt'     => current_time('mysql', 1),
3429 3429
             'comment_approved'     => 1,
3430 3430
             'comment_parent'       => 0,
3431 3431
             'comment_author'       => $comment_author,
@@ -3433,13 +3433,13 @@  discard block
 block discarded – undo
3433 3433
             'comment_author_url'   => '',
3434 3434
             'comment_author_email' => $comment_author_email,
3435 3435
             'comment_type'         => 'wpinv_note'
3436
-        ) ) );
3436
+        )));
3437 3437
 
3438
-        do_action( 'wpinv_insert_payment_note', $note_id, $this->get_id(), $note );
3438
+        do_action('wpinv_insert_payment_note', $note_id, $this->get_id(), $note);
3439 3439
 
3440
-        if ( $customer_type ) {
3441
-            add_comment_meta( $note_id, '_wpi_customer_note', 1 );
3442
-            do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->get_id(), 'user_note' => $note ) );
3440
+        if ($customer_type) {
3441
+            add_comment_meta($note_id, '_wpi_customer_note', 1);
3442
+            do_action('wpinv_new_customer_note', array('invoice_id' => $this->get_id(), 'user_note' => $note));
3443 3443
         }
3444 3444
 
3445 3445
         return $note_id;
@@ -3448,10 +3448,10 @@  discard block
 block discarded – undo
3448 3448
 	/**
3449 3449
      * Generates a unique key for the invoice.
3450 3450
      */
3451
-    public function generate_key( $string = '' ) {
3452
-        $auth_key  = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
3451
+    public function generate_key($string = '') {
3452
+        $auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
3453 3453
         return strtolower(
3454
-            md5( $this->get_id() . $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) )
3454
+            md5($this->get_id() . $string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))
3455 3455
         );
3456 3456
     }
3457 3457
 
@@ -3461,12 +3461,12 @@  discard block
 block discarded – undo
3461 3461
     public function generate_number() {
3462 3462
         $number = $this->get_id();
3463 3463
 
3464
-        if ( $this->has_status( 'auto-draft' ) && wpinv_sequential_number_active( $this->post_type ) ) {
3465
-            $next_number = wpinv_get_next_invoice_number( $this->post_type );
3464
+        if ($this->has_status('auto-draft') && wpinv_sequential_number_active($this->post_type)) {
3465
+            $next_number = wpinv_get_next_invoice_number($this->post_type);
3466 3466
             $number      = $next_number;
3467 3467
         }
3468 3468
 
3469
-		$number = wpinv_format_invoice_number( $number, $this->post_type );
3469
+		$number = wpinv_format_invoice_number($number, $this->post_type);
3470 3470
 
3471 3471
 		return $number;
3472 3472
 	}
@@ -3480,47 +3480,47 @@  discard block
 block discarded – undo
3480 3480
 		// Reset status transition variable.
3481 3481
 		$this->status_transition = false;
3482 3482
 
3483
-		if ( $status_transition ) {
3483
+		if ($status_transition) {
3484 3484
 			try {
3485 3485
 
3486 3486
 				// Fire a hook for the status change.
3487
-				do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
3487
+				do_action('getpaid_invoice_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition);
3488 3488
 
3489 3489
 				// @deprecated this is deprecated and will be removed in the future.
3490
-				do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3490
+				do_action('wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from']);
3491 3491
 
3492
-				if ( ! empty( $status_transition['from'] ) ) {
3492
+				if (!empty($status_transition['from'])) {
3493 3493
 
3494 3494
 					/* translators: 1: old invoice status 2: new invoice status */
3495
-					$transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'] ), wpinv_status_nicename( $status_transition['to'] ) );
3495
+					$transition_note = sprintf(__('Status changed from %1$s to %2$s.', 'invoicing'), wpinv_status_nicename($status_transition['from']), wpinv_status_nicename($status_transition['to']));
3496 3496
 
3497 3497
 					// Fire another hook.
3498
-					do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
3499
-					do_action( 'getpaid_invoice_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
3498
+					do_action('getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this);
3499
+					do_action('getpaid_invoice_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this);
3500 3500
 
3501 3501
 					// @deprecated this is deprecated and will be removed in the future.
3502
-					do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3502
+					do_action('wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from']);
3503 3503
 
3504 3504
 					// Note the transition occurred.
3505
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3505
+					$this->add_note(trim($status_transition['note'] . ' ' . $transition_note), 0, $status_transition['manual']);
3506 3506
 
3507 3507
 					// Work out if this was for a payment, and trigger a payment_status hook instead.
3508 3508
 					if (
3509
-						in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed' ), true )
3510
-						&& in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3509
+						in_array($status_transition['from'], array('wpi-cancelled', 'wpi-pending', 'wpi-failed'), true)
3510
+						&& in_array($status_transition['to'], array('publish', 'wpi-processing', 'wpi-renewal'), true)
3511 3511
 					) {
3512
-						do_action( 'getpaid_invoice_payment_status_changed', $this->get_id(), $this, $status_transition );
3512
+						do_action('getpaid_invoice_payment_status_changed', $this->get_id(), $this, $status_transition);
3513 3513
 					}
3514 3514
 				} else {
3515 3515
 					/* translators: %s: new invoice status */
3516
-					$transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'] ) );
3516
+					$transition_note = sprintf(__('Status set to %s.', 'invoicing'), wpinv_status_nicename($status_transition['to']));
3517 3517
 
3518 3518
 					// Note the transition occurred.
3519
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3519
+					$this->add_note(trim($status_transition['note'] . ' ' . $transition_note), 0, $status_transition['manual']);
3520 3520
 
3521 3521
 				}
3522
-			} catch ( Exception $e ) {
3523
-				$this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
3522
+			} catch (Exception $e) {
3523
+				$this->add_note(__('Error during status transition.', 'invoicing') . ' ' . $e->getMessage());
3524 3524
 			}
3525 3525
 		}
3526 3526
 	}
@@ -3528,13 +3528,13 @@  discard block
 block discarded – undo
3528 3528
 	/**
3529 3529
 	 * Updates an invoice status.
3530 3530
 	 */
3531
-	public function update_status( $new_status = false, $note = '', $manual = false ) {
3531
+	public function update_status($new_status = false, $note = '', $manual = false) {
3532 3532
 
3533 3533
 		// Fires before updating a status.
3534
-		do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) );
3534
+		do_action('wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status('edit'));
3535 3535
 
3536 3536
 		// Update the status.
3537
-		$this->set_status( $new_status, $note, $manual );
3537
+		$this->set_status($new_status, $note, $manual);
3538 3538
 
3539 3539
 		// Save the order.
3540 3540
 		return $this->save();
@@ -3545,18 +3545,18 @@  discard block
 block discarded – undo
3545 3545
 	 * @deprecated
3546 3546
 	 */
3547 3547
 	public function refresh_item_ids() {
3548
-        $item_ids = implode( ',', array_unique( array_keys( $this->get_items() ) ) );
3549
-        update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids );
3548
+        $item_ids = implode(',', array_unique(array_keys($this->get_items())));
3549
+        update_post_meta($this->get_id(), '_wpinv_item_ids', $item_ids);
3550 3550
 	}
3551 3551
 
3552 3552
 	/**
3553 3553
 	 * @deprecated
3554 3554
 	 */
3555
-	public function update_items( $temp = false ) {
3555
+	public function update_items($temp = false) {
3556 3556
 
3557
-		$this->set_items( $this->get_items() );
3557
+		$this->set_items($this->get_items());
3558 3558
 
3559
-		if ( ! $temp ) {
3559
+		if (!$temp) {
3560 3560
 			$this->save();
3561 3561
 		}
3562 3562
 
@@ -3570,11 +3570,11 @@  discard block
 block discarded – undo
3570 3570
 
3571 3571
         $discount_code = $this->get_discount_code();
3572 3572
 
3573
-        if ( empty( $discount_code ) ) {
3573
+        if (empty($discount_code)) {
3574 3574
             return false;
3575 3575
         }
3576 3576
 
3577
-        $discount = wpinv_get_discount_obj( $discount_code );
3577
+        $discount = wpinv_get_discount_obj($discount_code);
3578 3578
 
3579 3579
         // Ensure it is active.
3580 3580
         return $discount->exists();
@@ -3585,7 +3585,7 @@  discard block
 block discarded – undo
3585 3585
 	 * Refunds an invoice.
3586 3586
 	 */
3587 3587
     public function refund() {
3588
-		$this->set_status( 'wpi-refunded' );
3588
+		$this->set_status('wpi-refunded');
3589 3589
         $this->save();
3590 3590
     }
3591 3591
 
Please login to merge, or discard this patch.
includes/class-getpaid-payment-form-submission.php 1 patch
Spacing   +114 added lines, -114 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
 
@@ -147,8 +147,8 @@  discard block
 block discarded – undo
147 147
 		$this->state = wpinv_get_default_state();
148 148
 
149 149
 		// Do we have an actual submission?
150
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
151
-			$this->load_data( $_POST );
150
+		if (isset($_POST['getpaid_payment_form_submission'])) {
151
+			$this->load_data($_POST);
152 152
 		}
153 153
 	}
154 154
 
@@ -157,29 +157,29 @@  discard block
 block discarded – undo
157 157
 	 *
158 158
 	 * @param array $data
159 159
 	 */
160
-	public function load_data( $data ) {
160
+	public function load_data($data) {
161 161
 
162 162
 		// Prepare submitted data...
163
-		$data = wp_unslash( $data );
163
+		$data = wp_unslash($data);
164 164
 
165 165
 		// Fitter the data.
166
-		$data = apply_filters( 'getpaid_submission_data', $data, $this );
166
+		$data = apply_filters('getpaid_submission_data', $data, $this);
167 167
 
168 168
 		$this->data = $data;
169 169
 
170
-		$this->id = md5( wp_json_encode( $data ) );
170
+		$this->id = md5(wp_json_encode($data));
171 171
 
172 172
 		// Every submission needs an active payment form.
173
-		if ( empty( $data['form_id'] ) ) {
174
-			$this->last_error = __( 'Missing payment form', 'invoicing' );
173
+		if (empty($data['form_id'])) {
174
+			$this->last_error = __('Missing payment form', 'invoicing');
175 175
             return;
176 176
 		}
177 177
 
178 178
 		// Fetch the payment form.
179
-		$form = new GetPaid_Payment_Form( $data['form_id'] );
179
+		$form = new GetPaid_Payment_Form($data['form_id']);
180 180
 
181
-		if ( ! $form->is_active() ) {
182
-			$this->last_error = __( 'Payment form not active', 'invoicing' );
181
+		if (!$form->is_active()) {
182
+			$this->last_error = __('Payment form not active', 'invoicing');
183 183
 			return;
184 184
 		}
185 185
 
@@ -187,31 +187,31 @@  discard block
 block discarded – undo
187 187
 		$this->payment_form = $form;
188 188
 
189 189
 		// For existing invoices, make sure that it is valid.
190
-        if ( ! empty( $data['invoice_id'] ) ) {
191
-            $invoice = wpinv_get_invoice( $data['invoice_id'] );
190
+        if (!empty($data['invoice_id'])) {
191
+            $invoice = wpinv_get_invoice($data['invoice_id']);
192 192
 
193
-            if ( empty( $invoice ) ) {
194
-				$this->last_error = __( 'Invalid invoice', 'invoicing' );
193
+            if (empty($invoice)) {
194
+				$this->last_error = __('Invalid invoice', 'invoicing');
195 195
                 return;
196 196
             }
197 197
 
198
-			$this->payment_form->set_items( $invoice->get_items() );
198
+			$this->payment_form->set_items($invoice->get_items());
199 199
 
200 200
 			$this->country = $invoice->get_country();
201 201
 			$this->state = $invoice->get_state();
202 202
 
203 203
 		// Default forms do not have items.
204
-        } else if ( $form->is_default() && isset( $data['form_items'] ) ) {
205
-			$this->payment_form->set_items( $data['form_items'] );
204
+        } else if ($form->is_default() && isset($data['form_items'])) {
205
+			$this->payment_form->set_items($data['form_items']);
206 206
 		}
207 207
 
208 208
 		// User's country.
209
-		if ( ! empty( $data['wpinv_country'] ) ) {
209
+		if (!empty($data['wpinv_country'])) {
210 210
 			$this->country = $data['wpinv_country'];
211 211
 		}
212 212
 
213 213
 		// User's state.
214
-		if ( ! empty( $data['wpinv_state'] ) ) {
214
+		if (!empty($data['wpinv_state'])) {
215 215
 			$this->country = $data['wpinv_state'];
216 216
 		}
217 217
 
@@ -220,47 +220,47 @@  discard block
 block discarded – undo
220 220
 
221 221
 		// Handle items.
222 222
 		$selected_items = array();
223
-		if ( ! empty( $data['getpaid-items'] ) ) {
224
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
223
+		if (!empty($data['getpaid-items'])) {
224
+			$selected_items = wpinv_clean($data['getpaid-items']);
225 225
 		}
226 226
 
227
-		foreach ( $this->payment_form->get_items() as $item ) {
227
+		foreach ($this->payment_form->get_items() as $item) {
228 228
 
229 229
 			// Continue if this is an optional item and it has not been selected.
230
-			if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
230
+			if (!$item->is_required() && !isset($selected_items[$item->get_id()])) {
231 231
 				continue;
232 232
 			}
233 233
 
234 234
 			// (maybe) let customers change the quantities and prices.
235
-			if ( isset( $selected_items[ $item->get_id() ] ) ) {
235
+			if (isset($selected_items[$item->get_id()])) {
236 236
 
237 237
 				// Maybe change the quantities.
238
-				if ( $item->allows_quantities() && is_numeric( $selected_items[ $item->get_id() ]['quantity'] ) ) {
239
-					$item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] );
238
+				if ($item->allows_quantities() && is_numeric($selected_items[$item->get_id()]['quantity'])) {
239
+					$item->set_quantity((int) $selected_items[$item->get_id()]['quantity']);
240 240
 				}
241 241
 
242 242
 				// Maybe change the price.
243
-				if ( $item->user_can_set_their_price() ) {
244
-					$price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
243
+				if ($item->user_can_set_their_price()) {
244
+					$price = (float) wpinv_sanitize_amount($selected_items[$item->get_id()]['price']);
245 245
 
246 246
 					// But don't get lower than the minimum price.
247
-					if ( $price < $item->get_minimum_price() ) {
247
+					if ($price < $item->get_minimum_price()) {
248 248
 						$price = $item->get_minimum_price();
249 249
 					}
250 250
 
251
-					$item->set_price( $price );
251
+					$item->set_price($price);
252 252
 
253 253
 				}
254 254
 
255 255
 			}
256 256
 
257 257
 			// Add the item to the form.
258
-			$this->add_item( $item );
258
+			$this->add_item($item);
259 259
 
260 260
 		}
261 261
 
262 262
 		// Fired when we are done processing a submission.
263
-		do_action( 'getpaid_process_submission', $this );
263
+		do_action('getpaid_process_submission', $this);
264 264
 
265 265
 		// Remove invalid discount.
266 266
 		$this->maybe_remove_discount();
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 	 * @return bool
295 295
 	 */
296 296
 	public function has_invoice() {
297
-		return ! empty( $this->invoice );
297
+		return !empty($this->invoice);
298 298
 	}
299 299
 	
300 300
 	/**
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 	 * @return string
305 305
 	 */
306 306
 	public function get_currency() {
307
-		if ( $this->has_invoice() ) {
307
+		if ($this->has_invoice()) {
308 308
 			return $this->invoice->get_currency();
309 309
 		}
310 310
 		return wpinv_get_currency();
@@ -325,8 +325,8 @@  discard block
 block discarded – undo
325 325
 	 *
326 326
 	 * @since 1.0.19
327 327
 	 */
328
-	public function is_required_field_set( $field ) {
329
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
328
+	public function is_required_field_set($field) {
329
+		return empty($field['required']) || !empty($this->data[$field['id']]);
330 330
 	}
331 331
 
332 332
 	///////// Items //////////////
@@ -337,31 +337,31 @@  discard block
 block discarded – undo
337 337
 	 * @since 1.0.19
338 338
 	 * @param GetPaid_Form_Item $item
339 339
 	 */
340
-	public function add_item( $item ) {
340
+	public function add_item($item) {
341 341
 
342 342
 		// Make sure that it is available for purchase.
343
-		if ( ! $item->can_purchase() ) {
343
+		if (!$item->can_purchase()) {
344 344
 			return;
345 345
 		}
346 346
 
347 347
 		// Do we have a recurring item?
348
-		if ( $item->is_recurring() ) {
348
+		if ($item->is_recurring()) {
349 349
 
350
-			if ( $this->has_recurring ) {
351
-				$this->last_error = __( 'You can only buy one recurring item at a time.', 'invoicing' );
350
+			if ($this->has_recurring) {
351
+				$this->last_error = __('You can only buy one recurring item at a time.', 'invoicing');
352 352
 			}
353 353
 
354 354
 			$this->has_recurring = true;
355 355
 
356 356
 		}
357 357
 
358
-		$this->items[ $item->get_id() ] = $item;
358
+		$this->items[$item->get_id()] = $item;
359 359
 
360 360
 		$this->subtotal_amount += $item->get_sub_total();
361 361
 
362
-		$this->process_item_discount( $item );
362
+		$this->process_item_discount($item);
363 363
 
364
-		$this->process_item_tax( $item );
364
+		$this->process_item_tax($item);
365 365
 	}
366 366
 
367 367
 	/**
@@ -369,8 +369,8 @@  discard block
 block discarded – undo
369 369
 	 *
370 370
 	 * @since 1.0.19
371 371
 	 */
372
-	public function get_item( $item_id ) {
373
-		return isset( $this->items[ $item_id ] ) ? $this->items[ $item_id ] : null;
372
+	public function get_item($item_id) {
373
+		return isset($this->items[$item_id]) ? $this->items[$item_id] : null;
374 374
 	}
375 375
 
376 376
 	/**
@@ -390,15 +390,15 @@  discard block
 block discarded – undo
390 390
 	 *
391 391
 	 * @since 1.0.19
392 392
 	 */
393
-	public function add_tax( $name, $amount ) {
394
-		$amount = (float) wpinv_sanitize_amount( $amount );
393
+	public function add_tax($name, $amount) {
394
+		$amount = (float) wpinv_sanitize_amount($amount);
395 395
 
396 396
 		$this->total_tax_amount += $amount;
397 397
 
398
-		if ( isset( $this->taxes[ $name ] ) ) {
399
-			$this->taxes[ $name ] += $amount;
398
+		if (isset($this->taxes[$name])) {
399
+			$this->taxes[$name] += $amount;
400 400
 		} else {
401
-			$this->taxes[ $name ] = $amount;
401
+			$this->taxes[$name] = $amount;
402 402
 		}
403 403
 
404 404
 	}
@@ -412,11 +412,11 @@  discard block
 block discarded – undo
412 412
 
413 413
 		$use_taxes = wpinv_use_taxes();
414 414
 
415
-		if ( $this->has_invoice() && $this->invoice->disable_taxes ) {
415
+		if ($this->has_invoice() && $this->invoice->disable_taxes) {
416 416
 			$use_taxes = false;
417 417
 		}
418 418
 
419
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
419
+		return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this);
420 420
 
421 421
 	}
422 422
 
@@ -426,23 +426,23 @@  discard block
 block discarded – undo
426 426
 	 * @since 1.0.19 
427 427
 	 * @param GetPaid_Form_Item $item
428 428
 	 */
429
-	public function process_item_tax( $item ) {
429
+	public function process_item_tax($item) {
430 430
 
431 431
 		// Abort early if we're not using taxes.
432
-		if ( ! $this->use_taxes() ) {
432
+		if (!$this->use_taxes()) {
433 433
 			return;
434 434
 		}
435 435
 
436
-		$rate  = wpinv_get_tax_rate( $this->country, $this->state, $item->get_id() );
436
+		$rate  = wpinv_get_tax_rate($this->country, $this->state, $item->get_id());
437 437
 		$price = $item->get_sub_total();
438 438
 
439
-		if ( wpinv_prices_include_tax() ) {
440
-			$item_tax = $price - ( $price - $price * $rate * 0.01 );
439
+		if (wpinv_prices_include_tax()) {
440
+			$item_tax = $price - ($price - $price * $rate * 0.01);
441 441
 		} else {
442 442
 			$item_tax = $price * $rate * 0.01;
443 443
 		}
444 444
 
445
-		$this->add_tax( 'Tax', $item_tax );
445
+		$this->add_tax('Tax', $item_tax);
446 446
 
447 447
 	}
448 448
 
@@ -460,8 +460,8 @@  discard block
 block discarded – undo
460 460
 	 *
461 461
 	 * @since 1.0.19
462 462
 	 */
463
-	public function get_tax( $name ) {
464
-		return isset( $this->taxes[ $name ] ) ? $this->taxes[ $name ] : 0;
463
+	public function get_tax($name) {
464
+		return isset($this->taxes[$name]) ? $this->taxes[$name] : 0;
465 465
 	}
466 466
 
467 467
 	/**
@@ -480,15 +480,15 @@  discard block
 block discarded – undo
480 480
 	 *
481 481
 	 * @since 1.0.19
482 482
 	 */
483
-	public function add_discount( $name, $amount ) {
484
-		$amount = wpinv_sanitize_amount( $amount );
483
+	public function add_discount($name, $amount) {
484
+		$amount = wpinv_sanitize_amount($amount);
485 485
 
486 486
 		$this->total_discount_amount += $amount;
487 487
 
488
-		if ( isset( $this->discounts[ $name ] ) ) {
489
-			$this->discounts[ $name ] += $amount;
488
+		if (isset($this->discounts[$name])) {
489
+			$this->discounts[$name] += $amount;
490 490
 		} else {
491
-			$this->discounts[ $name ] = $amount;
491
+			$this->discounts[$name] = $amount;
492 492
 		}
493 493
 
494 494
 	}
@@ -498,11 +498,11 @@  discard block
 block discarded – undo
498 498
 	 *
499 499
 	 * @since 1.0.19
500 500
 	 */
501
-	public function remove_discount( $name ) {
501
+	public function remove_discount($name) {
502 502
 
503
-		if ( isset( $this->discounts[ $name ] ) ) {
504
-			$this->total_discount_amount -= $this->discounts[ $name ];
505
-			unset( $this->discounts[ $name ] );
503
+		if (isset($this->discounts[$name])) {
504
+			$this->total_discount_amount -= $this->discounts[$name];
505
+			unset($this->discounts[$name]);
506 506
 		}
507 507
 
508 508
 	}
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
 	 * @return bool
515 515
 	 */
516 516
 	public function has_discount_code() {
517
-		return ! empty( $this->discount );
517
+		return !empty($this->discount);
518 518
 	}
519 519
 
520 520
 	/**
@@ -535,32 +535,32 @@  discard block
 block discarded – undo
535 535
 	public function maybe_prepare_discount() {
536 536
 
537 537
 		// Do we have a discount?
538
-		if ( empty( $this->data['discount'] ) ) {
538
+		if (empty($this->data['discount'])) {
539 539
 			return;
540 540
 		}
541 541
 
542 542
 		// Fetch the discount.
543
-		$discount = wpinv_get_discount_obj( $this->data['discount'] );
543
+		$discount = wpinv_get_discount_obj($this->data['discount']);
544 544
 
545 545
 		// Ensure it is active.
546
-        if ( ! $discount->exists() || ! $discount->is_active() || ! $discount->has_started() || $discount->is_expired() ) {
546
+        if (!$discount->exists() || !$discount->is_active() || !$discount->has_started() || $discount->is_expired()) {
547 547
 			$this->is_discount_valid = false;
548
-			$this->last_error = __( 'Invalid or expired discount code', 'invoicing' );
548
+			$this->last_error = __('Invalid or expired discount code', 'invoicing');
549 549
 			return;
550 550
 		}
551 551
 
552 552
 		// For single use discounts...
553
-		if ( $discount->is_single_use ) {
553
+		if ($discount->is_single_use) {
554 554
 
555
-			if ( ! $this->has_billing_email() ) {
555
+			if (!$this->has_billing_email()) {
556 556
 				$this->is_discount_valid = false;
557
-				$this->last_error = __( 'You need to enter your billing email before applying this discount', 'invoicing' );
557
+				$this->last_error = __('You need to enter your billing email before applying this discount', 'invoicing');
558 558
 				return;
559 559
 			}
560 560
 
561
-			if ( ! $discount->is_valid_for_user( $this->get_billing_email() ) ) {
561
+			if (!$discount->is_valid_for_user($this->get_billing_email())) {
562 562
 				$this->is_discount_valid = false;
563
-				$this->last_error = __( 'You have already used this discount', 'invoicing' );
563
+				$this->last_error = __('You have already used this discount', 'invoicing');
564 564
 				return;
565 565
 			}
566 566
 		}
@@ -578,35 +578,35 @@  discard block
 block discarded – undo
578 578
 	public function maybe_remove_discount() {
579 579
 
580 580
 		// Do we have a discount?
581
-		if ( empty( $this->has_discount_code() ) ) {
581
+		if (empty($this->has_discount_code())) {
582 582
 			return;
583 583
 		}
584 584
 
585 585
 		// Fetch the discount amount.
586
-		$amount = $this->get_discount( 'Discount' );
586
+		$amount = $this->get_discount('Discount');
587 587
 
588 588
 		// Abort early if this is a "zero" discount.
589
-		if ( empty( $amount ) ) {
589
+		if (empty($amount)) {
590 590
 			return;
591 591
 		}
592 592
 
593 593
 		$total = $this->subtotal_amount + $this->get_total_fees() + $this->get_total_tax();
594 594
 
595
-		if ( ! $this->discount->is_minimum_amount_met( $total ) ) {
595
+		if (!$this->discount->is_minimum_amount_met($total)) {
596 596
 			$this->is_discount_valid = false;
597
-            $min = wpinv_price( wpinv_format_amount( $$this->discount->min_total ) );
598
-			$this->last_error = sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min );
597
+            $min = wpinv_price(wpinv_format_amount($$this->discount->min_total));
598
+			$this->last_error = sprintf(__('The minimum total for using this discount is %s', 'invoicing'), $min);
599 599
         }
600 600
 
601
-        if ( ! $$this->discount->is_maximum_amount_met( $total ) ) {
601
+        if (!$$this->discount->is_maximum_amount_met($total)) {
602 602
 			$this->is_discount_valid = false;
603
-            $max = wpinv_price( wpinv_format_amount( $$this->discount->max_total ) );
604
-			$this->last_error = sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max );
603
+            $max = wpinv_price(wpinv_format_amount($$this->discount->max_total));
604
+			$this->last_error = sprintf(__('The maximum total for using this discount is %s', 'invoicing'), $max);
605 605
 		}
606 606
 
607
-		if ( ! $this->is_discount_valid ) {
607
+		if (!$this->is_discount_valid) {
608 608
 			$this->discount = null;
609
-			$this->remove_discount( 'Discount' );
609
+			$this->remove_discount('Discount');
610 610
 		}
611 611
 
612 612
     }
@@ -617,22 +617,22 @@  discard block
 block discarded – undo
617 617
 	 * @since 1.0.19
618 618
 	 * @param GetPaid_Form_Item $item
619 619
 	 */
620
-	public function process_item_discount( $item ) {
620
+	public function process_item_discount($item) {
621 621
 
622 622
 		// Abort early if there is no discount.
623
-		if ( ! $this->has_discount_code() ) {
623
+		if (!$this->has_discount_code()) {
624 624
 			return;
625 625
 		}
626 626
 
627 627
 		// Ensure that it is valid for this item.
628
-		if ( ! $this->discount->is_valid_for_items( array( $item->get_id() ) ) ) {
628
+		if (!$this->discount->is_valid_for_items(array($item->get_id()))) {
629 629
 			return;
630 630
 		}
631 631
 
632 632
 		// Fetch the discounted amount.
633
-		$discount = $this->discount->get_discounted_amount( $item->get_price() * $item->get_quantity() );
633
+		$discount = $this->discount->get_discounted_amount($item->get_price() * $item->get_quantity());
634 634
 
635
-		$this->add_discount( 'Discount', $discount );
635
+		$this->add_discount('Discount', $discount);
636 636
 
637 637
 	}
638 638
 
@@ -650,8 +650,8 @@  discard block
 block discarded – undo
650 650
 	 *
651 651
 	 * @since 1.0.19
652 652
 	 */
653
-	public function get_discount( $name ) {
654
-		return isset( $this->discounts[ $name ] ) ? $this->discounts[ $name ] : 0;
653
+	public function get_discount($name) {
654
+		return isset($this->discounts[$name]) ? $this->discounts[$name] : 0;
655 655
 	}
656 656
 
657 657
 	/**
@@ -670,15 +670,15 @@  discard block
 block discarded – undo
670 670
 	 *
671 671
 	 * @since 1.0.19
672 672
 	 */
673
-	public function add_fee( $name, $amount ) {
674
-		$amount = wpinv_sanitize_amount( $amount );
673
+	public function add_fee($name, $amount) {
674
+		$amount = wpinv_sanitize_amount($amount);
675 675
 
676 676
 		$this->total_fees_amount += $amount;
677 677
 
678
-		if ( isset( $this->fees[ $name ] ) ) {
679
-			$this->fees[ $name ] += $amount;
678
+		if (isset($this->fees[$name])) {
679
+			$this->fees[$name] += $amount;
680 680
 		} else {
681
-			$this->fees[ $name ] = $amount;
681
+			$this->fees[$name] = $amount;
682 682
 		}
683 683
 
684 684
 	}
@@ -697,8 +697,8 @@  discard block
 block discarded – undo
697 697
 	 *
698 698
 	 * @since 1.0.19
699 699
 	 */
700
-	public function get_fee( $name ) {
701
-		return isset( $this->fees[ $name ] ) ? $this->fees[ $name ] : 0;
700
+	public function get_fee($name) {
701
+		return isset($this->fees[$name]) ? $this->fees[$name] : 0;
702 702
 	}
703 703
 
704 704
 	/**
@@ -719,8 +719,8 @@  discard block
 block discarded – undo
719 719
 	 */
720 720
 	public function get_total() {
721 721
 		$total = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax();
722
-		$total = apply_filters( 'getpaid_get_submission_total_amount', $total, $this  );
723
-		return wpinv_sanitize_amount( $total );
722
+		$total = apply_filters('getpaid_get_submission_total_amount', $total, $this);
723
+		return wpinv_sanitize_amount($total);
724 724
 	}
725 725
 
726 726
 	/**
@@ -731,11 +731,11 @@  discard block
 block discarded – undo
731 731
 	public function get_payment_details() {
732 732
 		$collect = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax();
733 733
 
734
-		if ( $this->has_recurring ) {
734
+		if ($this->has_recurring) {
735 735
 			$collect = true;
736 736
 		}
737 737
 
738
-		$collect = apply_filters( 'getpaid_submission_collect_payment_details', $collect, $this  );
738
+		$collect = apply_filters('getpaid_submission_collect_payment_details', $collect, $this);
739 739
 		return $collect;
740 740
 	}
741 741
 
@@ -745,8 +745,8 @@  discard block
 block discarded – undo
745 745
 	 * @since 1.0.19
746 746
 	 */
747 747
 	public function get_billing_email() {
748
-		$billing_email = empty( $this->data['billing_email'] ) ? '' : $this->data['billing_email'];
749
-		return apply_filters( 'getpaid_get_submission_billing_email', $billing_email, $this  );
748
+		$billing_email = empty($this->data['billing_email']) ? '' : $this->data['billing_email'];
749
+		return apply_filters('getpaid_get_submission_billing_email', $billing_email, $this);
750 750
 	}
751 751
 
752 752
 	/**
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
 	 */
757 757
 	public function has_billing_email() {
758 758
 		$billing_email = $this->get_billing_email();
759
-		return ! empty( $billing_email );
759
+		return !empty($billing_email);
760 760
 	}
761 761
 
762 762
 }
Please login to merge, or discard this patch.
includes/wpinv-invoice-functions.php 1 patch
Spacing   +810 added lines, -810 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 /**
@@ -16,18 +16,18 @@  discard block
 block discarded – undo
16 16
  */
17 17
 function getpaid_get_invoice_post_types() {
18 18
     $post_types = array(
19
-        'wpi_quote'   => __( 'Quote', 'invoicing' ),
20
-        'wpi_invoice' => __( 'Invoice', 'invoicing' ),
19
+        'wpi_quote'   => __('Quote', 'invoicing'),
20
+        'wpi_invoice' => __('Invoice', 'invoicing'),
21 21
     );
22 22
     
23
-    return apply_filters( 'getpaid_invoice_post_types', $post_types );
23
+    return apply_filters('getpaid_invoice_post_types', $post_types);
24 24
 }
25 25
 
26 26
 /**
27 27
  * Checks if this is an invocing post type.
28 28
  */
29
-function getpaid_is_invoice_post_type( $post_type ) {
30
-    return $post_type && array_key_exists( $post_type, getpaid_get_invoice_post_types() );
29
+function getpaid_is_invoice_post_type($post_type) {
30
+    return $post_type && array_key_exists($post_type, getpaid_get_invoice_post_types());
31 31
 }
32 32
 
33 33
 /**
@@ -36,15 +36,15 @@  discard block
 block discarded – undo
36 36
 function wpinv_get_invoice_cart_id() {
37 37
 
38 38
     // Ensure that we have an invoice key.
39
-    if ( empty( $_GET['invoice_key'] ) ) {
39
+    if (empty($_GET['invoice_key'])) {
40 40
         return 0;
41 41
     }
42 42
 
43 43
     // Retrieve an invoice using the key.
44
-    $invoice = new WPInv_Invoice( $_GET['invoice_key'] );
44
+    $invoice = new WPInv_Invoice($_GET['invoice_key']);
45 45
 
46 46
     // Compare the invoice key and the parsed key.
47
-    if ( $invoice->get_id() != 0 && $invoice->get_key() == $_GET['invoice_key'] ) {
47
+    if ($invoice->get_id() != 0 && $invoice->get_key() == $_GET['invoice_key']) {
48 48
         return $invoice->get_id();
49 49
     }
50 50
 
@@ -58,48 +58,48 @@  discard block
 block discarded – undo
58 58
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
59 59
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
60 60
  */
61
-function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) {
62
-    if ( empty( $invoice_data ) ) {
61
+function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) {
62
+    if (empty($invoice_data)) {
63 63
         return false;
64 64
     }
65 65
     
66
-    if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) {
67
-        return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast one item.', 'invoicing' ) ) : 0;
66
+    if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) {
67
+        return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast one item.', 'invoicing')) : 0;
68 68
     }
69 69
     
70 70
     // If no user id is provided, default to the current user id
71
-    if ( empty( $invoice_data['user_id'] ) ) {
71
+    if (empty($invoice_data['user_id'])) {
72 72
         $invoice_data['user_id'] = get_current_user_id();
73 73
     }
74 74
     
75
-    $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0;
75
+    $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int) $invoice_data['invoice_id'] : 0;
76 76
     
77
-    if ( empty( $invoice_data['status'] ) ) {
77
+    if (empty($invoice_data['status'])) {
78 78
         $invoice_data['status'] = 'wpi-pending';
79 79
     }
80 80
 
81
-    if ( empty( $invoice_data['post_type'] ) ) {
81
+    if (empty($invoice_data['post_type'])) {
82 82
         $invoice_data['post_type'] = 'wpi_invoice';
83 83
     }
84 84
     
85
-    if ( empty( $invoice_data['ip'] ) ) {
85
+    if (empty($invoice_data['ip'])) {
86 86
         $invoice_data['ip'] = wpinv_get_ip();
87 87
     }
88 88
 
89 89
     // default invoice args, note that status is checked for validity in wpinv_create_invoice()
90 90
     $default_args = array(
91
-        'invoice_id'    => (int)$invoice_data['invoice_id'],
92
-        'user_id'       => (int)$invoice_data['user_id'],
91
+        'invoice_id'    => (int) $invoice_data['invoice_id'],
92
+        'user_id'       => (int) $invoice_data['user_id'],
93 93
         'status'        => $invoice_data['status'],
94 94
         'post_type'     => $invoice_data['post_type'],
95 95
     );
96 96
 
97
-    $invoice = wpinv_create_invoice( $default_args, $invoice_data, true );
98
-    if ( is_wp_error( $invoice ) ) {
97
+    $invoice = wpinv_create_invoice($default_args, $invoice_data, true);
98
+    if (is_wp_error($invoice)) {
99 99
         return $wp_error ? $invoice : 0;
100 100
     }
101 101
     
102
-    if ( empty( $invoice_data['invoice_id'] ) ) {
102
+    if (empty($invoice_data['invoice_id'])) {
103 103
         //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );
104 104
     }
105 105
     
@@ -122,24 +122,24 @@  discard block
 block discarded – undo
122 122
         'discount'              => array(),
123 123
     );
124 124
 
125
-    if ( $user_id = (int)$invoice->get_user_id() ) {
126
-        if ( $user_address = wpinv_get_user_address( $user_id ) ) {
127
-            $default_user_info = wp_parse_args( $user_address, $default_user_info );
125
+    if ($user_id = (int) $invoice->get_user_id()) {
126
+        if ($user_address = wpinv_get_user_address($user_id)) {
127
+            $default_user_info = wp_parse_args($user_address, $default_user_info);
128 128
         }
129 129
     }
130 130
     
131
-    if ( empty( $invoice_data['user_info'] ) ) {
131
+    if (empty($invoice_data['user_info'])) {
132 132
         $invoice_data['user_info'] = array();
133 133
     }
134 134
     
135
-    $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info );
135
+    $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info);
136 136
     
137
-    if ( empty( $user_info['first_name'] ) ) {
137
+    if (empty($user_info['first_name'])) {
138 138
         $user_info['first_name'] = $default_user_info['first_name'];
139 139
         $user_info['last_name'] = $default_user_info['last_name'];
140 140
     }
141 141
     
142
-    if ( empty( $user_info['country'] ) ) {
142
+    if (empty($user_info['country'])) {
143 143
         $user_info['country'] = $default_user_info['country'];
144 144
         $user_info['state'] = $default_user_info['state'];
145 145
         $user_info['city'] = $default_user_info['city'];
@@ -148,13 +148,13 @@  discard block
 block discarded – undo
148 148
         $user_info['phone'] = $default_user_info['phone'];
149 149
     }
150 150
     
151
-    if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) {
152
-        $user_info['discount'] = (array)$user_info['discount'];
151
+    if (!empty($user_info['discount']) && !is_array($user_info['discount'])) {
152
+        $user_info['discount'] = (array) $user_info['discount'];
153 153
     }
154 154
 
155 155
     // Payment details
156 156
     $payment_details = array();
157
-    if ( !empty( $invoice_data['payment_details'] ) ) {
157
+    if (!empty($invoice_data['payment_details'])) {
158 158
         $default_payment_details = array(
159 159
             'gateway'           => 'manual',
160 160
             'gateway_title'     => '',
@@ -162,56 +162,56 @@  discard block
 block discarded – undo
162 162
             'transaction_id'    => '',
163 163
         );
164 164
         
165
-        $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details );
165
+        $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details);
166 166
         
167
-        if ( empty( $payment_details['gateway'] ) ) {
167
+        if (empty($payment_details['gateway'])) {
168 168
             $payment_details['gateway'] = 'manual';
169 169
         }
170 170
         
171
-        if ( empty( $payment_details['currency'] ) ) {
171
+        if (empty($payment_details['currency'])) {
172 172
             $payment_details['currency'] = wpinv_get_default_country();
173 173
         }
174 174
         
175
-        if ( empty( $payment_details['gateway_title'] ) ) {
176
-            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] );
175
+        if (empty($payment_details['gateway_title'])) {
176
+            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']);
177 177
         }
178 178
     }
179 179
     
180
-    $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'wpi-pending' ) );
181
-    
182
-    if ( !empty( $payment_details ) ) {
183
-        $invoice->set( 'currency', $payment_details['currency'] );
184
-        $invoice->set( 'gateway', $payment_details['gateway'] );
185
-        $invoice->set( 'gateway_title', $payment_details['gateway_title'] );
186
-        $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
187
-    }
188
-    
189
-    $invoice->set( 'user_info', $user_info );
190
-    $invoice->set( 'first_name', $user_info['first_name'] );
191
-    $invoice->set( 'last_name', $user_info['last_name'] );
192
-    $invoice->set( 'address', $user_info['address'] );
193
-    $invoice->set( 'company', $user_info['company'] );
194
-    $invoice->set( 'vat_number', $user_info['vat_number'] );
195
-    $invoice->set( 'phone', $user_info['phone'] );
196
-    $invoice->set( 'city', $user_info['city'] );
197
-    $invoice->set( 'country', $user_info['country'] );
198
-    $invoice->set( 'state', $user_info['state'] );
199
-    $invoice->set( 'zip', $user_info['zip'] );
200
-    $invoice->set( 'discounts', $user_info['discount'] );
201
-    $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) );
202
-    $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) );
203
-    $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) );
204
-    
205
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) {
206
-        foreach ( $invoice_data['cart_details'] as $key => $item ) {
207
-            $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
208
-            $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
209
-            $name           = !empty( $item['name'] ) ? $item['name'] : '';
210
-            $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : '';
180
+    $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'wpi-pending'));
181
+    
182
+    if (!empty($payment_details)) {
183
+        $invoice->set('currency', $payment_details['currency']);
184
+        $invoice->set('gateway', $payment_details['gateway']);
185
+        $invoice->set('gateway_title', $payment_details['gateway_title']);
186
+        $invoice->set('transaction_id', $payment_details['transaction_id']);
187
+    }
188
+    
189
+    $invoice->set('user_info', $user_info);
190
+    $invoice->set('first_name', $user_info['first_name']);
191
+    $invoice->set('last_name', $user_info['last_name']);
192
+    $invoice->set('address', $user_info['address']);
193
+    $invoice->set('company', $user_info['company']);
194
+    $invoice->set('vat_number', $user_info['vat_number']);
195
+    $invoice->set('phone', $user_info['phone']);
196
+    $invoice->set('city', $user_info['city']);
197
+    $invoice->set('country', $user_info['country']);
198
+    $invoice->set('state', $user_info['state']);
199
+    $invoice->set('zip', $user_info['zip']);
200
+    $invoice->set('discounts', $user_info['discount']);
201
+    $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip()));
202
+    $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live'));
203
+    $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : ''));
204
+    
205
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) {
206
+        foreach ($invoice_data['cart_details'] as $key => $item) {
207
+            $item_id        = !empty($item['id']) ? $item['id'] : 0;
208
+            $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
209
+            $name           = !empty($item['name']) ? $item['name'] : '';
210
+            $item_price     = isset($item['item_price']) ? $item['item_price'] : '';
211 211
             
212
-            $post_item  = new WPInv_Item( $item_id );
213
-            if ( !empty( $post_item ) ) {
214
-                $name       = !empty( $name ) ? $name : $post_item->get_name();
212
+            $post_item = new WPInv_Item($item_id);
213
+            if (!empty($post_item)) {
214
+                $name       = !empty($name) ? $name : $post_item->get_name();
215 215
                 $item_price = $item_price !== '' ? $item_price : $post_item->get_price();
216 216
             } else {
217 217
                 continue;
@@ -221,266 +221,266 @@  discard block
 block discarded – undo
221 221
                 'name'          => $name,
222 222
                 'quantity'      => $quantity,
223 223
                 'item_price'    => $item_price,
224
-                'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
225
-                'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0.00,
226
-                'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
227
-                'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
228
-                'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
224
+                'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
225
+                'tax'           => !empty($item['tax']) ? $item['tax'] : 0.00,
226
+                'discount'      => isset($item['discount']) ? $item['discount'] : 0,
227
+                'meta'          => isset($item['meta']) ? $item['meta'] : array(),
228
+                'fees'          => isset($item['fees']) ? $item['fees'] : array(),
229 229
             );
230 230
 
231
-            $invoice->add_item( $item_id, $args );
231
+            $invoice->add_item($item_id, $args);
232 232
         }
233 233
     }
234 234
 
235
-    $invoice->increase_tax( wpinv_get_cart_fee_tax() );
235
+    $invoice->increase_tax(wpinv_get_cart_fee_tax());
236 236
 
237
-    if ( isset( $invoice_data['post_date'] ) ) {
238
-        $invoice->set( 'date', $invoice_data['post_date'] );
237
+    if (isset($invoice_data['post_date'])) {
238
+        $invoice->set('date', $invoice_data['post_date']);
239 239
     }
240 240
     
241 241
     // Invoice due date
242
-    if ( isset( $invoice_data['due_date'] ) ) {
243
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
242
+    if (isset($invoice_data['due_date'])) {
243
+        $invoice->set('due_date', $invoice_data['due_date']);
244 244
     }
245 245
     
246 246
     $invoice->save();
247 247
     
248 248
     // Add notes
249
-    if ( !empty( $invoice_data['private_note'] ) ) {
250
-        $invoice->add_note( $invoice_data['private_note'] );
249
+    if (!empty($invoice_data['private_note'])) {
250
+        $invoice->add_note($invoice_data['private_note']);
251 251
     }
252
-    if ( !empty( $invoice_data['user_note'] ) ) {
253
-        $invoice->add_note( $invoice_data['user_note'], true );
252
+    if (!empty($invoice_data['user_note'])) {
253
+        $invoice->add_note($invoice_data['user_note'], true);
254 254
     }
255 255
     
256
-    if ( $invoice->is_quote() ) {
256
+    if ($invoice->is_quote()) {
257 257
 
258
-        if ( isset( $invoice_data['valid_until'] ) ) {
259
-            update_post_meta( $invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until'] );
258
+        if (isset($invoice_data['valid_until'])) {
259
+            update_post_meta($invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until']);
260 260
         }
261 261
         return $invoice;
262 262
 
263 263
     }
264 264
 
265
-    do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data );
265
+    do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data);
266 266
 
267
-    if ( ! empty( $invoice->ID ) ) {
267
+    if (!empty($invoice->ID)) {
268 268
         global $wpi_userID, $wpinv_ip_address_country;
269 269
         
270
-        if ( isset( $invoice_data['created_via'] ) ) {
271
-            update_post_meta( $invoice->ID, 'wpinv_created_via', $invoice_data['created_via'] );
270
+        if (isset($invoice_data['created_via'])) {
271
+            update_post_meta($invoice->ID, 'wpinv_created_via', $invoice_data['created_via']);
272 272
         }
273 273
 
274 274
         $checkout_session = wpinv_get_checkout_session();
275 275
         
276 276
         $data_session                   = array();
277 277
         $data_session['invoice_id']     = $invoice->ID;
278
-        $data_session['cart_discounts'] = $invoice->get_discounts( true );
278
+        $data_session['cart_discounts'] = $invoice->get_discounts(true);
279 279
         
280
-        wpinv_set_checkout_session( $data_session );
280
+        wpinv_set_checkout_session($data_session);
281 281
         
282
-        $wpi_userID         = (int)$invoice->get_user_id();
282
+        $wpi_userID         = (int) $invoice->get_user_id();
283 283
         
284
-        $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
284
+        $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
285 285
         $_POST['state']     = $invoice->state;
286 286
 
287
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
288
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
287
+        $invoice->set('country', sanitize_text_field($_POST['country']));
288
+        $invoice->set('state', sanitize_text_field($_POST['state']));
289 289
         
290 290
         $wpinv_ip_address_country = $invoice->country;
291 291
 
292
-        $invoice = $invoice->recalculate_totals( true );
292
+        $invoice = $invoice->recalculate_totals(true);
293 293
 
294
-        wpinv_set_checkout_session( $checkout_session );
294
+        wpinv_set_checkout_session($checkout_session);
295 295
 
296 296
         return $invoice;
297 297
     }
298 298
     
299
-    if ( $wp_error ) {
300
-        if ( is_wp_error( $invoice ) ) {
299
+    if ($wp_error) {
300
+        if (is_wp_error($invoice)) {
301 301
             return $invoice;
302 302
         } else {
303
-            return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) );
303
+            return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing'));
304 304
         }
305 305
     } else {
306 306
         return 0;
307 307
     }
308 308
 }
309 309
 
310
-function wpinv_update_invoice( $invoice_data = array(), $wp_error = false ) {
311
-    $invoice_ID = !empty( $invoice_data['ID'] ) ? absint( $invoice_data['ID'] ) : NULL;
310
+function wpinv_update_invoice($invoice_data = array(), $wp_error = false) {
311
+    $invoice_ID = !empty($invoice_data['ID']) ? absint($invoice_data['ID']) : NULL;
312 312
 
313
-    if ( !$invoice_ID ) {
314
-        if ( $wp_error ) {
315
-            return new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) );
313
+    if (!$invoice_ID) {
314
+        if ($wp_error) {
315
+            return new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing'));
316 316
         }
317 317
         return 0;
318 318
     }
319 319
 
320
-    $invoice = wpinv_get_invoice( $invoice_ID );
320
+    $invoice = wpinv_get_invoice($invoice_ID);
321 321
 
322
-    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring( true ) : NULL;
322
+    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring(true) : NULL;
323 323
 
324
-    if ( empty( $invoice->ID ) ) {
325
-        if ( $wp_error ) {
326
-            return new WP_Error( 'invalid_invoice', __( 'Invalid invoice.', 'invoicing' ) );
324
+    if (empty($invoice->ID)) {
325
+        if ($wp_error) {
326
+            return new WP_Error('invalid_invoice', __('Invalid invoice.', 'invoicing'));
327 327
         }
328 328
         return 0;
329 329
     }
330 330
 
331
-    if ( ! $invoice->has_status( array( 'wpi-pending' ) ) && ! $invoice->is_quote()  ) {
332
-        if ( $wp_error ) {
333
-            return new WP_Error( 'invalid_invoice_status', __( 'Only invoice with pending payment is allowed to update.', 'invoicing' ) );
331
+    if (!$invoice->has_status(array('wpi-pending')) && !$invoice->is_quote()) {
332
+        if ($wp_error) {
333
+            return new WP_Error('invalid_invoice_status', __('Only invoice with pending payment is allowed to update.', 'invoicing'));
334 334
         }
335 335
         return 0;
336 336
     }
337 337
 
338 338
     // Invoice status
339
-    if ( !empty( $invoice_data['status'] ) ) {
340
-        $invoice->set( 'status', $invoice_data['status'] );
339
+    if (!empty($invoice_data['status'])) {
340
+        $invoice->set('status', $invoice_data['status']);
341 341
     }
342 342
 
343 343
     // Invoice date
344
-    if ( !empty( $invoice_data['post_date'] ) ) {
345
-        $invoice->set( 'date', $invoice_data['post_date'] );
344
+    if (!empty($invoice_data['post_date'])) {
345
+        $invoice->set('date', $invoice_data['post_date']);
346 346
     }
347 347
 
348 348
     // Invoice due date
349
-    if ( isset( $invoice_data['due_date'] ) ) {
350
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
349
+    if (isset($invoice_data['due_date'])) {
350
+        $invoice->set('due_date', $invoice_data['due_date']);
351 351
     }
352 352
 
353 353
     // Invoice IP address
354
-    if ( !empty( $invoice_data['ip'] ) ) {
355
-        $invoice->set( 'ip', $invoice_data['ip'] );
354
+    if (!empty($invoice_data['ip'])) {
355
+        $invoice->set('ip', $invoice_data['ip']);
356 356
     }
357 357
     
358 358
     // User info
359
-    if ( !empty( $invoice_data['user_info'] ) && is_array( $invoice_data['user_info'] ) ) {
360
-        $user_info = wp_parse_args( $invoice_data['user_info'], $invoice->user_info );
359
+    if (!empty($invoice_data['user_info']) && is_array($invoice_data['user_info'])) {
360
+        $user_info = wp_parse_args($invoice_data['user_info'], $invoice->user_info);
361 361
 
362
-        if ( $discounts = $invoice->get_discounts() ) {
362
+        if ($discounts = $invoice->get_discounts()) {
363 363
             $set_discount = $discounts;
364 364
         } else {
365 365
             $set_discount = '';
366 366
         }
367 367
 
368 368
         // Manage discount
369
-        if ( !empty( $invoice_data['user_info']['discount'] ) ) {
369
+        if (!empty($invoice_data['user_info']['discount'])) {
370 370
             // Remove discount
371
-            if ( $invoice_data['user_info']['discount'] == 'none' ) {
371
+            if ($invoice_data['user_info']['discount'] == 'none') {
372 372
                 $set_discount = '';
373 373
             } else {
374 374
                 $set_discount = $invoice_data['user_info']['discount'];
375 375
             }
376 376
 
377
-            $invoice->set( 'discounts', $set_discount );
377
+            $invoice->set('discounts', $set_discount);
378 378
         }
379 379
 
380 380
         $user_info['discount'] = $set_discount;
381 381
 
382
-        $invoice->set( 'user_info', $user_info );
382
+        $invoice->set('user_info', $user_info);
383 383
     }
384 384
 
385
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) && $cart_details = $invoice_data['cart_details'] ) {
386
-        $remove_items = !empty( $cart_details['remove_items'] ) && is_array( $cart_details['remove_items'] ) ? $cart_details['remove_items'] : array();
385
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']) && $cart_details = $invoice_data['cart_details']) {
386
+        $remove_items = !empty($cart_details['remove_items']) && is_array($cart_details['remove_items']) ? $cart_details['remove_items'] : array();
387 387
 
388
-        if ( !empty( $remove_items[0]['id'] ) ) {
389
-            foreach ( $remove_items as $item ) {
390
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
391
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
392
-                if ( empty( $item_id ) ) {
388
+        if (!empty($remove_items[0]['id'])) {
389
+            foreach ($remove_items as $item) {
390
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
391
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
392
+                if (empty($item_id)) {
393 393
                     continue;
394 394
                 }
395 395
 
396
-                foreach ( $invoice->cart_details as $cart_index => $cart_item ) {
397
-                    if ( $item_id == $cart_item['id'] ) {
396
+                foreach ($invoice->cart_details as $cart_index => $cart_item) {
397
+                    if ($item_id == $cart_item['id']) {
398 398
                         $args = array(
399 399
                             'id'         => $item_id,
400 400
                             'quantity'   => $quantity,
401 401
                             'cart_index' => $cart_index
402 402
                         );
403 403
 
404
-                        $invoice->remove_item( $item_id, $args );
404
+                        $invoice->remove_item($item_id, $args);
405 405
                         break;
406 406
                     }
407 407
                 }
408 408
             }
409 409
         }
410 410
 
411
-        $add_items = !empty( $cart_details['add_items'] ) && is_array( $cart_details['add_items'] ) ? $cart_details['add_items'] : array();
411
+        $add_items = !empty($cart_details['add_items']) && is_array($cart_details['add_items']) ? $cart_details['add_items'] : array();
412 412
 
413
-        if ( !empty( $add_items[0]['id'] ) ) {
414
-            foreach ( $add_items as $item ) {
415
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
416
-                $post_item      = new WPInv_Item( $item_id );
417
-                if ( empty( $post_item ) ) {
413
+        if (!empty($add_items[0]['id'])) {
414
+            foreach ($add_items as $item) {
415
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
416
+                $post_item      = new WPInv_Item($item_id);
417
+                if (empty($post_item)) {
418 418
                     continue;
419 419
                 }
420 420
 
421 421
                 $valid_item = true;
422
-                if ( !empty( $recurring_item ) ) {
423
-                    if ( $recurring_item->ID != $item_id ) {
422
+                if (!empty($recurring_item)) {
423
+                    if ($recurring_item->ID != $item_id) {
424 424
                         $valid_item = false;
425 425
                     }
426
-                } else if ( wpinv_is_recurring_item( $item_id ) ) {
426
+                } else if (wpinv_is_recurring_item($item_id)) {
427 427
                     $valid_item = false;
428 428
                 }
429 429
                 
430
-                if ( !$valid_item ) {
431
-                    if ( $wp_error ) {
432
-                        return new WP_Error( 'invalid_invoice_item', __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ) );
430
+                if (!$valid_item) {
431
+                    if ($wp_error) {
432
+                        return new WP_Error('invalid_invoice_item', __('You can not add item because recurring item must be paid individually!', 'invoicing'));
433 433
                     }
434 434
                     return 0;
435 435
                 }
436 436
 
437
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
438
-                $name           = !empty( $item['name'] ) ? $item['name'] : $post_item->get_name();
439
-                $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : $post_item->get_price();
437
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
438
+                $name           = !empty($item['name']) ? $item['name'] : $post_item->get_name();
439
+                $item_price     = isset($item['item_price']) ? $item['item_price'] : $post_item->get_price();
440 440
 
441 441
                 $args = array(
442 442
                     'name'          => $name,
443 443
                     'quantity'      => $quantity,
444 444
                     'item_price'    => $item_price,
445
-                    'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
446
-                    'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0,
447
-                    'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
448
-                    'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
449
-                    'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
445
+                    'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
446
+                    'tax'           => !empty($item['tax']) ? $item['tax'] : 0,
447
+                    'discount'      => isset($item['discount']) ? $item['discount'] : 0,
448
+                    'meta'          => isset($item['meta']) ? $item['meta'] : array(),
449
+                    'fees'          => isset($item['fees']) ? $item['fees'] : array(),
450 450
                 );
451 451
 
452
-                $invoice->add_item( $item_id, $args );
452
+                $invoice->add_item($item_id, $args);
453 453
             }
454 454
         }
455 455
     }
456 456
     
457 457
     // Payment details
458
-    if ( !empty( $invoice_data['payment_details'] ) && $payment_details = $invoice_data['payment_details'] ) {
459
-        if ( !empty( $payment_details['gateway'] ) ) {
460
-            $invoice->set( 'gateway', $payment_details['gateway'] );
458
+    if (!empty($invoice_data['payment_details']) && $payment_details = $invoice_data['payment_details']) {
459
+        if (!empty($payment_details['gateway'])) {
460
+            $invoice->set('gateway', $payment_details['gateway']);
461 461
         }
462 462
 
463
-        if ( !empty( $payment_details['transaction_id'] ) ) {
464
-            $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
463
+        if (!empty($payment_details['transaction_id'])) {
464
+            $invoice->set('transaction_id', $payment_details['transaction_id']);
465 465
         }
466 466
     }
467 467
 
468
-    do_action( 'wpinv_pre_update_invoice', $invoice->ID, $invoice_data );
468
+    do_action('wpinv_pre_update_invoice', $invoice->ID, $invoice_data);
469 469
 
470 470
     // Parent invoice
471
-    if ( !empty( $invoice_data['parent'] ) ) {
472
-        $invoice->set( 'parent_invoice', $invoice_data['parent'] );
471
+    if (!empty($invoice_data['parent'])) {
472
+        $invoice->set('parent_invoice', $invoice_data['parent']);
473 473
     }
474 474
 
475 475
     // Save invoice data.
476 476
     $invoice->save();
477 477
     
478
-    if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) {
479
-        if ( $wp_error ) {
480
-            if ( is_wp_error( $invoice ) ) {
478
+    if (empty($invoice->ID) || is_wp_error($invoice)) {
479
+        if ($wp_error) {
480
+            if (is_wp_error($invoice)) {
481 481
                 return $invoice;
482 482
             } else {
483
-                return new WP_Error( 'wpinv_update_invoice_error', __( 'Error in update invoice.', 'invoicing' ) );
483
+                return new WP_Error('wpinv_update_invoice_error', __('Error in update invoice.', 'invoicing'));
484 484
             }
485 485
         } else {
486 486
             return 0;
@@ -488,19 +488,19 @@  discard block
 block discarded – undo
488 488
     }
489 489
 
490 490
     // Add private note
491
-    if ( !empty( $invoice_data['private_note'] ) ) {
492
-        $invoice->add_note( $invoice_data['private_note'] );
491
+    if (!empty($invoice_data['private_note'])) {
492
+        $invoice->add_note($invoice_data['private_note']);
493 493
     }
494 494
 
495 495
     // Add user note
496
-    if ( !empty( $invoice_data['user_note'] ) ) {
497
-        $invoice->add_note( $invoice_data['user_note'], true );
496
+    if (!empty($invoice_data['user_note'])) {
497
+        $invoice->add_note($invoice_data['user_note'], true);
498 498
     }
499 499
 
500
-    if ( $invoice->is_quote() ) {
500
+    if ($invoice->is_quote()) {
501 501
 
502
-        if ( isset( $invoice_data['valid_until'] ) ) {
503
-            update_post_meta( $invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until'] );
502
+        if (isset($invoice_data['valid_until'])) {
503
+            update_post_meta($invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until']);
504 504
         }
505 505
         return $invoice;
506 506
 
@@ -512,466 +512,466 @@  discard block
 block discarded – undo
512 512
 
513 513
     $data_session                   = array();
514 514
     $data_session['invoice_id']     = $invoice->ID;
515
-    $data_session['cart_discounts'] = $invoice->get_discounts( true );
515
+    $data_session['cart_discounts'] = $invoice->get_discounts(true);
516 516
 
517
-    wpinv_set_checkout_session( $data_session );
517
+    wpinv_set_checkout_session($data_session);
518 518
 
519
-    $wpi_userID         = (int)$invoice->get_user_id();
519
+    $wpi_userID         = (int) $invoice->get_user_id();
520 520
 
521
-    $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
521
+    $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
522 522
     $_POST['state']     = $invoice->state;
523 523
 
524
-    $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
525
-    $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
524
+    $invoice->set('country', sanitize_text_field($_POST['country']));
525
+    $invoice->set('state', sanitize_text_field($_POST['state']));
526 526
 
527 527
     $wpinv_ip_address_country = $invoice->country;
528 528
 
529
-    $invoice = $invoice->recalculate_totals( true );
529
+    $invoice = $invoice->recalculate_totals(true);
530 530
 
531
-    do_action( 'wpinv_post_update_invoice', $invoice->ID, $invoice_data );
531
+    do_action('wpinv_post_update_invoice', $invoice->ID, $invoice_data);
532 532
 
533
-    wpinv_set_checkout_session( $checkout_session );
533
+    wpinv_set_checkout_session($checkout_session);
534 534
 
535 535
     return $invoice;
536 536
 }
537 537
 
538
-function wpinv_get_invoice( $invoice_id = 0, $cart = false ) {
539
-    if ( $cart && empty( $invoice_id ) ) {
540
-        $invoice_id = (int)wpinv_get_invoice_cart_id();
538
+function wpinv_get_invoice($invoice_id = 0, $cart = false) {
539
+    if ($cart && empty($invoice_id)) {
540
+        $invoice_id = (int) wpinv_get_invoice_cart_id();
541 541
     }
542 542
 
543
-    $invoice = new WPInv_Invoice( $invoice_id );
543
+    $invoice = new WPInv_Invoice($invoice_id);
544 544
 
545
-    if ( $invoice->get_id() != 0 ) {
545
+    if ($invoice->get_id() != 0) {
546 546
         return $invoice;
547 547
     }
548 548
 
549 549
     return NULL;
550 550
 }
551 551
 
552
-function wpinv_get_invoice_cart( $invoice_id = 0 ) {
553
-    return wpinv_get_invoice( $invoice_id, true );
552
+function wpinv_get_invoice_cart($invoice_id = 0) {
553
+    return wpinv_get_invoice($invoice_id, true);
554 554
 }
555 555
 
556
-function wpinv_get_invoice_description( $invoice_id = 0 ) {
557
-    $invoice = new WPInv_Invoice( $invoice_id );
556
+function wpinv_get_invoice_description($invoice_id = 0) {
557
+    $invoice = new WPInv_Invoice($invoice_id);
558 558
     return $invoice->get_description();
559 559
 }
560 560
 
561
-function wpinv_get_invoice_currency_code( $invoice_id = 0 ) {
562
-    $invoice = new WPInv_Invoice( $invoice_id );
561
+function wpinv_get_invoice_currency_code($invoice_id = 0) {
562
+    $invoice = new WPInv_Invoice($invoice_id);
563 563
     return $invoice->get_currency();
564 564
 }
565 565
 
566
-function wpinv_get_payment_user_email( $invoice_id ) {
567
-    $invoice = new WPInv_Invoice( $invoice_id );
566
+function wpinv_get_payment_user_email($invoice_id) {
567
+    $invoice = new WPInv_Invoice($invoice_id);
568 568
     return $invoice->get_email();
569 569
 }
570 570
 
571
-function wpinv_get_user_id( $invoice_id ) {
572
-    $invoice = new WPInv_Invoice( $invoice_id );
571
+function wpinv_get_user_id($invoice_id) {
572
+    $invoice = new WPInv_Invoice($invoice_id);
573 573
     return $invoice->get_user_id();
574 574
 }
575 575
 
576
-function wpinv_get_invoice_status( $invoice_id, $return_label = false ) {
577
-    $invoice = new WPInv_Invoice( $invoice_id );
576
+function wpinv_get_invoice_status($invoice_id, $return_label = false) {
577
+    $invoice = new WPInv_Invoice($invoice_id);
578 578
     
579
-    return $invoice->get_status( $return_label );
579
+    return $invoice->get_status($return_label);
580 580
 }
581 581
 
582
-function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) {
583
-    $invoice = new WPInv_Invoice( $invoice_id );
582
+function wpinv_get_payment_gateway($invoice_id, $return_label = false) {
583
+    $invoice = new WPInv_Invoice($invoice_id);
584 584
     
585
-    return $invoice->get_gateway( $return_label );
585
+    return $invoice->get_gateway($return_label);
586 586
 }
587 587
 
588
-function wpinv_get_payment_gateway_name( $invoice_id ) {
589
-    $invoice = new WPInv_Invoice( $invoice_id );
588
+function wpinv_get_payment_gateway_name($invoice_id) {
589
+    $invoice = new WPInv_Invoice($invoice_id);
590 590
     
591 591
     return $invoice->get_gateway_title();
592 592
 }
593 593
 
594
-function wpinv_get_payment_transaction_id( $invoice_id ) {
595
-    $invoice = new WPInv_Invoice( $invoice_id );
594
+function wpinv_get_payment_transaction_id($invoice_id) {
595
+    $invoice = new WPInv_Invoice($invoice_id);
596 596
     
597 597
     return $invoice->get_transaction_id();
598 598
 }
599 599
 
600
-function wpinv_get_id_by_transaction_id( $key ) {
600
+function wpinv_get_id_by_transaction_id($key) {
601 601
     global $wpdb;
602 602
 
603
-    $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) );
603
+    $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key));
604 604
 
605
-    if ( $invoice_id != NULL )
605
+    if ($invoice_id != NULL)
606 606
         return $invoice_id;
607 607
 
608 608
     return 0;
609 609
 }
610 610
 
611
-function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) {
612
-    $invoice = new WPInv_Invoice( $invoice_id );
611
+function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) {
612
+    $invoice = new WPInv_Invoice($invoice_id);
613 613
 
614
-    return $invoice->get_meta( $meta_key, $single );
614
+    return $invoice->get_meta($meta_key, $single);
615 615
 }
616 616
 
617
-function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) {
618
-    $invoice = new WPInv_Invoice( $invoice_id );
617
+function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') {
618
+    $invoice = new WPInv_Invoice($invoice_id);
619 619
     
620
-    return $invoice->update_meta( $meta_key, $meta_value, $prev_value );
620
+    return $invoice->update_meta($meta_key, $meta_value, $prev_value);
621 621
 }
622 622
 
623
-function wpinv_get_items( $invoice_id = 0 ) {
624
-    $invoice            = wpinv_get_invoice( $invoice_id );
623
+function wpinv_get_items($invoice_id = 0) {
624
+    $invoice            = wpinv_get_invoice($invoice_id);
625 625
     
626 626
     $items              = $invoice->get_items();
627 627
     $invoice_currency   = $invoice->get_currency();
628 628
 
629
-    if ( !empty( $items ) && is_array( $items ) ) {
630
-        foreach ( $items as $key => $item ) {
629
+    if (!empty($items) && is_array($items)) {
630
+        foreach ($items as $key => $item) {
631 631
             $items[$key]['currency'] = $invoice_currency;
632 632
 
633
-            if ( !isset( $item['subtotal'] ) ) {
633
+            if (!isset($item['subtotal'])) {
634 634
                 $items[$key]['subtotal'] = $items[$key]['amount'] * 1;
635 635
             }
636 636
         }
637 637
     }
638 638
 
639
-    return apply_filters( 'wpinv_get_items', $items, $invoice_id );
639
+    return apply_filters('wpinv_get_items', $items, $invoice_id);
640 640
 }
641 641
 
642
-function wpinv_get_fees( $invoice_id = 0 ) {
643
-    $invoice           = wpinv_get_invoice( $invoice_id );
642
+function wpinv_get_fees($invoice_id = 0) {
643
+    $invoice           = wpinv_get_invoice($invoice_id);
644 644
     $fees              = $invoice->get_fees();
645 645
 
646
-    return apply_filters( 'wpinv_get_fees', $fees, $invoice_id );
646
+    return apply_filters('wpinv_get_fees', $fees, $invoice_id);
647 647
 }
648 648
 
649
-function wpinv_get_invoice_ip( $invoice_id ) {
650
-    $invoice = new WPInv_Invoice( $invoice_id );
649
+function wpinv_get_invoice_ip($invoice_id) {
650
+    $invoice = new WPInv_Invoice($invoice_id);
651 651
     return $invoice->get_ip();
652 652
 }
653 653
 
654
-function wpinv_get_invoice_user_info( $invoice_id ) {
655
-    $invoice = new WPInv_Invoice( $invoice_id );
654
+function wpinv_get_invoice_user_info($invoice_id) {
655
+    $invoice = new WPInv_Invoice($invoice_id);
656 656
     return $invoice->get_user_info();
657 657
 }
658 658
 
659
-function wpinv_subtotal( $invoice_id = 0, $currency = false ) {
660
-    $invoice = new WPInv_Invoice( $invoice_id );
659
+function wpinv_subtotal($invoice_id = 0, $currency = false) {
660
+    $invoice = new WPInv_Invoice($invoice_id);
661 661
 
662
-    return $invoice->get_subtotal( $currency );
662
+    return $invoice->get_subtotal($currency);
663 663
 }
664 664
 
665
-function wpinv_tax( $invoice_id = 0, $currency = false ) {
666
-    $invoice = new WPInv_Invoice( $invoice_id );
665
+function wpinv_tax($invoice_id = 0, $currency = false) {
666
+    $invoice = new WPInv_Invoice($invoice_id);
667 667
 
668
-    return $invoice->get_tax( $currency );
668
+    return $invoice->get_tax($currency);
669 669
 }
670 670
 
671
-function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) {
672
-    $invoice = wpinv_get_invoice( $invoice_id );
671
+function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) {
672
+    $invoice = wpinv_get_invoice($invoice_id);
673 673
 
674
-    return $invoice->get_discount( $currency, $dash );
674
+    return $invoice->get_discount($currency, $dash);
675 675
 }
676 676
 
677
-function wpinv_discount_code( $invoice_id = 0 ) {
678
-    $invoice = new WPInv_Invoice( $invoice_id );
677
+function wpinv_discount_code($invoice_id = 0) {
678
+    $invoice = new WPInv_Invoice($invoice_id);
679 679
 
680 680
     return $invoice->get_discount_code();
681 681
 }
682 682
 
683
-function wpinv_payment_total( $invoice_id = 0, $currency = false ) {
684
-    $invoice = new WPInv_Invoice( $invoice_id );
683
+function wpinv_payment_total($invoice_id = 0, $currency = false) {
684
+    $invoice = new WPInv_Invoice($invoice_id);
685 685
 
686
-    return $invoice->get_total( $currency );
686
+    return $invoice->get_total($currency);
687 687
 }
688 688
 
689
-function wpinv_get_date_created( $invoice_id = 0, $format = '' ) {
690
-    $invoice = new WPInv_Invoice( $invoice_id );
689
+function wpinv_get_date_created($invoice_id = 0, $format = '') {
690
+    $invoice = new WPInv_Invoice($invoice_id);
691 691
 
692
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
692
+    $format         = !empty($format) ? $format : get_option('date_format');
693 693
     $date_created   = $invoice->get_created_date();
694
-    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : '';
694
+    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : '';
695 695
 
696 696
     return $date_created;
697 697
 }
698 698
 
699
-function wpinv_get_invoice_date( $invoice_id = 0, $format = '', $default = true ) {
700
-    $invoice = new WPInv_Invoice( $invoice_id );
699
+function wpinv_get_invoice_date($invoice_id = 0, $format = '', $default = true) {
700
+    $invoice = new WPInv_Invoice($invoice_id);
701 701
     
702
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
702
+    $format         = !empty($format) ? $format : get_option('date_format');
703 703
     $date_completed = $invoice->get_completed_date();
704
-    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : '';
705
-    if ( $invoice_date == '' && $default ) {
706
-        $invoice_date   = wpinv_get_date_created( $invoice_id, $format );
704
+    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : '';
705
+    if ($invoice_date == '' && $default) {
706
+        $invoice_date = wpinv_get_date_created($invoice_id, $format);
707 707
     }
708 708
 
709 709
     return $invoice_date;
710 710
 }
711 711
 
712
-function wpinv_get_invoice_vat_number( $invoice_id = 0 ) {
713
-    $invoice = new WPInv_Invoice( $invoice_id );
712
+function wpinv_get_invoice_vat_number($invoice_id = 0) {
713
+    $invoice = new WPInv_Invoice($invoice_id);
714 714
     
715 715
     return $invoice->get_vat_number();
716 716
 }
717 717
 
718
-function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) {
719
-    $invoice = new WPInv_Invoice( $invoice_id );
718
+function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) {
719
+    $invoice = new WPInv_Invoice($invoice_id);
720 720
 
721
-    return $invoice->add_note( $note, $user_type, $added_by_user, $system );
721
+    return $invoice->add_note($note, $user_type, $added_by_user, $system);
722 722
 }
723 723
 
724
-function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) {
724
+function wpinv_get_invoice_notes($invoice_id = 0, $type = '') {
725 725
     global $invoicing;
726 726
     
727
-    if ( empty( $invoice_id ) ) {
727
+    if (empty($invoice_id)) {
728 728
         return NULL;
729 729
     }
730 730
     
731
-    $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type );
731
+    $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type);
732 732
     
733
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type );
733
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type);
734 734
 }
735 735
 
736
-function wpinv_get_payment_key( $invoice_id = 0 ) {
737
-	$invoice = new WPInv_Invoice( $invoice_id );
736
+function wpinv_get_payment_key($invoice_id = 0) {
737
+	$invoice = new WPInv_Invoice($invoice_id);
738 738
     return $invoice->get_key();
739 739
 }
740 740
 
741
-function wpinv_get_invoice_number( $invoice_id = 0 ) {
742
-    $invoice = new WPInv_Invoice( $invoice_id );
741
+function wpinv_get_invoice_number($invoice_id = 0) {
742
+    $invoice = new WPInv_Invoice($invoice_id);
743 743
     return $invoice->get_number();
744 744
 }
745 745
 
746
-function wpinv_get_cart_discountable_subtotal( $code_id ) {
746
+function wpinv_get_cart_discountable_subtotal($code_id) {
747 747
     $cart_items = wpinv_get_cart_content_details();
748 748
     $items      = array();
749 749
 
750
-    $excluded_items = wpinv_get_discount_excluded_items( $code_id );
750
+    $excluded_items = wpinv_get_discount_excluded_items($code_id);
751 751
 
752
-    if( $cart_items ) {
752
+    if ($cart_items) {
753 753
 
754
-        foreach( $cart_items as $item ) {
754
+        foreach ($cart_items as $item) {
755 755
 
756
-            if( ! in_array( $item['id'], $excluded_items ) ) {
757
-                $items[] =  $item;
756
+            if (!in_array($item['id'], $excluded_items)) {
757
+                $items[] = $item;
758 758
             }
759 759
         }
760 760
     }
761 761
 
762
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
762
+    $subtotal = wpinv_get_cart_items_subtotal($items);
763 763
 
764
-    return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal );
764
+    return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal);
765 765
 }
766 766
 
767
-function wpinv_get_cart_items_subtotal( $items ) {
767
+function wpinv_get_cart_items_subtotal($items) {
768 768
     $subtotal = 0.00;
769 769
 
770
-    if ( is_array( $items ) && ! empty( $items ) ) {
771
-        $prices = wp_list_pluck( $items, 'subtotal' );
770
+    if (is_array($items) && !empty($items)) {
771
+        $prices = wp_list_pluck($items, 'subtotal');
772 772
 
773
-        if( is_array( $prices ) ) {
774
-            $subtotal = array_sum( $prices );
773
+        if (is_array($prices)) {
774
+            $subtotal = array_sum($prices);
775 775
         } else {
776 776
             $subtotal = 0.00;
777 777
         }
778 778
 
779
-        if( $subtotal < 0 ) {
779
+        if ($subtotal < 0) {
780 780
             $subtotal = 0.00;
781 781
         }
782 782
     }
783 783
 
784
-    return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal );
784
+    return apply_filters('wpinv_get_cart_items_subtotal', $subtotal);
785 785
 }
786 786
 
787
-function wpinv_get_cart_subtotal( $items = array() ) {
788
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
789
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
787
+function wpinv_get_cart_subtotal($items = array()) {
788
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
789
+    $subtotal = wpinv_get_cart_items_subtotal($items);
790 790
 
791
-    return apply_filters( 'wpinv_get_cart_subtotal', $subtotal );
791
+    return apply_filters('wpinv_get_cart_subtotal', $subtotal);
792 792
 }
793 793
 
794
-function wpinv_cart_subtotal( $items = array(), $currency = '' ) {
794
+function wpinv_cart_subtotal($items = array(), $currency = '') {
795 795
 
796
-    if( empty( $currency ) ) {
796
+    if (empty($currency)) {
797 797
         $currency = wpinv_get_currency();
798 798
     }
799 799
 
800
-    $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ), $currency );
800
+    $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items)), $currency);
801 801
 
802 802
     return $price;
803 803
 }
804 804
 
805
-function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) {
806
-    $subtotal  = (float)wpinv_get_cart_subtotal( $items );
807
-    $discounts = (float)wpinv_get_cart_discounted_amount( $items );
808
-    $cart_tax  = (float)wpinv_get_cart_tax( $items, $invoice );
809
-    $fees      = (float)wpinv_get_cart_fee_total();
810
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
805
+function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) {
806
+    $subtotal  = (float) wpinv_get_cart_subtotal($items);
807
+    $discounts = (float) wpinv_get_cart_discounted_amount($items);
808
+    $cart_tax  = (float) wpinv_get_cart_tax($items, $invoice);
809
+    $fees      = (float) wpinv_get_cart_fee_total();
810
+    if (!empty($invoice) && $invoice->is_free_trial()) {
811 811
         $total = 0;
812 812
     } else {
813
-        $total     = $subtotal - $discounts + $cart_tax + $fees;
813
+        $total = $subtotal - $discounts + $cart_tax + $fees;
814 814
     }
815 815
 
816
-    if ( $total < 0 ) {
816
+    if ($total < 0) {
817 817
         $total = 0.00;
818 818
     }
819 819
     
820
-    $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items );
820
+    $total = (float) apply_filters('wpinv_get_cart_total', $total, $items);
821 821
 
822
-    return wpinv_sanitize_amount( $total );
822
+    return wpinv_sanitize_amount($total);
823 823
 }
824 824
 
825
-function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) {
825
+function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) {
826 826
     global $cart_total;
827
-    $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ), $invoice->get_currency() );
828
-    $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice );
827
+    $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice)), $invoice->get_currency());
828
+    $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice);
829 829
     
830 830
     $cart_total = $total;
831 831
 
832
-    if ( !$echo ) {
832
+    if (!$echo) {
833 833
         return $total;
834 834
     }
835 835
 
836 836
     echo $total;
837 837
 }
838 838
 
839
-function wpinv_get_cart_tax( $items = array(), $invoice = 0 ) {
839
+function wpinv_get_cart_tax($items = array(), $invoice = 0) {
840 840
 
841
-    if ( ! empty( $invoice ) && ! $invoice->is_taxable() ) {
841
+    if (!empty($invoice) && !$invoice->is_taxable()) {
842 842
         return 0;
843 843
     }
844 844
 
845 845
     $cart_tax = 0;
846
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
846
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
847 847
 
848
-    if ( $items ) {
849
-        $taxes = wp_list_pluck( $items, 'tax' );
848
+    if ($items) {
849
+        $taxes = wp_list_pluck($items, 'tax');
850 850
 
851
-        if( is_array( $taxes ) ) {
852
-            $cart_tax = array_sum( $taxes );
851
+        if (is_array($taxes)) {
852
+            $cart_tax = array_sum($taxes);
853 853
         }
854 854
     }
855 855
 
856 856
     $cart_tax += wpinv_get_cart_fee_tax();
857 857
 
858
-    return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) );
858
+    return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax));
859 859
 }
860 860
 
861
-function wpinv_cart_tax( $items = array(), $echo = false, $currency = '', $invoice = 0 ) {
861
+function wpinv_cart_tax($items = array(), $echo = false, $currency = '', $invoice = 0) {
862 862
 
863
-    if ( ! empty( $invoice && ! $invoice->is_taxable() ) ) {
864
-        echo wpinv_price( wpinv_format_amount( 0 ), $currency );
863
+    if (!empty($invoice && !$invoice->is_taxable())) {
864
+        echo wpinv_price(wpinv_format_amount(0), $currency);
865 865
         return;
866 866
     }
867 867
 
868
-    $cart_tax = wpinv_get_cart_tax( $items, $invoice );
869
-    $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ), $currency );
868
+    $cart_tax = wpinv_get_cart_tax($items, $invoice);
869
+    $cart_tax = wpinv_price(wpinv_format_amount($cart_tax), $currency);
870 870
 
871
-    $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items );
871
+    $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items);
872 872
 
873
-    if ( !$echo ) {
873
+    if (!$echo) {
874 874
         return $tax;
875 875
     }
876 876
 
877 877
     echo $tax;
878 878
 }
879 879
 
880
-function wpinv_get_cart_discount_code( $items = array() ) {
880
+function wpinv_get_cart_discount_code($items = array()) {
881 881
     $invoice = wpinv_get_invoice_cart();
882
-    $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : '';
882
+    $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : '';
883 883
     
884
-    return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code );
884
+    return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code);
885 885
 }
886 886
 
887
-function wpinv_cart_discount_code( $items = array(), $echo = false ) {
888
-    $cart_discount_code = wpinv_get_cart_discount_code( $items );
887
+function wpinv_cart_discount_code($items = array(), $echo = false) {
888
+    $cart_discount_code = wpinv_get_cart_discount_code($items);
889 889
 
890
-    if ( $cart_discount_code != '' ) {
890
+    if ($cart_discount_code != '') {
891 891
         $cart_discount_code = ' (' . $cart_discount_code . ')';
892 892
     }
893 893
     
894
-    $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items );
894
+    $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items);
895 895
 
896
-    if ( !$echo ) {
896
+    if (!$echo) {
897 897
         return $discount_code;
898 898
     }
899 899
 
900 900
     echo $discount_code;
901 901
 }
902 902
 
903
-function wpinv_get_cart_discount( $items = array() ) {
903
+function wpinv_get_cart_discount($items = array()) {
904 904
     $invoice = wpinv_get_invoice_cart();
905
-    $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0;
905
+    $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0;
906 906
     
907
-    return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items );
907
+    return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items);
908 908
 }
909 909
 
910
-function wpinv_cart_discount( $items = array(), $echo = false ) {
911
-    $cart_discount = wpinv_get_cart_discount( $items );
912
-    $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) );
910
+function wpinv_cart_discount($items = array(), $echo = false) {
911
+    $cart_discount = wpinv_get_cart_discount($items);
912
+    $cart_discount = wpinv_price(wpinv_format_amount($cart_discount));
913 913
 
914
-    $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items );
914
+    $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items);
915 915
 
916
-    if ( !$echo ) {
916
+    if (!$echo) {
917 917
         return $discount;
918 918
     }
919 919
 
920 920
     echo $discount;
921 921
 }
922 922
 
923
-function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) {
924
-    $item = new WPInv_Item( $item_id );
923
+function wpinv_get_cart_fees($type = 'all', $item_id = 0) {
924
+    $item = new WPInv_Item($item_id);
925 925
     
926
-    return $item->get_fees( $type, $item_id );
926
+    return $item->get_fees($type, $item_id);
927 927
 }
928 928
 
929 929
 function wpinv_get_cart_fee_total() {
930
-    $total  = 0;
930
+    $total = 0;
931 931
     $fees = wpinv_get_cart_fees();
932 932
     
933
-    if ( $fees ) {
934
-        foreach ( $fees as $fee_id => $fee ) {
933
+    if ($fees) {
934
+        foreach ($fees as $fee_id => $fee) {
935 935
             $total += $fee['amount'];
936 936
         }
937 937
     }
938 938
 
939
-    return apply_filters( 'wpinv_get_cart_fee_total', $total );
939
+    return apply_filters('wpinv_get_cart_fee_total', $total);
940 940
 }
941 941
 
942 942
 function wpinv_get_cart_fee_tax() {
943 943
     $tax  = 0;
944 944
     $fees = wpinv_get_cart_fees();
945 945
 
946
-    if ( $fees ) {
947
-        foreach ( $fees as $fee_id => $fee ) {
948
-            if( ! empty( $fee['no_tax'] ) ) {
946
+    if ($fees) {
947
+        foreach ($fees as $fee_id => $fee) {
948
+            if (!empty($fee['no_tax'])) {
949 949
                 continue;
950 950
             }
951 951
 
952
-            $tax += wpinv_calculate_tax( $fee['amount'] );
952
+            $tax += wpinv_calculate_tax($fee['amount']);
953 953
         }
954 954
     }
955 955
 
956
-    return apply_filters( 'wpinv_get_cart_fee_tax', $tax );
956
+    return apply_filters('wpinv_get_cart_fee_tax', $tax);
957 957
 }
958 958
 
959 959
 function wpinv_cart_has_recurring_item() {
960 960
     $cart_items = wpinv_get_cart_contents();
961 961
     
962
-    if ( empty( $cart_items ) ) {
962
+    if (empty($cart_items)) {
963 963
         return false;
964 964
     }
965 965
     
966 966
     $has_subscription = false;
967
-    foreach( $cart_items as $cart_item ) {
968
-        if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
967
+    foreach ($cart_items as $cart_item) {
968
+        if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
969 969
             $has_subscription = true;
970 970
             break;
971 971
         }
972 972
     }
973 973
     
974
-    return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items );
974
+    return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items);
975 975
 }
976 976
 
977 977
 function wpinv_cart_has_free_trial() {
@@ -979,100 +979,100 @@  discard block
 block discarded – undo
979 979
     
980 980
     $free_trial = false;
981 981
     
982
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
982
+    if (!empty($invoice) && $invoice->is_free_trial()) {
983 983
         $free_trial = true;
984 984
     }
985 985
     
986
-    return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice );
986
+    return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice);
987 987
 }
988 988
 
989 989
 function wpinv_get_cart_contents() {
990 990
     $cart_details = wpinv_get_cart_details();
991 991
     
992
-    return apply_filters( 'wpinv_get_cart_contents', $cart_details );
992
+    return apply_filters('wpinv_get_cart_contents', $cart_details);
993 993
 }
994 994
 
995 995
 function wpinv_get_cart_content_details() {
996 996
     global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
997 997
     $cart_items = wpinv_get_cart_contents();
998 998
     
999
-    if ( empty( $cart_items ) ) {
999
+    if (empty($cart_items)) {
1000 1000
         return false;
1001 1001
     }
1002 1002
     $invoice = wpinv_get_invoice_cart();
1003
-	if ( empty( $invoice ) ) {
1003
+	if (empty($invoice)) {
1004 1004
         return false;
1005 1005
     }
1006 1006
 
1007 1007
     $details = array();
1008
-    $length  = count( $cart_items ) - 1;
1008
+    $length  = count($cart_items) - 1;
1009 1009
     
1010
-    if ( empty( $_POST['country'] ) ) {
1010
+    if (empty($_POST['country'])) {
1011 1011
         $_POST['country'] = $invoice->country;
1012 1012
     }
1013
-    if ( !isset( $_POST['state'] ) ) {
1013
+    if (!isset($_POST['state'])) {
1014 1014
         $_POST['state'] = $invoice->state;
1015 1015
     }
1016 1016
 
1017
-    foreach( $cart_items as $key => $item ) {
1018
-        $item_id            = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '';
1019
-        if ( empty( $item_id ) ) {
1017
+    foreach ($cart_items as $key => $item) {
1018
+        $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : '';
1019
+        if (empty($item_id)) {
1020 1020
             continue;
1021 1021
         }
1022 1022
         
1023 1023
         $wpi_current_id         = $invoice->ID;
1024 1024
         $wpi_item_id            = $item_id;
1025 1025
         
1026
-        if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) {
1026
+        if (isset($item['custom_price']) && $item['custom_price'] !== '') {
1027 1027
             $item_price = $item['custom_price'];
1028 1028
         } else {
1029
-            if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) {
1029
+            if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) {
1030 1030
                 $item_price = $item['item_price'];
1031 1031
             } else {
1032
-                $item_price = wpinv_get_item_price( $item_id );
1032
+                $item_price = wpinv_get_item_price($item_id);
1033 1033
             }
1034 1034
         }
1035
-        $discount           = wpinv_get_cart_item_discount_amount( $item );
1036
-        $discount           = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item );
1037
-        $quantity           = wpinv_get_cart_item_quantity( $item );
1038
-        $fees               = wpinv_get_cart_fees( 'fee', $item_id );
1035
+        $discount           = wpinv_get_cart_item_discount_amount($item);
1036
+        $discount           = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item);
1037
+        $quantity           = wpinv_get_cart_item_quantity($item);
1038
+        $fees               = wpinv_get_cart_fees('fee', $item_id);
1039 1039
         
1040 1040
         $subtotal           = $item_price * $quantity;
1041
-        $tax_rate           = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id );
1042
-        $tax_class          = $wpinv_euvat->get_item_class( $item_id );
1043
-        $tax                = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount );
1041
+        $tax_rate           = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id);
1042
+        $tax_class          = $wpinv_euvat->get_item_class($item_id);
1043
+        $tax                = wpinv_get_cart_item_tax($item_id, $subtotal - $discount);
1044 1044
         
1045
-        if ( ! $invoice->is_taxable() ) {
1045
+        if (!$invoice->is_taxable()) {
1046 1046
             $tax = 0;
1047 1047
         }
1048
-        if ( wpinv_prices_include_tax() ) {
1049
-            $subtotal -= wpinv_round_amount( $tax );
1048
+        if (wpinv_prices_include_tax()) {
1049
+            $subtotal -= wpinv_round_amount($tax);
1050 1050
         }
1051 1051
         
1052
-        $total              = $subtotal - $discount + $tax;
1052
+        $total = $subtotal - $discount + $tax;
1053 1053
         
1054 1054
         // Do not allow totals to go negatve
1055
-        if( $total < 0 ) {
1055
+        if ($total < 0) {
1056 1056
             $total = 0;
1057 1057
         }
1058 1058
         
1059
-        $details[ $key ]  = array(
1059
+        $details[$key] = array(
1060 1060
             'id'                => $item_id,
1061
-            'name'              => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ),
1062
-            'item_price'        => wpinv_round_amount( $item_price ),
1063
-            'custom_price'      => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
1061
+            'name'              => !empty($item['name']) ? $item['name'] : get_the_title($item_id),
1062
+            'item_price'        => wpinv_round_amount($item_price),
1063
+            'custom_price'      => isset($item['custom_price']) ? $item['custom_price'] : '',
1064 1064
             'quantity'          => $quantity,
1065
-            'discount'          => wpinv_round_amount( $discount ),
1066
-            'subtotal'          => wpinv_round_amount( $subtotal ),
1067
-            'tax'               => wpinv_round_amount( $tax ),
1068
-            'price'             => wpinv_round_amount( $total ),
1065
+            'discount'          => wpinv_round_amount($discount),
1066
+            'subtotal'          => wpinv_round_amount($subtotal),
1067
+            'tax'               => wpinv_round_amount($tax),
1068
+            'price'             => wpinv_round_amount($total),
1069 1069
             'vat_rates_class'   => $tax_class,
1070 1070
             'vat_rate'          => $tax_rate,
1071
-            'meta'              => isset( $item['meta'] ) ? $item['meta'] : array(),
1071
+            'meta'              => isset($item['meta']) ? $item['meta'] : array(),
1072 1072
             'fees'              => $fees,
1073 1073
         );
1074 1074
         
1075
-        if ( $wpinv_is_last_cart_item ) {
1075
+        if ($wpinv_is_last_cart_item) {
1076 1076
             $wpinv_is_last_cart_item   = false;
1077 1077
             $wpinv_flat_discount_total = 0.00;
1078 1078
         }
@@ -1081,74 +1081,74 @@  discard block
 block discarded – undo
1081 1081
     return $details;
1082 1082
 }
1083 1083
 
1084
-function wpinv_get_cart_details( $invoice_id = 0 ) {
1084
+function wpinv_get_cart_details($invoice_id = 0) {
1085 1085
     global $ajax_cart_details;
1086 1086
 
1087
-    $invoice      = wpinv_get_invoice_cart( $invoice_id );
1087
+    $invoice      = wpinv_get_invoice_cart($invoice_id);
1088 1088
     $cart_details = $ajax_cart_details;
1089
-    if ( empty( $cart_details ) && ! empty( $invoice->cart_details ) ) {
1089
+    if (empty($cart_details) && !empty($invoice->cart_details)) {
1090 1090
         $cart_details = $invoice->cart_details;
1091 1091
     }
1092 1092
 
1093
-    if ( ! empty( $cart_details ) && is_array( $cart_details ) ) {
1094
-        $invoice_currency = ! empty( $invoice->currency ) ? $invoice->currency : wpinv_get_default_country();
1093
+    if (!empty($cart_details) && is_array($cart_details)) {
1094
+        $invoice_currency = !empty($invoice->currency) ? $invoice->currency : wpinv_get_default_country();
1095 1095
 
1096
-        foreach ( $cart_details as $key => $cart_item ) {
1097
-            $cart_details[ $key ]['currency'] = $invoice_currency;
1096
+        foreach ($cart_details as $key => $cart_item) {
1097
+            $cart_details[$key]['currency'] = $invoice_currency;
1098 1098
 
1099
-            if ( ! isset( $cart_item['subtotal'] ) ) {
1100
-                $cart_details[ $key ]['subtotal'] = $cart_item['price'];
1099
+            if (!isset($cart_item['subtotal'])) {
1100
+                $cart_details[$key]['subtotal'] = $cart_item['price'];
1101 1101
             }
1102 1102
         }
1103 1103
     }
1104 1104
 
1105
-    return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id );
1105
+    return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id);
1106 1106
 }
1107 1107
 
1108
-function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) {
1109
-    if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) {
1108
+function wpinv_record_status_change($invoice_id, $new_status, $old_status) {
1109
+    if ('wpi_invoice' != get_post_type($invoice_id)) {
1110 1110
         return;
1111 1111
     }
1112 1112
 
1113
-    if ( ( $old_status == 'wpi-pending' && $new_status == 'draft' ) || ( $old_status == 'draft' && $new_status == 'wpi-pending' ) ) {
1113
+    if (($old_status == 'wpi-pending' && $new_status == 'draft') || ($old_status == 'draft' && $new_status == 'wpi-pending')) {
1114 1114
         return;
1115 1115
     }
1116 1116
 
1117
-    $invoice    = wpinv_get_invoice( $invoice_id );
1117
+    $invoice = wpinv_get_invoice($invoice_id);
1118 1118
 
1119
-    if ( wpinv_use_taxes() && $new_status == 'publish' ) {
1119
+    if (wpinv_use_taxes() && $new_status == 'publish') {
1120 1120
         
1121
-        if ( WPInv_EUVat::same_country_rule() == 'no' && wpinv_is_base_country( $invoice->country ) ) {
1122
-            $invoice->add_note( __( 'VAT was reverse charged', 'invoicing' ), false, false, true );
1121
+        if (WPInv_EUVat::same_country_rule() == 'no' && wpinv_is_base_country($invoice->country)) {
1122
+            $invoice->add_note(__('VAT was reverse charged', 'invoicing'), false, false, true);
1123 1123
         }
1124 1124
     }
1125 1125
 
1126
-    $old_status = wpinv_status_nicename( $old_status );
1127
-    $new_status = wpinv_status_nicename( $new_status );
1126
+    $old_status = wpinv_status_nicename($old_status);
1127
+    $new_status = wpinv_status_nicename($new_status);
1128 1128
 
1129
-    $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status );
1129
+    $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status);
1130 1130
 
1131 1131
     // Add note
1132
-    return $invoice->add_note( $status_change, false, false, true );
1132
+    return $invoice->add_note($status_change, false, false, true);
1133 1133
 }
1134
-add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 );
1134
+add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3);
1135 1135
 
1136
-function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) {
1136
+function wpinv_complete_payment($invoice_id, $new_status, $old_status) {
1137 1137
     global $wpi_has_free_trial;
1138 1138
     
1139 1139
     $wpi_has_free_trial = false;
1140 1140
     
1141
-    if ( $old_status == 'publish' ) {
1141
+    if ($old_status == 'publish') {
1142 1142
         return; // Make sure that payments are only paid once
1143 1143
     }
1144 1144
 
1145 1145
     // Make sure the payment completion is only processed when new status is paid
1146
-    if ( $new_status != 'publish' ) {
1146
+    if ($new_status != 'publish') {
1147 1147
         return;
1148 1148
     }
1149 1149
 
1150
-    $invoice = new WPInv_Invoice( $invoice_id );
1151
-    if ( empty( $invoice ) ) {
1150
+    $invoice = new WPInv_Invoice($invoice_id);
1151
+    if (empty($invoice)) {
1152 1152
         return;
1153 1153
     }
1154 1154
 
@@ -1156,58 +1156,58 @@  discard block
 block discarded – undo
1156 1156
     $completed_date = $invoice->completed_date;
1157 1157
     $cart_details   = $invoice->cart_details;
1158 1158
 
1159
-    do_action( 'wpinv_pre_complete_payment', $invoice_id );
1159
+    do_action('wpinv_pre_complete_payment', $invoice_id);
1160 1160
 
1161
-    if ( is_array( $cart_details ) ) {
1161
+    if (is_array($cart_details)) {
1162 1162
         // Increase purchase count and earnings
1163
-        foreach ( $cart_details as $cart_index => $item ) {
1163
+        foreach ($cart_details as $cart_index => $item) {
1164 1164
             // Ensure these actions only run once, ever
1165
-            if ( empty( $completed_date ) ) {
1166
-                do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index );
1165
+            if (empty($completed_date)) {
1166
+                do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index);
1167 1167
             }
1168 1168
         }
1169 1169
     }
1170 1170
     
1171 1171
     // Check for discount codes and increment their use counts
1172
-    if ( $discounts = $invoice->get_discounts( true ) ) {
1173
-        if( ! empty( $discounts ) ) {
1174
-            foreach( $discounts as $code ) {
1175
-                wpinv_increase_discount_usage( $code );
1172
+    if ($discounts = $invoice->get_discounts(true)) {
1173
+        if (!empty($discounts)) {
1174
+            foreach ($discounts as $code) {
1175
+                wpinv_increase_discount_usage($code);
1176 1176
             }
1177 1177
         }
1178 1178
     }
1179 1179
     
1180 1180
     // Ensure this action only runs once ever
1181
-    if( empty( $completed_date ) ) {
1181
+    if (empty($completed_date)) {
1182 1182
         // Save the completed date
1183
-        $invoice->set( 'completed_date', current_time( 'mysql', 0 ) );
1183
+        $invoice->set('completed_date', current_time('mysql', 0));
1184 1184
         $invoice->save();
1185 1185
 
1186
-        do_action( 'wpinv_complete_payment', $invoice_id );
1186
+        do_action('wpinv_complete_payment', $invoice_id);
1187 1187
     }
1188 1188
 
1189 1189
     // Empty the shopping cart
1190 1190
     wpinv_empty_cart();
1191 1191
 }
1192
-add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 );
1192
+add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3);
1193 1193
 
1194
-function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) {    
1195
-    $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id );
1194
+function wpinv_update_payment_status($invoice_id, $new_status = 'publish') {    
1195
+    $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int) $invoice_id);
1196 1196
 
1197
-    if ( empty( $invoice ) ) {
1197
+    if (empty($invoice)) {
1198 1198
         return false;
1199 1199
     }
1200 1200
 
1201
-    return $invoice->update_status( $new_status );
1201
+    return $invoice->update_status($new_status);
1202 1202
 }
1203 1203
 
1204
-function wpinv_cart_has_fees( $type = 'all' ) {
1204
+function wpinv_cart_has_fees($type = 'all') {
1205 1205
     return false;
1206 1206
 }
1207 1207
 
1208 1208
 function wpinv_validate_checkout_fields() {
1209 1209
     // Check if there is $_POST
1210
-    if ( empty( $_POST ) ) {
1210
+    if (empty($_POST)) {
1211 1211
         return false;
1212 1212
     }
1213 1213
 
@@ -1230,28 +1230,28 @@  discard block
 block discarded – undo
1230 1230
     
1231 1231
     $invoice = wpinv_get_invoice_cart();
1232 1232
     $has_subscription = $invoice->is_recurring();
1233
-    if ( empty( $invoice ) ) {
1234
-        wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) );
1233
+    if (empty($invoice)) {
1234
+        wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing'));
1235 1235
         return $gateway;
1236 1236
     }
1237 1237
 
1238 1238
     // Check if a gateway value is present
1239
-    if ( !empty( $_REQUEST['wpi-gateway'] ) ) {
1240
-        $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] );
1239
+    if (!empty($_REQUEST['wpi-gateway'])) {
1240
+        $gateway = sanitize_text_field($_REQUEST['wpi-gateway']);
1241 1241
 
1242
-        if ( $invoice->is_free() ) {
1242
+        if ($invoice->is_free()) {
1243 1243
             $gateway = 'manual';
1244
-        } elseif ( !wpinv_is_gateway_active( $gateway ) ) {
1245
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) );
1246
-        } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) {
1247
-            if ( apply_filters( 'wpinv_reject_non_recurring_gateway', true ) ) {
1248
-                wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway does not support subscription payment', 'invoicing' ) );
1244
+        } elseif (!wpinv_is_gateway_active($gateway)) {
1245
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing'));
1246
+        } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) {
1247
+            if (apply_filters('wpinv_reject_non_recurring_gateway', true)) {
1248
+                wpinv_set_error('invalid_gateway', __('The selected payment gateway does not support subscription payment', 'invoicing'));
1249 1249
             }
1250 1250
         }
1251 1251
     }
1252 1252
 
1253
-    if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) {
1254
-        wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) );
1253
+    if ($has_subscription && count(wpinv_get_cart_contents()) > 1) {
1254
+        wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing'));
1255 1255
     }
1256 1256
 
1257 1257
     return $gateway;
@@ -1263,41 +1263,41 @@  discard block
 block discarded – undo
1263 1263
     // Retrieve the discount stored in cookies
1264 1264
     $discounts = wpinv_get_cart_discounts();
1265 1265
 
1266
-    if ( ! is_array( $discounts ) ) {
1266
+    if (!is_array($discounts)) {
1267 1267
         return NULL;
1268 1268
     }
1269 1269
 
1270
-    $discounts = array_filter( $discounts );
1271
-    $error    = false;
1270
+    $discounts = array_filter($discounts);
1271
+    $error = false;
1272 1272
 
1273
-    if ( empty( $discounts ) ) {
1273
+    if (empty($discounts)) {
1274 1274
         return NULL;
1275 1275
     }
1276 1276
 
1277 1277
     // If we have discounts, loop through them
1278
-    foreach ( $discounts as $discount ) {
1278
+    foreach ($discounts as $discount) {
1279 1279
         // Check if valid
1280
-        if (  ! wpinv_is_discount_valid( $discount, (int) $wpi_cart->get_user_id() ) ) {
1280
+        if (!wpinv_is_discount_valid($discount, (int) $wpi_cart->get_user_id())) {
1281 1281
             // Discount is not valid
1282 1282
             $error = true;
1283 1283
         }
1284 1284
 
1285 1285
     }
1286 1286
 
1287
-    if ( $error && ! wpinv_get_errors() ) {
1288
-        wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) );
1287
+    if ($error && !wpinv_get_errors()) {
1288
+        wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing'));
1289 1289
     }
1290 1290
 
1291
-    return implode( ',', $discounts );
1291
+    return implode(',', $discounts);
1292 1292
 }
1293 1293
 
1294 1294
 function wpinv_checkout_validate_cc() {
1295 1295
     $card_data = wpinv_checkout_get_cc_info();
1296 1296
 
1297 1297
     // Validate the card zip
1298
-    if ( !empty( $card_data['wpinv_zip'] ) ) {
1299
-        if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) {
1300
-            wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) );
1298
+    if (!empty($card_data['wpinv_zip'])) {
1299
+        if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) {
1300
+            wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing'));
1301 1301
         }
1302 1302
     }
1303 1303
 
@@ -1307,28 +1307,28 @@  discard block
 block discarded – undo
1307 1307
 
1308 1308
 function wpinv_checkout_get_cc_info() {
1309 1309
 	$cc_info = array();
1310
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
1311
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
1312
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
1313
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
1314
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
1315
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
1316
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
1317
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
1318
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
1319
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
1310
+	$cc_info['card_name']      = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : '';
1311
+	$cc_info['card_number']    = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : '';
1312
+	$cc_info['card_cvc']       = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : '';
1313
+	$cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : '';
1314
+	$cc_info['card_exp_year']  = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : '';
1315
+	$cc_info['card_address']   = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : '';
1316
+	$cc_info['card_city']      = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : '';
1317
+	$cc_info['card_state']     = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : '';
1318
+	$cc_info['card_country']   = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : '';
1319
+	$cc_info['card_zip']       = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : '';
1320 1320
 
1321 1321
 	// Return cc info
1322 1322
 	return $cc_info;
1323 1323
 }
1324 1324
 
1325
-function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
1325
+function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') {
1326 1326
     $ret = false;
1327 1327
 
1328
-    if ( empty( $zip ) || empty( $country_code ) )
1328
+    if (empty($zip) || empty($country_code))
1329 1329
         return $ret;
1330 1330
 
1331
-    $country_code = strtoupper( $country_code );
1331
+    $country_code = strtoupper($country_code);
1332 1332
 
1333 1333
     $zip_regex = array(
1334 1334
         "AD" => "AD\d{3}",
@@ -1488,72 +1488,72 @@  discard block
 block discarded – undo
1488 1488
         "ZM" => "\d{5}"
1489 1489
     );
1490 1490
 
1491
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
1491
+    if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip))
1492 1492
         $ret = true;
1493 1493
 
1494
-    return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
1494
+    return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code);
1495 1495
 }
1496 1496
 
1497 1497
 function wpinv_checkout_validate_agree_to_terms() {
1498 1498
     // Validate agree to terms
1499
-    if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) {
1499
+    if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) {
1500 1500
         // User did not agree
1501
-        wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) );
1501
+        wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing')));
1502 1502
     }
1503 1503
 }
1504 1504
 
1505 1505
 function wpinv_checkout_validate_invoice_user() {
1506 1506
     global $wpi_cart, $user_ID;
1507 1507
 
1508
-    if(empty($wpi_cart)){
1508
+    if (empty($wpi_cart)) {
1509 1509
         $wpi_cart = wpinv_get_invoice_cart();
1510 1510
     }
1511 1511
 
1512
-    $invoice_user = (int)$wpi_cart->get_user_id();
1512
+    $invoice_user = (int) $wpi_cart->get_user_id();
1513 1513
     $valid_user_data = array(
1514 1514
         'user_id' => $invoice_user
1515 1515
     );
1516 1516
 
1517 1517
     // If guest checkout allowed
1518
-    if ( !wpinv_require_login_to_checkout() ) {
1518
+    if (!wpinv_require_login_to_checkout()) {
1519 1519
         return $valid_user_data;
1520 1520
     }
1521 1521
     
1522 1522
     // Verify there is a user_ID
1523
-    if ( $user_ID == $invoice_user ) {
1523
+    if ($user_ID == $invoice_user) {
1524 1524
         // Get the logged in user data
1525
-        $user_data = get_userdata( $user_ID );
1526
-        $required_fields  = wpinv_checkout_required_fields();
1525
+        $user_data = get_userdata($user_ID);
1526
+        $required_fields = wpinv_checkout_required_fields();
1527 1527
 
1528 1528
         // Loop through required fields and show error messages
1529
-         if ( !empty( $required_fields ) ) {
1530
-            foreach ( $required_fields as $field_name => $value ) {
1531
-                if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
1532
-                    wpinv_set_error( $value['error_id'], $value['error_message'] );
1529
+         if (!empty($required_fields)) {
1530
+            foreach ($required_fields as $field_name => $value) {
1531
+                if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) {
1532
+                    wpinv_set_error($value['error_id'], $value['error_message']);
1533 1533
                 }
1534 1534
             }
1535 1535
         }
1536 1536
 
1537 1537
         // Verify data
1538
-        if ( $user_data ) {
1538
+        if ($user_data) {
1539 1539
             // Collected logged in user data
1540 1540
             $valid_user_data = array(
1541 1541
                 'user_id'     => $user_ID,
1542
-                'email'       => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email,
1543
-                'first_name'  => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name,
1544
-                'last_name'   => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name']  ) ? sanitize_text_field( $_POST['wpinv_last_name']  ) : $user_data->last_name,
1542
+                'email'       => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email,
1543
+                'first_name'  => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name,
1544
+                'last_name'   => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name,
1545 1545
             );
1546 1546
 
1547
-            if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) {
1548
-                wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) );
1547
+            if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) {
1548
+                wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing'));
1549 1549
             }
1550 1550
         } else {
1551 1551
             // Set invalid user error
1552
-            wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) );
1552
+            wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing'));
1553 1553
         }
1554 1554
     } else {
1555 1555
         // Set invalid user error
1556
-        wpinv_set_error( 'invalid_user_id', __( 'The invalid invoice user id', 'invoicing' ) );
1556
+        wpinv_set_error('invalid_user_id', __('The invalid invoice user id', 'invoicing'));
1557 1557
     }
1558 1558
 
1559 1559
     // Return user data
@@ -1565,27 +1565,27 @@  discard block
 block discarded – undo
1565 1565
 
1566 1566
     $data = array();
1567 1567
     
1568
-    if ( is_user_logged_in() ) {
1569
-        if ( !wpinv_require_login_to_checkout() || ( wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id() ) ) {
1570
-            $data['user_id'] = (int)get_current_user_id();
1568
+    if (is_user_logged_in()) {
1569
+        if (!wpinv_require_login_to_checkout() || (wpinv_require_login_to_checkout() && (int) $wpi_cart->get_user_id() === (int) get_current_user_id())) {
1570
+            $data['user_id'] = (int) get_current_user_id();
1571 1571
         } else {
1572
-            wpinv_set_error( 'logged_in_only', __( 'You are not allowed to pay for this invoice', 'invoicing' ) );
1572
+            wpinv_set_error('logged_in_only', __('You are not allowed to pay for this invoice', 'invoicing'));
1573 1573
         }
1574 1574
     } else {
1575 1575
         // If guest checkout allowed
1576
-        if ( !wpinv_require_login_to_checkout() ) {
1576
+        if (!wpinv_require_login_to_checkout()) {
1577 1577
             $data['user_id'] = 0;
1578 1578
         } else {
1579
-            wpinv_set_error( 'logged_in_only', __( 'You must be logged in to pay for this invoice', 'invoicing' ) );
1579
+            wpinv_set_error('logged_in_only', __('You must be logged in to pay for this invoice', 'invoicing'));
1580 1580
         }
1581 1581
     }
1582 1582
 
1583 1583
     return $data;
1584 1584
 }
1585 1585
 
1586
-function wpinv_checkout_form_get_user( $valid_data = array() ) {
1586
+function wpinv_checkout_form_get_user($valid_data = array()) {
1587 1587
 
1588
-    if ( !empty( $valid_data['current_user']['user_id'] ) ) {
1588
+    if (!empty($valid_data['current_user']['user_id'])) {
1589 1589
         $user = $valid_data['current_user'];
1590 1590
     } else {
1591 1591
         // Set the valid invoice user
@@ -1593,7 +1593,7 @@  discard block
 block discarded – undo
1593 1593
     }
1594 1594
 
1595 1595
     // Verify invoice have an user
1596
-    if ( false === $user || empty( $user ) ) {
1596
+    if (false === $user || empty($user)) {
1597 1597
         return false;
1598 1598
     }
1599 1599
 
@@ -1610,11 +1610,11 @@  discard block
 block discarded – undo
1610 1610
         'zip',
1611 1611
     );
1612 1612
     
1613
-    foreach ( $address_fields as $field ) {
1614
-        $user[$field]  = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false;
1613
+    foreach ($address_fields as $field) {
1614
+        $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false;
1615 1615
         
1616
-        if ( !empty( $user['user_id'] ) && !empty( $valid_data['current_user']['user_id'] ) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id'] ) {
1617
-            update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] );
1616
+        if (!empty($user['user_id']) && !empty($valid_data['current_user']['user_id']) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id']) {
1617
+            update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]);
1618 1618
         }
1619 1619
     }
1620 1620
 
@@ -1622,26 +1622,26 @@  discard block
 block discarded – undo
1622 1622
     return $user;
1623 1623
 }
1624 1624
 
1625
-function wpinv_set_checkout_session( $invoice_data = array() ) {
1625
+function wpinv_set_checkout_session($invoice_data = array()) {
1626 1626
     global $wpi_session;
1627
-    return $wpi_session->set( 'wpinv_checkout', $invoice_data );
1627
+    return $wpi_session->set('wpinv_checkout', $invoice_data);
1628 1628
 }
1629 1629
 
1630 1630
 function wpinv_get_checkout_session() {
1631 1631
 	global $wpi_session;
1632
-    return $wpi_session->get( 'wpinv_checkout' );
1632
+    return $wpi_session->get('wpinv_checkout');
1633 1633
 }
1634 1634
 
1635 1635
 function wpinv_empty_cart() {
1636 1636
     global $wpi_session;
1637 1637
 
1638 1638
     // Remove cart contents
1639
-    $wpi_session->set( 'wpinv_checkout', NULL );
1639
+    $wpi_session->set('wpinv_checkout', NULL);
1640 1640
 
1641 1641
     // Remove all cart fees
1642
-    $wpi_session->set( 'wpi_cart_fees', NULL );
1642
+    $wpi_session->set('wpi_cart_fees', NULL);
1643 1643
 
1644
-    do_action( 'wpinv_empty_cart' );
1644
+    do_action('wpinv_empty_cart');
1645 1645
 }
1646 1646
 
1647 1647
 function wpinv_process_checkout() {
@@ -1650,7 +1650,7 @@  discard block
 block discarded – undo
1650 1650
     wpinv_clear_errors();
1651 1651
 
1652 1652
     $invoice = wpinv_get_invoice_cart();
1653
-    if ( empty( $invoice ) ) {
1653
+    if (empty($invoice)) {
1654 1654
         return false;
1655 1655
     }
1656 1656
 
@@ -1658,42 +1658,42 @@  discard block
 block discarded – undo
1658 1658
 
1659 1659
     $wpi_checkout_id = $invoice->ID;
1660 1660
 
1661
-    do_action( 'wpinv_pre_process_checkout' );
1661
+    do_action('wpinv_pre_process_checkout');
1662 1662
     
1663
-    if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty
1663
+    if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty
1664 1664
         $valid_data = false;
1665
-        wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) );
1665
+        wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing'));
1666 1666
     } else {
1667 1667
         // Validate the form $_POST data
1668 1668
         $valid_data = wpinv_validate_checkout_fields();
1669 1669
         
1670 1670
         // Allow themes and plugins to hook to errors
1671
-        do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST );
1671
+        do_action('wpinv_checkout_error_checks', $valid_data, $_POST);
1672 1672
     }
1673 1673
     
1674
-    $is_ajax    = defined( 'DOING_AJAX' ) && DOING_AJAX;
1674
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1675 1675
     
1676 1676
     // Validate the user
1677
-    $user = wpinv_checkout_form_get_user( $valid_data );
1677
+    $user = wpinv_checkout_form_get_user($valid_data);
1678 1678
 
1679 1679
     // Let extensions validate fields after user is logged in if user has used login/registration form
1680
-    do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST );
1680
+    do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST);
1681 1681
     
1682
-    if ( false === $valid_data || wpinv_get_errors() || ! $user ) {
1683
-        if ( $is_ajax && 'wpinv_payment_form' != $_REQUEST['action'] ) {
1684
-            do_action( 'wpinv_ajax_checkout_errors' );
1682
+    if (false === $valid_data || wpinv_get_errors() || !$user) {
1683
+        if ($is_ajax && 'wpinv_payment_form' != $_REQUEST['action']) {
1684
+            do_action('wpinv_ajax_checkout_errors');
1685 1685
             die();
1686 1686
         } else {
1687 1687
             return false;
1688 1688
         }
1689 1689
     }
1690 1690
 
1691
-    if ( $is_ajax && 'wpinv_payment_form' != $_REQUEST['action'] ) {
1691
+    if ($is_ajax && 'wpinv_payment_form' != $_REQUEST['action']) {
1692 1692
         // Save address fields.
1693
-        $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' );
1694
-        foreach ( $address_fields as $field ) {
1695
-            if ( isset( $user[$field] ) ) {
1696
-                $invoice->set( $field, $user[$field] );
1693
+        $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company');
1694
+        foreach ($address_fields as $field) {
1695
+            if (isset($user[$field])) {
1696
+                $invoice->set($field, $user[$field]);
1697 1697
             }
1698 1698
 
1699 1699
             $invoice->save();
@@ -1701,16 +1701,16 @@  discard block
 block discarded – undo
1701 1701
 
1702 1702
         $response['success']            = true;
1703 1703
         $response['data']['subtotal']   = $invoice->get_subtotal();
1704
-        $response['data']['subtotalf']  = $invoice->get_subtotal( true );
1704
+        $response['data']['subtotalf']  = $invoice->get_subtotal(true);
1705 1705
         $response['data']['discount']   = $invoice->get_discount();
1706
-        $response['data']['discountf']  = $invoice->get_discount( true );
1706
+        $response['data']['discountf']  = $invoice->get_discount(true);
1707 1707
         $response['data']['tax']        = $invoice->get_tax();
1708
-        $response['data']['taxf']       = $invoice->get_tax( true );
1708
+        $response['data']['taxf']       = $invoice->get_tax(true);
1709 1709
         $response['data']['total']      = $invoice->get_total();
1710
-        $response['data']['totalf']     = $invoice->get_total( true );
1711
-	    $response['data']['free']       = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false;
1710
+        $response['data']['totalf']     = $invoice->get_total(true);
1711
+	    $response['data']['free'] = $invoice->is_free() && (!((float) $response['data']['total'] > 0) || $invoice->is_free_trial()) ? true : false;
1712 1712
 
1713
-        wp_send_json( $response );
1713
+        wp_send_json($response);
1714 1714
     }
1715 1715
     
1716 1716
     $user_info = array(
@@ -1732,42 +1732,42 @@  discard block
 block discarded – undo
1732 1732
     
1733 1733
     // Setup invoice information
1734 1734
     $invoice_data = array(
1735
-        'invoice_id'        => !empty( $invoice ) ? $invoice->ID : 0,
1735
+        'invoice_id'        => !empty($invoice) ? $invoice->ID : 0,
1736 1736
         'items'             => $cart_items,
1737 1737
         'cart_discounts'    => $discounts,
1738
-        'fees'              => wpinv_get_cart_fees(),        // Any arbitrary fees that have been added to the cart
1739
-        'subtotal'          => wpinv_get_cart_subtotal( $cart_items ),    // Amount before taxes and discounts
1740
-        'discount'          => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount
1741
-        'tax'               => wpinv_get_cart_tax( $cart_items, $invoice ),               // Taxed amount
1742
-        'price'             => wpinv_get_cart_total( $cart_items, $discounts ),    // Amount after taxes
1738
+        'fees'              => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart
1739
+        'subtotal'          => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts
1740
+        'discount'          => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount
1741
+        'tax'               => wpinv_get_cart_tax($cart_items, $invoice), // Taxed amount
1742
+        'price'             => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes
1743 1743
         'invoice_key'       => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(),
1744 1744
         'user_email'        => $invoice->get_email(),
1745
-        'date'              => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
1746
-        'user_info'         => stripslashes_deep( $user_info ),
1745
+        'date'              => date('Y-m-d H:i:s', current_time('timestamp')),
1746
+        'user_info'         => stripslashes_deep($user_info),
1747 1747
         'post_data'         => $_POST,
1748 1748
         'cart_details'      => $cart_items,
1749 1749
         'gateway'           => $valid_data['gateway'],
1750 1750
         'card_info'         => $valid_data['cc_info']
1751 1751
     );
1752 1752
     
1753
-    $vat_info   = $wpinv_euvat->current_vat_data();
1754
-    if ( is_array( $vat_info ) ) {
1753
+    $vat_info = $wpinv_euvat->current_vat_data();
1754
+    if (is_array($vat_info)) {
1755 1755
         $invoice_data['user_info']['vat_number']        = $vat_info['number'];
1756 1756
         $invoice_data['user_info']['vat_rate']          = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']);
1757
-        $invoice_data['user_info']['adddress_confirmed']    = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1757
+        $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1758 1758
 
1759 1759
         // Add the VAT rate to each item in the cart
1760
-        foreach( $invoice_data['cart_details'] as $key => $item_data) {
1760
+        foreach ($invoice_data['cart_details'] as $key => $item_data) {
1761 1761
             $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']);
1762
-            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 );
1762
+            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4);
1763 1763
         }
1764 1764
     }
1765 1765
     
1766 1766
     // Save vat fields.
1767
-    $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' );
1768
-    foreach ( $address_fields as $field ) {
1769
-        if ( isset( $invoice_data['user_info'][$field] ) ) {
1770
-            $invoice->set( $field, $invoice_data['user_info'][$field] );
1767
+    $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed');
1768
+    foreach ($address_fields as $field) {
1769
+        if (isset($invoice_data['user_info'][$field])) {
1770
+            $invoice->set($field, $invoice_data['user_info'][$field]);
1771 1771
         }
1772 1772
     }
1773 1773
     $invoice->save();
@@ -1776,54 +1776,54 @@  discard block
 block discarded – undo
1776 1776
     $valid_data['user'] = $user;
1777 1777
     
1778 1778
     // Allow themes and plugins to hook before the gateway
1779
-    do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data );
1779
+    do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data);
1780 1780
 
1781 1781
      // If it is free, abort.
1782
-     if ( $invoice->is_free() && ( ! $invoice->is_recurring() || 0 ==  $invoice->get_recurring_details( 'total' ) ) ) {
1782
+     if ($invoice->is_free() && (!$invoice->is_recurring() || 0 == $invoice->get_recurring_details('total'))) {
1783 1783
         $invoice_data['gateway'] = 'manual';
1784 1784
         $_POST['wpi-gateway'] = 'manual';
1785 1785
     }
1786 1786
 
1787 1787
     // Allow the invoice data to be modified before it is sent to the gateway
1788
-    $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data );
1788
+    $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data);
1789 1789
     
1790
-    if ( $invoice_data['price'] && $invoice_data['gateway'] == 'manual' ) {
1790
+    if ($invoice_data['price'] && $invoice_data['gateway'] == 'manual') {
1791 1791
         $mode = 'test';
1792 1792
     } else {
1793
-        $mode = wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live';
1793
+        $mode = wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live';
1794 1794
     }
1795 1795
 
1796 1796
     // Setup the data we're storing in the purchase session
1797 1797
     $session_data = $invoice_data;
1798 1798
     // Make sure credit card numbers are never stored in sessions
1799
-    if ( !empty( $session_data['card_info']['card_number'] ) ) {
1800
-        unset( $session_data['card_info']['card_number'] );
1799
+    if (!empty($session_data['card_info']['card_number'])) {
1800
+        unset($session_data['card_info']['card_number']);
1801 1801
     }
1802 1802
     
1803 1803
     // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data.
1804
-    wpinv_set_checkout_session( $invoice_data );
1804
+    wpinv_set_checkout_session($invoice_data);
1805 1805
     
1806 1806
     // Set gateway
1807
-    $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] );
1808
-    $invoice->update_meta( '_wpinv_mode', $mode );
1809
-    $invoice->update_meta( '_wpinv_checkout', date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) );
1807
+    $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']);
1808
+    $invoice->update_meta('_wpinv_mode', $mode);
1809
+    $invoice->update_meta('_wpinv_checkout', date_i18n('Y-m-d H:i:s', current_time('timestamp')));
1810 1810
     
1811
-    do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data );
1811
+    do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data);
1812 1812
 
1813 1813
     // Send info to the gateway for payment processing
1814
-    wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data );
1814
+    wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data);
1815 1815
     die();
1816 1816
 }
1817
-add_action( 'wpinv_payment', 'wpinv_process_checkout' );
1817
+add_action('wpinv_payment', 'wpinv_process_checkout');
1818 1818
 
1819
-function wpinv_get_invoices( $args ) {
1820
-    $args = wp_parse_args( $args, array(
1821
-        'status'   => array_keys( wpinv_get_invoice_statuses() ),
1819
+function wpinv_get_invoices($args) {
1820
+    $args = wp_parse_args($args, array(
1821
+        'status'   => array_keys(wpinv_get_invoice_statuses()),
1822 1822
         'type'     => 'wpi_invoice',
1823 1823
         'parent'   => null,
1824 1824
         'user'     => null,
1825 1825
         'email'    => '',
1826
-        'limit'    => get_option( 'posts_per_page' ),
1826
+        'limit'    => get_option('posts_per_page'),
1827 1827
         'offset'   => null,
1828 1828
         'page'     => 1,
1829 1829
         'exclude'  => array(),
@@ -1831,7 +1831,7 @@  discard block
 block discarded – undo
1831 1831
         'order'    => 'DESC',
1832 1832
         'return'   => 'objects',
1833 1833
         'paginate' => false,
1834
-    ) );
1834
+    ));
1835 1835
     
1836 1836
     // Handle some BW compatibility arg names where wp_query args differ in naming.
1837 1837
     $map_legacy = array(
@@ -1844,18 +1844,18 @@  discard block
 block discarded – undo
1844 1844
         'paged'          => 'page',
1845 1845
     );
1846 1846
 
1847
-    foreach ( $map_legacy as $from => $to ) {
1848
-        if ( isset( $args[ $from ] ) ) {
1849
-            $args[ $to ] = $args[ $from ];
1847
+    foreach ($map_legacy as $from => $to) {
1848
+        if (isset($args[$from])) {
1849
+            $args[$to] = $args[$from];
1850 1850
         }
1851 1851
     }
1852 1852
 
1853
-    if ( get_query_var( 'paged' ) )
1853
+    if (get_query_var('paged'))
1854 1854
         $args['page'] = get_query_var('paged');
1855
-    else if ( get_query_var( 'page' ) )
1856
-        $args['page'] = get_query_var( 'page' );
1857
-    else if ( !empty( $args[ 'page' ] ) )
1858
-        $args['page'] = $args[ 'page' ];
1855
+    else if (get_query_var('page'))
1856
+        $args['page'] = get_query_var('page');
1857
+    else if (!empty($args['page']))
1858
+        $args['page'] = $args['page'];
1859 1859
     else
1860 1860
         $args['page'] = 1;
1861 1861
 
@@ -1868,48 +1868,48 @@  discard block
 block discarded – undo
1868 1868
         'post_status'    => $args['status'],
1869 1869
         'posts_per_page' => $args['limit'],
1870 1870
         'meta_query'     => array(),
1871
-        'date_query'     => !empty( $args['date_query'] ) ? $args['date_query'] : array(),
1871
+        'date_query'     => !empty($args['date_query']) ? $args['date_query'] : array(),
1872 1872
         'fields'         => 'ids',
1873 1873
         'orderby'        => $args['orderby'],
1874 1874
         'order'          => $args['order'],
1875 1875
     );
1876 1876
     
1877
-    if ( !empty( $args['user'] ) ) {
1878
-        $wp_query_args['author'] = absint( $args['user'] );
1877
+    if (!empty($args['user'])) {
1878
+        $wp_query_args['author'] = absint($args['user']);
1879 1879
     }
1880 1880
 
1881
-    if ( ! is_null( $args['parent'] ) ) {
1882
-        $wp_query_args['post_parent'] = absint( $args['parent'] );
1881
+    if (!is_null($args['parent'])) {
1882
+        $wp_query_args['post_parent'] = absint($args['parent']);
1883 1883
     }
1884 1884
 
1885
-    if ( ! is_null( $args['offset'] ) ) {
1886
-        $wp_query_args['offset'] = absint( $args['offset'] );
1885
+    if (!is_null($args['offset'])) {
1886
+        $wp_query_args['offset'] = absint($args['offset']);
1887 1887
     } else {
1888
-        $wp_query_args['paged'] = absint( $args['page'] );
1888
+        $wp_query_args['paged'] = absint($args['page']);
1889 1889
     }
1890 1890
 
1891
-    if ( ! empty( $args['exclude'] ) ) {
1892
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
1891
+    if (!empty($args['exclude'])) {
1892
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
1893 1893
     }
1894 1894
 
1895
-    if ( ! $args['paginate' ] ) {
1895
+    if (!$args['paginate']) {
1896 1896
         $wp_query_args['no_found_rows'] = true;
1897 1897
     }
1898 1898
 
1899 1899
     $wp_query_args = apply_filters('wpinv_get_invoices_args', $wp_query_args, $args);
1900 1900
 
1901 1901
     // Get results.
1902
-    $invoices = new WP_Query( $wp_query_args );
1902
+    $invoices = new WP_Query($wp_query_args);
1903 1903
 
1904
-    if ( 'objects' === $args['return'] ) {
1905
-        $return = array_map( 'wpinv_get_invoice', $invoices->posts );
1906
-    } elseif ( 'self' === $args['return'] ) {
1904
+    if ('objects' === $args['return']) {
1905
+        $return = array_map('wpinv_get_invoice', $invoices->posts);
1906
+    } elseif ('self' === $args['return']) {
1907 1907
         return $invoices;
1908 1908
     } else {
1909 1909
         $return = $invoices->posts;
1910 1910
     }
1911 1911
 
1912
-    if ( $args['paginate' ] ) {
1912
+    if ($args['paginate']) {
1913 1913
         return (object) array(
1914 1914
             'invoices'      => $return,
1915 1915
             'total'         => $invoices->found_posts,
@@ -1922,22 +1922,22 @@  discard block
 block discarded – undo
1922 1922
 
1923 1923
 function wpinv_get_user_invoices_columns() {
1924 1924
     $columns = array(
1925
-            'invoice-number'  => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ),
1926
-            'created-date'    => array( 'title' => __( 'Created Date', 'invoicing' ), 'class' => 'text-left' ),
1927
-            'payment-date'    => array( 'title' => __( 'Payment Date', 'invoicing' ), 'class' => 'text-left' ),
1928
-            'invoice-status'  => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ),
1929
-            'invoice-total'   => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ),
1930
-            'invoice-actions' => array( 'title' => '&nbsp;', 'class' => 'text-center' ),
1925
+            'invoice-number'  => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'),
1926
+            'created-date'    => array('title' => __('Created Date', 'invoicing'), 'class' => 'text-left'),
1927
+            'payment-date'    => array('title' => __('Payment Date', 'invoicing'), 'class' => 'text-left'),
1928
+            'invoice-status'  => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'),
1929
+            'invoice-total'   => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'),
1930
+            'invoice-actions' => array('title' => '&nbsp;', 'class' => 'text-center'),
1931 1931
         );
1932 1932
 
1933
-    return apply_filters( 'wpinv_user_invoices_columns', $columns );
1933
+    return apply_filters('wpinv_user_invoices_columns', $columns);
1934 1934
 }
1935 1935
 
1936
-function wpinv_payment_receipt( $atts, $content = null ) {
1936
+function wpinv_payment_receipt($atts, $content = null) {
1937 1937
     global $wpinv_receipt_args;
1938 1938
 
1939
-    $wpinv_receipt_args = shortcode_atts( array(
1940
-        'error'           => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ),
1939
+    $wpinv_receipt_args = shortcode_atts(array(
1940
+        'error'           => __('Sorry, trouble retrieving payment receipt.', 'invoicing'),
1941 1941
         'price'           => true,
1942 1942
         'discount'        => true,
1943 1943
         'items'           => true,
@@ -1946,45 +1946,45 @@  discard block
 block discarded – undo
1946 1946
         'invoice_key'     => false,
1947 1947
         'payment_method'  => true,
1948 1948
         'invoice_id'      => true
1949
-    ), $atts, 'wpinv_receipt' );
1949
+    ), $atts, 'wpinv_receipt');
1950 1950
 
1951 1951
     // Find the invoice.
1952 1952
     $session = wpinv_get_checkout_session();
1953 1953
 
1954
-    if ( isset( $_GET['invoice_key'] ) ) {
1955
-        $invoice_id = wpinv_get_invoice_id_by_key( urldecode( $_GET['invoice_key'] ) );
1956
-    } else if ( isset( $_GET['invoice-id'] ) ) {
1954
+    if (isset($_GET['invoice_key'])) {
1955
+        $invoice_id = wpinv_get_invoice_id_by_key(urldecode($_GET['invoice_key']));
1956
+    } else if (isset($_GET['invoice-id'])) {
1957 1957
         $invoice_id = (int) $_GET['invoice-id'];
1958
-    } else if ( $session && isset( $session['invoice_key'] ) ) {
1959
-        $invoice_id = wpinv_get_invoice_id_by_key( $session['invoice_key'] );
1960
-    } else if ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) {
1961
-        $invoice_id = wpinv_get_invoice_id_by_key( $wpinv_receipt_args['invoice_key'] );
1958
+    } else if ($session && isset($session['invoice_key'])) {
1959
+        $invoice_id = wpinv_get_invoice_id_by_key($session['invoice_key']);
1960
+    } else if (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) {
1961
+        $invoice_id = wpinv_get_invoice_id_by_key($wpinv_receipt_args['invoice_key']);
1962 1962
     }
1963 1963
 
1964 1964
     // Did we find the invoice?
1965
-    if ( empty( $invoice_id ) || ! $invoice = wpinv_get_invoice( $invoice_id ) ) {
1966
-        return '<p class="alert alert-error">' . __( 'We could not find your invoice.', 'invoicing' ) . '</p>';
1965
+    if (empty($invoice_id) || !$invoice = wpinv_get_invoice($invoice_id)) {
1966
+        return '<p class="alert alert-error">' . __('We could not find your invoice.', 'invoicing') . '</p>';
1967 1967
     }
1968 1968
 
1969 1969
     $invoice_key   = $invoice->get_key();
1970
-    $user_can_view = wpinv_can_view_receipt( $invoice_key );
1971
-    if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1972
-        $user_can_view  = $_GET['invoice-id'] == $invoice->ID;
1970
+    $user_can_view = wpinv_can_view_receipt($invoice_key);
1971
+    if ($user_can_view && isset($_GET['invoice-id'])) {
1972
+        $user_can_view = $_GET['invoice-id'] == $invoice->ID;
1973 1973
     }
1974 1974
 
1975 1975
     // Key was provided, but user is logged out. Offer them the ability to login and view the receipt
1976
-    if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) {
1976
+    if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) {
1977 1977
         // login redirect
1978
-        return '<p class="alert alert-error">' . __( 'You must be logged in to view this receipt', 'invoicing' ) . '</p>';
1978
+        return '<p class="alert alert-error">' . __('You must be logged in to view this receipt', 'invoicing') . '</p>';
1979 1979
     }
1980 1980
 
1981
-    if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) {
1981
+    if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) {
1982 1982
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1983 1983
     }
1984 1984
 
1985 1985
     ob_start();
1986 1986
 
1987
-    wpinv_get_template_part( 'wpinv-invoice-receipt' );
1987
+    wpinv_get_template_part('wpinv-invoice-receipt');
1988 1988
 
1989 1989
     $display = ob_get_clean();
1990 1990
 
@@ -1994,148 +1994,148 @@  discard block
 block discarded – undo
1994 1994
 /**
1995 1995
  * Given an invoice key, this function returns the id.
1996 1996
  */
1997
-function wpinv_get_invoice_id_by_key( $key ) {
1997
+function wpinv_get_invoice_id_by_key($key) {
1998 1998
 	global $wpdb;
1999
-    $table      = $wpdb->prefix . 'getpaid_invoices';
2000
-	return (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key ) );
1999
+    $table = $wpdb->prefix . 'getpaid_invoices';
2000
+	return (int) $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key));
2001 2001
 }
2002 2002
 
2003
-function wpinv_can_view_receipt( $invoice_key = '' ) {
2004
-	$return = current_user_can( 'manage_options' );
2003
+function wpinv_can_view_receipt($invoice_key = '') {
2004
+	$return = current_user_can('manage_options');
2005 2005
 
2006
-	if ( empty( $invoice_key ) ) {
2006
+	if (empty($invoice_key)) {
2007 2007
 		return false;
2008 2008
 	}
2009 2009
 
2010 2010
 	global $wpinv_receipt_args;
2011 2011
 
2012
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
2013
-	if ( isset( $_GET['invoice-id'] ) ) {
2014
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
2012
+	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key);
2013
+	if (isset($_GET['invoice-id'])) {
2014
+		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? (int) $_GET['invoice-id'] : 0;
2015 2015
 	}
2016 2016
 
2017
-	if ( empty( $wpinv_receipt_args['id'] ) ) {
2017
+	if (empty($wpinv_receipt_args['id'])) {
2018 2018
 		return $return;
2019 2019
 	}
2020 2020
 
2021
-	$invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] );
2022
-	if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) {
2021
+	$invoice = wpinv_get_invoice($wpinv_receipt_args['id']);
2022
+	if (!(!empty($invoice->ID) && $invoice->get_key() === $invoice_key)) {
2023 2023
 		return $return;
2024 2024
 	}
2025 2025
 
2026
-	if ( is_user_logged_in() ) {
2027
-		if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) {
2026
+	if (is_user_logged_in()) {
2027
+		if ((int) $invoice->get_user_id() === (int) get_current_user_id()) {
2028 2028
 			$return = true;
2029 2029
 		}
2030 2030
 	}
2031 2031
 
2032 2032
 	$session = wpinv_get_checkout_session();
2033
-	if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) {
2034
-		$check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key'];
2033
+	if (isset($_GET['invoice_key']) || ($session && isset($session['invoice_key']))) {
2034
+		$check_key = isset($_GET['invoice_key']) ? $_GET['invoice_key'] : $session['invoice_key'];
2035 2035
 
2036
-		if ( wpinv_require_login_to_checkout() ) {
2036
+		if (wpinv_require_login_to_checkout()) {
2037 2037
 			$return = $return && $check_key == $invoice_key;
2038 2038
 		} else {
2039 2039
 			$return = $check_key == $invoice_key;
2040 2040
 		}
2041 2041
 	}
2042 2042
 
2043
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
2043
+	return (bool) apply_filters('wpinv_can_view_receipt', $return, $invoice_key);
2044 2044
 }
2045 2045
 
2046 2046
 function wpinv_pay_for_invoice() {
2047 2047
     global $wpinv_euvat;
2048 2048
     
2049
-    if ( isset( $_GET['invoice_key'] ) ) {
2049
+    if (isset($_GET['invoice_key'])) {
2050 2050
         $checkout_uri   = wpinv_get_checkout_uri();
2051
-        $invoice_key    = sanitize_text_field( $_GET['invoice_key'] );
2051
+        $invoice_key    = sanitize_text_field($_GET['invoice_key']);
2052 2052
         
2053
-        if ( empty( $invoice_key ) ) {
2054
-            wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) );
2055
-            wp_redirect( $checkout_uri );
2053
+        if (empty($invoice_key)) {
2054
+            wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing'));
2055
+            wp_redirect($checkout_uri);
2056 2056
             exit();
2057 2057
         }
2058 2058
         
2059
-        do_action( 'wpinv_check_pay_for_invoice', $invoice_key );
2059
+        do_action('wpinv_check_pay_for_invoice', $invoice_key);
2060 2060
 
2061
-        $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
2062
-        $user_can_view = wpinv_can_view_receipt( $invoice_key );
2063
-        if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
2064
-            $invoice_id     = (int)$_GET['invoice-id'];
2065
-            $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
2061
+        $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
2062
+        $user_can_view = wpinv_can_view_receipt($invoice_key);
2063
+        if ($user_can_view && isset($_GET['invoice-id'])) {
2064
+            $invoice_id     = (int) $_GET['invoice-id'];
2065
+            $user_can_view  = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? true : false;
2066 2066
         }
2067 2067
         
2068
-        if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) {
2069
-            if ( $invoice->needs_payment() ) {
2068
+        if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) {
2069
+            if ($invoice->needs_payment()) {
2070 2070
                 $data                   = array();
2071 2071
                 $data['invoice_id']     = $invoice_id;
2072
-                $data['cart_discounts'] = $invoice->get_discounts( true );
2072
+                $data['cart_discounts'] = $invoice->get_discounts(true);
2073 2073
                 
2074
-                wpinv_set_checkout_session( $data );
2074
+                wpinv_set_checkout_session($data);
2075 2075
                 
2076
-                if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
2076
+                if (wpinv_get_option('vat_ip_country_default')) {
2077 2077
                     $_POST['country']   = $wpinv_euvat->get_country_by_ip();
2078 2078
                     $_POST['state']     = $_POST['country'] == $invoice->country ? $invoice->state : '';
2079 2079
                     
2080
-                    wpinv_recalculate_tax( true );
2080
+                    wpinv_recalculate_tax(true);
2081 2081
                 }
2082 2082
                 
2083 2083
             } else {
2084 2084
                 $checkout_uri = $invoice->get_view_url();
2085 2085
             }
2086 2086
         } else {
2087
-            wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) );
2087
+            wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing'));
2088 2088
             
2089
-            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
2089
+            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
2090 2090
         }
2091 2091
         
2092
-        if(wp_redirect( $checkout_uri )){
2092
+        if (wp_redirect($checkout_uri)) {
2093 2093
             exit;
2094 2094
         };
2095 2095
         wpinv_die();
2096 2096
     }
2097 2097
 }
2098
-add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' );
2098
+add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice');
2099 2099
 
2100
-function wpinv_handle_pay_via_invoice_link( $invoice_key ) {
2101
-    if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) {
2102
-        if ( $invoice = wpinv_get_invoice( $invoice_id ) ) {
2100
+function wpinv_handle_pay_via_invoice_link($invoice_key) {
2101
+    if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) {
2102
+        if ($invoice = wpinv_get_invoice($invoice_id)) {
2103 2103
             $user_id = $invoice->get_user_id();
2104
-            $secret = sanitize_text_field( $_GET['_wpipay'] );
2104
+            $secret = sanitize_text_field($_GET['_wpipay']);
2105 2105
             
2106
-            if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link
2107
-                $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
2106
+            if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link
2107
+                $redirect_to = remove_query_arg('_wpipay', get_permalink());
2108 2108
                 
2109
-                wpinv_guest_redirect( $redirect_to, $user_id );
2109
+                wpinv_guest_redirect($redirect_to, $user_id);
2110 2110
                 exit();
2111 2111
             }
2112 2112
         }
2113 2113
     }
2114 2114
 }
2115
-add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' );
2115
+add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link');
2116 2116
 
2117
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
2118
-    $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id;
2117
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
2118
+    $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id;
2119 2119
     
2120
-    if ( empty( $invoice_id ) && $invoice_id > 0 ) {
2120
+    if (empty($invoice_id) && $invoice_id > 0) {
2121 2121
         return false;
2122 2122
     }
2123 2123
     
2124
-    if ( empty( $transaction_id ) ) {
2124
+    if (empty($transaction_id)) {
2125 2125
         $transaction_id = $invoice_id;
2126 2126
     }
2127 2127
 
2128
-    $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id );
2128
+    $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id);
2129 2129
     
2130
-    return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id );
2130
+    return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id);
2131 2131
 }
2132 2132
 
2133
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
2134
-    if ( empty( $status_display ) ) {
2135
-        $status_display = wpinv_status_nicename( $status );
2133
+function wpinv_invoice_status_label($status, $status_display = '') {
2134
+    if (empty($status_display)) {
2135
+        $status_display = wpinv_status_nicename($status);
2136 2136
     }
2137 2137
     
2138
-    switch ( $status ) {
2138
+    switch ($status) {
2139 2139
         case 'publish' :
2140 2140
         case 'wpi-renewal' :
2141 2141
             $class = 'label-success';
@@ -2160,201 +2160,201 @@  discard block
 block discarded – undo
2160 2160
     
2161 2161
     $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>';
2162 2162
     
2163
-    return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display );
2163
+    return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display);
2164 2164
 }
2165 2165
 
2166
-function wpinv_format_invoice_number( $number, $type = '' ) {
2167
-    $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type );
2168
-    if ( null !== $check ) {
2166
+function wpinv_format_invoice_number($number, $type = '') {
2167
+    $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type);
2168
+    if (null !== $check) {
2169 2169
         return $check;
2170 2170
     }
2171 2171
 
2172
-    if ( !empty( $number ) && !is_numeric( $number ) ) {
2172
+    if (!empty($number) && !is_numeric($number)) {
2173 2173
         return $number;
2174 2174
     }
2175 2175
 
2176
-    $padd  = wpinv_get_option( 'invoice_number_padd' );
2177
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2178
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2176
+    $padd = wpinv_get_option('invoice_number_padd');
2177
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2178
+    $postfix = wpinv_get_option('invoice_number_postfix');
2179 2179
     
2180
-    $padd = absint( $padd );
2181
-    $formatted_number = absint( $number );
2180
+    $padd = absint($padd);
2181
+    $formatted_number = absint($number);
2182 2182
     
2183
-    if ( $padd > 0 ) {
2184
-        $formatted_number = zeroise( $formatted_number, $padd );
2183
+    if ($padd > 0) {
2184
+        $formatted_number = zeroise($formatted_number, $padd);
2185 2185
     }    
2186 2186
 
2187 2187
     $formatted_number = $prefix . $formatted_number . $postfix;
2188 2188
 
2189
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
2189
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
2190 2190
 }
2191 2191
 
2192
-function wpinv_get_next_invoice_number( $type = '' ) {
2193
-    $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type );
2194
-    if ( null !== $check ) {
2192
+function wpinv_get_next_invoice_number($type = '') {
2193
+    $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type);
2194
+    if (null !== $check) {
2195 2195
         return $check;
2196 2196
     }
2197 2197
     
2198
-    if ( !wpinv_sequential_number_active() ) {
2198
+    if (!wpinv_sequential_number_active()) {
2199 2199
         return false;
2200 2200
     }
2201 2201
 
2202
-    $number = $last_number = get_option( 'wpinv_last_invoice_number', 0 );
2203
-    $start  = wpinv_get_option( 'invoice_sequence_start', 1 );
2204
-    if ( !absint( $start ) > 0 ) {
2202
+    $number = $last_number = get_option('wpinv_last_invoice_number', 0);
2203
+    $start  = wpinv_get_option('invoice_sequence_start', 1);
2204
+    if (!absint($start) > 0) {
2205 2205
         $start = 1;
2206 2206
     }
2207 2207
     $increment_number = true;
2208 2208
     $save_number = false;
2209 2209
 
2210
-    if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) {
2211
-        $number = wpinv_clean_invoice_number( $number );
2210
+    if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) {
2211
+        $number = wpinv_clean_invoice_number($number);
2212 2212
     }
2213 2213
 
2214
-    if ( empty( $number ) ) {
2215
-        if ( !( $last_number === 0 || $last_number === '0' ) ) {
2216
-            $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys( wpinv_get_invoice_statuses( true, true ) ) ) );
2214
+    if (empty($number)) {
2215
+        if (!($last_number === 0 || $last_number === '0')) {
2216
+            $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys(wpinv_get_invoice_statuses(true, true))));
2217 2217
 
2218
-            if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) {
2219
-                if ( is_numeric( $invoice_number ) ) {
2218
+            if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) {
2219
+                if (is_numeric($invoice_number)) {
2220 2220
                     $number = $invoice_number;
2221 2221
                 } else {
2222
-                    $number = wpinv_clean_invoice_number( $invoice_number );
2222
+                    $number = wpinv_clean_invoice_number($invoice_number);
2223 2223
                 }
2224 2224
             }
2225 2225
 
2226
-            if ( empty( $number ) ) {
2226
+            if (empty($number)) {
2227 2227
                 $increment_number = false;
2228 2228
                 $number = $start;
2229
-                $save_number = ( $number - 1 );
2229
+                $save_number = ($number - 1);
2230 2230
             } else {
2231 2231
                 $save_number = $number;
2232 2232
             }
2233 2233
         }
2234 2234
     }
2235 2235
 
2236
-    if ( $start > $number ) {
2236
+    if ($start > $number) {
2237 2237
         $increment_number = false;
2238 2238
         $number = $start;
2239
-        $save_number = ( $number - 1 );
2239
+        $save_number = ($number - 1);
2240 2240
     }
2241 2241
 
2242
-    if ( $save_number !== false ) {
2243
-        update_option( 'wpinv_last_invoice_number', $save_number );
2242
+    if ($save_number !== false) {
2243
+        update_option('wpinv_last_invoice_number', $save_number);
2244 2244
     }
2245 2245
     
2246
-    $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number );
2246
+    $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number);
2247 2247
 
2248
-    if ( $increment_number ) {
2248
+    if ($increment_number) {
2249 2249
         $number++;
2250 2250
     }
2251 2251
 
2252
-    return apply_filters( 'wpinv_get_next_invoice_number', $number );
2252
+    return apply_filters('wpinv_get_next_invoice_number', $number);
2253 2253
 }
2254 2254
 
2255
-function wpinv_clean_invoice_number( $number, $type = '' ) {
2256
-    $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type );
2257
-    if ( null !== $check ) {
2255
+function wpinv_clean_invoice_number($number, $type = '') {
2256
+    $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type);
2257
+    if (null !== $check) {
2258 2258
         return $check;
2259 2259
     }
2260 2260
     
2261
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2262
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2261
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2262
+    $postfix = wpinv_get_option('invoice_number_postfix');
2263 2263
 
2264
-    $number = preg_replace( '/' . $prefix . '/', '', $number, 1 );
2264
+    $number = preg_replace('/' . $prefix . '/', '', $number, 1);
2265 2265
 
2266
-    $length      = strlen( $number );
2267
-    $postfix_pos = strrpos( $number, $postfix );
2266
+    $length      = strlen($number);
2267
+    $postfix_pos = strrpos($number, $postfix);
2268 2268
     
2269
-    if ( false !== $postfix_pos ) {
2270
-        $number      = substr_replace( $number, '', $postfix_pos, $length );
2269
+    if (false !== $postfix_pos) {
2270
+        $number = substr_replace($number, '', $postfix_pos, $length);
2271 2271
     }
2272 2272
 
2273
-    $number = intval( $number );
2273
+    $number = intval($number);
2274 2274
 
2275
-    return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix );
2275
+    return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix);
2276 2276
 }
2277 2277
 
2278
-function wpinv_save_number_post_saved( $post_ID, $post, $update ) {
2278
+function wpinv_save_number_post_saved($post_ID, $post, $update) {
2279 2279
     global $wpdb;
2280 2280
 
2281
-    if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) {
2282
-        wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft', $post->post_type );
2281
+    if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) {
2282
+        wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft', $post->post_type);
2283 2283
     }
2284 2284
 
2285
-    if ( !$update ) {
2286
-        $wpdb->update( $wpdb->posts, array( 'post_name' => wpinv_generate_post_name( $post_ID ) ), array( 'ID' => $post_ID ) );
2287
-        clean_post_cache( $post_ID );
2285
+    if (!$update) {
2286
+        $wpdb->update($wpdb->posts, array('post_name' => wpinv_generate_post_name($post_ID)), array('ID' => $post_ID));
2287
+        clean_post_cache($post_ID);
2288 2288
     }
2289 2289
 }
2290
-add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 );
2290
+add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3);
2291 2291
 
2292
-function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) {
2293
-    if ( !empty( $post_after->post_type ) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status ) {
2294
-        wpinv_update_invoice_number( $post_ID, true, $post_after->post_type );
2292
+function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) {
2293
+    if (!empty($post_after->post_type) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status) {
2294
+        wpinv_update_invoice_number($post_ID, true, $post_after->post_type);
2295 2295
     }
2296 2296
 }
2297
-add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 );
2297
+add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3);
2298 2298
 
2299
-function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) {
2299
+function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') {
2300 2300
     global $wpdb;
2301 2301
     
2302
-    $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type );
2303
-    if ( null !== $check ) {
2302
+    $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type);
2303
+    if (null !== $check) {
2304 2304
         return $check;
2305 2305
     }
2306 2306
 
2307
-    if ( wpinv_sequential_number_active() ) {
2307
+    if (wpinv_sequential_number_active()) {
2308 2308
         $number = wpinv_get_next_invoice_number();
2309 2309
 
2310
-        if ( $save_sequential ) {
2311
-            update_option( 'wpinv_last_invoice_number', $number );
2310
+        if ($save_sequential) {
2311
+            update_option('wpinv_last_invoice_number', $number);
2312 2312
         }
2313 2313
     } else {
2314 2314
         $number = $post_ID;
2315 2315
     }
2316 2316
 
2317
-    $number = wpinv_format_invoice_number( $number );
2317
+    $number = wpinv_format_invoice_number($number);
2318 2318
 
2319
-    update_post_meta( $post_ID, '_wpinv_number', $number );
2319
+    update_post_meta($post_ID, '_wpinv_number', $number);
2320 2320
 
2321
-    $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) );
2321
+    $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID));
2322 2322
 
2323
-    clean_post_cache( $post_ID );
2323
+    clean_post_cache($post_ID);
2324 2324
 
2325 2325
     return $number;
2326 2326
 }
2327 2327
 
2328
-function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) {
2329
-    return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type );
2328
+function wpinv_post_name_prefix($post_type = 'wpi_invoice') {
2329
+    return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type);
2330 2330
 }
2331 2331
 
2332
-function wpinv_generate_post_name( $post_ID ) {
2333
-    $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) );
2334
-    $post_name = sanitize_title( $prefix . $post_ID );
2332
+function wpinv_generate_post_name($post_ID) {
2333
+    $prefix = wpinv_post_name_prefix(get_post_type($post_ID));
2334
+    $post_name = sanitize_title($prefix . $post_ID);
2335 2335
 
2336
-    return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix );
2336
+    return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix);
2337 2337
 }
2338 2338
 
2339
-function wpinv_is_invoice_viewed( $invoice_id ) {
2340
-    if ( empty( $invoice_id ) ) {
2339
+function wpinv_is_invoice_viewed($invoice_id) {
2340
+    if (empty($invoice_id)) {
2341 2341
         return false;
2342 2342
     }
2343 2343
 
2344
-    $viewed_meta = get_post_meta( $invoice_id, '_wpinv_is_viewed', true );
2344
+    $viewed_meta = get_post_meta($invoice_id, '_wpinv_is_viewed', true);
2345 2345
 
2346
-    return apply_filters( 'wpinv_is_invoice_viewed', 1 === (int)$viewed_meta, $invoice_id );
2346
+    return apply_filters('wpinv_is_invoice_viewed', 1 === (int) $viewed_meta, $invoice_id);
2347 2347
 }
2348 2348
 
2349 2349
 function wpinv_mark_invoice_viewed() {
2350 2350
 
2351
-    if ( isset( $_GET['invoice_key'] ) || is_singular( 'wpi_invoice' ) || is_singular( 'wpi_quote' ) ) {
2352
-        $invoice_key = isset( $_GET['invoice_key'] ) ? urldecode($_GET['invoice_key']) : '';
2351
+    if (isset($_GET['invoice_key']) || is_singular('wpi_invoice') || is_singular('wpi_quote')) {
2352
+        $invoice_key = isset($_GET['invoice_key']) ? urldecode($_GET['invoice_key']) : '';
2353 2353
 	    global $post;
2354 2354
 
2355
-        if(!empty($invoice_key)){
2355
+        if (!empty($invoice_key)) {
2356 2356
 	        $invoice_id = wpinv_get_invoice_id_by_key($invoice_key);
2357
-        } else if(!empty( $post ) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) {
2357
+        } else if (!empty($post) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) {
2358 2358
 			$invoice_id = $post->ID;
2359 2359
         } else {
2360 2360
         	return;
@@ -2362,73 +2362,73 @@  discard block
 block discarded – undo
2362 2362
 
2363 2363
         $invoice = new WPInv_Invoice($invoice_id);
2364 2364
 
2365
-        if(!$invoice_id){
2365
+        if (!$invoice_id) {
2366 2366
             return;
2367 2367
         }
2368 2368
 
2369
-	    if ( is_user_logged_in() ) {
2370
-		    if ( (int)$invoice->get_user_id() === get_current_user_id() ) {
2371
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2372
-		    } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2373
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2369
+	    if (is_user_logged_in()) {
2370
+		    if ((int) $invoice->get_user_id() === get_current_user_id()) {
2371
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2372
+		    } else if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2373
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2374 2374
 		    }
2375 2375
 	    } else {
2376
-		    if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2377
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2376
+		    if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2377
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2378 2378
 		    }
2379 2379
 	    }
2380 2380
     }
2381 2381
 
2382 2382
 }
2383
-add_action( 'template_redirect', 'wpinv_mark_invoice_viewed' );
2383
+add_action('template_redirect', 'wpinv_mark_invoice_viewed');
2384 2384
 
2385 2385
 /**
2386 2386
  * Fetch a subscription given an invoice.
2387 2387
  *
2388 2388
  * @return WPInv_Subscription|bool
2389 2389
  */
2390
-function wpinv_get_subscription( $invoice ) {
2390
+function wpinv_get_subscription($invoice) {
2391 2391
 
2392 2392
     // Abort if we do not have an invoice.
2393
-    if ( empty( $invoice ) ) {
2393
+    if (empty($invoice)) {
2394 2394
         return false;
2395 2395
     }
2396 2396
 
2397 2397
     // Retrieve the invoice.
2398
-    $invoice = new WPInv_Invoice( $invoice );
2398
+    $invoice = new WPInv_Invoice($invoice);
2399 2399
 
2400 2400
     // Ensure it is a recurring invoice.
2401
-    if ( ! $invoice->is_recurring() ) {
2401
+    if (!$invoice->is_recurring()) {
2402 2402
         return false;
2403 2403
     }
2404 2404
 
2405 2405
     // Fetch the subscription handler.
2406
-    $subs_db    = new WPInv_Subscriptions_DB();
2406
+    $subs_db = new WPInv_Subscriptions_DB();
2407 2407
 
2408 2408
     // Fetch the parent in case it is a renewal.
2409
-    if ( $invoice->is_renewal() ) {
2410
-        $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice->get_parent_id(), 'number' => 1 ) );
2409
+    if ($invoice->is_renewal()) {
2410
+        $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice->get_parent_id(), 'number' => 1));
2411 2411
     } else {
2412
-        $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice->get_id(), 'number' => 1 ) );
2412
+        $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice->get_id(), 'number' => 1));
2413 2413
     }
2414 2414
 
2415 2415
     // Return the subscription if it exists.
2416
-    if ( ! empty( $subs ) ) {
2417
-        return reset( $subs );
2416
+    if (!empty($subs)) {
2417
+        return reset($subs);
2418 2418
     }
2419 2419
 
2420 2420
     return false;
2421 2421
 }
2422 2422
 
2423
-function wpinv_filter_posts_clauses( $clauses, $wp_query ) {
2423
+function wpinv_filter_posts_clauses($clauses, $wp_query) {
2424 2424
     global $wpdb;
2425 2425
 
2426
-    if ( ! empty( $wp_query->query_vars['orderby'] ) && $wp_query->query_vars['orderby'] == 'invoice_date' ) {
2427
-        if ( !empty( $clauses['join'] ) ) {
2426
+    if (!empty($wp_query->query_vars['orderby']) && $wp_query->query_vars['orderby'] == 'invoice_date') {
2427
+        if (!empty($clauses['join'])) {
2428 2428
             $clauses['join'] .= " ";
2429 2429
         }
2430 2430
 
2431
-        if ( !empty( $clauses['fields'] ) ) {
2431
+        if (!empty($clauses['fields'])) {
2432 2432
             $clauses['fields'] .= ", ";
2433 2433
         }
2434 2434
 
@@ -2439,7 +2439,7 @@  discard block
 block discarded – undo
2439 2439
 
2440 2440
     return $clauses;
2441 2441
 }
2442
-add_filter( 'posts_clauses', 'wpinv_filter_posts_clauses', 10, 2 );
2442
+add_filter('posts_clauses', 'wpinv_filter_posts_clauses', 10, 2);
2443 2443
 
2444 2444
 /**
2445 2445
  * Processes an invoice refund.
@@ -2449,27 +2449,27 @@  discard block
 block discarded – undo
2449 2449
  * @param array $status_transition
2450 2450
  * @todo: descrease customer/store earnings
2451 2451
  */
2452
-function getpaid_maybe_process_refund( $invoice_id, $invoice, $status_transition ) {
2452
+function getpaid_maybe_process_refund($invoice_id, $invoice, $status_transition) {
2453 2453
 
2454
-    if ( empty( $status_transition['from'] ) || ! $invoice->has_status( 'wpi-refunded' ) || in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
2454
+    if (empty($status_transition['from']) || !$invoice->has_status('wpi-refunded') || in_array($status_transition['from'], array('publish', 'wpi-processing', 'wpi-renewal'))) {
2455 2455
         return;
2456 2456
     }
2457 2457
 
2458 2458
     $discount_code = $invoice->get_discount_code();
2459
-    if ( ! empty( $discount_code ) ) {
2460
-        $discount = wpinv_get_discount_obj( $discount_code );
2459
+    if (!empty($discount_code)) {
2460
+        $discount = wpinv_get_discount_obj($discount_code);
2461 2461
 
2462
-        if ( $discount->exists() ) {
2462
+        if ($discount->exists()) {
2463 2463
             $discount->increase_usage( -1 );
2464 2464
         }
2465 2465
     
2466 2466
     }
2467 2467
 
2468
-    do_action( 'wpinv_pre_refund_invoice', $invoice, $invoice_id );
2469
-    do_action( 'wpinv_refund_invoice', $invoice, $invoice_id );
2470
-    do_action( 'wpinv_post_refund_invoice', $invoice, $invoice_id );
2468
+    do_action('wpinv_pre_refund_invoice', $invoice, $invoice_id);
2469
+    do_action('wpinv_refund_invoice', $invoice, $invoice_id);
2470
+    do_action('wpinv_post_refund_invoice', $invoice, $invoice_id);
2471 2471
 }
2472
-add_action( 'getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 3 );
2472
+add_action('getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 3);
2473 2473
 
2474 2474
 /**
2475 2475
  * Fires when a payment fails.
@@ -2477,22 +2477,22 @@  discard block
 block discarded – undo
2477 2477
  * @param int $invoice_id
2478 2478
  * @param WPInv_Invoice $invoice
2479 2479
  */
2480
-function getpaid_maybe_process_failure( $invoice_id, $invoice ) {
2480
+function getpaid_maybe_process_failure($invoice_id, $invoice) {
2481 2481
 
2482
-    if ( ! $invoice->has_status( 'wpi-failed' ) ) {
2482
+    if (!$invoice->has_status('wpi-failed')) {
2483 2483
         return;
2484 2484
     }
2485 2485
 
2486 2486
     $discount_code = $invoice->get_discount_code();
2487
-    if ( ! empty( $discount_code ) ) {
2488
-        $discount = wpinv_get_discount_obj( $discount_code );
2487
+    if (!empty($discount_code)) {
2488
+        $discount = wpinv_get_discount_obj($discount_code);
2489 2489
 
2490
-        if ( $discount->exists() ) {
2490
+        if ($discount->exists()) {
2491 2491
             $discount->increase_usage( -1 );
2492 2492
         }
2493 2493
 
2494 2494
     }
2495 2495
 
2496
-    do_action( 'wpinv_invoice_payment_failed', $invoice, $invoice_id );
2496
+    do_action('wpinv_invoice_payment_failed', $invoice, $invoice_id);
2497 2497
 }
2498
-add_action( 'getpaid_invoice_status_wpi-failed', 'getpaid_maybe_process_failure', 10, 2 );
2499 2498
\ No newline at end of file
2499
+add_action('getpaid_invoice_status_wpi-failed', 'getpaid_maybe_process_failure', 10, 2);
2500 2500
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-gateway-functions.php 1 patch
Spacing   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -7,206 +7,206 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_get_payment_gateways() {
15 15
     // Default, built-in gateways
16 16
     $gateways = array(
17 17
         'paypal' => array(
18
-            'admin_label'    => __( 'PayPal Standard', 'invoicing' ),
19
-            'checkout_label' => __( 'PayPal Standard', 'invoicing' ),
18
+            'admin_label'    => __('PayPal Standard', 'invoicing'),
19
+            'checkout_label' => __('PayPal Standard', 'invoicing'),
20 20
             'ordering'       => 1,
21 21
         ),
22 22
         'authorizenet' => array(
23
-            'admin_label'    => __( 'Authorize.Net (AIM)', 'invoicing' ),
24
-            'checkout_label' => __( 'Authorize.Net - Credit Card / Debit Card', 'invoicing' ),
23
+            'admin_label'    => __('Authorize.Net (AIM)', 'invoicing'),
24
+            'checkout_label' => __('Authorize.Net - Credit Card / Debit Card', 'invoicing'),
25 25
             'ordering'       => 4,
26 26
         ),
27 27
         'worldpay' => array(
28
-            'admin_label'    => __( 'Worldpay', 'invoicing' ),
29
-            'checkout_label' => __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ),
28
+            'admin_label'    => __('Worldpay', 'invoicing'),
29
+            'checkout_label' => __('Worldpay - Credit Card / Debit Card', 'invoicing'),
30 30
             'ordering'       => 5,
31 31
         ),
32 32
         'bank_transfer' => array(
33
-            'admin_label'    => __( 'Pre Bank Transfer', 'invoicing' ),
34
-            'checkout_label' => __( 'Pre Bank Transfer', 'invoicing' ),
33
+            'admin_label'    => __('Pre Bank Transfer', 'invoicing'),
34
+            'checkout_label' => __('Pre Bank Transfer', 'invoicing'),
35 35
             'ordering'       => 11,
36 36
         ),
37 37
         'manual' => array(
38
-            'admin_label'    => __( 'Manual Payment', 'invoicing' ),
39
-            'checkout_label' => __( 'Manual Payment', 'invoicing' ),
38
+            'admin_label'    => __('Manual Payment', 'invoicing'),
39
+            'checkout_label' => __('Manual Payment', 'invoicing'),
40 40
             'ordering'       => 12,
41 41
         ),
42 42
     );
43 43
 
44
-    return apply_filters( 'wpinv_payment_gateways', $gateways );
44
+    return apply_filters('wpinv_payment_gateways', $gateways);
45 45
 }
46 46
 
47
-function wpinv_payment_gateway_titles( $all_gateways ) {
47
+function wpinv_payment_gateway_titles($all_gateways) {
48 48
     global $wpinv_options;
49 49
 
50 50
     $gateways = array();
51
-    foreach ( $all_gateways as $key => $gateway ) {
52
-        if ( !empty( $wpinv_options[$key . '_title'] ) ) {
53
-            $all_gateways[$key]['checkout_label'] = __( $wpinv_options[$key . '_title'], 'invoicing' );
51
+    foreach ($all_gateways as $key => $gateway) {
52
+        if (!empty($wpinv_options[$key . '_title'])) {
53
+            $all_gateways[$key]['checkout_label'] = __($wpinv_options[$key . '_title'], 'invoicing');
54 54
         }
55 55
 
56
-        $gateways[$key] = isset( $wpinv_options[$key . '_ordering'] ) ? $wpinv_options[$key . '_ordering'] : ( isset( $gateway['ordering'] ) ? $gateway['ordering'] : '' );
56
+        $gateways[$key] = isset($wpinv_options[$key . '_ordering']) ? $wpinv_options[$key . '_ordering'] : (isset($gateway['ordering']) ? $gateway['ordering'] : '');
57 57
     }
58 58
 
59
-    asort( $gateways );
59
+    asort($gateways);
60 60
 
61
-    foreach ( $gateways as $gateway => $key ) {
61
+    foreach ($gateways as $gateway => $key) {
62 62
         $gateways[$gateway] = $all_gateways[$gateway];
63 63
     }
64 64
 
65 65
     return $gateways;
66 66
 }
67
-add_filter( 'wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1 );
67
+add_filter('wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1);
68 68
 
69
-function wpinv_get_enabled_payment_gateways( $sort = false ) {
69
+function wpinv_get_enabled_payment_gateways($sort = false) {
70 70
     $gateways = wpinv_get_payment_gateways();
71
-    $enabled  = wpinv_get_option( 'gateways', false );
71
+    $enabled  = wpinv_get_option('gateways', false);
72 72
 
73 73
     $gateway_list = array();
74 74
 
75
-    foreach ( $gateways as $key => $gateway ) {
76
-        if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) {
77
-            $gateway_list[ $key ] = $gateway;
75
+    foreach ($gateways as $key => $gateway) {
76
+        if (isset($enabled[$key]) && $enabled[$key] == 1) {
77
+            $gateway_list[$key] = $gateway;
78 78
         }
79 79
     }
80 80
 
81
-    if ( true === $sort ) {
82
-        uasort( $gateway_list, 'wpinv_sort_gateway_order' );
81
+    if (true === $sort) {
82
+        uasort($gateway_list, 'wpinv_sort_gateway_order');
83 83
         
84 84
         // Reorder our gateways so the default is first
85 85
         $default_gateway_id = wpinv_get_default_gateway();
86 86
 
87
-        if ( wpinv_is_gateway_active( $default_gateway_id ) ) {
88
-            $default_gateway    = array( $default_gateway_id => $gateway_list[ $default_gateway_id ] );
89
-            unset( $gateway_list[ $default_gateway_id ] );
87
+        if (wpinv_is_gateway_active($default_gateway_id)) {
88
+            $default_gateway = array($default_gateway_id => $gateway_list[$default_gateway_id]);
89
+            unset($gateway_list[$default_gateway_id]);
90 90
 
91
-            $gateway_list = array_merge( $default_gateway, $gateway_list );
91
+            $gateway_list = array_merge($default_gateway, $gateway_list);
92 92
         }
93 93
     }
94 94
 
95
-    return apply_filters( 'wpinv_enabled_payment_gateways', $gateway_list );
95
+    return apply_filters('wpinv_enabled_payment_gateways', $gateway_list);
96 96
 }
97 97
 
98
-function wpinv_sort_gateway_order( $a, $b ) {
98
+function wpinv_sort_gateway_order($a, $b) {
99 99
     return $a['ordering'] - $b['ordering'];
100 100
 }
101 101
 
102
-function wpinv_is_gateway_active( $gateway ) {
102
+function wpinv_is_gateway_active($gateway) {
103 103
     $gateways = wpinv_get_enabled_payment_gateways();
104 104
 
105
-    $ret = is_array($gateways) && $gateway ?  array_key_exists( $gateway, $gateways ) : false;
105
+    $ret = is_array($gateways) && $gateway ?  array_key_exists($gateway, $gateways) : false;
106 106
 
107
-    return apply_filters( 'wpinv_is_gateway_active', $ret, $gateway, $gateways );
107
+    return apply_filters('wpinv_is_gateway_active', $ret, $gateway, $gateways);
108 108
 }
109 109
 
110 110
 function wpinv_get_default_gateway() {
111
-    $default = wpinv_get_option( 'default_gateway', 'paypal' );
111
+    $default = wpinv_get_option('default_gateway', 'paypal');
112 112
 
113
-    if ( !wpinv_is_gateway_active( $default ) ) {
113
+    if (!wpinv_is_gateway_active($default)) {
114 114
         $gateways = wpinv_get_enabled_payment_gateways();
115
-        $gateways = array_keys( $gateways );
116
-        $default  = reset( $gateways );
115
+        $gateways = array_keys($gateways);
116
+        $default  = reset($gateways);
117 117
     }
118 118
 
119
-    return apply_filters( 'wpinv_default_gateway', $default );
119
+    return apply_filters('wpinv_default_gateway', $default);
120 120
 }
121 121
 
122
-function wpinv_get_gateway_admin_label( $gateway ) {
122
+function wpinv_get_gateway_admin_label($gateway) {
123 123
     $gateways = wpinv_get_payment_gateways();
124
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway;
125
-    $payment  = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : false;
124
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway;
125
+    $payment  = isset($_GET['id']) ? absint($_GET['id']) : false;
126 126
 
127
-    if( $gateway == 'manual' && $payment ) {
128
-        if( !( (float)wpinv_payment_total( $payment ) > 0 ) ) {
129
-            $label = __( 'Free Purchase', 'invoicing' );
127
+    if ($gateway == 'manual' && $payment) {
128
+        if (!((float) wpinv_payment_total($payment) > 0)) {
129
+            $label = __('Free Purchase', 'invoicing');
130 130
         }
131 131
     }
132 132
 
133
-    return apply_filters( 'wpinv_gateway_admin_label', $label, $gateway );
133
+    return apply_filters('wpinv_gateway_admin_label', $label, $gateway);
134 134
 }
135 135
 
136
-function wpinv_get_gateway_description( $gateway ) {
136
+function wpinv_get_gateway_description($gateway) {
137 137
     global $wpinv_options;
138 138
 
139
-    $description = ! empty( $wpinv_options[$gateway . '_desc'] ) ? $wpinv_options[$gateway . '_desc'] : '';
139
+    $description = !empty($wpinv_options[$gateway . '_desc']) ? $wpinv_options[$gateway . '_desc'] : '';
140 140
 
141
-    return apply_filters( 'wpinv_gateway_description', $description, $gateway );
141
+    return apply_filters('wpinv_gateway_description', $description, $gateway);
142 142
 }
143 143
 
144
-function wpinv_get_gateway_button_label( $gateway ) {
145
-    return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' );
144
+function wpinv_get_gateway_button_label($gateway) {
145
+    return apply_filters('wpinv_gateway_' . $gateway . '_button_label', '');
146 146
 }
147 147
 
148
-function wpinv_get_gateway_checkout_label( $gateway ) {
148
+function wpinv_get_gateway_checkout_label($gateway) {
149 149
     $gateways = wpinv_get_payment_gateways();
150
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway;
150
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway;
151 151
 
152
-    if( $gateway == 'manual' ) {
153
-        $label = __( 'Manual Payment', 'invoicing' );
152
+    if ($gateway == 'manual') {
153
+        $label = __('Manual Payment', 'invoicing');
154 154
     }
155 155
 
156
-    return apply_filters( 'wpinv_gateway_checkout_label', $label, $gateway );
156
+    return apply_filters('wpinv_gateway_checkout_label', $label, $gateway);
157 157
 }
158 158
 
159
-function wpinv_settings_sections_gateways( $settings ) {
159
+function wpinv_settings_sections_gateways($settings) {
160 160
     $gateways = wpinv_get_payment_gateways();
161 161
     
162 162
     if (!empty($gateways)) {
163
-        foreach  ($gateways as $key => $gateway) {
163
+        foreach ($gateways as $key => $gateway) {
164 164
             $settings[$key] = $gateway['admin_label'];
165 165
         }
166 166
     }
167 167
     
168 168
     return $settings;    
169 169
 }
170
-add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 );
170
+add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1);
171 171
 
172
-function wpinv_settings_gateways( $settings ) {
172
+function wpinv_settings_gateways($settings) {
173 173
     $gateways = wpinv_get_payment_gateways();
174 174
     
175 175
     if (!empty($gateways)) {
176
-        foreach  ($gateways as $key => $gateway) {
176
+        foreach ($gateways as $key => $gateway) {
177 177
             $setting = array();
178 178
             $setting[$key . '_header'] = array(
179 179
                     'id'   => 'gateway_header',
180
-                    'name' => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>',
180
+                    'name' => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>',
181 181
                     'custom' => $key,
182 182
                     'type' => 'gateway_header',
183 183
                 );
184 184
             $setting[$key . '_active'] = array(
185 185
                     'id'   => $key . '_active',
186
-                    'name' => __( 'Active', 'invoicing' ),
187
-                    'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ),
186
+                    'name' => __('Active', 'invoicing'),
187
+                    'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']),
188 188
                     'type' => 'checkbox',
189 189
                 );
190 190
                 
191 191
             $setting[$key . '_title'] = array(
192 192
                     'id'   => $key . '_title',
193
-                    'name' => __( 'Title', 'invoicing' ),
194
-                    'desc' => __( 'This controls the title which the user sees during checkout.', 'invoicing' ),
193
+                    'name' => __('Title', 'invoicing'),
194
+                    'desc' => __('This controls the title which the user sees during checkout.', 'invoicing'),
195 195
                     'type' => 'text',
196 196
                     'std' => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : ''
197 197
                 );
198 198
             
199 199
             $setting[$key . '_desc'] = array(
200 200
                     'id'   => $key . '_desc',
201
-                    'name' => __( 'Description', 'invoicing' ),
202
-                    'desc' => __( 'This controls the description which the user sees during checkout.', 'invoicing' ),
201
+                    'name' => __('Description', 'invoicing'),
202
+                    'desc' => __('This controls the description which the user sees during checkout.', 'invoicing'),
203 203
                     'type' => 'text',
204 204
                     'size' => 'large'
205 205
                 );
206 206
                 
207 207
             $setting[$key . '_ordering'] = array(
208 208
                     'id'   => $key . '_ordering',
209
-                    'name' => __( 'Display Order', 'invoicing' ),
209
+                    'name' => __('Display Order', 'invoicing'),
210 210
                     'type' => 'number',
211 211
                     'size' => 'small',
212 212
                     'std'  => isset($gateway['ordering']) ? $gateway['ordering'] : '10',
@@ -215,8 +215,8 @@  discard block
 block discarded – undo
215 215
                     'step' => '1'
216 216
                 );
217 217
                 
218
-            $setting = apply_filters( 'wpinv_gateway_settings', $setting, $key );
219
-            $setting = apply_filters( 'wpinv_gateway_settings_' . $key, $setting );
218
+            $setting = apply_filters('wpinv_gateway_settings', $setting, $key);
219
+            $setting = apply_filters('wpinv_gateway_settings_' . $key, $setting);
220 220
             
221 221
             $settings[$key] = $setting;
222 222
         }
@@ -224,106 +224,106 @@  discard block
 block discarded – undo
224 224
     
225 225
     return $settings;    
226 226
 }
227
-add_filter( 'wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1 );
227
+add_filter('wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1);
228 228
 
229
-function wpinv_gateway_header_callback( $args ) {
230
-    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr( $args['custom'] ) . '" />';
229
+function wpinv_gateway_header_callback($args) {
230
+    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr($args['custom']) . '" />';
231 231
 }
232 232
 
233
-function wpinv_get_gateway_supports( $gateway ) {
233
+function wpinv_get_gateway_supports($gateway) {
234 234
     $gateways = wpinv_get_enabled_payment_gateways();
235
-    $supports = isset( $gateways[ $gateway ]['supports'] ) ? $gateways[ $gateway ]['supports'] : array();
236
-    return apply_filters( 'wpinv_gateway_supports', $supports, $gateway );
235
+    $supports = isset($gateways[$gateway]['supports']) ? $gateways[$gateway]['supports'] : array();
236
+    return apply_filters('wpinv_gateway_supports', $supports, $gateway);
237 237
 }
238 238
 
239
-function wpinv_gateway_supports_buy_now( $gateway ) {
240
-    $supports = wpinv_get_gateway_supports( $gateway );
241
-    $ret = in_array( 'buy_now', $supports );
242
-    return apply_filters( 'wpinv_gateway_supports_buy_now', $ret, $gateway );
239
+function wpinv_gateway_supports_buy_now($gateway) {
240
+    $supports = wpinv_get_gateway_supports($gateway);
241
+    $ret = in_array('buy_now', $supports);
242
+    return apply_filters('wpinv_gateway_supports_buy_now', $ret, $gateway);
243 243
 }
244 244
 
245 245
 function wpinv_shop_supports_buy_now() {
246 246
     $gateways = wpinv_get_enabled_payment_gateways();
247 247
     $ret      = false;
248 248
 
249
-    if ( !wpinv_use_taxes()  && $gateways ) {
250
-        foreach ( $gateways as $gateway_id => $gateway ) {
251
-            if ( wpinv_gateway_supports_buy_now( $gateway_id ) ) {
249
+    if (!wpinv_use_taxes() && $gateways) {
250
+        foreach ($gateways as $gateway_id => $gateway) {
251
+            if (wpinv_gateway_supports_buy_now($gateway_id)) {
252 252
                 $ret = true;
253 253
                 break;
254 254
             }
255 255
         }
256 256
     }
257 257
 
258
-    return apply_filters( 'wpinv_shop_supports_buy_now', $ret );
258
+    return apply_filters('wpinv_shop_supports_buy_now', $ret);
259 259
 }
260 260
 
261
-function wpinv_send_to_gateway( $gateway, $payment_data ) {
262
-    $payment_data['gateway_nonce'] = wp_create_nonce( 'wpi-gateway' );
261
+function wpinv_send_to_gateway($gateway, $payment_data) {
262
+    $payment_data['gateway_nonce'] = wp_create_nonce('wpi-gateway');
263 263
 
264 264
     // $gateway must match the ID used when registering the gateway
265
-    do_action( 'wpinv_gateway_' . $gateway, $payment_data );
265
+    do_action('wpinv_gateway_' . $gateway, $payment_data);
266 266
 }
267 267
 
268 268
 function wpinv_show_gateways() {
269 269
     $gateways = wpinv_get_enabled_payment_gateways();
270 270
     $show_gateways = false;
271 271
 
272
-    $chosen_gateway = isset( $_GET['payment-mode'] ) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode'] ) : false;
272
+    $chosen_gateway = isset($_GET['payment-mode']) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode']) : false;
273 273
 
274
-    if ( count( $gateways ) > 1 && empty( $chosen_gateway ) ) {
274
+    if (count($gateways) > 1 && empty($chosen_gateway)) {
275 275
         $show_gateways = true;
276
-        if ( wpinv_get_cart_total() <= 0 ) {
276
+        if (wpinv_get_cart_total() <= 0) {
277 277
             $show_gateways = false;
278 278
         }
279 279
     }
280 280
     
281
-    if ( !$show_gateways && wpinv_cart_has_recurring_item() ) {
281
+    if (!$show_gateways && wpinv_cart_has_recurring_item()) {
282 282
         $show_gateways = true;
283 283
     }
284 284
 
285
-    return apply_filters( 'wpinv_show_gateways', $show_gateways );
285
+    return apply_filters('wpinv_show_gateways', $show_gateways);
286 286
 }
287 287
 
288
-function wpinv_get_chosen_gateway( $invoice_id = 0 ) {
289
-	$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
288
+function wpinv_get_chosen_gateway($invoice_id = 0) {
289
+	$gateways = array_keys(wpinv_get_enabled_payment_gateways());
290 290
 
291 291
     $chosen = false;
292
-    if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) {
292
+    if ($invoice_id > 0 && $invoice = wpinv_get_invoice($invoice_id)) {
293 293
         $chosen = $invoice->get_gateway();
294 294
     }
295 295
 
296
-	$chosen   = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen;
296
+	$chosen = isset($_REQUEST['payment-mode']) ? sanitize_text_field($_REQUEST['payment-mode']) : $chosen;
297 297
 
298
-	if ( false !== $chosen ) {
299
-		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen );
298
+	if (false !== $chosen) {
299
+		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen);
300 300
 	}
301 301
 
302
-	if ( ! empty ( $chosen ) ) {
303
-		$enabled_gateway = urldecode( $chosen );
304
-	} else if (  !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) {
302
+	if (!empty ($chosen)) {
303
+		$enabled_gateway = urldecode($chosen);
304
+	} else if (!empty($invoice) && (float) $invoice->get_subtotal() <= 0) {
305 305
 		$enabled_gateway = 'manual';
306 306
 	} else {
307 307
 		$enabled_gateway = wpinv_get_default_gateway();
308 308
 	}
309 309
     
310
-    if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) {
311
-        if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){
310
+    if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) {
311
+        if (wpinv_is_gateway_active(wpinv_get_default_gateway())) {
312 312
             $enabled_gateway = wpinv_get_default_gateway();
313
-        }else{
313
+        } else {
314 314
             $enabled_gateway = $gateways[0];
315 315
         }
316 316
 
317 317
     }
318 318
 
319
-	return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway );
319
+	return apply_filters('wpinv_chosen_gateway', $enabled_gateway);
320 320
 }
321 321
 
322
-function wpinv_record_gateway_error( $title = '', $message = '', $parent = 0 ) {
323
-    return wpinv_error_log( $message, $title );
322
+function wpinv_record_gateway_error($title = '', $message = '', $parent = 0) {
323
+    return wpinv_error_log($message, $title);
324 324
 }
325 325
 
326
-function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) {
326
+function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') {
327 327
 	$ret  = 0;
328 328
 	$args = array(
329 329
 		'meta_key'    => '_wpinv_gateway',
@@ -334,48 +334,48 @@  discard block
 block discarded – undo
334 334
 		'fields'      => 'ids'
335 335
 	);
336 336
 
337
-	$payments = new WP_Query( $args );
337
+	$payments = new WP_Query($args);
338 338
 
339
-	if( $payments )
339
+	if ($payments)
340 340
 		$ret = $payments->post_count;
341 341
 	return $ret;
342 342
 }
343 343
 
344
-function wpinv_settings_update_gateways( $input ) {
344
+function wpinv_settings_update_gateways($input) {
345 345
     global $wpinv_options;
346 346
     
347
-    if ( !empty( $input['save_gateway'] ) ) {
348
-        $gateways = wpinv_get_option( 'gateways', false );
347
+    if (!empty($input['save_gateway'])) {
348
+        $gateways = wpinv_get_option('gateways', false);
349 349
         $gateways = !empty($gateways) ? $gateways : array();
350 350
         $gateway = $input['save_gateway'];
351 351
         
352
-        if ( !empty( $input[$gateway . '_active'] ) ) {
352
+        if (!empty($input[$gateway . '_active'])) {
353 353
             $gateways[$gateway] = 1;
354 354
         } else {
355
-            if ( isset( $gateways[$gateway] ) ) {
356
-                unset( $gateways[$gateway] );
355
+            if (isset($gateways[$gateway])) {
356
+                unset($gateways[$gateway]);
357 357
             }
358 358
         }
359 359
         
360 360
         $input['gateways'] = $gateways;
361 361
     }
362 362
     
363
-    if ( !empty( $input['default_gateway'] ) ) {
363
+    if (!empty($input['default_gateway'])) {
364 364
         $gateways = wpinv_get_payment_gateways();
365 365
         
366
-        foreach ( $gateways as $key => $gateway ) {
367
-            $active   = 0;
368
-            if ( !empty( $input['gateways'] ) && !empty( $input['gateways'][$key] ) ) {
366
+        foreach ($gateways as $key => $gateway) {
367
+            $active = 0;
368
+            if (!empty($input['gateways']) && !empty($input['gateways'][$key])) {
369 369
                 $active = 1;
370 370
             }
371 371
             
372 372
             $input[$key . '_active'] = $active;
373 373
             
374
-            if ( empty( $wpinv_options[$key . '_title'] ) ) {
374
+            if (empty($wpinv_options[$key . '_title'])) {
375 375
                 $input[$key . '_title'] = $gateway['checkout_label'];
376 376
             }
377 377
             
378
-            if ( !isset( $wpinv_options[$key . '_ordering'] ) && isset( $gateway['ordering'] ) ) {
378
+            if (!isset($wpinv_options[$key . '_ordering']) && isset($gateway['ordering'])) {
379 379
                 $input[$key . '_ordering'] = $gateway['ordering'];
380 380
             }
381 381
         }
@@ -383,27 +383,27 @@  discard block
 block discarded – undo
383 383
     
384 384
     return $input;
385 385
 }
386
-add_filter( 'wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1 );
386
+add_filter('wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1);
387 387
 
388 388
 // PayPal Standard settings
389
-function wpinv_gateway_settings_paypal( $setting ) {    
390
-    $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing' );
391
-    $setting['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
389
+function wpinv_gateway_settings_paypal($setting) {    
390
+    $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __('( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing');
391
+    $setting['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing');
392 392
     
393 393
     $setting['paypal_sandbox'] = array(
394 394
             'type' => 'checkbox',
395 395
             'id'   => 'paypal_sandbox',
396
-            'name' => __( 'PayPal Sandbox', 'invoicing' ),
397
-            'desc' => __( 'PayPal sandbox can be used to test payments.', 'invoicing' ),
396
+            'name' => __('PayPal Sandbox', 'invoicing'),
397
+            'desc' => __('PayPal sandbox can be used to test payments.', 'invoicing'),
398 398
             'std'  => 1
399 399
         );
400 400
         
401 401
     $setting['paypal_email'] = array(
402 402
             'type' => 'text',
403 403
             'id'   => 'paypal_email',
404
-            'name' => __( 'PayPal Email', 'invoicing' ),
405
-            'desc' => __( 'Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing' ),
406
-            'std' => __( '[email protected]', 'invoicing' ),
404
+            'name' => __('PayPal Email', 'invoicing'),
405
+            'desc' => __('Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing'),
406
+            'std' => __('[email protected]', 'invoicing'),
407 407
         );
408 408
     /*
409 409
     $setting['paypal_ipn_url'] = array(
@@ -417,139 +417,139 @@  discard block
 block discarded – undo
417 417
         
418 418
     return $setting;
419 419
 }
420
-add_filter( 'wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1 );
420
+add_filter('wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1);
421 421
 
422 422
 // Pre Bank Transfer settings
423
-function wpinv_gateway_settings_bank_transfer( $setting ) {
424
-    $setting['bank_transfer_desc']['std'] = __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' );
423
+function wpinv_gateway_settings_bank_transfer($setting) {
424
+    $setting['bank_transfer_desc']['std'] = __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing');
425 425
     
426 426
     $setting['bank_transfer_ac_name'] = array(
427 427
             'type' => 'text',
428 428
             'id' => 'bank_transfer_ac_name',
429
-            'name' => __( 'Account Name', 'invoicing' ),
430
-            'desc' => __( 'Enter the bank account name to which you want to transfer payment.', 'invoicing' ),
431
-            'std'  =>  __( 'Mr. John Martin', 'invoicing' ),
429
+            'name' => __('Account Name', 'invoicing'),
430
+            'desc' => __('Enter the bank account name to which you want to transfer payment.', 'invoicing'),
431
+            'std'  =>  __('Mr. John Martin', 'invoicing'),
432 432
         );
433 433
     
434 434
     $setting['bank_transfer_ac_no'] = array(
435 435
             'type' => 'text',
436 436
             'id' => 'bank_transfer_ac_no',
437
-            'name' => __( 'Account Number', 'invoicing' ),
438
-            'desc' => __( 'Enter your bank account number.', 'invoicing' ),
439
-            'std'  =>  __( 'TEST1234567890', 'invoicing' ),
437
+            'name' => __('Account Number', 'invoicing'),
438
+            'desc' => __('Enter your bank account number.', 'invoicing'),
439
+            'std'  =>  __('TEST1234567890', 'invoicing'),
440 440
         );
441 441
     
442 442
     $setting['bank_transfer_bank_name'] = array(
443 443
             'type' => 'text',
444 444
             'id'   => 'bank_transfer_bank_name',
445
-            'name' => __( 'Bank Name', 'invoicing' ),
446
-            'desc' => __( 'Enter the bank name to which you want to transfer payment.', 'invoicing' ),
447
-            'std' => __( 'ICICI Bank', 'invoicing' ),
445
+            'name' => __('Bank Name', 'invoicing'),
446
+            'desc' => __('Enter the bank name to which you want to transfer payment.', 'invoicing'),
447
+            'std' => __('ICICI Bank', 'invoicing'),
448 448
         );
449 449
     
450 450
     $setting['bank_transfer_ifsc'] = array(
451 451
             'type' => 'text',
452 452
             'id'   => 'bank_transfer_ifsc',
453
-            'name' => __( 'IFSC Code', 'invoicing' ),
454
-            'desc' => __( 'Enter your bank IFSC code.', 'invoicing' ),
455
-            'std'  =>  __( 'ICIC0001234', 'invoicing' ),
453
+            'name' => __('IFSC Code', 'invoicing'),
454
+            'desc' => __('Enter your bank IFSC code.', 'invoicing'),
455
+            'std'  =>  __('ICIC0001234', 'invoicing'),
456 456
         );
457 457
         
458 458
     $setting['bank_transfer_iban'] = array(
459 459
             'type' => 'text',
460 460
             'id'   => 'bank_transfer_iban',
461
-            'name' => __( 'IBAN', 'invoicing' ),
462
-            'desc' => __( 'Enter your International Bank Account Number(IBAN).', 'invoicing' ),
463
-            'std'  =>  __( 'GB29NWBK60161331926819', 'invoicing' ),
461
+            'name' => __('IBAN', 'invoicing'),
462
+            'desc' => __('Enter your International Bank Account Number(IBAN).', 'invoicing'),
463
+            'std'  =>  __('GB29NWBK60161331926819', 'invoicing'),
464 464
         );
465 465
         
466 466
     $setting['bank_transfer_bic'] = array(
467 467
             'type' => 'text',
468 468
             'id'   => 'bank_transfer_bic',
469
-            'name' => __( 'BIC/Swift Code', 'invoicing' ),
470
-            'std'  =>  __( 'ICICGB2L129', 'invoicing' ),
469
+            'name' => __('BIC/Swift Code', 'invoicing'),
470
+            'std'  =>  __('ICICGB2L129', 'invoicing'),
471 471
         );
472 472
 
473 473
     $setting['bank_transfer_sort_code'] = array(
474 474
         'type' => 'text',
475 475
         'id'   => 'bank_transfer_sort_code',
476
-        'name' => __( 'Sort Code', 'invoicing' ),
477
-        'std'  =>  __( '12-34-56', 'invoicing' ),
476
+        'name' => __('Sort Code', 'invoicing'),
477
+        'std'  =>  __('12-34-56', 'invoicing'),
478 478
     );
479 479
         
480 480
     $setting['bank_transfer_info'] = array(
481 481
             'id'   => 'bank_transfer_info',
482
-            'name' => __( 'Instructions', 'invoicing' ),
483
-            'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ),
482
+            'name' => __('Instructions', 'invoicing'),
483
+            'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'),
484 484
             'type' => 'textarea',
485
-            'std' => __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' ),
485
+            'std' => __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing'),
486 486
             'cols' => 37,
487 487
             'rows' => 5
488 488
         );
489 489
         
490 490
     return $setting;
491 491
 }
492
-add_filter( 'wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1 );
492
+add_filter('wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1);
493 493
 
494 494
 // Authorize.Net settings
495
-function wpinv_gateway_settings_authorizenet( $setting ) {
496
-    $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing' );
497
-    $setting['authorizenet_desc']['std'] = __( 'Pay using a Authorize.Net to process Credit card / Debit card transactions.', 'invoicing' );
495
+function wpinv_gateway_settings_authorizenet($setting) {
496
+    $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __('( Supported Currencies: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing');
497
+    $setting['authorizenet_desc']['std'] = __('Pay using a Authorize.Net to process Credit card / Debit card transactions.', 'invoicing');
498 498
     
499 499
     $setting['authorizenet_sandbox'] = array(
500 500
             'type' => 'checkbox',
501 501
             'id'   => 'authorizenet_sandbox',
502
-            'name' => __( 'Authorize.Net Test Mode', 'invoicing' ),
503
-            'desc' => __( 'Enable Authorize.Net test mode to test payments.', 'invoicing' ),
502
+            'name' => __('Authorize.Net Test Mode', 'invoicing'),
503
+            'desc' => __('Enable Authorize.Net test mode to test payments.', 'invoicing'),
504 504
             'std'  => 1
505 505
         );
506 506
         
507 507
     $setting['authorizenet_login_id'] = array(
508 508
             'type' => 'text',
509 509
             'id'   => 'authorizenet_login_id',
510
-            'name' => __( 'API Login ID', 'invoicing' ),
511
-            'desc' => __( 'API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing' ),
510
+            'name' => __('API Login ID', 'invoicing'),
511
+            'desc' => __('API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing'),
512 512
             'std' => '2j4rBekUnD',
513 513
         );
514 514
     
515 515
     $setting['authorizenet_transaction_key'] = array(
516 516
             'type' => 'text',
517 517
             'id'   => 'authorizenet_transaction_key',
518
-            'name' => __( 'Transaction Key', 'invoicing' ),
519
-            'desc' => __( 'Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing' ),
518
+            'name' => __('Transaction Key', 'invoicing'),
519
+            'desc' => __('Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing'),
520 520
             'std' => '4vyBUOJgR74679xa',
521 521
         );
522 522
         
523 523
     $setting['authorizenet_md5_hash'] = array(
524 524
             'type' => 'text',
525 525
             'id'   => 'authorizenet_md5_hash',
526
-            'name' => __( 'MD5-Hash', 'invoicing' ),
527
-            'desc' => __( 'The MD5 Hash security feature allows to authenticate transaction responses from the Authorize.Net for recurring payments. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing' ),
526
+            'name' => __('MD5-Hash', 'invoicing'),
527
+            'desc' => __('The MD5 Hash security feature allows to authenticate transaction responses from the Authorize.Net for recurring payments. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing'),
528 528
             'std' => '',
529 529
         );
530 530
 
531 531
     $setting['authorizenet_transaction_type'] = array(
532 532
         'id'          => 'authorizenet_transaction_type',
533
-        'name'        => __( 'Transaction Type', 'invoicing' ),
534
-        'desc'        => __( 'Choose transaction type.', 'invoicing' ),
533
+        'name'        => __('Transaction Type', 'invoicing'),
534
+        'desc'        => __('Choose transaction type.', 'invoicing'),
535 535
         'type'        => 'select',
536 536
         'class'       => 'wpi_select2',
537 537
         'options'     => array(
538
-            'authorize_capture' => __( 'Authorize And Capture', 'invoicing' ),
539
-            'authorize_only' => __( 'Authorize Only', 'invoicing' ),
538
+            'authorize_capture' => __('Authorize And Capture', 'invoicing'),
539
+            'authorize_only' => __('Authorize Only', 'invoicing'),
540 540
         ),
541 541
         'std'         => 'authorize_capture'
542 542
     );
543 543
 
544 544
     $setting['authorizenet_transaction_type_recurring'] = array(
545 545
         'id'          => 'authorizenet_transaction_type_recurring',
546
-        'name'        => __( 'Transaction Type for Recurring', 'invoicing' ),
547
-        'desc'        => __( 'Choose transaction type for recurring payments.', 'invoicing' ),
546
+        'name'        => __('Transaction Type for Recurring', 'invoicing'),
547
+        'desc'        => __('Choose transaction type for recurring payments.', 'invoicing'),
548 548
         'type'        => 'select',
549 549
         'class'       => 'wpi_select2',
550 550
         'options'     => array(
551
-            'authorize_capture' => __( 'Authorize And Capture', 'invoicing' ),
552
-            'authorize_only' => __( 'Authorize Only', 'invoicing' ),
551
+            'authorize_capture' => __('Authorize And Capture', 'invoicing'),
552
+            'authorize_only' => __('Authorize Only', 'invoicing'),
553 553
         ),
554 554
         'std'         => 'authorize_only'
555 555
     );
@@ -557,9 +557,9 @@  discard block
 block discarded – undo
557 557
     $setting['authorizenet_ipn_url'] = array(
558 558
             'type' => 'ipn_url',
559 559
             'id'   => 'authorizenet_ipn_url',
560
-            'name' => __( 'Silent Post URL', 'invoicing' ),
561
-            'std' => wpinv_get_ipn_url( 'authorizenet' ),
562
-            'desc' => __( 'If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing' ),
560
+            'name' => __('Silent Post URL', 'invoicing'),
561
+            'std' => wpinv_get_ipn_url('authorizenet'),
562
+            'desc' => __('If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing'),
563 563
             'size' => 'large',
564 564
             'custom' => 'authorizenet',
565 565
             'readonly' => true
@@ -567,26 +567,26 @@  discard block
 block discarded – undo
567 567
         
568 568
     return $setting;
569 569
 }
570
-add_filter( 'wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1 );
570
+add_filter('wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1);
571 571
 
572 572
 // Worldpay settings
573
-function wpinv_gateway_settings_worldpay( $setting ) {
574
-    $setting['worldpay_active']['desc'] = $setting['worldpay_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, ARS, CAD, CHF, DKK, EUR, HKD, MYR, GBP, NZD, NOK, SGD, LKR, SEK, TRY, USD, ZAR )', 'invoicing' );
575
-    $setting['worldpay_desc']['std'] = __( 'Pay using a Worldpay account to process Credit card / Debit card transactions.', 'invoicing' );
573
+function wpinv_gateway_settings_worldpay($setting) {
574
+    $setting['worldpay_active']['desc'] = $setting['worldpay_active']['desc'] . ' ' . __('( Supported Currencies: AUD, ARS, CAD, CHF, DKK, EUR, HKD, MYR, GBP, NZD, NOK, SGD, LKR, SEK, TRY, USD, ZAR )', 'invoicing');
575
+    $setting['worldpay_desc']['std'] = __('Pay using a Worldpay account to process Credit card / Debit card transactions.', 'invoicing');
576 576
     
577 577
     $setting['worldpay_sandbox'] = array(
578 578
             'type' => 'checkbox',
579 579
             'id'   => 'worldpay_sandbox',
580
-            'name' => __( 'Worldpay Test Mode', 'invoicing' ),
581
-            'desc' => __( 'This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing' ),
580
+            'name' => __('Worldpay Test Mode', 'invoicing'),
581
+            'desc' => __('This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing'),
582 582
             'std'  => 1
583 583
         );
584 584
         
585 585
     $setting['worldpay_instId'] = array(
586 586
             'type' => 'text',
587 587
             'id'   => 'worldpay_instId',
588
-            'name' => __( 'Installation Id', 'invoicing' ),
589
-            'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ),
588
+            'name' => __('Installation Id', 'invoicing'),
589
+            'desc' => __('Your installation id. Ex: 211616', 'invoicing'),
590 590
             'std' => '211616',
591 591
         );
592 592
     /*
@@ -602,9 +602,9 @@  discard block
 block discarded – undo
602 602
     $setting['worldpay_ipn_url'] = array(
603 603
             'type' => 'ipn_url',
604 604
             'id'   => 'worldpay_ipn_url',
605
-            'name' => __( 'Worldpay Callback Url', 'invoicing' ),
606
-            'std' => wpinv_get_ipn_url( 'worldpay' ),
607
-            'desc' => wp_sprintf( __( 'Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing' ), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url( 'worldpay' ) . '</font>', '<font style="color:#000;font-style:normal">&lt;wpdisplay item=MC_callback&gt;</font>' ),
605
+            'name' => __('Worldpay Callback Url', 'invoicing'),
606
+            'std' => wpinv_get_ipn_url('worldpay'),
607
+            'desc' => wp_sprintf(__('Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing'), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url('worldpay') . '</font>', '<font style="color:#000;font-style:normal">&lt;wpdisplay item=MC_callback&gt;</font>'),
608 608
             'size' => 'large',
609 609
             'custom' => 'worldpay',
610 610
             'readonly' => true
@@ -612,99 +612,99 @@  discard block
 block discarded – undo
612 612
         
613 613
     return $setting;
614 614
 }
615
-add_filter( 'wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1 );
615
+add_filter('wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1);
616 616
 
617
-function wpinv_ipn_url_callback( $args ) {    
618
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
617
+function wpinv_ipn_url_callback($args) {    
618
+    $sanitize_id = wpinv_sanitize_key($args['id']);
619 619
     
620 620
     $attrs = $args['readonly'] ? ' readonly' : '';
621 621
 
622
-    $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr( $args['std'] ) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">';
623
-    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">'  . $args['desc'] . '</label>';
622
+    $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr($args['std']) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">';
623
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>';
624 624
 
625 625
     echo $html;
626 626
 }
627 627
 
628
-function wpinv_is_test_mode( $gateway = '' ) {
629
-    if ( empty( $gateway ) ) {
628
+function wpinv_is_test_mode($gateway = '') {
629
+    if (empty($gateway)) {
630 630
         return false;
631 631
     }
632 632
     
633
-    $is_test_mode = wpinv_get_option( $gateway . '_sandbox', false );
633
+    $is_test_mode = wpinv_get_option($gateway . '_sandbox', false);
634 634
     
635
-    return apply_filters( 'wpinv_is_test_mode', $is_test_mode, $gateway );
635
+    return apply_filters('wpinv_is_test_mode', $is_test_mode, $gateway);
636 636
 }
637 637
 
638
-function wpinv_get_ipn_url( $gateway = '', $args = array() ) {
639
-    $data = array( 'wpi-listener' => 'IPN' );
638
+function wpinv_get_ipn_url($gateway = '', $args = array()) {
639
+    $data = array('wpi-listener' => 'IPN');
640 640
     
641
-    if ( !empty( $gateway ) ) {
642
-        $data['wpi-gateway'] = wpinv_sanitize_key( $gateway );
641
+    if (!empty($gateway)) {
642
+        $data['wpi-gateway'] = wpinv_sanitize_key($gateway);
643 643
     }
644 644
     
645
-    $args = !empty( $args ) && is_array( $args ) ? array_merge( $data, $args ) : $data;
645
+    $args = !empty($args) && is_array($args) ? array_merge($data, $args) : $data;
646 646
     
647
-    $ipn_url = add_query_arg( $args,  home_url( 'index.php' ) );
647
+    $ipn_url = add_query_arg($args, home_url('index.php'));
648 648
     
649
-    return apply_filters( 'wpinv_ipn_url', $ipn_url );
649
+    return apply_filters('wpinv_ipn_url', $ipn_url);
650 650
 }
651 651
 
652 652
 function wpinv_listen_for_payment_ipn() {
653 653
     // Regular PayPal IPN
654
-    if ( isset( $_GET['wpi-listener'] ) && $_GET['wpi-listener'] == 'IPN' ) {
655
-        do_action( 'wpinv_verify_payment_ipn' );
654
+    if (isset($_GET['wpi-listener']) && $_GET['wpi-listener'] == 'IPN') {
655
+        do_action('wpinv_verify_payment_ipn');
656 656
         
657
-        if ( !empty( $_GET['wpi-gateway'] ) ) {
658
-            wpinv_error_log( sanitize_text_field( $_GET['wpi-gateway'] ), 'WP Invoicing IPN', __FILE__, __LINE__ );
659
-            do_action( 'wpinv_verify_' . sanitize_text_field( $_GET['wpi-gateway'] ) . '_ipn' );
657
+        if (!empty($_GET['wpi-gateway'])) {
658
+            wpinv_error_log(sanitize_text_field($_GET['wpi-gateway']), 'WP Invoicing IPN', __FILE__, __LINE__);
659
+            do_action('wpinv_verify_' . sanitize_text_field($_GET['wpi-gateway']) . '_ipn');
660 660
         }
661 661
     }
662 662
 }
663
-add_action( 'init', 'wpinv_listen_for_payment_ipn' );
663
+add_action('init', 'wpinv_listen_for_payment_ipn');
664 664
 
665 665
 function wpinv_get_bank_instructions() {
666
-    $bank_instructions = wpinv_get_option( 'bank_transfer_info' );
666
+    $bank_instructions = wpinv_get_option('bank_transfer_info');
667 667
     
668
-    return apply_filters( 'wpinv_bank_instructions', $bank_instructions );
668
+    return apply_filters('wpinv_bank_instructions', $bank_instructions);
669 669
 }
670 670
 
671
-function wpinv_get_bank_info( $filtered = false ) {
671
+function wpinv_get_bank_info($filtered = false) {
672 672
     $bank_fields = array(
673
-        'bank_transfer_ac_name'     => __( 'Account Name', 'invoicing' ),
674
-        'bank_transfer_ac_no'       => __( 'Account Number', 'invoicing' ),
675
-        'bank_transfer_bank_name'   => __( 'Bank Name', 'invoicing' ),
676
-        'bank_transfer_ifsc'        => __( 'IFSC code', 'invoicing' ),
677
-        'bank_transfer_iban'        => __( 'IBAN', 'invoicing' ),
678
-        'bank_transfer_bic'         => __( 'BIC/Swift code', 'invoicing' ),
679
-        'bank_transfer_sort_code'   => __( 'Sort Code', 'invoicing' )
673
+        'bank_transfer_ac_name'     => __('Account Name', 'invoicing'),
674
+        'bank_transfer_ac_no'       => __('Account Number', 'invoicing'),
675
+        'bank_transfer_bank_name'   => __('Bank Name', 'invoicing'),
676
+        'bank_transfer_ifsc'        => __('IFSC code', 'invoicing'),
677
+        'bank_transfer_iban'        => __('IBAN', 'invoicing'),
678
+        'bank_transfer_bic'         => __('BIC/Swift code', 'invoicing'),
679
+        'bank_transfer_sort_code'   => __('Sort Code', 'invoicing')
680 680
     );
681 681
     
682 682
     $bank_info = array();
683
-    foreach ( $bank_fields as $field => $label ) {
684
-        if ( $filtered && !( $value = wpinv_get_option( $field ) ) ) {
683
+    foreach ($bank_fields as $field => $label) {
684
+        if ($filtered && !($value = wpinv_get_option($field))) {
685 685
             continue;
686 686
         }
687 687
         
688
-        $bank_info[$field] = array( 'label' => $label, 'value' => $value );
688
+        $bank_info[$field] = array('label' => $label, 'value' => $value);
689 689
     }
690 690
     
691
-    return apply_filters( 'wpinv_bank_info', $bank_info, $filtered );
691
+    return apply_filters('wpinv_bank_info', $bank_info, $filtered);
692 692
 }
693 693
 
694
-function wpinv_get_post_data( $method = 'request' ) {
694
+function wpinv_get_post_data($method = 'request') {
695 695
     $data       = array();
696 696
     $request    = $_REQUEST;
697 697
     
698
-    if ( $method == 'post' ) {
699
-        if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
698
+    if ($method == 'post') {
699
+        if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
700 700
             return $data;
701 701
         }
702 702
         
703 703
         $request = $_POST;
704 704
     }
705 705
     
706
-    if ( $method == 'get' ) {
707
-        if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'GET' ) {
706
+    if ($method == 'get') {
707
+        if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'GET') {
708 708
             return $data;
709 709
         }
710 710
         
@@ -715,11 +715,11 @@  discard block
 block discarded – undo
715 715
     $post_data = '';
716 716
     
717 717
     // Fallback just in case post_max_size is lower than needed
718
-    if ( ini_get( 'allow_url_fopen' ) ) {
719
-        $post_data = file_get_contents( 'php://input' );
718
+    if (ini_get('allow_url_fopen')) {
719
+        $post_data = file_get_contents('php://input');
720 720
     } else {
721 721
         // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
722
-        ini_set( 'post_max_size', '12M' );
722
+        ini_set('post_max_size', '12M');
723 723
     }
724 724
     // Start the encoded data collection with notification command
725 725
     $encoded_data = 'cmd=_notify-validate';
@@ -728,33 +728,33 @@  discard block
 block discarded – undo
728 728
     $arg_separator = wpinv_get_php_arg_separator_output();
729 729
 
730 730
     // Verify there is a post_data
731
-    if ( $post_data || strlen( $post_data ) > 0 ) {
731
+    if ($post_data || strlen($post_data) > 0) {
732 732
         // Append the data
733 733
         $encoded_data .= $arg_separator . $post_data;
734 734
     } else {
735 735
         // Check if POST is empty
736
-        if ( empty( $request ) ) {
736
+        if (empty($request)) {
737 737
             // Nothing to do
738 738
             return;
739 739
         } else {
740 740
             // Loop through each POST
741
-            foreach ( $request as $key => $value ) {
741
+            foreach ($request as $key => $value) {
742 742
                 // Encode the value and append the data
743
-                $encoded_data .= $arg_separator . "$key=" . urlencode( $value );
743
+                $encoded_data .= $arg_separator . "$key=" . urlencode($value);
744 744
             }
745 745
         }
746 746
     }
747 747
 
748 748
     // Convert collected post data to an array
749
-    wp_parse_str( $encoded_data, $data );
749
+    wp_parse_str($encoded_data, $data);
750 750
 
751
-    foreach ( $data as $key => $value ) {
752
-        if ( false !== strpos( $key, 'amp;' ) ) {
753
-            $new_key = str_replace( '&amp;', '&', $key );
754
-            $new_key = str_replace( 'amp;', '&' , $new_key );
751
+    foreach ($data as $key => $value) {
752
+        if (false !== strpos($key, 'amp;')) {
753
+            $new_key = str_replace('&amp;', '&', $key);
754
+            $new_key = str_replace('amp;', '&', $new_key);
755 755
 
756
-            unset( $data[ $key ] );
757
-            $data[ $new_key ] = sanitize_text_field( $value );
756
+            unset($data[$key]);
757
+            $data[$new_key] = sanitize_text_field($value);
758 758
         }
759 759
     }
760 760
     
@@ -764,12 +764,12 @@  discard block
 block discarded – undo
764 764
 /**
765 765
  * Checks if a given gateway supports subscription payments.
766 766
  */
767
-function wpinv_gateway_support_subscription( $gateway ) {
767
+function wpinv_gateway_support_subscription($gateway) {
768 768
     $supports = false;
769 769
 
770
-    if ( wpinv_is_gateway_active( $gateway ) ) {
771
-        $supports = apply_filters( 'wpinv_' . $gateway . '_support_subscription', $supports );
772
-        $supports = apply_filters( 'getapid_gateway_supports_subscription', $supports, $gateway );
770
+    if (wpinv_is_gateway_active($gateway)) {
771
+        $supports = apply_filters('wpinv_' . $gateway . '_support_subscription', $supports);
772
+        $supports = apply_filters('getapid_gateway_supports_subscription', $supports, $gateway);
773 773
     }
774 774
 
775 775
     return $supports;
@@ -781,14 +781,14 @@  discard block
 block discarded – undo
781 781
  * @param array $gateways an array of gateways.
782 782
  * @param GetPaid_Payment_Form $form payment form.
783 783
  */
784
-function wpinv_payment_gateways_on_cart( $gateways, $form ) {
784
+function wpinv_payment_gateways_on_cart($gateways, $form) {
785 785
 
786
-    if ( $form->is_recurring() ) {
786
+    if ($form->is_recurring()) {
787 787
 
788
-        foreach ( array_keys( $gateways ) as $gateway ) {
788
+        foreach (array_keys($gateways) as $gateway) {
789 789
 
790
-            if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
791
-                unset( $gateways[$gateway] );
790
+            if (!wpinv_gateway_support_subscription($gateway)) {
791
+                unset($gateways[$gateway]);
792 792
             }
793 793
 
794 794
         }
@@ -797,4 +797,4 @@  discard block
 block discarded – undo
797 797
 
798 798
     return $gateways;
799 799
 }
800
-add_filter( 'getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2 );
801 800
\ No newline at end of file
801
+add_filter('getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2);
802 802
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-getpaid-payment-form.php 1 patch
Spacing   +129 added lines, -129 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
 	}
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
 	 * @param  string $context View or edit context.
121 121
 	 * @return string
122 122
 	 */
123
-	public function get_version( $context = 'view' ) {
124
-		return $this->get_prop( 'version', $context );
123
+	public function get_version($context = 'view') {
124
+		return $this->get_prop('version', $context);
125 125
     }
126 126
 
127 127
     /**
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 	 * @param  string $context View or edit context.
132 132
 	 * @return string
133 133
 	 */
134
-	public function get_date_created( $context = 'view' ) {
135
-		return $this->get_prop( 'date_created', $context );
134
+	public function get_date_created($context = 'view') {
135
+		return $this->get_prop('date_created', $context);
136 136
     }
137 137
 
138 138
     /**
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
 	 * @param  string $context View or edit context.
143 143
 	 * @return string
144 144
 	 */
145
-	public function get_date_created_gmt( $context = 'view' ) {
146
-        $date = $this->get_date_created( $context );
145
+	public function get_date_created_gmt($context = 'view') {
146
+        $date = $this->get_date_created($context);
147 147
 
148
-        if ( $date ) {
149
-            $date = get_gmt_from_date( $date );
148
+        if ($date) {
149
+            $date = get_gmt_from_date($date);
150 150
         }
151 151
 		return $date;
152 152
     }
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
 	 * @param  string $context View or edit context.
159 159
 	 * @return string
160 160
 	 */
161
-	public function get_date_modified( $context = 'view' ) {
162
-		return $this->get_prop( 'date_modified', $context );
161
+	public function get_date_modified($context = 'view') {
162
+		return $this->get_prop('date_modified', $context);
163 163
     }
164 164
 
165 165
     /**
@@ -169,11 +169,11 @@  discard block
 block discarded – undo
169 169
 	 * @param  string $context View or edit context.
170 170
 	 * @return string
171 171
 	 */
172
-	public function get_date_modified_gmt( $context = 'view' ) {
173
-        $date = $this->get_date_modified( $context );
172
+	public function get_date_modified_gmt($context = 'view') {
173
+        $date = $this->get_date_modified($context);
174 174
 
175
-        if ( $date ) {
176
-            $date = get_gmt_from_date( $date );
175
+        if ($date) {
176
+            $date = get_gmt_from_date($date);
177 177
         }
178 178
 		return $date;
179 179
     }
@@ -185,8 +185,8 @@  discard block
 block discarded – undo
185 185
 	 * @param  string $context View or edit context.
186 186
 	 * @return string
187 187
 	 */
188
-	public function get_name( $context = 'view' ) {
189
-		return $this->get_prop( 'name', $context );
188
+	public function get_name($context = 'view') {
189
+		return $this->get_prop('name', $context);
190 190
     }
191 191
 
192 192
     /**
@@ -196,8 +196,8 @@  discard block
 block discarded – undo
196 196
 	 * @param  string $context View or edit context.
197 197
 	 * @return string
198 198
 	 */
199
-	public function get_title( $context = 'view' ) {
200
-		return $this->get_name( $context );
199
+	public function get_title($context = 'view') {
200
+		return $this->get_name($context);
201 201
 	}
202 202
 
203 203
     /**
@@ -207,8 +207,8 @@  discard block
 block discarded – undo
207 207
 	 * @param  string $context View or edit context.
208 208
 	 * @return int
209 209
 	 */
210
-	public function get_author( $context = 'view' ) {
211
-		return (int) $this->get_prop( 'author', $context );
210
+	public function get_author($context = 'view') {
211
+		return (int) $this->get_prop('author', $context);
212 212
     }
213 213
 
214 214
     /**
@@ -218,21 +218,21 @@  discard block
 block discarded – undo
218 218
 	 * @param  string $context View or edit context.
219 219
 	 * @return array
220 220
 	 */
221
-	public function get_elements( $context = 'view' ) {
222
-		$elements = $this->get_prop( 'elements', $context );
221
+	public function get_elements($context = 'view') {
222
+		$elements = $this->get_prop('elements', $context);
223 223
 
224
-		if ( empty( $elements ) || ! is_array( $elements ) ) {
225
-            return wpinv_get_data( 'sample-payment-form' );
224
+		if (empty($elements) || !is_array($elements)) {
225
+            return wpinv_get_data('sample-payment-form');
226 226
 		}
227 227
 
228 228
 		// Ensure that all required elements exist.
229 229
 		$_elements = array();
230
-		foreach ( $elements as $element ) {
230
+		foreach ($elements as $element) {
231 231
 
232
-			if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
232
+			if ($element['type'] == 'pay_button' && !$this->has_element_type('gateway_select')) {
233 233
 
234 234
 				$_elements[] = array(
235
-					'text'        => __( 'Select Payment Method', 'invoicing' ),
235
+					'text'        => __('Select Payment Method', 'invoicing'),
236 236
 					'id'          => 'gtscicd',
237 237
 					'name'        => 'gtscicd',
238 238
 					'type'        => 'gateway_select',
@@ -257,21 +257,21 @@  discard block
 block discarded – undo
257 257
 	 * @param  string $return objects or arrays.
258 258
 	 * @return GetPaid_Form_Item[]
259 259
 	 */
260
-	public function get_items( $context = 'view', $return = 'objects' ) {
261
-		$items = $this->get_prop( 'items', $context );
260
+	public function get_items($context = 'view', $return = 'objects') {
261
+		$items = $this->get_prop('items', $context);
262 262
 
263
-		if ( empty( $items ) || ! is_array( $items ) ) {
264
-            $items = wpinv_get_data( 'sample-payment-form-items' );
263
+		if (empty($items) || !is_array($items)) {
264
+            $items = wpinv_get_data('sample-payment-form-items');
265 265
 		}
266 266
 
267 267
 		// Convert the items.
268 268
 		$prepared = array();
269 269
 
270
-		foreach ( $items as $key => $value ) {
270
+		foreach ($items as $key => $value) {
271 271
 
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,44 +280,44 @@  discard block
 block discarded – undo
280 280
 			}
281 281
 
282 282
 			// $item_id => $quantity
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() ) {
287
-					$item->set_quantity( $value );
286
+				if ($item->can_purchase()) {
287
+					$item->set_quantity($value);
288 288
 					$prepared[] = $item;
289 289
 				}
290 290
 
291 291
 				continue;
292 292
 			}
293 293
 
294
-			if ( is_array( $value ) && isset( $value['id'] ) ) {
294
+			if (is_array($value) && isset($value['id'])) {
295 295
 
296
-				$item = new GetPaid_Form_Item( $value['id'] );
296
+				$item = new GetPaid_Form_Item($value['id']);
297 297
 
298
-				if ( ! $item->can_purchase() ) {
298
+				if (!$item->can_purchase()) {
299 299
 					continue;
300 300
 				}
301 301
 
302 302
 				// Sub-total (Cart items).
303
-				if ( isset( $value['subtotal'] ) ) {
304
-					$item->set_price( $value['subtotal'] );
303
+				if (isset($value['subtotal'])) {
304
+					$item->set_price($value['subtotal']);
305 305
 				}
306 306
 
307
-				if ( isset( $value['quantity'] ) ) {
308
-					$item->set_quantity( $value['quantity'] );
307
+				if (isset($value['quantity'])) {
308
+					$item->set_quantity($value['quantity']);
309 309
 				}
310 310
 
311
-				if ( isset( $value['allow_quantities'] ) ) {
312
-					$item->set_allow_quantities( $value['allow_quantities'] );
311
+				if (isset($value['allow_quantities'])) {
312
+					$item->set_allow_quantities($value['allow_quantities']);
313 313
 				}
314 314
 
315
-				if ( isset( $value['required'] ) ) {
316
-					$item->set_is_required( $value['required'] );
315
+				if (isset($value['required'])) {
316
+					$item->set_is_required($value['required']);
317 317
 				}
318 318
 
319
-				if ( isset( $value['description'] ) ) {
320
-					$item->set_custom_description( $value['description'] );
319
+				if (isset($value['description'])) {
320
+					$item->set_custom_description($value['description']);
321 321
 				}
322 322
 
323 323
 				$prepared[] = $item;
@@ -326,12 +326,12 @@  discard block
 block discarded – undo
326 326
 			}
327 327
 		}
328 328
 
329
-		if ( 'objects' == $return && 'view' == $context ) {
329
+		if ('objects' == $return && 'view' == $context) {
330 330
 			return $prepared;
331 331
 		}
332 332
 
333 333
 		$items = array();
334
-		foreach ( $prepared as $item ) {
334
+		foreach ($prepared as $item) {
335 335
 			$items[] = $item->prepare_data_for_use();
336 336
 		}
337 337
 
@@ -345,14 +345,14 @@  discard block
 block discarded – undo
345 345
 	 * @param  int $item_id The item id to return.
346 346
 	 * @return GetPaid_Form_Item|bool
347 347
 	 */
348
-	public function get_item( $item_id ) {
348
+	public function get_item($item_id) {
349 349
 
350
-		if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
350
+		if (empty($item_id) || !is_numeric($item_id)) {
351 351
 			return false;
352 352
 		}
353 353
 
354
-		foreach( $this->get_items() as $item ) {
355
-			if ( $item->get_id() == (int) $item_id ) {
354
+		foreach ($this->get_items() as $item) {
355
+			if ($item->get_id() == (int) $item_id) {
356 356
 				return $item;
357 357
 			}
358 358
 		}
@@ -368,15 +368,15 @@  discard block
 block discarded – undo
368 368
 	 * @param  string $element_type The element type to return.
369 369
 	 * @return array|bool
370 370
 	 */
371
-	public function get_element_type( $element_type ) {
371
+	public function get_element_type($element_type) {
372 372
 
373
-		if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
373
+		if (empty($element_type) || !is_scalar($element_type)) {
374 374
 			return false;
375 375
 		}
376 376
 
377
-		foreach ( $this->get_prop( 'elements' ) as $element ) {
377
+		foreach ($this->get_prop('elements') as $element) {
378 378
 
379
-			if ( $element['type'] == $element_type ) {
379
+			if ($element['type'] == $element_type) {
380 380
 				return $element;
381 381
 			}
382 382
 
@@ -393,8 +393,8 @@  discard block
 block discarded – undo
393 393
 	 * @param  string $context View or edit context.
394 394
 	 * @return array
395 395
 	 */
396
-	public function get_earned( $context = 'view' ) {
397
-		return $this->get_prop( 'earned', $context );
396
+	public function get_earned($context = 'view') {
397
+		return $this->get_prop('earned', $context);
398 398
 	}
399 399
 
400 400
 	/**
@@ -404,8 +404,8 @@  discard block
 block discarded – undo
404 404
 	 * @param  string $context View or edit context.
405 405
 	 * @return array
406 406
 	 */
407
-	public function get_refunded( $context = 'view' ) {
408
-		return $this->get_prop( 'refunded', $context );
407
+	public function get_refunded($context = 'view') {
408
+		return $this->get_prop('refunded', $context);
409 409
 	}
410 410
 
411 411
 	/**
@@ -415,8 +415,8 @@  discard block
 block discarded – undo
415 415
 	 * @param  string $context View or edit context.
416 416
 	 * @return array
417 417
 	 */
418
-	public function get_cancelled( $context = 'view' ) {
419
-		return $this->get_prop( 'cancelled', $context );
418
+	public function get_cancelled($context = 'view') {
419
+		return $this->get_prop('cancelled', $context);
420 420
 	}
421 421
 
422 422
 	/**
@@ -426,8 +426,8 @@  discard block
 block discarded – undo
426 426
 	 * @param  string $context View or edit context.
427 427
 	 * @return array
428 428
 	 */
429
-	public function get_failed( $context = 'view' ) {
430
-		return $this->get_prop( 'failed', $context );
429
+	public function get_failed($context = 'view') {
430
+		return $this->get_prop('failed', $context);
431 431
 	}
432 432
 
433 433
     /*
@@ -445,8 +445,8 @@  discard block
 block discarded – undo
445 445
 	 *
446 446
 	 * @since 1.0.19
447 447
 	 */
448
-	public function set_version( $value ) {
449
-		$this->set_prop( 'version', $value );
448
+	public function set_version($value) {
449
+		$this->set_prop('version', $value);
450 450
     }
451 451
 
452 452
     /**
@@ -456,11 +456,11 @@  discard block
 block discarded – undo
456 456
 	 * @param string $value Value to set.
457 457
      * @return bool Whether or not the date was set.
458 458
 	 */
459
-	public function set_date_created( $value ) {
460
-        $date = strtotime( $value );
459
+	public function set_date_created($value) {
460
+        $date = strtotime($value);
461 461
 
462
-        if ( $date ) {
463
-            $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) );
462
+        if ($date) {
463
+            $this->set_prop('date_created', date('Y-m-d H:i:s', $date));
464 464
             return true;
465 465
         }
466 466
 
@@ -475,11 +475,11 @@  discard block
 block discarded – undo
475 475
 	 * @param string $value Value to set.
476 476
      * @return bool Whether or not the date was set.
477 477
 	 */
478
-	public function set_date_modified( $value ) {
479
-        $date = strtotime( $value );
478
+	public function set_date_modified($value) {
479
+        $date = strtotime($value);
480 480
 
481
-        if ( $date ) {
482
-            $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) );
481
+        if ($date) {
482
+            $this->set_prop('date_modified', date('Y-m-d H:i:s', $date));
483 483
             return true;
484 484
         }
485 485
 
@@ -493,8 +493,8 @@  discard block
 block discarded – undo
493 493
 	 * @since 1.0.19
494 494
 	 * @param  string $value New name.
495 495
 	 */
496
-	public function set_name( $value ) {
497
-		$this->set_prop( 'name', sanitize_text_field( $value ) );
496
+	public function set_name($value) {
497
+		$this->set_prop('name', sanitize_text_field($value));
498 498
     }
499 499
 
500 500
     /**
@@ -503,8 +503,8 @@  discard block
 block discarded – undo
503 503
 	 * @since 1.0.19
504 504
 	 * @param  string $value New name.
505 505
 	 */
506
-	public function set_title( $value ) {
507
-		$this->set_name( $value );
506
+	public function set_title($value) {
507
+		$this->set_name($value);
508 508
     }
509 509
 
510 510
     /**
@@ -513,8 +513,8 @@  discard block
 block discarded – undo
513 513
 	 * @since 1.0.19
514 514
 	 * @param  int $value New author.
515 515
 	 */
516
-	public function set_author( $value ) {
517
-		$this->set_prop( 'author', (int) $value );
516
+	public function set_author($value) {
517
+		$this->set_prop('author', (int) $value);
518 518
 	}
519 519
 
520 520
 	/**
@@ -523,9 +523,9 @@  discard block
 block discarded – undo
523 523
 	 * @since 1.0.19
524 524
 	 * @param  array $value Form elements.
525 525
 	 */
526
-	public function set_elements( $value ) {
527
-		if ( is_array( $value ) ) {
528
-			$this->set_prop( 'elements', $value );
526
+	public function set_elements($value) {
527
+		if (is_array($value)) {
528
+			$this->set_prop('elements', $value);
529 529
 		}
530 530
 	}
531 531
 
@@ -535,9 +535,9 @@  discard block
 block discarded – undo
535 535
 	 * @since 1.0.19
536 536
 	 * @param  array $value Form elements.
537 537
 	 */
538
-	public function set_items( $value ) {
539
-		if ( is_array( $value ) ) {
540
-			$this->set_prop( 'items', $value );
538
+	public function set_items($value) {
539
+		if (is_array($value)) {
540
+			$this->set_prop('items', $value);
541 541
 		}
542 542
 	}
543 543
 
@@ -548,8 +548,8 @@  discard block
 block discarded – undo
548 548
 	 * @param  float $value Amount earned.
549 549
 	 * @return array
550 550
 	 */
551
-	public function set_earned( $value ) {
552
-		return $this->set_prop( 'earned', (float) $value );
551
+	public function set_earned($value) {
552
+		return $this->set_prop('earned', (float) $value);
553 553
 	}
554 554
 
555 555
 	/**
@@ -559,8 +559,8 @@  discard block
 block discarded – undo
559 559
 	 * @param  float $value Amount refunded.
560 560
 	 * @return array
561 561
 	 */
562
-	public function set_refunded( $value ) {
563
-		return $this->set_prop( 'refunded', (float) $value );
562
+	public function set_refunded($value) {
563
+		return $this->set_prop('refunded', (float) $value);
564 564
 	}
565 565
 
566 566
 	/**
@@ -570,8 +570,8 @@  discard block
 block discarded – undo
570 570
 	 * @param  float $value Amount cancelled.
571 571
 	 * @return array
572 572
 	 */
573
-	public function set_cancelled( $value ) {
574
-		return $this->set_prop( 'cancelled', (float) $value );
573
+	public function set_cancelled($value) {
574
+		return $this->set_prop('cancelled', (float) $value);
575 575
 	}
576 576
 
577 577
 	/**
@@ -581,8 +581,8 @@  discard block
 block discarded – undo
581 581
 	 * @param  float $value Amount cancelled.
582 582
 	 * @return array
583 583
 	 */
584
-	public function set_failed( $value ) {
585
-		return $this->set_prop( 'failed', (float) $value );
584
+	public function set_failed($value) {
585
+		return $this->set_prop('failed', (float) $value);
586 586
 	}
587 587
 
588 588
     /**
@@ -591,11 +591,11 @@  discard block
 block discarded – undo
591 591
      * @deprecated
592 592
 	 * @return int item id
593 593
      */
594
-    public function create( $data = array() ) {
594
+    public function create($data = array()) {
595 595
 
596 596
 		// Set the properties.
597
-		if ( is_array( $data ) ) {
598
-			$this->set_props( $data );
597
+		if (is_array($data)) {
598
+			$this->set_props($data);
599 599
 		}
600 600
 
601 601
 		// Save the item.
@@ -609,8 +609,8 @@  discard block
 block discarded – undo
609 609
      * @deprecated
610 610
 	 * @return int item id
611 611
      */
612
-    public function update( $data = array() ) {
613
-        return $this->create( $data );
612
+    public function update($data = array()) {
613
+        return $this->create($data);
614 614
     }
615 615
 
616 616
     /*
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
 	 */
631 631
     public function is_default() {
632 632
         $is_default = $this->get_id() == wpinv_get_default_payment_form();
633
-        return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this );
633
+        return (bool) apply_filters('wpinv_is_default_payment_form', $is_default, $this->get_id(), $this);
634 634
 	}
635 635
 
636 636
     /**
@@ -642,11 +642,11 @@  discard block
 block discarded – undo
642 642
     public function is_active() {
643 643
         $is_active = 0 !== (int) $this->get_id();
644 644
 
645
-        if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) {
645
+        if ($is_active && !current_user_can('edit_post', $this->get_id()) && $this->get_status() != 'publish') {
646 646
             $is_active = false;
647 647
         }
648 648
 
649
-        return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this );
649
+        return (bool) apply_filters('wpinv_is_payment_form_active', $is_active, $this);
650 650
 	}
651 651
 
652 652
 	/**
@@ -655,8 +655,8 @@  discard block
 block discarded – undo
655 655
 	 * @since 1.0.19
656 656
 	 * @return bool
657 657
 	 */
658
-    public function has_item( $item_id ) {
659
-        return false !== $this->get_item( $item_id );
658
+    public function has_item($item_id) {
659
+        return false !== $this->get_item($item_id);
660 660
 	}
661 661
 
662 662
 	/**
@@ -665,8 +665,8 @@  discard block
 block discarded – undo
665 665
 	 * @since 1.0.19
666 666
 	 * @return bool
667 667
 	 */
668
-    public function has_element_type( $element_type ) {
669
-        return false !== $this->get_element_type( $element_type );
668
+    public function has_element_type($element_type) {
669
+        return false !== $this->get_element_type($element_type);
670 670
 	}
671 671
 
672 672
 	/**
@@ -677,13 +677,13 @@  discard block
 block discarded – undo
677 677
 	 */
678 678
     public function is_recurring() {
679 679
 
680
-		if ( ! empty( $this->invoice ) ) {
680
+		if (!empty($this->invoice)) {
681 681
 			return $this->invoice->is_recurring();
682 682
 		}
683 683
 
684
-		foreach ( $this->get_items() as $item ) {
684
+		foreach ($this->get_items() as $item) {
685 685
 
686
-			if ( $item->is_recurring() ) {
686
+			if ($item->is_recurring()) {
687 687
 				return true;
688 688
 			}
689 689
 
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
     public function get_html() {
701 701
 
702 702
 		// Return the HTML.
703
-		return wpinv_get_template_html( 'payment-forms/form.php', array( 'form' => $this ) );
703
+		return wpinv_get_template_html('payment-forms/form.php', array('form' => $this));
704 704
 
705 705
 	}
706 706
 
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 1 patch
Spacing   +291 added lines, -291 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
 
@@ -102,36 +102,36 @@  discard block
 block discarded – undo
102 102
             'payment_form_refresh_prices' => true,
103 103
         );
104 104
 
105
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
106
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
107
-            add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
105
+        foreach ($ajax_events as $ajax_event => $nopriv) {
106
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
107
+            add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
108 108
 
109
-            if ( $nopriv ) {
110
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
111
-                add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
112
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
109
+            if ($nopriv) {
110
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
111
+                add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
112
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
113 113
             }
114 114
         }
115 115
     }
116 116
     
117 117
     public static function add_note() {
118
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
118
+        check_ajax_referer('add-invoice-note', '_nonce');
119 119
 
120
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
120
+        if (!wpinv_current_user_can_manage_invoicing()) {
121 121
             die(-1);
122 122
         }
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 128
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
129 129
 
130
-        if ( $post_id > 0 ) {
131
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
130
+        if ($post_id > 0) {
131
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
132 132
 
133
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
134
-                wpinv_get_invoice_note_line_item( $note_id );
133
+            if ($note_id > 0 && !is_wp_error($note_id)) {
134
+                wpinv_get_invoice_note_line_item($note_id);
135 135
             }
136 136
         }
137 137
 
@@ -139,16 +139,16 @@  discard block
 block discarded – undo
139 139
     }
140 140
 
141 141
     public static function delete_note() {
142
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
142
+        check_ajax_referer('delete-invoice-note', '_nonce');
143 143
 
144
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
144
+        if (!wpinv_current_user_can_manage_invoicing()) {
145 145
             die(-1);
146 146
         }
147 147
 
148
-        $note_id = (int)$_POST['note_id'];
148
+        $note_id = (int) $_POST['note_id'];
149 149
 
150
-        if ( $note_id > 0 ) {
151
-            wp_delete_comment( $note_id, true );
150
+        if ($note_id > 0) {
151
+            wp_delete_comment($note_id, true);
152 152
         }
153 153
 
154 154
         die();
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
     }
162 162
     
163 163
     public static function checkout() {
164
-        if ( ! defined( 'WPINV_CHECKOUT' ) ) {
165
-            define( 'WPINV_CHECKOUT', true );
164
+        if (!defined('WPINV_CHECKOUT')) {
165
+            define('WPINV_CHECKOUT', true);
166 166
         }
167 167
 
168 168
         wpinv_process_checkout();
@@ -175,34 +175,34 @@  discard block
 block discarded – undo
175 175
     public static function get_billing_details() {
176 176
 
177 177
         // Verify nonce.
178
-        check_ajax_referer( 'wpinv-nonce' );
178
+        check_ajax_referer('wpinv-nonce');
179 179
 
180 180
         // Can the user manage the plugin?
181
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
181
+        if (!wpinv_current_user_can_manage_invoicing()) {
182 182
             die(-1);
183 183
         }
184 184
 
185 185
         // Do we have a user id?
186 186
         $user_id = $_GET['user_id'];
187 187
 
188
-        if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
188
+        if (empty($user_id) || !is_numeric($user_id)) {
189 189
             die(-1);
190 190
         }
191 191
 
192 192
         // Fetch the billing details.
193
-        $billing_details    = wpinv_get_user_address( $user_id );
194
-        $billing_details    = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id );
193
+        $billing_details    = wpinv_get_user_address($user_id);
194
+        $billing_details    = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id);
195 195
 
196 196
         // unset the user id and email.
197
-        $to_ignore = array( 'user_id', 'email' );
197
+        $to_ignore = array('user_id', 'email');
198 198
 
199
-        foreach ( $to_ignore as $key ) {
200
-            if ( isset( $billing_details[ $key ] ) ) {
201
-                unset( $billing_details[ $key ] );
199
+        foreach ($to_ignore as $key) {
200
+            if (isset($billing_details[$key])) {
201
+                unset($billing_details[$key]);
202 202
             }
203 203
         }
204 204
 
205
-        wp_send_json_success( $billing_details );
205
+        wp_send_json_success($billing_details);
206 206
 
207 207
     }
208 208
 
@@ -212,47 +212,47 @@  discard block
 block discarded – undo
212 212
     public static function check_new_user_email() {
213 213
 
214 214
         // Verify nonce.
215
-        check_ajax_referer( 'wpinv-nonce' );
215
+        check_ajax_referer('wpinv-nonce');
216 216
 
217 217
         // Can the user manage the plugin?
218
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
218
+        if (!wpinv_current_user_can_manage_invoicing()) {
219 219
             die(-1);
220 220
         }
221 221
 
222 222
         // We need an email address.
223
-        if ( empty( $_GET['email'] ) ) {
224
-            _e( "Provide the new user's email address", 'invoicing' );
223
+        if (empty($_GET['email'])) {
224
+            _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_text_field( $_GET['email'] );
230
-        if ( ! is_email( $email ) ) {
231
-            _e( 'Invalid email address', 'invoicing' );
229
+        $email = sanitize_text_field($_GET['email']);
230
+        if (!is_email($email)) {
231
+            _e('Invalid email address', 'invoicing');
232 232
             exit;
233 233
         }
234 234
 
235 235
         // And it does not exist.
236
-        if ( email_exists( $email ) ) {
237
-            _e( 'A user with this email address already exists', 'invoicing' );
236
+        if (email_exists($email)) {
237
+            _e('A user with this email address already exists', 'invoicing');
238 238
             exit;
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' );
246
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
245
+        check_ajax_referer('wpinv-nonce', '_nonce');
246
+        if (!wpinv_current_user_can_manage_invoicing()) {
247 247
             die(-1);
248 248
         }
249 249
         
250
-        $tool = sanitize_text_field( $_POST['tool'] );
250
+        $tool = sanitize_text_field($_POST['tool']);
251 251
         
252
-        do_action( 'wpinv_run_tool' );
252
+        do_action('wpinv_run_tool');
253 253
         
254
-        if ( !empty( $tool ) ) {
255
-            do_action( 'wpinv_tool_' . $tool );
254
+        if (!empty($tool)) {
255
+            do_action('wpinv_tool_' . $tool);
256 256
         }
257 257
     }
258 258
 
@@ -262,30 +262,30 @@  discard block
 block discarded – undo
262 262
     public static function get_payment_form() {
263 263
 
264 264
         // Check nonce.
265
-        if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'], 'getpaid_ajax_form' ) ) {
266
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
265
+        if (!isset($_GET['nonce']) || !wp_verify_nonce($_GET['nonce'], 'getpaid_ajax_form')) {
266
+            _e('Error: Reload the page and try again.', 'invoicing');
267 267
             exit;
268 268
         }
269 269
 
270 270
         // Is the request set up correctly?
271
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
271
+		if (empty($_GET['form']) && empty($_GET['item'])) {
272 272
 			echo aui()->alert(
273 273
 				array(
274 274
 					'type'    => 'warning',
275
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
275
+					'content' => __('No payment form or item provided', 'invoicing'),
276 276
 				)
277 277
             );
278 278
             exit;
279 279
         }
280 280
 
281 281
         // Payment form or button?
282
-		if ( ! empty( $_GET['form'] ) ) {
283
-            echo getpaid_display_payment_form( $_GET['form'] );
284
-		} else if( $_GET['invoice'] ) {
285
-		    echo getpaid_display_invoice_payment_form( $_GET['invoice'] );
282
+		if (!empty($_GET['form'])) {
283
+            echo getpaid_display_payment_form($_GET['form']);
284
+		} else if ($_GET['invoice']) {
285
+		    echo getpaid_display_invoice_payment_form($_GET['invoice']);
286 286
         } else {
287
-			$items = getpaid_convert_items_to_array( $_GET['item'] );
288
-		    echo getpaid_display_item_payment_form( $items );
287
+			$items = getpaid_convert_items_to_array($_GET['item']);
288
+		    echo getpaid_display_item_payment_form($items);
289 289
         }
290 290
         
291 291
         exit;
@@ -301,11 +301,11 @@  discard block
 block discarded – undo
301 301
         global $invoicing, $wpi_checkout_id, $cart_total;
302 302
 
303 303
         // Check nonce.
304
-        check_ajax_referer( 'getpaid_form_nonce' );
304
+        check_ajax_referer('getpaid_form_nonce');
305 305
 
306 306
         // ... form fields...
307
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
308
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
307
+        if (empty($_POST['getpaid_payment_form_submission'])) {
308
+            _e('Error: Reload the page and try again.', 'invoicing');
309 309
             exit;
310 310
         }
311 311
 
@@ -313,25 +313,25 @@  discard block
 block discarded – undo
313 313
         $submission = new GetPaid_Payment_Form_Submission();
314 314
 
315 315
         // Do we have an error?
316
-        if ( ! empty( $submission->last_error ) ) {
316
+        if (!empty($submission->last_error)) {
317 317
             echo $submission->last_error;
318 318
             exit;
319 319
         }
320 320
 
321 321
         // We need a billing email.
322
-        if ( ! $submission->has_billing_email() || ! is_email( $submission->get_billing_email() ) ) {
323
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
322
+        if (!$submission->has_billing_email() || !is_email($submission->get_billing_email())) {
323
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
324 324
         }
325 325
 
326 326
         // Prepare items.
327 327
         $items            = $submission->get_items();
328 328
         $prepared_items   = array();
329 329
 
330
-        if ( ! empty( $items ) ) {
330
+        if (!empty($items)) {
331 331
 
332
-            foreach( $items as $item_id => $item ) {
332
+            foreach ($items as $item_id => $item) {
333 333
 
334
-                if ( $item->can_purchase() ) {
334
+                if ($item->can_purchase()) {
335 335
                     $prepared_items[] = array(
336 336
                         'id'           => $item_id,
337 337
                         'item_price'   => $item->get_price(),
@@ -345,90 +345,90 @@  discard block
 block discarded – undo
345 345
 
346 346
         }
347 347
 
348
-        if ( empty( $prepared_items ) ) {
349
-            wp_send_json_error( __( 'You have not selected any items.', 'invoicing' ) );
348
+        if (empty($prepared_items)) {
349
+            wp_send_json_error(__('You have not selected any items.', 'invoicing'));
350 350
         }
351 351
 
352
-        if ( $submission->has_recurring && 1 != count( $prepared_items ) ) {
353
-            wp_send_json_error( __( 'Recurring items should be bought individually.', 'invoicing' ) );
352
+        if ($submission->has_recurring && 1 != count($prepared_items)) {
353
+            wp_send_json_error(__('Recurring items should be bought individually.', 'invoicing'));
354 354
         }
355 355
 
356 356
         // Prepare the submission details.
357 357
         $prepared = array(
358
-            'billing_email'                    => sanitize_email( $submission->get_billing_email() ),
359
-            __( 'Billing Email', 'invoicing' ) => sanitize_email( $submission->get_billing_email() ),
360
-            __( 'Form Id', 'invoicing' )       => absint( $submission->payment_form->get_id() ),
358
+            'billing_email'                    => sanitize_email($submission->get_billing_email()),
359
+            __('Billing Email', 'invoicing') => sanitize_email($submission->get_billing_email()),
360
+            __('Form Id', 'invoicing')       => absint($submission->payment_form->get_id()),
361 361
         );
362 362
 
363 363
         // Address fields.
364 364
         $address_fields = array();
365 365
 
366 366
         // Add discount code.
367
-        if ( $submission->has_discount_code() ) {
368
-            $address_fields['discount'] = array( $submission->get_discount_code() );
367
+        if ($submission->has_discount_code()) {
368
+            $address_fields['discount'] = array($submission->get_discount_code());
369 369
         }
370 370
 
371 371
         // Are all required fields provided?
372 372
         $data = $submission->get_data();
373 373
 
374
-        foreach ( $submission->payment_form->get_elements() as $field ) {
374
+        foreach ($submission->payment_form->get_elements() as $field) {
375 375
 
376
-            if ( ! empty( $field['premade'] ) ) {
376
+            if (!empty($field['premade'])) {
377 377
                 continue;
378 378
             }
379 379
 
380
-            if ( ! $submission->is_required_field_set( $field ) ) {
381
-                wp_send_json_error( __( 'Fill all required fields.', 'invoicing' ) );
380
+            if (!$submission->is_required_field_set($field)) {
381
+                wp_send_json_error(__('Fill all required fields.', 'invoicing'));
382 382
             }
383 383
 
384
-            if ( $field['type'] == 'address' ) {
384
+            if ($field['type'] == 'address') {
385 385
 
386
-                foreach ( $field['fields'] as $address_field ) {
386
+                foreach ($field['fields'] as $address_field) {
387 387
 
388
-                    if ( empty( $address_field['visible'] ) ) {
388
+                    if (empty($address_field['visible'])) {
389 389
                         continue;
390 390
                     }
391 391
 
392
-                    if ( ! empty( $address_field['required'] ) && empty( $data[ $address_field['name'] ] ) ) {
393
-                        wp_send_json_error( __( 'Some required fields have not been filled.', 'invoicing' ) );
392
+                    if (!empty($address_field['required']) && empty($data[$address_field['name']])) {
393
+                        wp_send_json_error(__('Some required fields have not been filled.', 'invoicing'));
394 394
                     }
395 395
 
396
-                    if ( isset( $data[ $address_field['name'] ] ) ) {
397
-                        $label = str_replace( 'wpinv_', '', $address_field['name'] );
398
-                        $address_fields[ $label ] = wpinv_clean( $data[ $address_field['name'] ] );
396
+                    if (isset($data[$address_field['name']])) {
397
+                        $label = str_replace('wpinv_', '', $address_field['name']);
398
+                        $address_fields[$label] = wpinv_clean($data[$address_field['name']]);
399 399
                     }
400 400
 
401 401
                 }
402 402
 
403
-            } else if ( isset( $data[ $field['id'] ] ) ) {
403
+            } else if (isset($data[$field['id']])) {
404 404
                 $label = $field['id'];
405 405
 
406
-                if ( isset( $field['label'] ) ) {
406
+                if (isset($field['label'])) {
407 407
                     $label = $field['label'];
408 408
                 }
409 409
 
410
-                $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] );
410
+                $prepared[wpinv_clean($label)] = wpinv_clean($data[$field['id']]);
411 411
             }
412 412
 
413 413
         }
414 414
 
415 415
         // (Maybe) create the user.
416
-        $user = get_user_by( 'email', $prepared['billing_email'] );
416
+        $user = get_user_by('email', $prepared['billing_email']);
417 417
 
418
-        if ( empty( $user ) ) {
419
-            $user = wpinv_create_user( $prepared['billing_email'] );
418
+        if (empty($user)) {
419
+            $user = wpinv_create_user($prepared['billing_email']);
420 420
         }
421 421
 
422
-        if ( is_wp_error( $user ) ) {
423
-            wp_send_json_error( $user->get_error_message() );
422
+        if (is_wp_error($user)) {
423
+            wp_send_json_error($user->get_error_message());
424 424
         }
425 425
 
426
-        if ( is_numeric( $user ) ) {
427
-            $user = get_user_by( 'id', $user );
426
+        if (is_numeric($user)) {
427
+            $user = get_user_by('id', $user);
428 428
         }
429 429
 
430 430
         // Create the invoice.
431
-        if ( ! $submission->has_invoice() ) {
431
+        if (!$submission->has_invoice()) {
432 432
 
433 433
             $invoice = wpinv_insert_invoice(
434 434
                 array(
@@ -445,8 +445,8 @@  discard block
 block discarded – undo
445 445
 
446 446
             $invoice = $submission->get_invoice();
447 447
 
448
-            if ( $invoice->is_paid() ) {
449
-                wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
448
+            if ($invoice->is_paid()) {
449
+                wp_send_json_error(__('This invoice has already been paid for.', 'invoicing'));
450 450
             }
451 451
 
452 452
             $invoice = wpinv_update_invoice(
@@ -461,34 +461,34 @@  discard block
 block discarded – undo
461 461
 
462 462
         }
463 463
 
464
-        if ( is_wp_error( $invoice ) ) {
465
-            wp_send_json_error( $invoice->get_error_message() );
464
+        if (is_wp_error($invoice)) {
465
+            wp_send_json_error($invoice->get_error_message());
466 466
         }
467 467
 
468
-        if ( empty( $invoice ) ) {
469
-            wp_send_json_error( __( 'Could not create your invoice.', 'invoicing' ) );
468
+        if (empty($invoice)) {
469
+            wp_send_json_error(__('Could not create your invoice.', 'invoicing'));
470 470
         }
471 471
 
472
-        unset( $prepared['billing_email'] );
473
-        update_post_meta( $invoice->ID, 'payment_form_data', $prepared );
472
+        unset($prepared['billing_email']);
473
+        update_post_meta($invoice->ID, 'payment_form_data', $prepared);
474 474
 
475 475
         $wpi_checkout_id = $invoice->ID;
476 476
         $cart_total = wpinv_price(
477 477
             wpinv_format_amount(
478
-                wpinv_get_cart_total( $invoice->get_cart_details(), NULL, $invoice ) ),
478
+                wpinv_get_cart_total($invoice->get_cart_details(), NULL, $invoice) ),
479 479
                 $invoice->get_currency()
480 480
         );
481 481
 
482 482
         $data                   = array();
483 483
         $data['invoice_id']     = $invoice->ID;
484
-        $data['cart_discounts'] = $invoice->get_discounts( true );
484
+        $data['cart_discounts'] = $invoice->get_discounts(true);
485 485
 
486
-        wpinv_set_checkout_session( $data );
487
-        add_filter( 'wp_redirect', array( $invoicing->form_elements, 'send_redirect_response' ) );
488
-        add_action( 'wpinv_pre_send_back_to_checkout', array( $invoicing->form_elements, 'checkout_error' ) );
486
+        wpinv_set_checkout_session($data);
487
+        add_filter('wp_redirect', array($invoicing->form_elements, 'send_redirect_response'));
488
+        add_action('wpinv_pre_send_back_to_checkout', array($invoicing->form_elements, 'checkout_error'));
489 489
         
490
-        if ( ! defined( 'WPINV_CHECKOUT' ) ) {
491
-            define( 'WPINV_CHECKOUT', true );
490
+        if (!defined('WPINV_CHECKOUT')) {
491
+            define('WPINV_CHECKOUT', true);
492 492
         }
493 493
 
494 494
         wpinv_process_checkout();
@@ -506,51 +506,51 @@  discard block
 block discarded – undo
506 506
     public static function get_payment_form_states_field() {
507 507
         global $invoicing;
508 508
 
509
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
509
+        if (empty($_GET['country']) || empty($_GET['form'])) {
510 510
             exit;
511 511
         }
512 512
 
513
-        $elements = $invoicing->form_elements->get_form_elements( $_GET['form'] );
513
+        $elements = $invoicing->form_elements->get_form_elements($_GET['form']);
514 514
 
515
-        if ( empty( $elements ) ) {
515
+        if (empty($elements)) {
516 516
             exit;
517 517
         }
518 518
 
519 519
         $address_fields = array();
520
-        foreach ( $elements as $element ) {
521
-            if ( 'address' === $element['type'] ) {
520
+        foreach ($elements as $element) {
521
+            if ('address' === $element['type']) {
522 522
                 $address_fields = $element;
523 523
                 break;
524 524
             }
525 525
         }
526 526
 
527
-        if ( empty( $address_fields ) ) {
527
+        if (empty($address_fields)) {
528 528
             exit;
529 529
         }
530 530
 
531
-        foreach( $address_fields['fields'] as $address_field ) {
531
+        foreach ($address_fields['fields'] as $address_field) {
532 532
 
533
-            if ( 'wpinv_state' == $address_field['name'] ) {
533
+            if ('wpinv_state' == $address_field['name']) {
534 534
 
535 535
                 $label = $address_field['label'];
536 536
 
537
-                if ( ! empty( $address_field['required'] ) ) {
537
+                if (!empty($address_field['required'])) {
538 538
                     $label .= "<span class='text-danger'> *</span>";
539 539
                 }
540 540
 
541
-                $states = wpinv_get_country_states( $_GET['country'] );
541
+                $states = wpinv_get_country_states($_GET['country']);
542 542
 
543
-                if ( ! empty( $states ) ) {
543
+                if (!empty($states)) {
544 544
 
545 545
                     $html = aui()->select(
546 546
                             array(
547 547
                                 'options'          => $states,
548
-                                'name'             => esc_attr( $address_field['name'] ),
549
-                                'id'               => esc_attr( $address_field['name'] ),
550
-                                'placeholder'      => esc_attr( $address_field['placeholder'] ),
548
+                                'name'             => esc_attr($address_field['name']),
549
+                                'id'               => esc_attr($address_field['name']),
550
+                                'placeholder'      => esc_attr($address_field['placeholder']),
551 551
                                 'required'         => (bool) $address_field['required'],
552 552
                                 'no_wrap'          => true,
553
-                                'label'            => wp_kses_post( $label ),
553
+                                'label'            => wp_kses_post($label),
554 554
                                 'select2'          => false,
555 555
                             )
556 556
                         );
@@ -559,10 +559,10 @@  discard block
 block discarded – undo
559 559
 
560 560
                     $html = aui()->input(
561 561
                             array(
562
-                                'name'       => esc_attr( $address_field['name'] ),
563
-                                'id'         => esc_attr( $address_field['name'] ),
562
+                                'name'       => esc_attr($address_field['name']),
563
+                                'id'         => esc_attr($address_field['name']),
564 564
                                 'required'   => (bool) $address_field['required'],
565
-                                'label'      => wp_kses_post( $label ),
565
+                                'label'      => wp_kses_post($label),
566 566
                                 'no_wrap'    => true,
567 567
                                 'type'       => 'text',
568 568
                             )
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
 
571 571
                 }
572 572
 
573
-                wp_send_json_success( str_replace( 'sr-only', '', $html ) );
573
+                wp_send_json_success(str_replace('sr-only', '', $html));
574 574
                 exit;
575 575
 
576 576
             }
@@ -586,49 +586,49 @@  discard block
 block discarded – undo
586 586
     public static function recalculate_invoice_totals() {
587 587
 
588 588
         // Verify nonce.
589
-        check_ajax_referer( 'wpinv-nonce' );
589
+        check_ajax_referer('wpinv-nonce');
590 590
 
591
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
591
+        if (!wpinv_current_user_can_manage_invoicing()) {
592 592
             exit;
593 593
         }
594 594
 
595 595
         // We need an invoice.
596
-        if ( empty( $_POST['post_id'] ) ) {
596
+        if (empty($_POST['post_id'])) {
597 597
             exit;
598 598
         }
599 599
 
600 600
         // Fetch the invoice.
601
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
601
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
602 602
 
603 603
         // Ensure it exists.
604
-        if ( ! $invoice->get_id() ) {
604
+        if (!$invoice->get_id()) {
605 605
             exit;
606 606
         }
607 607
 
608 608
         // Maybe set the country, state, currency.
609
-        foreach ( array( 'country', 'state', 'currency' ) as $key ) {
610
-            if ( isset( $_POST[ $key ] ) ) {
609
+        foreach (array('country', 'state', 'currency') as $key) {
610
+            if (isset($_POST[$key])) {
611 611
                 $method = "set_$key";
612
-                $invoice->$method( $_POST[ $key ] );
612
+                $invoice->$method($_POST[$key]);
613 613
             }
614 614
         }
615 615
 
616 616
         // Maybe disable taxes.
617
-        $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) );
617
+        $invoice->set_disable_taxes(!empty($_POST['taxes']));
618 618
 
619 619
         // Recalculate totals.
620 620
         $invoice->recalculate_total();
621 621
 
622 622
         $totals = array(
623
-            'subtotal' => wpinv_price( wpinv_format_amount( $invoice->get_subtotal() ) ),
624
-            'discount' => wpinv_price( wpinv_format_amount( $invoice->get_total_discount() ) ),
625
-            'tax'      => wpinv_price( wpinv_format_amount( $invoice->get_total_tax() ) ),
626
-            'total'    => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ),
623
+            'subtotal' => wpinv_price(wpinv_format_amount($invoice->get_subtotal())),
624
+            'discount' => wpinv_price(wpinv_format_amount($invoice->get_total_discount())),
625
+            'tax'      => wpinv_price(wpinv_format_amount($invoice->get_total_tax())),
626
+            'total'    => wpinv_price(wpinv_format_amount($invoice->get_total())),
627 627
         );
628 628
 
629
-        $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice );
629
+        $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice);
630 630
 
631
-        wp_send_json_success( compact( 'totals' ) );
631
+        wp_send_json_success(compact('totals'));
632 632
     }
633 633
 
634 634
     /**
@@ -637,33 +637,33 @@  discard block
 block discarded – undo
637 637
     public static function get_invoice_items() {
638 638
 
639 639
         // Verify nonce.
640
-        check_ajax_referer( 'wpinv-nonce' );
640
+        check_ajax_referer('wpinv-nonce');
641 641
 
642
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
642
+        if (!wpinv_current_user_can_manage_invoicing()) {
643 643
             exit;
644 644
         }
645 645
 
646 646
         // We need an invoice and items.
647
-        if ( empty( $_POST['post_id'] ) ) {
647
+        if (empty($_POST['post_id'])) {
648 648
             exit;
649 649
         }
650 650
 
651 651
         // Fetch the invoice.
652
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
652
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
653 653
 
654 654
         // Ensure it exists.
655
-        if ( ! $invoice->get_id() ) {
655
+        if (!$invoice->get_id()) {
656 656
             exit;
657 657
         }
658 658
 
659 659
         // Return an array of invoice items.
660 660
         $items = array();
661 661
 
662
-        foreach ( $invoice->get_items() as $item_id => $item ) {
663
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax();
662
+        foreach ($invoice->get_items() as $item_id => $item) {
663
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax();
664 664
         }
665 665
 
666
-        wp_send_json_success( compact( 'items' ) );
666
+        wp_send_json_success(compact('items'));
667 667
     }
668 668
 
669 669
     /**
@@ -672,48 +672,48 @@  discard block
 block discarded – undo
672 672
     public static function edit_invoice_item() {
673 673
 
674 674
         // Verify nonce.
675
-        check_ajax_referer( 'wpinv-nonce' );
675
+        check_ajax_referer('wpinv-nonce');
676 676
 
677
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
677
+        if (!wpinv_current_user_can_manage_invoicing()) {
678 678
             exit;
679 679
         }
680 680
 
681 681
         // We need an invoice and item details.
682
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) {
682
+        if (empty($_POST['post_id']) || empty($_POST['data'])) {
683 683
             exit;
684 684
         }
685 685
 
686 686
         // Fetch the invoice.
687
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
687
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
688 688
 
689 689
         // Ensure it exists and its not been paid for.
690
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
690
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
691 691
             exit;
692 692
         }
693 693
 
694 694
         // Format the data.
695
-        $data = wp_list_pluck( $_POST['data'], 'value', 'field' );
695
+        $data = wp_list_pluck($_POST['data'], 'value', 'field');
696 696
 
697 697
         // Ensure that we have an item id.
698
-        if ( empty( $data['id'] ) ) {
698
+        if (empty($data['id'])) {
699 699
             exit;
700 700
         }
701 701
 
702 702
         // Abort if the invoice does not have the specified item.
703
-        $item = $invoice->get_item( (int) $data['id'] );
703
+        $item = $invoice->get_item((int) $data['id']);
704 704
 
705
-        if ( empty( $item ) ) {
705
+        if (empty($item)) {
706 706
             exit;
707 707
         }
708 708
 
709 709
         // Update the item.
710
-        $item->set_price( $data['price'] );
711
-        $item->set_name( $data['name'] );
712
-        $item->set_description( $data['description'] );
713
-        $item->set_quantity( $data['quantity'] );
710
+        $item->set_price($data['price']);
711
+        $item->set_name($data['name']);
712
+        $item->set_description($data['description']);
713
+        $item->set_quantity($data['quantity']);
714 714
 
715 715
         // Add it to the invoice.
716
-        $invoice->add_item( $item );
716
+        $invoice->add_item($item);
717 717
 
718 718
         // Update totals.
719 719
         $invoice->recalculate_total();
@@ -724,11 +724,11 @@  discard block
 block discarded – undo
724 724
         // Return an array of invoice items.
725 725
         $items = array();
726 726
 
727
-        foreach ( $invoice->get_items() as $item_id => $item ) {
728
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax();
727
+        foreach ($invoice->get_items() as $item_id => $item) {
728
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax();
729 729
         }
730 730
 
731
-        wp_send_json_success( compact( 'items' ) );
731
+        wp_send_json_success(compact('items'));
732 732
     }
733 733
     /**
734 734
      * Adds a items to an invoice.
@@ -736,38 +736,38 @@  discard block
 block discarded – undo
736 736
     public static function add_invoice_items() {
737 737
 
738 738
         // Verify nonce.
739
-        check_ajax_referer( 'wpinv-nonce' );
739
+        check_ajax_referer('wpinv-nonce');
740 740
 
741
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
741
+        if (!wpinv_current_user_can_manage_invoicing()) {
742 742
             exit;
743 743
         }
744 744
 
745 745
         // We need an invoice and items.
746
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) {
746
+        if (empty($_POST['post_id']) || empty($_POST['items'])) {
747 747
             exit;
748 748
         }
749 749
 
750 750
         // Fetch the invoice.
751
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
751
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
752 752
         $alert   = false;
753 753
 
754 754
         // Ensure it exists and its not been paid for.
755
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
755
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
756 756
             exit;
757 757
         }
758 758
 
759 759
         // Add the items.
760
-        foreach ( $_POST['items'] as $data ) {
760
+        foreach ($_POST['items'] as $data) {
761 761
 
762
-            $item = new GetPaid_Form_Item( $data[ 'id' ] );
762
+            $item = new GetPaid_Form_Item($data['id']);
763 763
 
764
-            if ( is_numeric( $data[ 'qty' ] ) && (int) $data[ 'qty' ] > 0 ) {
765
-                $item->set_quantity( $data[ 'qty' ] );
764
+            if (is_numeric($data['qty']) && (int) $data['qty'] > 0) {
765
+                $item->set_quantity($data['qty']);
766 766
             }
767 767
 
768
-            if ( $item->get_id() > 0 ) {
769
-                if ( ! $invoice->add_item( $item ) ) {
770
-                    $alert = __( 'An invoice can only contain one recurring item', 'invoicing' );
768
+            if ($item->get_id() > 0) {
769
+                if (!$invoice->add_item($item)) {
770
+                    $alert = __('An invoice can only contain one recurring item', 'invoicing');
771 771
                 }
772 772
             }
773 773
 
@@ -780,11 +780,11 @@  discard block
 block discarded – undo
780 780
         // Return an array of invoice items.
781 781
         $items = array();
782 782
 
783
-        foreach ( $invoice->get_items() as $item_id => $item ) {
784
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax();
783
+        foreach ($invoice->get_items() as $item_id => $item) {
784
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax();
785 785
         }
786 786
 
787
-        wp_send_json_success( compact( 'items', 'alert' ) );
787
+        wp_send_json_success(compact('items', 'alert'));
788 788
     }
789 789
 
790 790
     /**
@@ -793,15 +793,15 @@  discard block
 block discarded – undo
793 793
     public static function get_invoicing_items() {
794 794
 
795 795
         // Verify nonce.
796
-        check_ajax_referer( 'wpinv-nonce' );
796
+        check_ajax_referer('wpinv-nonce');
797 797
 
798
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
798
+        if (!wpinv_current_user_can_manage_invoicing()) {
799 799
             exit;
800 800
         }
801 801
 
802 802
         // We need a search term.
803
-        if ( empty( $_GET['search'] ) ) {
804
-            wp_send_json_success( array() );
803
+        if (empty($_GET['search'])) {
804
+            wp_send_json_success(array());
805 805
         }
806 806
 
807 807
         // Retrieve items.
@@ -810,8 +810,8 @@  discard block
 block discarded – undo
810 810
             'orderby'        => 'title',
811 811
             'order'          => 'ASC',
812 812
             'posts_per_page' => -1,
813
-            'post_status'    => array( 'publish' ),
814
-            's'              => trim( $_GET['search'] ),
813
+            'post_status'    => array('publish'),
814
+            's'              => trim($_GET['search']),
815 815
             'meta_query'     => array(
816 816
                 array(
817 817
                     'key'       => '_wpinv_type',
@@ -821,18 +821,18 @@  discard block
 block discarded – undo
821 821
             )
822 822
         );
823 823
 
824
-        $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) );
824
+        $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args));
825 825
         $data  = array();
826 826
 
827
-        foreach ( $items as $item ) {
828
-            $item      = new GetPaid_Form_Item( $item );
827
+        foreach ($items as $item) {
828
+            $item = new GetPaid_Form_Item($item);
829 829
             $data[] = array(
830 830
                 'id'   => $item->get_id(),
831 831
                 'text' => $item->get_name()
832 832
             );
833 833
         }
834 834
 
835
-        wp_send_json_success( $data );
835
+        wp_send_json_success($data);
836 836
 
837 837
     }
838 838
 
@@ -842,24 +842,24 @@  discard block
 block discarded – undo
842 842
     public static function get_aui_states_field() {
843 843
 
844 844
         // Verify nonce.
845
-        check_ajax_referer( 'wpinv-nonce' );
845
+        check_ajax_referer('wpinv-nonce');
846 846
 
847 847
         // We need a country.
848
-        if ( empty( $_GET['country'] ) ) {
848
+        if (empty($_GET['country'])) {
849 849
             exit;
850 850
         }
851 851
 
852
-        $states = wpinv_get_country_states( trim( $_GET['country'] ) );
853
-        $state  = isset( $_GET['state'] ) ? trim( $_GET['state'] ) : wpinv_get_default_state();
852
+        $states = wpinv_get_country_states(trim($_GET['country']));
853
+        $state  = isset($_GET['state']) ? trim($_GET['state']) : wpinv_get_default_state();
854 854
 
855
-        if ( empty( $states ) ) {
855
+        if (empty($states)) {
856 856
 
857 857
             $html = aui()->input(
858 858
                 array(
859 859
                     'type'        => 'text',
860 860
                     'id'          => 'wpinv_state',
861 861
                     'name'        => 'wpinv_state',
862
-                    'label'       => __( 'State', 'invoicing' ),
862
+                    'label'       => __('State', 'invoicing'),
863 863
                     'label_type'  => 'vertical',
864 864
                     'placeholder' => 'Liège',
865 865
                     'class'       => 'form-control-sm',
@@ -873,9 +873,9 @@  discard block
 block discarded – undo
873 873
                 array(
874 874
                     'id'          => 'wpinv_state',
875 875
                     'name'        => 'wpinv_state',
876
-                    'label'       => __( 'State', 'invoicing' ),
876
+                    'label'       => __('State', 'invoicing'),
877 877
                     'label_type'  => 'vertical',
878
-                    'placeholder' => __( 'Select a state', 'invoicing' ),
878
+                    'placeholder' => __('Select a state', 'invoicing'),
879 879
                     'class'       => 'form-control-sm',
880 880
                     'value'       => $state,
881 881
                     'options'     => $states,
@@ -889,7 +889,7 @@  discard block
 block discarded – undo
889 889
         wp_send_json_success(
890 890
             array(
891 891
                 'html'   => $html,
892
-                'select' => ! empty ( $states )
892
+                'select' => !empty ($states)
893 893
             )
894 894
         );
895 895
 
@@ -903,11 +903,11 @@  discard block
 block discarded – undo
903 903
     public static function payment_form_refresh_prices() {
904 904
 
905 905
         // Check nonce.
906
-        check_ajax_referer( 'getpaid_form_nonce' );
906
+        check_ajax_referer('getpaid_form_nonce');
907 907
 
908 908
         // ... form fields...
909
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
910
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
909
+        if (empty($_POST['getpaid_payment_form_submission'])) {
910
+            _e('Error: Reload the page and try again.', 'invoicing');
911 911
             exit;
912 912
         }
913 913
 
@@ -915,7 +915,7 @@  discard block
 block discarded – undo
915 915
         $submission = new GetPaid_Payment_Form_Submission();
916 916
 
917 917
         // Do we have an error?
918
-        if ( ! empty( $submission->last_error ) ) {
918
+        if (!empty($submission->last_error)) {
919 919
             echo $submission->last_error;
920 920
             exit;
921 921
         }
@@ -928,43 +928,43 @@  discard block
 block discarded – undo
928 928
             'is_free'       => $submission->get_payment_details(),
929 929
 
930 930
             'totals'        => array(
931
-                'subtotal'  => wpinv_price( wpinv_format_amount( $submission->subtotal_amount ), $submission->get_currency() ),
932
-                'discount'  => wpinv_price( wpinv_format_amount( $submission->get_total_discount() ), $submission->get_currency() ),
933
-                'fees'      => wpinv_price( wpinv_format_amount( $submission->get_total_fees() ), $submission->get_currency() ),
934
-                'tax'       => wpinv_price( wpinv_format_amount( $submission->get_total_tax() ), $submission->get_currency() ),
935
-                'total'     => wpinv_price( wpinv_format_amount( $submission->get_total() ), $submission->get_currency() ),
931
+                'subtotal'  => wpinv_price(wpinv_format_amount($submission->subtotal_amount), $submission->get_currency()),
932
+                'discount'  => wpinv_price(wpinv_format_amount($submission->get_total_discount()), $submission->get_currency()),
933
+                'fees'      => wpinv_price(wpinv_format_amount($submission->get_total_fees()), $submission->get_currency()),
934
+                'tax'       => wpinv_price(wpinv_format_amount($submission->get_total_tax()), $submission->get_currency()),
935
+                'total'     => wpinv_price(wpinv_format_amount($submission->get_total()), $submission->get_currency()),
936 936
             ),
937 937
 
938 938
             'texts'         => array(
939
-                '.getpaid-checkout-total-payable' => wpinv_price( wpinv_format_amount( $submission->get_total() ), $submission->get_currency() ),
939
+                '.getpaid-checkout-total-payable' => wpinv_price(wpinv_format_amount($submission->get_total()), $submission->get_currency()),
940 940
             )
941 941
 
942 942
         );
943 943
 
944 944
         // Add items.
945 945
         $items = $submission->get_items();
946
-        if ( ! empty( $items ) ) {
946
+        if (!empty($items)) {
947 947
             $result['items'] = array();
948 948
 
949
-            foreach( $items as $item_id => $item ) {
950
-                $result['items']["$item_id"] = wpinv_price( wpinv_format_amount( $item->get_price() * $item->get_quantity() ) );
949
+            foreach ($items as $item_id => $item) {
950
+                $result['items']["$item_id"] = wpinv_price(wpinv_format_amount($item->get_price() * $item->get_quantity()));
951 951
             }
952 952
         }
953 953
 
954 954
         // Add invoice.
955
-        if ( $submission->has_invoice() ) {
955
+        if ($submission->has_invoice()) {
956 956
             $result['invoice'] = $submission->get_invoice()->ID;
957 957
         }
958 958
 
959 959
         // Add discount code.
960
-        if ( $submission->has_discount_code() ) {
960
+        if ($submission->has_discount_code()) {
961 961
             $result['discount_code'] = $submission->get_discount_code();
962 962
         }
963 963
 
964 964
         // Filter the result.
965
-        $result = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $result, $submission );
965
+        $result = apply_filters('getpaid_payment_form_ajax_refresh_prices', $result, $submission);
966 966
 
967
-        wp_send_json_success( $result );
967
+        wp_send_json_success($result);
968 968
     }
969 969
 
970 970
     /**
@@ -975,53 +975,53 @@  discard block
 block discarded – undo
975 975
     public static function buy_items() {
976 976
         $user_id = get_current_user_id();
977 977
 
978
-        if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page
979
-            wp_send_json( array(
980
-                'success' => wp_login_url( wp_get_referer() )
981
-            ) );
978
+        if (empty($user_id)) { // If not logged in then lets redirect to the login page
979
+            wp_send_json(array(
980
+                'success' => wp_login_url(wp_get_referer())
981
+            ));
982 982
         } else {
983 983
             // Only check nonce if logged in as it could be cached when logged out.
984
-            if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) {
985
-                wp_send_json( array(
986
-                    'error' => __( 'Security checks failed.', 'invoicing' )
987
-                ) );
984
+            if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) {
985
+                wp_send_json(array(
986
+                    'error' => __('Security checks failed.', 'invoicing')
987
+                ));
988 988
                 wp_die();
989 989
             }
990 990
 
991 991
             // allow to set a custom price through post_id
992 992
             $items = $_POST['items'];
993
-            $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0;
994
-            $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0;
993
+            $related_post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0;
994
+            $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0;
995 995
 
996 996
             $cart_items = array();
997
-            if ( $items ) {
998
-                $items = explode( ',', $items );
997
+            if ($items) {
998
+                $items = explode(',', $items);
999 999
 
1000
-                foreach( $items as $item ) {
1000
+                foreach ($items as $item) {
1001 1001
                     $item_id = $item;
1002 1002
                     $quantity = 1;
1003 1003
 
1004
-                    if ( strpos( $item, '|' ) !== false ) {
1005
-                        $item_parts = explode( '|', $item );
1004
+                    if (strpos($item, '|') !== false) {
1005
+                        $item_parts = explode('|', $item);
1006 1006
                         $item_id = $item_parts[0];
1007 1007
                         $quantity = $item_parts[1];
1008 1008
                     }
1009 1009
 
1010
-                    if ( $item_id && $quantity ) {
1010
+                    if ($item_id && $quantity) {
1011 1011
                         $cart_items_arr = array(
1012
-                            'id'            => (int)$item_id,
1013
-                            'quantity'      => (int)$quantity
1012
+                            'id'            => (int) $item_id,
1013
+                            'quantity'      => (int) $quantity
1014 1014
                         );
1015 1015
 
1016 1016
                         // If there is a related post id then add it to meta
1017
-                        if ( $related_post_id ) {
1017
+                        if ($related_post_id) {
1018 1018
                             $cart_items_arr['meta'] = array(
1019 1019
                                 'post_id'   => $related_post_id
1020 1020
                             );
1021 1021
                         }
1022 1022
 
1023 1023
                         // If there is a custom price then set it.
1024
-                        if ( $custom_item_price ) {
1024
+                        if ($custom_item_price) {
1025 1025
                             $cart_items_arr['custom_price'] = $custom_item_price;
1026 1026
                         }
1027 1027
 
@@ -1037,37 +1037,37 @@  discard block
 block discarded – undo
1037 1037
              * @param int $related_post_id The related post id if any.
1038 1038
              * @since 1.0.0
1039 1039
              */
1040
-            $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id );
1040
+            $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id);
1041 1041
 
1042 1042
             // Make sure its not in the cart already, if it is then redirect to checkout.
1043 1043
             $cart_invoice = wpinv_get_invoice_cart();
1044 1044
 
1045
-            if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) {
1046
-                wp_send_json( array(
1045
+            if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) {
1046
+                wp_send_json(array(
1047 1047
                     'success' =>  $cart_invoice->get_checkout_payment_url()
1048
-                ) );
1048
+                ));
1049 1049
                 wp_die();
1050 1050
             }
1051 1051
 
1052 1052
             // Check if user has invoice with same items waiting to be paid.
1053
-            $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' );
1054
-            if ( !empty( $user_invoices ) ) {
1055
-                foreach( $user_invoices as $user_invoice ) {
1053
+            $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending');
1054
+            if (!empty($user_invoices)) {
1055
+                foreach ($user_invoices as $user_invoice) {
1056 1056
                     $user_cart_details = array();
1057
-                    $invoice  = wpinv_get_invoice( $user_invoice->ID );
1057
+                    $invoice = wpinv_get_invoice($user_invoice->ID);
1058 1058
                     $cart_details = $invoice->get_cart_details();
1059 1059
 
1060
-                    if ( !empty( $cart_details ) ) {
1061
-                        foreach ( $cart_details as $invoice_item ) {
1060
+                    if (!empty($cart_details)) {
1061
+                        foreach ($cart_details as $invoice_item) {
1062 1062
                             $ii_arr = array();
1063
-                            $ii_arr['id'] = (int)$invoice_item['id'];
1064
-                            $ii_arr['quantity'] = (int)$invoice_item['quantity'];
1063
+                            $ii_arr['id'] = (int) $invoice_item['id'];
1064
+                            $ii_arr['quantity'] = (int) $invoice_item['quantity'];
1065 1065
 
1066
-                            if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) {
1066
+                            if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) {
1067 1067
                                 $ii_arr['meta'] = $invoice_item['meta'];
1068 1068
                             }
1069 1069
 
1070
-                            if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) {
1070
+                            if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) {
1071 1071
                                 $ii_arr['custom_price'] = $invoice_item['custom_price'];
1072 1072
                             }
1073 1073
 
@@ -1075,17 +1075,17 @@  discard block
 block discarded – undo
1075 1075
                         }
1076 1076
                     }
1077 1077
 
1078
-                    if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) {
1079
-                        wp_send_json( array(
1078
+                    if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) {
1079
+                        wp_send_json(array(
1080 1080
                             'success' =>  $invoice->get_checkout_payment_url()
1081
-                        ) );
1081
+                        ));
1082 1082
                         wp_die();
1083 1083
                     }
1084 1084
                 }
1085 1085
             }
1086 1086
 
1087 1087
             // Create invoice and send user to checkout
1088
-            if ( !empty( $cart_items ) ) {
1088
+            if (!empty($cart_items)) {
1089 1089
                 $invoice_data = array(
1090 1090
                     'status'        =>  'wpi-pending',
1091 1091
                     'created_via'   =>  'wpi',
@@ -1093,21 +1093,21 @@  discard block
 block discarded – undo
1093 1093
                     'cart_details'  =>  $cart_items,
1094 1094
                 );
1095 1095
 
1096
-                $invoice = wpinv_insert_invoice( $invoice_data, true );
1096
+                $invoice = wpinv_insert_invoice($invoice_data, true);
1097 1097
 
1098
-                if ( !empty( $invoice ) && isset( $invoice->ID ) ) {
1099
-                    wp_send_json( array(
1098
+                if (!empty($invoice) && isset($invoice->ID)) {
1099
+                    wp_send_json(array(
1100 1100
                         'success' =>  $invoice->get_checkout_payment_url()
1101
-                    ) );
1101
+                    ));
1102 1102
                 } else {
1103
-                    wp_send_json( array(
1104
-                        'error' => __( 'Invoice failed to create', 'invoicing' )
1105
-                    ) );
1103
+                    wp_send_json(array(
1104
+                        'error' => __('Invoice failed to create', 'invoicing')
1105
+                    ));
1106 1106
                 }
1107 1107
             } else {
1108
-                wp_send_json( array(
1109
-                    'error' => __( 'Items not valid.', 'invoicing' )
1110
-                ) );
1108
+                wp_send_json(array(
1109
+                    'error' => __('Items not valid.', 'invoicing')
1110
+                ));
1111 1111
             }
1112 1112
         }
1113 1113
 
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 1 patch
Spacing   +746 added lines, -746 removed lines patch added patch discarded remove patch
@@ -4,99 +4,99 @@  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
  * Displays an invoice.
11 11
  * 
12 12
  * @param WPInv_Invoice $invoice.
13 13
  */
14
-function getpaid_invoice( $invoice ) {
15
-    if ( ! empty( $invoice ) ) {
16
-        wpinv_get_template( 'invoice/invoice.php', compact( 'invoice' ) );
14
+function getpaid_invoice($invoice) {
15
+    if (!empty($invoice)) {
16
+        wpinv_get_template('invoice/invoice.php', compact('invoice'));
17 17
     }
18 18
 }
19
-add_action( 'getpaid_invoice', 'getpaid_invoice', 10 );
19
+add_action('getpaid_invoice', 'getpaid_invoice', 10);
20 20
 
21 21
 /**
22 22
  * Displays the invoice footer.
23 23
  */
24
-function getpaid_invoice_footer( $invoice ) {
25
-    if ( ! empty( $invoice ) ) {
26
-        wpinv_get_template( 'invoice/footer.php', compact( 'invoice' ) );
24
+function getpaid_invoice_footer($invoice) {
25
+    if (!empty($invoice)) {
26
+        wpinv_get_template('invoice/footer.php', compact('invoice'));
27 27
     }
28 28
 }
29
-add_action( 'getpaid_invoice_footer', 'getpaid_invoice_footer', 10 );
29
+add_action('getpaid_invoice_footer', 'getpaid_invoice_footer', 10);
30 30
 
31 31
 /**
32 32
  * Displays the invoice top bar.
33 33
  */
34
-function getpaid_invoice_header( $invoice ) {
35
-    if ( ! empty( $invoice ) ) {
36
-        wpinv_get_template( 'invoice/header.php', compact( 'invoice' ) );
34
+function getpaid_invoice_header($invoice) {
35
+    if (!empty($invoice)) {
36
+        wpinv_get_template('invoice/header.php', compact('invoice'));
37 37
     }
38 38
 }
39
-add_action( 'getpaid_invoice_header', 'getpaid_invoice_header', 10 );
39
+add_action('getpaid_invoice_header', 'getpaid_invoice_header', 10);
40 40
 
41 41
 /**
42 42
  * Displays actions on the left side of the header.
43 43
  */
44
-function getpaid_invoice_header_left_actions( $invoice ) {
45
-    if ( ! empty( $invoice ) ) {
46
-        wpinv_get_template( 'invoice/header-left-actions.php', compact( 'invoice' ) );
44
+function getpaid_invoice_header_left_actions($invoice) {
45
+    if (!empty($invoice)) {
46
+        wpinv_get_template('invoice/header-left-actions.php', compact('invoice'));
47 47
     }
48 48
 }
49
-add_action( 'getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10 );
49
+add_action('getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10);
50 50
 
51 51
 /**
52 52
  * Displays actions on the right side of the invoice top bar.
53 53
  */
54
-function getpaid_invoice_header_right_actions( $invoice ) {
55
-    if ( ! empty( $invoice ) ) {
56
-        wpinv_get_template( 'invoice/header-right-actions.php', compact( 'invoice' ) );
54
+function getpaid_invoice_header_right_actions($invoice) {
55
+    if (!empty($invoice)) {
56
+        wpinv_get_template('invoice/header-right-actions.php', compact('invoice'));
57 57
     }
58 58
 }
59
-add_action( 'getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10 );
59
+add_action('getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10);
60 60
 
61 61
 /**
62 62
  * Displays the invoice title, watermark, logo etc.
63 63
  */
64
-function getpaid_invoice_details_top( $invoice ) {
65
-    if ( ! empty( $invoice ) ) {
66
-        wpinv_get_template( 'invoice/details-top.php', compact( 'invoice' ) );
64
+function getpaid_invoice_details_top($invoice) {
65
+    if (!empty($invoice)) {
66
+        wpinv_get_template('invoice/details-top.php', compact('invoice'));
67 67
     }
68 68
 }
69
-add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_top', 10 );
69
+add_action('getpaid_invoice_details', 'getpaid_invoice_details_top', 10);
70 70
 
71 71
 /**
72 72
  * Displays the company logo.
73 73
  */
74
-function getpaid_invoice_logo( $invoice ) {
75
-    if ( ! empty( $invoice ) ) {
76
-        wpinv_get_template( 'invoice/invoice-logo.php', compact( 'invoice' ) );
74
+function getpaid_invoice_logo($invoice) {
75
+    if (!empty($invoice)) {
76
+        wpinv_get_template('invoice/invoice-logo.php', compact('invoice'));
77 77
     }
78 78
 }
79
-add_action( 'getpaid_invoice_details_top_left', 'getpaid_invoice_logo' );
79
+add_action('getpaid_invoice_details_top_left', 'getpaid_invoice_logo');
80 80
 
81 81
 /**
82 82
  * Displays the type of invoice.
83 83
  */
84
-function getpaid_invoice_type( $invoice ) {
85
-    if ( ! empty( $invoice ) ) {
86
-        wpinv_get_template( 'invoice/invoice-type.php', compact( 'invoice' ) );
84
+function getpaid_invoice_type($invoice) {
85
+    if (!empty($invoice)) {
86
+        wpinv_get_template('invoice/invoice-type.php', compact('invoice'));
87 87
     }
88 88
 }
89
-add_action( 'getpaid_invoice_details_top_right', 'getpaid_invoice_type' );
89
+add_action('getpaid_invoice_details_top_right', 'getpaid_invoice_type');
90 90
 
91 91
 /**
92 92
  * Displays the invoice details.
93 93
  */
94
-function getpaid_invoice_details_main( $invoice ) {
95
-    if ( ! empty( $invoice ) ) {
96
-        wpinv_get_template( 'invoice/details.php', compact( 'invoice' ) );
94
+function getpaid_invoice_details_main($invoice) {
95
+    if (!empty($invoice)) {
96
+        wpinv_get_template('invoice/details.php', compact('invoice'));
97 97
     }
98 98
 }
99
-add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_main', 50 );
99
+add_action('getpaid_invoice_details', 'getpaid_invoice_details_main', 50);
100 100
 
101 101
 /**
102 102
  * Returns a path to the templates directory.
@@ -125,30 +125,30 @@  discard block
 block discarded – undo
125 125
  * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'.
126 126
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
127 127
  */
128
-function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
128
+function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
129 129
 
130 130
     // Make variables available to the template.
131
-    if ( ! empty( $args ) && is_array( $args ) ) {
132
-		extract( $args );
131
+    if (!empty($args) && is_array($args)) {
132
+		extract($args);
133 133
 	}
134 134
 
135 135
     // Locate the template.
136
-	$located = wpinv_locate_template( $template_name, $template_path, $default_path );
136
+	$located = wpinv_locate_template($template_name, $template_path, $default_path);
137 137
 
138 138
     // Abort if the file does not exist.
139
-	if ( ! file_exists( $located ) ) {
140
-        _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
139
+	if (!file_exists($located)) {
140
+        _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1');
141 141
 		return;
142 142
 	}
143 143
 
144 144
     // Fires before loading a template.
145
-	do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args );
145
+	do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args);
146 146
 
147 147
     // Load the template.
148
-	include( $located );
148
+	include($located);
149 149
 
150 150
     // Fires after loading a template.
151
-	do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args );
151
+	do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args);
152 152
 }
153 153
 
154 154
 /**
@@ -160,9 +160,9 @@  discard block
 block discarded – undo
160 160
  * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'.
161 161
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
162 162
  */
163
-function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
163
+function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') {
164 164
 	ob_start();
165
-	wpinv_get_template( $template_name, $args, $template_path, $default_path );
165
+	wpinv_get_template($template_name, $args, $template_path, $default_path);
166 166
 	return ob_get_clean();
167 167
 }
168 168
 
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
  * @return string
173 173
  */
174 174
 function wpinv_template_path() {
175
-    return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() );
175
+    return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name());
176 176
 }
177 177
 
178 178
 /**
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
  * @return string
182 182
  */
183 183
 function wpinv_get_theme_template_dir_name() {
184
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
184
+	return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing'));
185 185
 }
186 186
 
187 187
 /**
@@ -193,72 +193,72 @@  discard block
 block discarded – undo
193 193
  * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'.
194 194
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
195 195
  */
196
-function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
196
+function wpinv_locate_template($template_name, $template_path = '', $default_path = '') {
197 197
 
198 198
     // Load the defaults for the template path and default path.
199
-    $template_path = empty( $template_path ) ? wpinv_template_path() : $template_path;
200
-    $default_path  = empty( $default_path ) ? WPINV_PLUGIN_DIR . 'templates/' : $default_path;
199
+    $template_path = empty($template_path) ? wpinv_template_path() : $template_path;
200
+    $default_path  = empty($default_path) ? WPINV_PLUGIN_DIR . 'templates/' : $default_path;
201 201
 
202 202
     // Check if the template was overidden.
203 203
     $template = locate_template(
204
-        array( trailingslashit( $template_path ) . $template_name )
204
+        array(trailingslashit($template_path) . $template_name)
205 205
     );
206 206
 
207 207
     // Maybe replace it with a default path.
208
-    if ( empty( $template ) && ! empty( $default_path ) ) {
209
-        $template = trailingslashit( $default_path ) . $template_name;
208
+    if (empty($template) && !empty($default_path)) {
209
+        $template = trailingslashit($default_path) . $template_name;
210 210
     }
211 211
 
212 212
     // Return what we found.
213
-    return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path, $default_path );
213
+    return apply_filters('wpinv_locate_template', $template, $template_name, $template_path, $default_path);
214 214
 }
215 215
 
216
-function wpinv_get_template_part( $slug, $name = null, $load = true ) {
217
-	do_action( 'get_template_part_' . $slug, $slug, $name );
216
+function wpinv_get_template_part($slug, $name = null, $load = true) {
217
+	do_action('get_template_part_' . $slug, $slug, $name);
218 218
 
219 219
 	// Setup possible parts
220 220
 	$templates = array();
221
-	if ( isset( $name ) )
221
+	if (isset($name))
222 222
 		$templates[] = $slug . '-' . $name . '.php';
223 223
 	$templates[] = $slug . '.php';
224 224
 
225 225
 	// Allow template parts to be filtered
226
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
226
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
227 227
 
228 228
 	// Return the part that is found
229
-	return wpinv_locate_tmpl( $templates, $load, false );
229
+	return wpinv_locate_tmpl($templates, $load, false);
230 230
 }
231 231
 
232
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
232
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
233 233
 	// No file found yet
234 234
 	$located = false;
235 235
 
236 236
 	// Try to find a template file
237
-	foreach ( (array)$template_names as $template_name ) {
237
+	foreach ((array) $template_names as $template_name) {
238 238
 
239 239
 		// Continue if template is empty
240
-		if ( empty( $template_name ) )
240
+		if (empty($template_name))
241 241
 			continue;
242 242
 
243 243
 		// Trim off any slashes from the template name
244
-		$template_name = ltrim( $template_name, '/' );
244
+		$template_name = ltrim($template_name, '/');
245 245
 
246 246
 		// try locating this template file by looping through the template paths
247
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
247
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
248 248
 
249
-			if( file_exists( $template_path . $template_name ) ) {
249
+			if (file_exists($template_path . $template_name)) {
250 250
 				$located = $template_path . $template_name;
251 251
 				break;
252 252
 			}
253 253
 		}
254 254
 
255
-		if( !empty( $located ) ) {
255
+		if (!empty($located)) {
256 256
 			break;
257 257
 		}
258 258
 	}
259 259
 
260
-	if ( ( true == $load ) && ! empty( $located ) )
261
-		load_template( $located, $require_once );
260
+	if ((true == $load) && !empty($located))
261
+		load_template($located, $require_once);
262 262
 
263 263
 	return $located;
264 264
 }
@@ -267,155 +267,155 @@  discard block
 block discarded – undo
267 267
 	$template_dir = wpinv_get_theme_template_dir_name();
268 268
 
269 269
 	$file_paths = array(
270
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
271
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
270
+		1 => trailingslashit(get_stylesheet_directory()) . $template_dir,
271
+		10 => trailingslashit(get_template_directory()) . $template_dir,
272 272
 		100 => wpinv_get_templates_dir()
273 273
 	);
274 274
 
275
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
275
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
276 276
 
277 277
 	// sort the file paths based on priority
278
-	ksort( $file_paths, SORT_NUMERIC );
278
+	ksort($file_paths, SORT_NUMERIC);
279 279
 
280
-	return array_map( 'trailingslashit', $file_paths );
280
+	return array_map('trailingslashit', $file_paths);
281 281
 }
282 282
 
283 283
 function wpinv_checkout_meta_tags() {
284 284
 
285 285
 	$pages   = array();
286
-	$pages[] = wpinv_get_option( 'success_page' );
287
-	$pages[] = wpinv_get_option( 'failure_page' );
288
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
289
-	$pages[] = wpinv_get_option( 'invoice_subscription_page' );
286
+	$pages[] = wpinv_get_option('success_page');
287
+	$pages[] = wpinv_get_option('failure_page');
288
+	$pages[] = wpinv_get_option('invoice_history_page');
289
+	$pages[] = wpinv_get_option('invoice_subscription_page');
290 290
 
291
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
291
+	if (!wpinv_is_checkout() && !is_page($pages)) {
292 292
 		return;
293 293
 	}
294 294
 
295 295
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
296 296
 }
297
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
297
+add_action('wp_head', 'wpinv_checkout_meta_tags');
298 298
 
299
-function wpinv_add_body_classes( $class ) {
300
-	$classes = (array)$class;
299
+function wpinv_add_body_classes($class) {
300
+	$classes = (array) $class;
301 301
 
302
-	if( wpinv_is_checkout() ) {
302
+	if (wpinv_is_checkout()) {
303 303
 		$classes[] = 'wpinv-checkout';
304 304
 		$classes[] = 'wpinv-page';
305 305
 	}
306 306
 
307
-	if( wpinv_is_success_page() ) {
307
+	if (wpinv_is_success_page()) {
308 308
 		$classes[] = 'wpinv-success';
309 309
 		$classes[] = 'wpinv-page';
310 310
 	}
311 311
 
312
-	if( wpinv_is_failed_transaction_page() ) {
312
+	if (wpinv_is_failed_transaction_page()) {
313 313
 		$classes[] = 'wpinv-failed-transaction';
314 314
 		$classes[] = 'wpinv-page';
315 315
 	}
316 316
 
317
-	if( wpinv_is_invoice_history_page() ) {
317
+	if (wpinv_is_invoice_history_page()) {
318 318
 		$classes[] = 'wpinv-history';
319 319
 		$classes[] = 'wpinv-page';
320 320
 	}
321 321
 
322
-	if( wpinv_is_subscriptions_history_page() ) {
322
+	if (wpinv_is_subscriptions_history_page()) {
323 323
 		$classes[] = 'wpinv-subscription';
324 324
 		$classes[] = 'wpinv-page';
325 325
 	}
326 326
 
327
-	if( wpinv_is_test_mode() ) {
327
+	if (wpinv_is_test_mode()) {
328 328
 		$classes[] = 'wpinv-test-mode';
329 329
 		$classes[] = 'wpinv-page';
330 330
 	}
331 331
 
332
-	return array_unique( $classes );
332
+	return array_unique($classes);
333 333
 }
334
-add_filter( 'body_class', 'wpinv_add_body_classes' );
334
+add_filter('body_class', 'wpinv_add_body_classes');
335 335
 
336
-function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) {
337
-    $args = array( 'nopaging' => true );
336
+function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') {
337
+    $args = array('nopaging' => true);
338 338
 
339
-    if ( ! empty( $status ) )
339
+    if (!empty($status))
340 340
         $args['post_status'] = $status;
341 341
 
342
-    $discounts = wpinv_get_discounts( $args );
342
+    $discounts = wpinv_get_discounts($args);
343 343
     $options   = array();
344 344
 
345
-    if ( $discounts ) {
346
-        foreach ( $discounts as $discount ) {
347
-            $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) );
345
+    if ($discounts) {
346
+        foreach ($discounts as $discount) {
347
+            $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID));
348 348
         }
349 349
     } else {
350
-        $options[0] = __( 'No discounts found', 'invoicing' );
350
+        $options[0] = __('No discounts found', 'invoicing');
351 351
     }
352 352
 
353
-    $output = wpinv_html_select( array(
353
+    $output = wpinv_html_select(array(
354 354
         'name'             => $name,
355 355
         'selected'         => $selected,
356 356
         'options'          => $options,
357 357
         'show_option_all'  => false,
358 358
         'show_option_none' => false,
359
-    ) );
359
+    ));
360 360
 
361 361
     return $output;
362 362
 }
363 363
 
364
-function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
365
-    $current     = date( 'Y' );
366
-    $start_year  = $current - absint( $years_before );
367
-    $end_year    = $current + absint( $years_after );
368
-    $selected    = empty( $selected ) ? date( 'Y' ) : $selected;
364
+function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
365
+    $current     = date('Y');
366
+    $start_year  = $current - absint($years_before);
367
+    $end_year    = $current + absint($years_after);
368
+    $selected    = empty($selected) ? date('Y') : $selected;
369 369
     $options     = array();
370 370
 
371
-    while ( $start_year <= $end_year ) {
372
-        $options[ absint( $start_year ) ] = $start_year;
371
+    while ($start_year <= $end_year) {
372
+        $options[absint($start_year)] = $start_year;
373 373
         $start_year++;
374 374
     }
375 375
 
376
-    $output = wpinv_html_select( array(
376
+    $output = wpinv_html_select(array(
377 377
         'name'             => $name,
378 378
         'selected'         => $selected,
379 379
         'options'          => $options,
380 380
         'show_option_all'  => false,
381 381
         'show_option_none' => false
382
-    ) );
382
+    ));
383 383
 
384 384
     return $output;
385 385
 }
386 386
 
387
-function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) {
387
+function wpinv_html_month_dropdown($name = 'month', $selected = 0) {
388 388
 
389 389
     $options = array(
390
-        '1'  => __( 'January', 'invoicing' ),
391
-        '2'  => __( 'February', 'invoicing' ),
392
-        '3'  => __( 'March', 'invoicing' ),
393
-        '4'  => __( 'April', 'invoicing' ),
394
-        '5'  => __( 'May', 'invoicing' ),
395
-        '6'  => __( 'June', 'invoicing' ),
396
-        '7'  => __( 'July', 'invoicing' ),
397
-        '8'  => __( 'August', 'invoicing' ),
398
-        '9'  => __( 'September', 'invoicing' ),
399
-        '10' => __( 'October', 'invoicing' ),
400
-        '11' => __( 'November', 'invoicing' ),
401
-        '12' => __( 'December', 'invoicing' ),
390
+        '1'  => __('January', 'invoicing'),
391
+        '2'  => __('February', 'invoicing'),
392
+        '3'  => __('March', 'invoicing'),
393
+        '4'  => __('April', 'invoicing'),
394
+        '5'  => __('May', 'invoicing'),
395
+        '6'  => __('June', 'invoicing'),
396
+        '7'  => __('July', 'invoicing'),
397
+        '8'  => __('August', 'invoicing'),
398
+        '9'  => __('September', 'invoicing'),
399
+        '10' => __('October', 'invoicing'),
400
+        '11' => __('November', 'invoicing'),
401
+        '12' => __('December', 'invoicing'),
402 402
     );
403 403
 
404 404
     // If no month is selected, default to the current month
405
-    $selected = empty( $selected ) ? date( 'n' ) : $selected;
405
+    $selected = empty($selected) ? date('n') : $selected;
406 406
 
407
-    $output = wpinv_html_select( array(
407
+    $output = wpinv_html_select(array(
408 408
         'name'             => $name,
409 409
         'selected'         => $selected,
410 410
         'options'          => $options,
411 411
         'show_option_all'  => false,
412 412
         'show_option_none' => false
413
-    ) );
413
+    ));
414 414
 
415 415
     return $output;
416 416
 }
417 417
 
418
-function wpinv_html_select( $args = array() ) {
418
+function wpinv_html_select($args = array()) {
419 419
     $defaults = array(
420 420
         'options'          => array(),
421 421
         'name'             => null,
@@ -424,8 +424,8 @@  discard block
 block discarded – undo
424 424
         'selected'         => 0,
425 425
         'placeholder'      => null,
426 426
         'multiple'         => false,
427
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
428
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
427
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
428
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
429 429
         'data'             => array(),
430 430
         'onchange'         => null,
431 431
         'required'         => false,
@@ -433,74 +433,74 @@  discard block
 block discarded – undo
433 433
         'readonly'         => false,
434 434
     );
435 435
 
436
-    $args = wp_parse_args( $args, $defaults );
436
+    $args = wp_parse_args($args, $defaults);
437 437
 
438 438
     $data_elements = '';
439
-    foreach ( $args['data'] as $key => $value ) {
440
-        $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
439
+    foreach ($args['data'] as $key => $value) {
440
+        $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
441 441
     }
442 442
 
443
-    if( $args['multiple'] ) {
443
+    if ($args['multiple']) {
444 444
         $multiple = ' MULTIPLE';
445 445
     } else {
446 446
         $multiple = '';
447 447
     }
448 448
 
449
-    if( $args['placeholder'] ) {
449
+    if ($args['placeholder']) {
450 450
         $placeholder = $args['placeholder'];
451 451
     } else {
452 452
         $placeholder = '';
453 453
     }
454 454
     
455 455
     $options = '';
456
-    if( !empty( $args['onchange'] ) ) {
457
-        $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"';
456
+    if (!empty($args['onchange'])) {
457
+        $options .= ' onchange="' . esc_attr($args['onchange']) . '"';
458 458
     }
459 459
     
460
-    if( !empty( $args['required'] ) ) {
460
+    if (!empty($args['required'])) {
461 461
         $options .= ' required="required"';
462 462
     }
463 463
     
464
-    if( !empty( $args['disabled'] ) ) {
464
+    if (!empty($args['disabled'])) {
465 465
         $options .= ' disabled';
466 466
     }
467 467
     
468
-    if( !empty( $args['readonly'] ) ) {
468
+    if (!empty($args['readonly'])) {
469 469
         $options .= ' readonly';
470 470
     }
471 471
 
472
-    $class  = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
473
-    $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>';
472
+    $class  = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
473
+    $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>';
474 474
 
475
-    if ( $args['show_option_all'] ) {
476
-        if( $args['multiple'] ) {
477
-            $selected = selected( true, in_array( 0, $args['selected'] ), false );
475
+    if ($args['show_option_all']) {
476
+        if ($args['multiple']) {
477
+            $selected = selected(true, in_array(0, $args['selected']), false);
478 478
         } else {
479
-            $selected = selected( $args['selected'], 0, false );
479
+            $selected = selected($args['selected'], 0, false);
480 480
         }
481
-        $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
481
+        $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>';
482 482
     }
483 483
 
484
-    if ( !empty( $args['options'] ) ) {
484
+    if (!empty($args['options'])) {
485 485
 
486
-        if ( $args['show_option_none'] ) {
487
-            if( $args['multiple'] ) {
488
-                $selected = selected( true, in_array( "", $args['selected'] ), false );
486
+        if ($args['show_option_none']) {
487
+            if ($args['multiple']) {
488
+                $selected = selected(true, in_array("", $args['selected']), false);
489 489
             } else {
490
-                $selected = selected( $args['selected'] === "", true, false );
490
+                $selected = selected($args['selected'] === "", true, false);
491 491
             }
492
-            $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
492
+            $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>';
493 493
         }
494 494
 
495
-        foreach( $args['options'] as $key => $option ) {
495
+        foreach ($args['options'] as $key => $option) {
496 496
 
497
-            if( $args['multiple'] && is_array( $args['selected'] ) ) {
498
-                $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false );
497
+            if ($args['multiple'] && is_array($args['selected'])) {
498
+                $selected = selected(true, (bool) in_array($key, $args['selected']), false);
499 499
             } else {
500
-                $selected = selected( $args['selected'], $key, false );
500
+                $selected = selected($args['selected'], $key, false);
501 501
             }
502 502
 
503
-            $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
503
+            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>';
504 504
         }
505 505
     }
506 506
 
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
     return $output;
510 510
 }
511 511
 
512
-function wpinv_item_dropdown( $args = array() ) {
512
+function wpinv_item_dropdown($args = array()) {
513 513
     $defaults = array(
514 514
         'name'              => 'wpi_item',
515 515
         'id'                => 'wpi_item',
@@ -517,14 +517,14 @@  discard block
 block discarded – undo
517 517
         'multiple'          => false,
518 518
         'selected'          => 0,
519 519
         'number'            => 100,
520
-        'placeholder'       => __( 'Choose a item', 'invoicing' ),
521
-        'data'              => array( 'search-type' => 'item' ),
520
+        'placeholder'       => __('Choose a item', 'invoicing'),
521
+        'data'              => array('search-type' => 'item'),
522 522
         'show_option_all'   => false,
523 523
         'show_option_none'  => false,
524 524
         'show_recurring'    => false,
525 525
     );
526 526
 
527
-    $args = wp_parse_args( $args, $defaults );
527
+    $args = wp_parse_args($args, $defaults);
528 528
 
529 529
     $item_args = array(
530 530
         'post_type'      => 'wpi_item',
@@ -533,44 +533,44 @@  discard block
 block discarded – undo
533 533
         'posts_per_page' => $args['number']
534 534
     );
535 535
 
536
-    $item_args  = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults );
536
+    $item_args  = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults);
537 537
 
538
-    $items      = get_posts( $item_args );
538
+    $items      = get_posts($item_args);
539 539
     $options    = array();
540
-    if ( $items ) {
541
-        foreach ( $items as $item ) {
542
-            $title = esc_html( $item->post_title );
540
+    if ($items) {
541
+        foreach ($items as $item) {
542
+            $title = esc_html($item->post_title);
543 543
             
544
-            if ( !empty( $args['show_recurring'] ) ) {
545
-                $title .= wpinv_get_item_suffix( $item->ID, false );
544
+            if (!empty($args['show_recurring'])) {
545
+                $title .= wpinv_get_item_suffix($item->ID, false);
546 546
             }
547 547
             
548
-            $options[ absint( $item->ID ) ] = $title;
548
+            $options[absint($item->ID)] = $title;
549 549
         }
550 550
     }
551 551
 
552 552
     // This ensures that any selected items are included in the drop down
553
-    if( is_array( $args['selected'] ) ) {
554
-        foreach( $args['selected'] as $item ) {
555
-            if( ! in_array( $item, $options ) ) {
556
-                $title = get_the_title( $item );
557
-                if ( !empty( $args['show_recurring'] ) ) {
558
-                    $title .= wpinv_get_item_suffix( $item, false );
553
+    if (is_array($args['selected'])) {
554
+        foreach ($args['selected'] as $item) {
555
+            if (!in_array($item, $options)) {
556
+                $title = get_the_title($item);
557
+                if (!empty($args['show_recurring'])) {
558
+                    $title .= wpinv_get_item_suffix($item, false);
559 559
                 }
560 560
                 $options[$item] = $title;
561 561
             }
562 562
         }
563
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
564
-        if ( ! in_array( $args['selected'], $options ) ) {
565
-            $title = get_the_title( $args['selected'] );
566
-            if ( !empty( $args['show_recurring'] ) ) {
567
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
563
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
564
+        if (!in_array($args['selected'], $options)) {
565
+            $title = get_the_title($args['selected']);
566
+            if (!empty($args['show_recurring'])) {
567
+                $title .= wpinv_get_item_suffix($args['selected'], false);
568 568
             }
569
-            $options[$args['selected']] = get_the_title( $args['selected'] );
569
+            $options[$args['selected']] = get_the_title($args['selected']);
570 570
         }
571 571
     }
572 572
 
573
-    $output = wpinv_html_select( array(
573
+    $output = wpinv_html_select(array(
574 574
         'name'             => $args['name'],
575 575
         'selected'         => $args['selected'],
576 576
         'id'               => $args['id'],
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
         'show_option_all'  => $args['show_option_all'],
582 582
         'show_option_none' => $args['show_option_none'],
583 583
         'data'             => $args['data'],
584
-    ) );
584
+    ));
585 585
 
586 586
     return $output;
587 587
 }
@@ -601,16 +601,16 @@  discard block
 block discarded – undo
601 601
     );
602 602
 
603 603
     $options = array();
604
-    if ( $items ) {
605
-        foreach ( $items as $item ) {
606
-            $options[ $item->ID ] = esc_html( $item->post_title ) . wpinv_get_item_suffix( $item->ID, false );
604
+    if ($items) {
605
+        foreach ($items as $item) {
606
+            $options[$item->ID] = esc_html($item->post_title) . wpinv_get_item_suffix($item->ID, false);
607 607
         }
608 608
     }
609 609
 
610 610
     return $options;
611 611
 }
612 612
 
613
-function wpinv_html_checkbox( $args = array() ) {
613
+function wpinv_html_checkbox($args = array()) {
614 614
     $defaults = array(
615 615
         'name'     => null,
616 616
         'current'  => null,
@@ -621,17 +621,17 @@  discard block
 block discarded – undo
621 621
         )
622 622
     );
623 623
 
624
-    $args = wp_parse_args( $args, $defaults );
624
+    $args = wp_parse_args($args, $defaults);
625 625
 
626
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
626
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
627 627
     $options = '';
628
-    if ( ! empty( $args['options']['disabled'] ) ) {
628
+    if (!empty($args['options']['disabled'])) {
629 629
         $options .= ' disabled="disabled"';
630
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
630
+    } elseif (!empty($args['options']['readonly'])) {
631 631
         $options .= ' readonly';
632 632
     }
633 633
 
634
-    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />';
634
+    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />';
635 635
 
636 636
     return $output;
637 637
 }
@@ -639,30 +639,30 @@  discard block
 block discarded – undo
639 639
 /**
640 640
  * Displays a hidden field.
641 641
  */
642
-function getpaid_hidden_field( $name, $value ) {
643
-    $name  = sanitize_text_field( $name );
644
-    $value = esc_attr( $value );
642
+function getpaid_hidden_field($name, $value) {
643
+    $name  = sanitize_text_field($name);
644
+    $value = esc_attr($value);
645 645
 
646 646
     echo "<input type='hidden' name='$name' value='$value' />";
647 647
 }
648 648
 
649
-function wpinv_html_text( $args = array() ) {
649
+function wpinv_html_text($args = array()) {
650 650
     // Backwards compatibility
651
-    if ( func_num_args() > 1 ) {
651
+    if (func_num_args() > 1) {
652 652
         $args = func_get_args();
653 653
 
654 654
         $name  = $args[0];
655
-        $value = isset( $args[1] ) ? $args[1] : '';
656
-        $label = isset( $args[2] ) ? $args[2] : '';
657
-        $desc  = isset( $args[3] ) ? $args[3] : '';
655
+        $value = isset($args[1]) ? $args[1] : '';
656
+        $label = isset($args[2]) ? $args[2] : '';
657
+        $desc  = isset($args[3]) ? $args[3] : '';
658 658
     }
659 659
 
660 660
     $defaults = array(
661 661
         'id'           => '',
662
-        'name'         => isset( $name )  ? $name  : 'text',
663
-        'value'        => isset( $value ) ? $value : null,
664
-        'label'        => isset( $label ) ? $label : null,
665
-        'desc'         => isset( $desc )  ? $desc  : null,
662
+        'name'         => isset($name) ? $name : 'text',
663
+        'value'        => isset($value) ? $value : null,
664
+        'label'        => isset($label) ? $label : null,
665
+        'desc'         => isset($desc) ? $desc : null,
666 666
         'placeholder'  => '',
667 667
         'class'        => 'regular-text',
668 668
         'disabled'     => false,
@@ -672,51 +672,51 @@  discard block
 block discarded – undo
672 672
         'data'         => false
673 673
     );
674 674
 
675
-    $args = wp_parse_args( $args, $defaults );
675
+    $args = wp_parse_args($args, $defaults);
676 676
 
677
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
677
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
678 678
     $options = '';
679
-    if( $args['required'] ) {
679
+    if ($args['required']) {
680 680
         $options .= ' required="required"';
681 681
     }
682
-    if( $args['readonly'] ) {
682
+    if ($args['readonly']) {
683 683
         $options .= ' readonly';
684 684
     }
685
-    if( $args['readonly'] ) {
685
+    if ($args['readonly']) {
686 686
         $options .= ' readonly';
687 687
     }
688 688
 
689 689
     $data = '';
690
-    if ( !empty( $args['data'] ) ) {
691
-        foreach ( $args['data'] as $key => $value ) {
692
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
690
+    if (!empty($args['data'])) {
691
+        foreach ($args['data'] as $key => $value) {
692
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
693 693
         }
694 694
     }
695 695
 
696
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
697
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
698
-    if ( ! empty( $args['desc'] ) ) {
699
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
696
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
697
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
698
+    if (!empty($args['desc'])) {
699
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
700 700
     }
701 701
 
702
-    $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] )  . '" autocomplete="' . esc_attr( $args['autocomplete'] )  . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>';
702
+    $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>';
703 703
 
704 704
     $output .= '</span>';
705 705
 
706 706
     return $output;
707 707
 }
708 708
 
709
-function wpinv_html_date_field( $args = array() ) {
710
-    if( empty( $args['class'] ) ) {
709
+function wpinv_html_date_field($args = array()) {
710
+    if (empty($args['class'])) {
711 711
         $args['class'] = 'wpiDatepicker';
712
-    } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) {
712
+    } elseif (!strpos($args['class'], 'wpiDatepicker')) {
713 713
         $args['class'] .= ' wpiDatepicker';
714 714
     }
715 715
 
716
-    return wpinv_html_text( $args );
716
+    return wpinv_html_text($args);
717 717
 }
718 718
 
719
-function wpinv_html_textarea( $args = array() ) {
719
+function wpinv_html_textarea($args = array()) {
720 720
     $defaults = array(
721 721
         'name'        => 'textarea',
722 722
         'value'       => null,
@@ -727,31 +727,31 @@  discard block
 block discarded – undo
727 727
         'placeholder' => '',
728 728
     );
729 729
 
730
-    $args = wp_parse_args( $args, $defaults );
730
+    $args = wp_parse_args($args, $defaults);
731 731
 
732
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
732
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
733 733
     $disabled = '';
734
-    if( $args['disabled'] ) {
734
+    if ($args['disabled']) {
735 735
         $disabled = ' disabled="disabled"';
736 736
     }
737 737
 
738
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
739
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
740
-    $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
738
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
739
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
740
+    $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>';
741 741
 
742
-    if ( ! empty( $args['desc'] ) ) {
743
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
742
+    if (!empty($args['desc'])) {
743
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
744 744
     }
745 745
     $output .= '</span>';
746 746
 
747 747
     return $output;
748 748
 }
749 749
 
750
-function wpinv_html_ajax_user_search( $args = array() ) {
750
+function wpinv_html_ajax_user_search($args = array()) {
751 751
     $defaults = array(
752 752
         'name'        => 'user_id',
753 753
         'value'       => null,
754
-        'placeholder' => __( 'Enter username', 'invoicing' ),
754
+        'placeholder' => __('Enter username', 'invoicing'),
755 755
         'label'       => null,
756 756
         'desc'        => null,
757 757
         'class'       => '',
@@ -760,13 +760,13 @@  discard block
 block discarded – undo
760 760
         'data'        => false
761 761
     );
762 762
 
763
-    $args = wp_parse_args( $args, $defaults );
763
+    $args = wp_parse_args($args, $defaults);
764 764
 
765 765
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
766 766
 
767 767
     $output  = '<span class="wpinv_user_search_wrap">';
768
-        $output .= wpinv_html_text( $args );
769
-        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>';
768
+        $output .= wpinv_html_text($args);
769
+        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>';
770 770
     $output .= '</span>';
771 771
 
772 772
     return $output;
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
 function wpinv_ip_geolocation() {
776 776
     global $wpinv_euvat;
777 777
     
778
-    $ip         = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : '';    
778
+    $ip         = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : '';    
779 779
     $content    = '';
780 780
     $iso        = '';
781 781
     $country    = '';
@@ -786,69 +786,69 @@  discard block
 block discarded – undo
786 786
     $credit     = '';
787 787
     $address    = '';
788 788
     
789
-    if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) {
789
+    if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) {
790 790
         try {
791 791
             $iso        = $geoip2_city->country->isoCode;
792 792
             $country    = $geoip2_city->country->name;
793
-            $region     = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : '';
793
+            $region     = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : '';
794 794
             $city       = $geoip2_city->city->name;
795 795
             $longitude  = $geoip2_city->location->longitude;
796 796
             $latitude   = $geoip2_city->location->latitude;
797
-            $credit     = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' );
798
-        } catch( Exception $e ) { }
797
+            $credit     = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing');
798
+        } catch (Exception $e) { }
799 799
     }
800 800
     
801
-    if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) {
801
+    if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) {
802 802
         try {
803
-            $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
803
+            $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
804 804
             
805
-            if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) {
805
+            if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) {
806 806
                 $iso        = $load_xml->geoplugin_countryCode;
807 807
                 $country    = $load_xml->geoplugin_countryName;
808
-                $region     = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : '';
809
-                $city       = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : '';
808
+                $region     = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : '';
809
+                $city       = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : '';
810 810
                 $longitude  = $load_xml->geoplugin_longitude;
811 811
                 $latitude   = $load_xml->geoplugin_latitude;
812 812
                 $credit     = $load_xml->geoplugin_credit;
813
-                $credit     = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit;
813
+                $credit     = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit;
814 814
             }
815
-        } catch( Exception $e ) { }
815
+        } catch (Exception $e) { }
816 816
     }
817 817
     
818
-    if ( $iso && $longitude && $latitude ) {
819
-        if ( $city ) {
818
+    if ($iso && $longitude && $latitude) {
819
+        if ($city) {
820 820
             $address .= $city . ', ';
821 821
         }
822 822
         
823
-        if ( $region ) {
823
+        if ($region) {
824 824
             $address .= $region . ', ';
825 825
         }
826 826
         
827 827
         $address .= $country . ' (' . $iso . ')';
828
-        $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>';
829
-        $content .= '<p>'. $credit . '</p>';
828
+        $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>';
829
+        $content .= '<p>' . $credit . '</p>';
830 830
     } else {
831
-        $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>';
831
+        $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>';
832 832
     }
833 833
     ?>
834 834
 <!DOCTYPE html>
835
-<html><head><title><?php echo sprintf( __( 'IP: %s', 'invoicing' ), $ip );?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
835
+<html><head><title><?php echo sprintf(__('IP: %s', 'invoicing'), $ip); ?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
836 836
 <body>
837
-    <?php if ( $latitude && $latitude ) { ?>
837
+    <?php if ($latitude && $latitude) { ?>
838 838
     <div id="map"></div>
839 839
         <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script>
840 840
         <script type="text/javascript">
841 841
         var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
842 842
             osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
843 843
             osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}),
844
-            latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>);
844
+            latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>);
845 845
 
846 846
         var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]});
847 847
 
848 848
         var marker = new L.Marker(latlng);
849 849
         map.addLayer(marker);
850 850
 
851
-        marker.bindPopup("<p><?php esc_attr_e( $address );?></p>");
851
+        marker.bindPopup("<p><?php esc_attr_e($address); ?></p>");
852 852
     </script>
853 853
     <?php } ?>
854 854
     <div style="height:100px"><?php echo $content; ?></div>
@@ -856,37 +856,37 @@  discard block
 block discarded – undo
856 856
 <?php
857 857
     exit;
858 858
 }
859
-add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
860
-add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
859
+add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
860
+add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
861 861
 
862 862
 /**
863 863
  * Use our template to display invoices.
864 864
  * 
865 865
  * @param string $template the template that is currently being used.
866 866
  */
867
-function wpinv_template( $template ) {
867
+function wpinv_template($template) {
868 868
     global $post;
869 869
 
870
-    if ( ! is_admin() && ( is_single() || is_404() ) && ! empty( $post->ID ) && getpaid_is_invoice_post_type( get_post_type( $post->ID ) ) ) {
870
+    if (!is_admin() && (is_single() || is_404()) && !empty($post->ID) && getpaid_is_invoice_post_type(get_post_type($post->ID))) {
871 871
 
872 872
         // If the user can view this invoice, display it.
873
-        if ( wpinv_user_can_view_invoice( $post->ID ) ) {
874
-            return wpinv_get_template_part( 'wpinv-invoice-print', false, false );
873
+        if (wpinv_user_can_view_invoice($post->ID)) {
874
+            return wpinv_get_template_part('wpinv-invoice-print', false, false);
875 875
 
876 876
         // Else display an error message.
877 877
         } else {
878
-            return wpinv_get_template_part( 'wpinv-invalid-access', false, false );
878
+            return wpinv_get_template_part('wpinv-invalid-access', false, false);
879 879
         }
880 880
 
881 881
     }
882 882
 
883 883
     return $template;
884 884
 }
885
-add_filter( 'template_include', 'wpinv_template', 10, 1 );
885
+add_filter('template_include', 'wpinv_template', 10, 1);
886 886
 
887 887
 function wpinv_get_business_address() {
888 888
     $business_address   = wpinv_store_address();
889
-    $business_address   = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
889
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
890 890
     
891 891
     /*
892 892
     $default_country    = wpinv_get_default_country();
@@ -910,38 +910,38 @@  discard block
 block discarded – undo
910 910
     
911 911
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
912 912
     
913
-    return apply_filters( 'wpinv_get_business_address', $business_address );
913
+    return apply_filters('wpinv_get_business_address', $business_address);
914 914
 }
915 915
 
916 916
 /**
917 917
  * Displays the company address.
918 918
  */
919 919
 function wpinv_display_from_address() {
920
-    wpinv_get_template( 'invoice/company-address.php' );
920
+    wpinv_get_template('invoice/company-address.php');
921 921
 }
922
-add_action( 'getpaid_invoice_details_left', 'wpinv_display_from_address', 10 );
922
+add_action('getpaid_invoice_details_left', 'wpinv_display_from_address', 10);
923 923
 
924
-function wpinv_watermark( $id = 0 ) {
925
-    $output = wpinv_get_watermark( $id );
926
-    return apply_filters( 'wpinv_get_watermark', $output, $id );
924
+function wpinv_watermark($id = 0) {
925
+    $output = wpinv_get_watermark($id);
926
+    return apply_filters('wpinv_get_watermark', $output, $id);
927 927
 }
928 928
 
929
-function wpinv_get_watermark( $id ) {
930
-    if ( !$id > 0 ) {
929
+function wpinv_get_watermark($id) {
930
+    if (!$id > 0) {
931 931
         return NULL;
932 932
     }
933 933
 
934
-    $invoice = wpinv_get_invoice( $id );
934
+    $invoice = wpinv_get_invoice($id);
935 935
     
936
-    if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) {
937
-        if ( $invoice->is_paid() ) {
938
-            return __( 'Paid', 'invoicing' );
936
+    if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) {
937
+        if ($invoice->is_paid()) {
938
+            return __('Paid', 'invoicing');
939 939
         }
940
-        if ( $invoice->is_refunded() ) {
941
-            return __( 'Refunded', 'invoicing' );
940
+        if ($invoice->is_refunded()) {
941
+            return __('Refunded', 'invoicing');
942 942
         }
943
-        if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) {
944
-            return __( 'Cancelled', 'invoicing' );
943
+        if ($invoice->has_status(array('wpi-cancelled'))) {
944
+            return __('Cancelled', 'invoicing');
945 945
         }
946 946
     }
947 947
     
@@ -951,125 +951,125 @@  discard block
 block discarded – undo
951 951
 /**
952 952
  * @deprecated
953 953
  */
954
-function wpinv_display_invoice_details( $invoice ) {
955
-    return getpaid_invoice_meta( $invoice );
954
+function wpinv_display_invoice_details($invoice) {
955
+    return getpaid_invoice_meta($invoice);
956 956
 }
957 957
 
958 958
 /**
959 959
  * Displays invoice meta.
960 960
  */
961
-function getpaid_invoice_meta( $invoice ) {
961
+function getpaid_invoice_meta($invoice) {
962 962
 
963
-    $invoice = new WPInv_Invoice( $invoice );
963
+    $invoice = new WPInv_Invoice($invoice);
964 964
 
965 965
     // Ensure that we have an invoice.
966
-    if ( 0 == $invoice->get_id() ) {
966
+    if (0 == $invoice->get_id()) {
967 967
         return;
968 968
     }
969 969
 
970 970
     // Load the invoice meta.
971
-    $meta    = array(
971
+    $meta = array(
972 972
 
973 973
         'number' => array(
974 974
             'label' => sprintf(
975
-                __( '%s Number', 'invoicing' ),
976
-                ucfirst( $invoice->get_type() )
975
+                __('%s Number', 'invoicing'),
976
+                ucfirst($invoice->get_type())
977 977
             ),
978
-            'value' => sanitize_text_field( $invoice->get_number() ),
978
+            'value' => sanitize_text_field($invoice->get_number()),
979 979
         ),
980 980
 
981 981
         'status' => array(
982 982
             'label' => sprintf(
983
-                __( '%s Status', 'invoicing' ),
984
-                ucfirst( $invoice->get_type() )
983
+                __('%s Status', 'invoicing'),
984
+                ucfirst($invoice->get_type())
985 985
             ),
986
-            'value' => sanitize_text_field( $invoice->get_status_nicename() ),
986
+            'value' => sanitize_text_field($invoice->get_status_nicename()),
987 987
         ),
988 988
 
989 989
         'date' => array(
990 990
             'label' => sprintf(
991
-                __( '%s Date', 'invoicing' ),
992
-                ucfirst( $invoice->get_type() )
991
+                __('%s Date', 'invoicing'),
992
+                ucfirst($invoice->get_type())
993 993
             ),
994
-            'value' => getpaid_format_date( $invoice->get_created_date() ),
994
+            'value' => getpaid_format_date($invoice->get_created_date()),
995 995
         ),
996 996
 
997 997
         'date_paid' => array(
998
-            'label' => __( 'Paid On', 'invoicing' ),
999
-            'value' => getpaid_format_date( $invoice->get_completed_date() ),
998
+            'label' => __('Paid On', 'invoicing'),
999
+            'value' => getpaid_format_date($invoice->get_completed_date()),
1000 1000
         ),
1001 1001
 
1002 1002
         'due_date'  => array(
1003
-            'label' => __( 'Due Date', 'invoicing' ),
1004
-            'value' => getpaid_format_date( $invoice->get_due_date() ),
1003
+            'label' => __('Due Date', 'invoicing'),
1004
+            'value' => getpaid_format_date($invoice->get_due_date()),
1005 1005
         ),
1006 1006
 
1007 1007
         'vat_number' => array(
1008 1008
             'label' => sprintf(
1009
-                __( '%s Number', 'invoicing' ),
1009
+                __('%s Number', 'invoicing'),
1010 1010
                 $GLOBALS['wpinv_euvat']->get_vat_name()
1011 1011
             ),
1012
-            'value' => sanitize_text_field( $invoice->get_vat_number() ),
1012
+            'value' => sanitize_text_field($invoice->get_vat_number()),
1013 1013
         ),
1014 1014
 
1015 1015
     );
1016 1016
 
1017 1017
     // If it is not paid, remove the date of payment.
1018
-    if ( ! $invoice->is_paid() ) {
1019
-        unset( $meta[ 'date_paid' ] );
1018
+    if (!$invoice->is_paid()) {
1019
+        unset($meta['date_paid']);
1020 1020
     }
1021 1021
 
1022 1022
     // Only display the due date if due dates are enabled.
1023
-    if ( ! $invoice->needs_payment() || ! wpinv_get_option( 'overdue_active' ) ) {
1024
-        unset( $meta[ 'due_date' ] );
1023
+    if (!$invoice->needs_payment() || !wpinv_get_option('overdue_active')) {
1024
+        unset($meta['due_date']);
1025 1025
     }
1026 1026
 
1027 1027
     // Only display the vat number if taxes are enabled.
1028
-    if ( ! wpinv_use_taxes() ) {
1029
-        unset( $meta[ 'vat_number' ] );
1028
+    if (!wpinv_use_taxes()) {
1029
+        unset($meta['vat_number']);
1030 1030
     }
1031 1031
 
1032
-    if ( $invoice->is_recurring() ) {
1032
+    if ($invoice->is_recurring()) {
1033 1033
 
1034 1034
         // Link to the parent invoice.
1035
-        if ( $invoice->is_renewal() ) {
1035
+        if ($invoice->is_renewal()) {
1036 1036
 
1037
-            $meta[ 'parent' ] = array(
1037
+            $meta['parent'] = array(
1038 1038
 
1039 1039
                 'label' => sprintf(
1040
-                    __( 'Parent %s', 'invoicing' ),
1041
-                    ucfirst( $invoice->get_type() )
1040
+                    __('Parent %s', 'invoicing'),
1041
+                    ucfirst($invoice->get_type())
1042 1042
                 ),
1043 1043
 
1044
-                'value' => wpinv_invoice_link( $invoice->get_parent_id() ),
1044
+                'value' => wpinv_invoice_link($invoice->get_parent_id()),
1045 1045
 
1046 1046
             );
1047 1047
 
1048 1048
         }
1049 1049
 
1050
-        $subscription = wpinv_get_subscription( $invoice );
1050
+        $subscription = wpinv_get_subscription($invoice);
1051 1051
 
1052
-        if ( ! empty ( $subscription ) ) {
1052
+        if (!empty ($subscription)) {
1053 1053
 
1054 1054
             // Display the renewal date.
1055
-            if ( $subscription->is_active() && 'cancelled' != $subscription->status ) {
1055
+            if ($subscription->is_active() && 'cancelled' != $subscription->status) {
1056 1056
 
1057
-                $meta[ 'renewal_date' ] = array(
1057
+                $meta['renewal_date'] = array(
1058 1058
 
1059
-                    'label' => __( 'Renews On', 'invoicing' ),
1060
-                    'value' => getpaid_format_date( $subscription->expiration ),
1059
+                    'label' => __('Renews On', 'invoicing'),
1060
+                    'value' => getpaid_format_date($subscription->expiration),
1061 1061
         
1062 1062
                 );
1063 1063
 
1064 1064
             }
1065 1065
 
1066
-            if ( $invoice->is_parent() ) {
1066
+            if ($invoice->is_parent()) {
1067 1067
 
1068 1068
                 // Display the recurring amount.
1069
-                $meta[ 'recurring_total' ] = array(
1069
+                $meta['recurring_total'] = array(
1070 1070
 
1071
-                    'label' => __( 'Recurring Amount', 'invoicing' ),
1072
-                    'value' => wpinv_price( wpinv_format_amount( $subscription->recurring_amount ), $invoice->get_currency() ),
1071
+                    'label' => __('Recurring Amount', 'invoicing'),
1072
+                    'value' => wpinv_price(wpinv_format_amount($subscription->recurring_amount), $invoice->get_currency()),
1073 1073
         
1074 1074
                 );
1075 1075
 
@@ -1079,20 +1079,20 @@  discard block
 block discarded – undo
1079 1079
     }
1080 1080
 
1081 1081
     // Add the invoice total to the meta.
1082
-    $meta[ 'invoice_total' ] = array(
1082
+    $meta['invoice_total'] = array(
1083 1083
 
1084
-        'label' => __( 'Total Amount', 'invoicing' ),
1085
-        'value' => wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() ),
1084
+        'label' => __('Total Amount', 'invoicing'),
1085
+        'value' => wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency()),
1086 1086
 
1087 1087
     );
1088 1088
 
1089 1089
     // Provide a way for third party plugins to filter the meta.
1090
-    $meta = apply_filters( 'getpaid_invoice_meta_data', $meta, $invoice );
1090
+    $meta = apply_filters('getpaid_invoice_meta_data', $meta, $invoice);
1091 1091
 
1092
-    wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) );
1092
+    wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta'));
1093 1093
 
1094 1094
 }
1095
-add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 );
1095
+add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10);
1096 1096
 
1097 1097
 /**
1098 1098
  * Retrieves the address markup to use on Invoices.
@@ -1104,29 +1104,29 @@  discard block
 block discarded – undo
1104 1104
  * @param  string $separator How to separate address lines.
1105 1105
  * @return string
1106 1106
  */
1107
-function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) {
1107
+function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') {
1108 1108
 
1109 1109
     // Retrieve the address markup...
1110
-    $country= empty( $billing_details['country'] ) ? '' : $billing_details['country'];
1111
-    $format = wpinv_get_full_address_format( $country );
1110
+    $country = empty($billing_details['country']) ? '' : $billing_details['country'];
1111
+    $format = wpinv_get_full_address_format($country);
1112 1112
 
1113 1113
     // ... and the replacements.
1114
-    $replacements = wpinv_get_invoice_address_replacements( $billing_details );
1114
+    $replacements = wpinv_get_invoice_address_replacements($billing_details);
1115 1115
 
1116
-    $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format );
1116
+    $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format);
1117 1117
     
1118 1118
 	// Remove unavailable tags.
1119
-    $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address );
1119
+    $formatted_address = preg_replace("/\{\{\w+\}\}/", '', $formatted_address);
1120 1120
 
1121 1121
     // Clean up white space.
1122
-	$formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
1123
-    $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
1122
+	$formatted_address = preg_replace('/  +/', ' ', trim($formatted_address));
1123
+    $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address);
1124 1124
     
1125 1125
     // Break newlines apart and remove empty lines/trim commas and white space.
1126
-	$formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
1126
+	$formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address)));
1127 1127
 
1128 1128
     // Add html breaks.
1129
-	$formatted_address = implode( $separator, $formatted_address );
1129
+	$formatted_address = implode($separator, $formatted_address);
1130 1130
 
1131 1131
 	// We're done!
1132 1132
 	return $formatted_address;
@@ -1138,24 +1138,24 @@  discard block
 block discarded – undo
1138 1138
  * 
1139 1139
  * @param WPInv_Invoice $invoice
1140 1140
  */
1141
-function wpinv_display_to_address( $invoice = 0 ) {
1142
-    if ( ! empty( $invoice ) ) {
1143
-        wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) );
1141
+function wpinv_display_to_address($invoice = 0) {
1142
+    if (!empty($invoice)) {
1143
+        wpinv_get_template('invoice/billing-address.php', compact('invoice'));
1144 1144
     }
1145 1145
 }
1146
-add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 );
1146
+add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40);
1147 1147
 
1148 1148
 
1149 1149
 /**
1150 1150
  * Displays invoice line items.
1151 1151
  */
1152
-function wpinv_display_line_items( $invoice_id = 0 ) {
1152
+function wpinv_display_line_items($invoice_id = 0) {
1153 1153
 
1154 1154
     // Prepare the invoice.
1155
-    $invoice = new WPInv_Invoice( $invoice_id );
1155
+    $invoice = new WPInv_Invoice($invoice_id);
1156 1156
 
1157 1157
     // Abort if there is no invoice.
1158
-    if ( 0 == $invoice->get_id() ) {
1158
+    if (0 == $invoice->get_id()) {
1159 1159
         return;
1160 1160
     }
1161 1161
 
@@ -1163,110 +1163,110 @@  discard block
 block discarded – undo
1163 1163
     $columns = apply_filters(
1164 1164
         'getpaid_invoice_line_items_table_columns',
1165 1165
         array(
1166
-            'name'     => __( 'Item', 'invoicing' ),
1167
-            'price'    => __( 'Price', 'invoicing' ),
1168
-            'quantity' => __( 'Quantity', 'invoicing' ),
1169
-            'subtotal' => __( 'Subtotal', 'invoicing' ),
1166
+            'name'     => __('Item', 'invoicing'),
1167
+            'price'    => __('Price', 'invoicing'),
1168
+            'quantity' => __('Quantity', 'invoicing'),
1169
+            'subtotal' => __('Subtotal', 'invoicing'),
1170 1170
         ),
1171 1171
         $invoice
1172 1172
     );
1173 1173
 
1174 1174
     // Quantities.
1175
-    if ( isset( $columns[ 'quantity' ] ) ) {
1175
+    if (isset($columns['quantity'])) {
1176 1176
 
1177
-        if ( 'amount' == $invoice->get_template() ) {
1178
-            unset( $columns[ 'quantity' ] );
1177
+        if ('amount' == $invoice->get_template()) {
1178
+            unset($columns['quantity']);
1179 1179
         }
1180 1180
 
1181
-        if ( 'hours' == $invoice->get_template() ) {
1182
-            $columns[ 'quantity' ] = __( 'Hours', 'invoicing' );
1181
+        if ('hours' == $invoice->get_template()) {
1182
+            $columns['quantity'] = __('Hours', 'invoicing');
1183 1183
         }
1184 1184
 
1185
-        if ( ! wpinv_item_quantities_enabled() ) {
1186
-            unset( $columns[ 'quantity' ] );
1185
+        if (!wpinv_item_quantities_enabled()) {
1186
+            unset($columns['quantity']);
1187 1187
         }
1188 1188
 
1189 1189
     }
1190 1190
 
1191 1191
     // Price.
1192
-    if ( isset( $columns[ 'price' ] ) ) {
1192
+    if (isset($columns['price'])) {
1193 1193
 
1194
-        if ( 'amount' == $invoice->get_template() ) {
1195
-            $columns[ 'price' ] = __( 'Amount', 'invoicing' );
1194
+        if ('amount' == $invoice->get_template()) {
1195
+            $columns['price'] = __('Amount', 'invoicing');
1196 1196
         }
1197 1197
 
1198
-        if ( 'hours' == $invoice->get_template() ) {
1199
-            $columns[ 'price' ] = __( 'Rate', 'invoicing' );
1198
+        if ('hours' == $invoice->get_template()) {
1199
+            $columns['price'] = __('Rate', 'invoicing');
1200 1200
         }
1201 1201
 
1202 1202
     }
1203 1203
 
1204 1204
     // Sub total.
1205
-    if ( isset( $columns[ 'subtotal' ] ) ) {
1205
+    if (isset($columns['subtotal'])) {
1206 1206
 
1207
-        if ( 'amount' == $invoice->get_template() ) {
1208
-            unset( $columns[ 'subtotal' ] );
1207
+        if ('amount' == $invoice->get_template()) {
1208
+            unset($columns['subtotal']);
1209 1209
         }
1210 1210
 
1211 1211
     }
1212 1212
 
1213
-    wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) );
1213
+    wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns'));
1214 1214
 }
1215
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items' );
1215
+add_action('getpaid_invoice_line_items', 'wpinv_display_line_items');
1216 1216
 
1217 1217
 /**
1218 1218
  * @param WPInv_Invoice $invoice
1219 1219
  */
1220
-function wpinv_display_invoice_notes( $invoice ) {
1220
+function wpinv_display_invoice_notes($invoice) {
1221 1221
 
1222
-    $notes = wpinv_get_invoice_notes( $invoice->ID, 'customer' );
1222
+    $notes = wpinv_get_invoice_notes($invoice->ID, 'customer');
1223 1223
 
1224
-    if ( empty( $notes ) ) {
1224
+    if (empty($notes)) {
1225 1225
         return;
1226 1226
     }
1227 1227
 
1228 1228
     echo '<div class="wpi_invoice_notes_container">';
1229
-    echo '<h2>' . __( 'Invoice Notes', 'invoicing' ) .'</h2>';
1229
+    echo '<h2>' . __('Invoice Notes', 'invoicing') . '</h2>';
1230 1230
     echo '<ul class="wpi_invoice_notes">';
1231 1231
 
1232
-    foreach( $notes as $note ) {
1233
-        wpinv_get_invoice_note_line_item( $note );
1232
+    foreach ($notes as $note) {
1233
+        wpinv_get_invoice_note_line_item($note);
1234 1234
     }
1235 1235
 
1236 1236
     echo '</ul>';
1237 1237
     echo '</div>';
1238 1238
 }
1239
-add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_display_invoice_notes' );
1239
+add_action('wpinv_invoice_print_after_line_items', 'wpinv_display_invoice_notes');
1240 1240
 
1241
-function wpinv_display_invoice_totals( $invoice_id = 0 ) {
1241
+function wpinv_display_invoice_totals($invoice_id = 0) {
1242 1242
     $use_taxes = wpinv_use_taxes();
1243 1243
 
1244
-    do_action( 'wpinv_before_display_totals_table', $invoice_id ); 
1244
+    do_action('wpinv_before_display_totals_table', $invoice_id); 
1245 1245
     ?>
1246 1246
     <table class="table table-sm table-bordered table-responsive">
1247 1247
         <tbody>
1248
-            <?php do_action( 'wpinv_before_display_totals' ); ?>
1248
+            <?php do_action('wpinv_before_display_totals'); ?>
1249 1249
             <tr class="row-sub-total">
1250
-                <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td>
1251
-                <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1250
+                <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td>
1251
+                <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1252 1252
             </tr>
1253
-            <?php do_action( 'wpinv_after_display_totals' ); ?>
1254
-            <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?>
1253
+            <?php do_action('wpinv_after_display_totals'); ?>
1254
+            <?php if (wpinv_discount($invoice_id, false) > 0) { ?>
1255 1255
                 <tr class="row-discount">
1256
-                    <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td>
1257
-                    <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1256
+                    <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td>
1257
+                    <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1258 1258
                 </tr>
1259
-            <?php do_action( 'wpinv_after_display_discount' ); ?>
1259
+            <?php do_action('wpinv_after_display_discount'); ?>
1260 1260
             <?php } ?>
1261
-            <?php if ( $use_taxes ) { ?>
1261
+            <?php if ($use_taxes) { ?>
1262 1262
             <tr class="row-tax">
1263
-                <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td>
1264
-                <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1263
+                <td class="rate"><?php _e('Tax', 'invoicing'); ?></td>
1264
+                <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1265 1265
             </tr>
1266
-            <?php do_action( 'wpinv_after_display_tax' ); ?>
1266
+            <?php do_action('wpinv_after_display_tax'); ?>
1267 1267
             <?php } ?>
1268
-            <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?>
1269
-                <?php foreach ( $fees as $fee ) { ?>
1268
+            <?php if ($fees = wpinv_get_fees($invoice_id)) { ?>
1269
+                <?php foreach ($fees as $fee) { ?>
1270 1270
                     <tr class="row-fee">
1271 1271
                         <td class="rate"><?php echo $fee['label']; ?></td>
1272 1272
                         <td class="total"><?php echo $fee['amount_display']; ?></td>
@@ -1274,36 +1274,36 @@  discard block
 block discarded – undo
1274 1274
                 <?php } ?>
1275 1275
             <?php } ?>
1276 1276
             <tr class="table-active row-total">
1277
-                <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td>
1278
-                <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1277
+                <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td>
1278
+                <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1279 1279
             </tr>
1280
-            <?php do_action( 'wpinv_after_totals' ); ?>
1280
+            <?php do_action('wpinv_after_totals'); ?>
1281 1281
         </tbody>
1282 1282
 
1283 1283
     </table>
1284 1284
 
1285
-    <?php do_action( 'wpinv_after_totals_table' );
1285
+    <?php do_action('wpinv_after_totals_table');
1286 1286
 }
1287 1287
 
1288
-function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) {
1289
-    $invoice = wpinv_get_invoice( $invoice_id );
1288
+function wpinv_display_payments_info($invoice_id = 0, $echo = true) {
1289
+    $invoice = wpinv_get_invoice($invoice_id);
1290 1290
 
1291 1291
     ob_start();
1292
-    do_action( 'wpinv_before_display_payments_info', $invoice_id );
1293
-    if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() || $invoice->is_refunded() ) {
1292
+    do_action('wpinv_before_display_payments_info', $invoice_id);
1293
+    if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid() || $invoice->is_refunded()) {
1294 1294
         ?>
1295 1295
         <div class="wpi-payment-info">
1296
-            <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p>
1297
-            <?php if ( $gateway_title ) { ?>
1298
-            <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p>
1296
+            <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p>
1297
+            <?php if ($gateway_title) { ?>
1298
+            <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p>
1299 1299
             <?php } ?>
1300 1300
         </div>
1301 1301
         <?php
1302 1302
     }
1303
-    do_action( 'wpinv_after_display_payments_info', $invoice_id );
1303
+    do_action('wpinv_after_display_payments_info', $invoice_id);
1304 1304
     $outout = ob_get_clean();
1305 1305
 
1306
-    if ( $echo ) {
1306
+    if ($echo) {
1307 1307
         echo $outout;
1308 1308
     } else {
1309 1309
         return $outout;
@@ -1316,55 +1316,55 @@  discard block
 block discarded – undo
1316 1316
 function wpinv_display_style() {
1317 1317
 
1318 1318
     // Make sure that all scripts have been loaded.
1319
-    if ( ! did_action( 'wp_enqueue_scripts' ) ) {
1320
-        do_action( 'wp_enqueue_scripts' );
1319
+    if (!did_action('wp_enqueue_scripts')) {
1320
+        do_action('wp_enqueue_scripts');
1321 1321
     }
1322 1322
 
1323 1323
     // Register the invoices style.
1324
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) );
1324
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css'));
1325 1325
 
1326 1326
     // Load required styles
1327
-    wp_print_styles( 'open-sans' );
1328
-    wp_print_styles( 'wpinv-single-style' );
1329
-    wp_print_styles( 'ayecode-ui' );
1327
+    wp_print_styles('open-sans');
1328
+    wp_print_styles('wpinv-single-style');
1329
+    wp_print_styles('ayecode-ui');
1330 1330
 
1331 1331
     // Maybe load custom css.
1332
-    $custom_css = wpinv_get_option( 'template_custom_css' );
1332
+    $custom_css = wpinv_get_option('template_custom_css');
1333 1333
 
1334
-    if ( isset( $custom_css ) && ! empty( $custom_css ) ) {
1335
-        $custom_css     = wp_kses( $custom_css, array( '\'', '\"' ) );
1336
-        $custom_css     = str_replace( '&gt;', '>', $custom_css );
1334
+    if (isset($custom_css) && !empty($custom_css)) {
1335
+        $custom_css     = wp_kses($custom_css, array('\'', '\"'));
1336
+        $custom_css     = str_replace('&gt;', '>', $custom_css);
1337 1337
         echo '<style type="text/css">';
1338 1338
         echo $custom_css;
1339 1339
         echo '</style>';
1340 1340
     }
1341 1341
 
1342 1342
 }
1343
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
1344
-add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' );
1343
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
1344
+add_action('wpinv_invalid_invoice_head', 'wpinv_display_style');
1345 1345
 
1346 1346
 function wpinv_checkout_billing_details() {
1347
-    $invoice_id = (int)wpinv_get_invoice_cart_id();
1347
+    $invoice_id = (int) wpinv_get_invoice_cart_id();
1348 1348
     if (empty($invoice_id)) {
1349
-        wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ );
1349
+        wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__);
1350 1350
         return null;
1351 1351
     }
1352 1352
 
1353
-    $invoice = wpinv_get_invoice_cart( $invoice_id );
1353
+    $invoice = wpinv_get_invoice_cart($invoice_id);
1354 1354
     if (empty($invoice)) {
1355
-        wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ );
1355
+        wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__);
1356 1356
         return null;
1357 1357
     }
1358 1358
     $user_id        = $invoice->get_user_id();
1359 1359
     $user_info      = $invoice->get_user_info();
1360
-    $address_info   = wpinv_get_user_address( $user_id );
1360
+    $address_info   = wpinv_get_user_address($user_id);
1361 1361
 
1362
-    if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) {
1362
+    if (empty($user_info['first_name']) && !empty($user_info['first_name'])) {
1363 1363
         $user_info['first_name'] = $user_info['first_name'];
1364 1364
         $user_info['last_name'] = $user_info['last_name'];
1365 1365
     }
1366 1366
 
1367
-    if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) {
1367
+    if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) {
1368 1368
         $user_info['country']   = $address_info['country'];
1369 1369
         $user_info['state']     = $address_info['state'];
1370 1370
         $user_info['city']      = $address_info['city'];
@@ -1380,13 +1380,13 @@  discard block
 block discarded – undo
1380 1380
         'address'
1381 1381
     );
1382 1382
 
1383
-    foreach ( $address_fields as $field ) {
1384
-        if ( empty( $user_info[$field] ) ) {
1383
+    foreach ($address_fields as $field) {
1384
+        if (empty($user_info[$field])) {
1385 1385
             $user_info[$field] = $address_info[$field];
1386 1386
         }
1387 1387
     }
1388 1388
 
1389
-    return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice );
1389
+    return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice);
1390 1390
 }
1391 1391
 
1392 1392
 
@@ -1399,24 +1399,24 @@  discard block
 block discarded – undo
1399 1399
     // Retrieve the current invoice.
1400 1400
     $invoice_id = wpinv_get_invoice_cart_id();
1401 1401
 
1402
-    if ( empty( $invoice_id ) ) {
1402
+    if (empty($invoice_id)) {
1403 1403
 
1404 1404
         return aui()->alert(
1405 1405
             array(
1406 1406
                 'type'    => 'warning',
1407
-                'content' => __( 'Invalid invoice', 'invoicing' ),
1407
+                'content' => __('Invalid invoice', 'invoicing'),
1408 1408
             )
1409 1409
         );
1410 1410
 
1411 1411
     }
1412 1412
 
1413 1413
     // Can the user view this invoice?
1414
-    if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) {
1414
+    if (!wpinv_user_can_view_invoice($invoice_id)) {
1415 1415
 
1416 1416
         return aui()->alert(
1417 1417
             array(
1418 1418
                 'type'    => 'warning',
1419
-                'content' => __( 'You are not allowed to view this invoice', 'invoicing' ),
1419
+                'content' => __('You are not allowed to view this invoice', 'invoicing'),
1420 1420
             )
1421 1421
         );
1422 1422
 
@@ -1426,52 +1426,52 @@  discard block
 block discarded – undo
1426 1426
     $wpi_checkout_id = $invoice_id;
1427 1427
 
1428 1428
     // We'll display this invoice via the default form.
1429
-    $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
1429
+    $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form());
1430 1430
 
1431
-    if ( 0 == $form->get_id() ) {
1431
+    if (0 == $form->get_id()) {
1432 1432
 
1433 1433
         return aui()->alert(
1434 1434
             array(
1435 1435
                 'type'    => 'warning',
1436
-                'content' => __( 'Error loading the payment form', 'invoicing' ),
1436
+                'content' => __('Error loading the payment form', 'invoicing'),
1437 1437
             )
1438 1438
         );
1439 1439
 
1440 1440
     }
1441 1441
 
1442 1442
     // Set the invoice.
1443
-    $form->invoice = new WPInv_Invoice( $invoice_id );
1444
-    $form->set_items( $form->invoice->get_items() );
1443
+    $form->invoice = new WPInv_Invoice($invoice_id);
1444
+    $form->set_items($form->invoice->get_items());
1445 1445
 
1446 1446
     // Generate the html.
1447 1447
     return $form->get_html();
1448 1448
 
1449 1449
 }
1450 1450
 
1451
-function wpinv_checkout_cart( $cart_details = array(), $echo = true ) {
1451
+function wpinv_checkout_cart($cart_details = array(), $echo = true) {
1452 1452
     global $ajax_cart_details;
1453 1453
     $ajax_cart_details = $cart_details;
1454 1454
 
1455 1455
     ob_start();
1456
-    do_action( 'wpinv_before_checkout_cart' );
1456
+    do_action('wpinv_before_checkout_cart');
1457 1457
     echo '<div id="wpinv_checkout_cart_form" method="post">';
1458 1458
         echo '<div id="wpinv_checkout_cart_wrap">';
1459
-            wpinv_get_template_part( 'wpinv-checkout-cart' );
1459
+            wpinv_get_template_part('wpinv-checkout-cart');
1460 1460
         echo '</div>';
1461 1461
     echo '</div>';
1462
-    do_action( 'wpinv_after_checkout_cart' );
1462
+    do_action('wpinv_after_checkout_cart');
1463 1463
     $content = ob_get_clean();
1464 1464
 
1465
-    if ( $echo ) {
1465
+    if ($echo) {
1466 1466
         echo $content;
1467 1467
     } else {
1468 1468
         return $content;
1469 1469
     }
1470 1470
 }
1471
-add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 );
1471
+add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10);
1472 1472
 
1473 1473
 function wpinv_empty_cart_message() {
1474
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1474
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1475 1475
 }
1476 1476
 
1477 1477
 /**
@@ -1488,83 +1488,83 @@  discard block
 block discarded – undo
1488 1488
         )
1489 1489
     );
1490 1490
 }
1491
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1491
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1492 1492
 
1493 1493
 function wpinv_update_cart_button() {
1494
-    if ( !wpinv_item_quantities_enabled() )
1494
+    if (!wpinv_item_quantities_enabled())
1495 1495
         return;
1496 1496
 ?>
1497
-    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/>
1497
+    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/>
1498 1498
     <input type="hidden" name="wpi_action" value="update_cart"/>
1499 1499
 <?php
1500 1500
 }
1501 1501
 
1502 1502
 function wpinv_checkout_cart_columns() {
1503 1503
     $default = 3;
1504
-    if ( wpinv_item_quantities_enabled() ) {
1504
+    if (wpinv_item_quantities_enabled()) {
1505 1505
         $default++;
1506 1506
     }
1507 1507
     
1508
-    if ( wpinv_use_taxes() ) {
1508
+    if (wpinv_use_taxes()) {
1509 1509
         $default++;
1510 1510
     }
1511 1511
 
1512
-    return apply_filters( 'wpinv_checkout_cart_columns', $default );
1512
+    return apply_filters('wpinv_checkout_cart_columns', $default);
1513 1513
 }
1514 1514
 
1515 1515
 function wpinv_display_cart_messages() {
1516 1516
     global $wpi_session;
1517 1517
 
1518
-    $messages = $wpi_session->get( 'wpinv_cart_messages' );
1518
+    $messages = $wpi_session->get('wpinv_cart_messages');
1519 1519
 
1520
-    if ( $messages ) {
1521
-        foreach ( $messages as $message_id => $message ) {
1520
+    if ($messages) {
1521
+        foreach ($messages as $message_id => $message) {
1522 1522
             // Try and detect what type of message this is
1523
-            if ( strpos( strtolower( $message ), 'error' ) ) {
1523
+            if (strpos(strtolower($message), 'error')) {
1524 1524
                 $type = 'error';
1525
-            } elseif ( strpos( strtolower( $message ), 'success' ) ) {
1525
+            } elseif (strpos(strtolower($message), 'success')) {
1526 1526
                 $type = 'success';
1527 1527
             } else {
1528 1528
                 $type = 'info';
1529 1529
             }
1530 1530
 
1531
-            $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) );
1531
+            $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type));
1532 1532
 
1533
-            echo '<div class="' . implode( ' ', $classes ) . '">';
1533
+            echo '<div class="' . implode(' ', $classes) . '">';
1534 1534
                 // Loop message codes and display messages
1535 1535
                     echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>';
1536 1536
             echo '</div>';
1537 1537
         }
1538 1538
 
1539 1539
         // Remove all of the cart saving messages
1540
-        $wpi_session->set( 'wpinv_cart_messages', null );
1540
+        $wpi_session->set('wpinv_cart_messages', null);
1541 1541
     }
1542 1542
 }
1543
-add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' );
1543
+add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages');
1544 1544
 
1545 1545
 function wpinv_discount_field() {
1546
-    if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) {
1546
+    if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) {
1547 1547
         return; // Only show before a payment method has been selected if ajax is disabled
1548 1548
     }
1549 1549
 
1550
-    if ( !wpinv_is_checkout() ) {
1550
+    if (!wpinv_is_checkout()) {
1551 1551
         return;
1552 1552
     }
1553 1553
 
1554
-    if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) {
1554
+    if (wpinv_has_active_discounts() && wpinv_get_cart_total()) {
1555 1555
     ?>
1556 1556
     <div id="wpinv-discount-field" class="panel panel-default">
1557 1557
         <div class="panel-body">
1558 1558
             <p>
1559
-                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label>
1560
-                <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span>
1559
+                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label>
1560
+                <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span>
1561 1561
             </p>
1562 1562
             <div class="form-group row">
1563 1563
                 <div class="col-sm-4">
1564
-                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/>
1564
+                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/>
1565 1565
                 </div>
1566 1566
                 <div class="col-sm-3">
1567
-                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button>
1567
+                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button>
1568 1568
                 </div>
1569 1569
                 <div style="clear:both"></div>
1570 1570
                 <div class="col-sm-12 wpinv-discount-msg">
@@ -1577,10 +1577,10 @@  discard block
 block discarded – undo
1577 1577
 <?php
1578 1578
     }
1579 1579
 }
1580
-add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 );
1580
+add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10);
1581 1581
 
1582 1582
 function wpinv_agree_to_terms_js() {
1583
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
1583
+    if (wpinv_get_option('show_agree_to_terms', false)) {
1584 1584
 ?>
1585 1585
 <script type="text/javascript">
1586 1586
     jQuery(document).ready(function($){
@@ -1595,73 +1595,73 @@  discard block
 block discarded – undo
1595 1595
 <?php
1596 1596
     }
1597 1597
 }
1598
-add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' );
1598
+add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js');
1599 1599
 
1600 1600
 function wpinv_checkout_billing_info() {
1601
-    if ( wpinv_is_checkout() ) {
1601
+    if (wpinv_is_checkout()) {
1602 1602
         $billing_details    = wpinv_checkout_billing_details();
1603
-        $selected_country   = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country();
1603
+        $selected_country   = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country();
1604 1604
         ?>
1605 1605
         <div id="wpinv-fields" class="clearfix">
1606 1606
             <div id="wpi-billing" class="wpi-billing clearfix panel panel-default">
1607
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div>
1607
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div>
1608 1608
                 <div id="wpinv-fields-box" class="panel-body">
1609
-                    <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?>
1609
+                    <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?>
1610 1610
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1611
-                        <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><?php if ( wpinv_get_option( 'fname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1611
+                        <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><?php if (wpinv_get_option('fname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1612 1612
                         <?php
1613
-                        echo wpinv_html_text( array(
1613
+                        echo wpinv_html_text(array(
1614 1614
                                 'id'            => 'wpinv_first_name',
1615 1615
                                 'name'          => 'wpinv_first_name',
1616 1616
                                 'value'         => $billing_details['first_name'],
1617 1617
                                 'class'         => 'wpi-input form-control',
1618
-                                'placeholder'   => __( 'First name', 'invoicing' ),
1619
-                                'required'      => (bool)wpinv_get_option( 'fname_mandatory' ),
1620
-                            ) );
1618
+                                'placeholder'   => __('First name', 'invoicing'),
1619
+                                'required'      => (bool) wpinv_get_option('fname_mandatory'),
1620
+                            ));
1621 1621
                         ?>
1622 1622
                     </p>
1623 1623
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1624
-                        <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?><?php if ( wpinv_get_option( 'lname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1624
+                        <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?><?php if (wpinv_get_option('lname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1625 1625
                         <?php
1626
-                        echo wpinv_html_text( array(
1626
+                        echo wpinv_html_text(array(
1627 1627
                                 'id'            => 'wpinv_last_name',
1628 1628
                                 'name'          => 'wpinv_last_name',
1629 1629
                                 'value'         => $billing_details['last_name'],
1630 1630
                                 'class'         => 'wpi-input form-control',
1631
-                                'placeholder'   => __( 'Last name', 'invoicing' ),
1632
-                                'required'      => (bool)wpinv_get_option( 'lname_mandatory' ),
1633
-                            ) );
1631
+                                'placeholder'   => __('Last name', 'invoicing'),
1632
+                                'required'      => (bool) wpinv_get_option('lname_mandatory'),
1633
+                            ));
1634 1634
                         ?>
1635 1635
                     </p>
1636 1636
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1637
-                        <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><?php if ( wpinv_get_option( 'address_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1637
+                        <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><?php if (wpinv_get_option('address_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1638 1638
                         <?php
1639
-                        echo wpinv_html_text( array(
1639
+                        echo wpinv_html_text(array(
1640 1640
                                 'id'            => 'wpinv_address',
1641 1641
                                 'name'          => 'wpinv_address',
1642 1642
                                 'value'         => $billing_details['address'],
1643 1643
                                 'class'         => 'wpi-input form-control',
1644
-                                'placeholder'   => __( 'Address', 'invoicing' ),
1645
-                                'required'      => (bool)wpinv_get_option( 'address_mandatory' ),
1646
-                            ) );
1644
+                                'placeholder'   => __('Address', 'invoicing'),
1645
+                                'required'      => (bool) wpinv_get_option('address_mandatory'),
1646
+                            ));
1647 1647
                         ?>
1648 1648
                     </p>
1649 1649
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1650
-                        <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><?php if ( wpinv_get_option( 'city_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1650
+                        <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><?php if (wpinv_get_option('city_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1651 1651
                         <?php
1652
-                        echo wpinv_html_text( array(
1652
+                        echo wpinv_html_text(array(
1653 1653
                                 'id'            => 'wpinv_city',
1654 1654
                                 'name'          => 'wpinv_city',
1655 1655
                                 'value'         => $billing_details['city'],
1656 1656
                                 'class'         => 'wpi-input form-control',
1657
-                                'placeholder'   => __( 'City', 'invoicing' ),
1658
-                                'required'      => (bool)wpinv_get_option( 'city_mandatory' ),
1659
-                            ) );
1657
+                                'placeholder'   => __('City', 'invoicing'),
1658
+                                'required'      => (bool) wpinv_get_option('city_mandatory'),
1659
+                            ));
1660 1660
                         ?>
1661 1661
                     </p>
1662 1662
                     <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf">
1663
-                        <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><?php if ( wpinv_get_option( 'country_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1664
-                        <?php echo wpinv_html_select( array(
1663
+                        <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><?php if (wpinv_get_option('country_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1664
+                        <?php echo wpinv_html_select(array(
1665 1665
                             'options'          => wpinv_get_country_list(),
1666 1666
                             'name'             => 'wpinv_country',
1667 1667
                             'id'               => 'wpinv_country',
@@ -1669,16 +1669,16 @@  discard block
 block discarded – undo
1669 1669
                             'show_option_all'  => false,
1670 1670
                             'show_option_none' => false,
1671 1671
                             'class'            => 'wpi-input form-control wpi_select2',
1672
-                            'placeholder'      => __( 'Choose a country', 'invoicing' ),
1673
-                            'required'         => (bool)wpinv_get_option( 'country_mandatory' ),
1674
-                        ) ); ?>
1672
+                            'placeholder'      => __('Choose a country', 'invoicing'),
1673
+                            'required'         => (bool) wpinv_get_option('country_mandatory'),
1674
+                        )); ?>
1675 1675
                     </p>
1676 1676
                     <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll">
1677
-                        <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><?php if ( wpinv_get_option( 'state_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1677
+                        <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><?php if (wpinv_get_option('state_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1678 1678
                         <?php
1679
-                        $states = wpinv_get_country_states( $selected_country );
1680
-                        if( !empty( $states ) ) {
1681
-                            echo wpinv_html_select( array(
1679
+                        $states = wpinv_get_country_states($selected_country);
1680
+                        if (!empty($states)) {
1681
+                            echo wpinv_html_select(array(
1682 1682
                                 'options'          => $states,
1683 1683
                                 'name'             => 'wpinv_state',
1684 1684
                                 'id'               => 'wpinv_state',
@@ -1686,61 +1686,61 @@  discard block
 block discarded – undo
1686 1686
                                 'show_option_all'  => false,
1687 1687
                                 'show_option_none' => false,
1688 1688
                                 'class'            => 'wpi-input form-control wpi_select2',
1689
-                                'placeholder'      => __( 'Choose a state', 'invoicing' ),
1690
-                                'required'         => (bool)wpinv_get_option( 'state_mandatory' ),
1691
-                            ) );
1689
+                                'placeholder'      => __('Choose a state', 'invoicing'),
1690
+                                'required'         => (bool) wpinv_get_option('state_mandatory'),
1691
+                            ));
1692 1692
                         } else {
1693
-                            echo wpinv_html_text( array(
1693
+                            echo wpinv_html_text(array(
1694 1694
                                 'name'          => 'wpinv_state',
1695 1695
                                 'value'         => $billing_details['state'],
1696 1696
                                 'id'            => 'wpinv_state',
1697 1697
                                 'class'         => 'wpi-input form-control',
1698
-                                'placeholder'   => __( 'State / Province', 'invoicing' ),
1699
-                                'required'      => (bool)wpinv_get_option( 'state_mandatory' ),
1700
-                            ) );
1698
+                                'placeholder'   => __('State / Province', 'invoicing'),
1699
+                                'required'      => (bool) wpinv_get_option('state_mandatory'),
1700
+                            ));
1701 1701
                         }
1702 1702
                         ?>
1703 1703
                     </p>
1704 1704
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1705
-                        <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?><?php if ( wpinv_get_option( 'zip_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1705
+                        <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?><?php if (wpinv_get_option('zip_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1706 1706
                         <?php
1707
-                        echo wpinv_html_text( array(
1707
+                        echo wpinv_html_text(array(
1708 1708
                                 'name'          => 'wpinv_zip',
1709 1709
                                 'value'         => $billing_details['zip'],
1710 1710
                                 'id'            => 'wpinv_zip',
1711 1711
                                 'class'         => 'wpi-input form-control',
1712
-                                'placeholder'   => __( 'ZIP / Postcode', 'invoicing' ),
1713
-                                'required'      => (bool)wpinv_get_option( 'zip_mandatory' ),
1714
-                            ) );
1712
+                                'placeholder'   => __('ZIP / Postcode', 'invoicing'),
1713
+                                'required'      => (bool) wpinv_get_option('zip_mandatory'),
1714
+                            ));
1715 1715
                         ?>
1716 1716
                     </p>
1717 1717
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1718
-                        <label for="wpinv_phone" class="wpi-label"><?php _e( 'Phone', 'invoicing' );?><?php if ( wpinv_get_option( 'phone_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1718
+                        <label for="wpinv_phone" class="wpi-label"><?php _e('Phone', 'invoicing'); ?><?php if (wpinv_get_option('phone_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1719 1719
                         <?php
1720
-                        echo wpinv_html_text( array(
1720
+                        echo wpinv_html_text(array(
1721 1721
                                 'id'            => 'wpinv_phone',
1722 1722
                                 'name'          => 'wpinv_phone',
1723 1723
                                 'value'         => $billing_details['phone'],
1724 1724
                                 'class'         => 'wpi-input form-control',
1725
-                                'placeholder'   => __( 'Phone', 'invoicing' ),
1726
-                                'required'      => (bool)wpinv_get_option( 'phone_mandatory' ),
1727
-                            ) );
1725
+                                'placeholder'   => __('Phone', 'invoicing'),
1726
+                                'required'      => (bool) wpinv_get_option('phone_mandatory'),
1727
+                            ));
1728 1728
                         ?>
1729 1729
                     </p>
1730
-                    <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?>
1730
+                    <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?>
1731 1731
                     <div class="clearfix"></div>
1732 1732
                 </div>
1733 1733
             </div>
1734
-            <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?>
1734
+            <?php do_action('wpinv_after_billing_fields', $billing_details); ?>
1735 1735
         </div>
1736 1736
         <?php
1737 1737
     }
1738 1738
 }
1739
-add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' );
1739
+add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info');
1740 1740
 
1741 1741
 function wpinv_checkout_hidden_fields() {
1742 1742
 ?>
1743
-    <?php if ( is_user_logged_in() ) { ?>
1743
+    <?php if (is_user_logged_in()) { ?>
1744 1744
     <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/>
1745 1745
     <?php } ?>
1746 1746
     <input type="hidden" name="wpi_action" value="payment" />
@@ -1750,9 +1750,9 @@  discard block
 block discarded – undo
1750 1750
 function wpinv_checkout_button_purchase() {
1751 1751
     ob_start();
1752 1752
 ?>
1753
-    <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>" name="wpinv_payment" value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>"/>
1753
+    <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>" name="wpinv_payment" value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>"/>
1754 1754
 <?php
1755
-    return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() );
1755
+    return apply_filters('wpinv_checkout_button_purchase', ob_get_clean());
1756 1756
 }
1757 1757
 
1758 1758
 function wpinv_checkout_total() {
@@ -1761,64 +1761,64 @@  discard block
 block discarded – undo
1761 1761
 <div id="wpinv_checkout_total" class="panel panel-info">
1762 1762
     <div class="panel-body">
1763 1763
     <?php
1764
-    do_action( 'wpinv_purchase_form_before_checkout_total' );
1764
+    do_action('wpinv_purchase_form_before_checkout_total');
1765 1765
     ?>
1766
-    <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span>
1766
+    <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span>
1767 1767
     <?php
1768
-    do_action( 'wpinv_purchase_form_after_checkout_total' );
1768
+    do_action('wpinv_purchase_form_after_checkout_total');
1769 1769
     ?>
1770 1770
     </div>
1771 1771
 </div>
1772 1772
 <?php
1773 1773
 }
1774
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 );
1774
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998);
1775 1775
 
1776 1776
 function wpinv_checkout_submit() {
1777 1777
 ?>
1778 1778
 <div id="wpinv_purchase_submit" class="panel panel-success">
1779 1779
     <div class="panel-body text-center">
1780 1780
     <?php
1781
-    do_action( 'wpinv_purchase_form_before_submit' );
1781
+    do_action('wpinv_purchase_form_before_submit');
1782 1782
     wpinv_checkout_hidden_fields();
1783 1783
     echo wpinv_checkout_button_purchase();
1784
-    do_action( 'wpinv_purchase_form_after_submit' );
1784
+    do_action('wpinv_purchase_form_after_submit');
1785 1785
     ?>
1786 1786
     </div>
1787 1787
 </div>
1788 1788
 <?php
1789 1789
 }
1790
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 );
1790
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999);
1791 1791
 
1792
-function wpinv_receipt_billing_address( $invoice_id = 0 ) {
1793
-    $invoice = wpinv_get_invoice( $invoice_id );
1792
+function wpinv_receipt_billing_address($invoice_id = 0) {
1793
+    $invoice = wpinv_get_invoice($invoice_id);
1794 1794
 
1795
-    if ( empty( $invoice ) ) {
1795
+    if (empty($invoice)) {
1796 1796
         return NULL;
1797 1797
     }
1798 1798
 
1799 1799
     $billing_details = $invoice->get_user_info();
1800
-    $address_row = wpinv_get_invoice_address_markup( $billing_details );
1800
+    $address_row = wpinv_get_invoice_address_markup($billing_details);
1801 1801
 
1802 1802
     ob_start();
1803 1803
     ?>
1804 1804
     <table class="table table-bordered table-sm wpi-billing-details">
1805 1805
         <tbody>
1806 1806
             <tr class="wpi-receipt-name">
1807
-                <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th>
1808
-                <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td>
1807
+                <th class="text-left"><?php _e('Name', 'invoicing'); ?></th>
1808
+                <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td>
1809 1809
             </tr>
1810 1810
             <tr class="wpi-receipt-email">
1811
-                <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th>
1812
-                <td><?php echo $billing_details['email'] ;?></td>
1811
+                <th class="text-left"><?php _e('Email', 'invoicing'); ?></th>
1812
+                <td><?php echo $billing_details['email']; ?></td>
1813 1813
             </tr>
1814 1814
             <tr class="wpi-receipt-address">
1815
-                <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th>
1816
-                <td><?php echo $address_row ;?></td>
1815
+                <th class="text-left"><?php _e('Address', 'invoicing'); ?></th>
1816
+                <td><?php echo $address_row; ?></td>
1817 1817
             </tr>
1818
-            <?php if ( $billing_details['phone'] ) { ?>
1818
+            <?php if ($billing_details['phone']) { ?>
1819 1819
             <tr class="wpi-receipt-phone">
1820
-                <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th>
1821
-                <td><?php echo esc_html( $billing_details['phone'] ) ;?></td>
1820
+                <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th>
1821
+                <td><?php echo esc_html($billing_details['phone']); ?></td>
1822 1822
             </tr>
1823 1823
             <?php } ?>
1824 1824
         </tbody>
@@ -1826,74 +1826,74 @@  discard block
 block discarded – undo
1826 1826
     <?php
1827 1827
     $output = ob_get_clean();
1828 1828
     
1829
-    $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id );
1829
+    $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id);
1830 1830
 
1831 1831
     echo $output;
1832 1832
 }
1833 1833
 
1834
-function wpinv_filter_success_page_content( $content ) {
1835
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1836
-        if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) {
1837
-            $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content );
1834
+function wpinv_filter_success_page_content($content) {
1835
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1836
+        if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) {
1837
+            $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content);
1838 1838
         }
1839 1839
     }
1840 1840
 
1841 1841
     return $content;
1842 1842
 }
1843
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1843
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1844 1844
 
1845
-function wpinv_receipt_actions( $invoice ) {
1846
-    if ( !empty( $invoice ) ) {
1845
+function wpinv_receipt_actions($invoice) {
1846
+    if (!empty($invoice)) {
1847 1847
         $actions = array();
1848 1848
 
1849
-        if ( wpinv_user_can_view_invoice( $invoice->ID ) ) {
1850
-            $actions['print']   = array(
1851
-                'url'  => $invoice->get_view_url( true ),
1852
-                'name' => __( 'Print Invoice', 'invoicing' ),
1849
+        if (wpinv_user_can_view_invoice($invoice->ID)) {
1850
+            $actions['print'] = array(
1851
+                'url'  => $invoice->get_view_url(true),
1852
+                'name' => __('Print Invoice', 'invoicing'),
1853 1853
                 'class' => 'btn-primary',
1854 1854
             );
1855 1855
         }
1856 1856
 
1857
-        if ( is_user_logged_in() ) {
1857
+        if (is_user_logged_in()) {
1858 1858
             $actions['history'] = array(
1859 1859
                 'url'  => wpinv_get_history_page_uri(),
1860
-                'name' => __( 'Invoice History', 'invoicing' ),
1860
+                'name' => __('Invoice History', 'invoicing'),
1861 1861
                 'class' => 'btn-warning',
1862 1862
             );
1863 1863
         }
1864 1864
 
1865
-        $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice );
1865
+        $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice);
1866 1866
 
1867
-        if ( !empty( $actions ) ) {
1867
+        if (!empty($actions)) {
1868 1868
         ?>
1869 1869
         <div class="wpinv-receipt-actions text-right">
1870
-            <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?>
1871
-            <a href="<?php echo esc_url( $action['url'] );?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class( $key );?>" <?php echo ( !empty($action['attrs']) ? $action['attrs'] : '' ) ;?>><?php echo esc_html( $action['name'] );?></a>
1870
+            <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?>
1871
+            <a href="<?php echo esc_url($action['url']); ?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class($key); ?>" <?php echo (!empty($action['attrs']) ? $action['attrs'] : ''); ?>><?php echo esc_html($action['name']); ?></a>
1872 1872
             <?php } ?>
1873 1873
         </div>
1874 1874
         <?php
1875 1875
         }
1876 1876
     }
1877 1877
 }
1878
-add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 );
1878
+add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1);
1879 1879
 
1880
-function wpinv_invoice_link( $invoice_id ) {
1881
-    $invoice = wpinv_get_invoice( $invoice_id );
1880
+function wpinv_invoice_link($invoice_id) {
1881
+    $invoice = wpinv_get_invoice($invoice_id);
1882 1882
 
1883
-    if ( empty( $invoice ) ) {
1883
+    if (empty($invoice)) {
1884 1884
         return NULL;
1885 1885
     }
1886 1886
 
1887
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1887
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1888 1888
 
1889
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1889
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1890 1890
 }
1891 1891
 
1892
-function wpinv_invoice_subscription_details( $invoice ) {
1893
-    if ( !empty( $invoice ) && $invoice->is_recurring() && ! wpinv_is_subscription_payment( $invoice ) ) {
1894
-        $subscription = wpinv_get_subscription( $invoice, true );
1892
+function wpinv_invoice_subscription_details($invoice) {
1893
+    if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) {
1894
+        $subscription = wpinv_get_subscription($invoice, true);
1895 1895
 
1896
-        if ( empty( $subscription ) ) {
1896
+        if (empty($subscription)) {
1897 1897
             return;
1898 1898
         }
1899 1899
 
@@ -1904,15 +1904,15 @@  discard block
 block discarded – undo
1904 1904
         $payments = $subscription->get_child_payments();
1905 1905
         ?>
1906 1906
         <div class="wpinv-subscriptions-details">
1907
-            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3>
1907
+            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3>
1908 1908
             <table class="table">
1909 1909
                 <thead>
1910 1910
                     <tr>
1911
-                        <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th>
1912
-                        <th><?php _e( 'Start Date', 'invoicing' ) ;?></th>
1913
-                        <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th>
1914
-                        <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th>
1915
-                        <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th>
1911
+                        <th><?php _e('Billing Cycle', 'invoicing'); ?></th>
1912
+                        <th><?php _e('Start Date', 'invoicing'); ?></th>
1913
+                        <th><?php _e('Expiration Date', 'invoicing'); ?></th>
1914
+                        <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th>
1915
+                        <th class="text-center"><?php _e('Status', 'invoicing'); ?></th>
1916 1916
                     </tr>
1917 1917
                 </thead>
1918 1918
                 <tbody>
@@ -1926,29 +1926,29 @@  discard block
 block discarded – undo
1926 1926
                 </tbody>
1927 1927
             </table>
1928 1928
         </div>
1929
-        <?php if ( !empty( $payments ) ) { ?>
1929
+        <?php if (!empty($payments)) { ?>
1930 1930
         <div class="wpinv-renewal-payments">
1931
-            <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3>
1931
+            <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3>
1932 1932
             <table class="table">
1933 1933
                 <thead>
1934 1934
                     <tr>
1935 1935
                         <th>#</th>
1936
-                        <th><?php _e( 'Invoice', 'invoicing' ) ;?></th>
1937
-                        <th><?php _e( 'Date', 'invoicing' ) ;?></th>
1938
-                        <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th>
1936
+                        <th><?php _e('Invoice', 'invoicing'); ?></th>
1937
+                        <th><?php _e('Date', 'invoicing'); ?></th>
1938
+                        <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th>
1939 1939
                     </tr>
1940 1940
                 </thead>
1941 1941
                 <tbody>
1942 1942
                     <?php
1943 1943
                         $i = 1;
1944
-                        foreach ( $payments as $payment ) {
1944
+                        foreach ($payments as $payment) {
1945 1945
                             $invoice_id = $payment->ID;
1946 1946
                     ?>
1947 1947
                     <tr>
1948
-                        <th scope="row"><?php echo $i;?></th>
1949
-                        <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td>
1950
-                        <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td>
1951
-                        <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td>
1948
+                        <th scope="row"><?php echo $i; ?></th>
1949
+                        <td><?php echo wpinv_invoice_link($invoice_id); ?></td>
1950
+                        <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td>
1951
+                        <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td>
1952 1952
                     </tr>
1953 1953
                     <?php $i++; } ?>
1954 1954
                 </tbody>
@@ -1959,52 +1959,52 @@  discard block
 block discarded – undo
1959 1959
     }
1960 1960
 }
1961 1961
 
1962
-function wpinv_cart_total_label( $label, $invoice ) {
1963
-    if ( empty( $invoice ) ) {
1962
+function wpinv_cart_total_label($label, $invoice) {
1963
+    if (empty($invoice)) {
1964 1964
         return $label;
1965 1965
     }
1966 1966
 
1967 1967
     $prefix_label = '';
1968
-    if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) {
1969
-        $prefix_label   = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice );
1970
-    } else if ( $invoice->is_renewal() ) {
1971
-        $prefix_label   = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> ';        
1968
+    if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) {
1969
+        $prefix_label   = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice);
1970
+    } else if ($invoice->is_renewal()) {
1971
+        $prefix_label   = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> ';        
1972 1972
     }
1973 1973
 
1974
-    if ( $prefix_label != '' ) {
1975
-        $label  = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
1974
+    if ($prefix_label != '') {
1975
+        $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
1976 1976
     }
1977 1977
 
1978 1978
     return $label;
1979 1979
 }
1980
-add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
1981
-add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
1982
-add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
1980
+add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2);
1981
+add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2);
1982
+add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2);
1983 1983
 
1984
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 );
1984
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1);
1985 1985
 
1986
-function wpinv_invoice_print_description( $invoice ) {
1987
-    if ( empty( $invoice ) ) {
1986
+function wpinv_invoice_print_description($invoice) {
1987
+    if (empty($invoice)) {
1988 1988
         return NULL;
1989 1989
     }
1990
-    if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) {
1990
+    if ($description = wpinv_get_invoice_description($invoice->ID)) {
1991 1991
         ?>
1992 1992
         <div class="row wpinv-lower">
1993 1993
             <div class="col-sm-12 wpinv-description">
1994
-                <?php echo wpautop( $description ); ?>
1994
+                <?php echo wpautop($description); ?>
1995 1995
             </div>
1996 1996
         </div>
1997 1997
         <?php
1998 1998
     }
1999 1999
 }
2000
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 );
2000
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1);
2001 2001
 
2002
-function wpinv_invoice_print_payment_info( $invoice ) {
2003
-    if ( empty( $invoice ) ) {
2002
+function wpinv_invoice_print_payment_info($invoice) {
2003
+    if (empty($invoice)) {
2004 2004
         return NULL;
2005 2005
     }
2006 2006
 
2007
-    if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) {
2007
+    if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) {
2008 2008
         ?>
2009 2009
         <div class="row wpinv-payments">
2010 2010
             <div class="col-sm-12">
@@ -2016,43 +2016,43 @@  discard block
 block discarded – undo
2016 2016
 }
2017 2017
 // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 );
2018 2018
 
2019
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
2020
-    if ( empty( $note ) ) {
2019
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
2020
+    if (empty($note)) {
2021 2021
         return NULL;
2022 2022
     }
2023 2023
 
2024
-    if ( is_int( $note ) ) {
2025
-        $note = get_comment( $note );
2024
+    if (is_int($note)) {
2025
+        $note = get_comment($note);
2026 2026
     }
2027 2027
 
2028
-    if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
2028
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
2029 2029
         return NULL;
2030 2030
     }
2031 2031
 
2032
-    $note_classes   = array( 'note' );
2033
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
2032
+    $note_classes   = array('note');
2033
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
2034 2034
     $note_classes[] = $note->comment_author === 'System' ? 'system-note' : '';
2035
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
2036
-    $note_classes   = !empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
2035
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
2036
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
2037 2037
 
2038 2038
     ob_start();
2039 2039
     ?>
2040
-    <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>">
2040
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>">
2041 2041
         <div class="note_content">
2042
-            <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
2042
+            <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?>
2043 2043
         </div>
2044 2044
         <p class="meta">
2045
-            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr>&nbsp;&nbsp;
2046
-            <?php if ( is_admin() && ( $note->comment_author !== 'System' || wpinv_current_user_can_manage_invoicing() ) ) { ?>
2047
-                <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a>
2045
+            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr>&nbsp;&nbsp;
2046
+            <?php if (is_admin() && ($note->comment_author !== 'System' || wpinv_current_user_can_manage_invoicing())) { ?>
2047
+                <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
2048 2048
             <?php } ?>
2049 2049
         </p>
2050 2050
     </li>
2051 2051
     <?php
2052 2052
     $note_content = ob_get_clean();
2053
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
2053
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
2054 2054
 
2055
-    if ( $echo ) {
2055
+    if ($echo) {
2056 2056
         echo $note_content;
2057 2057
     } else {
2058 2058
         return $note_content;
@@ -2062,43 +2062,43 @@  discard block
 block discarded – undo
2062 2062
 function wpinv_invalid_invoice_content() {
2063 2063
     global $post;
2064 2064
 
2065
-    $invoice = wpinv_get_invoice( $post->ID );
2065
+    $invoice = wpinv_get_invoice($post->ID);
2066 2066
 
2067
-    $error = __( 'This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing' );
2068
-    if ( !empty( $invoice->ID ) && $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) {
2069
-        if ( is_user_logged_in() ) {
2070
-            if ( wpinv_require_login_to_checkout() ) {
2071
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2072
-                    $error = __( 'You are not allowed to view this invoice.', 'invoicing' );
2067
+    $error = __('This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing');
2068
+    if (!empty($invoice->ID) && $invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) {
2069
+        if (is_user_logged_in()) {
2070
+            if (wpinv_require_login_to_checkout()) {
2071
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2072
+                    $error = __('You are not allowed to view this invoice.', 'invoicing');
2073 2073
                 }
2074 2074
             }
2075 2075
         } else {
2076
-            if ( wpinv_require_login_to_checkout() ) {
2077
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2078
-                    $error = __( 'You must be logged in to view this invoice.', 'invoicing' );
2076
+            if (wpinv_require_login_to_checkout()) {
2077
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2078
+                    $error = __('You must be logged in to view this invoice.', 'invoicing');
2079 2079
                 }
2080 2080
             }
2081 2081
         }
2082 2082
     } else {
2083
-        $error = __( 'This invoice is deleted or does not exist.', 'invoicing' );
2083
+        $error = __('This invoice is deleted or does not exist.', 'invoicing');
2084 2084
     }
2085 2085
     ?>
2086 2086
     <div class="row wpinv-row-invalid">
2087 2087
         <div class="col-md-6 col-md-offset-3 wpinv-message error">
2088
-            <h3><?php _e( 'Access Denied', 'invoicing' ); ?></h3>
2088
+            <h3><?php _e('Access Denied', 'invoicing'); ?></h3>
2089 2089
             <p class="wpinv-msg-text"><?php echo $error; ?></p>
2090 2090
         </div>
2091 2091
     </div>
2092 2092
     <?php
2093 2093
 }
2094
-add_action( 'wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content' );
2094
+add_action('wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content');
2095 2095
 
2096
-add_action( 'wpinv_checkout_billing_fields_last', 'wpinv_force_company_name_field');
2097
-function wpinv_force_company_name_field(){
2096
+add_action('wpinv_checkout_billing_fields_last', 'wpinv_force_company_name_field');
2097
+function wpinv_force_company_name_field() {
2098 2098
     $invoice = wpinv_get_invoice_cart();
2099
-    $user_id = wpinv_get_user_id( $invoice->ID );
2100
-    $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true );
2101
-    if ( 1 == wpinv_get_option( 'force_show_company' ) && !wpinv_use_taxes() ) {
2099
+    $user_id = wpinv_get_user_id($invoice->ID);
2100
+    $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true);
2101
+    if (1 == wpinv_get_option('force_show_company') && !wpinv_use_taxes()) {
2102 2102
         ?>
2103 2103
         <p class="wpi-cart-field wpi-col2 wpi-colf">
2104 2104
             <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label>
@@ -2124,21 +2124,21 @@  discard block
 block discarded – undo
2124 2124
  * @return string
2125 2125
  */
2126 2126
 function wpinv_get_policy_text() {
2127
-    $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 );
2127
+    $privacy_page_id = get_option('wp_page_for_privacy_policy', 0);
2128 2128
 
2129
-    $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' ));
2129
+    $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]'));
2130 2130
 
2131
-    if(!$privacy_page_id){
2132
-        $privacy_page_id = wpinv_get_option( 'privacy_page', 0 );
2131
+    if (!$privacy_page_id) {
2132
+        $privacy_page_id = wpinv_get_option('privacy_page', 0);
2133 2133
     }
2134 2134
 
2135
-    $privacy_link    = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' );
2135
+    $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing');
2136 2136
 
2137 2137
     $find_replace = array(
2138 2138
         '[wpinv_privacy_policy]' => $privacy_link,
2139 2139
     );
2140 2140
 
2141
-    $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text );
2141
+    $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text);
2142 2142
 
2143 2143
     return wp_kses_post(wpautop($privacy_text));
2144 2144
 }
@@ -2147,25 +2147,25 @@  discard block
 block discarded – undo
2147 2147
 /**
2148 2148
  * Allows the user to set their own price for an invoice item
2149 2149
  */
2150
-function wpinv_checkout_cart_item_name_your_price( $cart_item, $key ) {
2150
+function wpinv_checkout_cart_item_name_your_price($cart_item, $key) {
2151 2151
     
2152 2152
     //Ensure we have an item id
2153
-    if(! is_array( $cart_item ) || empty( $cart_item['id'] ) ) {
2153
+    if (!is_array($cart_item) || empty($cart_item['id'])) {
2154 2154
         return;
2155 2155
     }
2156 2156
 
2157 2157
     //Fetch the item
2158 2158
     $item_id = $cart_item['id'];
2159
-    $item    = new WPInv_Item( $item_id );
2159
+    $item    = new WPInv_Item($item_id);
2160 2160
     
2161
-    if(! $item->supports_dynamic_pricing() || !$item->get_is_dynamic_pricing() ) {
2161
+    if (!$item->supports_dynamic_pricing() || !$item->get_is_dynamic_pricing()) {
2162 2162
         return;
2163 2163
     }
2164 2164
 
2165 2165
     //Fetch the dynamic pricing "strings"
2166
-    $suggested_price_text = esc_html( wpinv_get_option( 'suggested_price_text', __( 'Suggested Price:', 'invoicing' ) ) );
2167
-    $minimum_price_text   = esc_html( wpinv_get_option( 'minimum_price_text', __( 'Minimum Price:', 'invoicing' ) ) );
2168
-    $name_your_price_text = esc_html( wpinv_get_option( 'name_your_price_text', __( 'Name Your Price', 'invoicing' ) ) );
2166
+    $suggested_price_text = esc_html(wpinv_get_option('suggested_price_text', __('Suggested Price:', 'invoicing')));
2167
+    $minimum_price_text   = esc_html(wpinv_get_option('minimum_price_text', __('Minimum Price:', 'invoicing')));
2168
+    $name_your_price_text = esc_html(wpinv_get_option('name_your_price_text', __('Name Your Price', 'invoicing')));
2169 2169
 
2170 2170
     //Display a "name_your_price" button
2171 2171
     echo " &mdash; <a href='#' class='wpinv-name-your-price-frontend small'>$name_your_price_text</a></div>";
@@ -2174,7 +2174,7 @@  discard block
 block discarded – undo
2174 2174
     echo '<div class="name-your-price-miniform">';
2175 2175
     
2176 2176
     //Maybe display the recommended price
2177
-    if( $item->get_price() > 0 && !empty( $suggested_price_text ) ) {
2177
+    if ($item->get_price() > 0 && !empty($suggested_price_text)) {
2178 2178
         $suggested_price = $item->get_the_price();
2179 2179
         echo "<div>$suggested_price_text &mdash; $suggested_price</div>";
2180 2180
     }
@@ -2182,52 +2182,52 @@  discard block
 block discarded – undo
2182 2182
     //Display the update price form
2183 2183
     $symbol         = wpinv_currency_symbol();
2184 2184
     $position       = wpinv_currency_position();
2185
-    $minimum        = esc_attr( $item->get_minimum_price() );
2186
-    $price          = esc_attr( $cart_item['item_price'] );
2187
-    $update         = esc_attr__( "Update", 'invoicing' );
2185
+    $minimum        = esc_attr($item->get_minimum_price());
2186
+    $price          = esc_attr($cart_item['item_price']);
2187
+    $update         = esc_attr__("Update", 'invoicing');
2188 2188
 
2189 2189
     //Ensure it supports dynamic prici
2190
-    if( $price < $minimum ) {
2190
+    if ($price < $minimum) {
2191 2191
         $price = $minimum;
2192 2192
     }
2193 2193
 
2194 2194
     echo '<label>';
2195 2195
     echo $position != 'right' ? $symbol . '&nbsp;' : '';
2196 2196
     echo "<input type='number' min='$minimum' placeholder='$price' value='$price' class='wpi-field-price' />";
2197
-    echo $position == 'right' ? '&nbsp;' . $symbol : '' ;
2197
+    echo $position == 'right' ? '&nbsp;' . $symbol : '';
2198 2198
     echo "</label>";
2199 2199
     echo "<input type='hidden' value='$item_id' class='wpi-field-item' />";
2200 2200
     echo "<a class='btn btn-success wpinv-submit wpinv-update-dynamic-price-frontend'>$update</a>";
2201 2201
 
2202 2202
     //Maybe display the minimum price
2203
-    if( $item->get_minimum_price() > 0 && !empty( $minimum_price_text ) ) {
2204
-        $minimum_price = wpinv_price( wpinv_format_amount( $item->get_minimum_price() ) );
2203
+    if ($item->get_minimum_price() > 0 && !empty($minimum_price_text)) {
2204
+        $minimum_price = wpinv_price(wpinv_format_amount($item->get_minimum_price()));
2205 2205
         echo "<div>$minimum_price_text &mdash; $minimum_price</div>";
2206 2206
     }
2207 2207
 
2208 2208
     echo "</div>";
2209 2209
 
2210 2210
 }
2211
-add_action( 'wpinv_checkout_cart_item_price_after', 'wpinv_checkout_cart_item_name_your_price', 10, 2 );
2211
+add_action('wpinv_checkout_cart_item_price_after', 'wpinv_checkout_cart_item_name_your_price', 10, 2);
2212 2212
 
2213 2213
 function wpinv_oxygen_fix_conflict() {
2214 2214
     global $ct_ignore_post_types;
2215 2215
 
2216
-    if ( ! is_array( $ct_ignore_post_types ) ) {
2216
+    if (!is_array($ct_ignore_post_types)) {
2217 2217
         $ct_ignore_post_types = array();
2218 2218
     }
2219 2219
 
2220
-    $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item' );
2220
+    $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item');
2221 2221
 
2222
-    foreach ( $post_types as $post_type ) {
2222
+    foreach ($post_types as $post_type) {
2223 2223
         $ct_ignore_post_types[] = $post_type;
2224 2224
 
2225 2225
         // Ignore post type
2226
-        add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 );
2226
+        add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999);
2227 2227
     }
2228 2228
 
2229
-    remove_filter( 'template_include', 'wpinv_template', 10, 1 );
2230
-    add_filter( 'template_include', 'wpinv_template', 999, 1 );
2229
+    remove_filter('template_include', 'wpinv_template', 10, 1);
2230
+    add_filter('template_include', 'wpinv_template', 999, 1);
2231 2231
 }
2232 2232
 
2233 2233
 /**
@@ -2235,10 +2235,10 @@  discard block
 block discarded – undo
2235 2235
  * 
2236 2236
  * @param GetPaid_Payment_Form $form
2237 2237
  */
2238
-function getpaid_display_payment_form( $form ) {
2238
+function getpaid_display_payment_form($form) {
2239 2239
 
2240
-    if ( is_numeric( $form ) ) {
2241
-        $form = new GetPaid_Payment_Form( $form );
2240
+    if (is_numeric($form)) {
2241
+        $form = new GetPaid_Payment_Form($form);
2242 2242
     }
2243 2243
 
2244 2244
     $form->display();
@@ -2248,124 +2248,124 @@  discard block
 block discarded – undo
2248 2248
 /**
2249 2249
  * Helper function to display a item payment form on the frontend.
2250 2250
  */
2251
-function getpaid_display_item_payment_form( $items ) {
2251
+function getpaid_display_item_payment_form($items) {
2252 2252
     global $invoicing;
2253 2253
 
2254
-    foreach ( array_keys( $items ) as $id ) {
2255
-	    if ( 'publish' != get_post_status( $id ) ) {
2256
-		    unset( $items[ $id ] );
2254
+    foreach (array_keys($items) as $id) {
2255
+	    if ('publish' != get_post_status($id)) {
2256
+		    unset($items[$id]);
2257 2257
 	    }
2258 2258
     }
2259 2259
 
2260
-    if ( empty( $items ) ) {
2260
+    if (empty($items)) {
2261 2261
 		return aui()->alert(
2262 2262
 			array(
2263 2263
 				'type'    => 'warning',
2264
-				'content' => __( 'No published items found', 'invoicing' ),
2264
+				'content' => __('No published items found', 'invoicing'),
2265 2265
 			)
2266 2266
 		);
2267 2267
     }
2268 2268
 
2269
-    $item_key = getpaid_convert_items_to_string( $items );
2269
+    $item_key = getpaid_convert_items_to_string($items);
2270 2270
 
2271 2271
     // Get the form elements and items.
2272 2272
     $form     = wpinv_get_default_payment_form();
2273
-	$elements = $invoicing->form_elements->get_form_elements( $form );
2274
-	$items    = $invoicing->form_elements->convert_normal_items( $items );
2273
+	$elements = $invoicing->form_elements->get_form_elements($form);
2274
+	$items    = $invoicing->form_elements->convert_normal_items($items);
2275 2275
 
2276 2276
 	ob_start();
2277 2277
 	echo "<form class='wpinv_payment_form'>";
2278
-	do_action( 'wpinv_payment_form_top' );
2278
+	do_action('wpinv_payment_form_top');
2279 2279
     echo "<input type='hidden' name='form_id' value='$form'/>";
2280 2280
     echo "<input type='hidden' name='form_items' value='$item_key'/>";
2281
-	wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' );
2282
-	wp_nonce_field( 'vat_validation', '_wpi_nonce' );
2281
+	wp_nonce_field('wpinv_payment_form', 'wpinv_payment_form');
2282
+	wp_nonce_field('vat_validation', '_wpi_nonce');
2283 2283
 
2284
-	foreach ( $elements as $element ) {
2285
-		do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $form );
2286
-		do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form );
2284
+	foreach ($elements as $element) {
2285
+		do_action('wpinv_frontend_render_payment_form_element', $element, $items, $form);
2286
+		do_action("wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form);
2287 2287
 	}
2288 2288
 
2289 2289
 	echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>";
2290
-	do_action( 'wpinv_payment_form_bottom' );
2290
+	do_action('wpinv_payment_form_bottom');
2291 2291
 	echo '</form>';
2292 2292
 
2293 2293
 	$content = ob_get_clean();
2294
-	return str_replace( 'sr-only', '', $content );
2294
+	return str_replace('sr-only', '', $content);
2295 2295
 }
2296 2296
 
2297 2297
 /**
2298 2298
  * Helper function to display an invoice payment form on the frontend.
2299 2299
  */
2300
-function getpaid_display_invoice_payment_form( $invoice_id ) {
2300
+function getpaid_display_invoice_payment_form($invoice_id) {
2301 2301
     global $invoicing;
2302 2302
 
2303
-    $invoice = wpinv_get_invoice( $invoice_id );
2303
+    $invoice = wpinv_get_invoice($invoice_id);
2304 2304
 
2305
-    if ( empty( $invoice ) ) {
2305
+    if (empty($invoice)) {
2306 2306
 		return aui()->alert(
2307 2307
 			array(
2308 2308
 				'type'    => 'warning',
2309
-				'content' => __( 'Invoice not found', 'invoicing' ),
2309
+				'content' => __('Invoice not found', 'invoicing'),
2310 2310
 			)
2311 2311
 		);
2312 2312
     }
2313 2313
 
2314
-    if ( $invoice->is_paid() ) {
2314
+    if ($invoice->is_paid()) {
2315 2315
 		return aui()->alert(
2316 2316
 			array(
2317 2317
 				'type'    => 'warning',
2318
-				'content' => __( 'Invoice has already been paid', 'invoicing' ),
2318
+				'content' => __('Invoice has already been paid', 'invoicing'),
2319 2319
 			)
2320 2320
 		);
2321 2321
     }
2322 2322
 
2323 2323
     // Get the form elements and items.
2324
-    $form     = wpinv_get_default_payment_form();
2325
-	$elements = $invoicing->form_elements->get_form_elements( $form );
2326
-	$items    = $invoicing->form_elements->convert_checkout_items( $invoice->cart_details, $invoice );
2324
+    $form = wpinv_get_default_payment_form();
2325
+	$elements = $invoicing->form_elements->get_form_elements($form);
2326
+	$items    = $invoicing->form_elements->convert_checkout_items($invoice->cart_details, $invoice);
2327 2327
 
2328 2328
 	ob_start();
2329 2329
 	echo "<form class='wpinv_payment_form'>";
2330
-	do_action( 'wpinv_payment_form_top' );
2330
+	do_action('wpinv_payment_form_top');
2331 2331
     echo "<input type='hidden' name='form_id' value='$form'/>";
2332 2332
     echo "<input type='hidden' name='invoice_id' value='$invoice_id'/>";
2333
-	wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' );
2334
-	wp_nonce_field( 'vat_validation', '_wpi_nonce' );
2333
+	wp_nonce_field('wpinv_payment_form', 'wpinv_payment_form');
2334
+	wp_nonce_field('vat_validation', '_wpi_nonce');
2335 2335
 
2336
-	foreach ( $elements as $element ) {
2337
-		do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $form );
2338
-		do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form );
2336
+	foreach ($elements as $element) {
2337
+		do_action('wpinv_frontend_render_payment_form_element', $element, $items, $form);
2338
+		do_action("wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form);
2339 2339
 	}
2340 2340
 
2341 2341
 	echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>";
2342
-	do_action( 'wpinv_payment_form_bottom' );
2342
+	do_action('wpinv_payment_form_bottom');
2343 2343
 	echo '</form>';
2344 2344
 
2345 2345
 	$content = ob_get_clean();
2346
-	return str_replace( 'sr-only', '', $content );
2346
+	return str_replace('sr-only', '', $content);
2347 2347
 }
2348 2348
 
2349 2349
 /**
2350 2350
  * Helper function to convert item string to array.
2351 2351
  */
2352
-function getpaid_convert_items_to_array( $items ) {
2353
-    $items    = array_filter( array_map( 'trim', explode( ',', $items ) ) );
2352
+function getpaid_convert_items_to_array($items) {
2353
+    $items    = array_filter(array_map('trim', explode(',', $items)));
2354 2354
     $prepared = array();
2355 2355
 
2356
-    foreach ( $items as $item ) {
2357
-        $data = array_map( 'trim', explode( '|', $item ) );
2356
+    foreach ($items as $item) {
2357
+        $data = array_map('trim', explode('|', $item));
2358 2358
 
2359
-        if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) {
2359
+        if (empty($data[0]) || !is_numeric($data[0])) {
2360 2360
             continue;
2361 2361
         }
2362 2362
 
2363 2363
         $quantity = 1;
2364
-        if ( isset( $data[1] ) && is_numeric( $data[1] ) ) {
2364
+        if (isset($data[1]) && is_numeric($data[1])) {
2365 2365
             $quantity = $data[1];
2366 2366
         }
2367 2367
 
2368
-        $prepared[ $data[0] ] = $quantity;
2368
+        $prepared[$data[0]] = $quantity;
2369 2369
 
2370 2370
     }
2371 2371
 
@@ -2375,13 +2375,13 @@  discard block
 block discarded – undo
2375 2375
 /**
2376 2376
  * Helper function to convert item array to string.
2377 2377
  */
2378
-function getpaid_convert_items_to_string( $items ) {
2378
+function getpaid_convert_items_to_string($items) {
2379 2379
     $prepared = array();
2380 2380
 
2381
-    foreach ( $items as $item => $quantity ) {
2381
+    foreach ($items as $item => $quantity) {
2382 2382
         $prepared[] = "$item|$quantity";
2383 2383
     }
2384
-    return implode( ',', $prepared );
2384
+    return implode(',', $prepared);
2385 2385
 }
2386 2386
 
2387 2387
 /**
@@ -2389,22 +2389,22 @@  discard block
 block discarded – undo
2389 2389
  * 
2390 2390
  * Provide a label and one of $form, $items or $invoice.
2391 2391
  */
2392
-function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) {
2393
-    $label = sanitize_text_field( $label );
2392
+function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) {
2393
+    $label = sanitize_text_field($label);
2394 2394
     $nonce = wp_create_nonce('getpaid_ajax_form');
2395 2395
 
2396
-    if ( ! empty( $form ) ) {
2397
-        $form  = esc_attr( $form );
2396
+    if (!empty($form)) {
2397
+        $form = esc_attr($form);
2398 2398
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-form='$form'>$label</button>"; 
2399 2399
     }
2400 2400
 	
2401
-	if ( ! empty( $items ) ) {
2402
-        $items  = esc_attr( $items );
2401
+	if (!empty($items)) {
2402
+        $items = esc_attr($items);
2403 2403
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-item='$items'>$label</button>"; 
2404 2404
     }
2405 2405
     
2406
-    if ( ! empty( $invoice ) ) {
2407
-        $invoice  = esc_attr( $invoice );
2406
+    if (!empty($invoice)) {
2407
+        $invoice = esc_attr($invoice);
2408 2408
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-invoice='$invoice'>$label</button>"; 
2409 2409
     }
2410 2410
 
@@ -2415,15 +2415,15 @@  discard block
 block discarded – undo
2415 2415
  *
2416 2416
  * @param WPInv_Invoice $invoice
2417 2417
  */
2418
-function getpaid_the_invoice_description( $invoice ) {
2419
-    if ( empty( $invoice->description ) ) {
2418
+function getpaid_the_invoice_description($invoice) {
2419
+    if (empty($invoice->description)) {
2420 2420
         return;
2421 2421
     }
2422 2422
 
2423
-    $description = wp_kses_post( $invoice->description );
2423
+    $description = wp_kses_post($invoice->description);
2424 2424
     echo "<div style='color: #616161; font-size: 90%; margin-bottom: 20px;'><em>$description</em></div>";
2425 2425
 }
2426
-add_action( 'wpinv_invoice_print_before_line_items', 'getpaid_the_invoice_description' );
2426
+add_action('wpinv_invoice_print_before_line_items', 'getpaid_the_invoice_description');
2427 2427
 
2428 2428
 /**
2429 2429
  * Render element on a form.
@@ -2431,41 +2431,41 @@  discard block
 block discarded – undo
2431 2431
  * @param array $element
2432 2432
  * @param GetPaid_Payment_Form $form
2433 2433
  */
2434
-function getpaid_payment_form_element( $element, $form ) {
2434
+function getpaid_payment_form_element($element, $form) {
2435 2435
 
2436 2436
     // Set up the args.
2437
-    $element_type    = trim( $element['type'] );
2437
+    $element_type    = trim($element['type']);
2438 2438
     $element['form'] = $form;
2439
-    extract( $element );
2439
+    extract($element);
2440 2440
 
2441 2441
     // Try to locate the appropriate template.
2442
-    $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" );
2442
+    $located = wpinv_locate_template("payment-forms/elements/$element_type.php");
2443 2443
     
2444 2444
     // Abort if this is not our element.
2445
-    if ( empty( $located ) || ! file_exists( $located ) ) {
2445
+    if (empty($located) || !file_exists($located)) {
2446 2446
         return;
2447 2447
     }
2448 2448
 
2449 2449
     // Generate the class and id of the element.
2450
-    $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) );
2451
-    $id            = isset( $id ) ? $id : uniqid( 'gp' );
2450
+    $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type));
2451
+    $id            = isset($id) ? $id : uniqid('gp');
2452 2452
 
2453 2453
     // Echo the opening wrapper.
2454 2454
     echo "<div class='getpaid-payment-form-element $wrapper_class'>";
2455 2455
 
2456 2456
     // Fires before displaying a given element type's content.
2457
-    do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form );
2457
+    do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form);
2458 2458
 
2459 2459
     // Include the template for the element.
2460 2460
     include $located;
2461 2461
 
2462 2462
     // Fires after displaying a given element type's content.
2463
-    do_action( "getpaid_payment_form_{$element_type}_element", $element, $form );
2463
+    do_action("getpaid_payment_form_{$element_type}_element", $element, $form);
2464 2464
 
2465 2465
     // Echo the closing wrapper.
2466 2466
     echo '</div>';
2467 2467
 }
2468
-add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 );
2468
+add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2);
2469 2469
 
2470 2470
 /**
2471 2471
  * Shows a list of gateways that support recurring payments.
@@ -2473,16 +2473,16 @@  discard block
 block discarded – undo
2473 2473
 function wpinv_get_recurring_gateways_text() {
2474 2474
     $gateways = array();
2475 2475
 
2476
-    foreach ( wpinv_get_payment_gateways() as $key => $gateway ) {
2477
-        if ( wpinv_gateway_support_subscription( $key ) ) {
2478
-            $gateways[] = sanitize_text_field( $gateway['admin_label'] );
2476
+    foreach (wpinv_get_payment_gateways() as $key => $gateway) {
2477
+        if (wpinv_gateway_support_subscription($key)) {
2478
+            $gateways[] = sanitize_text_field($gateway['admin_label']);
2479 2479
         }
2480 2480
     }
2481 2481
 
2482
-    if ( empty( $gateways ) ) {
2483
-        return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) ."</span>";
2482
+    if (empty($gateways)) {
2483
+        return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . "</span>";
2484 2484
     }
2485 2485
 
2486
-    return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) ."</span>";
2486
+    return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . "</span>";
2487 2487
 
2488 2488
 }
Please login to merge, or discard this patch.
templates/wpinv-invoice-print.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -7,18 +7,18 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Fetch the invoice.
13
-$invoice = new WPInv_Invoice( $GLOBALS['post'] );
13
+$invoice = new WPInv_Invoice($GLOBALS['post']);
14 14
 
15 15
 // Abort if it does not exist.
16
-if ( $invoice->get_id() == 0 ) {
16
+if ($invoice->get_id() == 0) {
17 17
     exit;
18 18
 }
19 19
 
20 20
 // Fires before printing an invoice.
21
-do_action( 'wpinv_invoice_print_before_display', $invoice );
21
+do_action('wpinv_invoice_print_before_display', $invoice);
22 22
 
23 23
 ?><!DOCTYPE html>
24 24
 
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 
28 28
     <head>
29 29
 
30
-		<meta charset="<?php bloginfo( 'charset' ); ?>">
30
+		<meta charset="<?php bloginfo('charset'); ?>">
31 31
         <meta name="viewport" content="width=device-width, initial-scale=1.0" >
32 32
 
33 33
         <meta name="robots" content="noindex,nofollow">
@@ -36,15 +36,15 @@  discard block
 block discarded – undo
36 36
 
37 37
         <title><?php wp_title() ?></title>
38 38
 
39
-        <?php do_action( 'wpinv_invoice_print_head', $invoice ); ?>
39
+        <?php do_action('wpinv_invoice_print_head', $invoice); ?>
40 40
 
41 41
     </head>
42 42
     
43 43
 
44 44
     <body class="body wpinv wpinv-print">
45 45
 
46
-        <?php do_action( 'getpaid_invoice', $invoice ); ?>
47
-        <?php do_action( 'wpinv_invoice_print_body_end', $invoice ); ?>
46
+        <?php do_action('getpaid_invoice', $invoice); ?>
47
+        <?php do_action('wpinv_invoice_print_body_end', $invoice); ?>
48 48
 
49 49
     </body>
50 50
 
Please login to merge, or discard this patch.
templates/payment-forms/form.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -7,21 +7,21 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Make sure that the form is active.
13
-if ( ! $form->is_active() ) {
13
+if (!$form->is_active()) {
14 14
     echo aui()->alert(
15 15
         array(
16 16
             'type'    => 'warning',
17
-            'content' => __( 'This payment form is no longer active', 'invoicing' ),
17
+            'content' => __('This payment form is no longer active', 'invoicing'),
18 18
         )
19 19
     );
20 20
     return;
21 21
 }
22 22
 
23 23
 // Fires before displaying a payment form.
24
-do_action( 'getpaid_before_payment_form', $form );
24
+do_action('getpaid_before_payment_form', $form);
25 25
 
26 26
 ?>
27 27
 
@@ -31,44 +31,44 @@  discard block
 block discarded – undo
31 31
     <?php 
32 32
     
33 33
         // Fires when printing the top of a payment form.
34
-        do_action( 'getpaid_payment_form_top', $form );
34
+        do_action('getpaid_payment_form_top', $form);
35 35
 
36 36
         // Add the vat validation nonce.
37
-        wp_nonce_field( 'vat_validation', '_wpi_nonce' );
37
+        wp_nonce_field('vat_validation', '_wpi_nonce');
38 38
 
39 39
         // And the optional invoice id.
40
-        if ( ! empty( $form->invoice ) ) {
41
-            echo getpaid_hidden_field( 'invoice_id', $form->invoice->get_id() );
40
+        if (!empty($form->invoice)) {
41
+            echo getpaid_hidden_field('invoice_id', $form->invoice->get_id());
42 42
         }
43 43
 
44 44
         // We also want to include the form id.
45
-        echo getpaid_hidden_field( 'form_id', $form->get_id() );
45
+        echo getpaid_hidden_field('form_id', $form->get_id());
46 46
 
47 47
         // And an indication that this is a payment form submission.
48
-        echo getpaid_hidden_field( 'getpaid_payment_form_submission', '1' );
48
+        echo getpaid_hidden_field('getpaid_payment_form_submission', '1');
49 49
 
50 50
         // Fires before displaying payment form elements.
51
-        do_action( 'getpaid_payment_form_before_elements', $form );
51
+        do_action('getpaid_payment_form_before_elements', $form);
52 52
 
53 53
         // Display the elements.
54
-        foreach ( $form->get_elements() as $element ) {
55
-            if ( isset( $element['type'] ) ) {
56
-                do_action( 'getpaid_payment_form_element', $element, $form );
57
-                do_action( "getpaid_payment_form_element_{$element['type']}_template", $element, $form );
54
+        foreach ($form->get_elements() as $element) {
55
+            if (isset($element['type'])) {
56
+                do_action('getpaid_payment_form_element', $element, $form);
57
+                do_action("getpaid_payment_form_element_{$element['type']}_template", $element, $form);
58 58
             }
59 59
         }
60 60
 
61 61
         // Fires after displaying payment form elements.
62
-        do_action( 'getpaid_payment_form_after_elements', $form );
62
+        do_action('getpaid_payment_form_after_elements', $form);
63 63
 
64 64
         echo "<div class='getpaid-payment-form-errors alert alert-danger d-none'></div>";
65 65
 
66
-        if ( wpinv_current_user_can_manage_invoicing() ) {
66
+        if (wpinv_current_user_can_manage_invoicing()) {
67 67
 
68 68
             edit_post_link(
69
-                __( 'Edit this form.', 'invoicing' ),
69
+                __('Edit this form.', 'invoicing'),
70 70
                 '<small class="form-text text-muted">',
71
-                '&nbsp;' . __( 'This is only visible to website administators.', 'invoicing' ) . '</small>',
71
+                '&nbsp;' . __('This is only visible to website administators.', 'invoicing') . '</small>',
72 72
                 $form->get_id(),
73 73
                 'text-danger'
74 74
             );
@@ -82,4 +82,4 @@  discard block
 block discarded – undo
82 82
 <?php
83 83
 
84 84
 // Fires after displaying a payment form.
85
-do_action( 'getpaid_after_payment_form', $form );
85
+do_action('getpaid_after_payment_form', $form);
Please login to merge, or discard this patch.