Passed
Push — master ( 82fd8c...abf543 )
by Brian
04:42
created
includes/class-wpinv-legacy-invoice.php 1 patch
Spacing   +626 added lines, -626 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
 final class WPInv_Legacy_Invoice {
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
     /**
17 17
      * Invoice id.
18 18
      */
19
-    public $ID  = 0;
19
+    public $ID = 0;
20 20
 
21 21
     /**
22 22
      * The title of the invoice. Usually the invoice number.
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
     /**
133 133
      * The invoice status.
134 134
      */
135
-    public $status      = 'wpi-pending';
135
+    public $status = 'wpi-pending';
136 136
 
137 137
     /**
138 138
      * Same as self::$status.
@@ -259,17 +259,17 @@  discard block
 block discarded – undo
259 259
      */
260 260
     public $parent_invoice = 0;
261 261
     
262
-    public function __construct( $invoice_id = false ) {
263
-        if( empty( $invoice_id ) ) {
262
+    public function __construct($invoice_id = false) {
263
+        if (empty($invoice_id)) {
264 264
             return false;
265 265
         }
266 266
 
267
-        $this->setup_invoice( $invoice_id );
267
+        $this->setup_invoice($invoice_id);
268 268
     }
269 269
 
270
-    public function get( $key ) {
271
-        if ( method_exists( $this, 'get_' . $key ) ) {
272
-            $value = call_user_func( array( $this, 'get_' . $key ) );
270
+    public function get($key) {
271
+        if (method_exists($this, 'get_' . $key)) {
272
+            $value = call_user_func(array($this, 'get_' . $key));
273 273
         } else {
274 274
             $value = $this->$key;
275 275
         }
@@ -277,51 +277,51 @@  discard block
 block discarded – undo
277 277
         return $value;
278 278
     }
279 279
 
280
-    public function set( $key, $value ) {
281
-        $ignore = array( 'items', 'cart_details', 'fees', '_ID' );
280
+    public function set($key, $value) {
281
+        $ignore = array('items', 'cart_details', 'fees', '_ID');
282 282
 
283
-        if ( $key === 'status' ) {
283
+        if ($key === 'status') {
284 284
             $this->old_status = $this->status;
285 285
         }
286 286
 
287
-        if ( ! in_array( $key, $ignore ) ) {
288
-            $this->pending[ $key ] = $value;
287
+        if (!in_array($key, $ignore)) {
288
+            $this->pending[$key] = $value;
289 289
         }
290 290
 
291
-        if( '_ID' !== $key ) {
291
+        if ('_ID' !== $key) {
292 292
             $this->$key = $value;
293 293
         }
294 294
     }
295 295
 
296
-    public function _isset( $name ) {
297
-        if ( property_exists( $this, $name) ) {
298
-            return false === empty( $this->$name );
296
+    public function _isset($name) {
297
+        if (property_exists($this, $name)) {
298
+            return false === empty($this->$name);
299 299
         } else {
300 300
             return null;
301 301
         }
302 302
     }
303 303
 
304
-    private function setup_invoice( $invoice_id ) {
304
+    private function setup_invoice($invoice_id) {
305 305
         $this->pending = array();
306 306
 
307
-        if ( empty( $invoice_id ) ) {
307
+        if (empty($invoice_id)) {
308 308
             return false;
309 309
         }
310 310
 
311
-        $invoice = get_post( $invoice_id );
311
+        $invoice = get_post($invoice_id);
312 312
 
313
-        if( !$invoice || is_wp_error( $invoice ) ) {
313
+        if (!$invoice || is_wp_error($invoice)) {
314 314
             return false;
315 315
         }
316 316
 
317
-        if( !('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type) ) {
317
+        if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) {
318 318
             return false;
319 319
         }
320 320
 
321
-        do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id );
321
+        do_action('wpinv_pre_setup_invoice', $this, $invoice_id);
322 322
 
323 323
         // Primary Identifier
324
-        $this->ID              = absint( $invoice_id );
324
+        $this->ID              = absint($invoice_id);
325 325
         $this->post_type       = $invoice->post_type;
326 326
 
327 327
         // We have a payment, get the generic payment_meta item to reduce calls to it
@@ -331,14 +331,14 @@  discard block
 block discarded – undo
331 331
         $this->completed_date  = $this->setup_completed_date();
332 332
         $this->status          = $invoice->post_status;
333 333
 
334
-        if ( 'future' == $this->status ) {
334
+        if ('future' == $this->status) {
335 335
             $this->status = 'publish';
336 336
         }
337 337
 
338 338
         $this->post_status     = $this->status;
339 339
         $this->mode            = $this->setup_mode();
340 340
         $this->parent_invoice  = $invoice->post_parent;
341
-        $this->post_name       = $this->setup_post_name( $invoice );
341
+        $this->post_name       = $this->setup_post_name($invoice);
342 342
         $this->status_nicename = $this->setup_status_nicename($invoice->post_status);
343 343
 
344 344
         // Items
@@ -361,8 +361,8 @@  discard block
 block discarded – undo
361 361
         
362 362
         // User based
363 363
         $this->ip              = $this->setup_ip();
364
-        $this->user_id         = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id();
365
-        $this->email           = get_the_author_meta( 'email', $this->user_id );
364
+        $this->user_id         = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id();
365
+        $this->email           = get_the_author_meta('email', $this->user_id);
366 366
 
367 367
         $this->user_info       = $this->setup_user_info();
368 368
 
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
         $this->company         = $this->user_info['company'];
372 372
         $this->vat_number      = $this->user_info['vat_number'];
373 373
         $this->vat_rate        = $this->user_info['vat_rate'];
374
-        $this->adddress_confirmed  = $this->user_info['adddress_confirmed'];
374
+        $this->adddress_confirmed = $this->user_info['adddress_confirmed'];
375 375
         $this->address         = $this->user_info['address'];
376 376
         $this->city            = $this->user_info['city'];
377 377
         $this->country         = $this->user_info['country'];
@@ -386,39 +386,39 @@  discard block
 block discarded – undo
386 386
         // Other Identifiers
387 387
         $this->key             = $this->setup_invoice_key();
388 388
         $this->number          = $this->setup_invoice_number();
389
-        $this->title           = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number;
389
+        $this->title           = !empty($invoice->post_title) ? $invoice->post_title : $this->number;
390 390
         
391
-        $this->full_name       = trim( $this->first_name . ' '. $this->last_name );
391
+        $this->full_name       = trim($this->first_name . ' ' . $this->last_name);
392 392
         
393 393
         // Allow extensions to add items to this object via hook
394
-        do_action( 'wpinv_setup_invoice', $this, $invoice_id );
394
+        do_action('wpinv_setup_invoice', $this, $invoice_id);
395 395
 
396 396
         return true;
397 397
     }
398 398
 
399
-    private function setup_status_nicename( $status ) {
400
-        $all_invoice_statuses  = wpinv_get_invoice_statuses( true, true, $this );
399
+    private function setup_status_nicename($status) {
400
+        $all_invoice_statuses = wpinv_get_invoice_statuses(true, true, $this);
401 401
 
402
-        if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) {
403
-            $all_invoice_statuses  = Wpinv_Quotes_Shared::wpinv_get_quote_statuses();
402
+        if ($this->is_quote() && class_exists('Wpinv_Quotes_Shared')) {
403
+            $all_invoice_statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses();
404 404
         }
405
-        $status   = isset( $all_invoice_statuses[$status] ) ? $all_invoice_statuses[$status] : __( $status, 'invoicing' );
405
+        $status = isset($all_invoice_statuses[$status]) ? $all_invoice_statuses[$status] : __($status, 'invoicing');
406 406
 
407
-        return apply_filters( 'setup_status_nicename', $status );
407
+        return apply_filters('setup_status_nicename', $status);
408 408
     }
409 409
 
410
-    private function setup_post_name( $post = NULL ) {
410
+    private function setup_post_name($post = NULL) {
411 411
         global $wpdb;
412 412
         
413 413
         $post_name = '';
414 414
         
415
-        if ( !empty( $post ) ) {
416
-            if( !empty( $post->post_name ) ) {
415
+        if (!empty($post)) {
416
+            if (!empty($post->post_name)) {
417 417
                 $post_name = $post->post_name;
418
-            } else if ( !empty( $post->ID ) ) {
419
-                $post_name = wpinv_generate_post_name( $post->ID );
418
+            } else if (!empty($post->ID)) {
419
+                $post_name = wpinv_generate_post_name($post->ID);
420 420
 
421
-                $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) );
421
+                $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID));
422 422
             }
423 423
         }
424 424
 
@@ -426,12 +426,12 @@  discard block
 block discarded – undo
426 426
     }
427 427
     
428 428
     private function setup_due_date() {
429
-        $due_date = $this->get_meta( '_wpinv_due_date' );
429
+        $due_date = $this->get_meta('_wpinv_due_date');
430 430
         
431
-        if ( empty( $due_date ) ) {
432
-            $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) );
433
-            $due_date = date_i18n( 'Y-m-d', $overdue_time );
434
-        } else if ( $due_date == 'none' ) {
431
+        if (empty($due_date)) {
432
+            $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days')));
433
+            $due_date = date_i18n('Y-m-d', $overdue_time);
434
+        } else if ($due_date == 'none') {
435 435
             $due_date = '';
436 436
         }
437 437
         
@@ -439,67 +439,67 @@  discard block
 block discarded – undo
439 439
     }
440 440
     
441 441
     private function setup_completed_date() {
442
-        $invoice = get_post( $this->ID );
442
+        $invoice = get_post($this->ID);
443 443
 
444
-        if ( 'wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) {
444
+        if ('wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) {
445 445
             return false; // This invoice was never paid
446 446
         }
447 447
 
448
-        $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date;
448
+        $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date;
449 449
 
450 450
         return $date;
451 451
     }
452 452
     
453 453
     private function setup_cart_details() {
454
-        $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array();
454
+        $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array();
455 455
         return $cart_details;
456 456
     }
457 457
     
458 458
     public function array_convert() {
459
-        return get_object_vars( $this );
459
+        return get_object_vars($this);
460 460
     }
461 461
     
462 462
     private function setup_items() {
463
-        $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array();
463
+        $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array();
464 464
         return $items;
465 465
     }
466 466
     
467 467
     private function setup_fees() {
468
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
468
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
469 469
         return $payment_fees;
470 470
     }
471 471
         
472 472
     private function setup_currency() {
473
-        $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this );
473
+        $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this);
474 474
         return $currency;
475 475
     }
476 476
     
477 477
     private function setup_discount() {
478 478
         //$discount = $this->get_meta( '_wpinv_discount', true );
479
-        $discount = (float)$this->subtotal - ( (float)$this->total - (float)$this->tax - (float)$this->fees_total );
480
-        if ( $discount < 0 ) {
479
+        $discount = (float) $this->subtotal - ((float) $this->total - (float) $this->tax - (float) $this->fees_total);
480
+        if ($discount < 0) {
481 481
             $discount = 0;
482 482
         }
483
-        $discount = wpinv_round_amount( $discount );
483
+        $discount = wpinv_round_amount($discount);
484 484
         
485 485
         return $discount;
486 486
     }
487 487
     
488 488
     private function setup_discount_code() {
489
-        $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true );
489
+        $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true);
490 490
         return $discount_code;
491 491
     }
492 492
     
493 493
     private function setup_tax() {
494 494
 
495
-        $tax = $this->get_meta( '_wpinv_tax', true );
495
+        $tax = $this->get_meta('_wpinv_tax', true);
496 496
 
497 497
         // We don't have tax as it's own meta and no meta was passed
498
-        if ( '' === $tax ) {            
499
-            $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0;
498
+        if ('' === $tax) {            
499
+            $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0;
500 500
         }
501 501
         
502
-        if ( $tax < 0 || ! $this->is_taxable() ) {
502
+        if ($tax < 0 || !$this->is_taxable()) {
503 503
             $tax = 0;
504 504
         }
505 505
 
@@ -510,16 +510,16 @@  discard block
 block discarded – undo
510 510
      * If taxes are enabled, allow users to enable/disable taxes per invoice.
511 511
      */
512 512
     private function setup_is_taxable() {
513
-        return (int) $this->get_meta( '_wpinv_disable_taxes', true );
513
+        return (int) $this->get_meta('_wpinv_disable_taxes', true);
514 514
     }
515 515
 
516 516
     private function setup_subtotal() {
517 517
         $subtotal     = 0;
518 518
         $cart_details = $this->cart_details;
519 519
 
520
-        if ( is_array( $cart_details ) ) {
521
-            foreach ( $cart_details as $item ) {
522
-                if ( isset( $item['subtotal'] ) ) {
520
+        if (is_array($cart_details)) {
521
+            foreach ($cart_details as $item) {
522
+                if (isset($item['subtotal'])) {
523 523
                     $subtotal += $item['subtotal'];
524 524
                 }
525 525
             }
@@ -533,23 +533,23 @@  discard block
 block discarded – undo
533 533
     }
534 534
 
535 535
     private function setup_discounts() {
536
-        $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array();
536
+        $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array();
537 537
         return $discounts;
538 538
     }
539 539
     
540 540
     private function setup_total() {
541
-        $amount = $this->get_meta( '_wpinv_total', true );
541
+        $amount = $this->get_meta('_wpinv_total', true);
542 542
 
543
-        if ( empty( $amount ) && '0.00' != $amount ) {
544
-            $meta   = $this->get_meta( '_wpinv_payment_meta', true );
545
-            $meta   = maybe_unserialize( $meta );
543
+        if (empty($amount) && '0.00' != $amount) {
544
+            $meta   = $this->get_meta('_wpinv_payment_meta', true);
545
+            $meta   = maybe_unserialize($meta);
546 546
 
547
-            if ( isset( $meta['amount'] ) ) {
547
+            if (isset($meta['amount'])) {
548 548
                 $amount = $meta['amount'];
549 549
             }
550 550
         }
551 551
 
552
-        if($amount < 0){
552
+        if ($amount < 0) {
553 553
             $amount = 0;
554 554
         }
555 555
 
@@ -557,13 +557,13 @@  discard block
 block discarded – undo
557 557
     }
558 558
     
559 559
     private function setup_mode() {
560
-        return $this->get_meta( '_wpinv_mode' );
560
+        return $this->get_meta('_wpinv_mode');
561 561
     }
562 562
 
563 563
     private function setup_gateway() {
564
-        $gateway = $this->get_meta( '_wpinv_gateway' );
564
+        $gateway = $this->get_meta('_wpinv_gateway');
565 565
         
566
-        if ( empty( $gateway ) && 'publish' === $this->status ) {
566
+        if (empty($gateway) && 'publish' === $this->status) {
567 567
             $gateway = 'manual';
568 568
         }
569 569
         
@@ -571,23 +571,23 @@  discard block
 block discarded – undo
571 571
     }
572 572
 
573 573
     private function setup_gateway_title() {
574
-        $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway );
574
+        $gateway_title = wpinv_get_gateway_checkout_label($this->gateway);
575 575
         return $gateway_title;
576 576
     }
577 577
 
578 578
     private function setup_transaction_id() {
579
-        $transaction_id = $this->get_meta( '_wpinv_transaction_id' );
579
+        $transaction_id = $this->get_meta('_wpinv_transaction_id');
580 580
 
581
-        if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) {
581
+        if (empty($transaction_id) || (int) $transaction_id === (int) $this->ID) {
582 582
             $gateway        = $this->gateway;
583
-            $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID );
583
+            $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID);
584 584
         }
585 585
 
586 586
         return $transaction_id;
587 587
     }
588 588
 
589 589
     private function setup_ip() {
590
-        $ip = $this->get_meta( '_wpinv_user_ip' );
590
+        $ip = $this->get_meta('_wpinv_user_ip');
591 591
         return $ip;
592 592
     }
593 593
 
@@ -597,62 +597,62 @@  discard block
 block discarded – undo
597 597
     ///}
598 598
         
599 599
     private function setup_first_name() {
600
-        $first_name = $this->get_meta( '_wpinv_first_name' );
600
+        $first_name = $this->get_meta('_wpinv_first_name');
601 601
         return $first_name;
602 602
     }
603 603
     
604 604
     private function setup_last_name() {
605
-        $last_name = $this->get_meta( '_wpinv_last_name' );
605
+        $last_name = $this->get_meta('_wpinv_last_name');
606 606
         return $last_name;
607 607
     }
608 608
     
609 609
     private function setup_company() {
610
-        $company = $this->get_meta( '_wpinv_company' );
610
+        $company = $this->get_meta('_wpinv_company');
611 611
         return $company;
612 612
     }
613 613
     
614 614
     private function setup_vat_number() {
615
-        $vat_number = $this->get_meta( '_wpinv_vat_number' );
615
+        $vat_number = $this->get_meta('_wpinv_vat_number');
616 616
         return $vat_number;
617 617
     }
618 618
     
619 619
     private function setup_vat_rate() {
620
-        $vat_rate = $this->get_meta( '_wpinv_vat_rate' );
620
+        $vat_rate = $this->get_meta('_wpinv_vat_rate');
621 621
         return $vat_rate;
622 622
     }
623 623
     
624 624
     private function setup_adddress_confirmed() {
625
-        $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' );
625
+        $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed');
626 626
         return $adddress_confirmed;
627 627
     }
628 628
     
629 629
     private function setup_phone() {
630
-        $phone = $this->get_meta( '_wpinv_phone' );
630
+        $phone = $this->get_meta('_wpinv_phone');
631 631
         return $phone;
632 632
     }
633 633
     
634 634
     private function setup_address() {
635
-        $address = $this->get_meta( '_wpinv_address', true );
635
+        $address = $this->get_meta('_wpinv_address', true);
636 636
         return $address;
637 637
     }
638 638
     
639 639
     private function setup_city() {
640
-        $city = $this->get_meta( '_wpinv_city', true );
640
+        $city = $this->get_meta('_wpinv_city', true);
641 641
         return $city;
642 642
     }
643 643
     
644 644
     private function setup_country() {
645
-        $country = $this->get_meta( '_wpinv_country', true );
645
+        $country = $this->get_meta('_wpinv_country', true);
646 646
         return $country;
647 647
     }
648 648
     
649 649
     private function setup_state() {
650
-        $state = $this->get_meta( '_wpinv_state', true );
650
+        $state = $this->get_meta('_wpinv_state', true);
651 651
         return $state;
652 652
     }
653 653
     
654 654
     private function setup_zip() {
655
-        $zip = $this->get_meta( '_wpinv_zip', true );
655
+        $zip = $this->get_meta('_wpinv_zip', true);
656 656
         return $zip;
657 657
     }
658 658
 
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
             'user_id'        => $this->user_id,
662 662
             'first_name'     => $this->first_name,
663 663
             'last_name'      => $this->last_name,
664
-            'email'          => get_the_author_meta( 'email', $this->user_id ),
664
+            'email'          => get_the_author_meta('email', $this->user_id),
665 665
             'phone'          => $this->phone,
666 666
             'address'        => $this->address,
667 667
             'city'           => $this->city,
@@ -676,12 +676,12 @@  discard block
 block discarded – undo
676 676
         );
677 677
         
678 678
         $user_info = array();
679
-        if ( isset( $this->payment_meta['user_info'] ) ) {
680
-            $user_info = maybe_unserialize( $this->payment_meta['user_info'] );
679
+        if (isset($this->payment_meta['user_info'])) {
680
+            $user_info = maybe_unserialize($this->payment_meta['user_info']);
681 681
             
682
-            if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) {
682
+            if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) {
683 683
                 $this->user_id = $post->post_author;
684
-                $this->email = get_the_author_meta( 'email', $this->user_id );
684
+                $this->email = get_the_author_meta('email', $this->user_id);
685 685
                 
686 686
                 $user_info['user_id'] = $this->user_id;
687 687
                 $user_info['email'] = $this->email;
@@ -690,13 +690,13 @@  discard block
 block discarded – undo
690 690
             }
691 691
         }
692 692
         
693
-        $user_info    = wp_parse_args( $user_info, $defaults );
693
+        $user_info = wp_parse_args($user_info, $defaults);
694 694
         
695 695
         // Get the user, but only if it's been created
696
-        $user = get_userdata( $this->user_id );
696
+        $user = get_userdata($this->user_id);
697 697
         
698
-        if ( !empty( $user ) && $user->ID > 0 ) {
699
-            if ( empty( $user_info ) ) {
698
+        if (!empty($user) && $user->ID > 0) {
699
+            if (empty($user_info)) {
700 700
                 $user_info = array(
701 701
                     'user_id'    => $user->ID,
702 702
                     'first_name' => $user->first_name,
@@ -705,23 +705,23 @@  discard block
 block discarded – undo
705 705
                     'discount'   => '',
706 706
                 );
707 707
             } else {
708
-                foreach ( $user_info as $key => $value ) {
709
-                    if ( ! empty( $value ) ) {
708
+                foreach ($user_info as $key => $value) {
709
+                    if (!empty($value)) {
710 710
                         continue;
711 711
                     }
712 712
 
713
-                    switch( $key ) {
713
+                    switch ($key) {
714 714
                         case 'user_id':
715
-                            $user_info[ $key ] = $user->ID;
715
+                            $user_info[$key] = $user->ID;
716 716
                             break;
717 717
                         case 'first_name':
718
-                            $user_info[ $key ] = $user->first_name;
718
+                            $user_info[$key] = $user->first_name;
719 719
                             break;
720 720
                         case 'last_name':
721
-                            $user_info[ $key ] = $user->last_name;
721
+                            $user_info[$key] = $user->last_name;
722 722
                             break;
723 723
                         case 'email':
724
-                            $user_info[ $key ] = $user->user_email;
724
+                            $user_info[$key] = $user->user_email;
725 725
                             break;
726 726
                     }
727 727
                 }
@@ -732,25 +732,25 @@  discard block
 block discarded – undo
732 732
     }
733 733
 
734 734
     private function setup_invoice_key() {
735
-        $key = $this->get_meta( '_wpinv_key', true );
735
+        $key = $this->get_meta('_wpinv_key', true);
736 736
         
737 737
         return $key;
738 738
     }
739 739
 
740 740
     private function setup_invoice_number() {
741
-        $number = $this->get_meta( '_wpinv_number', true );
741
+        $number = $this->get_meta('_wpinv_number', true);
742 742
 
743
-        if ( !$number ) {
743
+        if (!$number) {
744 744
             $number = $this->ID;
745 745
 
746
-            if ( $this->status == 'auto-draft' ) {
747
-                if ( wpinv_sequential_number_active( $this->post_type ) ) {
748
-                    $next_number = wpinv_get_next_invoice_number( $this->post_type );
746
+            if ($this->status == 'auto-draft') {
747
+                if (wpinv_sequential_number_active($this->post_type)) {
748
+                    $next_number = wpinv_get_next_invoice_number($this->post_type);
749 749
                     $number      = $next_number;
750 750
                 }
751 751
             }
752 752
             
753
-            $number = wpinv_format_invoice_number( $number, $this->post_type );
753
+            $number = wpinv_format_invoice_number($number, $this->post_type);
754 754
         }
755 755
 
756 756
         return $number;
@@ -759,10 +759,10 @@  discard block
 block discarded – undo
759 759
     private function insert_invoice() {
760 760
         global $wpdb;
761 761
 
762
-        if ( empty( $this->post_type ) ) {
763
-            if ( !empty( $this->ID ) && $post_type = get_post_type( $this->ID ) ) {
762
+        if (empty($this->post_type)) {
763
+            if (!empty($this->ID) && $post_type = get_post_type($this->ID)) {
764 764
                 $this->post_type = $post_type;
765
-            } else if ( !empty( $this->parent_invoice ) && $post_type = get_post_type( $this->parent_invoice ) ) {
765
+            } else if (!empty($this->parent_invoice) && $post_type = get_post_type($this->parent_invoice)) {
766 766
                 $this->post_type = $post_type;
767 767
             } else {
768 768
                 $this->post_type = 'wpi_invoice';
@@ -770,16 +770,16 @@  discard block
 block discarded – undo
770 770
         }
771 771
 
772 772
         $invoice_number = $this->ID;
773
-        if ( $number = $this->get_meta( '_wpinv_number', true ) ) {
773
+        if ($number = $this->get_meta('_wpinv_number', true)) {
774 774
             $invoice_number = $number;
775 775
         }
776 776
 
777
-        if ( empty( $this->key ) ) {
777
+        if (empty($this->key)) {
778 778
             $this->key = self::generate_key();
779 779
             $this->pending['key'] = $this->key;
780 780
         }
781 781
 
782
-        if ( empty( $this->ip ) ) {
782
+        if (empty($this->ip)) {
783 783
             $this->ip = wpinv_get_ip();
784 784
             $this->pending['ip'] = $this->ip;
785 785
         }
@@ -816,60 +816,60 @@  discard block
 block discarded – undo
816 816
                         'post_status'   => $this->status,
817 817
                         'post_author'   => $this->user_id,
818 818
                         'post_type'     => $this->post_type,
819
-                        'post_date'     => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ),
820
-                        'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ),
819
+                        'post_date'     => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'),
820
+                        'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1),
821 821
                         'post_parent'   => $this->parent_invoice,
822 822
                     );
823
-        $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this );
823
+        $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this);
824 824
 
825 825
         // Create a blank invoice
826
-        if ( !empty( $this->ID ) ) {
827
-            $args['ID']         = $this->ID;
826
+        if (!empty($this->ID)) {
827
+            $args['ID'] = $this->ID;
828 828
 
829
-            $invoice_id = wp_update_post( $args, true );
829
+            $invoice_id = wp_update_post($args, true);
830 830
         } else {
831
-            $invoice_id = wp_insert_post( $args, true );
831
+            $invoice_id = wp_insert_post($args, true);
832 832
         }
833 833
 
834
-        if ( is_wp_error( $invoice_id ) ) {
834
+        if (is_wp_error($invoice_id)) {
835 835
             return false;
836 836
         }
837 837
 
838
-        if ( !empty( $invoice_id ) ) {
838
+        if (!empty($invoice_id)) {
839 839
             $this->ID  = $invoice_id;
840 840
             $this->_ID = $invoice_id;
841 841
 
842
-            $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data );
843
-            if ( ! empty( $this->payment_meta['fees'] ) ) {
844
-                $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] );
845
-                foreach( $this->fees as $fee ) {
846
-                    $this->increase_fees( $fee['amount'] );
842
+            $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data);
843
+            if (!empty($this->payment_meta['fees'])) {
844
+                $this->fees = array_merge($this->fees, $this->payment_meta['fees']);
845
+                foreach ($this->fees as $fee) {
846
+                    $this->increase_fees($fee['amount']);
847 847
                 }
848 848
             }
849 849
 
850
-            $this->update_meta( '_wpinv_payment_meta', $this->payment_meta );    
850
+            $this->update_meta('_wpinv_payment_meta', $this->payment_meta);    
851 851
             $this->new = true;
852 852
         }
853 853
 
854 854
         return $this->ID;
855 855
     }
856 856
 
857
-    public function save( $setup = false ) {
857
+    public function save($setup = false) {
858 858
         
859 859
         $saved = false;
860
-        if ( empty( $this->items ) ) {
860
+        if (empty($this->items)) {
861 861
             return $saved; // Don't save empty invoice.
862 862
         }
863 863
         
864
-        if ( empty( $this->key ) ) {
864
+        if (empty($this->key)) {
865 865
             $this->key = self::generate_key();
866 866
             $this->pending['key'] = $this->key;
867 867
         }
868 868
         
869
-        if ( empty( $this->ID ) ) {
869
+        if (empty($this->ID)) {
870 870
             $invoice_id = $this->insert_invoice();
871 871
 
872
-            if ( false === $invoice_id ) {
872
+            if (false === $invoice_id) {
873 873
                 $saved = false;
874 874
             } else {
875 875
                 $this->ID = $invoice_id;
@@ -877,27 +877,27 @@  discard block
 block discarded – undo
877 877
         }
878 878
 
879 879
         // If we have something pending, let's save it
880
-        if ( !empty( $this->pending ) ) {
880
+        if (!empty($this->pending)) {
881 881
             $total_increase = 0;
882 882
             $total_decrease = 0;
883 883
 
884
-            foreach ( $this->pending as $key => $value ) {
885
-                switch( $key ) {
884
+            foreach ($this->pending as $key => $value) {
885
+                switch ($key) {
886 886
                     case 'items':
887 887
                         // Update totals for pending items
888
-                        foreach ( $this->pending[ $key ] as $item ) {
889
-                            switch( $item['action'] ) {
888
+                        foreach ($this->pending[$key] as $item) {
889
+                            switch ($item['action']) {
890 890
                                 case 'add':
891 891
                                     $price = $item['price'];
892 892
                                     $taxes = $item['tax'];
893 893
 
894
-                                    if ( 'publish' === $this->status ) {
894
+                                    if ('publish' === $this->status) {
895 895
                                         $total_increase += $price;
896 896
                                     }
897 897
                                     break;
898 898
 
899 899
                                 case 'remove':
900
-                                    if ( 'publish' === $this->status ) {
900
+                                    if ('publish' === $this->status) {
901 901
                                         $total_decrease += $item['price'];
902 902
                                     }
903 903
                                     break;
@@ -905,16 +905,16 @@  discard block
 block discarded – undo
905 905
                         }
906 906
                         break;
907 907
                     case 'fees':
908
-                        if ( 'publish' !== $this->status ) {
908
+                        if ('publish' !== $this->status) {
909 909
                             break;
910 910
                         }
911 911
 
912
-                        if ( empty( $this->pending[ $key ] ) ) {
912
+                        if (empty($this->pending[$key])) {
913 913
                             break;
914 914
                         }
915 915
 
916
-                        foreach ( $this->pending[ $key ] as $fee ) {
917
-                            switch( $fee['action'] ) {
916
+                        foreach ($this->pending[$key] as $fee) {
917
+                            switch ($fee['action']) {
918 918
                                 case 'add':
919 919
                                     $total_increase += $fee['amount'];
920 920
                                     break;
@@ -926,86 +926,86 @@  discard block
 block discarded – undo
926 926
                         }
927 927
                         break;
928 928
                     case 'status':
929
-                        $this->update_status( $this->status );
929
+                        $this->update_status($this->status);
930 930
                         break;
931 931
                     case 'gateway':
932
-                        $this->update_meta( '_wpinv_gateway', $this->gateway );
932
+                        $this->update_meta('_wpinv_gateway', $this->gateway);
933 933
                         break;
934 934
                     case 'mode':
935
-                        $this->update_meta( '_wpinv_mode', $this->mode );
935
+                        $this->update_meta('_wpinv_mode', $this->mode);
936 936
                         break;
937 937
                     case 'transaction_id':
938
-                        $this->update_meta( '_wpinv_transaction_id', $this->transaction_id );
938
+                        $this->update_meta('_wpinv_transaction_id', $this->transaction_id);
939 939
                         break;
940 940
                     case 'ip':
941
-                        $this->update_meta( '_wpinv_user_ip', $this->ip );
941
+                        $this->update_meta('_wpinv_user_ip', $this->ip);
942 942
                         break;
943 943
                     ///case 'user_id':
944 944
                         ///$this->update_meta( '_wpinv_user_id', $this->user_id );
945 945
                         ///$this->user_info['user_id'] = $this->user_id;
946 946
                         ///break;
947 947
                     case 'first_name':
948
-                        $this->update_meta( '_wpinv_first_name', $this->first_name );
948
+                        $this->update_meta('_wpinv_first_name', $this->first_name);
949 949
                         $this->user_info['first_name'] = $this->first_name;
950 950
                         break;
951 951
                     case 'last_name':
952
-                        $this->update_meta( '_wpinv_last_name', $this->last_name );
952
+                        $this->update_meta('_wpinv_last_name', $this->last_name);
953 953
                         $this->user_info['last_name'] = $this->last_name;
954 954
                         break;
955 955
                     case 'phone':
956
-                        $this->update_meta( '_wpinv_phone', $this->phone );
956
+                        $this->update_meta('_wpinv_phone', $this->phone);
957 957
                         $this->user_info['phone'] = $this->phone;
958 958
                         break;
959 959
                     case 'address':
960
-                        $this->update_meta( '_wpinv_address', $this->address );
960
+                        $this->update_meta('_wpinv_address', $this->address);
961 961
                         $this->user_info['address'] = $this->address;
962 962
                         break;
963 963
                     case 'city':
964
-                        $this->update_meta( '_wpinv_city', $this->city );
964
+                        $this->update_meta('_wpinv_city', $this->city);
965 965
                         $this->user_info['city'] = $this->city;
966 966
                         break;
967 967
                     case 'country':
968
-                        $this->update_meta( '_wpinv_country', $this->country );
968
+                        $this->update_meta('_wpinv_country', $this->country);
969 969
                         $this->user_info['country'] = $this->country;
970 970
                         break;
971 971
                     case 'state':
972
-                        $this->update_meta( '_wpinv_state', $this->state );
972
+                        $this->update_meta('_wpinv_state', $this->state);
973 973
                         $this->user_info['state'] = $this->state;
974 974
                         break;
975 975
                     case 'zip':
976
-                        $this->update_meta( '_wpinv_zip', $this->zip );
976
+                        $this->update_meta('_wpinv_zip', $this->zip);
977 977
                         $this->user_info['zip'] = $this->zip;
978 978
                         break;
979 979
                     case 'company':
980
-                        $this->update_meta( '_wpinv_company', $this->company );
980
+                        $this->update_meta('_wpinv_company', $this->company);
981 981
                         $this->user_info['company'] = $this->company;
982 982
                         break;
983 983
                     case 'vat_number':
984
-                        $this->update_meta( '_wpinv_vat_number', $this->vat_number );
984
+                        $this->update_meta('_wpinv_vat_number', $this->vat_number);
985 985
                         $this->user_info['vat_number'] = $this->vat_number;
986 986
                         
987
-                        $vat_info = getpaid_session()->get( 'user_vat_data' );
988
-                        if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) {
989
-                            $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false;
990
-                            $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed );
991
-                            $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed;
987
+                        $vat_info = getpaid_session()->get('user_vat_data');
988
+                        if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) {
989
+                            $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
990
+                            $this->update_meta('_wpinv_adddress_confirmed', (bool) $adddress_confirmed);
991
+                            $this->user_info['adddress_confirmed'] = (bool) $adddress_confirmed;
992 992
                         }
993 993
     
994 994
                         break;
995 995
                     case 'vat_rate':
996
-                        $this->update_meta( '_wpinv_vat_rate', $this->vat_rate );
996
+                        $this->update_meta('_wpinv_vat_rate', $this->vat_rate);
997 997
                         $this->user_info['vat_rate'] = $this->vat_rate;
998 998
                         break;
999 999
                     case 'adddress_confirmed':
1000
-                        $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed );
1000
+                        $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed);
1001 1001
                         $this->user_info['adddress_confirmed'] = $this->adddress_confirmed;
1002 1002
                         break;
1003 1003
                     
1004 1004
                     case 'key':
1005
-                        $this->update_meta( '_wpinv_key', $this->key );
1005
+                        $this->update_meta('_wpinv_key', $this->key);
1006 1006
                         break;
1007 1007
                     case 'disable_taxes':
1008
-                        $this->update_meta( '_wpinv_disable_taxes', $this->disable_taxes );
1008
+                        $this->update_meta('_wpinv_disable_taxes', $this->disable_taxes);
1009 1009
                         break;
1010 1010
                     case 'date':
1011 1011
                         $args = array(
@@ -1014,49 +1014,49 @@  discard block
 block discarded – undo
1014 1014
                             'edit_date' => true,
1015 1015
                         );
1016 1016
 
1017
-                        wp_update_post( $args );
1017
+                        wp_update_post($args);
1018 1018
                         break;
1019 1019
                     case 'due_date':
1020
-                        if ( empty( $this->due_date ) ) {
1020
+                        if (empty($this->due_date)) {
1021 1021
                             $this->due_date = 'none';
1022 1022
                         }
1023 1023
                         
1024
-                        $this->update_meta( '_wpinv_due_date', $this->due_date );
1024
+                        $this->update_meta('_wpinv_due_date', $this->due_date);
1025 1025
                         break;
1026 1026
                     case 'completed_date':
1027
-                        $this->update_meta( '_wpinv_completed_date', $this->completed_date );
1027
+                        $this->update_meta('_wpinv_completed_date', $this->completed_date);
1028 1028
                         break;
1029 1029
                     case 'discounts':
1030
-                        if ( ! is_array( $this->discounts ) ) {
1031
-                            $this->discounts = explode( ',', $this->discounts );
1030
+                        if (!is_array($this->discounts)) {
1031
+                            $this->discounts = explode(',', $this->discounts);
1032 1032
                         }
1033 1033
 
1034
-                        $this->user_info['discount'] = implode( ',', $this->discounts );
1034
+                        $this->user_info['discount'] = implode(',', $this->discounts);
1035 1035
                         break;
1036 1036
                     case 'discount':
1037
-                        $this->update_meta( '_wpinv_discount', wpinv_round_amount( $this->discount ) );
1037
+                        $this->update_meta('_wpinv_discount', wpinv_round_amount($this->discount));
1038 1038
                         break;
1039 1039
                     case 'discount_code':
1040
-                        $this->update_meta( '_wpinv_discount_code', $this->discount_code );
1040
+                        $this->update_meta('_wpinv_discount_code', $this->discount_code);
1041 1041
                         break;
1042 1042
                     case 'parent_invoice':
1043 1043
                         $args = array(
1044 1044
                             'ID'          => $this->ID,
1045 1045
                             'post_parent' => $this->parent_invoice,
1046 1046
                         );
1047
-                        wp_update_post( $args );
1047
+                        wp_update_post($args);
1048 1048
                         break;
1049 1049
                     default:
1050
-                        do_action( 'wpinv_save', $this, $key );
1050
+                        do_action('wpinv_save', $this, $key);
1051 1051
                         break;
1052 1052
                 }
1053 1053
             }
1054 1054
 
1055
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
1056
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
1057
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
1055
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
1056
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
1057
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
1058 1058
             
1059
-            $this->items    = array_values( $this->items );
1059
+            $this->items = array_values($this->items);
1060 1060
             
1061 1061
             $new_meta = array(
1062 1062
                 'items'         => $this->items,
@@ -1067,12 +1067,12 @@  discard block
 block discarded – undo
1067 1067
             );
1068 1068
             
1069 1069
             $meta        = $this->get_meta();
1070
-            $merged_meta = array_merge( $meta, $new_meta );
1070
+            $merged_meta = array_merge($meta, $new_meta);
1071 1071
 
1072 1072
             // Only save the payment meta if it's changed
1073
-            if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) {
1074
-                $updated     = $this->update_meta( '_wpinv_payment_meta', $merged_meta );
1075
-                if ( false !== $updated ) {
1073
+            if (md5(serialize($meta)) !== md5(serialize($merged_meta))) {
1074
+                $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta);
1075
+                if (false !== $updated) {
1076 1076
                     $saved = true;
1077 1077
                 }
1078 1078
             }
@@ -1080,15 +1080,15 @@  discard block
 block discarded – undo
1080 1080
             $this->pending = array();
1081 1081
             $saved         = true;
1082 1082
         } else {
1083
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
1084
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
1085
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
1083
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
1084
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
1085
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
1086 1086
         }
1087 1087
         
1088
-        do_action( 'wpinv_invoice_save', $this, $saved );
1088
+        do_action('wpinv_invoice_save', $this, $saved);
1089 1089
 
1090
-        if ( true === $saved || $setup ) {
1091
-            $this->setup_invoice( $this->ID );
1090
+        if (true === $saved || $setup) {
1091
+            $this->setup_invoice($this->ID);
1092 1092
         }
1093 1093
         
1094 1094
         $this->refresh_item_ids();
@@ -1096,7 +1096,7 @@  discard block
 block discarded – undo
1096 1096
         return $saved;
1097 1097
     }
1098 1098
     
1099
-    public function add_fee( $args, $global = true ) {
1099
+    public function add_fee($args, $global = true) {
1100 1100
         $default_args = array(
1101 1101
             'label'       => '',
1102 1102
             'amount'      => 0,
@@ -1106,75 +1106,75 @@  discard block
 block discarded – undo
1106 1106
             'item_id'     => 0,
1107 1107
         );
1108 1108
 
1109
-        $fee = wp_parse_args( $args, $default_args );
1109
+        $fee = wp_parse_args($args, $default_args);
1110 1110
         
1111
-        if ( empty( $fee['label'] ) ) {
1111
+        if (empty($fee['label'])) {
1112 1112
             return false;
1113 1113
         }
1114 1114
         
1115
-        $fee['id']  = sanitize_title( $fee['label'] );
1115
+        $fee['id'] = sanitize_title($fee['label']);
1116 1116
         
1117
-        $this->fees[]               = $fee;
1117
+        $this->fees[] = $fee;
1118 1118
         
1119 1119
         $added_fee               = $fee;
1120 1120
         $added_fee['action']     = 'add';
1121 1121
         $this->pending['fees'][] = $added_fee;
1122
-        reset( $this->fees );
1122
+        reset($this->fees);
1123 1123
 
1124
-        $this->increase_fees( $fee['amount'] );
1124
+        $this->increase_fees($fee['amount']);
1125 1125
         return true;
1126 1126
     }
1127 1127
 
1128
-    public function remove_fee( $key ) {
1128
+    public function remove_fee($key) {
1129 1129
         $removed = false;
1130 1130
 
1131
-        if ( is_numeric( $key ) ) {
1132
-            $removed = $this->remove_fee_by( 'index', $key );
1131
+        if (is_numeric($key)) {
1132
+            $removed = $this->remove_fee_by('index', $key);
1133 1133
         }
1134 1134
 
1135 1135
         return $removed;
1136 1136
     }
1137 1137
 
1138
-    public function remove_fee_by( $key, $value, $global = false ) {
1139
-        $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array(
1138
+    public function remove_fee_by($key, $value, $global = false) {
1139
+        $allowed_fee_keys = apply_filters('wpinv_fee_keys', array(
1140 1140
             'index', 'label', 'amount', 'type',
1141
-        ) );
1141
+        ));
1142 1142
 
1143
-        if ( ! in_array( $key, $allowed_fee_keys ) ) {
1143
+        if (!in_array($key, $allowed_fee_keys)) {
1144 1144
             return false;
1145 1145
         }
1146 1146
 
1147 1147
         $removed = false;
1148
-        if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) {
1149
-            $removed_fee             = $this->fees[ $value ];
1148
+        if ('index' === $key && array_key_exists($value, $this->fees)) {
1149
+            $removed_fee             = $this->fees[$value];
1150 1150
             $removed_fee['action']   = 'remove';
1151 1151
             $this->pending['fees'][] = $removed_fee;
1152 1152
 
1153
-            $this->decrease_fees( $removed_fee['amount'] );
1153
+            $this->decrease_fees($removed_fee['amount']);
1154 1154
 
1155
-            unset( $this->fees[ $value ] );
1155
+            unset($this->fees[$value]);
1156 1156
             $removed = true;
1157
-        } else if ( 'index' !== $key ) {
1158
-            foreach ( $this->fees as $index => $fee ) {
1159
-                if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) {
1157
+        } else if ('index' !== $key) {
1158
+            foreach ($this->fees as $index => $fee) {
1159
+                if (isset($fee[$key]) && $fee[$key] == $value) {
1160 1160
                     $removed_fee             = $fee;
1161 1161
                     $removed_fee['action']   = 'remove';
1162 1162
                     $this->pending['fees'][] = $removed_fee;
1163 1163
 
1164
-                    $this->decrease_fees( $removed_fee['amount'] );
1164
+                    $this->decrease_fees($removed_fee['amount']);
1165 1165
 
1166
-                    unset( $this->fees[ $index ] );
1166
+                    unset($this->fees[$index]);
1167 1167
                     $removed = true;
1168 1168
 
1169
-                    if ( false === $global ) {
1169
+                    if (false === $global) {
1170 1170
                         break;
1171 1171
                     }
1172 1172
                 }
1173 1173
             }
1174 1174
         }
1175 1175
 
1176
-        if ( true === $removed ) {
1177
-            $this->fees = array_values( $this->fees );
1176
+        if (true === $removed) {
1177
+            $this->fees = array_values($this->fees);
1178 1178
         }
1179 1179
 
1180 1180
         return $removed;
@@ -1182,35 +1182,35 @@  discard block
 block discarded – undo
1182 1182
 
1183 1183
     
1184 1184
 
1185
-    public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
1185
+    public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) {
1186 1186
         // Bail if no note specified
1187
-        if( !$note ) {
1187
+        if (!$note) {
1188 1188
             return false;
1189 1189
         }
1190 1190
 
1191
-        if ( empty( $this->ID ) )
1191
+        if (empty($this->ID))
1192 1192
             return false;
1193 1193
         
1194
-        if ( ( ( is_user_logged_in() && wpinv_current_user_can_manage_invoicing() ) || $added_by_user ) && !$system ) {
1195
-            $user                 = get_user_by( 'id', get_current_user_id() );
1194
+        if (((is_user_logged_in() && wpinv_current_user_can_manage_invoicing()) || $added_by_user) && !$system) {
1195
+            $user                 = get_user_by('id', get_current_user_id());
1196 1196
             $comment_author       = $user->display_name;
1197 1197
             $comment_author_email = $user->user_email;
1198 1198
         } else {
1199 1199
             $comment_author       = 'System';
1200 1200
             $comment_author_email = 'system@';
1201
-            $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com';
1202
-            $comment_author_email = sanitize_email( $comment_author_email );
1201
+            $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com';
1202
+            $comment_author_email = sanitize_email($comment_author_email);
1203 1203
         }
1204 1204
 
1205
-        do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type );
1205
+        do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type);
1206 1206
 
1207
-        $note_id = wp_insert_comment( wp_filter_comment( array(
1207
+        $note_id = wp_insert_comment(wp_filter_comment(array(
1208 1208
             'comment_post_ID'      => $this->ID,
1209 1209
             'comment_content'      => $note,
1210 1210
             'comment_agent'        => 'WPInvoicing',
1211 1211
             'user_id'              => is_admin() ? get_current_user_id() : 0,
1212
-            'comment_date'         => current_time( 'mysql' ),
1213
-            'comment_date_gmt'     => current_time( 'mysql', 1 ),
1212
+            'comment_date'         => current_time('mysql'),
1213
+            'comment_date_gmt'     => current_time('mysql', 1),
1214 1214
             'comment_approved'     => 1,
1215 1215
             'comment_parent'       => 0,
1216 1216
             'comment_author'       => $comment_author,
@@ -1218,53 +1218,53 @@  discard block
 block discarded – undo
1218 1218
             'comment_author_url'   => '',
1219 1219
             'comment_author_email' => $comment_author_email,
1220 1220
             'comment_type'         => 'wpinv_note'
1221
-        ) ) );
1221
+        )));
1222 1222
 
1223
-        do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note );
1223
+        do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note);
1224 1224
         
1225
-        if ( $customer_type ) {
1226
-            add_comment_meta( $note_id, '_wpi_customer_note', 1 );
1225
+        if ($customer_type) {
1226
+            add_comment_meta($note_id, '_wpi_customer_note', 1);
1227 1227
 
1228
-            do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) );
1228
+            do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note));
1229 1229
         }
1230 1230
 
1231 1231
         return $note_id;
1232 1232
     }
1233 1233
 
1234
-    private function increase_subtotal( $amount = 0.00 ) {
1234
+    private function increase_subtotal($amount = 0.00) {
1235 1235
         $amount          = (float) $amount;
1236 1236
         $this->subtotal += $amount;
1237
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1237
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1238 1238
 
1239 1239
         $this->recalculate_total();
1240 1240
     }
1241 1241
 
1242
-    private function decrease_subtotal( $amount = 0.00 ) {
1242
+    private function decrease_subtotal($amount = 0.00) {
1243 1243
         $amount          = (float) $amount;
1244 1244
         $this->subtotal -= $amount;
1245
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1245
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1246 1246
 
1247
-        if ( $this->subtotal < 0 ) {
1247
+        if ($this->subtotal < 0) {
1248 1248
             $this->subtotal = 0;
1249 1249
         }
1250 1250
 
1251 1251
         $this->recalculate_total();
1252 1252
     }
1253 1253
 
1254
-    private function increase_fees( $amount = 0.00 ) {
1255
-        $amount            = (float)$amount;
1254
+    private function increase_fees($amount = 0.00) {
1255
+        $amount            = (float) $amount;
1256 1256
         $this->fees_total += $amount;
1257
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1257
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1258 1258
 
1259 1259
         $this->recalculate_total();
1260 1260
     }
1261 1261
 
1262
-    private function decrease_fees( $amount = 0.00 ) {
1262
+    private function decrease_fees($amount = 0.00) {
1263 1263
         $amount            = (float) $amount;
1264 1264
         $this->fees_total -= $amount;
1265
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1265
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1266 1266
 
1267
-        if ( $this->fees_total < 0 ) {
1267
+        if ($this->fees_total < 0) {
1268 1268
             $this->fees_total = 0;
1269 1269
         }
1270 1270
 
@@ -1275,54 +1275,54 @@  discard block
 block discarded – undo
1275 1275
         global $wpi_nosave;
1276 1276
         
1277 1277
         $this->total = $this->subtotal + $this->tax + $this->fees_total;
1278
-        $this->total = wpinv_round_amount( $this->total );
1278
+        $this->total = wpinv_round_amount($this->total);
1279 1279
         
1280
-        do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave );
1280
+        do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave);
1281 1281
     }
1282 1282
     
1283
-    public function increase_tax( $amount = 0.00 ) {
1283
+    public function increase_tax($amount = 0.00) {
1284 1284
         $amount       = (float) $amount;
1285 1285
         $this->tax   += $amount;
1286 1286
 
1287 1287
         $this->recalculate_total();
1288 1288
     }
1289 1289
 
1290
-    public function decrease_tax( $amount = 0.00 ) {
1290
+    public function decrease_tax($amount = 0.00) {
1291 1291
         $amount     = (float) $amount;
1292 1292
         $this->tax -= $amount;
1293 1293
 
1294
-        if ( $this->tax < 0 ) {
1294
+        if ($this->tax < 0) {
1295 1295
             $this->tax = 0;
1296 1296
         }
1297 1297
 
1298 1298
         $this->recalculate_total();
1299 1299
     }
1300 1300
 
1301
-    public function update_status( $new_status = false, $note = '', $manual = false ) {
1302
-        $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID );
1301
+    public function update_status($new_status = false, $note = '', $manual = false) {
1302
+        $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID);
1303 1303
 
1304
-        if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses( true ) ) ) ) {
1304
+        if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses(true)))) {
1305 1305
             return false; // Don't permit status changes that aren't changes
1306 1306
         }
1307 1307
 
1308
-        $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status );
1308
+        $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status);
1309 1309
         $updated = false;
1310 1310
 
1311
-        if ( $do_change ) {
1312
-            do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status );
1311
+        if ($do_change) {
1312
+            do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status);
1313 1313
 
1314 1314
             $update_post_data                   = array();
1315 1315
             $update_post_data['ID']             = $this->ID;
1316 1316
             $update_post_data['post_status']    = $new_status;
1317
-            $update_post_data['edit_date']      = current_time( 'mysql', 0 );
1318
-            $update_post_data['edit_date_gmt']  = current_time( 'mysql', 1 );
1317
+            $update_post_data['edit_date']      = current_time('mysql', 0);
1318
+            $update_post_data['edit_date_gmt']  = current_time('mysql', 1);
1319 1319
             
1320
-            $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID );
1320
+            $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID);
1321 1321
 
1322
-            $updated = wp_update_post( $update_post_data );     
1322
+            $updated = wp_update_post($update_post_data);     
1323 1323
            
1324 1324
             // Process any specific status functions
1325
-            switch( $new_status ) {
1325
+            switch ($new_status) {
1326 1326
                 case 'wpi-refunded':
1327 1327
                     $this->process_refund();
1328 1328
                     break;
@@ -1335,9 +1335,9 @@  discard block
 block discarded – undo
1335 1335
             }
1336 1336
             
1337 1337
             // Status was changed.
1338
-            do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status );
1339
-            do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status );
1340
-            do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status );
1338
+            do_action('wpinv_status_' . $new_status, $this->ID, $old_status);
1339
+            do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status);
1340
+            do_action('wpinv_update_status', $this->ID, $new_status, $old_status);
1341 1341
         }
1342 1342
 
1343 1343
         return $updated;
@@ -1351,20 +1351,20 @@  discard block
 block discarded – undo
1351 1351
         $this->save();
1352 1352
     }
1353 1353
 
1354
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
1355
-        if ( empty( $meta_key ) ) {
1354
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
1355
+        if (empty($meta_key)) {
1356 1356
             return false;
1357 1357
         }
1358 1358
 
1359
-        if ( $meta_key == 'key' || $meta_key == 'date' ) {
1359
+        if ($meta_key == 'key' || $meta_key == 'date') {
1360 1360
             $current_meta = $this->get_meta();
1361
-            $current_meta[ $meta_key ] = $meta_value;
1361
+            $current_meta[$meta_key] = $meta_value;
1362 1362
 
1363 1363
             $meta_key     = '_wpinv_payment_meta';
1364 1364
             $meta_value   = $current_meta;
1365 1365
         }
1366 1366
 
1367
-        $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID );
1367
+        $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID);
1368 1368
         
1369 1369
         // Do not update created date on invoice marked as paid.
1370 1370
         /*if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) {
@@ -1379,45 +1379,45 @@  discard block
 block discarded – undo
1379 1379
             wp_update_post( $args );
1380 1380
         }*/
1381 1381
         
1382
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
1382
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
1383 1383
     }
1384 1384
 
1385 1385
     private function process_refund() {
1386 1386
         $process_refund = true;
1387 1387
 
1388 1388
         // If the payment was not in publish, don't decrement stats as they were never incremented
1389
-        if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) {
1389
+        if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) {
1390 1390
             $process_refund = false;
1391 1391
         }
1392 1392
 
1393 1393
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1394
-        $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this );
1394
+        $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this);
1395 1395
 
1396
-        if ( false === $process_refund ) {
1396
+        if (false === $process_refund) {
1397 1397
             return;
1398 1398
         }
1399 1399
 
1400
-        do_action( 'wpinv_pre_refund_invoice', $this );
1400
+        do_action('wpinv_pre_refund_invoice', $this);
1401 1401
         
1402
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this );
1403
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this );
1404
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this );
1402
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this);
1403
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this);
1404
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this);
1405 1405
         
1406
-        do_action( 'wpinv_post_refund_invoice', $this );
1406
+        do_action('wpinv_post_refund_invoice', $this);
1407 1407
     }
1408 1408
 
1409 1409
     private function process_failure() {
1410 1410
         $discounts = $this->discounts;
1411
-        if ( empty( $discounts ) ) {
1411
+        if (empty($discounts)) {
1412 1412
             return;
1413 1413
         }
1414 1414
 
1415
-        if ( ! is_array( $discounts ) ) {
1416
-            $discounts = array_map( 'trim', explode( ',', $discounts ) );
1415
+        if (!is_array($discounts)) {
1416
+            $discounts = array_map('trim', explode(',', $discounts));
1417 1417
         }
1418 1418
 
1419
-        foreach ( $discounts as $discount ) {
1420
-            wpinv_decrease_discount_usage( $discount );
1419
+        foreach ($discounts as $discount) {
1420
+            wpinv_decrease_discount_usage($discount);
1421 1421
         }
1422 1422
     }
1423 1423
     
@@ -1425,92 +1425,92 @@  discard block
 block discarded – undo
1425 1425
         $process_pending = true;
1426 1426
 
1427 1427
         // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented
1428
-        if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'wpi-pending' != $this->status ) {
1428
+        if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'wpi-pending' != $this->status) {
1429 1429
             $process_pending = false;
1430 1430
         }
1431 1431
 
1432 1432
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1433
-        $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this );
1433
+        $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this);
1434 1434
 
1435
-        if ( false === $process_pending ) {
1435
+        if (false === $process_pending) {
1436 1436
             return;
1437 1437
         }
1438 1438
 
1439
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this );
1440
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this );
1441
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this );
1439
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this);
1440
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this);
1441
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this);
1442 1442
 
1443 1443
         $this->completed_date = '';
1444
-        $this->update_meta( '_wpinv_completed_date', '' );
1444
+        $this->update_meta('_wpinv_completed_date', '');
1445 1445
     }
1446 1446
     
1447 1447
     // get data
1448
-    public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) {
1449
-        $meta = get_post_meta( $this->ID, $meta_key, $single );
1448
+    public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) {
1449
+        $meta = get_post_meta($this->ID, $meta_key, $single);
1450 1450
 
1451
-        if ( $meta_key === '_wpinv_payment_meta' ) {
1451
+        if ($meta_key === '_wpinv_payment_meta') {
1452 1452
 
1453
-            if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is.
1453
+            if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is.
1454 1454
 
1455
-            if ( empty( $meta['key'] ) ) {
1455
+            if (empty($meta['key'])) {
1456 1456
                 $meta['key'] = $this->setup_invoice_key();
1457 1457
             }
1458 1458
 
1459
-            if ( empty( $meta['date'] ) ) {
1460
-                $meta['date'] = get_post_field( 'post_date', $this->ID );
1459
+            if (empty($meta['date'])) {
1460
+                $meta['date'] = get_post_field('post_date', $this->ID);
1461 1461
             }
1462 1462
         }
1463 1463
 
1464
-        $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID );
1464
+        $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID);
1465 1465
 
1466
-        return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key );
1466
+        return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key);
1467 1467
     }
1468 1468
     
1469 1469
     public function get_description() {
1470
-        $post = get_post( $this->ID );
1470
+        $post = get_post($this->ID);
1471 1471
         
1472
-        $description = !empty( $post ) ? $post->post_content : '';
1473
-        return apply_filters( 'wpinv_get_description', $description, $this->ID, $this );
1472
+        $description = !empty($post) ? $post->post_content : '';
1473
+        return apply_filters('wpinv_get_description', $description, $this->ID, $this);
1474 1474
     }
1475 1475
     
1476
-    public function get_status( $nicename = false ) {
1477
-        if ( !$nicename ) {
1476
+    public function get_status($nicename = false) {
1477
+        if (!$nicename) {
1478 1478
             $status = $this->status;
1479 1479
         } else {
1480 1480
             $status = $this->status_nicename;
1481 1481
         }
1482 1482
         
1483
-        return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this );
1483
+        return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this);
1484 1484
     }
1485 1485
     
1486 1486
     public function get_cart_details() {
1487
-        return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this );
1487
+        return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this);
1488 1488
     }
1489 1489
     
1490
-    public function get_subtotal( $currency = false ) {
1491
-        $subtotal = wpinv_round_amount( $this->subtotal );
1490
+    public function get_subtotal($currency = false) {
1491
+        $subtotal = wpinv_round_amount($this->subtotal);
1492 1492
         
1493
-        if ( $currency ) {
1494
-            $subtotal = wpinv_price( wpinv_format_amount( $subtotal, NULL, !$currency ), $this->get_currency() );
1493
+        if ($currency) {
1494
+            $subtotal = wpinv_price(wpinv_format_amount($subtotal, NULL, !$currency), $this->get_currency());
1495 1495
         }
1496 1496
         
1497
-        return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency );
1497
+        return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency);
1498 1498
     }
1499 1499
     
1500
-    public function get_total( $currency = false ) {        
1501
-        if ( $this->is_free_trial() ) {
1502
-            $total = wpinv_round_amount( 0 );
1500
+    public function get_total($currency = false) {        
1501
+        if ($this->is_free_trial()) {
1502
+            $total = wpinv_round_amount(0);
1503 1503
         } else {
1504
-            $total = wpinv_round_amount( $this->total );
1504
+            $total = wpinv_round_amount($this->total);
1505 1505
         }
1506
-        if ( $currency ) {
1507
-            $total = wpinv_price( wpinv_format_amount( $total, NULL, !$currency ), $this->get_currency() );
1506
+        if ($currency) {
1507
+            $total = wpinv_price(wpinv_format_amount($total, NULL, !$currency), $this->get_currency());
1508 1508
         }
1509 1509
         
1510
-        return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency );
1510
+        return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency);
1511 1511
     }
1512 1512
     
1513
-    public function get_recurring_details( $field = '', $currency = false ) {        
1513
+    public function get_recurring_details($field = '', $currency = false) {        
1514 1514
         $data                 = array();
1515 1515
         $data['cart_details'] = $this->cart_details;
1516 1516
         $data['subtotal']     = $this->get_subtotal();
@@ -1518,119 +1518,119 @@  discard block
 block discarded – undo
1518 1518
         $data['tax']          = $this->get_tax();
1519 1519
         $data['total']        = $this->get_total();
1520 1520
     
1521
-        if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) {
1521
+        if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) {
1522 1522
             $is_free_trial = $this->is_free_trial();
1523
-            $discounts = $this->get_discounts( true );
1523
+            $discounts = $this->get_discounts(true);
1524 1524
             
1525
-            if ( $is_free_trial || !empty( $discounts ) ) {
1525
+            if ($is_free_trial || !empty($discounts)) {
1526 1526
                 $first_use_only = false;
1527 1527
                 
1528
-                if ( !empty( $discounts ) ) {
1529
-                    foreach ( $discounts as $key => $code ) {
1530
-                        if ( wpinv_discount_is_recurring( $code, true ) && !$this->is_renewal() ) {
1528
+                if (!empty($discounts)) {
1529
+                    foreach ($discounts as $key => $code) {
1530
+                        if (wpinv_discount_is_recurring($code, true) && !$this->is_renewal()) {
1531 1531
                             $first_use_only = true;
1532 1532
                             break;
1533 1533
                         }
1534 1534
                     }
1535 1535
                 }
1536 1536
                     
1537
-                if ( !$first_use_only ) {
1538
-                    $data['subtotal'] = wpinv_round_amount( $this->subtotal );
1539
-                    $data['discount'] = wpinv_round_amount( $this->discount );
1540
-                    $data['tax']      = wpinv_round_amount( $this->tax );
1541
-                    $data['total']    = wpinv_round_amount( $this->total );
1537
+                if (!$first_use_only) {
1538
+                    $data['subtotal'] = wpinv_round_amount($this->subtotal);
1539
+                    $data['discount'] = wpinv_round_amount($this->discount);
1540
+                    $data['tax']      = wpinv_round_amount($this->tax);
1541
+                    $data['total']    = wpinv_round_amount($this->total);
1542 1542
                 } else {
1543 1543
                     $cart_subtotal   = 0;
1544 1544
                     $cart_discount   = $this->discount;
1545 1545
                     $cart_tax        = 0;
1546 1546
 
1547
-                    foreach ( $this->cart_details as $key => $item ) {
1548
-                        $item_quantity  = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1549
-                        $item_subtotal  = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1547
+                    foreach ($this->cart_details as $key => $item) {
1548
+                        $item_quantity  = $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1549
+                        $item_subtotal  = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1550 1550
                         $item_discount  = 0;
1551
-                        $item_tax       = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0;
1551
+                        $item_tax       = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float) $item['vat_rate']) : 0;
1552 1552
                         
1553
-                        if ( wpinv_prices_include_tax() ) {
1554
-                            $item_subtotal -= wpinv_round_amount( $item_tax );
1553
+                        if (wpinv_prices_include_tax()) {
1554
+                            $item_subtotal -= wpinv_round_amount($item_tax);
1555 1555
                         }
1556 1556
                         
1557 1557
                         $item_total     = $item_subtotal - $item_discount + $item_tax;
1558 1558
                         // Do not allow totals to go negative
1559
-                        if ( $item_total < 0 ) {
1559
+                        if ($item_total < 0) {
1560 1560
                             $item_total = 0;
1561 1561
                         }
1562 1562
                         
1563
-                        $cart_subtotal  += (float)($item_subtotal);
1564
-                        $cart_discount  += (float)($item_discount);
1565
-                        $cart_tax       += (float)($item_tax);
1563
+                        $cart_subtotal  += (float) ($item_subtotal);
1564
+                        $cart_discount  += (float) ($item_discount);
1565
+                        $cart_tax       += (float) ($item_tax);
1566 1566
                         
1567
-                        $data['cart_details'][$key]['discount']   = wpinv_round_amount( $item_discount );
1568
-                        $data['cart_details'][$key]['tax']        = wpinv_round_amount( $item_tax );
1569
-                        $data['cart_details'][$key]['price']      = wpinv_round_amount( $item_total );
1567
+                        $data['cart_details'][$key]['discount']   = wpinv_round_amount($item_discount);
1568
+                        $data['cart_details'][$key]['tax']        = wpinv_round_amount($item_tax);
1569
+                        $data['cart_details'][$key]['price']      = wpinv_round_amount($item_total);
1570 1570
                     }
1571 1571
 
1572 1572
 	                $total = $data['subtotal'] - $data['discount'] + $data['tax'];
1573
-	                if ( $total < 0 ) {
1573
+	                if ($total < 0) {
1574 1574
 		                $total = 0;
1575 1575
 	                }
1576 1576
 
1577
-                    $data['subtotal'] = wpinv_round_amount( $cart_subtotal );
1578
-                    $data['discount'] = wpinv_round_amount( $cart_discount );
1579
-                    $data['tax']      = wpinv_round_amount( $cart_tax );
1580
-                    $data['total']    = wpinv_round_amount( $total );
1577
+                    $data['subtotal'] = wpinv_round_amount($cart_subtotal);
1578
+                    $data['discount'] = wpinv_round_amount($cart_discount);
1579
+                    $data['tax']      = wpinv_round_amount($cart_tax);
1580
+                    $data['total']    = wpinv_round_amount($total);
1581 1581
                 }
1582 1582
             }
1583 1583
         }
1584 1584
         
1585
-        $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency );
1585
+        $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency);
1586 1586
 
1587
-        if ( isset( $data[$field] ) ) {
1588
-            return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
1587
+        if (isset($data[$field])) {
1588
+            return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]);
1589 1589
         }
1590 1590
         
1591 1591
         return $data;
1592 1592
     }
1593 1593
     
1594
-    public function get_final_tax( $currency = false ) {        
1595
-        $final_total = wpinv_round_amount( $this->tax );
1596
-        if ( $currency ) {
1597
-            $final_total = wpinv_price( wpinv_format_amount( $final_total, NULL, !$currency ), $this->get_currency() );
1594
+    public function get_final_tax($currency = false) {        
1595
+        $final_total = wpinv_round_amount($this->tax);
1596
+        if ($currency) {
1597
+            $final_total = wpinv_price(wpinv_format_amount($final_total, NULL, !$currency), $this->get_currency());
1598 1598
         }
1599 1599
         
1600
-        return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency );
1600
+        return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency);
1601 1601
     }
1602 1602
     
1603
-    public function get_discounts( $array = false ) {
1603
+    public function get_discounts($array = false) {
1604 1604
         $discounts = $this->discounts;
1605
-        if ( $array && $discounts ) {
1606
-            $discounts = explode( ',', $discounts );
1605
+        if ($array && $discounts) {
1606
+            $discounts = explode(',', $discounts);
1607 1607
         }
1608
-        return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array );
1608
+        return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array);
1609 1609
     }
1610 1610
     
1611
-    public function get_discount( $currency = false, $dash = false ) {
1612
-        if ( !empty( $this->discounts ) ) {
1611
+    public function get_discount($currency = false, $dash = false) {
1612
+        if (!empty($this->discounts)) {
1613 1613
             global $ajax_cart_details;
1614 1614
             $ajax_cart_details = $this->get_cart_details();
1615 1615
             
1616
-            if ( !empty( $ajax_cart_details ) && count( $ajax_cart_details ) == count( $this->items ) ) {
1616
+            if (!empty($ajax_cart_details) && count($ajax_cart_details) == count($this->items)) {
1617 1617
                 $cart_items = $ajax_cart_details;
1618 1618
             } else {
1619 1619
                 $cart_items = $this->items;
1620 1620
             }
1621 1621
 
1622
-            $this->discount = wpinv_get_cart_items_discount_amount( $cart_items , $this->discounts );
1622
+            $this->discount = wpinv_get_cart_items_discount_amount($cart_items, $this->discounts);
1623 1623
         }
1624
-        $discount   = wpinv_round_amount( $this->discount );
1624
+        $discount   = wpinv_round_amount($this->discount);
1625 1625
         $dash       = $dash && $discount > 0 ? '&ndash;' : '';
1626 1626
         
1627
-        if ( $currency ) {
1628
-            $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() );
1627
+        if ($currency) {
1628
+            $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency());
1629 1629
         }
1630 1630
         
1631
-        $discount   = $dash . $discount;
1631
+        $discount = $dash . $discount;
1632 1632
         
1633
-        return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash );
1633
+        return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash);
1634 1634
     }
1635 1635
     
1636 1636
     public function get_discount_code() {
@@ -1642,49 +1642,49 @@  discard block
 block discarded – undo
1642 1642
         return (int) $this->disable_taxes === 0;
1643 1643
     }
1644 1644
 
1645
-    public function get_tax( $currency = false ) {
1646
-        $tax = wpinv_round_amount( $this->tax );
1645
+    public function get_tax($currency = false) {
1646
+        $tax = wpinv_round_amount($this->tax);
1647 1647
 
1648
-        if ( $currency ) {
1649
-            $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() );
1648
+        if ($currency) {
1649
+            $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency());
1650 1650
         }
1651 1651
 
1652
-        if ( ! $this->is_taxable() ) {
1653
-            $tax = wpinv_round_amount( 0.00 );
1652
+        if (!$this->is_taxable()) {
1653
+            $tax = wpinv_round_amount(0.00);
1654 1654
         }
1655 1655
 
1656
-        return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency );
1656
+        return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency);
1657 1657
     }
1658 1658
     
1659
-    public function get_fees( $type = 'all' ) {
1660
-        $fees    = array();
1659
+    public function get_fees($type = 'all') {
1660
+        $fees = array();
1661 1661
 
1662
-        if ( ! empty( $this->fees ) && is_array( $this->fees ) ) {
1663
-            foreach ( $this->fees as $fee ) {
1664
-                if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) {
1662
+        if (!empty($this->fees) && is_array($this->fees)) {
1663
+            foreach ($this->fees as $fee) {
1664
+                if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) {
1665 1665
                     continue;
1666 1666
                 }
1667 1667
 
1668
-                $fee['label'] = stripslashes( $fee['label'] );
1669
-                $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() );
1670
-                $fees[]    = $fee;
1668
+                $fee['label'] = stripslashes($fee['label']);
1669
+                $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency());
1670
+                $fees[] = $fee;
1671 1671
             }
1672 1672
         }
1673 1673
 
1674
-        return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this );
1674
+        return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this);
1675 1675
     }
1676 1676
     
1677
-    public function get_fees_total( $type = 'all' ) {
1677
+    public function get_fees_total($type = 'all') {
1678 1678
         $fees_total = (float) 0.00;
1679 1679
 
1680
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
1681
-        if ( ! empty( $payment_fees ) ) {
1682
-            foreach ( $payment_fees as $fee ) {
1680
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
1681
+        if (!empty($payment_fees)) {
1682
+            foreach ($payment_fees as $fee) {
1683 1683
                 $fees_total += (float) $fee['amount'];
1684 1684
             }
1685 1685
         }
1686 1686
 
1687
-        return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this );
1687
+        return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this);
1688 1688
         /*
1689 1689
         $fees = $this->get_fees( $type );
1690 1690
 
@@ -1704,116 +1704,116 @@  discard block
 block discarded – undo
1704 1704
     }
1705 1705
 
1706 1706
     public function get_user_id() {
1707
-        return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this );
1707
+        return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this);
1708 1708
     }
1709 1709
     
1710 1710
     public function get_first_name() {
1711
-        return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this );
1711
+        return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this);
1712 1712
     }
1713 1713
     
1714 1714
     public function get_last_name() {
1715
-        return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this );
1715
+        return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this);
1716 1716
     }
1717 1717
     
1718 1718
     public function get_user_full_name() {
1719
-        return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this );
1719
+        return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this);
1720 1720
     }
1721 1721
     
1722 1722
     public function get_user_info() {
1723
-        return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this );
1723
+        return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this);
1724 1724
     }
1725 1725
     
1726 1726
     public function get_email() {
1727
-        return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this );
1727
+        return apply_filters('wpinv_user_email', $this->email, $this->ID, $this);
1728 1728
     }
1729 1729
     
1730 1730
     public function get_address() {
1731
-        return apply_filters( 'wpinv_address', $this->address, $this->ID, $this );
1731
+        return apply_filters('wpinv_address', $this->address, $this->ID, $this);
1732 1732
     }
1733 1733
     
1734 1734
     public function get_phone() {
1735
-        return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this );
1735
+        return apply_filters('wpinv_phone', $this->phone, $this->ID, $this);
1736 1736
     }
1737 1737
     
1738 1738
     public function get_number() {
1739
-        return apply_filters( 'wpinv_number', $this->number, $this->ID, $this );
1739
+        return apply_filters('wpinv_number', $this->number, $this->ID, $this);
1740 1740
     }
1741 1741
     
1742 1742
     public function get_items() {
1743
-        return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this );
1743
+        return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this);
1744 1744
     }
1745 1745
     
1746 1746
     public function get_key() {
1747
-        return apply_filters( 'wpinv_key', $this->key, $this->ID, $this );
1747
+        return apply_filters('wpinv_key', $this->key, $this->ID, $this);
1748 1748
     }
1749 1749
     
1750 1750
     public function get_transaction_id() {
1751
-        return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this );
1751
+        return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this);
1752 1752
     }
1753 1753
     
1754 1754
     public function get_gateway() {
1755
-        return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this );
1755
+        return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this);
1756 1756
     }
1757 1757
     
1758 1758
     public function get_gateway_title() {
1759
-        $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway );
1759
+        $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway);
1760 1760
         
1761
-        return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this );
1761
+        return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this);
1762 1762
     }
1763 1763
     
1764 1764
     public function get_currency() {
1765
-        return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this );
1765
+        return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this);
1766 1766
     }
1767 1767
     
1768 1768
     public function get_created_date() {
1769
-        return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this );
1769
+        return apply_filters('wpinv_created_date', $this->date, $this->ID, $this);
1770 1770
     }
1771 1771
     
1772
-    public function get_due_date( $display = false ) {
1773
-        $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this );
1772
+    public function get_due_date($display = false) {
1773
+        $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this);
1774 1774
 
1775
-        if ( ! $display ) {
1775
+        if (!$display) {
1776 1776
             return $due_date;
1777 1777
         }
1778 1778
         
1779
-        return getpaid_format_date( $this->due_date );
1779
+        return getpaid_format_date($this->due_date);
1780 1780
     }
1781 1781
     
1782 1782
     public function get_completed_date() {
1783
-        return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this );
1783
+        return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this);
1784 1784
     }
1785 1785
     
1786
-    public function get_invoice_date( $formatted = true ) {
1786
+    public function get_invoice_date($formatted = true) {
1787 1787
         $date_completed = $this->completed_date;
1788 1788
         $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
1789 1789
         
1790
-        if ( $invoice_date == '' ) {
1790
+        if ($invoice_date == '') {
1791 1791
             $date_created   = $this->date;
1792 1792
             $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : '';
1793 1793
         }
1794 1794
         
1795
-        if ( $formatted && $invoice_date ) {
1796
-            $invoice_date   = getpaid_format_date( $invoice_date );
1795
+        if ($formatted && $invoice_date) {
1796
+            $invoice_date = getpaid_format_date($invoice_date);
1797 1797
         }
1798 1798
 
1799
-        return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this );
1799
+        return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this);
1800 1800
     }
1801 1801
     
1802 1802
     public function get_ip() {
1803
-        return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this );
1803
+        return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this);
1804 1804
     }
1805 1805
         
1806
-    public function has_status( $status ) {
1807
-        return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status );
1806
+    public function has_status($status) {
1807
+        return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status);
1808 1808
     }
1809 1809
     
1810
-    public function add_item( $item_id = 0, $args = array() ) {
1810
+    public function add_item($item_id = 0, $args = array()) {
1811 1811
         global $wpi_current_id, $wpi_item_id;
1812 1812
         
1813
-        $item = new WPInv_Item( $item_id );
1813
+        $item = new WPInv_Item($item_id);
1814 1814
 
1815 1815
         // Bail if this post isn't a item
1816
-        if( !$item || $item->post_type !== 'wpi_item' ) {
1816
+        if (!$item || $item->post_type !== 'wpi_item') {
1817 1817
             return false;
1818 1818
         }
1819 1819
         
@@ -1832,8 +1832,8 @@  discard block
 block discarded – undo
1832 1832
             'fees'          => array()
1833 1833
         );
1834 1834
 
1835
-        $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults );
1836
-        $args['quantity']   = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1;
1835
+        $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults);
1836
+        $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1;
1837 1837
 
1838 1838
         $wpi_current_id         = $this->ID;
1839 1839
         $wpi_item_id            = $item->ID;
@@ -1845,19 +1845,19 @@  discard block
 block discarded – undo
1845 1845
         $found_cart_key         = false;
1846 1846
         
1847 1847
         if ($has_quantities) {
1848
-            $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1848
+            $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1849 1849
             
1850
-            foreach ( $this->items as $key => $cart_item ) {
1851
-                if ( (int)$item_id !== (int)$cart_item['id'] ) {
1850
+            foreach ($this->items as $key => $cart_item) {
1851
+                if ((int) $item_id !== (int) $cart_item['id']) {
1852 1852
                     continue;
1853 1853
                 }
1854 1854
 
1855
-                $this->items[ $key ]['quantity'] += $args['quantity'];
1855
+                $this->items[$key]['quantity'] += $args['quantity'];
1856 1856
                 break;
1857 1857
             }
1858 1858
             
1859
-            foreach ( $this->cart_details as $cart_key => $cart_item ) {
1860
-                if ( $item_id != $cart_item['id'] ) {
1859
+            foreach ($this->cart_details as $cart_key => $cart_item) {
1860
+                if ($item_id != $cart_item['id']) {
1861 1861
                     continue;
1862 1862
                 }
1863 1863
 
@@ -1869,29 +1869,29 @@  discard block
 block discarded – undo
1869 1869
         if ($has_quantities && $found_cart_key !== false) {
1870 1870
             $cart_item          = $this->cart_details[$found_cart_key];
1871 1871
             $item_price         = $cart_item['item_price'];
1872
-            $quantity           = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1873
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1872
+            $quantity           = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1873
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1874 1874
             
1875 1875
             $new_quantity       = $quantity + $args['quantity'];
1876 1876
             $subtotal           = $item_price * $new_quantity;
1877 1877
             
1878 1878
             $args['quantity']   = $new_quantity;
1879
-            $discount           = !empty( $args['discount'] ) ? $args['discount'] : 0;
1880
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1879
+            $discount           = !empty($args['discount']) ? $args['discount'] : 0;
1880
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
1881 1881
             
1882
-            $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0;
1883
-            $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0;
1882
+            $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float) $cart_item['discount'] ? $discount - (float) $cart_item['discount'] : 0;
1883
+            $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float) $cart_item['tax'] ? $tax - (float) $cart_item['tax'] : 0;
1884 1884
             // The total increase equals the number removed * the item_price
1885
-            $total_increased    = wpinv_round_amount( $item_price );
1885
+            $total_increased    = wpinv_round_amount($item_price);
1886 1886
             
1887
-            if ( wpinv_prices_include_tax() ) {
1888
-                $subtotal -= wpinv_round_amount( $tax );
1887
+            if (wpinv_prices_include_tax()) {
1888
+                $subtotal -= wpinv_round_amount($tax);
1889 1889
             }
1890 1890
 
1891
-            $total              = $subtotal - $discount + $tax;
1891
+            $total = $subtotal - $discount + $tax;
1892 1892
 
1893 1893
             // Do not allow totals to go negative
1894
-            if( $total < 0 ) {
1894
+            if ($total < 0) {
1895 1895
                 $total = 0;
1896 1896
             }
1897 1897
             
@@ -1907,25 +1907,25 @@  discard block
 block discarded – undo
1907 1907
             $this->cart_details[$found_cart_key] = $cart_item;
1908 1908
         } else {
1909 1909
             // Set custom price.
1910
-            if ( $args['custom_price'] !== '' ) {
1910
+            if ($args['custom_price'] !== '') {
1911 1911
                 $item_price = $args['custom_price'];
1912 1912
             } else {
1913 1913
                 // Allow overriding the price
1914
-                if ( false !== $args['item_price'] ) {
1914
+                if (false !== $args['item_price']) {
1915 1915
                     $item_price = $args['item_price'];
1916 1916
                 } else {
1917
-                    $item_price = wpinv_get_item_price( $item->ID );
1917
+                    $item_price = wpinv_get_item_price($item->ID);
1918 1918
                 }
1919 1919
             }
1920 1920
 
1921 1921
             // Sanitizing the price here so we don't have a dozen calls later
1922
-            $item_price = wpinv_sanitize_amount( $item_price );
1923
-            $subtotal   = wpinv_round_amount( $item_price * $args['quantity'] );
1922
+            $item_price = wpinv_sanitize_amount($item_price);
1923
+            $subtotal   = wpinv_round_amount($item_price * $args['quantity']);
1924 1924
         
1925
-            $discount   = !empty( $args['discount'] ) ? $args['discount'] : 0;
1926
-            $tax_class  = !empty( $args['vat_class'] ) ? $args['vat_class'] : '';
1927
-            $tax_rate   = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0;
1928
-            $tax        = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1925
+            $discount   = !empty($args['discount']) ? $args['discount'] : 0;
1926
+            $tax_class  = !empty($args['vat_class']) ? $args['vat_class'] : '';
1927
+            $tax_rate   = !empty($args['vat_rate']) ? $args['vat_rate'] : 0;
1928
+            $tax        = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
1929 1929
 
1930 1930
             // Setup the items meta item
1931 1931
             $new_item = array(
@@ -1933,29 +1933,29 @@  discard block
 block discarded – undo
1933 1933
                 'quantity' => $args['quantity'],
1934 1934
             );
1935 1935
 
1936
-            $this->items[]  = $new_item;
1936
+            $this->items[] = $new_item;
1937 1937
 
1938
-            if ( wpinv_prices_include_tax() ) {
1939
-                $subtotal -= wpinv_round_amount( $tax );
1938
+            if (wpinv_prices_include_tax()) {
1939
+                $subtotal -= wpinv_round_amount($tax);
1940 1940
             }
1941 1941
 
1942
-            $total      = $subtotal - $discount + $tax;
1942
+            $total = $subtotal - $discount + $tax;
1943 1943
 
1944 1944
             // Do not allow totals to go negative
1945
-            if( $total < 0 ) {
1945
+            if ($total < 0) {
1946 1946
                 $total = 0;
1947 1947
             }
1948 1948
         
1949 1949
             $this->cart_details[] = array(
1950 1950
                 'name'          => !empty($args['name']) ? $args['name'] : $item->get_name(),
1951 1951
                 'id'            => $item->ID,
1952
-                'item_price'    => wpinv_round_amount( $item_price ),
1953
-                'custom_price'  => ( $args['custom_price'] !== '' ? wpinv_round_amount( $args['custom_price'] ) : '' ),
1952
+                'item_price'    => wpinv_round_amount($item_price),
1953
+                'custom_price'  => ($args['custom_price'] !== '' ? wpinv_round_amount($args['custom_price']) : ''),
1954 1954
                 'quantity'      => $args['quantity'],
1955 1955
                 'discount'      => $discount,
1956
-                'subtotal'      => wpinv_round_amount( $subtotal ),
1957
-                'tax'           => wpinv_round_amount( $tax ),
1958
-                'price'         => wpinv_round_amount( $total ),
1956
+                'subtotal'      => wpinv_round_amount($subtotal),
1957
+                'tax'           => wpinv_round_amount($tax),
1958
+                'price'         => wpinv_round_amount($total),
1959 1959
                 'vat_rate'      => $tax_rate,
1960 1960
                 'vat_class'     => $tax_class,
1961 1961
                 'meta'          => $args['meta'],
@@ -1965,18 +1965,18 @@  discard block
 block discarded – undo
1965 1965
             $subtotal = $subtotal - $discount;
1966 1966
         }
1967 1967
         
1968
-        $added_item = end( $this->cart_details );
1969
-        $added_item['action']  = 'add';
1968
+        $added_item = end($this->cart_details);
1969
+        $added_item['action'] = 'add';
1970 1970
         
1971 1971
         $this->pending['items'][] = $added_item;
1972 1972
         
1973
-        $this->increase_subtotal( $subtotal );
1974
-        $this->increase_tax( $tax );
1973
+        $this->increase_subtotal($subtotal);
1974
+        $this->increase_tax($tax);
1975 1975
 
1976 1976
         return true;
1977 1977
     }
1978 1978
     
1979
-    public function remove_item( $item_id, $args = array() ) {
1979
+    public function remove_item($item_id, $args = array()) {
1980 1980
         // Set some defaults
1981 1981
         $defaults = array(
1982 1982
             'quantity'      => 1,
@@ -1984,51 +1984,51 @@  discard block
 block discarded – undo
1984 1984
             'custom_price'  => '',
1985 1985
             'cart_index'    => false,
1986 1986
         );
1987
-        $args = wp_parse_args( $args, $defaults );
1987
+        $args = wp_parse_args($args, $defaults);
1988 1988
 
1989 1989
         // Bail if this post isn't a item
1990
-        if ( get_post_type( $item_id ) !== 'wpi_item' ) {
1990
+        if (get_post_type($item_id) !== 'wpi_item') {
1991 1991
             return false;
1992 1992
         }
1993 1993
         
1994
-        $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1994
+        $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1995 1995
 
1996
-        foreach ( $this->items as $key => $item ) {
1997
-            if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) {
1996
+        foreach ($this->items as $key => $item) {
1997
+            if (!empty($item['id']) && (int) $item_id !== (int) $item['id']) {
1998 1998
                 continue;
1999 1999
             }
2000 2000
 
2001
-            if ( false !== $args['cart_index'] ) {
2002
-                $cart_index = absint( $args['cart_index'] );
2003
-                $cart_item  = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false;
2001
+            if (false !== $args['cart_index']) {
2002
+                $cart_index = absint($args['cart_index']);
2003
+                $cart_item  = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false;
2004 2004
 
2005
-                if ( ! empty( $cart_item ) ) {
2005
+                if (!empty($cart_item)) {
2006 2006
                     // If the cart index item isn't the same item ID, don't remove it
2007
-                    if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) {
2007
+                    if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) {
2008 2008
                         continue;
2009 2009
                     }
2010 2010
                 }
2011 2011
             }
2012 2012
 
2013
-            $item_quantity = $this->items[ $key ]['quantity'];
2014
-            if ( $item_quantity > $args['quantity'] ) {
2015
-                $this->items[ $key ]['quantity'] -= $args['quantity'];
2013
+            $item_quantity = $this->items[$key]['quantity'];
2014
+            if ($item_quantity > $args['quantity']) {
2015
+                $this->items[$key]['quantity'] -= $args['quantity'];
2016 2016
                 break;
2017 2017
             } else {
2018
-                unset( $this->items[ $key ] );
2018
+                unset($this->items[$key]);
2019 2019
                 break;
2020 2020
             }
2021 2021
         }
2022 2022
 
2023 2023
         $found_cart_key = false;
2024
-        if ( false === $args['cart_index'] ) {
2025
-            foreach ( $this->cart_details as $cart_key => $item ) {
2026
-                if ( $item_id != $item['id'] ) {
2024
+        if (false === $args['cart_index']) {
2025
+            foreach ($this->cart_details as $cart_key => $item) {
2026
+                if ($item_id != $item['id']) {
2027 2027
                     continue;
2028 2028
                 }
2029 2029
 
2030
-                if ( false !== $args['item_price'] ) {
2031
-                    if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) {
2030
+                if (false !== $args['item_price']) {
2031
+                    if (isset($item['item_price']) && (float) $args['item_price'] != (float) $item['item_price']) {
2032 2032
                         continue;
2033 2033
                     }
2034 2034
                 }
@@ -2037,13 +2037,13 @@  discard block
 block discarded – undo
2037 2037
                 break;
2038 2038
             }
2039 2039
         } else {
2040
-            $cart_index = absint( $args['cart_index'] );
2040
+            $cart_index = absint($args['cart_index']);
2041 2041
 
2042
-            if ( ! array_key_exists( $cart_index, $this->cart_details ) ) {
2042
+            if (!array_key_exists($cart_index, $this->cart_details)) {
2043 2043
                 return false; // Invalid cart index passed.
2044 2044
             }
2045 2045
 
2046
-            if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) {
2046
+            if ((int) $this->cart_details[$cart_index]['id'] > 0 && (int) $this->cart_details[$cart_index]['id'] !== (int) $item_id) {
2047 2047
                 return false; // We still need the proper Item ID to be sure.
2048 2048
             }
2049 2049
 
@@ -2051,41 +2051,41 @@  discard block
 block discarded – undo
2051 2051
         }
2052 2052
         
2053 2053
         $cart_item  = $this->cart_details[$found_cart_key];
2054
-        $quantity   = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
2054
+        $quantity   = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
2055 2055
         
2056
-        if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) {
2056
+        if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) {
2057 2057
             //return false; // Invoice must contain at least one item.
2058 2058
         }
2059 2059
         
2060
-        $discounts  = $this->get_discounts();
2060
+        $discounts = $this->get_discounts();
2061 2061
         
2062
-        if ( $quantity > $args['quantity'] ) {
2062
+        if ($quantity > $args['quantity']) {
2063 2063
             $item_price         = $cart_item['item_price'];
2064
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
2064
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
2065 2065
             
2066
-            $new_quantity       = max( $quantity - $args['quantity'], 1);
2066
+            $new_quantity       = max($quantity - $args['quantity'], 1);
2067 2067
             $subtotal           = $item_price * $new_quantity;
2068 2068
             
2069 2069
             $args['quantity']   = $new_quantity;
2070
-            $discount           = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
2071
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
2070
+            $discount           = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
2071
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
2072 2072
             
2073
-            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0;
2074
-            $discount_decrease  = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; 
2075
-            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0;
2076
-            $tax_decrease       = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease;
2073
+            $discount_decrease  = (float) $cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['discount'] / $quantity)) : 0;
2074
+            $discount_decrease  = $discount > 0 && $subtotal > 0 && (float) $cart_item['discount'] > $discount ? (float) $cart_item['discount'] - $discount : $discount_decrease; 
2075
+            $tax_decrease       = (float) $cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['tax'] / $quantity)) : 0;
2076
+            $tax_decrease       = $tax > 0 && $subtotal > 0 && (float) $cart_item['tax'] > $tax ? (float) $cart_item['tax'] - $tax : $tax_decrease;
2077 2077
             
2078 2078
             // The total increase equals the number removed * the item_price
2079
-            $total_decrease     = wpinv_round_amount( $item_price );
2079
+            $total_decrease     = wpinv_round_amount($item_price);
2080 2080
             
2081
-            if ( wpinv_prices_include_tax() ) {
2082
-                $subtotal -= wpinv_round_amount( $tax );
2081
+            if (wpinv_prices_include_tax()) {
2082
+                $subtotal -= wpinv_round_amount($tax);
2083 2083
             }
2084 2084
 
2085
-            $total              = $subtotal - $discount + $tax;
2085
+            $total = $subtotal - $discount + $tax;
2086 2086
 
2087 2087
             // Do not allow totals to go negative
2088
-            if( $total < 0 ) {
2088
+            if ($total < 0) {
2089 2089
                 $total = 0;
2090 2090
             }
2091 2091
             
@@ -2104,16 +2104,16 @@  discard block
 block discarded – undo
2104 2104
             
2105 2105
             $this->cart_details[$found_cart_key] = $cart_item;
2106 2106
             
2107
-            $remove_item = end( $this->cart_details );
2107
+            $remove_item = end($this->cart_details);
2108 2108
         } else {
2109 2109
             $item_price     = $cart_item['item_price'];
2110
-            $discount       = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
2111
-            $tax            = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0;
2110
+            $discount       = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
2111
+            $tax            = !empty($cart_item['tax']) ? $cart_item['tax'] : 0;
2112 2112
         
2113
-            $subtotal_decrease  = ( $item_price * $quantity ) - $discount;
2113
+            $subtotal_decrease  = ($item_price * $quantity) - $discount;
2114 2114
             $tax_decrease       = $tax;
2115 2115
 
2116
-            unset( $this->cart_details[$found_cart_key] );
2116
+            unset($this->cart_details[$found_cart_key]);
2117 2117
             
2118 2118
             $remove_item             = $args;
2119 2119
             $remove_item['id']       = $item_id;
@@ -2124,8 +2124,8 @@  discard block
 block discarded – undo
2124 2124
         $remove_item['action']      = 'remove';
2125 2125
         $this->pending['items'][]   = $remove_item;
2126 2126
                
2127
-        $this->decrease_subtotal( $subtotal_decrease );
2128
-        $this->decrease_tax( $tax_decrease );
2127
+        $this->decrease_subtotal($subtotal_decrease);
2128
+        $this->decrease_tax($tax_decrease);
2129 2129
         
2130 2130
         return true;
2131 2131
     }
@@ -2133,7 +2133,7 @@  discard block
 block discarded – undo
2133 2133
     public function update_items($temp = false) {
2134 2134
         global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave;
2135 2135
         
2136
-        if ( !empty( $this->cart_details ) ) {
2136
+        if (!empty($this->cart_details)) {
2137 2137
             $wpi_nosave             = $temp;
2138 2138
             $cart_subtotal          = 0;
2139 2139
             $cart_discount          = 0;
@@ -2143,65 +2143,65 @@  discard block
 block discarded – undo
2143 2143
             $_POST['wpinv_country'] = $this->country;
2144 2144
             $_POST['wpinv_state']   = $this->state;
2145 2145
 
2146
-            foreach ( $this->cart_details as $key => $item ) {
2146
+            foreach ($this->cart_details as $key => $item) {
2147 2147
                 $item_price = $item['item_price'];
2148
-                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
2149
-                $amount     = wpinv_round_amount( $item_price * $quantity );
2148
+                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1;
2149
+                $amount     = wpinv_round_amount($item_price * $quantity);
2150 2150
                 $subtotal   = $item_price * $quantity;
2151 2151
                 
2152 2152
                 $wpi_current_id         = $this->ID;
2153 2153
                 $wpi_item_id            = $item['id'];
2154 2154
                 
2155
-                $discount   = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() );
2155
+                $discount   = wpinv_get_cart_item_discount_amount($item, $this->get_discounts());
2156 2156
                 
2157
-                $tax_rate   = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id );
2158
-                $tax_class  = $wpinv_euvat->get_item_class( $wpi_item_id );
2159
-                $tax        = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
2157
+                $tax_rate   = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id);
2158
+                $tax_class  = $wpinv_euvat->get_item_class($wpi_item_id);
2159
+                $tax        = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
2160 2160
 
2161
-                if ( ! $this->is_taxable() ) {
2161
+                if (!$this->is_taxable()) {
2162 2162
                     $tax = 0;
2163 2163
                 }
2164 2164
 
2165
-                if ( wpinv_prices_include_tax() ) {
2166
-                    $subtotal -= wpinv_round_amount( $tax );
2165
+                if (wpinv_prices_include_tax()) {
2166
+                    $subtotal -= wpinv_round_amount($tax);
2167 2167
                 }
2168 2168
 
2169
-                $total      = $subtotal - $discount + $tax;
2169
+                $total = $subtotal - $discount + $tax;
2170 2170
 
2171 2171
                 // Do not allow totals to go negative
2172
-                if( $total < 0 ) {
2172
+                if ($total < 0) {
2173 2173
                     $total = 0;
2174 2174
                 }
2175 2175
 
2176 2176
                 $cart_details[] = array(
2177 2177
                     'id'          => $item['id'],
2178 2178
                     'name'        => $item['name'],
2179
-                    'item_price'  => wpinv_round_amount( $item_price ),
2180
-                    'custom_price'=> ( isset( $item['custom_price'] ) ? $item['custom_price'] : '' ),
2179
+                    'item_price'  => wpinv_round_amount($item_price),
2180
+                    'custom_price'=> (isset($item['custom_price']) ? $item['custom_price'] : ''),
2181 2181
                     'quantity'    => $quantity,
2182 2182
                     'discount'    => $discount,
2183
-                    'subtotal'    => wpinv_round_amount( $subtotal ),
2184
-                    'tax'         => wpinv_round_amount( $tax ),
2185
-                    'price'       => wpinv_round_amount( $total ),
2183
+                    'subtotal'    => wpinv_round_amount($subtotal),
2184
+                    'tax'         => wpinv_round_amount($tax),
2185
+                    'price'       => wpinv_round_amount($total),
2186 2186
                     'vat_rate'    => $tax_rate,
2187 2187
                     'vat_class'   => $tax_class,
2188 2188
                     'meta'        => isset($item['meta']) ? $item['meta'] : array(),
2189 2189
                     'fees'        => isset($item['fees']) ? $item['fees'] : array(),
2190 2190
                 );
2191 2191
 
2192
-                $cart_subtotal  += (float)($subtotal - $discount); // TODO
2193
-                $cart_discount  += (float)($discount);
2194
-                $cart_tax       += (float)($tax);
2192
+                $cart_subtotal  += (float) ($subtotal - $discount); // TODO
2193
+                $cart_discount  += (float) ($discount);
2194
+                $cart_tax       += (float) ($tax);
2195 2195
             }
2196
-            if ( $cart_subtotal < 0 ) {
2196
+            if ($cart_subtotal < 0) {
2197 2197
                 $cart_subtotal = 0;
2198 2198
             }
2199
-            if ( $cart_tax < 0 ) {
2199
+            if ($cart_tax < 0) {
2200 2200
                 $cart_tax = 0;
2201 2201
             }
2202
-            $this->subtotal = wpinv_round_amount( $cart_subtotal );
2203
-            $this->tax      = wpinv_round_amount( $cart_tax );
2204
-            $this->discount = wpinv_round_amount( $cart_discount );
2202
+            $this->subtotal = wpinv_round_amount($cart_subtotal);
2203
+            $this->tax      = wpinv_round_amount($cart_tax);
2204
+            $this->discount = wpinv_round_amount($cart_discount);
2205 2205
             
2206 2206
             $this->recalculate_total();
2207 2207
             
@@ -2213,177 +2213,177 @@  discard block
 block discarded – undo
2213 2213
     
2214 2214
     public function recalculate_totals($temp = false) {        
2215 2215
         $this->update_items($temp);
2216
-        $this->save( true );
2216
+        $this->save(true);
2217 2217
         
2218 2218
         return $this;
2219 2219
     }
2220 2220
     
2221 2221
     public function needs_payment() {
2222
-        $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'wpi-pending' ), $this );
2222
+        $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('wpi-pending'), $this);
2223 2223
 
2224
-        if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free() ) ) {
2224
+        if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free())) {
2225 2225
             $needs_payment = true;
2226 2226
         } else {
2227 2227
             $needs_payment = false;
2228 2228
         }
2229 2229
 
2230
-        return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses );
2230
+        return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses);
2231 2231
     }
2232 2232
     
2233
-    public function get_checkout_payment_url( $with_key = false, $secret = false ) {
2233
+    public function get_checkout_payment_url($with_key = false, $secret = false) {
2234 2234
         $pay_url = wpinv_get_checkout_uri();
2235 2235
 
2236
-        if ( is_ssl() ) {
2237
-            $pay_url = str_replace( 'http:', 'https:', $pay_url );
2236
+        if (is_ssl()) {
2237
+            $pay_url = str_replace('http:', 'https:', $pay_url);
2238 2238
         }
2239 2239
         
2240 2240
         $key = $this->get_key();
2241 2241
 
2242
-        if ( $with_key ) {
2243
-            $pay_url = add_query_arg( 'invoice_key', $key, $pay_url );
2242
+        if ($with_key) {
2243
+            $pay_url = add_query_arg('invoice_key', $key, $pay_url);
2244 2244
         } else {
2245
-            $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url );
2245
+            $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url);
2246 2246
         }
2247 2247
         
2248
-        if ( $secret ) {
2249
-            $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url );
2248
+        if ($secret) {
2249
+            $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url);
2250 2250
         }
2251 2251
 
2252
-        return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret );
2252
+        return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret);
2253 2253
     }
2254 2254
     
2255
-    public function get_view_url( $with_key = false ) {
2256
-        $invoice_url = get_permalink( $this->ID );
2255
+    public function get_view_url($with_key = false) {
2256
+        $invoice_url = get_permalink($this->ID);
2257 2257
 
2258
-        if ( $with_key ) {
2259
-            $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
2258
+        if ($with_key) {
2259
+            $invoice_url = add_query_arg('invoice_key', $this->get_key(), $invoice_url);
2260 2260
         }
2261 2261
 
2262
-        return apply_filters( 'wpinv_get_view_url', $invoice_url, $this, $with_key );
2262
+        return apply_filters('wpinv_get_view_url', $invoice_url, $this, $with_key);
2263 2263
     }
2264 2264
     
2265
-    public function generate_key( $string = '' ) {
2266
-        $auth_key  = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
2267
-        return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) );  // Unique key
2265
+    public function generate_key($string = '') {
2266
+        $auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
2267
+        return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key
2268 2268
     }
2269 2269
     
2270 2270
     public function is_recurring() {
2271
-        if ( empty( $this->cart_details ) ) {
2271
+        if (empty($this->cart_details)) {
2272 2272
             return false;
2273 2273
         }
2274 2274
         
2275 2275
         $has_subscription = false;
2276
-        foreach( $this->cart_details as $cart_item ) {
2277
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2276
+        foreach ($this->cart_details as $cart_item) {
2277
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2278 2278
                 $has_subscription = true;
2279 2279
                 break;
2280 2280
             }
2281 2281
         }
2282 2282
         
2283
-        if ( count( $this->cart_details ) > 1 ) {
2283
+        if (count($this->cart_details) > 1) {
2284 2284
             $has_subscription = false;
2285 2285
         }
2286 2286
 
2287
-        return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details );
2287
+        return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details);
2288 2288
     }
2289 2289
 
2290 2290
     public function is_free_trial() {
2291 2291
         $is_free_trial = false;
2292 2292
         
2293
-        if ( $this->is_parent() && $item = $this->get_recurring( true ) ) {
2294
-            if ( !empty( $item ) && $item->has_free_trial() ) {
2293
+        if ($this->is_parent() && $item = $this->get_recurring(true)) {
2294
+            if (!empty($item) && $item->has_free_trial()) {
2295 2295
                 $is_free_trial = true;
2296 2296
             }
2297 2297
         }
2298 2298
 
2299
-        return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this );
2299
+        return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this);
2300 2300
     }
2301 2301
 
2302 2302
     public function is_initial_free() {
2303 2303
         $is_initial_free = false;
2304 2304
         
2305
-        if ( ! ( (float)wpinv_round_amount( $this->get_total() ) > 0 ) && $this->is_parent() && $this->is_recurring() && ! $this->is_free_trial() && ! $this->is_free() ) {
2305
+        if (!((float) wpinv_round_amount($this->get_total()) > 0) && $this->is_parent() && $this->is_recurring() && !$this->is_free_trial() && !$this->is_free()) {
2306 2306
             $is_initial_free = true;
2307 2307
         }
2308 2308
 
2309
-        return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details );
2309
+        return apply_filters('wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details);
2310 2310
     }
2311 2311
     
2312
-    public function get_recurring( $object = false ) {
2312
+    public function get_recurring($object = false) {
2313 2313
         $item = NULL;
2314 2314
         
2315
-        if ( empty( $this->cart_details ) ) {
2315
+        if (empty($this->cart_details)) {
2316 2316
             return $item;
2317 2317
         }
2318 2318
         
2319
-        foreach( $this->cart_details as $cart_item ) {
2320
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2319
+        foreach ($this->cart_details as $cart_item) {
2320
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2321 2321
                 $item = $cart_item['id'];
2322 2322
                 break;
2323 2323
             }
2324 2324
         }
2325 2325
         
2326
-        if ( $object ) {
2327
-            $item = $item ? new WPInv_Item( $item ) : NULL;
2326
+        if ($object) {
2327
+            $item = $item ? new WPInv_Item($item) : NULL;
2328 2328
             
2329
-            apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this );
2329
+            apply_filters('wpinv_invoice_get_recurring_item', $item, $this);
2330 2330
         }
2331 2331
 
2332
-        return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this );
2332
+        return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this);
2333 2333
     }
2334 2334
 
2335 2335
     public function get_subscription_name() {
2336
-        $item = $this->get_recurring( true );
2336
+        $item = $this->get_recurring(true);
2337 2337
 
2338
-        if ( empty( $item ) ) {
2338
+        if (empty($item)) {
2339 2339
             return NULL;
2340 2340
         }
2341 2341
 
2342
-        if ( !($name = $item->get_name()) ) {
2342
+        if (!($name = $item->get_name())) {
2343 2343
             $name = $item->post_name;
2344 2344
         }
2345 2345
 
2346
-        return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this );
2346
+        return apply_filters('wpinv_invoice_get_subscription_name', $name, $this);
2347 2347
     }
2348 2348
 
2349 2349
     public function get_subscription_id() {
2350
-        $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true );
2350
+        $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true);
2351 2351
 
2352
-        if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) {
2353
-            $parent_invoice = wpinv_get_invoice( $this->parent_invoice );
2352
+        if (empty($subscription_id) && !empty($this->parent_invoice)) {
2353
+            $parent_invoice = wpinv_get_invoice($this->parent_invoice);
2354 2354
 
2355
-            $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true );
2355
+            $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true);
2356 2356
         }
2357 2357
         
2358 2358
         return $subscription_id;
2359 2359
     }
2360 2360
     
2361 2361
     public function is_parent() {
2362
-        $is_parent = empty( $this->parent_invoice ) ? true : false;
2362
+        $is_parent = empty($this->parent_invoice) ? true : false;
2363 2363
 
2364
-        return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this );
2364
+        return apply_filters('wpinv_invoice_is_parent', $is_parent, $this);
2365 2365
     }
2366 2366
     
2367 2367
     public function is_renewal() {
2368 2368
         $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false;
2369 2369
 
2370
-        return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this );
2370
+        return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this);
2371 2371
     }
2372 2372
     
2373 2373
     public function get_parent_payment() {
2374 2374
         $parent_payment = NULL;
2375 2375
         
2376
-        if ( $this->is_renewal() ) {
2377
-            $parent_payment = wpinv_get_invoice( $this->parent_invoice );
2376
+        if ($this->is_renewal()) {
2377
+            $parent_payment = wpinv_get_invoice($this->parent_invoice);
2378 2378
         }
2379 2379
         
2380 2380
         return $parent_payment;
2381 2381
     }
2382 2382
     
2383 2383
     public function is_paid() {
2384
-        $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) );
2384
+        $is_paid = $this->has_status(array('publish', 'wpi-processing', 'wpi-renewal'));
2385 2385
 
2386
-        return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this );
2386
+        return apply_filters('wpinv_invoice_is_paid', $is_paid, $this);
2387 2387
     }
2388 2388
 
2389 2389
     /**
@@ -2396,23 +2396,23 @@  discard block
 block discarded – undo
2396 2396
     }
2397 2397
     
2398 2398
     public function is_refunded() {
2399
-        $is_refunded = $this->has_status( array( 'wpi-refunded' ) );
2399
+        $is_refunded = $this->has_status(array('wpi-refunded'));
2400 2400
 
2401
-        return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this );
2401
+        return apply_filters('wpinv_invoice_is_refunded', $is_refunded, $this);
2402 2402
     }
2403 2403
     
2404 2404
     public function is_free() {
2405 2405
         $is_free = false;
2406 2406
         
2407
-        if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) {
2408
-            if ( $this->is_parent() && $this->is_recurring() ) {
2409
-                $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true;
2407
+        if (!((float) wpinv_round_amount($this->get_total()) > 0)) {
2408
+            if ($this->is_parent() && $this->is_recurring()) {
2409
+                $is_free = (float) wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true;
2410 2410
             } else {
2411 2411
                 $is_free = true;
2412 2412
             }
2413 2413
         }
2414 2414
         
2415
-        return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2415
+        return apply_filters('wpinv_invoice_is_free', $is_free, $this);
2416 2416
     }
2417 2417
     
2418 2418
     public function has_vat() {
@@ -2420,41 +2420,41 @@  discard block
 block discarded – undo
2420 2420
         
2421 2421
         $requires_vat = false;
2422 2422
         
2423
-        if ( $this->country ) {
2423
+        if ($this->country) {
2424 2424
             $wpi_country        = $this->country;
2425 2425
             
2426
-            $requires_vat       = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) );
2426
+            $requires_vat       = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this));
2427 2427
         }
2428 2428
         
2429
-        return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2429
+        return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this);
2430 2430
     }
2431 2431
     
2432 2432
     public function refresh_item_ids() {
2433 2433
         $item_ids = array();
2434 2434
         
2435
-        if ( !empty( $this->cart_details ) ) {
2436
-            foreach ( $this->cart_details as $key => $item ) {
2437
-                if ( !empty( $item['id'] ) ) {
2435
+        if (!empty($this->cart_details)) {
2436
+            foreach ($this->cart_details as $key => $item) {
2437
+                if (!empty($item['id'])) {
2438 2438
                     $item_ids[] = $item['id'];
2439 2439
                 }
2440 2440
             }
2441 2441
         }
2442 2442
         
2443
-        $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : '';
2443
+        $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : '';
2444 2444
         
2445
-        update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids );
2445
+        update_post_meta($this->ID, '_wpinv_item_ids', $item_ids);
2446 2446
     }
2447 2447
     
2448
-    public function get_invoice_quote_type( $post_id ) {
2449
-        if ( empty( $post_id ) ) {
2448
+    public function get_invoice_quote_type($post_id) {
2449
+        if (empty($post_id)) {
2450 2450
             return '';
2451 2451
         }
2452 2452
 
2453
-        $type = get_post_type( $post_id );
2453
+        $type = get_post_type($post_id);
2454 2454
 
2455
-        if ( 'wpi_invoice' === $type ) {
2455
+        if ('wpi_invoice' === $type) {
2456 2456
             $post_type = __('Invoice', 'invoicing');
2457
-        } else{
2457
+        } else {
2458 2458
             $post_type = __('Quote', 'invoicing');
2459 2459
         }
2460 2460
 
Please login to merge, or discard this patch.
includes/admin/register-settings.php 1 patch
Spacing   +396 added lines, -396 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   1.0.0
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Retrieves all default settings.
@@ -16,13 +16,13 @@  discard block
 block discarded – undo
16 16
 function wpinv_get_settings() {
17 17
     $defaults = array();
18 18
 
19
-    foreach ( array_values( wpinv_get_registered_settings() ) as $tab_settings ) {
19
+    foreach (array_values(wpinv_get_registered_settings()) as $tab_settings) {
20 20
 
21
-        foreach ( array_values( $tab_settings ) as $section_settings ) {
21
+        foreach (array_values($tab_settings) as $section_settings) {
22 22
 
23
-            foreach ( $section_settings as $key => $setting ) {
24
-                if ( isset( $setting['std'] ) ) {
25
-                    $defaults[ $key ] = $setting['std'];
23
+            foreach ($section_settings as $key => $setting) {
24
+                if (isset($setting['std'])) {
25
+                    $defaults[$key] = $setting['std'];
26 26
                 }
27 27
             }
28 28
 
@@ -43,12 +43,12 @@  discard block
 block discarded – undo
43 43
     global $wpinv_options;
44 44
 
45 45
     // Try fetching the saved options.
46
-    if ( ! is_array( $wpinv_options ) ) {
47
-        $wpinv_options = get_option( 'wpinv_settings' );
46
+    if (!is_array($wpinv_options)) {
47
+        $wpinv_options = get_option('wpinv_settings');
48 48
     }
49 49
 
50 50
     // If that fails, don't fetch the default settings to prevent a loop.
51
-    if ( ! is_array( $wpinv_options ) ) {
51
+    if (!is_array($wpinv_options)) {
52 52
         $wpinv_options = array();
53 53
     }
54 54
 
@@ -62,13 +62,13 @@  discard block
 block discarded – undo
62 62
  * @param mixed $default The default value to use if the setting has not been set.
63 63
  * @return mixed
64 64
  */
65
-function wpinv_get_option( $key = '', $default = false ) {
65
+function wpinv_get_option($key = '', $default = false) {
66 66
 
67 67
     $options = wpinv_get_options();
68
-    $value   = isset( $options[ $key ] ) ? $options[ $key ] : $default;
69
-    $value   = apply_filters( 'wpinv_get_option', $value, $key, $default );
68
+    $value   = isset($options[$key]) ? $options[$key] : $default;
69
+    $value   = apply_filters('wpinv_get_option', $value, $key, $default);
70 70
 
71
-    return apply_filters( 'wpinv_get_option_' . $key, $value, $key, $default );
71
+    return apply_filters('wpinv_get_option_' . $key, $value, $key, $default);
72 72
 }
73 73
 
74 74
 /**
@@ -77,11 +77,11 @@  discard block
 block discarded – undo
77 77
  * @param array $options the new options.
78 78
  * @return bool
79 79
  */
80
-function wpinv_update_options( $options ) {
80
+function wpinv_update_options($options) {
81 81
     global $wpinv_options;
82 82
 
83 83
     // update the option.
84
-    if ( is_array( $options ) && update_option( 'wpinv_settings', $options ) ) {
84
+    if (is_array($options) && update_option('wpinv_settings', $options)) {
85 85
         $wpinv_options = $options;
86 86
         return true;
87 87
     }
@@ -96,24 +96,24 @@  discard block
 block discarded – undo
96 96
  * @param mixed $value The setting value.
97 97
  * @return bool
98 98
  */
99
-function wpinv_update_option( $key = '', $value = false ) {
99
+function wpinv_update_option($key = '', $value = false) {
100 100
 
101 101
     // If no key, exit.
102
-    if ( empty( $key ) ) {
102
+    if (empty($key)) {
103 103
         return false;
104 104
     }
105 105
 
106 106
     // Maybe delete the option instead.
107
-    if ( is_null( $value ) ) {
108
-        return wpinv_delete_option( $key );
107
+    if (is_null($value)) {
108
+        return wpinv_delete_option($key);
109 109
     }
110 110
 
111 111
     // Prepare the new options.
112 112
     $options         = wpinv_get_options();
113
-    $options[ $key ] = apply_filters( 'wpinv_update_option', $value, $key );
113
+    $options[$key] = apply_filters('wpinv_update_option', $value, $key);
114 114
 
115 115
     // Save the new options.
116
-    return wpinv_update_options( $options );
116
+    return wpinv_update_options($options);
117 117
 
118 118
 }
119 119
 
@@ -123,18 +123,18 @@  discard block
 block discarded – undo
123 123
  * @param string $key the setting key.
124 124
  * @return bool
125 125
  */
126
-function wpinv_delete_option( $key = '' ) {
126
+function wpinv_delete_option($key = '') {
127 127
 
128 128
     // If no key, exit
129
-    if ( empty( $key ) ) {
129
+    if (empty($key)) {
130 130
         return false;
131 131
     }
132 132
 
133 133
     $options = wpinv_get_options();
134 134
 
135
-    if ( isset( $options[ $key ] ) ) {
136
-        unset( $options[ $key ] );
137
-        return wpinv_update_options( $options );
135
+    if (isset($options[$key])) {
136
+        unset($options[$key]);
137
+        return wpinv_update_options($options);
138 138
     }
139 139
 
140 140
     return true;
@@ -148,14 +148,14 @@  discard block
 block discarded – undo
148 148
 function wpinv_register_settings() {
149 149
 
150 150
     // Loop through all tabs.
151
-    foreach ( wpinv_get_registered_settings() as $tab => $sections ) {
151
+    foreach (wpinv_get_registered_settings() as $tab => $sections) {
152 152
 
153 153
         // In each tab, loop through sections.
154
-        foreach ( $sections as $section => $settings ) {
154
+        foreach ($sections as $section => $settings) {
155 155
 
156 156
             // Check for backwards compatibility
157
-            $section_tabs = wpinv_get_settings_tab_sections( $tab );
158
-            if ( ! is_array( $section_tabs ) || ! array_key_exists( $section, $section_tabs ) ) {
157
+            $section_tabs = wpinv_get_settings_tab_sections($tab);
158
+            if (!is_array($section_tabs) || !array_key_exists($section, $section_tabs)) {
159 159
                 $section = 'main';
160 160
                 $settings = $sections;
161 161
             }
@@ -168,9 +168,9 @@  discard block
 block discarded – undo
168 168
                 'wpinv_settings_' . $tab . '_' . $section
169 169
             );
170 170
 
171
-            foreach ( $settings as $option ) {
172
-                if ( ! empty( $option['id'] ) ) {
173
-                    wpinv_register_settings_option( $tab, $section, $option );
171
+            foreach ($settings as $option) {
172
+                if (!empty($option['id'])) {
173
+                    wpinv_register_settings_option($tab, $section, $option);
174 174
                 }
175 175
             }
176 176
 
@@ -178,9 +178,9 @@  discard block
 block discarded – undo
178 178
     }
179 179
 
180 180
     // Creates our settings in the options table.
181
-    register_setting( 'wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize' );
181
+    register_setting('wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize');
182 182
 }
183
-add_action( 'admin_init', 'wpinv_register_settings' );
183
+add_action('admin_init', 'wpinv_register_settings');
184 184
 
185 185
 /**
186 186
  * Register a single settings option.
@@ -190,46 +190,46 @@  discard block
 block discarded – undo
190 190
  * @param string $option
191 191
  * 
192 192
  */
193
-function wpinv_register_settings_option( $tab, $section, $option ) {
193
+function wpinv_register_settings_option($tab, $section, $option) {
194 194
 
195
-    $name    = isset( $option['name'] ) ? $option['name'] : '';
195
+    $name    = isset($option['name']) ? $option['name'] : '';
196 196
     $cb      = "wpinv_{$option['type']}_callback";
197 197
     $section = "wpinv_settings_{$tab}_$section";
198 198
 
199
-	if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) {
200
-		$tip   = esc_attr( $option['desc'] );
199
+	if (isset($option['desc']) && !empty($option['help-tip'])) {
200
+		$tip   = esc_attr($option['desc']);
201 201
 		$name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
202
-		unset( $option['desc'] );
202
+		unset($option['desc']);
203 203
 	}
204 204
 
205 205
     // Loop through all tabs.
206 206
     add_settings_field(
207 207
         'wpinv_settings[' . $option['id'] . ']',
208 208
         $name,
209
-        function_exists( $cb ) ? $cb : 'wpinv_missing_callback',
209
+        function_exists($cb) ? $cb : 'wpinv_missing_callback',
210 210
         $section,
211 211
         $section,
212 212
         array(
213 213
             'section'     => $section,
214
-            'id'          => isset( $option['id'] )          ? $option['id']          : null,
215
-            'desc'        => isset( $option['desc'] )        ? $option['desc']        : '',
214
+            'id'          => isset($option['id']) ? $option['id'] : null,
215
+            'desc'        => isset($option['desc']) ? $option['desc'] : '',
216 216
             'name'        => $name,
217
-            'size'        => isset( $option['size'] )        ? $option['size']        : null,
218
-            'options'     => isset( $option['options'] )     ? $option['options']     : '',
219
-            'selected'    => isset( $option['selected'] )    ? $option['selected']    : null,
220
-            'std'         => isset( $option['std'] )         ? $option['std']         : '',
221
-            'min'         => isset( $option['min'] )         ? $option['min']         : null,
222
-            'max'         => isset( $option['max'] )         ? $option['max']         : null,
223
-            'step'        => isset( $option['step'] )        ? $option['step']        : null,
224
-            'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : null,
225
-            'allow_blank' => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true,
226
-            'readonly'    => isset( $option['readonly'] )    ? $option['readonly']    : false,
227
-            'faux'        => isset( $option['faux'] )        ? $option['faux']        : false,
228
-            'onchange'    => isset( $option['onchange'] )   ? $option['onchange']     : '',
229
-            'custom'      => isset( $option['custom'] )     ? $option['custom']       : '',
230
-            'class'       => isset( $option['class'] )     ? $option['class']         : '',
231
-            'cols'        => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50,
232
-            'rows'        => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5,
217
+            'size'        => isset($option['size']) ? $option['size'] : null,
218
+            'options'     => isset($option['options']) ? $option['options'] : '',
219
+            'selected'    => isset($option['selected']) ? $option['selected'] : null,
220
+            'std'         => isset($option['std']) ? $option['std'] : '',
221
+            'min'         => isset($option['min']) ? $option['min'] : null,
222
+            'max'         => isset($option['max']) ? $option['max'] : null,
223
+            'step'        => isset($option['step']) ? $option['step'] : null,
224
+            'placeholder' => isset($option['placeholder']) ? $option['placeholder'] : null,
225
+            'allow_blank' => isset($option['allow_blank']) ? $option['allow_blank'] : true,
226
+            'readonly'    => isset($option['readonly']) ? $option['readonly'] : false,
227
+            'faux'        => isset($option['faux']) ? $option['faux'] : false,
228
+            'onchange'    => isset($option['onchange']) ? $option['onchange'] : '',
229
+            'custom'      => isset($option['custom']) ? $option['custom'] : '',
230
+            'class'       => isset($option['class']) ? $option['class'] : '',
231
+            'cols'        => isset($option['cols']) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50,
232
+            'rows'        => isset($option['rows']) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5,
233 233
         )
234 234
     );
235 235
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
  * @return array
242 242
  */
243 243
 function wpinv_get_registered_settings() {
244
-    return apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) );
244
+    return apply_filters('wpinv_registered_settings', wpinv_get_data('admin-settings'));
245 245
 }
246 246
 
247 247
 /**
@@ -249,134 +249,134 @@  discard block
 block discarded – undo
249 249
  * 
250 250
  * @return array
251 251
  */
252
-function wpinv_settings_sanitize( $input = array() ) {
252
+function wpinv_settings_sanitize($input = array()) {
253 253
 
254 254
     $wpinv_options = wpinv_get_options();
255 255
 
256
-    if ( empty( wp_get_raw_referer() ) ) {
256
+    if (empty(wp_get_raw_referer())) {
257 257
         return $input;
258 258
     }
259 259
 
260
-    wp_parse_str( wp_get_raw_referer(), $referrer );
260
+    wp_parse_str(wp_get_raw_referer(), $referrer);
261 261
 
262 262
     $settings = wpinv_get_registered_settings();
263
-    $tab      = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general';
264
-    $section  = isset( $referrer['section'] ) ? $referrer['section'] : 'main';
263
+    $tab      = isset($referrer['tab']) ? $referrer['tab'] : 'general';
264
+    $section  = isset($referrer['section']) ? $referrer['section'] : 'main';
265 265
 
266 266
     $input = $input ? $input : array();
267
-    $input = apply_filters( 'wpinv_settings_tab_' . $tab . '_sanitize', $input );
268
-    $input = apply_filters( 'wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input );
267
+    $input = apply_filters('wpinv_settings_tab_' . $tab . '_sanitize', $input);
268
+    $input = apply_filters('wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input);
269 269
 
270 270
     // Loop through each setting being saved and pass it through a sanitization filter
271
-    foreach ( $input as $key => $value ) {
271
+    foreach ($input as $key => $value) {
272 272
 
273 273
         // Get the setting type (checkbox, select, etc)
274
-        $type = isset( $settings[ $tab ][$section][ $key ]['type'] ) ? $settings[ $tab ][$section][ $key ]['type'] : false;
274
+        $type = isset($settings[$tab][$section][$key]['type']) ? $settings[$tab][$section][$key]['type'] : false;
275 275
 
276
-        if ( $type ) {
276
+        if ($type) {
277 277
             // Field type specific filter
278
-            $input[$key] = apply_filters( 'wpinv_settings_sanitize_' . $type, $value, $key );
278
+            $input[$key] = apply_filters('wpinv_settings_sanitize_' . $type, $value, $key);
279 279
         }
280 280
 
281 281
         // General filter
282
-        $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
282
+        $input[$key] = apply_filters('wpinv_settings_sanitize', $input[$key], $key);
283 283
     }
284 284
 
285 285
     // Loop through the whitelist and unset any that are empty for the tab being saved
286
-    $main_settings    = $section == 'main' ? $settings[ $tab ] : array(); // Check for extensions that aren't using new sections
287
-    $section_settings = ! empty( $settings[ $tab ][ $section ] ) ? $settings[ $tab ][ $section ] : array();
286
+    $main_settings    = $section == 'main' ? $settings[$tab] : array(); // Check for extensions that aren't using new sections
287
+    $section_settings = !empty($settings[$tab][$section]) ? $settings[$tab][$section] : array();
288 288
 
289
-    $found_settings = array_merge( $main_settings, $section_settings );
289
+    $found_settings = array_merge($main_settings, $section_settings);
290 290
 
291
-    if ( ! empty( $found_settings ) ) {
292
-        foreach ( $found_settings as $key => $value ) {
291
+    if (!empty($found_settings)) {
292
+        foreach ($found_settings as $key => $value) {
293 293
 
294 294
             // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work
295
-            if ( is_numeric( $key ) ) {
295
+            if (is_numeric($key)) {
296 296
                 $key = $value['id'];
297 297
             }
298 298
 
299
-            if ( ! isset( $input[ $key ] ) && isset( $wpinv_options[ $key ] ) ) {
300
-                unset( $wpinv_options[ $key ] );
299
+            if (!isset($input[$key]) && isset($wpinv_options[$key])) {
300
+                unset($wpinv_options[$key]);
301 301
             }
302 302
         }
303 303
     }
304 304
 
305 305
     // Merge our new settings with the existing
306
-    $output = array_merge( $wpinv_options, $input );
306
+    $output = array_merge($wpinv_options, $input);
307 307
 
308
-    add_settings_error( 'wpinv-notices', '', __( 'Settings updated.', 'invoicing' ), 'updated' );
308
+    add_settings_error('wpinv-notices', '', __('Settings updated.', 'invoicing'), 'updated');
309 309
 
310 310
     return $output;
311 311
 }
312 312
 
313
-function wpinv_settings_sanitize_misc_accounting( $input ) {
313
+function wpinv_settings_sanitize_misc_accounting($input) {
314 314
 
315
-    if ( ! wpinv_current_user_can_manage_invoicing() ) {
315
+    if (!wpinv_current_user_can_manage_invoicing()) {
316 316
         return $input;
317 317
     }
318 318
 
319
-    if( ! empty( $input['enable_sequential'] ) && !wpinv_get_option( 'enable_sequential' ) ) {
319
+    if (!empty($input['enable_sequential']) && !wpinv_get_option('enable_sequential')) {
320 320
         // Shows an admin notice about upgrading previous order numbers
321
-        getpaid_session()->set( 'upgrade_sequential', '1' );
321
+        getpaid_session()->set('upgrade_sequential', '1');
322 322
     }
323 323
 
324 324
     return $input;
325 325
 }
326
-add_filter( 'wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting' );
326
+add_filter('wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting');
327 327
 
328
-function wpinv_settings_sanitize_tax_rates( $input ) {
329
-    if( ! wpinv_current_user_can_manage_invoicing() ) {
328
+function wpinv_settings_sanitize_tax_rates($input) {
329
+    if (!wpinv_current_user_can_manage_invoicing()) {
330 330
         return $input;
331 331
     }
332 332
 
333
-    $new_rates = !empty( $_POST['tax_rates'] ) ? array_values( $_POST['tax_rates'] ) : array();
333
+    $new_rates = !empty($_POST['tax_rates']) ? array_values($_POST['tax_rates']) : array();
334 334
 
335 335
     $tax_rates = array();
336 336
 
337
-    if ( !empty( $new_rates ) ) {
338
-        foreach ( $new_rates as $rate ) {
339
-            if ( isset( $rate['country'] ) && empty( $rate['country'] ) && empty( $rate['state'] ) ) {
337
+    if (!empty($new_rates)) {
338
+        foreach ($new_rates as $rate) {
339
+            if (isset($rate['country']) && empty($rate['country']) && empty($rate['state'])) {
340 340
                 continue;
341 341
             }
342 342
             
343
-            $rate['rate'] = wpinv_sanitize_amount( $rate['rate'], 4 );
343
+            $rate['rate'] = wpinv_sanitize_amount($rate['rate'], 4);
344 344
             
345 345
             $tax_rates[] = $rate;
346 346
         }
347 347
     }
348 348
 
349
-    update_option( 'wpinv_tax_rates', $tax_rates );
349
+    update_option('wpinv_tax_rates', $tax_rates);
350 350
 
351 351
     return $input;
352 352
 }
353
-add_filter( 'wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates' );
353
+add_filter('wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates');
354 354
 
355
-function wpinv_sanitize_text_field( $input ) {
356
-    return trim( $input );
355
+function wpinv_sanitize_text_field($input) {
356
+    return trim($input);
357 357
 }
358
-add_filter( 'wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field' );
358
+add_filter('wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field');
359 359
 
360 360
 function wpinv_get_settings_tabs() {
361 361
     $tabs             = array();
362
-    $tabs['general']  = __( 'General', 'invoicing' );
363
-    $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' );
364
-    $tabs['taxes']    = __( 'Taxes', 'invoicing' );
365
-    $tabs['emails']   = __( 'Emails', 'invoicing' );
366
-    $tabs['privacy']  = __( 'Privacy', 'invoicing' );
367
-    $tabs['misc']     = __( 'Misc', 'invoicing' );
368
-    $tabs['tools']    = __( 'Tools', 'invoicing' );
369
-
370
-    return apply_filters( 'wpinv_settings_tabs', $tabs );
362
+    $tabs['general']  = __('General', 'invoicing');
363
+    $tabs['gateways'] = __('Payment Gateways', 'invoicing');
364
+    $tabs['taxes']    = __('Taxes', 'invoicing');
365
+    $tabs['emails']   = __('Emails', 'invoicing');
366
+    $tabs['privacy']  = __('Privacy', 'invoicing');
367
+    $tabs['misc']     = __('Misc', 'invoicing');
368
+    $tabs['tools']    = __('Tools', 'invoicing');
369
+
370
+    return apply_filters('wpinv_settings_tabs', $tabs);
371 371
 }
372 372
 
373
-function wpinv_get_settings_tab_sections( $tab = false ) {
373
+function wpinv_get_settings_tab_sections($tab = false) {
374 374
     $tabs     = false;
375 375
     $sections = wpinv_get_registered_settings_sections();
376 376
 
377
-    if( $tab && ! empty( $sections[ $tab ] ) ) {
378
-        $tabs = $sections[ $tab ];
379
-    } else if ( $tab ) {
377
+    if ($tab && !empty($sections[$tab])) {
378
+        $tabs = $sections[$tab];
379
+    } else if ($tab) {
380 380
         $tabs = false;
381 381
     }
382 382
 
@@ -386,150 +386,150 @@  discard block
 block discarded – undo
386 386
 function wpinv_get_registered_settings_sections() {
387 387
     static $sections = false;
388 388
 
389
-    if ( false !== $sections ) {
389
+    if (false !== $sections) {
390 390
         return $sections;
391 391
     }
392 392
 
393 393
     $sections = array(
394
-        'general' => apply_filters( 'wpinv_settings_sections_general', array(
395
-            'main' => __( 'General Settings', 'invoicing' ),
396
-            'currency_section' => __( 'Currency Settings', 'invoicing' ),
397
-            'labels' => __( 'Label Texts', 'invoicing' ),
398
-        ) ),
399
-        'gateways' => apply_filters( 'wpinv_settings_sections_gateways', array(
400
-            'main' => __( 'Gateway Settings', 'invoicing' ),
401
-        ) ),
402
-        'taxes' => apply_filters( 'wpinv_settings_sections_taxes', array(
403
-            'main' => __( 'Tax Settings', 'invoicing' ),
404
-            'rates' => __( 'Tax Rates', 'invoicing' ),
405
-        ) ),
406
-        'emails' => apply_filters( 'wpinv_settings_sections_emails', array(
407
-            'main' => __( 'Email Settings', 'invoicing' ),
408
-        ) ),
409
-        'privacy' => apply_filters( 'wpinv_settings_sections_privacy', array(
410
-            'main' => __( 'Privacy policy', 'invoicing' ),
411
-        ) ),
412
-        'misc' => apply_filters( 'wpinv_settings_sections_misc', array(
413
-            'main' => __( 'Miscellaneous', 'invoicing' ),
414
-            'fields' => __( 'Fields Settings', 'invoicing' ),
415
-            'custom-css' => __( 'Custom CSS', 'invoicing' ),
416
-        ) ),
417
-        'tools' => apply_filters( 'wpinv_settings_sections_tools', array(
418
-            'main' => __( 'Diagnostic Tools', 'invoicing' ),
419
-        ) ),
394
+        'general' => apply_filters('wpinv_settings_sections_general', array(
395
+            'main' => __('General Settings', 'invoicing'),
396
+            'currency_section' => __('Currency Settings', 'invoicing'),
397
+            'labels' => __('Label Texts', 'invoicing'),
398
+        )),
399
+        'gateways' => apply_filters('wpinv_settings_sections_gateways', array(
400
+            'main' => __('Gateway Settings', 'invoicing'),
401
+        )),
402
+        'taxes' => apply_filters('wpinv_settings_sections_taxes', array(
403
+            'main' => __('Tax Settings', 'invoicing'),
404
+            'rates' => __('Tax Rates', 'invoicing'),
405
+        )),
406
+        'emails' => apply_filters('wpinv_settings_sections_emails', array(
407
+            'main' => __('Email Settings', 'invoicing'),
408
+        )),
409
+        'privacy' => apply_filters('wpinv_settings_sections_privacy', array(
410
+            'main' => __('Privacy policy', 'invoicing'),
411
+        )),
412
+        'misc' => apply_filters('wpinv_settings_sections_misc', array(
413
+            'main' => __('Miscellaneous', 'invoicing'),
414
+            'fields' => __('Fields Settings', 'invoicing'),
415
+            'custom-css' => __('Custom CSS', 'invoicing'),
416
+        )),
417
+        'tools' => apply_filters('wpinv_settings_sections_tools', array(
418
+            'main' => __('Diagnostic Tools', 'invoicing'),
419
+        )),
420 420
     );
421 421
 
422
-    $sections = apply_filters( 'wpinv_settings_sections', $sections );
422
+    $sections = apply_filters('wpinv_settings_sections', $sections);
423 423
 
424 424
     return $sections;
425 425
 }
426 426
 
427
-function wpinv_get_pages( $with_slug = false, $default_label = NULL ) {
427
+function wpinv_get_pages($with_slug = false, $default_label = NULL) {
428 428
 	$pages_options = array();
429 429
 
430
-	if( $default_label !== NULL && $default_label !== false ) {
431
-		$pages_options = array( '' => $default_label ); // Blank option
430
+	if ($default_label !== NULL && $default_label !== false) {
431
+		$pages_options = array('' => $default_label); // Blank option
432 432
 	}
433 433
 
434 434
 	$pages = get_pages();
435
-	if ( $pages ) {
436
-		foreach ( $pages as $page ) {
435
+	if ($pages) {
436
+		foreach ($pages as $page) {
437 437
 			$title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
438
-            $pages_options[ $page->ID ] = $title;
438
+            $pages_options[$page->ID] = $title;
439 439
 		}
440 440
 	}
441 441
 
442 442
 	return $pages_options;
443 443
 }
444 444
 
445
-function wpinv_header_callback( $args ) {
446
-	if ( !empty( $args['desc'] ) ) {
445
+function wpinv_header_callback($args) {
446
+	if (!empty($args['desc'])) {
447 447
         echo $args['desc'];
448 448
     }
449 449
 }
450 450
 
451
-function wpinv_hidden_callback( $args ) {
451
+function wpinv_hidden_callback($args) {
452 452
 	global $wpinv_options;
453 453
 
454
-	if ( isset( $args['set_value'] ) ) {
454
+	if (isset($args['set_value'])) {
455 455
 		$value = $args['set_value'];
456
-	} elseif ( isset( $wpinv_options[ $args['id'] ] ) ) {
457
-		$value = $wpinv_options[ $args['id'] ];
456
+	} elseif (isset($wpinv_options[$args['id']])) {
457
+		$value = $wpinv_options[$args['id']];
458 458
 	} else {
459
-		$value = isset( $args['std'] ) ? $args['std'] : '';
459
+		$value = isset($args['std']) ? $args['std'] : '';
460 460
 	}
461 461
 
462
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
462
+	if (isset($args['faux']) && true === $args['faux']) {
463 463
 		$args['readonly'] = true;
464
-		$value = isset( $args['std'] ) ? $args['std'] : '';
464
+		$value = isset($args['std']) ? $args['std'] : '';
465 465
 		$name  = '';
466 466
 	} else {
467
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
467
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
468 468
 	}
469 469
 
470
-	$html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
470
+	$html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key($args['id']) . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '" />';
471 471
     
472 472
 	echo $html;
473 473
 }
474 474
 
475
-function wpinv_checkbox_callback( $args ) {
475
+function wpinv_checkbox_callback($args) {
476 476
 	global $wpinv_options;
477 477
     
478
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
478
+    $sanitize_id = wpinv_sanitize_key($args['id']);
479 479
 
480
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
480
+	if (isset($args['faux']) && true === $args['faux']) {
481 481
 		$name = '';
482 482
 	} else {
483 483
 		$name = 'name="wpinv_settings[' . $sanitize_id . ']"';
484 484
 	}
485 485
 
486
-	$std     = isset( $args['std'] ) ? $args['std'] : 0;
487
-	$value   = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std;
488
-	$checked = checked( empty( $value ), false, false );
486
+	$std     = isset($args['std']) ? $args['std'] : 0;
487
+	$value   = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : $std;
488
+	$checked = checked(empty($value), false, false);
489 489
 
490 490
 	$html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>';
491
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
491
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
492 492
 
493 493
 	echo $html;
494 494
 }
495 495
 
496
-function wpinv_multicheck_callback( $args ) {
496
+function wpinv_multicheck_callback($args) {
497 497
 	global $wpinv_options;
498 498
 
499
-	$sanitize_id = wpinv_sanitize_key( $args['id'] );
500
-	$class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
499
+	$sanitize_id = wpinv_sanitize_key($args['id']);
500
+	$class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : '';
501 501
 
502
-	if ( ! empty( $args['options'] ) ) {
502
+	if (!empty($args['options'])) {
503 503
 
504
-		$std     = isset( $args['std'] ) ? $args['std'] : array();
505
-		$value   = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std;
504
+		$std     = isset($args['std']) ? $args['std'] : array();
505
+		$value   = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : $std;
506 506
 
507 507
 		echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">';
508
-        foreach( $args['options'] as $key => $option ):
509
-			$sanitize_key = wpinv_sanitize_key( $key );
510
-			if ( in_array( $sanitize_key, $value ) ) { 
508
+        foreach ($args['options'] as $key => $option):
509
+			$sanitize_key = wpinv_sanitize_key($key);
510
+			if (in_array($sanitize_key, $value)) { 
511 511
 				$enabled = $sanitize_key;
512 512
 			} else { 
513 513
 				$enabled = NULL; 
514 514
 			}
515
-			echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
516
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>';
515
+			echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($sanitize_key) . '" ' . checked($sanitize_key, $enabled, false) . '/>&nbsp;';
516
+			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post($option) . '</label></div>';
517 517
 		endforeach;
518 518
 		echo '</div>';
519 519
 		echo '<p class="description">' . $args['desc'] . '</p>';
520 520
 	}
521 521
 }
522 522
 
523
-function wpinv_payment_icons_callback( $args ) {
523
+function wpinv_payment_icons_callback($args) {
524 524
 	global $wpinv_options;
525 525
     
526
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
526
+    $sanitize_id = wpinv_sanitize_key($args['id']);
527 527
 
528
-	if ( ! empty( $args['options'] ) ) {
529
-		foreach( $args['options'] as $key => $option ) {
530
-            $sanitize_key = wpinv_sanitize_key( $key );
528
+	if (!empty($args['options'])) {
529
+		foreach ($args['options'] as $key => $option) {
530
+            $sanitize_key = wpinv_sanitize_key($key);
531 531
             
532
-			if( isset( $wpinv_options[$args['id']][$key] ) ) {
532
+			if (isset($wpinv_options[$args['id']][$key])) {
533 533
 				$enabled = $option;
534 534
 			} else {
535 535
 				$enabled = NULL;
@@ -537,197 +537,197 @@  discard block
 block discarded – undo
537 537
 
538 538
 			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
539 539
 
540
-				echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
540
+				echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($option) . '" ' . checked($option, $enabled, false) . '/>&nbsp;';
541 541
 
542
-				if ( wpinv_string_is_image_url( $key ) ) {
543
-					echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
542
+				if (wpinv_string_is_image_url($key)) {
543
+					echo '<img class="payment-icon" src="' . esc_url($key) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
544 544
 				} else {
545
-					$card = strtolower( str_replace( ' ', '', $option ) );
545
+					$card = strtolower(str_replace(' ', '', $option));
546 546
 
547
-					if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
548
-						$image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
547
+					if (has_filter('wpinv_accepted_payment_' . $card . '_image')) {
548
+						$image = apply_filters('wpinv_accepted_payment_' . $card . '_image', '');
549 549
 					} else {
550
-						$image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
550
+						$image       = wpinv_locate_template('images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false);
551 551
 						$content_dir = WP_CONTENT_DIR;
552 552
 
553
-						if ( function_exists( 'wp_normalize_path' ) ) {
553
+						if (function_exists('wp_normalize_path')) {
554 554
 							// Replaces backslashes with forward slashes for Windows systems
555
-							$image = wp_normalize_path( $image );
556
-							$content_dir = wp_normalize_path( $content_dir );
555
+							$image = wp_normalize_path($image);
556
+							$content_dir = wp_normalize_path($content_dir);
557 557
 						}
558 558
 
559
-						$image = str_replace( $content_dir, content_url(), $image );
559
+						$image = str_replace($content_dir, content_url(), $image);
560 560
 					}
561 561
 
562
-					echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
562
+					echo '<img class="payment-icon" src="' . esc_url($image) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
563 563
 				}
564 564
 			echo $option . '</label>';
565 565
 		}
566
-		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
566
+		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post($args['desc']) . '</p>';
567 567
 	}
568 568
 }
569 569
 
570
-function wpinv_radio_callback( $args ) {
570
+function wpinv_radio_callback($args) {
571 571
 	global $wpinv_options;
572 572
     
573
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
573
+    $sanitize_id = wpinv_sanitize_key($args['id']);
574 574
     
575
-    foreach ( $args['options'] as $key => $option ) :
576
-		$sanitize_key = wpinv_sanitize_key( $key );
575
+    foreach ($args['options'] as $key => $option) :
576
+		$sanitize_key = wpinv_sanitize_key($key);
577 577
         
578 578
         $checked = false;
579 579
 
580
-		if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key )
580
+		if (isset($wpinv_options[$args['id']]) && $wpinv_options[$args['id']] == $key)
581 581
 			$checked = true;
582
-		elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) )
582
+		elseif (isset($args['std']) && $args['std'] == $key && !isset($wpinv_options[$args['id']]))
583 583
 			$checked = true;
584 584
 
585 585
 		echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/>&nbsp;';
586
-		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>';
586
+		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option) . '</label><br/>';
587 587
 	endforeach;
588 588
 
589
-	echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
589
+	echo '<p class="description">' . wp_kses_post($args['desc']) . '</p>';
590 590
 }
591 591
 
592
-function wpinv_gateways_callback( $args ) {
592
+function wpinv_gateways_callback($args) {
593 593
 	global $wpinv_options;
594 594
     
595
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
595
+    $sanitize_id = wpinv_sanitize_key($args['id']);
596 596
 
597
-	foreach ( $args['options'] as $key => $option ) :
598
-		$sanitize_key = wpinv_sanitize_key( $key );
597
+	foreach ($args['options'] as $key => $option) :
598
+		$sanitize_key = wpinv_sanitize_key($key);
599 599
         
600
-        if ( isset( $wpinv_options['gateways'][ $key ] ) )
600
+        if (isset($wpinv_options['gateways'][$key]))
601 601
 			$enabled = '1';
602 602
 		else
603 603
 			$enabled = null;
604 604
 
605
-		echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/>&nbsp;';
606
-		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>';
605
+		echo '<input name="wpinv_settings[' . esc_attr($args['id']) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/>&nbsp;';
606
+		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option['admin_label']) . '</label><br/>';
607 607
 	endforeach;
608 608
 }
609 609
 
610 610
 function wpinv_gateway_select_callback($args) {
611 611
 	global $wpinv_options;
612 612
     
613
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
614
-    $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
613
+    $sanitize_id = wpinv_sanitize_key($args['id']);
614
+    $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : '';
615 615
 
616
-	echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >';
616
+	echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="' . $class . '" >';
617 617
 
618
-	foreach ( $args['options'] as $key => $option ) :
619
-		if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
620
-            $selected = selected( $key, $args['selected'], false );
618
+	foreach ($args['options'] as $key => $option) :
619
+		if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) {
620
+            $selected = selected($key, $args['selected'], false);
621 621
         } else {
622
-            $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : '';
622
+            $selected = isset($wpinv_options[$args['id']]) ? selected($key, $wpinv_options[$args['id']], false) : '';
623 623
         }
624
-		echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
624
+		echo '<option value="' . wpinv_sanitize_key($key) . '"' . $selected . '>' . esc_html($option['admin_label']) . '</option>';
625 625
 	endforeach;
626 626
 
627 627
 	echo '</select>';
628
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
628
+	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
629 629
 }
630 630
 
631
-function wpinv_text_callback( $args ) {
631
+function wpinv_text_callback($args) {
632 632
 	global $wpinv_options;
633 633
     
634
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
634
+    $sanitize_id = wpinv_sanitize_key($args['id']);
635 635
 
636
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
637
-		$value = $wpinv_options[ $args['id'] ];
636
+	if (isset($wpinv_options[$args['id']])) {
637
+		$value = $wpinv_options[$args['id']];
638 638
 	} else {
639
-		$value = isset( $args['std'] ) ? $args['std'] : '';
639
+		$value = isset($args['std']) ? $args['std'] : '';
640 640
 	}
641 641
 
642
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
642
+	if (isset($args['faux']) && true === $args['faux']) {
643 643
 		$args['readonly'] = true;
644
-		$value = isset( $args['std'] ) ? $args['std'] : '';
644
+		$value = isset($args['std']) ? $args['std'] : '';
645 645
 		$name  = '';
646 646
 	} else {
647
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
647
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
648 648
 	}
649
-	$class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
649
+	$class = !empty($args['class']) ? sanitize_html_class($args['class']) : '';
650 650
 
651 651
 	$readonly = $args['readonly'] === true ? ' readonly="readonly"' : '';
652
-	$size     = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
653
-	$html     = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>';
654
-	$html    .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
652
+	$size     = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
653
+	$html     = '<input type="text" class="' . sanitize_html_class($size) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"' . $readonly . '/>';
654
+	$html    .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
655 655
 
656 656
 	echo $html;
657 657
 }
658 658
 
659
-function wpinv_number_callback( $args ) {
659
+function wpinv_number_callback($args) {
660 660
 	global $wpinv_options;
661 661
     
662
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
662
+    $sanitize_id = wpinv_sanitize_key($args['id']);
663 663
 
664
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
665
-		$value = $wpinv_options[ $args['id'] ];
664
+	if (isset($wpinv_options[$args['id']])) {
665
+		$value = $wpinv_options[$args['id']];
666 666
 	} else {
667
-		$value = isset( $args['std'] ) ? $args['std'] : '';
667
+		$value = isset($args['std']) ? $args['std'] : '';
668 668
 	}
669 669
 
670
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
670
+	if (isset($args['faux']) && true === $args['faux']) {
671 671
 		$args['readonly'] = true;
672
-		$value = isset( $args['std'] ) ? $args['std'] : '';
672
+		$value = isset($args['std']) ? $args['std'] : '';
673 673
 		$name  = '';
674 674
 	} else {
675
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
675
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
676 676
 	}
677 677
 
678
-	$max  = isset( $args['max'] ) ? $args['max'] : 999999;
679
-	$min  = isset( $args['min'] ) ? $args['min'] : 0;
680
-	$step = isset( $args['step'] ) ? $args['step'] : 1;
681
-	$class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
678
+	$max  = isset($args['max']) ? $args['max'] : 999999;
679
+	$min  = isset($args['min']) ? $args['min'] : 0;
680
+	$step = isset($args['step']) ? $args['step'] : 1;
681
+	$class = !empty($args['class']) ? sanitize_html_class($args['class']) : '';
682 682
 
683
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
684
-	$html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>';
685
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
683
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
684
+	$html = '<input type="number" step="' . esc_attr($step) . '" max="' . esc_attr($max) . '" min="' . esc_attr($min) . '" class="' . sanitize_html_class($size) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"/>';
685
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
686 686
 
687 687
 	echo $html;
688 688
 }
689 689
 
690
-function wpinv_textarea_callback( $args ) {
690
+function wpinv_textarea_callback($args) {
691 691
 	global $wpinv_options;
692 692
     
693
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
693
+    $sanitize_id = wpinv_sanitize_key($args['id']);
694 694
 
695
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
696
-		$value = $wpinv_options[ $args['id'] ];
695
+	if (isset($wpinv_options[$args['id']])) {
696
+		$value = $wpinv_options[$args['id']];
697 697
 	} else {
698
-		$value = isset( $args['std'] ) ? $args['std'] : '';
698
+		$value = isset($args['std']) ? $args['std'] : '';
699 699
 	}
700 700
     
701
-    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
702
-    $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text';
701
+    $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
702
+    $class = (isset($args['class']) && !is_null($args['class'])) ? $args['class'] : 'large-text';
703 703
 
704
-	$html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
705
-	$html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
704
+	$html = '<textarea class="' . sanitize_html_class($class) . ' txtarea-' . sanitize_html_class($size) . ' wpi-' . esc_attr(sanitize_html_class($sanitize_id)) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']">' . esc_textarea(stripslashes($value)) . '</textarea>';
705
+	$html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
706 706
 
707 707
 	echo $html;
708 708
 }
709 709
 
710
-function wpinv_password_callback( $args ) {
710
+function wpinv_password_callback($args) {
711 711
 	global $wpinv_options;
712 712
     
713
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
713
+    $sanitize_id = wpinv_sanitize_key($args['id']);
714 714
 
715
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
716
-		$value = $wpinv_options[ $args['id'] ];
715
+	if (isset($wpinv_options[$args['id']])) {
716
+		$value = $wpinv_options[$args['id']];
717 717
 	} else {
718
-		$value = isset( $args['std'] ) ? $args['std'] : '';
718
+		$value = isset($args['std']) ? $args['std'] : '';
719 719
 	}
720 720
 
721
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
722
-	$html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
723
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
721
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
722
+	$html = '<input type="password" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '"/>';
723
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
724 724
 
725 725
 	echo $html;
726 726
 }
727 727
 
728 728
 function wpinv_missing_callback($args) {
729 729
 	printf(
730
-		__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
730
+		__('The callback function used for the %s setting is missing.', 'invoicing'),
731 731
 		'<strong>' . $args['id'] . '</strong>'
732 732
 	);
733 733
 }
@@ -735,134 +735,134 @@  discard block
 block discarded – undo
735 735
 function wpinv_select_callback($args) {
736 736
 	global $wpinv_options;
737 737
     
738
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
738
+    $sanitize_id = wpinv_sanitize_key($args['id']);
739 739
 
740
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
741
-		$value = $wpinv_options[ $args['id'] ];
740
+	if (isset($wpinv_options[$args['id']])) {
741
+		$value = $wpinv_options[$args['id']];
742 742
 	} else {
743
-		$value = isset( $args['std'] ) ? $args['std'] : '';
743
+		$value = isset($args['std']) ? $args['std'] : '';
744 744
 	}
745 745
     
746
-    if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
746
+    if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) {
747 747
         $value = $args['selected'];
748 748
     }
749 749
 
750
-	if ( isset( $args['placeholder'] ) ) {
750
+	if (isset($args['placeholder'])) {
751 751
 		$placeholder = $args['placeholder'];
752 752
 	} else {
753 753
 		$placeholder = '';
754 754
 	}
755 755
     
756
-    if( !empty( $args['onchange'] ) ) {
757
-        $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"';
756
+    if (!empty($args['onchange'])) {
757
+        $onchange = ' onchange="' . esc_attr($args['onchange']) . '"';
758 758
     } else {
759 759
         $onchange = '';
760 760
     }
761 761
 
762
-    $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
762
+    $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : '';
763 763
 
764
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'"  name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />';
764
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="' . $class . '"  name="wpinv_settings[' . esc_attr($args['id']) . ']" data-placeholder="' . esc_html($placeholder) . '"' . $onchange . ' />';
765 765
 
766
-	foreach ( $args['options'] as $option => $name ) {
767
-		$selected = selected( $option, $value, false );
768
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
766
+	foreach ($args['options'] as $option => $name) {
767
+		$selected = selected($option, $value, false);
768
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>';
769 769
 	}
770 770
 
771 771
 	$html .= '</select>';
772
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
772
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
773 773
 
774 774
 	echo $html;
775 775
 }
776 776
 
777
-function wpinv_color_select_callback( $args ) {
777
+function wpinv_color_select_callback($args) {
778 778
 	global $wpinv_options;
779 779
     
780
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
780
+    $sanitize_id = wpinv_sanitize_key($args['id']);
781 781
 
782
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
783
-		$value = $wpinv_options[ $args['id'] ];
782
+	if (isset($wpinv_options[$args['id']])) {
783
+		$value = $wpinv_options[$args['id']];
784 784
 	} else {
785
-		$value = isset( $args['std'] ) ? $args['std'] : '';
785
+		$value = isset($args['std']) ? $args['std'] : '';
786 786
 	}
787 787
 
788
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
788
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"/>';
789 789
 
790
-	foreach ( $args['options'] as $option => $color ) {
791
-		$selected = selected( $option, $value, false );
792
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>';
790
+	foreach ($args['options'] as $option => $color) {
791
+		$selected = selected($option, $value, false);
792
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($color['label']) . '</option>';
793 793
 	}
794 794
 
795 795
 	$html .= '</select>';
796
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
796
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
797 797
 
798 798
 	echo $html;
799 799
 }
800 800
 
801
-function wpinv_rich_editor_callback( $args ) {
801
+function wpinv_rich_editor_callback($args) {
802 802
 	global $wpinv_options, $wp_version;
803 803
     
804
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
804
+    $sanitize_id = wpinv_sanitize_key($args['id']);
805 805
 
806
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
807
-		$value = $wpinv_options[ $args['id'] ];
806
+	if (isset($wpinv_options[$args['id']])) {
807
+		$value = $wpinv_options[$args['id']];
808 808
 
809
-		if( empty( $args['allow_blank'] ) && empty( $value ) ) {
810
-			$value = isset( $args['std'] ) ? $args['std'] : '';
809
+		if (empty($args['allow_blank']) && empty($value)) {
810
+			$value = isset($args['std']) ? $args['std'] : '';
811 811
 		}
812 812
 	} else {
813
-		$value = isset( $args['std'] ) ? $args['std'] : '';
813
+		$value = isset($args['std']) ? $args['std'] : '';
814 814
 	}
815 815
 
816
-	$rows = isset( $args['size'] ) ? $args['size'] : 20;
816
+	$rows = isset($args['size']) ? $args['size'] : 20;
817 817
 
818 818
 	$html = '<div class="getpaid-settings-editor-input">';
819
-	if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
819
+	if ($wp_version >= 3.3 && function_exists('wp_editor')) {
820 820
 		ob_start();
821
-		wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) );
821
+		wp_editor(stripslashes($value), 'wpinv_settings_' . esc_attr($args['id']), array('textarea_name' => 'wpinv_settings[' . esc_attr($args['id']) . ']', 'textarea_rows' => absint($rows), 'media_buttons' => false));
822 822
 		$html .= ob_get_clean();
823 823
 	} else {
824
-		$html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
824
+		$html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" class="wpi-' . esc_attr(sanitize_html_class($args['id'])) . '">' . esc_textarea(stripslashes($value)) . '</textarea>';
825 825
 	}
826 826
 
827
-	$html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
827
+	$html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
828 828
 
829 829
 	echo $html;
830 830
 }
831 831
 
832
-function wpinv_upload_callback( $args ) {
832
+function wpinv_upload_callback($args) {
833 833
 	global $wpinv_options;
834 834
     
835
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
835
+    $sanitize_id = wpinv_sanitize_key($args['id']);
836 836
 
837
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
837
+	if (isset($wpinv_options[$args['id']])) {
838 838
 		$value = $wpinv_options[$args['id']];
839 839
 	} else {
840 840
 		$value = isset($args['std']) ? $args['std'] : '';
841 841
 	}
842 842
 
843
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
844
-	$html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
845
-	$html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
846
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
843
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
844
+	$html = '<input type="text" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr(stripslashes($value)) . '"/>';
845
+	$html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __('Upload File', 'invoicing') . '"/></span>';
846
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
847 847
 
848 848
 	echo $html;
849 849
 }
850 850
 
851
-function wpinv_color_callback( $args ) {
851
+function wpinv_color_callback($args) {
852 852
 	global $wpinv_options;
853 853
     
854
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
854
+    $sanitize_id = wpinv_sanitize_key($args['id']);
855 855
 
856
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
857
-		$value = $wpinv_options[ $args['id'] ];
856
+	if (isset($wpinv_options[$args['id']])) {
857
+		$value = $wpinv_options[$args['id']];
858 858
 	} else {
859
-		$value = isset( $args['std'] ) ? $args['std'] : '';
859
+		$value = isset($args['std']) ? $args['std'] : '';
860 860
 	}
861 861
 
862
-	$default = isset( $args['std'] ) ? $args['std'] : '';
862
+	$default = isset($args['std']) ? $args['std'] : '';
863 863
 
864
-	$html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />';
865
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
864
+	$html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '" data-default-color="' . esc_attr($default) . '" />';
865
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
866 866
 
867 867
 	echo $html;
868 868
 }
@@ -870,9 +870,9 @@  discard block
 block discarded – undo
870 870
 function wpinv_country_states_callback($args) {
871 871
 	global $wpinv_options;
872 872
     
873
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
873
+    $sanitize_id = wpinv_sanitize_key($args['id']);
874 874
 
875
-	if ( isset( $args['placeholder'] ) ) {
875
+	if (isset($args['placeholder'])) {
876 876
 		$placeholder = $args['placeholder'];
877 877
 	} else {
878 878
 		$placeholder = '';
@@ -880,16 +880,16 @@  discard block
 block discarded – undo
880 880
 
881 881
 	$states = wpinv_get_country_states();
882 882
 
883
-	$class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"';
884
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
883
+	$class = empty($states) ? ' class="wpinv-no-states"' : ' class="wpi_select2"';
884
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"' . $class . 'data-placeholder="' . esc_html($placeholder) . '"/>';
885 885
 
886
-	foreach ( $states as $option => $name ) {
887
-		$selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : '';
888
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
886
+	foreach ($states as $option => $name) {
887
+		$selected = isset($wpinv_options[$args['id']]) ? selected($option, $wpinv_options[$args['id']], false) : '';
888
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>';
889 889
 	}
890 890
 
891 891
 	$html .= '</select>';
892
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
892
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
893 893
 
894 894
 	echo $html;
895 895
 }
@@ -904,96 +904,96 @@  discard block
 block discarded – undo
904 904
 	<table id="wpinv_tax_rates" class="wp-list-table widefat fixed posts">
905 905
 		<thead>
906 906
 			<tr>
907
-				<th scope="col" class="wpinv_tax_country"><?php _e( 'Country', 'invoicing' ); ?></th>
908
-				<th scope="col" class="wpinv_tax_state"><?php _e( 'State / Province', 'invoicing' ); ?></th>
909
-                <th scope="col" class="wpinv_tax_global" title="<?php esc_attr_e( 'Apply rate to whole country, regardless of state / province', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th>
910
-                <th scope="col" class="wpinv_tax_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> 
911
-                <th scope="col" class="wpinv_tax_name"><?php _e( 'Tax Name', 'invoicing' ); ?></th>
912
-				<th scope="col" class="wpinv_tax_action"><?php _e( 'Remove', 'invoicing' ); ?></th>
907
+				<th scope="col" class="wpinv_tax_country"><?php _e('Country', 'invoicing'); ?></th>
908
+				<th scope="col" class="wpinv_tax_state"><?php _e('State / Province', 'invoicing'); ?></th>
909
+                <th scope="col" class="wpinv_tax_global" title="<?php esc_attr_e('Apply rate to whole country, regardless of state / province', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th>
910
+                <th scope="col" class="wpinv_tax_rate"><?php _e('Rate %', 'invoicing'); ?></th> 
911
+                <th scope="col" class="wpinv_tax_name"><?php _e('Tax Name', 'invoicing'); ?></th>
912
+				<th scope="col" class="wpinv_tax_action"><?php _e('Remove', 'invoicing'); ?></th>
913 913
 			</tr>
914 914
 		</thead>
915 915
         <tbody>
916
-		<?php if( !empty( $rates ) ) : ?>
917
-			<?php foreach( $rates as $key => $rate ) : ?>
916
+		<?php if (!empty($rates)) : ?>
917
+			<?php foreach ($rates as $key => $rate) : ?>
918 918
             <?php 
919
-            $sanitized_key = wpinv_sanitize_key( $key );
919
+            $sanitized_key = wpinv_sanitize_key($key);
920 920
             ?>
921 921
 			<tr>
922 922
 				<td class="wpinv_tax_country">
923 923
 					<?php
924
-					echo wpinv_html_select( array(
925
-						'options'          => wpinv_get_country_list( true ),
924
+					echo wpinv_html_select(array(
925
+						'options'          => wpinv_get_country_list(true),
926 926
 						'name'             => 'tax_rates[' . $sanitized_key . '][country]',
927 927
                         'id'               => 'tax_rates[' . $sanitized_key . '][country]',
928 928
 						'selected'         => $rate['country'],
929 929
 						'show_option_all'  => false,
930 930
 						'show_option_none' => false,
931 931
 						'class'            => 'wpinv-tax-country wpi_select2',
932
-						'placeholder'      => __( 'Choose a country', 'invoicing' )
933
-					) );
932
+						'placeholder'      => __('Choose a country', 'invoicing')
933
+					));
934 934
 					?>
935 935
 				</td>
936 936
 				<td class="wpinv_tax_state">
937 937
 					<?php
938
-					$states = wpinv_get_country_states( $rate['country'] );
939
-					if( !empty( $states ) ) {
940
-						echo wpinv_html_select( array(
941
-							'options'          => array_merge( array( '' => '' ), $states ),
938
+					$states = wpinv_get_country_states($rate['country']);
939
+					if (!empty($states)) {
940
+						echo wpinv_html_select(array(
941
+							'options'          => array_merge(array('' => ''), $states),
942 942
 							'name'             => 'tax_rates[' . $sanitized_key . '][state]',
943 943
                             'id'               => 'tax_rates[' . $sanitized_key . '][state]',
944 944
 							'selected'         => $rate['state'],
945 945
 							'show_option_all'  => false,
946 946
 							'show_option_none' => false,
947 947
                             'class'            => 'wpi_select2',
948
-							'placeholder'      => __( 'Choose a state', 'invoicing' )
949
-						) );
948
+							'placeholder'      => __('Choose a state', 'invoicing')
949
+						));
950 950
 					} else {
951
-						echo wpinv_html_text( array(
951
+						echo wpinv_html_text(array(
952 952
 							'name'  => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'],
953
-							'value' => ! empty( $rate['state'] ) ? $rate['state'] : '',
953
+							'value' => !empty($rate['state']) ? $rate['state'] : '',
954 954
                             'id'    => 'tax_rates[' . $sanitized_key . '][state]',
955
-						) );
955
+						));
956 956
 					}
957 957
 					?>
958 958
 				</td>
959 959
 				<td class="wpinv_tax_global">
960
-					<input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked( true, ! empty( $rate['global'] ) ); ?>/>
961
-					<label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label>
960
+					<input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked(true, !empty($rate['global'])); ?>/>
961
+					<label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label>
962 962
 				</td>
963
-				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[<?php echo $sanitized_key; ?>][rate]" value="<?php echo esc_html( $rate['rate'] ); ?>"/></td>
964
-                <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[<?php echo $sanitized_key; ?>][name]" value="<?php echo esc_html( $rate['name'] ); ?>"/></td>
965
-				<td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td>
963
+				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[<?php echo $sanitized_key; ?>][rate]" value="<?php echo esc_html($rate['rate']); ?>"/></td>
964
+                <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[<?php echo $sanitized_key; ?>][name]" value="<?php echo esc_html($rate['name']); ?>"/></td>
965
+				<td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td>
966 966
 			</tr>
967 967
 			<?php endforeach; ?>
968 968
 		<?php else : ?>
969 969
 			<tr>
970 970
 				<td class="wpinv_tax_country">
971 971
 					<?php
972
-					echo wpinv_html_select( array(
973
-						'options'          => wpinv_get_country_list( true ),
972
+					echo wpinv_html_select(array(
973
+						'options'          => wpinv_get_country_list(true),
974 974
 						'name'             => 'tax_rates[0][country]',
975 975
 						'show_option_all'  => false,
976 976
 						'show_option_none' => false,
977 977
 						'class'            => 'wpinv-tax-country wpi_select2',
978
-						'placeholder'      => __( 'Choose a country', 'invoicing' )
979
-					) ); ?>
978
+						'placeholder'      => __('Choose a country', 'invoicing')
979
+					)); ?>
980 980
 				</td>
981 981
 				<td class="wpinv_tax_state">
982
-					<?php echo wpinv_html_text( array(
982
+					<?php echo wpinv_html_text(array(
983 983
 						'name' => 'tax_rates[0][state]'
984
-					) ); ?>
984
+					)); ?>
985 985
 				</td>
986 986
 				<td class="wpinv_tax_global">
987 987
 					<input type="checkbox" name="tax_rates[0][global]" id="tax_rates[0][global]" value="1"/>
988
-					<label for="tax_rates[0][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label>
988
+					<label for="tax_rates[0][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label>
989 989
 				</td>
990
-				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[0][rate]" placeholder="<?php echo (float)wpinv_get_option( 'tax_rate', 0 ) ;?>" value="<?php echo (float)wpinv_get_option( 'tax_rate', 0 ) ;?>"/></td>
990
+				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[0][rate]" placeholder="<?php echo (float) wpinv_get_option('tax_rate', 0); ?>" value="<?php echo (float) wpinv_get_option('tax_rate', 0); ?>"/></td>
991 991
                 <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[0][name]" /></td>
992
-				<td><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td>
992
+				<td><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td>
993 993
 			</tr>
994 994
 		<?php endif; ?>
995 995
         </tbody>
996
-        <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e( 'Add Tax Rate', 'invoicing' ); ?></span></td></tr></tfoot>
996
+        <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e('Add Tax Rate', 'invoicing'); ?></span></td></tr></tfoot>
997 997
 	</table>
998 998
 	<?php
999 999
 	echo ob_get_clean();
@@ -1004,76 +1004,76 @@  discard block
 block discarded – undo
1004 1004
     ob_start(); ?>
1005 1005
     </td><tr>
1006 1006
     <td colspan="2" class="wpinv_tools_tdbox">
1007
-    <?php if ( $args['desc'] ) { ?><p><?php echo $args['desc']; ?></p><?php } ?>
1008
-    <?php do_action( 'wpinv_tools_before' ); ?>
1007
+    <?php if ($args['desc']) { ?><p><?php echo $args['desc']; ?></p><?php } ?>
1008
+    <?php do_action('wpinv_tools_before'); ?>
1009 1009
     <table id="wpinv_tools_table" class="wp-list-table widefat fixed posts">
1010 1010
         <thead>
1011 1011
             <tr>
1012
-                <th scope="col" class="wpinv-th-tool"><?php _e( 'Tool', 'invoicing' ); ?></th>
1013
-                <th scope="col" class="wpinv-th-desc"><?php _e( 'Description', 'invoicing' ); ?></th>
1014
-                <th scope="col" class="wpinv-th-action"><?php _e( 'Action', 'invoicing' ); ?></th>
1012
+                <th scope="col" class="wpinv-th-tool"><?php _e('Tool', 'invoicing'); ?></th>
1013
+                <th scope="col" class="wpinv-th-desc"><?php _e('Description', 'invoicing'); ?></th>
1014
+                <th scope="col" class="wpinv-th-action"><?php _e('Action', 'invoicing'); ?></th>
1015 1015
             </tr>
1016 1016
         </thead>
1017
-            <?php do_action( 'wpinv_tools_row' ); ?>
1017
+            <?php do_action('wpinv_tools_row'); ?>
1018 1018
         <tbody>
1019 1019
         </tbody>
1020 1020
     </table>
1021
-    <?php do_action( 'wpinv_tools_after' ); ?>
1021
+    <?php do_action('wpinv_tools_after'); ?>
1022 1022
     <?php
1023 1023
     echo ob_get_clean();
1024 1024
 }
1025 1025
 
1026
-function wpinv_descriptive_text_callback( $args ) {
1027
-	echo wp_kses_post( $args['desc'] );
1026
+function wpinv_descriptive_text_callback($args) {
1027
+	echo wp_kses_post($args['desc']);
1028 1028
 }
1029 1029
 
1030
-function wpinv_hook_callback( $args ) {
1031
-	do_action( 'wpinv_' . $args['id'], $args );
1030
+function wpinv_hook_callback($args) {
1031
+	do_action('wpinv_' . $args['id'], $args);
1032 1032
 }
1033 1033
 
1034 1034
 function wpinv_set_settings_cap() {
1035 1035
 	return wpinv_get_capability();
1036 1036
 }
1037
-add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' );
1037
+add_filter('option_page_capability_wpinv_settings', 'wpinv_set_settings_cap');
1038 1038
 
1039
-function wpinv_settings_sanitize_input( $value, $key ) {
1040
-    if ( $key == 'tax_rate' || $key == 'eu_fallback_rate' ) {
1041
-        $value = wpinv_sanitize_amount( $value, 4 );
1039
+function wpinv_settings_sanitize_input($value, $key) {
1040
+    if ($key == 'tax_rate' || $key == 'eu_fallback_rate') {
1041
+        $value = wpinv_sanitize_amount($value, 4);
1042 1042
         $value = $value >= 100 ? 99 : $value;
1043 1043
     }
1044 1044
         
1045 1045
     return $value;
1046 1046
 }
1047
-add_filter( 'wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2 );
1047
+add_filter('wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2);
1048 1048
 
1049
-function wpinv_on_update_settings( $old_value, $value, $option ) {
1050
-    $old = !empty( $old_value['remove_data_on_unistall'] ) ? 1 : '';
1051
-    $new = !empty( $value['remove_data_on_unistall'] ) ? 1 : '';
1049
+function wpinv_on_update_settings($old_value, $value, $option) {
1050
+    $old = !empty($old_value['remove_data_on_unistall']) ? 1 : '';
1051
+    $new = !empty($value['remove_data_on_unistall']) ? 1 : '';
1052 1052
     
1053
-    if ( $old != $new ) {
1054
-        update_option( 'wpinv_remove_data_on_invoice_unistall', $new );
1053
+    if ($old != $new) {
1054
+        update_option('wpinv_remove_data_on_invoice_unistall', $new);
1055 1055
     }
1056 1056
 }
1057
-add_action( 'update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3 );
1058
-add_action( 'wpinv_settings_tab_bottom_emails_new_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1059
-add_action( 'wpinv_settings_tab_bottom_emails_cancelled_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1060
-add_action( 'wpinv_settings_tab_bottom_emails_failed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1061
-add_action( 'wpinv_settings_tab_bottom_emails_onhold_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1062
-add_action( 'wpinv_settings_tab_bottom_emails_processing_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1063
-add_action( 'wpinv_settings_tab_bottom_emails_completed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1064
-add_action( 'wpinv_settings_tab_bottom_emails_refunded_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1065
-add_action( 'wpinv_settings_tab_bottom_emails_user_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1066
-add_action( 'wpinv_settings_tab_bottom_emails_user_note', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1067
-add_action( 'wpinv_settings_tab_bottom_emails_overdue', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1068
-
1069
-function wpinv_settings_tab_bottom_emails( $active_tab, $section ) {
1057
+add_action('update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3);
1058
+add_action('wpinv_settings_tab_bottom_emails_new_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1059
+add_action('wpinv_settings_tab_bottom_emails_cancelled_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1060
+add_action('wpinv_settings_tab_bottom_emails_failed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1061
+add_action('wpinv_settings_tab_bottom_emails_onhold_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1062
+add_action('wpinv_settings_tab_bottom_emails_processing_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1063
+add_action('wpinv_settings_tab_bottom_emails_completed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1064
+add_action('wpinv_settings_tab_bottom_emails_refunded_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1065
+add_action('wpinv_settings_tab_bottom_emails_user_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1066
+add_action('wpinv_settings_tab_bottom_emails_user_note', 'wpinv_settings_tab_bottom_emails', 10, 2);
1067
+add_action('wpinv_settings_tab_bottom_emails_overdue', 'wpinv_settings_tab_bottom_emails', 10, 2);
1068
+
1069
+function wpinv_settings_tab_bottom_emails($active_tab, $section) {
1070 1070
     ?>
1071 1071
     <div class="wpinv-email-wc-row ">
1072 1072
         <div class="wpinv-email-wc-td">
1073
-            <h3 class="wpinv-email-wc-title"><?php echo apply_filters( 'wpinv_settings_email_wildcards_title', __( 'Wildcards For Emails', 'invoicing' ) ); ?></h3>
1073
+            <h3 class="wpinv-email-wc-title"><?php echo apply_filters('wpinv_settings_email_wildcards_title', __('Wildcards For Emails', 'invoicing')); ?></h3>
1074 1074
             <p class="wpinv-email-wc-description">
1075 1075
                 <?php
1076
-                $description = __( 'The following wildcards can be used in email subjects, heading and content:<br>
1076
+                $description = __('The following wildcards can be used in email subjects, heading and content:<br>
1077 1077
                     <strong>{site_title} :</strong> Site Title<br>
1078 1078
                     <strong>{name} :</strong> Customer\'s full name<br>
1079 1079
                     <strong>{first_name} :</strong> Customer\'s first name<br>
@@ -1087,7 +1087,7 @@  discard block
 block discarded – undo
1087 1087
                     <strong>{invoice_due_date} :</strong> The date the invoice is due<br>
1088 1088
                     <strong>{date} :</strong> Today\'s date.<br>
1089 1089
                     <strong>{is_was} :</strong> If due date of invoice is past, displays "was" otherwise displays "is"<br>
1090
-                    <strong>{invoice_label} :</strong> Invoices/quotes singular name. Ex: Invoice/Quote<br>', 'invoicing' );
1090
+                    <strong>{invoice_label} :</strong> Invoices/quotes singular name. Ex: Invoice/Quote<br>', 'invoicing');
1091 1091
                 echo apply_filters('wpinv_settings_email_wildcards_description', $description, $active_tab, $section);
1092 1092
                 ?>
1093 1093
             </p>
Please login to merge, or discard this patch.
includes/admin/admin-pages.php 1 patch
Spacing   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7
-add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' );
8
-function wpinv_discount_custom_column( $column ) {
7
+add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column');
8
+function wpinv_discount_custom_column($column) {
9 9
     global $post;
10 10
 
11
-    $discount = new WPInv_Discount( $post );
11
+    $discount = new WPInv_Discount($post);
12 12
 
13
-    switch ( $column ) {
13
+    switch ($column) {
14 14
         case 'code' :
15 15
             echo $discount->get_code();
16 16
         break;
@@ -21,38 +21,38 @@  discard block
 block discarded – undo
21 21
             echo $discount->get_usage();
22 22
         break;
23 23
         case 'start_date' :
24
-            echo getpaid_format_date_value( $discount->get_start_date() );
24
+            echo getpaid_format_date_value($discount->get_start_date());
25 25
         break;
26 26
         case 'expiry_date' :
27
-            echo getpaid_format_date_value( $discount->get_expiration_date(), __( 'Never', 'invoicing' ) );
27
+            echo getpaid_format_date_value($discount->get_expiration_date(), __('Never', 'invoicing'));
28 28
         break;
29 29
     }
30 30
 }
31 31
 
32
-add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 );
33
-function wpinv_post_row_actions( $actions, $post ) {
34
-    $post_type = !empty( $post->post_type ) ? $post->post_type : '';
32
+add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2);
33
+function wpinv_post_row_actions($actions, $post) {
34
+    $post_type = !empty($post->post_type) ? $post->post_type : '';
35 35
 
36
-    if ( $post_type == 'wpi_invoice' ) {
36
+    if ($post_type == 'wpi_invoice') {
37 37
         $actions = array();
38 38
     }
39 39
 
40
-    if ( $post_type == 'wpi_discount' ) {
41
-        $actions = wpinv_discount_row_actions( $post, $actions );
40
+    if ($post_type == 'wpi_discount') {
41
+        $actions = wpinv_discount_row_actions($post, $actions);
42 42
     }
43 43
 
44 44
     return $actions;
45 45
 }
46 46
 
47
-function wpinv_discount_row_actions( $discount, $row_actions ) {
48
-    $row_actions  = array();
49
-    $edit_link = get_edit_post_link( $discount->ID );
50
-    $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>';
47
+function wpinv_discount_row_actions($discount, $row_actions) {
48
+    $row_actions = array();
49
+    $edit_link = get_edit_post_link($discount->ID);
50
+    $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>';
51 51
 
52
-    if( in_array( strtolower( $discount->post_status ),  array(  'publish' ) ) ) {
53
-        $row_actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'deactivate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Deactivate', 'invoicing' ) . '</a>';
54
-    } elseif( in_array( strtolower( $discount->post_status ),  array( 'pending', 'draft' ) ) ) {
55
-        $row_actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'activate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Activate', 'invoicing' ) . '</a>';
52
+    if (in_array(strtolower($discount->post_status), array('publish'))) {
53
+        $row_actions['deactivate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'deactivate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Deactivate', 'invoicing') . '</a>';
54
+    } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) {
55
+        $row_actions['activate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'activate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Activate', 'invoicing') . '</a>';
56 56
     }
57 57
 
58 58
     $delete_url = esc_url(
@@ -66,110 +66,110 @@  discard block
 block discarded – undo
66 66
             'wpinv_discount_nonce'
67 67
         )
68 68
     );
69
-    $row_actions['delete'] = '<a href="' . $delete_url . '">' . __( 'Delete', 'invoicing' ) . '</a>';
69
+    $row_actions['delete'] = '<a href="' . $delete_url . '">' . __('Delete', 'invoicing') . '</a>';
70 70
 
71
-    $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount );
71
+    $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount);
72 72
 
73 73
     return $row_actions;
74 74
 }
75 75
 
76
-add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 );
77
-function wpinv_table_primary_column( $default, $screen_id ) {
78
-    if ( 'edit-wpi_invoice' === $screen_id ) {
76
+add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2);
77
+function wpinv_table_primary_column($default, $screen_id) {
78
+    if ('edit-wpi_invoice' === $screen_id) {
79 79
         return 'name';
80 80
     }
81 81
 
82 82
     return $default;
83 83
 }
84 84
 
85
-function wpinv_discount_bulk_actions( $actions, $display = false ) {
86
-    if ( !$display ) {
85
+function wpinv_discount_bulk_actions($actions, $display = false) {
86
+    if (!$display) {
87 87
         return array();
88 88
     }
89 89
 
90 90
     $actions = array(
91
-        'activate'   => __( 'Activate', 'invoicing' ),
92
-        'deactivate' => __( 'Deactivate', 'invoicing' ),
93
-        'delete'     => __( 'Delete', 'invoicing' ),
91
+        'activate'   => __('Activate', 'invoicing'),
92
+        'deactivate' => __('Deactivate', 'invoicing'),
93
+        'delete'     => __('Delete', 'invoicing'),
94 94
     );
95 95
     $two = '';
96 96
     $which = 'top';
97 97
     echo '</div><div class="alignleft actions bulkactions">';
98
-    echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>';
99
-    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">";
100
-    echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>";
98
+    echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>';
99
+    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">";
100
+    echo '<option value="-1">' . __('Bulk Actions') . "</option>";
101 101
 
102
-    foreach ( $actions as $name => $title ) {
102
+    foreach ($actions as $name => $title) {
103 103
         $class = 'edit' === $name ? ' class="hide-if-no-js"' : '';
104 104
 
105 105
         echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>";
106 106
     }
107 107
     echo "</select>";
108 108
 
109
-    submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
109
+    submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two"));
110 110
 
111 111
     echo '</div><div class="alignleft actions">';
112 112
 }
113
-add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 );
113
+add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10);
114 114
 
115
-function wpinv_disable_months_dropdown( $disable, $post_type ) {
116
-    if ( $post_type == 'wpi_discount' ) {
115
+function wpinv_disable_months_dropdown($disable, $post_type) {
116
+    if ($post_type == 'wpi_discount') {
117 117
         $disable = true;
118 118
     }
119 119
 
120 120
     return $disable;
121 121
 }
122
-add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 );
122
+add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2);
123 123
 
124 124
 function wpinv_restrict_manage_posts() {
125 125
     global $typenow;
126 126
 
127
-    if( 'wpi_discount' == $typenow ) {
127
+    if ('wpi_discount' == $typenow) {
128 128
         wpinv_discount_filters();
129 129
     }
130 130
 }
131
-add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 );
131
+add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10);
132 132
 
133 133
 function wpinv_discount_filters() {
134
-    wpinv_discount_bulk_actions( array(), true );
134
+    wpinv_discount_bulk_actions(array(), true);
135 135
 
136 136
     ?>
137 137
     <select name="discount_type" id="dropdown_wpinv_discount_type">
138
-        <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option>
138
+        <option value=""><?php _e('Show all types', 'invoicing'); ?></option>
139 139
         <?php
140 140
             $types = wpinv_get_discount_types();
141 141
 
142
-            foreach ( $types as $name => $type ) {
143
-                echo '<option value="' . esc_attr( $name ) . '"';
142
+            foreach ($types as $name => $type) {
143
+                echo '<option value="' . esc_attr($name) . '"';
144 144
 
145
-                if ( isset( $_GET['discount_type'] ) )
146
-                    selected( $name, $_GET['discount_type'] );
145
+                if (isset($_GET['discount_type']))
146
+                    selected($name, $_GET['discount_type']);
147 147
 
148
-                echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
148
+                echo '>' . esc_html__($type, 'invoicing') . '</option>';
149 149
             }
150 150
         ?>
151 151
     </select>
152 152
     <?php
153 153
 }
154 154
 
155
-function wpinv_request( $vars ) {
155
+function wpinv_request($vars) {
156 156
     global $typenow, $wp_query, $wp_post_statuses;
157 157
 
158
-    if ( 'wpi_invoice' === $typenow ) {
159
-        if ( !isset( $vars['post_status'] ) ) {
158
+    if ('wpi_invoice' === $typenow) {
159
+        if (!isset($vars['post_status'])) {
160 160
             $post_statuses = wpinv_get_invoice_statuses();
161 161
 
162
-            foreach ( $post_statuses as $status => $value ) {
163
-                if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) {
164
-                    unset( $post_statuses[ $status ] );
162
+            foreach ($post_statuses as $status => $value) {
163
+                if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) {
164
+                    unset($post_statuses[$status]);
165 165
                 }
166 166
             }
167 167
 
168
-            $vars['post_status'] = array_keys( $post_statuses );
168
+            $vars['post_status'] = array_keys($post_statuses);
169 169
         }
170 170
 
171
-        if ( isset( $vars['orderby'] ) ) {
172
-            if ( 'amount' == $vars['orderby'] ) {
171
+        if (isset($vars['orderby'])) {
172
+            if ('amount' == $vars['orderby']) {
173 173
                 $vars = array_merge(
174 174
                     $vars,
175 175
                     array(
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
                         'orderby'  => 'meta_value_num'
178 178
                     )
179 179
                 );
180
-            } else if ( 'customer' == $vars['orderby'] ) {
180
+            } else if ('customer' == $vars['orderby']) {
181 181
                 $vars = array_merge(
182 182
                     $vars,
183 183
                     array(
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
                         'orderby'  => 'meta_value'
186 186
                     )
187 187
                 );
188
-            } else if ( 'number' == $vars['orderby'] ) {
188
+            } else if ('number' == $vars['orderby']) {
189 189
                 $vars = array_merge(
190 190
                     $vars,
191 191
                     array(
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
                         'orderby'  => 'meta_value'
194 194
                     )
195 195
                 );
196
-            } else if ( 'payment_date' == $vars['orderby'] ) {
196
+            } else if ('payment_date' == $vars['orderby']) {
197 197
                 $vars = array_merge(
198 198
                     $vars,
199 199
                     array(
@@ -203,73 +203,73 @@  discard block
 block discarded – undo
203 203
                 );
204 204
             }
205 205
         }
206
-    } else if ( 'wpi_discount' == $typenow ) {
207
-        $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
206
+    } else if ('wpi_discount' == $typenow) {
207
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
208 208
         // Filter vat rule type
209
-        if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) {
209
+        if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') {
210 210
             $meta_query[] = array(
211 211
                     'key'   => '_wpi_discount_type',
212
-                    'value' => sanitize_text_field( $_GET['discount_type'] ),
212
+                    'value' => sanitize_text_field($_GET['discount_type']),
213 213
                     'compare' => '='
214 214
                 );
215 215
         }
216 216
 
217
-        if ( !empty( $meta_query ) ) {
217
+        if (!empty($meta_query)) {
218 218
             $vars['meta_query'] = $meta_query;
219 219
         }
220 220
     }
221 221
 
222 222
     return $vars;
223 223
 }
224
-add_filter( 'request', 'wpinv_request' );
224
+add_filter('request', 'wpinv_request');
225 225
 
226
-function wpinv_item_type_class( $classes, $class, $post_id ) {
226
+function wpinv_item_type_class($classes, $class, $post_id) {
227 227
     global $pagenow, $typenow;
228 228
 
229
-    if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow ) {
230
-        if ( $type = get_post_meta( $post_id, '_wpinv_type', true ) ) {
231
-            $classes[] = 'wpi-type-' . sanitize_html_class( $type );
229
+    if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow) {
230
+        if ($type = get_post_meta($post_id, '_wpinv_type', true)) {
231
+            $classes[] = 'wpi-type-' . sanitize_html_class($type);
232 232
         }
233 233
 
234
-        if ( !wpinv_item_is_editable( $post_id ) ) {
234
+        if (!wpinv_item_is_editable($post_id)) {
235 235
             $classes[] = 'wpi-editable-n';
236 236
         }
237 237
     }
238 238
     return $classes;
239 239
 }
240
-add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 );
240
+add_filter('post_class', 'wpinv_item_type_class', 10, 3);
241 241
 
242 242
 function wpinv_check_quick_edit() {
243 243
     global $pagenow, $current_screen, $wpinv_item_screen;
244 244
 
245
-    if ( $pagenow == 'edit.php' && !empty( $current_screen->post_type ) ) {
246
-        if ( empty( $wpinv_item_screen ) ) {
247
-            if ( $current_screen->post_type == 'wpi_item' ) {
245
+    if ($pagenow == 'edit.php' && !empty($current_screen->post_type)) {
246
+        if (empty($wpinv_item_screen)) {
247
+            if ($current_screen->post_type == 'wpi_item') {
248 248
                 $wpinv_item_screen = 'y';
249 249
             } else {
250 250
                 $wpinv_item_screen = 'n';
251 251
             }
252 252
         }
253 253
 
254
-        if ( $wpinv_item_screen == 'y' && $pagenow == 'edit.php' ) {
255
-            add_filter( 'post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 );
256
-            add_filter( 'page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 );
254
+        if ($wpinv_item_screen == 'y' && $pagenow == 'edit.php') {
255
+            add_filter('post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2);
256
+            add_filter('page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2);
257 257
         }
258 258
     }
259 259
 }
260
-add_action( 'admin_head', 'wpinv_check_quick_edit', 10 );
260
+add_action('admin_head', 'wpinv_check_quick_edit', 10);
261 261
 
262
-function wpinv_item_disable_quick_edit( $actions = array(), $row = null ) {
263
-    if ( isset( $actions['inline hide-if-no-js'] ) ) {
264
-        unset( $actions['inline hide-if-no-js'] );
262
+function wpinv_item_disable_quick_edit($actions = array(), $row = null) {
263
+    if (isset($actions['inline hide-if-no-js'])) {
264
+        unset($actions['inline hide-if-no-js']);
265 265
     }
266 266
 
267
-    if ( !empty( $row->post_type ) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable( $row ) ) {
268
-        if ( isset( $actions['trash'] ) ) {
269
-            unset( $actions['trash'] );
267
+    if (!empty($row->post_type) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable($row)) {
268
+        if (isset($actions['trash'])) {
269
+            unset($actions['trash']);
270 270
         }
271
-        if ( isset( $actions['delete'] ) ) {
272
-            unset( $actions['delete'] );
271
+        if (isset($actions['delete'])) {
272
+            unset($actions['delete']);
273 273
         }
274 274
     }
275 275
 
@@ -286,19 +286,19 @@  discard block
 block discarded – undo
286 286
  * @param int $post_parent (default: 0) Parent for the new page
287 287
  * @return int page ID
288 288
  */
289
-function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) {
289
+function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) {
290 290
     global $wpdb;
291 291
 
292
-    $option_value = wpinv_get_option( $option );
292
+    $option_value = wpinv_get_option($option);
293 293
 
294
-    if ( $option_value > 0 && ( $page_object = get_post( $option_value ) ) ) {
295
-        if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) {
294
+    if ($option_value > 0 && ($page_object = get_post($option_value))) {
295
+        if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) {
296 296
             // Valid page is already in place
297 297
             return $page_object->ID;
298 298
         }
299 299
     }
300 300
 
301
-    if(!empty($post_parent)){
301
+    if (!empty($post_parent)) {
302 302
         $page = get_page_by_path($post_parent);
303 303
         if ($page) {
304 304
             $post_parent = $page->ID;
@@ -307,40 +307,40 @@  discard block
 block discarded – undo
307 307
         }
308 308
     }
309 309
 
310
-    if ( strlen( $page_content ) > 0 ) {
310
+    if (strlen($page_content) > 0) {
311 311
         // Search for an existing page with the specified page content (typically a shortcode)
312
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
312
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
313 313
     } else {
314 314
         // Search for an existing page with the specified page slug
315
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug ) );
315
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug));
316 316
     }
317 317
 
318
-    $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content );
318
+    $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content);
319 319
 
320
-    if ( $valid_page_found ) {
321
-        if ( $option ) {
322
-            wpinv_update_option( $option, $valid_page_found );
320
+    if ($valid_page_found) {
321
+        if ($option) {
322
+            wpinv_update_option($option, $valid_page_found);
323 323
         }
324 324
         return $valid_page_found;
325 325
     }
326 326
 
327 327
     // Search for a matching valid trashed page
328
-    if ( strlen( $page_content ) > 0 ) {
328
+    if (strlen($page_content) > 0) {
329 329
         // Search for an existing page with the specified page content (typically a shortcode)
330
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
330
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
331 331
     } else {
332 332
         // Search for an existing page with the specified page slug
333
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) );
333
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug));
334 334
     }
335 335
 
336
-    if ( $trashed_page_found ) {
336
+    if ($trashed_page_found) {
337 337
         $page_id   = $trashed_page_found;
338 338
         $page_data = array(
339 339
             'ID'             => $page_id,
340 340
             'post_status'    => 'publish',
341 341
             'post_parent'    => $post_parent,
342 342
         );
343
-        wp_update_post( $page_data );
343
+        wp_update_post($page_data);
344 344
     } else {
345 345
         $page_data = array(
346 346
             'post_status'    => 'publish',
@@ -352,11 +352,11 @@  discard block
 block discarded – undo
352 352
             'post_parent'    => $post_parent,
353 353
             'comment_status' => 'closed',
354 354
         );
355
-        $page_id = wp_insert_post( $page_data );
355
+        $page_id = wp_insert_post($page_data);
356 356
     }
357 357
 
358
-    if ( $option ) {
359
-        wpinv_update_option( $option, (int)$page_id );
358
+    if ($option) {
359
+        wpinv_update_option($option, (int) $page_id);
360 360
     }
361 361
 
362 362
     return $page_id;
Please login to merge, or discard this patch.
includes/admin/class-getpaid-metaboxes.php 1 patch
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Metaboxes Admin Class
@@ -25,93 +25,93 @@  discard block
 block discarded – undo
25 25
 	public static function init() {
26 26
 
27 27
 		// Register metaboxes.
28
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
28
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2);
29 29
 
30 30
 		// Remove metaboxes.
31
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
31
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30);
32 32
 
33 33
 		// Rename metaboxes.
34
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
34
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45);
35 35
 
36 36
 		// Save metaboxes.
37
-		add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
37
+		add_action('save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2);
38 38
 	}
39 39
 
40 40
 	/**
41 41
 	 * Register core metaboxes.
42 42
 	 */
43
-	public static function add_meta_boxes( $post_type, $post ) {
43
+	public static function add_meta_boxes($post_type, $post) {
44 44
 		global $wpinv_euvat;
45 45
 
46 46
 		// For invoices...
47
-		if ( $post_type == 'wpi_invoice' ) {
48
-			$invoice = new WPInv_Invoice( $post );
47
+		if ($post_type == 'wpi_invoice') {
48
+			$invoice = new WPInv_Invoice($post);
49 49
 
50 50
 			// Resend invoice.
51
-			if ( ! $invoice->is_draft() && ! $invoice->is_paid() ) {
52
-				add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'GetPaid_Meta_Box_Resend_Invoice::output', 'wpi_invoice', 'side', 'low' );
51
+			if (!$invoice->is_draft() && !$invoice->is_paid()) {
52
+				add_meta_box('wpinv-mb-resend-invoice', __('Resend Invoice', 'invoicing'), 'GetPaid_Meta_Box_Resend_Invoice::output', 'wpi_invoice', 'side', 'low');
53 53
 			}
54 54
 
55 55
 			// Subscriptions.
56
-			$subscription = getpaid_get_invoice_subscription( $invoice );
57
-			if ( ! empty( $subscription ) ) {
58
-				add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', 'wpi_invoice', 'advanced' );
59
-				add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', 'wpi_invoice', 'advanced' );
56
+			$subscription = getpaid_get_invoice_subscription($invoice);
57
+			if (!empty($subscription)) {
58
+				add_meta_box('wpinv-mb-subscriptions', __('Subscription Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output', 'wpi_invoice', 'advanced');
59
+				add_meta_box('wpinv-mb-subscription-invoices', __('Related Payments', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', 'wpi_invoice', 'advanced');
60 60
 			}
61 61
 
62 62
 			// Invoice details.
63
-			add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Details::output', 'wpi_invoice', 'side', 'default' );
63
+			add_meta_box('wpinv-details', __('Invoice Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Details::output', 'wpi_invoice', 'side', 'default');
64 64
 			
65 65
 			// Payment details.
66
-			if ( ! $invoice->is_draft() ) {
67
-				add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', 'wpi_invoice', 'side', 'default' );
66
+			if (!$invoice->is_draft()) {
67
+				add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', 'wpi_invoice', 'side', 'default');
68 68
 			}
69 69
 
70 70
 			// Billing details.
71
-			add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', 'wpi_invoice', 'normal', 'high' );
71
+			add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Address::output', 'wpi_invoice', 'normal', 'high');
72 72
 			
73 73
 			// Invoice items.
74
-			add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Items::output', 'wpi_invoice', 'normal', 'high' );
74
+			add_meta_box('wpinv-items', __('Invoice Items', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Items::output', 'wpi_invoice', 'normal', 'high');
75 75
 			
76 76
 			// Invoice notes.
77
-			add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'side', 'low' );
77
+			add_meta_box('wpinv-notes', __('Invoice Notes', 'invoicing'), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'side', 'low');
78 78
 
79 79
 			// Payment form information.
80
-			if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) {
81
-				add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high' );
80
+			if (!empty($post->ID) && get_post_meta($post->ID, 'payment_form_data', true)) {
81
+				add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high');
82 82
 			}
83 83
 		}
84 84
 
85 85
 		// For payment forms.
86
-		if ( $post_type == 'wpi_payment_form' ) {
86
+		if ($post_type == 'wpi_payment_form') {
87 87
 
88 88
 			// Design payment form.
89
-			add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
89
+			add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal');
90 90
 
91 91
 			// Payment form information.
92
-			add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
92
+			add_meta_box('wpinv-payment-form-info', __('Details', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side');
93 93
 
94 94
 		}
95 95
 
96 96
 		// For invoice items.
97
-		if ( $post_type == 'wpi_item' ) {
97
+		if ($post_type == 'wpi_item') {
98 98
 
99 99
 			// Item details.
100
-			add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
100
+			add_meta_box('wpinv_item_details', __('Item Details', 'invoicing'), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high');
101 101
 
102 102
 			// If taxes are enabled, register the tax metabox.
103
-			if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) {
104
-				add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
103
+			if ($wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes()) {
104
+				add_meta_box('wpinv_item_vat', __('VAT / Tax', 'invoicing'), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high');
105 105
 			}
106 106
 
107 107
 			// Item info.
108
-			add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
108
+			add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core');
109 109
 
110 110
 		}
111 111
 
112 112
 		// For invoice discounts.
113
-		if ( $post_type == 'wpi_discount' ) {
114
-			add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
113
+		if ($post_type == 'wpi_discount') {
114
+			add_meta_box('wpinv_discount_details', __('Discount Details', 'invoicing'), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high');
115 115
 		}
116 116
 		
117 117
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 * Remove some metaboxes.
122 122
 	 */
123 123
 	public static function remove_meta_boxes() {
124
-		remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
124
+		remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal');
125 125
 	}
126 126
 
127 127
 	/**
@@ -137,37 +137,37 @@  discard block
 block discarded – undo
137 137
 	 * @param  int    $post_id Post ID.
138 138
 	 * @param  object $post Post object.
139 139
 	 */
140
-	public static function save_meta_boxes( $post_id, $post ) {
141
-		$post_id = absint( $post_id );
142
-		$data    = wp_unslash( $_POST );
140
+	public static function save_meta_boxes($post_id, $post) {
141
+		$post_id = absint($post_id);
142
+		$data    = wp_unslash($_POST);
143 143
 
144 144
 		// Do not save for ajax requests.
145
-		if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
145
+		if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
146 146
 			return;
147 147
 		}
148 148
 
149 149
 		// $post_id and $post are required
150
-		if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
150
+		if (empty($post_id) || empty($post) || self::$saved_meta_boxes) {
151 151
 			return;
152 152
 		}
153 153
 
154 154
 		// Dont' save meta boxes for revisions or autosaves.
155
-		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
155
+		if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
156 156
 			return;
157 157
 		}
158 158
 
159 159
 		// Check the nonce.
160
-		if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
160
+		if (empty($data['getpaid_meta_nonce']) || !wp_verify_nonce($data['getpaid_meta_nonce'], 'getpaid_meta_nonce')) {
161 161
 			return;
162 162
 		}
163 163
 
164 164
 		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
165
-		if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
165
+		if (empty($data['post_ID']) || absint($data['post_ID']) !== $post_id) {
166 166
 			return;
167 167
 		}
168 168
 
169 169
 		// Check user has permission to edit.
170
-		if ( ! current_user_can( 'edit_post', $post_id ) ) {
170
+		if (!current_user_can('edit_post', $post_id)) {
171 171
 			return;
172 172
 		}
173 173
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 		);
182 182
 
183 183
 		// Is this our post type?
184
-		if ( empty( $post->post_type ) || ! isset( $post_types_map[ $post->post_type ] ) ) {
184
+		if (empty($post->post_type) || !isset($post_types_map[$post->post_type])) {
185 185
 			return;
186 186
 		}
187 187
 
@@ -189,8 +189,8 @@  discard block
 block discarded – undo
189 189
 		self::$saved_meta_boxes = true;
190 190
 		
191 191
 		// Save the post.
192
-		$class = $post_types_map[ $post->post_type ];
193
-		$class::save( $post_id, $_POST, $post );
192
+		$class = $post_types_map[$post->post_type];
193
+		$class::save($post_id, $_POST, $post);
194 194
 
195 195
 	}
196 196
 
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-invoice-payment-meta.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  *
8 8
  */
9 9
 
10
-if ( ! defined( 'ABSPATH' ) ) {
10
+if (!defined('ABSPATH')) {
11 11
 	exit; // Exit if accessed directly
12 12
 }
13 13
 
@@ -21,10 +21,10 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @param WP_Post $post
23 23
 	 */
24
-    public static function output( $post ) {
24
+    public static function output($post) {
25 25
 
26 26
         // Prepare the invoice.
27
-        $invoice = new WPInv_Invoice( $post );
27
+        $invoice = new WPInv_Invoice($post);
28 28
 
29 29
         ?>
30 30
 
@@ -46,10 +46,10 @@  discard block
 block discarded – undo
46 46
                                 'type'        => 'text',
47 47
                                 'id'          => 'wpinv_key',
48 48
                                 'name'        => 'wpinv_key',
49
-                                'label'       => __( 'Invoice Key:', 'invoicing' ),
49
+                                'label'       => __('Invoice Key:', 'invoicing'),
50 50
                                 'label_type'  => 'vertical',
51 51
                                 'class'       => 'form-control-sm',
52
-                                'value'       => $invoice->get_key( 'edit' ),
52
+                                'value'       => $invoice->get_key('edit'),
53 53
                                 'extra_attributes' => array(
54 54
                                     'onclick'  => 'this.select();',
55 55
                                     'readonly' => 'true',
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
                                 'type'        => 'text',
64 64
                                 'id'          => 'wpinv_view_url',
65 65
                                 'name'        => 'wpinv_view_url',
66
-                                'label'       => __( 'Invoice URL:', 'invoicing' ),
66
+                                'label'       => __('Invoice URL:', 'invoicing'),
67 67
                                 'label_type'  => 'vertical',
68 68
                                 'class'       => 'form-control-sm',
69 69
                                 'value'       => $invoice->get_view_url(),
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
                         );
76 76
 
77 77
                         // If the invoice is paid...
78
-                        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
78
+                        if ($invoice->is_paid() || $invoice->is_refunded()) {
79 79
 
80 80
                             // Payment date.
81 81
                             echo aui()->input(
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
                                     'type'        => 'datepicker',
84 84
                                     'id'          => 'wpinv_date_completed',
85 85
                                     'name'        => 'date_completed',
86
-                                    'label'       => __( 'Payment Date:', 'invoicing' ),
86
+                                    'label'       => __('Payment Date:', 'invoicing'),
87 87
                                     'label_type'  => 'vertical',
88 88
                                     'placeholder' => 'YYYY-MM-DD 00:00',
89 89
                                     'class'       => 'form-control-sm',
90
-                                    'value'       => $invoice->get_date_completed( 'edit' ),
90
+                                    'value'       => $invoice->get_date_completed('edit'),
91 91
                                     'extra_attributes' => array(
92 92
                                         'data-enable-time' => 'true',
93 93
                                         'data-time_24hr'   => 'true',
@@ -102,10 +102,10 @@  discard block
 block discarded – undo
102 102
                                     'type'        => 'text',
103 103
                                     'id'          => 'wpinv_gateway',
104 104
                                     'name'        => 'wpinv_gateway',
105
-                                    'label'       => __( 'Gateway:', 'invoicing' ),
105
+                                    'label'       => __('Gateway:', 'invoicing'),
106 106
                                     'label_type'  => 'vertical',
107 107
                                     'class'       => 'form-control-sm',
108
-                                    'value'       => wpinv_get_gateway_admin_label( $invoice->get_gateway( 'edit' ) ),
108
+                                    'value'       => wpinv_get_gateway_admin_label($invoice->get_gateway('edit')),
109 109
                                     'extra_attributes' => array(
110 110
                                         'onclick'  => 'this.select();',
111 111
                                         'readonly' => 'true',
@@ -119,11 +119,11 @@  discard block
 block discarded – undo
119 119
                                     'type'        => 'text',
120 120
                                     'id'          => 'wpinv_transaction_id',
121 121
                                     'name'        => 'wpinv_transaction_id',
122
-                                    'label'       => __( 'Transaction ID:', 'invoicing' ),
122
+                                    'label'       => __('Transaction ID:', 'invoicing'),
123 123
                                     'label_type'  => 'vertical',
124 124
                                     'class'       => 'form-control-sm',
125
-                                    'value'       => $invoice->get_transaction_id( 'edit' ),
126
-                                    'help_text'   => apply_filters( 'wpinv_invoice_transaction_link_' . $invoice->get_gateway( 'edit' ), '', $invoice->get_transaction_id(), $invoice ),
125
+                                    'value'       => $invoice->get_transaction_id('edit'),
126
+                                    'help_text'   => apply_filters('wpinv_invoice_transaction_link_' . $invoice->get_gateway('edit'), '', $invoice->get_transaction_id(), $invoice),
127 127
                                     'extra_attributes' => array(
128 128
                                         'onclick'  => 'this.select();',
129 129
                                         'readonly' => 'true',
@@ -137,10 +137,10 @@  discard block
 block discarded – undo
137 137
                                     'type'        => 'text',
138 138
                                     'id'          => 'wpinv_currency',
139 139
                                     'name'        => 'wpinv_currency',
140
-                                    'label'       => __( 'Currency:', 'invoicing' ),
140
+                                    'label'       => __('Currency:', 'invoicing'),
141 141
                                     'label_type'  => 'vertical',
142 142
                                     'class'       => 'form-control-sm',
143
-                                    'value'       => $invoice->get_currency( 'edit' ),
143
+                                    'value'       => $invoice->get_currency('edit'),
144 144
                                     'extra_attributes' => array(
145 145
                                         'onclick'  => 'this.select();',
146 146
                                         'readonly' => 'true',
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
                                     'type'        => 'text',
157 157
                                     'id'          => 'wpinv_payment_url',
158 158
                                     'name'        => 'wpinv_payment_url',
159
-                                    'label'       => __( 'Payment URL:', 'invoicing' ),
159
+                                    'label'       => __('Payment URL:', 'invoicing'),
160 160
                                     'label_type'  => 'vertical',
161 161
                                     'class'       => 'form-control-sm',
162 162
                                     'value'       => $invoice->get_checkout_payment_url(),
@@ -172,13 +172,13 @@  discard block
 block discarded – undo
172 172
                                 array(
173 173
                                     'id'               => 'wpinv_gateway',
174 174
                                     'name'             => 'wpinv_gateway',
175
-                                    'label'            => __( 'Gateway:', 'invoicing' ),
175
+                                    'label'            => __('Gateway:', 'invoicing'),
176 176
                                     'label_type'       => 'vertical',
177
-                                    'placeholder'      => __( 'Select Gateway', 'invoicing' ),
178
-                                    'value'            => $invoice->get_gateway( 'edit' ),
177
+                                    'placeholder'      => __('Select Gateway', 'invoicing'),
178
+                                    'value'            => $invoice->get_gateway('edit'),
179 179
                                     'select2'          => true,
180 180
                                     'data-allow-clear' => 'false',
181
-                                    'options'          => wp_list_pluck( wpinv_get_enabled_payment_gateways( true ), 'admin_label' ),
181
+                                    'options'          => wp_list_pluck(wpinv_get_enabled_payment_gateways(true), 'admin_label'),
182 182
                                 )
183 183
                             );
184 184
 
Please login to merge, or discard this patch.
includes/admin/wpinv-upgrade-functions.php 1 patch
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -11,55 +11,55 @@  discard block
 block discarded – undo
11 11
  * @since 1.0.0
12 12
 */
13 13
 function wpinv_automatic_upgrade() {
14
-    $wpi_version = get_option( 'wpinv_version' );
14
+    $wpi_version = get_option('wpinv_version');
15 15
 
16 16
     // Update tables.
17
-    if ( ! get_option( 'getpaid_created_invoice_tables' ) ) {
17
+    if (!get_option('getpaid_created_invoice_tables')) {
18 18
         wpinv_v119_upgrades();
19
-        update_option( 'getpaid_created_invoice_tables', true );
19
+        update_option('getpaid_created_invoice_tables', true);
20 20
     }
21 21
 
22
-    if ( $wpi_version == WPINV_VERSION ) {
22
+    if ($wpi_version == WPINV_VERSION) {
23 23
         return;
24 24
     }
25 25
 
26
-    if ( version_compare( $wpi_version, '0.0.5', '<' ) ) {
26
+    if (version_compare($wpi_version, '0.0.5', '<')) {
27 27
         wpinv_v005_upgrades();
28 28
     }
29 29
 
30
-    if ( version_compare( $wpi_version, '1.0.3', '<' ) ) {
30
+    if (version_compare($wpi_version, '1.0.3', '<')) {
31 31
         wpinv_v110_upgrades();
32 32
     }
33 33
 
34
-    update_option( 'wpinv_version', WPINV_VERSION );
34
+    update_option('wpinv_version', WPINV_VERSION);
35 35
 }
36
-add_action( 'admin_init', 'wpinv_automatic_upgrade' );
36
+add_action('admin_init', 'wpinv_automatic_upgrade');
37 37
 
38 38
 function wpinv_v005_upgrades() {
39 39
     global $wpdb;
40 40
 
41 41
     // Invoices status
42
-    $results = $wpdb->get_results( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
43
-    if ( !empty( $results ) ) {
44
-        $wpdb->query( "UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
42
+    $results = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
43
+    if (!empty($results)) {
44
+        $wpdb->query("UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
45 45
 
46 46
         // Clean post cache
47
-        foreach ( $results as $row ) {
48
-            clean_post_cache( $row->ID );
47
+        foreach ($results as $row) {
48
+            clean_post_cache($row->ID);
49 49
         }
50 50
     }
51 51
 
52 52
     // Item meta key changes
53 53
     $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
54
-    $results = $wpdb->get_results( $query );
54
+    $results = $wpdb->get_results($query);
55 55
 
56
-    if ( !empty( $results ) ) {
57
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
58
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
59
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
56
+    if (!empty($results)) {
57
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )");
58
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'");
59
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'");
60 60
         
61
-        foreach ( $results as $row ) {
62
-            clean_post_cache( $row->post_id );
61
+        foreach ($results as $row) {
62
+            clean_post_cache($row->post_id);
63 63
         }
64 64
     }
65 65
 
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 function wpinv_create_invoices_table() {
89 89
     global $wpdb;
90 90
 
91
-    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
91
+    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
92 92
 
93 93
     // Create invoices table.
94 94
     $table = $wpdb->prefix . 'getpaid_invoices';
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
             KEY `key` ( `key` )
133 133
             ) CHARACTER SET utf8 COLLATE utf8_general_ci;";
134 134
 
135
-    dbDelta( $sql );
135
+    dbDelta($sql);
136 136
 
137 137
     // Create invoice items table.
138 138
     $table = $wpdb->prefix . 'getpaid_invoice_items';
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
             KEY post_id ( post_id )
161 161
             ) CHARACTER SET utf8 COLLATE utf8_general_ci;";
162 162
 
163
-    dbDelta( $sql );
163
+    dbDelta($sql);
164 164
 }
165 165
 
166 166
 /**
@@ -172,29 +172,29 @@  discard block
 block discarded – undo
172 172
     $invoices = array_unique(
173 173
         get_posts(
174 174
             array(
175
-                'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
175
+                'post_type'      => array('wpi_invoice', 'wpi_quote'),
176 176
                 'posts_per_page' => -1,
177 177
                 'fields'         => 'ids',
178
-                'post_status'    => array_keys( wpinv_get_invoice_statuses( true ) ),
178
+                'post_status'    => array_keys(wpinv_get_invoice_statuses(true)),
179 179
             )
180 180
         )
181 181
     );
182 182
     $invoices_table = $wpdb->prefix . 'getpaid_invoices';
183 183
     $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
184 184
 
185
-    if ( ! class_exists( 'WPInv_Legacy_Invoice' ) ) {
186
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' );
185
+    if (!class_exists('WPInv_Legacy_Invoice')) {
186
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php');
187 187
     }
188 188
 
189 189
     $invoice_rows = array();
190
-    foreach ( $invoices as $invoice ) {
190
+    foreach ($invoices as $invoice) {
191 191
 
192
-        $invoice = new WPInv_Legacy_Invoice( $invoice );
193
-        $fields = array (
192
+        $invoice = new WPInv_Legacy_Invoice($invoice);
193
+        $fields = array(
194 194
             'post_id'        => $invoice->ID,
195 195
             'number'         => $invoice->get_number(),
196 196
             'key'            => $invoice->get_key(),
197
-            'type'           => str_replace( 'wpi_', '', $invoice->post_type ),
197
+            'type'           => str_replace('wpi_', '', $invoice->post_type),
198 198
             'mode'           => $invoice->mode,
199 199
             'user_ip'        => $invoice->get_ip(),
200 200
             'first_name'     => $invoice->get_first_name(),
@@ -223,27 +223,27 @@  discard block
 block discarded – undo
223 223
             'custom_meta'    => $invoice->payment_meta
224 224
         );
225 225
 
226
-        foreach ( $fields as $key => $val ) {
227
-            if ( is_null( $val ) ) {
226
+        foreach ($fields as $key => $val) {
227
+            if (is_null($val)) {
228 228
                 $val = '';
229 229
             }
230
-            $val = maybe_serialize( $val );
231
-            $fields[ $key ] = $wpdb->prepare( '%s', $val );
230
+            $val = maybe_serialize($val);
231
+            $fields[$key] = $wpdb->prepare('%s', $val);
232 232
         }
233 233
 
234
-        $fields = implode( ', ', $fields );
234
+        $fields = implode(', ', $fields);
235 235
         $invoice_rows[] = "($fields)";
236 236
 
237 237
         $item_rows    = array();
238 238
         $item_columns = array();
239
-        foreach ( $invoice->get_cart_details() as $details ) {
239
+        foreach ($invoice->get_cart_details() as $details) {
240 240
             $fields = array(
241 241
                 'post_id'          => $invoice->ID,
242 242
                 'item_id'          => $details['id'],
243 243
                 'item_name'        => $details['name'],
244
-                'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
244
+                'item_description' => empty($details['meta']['description']) ? '' : $details['meta']['description'],
245 245
                 'vat_rate'         => $details['vat_rate'],
246
-                'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
246
+                'vat_class'        => empty($details['vat_class']) ? '_standard' : $details['vat_class'],
247 247
                 'tax'              => $details['tax'],
248 248
                 'item_price'       => $details['item_price'],
249 249
                 'custom_price'     => $details['custom_price'],
@@ -255,26 +255,26 @@  discard block
 block discarded – undo
255 255
                 'fees'             => $details['fees'],
256 256
             );
257 257
 
258
-            $item_columns = array_keys ( $fields );
258
+            $item_columns = array_keys($fields);
259 259
 
260
-            foreach ( $fields as $key => $val ) {
261
-                if ( is_null( $val ) ) {
260
+            foreach ($fields as $key => $val) {
261
+                if (is_null($val)) {
262 262
                     $val = '';
263 263
                 }
264
-                $val = maybe_serialize( $val );
265
-                $fields[ $key ] = $wpdb->prepare( '%s', $val );
264
+                $val = maybe_serialize($val);
265
+                $fields[$key] = $wpdb->prepare('%s', $val);
266 266
             }
267 267
 
268
-            $fields = implode( ', ', $fields );
268
+            $fields = implode(', ', $fields);
269 269
             $item_rows[] = "($fields)";
270 270
         }
271 271
 
272
-        $item_rows    = implode( ', ', $item_rows );
273
-        $item_columns = implode( ', ', $item_columns );
274
-        $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
272
+        $item_rows    = implode(', ', $item_rows);
273
+        $item_columns = implode(', ', $item_columns);
274
+        $wpdb->query("INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows");
275 275
     }
276 276
 
277
-    $invoice_rows = implode( ', ', $invoice_rows );
278
-    $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
277
+    $invoice_rows = implode(', ', $invoice_rows);
278
+    $wpdb->query("INSERT INTO $invoices_table VALUES $invoice_rows");
279 279
 
280 280
 }
Please login to merge, or discard this patch.
includes/subscription-functions.php 1 patch
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -15,26 +15,26 @@  discard block
 block discarded – undo
15 15
  *
16 16
  * @return int|array|WPInv_Subscription[]|GetPaid_Subscriptions_Query
17 17
  */
18
-function getpaid_get_subscriptions( $args = array(), $return = 'results' ) {
18
+function getpaid_get_subscriptions($args = array(), $return = 'results') {
19 19
 
20 20
 	// Do not retrieve all fields if we just want the count.
21
-	if ( 'count' == $return ) {
21
+	if ('count' == $return) {
22 22
 		$args['fields'] = 'id';
23 23
 		$args['number'] = 1;
24 24
 	}
25 25
 
26 26
 	// Do not count all matches if we just want the results.
27
-	if ( 'results' == $return ) {
27
+	if ('results' == $return) {
28 28
 		$args['count_total'] = false;
29 29
 	}
30 30
 
31
-	$query = new GetPaid_Subscriptions_Query( $args );
31
+	$query = new GetPaid_Subscriptions_Query($args);
32 32
 
33
-	if ( 'results' == $return ) {
33
+	if ('results' == $return) {
34 34
 		return $query->get_results();
35 35
 	}
36 36
 
37
-	if ( 'count' == $return ) {
37
+	if ('count' == $return) {
38 38
 		return $query->get_total();
39 39
 	}
40 40
 
@@ -51,13 +51,13 @@  discard block
 block discarded – undo
51 51
 	return apply_filters(
52 52
 		'getpaid_get_subscription_statuses',
53 53
 		array(
54
-			'pending'    => __( 'Pending', 'invoicing' ),
55
-			'trialling'  => __( 'Trialing', 'invoicing' ),
56
-			'active'     => __( 'Active', 'invoicing' ),
57
-			'failing'    => __( 'Failing', 'invoicing' ),
58
-			'expired'    => __( 'Expired', 'invoicing' ),
59
-			'completed'  => __( 'Complete', 'invoicing' ),
60
-			'cancelled'  => __( 'Cancelled', 'invoicing' ),
54
+			'pending'    => __('Pending', 'invoicing'),
55
+			'trialling'  => __('Trialing', 'invoicing'),
56
+			'active'     => __('Active', 'invoicing'),
57
+			'failing'    => __('Failing', 'invoicing'),
58
+			'expired'    => __('Expired', 'invoicing'),
59
+			'completed'  => __('Complete', 'invoicing'),
60
+			'cancelled'  => __('Cancelled', 'invoicing'),
61 61
 		)
62 62
 	);
63 63
 
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
  *
69 69
  * @return string
70 70
  */
71
-function getpaid_get_subscription_status_label( $status ) {
71
+function getpaid_get_subscription_status_label($status) {
72 72
 	$statuses = getpaid_get_subscription_statuses();
73
-	return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
73
+	return isset($statuses[$status]) ? $statuses[$status] : ucfirst(sanitize_text_field($status));
74 74
 }
75 75
 
76 76
 /**
@@ -100,14 +100,14 @@  discard block
 block discarded – undo
100 100
  *
101 101
  * @return array
102 102
  */
103
-function getpaid_get_subscription_status_counts( $args = array() ) {
103
+function getpaid_get_subscription_status_counts($args = array()) {
104 104
 
105
-	$statuses = array_keys( getpaid_get_subscription_statuses() );
105
+	$statuses = array_keys(getpaid_get_subscription_statuses());
106 106
 	$counts   = array();
107 107
 
108
-	foreach ( $statuses as $status ) {
109
-		$_args             = wp_parse_args( "status=$status", $args );
110
-		$counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
108
+	foreach ($statuses as $status) {
109
+		$_args             = wp_parse_args("status=$status", $args);
110
+		$counts[$status] = getpaid_get_subscriptions($_args, 'count');
111 111
 	}
112 112
 
113 113
 	return $counts;
@@ -126,23 +126,23 @@  discard block
 block discarded – undo
126 126
 		array(
127 127
 
128 128
 			'day'   => array(
129
-				'singular' => __( '%s day', 'invoicing' ),
130
-				'plural'   => __( '%d days', 'invoicing' ),
129
+				'singular' => __('%s day', 'invoicing'),
130
+				'plural'   => __('%d days', 'invoicing'),
131 131
 			),
132 132
 
133 133
 			'week'   => array(
134
-				'singular' => __( '%s week', 'invoicing' ),
135
-				'plural'   => __( '%d weeks', 'invoicing' ),
134
+				'singular' => __('%s week', 'invoicing'),
135
+				'plural'   => __('%d weeks', 'invoicing'),
136 136
 			),
137 137
 
138 138
 			'month'   => array(
139
-				'singular' => __( '%s month', 'invoicing' ),
140
-				'plural'   => __( '%d months', 'invoicing' ),
139
+				'singular' => __('%s month', 'invoicing'),
140
+				'plural'   => __('%d months', 'invoicing'),
141 141
 			),
142 142
 
143 143
 			'year'   => array(
144
-				'singular' => __( '%s year', 'invoicing' ),
145
-				'plural'   => __( '%d years', 'invoicing' ),
144
+				'singular' => __('%s year', 'invoicing'),
145
+				'plural'   => __('%d years', 'invoicing'),
146 146
 			),
147 147
 
148 148
 		)
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
  * @param string $trial_period
157 157
  * @return int
158 158
  */
159
-function getpaid_get_subscription_trial_period_interval( $trial_period ) {
160
-	return (int) preg_replace( '/[^0-9]/', '', $trial_period );
159
+function getpaid_get_subscription_trial_period_interval($trial_period) {
160
+	return (int) preg_replace('/[^0-9]/', '', $trial_period);
161 161
 }
162 162
 
163 163
 /**
@@ -166,8 +166,8 @@  discard block
 block discarded – undo
166 166
  * @param string $trial_period
167 167
  * @return string
168 168
  */
169
-function getpaid_get_subscription_trial_period_period( $trial_period ) {
170
-	return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
169
+function getpaid_get_subscription_trial_period_period($trial_period) {
170
+	return preg_replace('/[^a-z]/', '', strtolower($trial_period));
171 171
 }
172 172
 
173 173
 /**
@@ -177,9 +177,9 @@  discard block
 block discarded – undo
177 177
  * @param int $interval
178 178
  * @return string
179 179
  */
180
-function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) {
181
-	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
182
-	return strtolower( sanitize_text_field( $label ) );
180
+function getpaid_get_subscription_period_label($period, $interval = 1, $singular_prefix = '1') {
181
+	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label($period, $interval) : getpaid_get_singular_subscription_period_label($period, $singular_prefix);
182
+	return strtolower(sanitize_text_field($label));
183 183
 }
184 184
 
185 185
 /**
@@ -188,19 +188,19 @@  discard block
 block discarded – undo
188 188
  * @param string $period
189 189
  * @return string
190 190
  */
191
-function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) {
191
+function getpaid_get_singular_subscription_period_label($period, $singular_prefix = '1') {
192 192
 
193 193
 	$periods = getpaid_get_subscription_periods();
194
-	$period  = strtolower( $period );
194
+	$period  = strtolower($period);
195 195
 
196
-	if ( isset( $periods[ $period ] ) ) {
197
-		return sprintf( $periods[ $period ]['singular'], $singular_prefix );
196
+	if (isset($periods[$period])) {
197
+		return sprintf($periods[$period]['singular'], $singular_prefix);
198 198
 	}
199 199
 
200 200
 	// Backwards compatibility.
201
-	foreach ( $periods as $key => $data ) {
202
-		if ( strpos( $key, $period ) === 0 ) {
203
-			return sprintf( $data['singular'], $singular_prefix );
201
+	foreach ($periods as $key => $data) {
202
+		if (strpos($key, $period) === 0) {
203
+			return sprintf($data['singular'], $singular_prefix);
204 204
 		}
205 205
 	}
206 206
 
@@ -215,19 +215,19 @@  discard block
 block discarded – undo
215 215
  * @param int $interval
216 216
  * @return string
217 217
  */
218
-function getpaid_get_plural_subscription_period_label( $period, $interval ) {
218
+function getpaid_get_plural_subscription_period_label($period, $interval) {
219 219
 
220 220
 	$periods = getpaid_get_subscription_periods();
221
-	$period  = strtolower( $period );
221
+	$period  = strtolower($period);
222 222
 
223
-	if ( isset( $periods[ $period ] ) ) {
224
-		return sprintf( $periods[ $period ]['plural'], $interval );
223
+	if (isset($periods[$period])) {
224
+		return sprintf($periods[$period]['plural'], $interval);
225 225
 	}
226 226
 
227 227
 	// Backwards compatibility.
228
-	foreach ( $periods as $key => $data ) {
229
-		if ( strpos( $key, $period ) === 0 ) {
230
-			return sprintf( $data['plural'], $interval );
228
+	foreach ($periods as $key => $data) {
229
+		if (strpos($key, $period) === 0) {
230
+			return sprintf($data['plural'], $interval);
231 231
 		}
232 232
 	}
233 233
 
@@ -241,23 +241,23 @@  discard block
 block discarded – undo
241 241
  * @param WPInv_Subscription $subscription
242 242
  * @return string
243 243
  */
244
-function getpaid_get_formatted_subscription_amount( $subscription ) {
244
+function getpaid_get_formatted_subscription_amount($subscription) {
245 245
 
246
-	$initial   = wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() );
247
-	$recurring = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() );
248
-	$period    = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
246
+	$initial   = wpinv_price(wpinv_format_amount($subscription->get_initial_amount()), $subscription->get_parent_payment()->get_currency());
247
+	$recurring = wpinv_price(wpinv_format_amount($subscription->get_recurring_amount()), $subscription->get_parent_payment()->get_currency());
248
+	$period    = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), '');
249 249
 
250 250
 	// Trial periods.
251
-	if ( $subscription->has_trial_period() ) {
251
+	if ($subscription->has_trial_period()) {
252 252
 
253
-		$trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
254
-		$trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
253
+		$trial_period   = getpaid_get_subscription_trial_period_period($subscription->get_trial_period());
254
+		$trial_interval = getpaid_get_subscription_trial_period_interval($subscription->get_trial_period());
255 255
 		return sprintf(
256 256
 
257 257
 			// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
258
-			_x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
258
+			_x('%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing'),
259 259
 			$initial,
260
-			getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
260
+			getpaid_get_subscription_period_label($trial_period, $trial_interval),
261 261
 			$recurring,
262 262
 			$period
263 263
 
@@ -265,12 +265,12 @@  discard block
 block discarded – undo
265 265
 
266 266
 	}
267 267
 
268
-	if ( $initial != $recurring ) {
268
+	if ($initial != $recurring) {
269 269
 
270 270
 		return sprintf(
271 271
 
272 272
 			// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
273
-			_x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
273
+			_x('Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing'),
274 274
 			$initial,
275 275
 			$recurring,
276 276
 			$period
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 	return sprintf(
283 283
 
284 284
 		// translators: $1: is the recurring amount, $2: is the recurring period
285
-		_x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
285
+		_x('%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing'),
286 286
 		$initial,
287 287
 		$period
288 288
 
@@ -296,8 +296,8 @@  discard block
 block discarded – undo
296 296
  * @param WPInv_Invoice $invoice
297 297
  * @return WPInv_Subscription|bool
298 298
  */
299
-function getpaid_get_invoice_subscription( $invoice ) {
300
-	return getpaid_subscriptions()->get_invoice_subscription( $invoice );
299
+function getpaid_get_invoice_subscription($invoice) {
300
+	return getpaid_subscriptions()->get_invoice_subscription($invoice);
301 301
 }
302 302
 
303 303
 /**
@@ -305,9 +305,9 @@  discard block
 block discarded – undo
305 305
  *
306 306
  * @param WPInv_Invoice $invoice
307 307
  */
308
-function getpaid_activate_invoice_subscription( $invoice ) {
309
-	$subscription = getpaid_get_invoice_subscription( $invoice );
310
-	if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
308
+function getpaid_activate_invoice_subscription($invoice) {
309
+	$subscription = getpaid_get_invoice_subscription($invoice);
310
+	if (is_a($subscription, 'WPInv_Subscription')) {
311 311
 		$subscription->activate();
312 312
 	}
313 313
 }
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
  * @return WPInv_Subscriptions
319 319
  */
320 320
 function getpaid_subscriptions() {
321
-	return getpaid()->get( 'subscriptions' );
321
+	return getpaid()->get('subscriptions');
322 322
 }
323 323
 
324 324
 /**
@@ -326,13 +326,13 @@  discard block
 block discarded – undo
326 326
  *
327 327
  * @return WPInv_Subscription|bool
328 328
  */
329
-function wpinv_get_subscription( $invoice ) {
329
+function wpinv_get_subscription($invoice) {
330 330
 
331 331
     // Retrieve the invoice.
332
-    $invoice = new WPInv_Invoice( $invoice );
332
+    $invoice = new WPInv_Invoice($invoice);
333 333
 
334 334
     // Ensure it is a recurring invoice.
335
-    if ( ! $invoice->is_recurring() ) {
335
+    if (!$invoice->is_recurring()) {
336 336
         return false;
337 337
     }
338 338
 
@@ -344,6 +344,6 @@  discard block
 block discarded – undo
344 344
 		)
345 345
 	);
346 346
 
347
-	return empty( $subscription ) ? false : $subscription[0];
347
+	return empty($subscription) ? false : $subscription[0];
348 348
 
349 349
 }
Please login to merge, or discard this patch.
includes/class-getpaid-invoice-notification-emails.php 1 patch
Spacing   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * This class handles invoice notificaiton emails.
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 		$this->invoice_actions = apply_filters(
29 29
 			'getpaid_notification_email_invoice_triggers',
30 30
 			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
31
+				'getpaid_new_invoice'                   => array('new_invoice', 'user_invoice'),
32 32
 				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33 33
 				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34 34
 				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
@@ -50,11 +50,11 @@  discard block
 block discarded – undo
50 50
 	 */
51 51
 	public function init_hooks() {
52 52
 
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
53
+		add_filter('getpaid_get_email_merge_tags', array($this, 'invoice_merge_tags'), 10, 2);
54
+		add_filter('getpaid_invoice_email_recipients', array($this, 'filter_email_recipients'), 10, 2);
55 55
 
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
56
+		foreach ($this->invoice_actions as $hook => $email_type) {
57
+			$this->init_email_type_hook($hook, $email_type);
58 58
 		}
59 59
 	}
60 60
 
@@ -64,25 +64,25 @@  discard block
 block discarded – undo
64 64
 	 * @param string $hook
65 65
 	 * @param string|array $email_type
66 66
 	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
67
+	public function init_email_type_hook($hook, $email_type) {
68 68
 
69
-		$email_type = wpinv_parse_list( $email_type );
69
+		$email_type = wpinv_parse_list($email_type);
70 70
 
71
-		foreach ( $email_type as $type ) {
71
+		foreach ($email_type as $type) {
72 72
 
73
-			$email = new GetPaid_Notification_Email( $type );
73
+			$email = new GetPaid_Notification_Email($type);
74 74
 
75 75
 			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
76
+			if (!$email->is_active()) {
77 77
 				continue;
78 78
 			}
79 79
 
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
80
+			if (method_exists($this, $type)) {
81
+				add_action($hook, array($this, $type), 100, 2);
82 82
 				continue;
83 83
 			}
84 84
 
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type );
85
+			do_action('getpaid_invoice_init_email_type_hook', $type);
86 86
 		}
87 87
 
88 88
 	}
@@ -93,19 +93,19 @@  discard block
 block discarded – undo
93 93
 	 * @param array $merge_tags
94 94
 	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95 95
 	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
96
+	public function invoice_merge_tags($merge_tags, $object) {
97 97
 
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
98
+		if (is_a($object, 'WPInv_Invoice')) {
99 99
 			return array_merge(
100 100
 				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
101
+				$this->get_invoice_merge_tags($object)
102 102
 			);
103 103
 		}
104 104
 
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
105
+		if (is_a($object, 'WPInv_Subscription')) {
106 106
 			return array_merge(
107 107
 				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
108
+				$this->get_invoice_merge_tags($object->get_parent_payment())
109 109
 			);
110 110
 		}
111 111
 
@@ -119,32 +119,32 @@  discard block
 block discarded – undo
119 119
 	 * @param WPInv_Invoice $invoice
120 120
 	 * @return array
121 121
 	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
122
+	public function get_invoice_merge_tags($invoice) {
123 123
 
124 124
 		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
125
+		if (!$invoice->get_id()) {
126 126
 			return array();
127 127
 		}
128 128
 
129 129
 		return array(
130
-			'{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'               => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'       => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ),
138
-			'{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'       => sanitize_text_field( $invoice->get_type() ),
144
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_type() ) ),
145
-			'{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
130
+			'{name}'                => sanitize_text_field($invoice->get_user_full_name()),
131
+			'{full_name}'           => sanitize_text_field($invoice->get_user_full_name()),
132
+			'{first_name}'          => sanitize_text_field($invoice->get_first_name()),
133
+			'{last_name}'           => sanitize_text_field($invoice->get_last_name()),
134
+			'{email}'               => sanitize_email($invoice->get_email()),
135
+			'{invoice_number}'      => sanitize_text_field($invoice->get_number()),
136
+			'{invoice_currency}'    => sanitize_text_field($invoice->get_currency()),
137
+			'{invoice_total}'       => wpinv_price(wpinv_format_amount($invoice->get_total())),
138
+			'{invoice_link}'        => esc_url($invoice->get_view_url()),
139
+			'{invoice_pay_link}'    => esc_url($invoice->get_checkout_payment_url()),
140
+			'{invoice_receipt_link}'=> esc_url($invoice->get_receipt_url()),
141
+			'{invoice_date}'        => getpaid_format_date_value($invoice->get_date_created()),
142
+			'{invoice_due_date}'    => getpaid_format_date_value($invoice->get_due_date(), __('on receipt', 'invoicing')),
143
+			'{invoice_quote}'       => sanitize_text_field($invoice->get_type()),
144
+			'{invoice_label}'       => sanitize_text_field(ucfirst($invoice->get_type())),
145
+			'{invoice_description}' => wp_kses_post($invoice->get_description()),
146
+			'{subscription_name}'   => wp_kses_post($invoice->get_subscription_name()),
147
+			'{is_was}'              => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'),
148 148
 		);
149 149
 
150 150
 	}
@@ -158,35 +158,35 @@  discard block
 block discarded – undo
158 158
 	 * @param string|array $recipients
159 159
 	 * @param array $extra_args Extra template args.
160 160
 	 */
161
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
161
+	public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) {
162 162
 
163
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
163
+		do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email);
164 164
 
165 165
 		$mailer     = new GetPaid_Notification_Email_Sender();
166 166
 		$merge_tags = $email->get_merge_tags();
167 167
 
168 168
 		$result = $mailer->send(
169
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
170
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
171
-			$email->get_content( $merge_tags, $extra_args ),
169
+			apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email),
170
+			$email->add_merge_tags($email->get_subject(), $merge_tags),
171
+			$email->get_content($merge_tags, $extra_args),
172 172
 			$email->get_attachments()
173 173
 		);
174 174
 
175 175
 		// Maybe send a copy to the admin.
176
-		if ( $email->include_admin_bcc() ) {
176
+		if ($email->include_admin_bcc()) {
177 177
 			$mailer->send(
178 178
 				wpinv_get_admin_email(),
179
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
180
-				$email->get_content( $merge_tags ),
179
+				$email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags),
180
+				$email->get_content($merge_tags),
181 181
 				$email->get_attachments()
182 182
 			);
183 183
 		}
184 184
 
185
-		if ( ! $result ) {
186
-			$invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
185
+		if (!$result) {
186
+			$invoice->add_note(sprintf(__('Failed sending %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true);
187 187
 		}
188 188
 
189
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
189
+		do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email);
190 190
 
191 191
 		return $result;
192 192
 	}
@@ -197,14 +197,14 @@  discard block
 block discarded – undo
197 197
 	 * @param array $recipients
198 198
 	 * @param GetPaid_Notification_Email $email
199 199
 	 */
200
-	public function filter_email_recipients( $recipients, $email ) {
200
+	public function filter_email_recipients($recipients, $email) {
201 201
 
202
-		if ( ! $email->is_admin_email() ) {
202
+		if (!$email->is_admin_email()) {
203 203
 			$cc = $email->object->get_email_cc();
204 204
 
205
-			if ( ! empty( $cc ) ) {
206
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
207
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
205
+			if (!empty($cc)) {
206
+				$cc = array_map('sanitize_email', wpinv_parse_list($cc));
207
+				$recipients = array_filter(array_unique(array_merge($recipients, $cc)));
208 208
 			}
209 209
 
210 210
 		}
@@ -218,12 +218,12 @@  discard block
 block discarded – undo
218 218
 	 *
219 219
 	 * @param WPInv_Invoice $invoice
220 220
 	 */
221
-	public function new_invoice( $invoice ) {
221
+	public function new_invoice($invoice) {
222 222
 
223
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
223
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
224 224
 		$recipient = wpinv_get_admin_email();
225 225
 
226
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
226
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
227 227
 
228 228
 	}
229 229
 
@@ -232,12 +232,12 @@  discard block
 block discarded – undo
232 232
 	 *
233 233
 	 * @param WPInv_Invoice $invoice
234 234
 	 */
235
-	public function cancelled_invoice( $invoice ) {
235
+	public function cancelled_invoice($invoice) {
236 236
 
237
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
237
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
238 238
 		$recipient = wpinv_get_admin_email();
239 239
 
240
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
240
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
241 241
 
242 242
 	}
243 243
 
@@ -246,12 +246,12 @@  discard block
 block discarded – undo
246 246
 	 *
247 247
 	 * @param WPInv_Invoice $invoice
248 248
 	 */
249
-	public function failed_invoice( $invoice ) {
249
+	public function failed_invoice($invoice) {
250 250
 
251
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
251
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
252 252
 		$recipient = wpinv_get_admin_email();
253 253
 
254
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
254
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
255 255
 
256 256
 	}
257 257
 
@@ -260,12 +260,12 @@  discard block
 block discarded – undo
260 260
 	 *
261 261
 	 * @param WPInv_Invoice $invoice
262 262
 	 */
263
-	public function onhold_invoice( $invoice ) {
263
+	public function onhold_invoice($invoice) {
264 264
 
265
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
265
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
266 266
 		$recipient = $invoice->get_email();
267 267
 
268
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
268
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
269 269
 
270 270
 	}
271 271
 
@@ -274,12 +274,12 @@  discard block
 block discarded – undo
274 274
 	 *
275 275
 	 * @param WPInv_Invoice $invoice
276 276
 	 */
277
-	public function processing_invoice( $invoice ) {
277
+	public function processing_invoice($invoice) {
278 278
 
279
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
279
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
280 280
 		$recipient = $invoice->get_email();
281 281
 
282
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
282
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
283 283
 
284 284
 	}
285 285
 
@@ -288,17 +288,17 @@  discard block
 block discarded – undo
288 288
 	 *
289 289
 	 * @param WPInv_Invoice $invoice
290 290
 	 */
291
-	public function completed_invoice( $invoice ) {
291
+	public function completed_invoice($invoice) {
292 292
 
293 293
 		// (Maybe) abort if it is a renewal invoice.
294
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
294
+		if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) {
295 295
 			return;
296 296
 		}
297 297
 
298
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
298
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
299 299
 		$recipient = $invoice->get_email();
300 300
 
301
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
301
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
302 302
 
303 303
 	}
304 304
 
@@ -307,12 +307,12 @@  discard block
 block discarded – undo
307 307
 	 *
308 308
 	 * @param WPInv_Invoice $invoice
309 309
 	 */
310
-	public function refunded_invoice( $invoice ) {
310
+	public function refunded_invoice($invoice) {
311 311
 
312
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
312
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
313 313
 		$recipient = $invoice->get_email();
314 314
 
315
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
315
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
316 316
 
317 317
 	}
318 318
 
@@ -321,17 +321,17 @@  discard block
 block discarded – undo
321 321
 	 *
322 322
 	 * @param WPInv_Invoice $invoice
323 323
 	 */
324
-	public function user_invoice( $invoice ) {
324
+	public function user_invoice($invoice) {
325 325
 
326 326
 		// Only send this email for invoices created via the admin page.
327
-		if ( $this->is_payment_form_invoice( $invoice->get_id() ) ) {
327
+		if ($this->is_payment_form_invoice($invoice->get_id())) {
328 328
 			return;
329 329
 		}
330 330
 
331
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
331
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
332 332
 		$recipient = $invoice->get_email();
333 333
 
334
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
334
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
335 335
 
336 336
 	}
337 337
 
@@ -341,8 +341,8 @@  discard block
 block discarded – undo
341 341
 	 * @param int $invoice
342 342
 	 * @return bool
343 343
 	 */
344
-	public function is_payment_form_invoice( $invoice ) {
345
-		return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true );
344
+	public function is_payment_form_invoice($invoice) {
345
+		return empty($_GET['getpaid-admin-action']) && 'payment_form' == get_post_meta($invoice, 'wpinv_created_via', true);
346 346
 	}
347 347
 
348 348
 	/**
@@ -351,12 +351,12 @@  discard block
 block discarded – undo
351 351
 	 * @param WPInv_Invoice $invoice
352 352
 	 * @param string $note
353 353
 	 */
354
-	public function user_note( $invoice, $note ) {
354
+	public function user_note($invoice, $note) {
355 355
 
356
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
356
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
357 357
 		$recipient = $invoice->get_email();
358 358
 
359
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
359
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note));
360 360
 
361 361
 	}
362 362
 
@@ -365,9 +365,9 @@  discard block
 block discarded – undo
365 365
 	 *
366 366
 	 * @param WPInv_Invoice $invoice
367 367
 	 */
368
-	public function force_send_overdue_notice( $invoice ) {
369
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
370
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
368
+	public function force_send_overdue_notice($invoice) {
369
+		$email = new GetPaid_Notification_Email('overdue', $invoice);
370
+		return $this->send_email($invoice, $email, 'overdue', $invoice->get_email());
371 371
 	}
372 372
 
373 373
 	/**
@@ -378,37 +378,37 @@  discard block
 block discarded – undo
378 378
 	public function overdue() {
379 379
 		global $wpdb;
380 380
 
381
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
381
+		$email = new GetPaid_Notification_Email(__FUNCTION__);
382 382
 
383 383
 		// Fetch reminder days.
384
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
384
+		$reminder_days = array_unique(wp_parse_id_list($email->get_option('days')));
385 385
 
386 386
 		// Abort if non is set.
387
-		if ( empty( $reminder_days ) ) {
387
+		if (empty($reminder_days)) {
388 388
 			return;
389 389
 		}
390 390
 
391 391
 		// Retrieve date query.
392
-		$date_query = $this->get_date_query( $reminder_days );
392
+		$date_query = $this->get_date_query($reminder_days);
393 393
 
394 394
 		// Invoices table.
395 395
 		$table = $wpdb->prefix . 'getpaid_invoices';
396 396
 
397 397
 		// Fetch invoices.
398
-		$invoices  = $wpdb->get_col(
398
+		$invoices = $wpdb->get_col(
399 399
 			"SELECT posts.ID FROM $wpdb->posts as posts
400 400
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
401 401
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
402 402
 
403
-		foreach ( $invoices as $invoice ) {
403
+		foreach ($invoices as $invoice) {
404 404
 
405 405
 			// Only send this email for invoices created via the admin page.
406
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
407
-				$invoice       = new WPInv_Invoice( $invoice );
406
+			if (!$this->is_payment_form_invoice($invoice)) {
407
+				$invoice       = new WPInv_Invoice($invoice);
408 408
 				$email->object = $invoice;
409 409
 
410
-				if ( $invoice->needs_payment() ) {
411
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
410
+				if ($invoice->needs_payment()) {
411
+					$this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email());
412 412
 				}
413 413
 
414 414
 			}
@@ -423,14 +423,14 @@  discard block
 block discarded – undo
423 423
 	 * @param array $reminder_days
424 424
 	 * @return string
425 425
 	 */
426
-	public function get_date_query( $reminder_days ) {
426
+	public function get_date_query($reminder_days) {
427 427
 
428 428
 		$date_query = array(
429 429
 			'relation'  => 'OR'
430 430
 		);
431 431
 
432
-		foreach ( $reminder_days as $days ) {
433
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
432
+		foreach ($reminder_days as $days) {
433
+			$date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp'))));
434 434
 
435 435
 			$date_query[] = array(
436 436
 				'year'  => $date['year'],
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
 
441 441
 		}
442 442
 
443
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
443
+		$date_query = new WP_Date_Query($date_query, 'invoices.due_date');
444 444
 
445 445
 		return $date_query->get_sql();
446 446
 
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-manual-gateway.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Manual Payment Gateway class.
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @var array
26 26
 	 */
27
-    protected $supports = array( 'subscription' );
27
+    protected $supports = array('subscription');
28 28
 
29 29
     /**
30 30
 	 * Payment method order.
@@ -39,10 +39,10 @@  discard block
 block discarded – undo
39 39
 	public function __construct() {
40 40
         parent::__construct();
41 41
 
42
-        $this->title        = __( 'Manual Payment', 'invoicing' );
43
-        $this->method_title = __( 'Manual Payment', 'invoicing' );
42
+        $this->title        = __('Manual Payment', 'invoicing');
43
+        $this->method_title = __('Manual Payment', 'invoicing');
44 44
 
45
-        add_filter( 'getpaid_daily_maintenance_should_expire_subscription', array( $this, 'maybe_renew_subscription' ), 10, 2 );
45
+        add_filter('getpaid_daily_maintenance_should_expire_subscription', array($this, 'maybe_renew_subscription'), 10, 2);
46 46
     }
47 47
 
48 48
     /**
@@ -54,16 +54,16 @@  discard block
 block discarded – undo
54 54
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
55 55
 	 * @return array
56 56
 	 */
57
-	public function process_payment( $invoice, $submission_data, $submission ) {
57
+	public function process_payment($invoice, $submission_data, $submission) {
58 58
 
59 59
         // Mark it as paid.
60 60
         $invoice->mark_paid();
61 61
 
62 62
         // (Maybe) activate subscription.
63
-        getpaid_activate_invoice_subscription( $invoice );
63
+        getpaid_activate_invoice_subscription($invoice);
64 64
 
65 65
         // Send to the success page.
66
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
66
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
67 67
 
68 68
     }
69 69
 
@@ -74,15 +74,15 @@  discard block
 block discarded – undo
74 74
 	 * @param bool $should_expire
75 75
      * @param WPInv_Subscription $subscription
76 76
 	 */
77
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
77
+	public function maybe_renew_subscription($should_expire, $subscription) {
78 78
 
79 79
         // Ensure its our subscription && it's active.
80
-        if ( 'manual' != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
80
+        if ('manual' != $subscription->get_gateway() || !$subscription->has_status('active trialling')) {
81 81
             return $should_expire;
82 82
         }
83 83
 
84 84
         // If this is the last renewal, complete the subscription.
85
-        if ( $subscription->is_last_renewal() ) {
85
+        if ($subscription->is_last_renewal()) {
86 86
             $subscription->complete();
87 87
             return false;
88 88
         }
Please login to merge, or discard this patch.