Passed
Push — master ( c3b9b9...2d5ec3 )
by Stiofan
12:21 queued 06:01
created
includes/gateways/worldpay.php 1 patch
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-add_action( 'wpinv_worldpay_cc_form', '__return_false' );
5
+add_action('wpinv_worldpay_cc_form', '__return_false');
6 6
 
7
-function wpinv_process_worldpay_payment( $purchase_data ) {
8
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
9
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
7
+function wpinv_process_worldpay_payment($purchase_data) {
8
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
9
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
10 10
     }
11 11
     
12 12
     // Collect payment data
@@ -24,120 +24,120 @@  discard block
 block discarded – undo
24 24
     );
25 25
 
26 26
     // Record the pending payment
27
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
27
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
28 28
     
29
-    if ( !empty( $invoice ) ) {
29
+    if (!empty($invoice)) {
30 30
         $quantities_enabled = wpinv_item_quantities_enabled();
31 31
         
32
-        $instId     = wpinv_get_option( 'worldpay_instId', false );
32
+        $instId     = wpinv_get_option('worldpay_instId', false);
33 33
         $cartId     = $invoice->get_number();
34
-        $testMode   = wpinv_is_test_mode( 'worldpay' ) ? 100 : 0;
34
+        $testMode   = wpinv_is_test_mode('worldpay') ? 100 : 0;
35 35
         $name       = $invoice->get_user_full_name();
36
-        $address    = wp_strip_all_tags( $invoice->get_address(), true );
36
+        $address    = wp_strip_all_tags($invoice->get_address(), true);
37 37
         $postcode   = $invoice->zip;
38 38
         $tel        = $invoice->phone;
39 39
         $email      = $invoice->get_email();
40 40
         $country    = $invoice->country;
41
-        $amount     = wpinv_sanitize_amount( $invoice->get_total() );
41
+        $amount     = wpinv_sanitize_amount($invoice->get_total());
42 42
         $currency   = wpinv_get_currency();
43 43
         
44 44
         $items      = array();
45
-        foreach ( $invoice->get_cart_details() as $item ) {
45
+        foreach ($invoice->get_cart_details() as $item) {
46 46
             $item_desc  = $item['name'];
47
-            $quantity   = !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1;
48
-            $item_desc .= ' (' . ( $quantities_enabled ? $quantity . 'x ' : '' ) . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')';
47
+            $quantity   = !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1;
48
+            $item_desc .= ' (' . ($quantities_enabled ? $quantity . 'x ' : '') . wpinv_price(wpinv_format_amount($item['item_price'])) . ')';
49 49
             
50 50
             $items[] = $item_desc;
51 51
         }
52 52
         
53
-        $desc = implode( ', ', $items );
54
-        if ( wpinv_use_taxes() && $invoice->get_tax() > 0 ) {
55
-            $desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) );
53
+        $desc = implode(', ', $items);
54
+        if (wpinv_use_taxes() && $invoice->get_tax() > 0) {
55
+            $desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true));
56 56
         }
57 57
         
58 58
         $extra_params                   = array();
59 59
         $extra_params['MC_description'] = $desc;
60
-        $extra_params['MC_callback']    = wpinv_get_ipn_url( 'worldpay' );
60
+        $extra_params['MC_callback']    = wpinv_get_ipn_url('worldpay');
61 61
         $extra_params['MC_key']         = $invoice->get_key();
62 62
         $extra_params['MC_invoice_id']  = $invoice->ID;
63 63
         $extra_params['address1']       = $address;
64 64
         $extra_params['town']           = $invoice->city;
65 65
         $extra_params['region']         = $invoice->state;
66
-        $extra_params['amountString']   = $invoice->get_total( true );
67
-        $extra_params['countryString']  = wpinv_country_name( $invoice->country );
66
+        $extra_params['amountString']   = $invoice->get_total(true);
67
+        $extra_params['countryString']  = wpinv_country_name($invoice->country);
68 68
         $extra_params['compName']       = $invoice->company;
69 69
         
70
-        $extra_params   = apply_filters( 'wpinv_worldpay_form_extra_parameters', $extra_params, $invoice );
70
+        $extra_params   = apply_filters('wpinv_worldpay_form_extra_parameters', $extra_params, $invoice);
71 71
         
72
-        $redirect_text  = __( 'Redirecting to Worldpay site, click on button if not redirected.', 'invoicing' );
73
-        $redirect_text  = apply_filters( 'wpinv_worldpay_redirect_text', $redirect_text, $invoice );
72
+        $redirect_text  = __('Redirecting to Worldpay site, click on button if not redirected.', 'invoicing');
73
+        $redirect_text  = apply_filters('wpinv_worldpay_redirect_text', $redirect_text, $invoice);
74 74
         
75 75
         // Empty the shopping cart
76 76
         wpinv_empty_cart();
77 77
         ?>
78 78
 <div class="wpi-worldpay-form" style="padding:20px;font-family:arial,sans-serif;text-align:center;color:#555">
79
-<?php do_action( 'wpinv_worldpay_form_before', $invoice ); ?>
80
-<h3><?php echo $redirect_text ;?></h3>
79
+<?php do_action('wpinv_worldpay_form_before', $invoice); ?>
80
+<h3><?php echo $redirect_text; ?></h3>
81 81
 <form action="<?php echo wpinv_get_worldpay_redirect(); ?>" name="wpi_worldpay_form" method="POST">
82
-    <input type="hidden" value="<?php echo $amount;?>" name="amount">
83
-    <input type="hidden" value="<?php echo esc_attr( $cartId );?>" name="cartId">
84
-    <input type="hidden" value="<?php echo $currency;?>" name="currency">
85
-    <input type="hidden" value="<?php echo $instId;?>" name="instId">
86
-    <input type="hidden" value="<?php echo $testMode;?>" name="testMode">
87
-    <input type="hidden" value="<?php echo esc_attr( $name );?>" name="name">
88
-    <input type="hidden" value="<?php echo esc_attr( $address );?>" name="address">
89
-    <input type="hidden" value="<?php echo esc_attr( $postcode );?>" name="postcode">
90
-    <input type="hidden" value="<?php echo esc_attr( $tel );?>" name="tel">
91
-    <input type="hidden" value="<?php echo esc_attr( $email );?>" name="email">
92
-    <input type="hidden" value="<?php echo esc_attr( $country );?>" name="country">
93
-    <input type="hidden" value="<?php echo esc_attr( $desc );?>" name="desc">
94
-    <?php foreach ( $extra_params as $param => $value ) { ?>
95
-        <?php if ( !empty( $value !== false ) ) { ?>
96
-    <input type="hidden" value="<?php echo esc_attr( $value );?>" name="<?php echo esc_attr( $param );?>">
82
+    <input type="hidden" value="<?php echo $amount; ?>" name="amount">
83
+    <input type="hidden" value="<?php echo esc_attr($cartId); ?>" name="cartId">
84
+    <input type="hidden" value="<?php echo $currency; ?>" name="currency">
85
+    <input type="hidden" value="<?php echo $instId; ?>" name="instId">
86
+    <input type="hidden" value="<?php echo $testMode; ?>" name="testMode">
87
+    <input type="hidden" value="<?php echo esc_attr($name); ?>" name="name">
88
+    <input type="hidden" value="<?php echo esc_attr($address); ?>" name="address">
89
+    <input type="hidden" value="<?php echo esc_attr($postcode); ?>" name="postcode">
90
+    <input type="hidden" value="<?php echo esc_attr($tel); ?>" name="tel">
91
+    <input type="hidden" value="<?php echo esc_attr($email); ?>" name="email">
92
+    <input type="hidden" value="<?php echo esc_attr($country); ?>" name="country">
93
+    <input type="hidden" value="<?php echo esc_attr($desc); ?>" name="desc">
94
+    <?php foreach ($extra_params as $param => $value) { ?>
95
+        <?php if (!empty($value !== false)) { ?>
96
+    <input type="hidden" value="<?php echo esc_attr($value); ?>" name="<?php echo esc_attr($param); ?>">
97 97
         <?php } ?>
98 98
     <?php } ?>
99
-    <?php do_action( 'wpinv_worldpay_form_parameters', $invoice ); ?>
100
-    <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e( 'Pay by Debit/Credit Card (WorldPay)', 'invoicing' ) ;?>">
99
+    <?php do_action('wpinv_worldpay_form_parameters', $invoice); ?>
100
+    <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e('Pay by Debit/Credit Card (WorldPay)', 'invoicing'); ?>">
101 101
 </form>
102 102
 <script type="text/javascript">document.wpi_worldpay_form.submit();</script>
103
-<?php do_action( 'wpinv_worldpay_form_after', $invoice ); ?>
103
+<?php do_action('wpinv_worldpay_form_after', $invoice); ?>
104 104
 </div>
105 105
         <?php
106 106
     } else {
107
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice );
107
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice);
108 108
         // If errors are present, send the user back to the purchase page so they can be corrected
109
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
109
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
110 110
     }
111 111
 }
112
-add_action( 'wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment' );
112
+add_action('wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment');
113 113
 
114 114
 function wpinv_get_worldpay_redirect() {
115
-    $redirect = wpinv_is_test_mode( 'worldpay' ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
115
+    $redirect = wpinv_is_test_mode('worldpay') ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
116 116
     
117
-    return apply_filters( 'wpinv_worldpay_redirect', $redirect );
117
+    return apply_filters('wpinv_worldpay_redirect', $redirect);
118 118
 }
119 119
 
120 120
 function wpinv_process_worldpay_ipn() {
121
-    $request = wpinv_get_post_data( 'post' );
121
+    $request = wpinv_get_post_data('post');
122 122
     
123
-    if ( !empty( $request['cartId'] ) && !empty( $request['transStatus'] ) && !empty( $request['installation'] ) && isset( $request['testMode'] ) && isset( $request['MC_invoice_id'] ) && isset( $request['MC_key'] ) ) {
123
+    if (!empty($request['cartId']) && !empty($request['transStatus']) && !empty($request['installation']) && isset($request['testMode']) && isset($request['MC_invoice_id']) && isset($request['MC_key'])) {
124 124
         $invoice_id = $request['MC_invoice_id'];
125 125
         
126
-        if ( $invoice_id == wpinv_get_invoice_id_by_key( $request['MC_key'] ) && $invoice = wpinv_get_invoice( $invoice_id ) ) {
127
-            if ( $request['transStatus'] == 'Y' ) {                
128
-                wpinv_update_payment_status( $invoice_id, 'publish' );
129
-                wpinv_set_payment_transaction_id( $invoice_id, $request['transId'] );
130
-                wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Worldpay Transaction ID: %s', 'invoicing' ), $request['transId'] ) );
126
+        if ($invoice_id == wpinv_get_invoice_id_by_key($request['MC_key']) && $invoice = wpinv_get_invoice($invoice_id)) {
127
+            if ($request['transStatus'] == 'Y') {                
128
+                wpinv_update_payment_status($invoice_id, 'publish');
129
+                wpinv_set_payment_transaction_id($invoice_id, $request['transId']);
130
+                wpinv_insert_payment_note($invoice_id, sprintf(__('Worldpay Transaction ID: %s', 'invoicing'), $request['transId']));
131 131
                 return;
132
-            } else if ( $request['transStatus'] == 'C' ) {
133
-                wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
134
-                wpinv_insert_payment_note( $invoice_id, __( 'Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing' ) );
132
+            } else if ($request['transStatus'] == 'C') {
133
+                wpinv_update_payment_status($invoice_id, 'wpi-failed');
134
+                wpinv_insert_payment_note($invoice_id, __('Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing'));
135 135
                 
136
-                wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing' ), json_encode( $request ) ), $invoice_id );
136
+                wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing'), json_encode($request)), $invoice_id);
137 137
                 return;
138 138
             }
139 139
         }
140 140
     }
141 141
     return;
142 142
 }
143
-add_action( 'wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn' );
144 143
\ No newline at end of file
144
+add_action('wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn');
145 145
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-invoice.php 1 patch
Spacing   +776 added lines, -776 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  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_Invoice {
15
-    public $ID  = 0;
15
+    public $ID = 0;
16 16
     public $title;
17 17
     public $post_type;
18 18
     
@@ -65,17 +65,17 @@  discard block
 block discarded – undo
65 65
     public $full_name = '';
66 66
     public $parent_invoice = 0;
67 67
     
68
-    public function __construct( $invoice_id = false ) {
69
-        if( empty( $invoice_id ) ) {
68
+    public function __construct($invoice_id = false) {
69
+        if (empty($invoice_id)) {
70 70
             return false;
71 71
         }
72 72
 
73
-        $this->setup_invoice( $invoice_id );
73
+        $this->setup_invoice($invoice_id);
74 74
     }
75 75
 
76
-    public function get( $key ) {
77
-        if ( method_exists( $this, 'get_' . $key ) ) {
78
-            $value = call_user_func( array( $this, 'get_' . $key ) );
76
+    public function get($key) {
77
+        if (method_exists($this, 'get_' . $key)) {
78
+            $value = call_user_func(array($this, 'get_' . $key));
79 79
         } else {
80 80
             $value = $this->$key;
81 81
         }
@@ -83,52 +83,52 @@  discard block
 block discarded – undo
83 83
         return $value;
84 84
     }
85 85
 
86
-    public function set( $key, $value ) {
87
-        $ignore = array( 'items', 'cart_details', 'fees', '_ID' );
86
+    public function set($key, $value) {
87
+        $ignore = array('items', 'cart_details', 'fees', '_ID');
88 88
 
89
-        if ( $key === 'status' ) {
89
+        if ($key === 'status') {
90 90
             $this->old_status = $this->status;
91 91
         }
92 92
 
93
-        if ( ! in_array( $key, $ignore ) ) {
94
-            $this->pending[ $key ] = $value;
93
+        if (!in_array($key, $ignore)) {
94
+            $this->pending[$key] = $value;
95 95
         }
96 96
 
97
-        if( '_ID' !== $key ) {
97
+        if ('_ID' !== $key) {
98 98
             $this->$key = $value;
99 99
         }
100 100
     }
101 101
 
102
-    public function _isset( $name ) {
103
-        if ( property_exists( $this, $name) ) {
104
-            return false === empty( $this->$name );
102
+    public function _isset($name) {
103
+        if (property_exists($this, $name)) {
104
+            return false === empty($this->$name);
105 105
         } else {
106 106
             return null;
107 107
         }
108 108
     }
109 109
 
110
-    private function setup_invoice( $invoice_id ) {
110
+    private function setup_invoice($invoice_id) {
111 111
         $this->pending = array();
112 112
 
113
-        if ( empty( $invoice_id ) ) {
113
+        if (empty($invoice_id)) {
114 114
             return false;
115 115
         }
116 116
 
117
-        $invoice = get_post( $invoice_id );
117
+        $invoice = get_post($invoice_id);
118 118
 
119
-        if( !$invoice || is_wp_error( $invoice ) ) {
119
+        if (!$invoice || is_wp_error($invoice)) {
120 120
             return false;
121 121
         }
122 122
 
123
-        if( !('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type) ) {
123
+        if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) {
124 124
             return false;
125 125
         }
126 126
 
127
-        do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id );
127
+        do_action('wpinv_pre_setup_invoice', $this, $invoice_id);
128 128
         
129 129
         // Primary Identifier
130
-        $this->ID              = absint( $invoice_id );
131
-        $this->post_type            = $invoice->post_type;
130
+        $this->ID = absint($invoice_id);
131
+        $this->post_type = $invoice->post_type;
132 132
         
133 133
         // We have a payment, get the generic payment_meta item to reduce calls to it
134 134
         $this->payment_meta    = $this->get_meta();
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
         $this->post_status     = $this->status;
140 140
         $this->mode            = $this->setup_mode();
141 141
         $this->parent_invoice  = $invoice->post_parent;
142
-        $this->post_name       = $this->setup_post_name( $invoice );
142
+        $this->post_name       = $this->setup_post_name($invoice);
143 143
         $this->status_nicename = $this->setup_status_nicename();
144 144
 
145 145
         // Items
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
         
162 162
         // User based
163 163
         $this->ip              = $this->setup_ip();
164
-        $this->user_id         = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id();
165
-        $this->email           = get_the_author_meta( 'email', $this->user_id );
164
+        $this->user_id         = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id();
165
+        $this->email           = get_the_author_meta('email', $this->user_id);
166 166
         
167 167
         $this->user_info       = $this->setup_user_info();
168 168
                 
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
         $this->company         = $this->user_info['company'];
172 172
         $this->vat_number      = $this->user_info['vat_number'];
173 173
         $this->vat_rate        = $this->user_info['vat_rate'];
174
-        $this->adddress_confirmed  = $this->user_info['adddress_confirmed'];
174
+        $this->adddress_confirmed = $this->user_info['adddress_confirmed'];
175 175
         $this->address         = $this->user_info['address'];
176 176
         $this->city            = $this->user_info['city'];
177 177
         $this->country         = $this->user_info['country'];
@@ -186,48 +186,48 @@  discard block
 block discarded – undo
186 186
         // Other Identifiers
187 187
         $this->key             = $this->setup_invoice_key();
188 188
         $this->number          = $this->setup_invoice_number();
189
-        $this->title           = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number;
189
+        $this->title           = !empty($invoice->post_title) ? $invoice->post_title : $this->number;
190 190
         
191
-        $this->full_name       = trim( $this->first_name . ' '. $this->last_name );
191
+        $this->full_name       = trim($this->first_name . ' ' . $this->last_name);
192 192
         
193 193
         // Allow extensions to add items to this object via hook
194
-        do_action( 'wpinv_setup_invoice', $this, $invoice_id );
194
+        do_action('wpinv_setup_invoice', $this, $invoice_id);
195 195
 
196 196
         return true;
197 197
     }
198 198
     
199 199
     private function setup_status_nicename() {
200
-        $all_invoice_statuses  = wpinv_get_invoice_statuses();
200
+        $all_invoice_statuses = wpinv_get_invoice_statuses();
201 201
         
202
-        $status = array_key_exists( $this->status, $all_invoice_statuses ) ? $all_invoice_statuses[$this->status] : ucfirst( $this->status );
202
+        $status = array_key_exists($this->status, $all_invoice_statuses) ? $all_invoice_statuses[$this->status] : ucfirst($this->status);
203 203
 
204 204
         return $status;
205 205
     }
206 206
     
207
-    private function setup_post_name( $post = NULL ) {
207
+    private function setup_post_name($post = NULL) {
208 208
         $post_name = '';
209 209
         
210
-        if ( !empty( $post ) ) {
211
-            if( !empty( $post->post_name ) ) {
210
+        if (!empty($post)) {
211
+            if (!empty($post->post_name)) {
212 212
                 $post_name = $post->post_name;
213
-            } else if ( !empty( $post->ID ) && !empty( $post->post_title ) ) {
214
-                $post_name = sanitize_title( $post->post_title );
213
+            } else if (!empty($post->ID) && !empty($post->post_title)) {
214
+                $post_name = sanitize_title($post->post_title);
215 215
                 
216 216
                 global $wpdb;
217
-                $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) );
217
+                $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID));
218 218
             }
219 219
         }
220 220
 
221
-        $this->post_name   = $post_name;
221
+        $this->post_name = $post_name;
222 222
     }
223 223
     
224 224
     private function setup_due_date() {
225
-        $due_date = $this->get_meta( '_wpinv_due_date' );
225
+        $due_date = $this->get_meta('_wpinv_due_date');
226 226
         
227
-        if ( empty( $due_date ) ) {
228
-            $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) );
229
-            $due_date = date_i18n( 'Y-m-d', $overdue_time );
230
-        } else if ( $due_date == 'none' ) {
227
+        if (empty($due_date)) {
228
+            $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days')));
229
+            $due_date = date_i18n('Y-m-d', $overdue_time);
230
+        } else if ($due_date == 'none') {
231 231
             $due_date = '';
232 232
         }
233 233
         
@@ -235,63 +235,63 @@  discard block
 block discarded – undo
235 235
     }
236 236
     
237 237
     private function setup_completed_date() {
238
-        $invoice = get_post( $this->ID );
238
+        $invoice = get_post($this->ID);
239 239
 
240
-        if ( 'pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) {
240
+        if ('pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) {
241 241
             return false; // This invoice was never paid
242 242
         }
243 243
 
244
-        $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date;
244
+        $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date;
245 245
 
246 246
         return $date;
247 247
     }
248 248
     
249 249
     private function setup_cart_details() {
250
-        $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array();
250
+        $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array();
251 251
         return $cart_details;
252 252
     }
253 253
     
254 254
     public function array_convert() {
255
-        return get_object_vars( $this );
255
+        return get_object_vars($this);
256 256
     }
257 257
     
258 258
     private function setup_items() {
259
-        $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array();
259
+        $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array();
260 260
         return $items;
261 261
     }
262 262
     
263 263
     private function setup_fees() {
264
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
264
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
265 265
         return $payment_fees;
266 266
     }
267 267
         
268 268
     private function setup_currency() {
269
-        $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this );
269
+        $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this);
270 270
         return $currency;
271 271
     }
272 272
     
273 273
     private function setup_discount() {
274 274
         //$discount = $this->get_meta( '_wpinv_discount', true );
275
-        $discount = $this->subtotal - ( $this->total - $this->tax - $this->fees_total );
276
-        if ( $discount < 0 ) {
275
+        $discount = $this->subtotal - ($this->total - $this->tax - $this->fees_total);
276
+        if ($discount < 0) {
277 277
             $discount = 0;
278 278
         }
279
-        $discount = wpinv_format_amount( $discount, NULL, true );
279
+        $discount = wpinv_format_amount($discount, NULL, true);
280 280
         
281 281
         return $discount;
282 282
     }
283 283
     
284 284
     private function setup_discount_code() {
285
-        $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true );
285
+        $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true);
286 286
         return $discount_code;
287 287
     }
288 288
     
289 289
     private function setup_tax() {
290
-        $tax = $this->get_meta( '_wpinv_tax', true );
290
+        $tax = $this->get_meta('_wpinv_tax', true);
291 291
 
292 292
         // We don't have tax as it's own meta and no meta was passed
293
-        if ( '' === $tax ) {            
294
-            $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0;
293
+        if ('' === $tax) {            
294
+            $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0;
295 295
         }
296 296
 
297 297
         return $tax;
@@ -305,9 +305,9 @@  discard block
 block discarded – undo
305 305
         $subtotal     = 0;
306 306
         $cart_details = $this->cart_details;
307 307
 
308
-        if ( is_array( $cart_details ) ) {
309
-            foreach ( $cart_details as $item ) {
310
-                if ( isset( $item['subtotal'] ) ) {
308
+        if (is_array($cart_details)) {
309
+            foreach ($cart_details as $item) {
310
+                if (isset($item['subtotal'])) {
311 311
                     $subtotal += $item['subtotal'];
312 312
                 }
313 313
             }
@@ -321,18 +321,18 @@  discard block
 block discarded – undo
321 321
     }
322 322
     
323 323
     private function setup_discounts() {
324
-        $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array();
324
+        $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array();
325 325
         return $discounts;
326 326
     }
327 327
     
328 328
     private function setup_total() {
329
-        $amount = $this->get_meta( '_wpinv_total', true );
329
+        $amount = $this->get_meta('_wpinv_total', true);
330 330
 
331
-        if ( empty( $amount ) && '0.00' != $amount ) {
332
-            $meta   = $this->get_meta( '_wpinv_payment_meta', true );
333
-            $meta   = maybe_unserialize( $meta );
331
+        if (empty($amount) && '0.00' != $amount) {
332
+            $meta   = $this->get_meta('_wpinv_payment_meta', true);
333
+            $meta   = maybe_unserialize($meta);
334 334
 
335
-            if ( isset( $meta['amount'] ) ) {
335
+            if (isset($meta['amount'])) {
336 336
                 $amount = $meta['amount'];
337 337
             }
338 338
         }
@@ -341,13 +341,13 @@  discard block
 block discarded – undo
341 341
     }
342 342
     
343 343
     private function setup_mode() {
344
-        return $this->get_meta( '_wpinv_mode' );
344
+        return $this->get_meta('_wpinv_mode');
345 345
     }
346 346
 
347 347
     private function setup_gateway() {
348
-        $gateway = $this->get_meta( '_wpinv_gateway' );
348
+        $gateway = $this->get_meta('_wpinv_gateway');
349 349
         
350
-        if ( empty( $gateway ) && 'publish' === $this->status ) {
350
+        if (empty($gateway) && 'publish' === $this->status) {
351 351
             $gateway = 'manual';
352 352
         }
353 353
         
@@ -355,23 +355,23 @@  discard block
 block discarded – undo
355 355
     }
356 356
     
357 357
     private function setup_gateway_title() {
358
-        $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway );
358
+        $gateway_title = wpinv_get_gateway_checkout_label($this->gateway);
359 359
         return $gateway_title;
360 360
     }
361 361
 
362 362
     private function setup_transaction_id() {
363
-        $transaction_id = $this->get_meta( '_wpinv_transaction_id' );
363
+        $transaction_id = $this->get_meta('_wpinv_transaction_id');
364 364
 
365
-        if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) {
365
+        if (empty($transaction_id) || (int)$transaction_id === (int)$this->ID) {
366 366
             $gateway        = $this->gateway;
367
-            $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID );
367
+            $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID);
368 368
         }
369 369
 
370 370
         return $transaction_id;
371 371
     }
372 372
 
373 373
     private function setup_ip() {
374
-        $ip = $this->get_meta( '_wpinv_user_ip' );
374
+        $ip = $this->get_meta('_wpinv_user_ip');
375 375
         return $ip;
376 376
     }
377 377
 
@@ -381,62 +381,62 @@  discard block
 block discarded – undo
381 381
     ///}
382 382
         
383 383
     private function setup_first_name() {
384
-        $first_name = $this->get_meta( '_wpinv_first_name' );
384
+        $first_name = $this->get_meta('_wpinv_first_name');
385 385
         return $first_name;
386 386
     }
387 387
     
388 388
     private function setup_last_name() {
389
-        $last_name = $this->get_meta( '_wpinv_last_name' );
389
+        $last_name = $this->get_meta('_wpinv_last_name');
390 390
         return $last_name;
391 391
     }
392 392
     
393 393
     private function setup_company() {
394
-        $company = $this->get_meta( '_wpinv_company' );
394
+        $company = $this->get_meta('_wpinv_company');
395 395
         return $company;
396 396
     }
397 397
     
398 398
     private function setup_vat_number() {
399
-        $vat_number = $this->get_meta( '_wpinv_vat_number' );
399
+        $vat_number = $this->get_meta('_wpinv_vat_number');
400 400
         return $vat_number;
401 401
     }
402 402
     
403 403
     private function setup_vat_rate() {
404
-        $vat_rate = $this->get_meta( '_wpinv_vat_rate' );
404
+        $vat_rate = $this->get_meta('_wpinv_vat_rate');
405 405
         return $vat_rate;
406 406
     }
407 407
     
408 408
     private function setup_adddress_confirmed() {
409
-        $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' );
409
+        $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed');
410 410
         return $adddress_confirmed;
411 411
     }
412 412
     
413 413
     private function setup_phone() {
414
-        $phone = $this->get_meta( '_wpinv_phone' );
414
+        $phone = $this->get_meta('_wpinv_phone');
415 415
         return $phone;
416 416
     }
417 417
     
418 418
     private function setup_address() {
419
-        $address = $this->get_meta( '_wpinv_address', true );
419
+        $address = $this->get_meta('_wpinv_address', true);
420 420
         return $address;
421 421
     }
422 422
     
423 423
     private function setup_city() {
424
-        $city = $this->get_meta( '_wpinv_city', true );
424
+        $city = $this->get_meta('_wpinv_city', true);
425 425
         return $city;
426 426
     }
427 427
     
428 428
     private function setup_country() {
429
-        $country = $this->get_meta( '_wpinv_country', true );
429
+        $country = $this->get_meta('_wpinv_country', true);
430 430
         return $country;
431 431
     }
432 432
     
433 433
     private function setup_state() {
434
-        $state = $this->get_meta( '_wpinv_state', true );
434
+        $state = $this->get_meta('_wpinv_state', true);
435 435
         return $state;
436 436
     }
437 437
     
438 438
     private function setup_zip() {
439
-        $zip = $this->get_meta( '_wpinv_zip', true );
439
+        $zip = $this->get_meta('_wpinv_zip', true);
440 440
         return $zip;
441 441
     }
442 442
 
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
             'user_id'        => $this->user_id,
446 446
             'first_name'     => $this->first_name,
447 447
             'last_name'      => $this->last_name,
448
-            'email'          => get_the_author_meta( 'email', $this->user_id ),
448
+            'email'          => get_the_author_meta('email', $this->user_id),
449 449
             'phone'          => $this->phone,
450 450
             'address'        => $this->address,
451 451
             'city'           => $this->city,
@@ -460,12 +460,12 @@  discard block
 block discarded – undo
460 460
         );
461 461
         
462 462
         $user_info = array();
463
-        if ( isset( $this->payment_meta['user_info'] ) ) {
464
-            $user_info = maybe_unserialize( $this->payment_meta['user_info'] );
463
+        if (isset($this->payment_meta['user_info'])) {
464
+            $user_info = maybe_unserialize($this->payment_meta['user_info']);
465 465
             
466
-            if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) {
466
+            if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) {
467 467
                 $this->user_id = $post->post_author;
468
-                $this->email = get_the_author_meta( 'email', $this->user_id );
468
+                $this->email = get_the_author_meta('email', $this->user_id);
469 469
                 
470 470
                 $user_info['user_id'] = $this->user_id;
471 471
                 $user_info['email'] = $this->email;
@@ -474,13 +474,13 @@  discard block
 block discarded – undo
474 474
             }
475 475
         }
476 476
         
477
-        $user_info    = wp_parse_args( $user_info, $defaults );
477
+        $user_info = wp_parse_args($user_info, $defaults);
478 478
         
479 479
         // Get the user, but only if it's been created
480
-        $user = get_userdata( $this->user_id );
480
+        $user = get_userdata($this->user_id);
481 481
         
482
-        if ( !empty( $user ) && $user->ID > 0 ) {
483
-            if ( empty( $user_info ) ) {
482
+        if (!empty($user) && $user->ID > 0) {
483
+            if (empty($user_info)) {
484 484
                 $user_info = array(
485 485
                     'user_id'    => $user->ID,
486 486
                     'first_name' => $user->first_name,
@@ -489,23 +489,23 @@  discard block
 block discarded – undo
489 489
                     'discount'   => '',
490 490
                 );
491 491
             } else {
492
-                foreach ( $user_info as $key => $value ) {
493
-                    if ( ! empty( $value ) ) {
492
+                foreach ($user_info as $key => $value) {
493
+                    if (!empty($value)) {
494 494
                         continue;
495 495
                     }
496 496
 
497
-                    switch( $key ) {
497
+                    switch ($key) {
498 498
                         case 'user_id':
499
-                            $user_info[ $key ] = $user->ID;
499
+                            $user_info[$key] = $user->ID;
500 500
                             break;
501 501
                         case 'first_name':
502
-                            $user_info[ $key ] = $user->first_name;
502
+                            $user_info[$key] = $user->first_name;
503 503
                             break;
504 504
                         case 'last_name':
505
-                            $user_info[ $key ] = $user->last_name;
505
+                            $user_info[$key] = $user->last_name;
506 506
                             break;
507 507
                         case 'email':
508
-                            $user_info[ $key ] = $user->user_email;
508
+                            $user_info[$key] = $user->user_email;
509 509
                             break;
510 510
                     }
511 511
                 }
@@ -516,16 +516,16 @@  discard block
 block discarded – undo
516 516
     }
517 517
 
518 518
     private function setup_invoice_key() {
519
-        $key = $this->get_meta( '_wpinv_key', true );
519
+        $key = $this->get_meta('_wpinv_key', true);
520 520
         
521 521
         return $key;
522 522
     }
523 523
 
524 524
     private function setup_invoice_number() {
525
-        $number = $this->get_meta( '_wpinv_number', true );
525
+        $number = $this->get_meta('_wpinv_number', true);
526 526
 
527
-        if ( !$number ) {
528
-            $number = wpinv_format_invoice_number( $this->ID );
527
+        if (!$number) {
528
+            $number = wpinv_format_invoice_number($this->ID);
529 529
         }
530 530
 
531 531
         return $number;
@@ -536,18 +536,18 @@  discard block
 block discarded – undo
536 536
 
537 537
         if ($number = $this->get_number()) {
538 538
             $invoice_title = $number;
539
-        } else if ( ! empty( $this->ID ) ) {
540
-            $invoice_title = wpinv_format_invoice_number( $this->ID );
539
+        } else if (!empty($this->ID)) {
540
+            $invoice_title = wpinv_format_invoice_number($this->ID);
541 541
         } else {
542
-            $invoice_title = wpinv_format_invoice_number( 0 );
542
+            $invoice_title = wpinv_format_invoice_number(0);
543 543
         }
544 544
 
545
-        if ( empty( $this->key ) ) {
545
+        if (empty($this->key)) {
546 546
             $this->key = self::generate_key();
547 547
             $this->pending['key'] = $this->key;
548 548
         }
549 549
 
550
-        if ( empty( $this->ip ) ) {
550
+        if (empty($this->ip)) {
551 551
             $this->ip = wpinv_get_ip();
552 552
             $this->pending['ip'] = $this->ip;
553 553
         }
@@ -579,75 +579,75 @@  discard block
 block discarded – undo
579 579
             'fees'         => $this->fees,
580 580
         );
581 581
         
582
-        $post_name      = sanitize_title( $invoice_title );
582
+        $post_name = sanitize_title($invoice_title);
583 583
 
584 584
         $post_data = array(
585 585
                         'post_title'    => $invoice_title,
586 586
                         'post_status'   => $this->status,
587 587
                         'post_author'   => $this->user_id,
588 588
                         'post_type'     => $this->post_type,
589
-                        'post_date'     => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ),
590
-                        'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ),
589
+                        'post_date'     => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'),
590
+                        'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1),
591 591
                         'post_parent'   => $this->parent_invoice,
592 592
                     );
593
-        $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this );
593
+        $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this);
594 594
 
595 595
         // Create a blank invoice
596
-        if ( !empty( $this->ID ) ) {
596
+        if (!empty($this->ID)) {
597 597
             $args['ID']         = $this->ID;
598 598
             $args['post_name']  = $post_name;
599 599
             
600
-            $invoice_id = wp_update_post( $args );
600
+            $invoice_id = wp_update_post($args);
601 601
         } else {
602
-            $invoice_id = wp_insert_post( $args );
602
+            $invoice_id = wp_insert_post($args);
603 603
             
604
-            $post_title = wpinv_format_invoice_number( $invoice_id );
604
+            $post_title = wpinv_format_invoice_number($invoice_id);
605 605
             global $wpdb;
606
-            $wpdb->update( $wpdb->posts, array( 'post_title' => $post_title, 'post_name' => sanitize_title( $post_title ) ), array( 'ID' => $invoice_id ) );
607
-            clean_post_cache( $invoice_id );
606
+            $wpdb->update($wpdb->posts, array('post_title' => $post_title, 'post_name' => sanitize_title($post_title)), array('ID' => $invoice_id));
607
+            clean_post_cache($invoice_id);
608 608
         }
609 609
 
610
-        if ( !empty( $invoice_id ) ) {             
610
+        if (!empty($invoice_id)) {             
611 611
             $this->ID  = $invoice_id;
612 612
             $this->_ID = $invoice_id;
613 613
             
614 614
             ///$this->pending['user_id'] = $this->user_id;
615
-            if ( isset( $this->pending['number'] ) ) {
615
+            if (isset($this->pending['number'])) {
616 616
                 $this->pending['number'] = $post_name;
617 617
             }
618 618
             
619
-            $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data );
620
-            if ( ! empty( $this->payment_meta['fees'] ) ) {
621
-                $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] );
622
-                foreach( $this->fees as $fee ) {
623
-                    $this->increase_fees( $fee['amount'] );
619
+            $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data);
620
+            if (!empty($this->payment_meta['fees'])) {
621
+                $this->fees = array_merge($this->fees, $this->payment_meta['fees']);
622
+                foreach ($this->fees as $fee) {
623
+                    $this->increase_fees($fee['amount']);
624 624
                 }
625 625
             }
626 626
 
627
-            $this->update_meta( '_wpinv_payment_meta', $this->payment_meta );            
627
+            $this->update_meta('_wpinv_payment_meta', $this->payment_meta);            
628 628
             $this->new = true;
629 629
         }
630 630
 
631 631
         return $this->ID;
632 632
     }
633 633
 
634
-    public function save( $setup = false ) {
634
+    public function save($setup = false) {
635 635
         global $wpi_session;
636 636
         
637 637
         $saved = false;
638
-        if ( empty( $this->items ) ) {
638
+        if (empty($this->items)) {
639 639
             return $saved; // Don't save empty invoice.
640 640
         }
641 641
         
642
-        if ( empty( $this->key ) ) {
642
+        if (empty($this->key)) {
643 643
             $this->key = self::generate_key();
644 644
             $this->pending['key'] = $this->key;
645 645
         }
646 646
         
647
-        if ( empty( $this->ID ) ) {
647
+        if (empty($this->ID)) {
648 648
             $invoice_id = $this->insert_invoice();
649 649
 
650
-            if ( false === $invoice_id ) {
650
+            if (false === $invoice_id) {
651 651
                 $saved = false;
652 652
             } else {
653 653
                 $this->ID = $invoice_id;
@@ -655,27 +655,27 @@  discard block
 block discarded – undo
655 655
         }        
656 656
 
657 657
         // If we have something pending, let's save it
658
-        if ( !empty( $this->pending ) ) {
658
+        if (!empty($this->pending)) {
659 659
             $total_increase = 0;
660 660
             $total_decrease = 0;
661 661
 
662
-            foreach ( $this->pending as $key => $value ) {
663
-                switch( $key ) {
662
+            foreach ($this->pending as $key => $value) {
663
+                switch ($key) {
664 664
                     case 'items':
665 665
                         // Update totals for pending items
666
-                        foreach ( $this->pending[ $key ] as $item ) {
667
-                            switch( $item['action'] ) {
666
+                        foreach ($this->pending[$key] as $item) {
667
+                            switch ($item['action']) {
668 668
                                 case 'add':
669 669
                                     $price = $item['price'];
670 670
                                     $taxes = $item['tax'];
671 671
 
672
-                                    if ( 'publish' === $this->status ) {
672
+                                    if ('publish' === $this->status) {
673 673
                                         $total_increase += $price;
674 674
                                     }
675 675
                                     break;
676 676
 
677 677
                                 case 'remove':
678
-                                    if ( 'publish' === $this->status ) {
678
+                                    if ('publish' === $this->status) {
679 679
                                         $total_decrease += $item['price'];
680 680
                                     }
681 681
                                     break;
@@ -683,16 +683,16 @@  discard block
 block discarded – undo
683 683
                         }
684 684
                         break;
685 685
                     case 'fees':
686
-                        if ( 'publish' !== $this->status ) {
686
+                        if ('publish' !== $this->status) {
687 687
                             break;
688 688
                         }
689 689
 
690
-                        if ( empty( $this->pending[ $key ] ) ) {
690
+                        if (empty($this->pending[$key])) {
691 691
                             break;
692 692
                         }
693 693
 
694
-                        foreach ( $this->pending[ $key ] as $fee ) {
695
-                            switch( $fee['action'] ) {
694
+                        foreach ($this->pending[$key] as $fee) {
695
+                            switch ($fee['action']) {
696 696
                                 case 'add':
697 697
                                     $total_increase += $fee['amount'];
698 698
                                     break;
@@ -704,86 +704,86 @@  discard block
 block discarded – undo
704 704
                         }
705 705
                         break;
706 706
                     case 'status':
707
-                        $this->update_status( $this->status );
707
+                        $this->update_status($this->status);
708 708
                         break;
709 709
                     case 'gateway':
710
-                        $this->update_meta( '_wpinv_gateway', $this->gateway );
710
+                        $this->update_meta('_wpinv_gateway', $this->gateway);
711 711
                         break;
712 712
                     case 'mode':
713
-                        $this->update_meta( '_wpinv_mode', $this->mode );
713
+                        $this->update_meta('_wpinv_mode', $this->mode);
714 714
                         break;
715 715
                     case 'transaction_id':
716
-                        $this->update_meta( '_wpinv_transaction_id', $this->transaction_id );
716
+                        $this->update_meta('_wpinv_transaction_id', $this->transaction_id);
717 717
                         break;
718 718
                     case 'ip':
719
-                        $this->update_meta( '_wpinv_user_ip', $this->ip );
719
+                        $this->update_meta('_wpinv_user_ip', $this->ip);
720 720
                         break;
721 721
                     ///case 'user_id':
722 722
                         ///$this->update_meta( '_wpinv_user_id', $this->user_id );
723 723
                         ///$this->user_info['user_id'] = $this->user_id;
724 724
                         ///break;
725 725
                     case 'first_name':
726
-                        $this->update_meta( '_wpinv_first_name', $this->first_name );
726
+                        $this->update_meta('_wpinv_first_name', $this->first_name);
727 727
                         $this->user_info['first_name'] = $this->first_name;
728 728
                         break;
729 729
                     case 'last_name':
730
-                        $this->update_meta( '_wpinv_last_name', $this->last_name );
730
+                        $this->update_meta('_wpinv_last_name', $this->last_name);
731 731
                         $this->user_info['last_name'] = $this->last_name;
732 732
                         break;
733 733
                     case 'phone':
734
-                        $this->update_meta( '_wpinv_phone', $this->phone );
734
+                        $this->update_meta('_wpinv_phone', $this->phone);
735 735
                         $this->user_info['phone'] = $this->phone;
736 736
                         break;
737 737
                     case 'address':
738
-                        $this->update_meta( '_wpinv_address', $this->address );
738
+                        $this->update_meta('_wpinv_address', $this->address);
739 739
                         $this->user_info['address'] = $this->address;
740 740
                         break;
741 741
                     case 'city':
742
-                        $this->update_meta( '_wpinv_city', $this->city );
742
+                        $this->update_meta('_wpinv_city', $this->city);
743 743
                         $this->user_info['city'] = $this->city;
744 744
                         break;
745 745
                     case 'country':
746
-                        $this->update_meta( '_wpinv_country', $this->country );
746
+                        $this->update_meta('_wpinv_country', $this->country);
747 747
                         $this->user_info['country'] = $this->country;
748 748
                         break;
749 749
                     case 'state':
750
-                        $this->update_meta( '_wpinv_state', $this->state );
750
+                        $this->update_meta('_wpinv_state', $this->state);
751 751
                         $this->user_info['state'] = $this->state;
752 752
                         break;
753 753
                     case 'zip':
754
-                        $this->update_meta( '_wpinv_zip', $this->zip );
754
+                        $this->update_meta('_wpinv_zip', $this->zip);
755 755
                         $this->user_info['zip'] = $this->zip;
756 756
                         break;
757 757
                     case 'company':
758
-                        $this->update_meta( '_wpinv_company', $this->company );
758
+                        $this->update_meta('_wpinv_company', $this->company);
759 759
                         $this->user_info['company'] = $this->company;
760 760
                         break;
761 761
                     case 'vat_number':
762
-                        $this->update_meta( '_wpinv_vat_number', $this->vat_number );
762
+                        $this->update_meta('_wpinv_vat_number', $this->vat_number);
763 763
                         $this->user_info['vat_number'] = $this->vat_number;
764 764
                         
765
-                        $vat_info = $wpi_session->get( 'user_vat_data' );
766
-                        if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) {
767
-                            $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false;
768
-                            $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed );
765
+                        $vat_info = $wpi_session->get('user_vat_data');
766
+                        if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) {
767
+                            $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
768
+                            $this->update_meta('_wpinv_adddress_confirmed', (bool)$adddress_confirmed);
769 769
                             $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed;
770 770
                         }
771 771
     
772 772
                         break;
773 773
                     case 'vat_rate':
774
-                        $this->update_meta( '_wpinv_vat_rate', $this->vat_rate );
774
+                        $this->update_meta('_wpinv_vat_rate', $this->vat_rate);
775 775
                         $this->user_info['vat_rate'] = $this->vat_rate;
776 776
                         break;
777 777
                     case 'adddress_confirmed':
778
-                        $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed );
778
+                        $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed);
779 779
                         $this->user_info['adddress_confirmed'] = $this->adddress_confirmed;
780 780
                         break;
781 781
                     
782 782
                     case 'key':
783
-                        $this->update_meta( '_wpinv_key', $this->key );
783
+                        $this->update_meta('_wpinv_key', $this->key);
784 784
                         break;
785 785
                     case 'number':
786
-                        $this->update_meta( '_wpinv_number', $this->number );
786
+                        $this->update_meta('_wpinv_number', $this->number);
787 787
                         break;
788 788
                     case 'date':
789 789
                         $args = array(
@@ -792,34 +792,34 @@  discard block
 block discarded – undo
792 792
                             'edit_date' => true,
793 793
                         );
794 794
 
795
-                        wp_update_post( $args );
795
+                        wp_update_post($args);
796 796
                         break;
797 797
                     case 'due_date':
798
-                        if ( empty( $this->due_date ) ) {
798
+                        if (empty($this->due_date)) {
799 799
                             $this->due_date = 'none';
800 800
                         }
801 801
                         
802
-                        $this->update_meta( '_wpinv_due_date', $this->due_date );
802
+                        $this->update_meta('_wpinv_due_date', $this->due_date);
803 803
                         break;
804 804
                     case 'completed_date':
805
-                        $this->update_meta( '_wpinv_completed_date', $this->completed_date );
805
+                        $this->update_meta('_wpinv_completed_date', $this->completed_date);
806 806
                         break;
807 807
                     case 'discounts':
808
-                        if ( ! is_array( $this->discounts ) ) {
809
-                            $this->discounts = explode( ',', $this->discounts );
808
+                        if (!is_array($this->discounts)) {
809
+                            $this->discounts = explode(',', $this->discounts);
810 810
                         }
811 811
 
812
-                        $this->user_info['discount'] = implode( ',', $this->discounts );
812
+                        $this->user_info['discount'] = implode(',', $this->discounts);
813 813
                         break;
814 814
                         
815 815
                     //case 'tax':
816 816
                         //$this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) );
817 817
                         //break;
818 818
                     case 'discount':
819
-                        $this->update_meta( '_wpinv_discount', wpinv_format_amount( $this->discount, NULL, true ) );
819
+                        $this->update_meta('_wpinv_discount', wpinv_format_amount($this->discount, NULL, true));
820 820
                         break;
821 821
                     case 'discount_code':
822
-                        $this->update_meta( '_wpinv_discount_code', $this->discount_code );
822
+                        $this->update_meta('_wpinv_discount_code', $this->discount_code);
823 823
                         break;
824 824
                     //case 'fees':
825 825
                         //$this->update_meta( '_wpinv_fees', $this->fees );
@@ -829,19 +829,19 @@  discard block
 block discarded – undo
829 829
                             'ID'          => $this->ID,
830 830
                             'post_parent' => $this->parent_invoice,
831 831
                         );
832
-                        wp_update_post( $args );
832
+                        wp_update_post($args);
833 833
                         break;
834 834
                     default:
835
-                        do_action( 'wpinv_save', $this, $key );
835
+                        do_action('wpinv_save', $this, $key);
836 836
                         break;
837 837
                 }
838 838
             }       
839 839
 
840
-            $this->update_meta( '_wpinv_subtotal', wpinv_format_amount( $this->subtotal, NULL, true ) );
841
-            $this->update_meta( '_wpinv_total', wpinv_format_amount( $this->total, NULL, true ) );
842
-            $this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) );
840
+            $this->update_meta('_wpinv_subtotal', wpinv_format_amount($this->subtotal, NULL, true));
841
+            $this->update_meta('_wpinv_total', wpinv_format_amount($this->total, NULL, true));
842
+            $this->update_meta('_wpinv_tax', wpinv_format_amount($this->tax, NULL, true));
843 843
             
844
-            $this->items    = array_values( $this->items );
844
+            $this->items = array_values($this->items);
845 845
             
846 846
             $new_meta = array(
847 847
                 'items'         => $this->items,
@@ -852,12 +852,12 @@  discard block
 block discarded – undo
852 852
             );
853 853
             
854 854
             $meta        = $this->get_meta();
855
-            $merged_meta = array_merge( $meta, $new_meta );
855
+            $merged_meta = array_merge($meta, $new_meta);
856 856
 
857 857
             // Only save the payment meta if it's changed
858
-            if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) {
859
-                $updated     = $this->update_meta( '_wpinv_payment_meta', $merged_meta );
860
-                if ( false !== $updated ) {
858
+            if (md5(serialize($meta)) !== md5(serialize($merged_meta))) {
859
+                $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta);
860
+                if (false !== $updated) {
861 861
                     $saved = true;
862 862
                 }
863 863
             }
@@ -865,15 +865,15 @@  discard block
 block discarded – undo
865 865
             $this->pending = array();
866 866
             $saved         = true;
867 867
         } else {
868
-            $this->update_meta( '_wpinv_subtotal', wpinv_format_amount( $this->subtotal, NULL, true ) );
869
-            $this->update_meta( '_wpinv_total', wpinv_format_amount( $this->total, NULL, true ) );
870
-            $this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) );
868
+            $this->update_meta('_wpinv_subtotal', wpinv_format_amount($this->subtotal, NULL, true));
869
+            $this->update_meta('_wpinv_total', wpinv_format_amount($this->total, NULL, true));
870
+            $this->update_meta('_wpinv_tax', wpinv_format_amount($this->tax, NULL, true));
871 871
         }
872 872
         
873
-        do_action( 'wpinv_invoice_save', $this, $saved );
873
+        do_action('wpinv_invoice_save', $this, $saved);
874 874
 
875
-        if ( true === $saved || $setup ) {
876
-            $this->setup_invoice( $this->ID );
875
+        if (true === $saved || $setup) {
876
+            $this->setup_invoice($this->ID);
877 877
         }
878 878
         
879 879
         $this->refresh_item_ids();
@@ -881,7 +881,7 @@  discard block
 block discarded – undo
881 881
         return $saved;
882 882
     }
883 883
     
884
-    public function add_fee( $args, $global = true ) {
884
+    public function add_fee($args, $global = true) {
885 885
         $default_args = array(
886 886
             'label'       => '',
887 887
             'amount'      => 0,
@@ -891,75 +891,75 @@  discard block
 block discarded – undo
891 891
             'item_id'     => 0,
892 892
         );
893 893
 
894
-        $fee = wp_parse_args( $args, $default_args );
894
+        $fee = wp_parse_args($args, $default_args);
895 895
         
896
-        if ( !empty( $fee['label'] ) ) {
896
+        if (!empty($fee['label'])) {
897 897
             return false;
898 898
         }
899 899
         
900
-        $fee['id']  = sanitize_title( $fee['label'] );
900
+        $fee['id'] = sanitize_title($fee['label']);
901 901
         
902
-        $this->fees[]               = $fee;
902
+        $this->fees[] = $fee;
903 903
         
904 904
         $added_fee               = $fee;
905 905
         $added_fee['action']     = 'add';
906 906
         $this->pending['fees'][] = $added_fee;
907
-        reset( $this->fees );
907
+        reset($this->fees);
908 908
 
909
-        $this->increase_fees( $fee['amount'] );
909
+        $this->increase_fees($fee['amount']);
910 910
         return true;
911 911
     }
912 912
 
913
-    public function remove_fee( $key ) {
913
+    public function remove_fee($key) {
914 914
         $removed = false;
915 915
 
916
-        if ( is_numeric( $key ) ) {
917
-            $removed = $this->remove_fee_by( 'index', $key );
916
+        if (is_numeric($key)) {
917
+            $removed = $this->remove_fee_by('index', $key);
918 918
         }
919 919
 
920 920
         return $removed;
921 921
     }
922 922
 
923
-    public function remove_fee_by( $key, $value, $global = false ) {
924
-        $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array(
923
+    public function remove_fee_by($key, $value, $global = false) {
924
+        $allowed_fee_keys = apply_filters('wpinv_fee_keys', array(
925 925
             'index', 'label', 'amount', 'type',
926
-        ) );
926
+        ));
927 927
 
928
-        if ( ! in_array( $key, $allowed_fee_keys ) ) {
928
+        if (!in_array($key, $allowed_fee_keys)) {
929 929
             return false;
930 930
         }
931 931
 
932 932
         $removed = false;
933
-        if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) {
934
-            $removed_fee             = $this->fees[ $value ];
933
+        if ('index' === $key && array_key_exists($value, $this->fees)) {
934
+            $removed_fee             = $this->fees[$value];
935 935
             $removed_fee['action']   = 'remove';
936 936
             $this->pending['fees'][] = $removed_fee;
937 937
 
938
-            $this->decrease_fees( $removed_fee['amount'] );
938
+            $this->decrease_fees($removed_fee['amount']);
939 939
 
940
-            unset( $this->fees[ $value ] );
940
+            unset($this->fees[$value]);
941 941
             $removed = true;
942
-        } else if ( 'index' !== $key ) {
943
-            foreach ( $this->fees as $index => $fee ) {
944
-                if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) {
942
+        } else if ('index' !== $key) {
943
+            foreach ($this->fees as $index => $fee) {
944
+                if (isset($fee[$key]) && $fee[$key] == $value) {
945 945
                     $removed_fee             = $fee;
946 946
                     $removed_fee['action']   = 'remove';
947 947
                     $this->pending['fees'][] = $removed_fee;
948 948
 
949
-                    $this->decrease_fees( $removed_fee['amount'] );
949
+                    $this->decrease_fees($removed_fee['amount']);
950 950
 
951
-                    unset( $this->fees[ $index ] );
951
+                    unset($this->fees[$index]);
952 952
                     $removed = true;
953 953
 
954
-                    if ( false === $global ) {
954
+                    if (false === $global) {
955 955
                         break;
956 956
                     }
957 957
                 }
958 958
             }
959 959
         }
960 960
 
961
-        if ( true === $removed ) {
962
-            $this->fees = array_values( $this->fees );
961
+        if (true === $removed) {
962
+            $this->fees = array_values($this->fees);
963 963
         }
964 964
 
965 965
         return $removed;
@@ -967,35 +967,35 @@  discard block
 block discarded – undo
967 967
 
968 968
     
969 969
 
970
-    public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
970
+    public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) {
971 971
         // Bail if no note specified
972
-        if( !$note ) {
972
+        if (!$note) {
973 973
             return false;
974 974
         }
975 975
 
976
-        if ( empty( $this->ID ) )
976
+        if (empty($this->ID))
977 977
             return false;
978 978
         
979
-        if ( ( ( is_user_logged_in() && current_user_can( 'manage_options' ) ) || $added_by_user ) && !$system ) {
980
-            $user                 = get_user_by( 'id', get_current_user_id() );
979
+        if (((is_user_logged_in() && current_user_can('manage_options')) || $added_by_user) && !$system) {
980
+            $user                 = get_user_by('id', get_current_user_id());
981 981
             $comment_author       = $user->display_name;
982 982
             $comment_author_email = $user->user_email;
983 983
         } else {
984
-            $comment_author       = __( 'System', 'invoicing' );
985
-            $comment_author_email = strtolower( __( 'System', 'invoicing' ) ) . '@';
986
-            $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com';
987
-            $comment_author_email = sanitize_email( $comment_author_email );
984
+            $comment_author       = __('System', 'invoicing');
985
+            $comment_author_email = strtolower(__('System', 'invoicing')) . '@';
986
+            $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com';
987
+            $comment_author_email = sanitize_email($comment_author_email);
988 988
         }
989 989
 
990
-        do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type );
990
+        do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type);
991 991
 
992
-        $note_id = wp_insert_comment( wp_filter_comment( array(
992
+        $note_id = wp_insert_comment(wp_filter_comment(array(
993 993
             'comment_post_ID'      => $this->ID,
994 994
             'comment_content'      => $note,
995 995
             'comment_agent'        => 'GeoDirectory',
996 996
             'user_id'              => is_admin() ? get_current_user_id() : 0,
997
-            'comment_date'         => current_time( 'mysql' ),
998
-            'comment_date_gmt'     => current_time( 'mysql', 1 ),
997
+            'comment_date'         => current_time('mysql'),
998
+            'comment_date_gmt'     => current_time('mysql', 1),
999 999
             'comment_approved'     => 1,
1000 1000
             'comment_parent'       => 0,
1001 1001
             'comment_author'       => $comment_author,
@@ -1003,53 +1003,53 @@  discard block
 block discarded – undo
1003 1003
             'comment_author_url'   => '',
1004 1004
             'comment_author_email' => $comment_author_email,
1005 1005
             'comment_type'         => 'wpinv_note'
1006
-        ) ) );
1006
+        )));
1007 1007
 
1008
-        do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note );
1008
+        do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note);
1009 1009
         
1010
-        if ( $customer_type ) {
1011
-            add_comment_meta( $note_id, '_wpi_customer_note', 1 );
1010
+        if ($customer_type) {
1011
+            add_comment_meta($note_id, '_wpi_customer_note', 1);
1012 1012
 
1013
-            do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) );
1013
+            do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note));
1014 1014
         }
1015 1015
 
1016 1016
         return $note_id;
1017 1017
     }
1018 1018
 
1019
-    private function increase_subtotal( $amount = 0.00 ) {
1020
-        $amount          = (float) $amount;
1019
+    private function increase_subtotal($amount = 0.00) {
1020
+        $amount          = (float)$amount;
1021 1021
         $this->subtotal += $amount;
1022
-        $this->subtotal  = wpinv_format_amount( $this->subtotal, NULL, true );
1022
+        $this->subtotal  = wpinv_format_amount($this->subtotal, NULL, true);
1023 1023
 
1024 1024
         $this->recalculate_total();
1025 1025
     }
1026 1026
 
1027
-    private function decrease_subtotal( $amount = 0.00 ) {
1028
-        $amount          = (float) $amount;
1027
+    private function decrease_subtotal($amount = 0.00) {
1028
+        $amount          = (float)$amount;
1029 1029
         $this->subtotal -= $amount;
1030
-        $this->subtotal  = wpinv_format_amount( $this->subtotal, NULL, true );
1030
+        $this->subtotal  = wpinv_format_amount($this->subtotal, NULL, true);
1031 1031
 
1032
-        if ( $this->subtotal < 0 ) {
1032
+        if ($this->subtotal < 0) {
1033 1033
             $this->subtotal = 0;
1034 1034
         }
1035 1035
 
1036 1036
         $this->recalculate_total();
1037 1037
     }
1038 1038
 
1039
-    private function increase_fees( $amount = 0.00 ) {
1039
+    private function increase_fees($amount = 0.00) {
1040 1040
         $amount            = (float)$amount;
1041 1041
         $this->fees_total += $amount;
1042
-        $this->fees_total  = wpinv_format_amount( $this->fees_total, NULL, true );
1042
+        $this->fees_total  = wpinv_format_amount($this->fees_total, NULL, true);
1043 1043
 
1044 1044
         $this->recalculate_total();
1045 1045
     }
1046 1046
 
1047
-    private function decrease_fees( $amount = 0.00 ) {
1048
-        $amount            = (float) $amount;
1047
+    private function decrease_fees($amount = 0.00) {
1048
+        $amount            = (float)$amount;
1049 1049
         $this->fees_total -= $amount;
1050
-        $this->fees_total  = wpinv_format_amount( $this->fees_total, NULL, true );
1050
+        $this->fees_total  = wpinv_format_amount($this->fees_total, NULL, true);
1051 1051
 
1052
-        if ( $this->fees_total < 0 ) {
1052
+        if ($this->fees_total < 0) {
1053 1053
             $this->fees_total = 0;
1054 1054
         }
1055 1055
 
@@ -1060,54 +1060,54 @@  discard block
 block discarded – undo
1060 1060
         global $wpi_nosave;
1061 1061
         
1062 1062
         $this->total = $this->subtotal + $this->tax + $this->fees_total;
1063
-        $this->total = wpinv_format_amount( $this->total, NULL, true );
1063
+        $this->total = wpinv_format_amount($this->total, NULL, true);
1064 1064
         
1065
-        do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave );
1065
+        do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave);
1066 1066
     }
1067 1067
     
1068
-    public function increase_tax( $amount = 0.00 ) {
1069
-        $amount       = (float) $amount;
1068
+    public function increase_tax($amount = 0.00) {
1069
+        $amount       = (float)$amount;
1070 1070
         $this->tax   += $amount;
1071 1071
 
1072 1072
         $this->recalculate_total();
1073 1073
     }
1074 1074
 
1075
-    public function decrease_tax( $amount = 0.00 ) {
1076
-        $amount     = (float) $amount;
1075
+    public function decrease_tax($amount = 0.00) {
1076
+        $amount     = (float)$amount;
1077 1077
         $this->tax -= $amount;
1078 1078
 
1079
-        if ( $this->tax < 0 ) {
1079
+        if ($this->tax < 0) {
1080 1080
             $this->tax = 0;
1081 1081
         }
1082 1082
 
1083 1083
         $this->recalculate_total();
1084 1084
     }
1085 1085
 
1086
-    public function update_status( $new_status = false, $note = '', $manual = false ) {
1087
-        $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID );
1086
+    public function update_status($new_status = false, $note = '', $manual = false) {
1087
+        $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID);
1088 1088
         
1089
-        if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses() ) ) ) {
1089
+        if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses()))) {
1090 1090
             return false; // Don't permit status changes that aren't changes
1091 1091
         }
1092 1092
 
1093
-        $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status );
1093
+        $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status);
1094 1094
         $updated = false;
1095 1095
 
1096
-        if ( $do_change ) {
1097
-            do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status );
1096
+        if ($do_change) {
1097
+            do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status);
1098 1098
 
1099 1099
             $update_post_data                   = array();
1100 1100
             $update_post_data['ID']             = $this->ID;
1101 1101
             $update_post_data['post_status']    = $new_status;
1102
-            $update_post_data['edit_date']      = current_time( 'mysql', 0 );
1103
-            $update_post_data['edit_date_gmt']  = current_time( 'mysql', 1 );
1102
+            $update_post_data['edit_date']      = current_time('mysql', 0);
1103
+            $update_post_data['edit_date_gmt']  = current_time('mysql', 1);
1104 1104
             
1105
-            $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID );
1105
+            $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID);
1106 1106
 
1107
-            $updated = wp_update_post( $update_post_data );     
1107
+            $updated = wp_update_post($update_post_data);     
1108 1108
            
1109 1109
             // Process any specific status functions
1110
-            switch( $new_status ) {
1110
+            switch ($new_status) {
1111 1111
                 case 'wpi-refunded':
1112 1112
                     $this->process_refund();
1113 1113
                     break;
@@ -1120,9 +1120,9 @@  discard block
 block discarded – undo
1120 1120
             }
1121 1121
             
1122 1122
             // Status was changed.
1123
-            do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status );
1124
-            do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status );
1125
-            do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status );
1123
+            do_action('wpinv_status_' . $new_status, $this->ID, $old_status);
1124
+            do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status);
1125
+            do_action('wpinv_update_status', $this->ID, $new_status, $old_status);
1126 1126
         }
1127 1127
 
1128 1128
         return $updated;
@@ -1136,72 +1136,72 @@  discard block
 block discarded – undo
1136 1136
         $this->save();
1137 1137
     }
1138 1138
 
1139
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
1140
-        if ( empty( $meta_key ) ) {
1139
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
1140
+        if (empty($meta_key)) {
1141 1141
             return false;
1142 1142
         }
1143 1143
 
1144
-        if ( $meta_key == 'key' || $meta_key == 'date' ) {
1144
+        if ($meta_key == 'key' || $meta_key == 'date') {
1145 1145
             $current_meta = $this->get_meta();
1146
-            $current_meta[ $meta_key ] = $meta_value;
1146
+            $current_meta[$meta_key] = $meta_value;
1147 1147
 
1148 1148
             $meta_key     = '_wpinv_payment_meta';
1149 1149
             $meta_value   = $current_meta;
1150 1150
         }
1151 1151
 
1152
-        $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID );
1152
+        $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID);
1153 1153
         
1154
-        if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) {
1154
+        if ($meta_key == '_wpinv_completed_date' && !empty($meta_value)) {
1155 1155
             $args = array(
1156 1156
                 'ID'                => $this->ID,
1157 1157
                 'post_date'         => $meta_value,
1158 1158
                 'edit_date'         => true,
1159
-                'post_date_gmt'     => get_gmt_from_date( $meta_value ),
1159
+                'post_date_gmt'     => get_gmt_from_date($meta_value),
1160 1160
                 'post_modified'     => $meta_value,
1161
-                'post_modified_gmt' => get_gmt_from_date( $meta_value )
1161
+                'post_modified_gmt' => get_gmt_from_date($meta_value)
1162 1162
             );
1163
-            wp_update_post( $args );
1163
+            wp_update_post($args);
1164 1164
         }
1165 1165
         
1166
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
1166
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
1167 1167
     }
1168 1168
 
1169 1169
     private function process_refund() {
1170 1170
         $process_refund = true;
1171 1171
 
1172 1172
         // If the payment was not in publish, don't decrement stats as they were never incremented
1173
-        if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) {
1173
+        if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) {
1174 1174
             $process_refund = false;
1175 1175
         }
1176 1176
 
1177 1177
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1178
-        $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this );
1178
+        $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this);
1179 1179
 
1180
-        if ( false === $process_refund ) {
1180
+        if (false === $process_refund) {
1181 1181
             return;
1182 1182
         }
1183 1183
 
1184
-        do_action( 'wpinv_pre_refund_invoice', $this );
1184
+        do_action('wpinv_pre_refund_invoice', $this);
1185 1185
         
1186
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this );
1187
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this );
1188
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this );
1186
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this);
1187
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this);
1188
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this);
1189 1189
         
1190
-        do_action( 'wpinv_post_refund_invoice', $this );
1190
+        do_action('wpinv_post_refund_invoice', $this);
1191 1191
     }
1192 1192
 
1193 1193
     private function process_failure() {
1194 1194
         $discounts = $this->discounts;
1195
-        if ( empty( $discounts ) ) {
1195
+        if (empty($discounts)) {
1196 1196
             return;
1197 1197
         }
1198 1198
 
1199
-        if ( ! is_array( $discounts ) ) {
1200
-            $discounts = array_map( 'trim', explode( ',', $discounts ) );
1199
+        if (!is_array($discounts)) {
1200
+            $discounts = array_map('trim', explode(',', $discounts));
1201 1201
         }
1202 1202
 
1203
-        foreach ( $discounts as $discount ) {
1204
-            wpinv_decrease_discount_usage( $discount );
1203
+        foreach ($discounts as $discount) {
1204
+            wpinv_decrease_discount_usage($discount);
1205 1205
         }
1206 1206
     }
1207 1207
     
@@ -1209,92 +1209,92 @@  discard block
 block discarded – undo
1209 1209
         $process_pending = true;
1210 1210
 
1211 1211
         // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented
1212
-        if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'pending' != $this->status ) {
1212
+        if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'pending' != $this->status) {
1213 1213
             $process_pending = false;
1214 1214
         }
1215 1215
 
1216 1216
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1217
-        $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this );
1217
+        $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this);
1218 1218
 
1219
-        if ( false === $process_pending ) {
1219
+        if (false === $process_pending) {
1220 1220
             return;
1221 1221
         }
1222 1222
 
1223
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this );
1224
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this );
1225
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this );
1223
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this);
1224
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this);
1225
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this);
1226 1226
 
1227 1227
         $this->completed_date = '';
1228
-        $this->update_meta( '_wpinv_completed_date', '' );
1228
+        $this->update_meta('_wpinv_completed_date', '');
1229 1229
     }
1230 1230
     
1231 1231
     // get data
1232
-    public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) {
1233
-        $meta = get_post_meta( $this->ID, $meta_key, $single );
1232
+    public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) {
1233
+        $meta = get_post_meta($this->ID, $meta_key, $single);
1234 1234
 
1235
-        if ( $meta_key === '_wpinv_payment_meta' ) {
1235
+        if ($meta_key === '_wpinv_payment_meta') {
1236 1236
 
1237
-            if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is.
1237
+            if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is.
1238 1238
 
1239
-            if ( empty( $meta['key'] ) ) {
1239
+            if (empty($meta['key'])) {
1240 1240
                 $meta['key'] = $this->setup_invoice_key();
1241 1241
             }
1242 1242
 
1243
-            if ( empty( $meta['date'] ) ) {
1244
-                $meta['date'] = get_post_field( 'post_date', $this->ID );
1243
+            if (empty($meta['date'])) {
1244
+                $meta['date'] = get_post_field('post_date', $this->ID);
1245 1245
             }
1246 1246
         }
1247 1247
 
1248
-        $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID );
1248
+        $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID);
1249 1249
 
1250
-        return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key );
1250
+        return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key);
1251 1251
     }
1252 1252
     
1253 1253
     public function get_description() {
1254
-        $post = get_post( $this->ID );
1254
+        $post = get_post($this->ID);
1255 1255
         
1256
-        $description = !empty( $post ) ? $post->post_content : '';
1257
-        return apply_filters( 'wpinv_get_description', $description, $this->ID, $this );
1256
+        $description = !empty($post) ? $post->post_content : '';
1257
+        return apply_filters('wpinv_get_description', $description, $this->ID, $this);
1258 1258
     }
1259 1259
     
1260
-    public function get_status( $nicename = false ) {
1261
-        if ( !$nicename ) {
1260
+    public function get_status($nicename = false) {
1261
+        if (!$nicename) {
1262 1262
             $status = $this->status;
1263 1263
         } else {
1264 1264
             $status = $this->status_nicename;
1265 1265
         }
1266 1266
         
1267
-        return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this );
1267
+        return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this);
1268 1268
     }
1269 1269
     
1270 1270
     public function get_cart_details() {
1271
-        return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this );
1271
+        return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this);
1272 1272
     }
1273 1273
     
1274
-    public function get_subtotal( $currency = false ) {
1275
-        $subtotal = wpinv_format_amount( $this->subtotal, NULL, !$currency );
1274
+    public function get_subtotal($currency = false) {
1275
+        $subtotal = wpinv_format_amount($this->subtotal, NULL, !$currency);
1276 1276
         
1277
-        if ( $currency ) {
1278
-            $subtotal = wpinv_price( $subtotal, $this->get_currency() );
1277
+        if ($currency) {
1278
+            $subtotal = wpinv_price($subtotal, $this->get_currency());
1279 1279
         }
1280 1280
         
1281
-        return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency );
1281
+        return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency);
1282 1282
     }
1283 1283
     
1284
-    public function get_total( $currency = false ) {        
1285
-        if ( $this->is_free_trial() ) {
1286
-            $total = wpinv_format_amount( 0, NULL, !$currency );
1284
+    public function get_total($currency = false) {        
1285
+        if ($this->is_free_trial()) {
1286
+            $total = wpinv_format_amount(0, NULL, !$currency);
1287 1287
         } else {
1288
-            $total = wpinv_format_amount( $this->total, NULL, !$currency );
1288
+            $total = wpinv_format_amount($this->total, NULL, !$currency);
1289 1289
         }
1290
-        if ( $currency ) {
1291
-            $total = wpinv_price( $total, $this->get_currency() );
1290
+        if ($currency) {
1291
+            $total = wpinv_price($total, $this->get_currency());
1292 1292
         }
1293 1293
         
1294
-        return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency );
1294
+        return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency);
1295 1295
     }
1296 1296
     
1297
-    public function get_recurring_details( $field = '', $currency = false ) {        
1297
+    public function get_recurring_details($field = '', $currency = false) {        
1298 1298
         $data                 = array();
1299 1299
         $data['cart_details'] = $this->cart_details;
1300 1300
         $data['subtotal']     = $this->get_subtotal();
@@ -1302,45 +1302,45 @@  discard block
 block discarded – undo
1302 1302
         $data['tax']          = $this->get_tax();
1303 1303
         $data['total']        = $this->get_total();
1304 1304
     
1305
-        if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) {
1305
+        if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) {
1306 1306
             $is_free_trial = $this->is_free_trial();
1307
-            $discounts = $this->get_discounts( true );
1307
+            $discounts = $this->get_discounts(true);
1308 1308
             
1309
-            if ( $is_free_trial || !empty( $discounts ) ) {
1309
+            if ($is_free_trial || !empty($discounts)) {
1310 1310
                 $first_use_only = false;
1311 1311
                 
1312
-                if ( !empty( $discounts ) ) {
1313
-                    foreach ( $discounts as $key => $code ) {
1314
-                        if ( wpinv_discount_is_recurring( $code, true ) ) {
1312
+                if (!empty($discounts)) {
1313
+                    foreach ($discounts as $key => $code) {
1314
+                        if (wpinv_discount_is_recurring($code, true)) {
1315 1315
                             $first_use_only = true;
1316 1316
                             break;
1317 1317
                         }
1318 1318
                     }
1319 1319
                 }
1320 1320
                     
1321
-                if ( !$first_use_only ) {
1322
-                    $data['subtotal'] = wpinv_format_amount( $this->subtotal, NULL, true );
1323
-                    $data['discount'] = wpinv_format_amount( $this->discount, NULL, true );
1324
-                    $data['tax']      = wpinv_format_amount( $this->tax, NULL, true );
1325
-                    $data['total']    = wpinv_format_amount( $this->total, NULL, true );
1321
+                if (!$first_use_only) {
1322
+                    $data['subtotal'] = wpinv_format_amount($this->subtotal, NULL, true);
1323
+                    $data['discount'] = wpinv_format_amount($this->discount, NULL, true);
1324
+                    $data['tax']      = wpinv_format_amount($this->tax, NULL, true);
1325
+                    $data['total']    = wpinv_format_amount($this->total, NULL, true);
1326 1326
                 } else {
1327 1327
                     $cart_subtotal   = 0;
1328 1328
                     $cart_discount   = 0;
1329 1329
                     $cart_tax        = 0;
1330 1330
 
1331
-                    foreach ( $this->cart_details as $key => $item ) {
1332
-                        $item_quantity  = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1333
-                        $item_subtotal  = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1331
+                    foreach ($this->cart_details as $key => $item) {
1332
+                        $item_quantity  = $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1333
+                        $item_subtotal  = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1334 1334
                         $item_discount  = 0;
1335
-                        $item_tax       = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0;
1335
+                        $item_tax       = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float)$item['vat_rate']) : 0;
1336 1336
                         
1337
-                        if ( wpinv_prices_include_tax() ) {
1338
-                            $item_subtotal -= wpinv_format_amount( $item_tax, NULL, true );
1337
+                        if (wpinv_prices_include_tax()) {
1338
+                            $item_subtotal -= wpinv_format_amount($item_tax, NULL, true);
1339 1339
                         }
1340 1340
                         
1341 1341
                         $item_total     = $item_subtotal - $item_discount + $item_tax;
1342 1342
                         // Do not allow totals to go negative
1343
-                        if ( $item_total < 0 ) {
1343
+                        if ($item_total < 0) {
1344 1344
                             $item_total = 0;
1345 1345
                         }
1346 1346
                         
@@ -1348,107 +1348,107 @@  discard block
 block discarded – undo
1348 1348
                         $cart_discount  += (float)($item_discount);
1349 1349
                         $cart_tax       += (float)($item_tax);
1350 1350
                         
1351
-                        $data['cart_details'][$key]['discount']   = wpinv_format_amount( $item_discount, NULL, true );
1352
-                        $data['cart_details'][$key]['tax']        = wpinv_format_amount( $item_tax, NULL, true );
1353
-                        $data['cart_details'][$key]['price']      = wpinv_format_amount( $item_total, NULL, true );
1351
+                        $data['cart_details'][$key]['discount']   = wpinv_format_amount($item_discount, NULL, true);
1352
+                        $data['cart_details'][$key]['tax']        = wpinv_format_amount($item_tax, NULL, true);
1353
+                        $data['cart_details'][$key]['price']      = wpinv_format_amount($item_total, NULL, true);
1354 1354
                     }
1355 1355
                     
1356
-                    $data['subtotal'] = wpinv_format_amount( $cart_subtotal, NULL, true );
1357
-                    $data['discount'] = wpinv_format_amount( $cart_discount, NULL, true );
1358
-                    $data['tax']      = wpinv_format_amount( $cart_tax, NULL, true );
1359
-                    $data['total']    = wpinv_format_amount( ( $data['subtotal'] + $data['tax'] ), NULL, true );
1356
+                    $data['subtotal'] = wpinv_format_amount($cart_subtotal, NULL, true);
1357
+                    $data['discount'] = wpinv_format_amount($cart_discount, NULL, true);
1358
+                    $data['tax']      = wpinv_format_amount($cart_tax, NULL, true);
1359
+                    $data['total']    = wpinv_format_amount(($data['subtotal'] + $data['tax']), NULL, true);
1360 1360
                 }
1361 1361
             }
1362 1362
         }
1363 1363
         
1364
-        $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency );
1364
+        $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency);
1365 1365
 
1366
-        if ( isset( $data[$field] ) ) {
1367
-            return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
1366
+        if (isset($data[$field])) {
1367
+            return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]);
1368 1368
         }
1369 1369
         
1370 1370
         return $data;
1371 1371
     }
1372 1372
     
1373
-    public function get_final_tax( $currency = false ) {        
1374
-        $final_total = wpinv_format_amount( $this->tax, NULL, !$currency );
1375
-        if ( $currency ) {
1376
-            $final_total = wpinv_price( $final_total, $this->get_currency() );
1373
+    public function get_final_tax($currency = false) {        
1374
+        $final_total = wpinv_format_amount($this->tax, NULL, !$currency);
1375
+        if ($currency) {
1376
+            $final_total = wpinv_price($final_total, $this->get_currency());
1377 1377
         }
1378 1378
         
1379
-        return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency );
1379
+        return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency);
1380 1380
     }
1381 1381
     
1382
-    public function get_discounts( $array = false ) {
1382
+    public function get_discounts($array = false) {
1383 1383
         $discounts = $this->discounts;
1384
-        if ( $array && $discounts ) {
1385
-            $discounts = explode( ',', $discounts );
1384
+        if ($array && $discounts) {
1385
+            $discounts = explode(',', $discounts);
1386 1386
         }
1387
-        return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array );
1387
+        return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array);
1388 1388
     }
1389 1389
     
1390
-    public function get_discount( $currency = false, $dash = false ) {
1391
-        if ( !empty( $this->discounts ) ) {
1390
+    public function get_discount($currency = false, $dash = false) {
1391
+        if (!empty($this->discounts)) {
1392 1392
             global $ajax_cart_details;
1393 1393
             $ajax_cart_details = $this->get_cart_details();
1394 1394
 
1395
-            $this->discount = wpinv_get_cart_items_discount_amount( $this->items , $this->discounts );
1395
+            $this->discount = wpinv_get_cart_items_discount_amount($this->items, $this->discounts);
1396 1396
         }
1397
-        $discount   = wpinv_format_amount( $this->discount, NULL, !$currency );
1397
+        $discount   = wpinv_format_amount($this->discount, NULL, !$currency);
1398 1398
         $dash       = $dash && $discount > 0 ? '&ndash;' : '';
1399 1399
         
1400
-        if ( $currency ) {
1401
-            $discount = wpinv_price( $discount, $this->get_currency() );
1400
+        if ($currency) {
1401
+            $discount = wpinv_price($discount, $this->get_currency());
1402 1402
         }
1403 1403
         
1404
-        $discount   = $dash . $discount;
1404
+        $discount = $dash . $discount;
1405 1405
         
1406
-        return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash );
1406
+        return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash);
1407 1407
     }
1408 1408
     
1409 1409
     public function get_discount_code() {
1410 1410
         return $this->discount_code;
1411 1411
     }
1412 1412
     
1413
-    public function get_tax( $currency = false ) {
1414
-        $tax = wpinv_format_amount( $this->tax, NULL, !$currency );
1413
+    public function get_tax($currency = false) {
1414
+        $tax = wpinv_format_amount($this->tax, NULL, !$currency);
1415 1415
         
1416
-        if ( $currency ) {
1417
-            $tax = wpinv_price( $tax, $this->get_currency() );
1416
+        if ($currency) {
1417
+            $tax = wpinv_price($tax, $this->get_currency());
1418 1418
         }
1419 1419
         
1420
-        return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency );
1420
+        return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency);
1421 1421
     }
1422 1422
     
1423
-    public function get_fees( $type = 'all' ) {
1424
-        $fees    = array();
1423
+    public function get_fees($type = 'all') {
1424
+        $fees = array();
1425 1425
 
1426
-        if ( ! empty( $this->fees ) && is_array( $this->fees ) ) {
1427
-            foreach ( $this->fees as $fee ) {
1428
-                if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) {
1426
+        if (!empty($this->fees) && is_array($this->fees)) {
1427
+            foreach ($this->fees as $fee) {
1428
+                if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) {
1429 1429
                     continue;
1430 1430
                 }
1431 1431
 
1432
-                $fee['label'] = stripslashes( $fee['label'] );
1433
-                $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() );
1434
-                $fees[]    = $fee;
1432
+                $fee['label'] = stripslashes($fee['label']);
1433
+                $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency());
1434
+                $fees[] = $fee;
1435 1435
             }
1436 1436
         }
1437 1437
 
1438
-        return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this );
1438
+        return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this);
1439 1439
     }
1440 1440
     
1441
-    public function get_fees_total( $type = 'all' ) {
1442
-        $fees_total = (float) 0.00;
1441
+    public function get_fees_total($type = 'all') {
1442
+        $fees_total = (float)0.00;
1443 1443
 
1444
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
1445
-        if ( ! empty( $payment_fees ) ) {
1446
-            foreach ( $payment_fees as $fee ) {
1447
-                $fees_total += (float) $fee['amount'];
1444
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
1445
+        if (!empty($payment_fees)) {
1446
+            foreach ($payment_fees as $fee) {
1447
+                $fees_total += (float)$fee['amount'];
1448 1448
             }
1449 1449
         }
1450 1450
 
1451
-        return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this );
1451
+        return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this);
1452 1452
         /*
1453 1453
         $fees = $this->get_fees( $type );
1454 1454
 
@@ -1468,116 +1468,116 @@  discard block
 block discarded – undo
1468 1468
     }
1469 1469
 
1470 1470
     public function get_user_id() {
1471
-        return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this );
1471
+        return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this);
1472 1472
     }
1473 1473
     
1474 1474
     public function get_first_name() {
1475
-        return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this );
1475
+        return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this);
1476 1476
     }
1477 1477
     
1478 1478
     public function get_last_name() {
1479
-        return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this );
1479
+        return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this);
1480 1480
     }
1481 1481
     
1482 1482
     public function get_user_full_name() {
1483
-        return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this );
1483
+        return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this);
1484 1484
     }
1485 1485
     
1486 1486
     public function get_user_info() {
1487
-        return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this );
1487
+        return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this);
1488 1488
     }
1489 1489
     
1490 1490
     public function get_email() {
1491
-        return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this );
1491
+        return apply_filters('wpinv_user_email', $this->email, $this->ID, $this);
1492 1492
     }
1493 1493
     
1494 1494
     public function get_address() {
1495
-        return apply_filters( 'wpinv_address', $this->address, $this->ID, $this );
1495
+        return apply_filters('wpinv_address', $this->address, $this->ID, $this);
1496 1496
     }
1497 1497
     
1498 1498
     public function get_phone() {
1499
-        return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this );
1499
+        return apply_filters('wpinv_phone', $this->phone, $this->ID, $this);
1500 1500
     }
1501 1501
     
1502 1502
     public function get_number() {
1503
-        return apply_filters( 'wpinv_number', $this->number, $this->ID, $this );
1503
+        return apply_filters('wpinv_number', $this->number, $this->ID, $this);
1504 1504
     }
1505 1505
     
1506 1506
     public function get_items() {
1507
-        return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this );
1507
+        return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this);
1508 1508
     }
1509 1509
     
1510 1510
     public function get_key() {
1511
-        return apply_filters( 'wpinv_key', $this->key, $this->ID, $this );
1511
+        return apply_filters('wpinv_key', $this->key, $this->ID, $this);
1512 1512
     }
1513 1513
     
1514 1514
     public function get_transaction_id() {
1515
-        return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this );
1515
+        return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this);
1516 1516
     }
1517 1517
     
1518 1518
     public function get_gateway() {
1519
-        return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this );
1519
+        return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this);
1520 1520
     }
1521 1521
     
1522 1522
     public function get_gateway_title() {
1523
-        $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway );
1523
+        $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway);
1524 1524
         
1525
-        return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this );
1525
+        return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this);
1526 1526
     }
1527 1527
     
1528 1528
     public function get_currency() {
1529
-        return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this );
1529
+        return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this);
1530 1530
     }
1531 1531
     
1532 1532
     public function get_created_date() {
1533
-        return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this );
1533
+        return apply_filters('wpinv_created_date', $this->date, $this->ID, $this);
1534 1534
     }
1535 1535
     
1536
-    public function get_due_date( $display = false ) {
1537
-        $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this );
1536
+    public function get_due_date($display = false) {
1537
+        $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this);
1538 1538
         
1539
-        if ( !$display || empty( $due_date ) ) {
1539
+        if (!$display || empty($due_date)) {
1540 1540
             return $due_date;
1541 1541
         }
1542 1542
         
1543
-        return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) );
1543
+        return date_i18n(get_option('date_format'), strtotime($due_date));
1544 1544
     }
1545 1545
     
1546 1546
     public function get_completed_date() {
1547
-        return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this );
1547
+        return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this);
1548 1548
     }
1549 1549
     
1550
-    public function get_invoice_date( $formatted = true ) {
1550
+    public function get_invoice_date($formatted = true) {
1551 1551
         $date_completed = $this->completed_date;
1552 1552
         $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
1553 1553
         
1554
-        if ( $invoice_date == '' ) {
1554
+        if ($invoice_date == '') {
1555 1555
             $date_created   = $this->date;
1556 1556
             $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : '';
1557 1557
         }
1558 1558
         
1559
-        if ( $formatted && $invoice_date ) {
1560
-            $invoice_date   = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );
1559
+        if ($formatted && $invoice_date) {
1560
+            $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date));
1561 1561
         }
1562 1562
 
1563
-        return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this );
1563
+        return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this);
1564 1564
     }
1565 1565
     
1566 1566
     public function get_ip() {
1567
-        return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this );
1567
+        return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this);
1568 1568
     }
1569 1569
         
1570
-    public function has_status( $status ) {
1571
-        return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status );
1570
+    public function has_status($status) {
1571
+        return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status);
1572 1572
     }
1573 1573
     
1574
-    public function add_item( $item_id = 0, $args = array() ) {
1574
+    public function add_item($item_id = 0, $args = array()) {
1575 1575
         global $wpi_current_id, $wpi_item_id;
1576 1576
         
1577
-        $item = new WPInv_Item( $item_id );
1577
+        $item = new WPInv_Item($item_id);
1578 1578
 
1579 1579
         // Bail if this post isn't a item
1580
-        if( !$item || $item->post_type !== 'wpi_item' ) {
1580
+        if (!$item || $item->post_type !== 'wpi_item') {
1581 1581
             return false;
1582 1582
         }
1583 1583
         
@@ -1595,8 +1595,8 @@  discard block
 block discarded – undo
1595 1595
             'fees'      => array()
1596 1596
         );
1597 1597
 
1598
-        $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults );
1599
-        $args['quantity']   = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1;
1598
+        $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults);
1599
+        $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1;
1600 1600
 
1601 1601
         $wpi_current_id         = $this->ID;
1602 1602
         $wpi_item_id            = $item->ID;
@@ -1608,19 +1608,19 @@  discard block
 block discarded – undo
1608 1608
         $found_cart_key         = false;
1609 1609
         
1610 1610
         if ($has_quantities) {
1611
-            $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1611
+            $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1612 1612
             
1613
-            foreach ( $this->items as $key => $cart_item ) {
1614
-                if ( (int)$item_id !== (int)$cart_item['id'] ) {
1613
+            foreach ($this->items as $key => $cart_item) {
1614
+                if ((int)$item_id !== (int)$cart_item['id']) {
1615 1615
                     continue;
1616 1616
                 }
1617 1617
 
1618
-                $this->items[ $key ]['quantity'] += $args['quantity'];
1618
+                $this->items[$key]['quantity'] += $args['quantity'];
1619 1619
                 break;
1620 1620
             }
1621 1621
             
1622
-            foreach ( $this->cart_details as $cart_key => $cart_item ) {
1623
-                if ( $item_id != $cart_item['id'] ) {
1622
+            foreach ($this->cart_details as $cart_key => $cart_item) {
1623
+                if ($item_id != $cart_item['id']) {
1624 1624
                     continue;
1625 1625
                 }
1626 1626
 
@@ -1632,29 +1632,29 @@  discard block
 block discarded – undo
1632 1632
         if ($has_quantities && $found_cart_key !== false) {
1633 1633
             $cart_item          = $this->cart_details[$found_cart_key];
1634 1634
             $item_price         = $cart_item['item_price'];
1635
-            $quantity           = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1636
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1635
+            $quantity           = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1636
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1637 1637
             
1638 1638
             $new_quantity       = $quantity + $args['quantity'];
1639 1639
             $subtotal           = $item_price * $new_quantity;
1640 1640
             
1641 1641
             $args['quantity']   = $new_quantity;
1642
-            $discount           = !empty( $args['discount'] ) ? $args['discount'] : 0;
1643
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1642
+            $discount           = !empty($args['discount']) ? $args['discount'] : 0;
1643
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1644 1644
             
1645 1645
             $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0;
1646 1646
             $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0;
1647 1647
             // The total increase equals the number removed * the item_price
1648
-            $total_increased    = wpinv_format_amount( $item_price, NULL, true );
1648
+            $total_increased    = wpinv_format_amount($item_price, NULL, true);
1649 1649
             
1650
-            if ( wpinv_prices_include_tax() ) {
1651
-                $subtotal -= wpinv_format_amount( $tax, NULL, true );
1650
+            if (wpinv_prices_include_tax()) {
1651
+                $subtotal -= wpinv_format_amount($tax, NULL, true);
1652 1652
             }
1653 1653
 
1654
-            $total              = $subtotal - $discount + $tax;
1654
+            $total = $subtotal - $discount + $tax;
1655 1655
 
1656 1656
             // Do not allow totals to go negative
1657
-            if( $total < 0 ) {
1657
+            if ($total < 0) {
1658 1658
                 $total = 0;
1659 1659
             }
1660 1660
             
@@ -1670,20 +1670,20 @@  discard block
 block discarded – undo
1670 1670
             $this->cart_details[$found_cart_key] = $cart_item;
1671 1671
         } else {
1672 1672
             // Allow overriding the price
1673
-            if( false !== $args['item_price'] ) {
1673
+            if (false !== $args['item_price']) {
1674 1674
                 $item_price = $args['item_price'];
1675 1675
             } else {
1676
-                $item_price = wpinv_get_item_price( $item->ID );
1676
+                $item_price = wpinv_get_item_price($item->ID);
1677 1677
             }
1678 1678
 
1679 1679
             // Sanitizing the price here so we don't have a dozen calls later
1680
-            $item_price = wpinv_sanitize_amount( $item_price );
1681
-            $subtotal   = wpinv_format_amount( $item_price * $args['quantity'], NULL, true );
1680
+            $item_price = wpinv_sanitize_amount($item_price);
1681
+            $subtotal   = wpinv_format_amount($item_price * $args['quantity'], NULL, true);
1682 1682
         
1683
-            $discount   = !empty( $args['discount'] ) ? $args['discount'] : 0;
1684
-            $tax_class  = !empty( $args['vat_class'] ) ? $args['vat_class'] : '';
1685
-            $tax_rate   = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0;
1686
-            $tax        = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1683
+            $discount   = !empty($args['discount']) ? $args['discount'] : 0;
1684
+            $tax_class  = !empty($args['vat_class']) ? $args['vat_class'] : '';
1685
+            $tax_rate   = !empty($args['vat_rate']) ? $args['vat_rate'] : 0;
1686
+            $tax        = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1687 1687
 
1688 1688
             // Setup the items meta item
1689 1689
             $new_item = array(
@@ -1691,28 +1691,28 @@  discard block
 block discarded – undo
1691 1691
                 'quantity' => $args['quantity'],
1692 1692
             );
1693 1693
 
1694
-            $this->items[]  = $new_item;
1694
+            $this->items[] = $new_item;
1695 1695
 
1696
-            if ( wpinv_prices_include_tax() ) {
1697
-                $subtotal -= wpinv_format_amount( $tax, NULL, true );
1696
+            if (wpinv_prices_include_tax()) {
1697
+                $subtotal -= wpinv_format_amount($tax, NULL, true);
1698 1698
             }
1699 1699
 
1700
-            $total      = $subtotal - $discount + $tax;
1700
+            $total = $subtotal - $discount + $tax;
1701 1701
 
1702 1702
             // Do not allow totals to go negative
1703
-            if( $total < 0 ) {
1703
+            if ($total < 0) {
1704 1704
                 $total = 0;
1705 1705
             }
1706 1706
         
1707 1707
             $this->cart_details[] = array(
1708 1708
                 'name'        => !empty($args['name']) ? $args['name'] : $item->get_name(),
1709 1709
                 'id'          => $item->ID,
1710
-                'item_price'  => wpinv_format_amount( $item_price, NULL, true ),
1710
+                'item_price'  => wpinv_format_amount($item_price, NULL, true),
1711 1711
                 'quantity'    => $args['quantity'],
1712 1712
                 'discount'    => $discount,
1713
-                'subtotal'    => wpinv_format_amount( $subtotal, NULL, true ),
1714
-                'tax'         => wpinv_format_amount( $tax, NULL, true ),
1715
-                'price'       => wpinv_format_amount( $total, NULL, true ),
1713
+                'subtotal'    => wpinv_format_amount($subtotal, NULL, true),
1714
+                'tax'         => wpinv_format_amount($tax, NULL, true),
1715
+                'price'       => wpinv_format_amount($total, NULL, true),
1716 1716
                 'vat_rate'    => $tax_rate,
1717 1717
                 'vat_class'   => $tax_class,
1718 1718
                 'meta'        => $args['meta'],
@@ -1722,69 +1722,69 @@  discard block
 block discarded – undo
1722 1722
             $subtotal = $subtotal - $discount;
1723 1723
         }
1724 1724
         
1725
-        $added_item = end( $this->cart_details );
1726
-        $added_item['action']  = 'add';
1725
+        $added_item = end($this->cart_details);
1726
+        $added_item['action'] = 'add';
1727 1727
         
1728 1728
         $this->pending['items'][] = $added_item;
1729 1729
         
1730
-        $this->increase_subtotal( $subtotal );
1731
-        $this->increase_tax( $tax );
1730
+        $this->increase_subtotal($subtotal);
1731
+        $this->increase_tax($tax);
1732 1732
 
1733 1733
         return true;
1734 1734
     }
1735 1735
     
1736
-    public function remove_item( $item_id, $args = array() ) {
1736
+    public function remove_item($item_id, $args = array()) {
1737 1737
         // Set some defaults
1738 1738
         $defaults = array(
1739 1739
             'quantity'   => 1,
1740 1740
             'item_price' => false,
1741 1741
             'cart_index' => false,
1742 1742
         );
1743
-        $args = wp_parse_args( $args, $defaults );
1743
+        $args = wp_parse_args($args, $defaults);
1744 1744
 
1745 1745
         // Bail if this post isn't a item
1746
-        if ( get_post_type( $item_id ) !== 'wpi_item' ) {
1746
+        if (get_post_type($item_id) !== 'wpi_item') {
1747 1747
             return false;
1748 1748
         }
1749 1749
         
1750
-        $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1750
+        $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1751 1751
 
1752
-        foreach ( $this->items as $key => $item ) {
1753
-            if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) {
1752
+        foreach ($this->items as $key => $item) {
1753
+            if (!empty($item['id']) && (int)$item_id !== (int)$item['id']) {
1754 1754
                 continue;
1755 1755
             }
1756 1756
 
1757
-            if ( false !== $args['cart_index'] ) {
1758
-                $cart_index = absint( $args['cart_index'] );
1759
-                $cart_item  = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false;
1757
+            if (false !== $args['cart_index']) {
1758
+                $cart_index = absint($args['cart_index']);
1759
+                $cart_item  = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false;
1760 1760
 
1761
-                if ( ! empty( $cart_item ) ) {
1761
+                if (!empty($cart_item)) {
1762 1762
                     // If the cart index item isn't the same item ID, don't remove it
1763
-                    if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) {
1763
+                    if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) {
1764 1764
                         continue;
1765 1765
                     }
1766 1766
                 }
1767 1767
             }
1768 1768
 
1769
-            $item_quantity = $this->items[ $key ]['quantity'];
1770
-            if ( $item_quantity > $args['quantity'] ) {
1771
-                $this->items[ $key ]['quantity'] -= $args['quantity'];
1769
+            $item_quantity = $this->items[$key]['quantity'];
1770
+            if ($item_quantity > $args['quantity']) {
1771
+                $this->items[$key]['quantity'] -= $args['quantity'];
1772 1772
                 break;
1773 1773
             } else {
1774
-                unset( $this->items[ $key ] );
1774
+                unset($this->items[$key]);
1775 1775
                 break;
1776 1776
             }
1777 1777
         }
1778 1778
 
1779 1779
         $found_cart_key = false;
1780
-        if ( false === $args['cart_index'] ) {
1781
-            foreach ( $this->cart_details as $cart_key => $item ) {
1782
-                if ( $item_id != $item['id'] ) {
1780
+        if (false === $args['cart_index']) {
1781
+            foreach ($this->cart_details as $cart_key => $item) {
1782
+                if ($item_id != $item['id']) {
1783 1783
                     continue;
1784 1784
                 }
1785 1785
 
1786
-                if ( false !== $args['item_price'] ) {
1787
-                    if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) {
1786
+                if (false !== $args['item_price']) {
1787
+                    if (isset($item['item_price']) && (float)$args['item_price'] != (float)$item['item_price']) {
1788 1788
                         continue;
1789 1789
                     }
1790 1790
                 }
@@ -1793,13 +1793,13 @@  discard block
 block discarded – undo
1793 1793
                 break;
1794 1794
             }
1795 1795
         } else {
1796
-            $cart_index = absint( $args['cart_index'] );
1796
+            $cart_index = absint($args['cart_index']);
1797 1797
 
1798
-            if ( ! array_key_exists( $cart_index, $this->cart_details ) ) {
1798
+            if (!array_key_exists($cart_index, $this->cart_details)) {
1799 1799
                 return false; // Invalid cart index passed.
1800 1800
             }
1801 1801
 
1802
-            if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) {
1802
+            if ((int)$this->cart_details[$cart_index]['id'] > 0 && (int)$this->cart_details[$cart_index]['id'] !== (int)$item_id) {
1803 1803
                 return false; // We still need the proper Item ID to be sure.
1804 1804
             }
1805 1805
 
@@ -1807,41 +1807,41 @@  discard block
 block discarded – undo
1807 1807
         }
1808 1808
         
1809 1809
         $cart_item  = $this->cart_details[$found_cart_key];
1810
-        $quantity   = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1810
+        $quantity   = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1811 1811
         
1812
-        if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) {
1812
+        if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) {
1813 1813
             return false; // Invoice must contain at least one item.
1814 1814
         }
1815 1815
         
1816
-        $discounts  = $this->get_discounts();
1816
+        $discounts = $this->get_discounts();
1817 1817
         
1818
-        if ( $quantity > $args['quantity'] ) {
1818
+        if ($quantity > $args['quantity']) {
1819 1819
             $item_price         = $cart_item['item_price'];
1820
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1820
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1821 1821
             
1822
-            $new_quantity       = max( $quantity - $args['quantity'], 1);
1822
+            $new_quantity       = max($quantity - $args['quantity'], 1);
1823 1823
             $subtotal           = $item_price * $new_quantity;
1824 1824
             
1825 1825
             $args['quantity']   = $new_quantity;
1826
-            $discount           = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1827
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1826
+            $discount           = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1827
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1828 1828
             
1829
-            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_format_amount( ( (float)$cart_item['discount'] / $quantity ), NULL, true ) : 0;
1829
+            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_format_amount(((float)$cart_item['discount'] / $quantity), NULL, true) : 0;
1830 1830
             $discount_decrease  = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; 
1831
-            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_format_amount( ( (float)$cart_item['tax'] / $quantity ), NULL, true ) : 0;
1831
+            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_format_amount(((float)$cart_item['tax'] / $quantity), NULL, true) : 0;
1832 1832
             $tax_decrease       = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease;
1833 1833
             
1834 1834
             // The total increase equals the number removed * the item_price
1835
-            $total_decrease     = wpinv_format_amount( $item_price, NULL, true );
1835
+            $total_decrease     = wpinv_format_amount($item_price, NULL, true);
1836 1836
             
1837
-            if ( wpinv_prices_include_tax() ) {
1838
-                $subtotal -= wpinv_format_amount( $tax, NULL, true );
1837
+            if (wpinv_prices_include_tax()) {
1838
+                $subtotal -= wpinv_format_amount($tax, NULL, true);
1839 1839
             }
1840 1840
 
1841
-            $total              = $subtotal - $discount + $tax;
1841
+            $total = $subtotal - $discount + $tax;
1842 1842
 
1843 1843
             // Do not allow totals to go negative
1844
-            if( $total < 0 ) {
1844
+            if ($total < 0) {
1845 1845
                 $total = 0;
1846 1846
             }
1847 1847
             
@@ -1860,16 +1860,16 @@  discard block
 block discarded – undo
1860 1860
             
1861 1861
             $this->cart_details[$found_cart_key] = $cart_item;
1862 1862
             
1863
-            $remove_item = end( $this->cart_details );
1863
+            $remove_item = end($this->cart_details);
1864 1864
         } else {
1865 1865
             $item_price     = $cart_item['item_price'];
1866
-            $discount       = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1867
-            $tax            = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0;
1866
+            $discount       = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1867
+            $tax            = !empty($cart_item['tax']) ? $cart_item['tax'] : 0;
1868 1868
         
1869
-            $subtotal_decrease  = ( $item_price * $quantity ) - $discount;
1869
+            $subtotal_decrease  = ($item_price * $quantity) - $discount;
1870 1870
             $tax_decrease       = $tax;
1871 1871
 
1872
-            unset( $this->cart_details[$found_cart_key] );
1872
+            unset($this->cart_details[$found_cart_key]);
1873 1873
             
1874 1874
             $remove_item             = $args;
1875 1875
             $remove_item['id']       = $item_id;
@@ -1880,8 +1880,8 @@  discard block
 block discarded – undo
1880 1880
         $remove_item['action']      = 'remove';
1881 1881
         $this->pending['items'][]   = $remove_item;
1882 1882
                
1883
-        $this->decrease_subtotal( $subtotal_decrease );
1884
-        $this->decrease_tax( $tax_decrease );
1883
+        $this->decrease_subtotal($subtotal_decrease);
1884
+        $this->decrease_tax($tax_decrease);
1885 1885
         
1886 1886
         return true;
1887 1887
     }
@@ -1889,7 +1889,7 @@  discard block
 block discarded – undo
1889 1889
     public function update_items($temp = false) {
1890 1890
         global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave;
1891 1891
         
1892
-        if ( !empty( $this->cart_details ) ) {
1892
+        if (!empty($this->cart_details)) {
1893 1893
             $wpi_nosave             = $temp;
1894 1894
             $cart_subtotal          = 0;
1895 1895
             $cart_discount          = 0;
@@ -1899,41 +1899,41 @@  discard block
 block discarded – undo
1899 1899
             $_POST['wpinv_country'] = $this->country;
1900 1900
             $_POST['wpinv_state']   = $this->state;
1901 1901
             
1902
-            foreach ( $this->cart_details as $key => $item ) {
1902
+            foreach ($this->cart_details as $key => $item) {
1903 1903
                 $item_price = $item['item_price'];
1904
-                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1905
-                $amount     = wpinv_format_amount( $item_price * $quantity, NULL, true );
1904
+                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1905
+                $amount     = wpinv_format_amount($item_price * $quantity, NULL, true);
1906 1906
                 $subtotal   = $item_price * $quantity;
1907 1907
                 
1908 1908
                 $wpi_current_id         = $this->ID;
1909 1909
                 $wpi_item_id            = $item['id'];
1910 1910
                 
1911
-                $discount   = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() );
1911
+                $discount   = wpinv_get_cart_item_discount_amount($item, $this->get_discounts());
1912 1912
                 
1913
-                $tax_rate   = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id );
1914
-                $tax_class  = $wpinv_euvat->get_item_class( $wpi_item_id );
1915
-                $tax        = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1913
+                $tax_rate   = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id);
1914
+                $tax_class  = $wpinv_euvat->get_item_class($wpi_item_id);
1915
+                $tax        = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1916 1916
 
1917
-                if ( wpinv_prices_include_tax() ) {
1918
-                    $subtotal -= wpinv_format_amount( $tax, NULL, true );
1917
+                if (wpinv_prices_include_tax()) {
1918
+                    $subtotal -= wpinv_format_amount($tax, NULL, true);
1919 1919
                 }
1920 1920
 
1921
-                $total      = $subtotal - $discount + $tax;
1921
+                $total = $subtotal - $discount + $tax;
1922 1922
 
1923 1923
                 // Do not allow totals to go negative
1924
-                if( $total < 0 ) {
1924
+                if ($total < 0) {
1925 1925
                     $total = 0;
1926 1926
                 }
1927 1927
 
1928 1928
                 $cart_details[] = array(
1929 1929
                     'id'          => $item['id'],
1930 1930
                     'name'        => $item['name'],
1931
-                    'item_price'  => wpinv_format_amount( $item_price, NULL, true ),
1931
+                    'item_price'  => wpinv_format_amount($item_price, NULL, true),
1932 1932
                     'quantity'    => $quantity,
1933 1933
                     'discount'    => $discount,
1934
-                    'subtotal'    => wpinv_format_amount( $subtotal, NULL, true ),
1935
-                    'tax'         => wpinv_format_amount( $tax, NULL, true ),
1936
-                    'price'       => wpinv_format_amount( $total, NULL, true ),
1934
+                    'subtotal'    => wpinv_format_amount($subtotal, NULL, true),
1935
+                    'tax'         => wpinv_format_amount($tax, NULL, true),
1936
+                    'price'       => wpinv_format_amount($total, NULL, true),
1937 1937
                     'vat_rate'    => $tax_rate,
1938 1938
                     'vat_class'   => $tax_class,
1939 1939
                     'meta'        => isset($item['meta']) ? $item['meta'] : array(),
@@ -1944,9 +1944,9 @@  discard block
 block discarded – undo
1944 1944
                 $cart_discount  += (float)($discount);
1945 1945
                 $cart_tax       += (float)($tax);
1946 1946
             }
1947
-            $this->subtotal = wpinv_format_amount( $cart_subtotal, NULL, true );
1948
-            $this->tax      = wpinv_format_amount( $cart_tax, NULL, true );
1949
-            $this->discount = wpinv_format_amount( $cart_discount, NULL, true );
1947
+            $this->subtotal = wpinv_format_amount($cart_subtotal, NULL, true);
1948
+            $this->tax      = wpinv_format_amount($cart_tax, NULL, true);
1949
+            $this->discount = wpinv_format_amount($cart_discount, NULL, true);
1950 1950
             
1951 1951
             $this->recalculate_total();
1952 1952
             
@@ -1958,221 +1958,221 @@  discard block
 block discarded – undo
1958 1958
     
1959 1959
     public function recalculate_totals($temp = false) {        
1960 1960
         $this->update_items($temp);
1961
-        $this->save( true );
1961
+        $this->save(true);
1962 1962
         
1963 1963
         return $this;
1964 1964
     }
1965 1965
     
1966 1966
     public function needs_payment() {
1967
-        $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'pending' ), $this );
1967
+        $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('pending'), $this);
1968 1968
 
1969
-        if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() ) ) {
1969
+        if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial())) {
1970 1970
             $needs_payment = true;
1971 1971
         } else {
1972 1972
             $needs_payment = false;
1973 1973
         }
1974 1974
 
1975
-        return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses );
1975
+        return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses);
1976 1976
     }
1977 1977
     
1978
-    public function get_checkout_payment_url( $on_checkout = false, $secret = false ) {
1978
+    public function get_checkout_payment_url($on_checkout = false, $secret = false) {
1979 1979
         $pay_url = wpinv_get_checkout_uri();
1980 1980
 
1981
-        if ( is_ssl() ) {
1982
-            $pay_url = str_replace( 'http:', 'https:', $pay_url );
1981
+        if (is_ssl()) {
1982
+            $pay_url = str_replace('http:', 'https:', $pay_url);
1983 1983
         }
1984 1984
         
1985 1985
         $key = $this->get_key();
1986 1986
 
1987
-        if ( $on_checkout ) {
1988
-            $pay_url = add_query_arg( 'invoice_key', $key, $pay_url );
1987
+        if ($on_checkout) {
1988
+            $pay_url = add_query_arg('invoice_key', $key, $pay_url);
1989 1989
         } else {
1990
-            $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url );
1990
+            $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url);
1991 1991
         }
1992 1992
         
1993
-        if ( $secret ) {
1994
-            $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url );
1993
+        if ($secret) {
1994
+            $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url);
1995 1995
         }
1996 1996
 
1997
-        return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this );
1997
+        return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this);
1998 1998
     }
1999 1999
     
2000
-    public function get_view_url( $secret = false ) {
2001
-        $print_url = get_permalink( $this->ID );
2000
+    public function get_view_url($secret = false) {
2001
+        $print_url = get_permalink($this->ID);
2002 2002
         
2003
-        if ( $secret ) {
2004
-            $print_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $print_url );
2003
+        if ($secret) {
2004
+            $print_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key())), $print_url);
2005 2005
         }
2006 2006
 
2007
-        return apply_filters( 'wpinv_get_view_url', $print_url, $this );
2007
+        return apply_filters('wpinv_get_view_url', $print_url, $this);
2008 2008
     }
2009 2009
     
2010
-    public function generate_key( $string = '' ) {
2011
-        $auth_key  = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
2012
-        return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) );  // Unique key
2010
+    public function generate_key($string = '') {
2011
+        $auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
2012
+        return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key
2013 2013
     }
2014 2014
     
2015 2015
     public function is_recurring() {
2016
-        if ( empty( $this->cart_details ) ) {
2016
+        if (empty($this->cart_details)) {
2017 2017
             return false;
2018 2018
         }
2019 2019
         
2020 2020
         $has_subscription = false;
2021
-        foreach( $this->cart_details as $cart_item ) {
2022
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2021
+        foreach ($this->cart_details as $cart_item) {
2022
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2023 2023
                 $has_subscription = true;
2024 2024
                 break;
2025 2025
             }
2026 2026
         }
2027 2027
         
2028
-        if ( count( $this->cart_details ) > 1 ) {
2028
+        if (count($this->cart_details) > 1) {
2029 2029
             $has_subscription = false;
2030 2030
         }
2031 2031
 
2032
-        return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details );
2032
+        return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details);
2033 2033
     }
2034 2034
     
2035 2035
     public function is_free_trial() {
2036 2036
         $is_free_trial = false;
2037 2037
         
2038
-        if ( $this->is_parent() && $item = $this->get_recurring( true ) ) {
2039
-            if ( !empty( $item ) && $item->has_free_trial() ) {
2038
+        if ($this->is_parent() && $item = $this->get_recurring(true)) {
2039
+            if (!empty($item) && $item->has_free_trial()) {
2040 2040
                 $is_free_trial = true;
2041 2041
             }
2042 2042
         }
2043 2043
 
2044
-        return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details );
2044
+        return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details);
2045 2045
     }
2046 2046
     
2047
-    public function get_recurring( $object = false ) {
2047
+    public function get_recurring($object = false) {
2048 2048
         $item = NULL;
2049 2049
         
2050
-        if ( empty( $this->cart_details ) ) {
2050
+        if (empty($this->cart_details)) {
2051 2051
             return $item;
2052 2052
         }
2053 2053
         
2054
-        foreach( $this->cart_details as $cart_item ) {
2055
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2054
+        foreach ($this->cart_details as $cart_item) {
2055
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2056 2056
                 $item = $cart_item['id'];
2057 2057
                 break;
2058 2058
             }
2059 2059
         }
2060 2060
         
2061
-        if ( $object ) {
2062
-            $item = $item ? new WPInv_Item( $item ) : NULL;
2061
+        if ($object) {
2062
+            $item = $item ? new WPInv_Item($item) : NULL;
2063 2063
             
2064
-            apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this );
2064
+            apply_filters('wpinv_invoice_get_recurring_item', $item, $this);
2065 2065
         }
2066 2066
 
2067
-        return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this );
2067
+        return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this);
2068 2068
     }
2069 2069
     
2070 2070
     public function get_subscription_name() {
2071
-        $item = $this->get_recurring( true );
2071
+        $item = $this->get_recurring(true);
2072 2072
         
2073
-        if ( empty( $item ) ) {
2073
+        if (empty($item)) {
2074 2074
             return NULL;
2075 2075
         }
2076 2076
         
2077
-        if ( !($name = $item->get_name()) ) {
2077
+        if (!($name = $item->get_name())) {
2078 2078
             $name = $item->post_name;
2079 2079
         }
2080 2080
 
2081
-        return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this );
2081
+        return apply_filters('wpinv_invoice_get_subscription_name', $name, $this);
2082 2082
     }
2083 2083
         
2084 2084
     public function get_expiration() {
2085
-        $expiration = $this->get_meta( '_wpinv_subscr_expiration', true );
2085
+        $expiration = $this->get_meta('_wpinv_subscr_expiration', true);
2086 2086
         return $expiration;
2087 2087
     }
2088 2088
     
2089
-    public function get_cancelled_date( $formatted = true ) {
2090
-        $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta( '_wpinv_subscr_cancelled_on', true ) : '';
2089
+    public function get_cancelled_date($formatted = true) {
2090
+        $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta('_wpinv_subscr_cancelled_on', true) : '';
2091 2091
         
2092
-        if ( $formatted && $cancelled_date ) {
2093
-            $cancelled_date = date_i18n( get_option( 'date_format' ), strtotime( $cancelled_date ) );
2092
+        if ($formatted && $cancelled_date) {
2093
+            $cancelled_date = date_i18n(get_option('date_format'), strtotime($cancelled_date));
2094 2094
         }
2095 2095
         
2096 2096
         return $cancelled_date;
2097 2097
     }
2098 2098
     
2099
-    public function get_trial_end_date( $formatted = true ) {
2100
-        if ( !$this->is_free_trial() || !$this->is_paid() ) {
2099
+    public function get_trial_end_date($formatted = true) {
2100
+        if (!$this->is_free_trial() || !$this->is_paid()) {
2101 2101
             return NULL;
2102 2102
         }
2103 2103
         
2104
-        $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta( '_wpinv_subscr_trial_end', true ) : '';
2104
+        $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta('_wpinv_subscr_trial_end', true) : '';
2105 2105
         
2106
-        if ( empty( $trial_end_date ) ) {
2107
-            $trial_start_time = strtotime( $this->get_subscription_start() );
2108
-            $trial_start_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;
2106
+        if (empty($trial_end_date)) {
2107
+            $trial_start_time = strtotime($this->get_subscription_start());
2108
+            $trial_start_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);
2109 2109
             
2110
-            $trial_end_date = date_i18n( 'Y-m-d H:i:s', $trial_start_time );
2110
+            $trial_end_date = date_i18n('Y-m-d H:i:s', $trial_start_time);
2111 2111
         }
2112 2112
         
2113
-        if ( $formatted && $trial_end_date ) {
2114
-            $trial_end_date = date_i18n( get_option( 'date_format' ), strtotime( $trial_end_date ) );
2113
+        if ($formatted && $trial_end_date) {
2114
+            $trial_end_date = date_i18n(get_option('date_format'), strtotime($trial_end_date));
2115 2115
         }
2116 2116
         
2117 2117
         return $trial_end_date;
2118 2118
     }
2119 2119
     
2120
-    public function get_subscription_created( $default = true ) {
2121
-        $created = $this->get_meta( '_wpinv_subscr_created', true );
2120
+    public function get_subscription_created($default = true) {
2121
+        $created = $this->get_meta('_wpinv_subscr_created', true);
2122 2122
         
2123
-        if ( empty( $created ) && $default ) {
2123
+        if (empty($created) && $default) {
2124 2124
             $created = $this->date;
2125 2125
         }
2126 2126
         return $created;
2127 2127
     }
2128 2128
     
2129
-    public function get_subscription_start( $formatted = true ) {
2130
-        if ( !$this->is_paid() ) {
2129
+    public function get_subscription_start($formatted = true) {
2130
+        if (!$this->is_paid()) {
2131 2131
             return '-';
2132 2132
         }
2133
-        $start   = $this->get_subscription_created();
2133
+        $start = $this->get_subscription_created();
2134 2134
         
2135
-        if ( $formatted ) {
2136
-            $date = date_i18n( get_option( 'date_format' ), strtotime( $start ) );
2135
+        if ($formatted) {
2136
+            $date = date_i18n(get_option('date_format'), strtotime($start));
2137 2137
         } else {
2138
-            $date = date_i18n( 'Y-m-d H:i:s', strtotime( $start ) );
2138
+            $date = date_i18n('Y-m-d H:i:s', strtotime($start));
2139 2139
         }
2140 2140
 
2141 2141
         return $date;
2142 2142
     }
2143 2143
     
2144
-    public function get_subscription_end( $formatted = true ) {
2145
-        if ( !$this->is_paid() ) {
2144
+    public function get_subscription_end($formatted = true) {
2145
+        if (!$this->is_paid()) {
2146 2146
             return '-';
2147 2147
         }
2148 2148
         $start          = $this->get_subscription_created();
2149 2149
         $interval       = $this->get_subscription_interval();
2150
-        $period         = $this->get_subscription_period( true );
2150
+        $period         = $this->get_subscription_period(true);
2151 2151
         $bill_times     = (int)$this->get_bill_times();
2152 2152
         
2153
-        if ( $bill_times == 0 ) {
2154
-            return $formatted ? __( 'Until cancelled', 'invoicing' ) : $bill_times;
2153
+        if ($bill_times == 0) {
2154
+            return $formatted ? __('Until cancelled', 'invoicing') : $bill_times;
2155 2155
         }
2156 2156
         
2157
-        $total_period = $start . '+' . ( $interval * $bill_times ) . ' ' . $period;
2157
+        $total_period = $start . '+' . ($interval * $bill_times) . ' ' . $period;
2158 2158
         
2159
-        $end_time = strtotime( $start . '+' . ( $interval * $bill_times ) . ' ' . $period );
2159
+        $end_time = strtotime($start . '+' . ($interval * $bill_times) . ' ' . $period);
2160 2160
         
2161
-        if ( $this->is_free_trial() ) {
2162
-            $end_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;
2161
+        if ($this->is_free_trial()) {
2162
+            $end_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);
2163 2163
         }
2164 2164
         
2165
-        if ( $formatted ) {
2166
-            $date = date_i18n( get_option( 'date_format' ), $end_time );
2165
+        if ($formatted) {
2166
+            $date = date_i18n(get_option('date_format'), $end_time);
2167 2167
         } else {
2168
-            $date = date_i18n( 'Y-m-d H:i:s', $end_time );
2168
+            $date = date_i18n('Y-m-d H:i:s', $end_time);
2169 2169
         }
2170 2170
 
2171 2171
         return $date;
2172 2172
     }
2173 2173
     
2174 2174
     public function get_expiration_time() {
2175
-        return strtotime( $this->get_expiration(), current_time( 'timestamp' ) );
2175
+        return strtotime($this->get_expiration(), current_time('timestamp'));
2176 2176
     }
2177 2177
     
2178 2178
     public function get_original_invoice_id() {        
@@ -2184,125 +2184,125 @@  discard block
 block discarded – undo
2184 2184
         return $subscription_data['bill_times'];
2185 2185
     }
2186 2186
 
2187
-    public function get_child_payments( $self = false ) {
2188
-        $invoices = get_posts( array(
2187
+    public function get_child_payments($self = false) {
2188
+        $invoices = get_posts(array(
2189 2189
             'post_type'         => $this->post_type,
2190 2190
             'post_parent'       => (int)$this->ID,
2191 2191
             'posts_per_page'    => '999',
2192
-            'post_status'       => array( 'publish', 'wpi-processing', 'wpi-renewal' ),
2192
+            'post_status'       => array('publish', 'wpi-processing', 'wpi-renewal'),
2193 2193
             'orderby'           => 'ID',
2194 2194
             'order'             => 'DESC',
2195 2195
             'fields'            => 'ids'
2196
-        ) );
2196
+        ));
2197 2197
         
2198
-        if ( $this->is_free_trial() ) {
2198
+        if ($this->is_free_trial()) {
2199 2199
             $self = false;
2200 2200
         }
2201 2201
         
2202
-        if ( $self && $this->is_paid() ) {
2203
-            if ( !empty( $invoices ) ) {
2202
+        if ($self && $this->is_paid()) {
2203
+            if (!empty($invoices)) {
2204 2204
                 $invoices[] = (int)$this->ID;
2205 2205
             } else {
2206
-                $invoices = array( $this->ID );
2206
+                $invoices = array($this->ID);
2207 2207
             }
2208 2208
             
2209
-            $invoices = array_unique( $invoices );
2209
+            $invoices = array_unique($invoices);
2210 2210
         }
2211 2211
 
2212 2212
         return $invoices;
2213 2213
     }
2214 2214
 
2215
-    public function get_total_payments( $self = true ) {
2216
-        return count( $this->get_child_payments( $self ) );
2215
+    public function get_total_payments($self = true) {
2216
+        return count($this->get_child_payments($self));
2217 2217
     }
2218 2218
     
2219
-    public function get_subscriptions( $limit = -1 ) {
2220
-        $subscriptions = wpinv_get_subscriptions( array( 'parent_invoice_id' => $this->ID, 'numberposts' => $limit ) );
2219
+    public function get_subscriptions($limit = -1) {
2220
+        $subscriptions = wpinv_get_subscriptions(array('parent_invoice_id' => $this->ID, 'numberposts' => $limit));
2221 2221
 
2222 2222
         return $subscriptions;
2223 2223
     }
2224 2224
     
2225 2225
     public function get_subscription_id() {
2226
-        $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true );
2226
+        $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true);
2227 2227
         
2228
-        if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) {
2229
-            $parent_invoice = wpinv_get_invoice( $this->parent_invoice );
2228
+        if (empty($subscription_id) && !empty($this->parent_invoice)) {
2229
+            $parent_invoice = wpinv_get_invoice($this->parent_invoice);
2230 2230
             
2231
-            $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true );
2231
+            $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true);
2232 2232
         }
2233 2233
         
2234 2234
         return $subscription_id;
2235 2235
     }
2236 2236
     
2237 2237
     public function get_subscription_status() {
2238
-        $subscription_status = $this->get_meta( '_wpinv_subscr_status', true );
2238
+        $subscription_status = $this->get_meta('_wpinv_subscr_status', true);
2239 2239
 
2240
-        if ( empty( $subscription_status ) ) {
2240
+        if (empty($subscription_status)) {
2241 2241
             $status = 'pending';
2242 2242
             
2243
-            if ( $this->is_paid() ) {        
2243
+            if ($this->is_paid()) {        
2244 2244
                 $bill_times   = (int)$this->get_bill_times();
2245 2245
                 $times_billed = (int)$this->get_total_payments();
2246
-                $expiration = $this->get_subscription_end( false );
2247
-                $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime( date_i18n( 'Y-m-d', strtotime( $expiration ) ) ) < strtotime( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) ) ? true : false;
2246
+                $expiration = $this->get_subscription_end(false);
2247
+                $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime(date_i18n('Y-m-d', strtotime($expiration))) < strtotime(date_i18n('Y-m-d', current_time('timestamp'))) ? true : false;
2248 2248
                 
2249
-                if ( (int)$bill_times == 0 ) {
2249
+                if ((int)$bill_times == 0) {
2250 2250
                     $status = $expired ? 'expired' : 'active';
2251
-                } else if ( $bill_times > 0 && $times_billed >= $bill_times ) {
2251
+                } else if ($bill_times > 0 && $times_billed >= $bill_times) {
2252 2252
                     $status = 'completed';
2253
-                } else if ( $expired ) {
2253
+                } else if ($expired) {
2254 2254
                     $status = 'expired';
2255
-                } else if ( $bill_times > 0 ) {
2255
+                } else if ($bill_times > 0) {
2256 2256
                     $status = 'active';
2257 2257
                 } else {
2258 2258
                     $status = 'pending';
2259 2259
                 }
2260 2260
             }
2261 2261
             
2262
-            if ( $status && $status != $subscription_status ) {
2262
+            if ($status && $status != $subscription_status) {
2263 2263
                 $subscription_status = $status;
2264 2264
                 
2265
-                $this->update_meta( '_wpinv_subscr_status', $status );
2265
+                $this->update_meta('_wpinv_subscr_status', $status);
2266 2266
             }
2267 2267
         }
2268 2268
         
2269 2269
         return $subscription_status;
2270 2270
     }
2271 2271
     
2272
-    public function get_subscription_status_label( $status = '' ) {
2273
-        $status = !empty( $status ) ? $status : $this->get_subscription_status();
2272
+    public function get_subscription_status_label($status = '') {
2273
+        $status = !empty($status) ? $status : $this->get_subscription_status();
2274 2274
 
2275
-        switch( $status ) {
2275
+        switch ($status) {
2276 2276
             case 'active' :
2277
-                $status_label = __( 'Active', 'invoicing' );
2277
+                $status_label = __('Active', 'invoicing');
2278 2278
                 break;
2279 2279
 
2280 2280
             case 'cancelled' :
2281
-                $status_label = __( 'Cancelled', 'invoicing' );
2281
+                $status_label = __('Cancelled', 'invoicing');
2282 2282
                 break;
2283 2283
                 
2284 2284
             case 'completed' :
2285
-                $status_label = __( 'Completed', 'invoicing' );
2285
+                $status_label = __('Completed', 'invoicing');
2286 2286
                 break;
2287 2287
 
2288 2288
             case 'expired' :
2289
-                $status_label = __( 'Expired', 'invoicing' );
2289
+                $status_label = __('Expired', 'invoicing');
2290 2290
                 break;
2291 2291
 
2292 2292
             case 'pending' :
2293
-                $status_label = __( 'Pending', 'invoicing' );
2293
+                $status_label = __('Pending', 'invoicing');
2294 2294
                 break;
2295 2295
 
2296 2296
             case 'failing' :
2297
-                $status_label = __( 'Failing', 'invoicing' );
2297
+                $status_label = __('Failing', 'invoicing');
2298 2298
                 break;
2299 2299
                 
2300 2300
             case 'stopped' :
2301
-                $status_label = __( 'Stopped', 'invoicing' );
2301
+                $status_label = __('Stopped', 'invoicing');
2302 2302
                 break;
2303 2303
                 
2304 2304
             case 'trialing' :
2305
-                $status_label = __( 'Trialing', 'invoicing' );
2305
+                $status_label = __('Trialing', 'invoicing');
2306 2306
                 break;
2307 2307
 
2308 2308
             default:
@@ -2313,15 +2313,15 @@  discard block
 block discarded – undo
2313 2313
         return $status_label;
2314 2314
     }
2315 2315
     
2316
-    public function get_subscription_period( $full = false ) {
2317
-        $period = $this->get_meta( '_wpinv_subscr_period', true );
2316
+    public function get_subscription_period($full = false) {
2317
+        $period = $this->get_meta('_wpinv_subscr_period', true);
2318 2318
         
2319
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2319
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
2320 2320
             $period = 'D';
2321 2321
         }
2322 2322
         
2323
-        if ( $full ) {
2324
-            switch( $period ) {
2323
+        if ($full) {
2324
+            switch ($period) {
2325 2325
                 case 'D':
2326 2326
                     $period = 'day';
2327 2327
                 break;
@@ -2341,28 +2341,28 @@  discard block
 block discarded – undo
2341 2341
     }
2342 2342
     
2343 2343
     public function get_subscription_interval() {
2344
-        $interval = (int)$this->get_meta( '_wpinv_subscr_interval', true );
2344
+        $interval = (int)$this->get_meta('_wpinv_subscr_interval', true);
2345 2345
         
2346
-        if ( !$interval > 0 ) {
2346
+        if (!$interval > 0) {
2347 2347
             $interval = 1;
2348 2348
         }
2349 2349
         
2350 2350
         return $interval;
2351 2351
     }
2352 2352
     
2353
-    public function get_subscription_trial_period( $full = false ) {
2354
-        if ( !$this->is_free_trial() ) {
2353
+    public function get_subscription_trial_period($full = false) {
2354
+        if (!$this->is_free_trial()) {
2355 2355
             return '';
2356 2356
         }
2357 2357
         
2358
-        $period = $this->get_meta( '_wpinv_subscr_trial_period', true );
2358
+        $period = $this->get_meta('_wpinv_subscr_trial_period', true);
2359 2359
         
2360
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2360
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
2361 2361
             $period = 'D';
2362 2362
         }
2363 2363
         
2364
-        if ( $full ) {
2365
-            switch( $period ) {
2364
+        if ($full) {
2365
+            switch ($period) {
2366 2366
                 case 'D':
2367 2367
                     $period = 'day';
2368 2368
                 break;
@@ -2382,13 +2382,13 @@  discard block
 block discarded – undo
2382 2382
     }
2383 2383
     
2384 2384
     public function get_subscription_trial_interval() {
2385
-        if ( !$this->is_free_trial() ) {
2385
+        if (!$this->is_free_trial()) {
2386 2386
             return 0;
2387 2387
         }
2388 2388
         
2389
-        $interval = (int)$this->get_meta( '_wpinv_subscr_trial_interval', true );
2389
+        $interval = (int)$this->get_meta('_wpinv_subscr_trial_interval', true);
2390 2390
         
2391
-        if ( !$interval > 0 ) {
2391
+        if (!$interval > 0) {
2392 2392
             $interval = 1;
2393 2393
         }
2394 2394
         
@@ -2400,8 +2400,8 @@  discard block
 block discarded – undo
2400 2400
             'status' => 'failing'
2401 2401
         );
2402 2402
 
2403
-        if ( $this->update_subscription( $args ) ) {
2404
-            do_action( 'wpinv_subscription_failing', $this->ID, $this );
2403
+        if ($this->update_subscription($args)) {
2404
+            do_action('wpinv_subscription_failing', $this->ID, $this);
2405 2405
             return true;
2406 2406
         }
2407 2407
 
@@ -2413,8 +2413,8 @@  discard block
 block discarded – undo
2413 2413
             'status' => 'stopped'
2414 2414
         );
2415 2415
 
2416
-        if ( $this->update_subscription( $args ) ) {
2417
-            do_action( 'wpinv_subscription_stopped', $this->ID, $this );
2416
+        if ($this->update_subscription($args)) {
2417
+            do_action('wpinv_subscription_stopped', $this->ID, $this);
2418 2418
             return true;
2419 2419
         }
2420 2420
 
@@ -2426,8 +2426,8 @@  discard block
 block discarded – undo
2426 2426
             'status' => 'active'
2427 2427
         );
2428 2428
 
2429
-        if ( $this->update_subscription( $args ) ) {
2430
-            do_action( 'wpinv_subscription_restarted', $this->ID, $this );
2429
+        if ($this->update_subscription($args)) {
2430
+            do_action('wpinv_subscription_restarted', $this->ID, $this);
2431 2431
             return true;
2432 2432
         }
2433 2433
 
@@ -2439,23 +2439,23 @@  discard block
 block discarded – undo
2439 2439
             'status' => 'cancelled'
2440 2440
         );
2441 2441
 
2442
-        if ( $this->update_subscription( $args ) ) {
2443
-            if ( is_user_logged_in() ) {
2444
-                $userdata = get_userdata( get_current_user_id() );
2442
+        if ($this->update_subscription($args)) {
2443
+            if (is_user_logged_in()) {
2444
+                $userdata = get_userdata(get_current_user_id());
2445 2445
                 $user     = $userdata->user_login;
2446 2446
             } else {
2447
-                $user = __( 'gateway', 'invoicing' );
2447
+                $user = __('gateway', 'invoicing');
2448 2448
             }
2449 2449
             
2450 2450
             $subscription_id = $this->get_subscription_id();
2451
-            if ( !$subscription_id ) {
2451
+            if (!$subscription_id) {
2452 2452
                 $subscription_id = $this->ID;
2453 2453
             }
2454 2454
 
2455
-            $note = sprintf( __( 'Subscription %s has been cancelled by %s', 'invoicing' ), $subscription_id, $user );
2456
-            $this->add_note( $note );
2455
+            $note = sprintf(__('Subscription %s has been cancelled by %s', 'invoicing'), $subscription_id, $user);
2456
+            $this->add_note($note);
2457 2457
 
2458
-            do_action( 'wpinv_subscription_cancelled', $this->ID, $this );
2458
+            do_action('wpinv_subscription_cancelled', $this->ID, $this);
2459 2459
             return true;
2460 2460
         }
2461 2461
 
@@ -2463,11 +2463,11 @@  discard block
 block discarded – undo
2463 2463
     }
2464 2464
 
2465 2465
     public function can_cancel() {
2466
-        return apply_filters( 'wpinv_subscription_can_cancel', false, $this );
2466
+        return apply_filters('wpinv_subscription_can_cancel', false, $this);
2467 2467
     }
2468 2468
     
2469
-    public function add_subscription( $data = array() ) {
2470
-        if ( empty( $this->ID ) ) {
2469
+    public function add_subscription($data = array()) {
2470
+        if (empty($this->ID)) {
2471 2471
             return false;
2472 2472
         }
2473 2473
 
@@ -2486,85 +2486,85 @@  discard block
 block discarded – undo
2486 2486
             'profile_id'        => '',
2487 2487
         );
2488 2488
 
2489
-        $args = wp_parse_args( $data, $defaults );
2489
+        $args = wp_parse_args($data, $defaults);
2490 2490
 
2491
-        if ( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
2492
-            if ( 'active' == $args['status'] || $args['status'] == 'trialing' ) {
2491
+        if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
2492
+            if ('active' == $args['status'] || $args['status'] == 'trialing') {
2493 2493
                 $args['status'] = 'expired';
2494 2494
             }
2495 2495
         }
2496 2496
 
2497
-        do_action( 'wpinv_subscription_pre_create', $args, $data, $this );
2497
+        do_action('wpinv_subscription_pre_create', $args, $data, $this);
2498 2498
         
2499
-        if ( !empty( $args ) ) {
2500
-            foreach ( $args as $key => $value ) {
2501
-                $this->update_meta( '_wpinv_subscr_' . $key, $value );
2499
+        if (!empty($args)) {
2500
+            foreach ($args as $key => $value) {
2501
+                $this->update_meta('_wpinv_subscr_' . $key, $value);
2502 2502
             }
2503 2503
         }
2504 2504
 
2505
-        do_action( 'wpinv_subscription_post_create', $args, $data, $this );
2505
+        do_action('wpinv_subscription_post_create', $args, $data, $this);
2506 2506
 
2507 2507
         return true;
2508 2508
     }
2509 2509
     
2510
-    public function update_subscription( $args = array() ) {
2511
-        if ( empty( $this->ID ) ) {
2510
+    public function update_subscription($args = array()) {
2511
+        if (empty($this->ID)) {
2512 2512
             return false;
2513 2513
         }
2514 2514
 
2515
-        if ( !empty( $args['expiration'] ) && $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
2516
-            if ( !isset( $args['status'] ) || ( isset( $args['status'] ) && ( 'active' == $args['status'] || $args['status'] == 'trialing' ) ) ) {
2515
+        if (!empty($args['expiration']) && $args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
2516
+            if (!isset($args['status']) || (isset($args['status']) && ('active' == $args['status'] || $args['status'] == 'trialing'))) {
2517 2517
                 $args['status'] = 'expired';
2518 2518
             }
2519 2519
         }
2520 2520
 
2521
-        if ( isset( $args['status'] ) && $args['status'] == 'cancelled' && empty( $args['cancelled_on'] ) ) {
2522
-            $args['cancelled_on'] = date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) );
2521
+        if (isset($args['status']) && $args['status'] == 'cancelled' && empty($args['cancelled_on'])) {
2522
+            $args['cancelled_on'] = date_i18n('Y-m-d H:i:s', current_time('timestamp'));
2523 2523
         }
2524 2524
 
2525
-        do_action( 'wpinv_subscription_pre_update', $args, $this );
2525
+        do_action('wpinv_subscription_pre_update', $args, $this);
2526 2526
         
2527
-        if ( !empty( $args ) ) {
2528
-            foreach ( $args as $key => $value ) {
2529
-                $this->update_meta( '_wpinv_subscr_' . $key, $value );
2527
+        if (!empty($args)) {
2528
+            foreach ($args as $key => $value) {
2529
+                $this->update_meta('_wpinv_subscr_' . $key, $value);
2530 2530
             }
2531 2531
         }
2532 2532
 
2533
-        do_action( 'wpinv_subscription_post_update', $args, $this );
2533
+        do_action('wpinv_subscription_post_update', $args, $this);
2534 2534
 
2535 2535
         return true;
2536 2536
     }
2537 2537
     
2538 2538
     public function renew_subscription() {
2539 2539
         $parent_invoice = $this->get_parent_payment();
2540
-        $parent_invoice = empty( $parent_invoice ) ? $this : $parent_invoice;
2540
+        $parent_invoice = empty($parent_invoice) ? $this : $parent_invoice;
2541 2541
         
2542
-        $current_time   = current_time( 'timestamp' );
2542
+        $current_time   = current_time('timestamp');
2543 2543
         $start          = $this->get_subscription_created();
2544
-        $start          = $start ? strtotime( $start ) : $current_time;
2544
+        $start          = $start ? strtotime($start) : $current_time;
2545 2545
         $expires        = $this->get_expiration_time();
2546 2546
         
2547
-        if ( !$expires ) {
2548
-            $expires    = strtotime( '+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period( true ), $start );
2547
+        if (!$expires) {
2548
+            $expires    = strtotime('+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period(true), $start);
2549 2549
         }
2550 2550
         
2551
-        $expiration     = date_i18n( 'Y-m-d 23:59:59', $expires );
2552
-        $expiration     = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this );
2551
+        $expiration     = date_i18n('Y-m-d 23:59:59', $expires);
2552
+        $expiration     = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this);
2553 2553
         $bill_times     = $parent_invoice->get_bill_times();
2554 2554
         $times_billed   = $parent_invoice->get_total_payments();
2555 2555
         
2556
-        if ( $parent_invoice->get_subscription_status() == 'trialing' && ( $times_billed > 0 || strtotime( date_i18n( 'Y-m-d' ) ) < strtotime( $parent_invoice->get_trial_end_date( false ) ) ) ) {
2556
+        if ($parent_invoice->get_subscription_status() == 'trialing' && ($times_billed > 0 || strtotime(date_i18n('Y-m-d')) < strtotime($parent_invoice->get_trial_end_date(false)))) {
2557 2557
             $args = array(
2558 2558
                 'status'     => 'active',
2559 2559
             );
2560 2560
 
2561
-            $parent_invoice->update_subscription( $args );
2561
+            $parent_invoice->update_subscription($args);
2562 2562
         }
2563 2563
         
2564
-        do_action( 'wpinv_subscription_pre_renew', $this->ID, $expiration, $this );
2564
+        do_action('wpinv_subscription_pre_renew', $this->ID, $expiration, $this);
2565 2565
 
2566
-        $status       = 'active';
2567
-        if ( $bill_times > 0 && $times_billed >= $bill_times ) {
2566
+        $status = 'active';
2567
+        if ($bill_times > 0 && $times_billed >= $bill_times) {
2568 2568
             $this->complete_subscription();
2569 2569
             $status = 'completed';
2570 2570
         }
@@ -2574,10 +2574,10 @@  discard block
 block discarded – undo
2574 2574
             'status'     => $status,
2575 2575
         );
2576 2576
 
2577
-        $this->update_subscription( $args );
2577
+        $this->update_subscription($args);
2578 2578
 
2579
-        do_action( 'wpinv_subscription_post_renew', $this->ID, $expiration, $this );
2580
-        do_action( 'wpinv_recurring_set_subscription_status', $this->ID, $status, $this );
2579
+        do_action('wpinv_subscription_post_renew', $this->ID, $expiration, $this);
2580
+        do_action('wpinv_recurring_set_subscription_status', $this->ID, $status, $this);
2581 2581
     }
2582 2582
     
2583 2583
     public function complete_subscription() {
@@ -2585,8 +2585,8 @@  discard block
 block discarded – undo
2585 2585
             'status' => 'completed'
2586 2586
         );
2587 2587
 
2588
-        if ( $this->update_subscription( $args ) ) {
2589
-            do_action( 'wpinv_subscription_completed', $this->ID, $this );
2588
+        if ($this->update_subscription($args)) {
2589
+            do_action('wpinv_subscription_completed', $this->ID, $this);
2590 2590
         }
2591 2591
     }
2592 2592
     
@@ -2595,44 +2595,44 @@  discard block
 block discarded – undo
2595 2595
             'status' => 'expired'
2596 2596
         );
2597 2597
 
2598
-        if ( $this->update_subscription( $args ) ) {
2599
-            do_action( 'wpinv_subscription_expired', $this->ID, $this );
2598
+        if ($this->update_subscription($args)) {
2599
+            do_action('wpinv_subscription_expired', $this->ID, $this);
2600 2600
         }
2601 2601
     }
2602 2602
 
2603 2603
     public function get_cancel_url() {
2604
-        $url = wp_nonce_url( add_query_arg( array( 'wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID ) ), 'wpinv-recurring-cancel' );
2604
+        $url = wp_nonce_url(add_query_arg(array('wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID)), 'wpinv-recurring-cancel');
2605 2605
 
2606
-        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
2606
+        return apply_filters('wpinv_subscription_cancel_url', $url, $this);
2607 2607
     }
2608 2608
 
2609 2609
     public function can_update() {
2610
-        return apply_filters( 'wpinv_subscription_can_update', false, $this );
2610
+        return apply_filters('wpinv_subscription_can_update', false, $this);
2611 2611
     }
2612 2612
 
2613 2613
     public function get_update_url() {
2614
-        $url = add_query_arg( array( 'action' => 'update', 'sub_id' => $this->ID ) );
2614
+        $url = add_query_arg(array('action' => 'update', 'sub_id' => $this->ID));
2615 2615
 
2616
-        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
2616
+        return apply_filters('wpinv_subscription_update_url', $url, $this);
2617 2617
     }
2618 2618
 
2619 2619
     public function is_parent() {
2620
-        $is_parent = empty( $this->parent_invoice ) ? true : false;
2620
+        $is_parent = empty($this->parent_invoice) ? true : false;
2621 2621
 
2622
-        return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this );
2622
+        return apply_filters('wpinv_invoice_is_parent', $is_parent, $this);
2623 2623
     }
2624 2624
     
2625 2625
     public function is_renewal() {
2626 2626
         $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false;
2627 2627
 
2628
-        return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this );
2628
+        return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this);
2629 2629
     }
2630 2630
     
2631 2631
     public function get_parent_payment() {
2632 2632
         $parent_payment = NULL;
2633 2633
         
2634
-        if ( $this->is_renewal() ) {
2635
-            $parent_payment = wpinv_get_invoice( $this->parent_invoice );
2634
+        if ($this->is_renewal()) {
2635
+            $parent_payment = wpinv_get_invoice($this->parent_invoice);
2636 2636
         }
2637 2637
         
2638 2638
         return $parent_payment;
@@ -2643,100 +2643,100 @@  discard block
 block discarded – undo
2643 2643
         
2644 2644
         $subscription_status = $this->get_subscription_status();
2645 2645
 
2646
-        if( ! $this->is_subscription_expired() && ( $subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing' ) ) {
2646
+        if (!$this->is_subscription_expired() && ($subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing')) {
2647 2647
             $ret = true;
2648 2648
         }
2649 2649
 
2650
-        return apply_filters( 'wpinv_subscription_is_active', $ret, $this->ID, $this );
2650
+        return apply_filters('wpinv_subscription_is_active', $ret, $this->ID, $this);
2651 2651
     }
2652 2652
 
2653 2653
     public function is_subscription_expired() {
2654 2654
         $ret = false;
2655 2655
         $subscription_status = $this->get_subscription_status();
2656 2656
 
2657
-        if ( $subscription_status == 'expired' ) {
2657
+        if ($subscription_status == 'expired') {
2658 2658
             $ret = true;
2659
-        } else if ( 'active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status ) {
2659
+        } else if ('active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status) {
2660 2660
             $ret        = false;
2661 2661
             $expiration = $this->get_expiration_time();
2662 2662
 
2663
-            if ( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) {
2663
+            if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) {
2664 2664
                 $ret = true;
2665 2665
 
2666
-                if ( 'active' === $subscription_status || 'trialing' === $subscription_status ) {
2666
+                if ('active' === $subscription_status || 'trialing' === $subscription_status) {
2667 2667
                     $this->expire_subscription();
2668 2668
                 }
2669 2669
             }
2670 2670
         }
2671 2671
 
2672
-        return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->ID, $this );
2672
+        return apply_filters('wpinv_subscription_is_expired', $ret, $this->ID, $this);
2673 2673
     }
2674 2674
     
2675
-    public function get_new_expiration( $item_id = 0, $trial = true ) {
2676
-        $item   = new WPInv_Item( $item_id );
2675
+    public function get_new_expiration($item_id = 0, $trial = true) {
2676
+        $item   = new WPInv_Item($item_id);
2677 2677
         $interval = $item->get_recurring_interval();
2678
-        $period = $item->get_recurring_period( true );
2678
+        $period = $item->get_recurring_period(true);
2679 2679
         
2680
-        $expiration_time = strtotime( '+' . $interval . ' ' . $period );
2680
+        $expiration_time = strtotime('+' . $interval . ' ' . $period);
2681 2681
         
2682
-        if ( $trial && $this->is_free_trial() && $item->has_free_trial() ) {
2683
-            $expiration_time += ( wpinv_period_in_days( $item->get_trial_interval(), $item->get_trial_period() ) * DAY_IN_SECONDS ) ;
2682
+        if ($trial && $this->is_free_trial() && $item->has_free_trial()) {
2683
+            $expiration_time += (wpinv_period_in_days($item->get_trial_interval(), $item->get_trial_period()) * DAY_IN_SECONDS);
2684 2684
         }
2685 2685
 
2686
-        return date_i18n( 'Y-m-d 23:59:59', $expiration_time );
2686
+        return date_i18n('Y-m-d 23:59:59', $expiration_time);
2687 2687
     }
2688 2688
     
2689
-    public function get_subscription_data( $filed = '' ) {
2690
-        $fields = array( 'item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on' );
2689
+    public function get_subscription_data($filed = '') {
2690
+        $fields = array('item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on');
2691 2691
         
2692 2692
         $subscription_meta = array();
2693
-        foreach ( $fields as $field ) {
2694
-            $subscription_meta[ $field ] = $this->get_meta( '_wpinv_subscr_' . $field );
2693
+        foreach ($fields as $field) {
2694
+            $subscription_meta[$field] = $this->get_meta('_wpinv_subscr_' . $field);
2695 2695
         }
2696 2696
         
2697
-        $item = $this->get_recurring( true );
2697
+        $item = $this->get_recurring(true);
2698 2698
         
2699
-        if ( !empty( $item ) ) {
2700
-            if ( empty( $subscription_meta['item_id'] ) ) {
2699
+        if (!empty($item)) {
2700
+            if (empty($subscription_meta['item_id'])) {
2701 2701
                 $subscription_meta['item_id'] = $item->ID;
2702 2702
             }
2703
-            if ( empty( $subscription_meta['period'] ) ) {
2703
+            if (empty($subscription_meta['period'])) {
2704 2704
                 $subscription_meta['period'] = $item->get_recurring_period();
2705 2705
             }
2706
-            if ( empty( $subscription_meta['interval'] ) ) {
2706
+            if (empty($subscription_meta['interval'])) {
2707 2707
                 $subscription_meta['interval'] = $item->get_recurring_interval();
2708 2708
             }
2709
-            if ( $item->has_free_trial() ) {
2710
-                if ( empty( $subscription_meta['trial_period'] ) ) {
2709
+            if ($item->has_free_trial()) {
2710
+                if (empty($subscription_meta['trial_period'])) {
2711 2711
                     $subscription_meta['trial_period'] = $item->get_trial_period();
2712 2712
                 }
2713
-                if ( empty( $subscription_meta['trial_interval'] ) ) {
2713
+                if (empty($subscription_meta['trial_interval'])) {
2714 2714
                     $subscription_meta['trial_interval'] = $item->get_trial_interval();
2715 2715
                 }
2716 2716
             } else {
2717 2717
                 $subscription_meta['trial_period']      = '';
2718 2718
                 $subscription_meta['trial_interval']    = 0;
2719 2719
             }
2720
-            if ( !$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0 ) {
2720
+            if (!$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0) {
2721 2721
                 $subscription_meta['bill_times'] = $item->get_recurring_limit();
2722 2722
             }
2723
-            if ( $subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '' ) {
2724
-                $subscription_meta['initial_amount']    = wpinv_format_amount( $this->get_total() );
2725
-                $subscription_meta['recurring_amount']  = wpinv_format_amount( $this->get_recurring_details( 'total' ) );
2723
+            if ($subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '') {
2724
+                $subscription_meta['initial_amount']    = wpinv_format_amount($this->get_total());
2725
+                $subscription_meta['recurring_amount']  = wpinv_format_amount($this->get_recurring_details('total'));
2726 2726
             }
2727 2727
         }
2728 2728
         
2729
-        if ( $filed === '' ) {
2730
-            return apply_filters( 'wpinv_get_invoice_subscription_data', $subscription_meta, $this );
2729
+        if ($filed === '') {
2730
+            return apply_filters('wpinv_get_invoice_subscription_data', $subscription_meta, $this);
2731 2731
         }
2732 2732
         
2733
-        $value = isset( $subscription_meta[$filed] ) ? $subscription_meta[$filed] : '';
2733
+        $value = isset($subscription_meta[$filed]) ? $subscription_meta[$filed] : '';
2734 2734
         
2735
-        return apply_filters( 'wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this );
2735
+        return apply_filters('wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this);
2736 2736
     }
2737 2737
     
2738 2738
     public function is_paid() {
2739
-        if ( $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
2739
+        if ($this->has_status(array('publish', 'wpi-processing', 'wpi-renewal'))) {
2740 2740
             return true;
2741 2741
         }
2742 2742
         
@@ -2748,28 +2748,28 @@  discard block
 block discarded – undo
2748 2748
         
2749 2749
         $requires_vat = false;
2750 2750
         
2751
-        if ( $this->country ) {
2751
+        if ($this->country) {
2752 2752
             $wpi_country        = $this->country;
2753 2753
             
2754
-            $requires_vat       = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) );
2754
+            $requires_vat       = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this));
2755 2755
         }
2756 2756
         
2757
-        return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2757
+        return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this);
2758 2758
     }
2759 2759
     
2760 2760
     public function refresh_item_ids() {
2761 2761
         $item_ids = array();
2762 2762
         
2763
-        if ( !empty( $this->cart_details ) ) {
2764
-            foreach ( $this->cart_details as $key => $item ) {
2765
-                if ( !empty( $item['id'] ) ) {
2763
+        if (!empty($this->cart_details)) {
2764
+            foreach ($this->cart_details as $key => $item) {
2765
+                if (!empty($item['id'])) {
2766 2766
                     $item_ids[] = $item['id'];
2767 2767
                 }
2768 2768
             }
2769 2769
         }
2770 2770
         
2771
-        $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : '';
2771
+        $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : '';
2772 2772
         
2773
-        update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids );
2773
+        update_post_meta($this->ID, '_wpinv_item_ids', $item_ids);
2774 2774
     }
2775 2775
 }
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Spacing   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  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
 class WPInv_Plugin {
15 15
     private static $instance;
16 16
     
17 17
     public static function run() {
18
-        if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) {
18
+        if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) {
19 19
             self::$instance = new WPInv_Plugin;
20 20
             self::$instance->includes();
21 21
             self::$instance->actions();
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
             self::$instance->reports    = new WPInv_Reports();
24 24
         }
25 25
         
26
-        do_action( 'wpinv_loaded' );
26
+        do_action('wpinv_loaded');
27 27
         
28 28
         return self::$instance;
29 29
     }
@@ -33,31 +33,31 @@  discard block
 block discarded – undo
33 33
     }
34 34
     
35 35
     public function define_constants() {
36
-        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
37
-        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
36
+        define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
37
+        define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
38 38
     }
39 39
     
40 40
     private function actions() {
41 41
         /* Internationalize the text strings used. */
42
-        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
42
+        add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
43 43
         
44 44
         /* Perform actions on admin initialization. */
45
-        add_action( 'admin_init', array( &$this, 'admin_init') );
46
-        add_action( 'init', array( &$this, 'init' ), 3 );
47
-        add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) );
48
-        add_action( 'init', array( &$this, 'wpinv_actions' ) );
45
+        add_action('admin_init', array(&$this, 'admin_init'));
46
+        add_action('init', array(&$this, 'init'), 3);
47
+        add_action('init', array('WPInv_Shortcodes', 'init'));
48
+        add_action('init', array(&$this, 'wpinv_actions'));
49 49
         
50
-        if ( class_exists( 'BuddyPress' ) ) {
51
-            add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
50
+        if (class_exists('BuddyPress')) {
51
+            add_action('bp_include', array(&$this, 'bp_invoicing_init'));
52 52
         }
53 53
 
54
-        add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
54
+        add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts'));
55 55
         
56
-        if ( is_admin() ) {
57
-            add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
58
-            add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) );
56
+        if (is_admin()) {
57
+            add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
58
+            add_action('admin_body_class', array(&$this, 'admin_body_class'));
59 59
         } else {
60
-            add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
60
+            add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
61 61
         }
62 62
         
63 63
         /**
@@ -67,9 +67,9 @@  discard block
 block discarded – undo
67 67
          *
68 68
          * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference.
69 69
          */
70
-        do_action_ref_array( 'wpinv_actions', array( &$this ) );
70
+        do_action_ref_array('wpinv_actions', array(&$this));
71 71
 
72
-        add_action( 'admin_init', array( &$this, 'activation_redirect') );
72
+        add_action('admin_init', array(&$this, 'activation_redirect'));
73 73
     }
74 74
     
75 75
     public function plugins_loaded() {
@@ -83,189 +83,189 @@  discard block
 block discarded – undo
83 83
      * @since 1.0
84 84
      */
85 85
     public function load_textdomain() {
86
-        $locale = apply_filters( 'plugin_locale', get_locale(), 'invoicing' );
86
+        $locale = apply_filters('plugin_locale', get_locale(), 'invoicing');
87 87
         
88
-        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
89
-        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
88
+        load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo');
89
+        load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages');
90 90
         
91 91
         /**
92 92
          * Define language constants.
93 93
          */
94
-        require_once( WPINV_PLUGIN_DIR . 'language.php' );
94
+        require_once(WPINV_PLUGIN_DIR . 'language.php');
95 95
     }
96 96
         
97 97
     public function includes() {
98 98
         global $wpinv_options;
99 99
         
100
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
100
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php');
101 101
         $wpinv_options = wpinv_get_settings();
102 102
         
103
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' );
104
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
105
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
106
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
107
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
108
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
109
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
110
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' );
111
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
112
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
113
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
114
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
115
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
116
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php' );
117
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' );
118
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' );
119
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' );
120
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' );
121
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' );
122
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
123
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
124
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
125
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' );
126
-        if ( !class_exists( 'Geodir_EUVat' ) ) {
127
-            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
103
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php');
104
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php');
105
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php');
106
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php');
107
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php');
108
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php');
109
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php');
110
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php');
111
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php');
112
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php');
113
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php');
114
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php');
115
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php');
116
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php');
117
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php');
118
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php');
119
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php');
120
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php');
121
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php');
122
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php');
123
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php');
124
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php');
125
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php');
126
+        if (!class_exists('Geodir_EUVat')) {
127
+            require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php');
128 128
         }
129 129
         
130
-        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
131
-        if ( !empty( $gateways ) ) {
132
-            foreach ( $gateways as $gateway ) {
133
-                if ( $gateway == 'manual' ) {
130
+        $gateways = array_keys(wpinv_get_enabled_payment_gateways());
131
+        if (!empty($gateways)) {
132
+            foreach ($gateways as $gateway) {
133
+                if ($gateway == 'manual') {
134 134
                     continue;
135 135
                 }
136 136
                 
137 137
                 $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
138 138
                 
139
-                if ( file_exists( $gateway_file ) ) {
140
-                    require_once( $gateway_file );
139
+                if (file_exists($gateway_file)) {
140
+                    require_once($gateway_file);
141 141
                 }
142 142
             }
143 143
         }
144
-        require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' );
145
-        
146
-        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
147
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
148
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
149
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' );
150
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' );
151
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' );
152
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
153
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' );
154
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
144
+        require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php');
145
+        
146
+        if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
147
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php');
148
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php');
149
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php');
150
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php');
151
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php');
152
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php');
153
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php');
154
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php');
155 155
             
156 156
         }
157 157
         
158 158
         // include css inliner
159
-        if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
160
-            include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
159
+        if (!class_exists('Emogrifier') && class_exists('DOMDocument')) {
160
+            include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php');
161 161
         }
162 162
         
163
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
163
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php');
164 164
     }
165 165
     
166 166
     public function init() {
167 167
     }
168 168
     
169 169
     public function admin_init() {
170
-        if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
170
+        if (!(defined('DOING_AJAX') && DOING_AJAX)) {
171 171
         }
172 172
         
173
-        add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) );
173
+        add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php'));
174 174
     }
175 175
 
176 176
     public function activation_redirect() {
177 177
         // Bail if no activation redirect
178
-        if ( !get_transient( '_wpinv_activation_redirect' ) ) {
178
+        if (!get_transient('_wpinv_activation_redirect')) {
179 179
             return;
180 180
         }
181 181
 
182 182
         // Delete the redirect transient
183
-        delete_transient( '_wpinv_activation_redirect' );
183
+        delete_transient('_wpinv_activation_redirect');
184 184
 
185 185
         // Bail if activating from network, or bulk
186
-        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
186
+        if (is_network_admin() || isset($_GET['activate-multi'])) {
187 187
             return;
188 188
         }
189 189
 
190
-        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
190
+        wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
191 191
         exit;
192 192
     }
193 193
     
194 194
     public function enqueue_scripts() {
195
-        $suffix       = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
195
+        $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
196 196
         
197
-        wp_deregister_style( 'font-awesome' );
198
-        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
199
-        wp_enqueue_style( 'font-awesome' );
197
+        wp_deregister_style('font-awesome');
198
+        wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0');
199
+        wp_enqueue_style('font-awesome');
200 200
         
201
-        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION );
202
-        wp_enqueue_style( 'wpinv_front_style' );
201
+        wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION);
202
+        wp_enqueue_style('wpinv_front_style');
203 203
                
204 204
         // Register scripts
205
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
206
-        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array( 'jquery', 'wpinv-vat-script' ),  WPINV_VERSION );
205
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
206
+        wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array('jquery', 'wpinv-vat-script'), WPINV_VERSION);
207 207
         
208 208
         $localize                         = array();
209
-        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
210
-        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
209
+        $localize['ajax_url']             = admin_url('admin-ajax.php');
210
+        $localize['nonce']                = wp_create_nonce('wpinv-nonce');
211 211
         $localize['currency_symbol']      = wpinv_currency_symbol();
212 212
         $localize['currency_pos']         = wpinv_currency_position();
213 213
         $localize['thousand_sep']         = wpinv_thousands_seperator();
214 214
         $localize['decimal_sep']          = wpinv_decimal_seperator();
215 215
         $localize['decimals']             = wpinv_decimals();
216 216
         
217
-        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
217
+        $localize = apply_filters('wpinv_front_js_localize', $localize);
218 218
         
219
-        wp_enqueue_script( 'jquery-blockui' );
220
-        wp_enqueue_script( 'wpinv-front-script' );
221
-        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
219
+        wp_enqueue_script('jquery-blockui');
220
+        wp_enqueue_script('wpinv-front-script');
221
+        wp_localize_script('wpinv-front-script', 'WPInv', $localize);
222 222
     }
223 223
     
224 224
     public function admin_enqueue_scripts() {
225 225
         global $post, $pagenow;
226 226
         
227 227
         $post_type  = wpinv_admin_post_type();
228
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
228
+        $suffix     = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
229 229
         
230
-        wp_deregister_style( 'font-awesome' );
231
-        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
232
-        wp_enqueue_style( 'font-awesome' );
230
+        wp_deregister_style('font-awesome');
231
+        wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0');
232
+        wp_enqueue_style('font-awesome');
233 233
         
234
-        wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
235
-        wp_enqueue_style( 'jquery-ui-css' );
234
+        wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16');
235
+        wp_enqueue_style('jquery-ui-css');
236 236
         
237
-        wp_register_style( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2' );
238
-        wp_enqueue_style( 'jquery-chosen' );
237
+        wp_register_style('jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2');
238
+        wp_enqueue_style('jquery-chosen');
239 239
 
240
-        wp_register_script( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.6.2' );
241
-        wp_enqueue_script( 'jquery-chosen' );
240
+        wp_register_script('jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array('jquery'), '1.6.2');
241
+        wp_enqueue_script('jquery-chosen');
242 242
         
243
-        wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
244
-        wp_enqueue_style( 'wpinv_meta_box_style' );
243
+        wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
244
+        wp_enqueue_style('wpinv_meta_box_style');
245 245
         
246
-        wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION );
247
-        wp_enqueue_style( 'wpinv_admin_style' );
246
+        wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION);
247
+        wp_enqueue_style('wpinv_admin_style');
248 248
         
249
-        if ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
250
-            wp_enqueue_script( 'jquery-ui-datepicker' );
249
+        if ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
250
+            wp_enqueue_script('jquery-ui-datepicker');
251 251
         }
252 252
 
253
-        wp_enqueue_style( 'wp-color-picker' );
254
-        wp_enqueue_script( 'wp-color-picker' );
253
+        wp_enqueue_style('wp-color-picker');
254
+        wp_enqueue_script('wp-color-picker');
255 255
         
256
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
256
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
257 257
         
258
-        wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui' ),  WPINV_VERSION );
259
-        wp_enqueue_script( 'wpinv-admin-script' );
258
+        wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui'), WPINV_VERSION);
259
+        wp_enqueue_script('wpinv-admin-script');
260 260
         
261 261
         $localize                               = array();
262
-        $localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
263
-        $localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
264
-        $localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
265
-        $localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
266
-        $localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
267
-        $localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
268
-        $localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
262
+        $localize['ajax_url']                   = admin_url('admin-ajax.php');
263
+        $localize['post_ID']                    = isset($post->ID) ? $post->ID : '';
264
+        $localize['wpinv_nonce']                = wp_create_nonce('wpinv-nonce');
265
+        $localize['add_invoice_note_nonce']     = wp_create_nonce('add-invoice-note');
266
+        $localize['delete_invoice_note_nonce']  = wp_create_nonce('delete-invoice-note');
267
+        $localize['invoice_item_nonce']         = wp_create_nonce('invoice-item');
268
+        $localize['billing_details_nonce']      = wp_create_nonce('get-billing-details');
269 269
         $localize['tax']                        = wpinv_tax_amount();
270 270
         $localize['discount']                   = wpinv_discount_amount();
271 271
         $localize['currency_symbol']            = wpinv_currency_symbol();
@@ -273,55 +273,55 @@  discard block
 block discarded – undo
273 273
         $localize['thousand_sep']               = wpinv_thousands_seperator();
274 274
         $localize['decimal_sep']                = wpinv_decimal_seperator();
275 275
         $localize['decimals']                   = wpinv_decimals();
276
-        $localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
277
-        $localize['status_publish']             = wpinv_status_nicename( 'publish' );
278
-        $localize['status_pending']             = wpinv_status_nicename( 'pending' );
279
-        $localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
280
-        $localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
281
-        $localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
282
-        $localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
283
-        $localize['confirmCalcTotals']          = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' );
284
-        $localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
285
-        $localize['hasGD']                      = wpinv_gd_active();;
276
+        $localize['save_invoice']               = __('Save Invoice', 'invoicing');
277
+        $localize['status_publish']             = wpinv_status_nicename('publish');
278
+        $localize['status_pending']             = wpinv_status_nicename('pending');
279
+        $localize['delete_tax_rate']            = __('Are you sure you wish to delete this tax rate?', 'invoicing');
280
+        $localize['OneItemMin']                 = __('Invoice must contain at least one item', 'invoicing');
281
+        $localize['DeleteInvoiceItem']          = __('Are you sure you wish to delete this item?', 'invoicing');
282
+        $localize['FillBillingDetails']         = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing');
283
+        $localize['confirmCalcTotals']          = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing');
284
+        $localize['AreYouSure']                 = __('Are you sure?', 'invoicing');
285
+        $localize['hasGD']                      = wpinv_gd_active(); ;
286 286
         $localize['hasPM']                      = wpinv_pm_active();
287
-        $localize['emptyInvoice']               = __( 'Add atleast one item to save invoice!', 'invoicing' );
288
-        $localize['deletePackage']              = __( 'GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing' );
289
-        $localize['deletePackages']             = __( 'GD package items should be deleted from GD payment manager only', 'invoicing' );
290
-        $localize['deleteInvoiceFirst']         = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
287
+        $localize['emptyInvoice']               = __('Add atleast one item to save invoice!', 'invoicing');
288
+        $localize['deletePackage']              = __('GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing');
289
+        $localize['deletePackages']             = __('GD package items should be deleted from GD payment manager only', 'invoicing');
290
+        $localize['deleteInvoiceFirst']         = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing');
291 291
         
292
-        wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
292
+        wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize);
293 293
     }
294 294
     
295
-    public function admin_body_class( $classes ) {
295
+    public function admin_body_class($classes) {
296 296
         global $pagenow;
297 297
         
298
-        $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
298
+        $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
299 299
 
300 300
         $add_class = false;
301
-        if ( $pagenow == 'admin.php' && $page ) {
302
-            $add_class = strpos( $page, 'wpinv-' );
301
+        if ($pagenow == 'admin.php' && $page) {
302
+            $add_class = strpos($page, 'wpinv-');
303 303
         }
304 304
         
305 305
         $settings_class = array();
306
-        if ( $page == 'wpinv-settings' ) {
307
-            if ( !empty( $_REQUEST['tab'] ) ) {
308
-                $settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
306
+        if ($page == 'wpinv-settings') {
307
+            if (!empty($_REQUEST['tab'])) {
308
+                $settings_class[] = sanitize_text_field($_REQUEST['tab']);
309 309
             }
310 310
             
311
-            if ( !empty( $_REQUEST['section'] ) ) {
312
-                $settings_class[] = sanitize_text_field( $_REQUEST['section'] );
311
+            if (!empty($_REQUEST['section'])) {
312
+                $settings_class[] = sanitize_text_field($_REQUEST['section']);
313 313
             }
314 314
             
315
-            $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
315
+            $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main';
316 316
         }
317 317
         
318
-        if ( !empty( $settings_class ) ) {
319
-            $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
318
+        if (!empty($settings_class)) {
319
+            $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-'));
320 320
         }
321 321
         
322 322
         $post_type = wpinv_admin_post_type();
323 323
         
324
-        if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
324
+        if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) {
325 325
             return $classes .= ' wpinv';
326 326
         } else {
327 327
             return $classes;
@@ -333,26 +333,26 @@  discard block
 block discarded – undo
333 333
     public function admin_print_scripts_edit_php() {
334 334
         $post_type = wpinv_admin_post_type();
335 335
         
336
-        if ( $post_type == 'wpi_item' ) {
337
-            wp_enqueue_script( 'wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array( 'jquery', 'inline-edit-post' ), '', true );
336
+        if ($post_type == 'wpi_item') {
337
+            wp_enqueue_script('wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array('jquery', 'inline-edit-post'), '', true);
338 338
         }
339 339
     }
340 340
     
341 341
     public function wpinv_actions() {
342
-        if ( isset( $_REQUEST['wpi_action'] ) ) {
343
-            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
342
+        if (isset($_REQUEST['wpi_action'])) {
343
+            do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
344 344
         }
345 345
     }
346 346
     
347
-    public function pre_get_posts( $wp_query ) {
348
-        if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
349
-            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
347
+    public function pre_get_posts($wp_query) {
348
+        if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) {
349
+            $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses());
350 350
         }
351 351
         
352 352
         return $wp_query;
353 353
     }
354 354
     
355 355
     public function bp_invoicing_init() {
356
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
356
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php');
357 357
     }
358 358
 }
359 359
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 1 patch
Spacing   +670 added lines, -670 removed lines patch added patch discarded remove patch
@@ -7,109 +7,109 @@  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
-if ( !is_admin() ) {
15
-    add_filter( 'template_include', 'wpinv_template', 10, 1 );
16
-    add_action( 'wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar' );
17
-    add_action( 'wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions' );
18
-    add_action( 'wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions' );
14
+if (!is_admin()) {
15
+    add_filter('template_include', 'wpinv_template', 10, 1);
16
+    add_action('wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar');
17
+    add_action('wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions');
18
+    add_action('wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions');
19 19
 }
20 20
 
21 21
 function wpinv_template_path() {
22
-    return apply_filters( 'wpinv_template_path', 'invoicing/' );
22
+    return apply_filters('wpinv_template_path', 'invoicing/');
23 23
 }
24 24
 
25
-function wpinv_post_class( $classes, $class, $post_id ) {
25
+function wpinv_post_class($classes, $class, $post_id) {
26 26
     global $pagenow, $typenow;
27 27
 
28
-    if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' ) {
28
+    if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow && get_post_meta($post_id, '_wpinv_type', true) == 'package') {
29 29
         $classes[] = 'wpi-gd-package';
30 30
     }
31 31
     return $classes;
32 32
 }
33
-add_filter( 'post_class', 'wpinv_post_class', 10, 3 );
33
+add_filter('post_class', 'wpinv_post_class', 10, 3);
34 34
 
35
-function wpinv_display_invoice_top_bar( $invoice ) {
36
-    if ( empty( $invoice ) ) {
35
+function wpinv_display_invoice_top_bar($invoice) {
36
+    if (empty($invoice)) {
37 37
         return;
38 38
     }
39 39
     ?>
40 40
     <div class="row wpinv-top-bar no-print">
41 41
         <div class="container">
42 42
             <div class="col-xs-6">
43
-                <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?>
43
+                <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?>
44 44
             </div>
45 45
             <div class="col-xs-6 text-right">
46
-                <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?>
46
+                <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?>
47 47
             </div>
48 48
         </div>
49 49
     </div>
50 50
     <?php
51 51
 }
52 52
 
53
-function wpinv_invoice_display_left_actions( $invoice ) {
54
-    if ( empty( $invoice ) ) {
53
+function wpinv_invoice_display_left_actions($invoice) {
54
+    if (empty($invoice)) {
55 55
         return;
56 56
     }
57 57
     
58
-    if($invoice->post_type == 'wpi_invoice'){
58
+    if ($invoice->post_type == 'wpi_invoice') {
59 59
     
60 60
         $user_id = (int)$invoice->get_user_id();
61 61
         $current_user_id = (int)get_current_user_id();
62 62
 
63
-        if ( $user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment() ) {
63
+        if ($user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment()) {
64 64
             ?> 
65
-            <a class="btn btn-success btn-sm" title="<?php esc_attr_e( 'Pay This Invoice', 'invoicing' ); ?>" href="<?php echo esc_url( $invoice->get_checkout_payment_url() ); ?>"><?php _e( 'Pay For Invoice', 'invoicing' ); ?></a>
65
+            <a class="btn btn-success btn-sm" title="<?php esc_attr_e('Pay This Invoice', 'invoicing'); ?>" href="<?php echo esc_url($invoice->get_checkout_payment_url()); ?>"><?php _e('Pay For Invoice', 'invoicing'); ?></a>
66 66
             <?php
67 67
         }
68 68
     }
69 69
     do_action('wpinv_invoice_display_left_actions', $invoice);
70 70
 }
71 71
 
72
-function wpinv_invoice_display_right_actions( $invoice ) {
73
-    if ( empty( $invoice ) ) return; //Exit if invoice is not set.
72
+function wpinv_invoice_display_right_actions($invoice) {
73
+    if (empty($invoice)) return; //Exit if invoice is not set.
74 74
     
75
-    if($invoice->post_type == 'wpi_invoice'){
75
+    if ($invoice->post_type == 'wpi_invoice') {
76 76
         $user_id = (int)$invoice->get_user_id();
77 77
         $current_user_id = (int)get_current_user_id();
78 78
 
79
-        if ( $user_id > 0 && $user_id == $current_user_id ) {
79
+        if ($user_id > 0 && $user_id == $current_user_id) {
80 80
         ?>
81
-            <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a> &nbsp;
82
-            <a class="btn btn-warning btn-sm" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a>
81
+            <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a> &nbsp;
82
+            <a class="btn btn-warning btn-sm" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a>
83 83
         <?php } 
84 84
     }
85 85
     do_action('wpinv_invoice_display_right_actions', $invoice);
86 86
 }
87 87
 
88
-function wpinv_before_invoice_content( $content ) {
88
+function wpinv_before_invoice_content($content) {
89 89
     global $post;
90 90
 
91
-    if ( $post && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
91
+    if ($post && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
92 92
         ob_start();
93
-        do_action( 'wpinv_before_invoice_content', $post->ID );
93
+        do_action('wpinv_before_invoice_content', $post->ID);
94 94
         $content = ob_get_clean() . $content;
95 95
     }
96 96
 
97 97
     return $content;
98 98
 }
99
-add_filter( 'the_content', 'wpinv_before_invoice_content' );
99
+add_filter('the_content', 'wpinv_before_invoice_content');
100 100
 
101
-function wpinv_after_invoice_content( $content ) {
101
+function wpinv_after_invoice_content($content) {
102 102
     global $post;
103 103
 
104
-    if ( $post && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
104
+    if ($post && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
105 105
         ob_start();
106
-        do_action( 'wpinv_after_invoice_content', $post->ID );
106
+        do_action('wpinv_after_invoice_content', $post->ID);
107 107
         $content .= ob_get_clean();
108 108
     }
109 109
 
110 110
     return $content;
111 111
 }
112
-add_filter( 'the_content', 'wpinv_after_invoice_content' );
112
+add_filter('the_content', 'wpinv_after_invoice_content');
113 113
 
114 114
 function wpinv_get_templates_dir() {
115 115
     return WPINV_PLUGIN_DIR . 'templates';
@@ -119,105 +119,105 @@  discard block
 block discarded – undo
119 119
     return WPINV_PLUGIN_URL . 'templates';
120 120
 }
121 121
 
122
-function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
123
-    if ( ! empty( $args ) && is_array( $args ) ) {
124
-		extract( $args );
122
+function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
123
+    if (!empty($args) && is_array($args)) {
124
+		extract($args);
125 125
 	}
126 126
 
127
-	$located = wpinv_locate_template( $template_name, $template_path, $default_path );
127
+	$located = wpinv_locate_template($template_name, $template_path, $default_path);
128 128
 	// Allow 3rd party plugin filter template file from their plugin.
129
-	$located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path );
129
+	$located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path);
130 130
 
131
-	if ( ! file_exists( $located ) ) {
132
-        _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
131
+	if (!file_exists($located)) {
132
+        _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1');
133 133
 		return;
134 134
 	}
135 135
 
136
-	do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args );
136
+	do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args);
137 137
 
138
-	include( $located );
138
+	include($located);
139 139
 
140
-	do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args );
140
+	do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args);
141 141
 }
142 142
 
143
-function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
143
+function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') {
144 144
 	ob_start();
145
-	wpinv_get_template( $template_name, $args, $template_path, $default_path );
145
+	wpinv_get_template($template_name, $args, $template_path, $default_path);
146 146
 	return ob_get_clean();
147 147
 }
148 148
 
149
-function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
150
-    if ( ! $template_path ) {
149
+function wpinv_locate_template($template_name, $template_path = '', $default_path = '') {
150
+    if (!$template_path) {
151 151
         $template_path = wpinv_template_path();
152 152
     }
153 153
 
154
-    if ( ! $default_path ) {
154
+    if (!$default_path) {
155 155
         $default_path = WPINV_PLUGIN_DIR . 'templates/';
156 156
     }
157 157
 
158 158
     // Look within passed path within the theme - this is priority.
159 159
     $template = locate_template(
160 160
         array(
161
-            trailingslashit( $template_path ) . $template_name,
161
+            trailingslashit($template_path) . $template_name,
162 162
             $template_name
163 163
         )
164 164
     );
165 165
 
166 166
     // Get default templates/
167
-    if ( !$template && $default_path ) {
168
-        $template = trailingslashit( $default_path ) . $template_name;
167
+    if (!$template && $default_path) {
168
+        $template = trailingslashit($default_path) . $template_name;
169 169
     }
170 170
 
171 171
     // Return what we found.
172
-    return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path );
172
+    return apply_filters('wpinv_locate_template', $template, $template_name, $template_path);
173 173
 }
174 174
 
175
-function wpinv_get_template_part( $slug, $name = null, $load = true ) {
176
-	do_action( 'get_template_part_' . $slug, $slug, $name );
175
+function wpinv_get_template_part($slug, $name = null, $load = true) {
176
+	do_action('get_template_part_' . $slug, $slug, $name);
177 177
 
178 178
 	// Setup possible parts
179 179
 	$templates = array();
180
-	if ( isset( $name ) )
180
+	if (isset($name))
181 181
 		$templates[] = $slug . '-' . $name . '.php';
182 182
 	$templates[] = $slug . '.php';
183 183
 
184 184
 	// Allow template parts to be filtered
185
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
185
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
186 186
 
187 187
 	// Return the part that is found
188
-	return wpinv_locate_tmpl( $templates, $load, false );
188
+	return wpinv_locate_tmpl($templates, $load, false);
189 189
 }
190 190
 
191
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
191
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
192 192
 	// No file found yet
193 193
 	$located = false;
194 194
 
195 195
 	// Try to find a template file
196
-	foreach ( (array)$template_names as $template_name ) {
196
+	foreach ((array)$template_names as $template_name) {
197 197
 
198 198
 		// Continue if template is empty
199
-		if ( empty( $template_name ) )
199
+		if (empty($template_name))
200 200
 			continue;
201 201
 
202 202
 		// Trim off any slashes from the template name
203
-		$template_name = ltrim( $template_name, '/' );
203
+		$template_name = ltrim($template_name, '/');
204 204
 
205 205
 		// try locating this template file by looping through the template paths
206
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
206
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
207 207
 
208
-			if( file_exists( $template_path . $template_name ) ) {
208
+			if (file_exists($template_path . $template_name)) {
209 209
 				$located = $template_path . $template_name;
210 210
 				break;
211 211
 			}
212 212
 		}
213 213
 
214
-		if( !empty( $located ) ) {
214
+		if (!empty($located)) {
215 215
 			break;
216 216
 		}
217 217
 	}
218 218
 
219
-	if ( ( true == $load ) && ! empty( $located ) )
220
-		load_template( $located, $require_once );
219
+	if ((true == $load) && !empty($located))
220
+		load_template($located, $require_once);
221 221
 
222 222
 	return $located;
223 223
 }
@@ -226,143 +226,143 @@  discard block
 block discarded – undo
226 226
 	$template_dir = wpinv_get_theme_template_dir_name();
227 227
 
228 228
 	$file_paths = array(
229
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
230
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
229
+		1 => trailingslashit(get_stylesheet_directory()) . $template_dir,
230
+		10 => trailingslashit(get_template_directory()) . $template_dir,
231 231
 		100 => wpinv_get_templates_dir()
232 232
 	);
233 233
 
234
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
234
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
235 235
 
236 236
 	// sort the file paths based on priority
237
-	ksort( $file_paths, SORT_NUMERIC );
237
+	ksort($file_paths, SORT_NUMERIC);
238 238
 
239
-	return array_map( 'trailingslashit', $file_paths );
239
+	return array_map('trailingslashit', $file_paths);
240 240
 }
241 241
 
242 242
 function wpinv_get_theme_template_dir_name() {
243
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'wpinv_templates' ) );
243
+	return trailingslashit(apply_filters('wpinv_templates_dir', 'wpinv_templates'));
244 244
 }
245 245
 
246 246
 function wpinv_checkout_meta_tags() {
247 247
 
248 248
 	$pages   = array();
249
-	$pages[] = wpinv_get_option( 'success_page' );
250
-	$pages[] = wpinv_get_option( 'failure_page' );
251
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
249
+	$pages[] = wpinv_get_option('success_page');
250
+	$pages[] = wpinv_get_option('failure_page');
251
+	$pages[] = wpinv_get_option('invoice_history_page');
252 252
 
253
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
253
+	if (!wpinv_is_checkout() && !is_page($pages)) {
254 254
 		return;
255 255
 	}
256 256
 
257 257
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
258 258
 }
259
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
259
+add_action('wp_head', 'wpinv_checkout_meta_tags');
260 260
 
261
-function wpinv_add_body_classes( $class ) {
261
+function wpinv_add_body_classes($class) {
262 262
 	$classes = (array)$class;
263 263
 
264
-	if( wpinv_is_checkout() ) {
264
+	if (wpinv_is_checkout()) {
265 265
 		$classes[] = 'wpinv-checkout';
266 266
 		$classes[] = 'wpinv-page';
267 267
 	}
268 268
 
269
-	if( wpinv_is_success_page() ) {
269
+	if (wpinv_is_success_page()) {
270 270
 		$classes[] = 'wpinv-success';
271 271
 		$classes[] = 'wpinv-page';
272 272
 	}
273 273
 
274
-	if( wpinv_is_failed_transaction_page() ) {
274
+	if (wpinv_is_failed_transaction_page()) {
275 275
 		$classes[] = 'wpinv-failed-transaction';
276 276
 		$classes[] = 'wpinv-page';
277 277
 	}
278 278
 
279
-	if( wpinv_is_invoice_history_page() ) {
279
+	if (wpinv_is_invoice_history_page()) {
280 280
 		$classes[] = 'wpinv-history';
281 281
 		$classes[] = 'wpinv-page';
282 282
 	}
283 283
 
284
-	if( wpinv_is_test_mode() ) {
284
+	if (wpinv_is_test_mode()) {
285 285
 		$classes[] = 'wpinv-test-mode';
286 286
 		$classes[] = 'wpinv-page';
287 287
 	}
288 288
 
289
-	return array_unique( $classes );
289
+	return array_unique($classes);
290 290
 }
291
-add_filter( 'body_class', 'wpinv_add_body_classes' );
291
+add_filter('body_class', 'wpinv_add_body_classes');
292 292
 
293
-function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) {
294
-    $args = array( 'nopaging' => true );
293
+function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') {
294
+    $args = array('nopaging' => true);
295 295
 
296
-    if ( ! empty( $status ) )
296
+    if (!empty($status))
297 297
         $args['post_status'] = $status;
298 298
 
299
-    $discounts = wpinv_get_discounts( $args );
299
+    $discounts = wpinv_get_discounts($args);
300 300
     $options   = array();
301 301
 
302
-    if ( $discounts ) {
303
-        foreach ( $discounts as $discount ) {
304
-            $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) );
302
+    if ($discounts) {
303
+        foreach ($discounts as $discount) {
304
+            $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID));
305 305
         }
306 306
     } else {
307
-        $options[0] = __( 'No discounts found', 'invoicing' );
307
+        $options[0] = __('No discounts found', 'invoicing');
308 308
     }
309 309
 
310
-    $output = wpinv_html_select( array(
310
+    $output = wpinv_html_select(array(
311 311
         'name'             => $name,
312 312
         'selected'         => $selected,
313 313
         'options'          => $options,
314 314
         'show_option_all'  => false,
315 315
         'show_option_none' => false,
316
-    ) );
316
+    ));
317 317
 
318 318
     return $output;
319 319
 }
320 320
 
321
-function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
322
-    $current     = date( 'Y' );
323
-    $start_year  = $current - absint( $years_before );
324
-    $end_year    = $current + absint( $years_after );
325
-    $selected    = empty( $selected ) ? date( 'Y' ) : $selected;
321
+function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
322
+    $current     = date('Y');
323
+    $start_year  = $current - absint($years_before);
324
+    $end_year    = $current + absint($years_after);
325
+    $selected    = empty($selected) ? date('Y') : $selected;
326 326
     $options     = array();
327 327
 
328
-    while ( $start_year <= $end_year ) {
329
-        $options[ absint( $start_year ) ] = $start_year;
328
+    while ($start_year <= $end_year) {
329
+        $options[absint($start_year)] = $start_year;
330 330
         $start_year++;
331 331
     }
332 332
 
333
-    $output = wpinv_html_select( array(
333
+    $output = wpinv_html_select(array(
334 334
         'name'             => $name,
335 335
         'selected'         => $selected,
336 336
         'options'          => $options,
337 337
         'show_option_all'  => false,
338 338
         'show_option_none' => false
339
-    ) );
339
+    ));
340 340
 
341 341
     return $output;
342 342
 }
343 343
 
344
-function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) {
344
+function wpinv_html_month_dropdown($name = 'month', $selected = 0) {
345 345
     $month   = 1;
346 346
     $options = array();
347
-    $selected = empty( $selected ) ? date( 'n' ) : $selected;
347
+    $selected = empty($selected) ? date('n') : $selected;
348 348
 
349
-    while ( $month <= 12 ) {
350
-        $options[ absint( $month ) ] = wpinv_month_num_to_name( $month );
349
+    while ($month <= 12) {
350
+        $options[absint($month)] = wpinv_month_num_to_name($month);
351 351
         $month++;
352 352
     }
353 353
 
354
-    $output = wpinv_html_select( array(
354
+    $output = wpinv_html_select(array(
355 355
         'name'             => $name,
356 356
         'selected'         => $selected,
357 357
         'options'          => $options,
358 358
         'show_option_all'  => false,
359 359
         'show_option_none' => false
360
-    ) );
360
+    ));
361 361
 
362 362
     return $output;
363 363
 }
364 364
 
365
-function wpinv_html_select( $args = array() ) {
365
+function wpinv_html_select($args = array()) {
366 366
     $defaults = array(
367 367
         'options'          => array(),
368 368
         'name'             => null,
@@ -372,8 +372,8 @@  discard block
 block discarded – undo
372 372
         'chosen'           => false,
373 373
         'placeholder'      => null,
374 374
         'multiple'         => false,
375
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
376
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
375
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
376
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
377 377
         'data'             => array(),
378 378
         'onchange'         => null,
379 379
         'required'         => false,
@@ -381,78 +381,78 @@  discard block
 block discarded – undo
381 381
         'readonly'         => false,
382 382
     );
383 383
 
384
-    $args = wp_parse_args( $args, $defaults );
384
+    $args = wp_parse_args($args, $defaults);
385 385
 
386 386
     $data_elements = '';
387
-    foreach ( $args['data'] as $key => $value ) {
388
-        $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
387
+    foreach ($args['data'] as $key => $value) {
388
+        $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
389 389
     }
390 390
 
391
-    if( $args['multiple'] ) {
391
+    if ($args['multiple']) {
392 392
         $multiple = ' MULTIPLE';
393 393
     } else {
394 394
         $multiple = '';
395 395
     }
396 396
 
397
-    if( $args['chosen'] ) {
397
+    if ($args['chosen']) {
398 398
         $args['class'] .= ' wpinv-select-chosen';
399 399
     }
400 400
 
401
-    if( $args['placeholder'] ) {
401
+    if ($args['placeholder']) {
402 402
         $placeholder = $args['placeholder'];
403 403
     } else {
404 404
         $placeholder = '';
405 405
     }
406 406
     
407 407
     $options = '';
408
-    if( !empty( $args['onchange'] ) ) {
409
-        $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"';
408
+    if (!empty($args['onchange'])) {
409
+        $options .= ' onchange="' . esc_attr($args['onchange']) . '"';
410 410
     }
411 411
     
412
-    if( !empty( $args['required'] ) ) {
412
+    if (!empty($args['required'])) {
413 413
         $options .= ' required="required"';
414 414
     }
415 415
     
416
-    if( !empty( $args['disabled'] ) ) {
416
+    if (!empty($args['disabled'])) {
417 417
         $options .= ' disabled';
418 418
     }
419 419
     
420
-    if( !empty( $args['readonly'] ) ) {
420
+    if (!empty($args['readonly'])) {
421 421
         $options .= ' readonly';
422 422
     }
423 423
 
424
-    $class  = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
425
-    $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>';
424
+    $class  = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
425
+    $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>';
426 426
 
427
-    if ( $args['show_option_all'] ) {
428
-        if( $args['multiple'] ) {
429
-            $selected = selected( true, in_array( 0, $args['selected'] ), false );
427
+    if ($args['show_option_all']) {
428
+        if ($args['multiple']) {
429
+            $selected = selected(true, in_array(0, $args['selected']), false);
430 430
         } else {
431
-            $selected = selected( $args['selected'], 0, false );
431
+            $selected = selected($args['selected'], 0, false);
432 432
         }
433
-        $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
433
+        $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>';
434 434
     }
435 435
 
436
-    if ( !empty( $args['options'] ) ) {
436
+    if (!empty($args['options'])) {
437 437
 
438
-        if ( $args['show_option_none'] ) {
439
-            if( $args['multiple'] ) {
440
-                $selected = selected( true, in_array( "", $args['selected'] ), false );
438
+        if ($args['show_option_none']) {
439
+            if ($args['multiple']) {
440
+                $selected = selected(true, in_array("", $args['selected']), false);
441 441
             } else {
442
-                $selected = selected( $args['selected'] === "", true, false );
442
+                $selected = selected($args['selected'] === "", true, false);
443 443
             }
444
-            $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
444
+            $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>';
445 445
         }
446 446
 
447
-        foreach( $args['options'] as $key => $option ) {
447
+        foreach ($args['options'] as $key => $option) {
448 448
 
449
-            if( $args['multiple'] && is_array( $args['selected'] ) ) {
450
-                $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false );
449
+            if ($args['multiple'] && is_array($args['selected'])) {
450
+                $selected = selected(true, (bool)in_array($key, $args['selected']), false);
451 451
             } else {
452
-                $selected = selected( $args['selected'], $key, false );
452
+                $selected = selected($args['selected'], $key, false);
453 453
             }
454 454
 
455
-            $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
455
+            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>';
456 456
         }
457 457
     }
458 458
 
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
     return $output;
462 462
 }
463 463
 
464
-function wpinv_item_dropdown( $args = array() ) {
464
+function wpinv_item_dropdown($args = array()) {
465 465
     $defaults = array(
466 466
         'name'              => 'wpi_item',
467 467
         'id'                => 'wpi_item',
@@ -470,15 +470,15 @@  discard block
 block discarded – undo
470 470
         'selected'          => 0,
471 471
         'chosen'            => false,
472 472
         'number'            => 100,
473
-        'placeholder'       => __( 'Choose a item', 'invoicing' ),
474
-        'data'              => array( 'search-type' => 'item' ),
473
+        'placeholder'       => __('Choose a item', 'invoicing'),
474
+        'data'              => array('search-type' => 'item'),
475 475
         'show_option_all'   => false,
476 476
         'show_option_none'  => false,
477 477
         'with_packages'     => true,
478 478
         'show_recurring'    => false,
479 479
     );
480 480
 
481
-    $args = wp_parse_args( $args, $defaults );
481
+    $args = wp_parse_args($args, $defaults);
482 482
 
483 483
     $item_args = array(
484 484
         'post_type'      => 'wpi_item',
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
         'posts_per_page' => $args['number']
488 488
     );
489 489
     
490
-    if ( !$args['with_packages'] ) {
490
+    if (!$args['with_packages']) {
491 491
         $item_args['meta_query'] = array(
492 492
             array(
493 493
                 'key'       => '_wpinv_type',
@@ -497,42 +497,42 @@  discard block
 block discarded – undo
497 497
         );
498 498
     }
499 499
 
500
-    $items      = get_posts( $item_args );
500
+    $items      = get_posts($item_args);
501 501
     $options    = array();
502
-    if ( $items ) {
503
-        foreach ( $items as $item ) {
504
-            $title = esc_html( $item->post_title );
502
+    if ($items) {
503
+        foreach ($items as $item) {
504
+            $title = esc_html($item->post_title);
505 505
             
506
-            if ( !empty( $args['show_recurring'] ) ) {
507
-                $title .= wpinv_get_item_suffix( $item->ID, false );
506
+            if (!empty($args['show_recurring'])) {
507
+                $title .= wpinv_get_item_suffix($item->ID, false);
508 508
             }
509 509
             
510
-            $options[ absint( $item->ID ) ] = $title;
510
+            $options[absint($item->ID)] = $title;
511 511
         }
512 512
     }
513 513
 
514 514
     // This ensures that any selected items are included in the drop down
515
-    if( is_array( $args['selected'] ) ) {
516
-        foreach( $args['selected'] as $item ) {
517
-            if( ! in_array( $item, $options ) ) {
518
-                $title = get_the_title( $item );
519
-                if ( !empty( $args['show_recurring'] ) ) {
520
-                    $title .= wpinv_get_item_suffix( $item, false );
515
+    if (is_array($args['selected'])) {
516
+        foreach ($args['selected'] as $item) {
517
+            if (!in_array($item, $options)) {
518
+                $title = get_the_title($item);
519
+                if (!empty($args['show_recurring'])) {
520
+                    $title .= wpinv_get_item_suffix($item, false);
521 521
                 }
522 522
                 $options[$item] = $title;
523 523
             }
524 524
         }
525
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
526
-        if ( ! in_array( $args['selected'], $options ) ) {
527
-            $title = get_the_title( $args['selected'] );
528
-            if ( !empty( $args['show_recurring'] ) ) {
529
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
525
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
526
+        if (!in_array($args['selected'], $options)) {
527
+            $title = get_the_title($args['selected']);
528
+            if (!empty($args['show_recurring'])) {
529
+                $title .= wpinv_get_item_suffix($args['selected'], false);
530 530
             }
531
-            $options[$args['selected']] = get_the_title( $args['selected'] );
531
+            $options[$args['selected']] = get_the_title($args['selected']);
532 532
         }
533 533
     }
534 534
 
535
-    $output = wpinv_html_select( array(
535
+    $output = wpinv_html_select(array(
536 536
         'name'             => $args['name'],
537 537
         'selected'         => $args['selected'],
538 538
         'id'               => $args['id'],
@@ -544,12 +544,12 @@  discard block
 block discarded – undo
544 544
         'show_option_all'  => $args['show_option_all'],
545 545
         'show_option_none' => $args['show_option_none'],
546 546
         'data'             => $args['data'],
547
-    ) );
547
+    ));
548 548
 
549 549
     return $output;
550 550
 }
551 551
 
552
-function wpinv_html_checkbox( $args = array() ) {
552
+function wpinv_html_checkbox($args = array()) {
553 553
     $defaults = array(
554 554
         'name'     => null,
555 555
         'current'  => null,
@@ -560,38 +560,38 @@  discard block
 block discarded – undo
560 560
         )
561 561
     );
562 562
 
563
-    $args = wp_parse_args( $args, $defaults );
563
+    $args = wp_parse_args($args, $defaults);
564 564
 
565
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
565
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
566 566
     $options = '';
567
-    if ( ! empty( $args['options']['disabled'] ) ) {
567
+    if (!empty($args['options']['disabled'])) {
568 568
         $options .= ' disabled="disabled"';
569
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
569
+    } elseif (!empty($args['options']['readonly'])) {
570 570
         $options .= ' readonly';
571 571
     }
572 572
 
573
-    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />';
573
+    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />';
574 574
 
575 575
     return $output;
576 576
 }
577 577
 
578
-function wpinv_html_text( $args = array() ) {
578
+function wpinv_html_text($args = array()) {
579 579
     // Backwards compatibility
580
-    if ( func_num_args() > 1 ) {
580
+    if (func_num_args() > 1) {
581 581
         $args = func_get_args();
582 582
 
583 583
         $name  = $args[0];
584
-        $value = isset( $args[1] ) ? $args[1] : '';
585
-        $label = isset( $args[2] ) ? $args[2] : '';
586
-        $desc  = isset( $args[3] ) ? $args[3] : '';
584
+        $value = isset($args[1]) ? $args[1] : '';
585
+        $label = isset($args[2]) ? $args[2] : '';
586
+        $desc  = isset($args[3]) ? $args[3] : '';
587 587
     }
588 588
 
589 589
     $defaults = array(
590 590
         'id'           => '',
591
-        'name'         => isset( $name )  ? $name  : 'text',
592
-        'value'        => isset( $value ) ? $value : null,
593
-        'label'        => isset( $label ) ? $label : null,
594
-        'desc'         => isset( $desc )  ? $desc  : null,
591
+        'name'         => isset($name) ? $name : 'text',
592
+        'value'        => isset($value) ? $value : null,
593
+        'label'        => isset($label) ? $label : null,
594
+        'desc'         => isset($desc) ? $desc : null,
595 595
         'placeholder'  => '',
596 596
         'class'        => 'regular-text',
597 597
         'disabled'     => false,
@@ -601,51 +601,51 @@  discard block
 block discarded – undo
601 601
         'data'         => false
602 602
     );
603 603
 
604
-    $args = wp_parse_args( $args, $defaults );
604
+    $args = wp_parse_args($args, $defaults);
605 605
 
606
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
606
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
607 607
     $options = '';
608
-    if( $args['required'] ) {
608
+    if ($args['required']) {
609 609
         $options .= ' required="required"';
610 610
     }
611
-    if( $args['readonly'] ) {
611
+    if ($args['readonly']) {
612 612
         $options .= ' readonly';
613 613
     }
614
-    if( $args['readonly'] ) {
614
+    if ($args['readonly']) {
615 615
         $options .= ' readonly';
616 616
     }
617 617
 
618 618
     $data = '';
619
-    if ( !empty( $args['data'] ) ) {
620
-        foreach ( $args['data'] as $key => $value ) {
621
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
619
+    if (!empty($args['data'])) {
620
+        foreach ($args['data'] as $key => $value) {
621
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
622 622
         }
623 623
     }
624 624
 
625
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
626
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
627
-    if ( ! empty( $args['desc'] ) ) {
628
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
625
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
626
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
627
+    if (!empty($args['desc'])) {
628
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
629 629
     }
630 630
 
631
-    $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] )  . '" autocomplete="' . esc_attr( $args['autocomplete'] )  . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>';
631
+    $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>';
632 632
 
633 633
     $output .= '</span>';
634 634
 
635 635
     return $output;
636 636
 }
637 637
 
638
-function wpinv_html_date_field( $args = array() ) {
639
-    if( empty( $args['class'] ) ) {
638
+function wpinv_html_date_field($args = array()) {
639
+    if (empty($args['class'])) {
640 640
         $args['class'] = 'wpiDatepicker';
641
-    } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) {
641
+    } elseif (!strpos($args['class'], 'wpiDatepicker')) {
642 642
         $args['class'] .= ' wpiDatepicker';
643 643
     }
644 644
 
645
-    return wpinv_html_text( $args );
645
+    return wpinv_html_text($args);
646 646
 }
647 647
 
648
-function wpinv_html_textarea( $args = array() ) {
648
+function wpinv_html_textarea($args = array()) {
649 649
     $defaults = array(
650 650
         'name'        => 'textarea',
651 651
         'value'       => null,
@@ -655,31 +655,31 @@  discard block
 block discarded – undo
655 655
         'disabled'    => false
656 656
     );
657 657
 
658
-    $args = wp_parse_args( $args, $defaults );
658
+    $args = wp_parse_args($args, $defaults);
659 659
 
660
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
660
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
661 661
     $disabled = '';
662
-    if( $args['disabled'] ) {
662
+    if ($args['disabled']) {
663 663
         $disabled = ' disabled="disabled"';
664 664
     }
665 665
 
666
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
667
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
668
-    $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
666
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
667
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
668
+    $output .= '<textarea name="' . esc_attr($args['name']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>';
669 669
 
670
-    if ( ! empty( $args['desc'] ) ) {
671
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
670
+    if (!empty($args['desc'])) {
671
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
672 672
     }
673 673
     $output .= '</span>';
674 674
 
675 675
     return $output;
676 676
 }
677 677
 
678
-function wpinv_html_ajax_user_search( $args = array() ) {
678
+function wpinv_html_ajax_user_search($args = array()) {
679 679
     $defaults = array(
680 680
         'name'        => 'user_id',
681 681
         'value'       => null,
682
-        'placeholder' => __( 'Enter username', 'invoicing' ),
682
+        'placeholder' => __('Enter username', 'invoicing'),
683 683
         'label'       => null,
684 684
         'desc'        => null,
685 685
         'class'       => '',
@@ -688,13 +688,13 @@  discard block
 block discarded – undo
688 688
         'data'        => false
689 689
     );
690 690
 
691
-    $args = wp_parse_args( $args, $defaults );
691
+    $args = wp_parse_args($args, $defaults);
692 692
 
693 693
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
694 694
 
695 695
     $output  = '<span class="wpinv_user_search_wrap">';
696
-        $output .= wpinv_html_text( $args );
697
-        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>';
696
+        $output .= wpinv_html_text($args);
697
+        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>';
698 698
     $output .= '</span>';
699 699
 
700 700
     return $output;
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
 function wpinv_ip_geolocation() {
704 704
     global $wpinv_euvat;
705 705
     
706
-    $ip         = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : '';    
706
+    $ip         = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : '';    
707 707
     $content    = '';
708 708
     $iso        = '';
709 709
     $country    = '';
@@ -714,69 +714,69 @@  discard block
 block discarded – undo
714 714
     $credit     = '';
715 715
     $address    = '';
716 716
     
717
-    if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) {
717
+    if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) {
718 718
         try {
719 719
             $iso        = $geoip2_city->country->isoCode;
720 720
             $country    = $geoip2_city->country->name;
721
-            $region     = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : '';
721
+            $region     = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : '';
722 722
             $city       = $geoip2_city->city->name;
723 723
             $longitude  = $geoip2_city->location->longitude;
724 724
             $latitude   = $geoip2_city->location->latitude;
725
-            $credit     = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' );
726
-        } catch( Exception $e ) { }
725
+            $credit     = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing');
726
+        } catch (Exception $e) { }
727 727
     }
728 728
     
729
-    if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) {
729
+    if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) {
730 730
         try {
731
-            $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
731
+            $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
732 732
             
733
-            if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) {
733
+            if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) {
734 734
                 $iso        = $load_xml->geoplugin_countryCode;
735 735
                 $country    = $load_xml->geoplugin_countryName;
736
-                $region     = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : '';
737
-                $city       = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : '';
736
+                $region     = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : '';
737
+                $city       = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : '';
738 738
                 $longitude  = $load_xml->geoplugin_longitude;
739 739
                 $latitude   = $load_xml->geoplugin_latitude;
740 740
                 $credit     = $load_xml->geoplugin_credit;
741
-                $credit     = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit;
741
+                $credit     = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit;
742 742
             }
743
-        } catch( Exception $e ) { }
743
+        } catch (Exception $e) { }
744 744
     }
745 745
     
746
-    if ( $iso && $longitude && $latitude ) {
747
-        if ( $city ) {
746
+    if ($iso && $longitude && $latitude) {
747
+        if ($city) {
748 748
             $address .= $city . ', ';
749 749
         }
750 750
         
751
-        if ( $region ) {
751
+        if ($region) {
752 752
             $address .= $region . ', ';
753 753
         }
754 754
         
755 755
         $address .= $country . ' (' . $iso . ')';
756
-        $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>';
757
-        $content .= '<p>'. $credit . '</p>';
756
+        $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>';
757
+        $content .= '<p>' . $credit . '</p>';
758 758
     } else {
759
-        $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>';
759
+        $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>';
760 760
     }
761 761
     ?>
762 762
 <!DOCTYPE html>
763
-<html><head><title><?php echo sprintf( __( 'IP: %s', 'invoicing' ), $ip );?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
763
+<html><head><title><?php echo sprintf(__('IP: %s', 'invoicing'), $ip); ?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
764 764
 <body>
765
-    <?php if ( $latitude && $latitude ) { ?>
765
+    <?php if ($latitude && $latitude) { ?>
766 766
     <div id="map"></div>
767 767
         <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script>
768 768
         <script type="text/javascript">
769 769
         var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
770 770
             osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
771 771
             osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}),
772
-            latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>);
772
+            latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>);
773 773
 
774 774
         var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]});
775 775
 
776 776
         var marker = new L.Marker(latlng);
777 777
         map.addLayer(marker);
778 778
 
779
-        marker.bindPopup("<p><?php esc_attr_e( $address );?></p>");
779
+        marker.bindPopup("<p><?php esc_attr_e($address); ?></p>");
780 780
     </script>
781 781
     <?php } ?>
782 782
     <div style="height:100px"><?php echo $content; ?></div>
@@ -784,31 +784,31 @@  discard block
 block discarded – undo
784 784
 <?php
785 785
     exit;
786 786
 }
787
-add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
788
-add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
787
+add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
788
+add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
789 789
 
790 790
 // Set up the template for the invoice.
791
-function wpinv_template( $template ) {
791
+function wpinv_template($template) {
792 792
     global $post, $wp_query;
793 793
     
794
-    if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) {
795
-        if ( wpinv_user_can_print_invoice( $post->ID ) ) {
796
-            $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false );
794
+    if ((is_single() || is_404()) && !empty($post->ID) && (get_post_type($post->ID) == 'wpi_invoice' or get_post_type($post->ID) == 'wpi_quote')) {
795
+        if (wpinv_user_can_print_invoice($post->ID)) {
796
+            $template = wpinv_get_template_part('wpinv-invoice-print', false, false);
797 797
         } else {
798
-            if ( !is_user_logged_in() && !empty( $_REQUEST['_wpipay'] ) && $invoice = wpinv_get_invoice( $post->ID ) ) {
798
+            if (!is_user_logged_in() && !empty($_REQUEST['_wpipay']) && $invoice = wpinv_get_invoice($post->ID)) {
799 799
                 $user_id = $invoice->get_user_id();
800
-                $secret = sanitize_text_field( $_GET['_wpipay'] );
800
+                $secret = sanitize_text_field($_GET['_wpipay']);
801 801
 
802
-                if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key() ) ) { // valid invoice link
803
-                    $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
802
+                if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key())) { // valid invoice link
803
+                    $redirect_to = remove_query_arg('_wpipay', get_permalink());
804 804
 
805
-                    wpinv_guest_redirect( $redirect_to, $user_id );
805
+                    wpinv_guest_redirect($redirect_to, $user_id);
806 806
                     wpinv_die();
807 807
                 }
808 808
             }
809
-            $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
809
+            $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
810 810
 
811
-            wp_redirect( $redirect_to );
811
+            wp_redirect($redirect_to);
812 812
             wpinv_die();
813 813
         }
814 814
     }
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
 
819 819
 function wpinv_get_business_address() {
820 820
     $business_address   = wpinv_store_address();
821
-    $business_address   = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
821
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
822 822
     
823 823
     /*
824 824
     $default_country    = wpinv_get_default_country();
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
     
843 843
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
844 844
     
845
-    return apply_filters( 'wpinv_get_business_address', $business_address );
845
+    return apply_filters('wpinv_get_business_address', $business_address);
846 846
 }
847 847
 
848 848
 function wpinv_display_from_address() {
@@ -852,185 +852,185 @@  discard block
 block discarded – undo
852 852
     if (empty($from_name)) {
853 853
         $from_name = wpinv_get_business_name();
854 854
     }
855
-    ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div>
855
+    ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div>
856 856
     <div class="wrapper col-xs-10">
857
-        <div class="name"><?php echo esc_html( $from_name ); ?></div>
858
-        <?php if ( $address = wpinv_get_business_address() ) { ?>
859
-        <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div>
857
+        <div class="name"><?php echo esc_html($from_name); ?></div>
858
+        <?php if ($address = wpinv_get_business_address()) { ?>
859
+        <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div>
860 860
         <?php } ?>
861
-        <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?>
862
-        <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s' ), $email_from );?></div>
861
+        <?php if ($email_from = wpinv_mail_get_from_address()) { ?>
862
+        <div class="email_from"><?php echo wp_sprintf(__('Email: %s'), $email_from); ?></div>
863 863
         <?php } ?>
864 864
     </div>
865 865
     <?php
866 866
 }
867 867
 
868
-function wpinv_watermark( $id = 0 ) {
869
-    $output = wpinv_get_watermark( $id );
868
+function wpinv_watermark($id = 0) {
869
+    $output = wpinv_get_watermark($id);
870 870
     
871
-    return apply_filters( 'wpinv_get_watermark', $output, $id );
871
+    return apply_filters('wpinv_get_watermark', $output, $id);
872 872
 }
873 873
 
874
-function wpinv_get_watermark( $id ) {
875
-    if ( !$id > 0 ) {
874
+function wpinv_get_watermark($id) {
875
+    if (!$id > 0) {
876 876
         return NULL;
877 877
     }
878
-    $invoice = wpinv_get_invoice( $id );
878
+    $invoice = wpinv_get_invoice($id);
879 879
     
880
-    if ( !empty( $invoice ) ) {
881
-        if ( $invoice->is_paid() ) {
882
-            return __( 'Paid', 'invoicing' );
880
+    if (!empty($invoice)) {
881
+        if ($invoice->is_paid()) {
882
+            return __('Paid', 'invoicing');
883 883
         }
884
-        if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) {
885
-            return __( 'Cancelled', 'invoicing' );
884
+        if ($invoice->has_status(array('wpi-cancelled'))) {
885
+            return __('Cancelled', 'invoicing');
886 886
         }
887 887
     }
888 888
     
889 889
     return NULL;
890 890
 }
891 891
 
892
-function wpinv_display_invoice_details( $invoice ) {
892
+function wpinv_display_invoice_details($invoice) {
893 893
     global $wpinv_euvat;
894 894
     
895 895
     $invoice_id = $invoice->ID;
896 896
     $vat_name   = $wpinv_euvat->get_vat_name();
897 897
     $use_taxes  = wpinv_use_taxes();
898 898
     
899
-    $invoice_status = wpinv_get_invoice_status( $invoice_id );
899
+    $invoice_status = wpinv_get_invoice_status($invoice_id);
900 900
     
901
-    if($invoice->post_type == 'wpi_invoice') $type = 'Invoice';
902
-    elseif($invoice->post_type == 'wpi_quote') $type = 'Quote';
901
+    if ($invoice->post_type == 'wpi_invoice') $type = 'Invoice';
902
+    elseif ($invoice->post_type == 'wpi_quote') $type = 'Quote';
903 903
     ?>
904 904
     <table class="table table-bordered table-sm">
905
-        <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?>
905
+        <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?>
906 906
             <tr class="wpi-row-number">
907
-                <th><?php echo sprintf(__( '%s Number', 'invoicing' ), $type); ?></th>
908
-                <td><?php echo esc_html( $invoice_number ); ?></td>
907
+                <th><?php echo sprintf(__('%s Number', 'invoicing'), $type); ?></th>
908
+                <td><?php echo esc_html($invoice_number); ?></td>
909 909
             </tr>
910 910
         <?php } ?>
911 911
         <tr class="wpi-row-status">
912
-            <th><?php echo wp_sprintf(__( '%s Status', 'invoicing' ), $type); ?></th>
913
-            <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td>
912
+            <th><?php echo wp_sprintf(__('%s Status', 'invoicing'), $type); ?></th>
913
+            <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td>
914 914
         </tr>
915
-        <?php if ( $invoice->is_renewal() ) { ?>
915
+        <?php if ($invoice->is_renewal()) { ?>
916 916
         <tr class="wpi-row-parent">
917
-            <th><?php echo wp_sprintf(__( 'Parent %s', 'invoicing' ), $type); ?></th>
918
-            <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td>
917
+            <th><?php echo wp_sprintf(__('Parent %s', 'invoicing'), $type); ?></th>
918
+            <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td>
919 919
         </tr>
920 920
         <?php } ?>
921 921
         <tr class="wpi-row-gateway">
922
-            <th><?php _e( 'Payment Method', 'invoicing' ); ?></th>
923
-            <td><?php echo wpinv_get_payment_gateway_name( $invoice_id ); ?></td>
922
+            <th><?php _e('Payment Method', 'invoicing'); ?></th>
923
+            <td><?php echo wpinv_get_payment_gateway_name($invoice_id); ?></td>
924 924
         </tr>
925
-        <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?>
925
+        <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?>
926 926
             <tr class="wpi-row-date">
927
-                <th><?php echo wp_sprintf(__( '%s Date', 'invoicing' ), $type); ?></th>
927
+                <th><?php echo wp_sprintf(__('%s Date', 'invoicing'), $type); ?></th>
928 928
                 <td><?php echo $invoice_date; ?></td>
929 929
             </tr>
930 930
         <?php } ?>
931
-        <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?>
931
+        <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?>
932 932
             <tr class="wpi-row-date">
933
-                <th><?php _e( 'Due Date', 'invoicing' ); ?></th>
933
+                <th><?php _e('Due Date', 'invoicing'); ?></th>
934 934
                 <td><?php echo $due_date; ?></td>
935 935
             </tr>
936 936
         <?php } ?>
937
-        <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?>
937
+        <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?>
938 938
             <tr class="wpi-row-ovatno">
939
-                <th><?php echo wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ); ?></th>
939
+                <th><?php echo wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name); ?></th>
940 940
                 <td><?php echo $owner_vat_number; ?></td>
941 941
             </tr>
942 942
         <?php } ?>
943
-        <?php if ( $use_taxes && $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) { ?>
943
+        <?php if ($use_taxes && $user_vat_number = wpinv_get_invoice_vat_number($invoice_id)) { ?>
944 944
             <tr class="wpi-row-uvatno">
945
-                <th><?php echo wp_sprintf( __( 'Your %s Number', 'invoicing' ), $vat_name ); ?></th>
945
+                <th><?php echo wp_sprintf(__('Your %s Number', 'invoicing'), $vat_name); ?></th>
946 946
                 <td><?php echo $user_vat_number; ?></td>
947 947
             </tr>
948 948
         <?php } ?>
949 949
         <tr class="table-active tr-total wpi-row-total">
950
-            <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th>
951
-            <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td>
950
+            <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th>
951
+            <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td>
952 952
         </tr>
953 953
     </table>
954 954
 <?php
955 955
 }
956 956
 
957
-function wpinv_display_to_address( $invoice_id = 0 ) {
958
-    $invoice = wpinv_get_invoice( $invoice_id );
957
+function wpinv_display_to_address($invoice_id = 0) {
958
+    $invoice = wpinv_get_invoice($invoice_id);
959 959
     
960
-    if ( empty( $invoice ) ) {
960
+    if (empty($invoice)) {
961 961
         return NULL;
962 962
     }
963 963
     
964 964
     $billing_details = $invoice->get_user_info();
965
-    $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>';
965
+    $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>';
966 966
     $output .= '<div class="wrapper col-xs-10">';
967 967
     
968 968
     ob_start();
969
-    do_action( 'wpinv_display_to_address_top', $invoice );
969
+    do_action('wpinv_display_to_address_top', $invoice);
970 970
     $output .= ob_get_clean();
971 971
     
972
-    $output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>';
973
-    if ( $company = $billing_details['company'] ) {
974
-        $output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>';
972
+    $output .= '<div class="name">' . esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])) . '</div>';
973
+    if ($company = $billing_details['company']) {
974
+        $output .= '<div class="company">' . wpautop(wp_kses_post($company)) . '</div>';
975 975
     }
976 976
     $address_row = '';
977
-    if ( $address = $billing_details['address'] ) {
978
-        $address_row .= wpautop( wp_kses_post( $address ) );
977
+    if ($address = $billing_details['address']) {
978
+        $address_row .= wpautop(wp_kses_post($address));
979 979
     }
980 980
     
981 981
     $address_fields = array();
982
-    if ( !empty( $billing_details['city'] ) ) {
982
+    if (!empty($billing_details['city'])) {
983 983
         $address_fields[] = $billing_details['city'];
984 984
     }
985 985
     
986
-    $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : '';
987
-    if ( !empty( $billing_details['state'] ) ) {
988
-        $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country );
986
+    $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : '';
987
+    if (!empty($billing_details['state'])) {
988
+        $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country);
989 989
     }
990 990
     
991
-    if ( !empty( $billing_country ) ) {
992
-        $address_fields[] = wpinv_country_name( $billing_country );
991
+    if (!empty($billing_country)) {
992
+        $address_fields[] = wpinv_country_name($billing_country);
993 993
     }
994 994
     
995
-    if ( !empty( $address_fields ) ) {
996
-        $address_fields = implode( ", ", $address_fields );
995
+    if (!empty($address_fields)) {
996
+        $address_fields = implode(", ", $address_fields);
997 997
         
998
-        if ( !empty( $billing_details['zip'] ) ) {
998
+        if (!empty($billing_details['zip'])) {
999 999
             $address_fields .= ' ' . $billing_details['zip'];
1000 1000
         }
1001 1001
         
1002
-        $address_row .= wpautop( wp_kses_post( $address_fields ) );
1002
+        $address_row .= wpautop(wp_kses_post($address_fields));
1003 1003
     }
1004 1004
     
1005
-    if ( $address_row ) {
1005
+    if ($address_row) {
1006 1006
         $output .= '<div class="address">' . $address_row . '</div>';
1007 1007
     }
1008 1008
     
1009
-    if ( $phone = $invoice->get_phone() ) {
1010
-        $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s' ), esc_html( $phone ) ) . '</div>';
1009
+    if ($phone = $invoice->get_phone()) {
1010
+        $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s'), esc_html($phone)) . '</div>';
1011 1011
     }
1012
-    if ( $email = $invoice->get_email() ) {
1013
-        $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' ), esc_html( $email ) ) . '</div>';
1012
+    if ($email = $invoice->get_email()) {
1013
+        $output .= '<div class="email">' . wp_sprintf(__('Email: %s'), esc_html($email)) . '</div>';
1014 1014
     }
1015 1015
     
1016 1016
     ob_start();
1017
-    do_action( 'wpinv_display_to_address_bottom', $invoice );
1017
+    do_action('wpinv_display_to_address_bottom', $invoice);
1018 1018
     $output .= ob_get_clean();
1019 1019
     
1020 1020
     $output .= '</div>';
1021
-    $output = apply_filters( 'wpinv_display_to_address', $output, $invoice );
1021
+    $output = apply_filters('wpinv_display_to_address', $output, $invoice);
1022 1022
 
1023 1023
     echo $output;
1024 1024
 }
1025 1025
 
1026
-function wpinv_display_line_items( $invoice_id = 0 ) {
1026
+function wpinv_display_line_items($invoice_id = 0) {
1027 1027
     global $wpinv_euvat, $ajax_cart_details;
1028
-    $invoice            = wpinv_get_invoice( $invoice_id );
1028
+    $invoice            = wpinv_get_invoice($invoice_id);
1029 1029
     $quantities_enabled = wpinv_item_quantities_enabled();
1030 1030
     $use_taxes          = wpinv_use_taxes();
1031 1031
     $zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
1032
-    $tax_label           = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' );
1033
-    $tax_title          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
1032
+    $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing');
1033
+    $tax_title          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
1034 1034
     
1035 1035
     $cart_details       = $invoice->get_cart_details();
1036 1036
     $ajax_cart_details  = $cart_details;
@@ -1039,68 +1039,68 @@  discard block
 block discarded – undo
1039 1039
     <table class="table table-sm table-bordered table-responsive">
1040 1040
         <thead>
1041 1041
             <tr>
1042
-                <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th>
1043
-                <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th>
1042
+                <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th>
1043
+                <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th>
1044 1044
                 <?php if ($quantities_enabled) { ?>
1045
-                    <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th>
1045
+                    <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th>
1046 1046
                 <?php } ?>
1047 1047
                 <?php if ($use_taxes && !$zero_tax) { ?>
1048 1048
                     <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th>
1049 1049
                 <?php } ?>
1050
-                <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th>
1050
+                <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th>
1051 1051
             </tr>
1052 1052
         </thead>
1053 1053
         <tbody>
1054 1054
         <?php 
1055
-            if ( !empty( $cart_details ) ) {
1056
-                do_action( 'wpinv_display_line_items_start', $invoice );
1055
+            if (!empty($cart_details)) {
1056
+                do_action('wpinv_display_line_items_start', $invoice);
1057 1057
                 
1058 1058
                 $count = 0;
1059 1059
                 $cols  = 3;
1060
-                foreach ( $cart_details as $key => $cart_item ) {
1061
-                    $item_id    = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : '';
1062
-                    $item_price = isset($cart_item["item_price"]) ? wpinv_format_amount( $cart_item["item_price"] ) : 0;
1063
-                    $line_total = isset($cart_item["subtotal"]) ? wpinv_format_amount( $cart_item["subtotal"] ) : 0;
1064
-                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1;
1060
+                foreach ($cart_details as $key => $cart_item) {
1061
+                    $item_id    = !empty($cart_item['id']) ? absint($cart_item['id']) : '';
1062
+                    $item_price = isset($cart_item["item_price"]) ? wpinv_format_amount($cart_item["item_price"]) : 0;
1063
+                    $line_total = isset($cart_item["subtotal"]) ? wpinv_format_amount($cart_item["subtotal"]) : 0;
1064
+                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1;
1065 1065
                     
1066
-                    $item       = $item_id ? new WPInv_Item( $item_id ) : NULL;
1066
+                    $item       = $item_id ? new WPInv_Item($item_id) : NULL;
1067 1067
                     $summary    = '';
1068 1068
                     $cols       = 3;
1069
-                    if ( !empty($item) ) {
1069
+                    if (!empty($item)) {
1070 1070
                         $item_name  = $item->get_name();
1071 1071
                         $summary    = $item->get_summary();
1072 1072
                     }
1073
-                    $item_name  = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1073
+                    $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1074 1074
                     
1075 1075
                     if (!empty($item) && $item->is_package() && !empty($cart_item['meta']['post_id'])) {
1076
-                        $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>';
1077
-                        $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $item->get_cpt_singular_name(), $post_link );
1076
+                        $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>';
1077
+                        $summary = wp_sprintf(__('%s: %s', 'invoicing'), $item->get_cpt_singular_name(), $post_link);
1078 1078
                     }
1079
-                    $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice );
1079
+                    $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice);
1080 1080
                     
1081 1081
                     $item_tax       = '';
1082 1082
                     $tax_rate       = '';
1083
-                    if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1084
-                        $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) );
1085
-                        $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1086
-                        $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount( $tax_rate, 2 ) : '';
1083
+                    if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1084
+                        $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']));
1085
+                        $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1086
+                        $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount($tax_rate, 2) : '';
1087 1087
                         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : '';
1088 1088
                     }
1089 1089
                     
1090 1090
                     $line_item_tax = $item_tax . $tax_rate;
1091 1091
                     
1092
-                    if ( $line_item_tax === '' ) {
1092
+                    if ($line_item_tax === '') {
1093 1093
                         $line_item_tax = 0; // Zero tax
1094 1094
                     }
1095 1095
                     
1096
-                    $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">';
1097
-                        $line_item .= '<td class="name">' . esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item );
1098
-                        if ( $summary !== '' ) {
1099
-                            $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>';
1096
+                    $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">';
1097
+                        $line_item .= '<td class="name">' . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item);
1098
+                        if ($summary !== '') {
1099
+                            $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>';
1100 1100
                         }
1101 1101
                         $line_item .= '</td>';
1102 1102
                         
1103
-                        $line_item .= '<td class="rate">' . esc_html__( wpinv_price( $item_price, $invoice->get_currency() ) ) . '</td>';
1103
+                        $line_item .= '<td class="rate">' . esc_html__(wpinv_price($item_price, $invoice->get_currency())) . '</td>';
1104 1104
                         if ($quantities_enabled) {
1105 1105
                             $cols++;
1106 1106
                             $line_item .= '<td class="qty">' . $quantity . '</td>';
@@ -1109,55 +1109,55 @@  discard block
 block discarded – undo
1109 1109
                             $cols++;
1110 1110
                             $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1111 1111
                         }
1112
-                        $line_item .= '<td class="total">' . esc_html__( wpinv_price( $line_total, $invoice->get_currency() ) ) . '</td>';
1112
+                        $line_item .= '<td class="total">' . esc_html__(wpinv_price($line_total, $invoice->get_currency())) . '</td>';
1113 1113
                     $line_item .= '</tr>';
1114 1114
                     
1115
-                    echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols );
1115
+                    echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols);
1116 1116
 
1117 1117
                     $count++;
1118 1118
                 }
1119 1119
                 
1120
-                do_action( 'wpinv_display_before_subtotal', $invoice, $cols );
1120
+                do_action('wpinv_display_before_subtotal', $invoice, $cols);
1121 1121
                 ?>
1122 1122
                 <tr class="row-sub-total row_odd">
1123
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1124
-                    <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1123
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1124
+                    <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1125 1125
                 </tr>
1126 1126
                 <?php
1127
-                do_action( 'wpinv_display_after_subtotal', $invoice, $cols );
1127
+                do_action('wpinv_display_after_subtotal', $invoice, $cols);
1128 1128
                 
1129
-                if ( wpinv_discount( $invoice_id, false ) > 0 ) {
1130
-                    do_action( 'wpinv_display_before_discount', $invoice, $cols );
1129
+                if (wpinv_discount($invoice_id, false) > 0) {
1130
+                    do_action('wpinv_display_before_discount', $invoice, $cols);
1131 1131
                     ?>
1132 1132
                         <tr class="row-discount">
1133
-                            <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td>
1134
-                            <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1133
+                            <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td>
1134
+                            <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1135 1135
                         </tr>
1136 1136
                     <?php
1137
-                    do_action( 'wpinv_display_after_discount', $invoice, $cols );
1137
+                    do_action('wpinv_display_after_discount', $invoice, $cols);
1138 1138
                 }
1139 1139
                 
1140
-                if ( $use_taxes ) {
1141
-                    do_action( 'wpinv_display_before_tax', $invoice, $cols );
1140
+                if ($use_taxes) {
1141
+                    do_action('wpinv_display_before_tax', $invoice, $cols);
1142 1142
                     ?>
1143 1143
                     <tr class="row-tax">
1144
-                        <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td>
1145
-                        <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1144
+                        <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td>
1145
+                        <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1146 1146
                     </tr>
1147 1147
                     <?php
1148
-                    do_action( 'wpinv_display_after_tax', $invoice, $cols );
1148
+                    do_action('wpinv_display_after_tax', $invoice, $cols);
1149 1149
                 }
1150 1150
                 
1151
-                do_action( 'wpinv_display_before_total', $invoice, $cols );
1151
+                do_action('wpinv_display_before_total', $invoice, $cols);
1152 1152
                 ?>
1153 1153
                 <tr class="table-active row-total">
1154
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1155
-                    <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1154
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1155
+                    <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1156 1156
                 </tr>
1157 1157
                 <?php
1158
-                do_action( 'wpinv_display_after_total', $invoice, $cols );
1158
+                do_action('wpinv_display_after_total', $invoice, $cols);
1159 1159
                 
1160
-                do_action( 'wpinv_display_line_end', $invoice, $cols );
1160
+                do_action('wpinv_display_line_end', $invoice, $cols);
1161 1161
             }
1162 1162
         ?>
1163 1163
         </tbody>
@@ -1166,35 +1166,35 @@  discard block
 block discarded – undo
1166 1166
     echo ob_get_clean();
1167 1167
 }
1168 1168
 
1169
-function wpinv_display_invoice_totals( $invoice_id = 0 ) {    
1169
+function wpinv_display_invoice_totals($invoice_id = 0) {    
1170 1170
     $use_taxes = wpinv_use_taxes();
1171 1171
     
1172
-    do_action( 'wpinv_before_display_totals_table', $invoice_id ); 
1172
+    do_action('wpinv_before_display_totals_table', $invoice_id); 
1173 1173
     ?>
1174 1174
     <table class="table table-sm table-bordered table-responsive">
1175 1175
         <tbody>
1176
-            <?php do_action( 'wpinv_before_display_totals' ); ?>
1176
+            <?php do_action('wpinv_before_display_totals'); ?>
1177 1177
             <tr class="row-sub-total">
1178
-                <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td>
1179
-                <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1178
+                <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td>
1179
+                <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1180 1180
             </tr>
1181
-            <?php do_action( 'wpinv_after_display_totals' ); ?>
1182
-            <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?>
1181
+            <?php do_action('wpinv_after_display_totals'); ?>
1182
+            <?php if (wpinv_discount($invoice_id, false) > 0) { ?>
1183 1183
                 <tr class="row-discount">
1184
-                    <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td>
1185
-                    <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1184
+                    <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td>
1185
+                    <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1186 1186
                 </tr>
1187
-            <?php do_action( 'wpinv_after_display_discount' ); ?>
1187
+            <?php do_action('wpinv_after_display_discount'); ?>
1188 1188
             <?php } ?>
1189
-            <?php if ( $use_taxes ) { ?>
1189
+            <?php if ($use_taxes) { ?>
1190 1190
             <tr class="row-tax">
1191
-                <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td>
1192
-                <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1191
+                <td class="rate"><?php _e('Tax', 'invoicing'); ?></td>
1192
+                <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1193 1193
             </tr>
1194
-            <?php do_action( 'wpinv_after_display_tax' ); ?>
1194
+            <?php do_action('wpinv_after_display_tax'); ?>
1195 1195
             <?php } ?>
1196
-            <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?>
1197
-                <?php foreach ( $fees as $fee ) { ?>
1196
+            <?php if ($fees = wpinv_get_fees($invoice_id)) { ?>
1197
+                <?php foreach ($fees as $fee) { ?>
1198 1198
                     <tr class="row-fee">
1199 1199
                         <td class="rate"><?php echo $fee['label']; ?></td>
1200 1200
                         <td class="total"><?php echo $fee['amount_display']; ?></td>
@@ -1202,72 +1202,72 @@  discard block
 block discarded – undo
1202 1202
                 <?php } ?>
1203 1203
             <?php } ?>
1204 1204
             <tr class="table-active row-total">
1205
-                <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td>
1206
-                <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1205
+                <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td>
1206
+                <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1207 1207
             </tr>
1208
-            <?php do_action( 'wpinv_after_totals' ); ?>
1208
+            <?php do_action('wpinv_after_totals'); ?>
1209 1209
         </tbody>
1210 1210
 
1211 1211
     </table>
1212 1212
 
1213
-    <?php do_action( 'wpinv_after_totals_table' );
1213
+    <?php do_action('wpinv_after_totals_table');
1214 1214
 }
1215 1215
 
1216
-function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) {
1217
-    $invoice = wpinv_get_invoice( $invoice_id );
1216
+function wpinv_display_payments_info($invoice_id = 0, $echo = true) {
1217
+    $invoice = wpinv_get_invoice($invoice_id);
1218 1218
     
1219 1219
     ob_start();
1220
-    do_action( 'wpinv_before_display_payments_info', $invoice_id );
1221
-    if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() ) {
1220
+    do_action('wpinv_before_display_payments_info', $invoice_id);
1221
+    if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid()) {
1222 1222
         ?>
1223 1223
         <div class="wpi-payment-info">
1224
-            <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p>
1225
-            <?php if ( $gateway_title ) { ?>
1226
-            <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p>
1224
+            <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p>
1225
+            <?php if ($gateway_title) { ?>
1226
+            <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p>
1227 1227
             <?php } ?>
1228 1228
         </div>
1229 1229
         <?php
1230 1230
     }
1231
-    do_action( 'wpinv_after_display_payments_info', $invoice_id );
1231
+    do_action('wpinv_after_display_payments_info', $invoice_id);
1232 1232
     $outout = ob_get_clean();
1233 1233
     
1234
-    if ( $echo ) {
1234
+    if ($echo) {
1235 1235
         echo $outout;
1236 1236
     } else {
1237 1237
         return $outout;
1238 1238
     }
1239 1239
 }
1240 1240
 
1241
-function wpinv_display_style( $invoice ) {
1242
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION );
1241
+function wpinv_display_style($invoice) {
1242
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION);
1243 1243
     
1244
-    wp_print_styles( 'open-sans' );
1245
-    wp_print_styles( 'wpinv-single-style' );
1244
+    wp_print_styles('open-sans');
1245
+    wp_print_styles('wpinv-single-style');
1246 1246
 }
1247
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
1247
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
1248 1248
 
1249 1249
 function wpinv_checkout_billing_details() {  
1250 1250
     $invoice_id = (int)wpinv_get_invoice_cart_id();
1251 1251
     if (empty($invoice_id)) {
1252
-        wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ );
1252
+        wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__);
1253 1253
         return null;
1254 1254
     }
1255 1255
     
1256
-    $invoice = wpinv_get_invoice_cart( $invoice_id );
1256
+    $invoice = wpinv_get_invoice_cart($invoice_id);
1257 1257
     if (empty($invoice)) {
1258
-        wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ );
1258
+        wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__);
1259 1259
         return null;
1260 1260
     }
1261 1261
     $user_id        = $invoice->get_user_id();
1262 1262
     $user_info      = $invoice->get_user_info();
1263
-    $address_info   = wpinv_get_user_address( $user_id );
1263
+    $address_info   = wpinv_get_user_address($user_id);
1264 1264
     
1265
-    if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) {
1265
+    if (empty($user_info['first_name']) && !empty($user_info['first_name'])) {
1266 1266
         $user_info['first_name'] = $user_info['first_name'];
1267 1267
         $user_info['last_name'] = $user_info['last_name'];
1268 1268
     }
1269 1269
     
1270
-    if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) {
1270
+    if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) {
1271 1271
         $user_info['country']   = $address_info['country'];
1272 1272
         $user_info['state']     = $address_info['state'];
1273 1273
         $user_info['city']      = $address_info['city'];
@@ -1283,103 +1283,103 @@  discard block
 block discarded – undo
1283 1283
         'address'
1284 1284
     );
1285 1285
     
1286
-    foreach ( $address_fields as $field ) {
1287
-        if ( empty( $user_info[$field] ) ) {
1286
+    foreach ($address_fields as $field) {
1287
+        if (empty($user_info[$field])) {
1288 1288
             $user_info[$field] = $address_info[$field];
1289 1289
         }
1290 1290
     }
1291 1291
     
1292
-    return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice );
1292
+    return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice);
1293 1293
 }
1294 1294
 
1295 1295
 function wpinv_admin_get_line_items($invoice = array()) {
1296 1296
     $item_quantities    = wpinv_item_quantities_enabled();
1297 1297
     $use_taxes          = wpinv_use_taxes();
1298 1298
     
1299
-    if ( empty( $invoice ) ) {
1299
+    if (empty($invoice)) {
1300 1300
         return NULL;
1301 1301
     }
1302 1302
     
1303 1303
     $cart_items = $invoice->get_cart_details();
1304
-    if ( empty( $cart_items ) ) {
1304
+    if (empty($cart_items)) {
1305 1305
         return NULL;
1306 1306
     }
1307 1307
     ob_start();
1308 1308
     
1309
-    do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice );
1309
+    do_action('wpinv_admin_before_line_items', $cart_items, $invoice);
1310 1310
     
1311 1311
     $count = 0;
1312
-    foreach ( $cart_items as $key => $cart_item ) {
1312
+    foreach ($cart_items as $key => $cart_item) {
1313 1313
         $item_id    = $cart_item['id'];
1314
-        $wpi_item   = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL;
1314
+        $wpi_item   = $item_id > 0 ? new WPInv_Item($item_id) : NULL;
1315 1315
         
1316 1316
         if (empty($wpi_item)) {
1317 1317
             continue;
1318 1318
         }
1319 1319
         
1320
-        $item_price     = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ) );
1321
-        $quantity       = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1322
-        $item_subtotal  = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ) );
1320
+        $item_price     = wpinv_price(wpinv_format_amount($cart_item['item_price']));
1321
+        $quantity       = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1322
+        $item_subtotal  = wpinv_price(wpinv_format_amount($cart_item['subtotal']));
1323 1323
         $can_remove     = true;
1324 1324
         
1325 1325
         $summary = '';
1326 1326
         if ($wpi_item->is_package() && !empty($cart_item['meta']['post_id'])) {
1327
-            $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>';
1328
-            $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_cpt_singular_name(), $post_link );
1327
+            $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>';
1328
+            $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_cpt_singular_name(), $post_link);
1329 1329
         }
1330
-        $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice );
1330
+        $summary = apply_filters('wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice);
1331 1331
         
1332 1332
         $item_tax       = '';
1333 1333
         $tax_rate       = '';
1334
-        if ( $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1335
-            $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) );
1336
-            $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1337
-            $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount( $tax_rate, 2 ) : '';
1334
+        if ($cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1335
+            $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']));
1336
+            $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1337
+            $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount($tax_rate, 2) : '';
1338 1338
             $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : '';
1339 1339
         }
1340 1340
         $line_item_tax = $item_tax . $tax_rate;
1341 1341
         
1342
-        if ( $line_item_tax === '' ) {
1342
+        if ($line_item_tax === '') {
1343 1343
             $line_item_tax = 0; // Zero tax
1344 1344
         }
1345 1345
 
1346
-        $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">';
1346
+        $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">';
1347 1347
             $line_item .= '<td class="id">' . $item_id . '</td>';
1348
-            $line_item .= '<td class="title"><a href="' . get_edit_post_link( $item_id ) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix( $wpi_item );
1349
-            if ( $summary !== '' ) {
1350
-                $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>';
1348
+            $line_item .= '<td class="title"><a href="' . get_edit_post_link($item_id) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix($wpi_item);
1349
+            if ($summary !== '') {
1350
+                $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>';
1351 1351
             }
1352 1352
             $line_item .= '</td>';
1353 1353
             $line_item .= '<td class="price">' . $item_price . '</td>';
1354 1354
             
1355
-            if ( $item_quantities ) {
1356
-                if ( count( $cart_items ) == 1 && $quantity <= 1 ) {
1355
+            if ($item_quantities) {
1356
+                if (count($cart_items) == 1 && $quantity <= 1) {
1357 1357
                     $can_remove = false;
1358 1358
                 }
1359 1359
                 $line_item .= '<td class="qty" data-quantity="' . $quantity . '">&nbsp;&times;&nbsp;' . $quantity . '</td>';
1360 1360
             } else {
1361
-                if ( count( $cart_items ) == 1 ) {
1361
+                if (count($cart_items) == 1) {
1362 1362
                     $can_remove = false;
1363 1363
                 }
1364 1364
             }
1365 1365
             $line_item .= '<td class="total">' . $item_subtotal . '</td>';
1366 1366
             
1367
-            if ( $use_taxes ) {
1367
+            if ($use_taxes) {
1368 1368
                 $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1369 1369
             }
1370 1370
             $line_item .= '<td class="action">';
1371
-            if ( !$invoice->is_paid() && $can_remove ) {
1371
+            if (!$invoice->is_paid() && $can_remove) {
1372 1372
                 $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>';
1373 1373
             }
1374 1374
             $line_item .= '</td>';
1375 1375
         $line_item .= '</tr>';
1376 1376
         
1377
-        echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice );
1377
+        echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice);
1378 1378
         
1379 1379
         $count++;
1380 1380
     } 
1381 1381
     
1382
-    do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice );
1382
+    do_action('wpinv_admin_after_line_items', $cart_items, $invoice);
1383 1383
     
1384 1384
     return ob_get_clean();
1385 1385
 }
@@ -1390,35 +1390,35 @@  discard block
 block discarded – undo
1390 1390
     // Set current invoice id.
1391 1391
     $wpi_checkout_id = wpinv_get_invoice_cart_id();
1392 1392
     
1393
-    $form_action  = esc_url( wpinv_get_checkout_uri() );
1393
+    $form_action = esc_url(wpinv_get_checkout_uri());
1394 1394
 
1395 1395
     ob_start();
1396 1396
         echo '<div id="wpinv_checkout_wrap">';
1397 1397
         
1398
-        if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) {
1398
+        if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) {
1399 1399
             ?>
1400 1400
             <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive">
1401
-                <?php do_action( 'wpinv_before_checkout_form' ); ?>
1401
+                <?php do_action('wpinv_before_checkout_form'); ?>
1402 1402
                 <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST">
1403 1403
                     <?php
1404
-                    do_action( 'wpinv_checkout_form_top' );
1405
-                    do_action( 'wpinv_checkout_billing_info' );
1406
-                    do_action( 'wpinv_checkout_cart' );
1407
-                    do_action( 'wpinv_payment_mode_select'  );
1408
-                    do_action( 'wpinv_checkout_form_bottom' )
1404
+                    do_action('wpinv_checkout_form_top');
1405
+                    do_action('wpinv_checkout_billing_info');
1406
+                    do_action('wpinv_checkout_cart');
1407
+                    do_action('wpinv_payment_mode_select');
1408
+                    do_action('wpinv_checkout_form_bottom')
1409 1409
                     ?>
1410 1410
                 </form>
1411
-                <?php do_action( 'wpinv_after_purchase_form' ); ?>
1411
+                <?php do_action('wpinv_after_purchase_form'); ?>
1412 1412
             </div><!--end #wpinv_checkout_form_wrap-->
1413 1413
         <?php
1414 1414
         } else {
1415
-            do_action( 'wpinv_cart_empty' );
1415
+            do_action('wpinv_cart_empty');
1416 1416
         }
1417 1417
         echo '</div><!--end #wpinv_checkout_wrap-->';
1418 1418
     return ob_get_clean();
1419 1419
 }
1420 1420
 
1421
-function wpinv_checkout_cart( $cart_details = array(), $echo = true ) {
1421
+function wpinv_checkout_cart($cart_details = array(), $echo = true) {
1422 1422
     global $ajax_cart_details;
1423 1423
     $ajax_cart_details = $cart_details;
1424 1424
     /*
@@ -1433,25 +1433,25 @@  discard block
 block discarded – undo
1433 1433
     }
1434 1434
     */
1435 1435
     ob_start();
1436
-    do_action( 'wpinv_before_checkout_cart' );
1436
+    do_action('wpinv_before_checkout_cart');
1437 1437
     echo '<div id="wpinv_checkout_cart_form" method="post">';
1438 1438
         echo '<div id="wpinv_checkout_cart_wrap">';
1439
-            wpinv_get_template_part( 'wpinv-checkout-cart' );
1439
+            wpinv_get_template_part('wpinv-checkout-cart');
1440 1440
         echo '</div>';
1441 1441
     echo '</div>';
1442
-    do_action( 'wpinv_after_checkout_cart' );
1442
+    do_action('wpinv_after_checkout_cart');
1443 1443
     $content = ob_get_clean();
1444 1444
     
1445
-    if ( $echo ) {
1445
+    if ($echo) {
1446 1446
         echo $content;
1447 1447
     } else {
1448 1448
         return $content;
1449 1449
     }
1450 1450
 }
1451
-add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 );
1451
+add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10);
1452 1452
 
1453 1453
 function wpinv_empty_cart_message() {
1454
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1454
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1455 1455
 }
1456 1456
 
1457 1457
 /**
@@ -1463,91 +1463,91 @@  discard block
 block discarded – undo
1463 1463
 function wpinv_empty_checkout_cart() {
1464 1464
 	echo wpinv_empty_cart_message();
1465 1465
 }
1466
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1466
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1467 1467
 
1468 1468
 function wpinv_save_cart_button() {
1469
-    if ( wpinv_is_cart_saving_disabled() )
1469
+    if (wpinv_is_cart_saving_disabled())
1470 1470
         return;
1471 1471
 ?>
1472
-    <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url( add_query_arg( 'wpi_action', 'save_cart' ) ); ?>"><?php _e( 'Save Cart', 'invoicing' ); ?></a>
1472
+    <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url(add_query_arg('wpi_action', 'save_cart')); ?>"><?php _e('Save Cart', 'invoicing'); ?></a>
1473 1473
 <?php
1474 1474
 }
1475 1475
 
1476 1476
 function wpinv_update_cart_button() {
1477
-    if ( !wpinv_item_quantities_enabled() )
1477
+    if (!wpinv_item_quantities_enabled())
1478 1478
         return;
1479 1479
 ?>
1480
-    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/>
1480
+    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/>
1481 1481
     <input type="hidden" name="wpi_action" value="update_cart"/>
1482 1482
 <?php
1483 1483
 }
1484 1484
 
1485 1485
 function wpinv_checkout_cart_columns() {
1486 1486
     $default = 3;
1487
-    if ( wpinv_item_quantities_enabled() ) {
1487
+    if (wpinv_item_quantities_enabled()) {
1488 1488
         $default++;
1489 1489
     }
1490 1490
     
1491
-    if ( wpinv_use_taxes() ) {
1491
+    if (wpinv_use_taxes()) {
1492 1492
         $default++;
1493 1493
     }
1494 1494
 
1495
-    return apply_filters( 'wpinv_checkout_cart_columns', $default );
1495
+    return apply_filters('wpinv_checkout_cart_columns', $default);
1496 1496
 }
1497 1497
 
1498 1498
 function wpinv_display_cart_messages() {
1499 1499
     global $wpi_session;
1500 1500
 
1501
-    $messages = $wpi_session->get( 'wpinv_cart_messages' );
1501
+    $messages = $wpi_session->get('wpinv_cart_messages');
1502 1502
 
1503
-    if ( $messages ) {
1504
-        foreach ( $messages as $message_id => $message ) {
1503
+    if ($messages) {
1504
+        foreach ($messages as $message_id => $message) {
1505 1505
             // Try and detect what type of message this is
1506
-            if ( strpos( strtolower( $message ), 'error' ) ) {
1506
+            if (strpos(strtolower($message), 'error')) {
1507 1507
                 $type = 'error';
1508
-            } elseif ( strpos( strtolower( $message ), 'success' ) ) {
1508
+            } elseif (strpos(strtolower($message), 'success')) {
1509 1509
                 $type = 'success';
1510 1510
             } else {
1511 1511
                 $type = 'info';
1512 1512
             }
1513 1513
 
1514
-            $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) );
1514
+            $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type));
1515 1515
 
1516
-            echo '<div class="' . implode( ' ', $classes ) . '">';
1516
+            echo '<div class="' . implode(' ', $classes) . '">';
1517 1517
                 // Loop message codes and display messages
1518 1518
                     echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>';
1519 1519
             echo '</div>';
1520 1520
         }
1521 1521
 
1522 1522
         // Remove all of the cart saving messages
1523
-        $wpi_session->set( 'wpinv_cart_messages', null );
1523
+        $wpi_session->set('wpinv_cart_messages', null);
1524 1524
     }
1525 1525
 }
1526
-add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' );
1526
+add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages');
1527 1527
 
1528 1528
 function wpinv_discount_field() {
1529
-    if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) {
1529
+    if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) {
1530 1530
         return; // Only show before a payment method has been selected if ajax is disabled
1531 1531
     }
1532 1532
 
1533
-    if ( !wpinv_is_checkout() ) {
1533
+    if (!wpinv_is_checkout()) {
1534 1534
         return;
1535 1535
     }
1536 1536
 
1537
-    if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) {
1537
+    if (wpinv_has_active_discounts() && wpinv_get_cart_total()) {
1538 1538
     ?>
1539 1539
     <div id="wpinv-discount-field" class="panel panel-default">
1540 1540
         <div class="panel-body">
1541 1541
             <p>
1542
-                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label>
1543
-                <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span>
1542
+                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label>
1543
+                <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span>
1544 1544
             </p>
1545 1545
             <div class="form-group row">
1546 1546
                 <div class="col-sm-4">
1547
-                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/>
1547
+                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/>
1548 1548
                 </div>
1549 1549
                 <div class="col-sm-3">
1550
-                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button>
1550
+                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button>
1551 1551
                 </div>
1552 1552
                 <div class="col-sm-12 wpinv-discount-msg">
1553 1553
                     <div class="alert alert-success"><i class="fa fa-check-circle"></i><span class="wpi-msg"></span></div>
@@ -1559,10 +1559,10 @@  discard block
 block discarded – undo
1559 1559
 <?php
1560 1560
     }
1561 1561
 }
1562
-add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 );
1562
+add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10);
1563 1563
 
1564 1564
 function wpinv_agree_to_terms_js() {
1565
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
1565
+    if (wpinv_get_option('show_agree_to_terms', false)) {
1566 1566
 ?>
1567 1567
 <script type="text/javascript">
1568 1568
     jQuery(document).ready(function($){
@@ -1577,124 +1577,124 @@  discard block
 block discarded – undo
1577 1577
 <?php
1578 1578
     }
1579 1579
 }
1580
-add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' );
1580
+add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js');
1581 1581
 
1582 1582
 function wpinv_payment_mode_select() {
1583
-    $gateways = wpinv_get_enabled_payment_gateways( true );
1584
-    $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways );
1583
+    $gateways = wpinv_get_enabled_payment_gateways(true);
1584
+    $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways);
1585 1585
     $page_URL = wpinv_get_current_page_url();
1586 1586
     
1587 1587
     do_action('wpinv_payment_mode_top');
1588 1588
     $invoice_id = (int)wpinv_get_invoice_cart_id();
1589 1589
     ?>
1590 1590
     <div id="wpinv_payment_mode_select">
1591
-            <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?>
1591
+            <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?>
1592 1592
             <div id="wpinv-payment-mode-wrap" class="panel panel-default">
1593
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div>
1593
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div>
1594 1594
                 <div class="panel-body list-group wpi-payment_methods">
1595 1595
                     <?php
1596
-                    do_action( 'wpinv_payment_mode_before_gateways' );
1597
-                    $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id );
1596
+                    do_action('wpinv_payment_mode_before_gateways');
1597
+                    $chosen_gateway = wpinv_get_chosen_gateway($invoice_id);
1598 1598
                     
1599
-                    if(!empty($gateways)){
1600
-	                    foreach ( $gateways as $gateway_id => $gateway ) {
1601
-		                    $checked = checked( $gateway_id, $chosen_gateway, false );
1602
-		                    $button_label = wpinv_get_gateway_button_label( $gateway_id );
1603
-		                    $description = wpinv_get_gateway_description( $gateway_id );
1599
+                    if (!empty($gateways)) {
1600
+	                    foreach ($gateways as $gateway_id => $gateway) {
1601
+		                    $checked = checked($gateway_id, $chosen_gateway, false);
1602
+		                    $button_label = wpinv_get_gateway_button_label($gateway_id);
1603
+		                    $description = wpinv_get_gateway_description($gateway_id);
1604 1604
 		                    ?>
1605 1605
 		                    <div class="list-group-item">
1606 1606
 			                    <div class="radio">
1607
-				                    <label><input type="radio" data-button-text="<?php echo esc_attr( $button_label );?>" value="<?php echo esc_attr( $gateway_id ) ;?>" <?php echo $checked ;?> id="wpi_gateway_<?php echo esc_attr( $gateway_id );?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html( $gateway['checkout_label'] ); ?></label>
1607
+				                    <label><input type="radio" data-button-text="<?php echo esc_attr($button_label); ?>" value="<?php echo esc_attr($gateway_id); ?>" <?php echo $checked; ?> id="wpi_gateway_<?php echo esc_attr($gateway_id); ?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html($gateway['checkout_label']); ?></label>
1608 1608
 			                    </div>
1609
-			                    <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert">
1610
-				                    <?php if ( !empty( $description ) ) { ?>
1611
-					                    <div class="wpi-gateway-desc alert alert-info"><?php echo $description;?></div>
1609
+			                    <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert">
1610
+				                    <?php if (!empty($description)) { ?>
1611
+					                    <div class="wpi-gateway-desc alert alert-info"><?php echo $description; ?></div>
1612 1612
 				                    <?php } ?>
1613
-				                    <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?>
1613
+				                    <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?>
1614 1614
 			                    </div>
1615 1615
 		                    </div>
1616 1616
 		                    <?php
1617 1617
 	                    }
1618
-                    }else{
1619
-	                    echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>';
1618
+                    } else {
1619
+	                    echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>';
1620 1620
                     }
1621 1621
 
1622
-                    do_action( 'wpinv_payment_mode_after_gateways' );
1622
+                    do_action('wpinv_payment_mode_after_gateways');
1623 1623
                     ?>
1624 1624
                 </div>
1625 1625
             </div>
1626
-            <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?>
1626
+            <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?>
1627 1627
     </div>
1628 1628
     <?php
1629 1629
     do_action('wpinv_payment_mode_bottom');
1630 1630
 }
1631
-add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' );
1631
+add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select');
1632 1632
 
1633 1633
 function wpinv_checkout_billing_info() {    
1634
-    if ( wpinv_is_checkout() ) {
1634
+    if (wpinv_is_checkout()) {
1635 1635
         $logged_in          = is_user_logged_in();
1636 1636
         $billing_details    = wpinv_checkout_billing_details();
1637
-        $selected_country   = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country();
1637
+        $selected_country   = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country();
1638 1638
         ?>
1639 1639
         <div id="wpinv-fields" class="clearfix">
1640 1640
             <div id="wpi-billing" class="wpi-billing clearfix panel panel-default">
1641
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div>
1641
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div>
1642 1642
                 <div id="wpinv-fields-box" class="panel-body">
1643
-                    <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?>
1643
+                    <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?>
1644 1644
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1645
-                        <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><span class="wpi-required">*</span></label>
1645
+                        <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><span class="wpi-required">*</span></label>
1646 1646
                         <?php
1647
-                        echo wpinv_html_text( array(
1647
+                        echo wpinv_html_text(array(
1648 1648
                                 'id'            => 'wpinv_first_name',
1649 1649
                                 'name'          => 'wpinv_first_name',
1650 1650
                                 'value'         => $billing_details['first_name'],
1651 1651
                                 'class'         => 'wpi-input form-control required',
1652
-                                'placeholder'   => __( 'First name', 'invoicing' ),
1652
+                                'placeholder'   => __('First name', 'invoicing'),
1653 1653
                                 'required'      => true,
1654
-                            ) );
1654
+                            ));
1655 1655
                         ?>
1656 1656
                     </p>
1657 1657
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1658
-                        <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?></label>
1658
+                        <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?></label>
1659 1659
                         <?php
1660
-                        echo wpinv_html_text( array(
1660
+                        echo wpinv_html_text(array(
1661 1661
                                 'id'            => 'wpinv_last_name',
1662 1662
                                 'name'          => 'wpinv_last_name',
1663 1663
                                 'value'         => $billing_details['last_name'],
1664 1664
                                 'class'         => 'wpi-input form-control',
1665
-                                'placeholder'   => __( 'Last name', 'invoicing' ),
1666
-                            ) );
1665
+                                'placeholder'   => __('Last name', 'invoicing'),
1666
+                            ));
1667 1667
                         ?>
1668 1668
                     </p>
1669 1669
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1670
-                        <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><span class="wpi-required">*</span></label>
1670
+                        <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><span class="wpi-required">*</span></label>
1671 1671
                         <?php
1672
-                        echo wpinv_html_text( array(
1672
+                        echo wpinv_html_text(array(
1673 1673
                                 'id'            => 'wpinv_address',
1674 1674
                                 'name'          => 'wpinv_address',
1675 1675
                                 'value'         => $billing_details['address'],
1676 1676
                                 'class'         => 'wpi-input form-control required',
1677
-                                'placeholder'   => __( 'Address', 'invoicing' ),
1677
+                                'placeholder'   => __('Address', 'invoicing'),
1678 1678
                                 'required'      => true,
1679
-                            ) );
1679
+                            ));
1680 1680
                         ?>
1681 1681
                     </p>
1682 1682
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1683
-                        <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><span class="wpi-required">*</span></label>
1683
+                        <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><span class="wpi-required">*</span></label>
1684 1684
                         <?php
1685
-                        echo wpinv_html_text( array(
1685
+                        echo wpinv_html_text(array(
1686 1686
                                 'id'            => 'wpinv_city',
1687 1687
                                 'name'          => 'wpinv_city',
1688 1688
                                 'value'         => $billing_details['city'],
1689 1689
                                 'class'         => 'wpi-input form-control required',
1690
-                                'placeholder'   => __( 'City', 'invoicing' ),
1690
+                                'placeholder'   => __('City', 'invoicing'),
1691 1691
                                 'required'      => true,
1692
-                            ) );
1692
+                            ));
1693 1693
                         ?>
1694 1694
                     </p>
1695 1695
                     <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf">
1696
-                        <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><span class="wpi-required">*</span></label>
1697
-                        <?php echo wpinv_html_select( array(
1696
+                        <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><span class="wpi-required">*</span></label>
1697
+                        <?php echo wpinv_html_select(array(
1698 1698
                             'options'          => wpinv_get_country_list(),
1699 1699
                             'name'             => 'wpinv_country',
1700 1700
                             'id'               => 'wpinv_country',
@@ -1702,16 +1702,16 @@  discard block
 block discarded – undo
1702 1702
                             'show_option_all'  => false,
1703 1703
                             'show_option_none' => false,
1704 1704
                             'class'            => 'wpi-input form-control required',
1705
-                            'placeholder'      => __( 'Choose a country', 'invoicing' ),
1705
+                            'placeholder'      => __('Choose a country', 'invoicing'),
1706 1706
                             'required'          => true,
1707
-                        ) ); ?>
1707
+                        )); ?>
1708 1708
                     </p>
1709 1709
                     <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll">
1710
-                        <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><span class="wpi-required">*</span></label>
1710
+                        <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><span class="wpi-required">*</span></label>
1711 1711
                         <?php
1712
-                        $states = wpinv_get_country_states( $selected_country );
1713
-                        if( !empty( $states ) ) {
1714
-                            echo wpinv_html_select( array(
1712
+                        $states = wpinv_get_country_states($selected_country);
1713
+                        if (!empty($states)) {
1714
+                            echo wpinv_html_select(array(
1715 1715
                                 'options'          => $states,
1716 1716
                                 'name'             => 'wpinv_state',
1717 1717
                                 'id'               => 'wpinv_state',
@@ -1719,60 +1719,60 @@  discard block
 block discarded – undo
1719 1719
                                 'show_option_all'  => false,
1720 1720
                                 'show_option_none' => false,
1721 1721
                                 'class'            => 'wpi-input form-control required',
1722
-                                'placeholder'      => __( 'Choose a state', 'invoicing' ),
1722
+                                'placeholder'      => __('Choose a state', 'invoicing'),
1723 1723
                                 'required'         => true,
1724
-                            ) );
1724
+                            ));
1725 1725
                         } else {
1726
-                            echo wpinv_html_text( array(
1726
+                            echo wpinv_html_text(array(
1727 1727
                                 'name'          => 'wpinv_state',
1728 1728
                                 'value'         => $billing_details['state'],
1729 1729
                                 'id'            => 'wpinv_state',
1730 1730
                                 'class'         => 'wpi-input form-control required',
1731
-                                'placeholder'   => __( 'State / Province', 'invoicing' ),
1731
+                                'placeholder'   => __('State / Province', 'invoicing'),
1732 1732
                                 'required'      => true,
1733
-                            ) );
1733
+                            ));
1734 1734
                         }
1735 1735
                         ?>
1736 1736
                     </p>
1737 1737
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1738
-                        <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?></label>
1738
+                        <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?></label>
1739 1739
                         <?php
1740
-                        echo wpinv_html_text( array(
1740
+                        echo wpinv_html_text(array(
1741 1741
                                 'name'          => 'wpinv_zip',
1742 1742
                                 'value'         => $billing_details['zip'],
1743 1743
                                 'id'            => 'wpinv_zip',
1744 1744
                                 'class'         => 'wpi-input form-control',
1745
-                                'placeholder'   => __( 'ZIP / Postcode', 'invoicing' ),
1746
-                            ) );
1745
+                                'placeholder'   => __('ZIP / Postcode', 'invoicing'),
1746
+                            ));
1747 1747
                         ?>
1748 1748
                     </p>
1749 1749
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1750
-                        <label for="wpinv_phone" class="wpi-label"><?php _e( 'Phone', 'invoicing' );?><?php if ( wpinv_get_option( 'phone_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1750
+                        <label for="wpinv_phone" class="wpi-label"><?php _e('Phone', 'invoicing'); ?><?php if (wpinv_get_option('phone_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1751 1751
                         <?php
1752
-                        echo wpinv_html_text( array(
1752
+                        echo wpinv_html_text(array(
1753 1753
                                 'id'            => 'wpinv_phone',
1754 1754
                                 'name'          => 'wpinv_phone',
1755 1755
                                 'value'         => $billing_details['phone'],
1756 1756
                                 'class'         => 'wpi-input form-control',
1757
-                                'placeholder'   => __( 'Phone', 'invoicing' ),
1758
-                                'required'      => (bool)wpinv_get_option( 'phone_mandatory' ),
1759
-                            ) );
1757
+                                'placeholder'   => __('Phone', 'invoicing'),
1758
+                                'required'      => (bool)wpinv_get_option('phone_mandatory'),
1759
+                            ));
1760 1760
                         ?>
1761 1761
                     </p>
1762
-                    <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?>
1762
+                    <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?>
1763 1763
                     <div class="clearfix"></div>
1764 1764
                 </div>
1765 1765
             </div>
1766
-            <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?>
1766
+            <?php do_action('wpinv_after_billing_fields', $billing_details); ?>
1767 1767
         </div>
1768 1768
         <?php
1769 1769
     }
1770 1770
 }
1771
-add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' );
1771
+add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info');
1772 1772
 
1773 1773
 function wpinv_checkout_hidden_fields() {
1774 1774
 ?>
1775
-    <?php if ( is_user_logged_in() ) { ?>
1775
+    <?php if (is_user_logged_in()) { ?>
1776 1776
     <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/>
1777 1777
     <?php } ?>
1778 1778
     <input type="hidden" name="wpi_action" value="payment" />
@@ -1782,9 +1782,9 @@  discard block
 block discarded – undo
1782 1782
 function wpinv_checkout_button_purchase() {
1783 1783
     ob_start();
1784 1784
 ?>
1785
-    <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>" name="wpinv_payment" value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>"/>
1785
+    <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>" name="wpinv_payment" value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>"/>
1786 1786
 <?php
1787
-    return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() );
1787
+    return apply_filters('wpinv_checkout_button_purchase', ob_get_clean());
1788 1788
 }
1789 1789
 
1790 1790
 function wpinv_checkout_total() {
@@ -1793,96 +1793,96 @@  discard block
 block discarded – undo
1793 1793
 <div id="wpinv_checkout_total" class="panel panel-info">
1794 1794
     <div class="panel-body">
1795 1795
     <?php
1796
-    do_action( 'wpinv_purchase_form_before_checkout_total' );
1796
+    do_action('wpinv_purchase_form_before_checkout_total');
1797 1797
     ?>
1798
-    <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span>
1798
+    <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span>
1799 1799
     <?php
1800
-    do_action( 'wpinv_purchase_form_after_checkout_total' );
1800
+    do_action('wpinv_purchase_form_after_checkout_total');
1801 1801
     ?>
1802 1802
     </div>
1803 1803
 </div>
1804 1804
 <?php
1805 1805
 }
1806
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 );
1806
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998);
1807 1807
 
1808 1808
 function wpinv_checkout_submit() {
1809 1809
 ?>
1810 1810
 <div id="wpinv_purchase_submit" class="panel panel-success">
1811 1811
     <div class="panel-body text-center">
1812 1812
     <?php
1813
-    do_action( 'wpinv_purchase_form_before_submit' );
1813
+    do_action('wpinv_purchase_form_before_submit');
1814 1814
     wpinv_checkout_hidden_fields();
1815 1815
     echo wpinv_checkout_button_purchase();
1816
-    do_action( 'wpinv_purchase_form_after_submit' );
1816
+    do_action('wpinv_purchase_form_after_submit');
1817 1817
     ?>
1818 1818
     </div>
1819 1819
 </div>
1820 1820
 <?php
1821 1821
 }
1822
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 );
1822
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999);
1823 1823
 
1824
-function wpinv_receipt_billing_address( $invoice_id = 0 ) {
1825
-    $invoice = wpinv_get_invoice( $invoice_id );
1824
+function wpinv_receipt_billing_address($invoice_id = 0) {
1825
+    $invoice = wpinv_get_invoice($invoice_id);
1826 1826
     
1827
-    if ( empty( $invoice ) ) {
1827
+    if (empty($invoice)) {
1828 1828
         return NULL;
1829 1829
     }
1830 1830
     
1831 1831
     $billing_details = $invoice->get_user_info();
1832 1832
     $address_row = '';
1833
-    if ( $address = $billing_details['address'] ) {
1834
-        $address_row .= wpautop( wp_kses_post( $address ) );
1833
+    if ($address = $billing_details['address']) {
1834
+        $address_row .= wpautop(wp_kses_post($address));
1835 1835
     }
1836 1836
     
1837 1837
     $address_fields = array();
1838
-    if ( !empty( $billing_details['city'] ) ) {
1838
+    if (!empty($billing_details['city'])) {
1839 1839
         $address_fields[] = $billing_details['city'];
1840 1840
     }
1841 1841
     
1842
-    $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : '';
1843
-    if ( !empty( $billing_details['state'] ) ) {
1844
-        $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country );
1842
+    $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : '';
1843
+    if (!empty($billing_details['state'])) {
1844
+        $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country);
1845 1845
     }
1846 1846
     
1847
-    if ( !empty( $billing_country ) ) {
1848
-        $address_fields[] = wpinv_country_name( $billing_country );
1847
+    if (!empty($billing_country)) {
1848
+        $address_fields[] = wpinv_country_name($billing_country);
1849 1849
     }
1850 1850
     
1851
-    if ( !empty( $address_fields ) ) {
1852
-        $address_fields = implode( ", ", $address_fields );
1851
+    if (!empty($address_fields)) {
1852
+        $address_fields = implode(", ", $address_fields);
1853 1853
         
1854
-        if ( !empty( $billing_details['zip'] ) ) {
1854
+        if (!empty($billing_details['zip'])) {
1855 1855
             $address_fields .= ' ' . $billing_details['zip'];
1856 1856
         }
1857 1857
         
1858
-        $address_row .= wpautop( wp_kses_post( $address_fields ) );
1858
+        $address_row .= wpautop(wp_kses_post($address_fields));
1859 1859
     }
1860 1860
     ob_start();
1861 1861
     ?>
1862 1862
     <table class="table table-bordered table-sm wpi-billing-details">
1863 1863
         <tbody>
1864 1864
             <tr class="wpi-receipt-name">
1865
-                <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th>
1866
-                <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td>
1865
+                <th class="text-left"><?php _e('Name', 'invoicing'); ?></th>
1866
+                <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td>
1867 1867
             </tr>
1868 1868
             <tr class="wpi-receipt-email">
1869
-                <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th>
1870
-                <td><?php echo $billing_details['email'] ;?></td>
1869
+                <th class="text-left"><?php _e('Email', 'invoicing'); ?></th>
1870
+                <td><?php echo $billing_details['email']; ?></td>
1871 1871
             </tr>
1872
-            <?php if ( $billing_details['company'] ) { ?>
1872
+            <?php if ($billing_details['company']) { ?>
1873 1873
             <tr class="wpi-receipt-company">
1874
-                <th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th>
1875
-                <td><?php echo esc_html( $billing_details['company'] ) ;?></td>
1874
+                <th class="text-left"><?php _e('Company', 'invoicing'); ?></th>
1875
+                <td><?php echo esc_html($billing_details['company']); ?></td>
1876 1876
             </tr>
1877 1877
             <?php } ?>
1878 1878
             <tr class="wpi-receipt-address">
1879
-                <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th>
1880
-                <td><?php echo $address_row ;?></td>
1879
+                <th class="text-left"><?php _e('Address', 'invoicing'); ?></th>
1880
+                <td><?php echo $address_row; ?></td>
1881 1881
             </tr>
1882
-            <?php if ( $billing_details['phone'] ) { ?>
1882
+            <?php if ($billing_details['phone']) { ?>
1883 1883
             <tr class="wpi-receipt-phone">
1884
-                <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th>
1885
-                <td><?php echo esc_html( $billing_details['phone'] ) ;?></td>
1884
+                <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th>
1885
+                <td><?php echo esc_html($billing_details['phone']); ?></td>
1886 1886
             </tr>
1887 1887
             <?php } ?>
1888 1888
         </tbody>
@@ -1890,98 +1890,98 @@  discard block
 block discarded – undo
1890 1890
     <?php
1891 1891
     $output = ob_get_clean();
1892 1892
     
1893
-    $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id );
1893
+    $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id);
1894 1894
 
1895 1895
     echo $output;
1896 1896
 }
1897 1897
 
1898
-function wpinv_filter_success_page_content( $content ) {
1899
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1900
-        if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) {
1901
-            $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content );
1898
+function wpinv_filter_success_page_content($content) {
1899
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1900
+        if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) {
1901
+            $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content);
1902 1902
         }
1903 1903
     }
1904 1904
 
1905 1905
     return $content;
1906 1906
 }
1907
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1907
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1908 1908
 
1909
-function wpinv_receipt_actions( $invoice ) {
1910
-    if ( !empty( $invoice ) ) {
1909
+function wpinv_receipt_actions($invoice) {
1910
+    if (!empty($invoice)) {
1911 1911
         $actions = array(
1912 1912
             'print'   => array(
1913 1913
                 'url'  => $invoice->get_view_url(),
1914
-                'name' => __( 'Print Invoice', 'invoicing' ),
1914
+                'name' => __('Print Invoice', 'invoicing'),
1915 1915
                 'class' => 'btn-primary',
1916 1916
             ),
1917 1917
             'history'   => array(
1918 1918
                 'url'  => wpinv_get_history_page_uri(),
1919
-                'name' => __( 'Invoice History', 'invoicing' ),
1919
+                'name' => __('Invoice History', 'invoicing'),
1920 1920
                 'class' => 'btn-warning',
1921 1921
             )
1922 1922
         );
1923 1923
 
1924
-        $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice );
1924
+        $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice);
1925 1925
         
1926
-        if ( !empty( $actions ) ) {
1926
+        if (!empty($actions)) {
1927 1927
         ?>
1928 1928
         <div class="wpinv-receipt-actions text-right">
1929
-            <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?>
1930
-            <a href="<?php echo esc_url( $action['url'] );?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class( $key );?>" <?php echo ( !empty($action['attrs']) ? $action['attrs'] : '' ) ;?>><?php echo esc_html( $action['name'] );?></a>
1929
+            <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?>
1930
+            <a href="<?php echo esc_url($action['url']); ?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class($key); ?>" <?php echo (!empty($action['attrs']) ? $action['attrs'] : ''); ?>><?php echo esc_html($action['name']); ?></a>
1931 1931
             <?php } ?>
1932 1932
         </div>
1933 1933
         <?php
1934 1934
         }
1935 1935
     }
1936 1936
 }
1937
-add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 );
1937
+add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1);
1938 1938
 
1939
-function wpinv_invoice_link( $invoice_id ) {
1940
-    $invoice = wpinv_get_invoice( $invoice_id );
1939
+function wpinv_invoice_link($invoice_id) {
1940
+    $invoice = wpinv_get_invoice($invoice_id);
1941 1941
     
1942
-    if ( empty( $invoice ) ) {
1942
+    if (empty($invoice)) {
1943 1943
         return NULL;
1944 1944
     }
1945 1945
     
1946
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1946
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1947 1947
     
1948
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1948
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1949 1949
 }
1950 1950
 
1951
-function wpinv_invoice_subscription_details( $invoice ) {
1952
-    if ( !empty( $invoice ) && $invoice->is_recurring() && !wpinv_is_subscription_payment( $invoice ) ) {
1951
+function wpinv_invoice_subscription_details($invoice) {
1952
+    if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) {
1953 1953
         $total_payments = (int)$invoice->get_total_payments();
1954 1954
         $payments       = $invoice->get_child_payments();
1955 1955
         
1956 1956
         $subscription   = $invoice->get_subscription_data();
1957 1957
         
1958
-        if ( !( !empty( $subscription ) && !empty( $subscription['item_id'] ) ) ) {
1958
+        if (!(!empty($subscription) && !empty($subscription['item_id']))) {
1959 1959
             return;
1960 1960
         }
1961 1961
         
1962
-        $billing_cycle  = wpinv_get_billing_cycle( $subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency() );
1963
-        $times_billed   = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] );
1962
+        $billing_cycle  = wpinv_get_billing_cycle($subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency());
1963
+        $times_billed   = $total_payments . ' / ' . (((int)$subscription['bill_times'] == 0) ? __('Until cancelled', 'invoicing') : $subscription['bill_times']);
1964 1964
         
1965 1965
         $subscription_status = $invoice->get_subscription_status();
1966 1966
         
1967 1967
         $status_desc = '';
1968
-        if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) {
1969
-            $status_desc = wp_sprintf( __( 'Until: %s', 'invoicing' ), $trial_end_date );
1970
-        } else if ( $subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date() ) {
1971
-            $status_desc = wp_sprintf( __( 'On: %s', 'invoicing' ), $cancelled_date );
1968
+        if ($subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date()) {
1969
+            $status_desc = wp_sprintf(__('Until: %s', 'invoicing'), $trial_end_date);
1970
+        } else if ($subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date()) {
1971
+            $status_desc = wp_sprintf(__('On: %s', 'invoicing'), $cancelled_date);
1972 1972
         }
1973 1973
         $status_desc = $status_desc != '' ? '<span class="meta">' . $status_desc . '</span>' : '';
1974 1974
         ?>
1975 1975
         <div class="wpinv-subscriptions-details">
1976
-            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3>
1976
+            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3>
1977 1977
             <table class="table">
1978 1978
                 <thead>
1979 1979
                     <tr>
1980
-                        <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th>
1981
-                        <th><?php _e( 'Start Date', 'invoicing' ) ;?></th>
1982
-                        <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th>
1983
-                        <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th>
1984
-                        <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th>
1980
+                        <th><?php _e('Billing Cycle', 'invoicing'); ?></th>
1981
+                        <th><?php _e('Start Date', 'invoicing'); ?></th>
1982
+                        <th><?php _e('Expiration Date', 'invoicing'); ?></th>
1983
+                        <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th>
1984
+                        <th class="text-center"><?php _e('Status', 'invoicing'); ?></th>
1985 1985
                     </tr>
1986 1986
                 </thead>
1987 1987
                 <tbody>
@@ -1990,32 +1990,32 @@  discard block
 block discarded – undo
1990 1990
                         <td><?php echo $invoice->get_subscription_start(); ?></td>
1991 1991
                         <td><?php echo $invoice->get_subscription_end(); ?></td>
1992 1992
                         <td class="text-center"><?php echo $times_billed; ?></td>
1993
-                        <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label() ;?>
1993
+                        <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label(); ?>
1994 1994
                         <?php echo $status_desc; ?>
1995 1995
                         </td>
1996 1996
                     </tr>
1997 1997
                 </tbody>
1998 1998
             </table>
1999 1999
         </div>
2000
-        <?php if ( !empty( $payments ) ) { ?>
2000
+        <?php if (!empty($payments)) { ?>
2001 2001
         <div class="wpinv-renewal-payments">
2002
-            <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3>
2002
+            <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3>
2003 2003
             <table class="table">
2004 2004
                 <thead>
2005 2005
                     <tr>
2006 2006
                         <th>#</th>
2007
-                        <th><?php _e( 'Invoice', 'invoicing' ) ;?></th>
2008
-                        <th><?php _e( 'Date', 'invoicing' ) ;?></th>
2009
-                        <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th>
2007
+                        <th><?php _e('Invoice', 'invoicing'); ?></th>
2008
+                        <th><?php _e('Date', 'invoicing'); ?></th>
2009
+                        <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th>
2010 2010
                     </tr>
2011 2011
                 </thead>
2012 2012
                 <tbody>
2013
-                    <?php foreach ( $payments as $key => $invoice_id ) { ?>
2013
+                    <?php foreach ($payments as $key => $invoice_id) { ?>
2014 2014
                     <tr>
2015
-                        <th scope="row"><?php echo ( $key + 1 );?></th>
2016
-                        <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td>
2017
-                        <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td>
2018
-                        <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td>
2015
+                        <th scope="row"><?php echo ($key + 1); ?></th>
2016
+                        <td><?php echo wpinv_invoice_link($invoice_id); ?></td>
2017
+                        <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td>
2018
+                        <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td>
2019 2019
                     </tr>
2020 2020
                     <?php } ?>
2021 2021
                     <tr><td colspan="4" style="padding:0"></td></tr>
@@ -2027,52 +2027,52 @@  discard block
 block discarded – undo
2027 2027
     }
2028 2028
 }
2029 2029
 
2030
-function wpinv_cart_total_label( $label, $invoice ) {
2031
-    if ( empty( $invoice ) ) {
2030
+function wpinv_cart_total_label($label, $invoice) {
2031
+    if (empty($invoice)) {
2032 2032
         return $label;
2033 2033
     }
2034 2034
     
2035 2035
     $prefix_label = '';
2036
-    if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) {        
2037
-        $prefix_label   = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice );
2038
-    } else if ( $invoice->is_renewal() ) {
2039
-        $prefix_label   = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> ';        
2036
+    if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) {        
2037
+        $prefix_label   = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice);
2038
+    } else if ($invoice->is_renewal()) {
2039
+        $prefix_label   = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> ';        
2040 2040
     }
2041 2041
     
2042
-    if ( $prefix_label != '' ) {
2043
-        $label  = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2042
+    if ($prefix_label != '') {
2043
+        $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2044 2044
     }
2045 2045
     
2046 2046
     return $label;
2047 2047
 }
2048
-add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2049
-add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2050
-add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2048
+add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2049
+add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2050
+add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2051 2051
 
2052
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 );
2052
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1);
2053 2053
 
2054
-function wpinv_invoice_print_description( $invoice ) {
2055
-    if ( empty( $invoice ) ) {
2054
+function wpinv_invoice_print_description($invoice) {
2055
+    if (empty($invoice)) {
2056 2056
         return NULL;
2057 2057
     }
2058
-    if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) {
2058
+    if ($description = wpinv_get_invoice_description($invoice->ID)) {
2059 2059
         ?>
2060 2060
         <div class="row wpinv-lower">
2061 2061
             <div class="col-sm-12 wpinv-description">
2062
-                <?php echo wpautop( $description ); ?>
2062
+                <?php echo wpautop($description); ?>
2063 2063
             </div>
2064 2064
         </div>
2065 2065
         <?php
2066 2066
     }
2067 2067
 }
2068
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 );
2068
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1);
2069 2069
 
2070
-function wpinv_invoice_print_payment_info( $invoice ) {
2071
-    if ( empty( $invoice ) ) {
2070
+function wpinv_invoice_print_payment_info($invoice) {
2071
+    if (empty($invoice)) {
2072 2072
         return NULL;
2073 2073
     }
2074 2074
     
2075
-    if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) {
2075
+    if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) {
2076 2076
         ?>
2077 2077
         <div class="row wpinv-payments">
2078 2078
             <div class="col-sm-12">
@@ -2084,40 +2084,40 @@  discard block
 block discarded – undo
2084 2084
 }
2085 2085
 // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 );
2086 2086
 
2087
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
2088
-    if ( empty( $note ) ) {
2087
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
2088
+    if (empty($note)) {
2089 2089
         return NULL;
2090 2090
     }
2091 2091
     
2092
-    if ( is_int( $note ) ) {
2093
-        $note = get_comment( $note );
2092
+    if (is_int($note)) {
2093
+        $note = get_comment($note);
2094 2094
     }
2095 2095
     
2096
-    if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
2096
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
2097 2097
         return NULL;
2098 2098
     }
2099 2099
     
2100
-    $note_classes   = array( 'note' );
2101
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
2102
-    $note_classes[] = $note->comment_author === __( 'GeoDirectory', 'invoicing' ) ? 'system-note' : '';
2103
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
2104
-    $note_classes   = !empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
2100
+    $note_classes   = array('note');
2101
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
2102
+    $note_classes[] = $note->comment_author === __('GeoDirectory', 'invoicing') ? 'system-note' : '';
2103
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
2104
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
2105 2105
     
2106 2106
     ob_start();
2107 2107
     ?>
2108
-    <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>">
2108
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>">
2109 2109
         <div class="note_content">
2110
-            <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
2110
+            <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?>
2111 2111
         </div>
2112 2112
         <p class="meta">
2113
-            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr>&nbsp;&nbsp;<a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a>
2113
+            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr>&nbsp;&nbsp;<a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
2114 2114
         </p>
2115 2115
     </li>
2116 2116
     <?php
2117 2117
     $note_content = ob_get_clean();
2118
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
2118
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
2119 2119
     
2120
-    if ( $echo ) {
2120
+    if ($echo) {
2121 2121
         echo $note_content;
2122 2122
     } else {
2123 2123
         return $note_content;
Please login to merge, or discard this patch.