Passed
Pull Request — master (#322)
by Brian
09:18
created
includes/wpinv-invoice-functions.php 1 patch
Spacing   +781 added lines, -781 removed lines patch added patch discarded remove patch
@@ -7,14 +7,14 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_get_invoice_cart_id() {
15 15
     $wpinv_checkout = wpinv_get_checkout_session();
16 16
     
17
-    if ( !empty( $wpinv_checkout['invoice_id'] ) ) {
17
+    if (!empty($wpinv_checkout['invoice_id'])) {
18 18
         return $wpinv_checkout['invoice_id'];
19 19
     }
20 20
     
@@ -28,48 +28,48 @@  discard block
 block discarded – undo
28 28
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
29 29
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
30 30
  */
31
-function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) {
32
-    if ( empty( $invoice_data ) ) {
31
+function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) {
32
+    if (empty($invoice_data)) {
33 33
         return false;
34 34
     }
35 35
     
36
-    if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) {
37
-        return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast one item.', 'invoicing' ) ) : 0;
36
+    if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) {
37
+        return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast one item.', 'invoicing')) : 0;
38 38
     }
39 39
     
40 40
     // If no user id is provided, default to the current user id
41
-    if ( empty( $invoice_data['user_id'] ) ) {
41
+    if (empty($invoice_data['user_id'])) {
42 42
         $invoice_data['user_id'] = get_current_user_id();
43 43
     }
44 44
     
45
-    $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0;
45
+    $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int) $invoice_data['invoice_id'] : 0;
46 46
     
47
-    if ( empty( $invoice_data['status'] ) ) {
47
+    if (empty($invoice_data['status'])) {
48 48
         $invoice_data['status'] = 'wpi-pending';
49 49
     }
50 50
 
51
-    if ( empty( $invoice_data['post_type'] ) ) {
51
+    if (empty($invoice_data['post_type'])) {
52 52
         $invoice_data['post_type'] = 'wpi_invoice';
53 53
     }
54 54
     
55
-    if ( empty( $invoice_data['ip'] ) ) {
55
+    if (empty($invoice_data['ip'])) {
56 56
         $invoice_data['ip'] = wpinv_get_ip();
57 57
     }
58 58
 
59 59
     // default invoice args, note that status is checked for validity in wpinv_create_invoice()
60 60
     $default_args = array(
61
-        'invoice_id'    => (int)$invoice_data['invoice_id'],
62
-        'user_id'       => (int)$invoice_data['user_id'],
61
+        'invoice_id'    => (int) $invoice_data['invoice_id'],
62
+        'user_id'       => (int) $invoice_data['user_id'],
63 63
         'status'        => $invoice_data['status'],
64 64
         'post_type'     => $invoice_data['post_type'],
65 65
     );
66 66
 
67
-    $invoice = wpinv_create_invoice( $default_args, $invoice_data, true );
68
-    if ( is_wp_error( $invoice ) ) {
67
+    $invoice = wpinv_create_invoice($default_args, $invoice_data, true);
68
+    if (is_wp_error($invoice)) {
69 69
         return $wp_error ? $invoice : 0;
70 70
     }
71 71
     
72
-    if ( empty( $invoice_data['invoice_id'] ) ) {
72
+    if (empty($invoice_data['invoice_id'])) {
73 73
         //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );
74 74
     }
75 75
     
@@ -92,24 +92,24 @@  discard block
 block discarded – undo
92 92
         'discount'              => array(),
93 93
     );
94 94
 
95
-    if ( $user_id = (int)$invoice->get_user_id() ) {
96
-        if ( $user_address = wpinv_get_user_address( $user_id ) ) {
97
-            $default_user_info = wp_parse_args( $user_address, $default_user_info );
95
+    if ($user_id = (int) $invoice->get_user_id()) {
96
+        if ($user_address = wpinv_get_user_address($user_id)) {
97
+            $default_user_info = wp_parse_args($user_address, $default_user_info);
98 98
         }
99 99
     }
100 100
     
101
-    if ( empty( $invoice_data['user_info'] ) ) {
101
+    if (empty($invoice_data['user_info'])) {
102 102
         $invoice_data['user_info'] = array();
103 103
     }
104 104
     
105
-    $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info );
105
+    $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info);
106 106
     
107
-    if ( empty( $user_info['first_name'] ) ) {
107
+    if (empty($user_info['first_name'])) {
108 108
         $user_info['first_name'] = $default_user_info['first_name'];
109 109
         $user_info['last_name'] = $default_user_info['last_name'];
110 110
     }
111 111
     
112
-    if ( empty( $user_info['country'] ) ) {
112
+    if (empty($user_info['country'])) {
113 113
         $user_info['country'] = $default_user_info['country'];
114 114
         $user_info['state'] = $default_user_info['state'];
115 115
         $user_info['city'] = $default_user_info['city'];
@@ -118,13 +118,13 @@  discard block
 block discarded – undo
118 118
         $user_info['phone'] = $default_user_info['phone'];
119 119
     }
120 120
     
121
-    if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) {
122
-        $user_info['discount'] = (array)$user_info['discount'];
121
+    if (!empty($user_info['discount']) && !is_array($user_info['discount'])) {
122
+        $user_info['discount'] = (array) $user_info['discount'];
123 123
     }
124 124
 
125 125
     // Payment details
126 126
     $payment_details = array();
127
-    if ( !empty( $invoice_data['payment_details'] ) ) {
127
+    if (!empty($invoice_data['payment_details'])) {
128 128
         $default_payment_details = array(
129 129
             'gateway'           => 'manual',
130 130
             'gateway_title'     => '',
@@ -132,56 +132,56 @@  discard block
 block discarded – undo
132 132
             'transaction_id'    => '',
133 133
         );
134 134
         
135
-        $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details );
135
+        $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details);
136 136
         
137
-        if ( empty( $payment_details['gateway'] ) ) {
137
+        if (empty($payment_details['gateway'])) {
138 138
             $payment_details['gateway'] = 'manual';
139 139
         }
140 140
         
141
-        if ( empty( $payment_details['currency'] ) ) {
141
+        if (empty($payment_details['currency'])) {
142 142
             $payment_details['currency'] = wpinv_get_default_country();
143 143
         }
144 144
         
145
-        if ( empty( $payment_details['gateway_title'] ) ) {
146
-            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] );
145
+        if (empty($payment_details['gateway_title'])) {
146
+            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']);
147 147
         }
148 148
     }
149 149
     
150
-    $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'wpi-pending' ) );
151
-    
152
-    if ( !empty( $payment_details ) ) {
153
-        $invoice->set( 'currency', $payment_details['currency'] );
154
-        $invoice->set( 'gateway', $payment_details['gateway'] );
155
-        $invoice->set( 'gateway_title', $payment_details['gateway_title'] );
156
-        $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
157
-    }
158
-    
159
-    $invoice->set( 'user_info', $user_info );
160
-    $invoice->set( 'first_name', $user_info['first_name'] );
161
-    $invoice->set( 'last_name', $user_info['last_name'] );
162
-    $invoice->set( 'address', $user_info['address'] );
163
-    $invoice->set( 'company', $user_info['company'] );
164
-    $invoice->set( 'vat_number', $user_info['vat_number'] );
165
-    $invoice->set( 'phone', $user_info['phone'] );
166
-    $invoice->set( 'city', $user_info['city'] );
167
-    $invoice->set( 'country', $user_info['country'] );
168
-    $invoice->set( 'state', $user_info['state'] );
169
-    $invoice->set( 'zip', $user_info['zip'] );
170
-    $invoice->set( 'discounts', $user_info['discount'] );
171
-    $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) );
172
-    $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) );
173
-    $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) );
174
-    
175
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) {
176
-        foreach ( $invoice_data['cart_details'] as $key => $item ) {
177
-            $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
178
-            $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
179
-            $name           = !empty( $item['name'] ) ? $item['name'] : '';
180
-            $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : '';
150
+    $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'wpi-pending'));
151
+    
152
+    if (!empty($payment_details)) {
153
+        $invoice->set('currency', $payment_details['currency']);
154
+        $invoice->set('gateway', $payment_details['gateway']);
155
+        $invoice->set('gateway_title', $payment_details['gateway_title']);
156
+        $invoice->set('transaction_id', $payment_details['transaction_id']);
157
+    }
158
+    
159
+    $invoice->set('user_info', $user_info);
160
+    $invoice->set('first_name', $user_info['first_name']);
161
+    $invoice->set('last_name', $user_info['last_name']);
162
+    $invoice->set('address', $user_info['address']);
163
+    $invoice->set('company', $user_info['company']);
164
+    $invoice->set('vat_number', $user_info['vat_number']);
165
+    $invoice->set('phone', $user_info['phone']);
166
+    $invoice->set('city', $user_info['city']);
167
+    $invoice->set('country', $user_info['country']);
168
+    $invoice->set('state', $user_info['state']);
169
+    $invoice->set('zip', $user_info['zip']);
170
+    $invoice->set('discounts', $user_info['discount']);
171
+    $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip()));
172
+    $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live'));
173
+    $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : ''));
174
+    
175
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) {
176
+        foreach ($invoice_data['cart_details'] as $key => $item) {
177
+            $item_id        = !empty($item['id']) ? $item['id'] : 0;
178
+            $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
179
+            $name           = !empty($item['name']) ? $item['name'] : '';
180
+            $item_price     = isset($item['item_price']) ? $item['item_price'] : '';
181 181
             
182
-            $post_item  = new WPInv_Item( $item_id );
183
-            if ( !empty( $post_item ) ) {
184
-                $name       = !empty( $name ) ? $name : $post_item->get_name();
182
+            $post_item = new WPInv_Item($item_id);
183
+            if (!empty($post_item)) {
184
+                $name       = !empty($name) ? $name : $post_item->get_name();
185 185
                 $item_price = $item_price !== '' ? $item_price : $post_item->get_price();
186 186
             } else {
187 187
                 continue;
@@ -191,262 +191,262 @@  discard block
 block discarded – undo
191 191
                 'name'          => $name,
192 192
                 'quantity'      => $quantity,
193 193
                 'item_price'    => $item_price,
194
-                'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
195
-                'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0.00,
196
-                'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
197
-                'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
198
-                'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
194
+                'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
195
+                'tax'           => !empty($item['tax']) ? $item['tax'] : 0.00,
196
+                'discount'      => isset($item['discount']) ? $item['discount'] : 0,
197
+                'meta'          => isset($item['meta']) ? $item['meta'] : array(),
198
+                'fees'          => isset($item['fees']) ? $item['fees'] : array(),
199 199
             );
200 200
 
201
-            $invoice->add_item( $item_id, $args );
201
+            $invoice->add_item($item_id, $args);
202 202
         }
203 203
     }
204 204
 
205
-    $invoice->increase_tax( wpinv_get_cart_fee_tax() );
205
+    $invoice->increase_tax(wpinv_get_cart_fee_tax());
206 206
 
207
-    if ( isset( $invoice_data['post_date'] ) ) {
208
-        $invoice->set( 'date', $invoice_data['post_date'] );
207
+    if (isset($invoice_data['post_date'])) {
208
+        $invoice->set('date', $invoice_data['post_date']);
209 209
     }
210 210
     
211 211
     // Invoice due date
212
-    if ( isset( $invoice_data['due_date'] ) ) {
213
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
212
+    if (isset($invoice_data['due_date'])) {
213
+        $invoice->set('due_date', $invoice_data['due_date']);
214 214
     }
215 215
     
216 216
     $invoice->save();
217 217
     
218 218
     // Add notes
219
-    if ( !empty( $invoice_data['private_note'] ) ) {
220
-        $invoice->add_note( $invoice_data['private_note'] );
219
+    if (!empty($invoice_data['private_note'])) {
220
+        $invoice->add_note($invoice_data['private_note']);
221 221
     }
222
-    if ( !empty( $invoice_data['user_note'] ) ) {
223
-        $invoice->add_note( $invoice_data['user_note'], true );
222
+    if (!empty($invoice_data['user_note'])) {
223
+        $invoice->add_note($invoice_data['user_note'], true);
224 224
     }
225 225
     
226
-    if ( $invoice->is_quote() ) {
226
+    if ($invoice->is_quote()) {
227 227
 
228
-        if ( isset( $invoice_data['valid_until'] ) ) {
229
-            update_post_meta( $invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until'] );
228
+        if (isset($invoice_data['valid_until'])) {
229
+            update_post_meta($invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until']);
230 230
         }
231 231
         return $invoice;
232 232
 
233 233
     }
234 234
 
235
-    do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data );
235
+    do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data);
236 236
 
237
-    if ( ! empty( $invoice->ID ) ) {
237
+    if (!empty($invoice->ID)) {
238 238
         global $wpi_userID, $wpinv_ip_address_country;
239 239
         
240 240
         $checkout_session = wpinv_get_checkout_session();
241 241
         
242 242
         $data_session                   = array();
243 243
         $data_session['invoice_id']     = $invoice->ID;
244
-        $data_session['cart_discounts'] = $invoice->get_discounts( true );
244
+        $data_session['cart_discounts'] = $invoice->get_discounts(true);
245 245
         
246
-        wpinv_set_checkout_session( $data_session );
246
+        wpinv_set_checkout_session($data_session);
247 247
         
248
-        $wpi_userID         = (int)$invoice->get_user_id();
248
+        $wpi_userID         = (int) $invoice->get_user_id();
249 249
         
250
-        $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
250
+        $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
251 251
         $_POST['state']     = $invoice->state;
252 252
 
253
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
254
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
253
+        $invoice->set('country', sanitize_text_field($_POST['country']));
254
+        $invoice->set('state', sanitize_text_field($_POST['state']));
255 255
         
256 256
         $wpinv_ip_address_country = $invoice->country;
257 257
         
258
-        $invoice = $invoice->recalculate_totals( true );
258
+        $invoice = $invoice->recalculate_totals(true);
259 259
         
260
-        wpinv_set_checkout_session( $checkout_session );
260
+        wpinv_set_checkout_session($checkout_session);
261 261
                     
262 262
         return $invoice;
263 263
     }
264 264
     
265
-    if ( $wp_error ) {
266
-        if ( is_wp_error( $invoice ) ) {
265
+    if ($wp_error) {
266
+        if (is_wp_error($invoice)) {
267 267
             return $invoice;
268 268
         } else {
269
-            return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) );
269
+            return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing'));
270 270
         }
271 271
     } else {
272 272
         return 0;
273 273
     }
274 274
 }
275 275
 
276
-function wpinv_update_invoice( $invoice_data = array(), $wp_error = false ) {
277
-    $invoice_ID = !empty( $invoice_data['ID'] ) ? absint( $invoice_data['ID'] ) : NULL;
276
+function wpinv_update_invoice($invoice_data = array(), $wp_error = false) {
277
+    $invoice_ID = !empty($invoice_data['ID']) ? absint($invoice_data['ID']) : NULL;
278 278
 
279
-    if ( !$invoice_ID ) {
280
-        if ( $wp_error ) {
281
-            return new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) );
279
+    if (!$invoice_ID) {
280
+        if ($wp_error) {
281
+            return new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing'));
282 282
         }
283 283
         return 0;
284 284
     }
285 285
 
286
-    $invoice = wpinv_get_invoice( $invoice_ID );
286
+    $invoice = wpinv_get_invoice($invoice_ID);
287 287
 
288
-    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring( true ) : NULL;
288
+    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring(true) : NULL;
289 289
 
290
-    if ( empty( $invoice->ID ) ) {
291
-        if ( $wp_error ) {
292
-            return new WP_Error( 'invalid_invoice', __( 'Invalid invoice.', 'invoicing' ) );
290
+    if (empty($invoice->ID)) {
291
+        if ($wp_error) {
292
+            return new WP_Error('invalid_invoice', __('Invalid invoice.', 'invoicing'));
293 293
         }
294 294
         return 0;
295 295
     }
296 296
 
297
-    if ( ! $invoice->has_status( array( 'wpi-pending' ) ) && ! $invoice->is_quote()  ) {
298
-        if ( $wp_error ) {
299
-            return new WP_Error( 'invalid_invoice_status', __( 'Only invoice with pending payment is allowed to update.', 'invoicing' ) );
297
+    if (!$invoice->has_status(array('wpi-pending')) && !$invoice->is_quote()) {
298
+        if ($wp_error) {
299
+            return new WP_Error('invalid_invoice_status', __('Only invoice with pending payment is allowed to update.', 'invoicing'));
300 300
         }
301 301
         return 0;
302 302
     }
303 303
 
304 304
     // Invoice status
305
-    if ( !empty( $invoice_data['status'] ) ) {
306
-        $invoice->set( 'status', $invoice_data['status'] );
305
+    if (!empty($invoice_data['status'])) {
306
+        $invoice->set('status', $invoice_data['status']);
307 307
     }
308 308
 
309 309
     // Invoice date
310
-    if ( !empty( $invoice_data['post_date'] ) ) {
311
-        $invoice->set( 'date', $invoice_data['post_date'] );
310
+    if (!empty($invoice_data['post_date'])) {
311
+        $invoice->set('date', $invoice_data['post_date']);
312 312
     }
313 313
 
314 314
     // Invoice due date
315
-    if ( isset( $invoice_data['due_date'] ) ) {
316
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
315
+    if (isset($invoice_data['due_date'])) {
316
+        $invoice->set('due_date', $invoice_data['due_date']);
317 317
     }
318 318
 
319 319
     // Invoice IP address
320
-    if ( !empty( $invoice_data['ip'] ) ) {
321
-        $invoice->set( 'ip', $invoice_data['ip'] );
320
+    if (!empty($invoice_data['ip'])) {
321
+        $invoice->set('ip', $invoice_data['ip']);
322 322
     }
323 323
     
324 324
     // User info
325
-    if ( !empty( $invoice_data['user_info'] ) && is_array( $invoice_data['user_info'] ) ) {
326
-        $user_info = wp_parse_args( $invoice_data['user_info'], $invoice->user_info );
325
+    if (!empty($invoice_data['user_info']) && is_array($invoice_data['user_info'])) {
326
+        $user_info = wp_parse_args($invoice_data['user_info'], $invoice->user_info);
327 327
 
328
-        if ( $discounts = $invoice->get_discounts() ) {
328
+        if ($discounts = $invoice->get_discounts()) {
329 329
             $set_discount = $discounts;
330 330
         } else {
331 331
             $set_discount = '';
332 332
         }
333 333
 
334 334
         // Manage discount
335
-        if ( !empty( $invoice_data['user_info']['discount'] ) ) {
335
+        if (!empty($invoice_data['user_info']['discount'])) {
336 336
             // Remove discount
337
-            if ( $invoice_data['user_info']['discount'] == 'none' ) {
337
+            if ($invoice_data['user_info']['discount'] == 'none') {
338 338
                 $set_discount = '';
339 339
             } else {
340 340
                 $set_discount = $invoice_data['user_info']['discount'];
341 341
             }
342 342
 
343
-            $invoice->set( 'discounts', $set_discount );
343
+            $invoice->set('discounts', $set_discount);
344 344
         }
345 345
 
346 346
         $user_info['discount'] = $set_discount;
347 347
 
348
-        $invoice->set( 'user_info', $user_info );
348
+        $invoice->set('user_info', $user_info);
349 349
     }
350 350
 
351
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) && $cart_details = $invoice_data['cart_details'] ) {
352
-        $remove_items = !empty( $cart_details['remove_items'] ) && is_array( $cart_details['remove_items'] ) ? $cart_details['remove_items'] : array();
351
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']) && $cart_details = $invoice_data['cart_details']) {
352
+        $remove_items = !empty($cart_details['remove_items']) && is_array($cart_details['remove_items']) ? $cart_details['remove_items'] : array();
353 353
 
354
-        if ( !empty( $remove_items[0]['id'] ) ) {
355
-            foreach ( $remove_items as $item ) {
356
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
357
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
358
-                if ( empty( $item_id ) ) {
354
+        if (!empty($remove_items[0]['id'])) {
355
+            foreach ($remove_items as $item) {
356
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
357
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
358
+                if (empty($item_id)) {
359 359
                     continue;
360 360
                 }
361 361
 
362
-                foreach ( $invoice->cart_details as $cart_index => $cart_item ) {
363
-                    if ( $item_id == $cart_item['id'] ) {
362
+                foreach ($invoice->cart_details as $cart_index => $cart_item) {
363
+                    if ($item_id == $cart_item['id']) {
364 364
                         $args = array(
365 365
                             'id'         => $item_id,
366 366
                             'quantity'   => $quantity,
367 367
                             'cart_index' => $cart_index
368 368
                         );
369 369
 
370
-                        $invoice->remove_item( $item_id, $args );
370
+                        $invoice->remove_item($item_id, $args);
371 371
                         break;
372 372
                     }
373 373
                 }
374 374
             }
375 375
         }
376 376
 
377
-        $add_items = !empty( $cart_details['add_items'] ) && is_array( $cart_details['add_items'] ) ? $cart_details['add_items'] : array();
377
+        $add_items = !empty($cart_details['add_items']) && is_array($cart_details['add_items']) ? $cart_details['add_items'] : array();
378 378
 
379
-        if ( !empty( $add_items[0]['id'] ) ) {
380
-            foreach ( $add_items as $item ) {
381
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
382
-                $post_item      = new WPInv_Item( $item_id );
383
-                if ( empty( $post_item ) ) {
379
+        if (!empty($add_items[0]['id'])) {
380
+            foreach ($add_items as $item) {
381
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
382
+                $post_item      = new WPInv_Item($item_id);
383
+                if (empty($post_item)) {
384 384
                     continue;
385 385
                 }
386 386
 
387 387
                 $valid_item = true;
388
-                if ( !empty( $recurring_item ) ) {
389
-                    if ( $recurring_item->ID != $item_id ) {
388
+                if (!empty($recurring_item)) {
389
+                    if ($recurring_item->ID != $item_id) {
390 390
                         $valid_item = false;
391 391
                     }
392
-                } else if ( wpinv_is_recurring_item( $item_id ) ) {
392
+                } else if (wpinv_is_recurring_item($item_id)) {
393 393
                     $valid_item = false;
394 394
                 }
395 395
                 
396
-                if ( !$valid_item ) {
397
-                    if ( $wp_error ) {
398
-                        return new WP_Error( 'invalid_invoice_item', __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ) );
396
+                if (!$valid_item) {
397
+                    if ($wp_error) {
398
+                        return new WP_Error('invalid_invoice_item', __('You can not add item because recurring item must be paid individually!', 'invoicing'));
399 399
                     }
400 400
                     return 0;
401 401
                 }
402 402
 
403
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
404
-                $name           = !empty( $item['name'] ) ? $item['name'] : $post_item->get_name();
405
-                $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : $post_item->get_price();
403
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
404
+                $name           = !empty($item['name']) ? $item['name'] : $post_item->get_name();
405
+                $item_price     = isset($item['item_price']) ? $item['item_price'] : $post_item->get_price();
406 406
 
407 407
                 $args = array(
408 408
                     'name'          => $name,
409 409
                     'quantity'      => $quantity,
410 410
                     'item_price'    => $item_price,
411
-                    'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
412
-                    'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0,
413
-                    'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
414
-                    'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
415
-                    'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
411
+                    'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
412
+                    'tax'           => !empty($item['tax']) ? $item['tax'] : 0,
413
+                    'discount'      => isset($item['discount']) ? $item['discount'] : 0,
414
+                    'meta'          => isset($item['meta']) ? $item['meta'] : array(),
415
+                    'fees'          => isset($item['fees']) ? $item['fees'] : array(),
416 416
                 );
417 417
 
418
-                $invoice->add_item( $item_id, $args );
418
+                $invoice->add_item($item_id, $args);
419 419
             }
420 420
         }
421 421
     }
422 422
     
423 423
     // Payment details
424
-    if ( !empty( $invoice_data['payment_details'] ) && $payment_details = $invoice_data['payment_details'] ) {
425
-        if ( !empty( $payment_details['gateway'] ) ) {
426
-            $invoice->set( 'gateway', $payment_details['gateway'] );
424
+    if (!empty($invoice_data['payment_details']) && $payment_details = $invoice_data['payment_details']) {
425
+        if (!empty($payment_details['gateway'])) {
426
+            $invoice->set('gateway', $payment_details['gateway']);
427 427
         }
428 428
 
429
-        if ( !empty( $payment_details['transaction_id'] ) ) {
430
-            $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
429
+        if (!empty($payment_details['transaction_id'])) {
430
+            $invoice->set('transaction_id', $payment_details['transaction_id']);
431 431
         }
432 432
     }
433 433
 
434
-    do_action( 'wpinv_pre_update_invoice', $invoice->ID, $invoice_data );
434
+    do_action('wpinv_pre_update_invoice', $invoice->ID, $invoice_data);
435 435
 
436 436
     // Parent invoice
437
-    if ( !empty( $invoice_data['parent'] ) ) {
438
-        $invoice->set( 'parent_invoice', $invoice_data['parent'] );
437
+    if (!empty($invoice_data['parent'])) {
438
+        $invoice->set('parent_invoice', $invoice_data['parent']);
439 439
     }
440 440
 
441 441
     // Save invoice data.
442 442
     $invoice->save();
443 443
     
444
-    if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) {
445
-        if ( $wp_error ) {
446
-            if ( is_wp_error( $invoice ) ) {
444
+    if (empty($invoice->ID) || is_wp_error($invoice)) {
445
+        if ($wp_error) {
446
+            if (is_wp_error($invoice)) {
447 447
                 return $invoice;
448 448
             } else {
449
-                return new WP_Error( 'wpinv_update_invoice_error', __( 'Error in update invoice.', 'invoicing' ) );
449
+                return new WP_Error('wpinv_update_invoice_error', __('Error in update invoice.', 'invoicing'));
450 450
             }
451 451
         } else {
452 452
             return 0;
@@ -454,19 +454,19 @@  discard block
 block discarded – undo
454 454
     }
455 455
 
456 456
     // Add private note
457
-    if ( !empty( $invoice_data['private_note'] ) ) {
458
-        $invoice->add_note( $invoice_data['private_note'] );
457
+    if (!empty($invoice_data['private_note'])) {
458
+        $invoice->add_note($invoice_data['private_note']);
459 459
     }
460 460
 
461 461
     // Add user note
462
-    if ( !empty( $invoice_data['user_note'] ) ) {
463
-        $invoice->add_note( $invoice_data['user_note'], true );
462
+    if (!empty($invoice_data['user_note'])) {
463
+        $invoice->add_note($invoice_data['user_note'], true);
464 464
     }
465 465
 
466
-    if ( $invoice->is_quote() ) {
466
+    if ($invoice->is_quote()) {
467 467
 
468
-        if ( isset( $invoice_data['valid_until'] ) ) {
469
-            update_post_meta( $invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until'] );
468
+        if (isset($invoice_data['valid_until'])) {
469
+            update_post_meta($invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until']);
470 470
         }
471 471
         return $invoice;
472 472
 
@@ -478,466 +478,466 @@  discard block
 block discarded – undo
478 478
 
479 479
     $data_session                   = array();
480 480
     $data_session['invoice_id']     = $invoice->ID;
481
-    $data_session['cart_discounts'] = $invoice->get_discounts( true );
481
+    $data_session['cart_discounts'] = $invoice->get_discounts(true);
482 482
 
483
-    wpinv_set_checkout_session( $data_session );
483
+    wpinv_set_checkout_session($data_session);
484 484
 
485
-    $wpi_userID         = (int)$invoice->get_user_id();
485
+    $wpi_userID         = (int) $invoice->get_user_id();
486 486
 
487
-    $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
487
+    $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
488 488
     $_POST['state']     = $invoice->state;
489 489
 
490
-    $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
491
-    $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
490
+    $invoice->set('country', sanitize_text_field($_POST['country']));
491
+    $invoice->set('state', sanitize_text_field($_POST['state']));
492 492
 
493 493
     $wpinv_ip_address_country = $invoice->country;
494 494
 
495
-    $invoice = $invoice->recalculate_totals( true );
495
+    $invoice = $invoice->recalculate_totals(true);
496 496
 
497
-    do_action( 'wpinv_post_update_invoice', $invoice->ID, $invoice_data );
497
+    do_action('wpinv_post_update_invoice', $invoice->ID, $invoice_data);
498 498
 
499
-    wpinv_set_checkout_session( $checkout_session );
499
+    wpinv_set_checkout_session($checkout_session);
500 500
 
501 501
     return $invoice;
502 502
 }
503 503
 
504
-function wpinv_get_invoice( $invoice_id = 0, $cart = false ) {
505
-    if ( $cart && empty( $invoice_id ) ) {
506
-        $invoice_id = (int)wpinv_get_invoice_cart_id();
504
+function wpinv_get_invoice($invoice_id = 0, $cart = false) {
505
+    if ($cart && empty($invoice_id)) {
506
+        $invoice_id = (int) wpinv_get_invoice_cart_id();
507 507
     }
508 508
 
509
-    $invoice = new WPInv_Invoice( $invoice_id );
509
+    $invoice = new WPInv_Invoice($invoice_id);
510 510
 
511
-    if ( ! empty( $invoice ) && ! empty( $invoice->ID ) ) {
511
+    if (!empty($invoice) && !empty($invoice->ID)) {
512 512
         return $invoice;
513 513
     }
514 514
     
515 515
     return NULL;
516 516
 }
517 517
 
518
-function wpinv_get_invoice_cart( $invoice_id = 0 ) {
519
-    return wpinv_get_invoice( $invoice_id, true );
518
+function wpinv_get_invoice_cart($invoice_id = 0) {
519
+    return wpinv_get_invoice($invoice_id, true);
520 520
 }
521 521
 
522
-function wpinv_get_invoice_description( $invoice_id = 0 ) {
523
-    $invoice = new WPInv_Invoice( $invoice_id );
522
+function wpinv_get_invoice_description($invoice_id = 0) {
523
+    $invoice = new WPInv_Invoice($invoice_id);
524 524
     return $invoice->get_description();
525 525
 }
526 526
 
527
-function wpinv_get_invoice_currency_code( $invoice_id = 0 ) {
528
-    $invoice = new WPInv_Invoice( $invoice_id );
527
+function wpinv_get_invoice_currency_code($invoice_id = 0) {
528
+    $invoice = new WPInv_Invoice($invoice_id);
529 529
     return $invoice->get_currency();
530 530
 }
531 531
 
532
-function wpinv_get_payment_user_email( $invoice_id ) {
533
-    $invoice = new WPInv_Invoice( $invoice_id );
532
+function wpinv_get_payment_user_email($invoice_id) {
533
+    $invoice = new WPInv_Invoice($invoice_id);
534 534
     return $invoice->get_email();
535 535
 }
536 536
 
537
-function wpinv_get_user_id( $invoice_id ) {
538
-    $invoice = new WPInv_Invoice( $invoice_id );
537
+function wpinv_get_user_id($invoice_id) {
538
+    $invoice = new WPInv_Invoice($invoice_id);
539 539
     return $invoice->get_user_id();
540 540
 }
541 541
 
542
-function wpinv_get_invoice_status( $invoice_id, $return_label = false ) {
543
-    $invoice = new WPInv_Invoice( $invoice_id );
542
+function wpinv_get_invoice_status($invoice_id, $return_label = false) {
543
+    $invoice = new WPInv_Invoice($invoice_id);
544 544
     
545
-    return $invoice->get_status( $return_label );
545
+    return $invoice->get_status($return_label);
546 546
 }
547 547
 
548
-function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) {
549
-    $invoice = new WPInv_Invoice( $invoice_id );
548
+function wpinv_get_payment_gateway($invoice_id, $return_label = false) {
549
+    $invoice = new WPInv_Invoice($invoice_id);
550 550
     
551
-    return $invoice->get_gateway( $return_label );
551
+    return $invoice->get_gateway($return_label);
552 552
 }
553 553
 
554
-function wpinv_get_payment_gateway_name( $invoice_id ) {
555
-    $invoice = new WPInv_Invoice( $invoice_id );
554
+function wpinv_get_payment_gateway_name($invoice_id) {
555
+    $invoice = new WPInv_Invoice($invoice_id);
556 556
     
557 557
     return $invoice->get_gateway_title();
558 558
 }
559 559
 
560
-function wpinv_get_payment_transaction_id( $invoice_id ) {
561
-    $invoice = new WPInv_Invoice( $invoice_id );
560
+function wpinv_get_payment_transaction_id($invoice_id) {
561
+    $invoice = new WPInv_Invoice($invoice_id);
562 562
     
563 563
     return $invoice->get_transaction_id();
564 564
 }
565 565
 
566
-function wpinv_get_id_by_transaction_id( $key ) {
566
+function wpinv_get_id_by_transaction_id($key) {
567 567
     global $wpdb;
568 568
 
569
-    $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) );
569
+    $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key));
570 570
 
571
-    if ( $invoice_id != NULL )
571
+    if ($invoice_id != NULL)
572 572
         return $invoice_id;
573 573
 
574 574
     return 0;
575 575
 }
576 576
 
577
-function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) {
578
-    $invoice = new WPInv_Invoice( $invoice_id );
577
+function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) {
578
+    $invoice = new WPInv_Invoice($invoice_id);
579 579
 
580
-    return $invoice->get_meta( $meta_key, $single );
580
+    return $invoice->get_meta($meta_key, $single);
581 581
 }
582 582
 
583
-function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) {
584
-    $invoice = new WPInv_Invoice( $invoice_id );
583
+function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') {
584
+    $invoice = new WPInv_Invoice($invoice_id);
585 585
     
586
-    return $invoice->update_meta( $meta_key, $meta_value, $prev_value );
586
+    return $invoice->update_meta($meta_key, $meta_value, $prev_value);
587 587
 }
588 588
 
589
-function wpinv_get_items( $invoice_id = 0 ) {
590
-    $invoice            = wpinv_get_invoice( $invoice_id );
589
+function wpinv_get_items($invoice_id = 0) {
590
+    $invoice            = wpinv_get_invoice($invoice_id);
591 591
     
592 592
     $items              = $invoice->get_items();
593 593
     $invoice_currency   = $invoice->get_currency();
594 594
 
595
-    if ( !empty( $items ) && is_array( $items ) ) {
596
-        foreach ( $items as $key => $item ) {
595
+    if (!empty($items) && is_array($items)) {
596
+        foreach ($items as $key => $item) {
597 597
             $items[$key]['currency'] = $invoice_currency;
598 598
 
599
-            if ( !isset( $item['subtotal'] ) ) {
599
+            if (!isset($item['subtotal'])) {
600 600
                 $items[$key]['subtotal'] = $items[$key]['amount'] * 1;
601 601
             }
602 602
         }
603 603
     }
604 604
 
605
-    return apply_filters( 'wpinv_get_items', $items, $invoice_id );
605
+    return apply_filters('wpinv_get_items', $items, $invoice_id);
606 606
 }
607 607
 
608
-function wpinv_get_fees( $invoice_id = 0 ) {
609
-    $invoice           = wpinv_get_invoice( $invoice_id );
608
+function wpinv_get_fees($invoice_id = 0) {
609
+    $invoice           = wpinv_get_invoice($invoice_id);
610 610
     $fees              = $invoice->get_fees();
611 611
 
612
-    return apply_filters( 'wpinv_get_fees', $fees, $invoice_id );
612
+    return apply_filters('wpinv_get_fees', $fees, $invoice_id);
613 613
 }
614 614
 
615
-function wpinv_get_invoice_ip( $invoice_id ) {
616
-    $invoice = new WPInv_Invoice( $invoice_id );
615
+function wpinv_get_invoice_ip($invoice_id) {
616
+    $invoice = new WPInv_Invoice($invoice_id);
617 617
     return $invoice->get_ip();
618 618
 }
619 619
 
620
-function wpinv_get_invoice_user_info( $invoice_id ) {
621
-    $invoice = new WPInv_Invoice( $invoice_id );
620
+function wpinv_get_invoice_user_info($invoice_id) {
621
+    $invoice = new WPInv_Invoice($invoice_id);
622 622
     return $invoice->get_user_info();
623 623
 }
624 624
 
625
-function wpinv_subtotal( $invoice_id = 0, $currency = false ) {
626
-    $invoice = new WPInv_Invoice( $invoice_id );
625
+function wpinv_subtotal($invoice_id = 0, $currency = false) {
626
+    $invoice = new WPInv_Invoice($invoice_id);
627 627
 
628
-    return $invoice->get_subtotal( $currency );
628
+    return $invoice->get_subtotal($currency);
629 629
 }
630 630
 
631
-function wpinv_tax( $invoice_id = 0, $currency = false ) {
632
-    $invoice = new WPInv_Invoice( $invoice_id );
631
+function wpinv_tax($invoice_id = 0, $currency = false) {
632
+    $invoice = new WPInv_Invoice($invoice_id);
633 633
 
634
-    return $invoice->get_tax( $currency );
634
+    return $invoice->get_tax($currency);
635 635
 }
636 636
 
637
-function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) {
638
-    $invoice = wpinv_get_invoice( $invoice_id );
637
+function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) {
638
+    $invoice = wpinv_get_invoice($invoice_id);
639 639
 
640
-    return $invoice->get_discount( $currency, $dash );
640
+    return $invoice->get_discount($currency, $dash);
641 641
 }
642 642
 
643
-function wpinv_discount_code( $invoice_id = 0 ) {
644
-    $invoice = new WPInv_Invoice( $invoice_id );
643
+function wpinv_discount_code($invoice_id = 0) {
644
+    $invoice = new WPInv_Invoice($invoice_id);
645 645
 
646 646
     return $invoice->get_discount_code();
647 647
 }
648 648
 
649
-function wpinv_payment_total( $invoice_id = 0, $currency = false ) {
650
-    $invoice = new WPInv_Invoice( $invoice_id );
649
+function wpinv_payment_total($invoice_id = 0, $currency = false) {
650
+    $invoice = new WPInv_Invoice($invoice_id);
651 651
 
652
-    return $invoice->get_total( $currency );
652
+    return $invoice->get_total($currency);
653 653
 }
654 654
 
655
-function wpinv_get_date_created( $invoice_id = 0, $format = '' ) {
656
-    $invoice = new WPInv_Invoice( $invoice_id );
655
+function wpinv_get_date_created($invoice_id = 0, $format = '') {
656
+    $invoice = new WPInv_Invoice($invoice_id);
657 657
 
658
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
658
+    $format         = !empty($format) ? $format : get_option('date_format');
659 659
     $date_created   = $invoice->get_created_date();
660
-    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : '';
660
+    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : '';
661 661
 
662 662
     return $date_created;
663 663
 }
664 664
 
665
-function wpinv_get_invoice_date( $invoice_id = 0, $format = '', $default = true ) {
666
-    $invoice = new WPInv_Invoice( $invoice_id );
665
+function wpinv_get_invoice_date($invoice_id = 0, $format = '', $default = true) {
666
+    $invoice = new WPInv_Invoice($invoice_id);
667 667
     
668
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
668
+    $format         = !empty($format) ? $format : get_option('date_format');
669 669
     $date_completed = $invoice->get_completed_date();
670
-    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : '';
671
-    if ( $invoice_date == '' && $default ) {
672
-        $invoice_date   = wpinv_get_date_created( $invoice_id, $format );
670
+    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : '';
671
+    if ($invoice_date == '' && $default) {
672
+        $invoice_date = wpinv_get_date_created($invoice_id, $format);
673 673
     }
674 674
 
675 675
     return $invoice_date;
676 676
 }
677 677
 
678
-function wpinv_get_invoice_vat_number( $invoice_id = 0 ) {
679
-    $invoice = new WPInv_Invoice( $invoice_id );
678
+function wpinv_get_invoice_vat_number($invoice_id = 0) {
679
+    $invoice = new WPInv_Invoice($invoice_id);
680 680
     
681 681
     return $invoice->vat_number;
682 682
 }
683 683
 
684
-function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) {
685
-    $invoice = new WPInv_Invoice( $invoice_id );
684
+function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) {
685
+    $invoice = new WPInv_Invoice($invoice_id);
686 686
 
687
-    return $invoice->add_note( $note, $user_type, $added_by_user, $system );
687
+    return $invoice->add_note($note, $user_type, $added_by_user, $system);
688 688
 }
689 689
 
690
-function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) {
690
+function wpinv_get_invoice_notes($invoice_id = 0, $type = '') {
691 691
     global $invoicing;
692 692
     
693
-    if ( empty( $invoice_id ) ) {
693
+    if (empty($invoice_id)) {
694 694
         return NULL;
695 695
     }
696 696
     
697
-    $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type );
697
+    $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type);
698 698
     
699
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type );
699
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type);
700 700
 }
701 701
 
702
-function wpinv_get_payment_key( $invoice_id = 0 ) {
703
-	$invoice = new WPInv_Invoice( $invoice_id );
702
+function wpinv_get_payment_key($invoice_id = 0) {
703
+	$invoice = new WPInv_Invoice($invoice_id);
704 704
     return $invoice->get_key();
705 705
 }
706 706
 
707
-function wpinv_get_invoice_number( $invoice_id = 0 ) {
708
-    $invoice = new WPInv_Invoice( $invoice_id );
707
+function wpinv_get_invoice_number($invoice_id = 0) {
708
+    $invoice = new WPInv_Invoice($invoice_id);
709 709
     return $invoice->get_number();
710 710
 }
711 711
 
712
-function wpinv_get_cart_discountable_subtotal( $code_id ) {
712
+function wpinv_get_cart_discountable_subtotal($code_id) {
713 713
     $cart_items = wpinv_get_cart_content_details();
714 714
     $items      = array();
715 715
 
716
-    $excluded_items = wpinv_get_discount_excluded_items( $code_id );
716
+    $excluded_items = wpinv_get_discount_excluded_items($code_id);
717 717
 
718
-    if( $cart_items ) {
718
+    if ($cart_items) {
719 719
 
720
-        foreach( $cart_items as $item ) {
720
+        foreach ($cart_items as $item) {
721 721
 
722
-            if( ! in_array( $item['id'], $excluded_items ) ) {
723
-                $items[] =  $item;
722
+            if (!in_array($item['id'], $excluded_items)) {
723
+                $items[] = $item;
724 724
             }
725 725
         }
726 726
     }
727 727
 
728
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
728
+    $subtotal = wpinv_get_cart_items_subtotal($items);
729 729
 
730
-    return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal );
730
+    return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal);
731 731
 }
732 732
 
733
-function wpinv_get_cart_items_subtotal( $items ) {
733
+function wpinv_get_cart_items_subtotal($items) {
734 734
     $subtotal = 0.00;
735 735
 
736
-    if ( is_array( $items ) && ! empty( $items ) ) {
737
-        $prices = wp_list_pluck( $items, 'subtotal' );
736
+    if (is_array($items) && !empty($items)) {
737
+        $prices = wp_list_pluck($items, 'subtotal');
738 738
 
739
-        if( is_array( $prices ) ) {
740
-            $subtotal = array_sum( $prices );
739
+        if (is_array($prices)) {
740
+            $subtotal = array_sum($prices);
741 741
         } else {
742 742
             $subtotal = 0.00;
743 743
         }
744 744
 
745
-        if( $subtotal < 0 ) {
745
+        if ($subtotal < 0) {
746 746
             $subtotal = 0.00;
747 747
         }
748 748
     }
749 749
 
750
-    return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal );
750
+    return apply_filters('wpinv_get_cart_items_subtotal', $subtotal);
751 751
 }
752 752
 
753
-function wpinv_get_cart_subtotal( $items = array() ) {
754
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
755
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
753
+function wpinv_get_cart_subtotal($items = array()) {
754
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
755
+    $subtotal = wpinv_get_cart_items_subtotal($items);
756 756
 
757
-    return apply_filters( 'wpinv_get_cart_subtotal', $subtotal );
757
+    return apply_filters('wpinv_get_cart_subtotal', $subtotal);
758 758
 }
759 759
 
760
-function wpinv_cart_subtotal( $items = array(), $currency = '' ) {
760
+function wpinv_cart_subtotal($items = array(), $currency = '') {
761 761
 
762
-    if( empty( $currency ) ) {
762
+    if (empty($currency)) {
763 763
         $currency = wpinv_get_currency();
764 764
     }
765 765
 
766
-    $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ), $currency );
766
+    $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items)), $currency);
767 767
 
768 768
     return $price;
769 769
 }
770 770
 
771
-function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) {
772
-    $subtotal  = (float)wpinv_get_cart_subtotal( $items );
773
-    $discounts = (float)wpinv_get_cart_discounted_amount( $items );
774
-    $cart_tax  = (float)wpinv_get_cart_tax( $items, $invoice );
775
-    $fees      = (float)wpinv_get_cart_fee_total();
776
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
771
+function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) {
772
+    $subtotal  = (float) wpinv_get_cart_subtotal($items);
773
+    $discounts = (float) wpinv_get_cart_discounted_amount($items);
774
+    $cart_tax  = (float) wpinv_get_cart_tax($items, $invoice);
775
+    $fees      = (float) wpinv_get_cart_fee_total();
776
+    if (!empty($invoice) && $invoice->is_free_trial()) {
777 777
         $total = 0;
778 778
     } else {
779
-        $total     = $subtotal - $discounts + $cart_tax + $fees;
779
+        $total = $subtotal - $discounts + $cart_tax + $fees;
780 780
     }
781 781
 
782
-    if ( $total < 0 ) {
782
+    if ($total < 0) {
783 783
         $total = 0.00;
784 784
     }
785 785
     
786
-    $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items );
786
+    $total = (float) apply_filters('wpinv_get_cart_total', $total, $items);
787 787
 
788
-    return wpinv_sanitize_amount( $total );
788
+    return wpinv_sanitize_amount($total);
789 789
 }
790 790
 
791
-function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) {
791
+function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) {
792 792
     global $cart_total;
793
-    $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ), $invoice->get_currency() );
794
-    $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice );
793
+    $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice)), $invoice->get_currency());
794
+    $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice);
795 795
     
796 796
     $cart_total = $total;
797 797
 
798
-    if ( !$echo ) {
798
+    if (!$echo) {
799 799
         return $total;
800 800
     }
801 801
 
802 802
     echo $total;
803 803
 }
804 804
 
805
-function wpinv_get_cart_tax( $items = array(), $invoice = 0 ) {
805
+function wpinv_get_cart_tax($items = array(), $invoice = 0) {
806 806
 
807
-    if ( ! empty( $invoice ) && ! $invoice->is_taxable() ) {
807
+    if (!empty($invoice) && !$invoice->is_taxable()) {
808 808
         return 0;
809 809
     }
810 810
 
811 811
     $cart_tax = 0;
812
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
812
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
813 813
 
814
-    if ( $items ) {
815
-        $taxes = wp_list_pluck( $items, 'tax' );
814
+    if ($items) {
815
+        $taxes = wp_list_pluck($items, 'tax');
816 816
 
817
-        if( is_array( $taxes ) ) {
818
-            $cart_tax = array_sum( $taxes );
817
+        if (is_array($taxes)) {
818
+            $cart_tax = array_sum($taxes);
819 819
         }
820 820
     }
821 821
 
822 822
     $cart_tax += wpinv_get_cart_fee_tax();
823 823
 
824
-    return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) );
824
+    return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax));
825 825
 }
826 826
 
827
-function wpinv_cart_tax( $items = array(), $echo = false, $currency = '', $invoice = 0 ) {
827
+function wpinv_cart_tax($items = array(), $echo = false, $currency = '', $invoice = 0) {
828 828
 
829
-    if ( ! empty( $invoice && ! $invoice->is_taxable() ) ) {
830
-        echo wpinv_price( wpinv_format_amount( 0 ), $currency );
829
+    if (!empty($invoice && !$invoice->is_taxable())) {
830
+        echo wpinv_price(wpinv_format_amount(0), $currency);
831 831
         return;
832 832
     }
833 833
 
834
-    $cart_tax = wpinv_get_cart_tax( $items, $invoice );
835
-    $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ), $currency );
834
+    $cart_tax = wpinv_get_cart_tax($items, $invoice);
835
+    $cart_tax = wpinv_price(wpinv_format_amount($cart_tax), $currency);
836 836
 
837
-    $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items );
837
+    $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items);
838 838
 
839
-    if ( !$echo ) {
839
+    if (!$echo) {
840 840
         return $tax;
841 841
     }
842 842
 
843 843
     echo $tax;
844 844
 }
845 845
 
846
-function wpinv_get_cart_discount_code( $items = array() ) {
846
+function wpinv_get_cart_discount_code($items = array()) {
847 847
     $invoice = wpinv_get_invoice_cart();
848
-    $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : '';
848
+    $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : '';
849 849
     
850
-    return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code );
850
+    return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code);
851 851
 }
852 852
 
853
-function wpinv_cart_discount_code( $items = array(), $echo = false ) {
854
-    $cart_discount_code = wpinv_get_cart_discount_code( $items );
853
+function wpinv_cart_discount_code($items = array(), $echo = false) {
854
+    $cart_discount_code = wpinv_get_cart_discount_code($items);
855 855
 
856
-    if ( $cart_discount_code != '' ) {
856
+    if ($cart_discount_code != '') {
857 857
         $cart_discount_code = ' (' . $cart_discount_code . ')';
858 858
     }
859 859
     
860
-    $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items );
860
+    $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items);
861 861
 
862
-    if ( !$echo ) {
862
+    if (!$echo) {
863 863
         return $discount_code;
864 864
     }
865 865
 
866 866
     echo $discount_code;
867 867
 }
868 868
 
869
-function wpinv_get_cart_discount( $items = array() ) {
869
+function wpinv_get_cart_discount($items = array()) {
870 870
     $invoice = wpinv_get_invoice_cart();
871
-    $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0;
871
+    $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0;
872 872
     
873
-    return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items );
873
+    return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items);
874 874
 }
875 875
 
876
-function wpinv_cart_discount( $items = array(), $echo = false ) {
877
-    $cart_discount = wpinv_get_cart_discount( $items );
878
-    $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) );
876
+function wpinv_cart_discount($items = array(), $echo = false) {
877
+    $cart_discount = wpinv_get_cart_discount($items);
878
+    $cart_discount = wpinv_price(wpinv_format_amount($cart_discount));
879 879
 
880
-    $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items );
880
+    $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items);
881 881
 
882
-    if ( !$echo ) {
882
+    if (!$echo) {
883 883
         return $discount;
884 884
     }
885 885
 
886 886
     echo $discount;
887 887
 }
888 888
 
889
-function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) {
890
-    $item = new WPInv_Item( $item_id );
889
+function wpinv_get_cart_fees($type = 'all', $item_id = 0) {
890
+    $item = new WPInv_Item($item_id);
891 891
     
892
-    return $item->get_fees( $type, $item_id );
892
+    return $item->get_fees($type, $item_id);
893 893
 }
894 894
 
895 895
 function wpinv_get_cart_fee_total() {
896
-    $total  = 0;
896
+    $total = 0;
897 897
     $fees = wpinv_get_cart_fees();
898 898
     
899
-    if ( $fees ) {
900
-        foreach ( $fees as $fee_id => $fee ) {
899
+    if ($fees) {
900
+        foreach ($fees as $fee_id => $fee) {
901 901
             $total += $fee['amount'];
902 902
         }
903 903
     }
904 904
 
905
-    return apply_filters( 'wpinv_get_cart_fee_total', $total );
905
+    return apply_filters('wpinv_get_cart_fee_total', $total);
906 906
 }
907 907
 
908 908
 function wpinv_get_cart_fee_tax() {
909 909
     $tax  = 0;
910 910
     $fees = wpinv_get_cart_fees();
911 911
 
912
-    if ( $fees ) {
913
-        foreach ( $fees as $fee_id => $fee ) {
914
-            if( ! empty( $fee['no_tax'] ) ) {
912
+    if ($fees) {
913
+        foreach ($fees as $fee_id => $fee) {
914
+            if (!empty($fee['no_tax'])) {
915 915
                 continue;
916 916
             }
917 917
 
918
-            $tax += wpinv_calculate_tax( $fee['amount'] );
918
+            $tax += wpinv_calculate_tax($fee['amount']);
919 919
         }
920 920
     }
921 921
 
922
-    return apply_filters( 'wpinv_get_cart_fee_tax', $tax );
922
+    return apply_filters('wpinv_get_cart_fee_tax', $tax);
923 923
 }
924 924
 
925 925
 function wpinv_cart_has_recurring_item() {
926 926
     $cart_items = wpinv_get_cart_contents();
927 927
     
928
-    if ( empty( $cart_items ) ) {
928
+    if (empty($cart_items)) {
929 929
         return false;
930 930
     }
931 931
     
932 932
     $has_subscription = false;
933
-    foreach( $cart_items as $cart_item ) {
934
-        if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
933
+    foreach ($cart_items as $cart_item) {
934
+        if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
935 935
             $has_subscription = true;
936 936
             break;
937 937
         }
938 938
     }
939 939
     
940
-    return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items );
940
+    return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items);
941 941
 }
942 942
 
943 943
 function wpinv_cart_has_free_trial() {
@@ -945,100 +945,100 @@  discard block
 block discarded – undo
945 945
     
946 946
     $free_trial = false;
947 947
     
948
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
948
+    if (!empty($invoice) && $invoice->is_free_trial()) {
949 949
         $free_trial = true;
950 950
     }
951 951
     
952
-    return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice );
952
+    return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice);
953 953
 }
954 954
 
955 955
 function wpinv_get_cart_contents() {
956 956
     $cart_details = wpinv_get_cart_details();
957 957
     
958
-    return apply_filters( 'wpinv_get_cart_contents', $cart_details );
958
+    return apply_filters('wpinv_get_cart_contents', $cart_details);
959 959
 }
960 960
 
961 961
 function wpinv_get_cart_content_details() {
962 962
     global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
963 963
     $cart_items = wpinv_get_cart_contents();
964 964
     
965
-    if ( empty( $cart_items ) ) {
965
+    if (empty($cart_items)) {
966 966
         return false;
967 967
     }
968 968
     $invoice = wpinv_get_invoice_cart();
969
-	if ( empty( $invoice ) ) {
969
+	if (empty($invoice)) {
970 970
         return false;
971 971
     }
972 972
 
973 973
     $details = array();
974
-    $length  = count( $cart_items ) - 1;
974
+    $length  = count($cart_items) - 1;
975 975
     
976
-    if ( empty( $_POST['country'] ) ) {
976
+    if (empty($_POST['country'])) {
977 977
         $_POST['country'] = $invoice->country;
978 978
     }
979
-    if ( !isset( $_POST['state'] ) ) {
979
+    if (!isset($_POST['state'])) {
980 980
         $_POST['state'] = $invoice->state;
981 981
     }
982 982
 
983
-    foreach( $cart_items as $key => $item ) {
984
-        $item_id            = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '';
985
-        if ( empty( $item_id ) ) {
983
+    foreach ($cart_items as $key => $item) {
984
+        $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : '';
985
+        if (empty($item_id)) {
986 986
             continue;
987 987
         }
988 988
         
989 989
         $wpi_current_id         = $invoice->ID;
990 990
         $wpi_item_id            = $item_id;
991 991
         
992
-        if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) {
992
+        if (isset($item['custom_price']) && $item['custom_price'] !== '') {
993 993
             $item_price = $item['custom_price'];
994 994
         } else {
995
-            if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) {
995
+            if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) {
996 996
                 $item_price = $item['item_price'];
997 997
             } else {
998
-                $item_price = wpinv_get_item_price( $item_id );
998
+                $item_price = wpinv_get_item_price($item_id);
999 999
             }
1000 1000
         }
1001
-        $discount           = wpinv_get_cart_item_discount_amount( $item );
1002
-        $discount           = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item );
1003
-        $quantity           = wpinv_get_cart_item_quantity( $item );
1004
-        $fees               = wpinv_get_cart_fees( 'fee', $item_id );
1001
+        $discount           = wpinv_get_cart_item_discount_amount($item);
1002
+        $discount           = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item);
1003
+        $quantity           = wpinv_get_cart_item_quantity($item);
1004
+        $fees               = wpinv_get_cart_fees('fee', $item_id);
1005 1005
         
1006 1006
         $subtotal           = $item_price * $quantity;
1007
-        $tax_rate           = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id );
1008
-        $tax_class          = $wpinv_euvat->get_item_class( $item_id );
1009
-        $tax                = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount );
1007
+        $tax_rate           = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id);
1008
+        $tax_class          = $wpinv_euvat->get_item_class($item_id);
1009
+        $tax                = wpinv_get_cart_item_tax($item_id, $subtotal - $discount);
1010 1010
         
1011
-        if ( ! $invoice->is_taxable() ) {
1011
+        if (!$invoice->is_taxable()) {
1012 1012
             $tax = 0;
1013 1013
         }
1014
-        if ( wpinv_prices_include_tax() ) {
1015
-            $subtotal -= wpinv_round_amount( $tax );
1014
+        if (wpinv_prices_include_tax()) {
1015
+            $subtotal -= wpinv_round_amount($tax);
1016 1016
         }
1017 1017
         
1018
-        $total              = $subtotal - $discount + $tax;
1018
+        $total = $subtotal - $discount + $tax;
1019 1019
         
1020 1020
         // Do not allow totals to go negatve
1021
-        if( $total < 0 ) {
1021
+        if ($total < 0) {
1022 1022
             $total = 0;
1023 1023
         }
1024 1024
         
1025
-        $details[ $key ]  = array(
1025
+        $details[$key] = array(
1026 1026
             'id'                => $item_id,
1027
-            'name'              => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ),
1028
-            'item_price'        => wpinv_round_amount( $item_price ),
1029
-            'custom_price'      => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
1027
+            'name'              => !empty($item['name']) ? $item['name'] : get_the_title($item_id),
1028
+            'item_price'        => wpinv_round_amount($item_price),
1029
+            'custom_price'      => isset($item['custom_price']) ? $item['custom_price'] : '',
1030 1030
             'quantity'          => $quantity,
1031
-            'discount'          => wpinv_round_amount( $discount ),
1032
-            'subtotal'          => wpinv_round_amount( $subtotal ),
1033
-            'tax'               => wpinv_round_amount( $tax ),
1034
-            'price'             => wpinv_round_amount( $total ),
1031
+            'discount'          => wpinv_round_amount($discount),
1032
+            'subtotal'          => wpinv_round_amount($subtotal),
1033
+            'tax'               => wpinv_round_amount($tax),
1034
+            'price'             => wpinv_round_amount($total),
1035 1035
             'vat_rates_class'   => $tax_class,
1036 1036
             'vat_rate'          => $tax_rate,
1037
-            'meta'              => isset( $item['meta'] ) ? $item['meta'] : array(),
1037
+            'meta'              => isset($item['meta']) ? $item['meta'] : array(),
1038 1038
             'fees'              => $fees,
1039 1039
         );
1040 1040
         
1041
-        if ( $wpinv_is_last_cart_item ) {
1041
+        if ($wpinv_is_last_cart_item) {
1042 1042
             $wpinv_is_last_cart_item   = false;
1043 1043
             $wpinv_flat_discount_total = 0.00;
1044 1044
         }
@@ -1047,67 +1047,67 @@  discard block
 block discarded – undo
1047 1047
     return $details;
1048 1048
 }
1049 1049
 
1050
-function wpinv_get_cart_details( $invoice_id = 0 ) {
1050
+function wpinv_get_cart_details($invoice_id = 0) {
1051 1051
     global $ajax_cart_details;
1052 1052
 
1053
-    $invoice      = wpinv_get_invoice_cart( $invoice_id );
1053
+    $invoice      = wpinv_get_invoice_cart($invoice_id);
1054 1054
     $cart_details = $ajax_cart_details;
1055
-    if ( empty( $cart_details ) && ! empty( $invoice->cart_details ) ) {
1055
+    if (empty($cart_details) && !empty($invoice->cart_details)) {
1056 1056
         $cart_details = $invoice->cart_details;
1057 1057
     }
1058 1058
 
1059
-    if ( ! empty( $cart_details ) && is_array( $cart_details ) ) {
1060
-        $invoice_currency = ! empty( $invoice->currency ) ? $invoice->currency : wpinv_get_default_country();
1059
+    if (!empty($cart_details) && is_array($cart_details)) {
1060
+        $invoice_currency = !empty($invoice->currency) ? $invoice->currency : wpinv_get_default_country();
1061 1061
 
1062
-        foreach ( $cart_details as $key => $cart_item ) {
1063
-            $cart_details[ $key ]['currency'] = $invoice_currency;
1062
+        foreach ($cart_details as $key => $cart_item) {
1063
+            $cart_details[$key]['currency'] = $invoice_currency;
1064 1064
 
1065
-            if ( ! isset( $cart_item['subtotal'] ) ) {
1066
-                $cart_details[ $key ]['subtotal'] = $cart_item['price'];
1065
+            if (!isset($cart_item['subtotal'])) {
1066
+                $cart_details[$key]['subtotal'] = $cart_item['price'];
1067 1067
             }
1068 1068
         }
1069 1069
     }
1070 1070
 
1071
-    return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id );
1071
+    return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id);
1072 1072
 }
1073 1073
 
1074
-function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) {
1075
-    if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) {
1074
+function wpinv_record_status_change($invoice_id, $new_status, $old_status) {
1075
+    if ('wpi_invoice' != get_post_type($invoice_id)) {
1076 1076
         return;
1077 1077
     }
1078 1078
 
1079
-    if ( ( $old_status == 'wpi-pending' && $new_status == 'draft' ) || ( $old_status == 'draft' && $new_status == 'wpi-pending' ) ) {
1079
+    if (($old_status == 'wpi-pending' && $new_status == 'draft') || ($old_status == 'draft' && $new_status == 'wpi-pending')) {
1080 1080
         return;
1081 1081
     }
1082 1082
 
1083
-    $invoice    = wpinv_get_invoice( $invoice_id );
1083
+    $invoice    = wpinv_get_invoice($invoice_id);
1084 1084
     
1085
-    $old_status = wpinv_status_nicename( $old_status );
1086
-    $new_status = wpinv_status_nicename( $new_status );
1085
+    $old_status = wpinv_status_nicename($old_status);
1086
+    $new_status = wpinv_status_nicename($new_status);
1087 1087
 
1088
-    $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status );
1088
+    $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status);
1089 1089
     
1090 1090
     // Add note
1091
-    return $invoice->add_note( $status_change, false, false, true );
1091
+    return $invoice->add_note($status_change, false, false, true);
1092 1092
 }
1093
-add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 );
1093
+add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3);
1094 1094
 
1095
-function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) {
1095
+function wpinv_complete_payment($invoice_id, $new_status, $old_status) {
1096 1096
     global $wpi_has_free_trial;
1097 1097
     
1098 1098
     $wpi_has_free_trial = false;
1099 1099
     
1100
-    if ( $old_status == 'publish' ) {
1100
+    if ($old_status == 'publish') {
1101 1101
         return; // Make sure that payments are only paid once
1102 1102
     }
1103 1103
 
1104 1104
     // Make sure the payment completion is only processed when new status is paid
1105
-    if ( $new_status != 'publish' ) {
1105
+    if ($new_status != 'publish') {
1106 1106
         return;
1107 1107
     }
1108 1108
 
1109
-    $invoice = new WPInv_Invoice( $invoice_id );
1110
-    if ( empty( $invoice ) ) {
1109
+    $invoice = new WPInv_Invoice($invoice_id);
1110
+    if (empty($invoice)) {
1111 1111
         return;
1112 1112
     }
1113 1113
 
@@ -1115,58 +1115,58 @@  discard block
 block discarded – undo
1115 1115
     $completed_date = $invoice->completed_date;
1116 1116
     $cart_details   = $invoice->cart_details;
1117 1117
 
1118
-    do_action( 'wpinv_pre_complete_payment', $invoice_id );
1118
+    do_action('wpinv_pre_complete_payment', $invoice_id);
1119 1119
 
1120
-    if ( is_array( $cart_details ) ) {
1120
+    if (is_array($cart_details)) {
1121 1121
         // Increase purchase count and earnings
1122
-        foreach ( $cart_details as $cart_index => $item ) {
1122
+        foreach ($cart_details as $cart_index => $item) {
1123 1123
             // Ensure these actions only run once, ever
1124
-            if ( empty( $completed_date ) ) {
1125
-                do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index );
1124
+            if (empty($completed_date)) {
1125
+                do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index);
1126 1126
             }
1127 1127
         }
1128 1128
     }
1129 1129
     
1130 1130
     // Check for discount codes and increment their use counts
1131
-    if ( $discounts = $invoice->get_discounts( true ) ) {
1132
-        if( ! empty( $discounts ) ) {
1133
-            foreach( $discounts as $code ) {
1134
-                wpinv_increase_discount_usage( $code );
1131
+    if ($discounts = $invoice->get_discounts(true)) {
1132
+        if (!empty($discounts)) {
1133
+            foreach ($discounts as $code) {
1134
+                wpinv_increase_discount_usage($code);
1135 1135
             }
1136 1136
         }
1137 1137
     }
1138 1138
     
1139 1139
     // Ensure this action only runs once ever
1140
-    if( empty( $completed_date ) ) {
1140
+    if (empty($completed_date)) {
1141 1141
         // Save the completed date
1142
-        $invoice->set( 'completed_date', current_time( 'mysql', 0 ) );
1142
+        $invoice->set('completed_date', current_time('mysql', 0));
1143 1143
         $invoice->save();
1144 1144
 
1145
-        do_action( 'wpinv_complete_payment', $invoice_id );
1145
+        do_action('wpinv_complete_payment', $invoice_id);
1146 1146
     }
1147 1147
 
1148 1148
     // Empty the shopping cart
1149 1149
     wpinv_empty_cart();
1150 1150
 }
1151
-add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 );
1151
+add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3);
1152 1152
 
1153
-function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) {    
1154
-    $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id );
1153
+function wpinv_update_payment_status($invoice_id, $new_status = 'publish') {    
1154
+    $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int) $invoice_id);
1155 1155
     
1156
-    if ( empty( $invoice ) ) {
1156
+    if (empty($invoice)) {
1157 1157
         return false;
1158 1158
     }
1159 1159
     
1160
-    return $invoice->update_status( $new_status );
1160
+    return $invoice->update_status($new_status);
1161 1161
 }
1162 1162
 
1163
-function wpinv_cart_has_fees( $type = 'all' ) {
1163
+function wpinv_cart_has_fees($type = 'all') {
1164 1164
     return false;
1165 1165
 }
1166 1166
 
1167 1167
 function wpinv_validate_checkout_fields() {    
1168 1168
     // Check if there is $_POST
1169
-    if ( empty( $_POST ) ) {
1169
+    if (empty($_POST)) {
1170 1170
         return false;
1171 1171
     }
1172 1172
     
@@ -1178,11 +1178,11 @@  discard block
 block discarded – undo
1178 1178
     );
1179 1179
     
1180 1180
     // Validate agree to terms
1181
-    $page = wpinv_get_option( 'tandc_page' );
1182
-    if(isset($page) && (int)$page > 0 && apply_filters( 'wpinv_checkout_show_terms', true )){
1181
+    $page = wpinv_get_option('tandc_page');
1182
+    if (isset($page) && (int) $page > 0 && apply_filters('wpinv_checkout_show_terms', true)) {
1183 1183
         // Validate agree to terms
1184
-        if ( ! isset( $_POST['wpi_terms'] ) || !$_POST['wpi_terms'] ) {
1185
-            wpinv_set_error( 'accept_terms', apply_filters( 'wpinv_accept_terms_error_text', __( 'You must accept terms and conditions', 'invoicing' ) ) );
1184
+        if (!isset($_POST['wpi_terms']) || !$_POST['wpi_terms']) {
1185
+            wpinv_set_error('accept_terms', apply_filters('wpinv_accept_terms_error_text', __('You must accept terms and conditions', 'invoicing')));
1186 1186
         }
1187 1187
     }
1188 1188
     
@@ -1198,28 +1198,28 @@  discard block
 block discarded – undo
1198 1198
     
1199 1199
     $invoice = wpinv_get_invoice_cart();
1200 1200
     $has_subscription = $invoice->is_recurring();
1201
-    if ( empty( $invoice ) ) {
1202
-        wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) );
1201
+    if (empty($invoice)) {
1202
+        wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing'));
1203 1203
         return $gateway;
1204 1204
     }
1205 1205
 
1206 1206
     // Check if a gateway value is present
1207
-    if ( !empty( $_REQUEST['wpi-gateway'] ) ) {
1208
-        $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] );
1207
+    if (!empty($_REQUEST['wpi-gateway'])) {
1208
+        $gateway = sanitize_text_field($_REQUEST['wpi-gateway']);
1209 1209
 
1210
-        if ( $invoice->is_free() ) {
1210
+        if ($invoice->is_free()) {
1211 1211
             $gateway = 'manual';
1212
-        } elseif ( !wpinv_is_gateway_active( $gateway ) ) {
1213
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) );
1214
-        } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) {
1215
-            if ( apply_filters( 'wpinv_reject_non_recurring_gateway', true ) ) {
1216
-                wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway does not support subscription payment', 'invoicing' ) );
1212
+        } elseif (!wpinv_is_gateway_active($gateway)) {
1213
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing'));
1214
+        } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) {
1215
+            if (apply_filters('wpinv_reject_non_recurring_gateway', true)) {
1216
+                wpinv_set_error('invalid_gateway', __('The selected payment gateway does not support subscription payment', 'invoicing'));
1217 1217
             }
1218 1218
         }
1219 1219
     }
1220 1220
 
1221
-    if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) {
1222
-        wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) );
1221
+    if ($has_subscription && count(wpinv_get_cart_contents()) > 1) {
1222
+        wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing'));
1223 1223
     }
1224 1224
 
1225 1225
     return $gateway;
@@ -1233,10 +1233,10 @@  discard block
 block discarded – undo
1233 1233
     
1234 1234
     $error = false;
1235 1235
     // If we have discounts, loop through them
1236
-    if ( ! empty( $discounts ) ) {
1237
-        foreach ( $discounts as $discount ) {
1236
+    if (!empty($discounts)) {
1237
+        foreach ($discounts as $discount) {
1238 1238
             // Check if valid
1239
-            if (  !wpinv_is_discount_valid( $discount, (int)$wpi_cart->get_user_id() ) ) {
1239
+            if (!wpinv_is_discount_valid($discount, (int) $wpi_cart->get_user_id())) {
1240 1240
                 // Discount is not valid
1241 1241
                 $error = true;
1242 1242
             }
@@ -1246,20 +1246,20 @@  discard block
 block discarded – undo
1246 1246
         return NULL;
1247 1247
     }
1248 1248
 
1249
-    if ( $error && !wpinv_get_errors() ) {
1250
-        wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) );
1249
+    if ($error && !wpinv_get_errors()) {
1250
+        wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing'));
1251 1251
     }
1252 1252
 
1253
-    return implode( ',', $discounts );
1253
+    return implode(',', $discounts);
1254 1254
 }
1255 1255
 
1256 1256
 function wpinv_checkout_validate_cc() {
1257 1257
     $card_data = wpinv_checkout_get_cc_info();
1258 1258
 
1259 1259
     // Validate the card zip
1260
-    if ( !empty( $card_data['wpinv_zip'] ) ) {
1261
-        if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) {
1262
-            wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) );
1260
+    if (!empty($card_data['wpinv_zip'])) {
1261
+        if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) {
1262
+            wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing'));
1263 1263
         }
1264 1264
     }
1265 1265
 
@@ -1269,28 +1269,28 @@  discard block
 block discarded – undo
1269 1269
 
1270 1270
 function wpinv_checkout_get_cc_info() {
1271 1271
 	$cc_info = array();
1272
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
1273
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
1274
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
1275
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
1276
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
1277
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
1278
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
1279
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
1280
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
1281
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
1272
+	$cc_info['card_name']      = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : '';
1273
+	$cc_info['card_number']    = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : '';
1274
+	$cc_info['card_cvc']       = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : '';
1275
+	$cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : '';
1276
+	$cc_info['card_exp_year']  = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : '';
1277
+	$cc_info['card_address']   = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : '';
1278
+	$cc_info['card_city']      = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : '';
1279
+	$cc_info['card_state']     = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : '';
1280
+	$cc_info['card_country']   = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : '';
1281
+	$cc_info['card_zip']       = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : '';
1282 1282
 
1283 1283
 	// Return cc info
1284 1284
 	return $cc_info;
1285 1285
 }
1286 1286
 
1287
-function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
1287
+function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') {
1288 1288
     $ret = false;
1289 1289
 
1290
-    if ( empty( $zip ) || empty( $country_code ) )
1290
+    if (empty($zip) || empty($country_code))
1291 1291
         return $ret;
1292 1292
 
1293
-    $country_code = strtoupper( $country_code );
1293
+    $country_code = strtoupper($country_code);
1294 1294
 
1295 1295
     $zip_regex = array(
1296 1296
         "AD" => "AD\d{3}",
@@ -1450,72 +1450,72 @@  discard block
 block discarded – undo
1450 1450
         "ZM" => "\d{5}"
1451 1451
     );
1452 1452
 
1453
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
1453
+    if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip))
1454 1454
         $ret = true;
1455 1455
 
1456
-    return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
1456
+    return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code);
1457 1457
 }
1458 1458
 
1459 1459
 function wpinv_checkout_validate_agree_to_terms() {
1460 1460
     // Validate agree to terms
1461
-    if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) {
1461
+    if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) {
1462 1462
         // User did not agree
1463
-        wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) );
1463
+        wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing')));
1464 1464
     }
1465 1465
 }
1466 1466
 
1467 1467
 function wpinv_checkout_validate_invoice_user() {
1468 1468
     global $wpi_cart, $user_ID;
1469 1469
 
1470
-    if(empty($wpi_cart)){
1470
+    if (empty($wpi_cart)) {
1471 1471
         $wpi_cart = wpinv_get_invoice_cart();
1472 1472
     }
1473 1473
 
1474
-    $invoice_user = (int)$wpi_cart->get_user_id();
1474
+    $invoice_user = (int) $wpi_cart->get_user_id();
1475 1475
     $valid_user_data = array(
1476 1476
         'user_id' => $invoice_user
1477 1477
     );
1478 1478
 
1479 1479
     // If guest checkout allowed
1480
-    if ( !wpinv_require_login_to_checkout() ) {
1480
+    if (!wpinv_require_login_to_checkout()) {
1481 1481
         return $valid_user_data;
1482 1482
     }
1483 1483
     
1484 1484
     // Verify there is a user_ID
1485
-    if ( $user_ID == $invoice_user ) {
1485
+    if ($user_ID == $invoice_user) {
1486 1486
         // Get the logged in user data
1487
-        $user_data = get_userdata( $user_ID );
1488
-        $required_fields  = wpinv_checkout_required_fields();
1487
+        $user_data = get_userdata($user_ID);
1488
+        $required_fields = wpinv_checkout_required_fields();
1489 1489
 
1490 1490
         // Loop through required fields and show error messages
1491
-         if ( !empty( $required_fields ) ) {
1492
-            foreach ( $required_fields as $field_name => $value ) {
1493
-                if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
1494
-                    wpinv_set_error( $value['error_id'], $value['error_message'] );
1491
+         if (!empty($required_fields)) {
1492
+            foreach ($required_fields as $field_name => $value) {
1493
+                if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) {
1494
+                    wpinv_set_error($value['error_id'], $value['error_message']);
1495 1495
                 }
1496 1496
             }
1497 1497
         }
1498 1498
 
1499 1499
         // Verify data
1500
-        if ( $user_data ) {
1500
+        if ($user_data) {
1501 1501
             // Collected logged in user data
1502 1502
             $valid_user_data = array(
1503 1503
                 'user_id'     => $user_ID,
1504
-                'email'       => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email,
1505
-                'first_name'  => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name,
1506
-                'last_name'   => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name']  ) ? sanitize_text_field( $_POST['wpinv_last_name']  ) : $user_data->last_name,
1504
+                'email'       => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email,
1505
+                'first_name'  => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name,
1506
+                'last_name'   => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name,
1507 1507
             );
1508 1508
 
1509
-            if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) {
1510
-                wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) );
1509
+            if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) {
1510
+                wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing'));
1511 1511
             }
1512 1512
         } else {
1513 1513
             // Set invalid user error
1514
-            wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) );
1514
+            wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing'));
1515 1515
         }
1516 1516
     } else {
1517 1517
         // Set invalid user error
1518
-        wpinv_set_error( 'invalid_user_id', __( 'The invalid invoice user id', 'invoicing' ) );
1518
+        wpinv_set_error('invalid_user_id', __('The invalid invoice user id', 'invoicing'));
1519 1519
     }
1520 1520
 
1521 1521
     // Return user data
@@ -1527,27 +1527,27 @@  discard block
 block discarded – undo
1527 1527
 
1528 1528
     $data = array();
1529 1529
     
1530
-    if ( is_user_logged_in() ) {
1531
-        if ( !wpinv_require_login_to_checkout() || ( wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id() ) ) {
1532
-            $data['user_id'] = (int)get_current_user_id();
1530
+    if (is_user_logged_in()) {
1531
+        if (!wpinv_require_login_to_checkout() || (wpinv_require_login_to_checkout() && (int) $wpi_cart->get_user_id() === (int) get_current_user_id())) {
1532
+            $data['user_id'] = (int) get_current_user_id();
1533 1533
         } else {
1534
-            wpinv_set_error( 'logged_in_only', __( 'You are not allowed to pay for this invoice', 'invoicing' ) );
1534
+            wpinv_set_error('logged_in_only', __('You are not allowed to pay for this invoice', 'invoicing'));
1535 1535
         }
1536 1536
     } else {
1537 1537
         // If guest checkout allowed
1538
-        if ( !wpinv_require_login_to_checkout() ) {
1538
+        if (!wpinv_require_login_to_checkout()) {
1539 1539
             $data['user_id'] = 0;
1540 1540
         } else {
1541
-            wpinv_set_error( 'logged_in_only', __( 'You must be logged in to pay for this invoice', 'invoicing' ) );
1541
+            wpinv_set_error('logged_in_only', __('You must be logged in to pay for this invoice', 'invoicing'));
1542 1542
         }
1543 1543
     }
1544 1544
 
1545 1545
     return $data;
1546 1546
 }
1547 1547
 
1548
-function wpinv_checkout_form_get_user( $valid_data = array() ) {
1548
+function wpinv_checkout_form_get_user($valid_data = array()) {
1549 1549
 
1550
-    if ( !empty( $valid_data['current_user']['user_id'] ) ) {
1550
+    if (!empty($valid_data['current_user']['user_id'])) {
1551 1551
         $user = $valid_data['current_user'];
1552 1552
     } else {
1553 1553
         // Set the valid invoice user
@@ -1555,7 +1555,7 @@  discard block
 block discarded – undo
1555 1555
     }
1556 1556
 
1557 1557
     // Verify invoice have an user
1558
-    if ( false === $user || empty( $user ) ) {
1558
+    if (false === $user || empty($user)) {
1559 1559
         return false;
1560 1560
     }
1561 1561
 
@@ -1572,11 +1572,11 @@  discard block
 block discarded – undo
1572 1572
         'zip',
1573 1573
     );
1574 1574
     
1575
-    foreach ( $address_fields as $field ) {
1576
-        $user[$field]  = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false;
1575
+    foreach ($address_fields as $field) {
1576
+        $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false;
1577 1577
         
1578
-        if ( !empty( $user['user_id'] ) && !empty( $valid_data['current_user']['user_id'] ) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id'] ) {
1579
-            update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] );
1578
+        if (!empty($user['user_id']) && !empty($valid_data['current_user']['user_id']) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id']) {
1579
+            update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]);
1580 1580
         }
1581 1581
     }
1582 1582
 
@@ -1584,28 +1584,28 @@  discard block
 block discarded – undo
1584 1584
     return $user;
1585 1585
 }
1586 1586
 
1587
-function wpinv_set_checkout_session( $invoice_data = array() ) {
1587
+function wpinv_set_checkout_session($invoice_data = array()) {
1588 1588
     global $wpi_session;
1589 1589
     
1590
-    return $wpi_session->set( 'wpinv_checkout', $invoice_data );
1590
+    return $wpi_session->set('wpinv_checkout', $invoice_data);
1591 1591
 }
1592 1592
 
1593 1593
 function wpinv_get_checkout_session() {
1594 1594
 	global $wpi_session;
1595 1595
 
1596
-    return $wpi_session->get( 'wpinv_checkout' );
1596
+    return $wpi_session->get('wpinv_checkout');
1597 1597
 }
1598 1598
 
1599 1599
 function wpinv_empty_cart() {
1600 1600
     global $wpi_session;
1601 1601
 
1602 1602
     // Remove cart contents
1603
-    $wpi_session->set( 'wpinv_checkout', NULL );
1603
+    $wpi_session->set('wpinv_checkout', NULL);
1604 1604
 
1605 1605
     // Remove all cart fees
1606
-    $wpi_session->set( 'wpi_cart_fees', NULL );
1606
+    $wpi_session->set('wpi_cart_fees', NULL);
1607 1607
 
1608
-    do_action( 'wpinv_empty_cart' );
1608
+    do_action('wpinv_empty_cart');
1609 1609
 }
1610 1610
 
1611 1611
 function wpinv_process_checkout() {
@@ -1614,7 +1614,7 @@  discard block
 block discarded – undo
1614 1614
     wpinv_clear_errors();
1615 1615
 
1616 1616
     $invoice = wpinv_get_invoice_cart();
1617
-    if ( empty( $invoice ) ) {
1617
+    if (empty($invoice)) {
1618 1618
         return false;
1619 1619
     }
1620 1620
 
@@ -1622,42 +1622,42 @@  discard block
 block discarded – undo
1622 1622
 
1623 1623
     $wpi_checkout_id = $invoice->ID;
1624 1624
 
1625
-    do_action( 'wpinv_pre_process_checkout' );
1625
+    do_action('wpinv_pre_process_checkout');
1626 1626
     
1627
-    if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty
1627
+    if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty
1628 1628
         $valid_data = false;
1629
-        wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) );
1629
+        wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing'));
1630 1630
     } else {
1631 1631
         // Validate the form $_POST data
1632 1632
         $valid_data = wpinv_validate_checkout_fields();
1633 1633
         
1634 1634
         // Allow themes and plugins to hook to errors
1635
-        do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST );
1635
+        do_action('wpinv_checkout_error_checks', $valid_data, $_POST);
1636 1636
     }
1637 1637
     
1638
-    $is_ajax    = defined( 'DOING_AJAX' ) && DOING_AJAX;
1638
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1639 1639
     
1640 1640
     // Validate the user
1641
-    $user = wpinv_checkout_form_get_user( $valid_data );
1641
+    $user = wpinv_checkout_form_get_user($valid_data);
1642 1642
 
1643 1643
     // Let extensions validate fields after user is logged in if user has used login/registration form
1644
-    do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST );
1644
+    do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST);
1645 1645
     
1646
-    if ( false === $valid_data || wpinv_get_errors() || ! $user ) {
1647
-        if ( $is_ajax && 'wpinv_payment_form' != $_REQUEST['action'] ) {
1648
-            do_action( 'wpinv_ajax_checkout_errors' );
1646
+    if (false === $valid_data || wpinv_get_errors() || !$user) {
1647
+        if ($is_ajax && 'wpinv_payment_form' != $_REQUEST['action']) {
1648
+            do_action('wpinv_ajax_checkout_errors');
1649 1649
             die();
1650 1650
         } else {
1651 1651
             return false;
1652 1652
         }
1653 1653
     }
1654 1654
 
1655
-    if ( $is_ajax && 'wpinv_payment_form' != $_REQUEST['action'] ) {
1655
+    if ($is_ajax && 'wpinv_payment_form' != $_REQUEST['action']) {
1656 1656
         // Save address fields.
1657
-        $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' );
1658
-        foreach ( $address_fields as $field ) {
1659
-            if ( isset( $user[$field] ) ) {
1660
-                $invoice->set( $field, $user[$field] );
1657
+        $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company');
1658
+        foreach ($address_fields as $field) {
1659
+            if (isset($user[$field])) {
1660
+                $invoice->set($field, $user[$field]);
1661 1661
             }
1662 1662
 
1663 1663
             $invoice->save();
@@ -1665,16 +1665,16 @@  discard block
 block discarded – undo
1665 1665
 
1666 1666
         $response['success']            = true;
1667 1667
         $response['data']['subtotal']   = $invoice->get_subtotal();
1668
-        $response['data']['subtotalf']  = $invoice->get_subtotal( true );
1668
+        $response['data']['subtotalf']  = $invoice->get_subtotal(true);
1669 1669
         $response['data']['discount']   = $invoice->get_discount();
1670
-        $response['data']['discountf']  = $invoice->get_discount( true );
1670
+        $response['data']['discountf']  = $invoice->get_discount(true);
1671 1671
         $response['data']['tax']        = $invoice->get_tax();
1672
-        $response['data']['taxf']       = $invoice->get_tax( true );
1672
+        $response['data']['taxf']       = $invoice->get_tax(true);
1673 1673
         $response['data']['total']      = $invoice->get_total();
1674
-        $response['data']['totalf']     = $invoice->get_total( true );
1675
-	    $response['data']['free']       = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false;
1674
+        $response['data']['totalf']     = $invoice->get_total(true);
1675
+	    $response['data']['free'] = $invoice->is_free() && (!((float) $response['data']['total'] > 0) || $invoice->is_free_trial()) ? true : false;
1676 1676
 
1677
-        wp_send_json( $response );
1677
+        wp_send_json($response);
1678 1678
     }
1679 1679
     
1680 1680
     $user_info = array(
@@ -1696,42 +1696,42 @@  discard block
 block discarded – undo
1696 1696
     
1697 1697
     // Setup invoice information
1698 1698
     $invoice_data = array(
1699
-        'invoice_id'        => !empty( $invoice ) ? $invoice->ID : 0,
1699
+        'invoice_id'        => !empty($invoice) ? $invoice->ID : 0,
1700 1700
         'items'             => $cart_items,
1701 1701
         'cart_discounts'    => $discounts,
1702
-        'fees'              => wpinv_get_cart_fees(),        // Any arbitrary fees that have been added to the cart
1703
-        'subtotal'          => wpinv_get_cart_subtotal( $cart_items ),    // Amount before taxes and discounts
1704
-        'discount'          => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount
1705
-        'tax'               => wpinv_get_cart_tax( $cart_items, $invoice ),               // Taxed amount
1706
-        'price'             => wpinv_get_cart_total( $cart_items, $discounts ),    // Amount after taxes
1702
+        'fees'              => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart
1703
+        'subtotal'          => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts
1704
+        'discount'          => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount
1705
+        'tax'               => wpinv_get_cart_tax($cart_items, $invoice), // Taxed amount
1706
+        'price'             => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes
1707 1707
         'invoice_key'       => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(),
1708 1708
         'user_email'        => $invoice->get_email(),
1709
-        'date'              => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
1710
-        'user_info'         => stripslashes_deep( $user_info ),
1709
+        'date'              => date('Y-m-d H:i:s', current_time('timestamp')),
1710
+        'user_info'         => stripslashes_deep($user_info),
1711 1711
         'post_data'         => $_POST,
1712 1712
         'cart_details'      => $cart_items,
1713 1713
         'gateway'           => $valid_data['gateway'],
1714 1714
         'card_info'         => $valid_data['cc_info']
1715 1715
     );
1716 1716
     
1717
-    $vat_info   = $wpinv_euvat->current_vat_data();
1718
-    if ( is_array( $vat_info ) ) {
1717
+    $vat_info = $wpinv_euvat->current_vat_data();
1718
+    if (is_array($vat_info)) {
1719 1719
         $invoice_data['user_info']['vat_number']        = $vat_info['number'];
1720 1720
         $invoice_data['user_info']['vat_rate']          = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']);
1721
-        $invoice_data['user_info']['adddress_confirmed']    = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1721
+        $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1722 1722
 
1723 1723
         // Add the VAT rate to each item in the cart
1724
-        foreach( $invoice_data['cart_details'] as $key => $item_data) {
1724
+        foreach ($invoice_data['cart_details'] as $key => $item_data) {
1725 1725
             $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']);
1726
-            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 );
1726
+            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4);
1727 1727
         }
1728 1728
     }
1729 1729
     
1730 1730
     // Save vat fields.
1731
-    $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' );
1732
-    foreach ( $address_fields as $field ) {
1733
-        if ( isset( $invoice_data['user_info'][$field] ) ) {
1734
-            $invoice->set( $field, $invoice_data['user_info'][$field] );
1731
+    $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed');
1732
+    foreach ($address_fields as $field) {
1733
+        if (isset($invoice_data['user_info'][$field])) {
1734
+            $invoice->set($field, $invoice_data['user_info'][$field]);
1735 1735
         }
1736 1736
 
1737 1737
         $invoice->save();
@@ -1741,55 +1741,55 @@  discard block
 block discarded – undo
1741 1741
     $valid_data['user'] = $user;
1742 1742
     
1743 1743
     // Allow themes and plugins to hook before the gateway
1744
-    do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data );
1744
+    do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data);
1745 1745
     
1746 1746
     // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice
1747
-    if ( !$invoice_data['price'] ) {
1747
+    if (!$invoice_data['price']) {
1748 1748
         // Revert to manual
1749 1749
         $invoice_data['gateway'] = 'manual';
1750 1750
         $_POST['wpi-gateway'] = 'manual';
1751 1751
     }
1752 1752
     
1753 1753
     // Allow the invoice data to be modified before it is sent to the gateway
1754
-    $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data );
1754
+    $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data);
1755 1755
     
1756
-    if ( $invoice_data['price'] && $invoice_data['gateway'] == 'manual' ) {
1756
+    if ($invoice_data['price'] && $invoice_data['gateway'] == 'manual') {
1757 1757
         $mode = 'test';
1758 1758
     } else {
1759
-        $mode = wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live';
1759
+        $mode = wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live';
1760 1760
     }
1761 1761
     
1762 1762
     // Setup the data we're storing in the purchase session
1763 1763
     $session_data = $invoice_data;
1764 1764
     // Make sure credit card numbers are never stored in sessions
1765
-    if ( !empty( $session_data['card_info']['card_number'] ) ) {
1766
-        unset( $session_data['card_info']['card_number'] );
1765
+    if (!empty($session_data['card_info']['card_number'])) {
1766
+        unset($session_data['card_info']['card_number']);
1767 1767
     }
1768 1768
     
1769 1769
     // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data.
1770
-    wpinv_set_checkout_session( $invoice_data );
1770
+    wpinv_set_checkout_session($invoice_data);
1771 1771
     
1772 1772
     // Set gateway
1773
-    $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] );
1774
-    $invoice->update_meta( '_wpinv_mode', $mode );
1775
-    $invoice->update_meta( '_wpinv_checkout', date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) );
1773
+    $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']);
1774
+    $invoice->update_meta('_wpinv_mode', $mode);
1775
+    $invoice->update_meta('_wpinv_checkout', date_i18n('Y-m-d H:i:s', current_time('timestamp')));
1776 1776
     
1777
-    do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data );
1777
+    do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data);
1778 1778
 
1779 1779
     // Send info to the gateway for payment processing
1780
-    wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data );
1780
+    wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data);
1781 1781
     die();
1782 1782
 }
1783
-add_action( 'wpinv_payment', 'wpinv_process_checkout' );
1783
+add_action('wpinv_payment', 'wpinv_process_checkout');
1784 1784
 
1785
-function wpinv_get_invoices( $args ) {
1786
-    $args = wp_parse_args( $args, array(
1787
-        'status'   => array_keys( wpinv_get_invoice_statuses() ),
1785
+function wpinv_get_invoices($args) {
1786
+    $args = wp_parse_args($args, array(
1787
+        'status'   => array_keys(wpinv_get_invoice_statuses()),
1788 1788
         'type'     => 'wpi_invoice',
1789 1789
         'parent'   => null,
1790 1790
         'user'     => null,
1791 1791
         'email'    => '',
1792
-        'limit'    => get_option( 'posts_per_page' ),
1792
+        'limit'    => get_option('posts_per_page'),
1793 1793
         'offset'   => null,
1794 1794
         'page'     => 1,
1795 1795
         'exclude'  => array(),
@@ -1797,7 +1797,7 @@  discard block
 block discarded – undo
1797 1797
         'order'    => 'DESC',
1798 1798
         'return'   => 'objects',
1799 1799
         'paginate' => false,
1800
-    ) );
1800
+    ));
1801 1801
     
1802 1802
     // Handle some BW compatibility arg names where wp_query args differ in naming.
1803 1803
     $map_legacy = array(
@@ -1810,18 +1810,18 @@  discard block
 block discarded – undo
1810 1810
         'paged'          => 'page',
1811 1811
     );
1812 1812
 
1813
-    foreach ( $map_legacy as $from => $to ) {
1814
-        if ( isset( $args[ $from ] ) ) {
1815
-            $args[ $to ] = $args[ $from ];
1813
+    foreach ($map_legacy as $from => $to) {
1814
+        if (isset($args[$from])) {
1815
+            $args[$to] = $args[$from];
1816 1816
         }
1817 1817
     }
1818 1818
 
1819
-    if ( get_query_var( 'paged' ) )
1819
+    if (get_query_var('paged'))
1820 1820
         $args['page'] = get_query_var('paged');
1821
-    else if ( get_query_var( 'page' ) )
1822
-        $args['page'] = get_query_var( 'page' );
1823
-    else if ( !empty( $args[ 'page' ] ) )
1824
-        $args['page'] = $args[ 'page' ];
1821
+    else if (get_query_var('page'))
1822
+        $args['page'] = get_query_var('page');
1823
+    else if (!empty($args['page']))
1824
+        $args['page'] = $args['page'];
1825 1825
     else
1826 1826
         $args['page'] = 1;
1827 1827
 
@@ -1834,48 +1834,48 @@  discard block
 block discarded – undo
1834 1834
         'post_status'    => $args['status'],
1835 1835
         'posts_per_page' => $args['limit'],
1836 1836
         'meta_query'     => array(),
1837
-        'date_query'     => !empty( $args['date_query'] ) ? $args['date_query'] : array(),
1837
+        'date_query'     => !empty($args['date_query']) ? $args['date_query'] : array(),
1838 1838
         'fields'         => 'ids',
1839 1839
         'orderby'        => $args['orderby'],
1840 1840
         'order'          => $args['order'],
1841 1841
     );
1842 1842
     
1843
-    if ( !empty( $args['user'] ) ) {
1844
-        $wp_query_args['author'] = absint( $args['user'] );
1843
+    if (!empty($args['user'])) {
1844
+        $wp_query_args['author'] = absint($args['user']);
1845 1845
     }
1846 1846
 
1847
-    if ( ! is_null( $args['parent'] ) ) {
1848
-        $wp_query_args['post_parent'] = absint( $args['parent'] );
1847
+    if (!is_null($args['parent'])) {
1848
+        $wp_query_args['post_parent'] = absint($args['parent']);
1849 1849
     }
1850 1850
 
1851
-    if ( ! is_null( $args['offset'] ) ) {
1852
-        $wp_query_args['offset'] = absint( $args['offset'] );
1851
+    if (!is_null($args['offset'])) {
1852
+        $wp_query_args['offset'] = absint($args['offset']);
1853 1853
     } else {
1854
-        $wp_query_args['paged'] = absint( $args['page'] );
1854
+        $wp_query_args['paged'] = absint($args['page']);
1855 1855
     }
1856 1856
 
1857
-    if ( ! empty( $args['exclude'] ) ) {
1858
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
1857
+    if (!empty($args['exclude'])) {
1858
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
1859 1859
     }
1860 1860
 
1861
-    if ( ! $args['paginate' ] ) {
1861
+    if (!$args['paginate']) {
1862 1862
         $wp_query_args['no_found_rows'] = true;
1863 1863
     }
1864 1864
 
1865 1865
     $wp_query_args = apply_filters('wpinv_get_invoices_args', $wp_query_args, $args);
1866 1866
 
1867 1867
     // Get results.
1868
-    $invoices = new WP_Query( $wp_query_args );
1868
+    $invoices = new WP_Query($wp_query_args);
1869 1869
 
1870
-    if ( 'objects' === $args['return'] ) {
1871
-        $return = array_map( 'wpinv_get_invoice', $invoices->posts );
1872
-    } elseif ( 'self' === $args['return'] ) {
1870
+    if ('objects' === $args['return']) {
1871
+        $return = array_map('wpinv_get_invoice', $invoices->posts);
1872
+    } elseif ('self' === $args['return']) {
1873 1873
         return $invoices;
1874 1874
     } else {
1875 1875
         $return = $invoices->posts;
1876 1876
     }
1877 1877
 
1878
-    if ( $args['paginate' ] ) {
1878
+    if ($args['paginate']) {
1879 1879
         return (object) array(
1880 1880
             'invoices'      => $return,
1881 1881
             'total'         => $invoices->found_posts,
@@ -1888,22 +1888,22 @@  discard block
 block discarded – undo
1888 1888
 
1889 1889
 function wpinv_get_user_invoices_columns() {
1890 1890
     $columns = array(
1891
-            'invoice-number'  => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ),
1892
-            'created-date'    => array( 'title' => __( 'Created Date', 'invoicing' ), 'class' => 'text-left' ),
1893
-            'payment-date'    => array( 'title' => __( 'Payment Date', 'invoicing' ), 'class' => 'text-left' ),
1894
-            'invoice-status'  => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ),
1895
-            'invoice-total'   => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ),
1896
-            'invoice-actions' => array( 'title' => '&nbsp;', 'class' => 'text-center' ),
1891
+            'invoice-number'  => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'),
1892
+            'created-date'    => array('title' => __('Created Date', 'invoicing'), 'class' => 'text-left'),
1893
+            'payment-date'    => array('title' => __('Payment Date', 'invoicing'), 'class' => 'text-left'),
1894
+            'invoice-status'  => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'),
1895
+            'invoice-total'   => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'),
1896
+            'invoice-actions' => array('title' => '&nbsp;', 'class' => 'text-center'),
1897 1897
         );
1898 1898
 
1899
-    return apply_filters( 'wpinv_user_invoices_columns', $columns );
1899
+    return apply_filters('wpinv_user_invoices_columns', $columns);
1900 1900
 }
1901 1901
 
1902
-function wpinv_payment_receipt( $atts, $content = null ) {
1902
+function wpinv_payment_receipt($atts, $content = null) {
1903 1903
     global $wpinv_receipt_args;
1904 1904
 
1905
-    $wpinv_receipt_args = shortcode_atts( array(
1906
-        'error'           => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ),
1905
+    $wpinv_receipt_args = shortcode_atts(array(
1906
+        'error'           => __('Sorry, trouble retrieving payment receipt.', 'invoicing'),
1907 1907
         'price'           => true,
1908 1908
         'discount'        => true,
1909 1909
         'items'           => true,
@@ -1912,197 +1912,197 @@  discard block
 block discarded – undo
1912 1912
         'invoice_key'     => false,
1913 1913
         'payment_method'  => true,
1914 1914
         'invoice_id'      => true
1915
-    ), $atts, 'wpinv_receipt' );
1915
+    ), $atts, 'wpinv_receipt');
1916 1916
 
1917 1917
     $session = wpinv_get_checkout_session();
1918
-    if ( isset( $_GET['invoice_key'] ) ) {
1919
-        $invoice_key = urldecode( $_GET['invoice_key'] );
1920
-    } else if ( $session && isset( $session['invoice_key'] ) ) {
1918
+    if (isset($_GET['invoice_key'])) {
1919
+        $invoice_key = urldecode($_GET['invoice_key']);
1920
+    } else if ($session && isset($session['invoice_key'])) {
1921 1921
         $invoice_key = $session['invoice_key'];
1922
-    } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) {
1922
+    } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) {
1923 1923
         $invoice_key = $wpinv_receipt_args['invoice_key'];
1924
-    } else if ( isset( $_GET['invoice-id'] ) ) {
1925
-        $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] );
1924
+    } else if (isset($_GET['invoice-id'])) {
1925
+        $invoice_key = wpinv_get_payment_key((int) $_GET['invoice-id']);
1926 1926
     }
1927 1927
 
1928 1928
     // No key found
1929
-    if ( ! isset( $invoice_key ) ) {
1929
+    if (!isset($invoice_key)) {
1930 1930
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1931 1931
     }
1932 1932
 
1933
-    $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1934
-    $user_can_view = wpinv_can_view_receipt( $invoice_key );
1935
-    if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1936
-        $invoice_id     = (int)$_GET['invoice-id'];
1937
-        $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1933
+    $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1934
+    $user_can_view = wpinv_can_view_receipt($invoice_key);
1935
+    if ($user_can_view && isset($_GET['invoice-id'])) {
1936
+        $invoice_id     = (int) $_GET['invoice-id'];
1937
+        $user_can_view  = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? true : false;
1938 1938
     }
1939 1939
 
1940 1940
     // Key was provided, but user is logged out. Offer them the ability to login and view the receipt
1941
-    if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) {
1941
+    if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) {
1942 1942
         // login redirect
1943
-        return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>';
1943
+        return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>';
1944 1944
     }
1945 1945
 
1946
-    if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) {
1946
+    if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) {
1947 1947
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1948 1948
     }
1949 1949
 
1950 1950
     ob_start();
1951 1951
 
1952
-    wpinv_get_template_part( 'wpinv-invoice-receipt' );
1952
+    wpinv_get_template_part('wpinv-invoice-receipt');
1953 1953
 
1954 1954
     $display = ob_get_clean();
1955 1955
 
1956 1956
     return $display;
1957 1957
 }
1958 1958
 
1959
-function wpinv_get_invoice_id_by_key( $key ) {
1959
+function wpinv_get_invoice_id_by_key($key) {
1960 1960
 	global $wpdb;
1961 1961
 
1962
-	$invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) );
1962
+	$invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key));
1963 1963
 
1964
-	if ( $invoice_id != NULL )
1964
+	if ($invoice_id != NULL)
1965 1965
 		return $invoice_id;
1966 1966
 
1967 1967
 	return 0;
1968 1968
 }
1969 1969
 
1970
-function wpinv_can_view_receipt( $invoice_key = '' ) {
1970
+function wpinv_can_view_receipt($invoice_key = '') {
1971 1971
 	$return = false;
1972 1972
 
1973
-	if ( empty( $invoice_key ) ) {
1973
+	if (empty($invoice_key)) {
1974 1974
 		return $return;
1975 1975
 	}
1976 1976
 
1977 1977
 	global $wpinv_receipt_args;
1978 1978
 
1979
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1980
-	if ( isset( $_GET['invoice-id'] ) ) {
1981
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1979
+	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key);
1980
+	if (isset($_GET['invoice-id'])) {
1981
+		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? (int) $_GET['invoice-id'] : 0;
1982 1982
 	}
1983 1983
 
1984
-	if ( empty( $wpinv_receipt_args['id'] ) ) {
1984
+	if (empty($wpinv_receipt_args['id'])) {
1985 1985
 		return $return;
1986 1986
 	}
1987 1987
 
1988
-	$invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] );
1989
-	if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) {
1988
+	$invoice = wpinv_get_invoice($wpinv_receipt_args['id']);
1989
+	if (!(!empty($invoice->ID) && $invoice->get_key() === $invoice_key)) {
1990 1990
 		return $return;
1991 1991
 	}
1992 1992
 
1993
-	if ( is_user_logged_in() ) {
1994
-		if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) {
1993
+	if (is_user_logged_in()) {
1994
+		if ((int) $invoice->get_user_id() === (int) get_current_user_id()) {
1995 1995
 			$return = true;
1996 1996
 		}
1997 1997
 	}
1998 1998
 
1999 1999
 	$session = wpinv_get_checkout_session();
2000
-	if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) {
2001
-		$check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key'];
2000
+	if (isset($_GET['invoice_key']) || ($session && isset($session['invoice_key']))) {
2001
+		$check_key = isset($_GET['invoice_key']) ? $_GET['invoice_key'] : $session['invoice_key'];
2002 2002
 
2003
-		if ( wpinv_require_login_to_checkout() ) {
2003
+		if (wpinv_require_login_to_checkout()) {
2004 2004
 			$return = $return && $check_key === $invoice_key;
2005 2005
 		} else {
2006 2006
 			$return = $check_key === $invoice_key;
2007 2007
 		}
2008 2008
 	}
2009 2009
 
2010
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
2010
+	return (bool) apply_filters('wpinv_can_view_receipt', $return, $invoice_key);
2011 2011
 }
2012 2012
 
2013 2013
 function wpinv_pay_for_invoice() {
2014 2014
     global $wpinv_euvat;
2015 2015
     
2016
-    if ( isset( $_GET['invoice_key'] ) ) {
2016
+    if (isset($_GET['invoice_key'])) {
2017 2017
         $checkout_uri   = wpinv_get_checkout_uri();
2018
-        $invoice_key    = sanitize_text_field( $_GET['invoice_key'] );
2018
+        $invoice_key    = sanitize_text_field($_GET['invoice_key']);
2019 2019
         
2020
-        if ( empty( $invoice_key ) ) {
2021
-            wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) );
2022
-            wp_redirect( $checkout_uri );
2020
+        if (empty($invoice_key)) {
2021
+            wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing'));
2022
+            wp_redirect($checkout_uri);
2023 2023
             exit();
2024 2024
         }
2025 2025
         
2026
-        do_action( 'wpinv_check_pay_for_invoice', $invoice_key );
2026
+        do_action('wpinv_check_pay_for_invoice', $invoice_key);
2027 2027
 
2028
-        $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
2029
-        $user_can_view = wpinv_can_view_receipt( $invoice_key );
2030
-        if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
2031
-            $invoice_id     = (int)$_GET['invoice-id'];
2032
-            $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
2028
+        $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
2029
+        $user_can_view = wpinv_can_view_receipt($invoice_key);
2030
+        if ($user_can_view && isset($_GET['invoice-id'])) {
2031
+            $invoice_id     = (int) $_GET['invoice-id'];
2032
+            $user_can_view  = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? true : false;
2033 2033
         }
2034 2034
         
2035
-        if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) {
2036
-            if ( $invoice->needs_payment() ) {
2035
+        if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) {
2036
+            if ($invoice->needs_payment()) {
2037 2037
                 $data                   = array();
2038 2038
                 $data['invoice_id']     = $invoice_id;
2039
-                $data['cart_discounts'] = $invoice->get_discounts( true );
2039
+                $data['cart_discounts'] = $invoice->get_discounts(true);
2040 2040
                 
2041
-                wpinv_set_checkout_session( $data );
2041
+                wpinv_set_checkout_session($data);
2042 2042
                 
2043
-                if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
2043
+                if (wpinv_get_option('vat_ip_country_default')) {
2044 2044
                     $_POST['country']   = $wpinv_euvat->get_country_by_ip();
2045 2045
                     $_POST['state']     = $_POST['country'] == $invoice->country ? $invoice->state : '';
2046 2046
                     
2047
-                    wpinv_recalculate_tax( true );
2047
+                    wpinv_recalculate_tax(true);
2048 2048
                 }
2049 2049
                 
2050 2050
             } else {
2051 2051
                 $checkout_uri = $invoice->get_view_url();
2052 2052
             }
2053 2053
         } else {
2054
-            wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) );
2054
+            wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing'));
2055 2055
             
2056
-            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
2056
+            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
2057 2057
         }
2058 2058
         
2059
-        if(wp_redirect( $checkout_uri )){
2059
+        if (wp_redirect($checkout_uri)) {
2060 2060
             exit;
2061 2061
         };
2062 2062
         wpinv_die();
2063 2063
     }
2064 2064
 }
2065
-add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' );
2065
+add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice');
2066 2066
 
2067
-function wpinv_handle_pay_via_invoice_link( $invoice_key ) {
2068
-    if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) {
2069
-        if ( $invoice = wpinv_get_invoice( $invoice_id ) ) {
2067
+function wpinv_handle_pay_via_invoice_link($invoice_key) {
2068
+    if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) {
2069
+        if ($invoice = wpinv_get_invoice($invoice_id)) {
2070 2070
             $user_id = $invoice->get_user_id();
2071
-            $secret = sanitize_text_field( $_GET['_wpipay'] );
2071
+            $secret = sanitize_text_field($_GET['_wpipay']);
2072 2072
             
2073
-            if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link
2074
-                $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
2073
+            if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link
2074
+                $redirect_to = remove_query_arg('_wpipay', get_permalink());
2075 2075
                 
2076
-                wpinv_guest_redirect( $redirect_to, $user_id );
2076
+                wpinv_guest_redirect($redirect_to, $user_id);
2077 2077
                 exit();
2078 2078
             }
2079 2079
         }
2080 2080
     }
2081 2081
 }
2082
-add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' );
2082
+add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link');
2083 2083
 
2084
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
2085
-    $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id;
2084
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
2085
+    $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id;
2086 2086
     
2087
-    if ( empty( $invoice_id ) && $invoice_id > 0 ) {
2087
+    if (empty($invoice_id) && $invoice_id > 0) {
2088 2088
         return false;
2089 2089
     }
2090 2090
     
2091
-    if ( empty( $transaction_id ) ) {
2091
+    if (empty($transaction_id)) {
2092 2092
         $transaction_id = $invoice_id;
2093 2093
     }
2094 2094
 
2095
-    $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id );
2095
+    $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id);
2096 2096
     
2097
-    return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id );
2097
+    return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id);
2098 2098
 }
2099 2099
 
2100
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
2101
-    if ( empty( $status_display ) ) {
2102
-        $status_display = wpinv_status_nicename( $status );
2100
+function wpinv_invoice_status_label($status, $status_display = '') {
2101
+    if (empty($status_display)) {
2102
+        $status_display = wpinv_status_nicename($status);
2103 2103
     }
2104 2104
     
2105
-    switch ( $status ) {
2105
+    switch ($status) {
2106 2106
         case 'publish' :
2107 2107
         case 'wpi-renewal' :
2108 2108
             $class = 'label-success';
@@ -2127,201 +2127,201 @@  discard block
 block discarded – undo
2127 2127
     
2128 2128
     $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>';
2129 2129
     
2130
-    return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display );
2130
+    return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display);
2131 2131
 }
2132 2132
 
2133
-function wpinv_format_invoice_number( $number, $type = '' ) {
2134
-    $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type );
2135
-    if ( null !== $check ) {
2133
+function wpinv_format_invoice_number($number, $type = '') {
2134
+    $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type);
2135
+    if (null !== $check) {
2136 2136
         return $check;
2137 2137
     }
2138 2138
 
2139
-    if ( !empty( $number ) && !is_numeric( $number ) ) {
2139
+    if (!empty($number) && !is_numeric($number)) {
2140 2140
         return $number;
2141 2141
     }
2142 2142
 
2143
-    $padd  = wpinv_get_option( 'invoice_number_padd' );
2144
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2145
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2143
+    $padd = wpinv_get_option('invoice_number_padd');
2144
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2145
+    $postfix = wpinv_get_option('invoice_number_postfix');
2146 2146
     
2147
-    $padd = absint( $padd );
2148
-    $formatted_number = absint( $number );
2147
+    $padd = absint($padd);
2148
+    $formatted_number = absint($number);
2149 2149
     
2150
-    if ( $padd > 0 ) {
2151
-        $formatted_number = zeroise( $formatted_number, $padd );
2150
+    if ($padd > 0) {
2151
+        $formatted_number = zeroise($formatted_number, $padd);
2152 2152
     }    
2153 2153
 
2154 2154
     $formatted_number = $prefix . $formatted_number . $postfix;
2155 2155
 
2156
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
2156
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
2157 2157
 }
2158 2158
 
2159
-function wpinv_get_next_invoice_number( $type = '' ) {
2160
-    $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type );
2161
-    if ( null !== $check ) {
2159
+function wpinv_get_next_invoice_number($type = '') {
2160
+    $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type);
2161
+    if (null !== $check) {
2162 2162
         return $check;
2163 2163
     }
2164 2164
     
2165
-    if ( !wpinv_sequential_number_active() ) {
2165
+    if (!wpinv_sequential_number_active()) {
2166 2166
         return false;
2167 2167
     }
2168 2168
 
2169
-    $number = $last_number = get_option( 'wpinv_last_invoice_number', 0 );
2170
-    $start  = wpinv_get_option( 'invoice_sequence_start', 1 );
2171
-    if ( !absint( $start ) > 0 ) {
2169
+    $number = $last_number = get_option('wpinv_last_invoice_number', 0);
2170
+    $start  = wpinv_get_option('invoice_sequence_start', 1);
2171
+    if (!absint($start) > 0) {
2172 2172
         $start = 1;
2173 2173
     }
2174 2174
     $increment_number = true;
2175 2175
     $save_number = false;
2176 2176
 
2177
-    if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) {
2178
-        $number = wpinv_clean_invoice_number( $number );
2177
+    if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) {
2178
+        $number = wpinv_clean_invoice_number($number);
2179 2179
     }
2180 2180
 
2181
-    if ( empty( $number ) ) {
2182
-        if ( !( $last_number === 0 || $last_number === '0' ) ) {
2183
-            $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys( wpinv_get_invoice_statuses( true, true ) ) ) );
2181
+    if (empty($number)) {
2182
+        if (!($last_number === 0 || $last_number === '0')) {
2183
+            $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys(wpinv_get_invoice_statuses(true, true))));
2184 2184
 
2185
-            if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) {
2186
-                if ( is_numeric( $invoice_number ) ) {
2185
+            if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) {
2186
+                if (is_numeric($invoice_number)) {
2187 2187
                     $number = $invoice_number;
2188 2188
                 } else {
2189
-                    $number = wpinv_clean_invoice_number( $invoice_number );
2189
+                    $number = wpinv_clean_invoice_number($invoice_number);
2190 2190
                 }
2191 2191
             }
2192 2192
 
2193
-            if ( empty( $number ) ) {
2193
+            if (empty($number)) {
2194 2194
                 $increment_number = false;
2195 2195
                 $number = $start;
2196
-                $save_number = ( $number - 1 );
2196
+                $save_number = ($number - 1);
2197 2197
             } else {
2198 2198
                 $save_number = $number;
2199 2199
             }
2200 2200
         }
2201 2201
     }
2202 2202
 
2203
-    if ( $start > $number ) {
2203
+    if ($start > $number) {
2204 2204
         $increment_number = false;
2205 2205
         $number = $start;
2206
-        $save_number = ( $number - 1 );
2206
+        $save_number = ($number - 1);
2207 2207
     }
2208 2208
 
2209
-    if ( $save_number !== false ) {
2210
-        update_option( 'wpinv_last_invoice_number', $save_number );
2209
+    if ($save_number !== false) {
2210
+        update_option('wpinv_last_invoice_number', $save_number);
2211 2211
     }
2212 2212
     
2213
-    $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number );
2213
+    $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number);
2214 2214
 
2215
-    if ( $increment_number ) {
2215
+    if ($increment_number) {
2216 2216
         $number++;
2217 2217
     }
2218 2218
 
2219
-    return apply_filters( 'wpinv_get_next_invoice_number', $number );
2219
+    return apply_filters('wpinv_get_next_invoice_number', $number);
2220 2220
 }
2221 2221
 
2222
-function wpinv_clean_invoice_number( $number, $type = '' ) {
2223
-    $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type );
2224
-    if ( null !== $check ) {
2222
+function wpinv_clean_invoice_number($number, $type = '') {
2223
+    $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type);
2224
+    if (null !== $check) {
2225 2225
         return $check;
2226 2226
     }
2227 2227
     
2228
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2229
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2228
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2229
+    $postfix = wpinv_get_option('invoice_number_postfix');
2230 2230
 
2231
-    $number = preg_replace( '/' . $prefix . '/', '', $number, 1 );
2231
+    $number = preg_replace('/' . $prefix . '/', '', $number, 1);
2232 2232
 
2233
-    $length      = strlen( $number );
2234
-    $postfix_pos = strrpos( $number, $postfix );
2233
+    $length      = strlen($number);
2234
+    $postfix_pos = strrpos($number, $postfix);
2235 2235
     
2236
-    if ( false !== $postfix_pos ) {
2237
-        $number      = substr_replace( $number, '', $postfix_pos, $length );
2236
+    if (false !== $postfix_pos) {
2237
+        $number = substr_replace($number, '', $postfix_pos, $length);
2238 2238
     }
2239 2239
 
2240
-    $number = intval( $number );
2240
+    $number = intval($number);
2241 2241
 
2242
-    return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix );
2242
+    return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix);
2243 2243
 }
2244 2244
 
2245
-function wpinv_save_number_post_saved( $post_ID, $post, $update ) {
2245
+function wpinv_save_number_post_saved($post_ID, $post, $update) {
2246 2246
     global $wpdb;
2247 2247
 
2248
-    if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) {
2249
-        wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft', $post->post_type );
2248
+    if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) {
2249
+        wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft', $post->post_type);
2250 2250
     }
2251 2251
 
2252
-    if ( !$update ) {
2253
-        $wpdb->update( $wpdb->posts, array( 'post_name' => wpinv_generate_post_name( $post_ID ) ), array( 'ID' => $post_ID ) );
2254
-        clean_post_cache( $post_ID );
2252
+    if (!$update) {
2253
+        $wpdb->update($wpdb->posts, array('post_name' => wpinv_generate_post_name($post_ID)), array('ID' => $post_ID));
2254
+        clean_post_cache($post_ID);
2255 2255
     }
2256 2256
 }
2257
-add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 );
2257
+add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3);
2258 2258
 
2259
-function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) {
2260
-    if ( !empty( $post_after->post_type ) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status ) {
2261
-        wpinv_update_invoice_number( $post_ID, true, $post_after->post_type );
2259
+function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) {
2260
+    if (!empty($post_after->post_type) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status) {
2261
+        wpinv_update_invoice_number($post_ID, true, $post_after->post_type);
2262 2262
     }
2263 2263
 }
2264
-add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 );
2264
+add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3);
2265 2265
 
2266
-function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) {
2266
+function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') {
2267 2267
     global $wpdb;
2268 2268
     
2269
-    $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type );
2270
-    if ( null !== $check ) {
2269
+    $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type);
2270
+    if (null !== $check) {
2271 2271
         return $check;
2272 2272
     }
2273 2273
 
2274
-    if ( wpinv_sequential_number_active() ) {
2274
+    if (wpinv_sequential_number_active()) {
2275 2275
         $number = wpinv_get_next_invoice_number();
2276 2276
 
2277
-        if ( $save_sequential ) {
2278
-            update_option( 'wpinv_last_invoice_number', $number );
2277
+        if ($save_sequential) {
2278
+            update_option('wpinv_last_invoice_number', $number);
2279 2279
         }
2280 2280
     } else {
2281 2281
         $number = $post_ID;
2282 2282
     }
2283 2283
 
2284
-    $number = wpinv_format_invoice_number( $number );
2284
+    $number = wpinv_format_invoice_number($number);
2285 2285
 
2286
-    update_post_meta( $post_ID, '_wpinv_number', $number );
2286
+    update_post_meta($post_ID, '_wpinv_number', $number);
2287 2287
 
2288
-    $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) );
2288
+    $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID));
2289 2289
 
2290
-    clean_post_cache( $post_ID );
2290
+    clean_post_cache($post_ID);
2291 2291
 
2292 2292
     return $number;
2293 2293
 }
2294 2294
 
2295
-function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) {
2296
-    return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type );
2295
+function wpinv_post_name_prefix($post_type = 'wpi_invoice') {
2296
+    return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type);
2297 2297
 }
2298 2298
 
2299
-function wpinv_generate_post_name( $post_ID ) {
2300
-    $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) );
2301
-    $post_name = sanitize_title( $prefix . $post_ID );
2299
+function wpinv_generate_post_name($post_ID) {
2300
+    $prefix = wpinv_post_name_prefix(get_post_type($post_ID));
2301
+    $post_name = sanitize_title($prefix . $post_ID);
2302 2302
 
2303
-    return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix );
2303
+    return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix);
2304 2304
 }
2305 2305
 
2306
-function wpinv_is_invoice_viewed( $invoice_id ) {
2307
-    if ( empty( $invoice_id ) ) {
2306
+function wpinv_is_invoice_viewed($invoice_id) {
2307
+    if (empty($invoice_id)) {
2308 2308
         return false;
2309 2309
     }
2310 2310
 
2311
-    $viewed_meta = get_post_meta( $invoice_id, '_wpinv_is_viewed', true );
2311
+    $viewed_meta = get_post_meta($invoice_id, '_wpinv_is_viewed', true);
2312 2312
 
2313
-    return apply_filters( 'wpinv_is_invoice_viewed', 1 === (int)$viewed_meta, $invoice_id );
2313
+    return apply_filters('wpinv_is_invoice_viewed', 1 === (int) $viewed_meta, $invoice_id);
2314 2314
 }
2315 2315
 
2316 2316
 function wpinv_mark_invoice_viewed() {
2317 2317
 
2318
-    if ( isset( $_GET['invoice_key'] ) || is_singular( 'wpi_invoice' ) || is_singular( 'wpi_quote' ) ) {
2319
-        $invoice_key = isset( $_GET['invoice_key'] ) ? urldecode($_GET['invoice_key']) : '';
2318
+    if (isset($_GET['invoice_key']) || is_singular('wpi_invoice') || is_singular('wpi_quote')) {
2319
+        $invoice_key = isset($_GET['invoice_key']) ? urldecode($_GET['invoice_key']) : '';
2320 2320
 	    global $post;
2321 2321
 
2322
-        if(!empty($invoice_key)){
2322
+        if (!empty($invoice_key)) {
2323 2323
 	        $invoice_id = wpinv_get_invoice_id_by_key($invoice_key);
2324
-        } else if(!empty( $post ) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) {
2324
+        } else if (!empty($post) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) {
2325 2325
 			$invoice_id = $post->ID;
2326 2326
         } else {
2327 2327
         	return;
@@ -2329,60 +2329,60 @@  discard block
 block discarded – undo
2329 2329
 
2330 2330
         $invoice = new WPInv_Invoice($invoice_id);
2331 2331
 
2332
-        if(!$invoice_id){
2332
+        if (!$invoice_id) {
2333 2333
             return;
2334 2334
         }
2335 2335
 
2336
-	    if ( is_user_logged_in() ) {
2337
-		    if ( (int)$invoice->get_user_id() === get_current_user_id() ) {
2338
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2339
-		    } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2340
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2336
+	    if (is_user_logged_in()) {
2337
+		    if ((int) $invoice->get_user_id() === get_current_user_id()) {
2338
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2339
+		    } else if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2340
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2341 2341
 		    }
2342 2342
 	    } else {
2343
-		    if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2344
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2343
+		    if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2344
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2345 2345
 		    }
2346 2346
 	    }
2347 2347
     }
2348 2348
 
2349 2349
 }
2350
-add_action( 'template_redirect', 'wpinv_mark_invoice_viewed' );
2350
+add_action('template_redirect', 'wpinv_mark_invoice_viewed');
2351 2351
 
2352
-function wpinv_get_subscription( $invoice, $by_parent = false ) {
2353
-    if ( empty( $invoice ) ) {
2352
+function wpinv_get_subscription($invoice, $by_parent = false) {
2353
+    if (empty($invoice)) {
2354 2354
         return false;
2355 2355
     }
2356 2356
     
2357
-    if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) {
2358
-        $invoice = wpinv_get_invoice( $invoice );
2357
+    if (!is_object($invoice) && is_scalar($invoice)) {
2358
+        $invoice = wpinv_get_invoice($invoice);
2359 2359
     }
2360 2360
     
2361
-    if ( !( is_object( $invoice ) && ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) {
2361
+    if (!(is_object($invoice) && !empty($invoice->ID) && $invoice->is_recurring())) {
2362 2362
         return false;
2363 2363
     }
2364 2364
     
2365
-    $invoice_id = ! $by_parent && ! empty( $invoice->parent_invoice ) ? $invoice->parent_invoice : $invoice->ID;
2365
+    $invoice_id = !$by_parent && !empty($invoice->parent_invoice) ? $invoice->parent_invoice : $invoice->ID;
2366 2366
     
2367 2367
     $subs_db    = new WPInv_Subscriptions_DB;
2368
-    $subs       = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice_id, 'number' => 1 ) );
2368
+    $subs       = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice_id, 'number' => 1));
2369 2369
     
2370
-    if ( ! empty( $subs ) ) {
2371
-        return reset( $subs );
2370
+    if (!empty($subs)) {
2371
+        return reset($subs);
2372 2372
     }
2373 2373
     
2374 2374
     return false;
2375 2375
 }
2376 2376
 
2377
-function wpinv_filter_posts_clauses( $clauses, $wp_query ) {
2377
+function wpinv_filter_posts_clauses($clauses, $wp_query) {
2378 2378
     global $wpdb;
2379 2379
 
2380
-    if ( ! empty( $wp_query->query_vars['orderby'] ) && $wp_query->query_vars['orderby'] == 'invoice_date' ) {
2381
-        if ( !empty( $clauses['join'] ) ) {
2380
+    if (!empty($wp_query->query_vars['orderby']) && $wp_query->query_vars['orderby'] == 'invoice_date') {
2381
+        if (!empty($clauses['join'])) {
2382 2382
             $clauses['join'] .= " ";
2383 2383
         }
2384 2384
 
2385
-        if ( !empty( $clauses['fields'] ) ) {
2385
+        if (!empty($clauses['fields'])) {
2386 2386
             $clauses['fields'] .= ", ";
2387 2387
         }
2388 2388
 
@@ -2393,4 +2393,4 @@  discard block
 block discarded – undo
2393 2393
 
2394 2394
     return $clauses;
2395 2395
 }
2396
-add_filter( 'posts_clauses', 'wpinv_filter_posts_clauses', 10, 2 );
2397 2396
\ No newline at end of file
2397
+add_filter('posts_clauses', 'wpinv_filter_posts_clauses', 10, 2);
2398 2398
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-general-functions.php 1 patch
Spacing   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -7,202 +7,202 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_is_checkout() {
15 15
     global $wp_query;
16 16
 
17
-    $is_object_set    = isset( $wp_query->queried_object );
18
-    $is_object_id_set = isset( $wp_query->queried_object_id );
19
-    $is_checkout      = is_page( wpinv_get_option( 'checkout_page' ) );
17
+    $is_object_set    = isset($wp_query->queried_object);
18
+    $is_object_id_set = isset($wp_query->queried_object_id);
19
+    $is_checkout      = is_page(wpinv_get_option('checkout_page'));
20 20
 
21
-    if ( !$is_object_set ) {
22
-        unset( $wp_query->queried_object );
21
+    if (!$is_object_set) {
22
+        unset($wp_query->queried_object);
23 23
     }
24 24
 
25
-    if ( !$is_object_id_set ) {
26
-        unset( $wp_query->queried_object_id );
25
+    if (!$is_object_id_set) {
26
+        unset($wp_query->queried_object_id);
27 27
     }
28 28
 
29
-    return apply_filters( 'wpinv_is_checkout', $is_checkout );
29
+    return apply_filters('wpinv_is_checkout', $is_checkout);
30 30
 }
31 31
 
32 32
 function wpinv_can_checkout() {
33 33
 	$can_checkout = true; // Always true for now
34 34
 
35
-	return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout );
35
+	return (bool) apply_filters('wpinv_can_checkout', $can_checkout);
36 36
 }
37 37
 
38 38
 function wpinv_get_success_page_uri() {
39
-	$page_id = wpinv_get_option( 'success_page', 0 );
40
-	$page_id = absint( $page_id );
39
+	$page_id = wpinv_get_option('success_page', 0);
40
+	$page_id = absint($page_id);
41 41
 
42
-	return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) );
42
+	return apply_filters('wpinv_get_success_page_uri', get_permalink($page_id));
43 43
 }
44 44
 
45 45
 function wpinv_get_history_page_uri() {
46
-	$page_id = wpinv_get_option( 'invoice_history_page', 0 );
47
-	$page_id = absint( $page_id );
46
+	$page_id = wpinv_get_option('invoice_history_page', 0);
47
+	$page_id = absint($page_id);
48 48
 
49
-	return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) );
49
+	return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id));
50 50
 }
51 51
 
52 52
 function wpinv_is_success_page() {
53
-	$is_success_page = wpinv_get_option( 'success_page', false );
54
-	$is_success_page = isset( $is_success_page ) ? is_page( $is_success_page ) : false;
53
+	$is_success_page = wpinv_get_option('success_page', false);
54
+	$is_success_page = isset($is_success_page) ? is_page($is_success_page) : false;
55 55
 
56
-	return apply_filters( 'wpinv_is_success_page', $is_success_page );
56
+	return apply_filters('wpinv_is_success_page', $is_success_page);
57 57
 }
58 58
 
59 59
 function wpinv_is_invoice_history_page() {
60
-	$ret = wpinv_get_option( 'invoice_history_page', false );
61
-	$ret = $ret ? is_page( $ret ) : false;
62
-	return apply_filters( 'wpinv_is_invoice_history_page', $ret );
60
+	$ret = wpinv_get_option('invoice_history_page', false);
61
+	$ret = $ret ? is_page($ret) : false;
62
+	return apply_filters('wpinv_is_invoice_history_page', $ret);
63 63
 }
64 64
 
65 65
 function wpinv_is_subscriptions_history_page() {
66
-    $ret = wpinv_get_option( 'invoice_subscription_page', false );
67
-    $ret = $ret ? is_page( $ret ) : false;
68
-    return apply_filters( 'wpinv_is_subscriptions_history_page', $ret );
66
+    $ret = wpinv_get_option('invoice_subscription_page', false);
67
+    $ret = $ret ? is_page($ret) : false;
68
+    return apply_filters('wpinv_is_subscriptions_history_page', $ret);
69 69
 }
70 70
 
71
-function wpinv_send_to_success_page( $args = null ) {
71
+function wpinv_send_to_success_page($args = null) {
72 72
 	$redirect = wpinv_get_success_page_uri();
73 73
     
74
-    if ( !empty( $args ) ) {
74
+    if (!empty($args)) {
75 75
         // Check for backward compatibility
76
-        if ( is_string( $args ) )
77
-            $args = str_replace( '?', '', $args );
76
+        if (is_string($args))
77
+            $args = str_replace('?', '', $args);
78 78
 
79
-        $args = wp_parse_args( $args );
79
+        $args = wp_parse_args($args);
80 80
 
81
-        $redirect = add_query_arg( $args, $redirect );
81
+        $redirect = add_query_arg($args, $redirect);
82 82
     }
83 83
 
84
-    $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';
84
+    $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';
85 85
     
86
-    $redirect = apply_filters( 'wpinv_success_page_redirect', $redirect, $gateway, $args );
87
-    wp_redirect( $redirect );
86
+    $redirect = apply_filters('wpinv_success_page_redirect', $redirect, $gateway, $args);
87
+    wp_redirect($redirect);
88 88
     exit;
89 89
 }
90 90
 
91
-function wpinv_send_to_failed_page( $args = null ) {
91
+function wpinv_send_to_failed_page($args = null) {
92 92
 	$redirect = wpinv_get_failed_transaction_uri();
93 93
     
94
-    if ( !empty( $args ) ) {
94
+    if (!empty($args)) {
95 95
         // Check for backward compatibility
96
-        if ( is_string( $args ) )
97
-            $args = str_replace( '?', '', $args );
96
+        if (is_string($args))
97
+            $args = str_replace('?', '', $args);
98 98
 
99
-        $args = wp_parse_args( $args );
99
+        $args = wp_parse_args($args);
100 100
 
101
-        $redirect = add_query_arg( $args, $redirect );
101
+        $redirect = add_query_arg($args, $redirect);
102 102
     }
103 103
 
104
-    $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';
104
+    $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';
105 105
     
106
-    $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args );
107
-    wp_redirect( $redirect );
106
+    $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args);
107
+    wp_redirect($redirect);
108 108
     exit;
109 109
 }
110 110
 
111
-function wpinv_get_checkout_uri( $args = array() ) {
112
-	$uri = wpinv_get_option( 'checkout_page', false );
113
-	$uri = isset( $uri ) ? get_permalink( $uri ) : NULL;
111
+function wpinv_get_checkout_uri($args = array()) {
112
+	$uri = wpinv_get_option('checkout_page', false);
113
+	$uri = isset($uri) ? get_permalink($uri) : NULL;
114 114
 
115
-	if ( !empty( $args ) ) {
115
+	if (!empty($args)) {
116 116
 		// Check for backward compatibility
117
-		if ( is_string( $args ) )
118
-			$args = str_replace( '?', '', $args );
117
+		if (is_string($args))
118
+			$args = str_replace('?', '', $args);
119 119
 
120
-		$args = wp_parse_args( $args );
120
+		$args = wp_parse_args($args);
121 121
 
122
-		$uri = add_query_arg( $args, $uri );
122
+		$uri = add_query_arg($args, $uri);
123 123
 	}
124 124
 
125
-	$scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';
125
+	$scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin';
126 126
 
127
-	$ajax_url = admin_url( 'admin-ajax.php', $scheme );
127
+	$ajax_url = admin_url('admin-ajax.php', $scheme);
128 128
 
129
-	if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) {
130
-		$uri = preg_replace( '/^http:/', 'https:', $uri );
129
+	if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) {
130
+		$uri = preg_replace('/^http:/', 'https:', $uri);
131 131
 	}
132 132
 
133
-	return apply_filters( 'wpinv_get_checkout_uri', $uri );
133
+	return apply_filters('wpinv_get_checkout_uri', $uri);
134 134
 }
135 135
 
136
-function wpinv_send_back_to_checkout( $args = array() ) {
136
+function wpinv_send_back_to_checkout($args = array()) {
137 137
 	$redirect = wpinv_get_checkout_uri();
138 138
 
139
-	if ( ! empty( $args ) ) {
139
+	if (!empty($args)) {
140 140
 		// Check for backward compatibility
141
-		if ( is_string( $args ) )
142
-			$args = str_replace( '?', '', $args );
141
+		if (is_string($args))
142
+			$args = str_replace('?', '', $args);
143 143
 
144
-		$args = wp_parse_args( $args );
144
+		$args = wp_parse_args($args);
145 145
 
146
-		$redirect = add_query_arg( $args, $redirect );
146
+		$redirect = add_query_arg($args, $redirect);
147 147
 	}
148 148
 
149
-    do_action( 'wpinv_pre_send_back_to_checkout', $args );
150
-	wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) );
149
+    do_action('wpinv_pre_send_back_to_checkout', $args);
150
+	wp_redirect(apply_filters('wpinv_send_back_to_checkout', $redirect, $args));
151 151
 	exit;
152 152
 }
153 153
 
154
-function wpinv_get_success_page_url( $query_string = null ) {
155
-	$success_page = wpinv_get_option( 'success_page', 0 );
156
-	$success_page = get_permalink( $success_page );
154
+function wpinv_get_success_page_url($query_string = null) {
155
+	$success_page = wpinv_get_option('success_page', 0);
156
+	$success_page = get_permalink($success_page);
157 157
 
158
-	if ( $query_string )
158
+	if ($query_string)
159 159
 		$success_page .= $query_string;
160 160
 
161
-	return apply_filters( 'wpinv_success_page_url', $success_page );
161
+	return apply_filters('wpinv_success_page_url', $success_page);
162 162
 }
163 163
 
164
-function wpinv_get_failed_transaction_uri( $extras = false ) {
165
-	$uri = wpinv_get_option( 'failure_page', '' );
166
-	$uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url();
164
+function wpinv_get_failed_transaction_uri($extras = false) {
165
+	$uri = wpinv_get_option('failure_page', '');
166
+	$uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url();
167 167
 
168
-	if ( $extras )
168
+	if ($extras)
169 169
 		$uri .= $extras;
170 170
 
171
-	return apply_filters( 'wpinv_get_failed_transaction_uri', $uri );
171
+	return apply_filters('wpinv_get_failed_transaction_uri', $uri);
172 172
 }
173 173
 
174 174
 function wpinv_is_failed_transaction_page() {
175
-	$ret = wpinv_get_option( 'failure_page', false );
176
-	$ret = isset( $ret ) ? is_page( $ret ) : false;
175
+	$ret = wpinv_get_option('failure_page', false);
176
+	$ret = isset($ret) ? is_page($ret) : false;
177 177
 
178
-	return apply_filters( 'wpinv_is_failure_page', $ret );
178
+	return apply_filters('wpinv_is_failure_page', $ret);
179 179
 }
180 180
 
181
-function wpinv_transaction_query( $type = 'start' ) {
181
+function wpinv_transaction_query($type = 'start') {
182 182
     global $wpdb;
183 183
 
184 184
     $wpdb->hide_errors();
185 185
 
186
-    if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) {
187
-        define( 'WPINV_USE_TRANSACTIONS', true );
186
+    if (!defined('WPINV_USE_TRANSACTIONS')) {
187
+        define('WPINV_USE_TRANSACTIONS', true);
188 188
     }
189 189
 
190
-    if ( WPINV_USE_TRANSACTIONS ) {
191
-        switch ( $type ) {
190
+    if (WPINV_USE_TRANSACTIONS) {
191
+        switch ($type) {
192 192
             case 'commit' :
193
-                $wpdb->query( 'COMMIT' );
193
+                $wpdb->query('COMMIT');
194 194
                 break;
195 195
             case 'rollback' :
196
-                $wpdb->query( 'ROLLBACK' );
196
+                $wpdb->query('ROLLBACK');
197 197
                 break;
198 198
             default :
199
-                $wpdb->query( 'START TRANSACTION' );
199
+                $wpdb->query('START TRANSACTION');
200 200
             break;
201 201
         }
202 202
     }
203 203
 }
204 204
 
205
-function wpinv_create_invoice( $args = array(), $data = array(), $wp_error = false ) {
205
+function wpinv_create_invoice($args = array(), $data = array(), $wp_error = false) {
206 206
     $default_args = array(
207 207
         'status'        => '',
208 208
         'user_id'       => null,
@@ -213,66 +213,66 @@  discard block
 block discarded – undo
213 213
         'post_type'     => 'wpi_invoice'
214 214
     );
215 215
 
216
-    $args           = wp_parse_args( $args, $default_args );
216
+    $args           = wp_parse_args($args, $default_args);
217 217
     $invoice_data   = array();
218 218
 
219
-    if ( $args['invoice_id'] > 0 ) {
220
-        $updating           = true;
219
+    if ($args['invoice_id'] > 0) {
220
+        $updating = true;
221 221
         $invoice_data['post_type']  = $args['post_type'];
222 222
         $invoice_data['ID']         = $args['invoice_id'];
223 223
     } else {
224 224
         $updating                       = false;
225 225
         $invoice_data['post_type']      = $args['post_type'];
226
-        $invoice_data['post_status']    = apply_filters( 'wpinv_default_invoice_status', 'wpi-pending' );
226
+        $invoice_data['post_status']    = apply_filters('wpinv_default_invoice_status', 'wpi-pending');
227 227
         $invoice_data['ping_status']    = 'closed';
228
-        $invoice_data['post_author']    = !empty( $args['user_id'] ) ? $args['user_id'] : get_current_user_id();
229
-        $invoice_data['post_title']     = wpinv_format_invoice_number( '0' );
230
-        $invoice_data['post_parent']    = absint( $args['parent'] );
231
-        if ( !empty( $args['created_date'] ) ) {
228
+        $invoice_data['post_author']    = !empty($args['user_id']) ? $args['user_id'] : get_current_user_id();
229
+        $invoice_data['post_title']     = wpinv_format_invoice_number('0');
230
+        $invoice_data['post_parent']    = absint($args['parent']);
231
+        if (!empty($args['created_date'])) {
232 232
             $invoice_data['post_date']      = $args['created_date'];
233
-            $invoice_data['post_date_gmt']  = get_gmt_from_date( $args['created_date'] );
233
+            $invoice_data['post_date_gmt']  = get_gmt_from_date($args['created_date']);
234 234
         }
235 235
     }
236 236
 
237
-    if ( $args['status'] ) {
238
-        if ( ! in_array( $args['status'], array_keys( wpinv_get_invoice_statuses() ) ) && 'wpi_invoice' === $invoice_data['post_type'] ) {
239
-            return new WP_Error( 'wpinv_invalid_invoice_status', wp_sprintf( __( 'Invalid invoice status: %s', 'invoicing' ), $args['status'] ) );
237
+    if ($args['status']) {
238
+        if (!in_array($args['status'], array_keys(wpinv_get_invoice_statuses())) && 'wpi_invoice' === $invoice_data['post_type']) {
239
+            return new WP_Error('wpinv_invalid_invoice_status', wp_sprintf(__('Invalid invoice status: %s', 'invoicing'), $args['status']));
240 240
         }
241
-        $invoice_data['post_status']    = $args['status'];
241
+        $invoice_data['post_status'] = $args['status'];
242 242
     }
243 243
 
244
-    if ( ! is_null( $args['user_note'] ) ) {
245
-        $invoice_data['post_excerpt']   = $args['user_note'];
244
+    if (!is_null($args['user_note'])) {
245
+        $invoice_data['post_excerpt'] = $args['user_note'];
246 246
     }
247 247
 
248
-    if ( $updating ) {
249
-        $invoice_id = wp_update_post( $invoice_data, true );
248
+    if ($updating) {
249
+        $invoice_id = wp_update_post($invoice_data, true);
250 250
     } else {
251
-        $invoice_id = wp_insert_post( apply_filters( 'wpinv_new_invoice_data', $invoice_data ), true );
251
+        $invoice_id = wp_insert_post(apply_filters('wpinv_new_invoice_data', $invoice_data), true);
252 252
     }
253 253
 
254
-    if ( is_wp_error( $invoice_id ) ) {
254
+    if (is_wp_error($invoice_id)) {
255 255
         return $wp_error ? $invoice_id : 0;
256 256
     }
257 257
     
258
-    $invoice = wpinv_get_invoice( $invoice_id );
259
-
260
-    if ( !$updating ) {
261
-        update_post_meta( $invoice_id, '_wpinv_key', apply_filters( 'wpinv_generate_invoice_key', uniqid( 'wpinv_' ) ) );
262
-        update_post_meta( $invoice_id, '_wpinv_currency', wpinv_get_currency() );
263
-        update_post_meta( $invoice_id, '_wpinv_include_tax', get_option( 'wpinv_prices_include_tax' ) );
264
-        update_post_meta( $invoice_id, '_wpinv_user_ip', wpinv_get_ip() );
265
-        update_post_meta( $invoice_id, '_wpinv_user_agent', wpinv_get_user_agent() );
266
-        update_post_meta( $invoice_id, '_wpinv_created_via', sanitize_text_field( $args['created_via'] ) );
258
+    $invoice = wpinv_get_invoice($invoice_id);
259
+
260
+    if (!$updating) {
261
+        update_post_meta($invoice_id, '_wpinv_key', apply_filters('wpinv_generate_invoice_key', uniqid('wpinv_')));
262
+        update_post_meta($invoice_id, '_wpinv_currency', wpinv_get_currency());
263
+        update_post_meta($invoice_id, '_wpinv_include_tax', get_option('wpinv_prices_include_tax'));
264
+        update_post_meta($invoice_id, '_wpinv_user_ip', wpinv_get_ip());
265
+        update_post_meta($invoice_id, '_wpinv_user_agent', wpinv_get_user_agent());
266
+        update_post_meta($invoice_id, '_wpinv_created_via', sanitize_text_field($args['created_via']));
267 267
         
268 268
         // Add invoice note
269
-        if ( ! $invoice->is_quote() ) {
270
-            $invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );
269
+        if (!$invoice->is_quote()) {
270
+            $invoice->add_note(wp_sprintf(__('Invoice is created with status %s.', 'invoicing'), wpinv_status_nicename($invoice->status)));
271 271
         }
272 272
         
273 273
     }
274 274
 
275
-    update_post_meta( $invoice_id, '_wpinv_version', WPINV_VERSION );
275
+    update_post_meta($invoice_id, '_wpinv_version', WPINV_VERSION);
276 276
 
277 277
     return $invoice;
278 278
 }
@@ -280,184 +280,184 @@  discard block
 block discarded – undo
280 280
 function wpinv_get_prefix() {
281 281
     $invoice_prefix = 'INV-';
282 282
     
283
-    return apply_filters( 'wpinv_get_prefix', $invoice_prefix );
283
+    return apply_filters('wpinv_get_prefix', $invoice_prefix);
284 284
 }
285 285
 
286 286
 function wpinv_get_business_logo() {
287
-    $business_logo = wpinv_get_option( 'logo' );
288
-    return apply_filters( 'wpinv_get_business_logo', $business_logo );
287
+    $business_logo = wpinv_get_option('logo');
288
+    return apply_filters('wpinv_get_business_logo', $business_logo);
289 289
 }
290 290
 
291 291
 function wpinv_get_business_name() {
292 292
     $business_name = wpinv_get_option('store_name');
293
-    return apply_filters( 'wpinv_get_business_name', $business_name );
293
+    return apply_filters('wpinv_get_business_name', $business_name);
294 294
 }
295 295
 
296 296
 function wpinv_get_blogname() {
297
-    return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
297
+    return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
298 298
 }
299 299
 
300 300
 function wpinv_get_admin_email() {
301
-    $admin_email = wpinv_get_option( 'admin_email', get_option( 'admin_email' ) );
302
-    return apply_filters( 'wpinv_admin_email', $admin_email );
301
+    $admin_email = wpinv_get_option('admin_email', get_option('admin_email'));
302
+    return apply_filters('wpinv_admin_email', $admin_email);
303 303
 }
304 304
 
305 305
 function wpinv_get_business_website() {
306
-    $business_website = home_url( '/' );
307
-    return apply_filters( 'wpinv_get_business_website', $business_website );
306
+    $business_website = home_url('/');
307
+    return apply_filters('wpinv_get_business_website', $business_website);
308 308
 }
309 309
 
310
-function wpinv_get_terms_text( $invoice_id = 0 ) {
310
+function wpinv_get_terms_text($invoice_id = 0) {
311 311
     $terms_text = '';
312
-    return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id );
312
+    return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id);
313 313
 }
314 314
 
315 315
 function wpinv_get_business_footer() {
316
-    $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>';
317
-    $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link );
318
-    return apply_filters( 'wpinv_get_business_footer', $business_footer );
316
+    $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>';
317
+    $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link);
318
+    return apply_filters('wpinv_get_business_footer', $business_footer);
319 319
 }
320 320
 
321 321
 function wpinv_checkout_required_fields() {
322 322
     $required_fields = array();
323 323
     
324 324
     // Let payment gateways and other extensions determine if address fields should be required
325
-    $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() );
325
+    $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes());
326 326
     
327
-    if ( $require_billing_details ) {
328
-		if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) {
327
+    if ($require_billing_details) {
328
+		if ((bool) wpinv_get_option('fname_mandatory')) {
329 329
 			$required_fields['first_name'] = array(
330 330
 				'error_id' => 'invalid_first_name',
331
-				'error_message' => __( 'Please enter your first name', 'invoicing' )
331
+				'error_message' => __('Please enter your first name', 'invoicing')
332 332
 			);
333 333
 		}
334
-		if ( (bool)wpinv_get_option( 'address_mandatory' ) ) {
334
+		if ((bool) wpinv_get_option('address_mandatory')) {
335 335
 			$required_fields['address'] = array(
336 336
 				'error_id' => 'invalid_address',
337
-				'error_message' => __( 'Please enter your address', 'invoicing' )
337
+				'error_message' => __('Please enter your address', 'invoicing')
338 338
 			);
339 339
 		}
340
-		if ( (bool)wpinv_get_option( 'city_mandatory' ) ) {
340
+		if ((bool) wpinv_get_option('city_mandatory')) {
341 341
 			$required_fields['city'] = array(
342 342
 				'error_id' => 'invalid_city',
343
-				'error_message' => __( 'Please enter your billing city', 'invoicing' )
343
+				'error_message' => __('Please enter your billing city', 'invoicing')
344 344
 			);
345 345
 		}
346
-		if ( (bool)wpinv_get_option( 'state_mandatory' ) ) {
346
+		if ((bool) wpinv_get_option('state_mandatory')) {
347 347
 			$required_fields['state'] = array(
348 348
 				'error_id' => 'invalid_state',
349
-				'error_message' => __( 'Please enter billing state / province', 'invoicing' )
349
+				'error_message' => __('Please enter billing state / province', 'invoicing')
350 350
 			);
351 351
 		}
352
-		if ( (bool)wpinv_get_option( 'country_mandatory' ) ) {
352
+		if ((bool) wpinv_get_option('country_mandatory')) {
353 353
 			$required_fields['country'] = array(
354 354
 				'error_id' => 'invalid_country',
355
-				'error_message' => __( 'Please select your billing country', 'invoicing' )
355
+				'error_message' => __('Please select your billing country', 'invoicing')
356 356
 			);
357 357
 		}
358 358
     }
359 359
 
360
-    return apply_filters( 'wpinv_checkout_required_fields', $required_fields );
360
+    return apply_filters('wpinv_checkout_required_fields', $required_fields);
361 361
 }
362 362
 
363 363
 function wpinv_is_ssl_enforced() {
364
-    $ssl_enforced = wpinv_get_option( 'enforce_ssl', false );
365
-    return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced );
364
+    $ssl_enforced = wpinv_get_option('enforce_ssl', false);
365
+    return (bool) apply_filters('wpinv_is_ssl_enforced', $ssl_enforced);
366 366
 }
367 367
 
368
-function wpinv_user_can_view_invoice( $post ) {
368
+function wpinv_user_can_view_invoice($post) {
369 369
     $allow = false;
370 370
 
371
-    $post = get_post( $post );
371
+    $post = get_post($post);
372 372
 
373
-    if ( empty( $post->ID ) ) {
373
+    if (empty($post->ID)) {
374 374
         return $allow;
375 375
     }
376 376
 
377
-    $invoice = wpinv_get_invoice( $post->ID );
378
-    if ( empty( $invoice->ID ) ) {
377
+    $invoice = wpinv_get_invoice($post->ID);
378
+    if (empty($invoice->ID)) {
379 379
         return $allow;
380 380
     }
381 381
 
382 382
     // Don't allow trash, draft status
383
-    if ( $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) {
384
-        if ( wpinv_current_user_can_manage_invoicing() || current_user_can( 'view_invoices', $invoice->ID ) ) { // Admin user
383
+    if ($invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) {
384
+        if (wpinv_current_user_can_manage_invoicing() || current_user_can('view_invoices', $invoice->ID)) { // Admin user
385 385
             $allow = true;
386 386
         } else {
387
-            if ( is_user_logged_in() ) {
388
-                if ( (int)$invoice->get_user_id() === (int)get_current_user_id() ) {
387
+            if (is_user_logged_in()) {
388
+                if ((int) $invoice->get_user_id() === (int) get_current_user_id()) {
389 389
                     $allow = true;
390
-                } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
390
+                } else if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
391 391
                     $allow = true;
392 392
                 }
393 393
             } else {
394
-                if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
394
+                if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
395 395
                     $allow = true;
396 396
                 }
397 397
             }
398 398
         }
399 399
     }
400 400
     
401
-    return apply_filters( 'wpinv_can_print_invoice', $allow, $post, $invoice );
401
+    return apply_filters('wpinv_can_print_invoice', $allow, $post, $invoice);
402 402
 }
403 403
 
404 404
 function wpinv_schedule_events() {
405 405
     // hourly, daily and twicedaily
406
-    if ( !wp_next_scheduled( 'wpinv_register_schedule_event_twicedaily' ) ) {
407
-        wp_schedule_event( current_time( 'timestamp' ), 'twicedaily', 'wpinv_register_schedule_event_twicedaily' );
406
+    if (!wp_next_scheduled('wpinv_register_schedule_event_twicedaily')) {
407
+        wp_schedule_event(current_time('timestamp'), 'twicedaily', 'wpinv_register_schedule_event_twicedaily');
408 408
     }
409 409
 }
410
-add_action( 'wp', 'wpinv_schedule_events' );
410
+add_action('wp', 'wpinv_schedule_events');
411 411
 
412 412
 function wpinv_schedule_event_twicedaily() {
413 413
     wpinv_email_payment_reminders();
414 414
 }
415
-add_action( 'wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily' );
415
+add_action('wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily');
416 416
 
417 417
 function wpinv_require_login_to_checkout() {
418
-    $return = wpinv_get_option( 'login_to_checkout', false );
419
-    return (bool) apply_filters( 'wpinv_require_login_to_checkout', $return );
418
+    $return = wpinv_get_option('login_to_checkout', false);
419
+    return (bool) apply_filters('wpinv_require_login_to_checkout', $return);
420 420
 }
421 421
 
422
-function wpinv_sequential_number_active( $type = '' ) {
423
-    $check = apply_filters( 'wpinv_pre_check_sequential_number_active', null, $type );
424
-    if ( null !== $check ) {
422
+function wpinv_sequential_number_active($type = '') {
423
+    $check = apply_filters('wpinv_pre_check_sequential_number_active', null, $type);
424
+    if (null !== $check) {
425 425
         return $check;
426 426
     }
427 427
     
428
-    return wpinv_get_option( 'sequential_invoice_number' );
428
+    return wpinv_get_option('sequential_invoice_number');
429 429
 }
430 430
 
431
-function wpinv_switch_to_locale( $locale = NULL ) {
431
+function wpinv_switch_to_locale($locale = NULL) {
432 432
     global $invoicing, $wpi_switch_locale;
433 433
 
434
-    if ( ! empty( $invoicing ) && function_exists( 'switch_to_locale' ) ) {
435
-        $locale = empty( $locale ) ? get_locale() : $locale;
434
+    if (!empty($invoicing) && function_exists('switch_to_locale')) {
435
+        $locale = empty($locale) ? get_locale() : $locale;
436 436
 
437
-        switch_to_locale( $locale );
437
+        switch_to_locale($locale);
438 438
 
439 439
         $wpi_switch_locale = $locale;
440 440
 
441
-        add_filter( 'plugin_locale', 'get_locale' );
441
+        add_filter('plugin_locale', 'get_locale');
442 442
 
443 443
         $invoicing->load_textdomain();
444 444
 
445
-        do_action( 'wpinv_switch_to_locale', $locale );
445
+        do_action('wpinv_switch_to_locale', $locale);
446 446
     }
447 447
 }
448 448
 
449 449
 function wpinv_restore_locale() {
450 450
     global $invoicing, $wpi_switch_locale;
451 451
     
452
-    if ( ! empty( $invoicing ) && function_exists( 'restore_previous_locale' ) && $wpi_switch_locale ) {
452
+    if (!empty($invoicing) && function_exists('restore_previous_locale') && $wpi_switch_locale) {
453 453
         restore_previous_locale();
454 454
 
455 455
         $wpi_switch_locale = NULL;
456 456
 
457
-        remove_filter( 'plugin_locale', 'get_locale' );
457
+        remove_filter('plugin_locale', 'get_locale');
458 458
 
459 459
         $invoicing->load_textdomain();
460 460
 
461
-        do_action( 'wpinv_restore_locale' );
461
+        do_action('wpinv_restore_locale');
462 462
     }
463 463
 }
464 464
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Spacing   +245 added lines, -245 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();
@@ -33,34 +33,34 @@  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( &$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(&$this, 'wpinv_actions'));
48 48
         
49
-        if ( class_exists( 'BuddyPress' ) ) {
50
-            add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
49
+        if (class_exists('BuddyPress')) {
50
+            add_action('bp_include', array(&$this, 'bp_invoicing_init'));
51 51
         }
52 52
 
53
-        add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
54
-        add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
55
-        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
53
+        add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts'));
54
+        add_action('widgets_init', array(&$this, 'register_widgets'));
55
+        add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids'));
56 56
 
57
-        if ( is_admin() ) {
58
-            add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
59
-            add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ) );
60
-            add_action( 'admin_init', array( &$this, 'init_ayecode_connect_helper' ) );
57
+        if (is_admin()) {
58
+            add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
59
+            add_filter('admin_body_class', array(&$this, 'admin_body_class'));
60
+            add_action('admin_init', array(&$this, 'init_ayecode_connect_helper'));
61 61
 
62 62
         } else {
63
-            add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
63
+            add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
64 64
         }
65 65
         
66 66
         /**
@@ -70,28 +70,28 @@  discard block
 block discarded – undo
70 70
          *
71 71
          * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference.
72 72
          */
73
-        do_action_ref_array( 'wpinv_actions', array( &$this ) );
73
+        do_action_ref_array('wpinv_actions', array(&$this));
74 74
 
75
-        add_action( 'admin_init', array( &$this, 'activation_redirect') );
75
+        add_action('admin_init', array(&$this, 'activation_redirect'));
76 76
     }
77 77
 
78 78
     /**
79 79
      * Maybe show the AyeCode Connect Notice.
80 80
      */
81
-    public function init_ayecode_connect_helper(){
81
+    public function init_ayecode_connect_helper() {
82 82
         // AyeCode Connect notice
83
-        if ( is_admin() ){
83
+        if (is_admin()) {
84 84
             // set the strings so they can be translated
85 85
             $strings = array(
86
-                'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
87
-                'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
88
-                'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
89
-                'connect_button'    => __("Connect Site","invoicing"),
90
-                'connecting_button'    => __("Connecting...","invoicing"),
91
-                'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
92
-                'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
86
+                'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"),
87
+                'connect_external'  => __("Please confirm you wish to connect your site?", "invoicing"),
88
+                'connect'           => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"),
89
+                'connect_button'    => __("Connect Site", "invoicing"),
90
+                'connecting_button'    => __("Connecting...", "invoicing"),
91
+                'error_localhost'   => __("This service will only work with a live domain, not a localhost.", "invoicing"),
92
+                'error'             => __("Something went wrong, please refresh and try again.", "invoicing"),
93 93
             );
94
-            new AyeCode_Connect_Helper($strings,array('wpi-addons'));
94
+            new AyeCode_Connect_Helper($strings, array('wpi-addons'));
95 95
         }
96 96
     }
97 97
     
@@ -99,10 +99,10 @@  discard block
 block discarded – undo
99 99
         /* Internationalize the text strings used. */
100 100
         $this->load_textdomain();
101 101
 
102
-        do_action( 'wpinv_loaded' );
102
+        do_action('wpinv_loaded');
103 103
 
104 104
         // Fix oxygen page builder conflict
105
-        if ( function_exists( 'ct_css_output' ) ) {
105
+        if (function_exists('ct_css_output')) {
106 106
             wpinv_oxygen_fix_conflict();
107 107
         }
108 108
     }
@@ -112,237 +112,237 @@  discard block
 block discarded – undo
112 112
      *
113 113
      * @since 1.0
114 114
      */
115
-    public function load_textdomain( $locale = NULL ) {
116
-        if ( empty( $locale ) ) {
117
-            $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
115
+    public function load_textdomain($locale = NULL) {
116
+        if (empty($locale)) {
117
+            $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale();
118 118
         }
119 119
 
120
-        $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
120
+        $locale = apply_filters('plugin_locale', $locale, 'invoicing');
121 121
         
122
-        unload_textdomain( 'invoicing' );
123
-        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
124
-        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
122
+        unload_textdomain('invoicing');
123
+        load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo');
124
+        load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages');
125 125
         
126 126
         /**
127 127
          * Define language constants.
128 128
          */
129
-        require_once( WPINV_PLUGIN_DIR . 'language.php' );
129
+        require_once(WPINV_PLUGIN_DIR . 'language.php');
130 130
     }
131 131
         
132 132
     public function includes() {
133 133
         global $wpinv_options;
134 134
         
135
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
135
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php');
136 136
         $wpinv_options = wpinv_get_settings();
137 137
         
138
-        require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
139
-        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' );
140
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
141
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
142
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
143
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
144
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
145
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
146
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' );
147
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
148
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
149
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
150
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
151
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
152
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' );
153
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' );
154
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' );
155
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-discount.php' );
156
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' );
157
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' );
158
-        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
159
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
160
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
161
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
162
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
163
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
164
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
165
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
166
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
167
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' );
168
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
169
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' );
170
-        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
171
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
172
-        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
173
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
174
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
175
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
176
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
177
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
178
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
179
-        require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
180
-        require_once( WPINV_PLUGIN_DIR . 'widgets/payment-form.php' );
181
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' );
182
-
183
-        if ( !class_exists( 'WPInv_EUVat' ) ) {
184
-            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
138
+        require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php');
139
+        require_once(WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php');
140
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php');
141
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php');
142
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php');
143
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php');
144
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php');
145
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php');
146
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php');
147
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php');
148
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php');
149
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php');
150
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php');
151
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php');
152
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php');
153
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php');
154
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php');
155
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-discount.php');
156
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php');
157
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php');
158
+        require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php');
159
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php');
160
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php');
161
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php');
162
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php');
163
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php');
164
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php');
165
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php');
166
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php');
167
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php');
168
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php');
169
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php');
170
+        require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php');
171
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php');
172
+        require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php');
173
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php');
174
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php');
175
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php');
176
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php');
177
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php');
178
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php');
179
+        require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php');
180
+        require_once(WPINV_PLUGIN_DIR . 'widgets/payment-form.php');
181
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php');
182
+
183
+        if (!class_exists('WPInv_EUVat')) {
184
+            require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php');
185 185
         }
186 186
         
187
-        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
188
-        if ( !empty( $gateways ) ) {
189
-            foreach ( $gateways as $gateway ) {
190
-                if ( $gateway == 'manual' ) {
187
+        $gateways = array_keys(wpinv_get_enabled_payment_gateways());
188
+        if (!empty($gateways)) {
189
+            foreach ($gateways as $gateway) {
190
+                if ($gateway == 'manual') {
191 191
                     continue;
192 192
                 }
193 193
                 
194 194
                 $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
195 195
                 
196
-                if ( file_exists( $gateway_file ) ) {
197
-                    require_once( $gateway_file );
196
+                if (file_exists($gateway_file)) {
197
+                    require_once($gateway_file);
198 198
                 }
199 199
             }
200 200
         }
201
-        require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' );
201
+        require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php');
202 202
         
203
-        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
204
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
205
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
206
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' );
203
+        if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
204
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php');
205
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php');
206
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php');
207 207
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' );
208
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' );
209
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' );
210
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
211
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
212
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' );
213
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
214
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
215
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
208
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php');
209
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php');
210
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php');
211
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php');
212
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php');
213
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php');
214
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php');
215
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php');
216 216
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
217 217
             // load the user class only on the users.php page
218 218
             global $pagenow;
219
-            if($pagenow=='users.php'){
219
+            if ($pagenow == 'users.php') {
220 220
                 new WPInv_Admin_Users();
221 221
             }
222 222
         }
223 223
 
224 224
         // Register cli commands
225
-        if ( defined( 'WP_CLI' ) && WP_CLI ) {
226
-            require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
227
-            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
225
+        if (defined('WP_CLI') && WP_CLI) {
226
+            require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php');
227
+            WP_CLI::add_command('invoicing', 'WPInv_CLI');
228 228
         }
229 229
         
230 230
         // include css inliner
231
-        if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
232
-            include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
231
+        if (!class_exists('Emogrifier') && class_exists('DOMDocument')) {
232
+            include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php');
233 233
         }
234 234
         
235
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
235
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php');
236 236
     }
237 237
     
238 238
     public function init() {
239 239
     }
240 240
     
241 241
     public function admin_init() {
242
-        add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) );
242
+        add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php'));
243 243
     }
244 244
 
245 245
     public function activation_redirect() {
246 246
         // Bail if no activation redirect
247
-        if ( !get_transient( '_wpinv_activation_redirect' ) ) {
247
+        if (!get_transient('_wpinv_activation_redirect')) {
248 248
             return;
249 249
         }
250 250
 
251 251
         // Delete the redirect transient
252
-        delete_transient( '_wpinv_activation_redirect' );
252
+        delete_transient('_wpinv_activation_redirect');
253 253
 
254 254
         // Bail if activating from network, or bulk
255
-        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
255
+        if (is_network_admin() || isset($_GET['activate-multi'])) {
256 256
             return;
257 257
         }
258 258
 
259
-        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
259
+        wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
260 260
         exit;
261 261
     }
262 262
     
263 263
     public function enqueue_scripts() {
264
-        $suffix       = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
264
+        $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
265 265
         
266
-        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION );
267
-        wp_enqueue_style( 'wpinv_front_style' );
266
+        wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION);
267
+        wp_enqueue_style('wpinv_front_style');
268 268
                
269 269
         // Register scripts
270
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
271
-        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ),  filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) );
270
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
271
+        wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), filemtime(WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js'));
272 272
 
273 273
         $localize                         = array();
274
-        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
275
-        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
274
+        $localize['ajax_url']             = admin_url('admin-ajax.php');
275
+        $localize['nonce']                = wp_create_nonce('wpinv-nonce');
276 276
         $localize['currency_symbol']      = wpinv_currency_symbol();
277 277
         $localize['currency_pos']         = wpinv_currency_position();
278 278
         $localize['thousand_sep']         = wpinv_thousands_separator();
279 279
         $localize['decimal_sep']          = wpinv_decimal_separator();
280 280
         $localize['decimals']             = wpinv_decimals();
281
-        $localize['txtComplete']          = __( 'Complete', 'invoicing' );
281
+        $localize['txtComplete']          = __('Complete', 'invoicing');
282 282
         $localize['UseTaxes']             = wpinv_use_taxes();
283
-        $localize['checkoutNonce']        = wp_create_nonce( 'wpinv_checkout_nonce' );
283
+        $localize['checkoutNonce']        = wp_create_nonce('wpinv_checkout_nonce');
284 284
 
285
-        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
285
+        $localize = apply_filters('wpinv_front_js_localize', $localize);
286 286
         
287
-        wp_enqueue_script( 'jquery-blockui' );
287
+        wp_enqueue_script('jquery-blockui');
288 288
         $autofill_api = wpinv_get_option('address_autofill_api');
289 289
         $autofill_active = wpinv_get_option('address_autofill_active');
290
-        if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) {
291
-            if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) {
292
-                wp_dequeue_script( 'google-maps-api' );
290
+        if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) {
291
+            if (wp_script_is('google-maps-api', 'enqueued')) {
292
+                wp_dequeue_script('google-maps-api');
293 293
             }
294
-            wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false );
295
-            wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true );
294
+            wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false);
295
+            wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true);
296 296
         }
297 297
 
298
-        wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
299
-        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
298
+        wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all');
299
+        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION);
300 300
 
301
-        wp_enqueue_script( 'wpinv-front-script' );
302
-        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
301
+        wp_enqueue_script('wpinv-front-script');
302
+        wp_localize_script('wpinv-front-script', 'WPInv', $localize);
303 303
 
304
-        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
305
-        wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ),  $version, true );
304
+        $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js');
305
+        wp_enqueue_script('wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('wpinv-front-script', 'wp-hooks'), $version, true);
306 306
     }
307 307
 
308
-    public function admin_enqueue_scripts( $hook ) {
308
+    public function admin_enqueue_scripts($hook) {
309 309
         global $post, $pagenow;
310 310
         
311 311
         $post_type  = wpinv_admin_post_type();
312
-        $suffix     = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
313
-        $page       = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : '';
312
+        $suffix     = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
313
+        $page       = isset($_GET['page']) ? strtolower($_GET['page']) : '';
314 314
 
315 315
         $jquery_ui_css = false;
316
-        if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
316
+        if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
317 317
             $jquery_ui_css = true;
318
-        } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) {
318
+        } else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') {
319 319
             $jquery_ui_css = true;
320 320
         }
321
-        if ( $jquery_ui_css ) {
322
-            wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
323
-            wp_enqueue_style( 'jquery-ui-css' );
321
+        if ($jquery_ui_css) {
322
+            wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16');
323
+            wp_enqueue_style('jquery-ui-css');
324 324
         }
325 325
 
326
-        wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
327
-        wp_enqueue_style( 'wpinv_meta_box_style' );
326
+        wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
327
+        wp_enqueue_style('wpinv_meta_box_style');
328 328
         
329
-        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' );
330
-        wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version );
331
-        wp_enqueue_style( 'wpinv_admin_style' );
329
+        $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css');
330
+        wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version);
331
+        wp_enqueue_style('wpinv_admin_style');
332 332
 
333
-        $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) );
334
-        if ( $page == 'wpinv-subscriptions' ) {
335
-            wp_enqueue_script( 'jquery-ui-datepicker' );
333
+        $enqueue = ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php'));
334
+        if ($page == 'wpinv-subscriptions') {
335
+            wp_enqueue_script('jquery-ui-datepicker');
336 336
         }
337 337
         
338
-        if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) {
339
-            wp_enqueue_script( 'jquery-ui-datepicker' );
338
+        if ($enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue)) {
339
+            wp_enqueue_script('jquery-ui-datepicker');
340 340
         }
341 341
 
342
-        wp_enqueue_style( 'wp-color-picker' );
343
-        wp_enqueue_script( 'wp-color-picker' );
342
+        wp_enqueue_style('wp-color-picker');
343
+        wp_enqueue_script('wp-color-picker');
344 344
         
345
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
345
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
346 346
 
347 347
         if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
348 348
             $autofill_api = wpinv_get_option('address_autofill_api');
@@ -353,21 +353,21 @@  discard block
 block discarded – undo
353 353
             }
354 354
         }
355 355
 
356
-        wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
357
-        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
356
+        wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all');
357
+        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION);
358 358
 
359
-        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' );
360
-        wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ),  $version );
361
-        wp_enqueue_script( 'wpinv-admin-script' );
359
+        $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js');
360
+        wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), $version);
361
+        wp_enqueue_script('wpinv-admin-script');
362 362
         
363 363
         $localize                               = array();
364
-        $localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
365
-        $localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
366
-        $localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
367
-        $localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
368
-        $localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
369
-        $localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
370
-        $localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
364
+        $localize['ajax_url']                   = admin_url('admin-ajax.php');
365
+        $localize['post_ID']                    = isset($post->ID) ? $post->ID : '';
366
+        $localize['wpinv_nonce']                = wp_create_nonce('wpinv-nonce');
367
+        $localize['add_invoice_note_nonce']     = wp_create_nonce('add-invoice-note');
368
+        $localize['delete_invoice_note_nonce']  = wp_create_nonce('delete-invoice-note');
369
+        $localize['invoice_item_nonce']         = wp_create_nonce('invoice-item');
370
+        $localize['billing_details_nonce']      = wp_create_nonce('get-billing-details');
371 371
         $localize['tax']                        = wpinv_tax_amount();
372 372
         $localize['discount']                   = wpinv_discount_amount();
373 373
         $localize['currency_symbol']            = wpinv_currency_symbol();
@@ -375,95 +375,95 @@  discard block
 block discarded – undo
375 375
         $localize['thousand_sep']               = wpinv_thousands_separator();
376 376
         $localize['decimal_sep']                = wpinv_decimal_separator();
377 377
         $localize['decimals']                   = wpinv_decimals();
378
-        $localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
379
-        $localize['status_publish']             = wpinv_status_nicename( 'publish' );
380
-        $localize['status_pending']             = wpinv_status_nicename( 'wpi-pending' );
381
-        $localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
382
-        $localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
383
-        $localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
384
-        $localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
385
-        $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' );
386
-        $localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
387
-        $localize['emptyInvoice']               = __( 'Add at least one item to save invoice!', 'invoicing' );
388
-        $localize['errDeleteItem']              = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
389
-        $localize['delete_subscription']        = __( 'Are you sure you want to delete this subscription?', 'invoicing' );
390
-        $localize['action_edit']                = __( 'Edit', 'invoicing' );
391
-        $localize['action_cancel']              = __( 'Cancel', 'invoicing' );
392
-
393
-        $localize = apply_filters( 'wpinv_admin_js_localize', $localize );
394
-
395
-        wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
378
+        $localize['save_invoice']               = __('Save Invoice', 'invoicing');
379
+        $localize['status_publish']             = wpinv_status_nicename('publish');
380
+        $localize['status_pending']             = wpinv_status_nicename('wpi-pending');
381
+        $localize['delete_tax_rate']            = __('Are you sure you wish to delete this tax rate?', 'invoicing');
382
+        $localize['OneItemMin']                 = __('Invoice must contain at least one item', 'invoicing');
383
+        $localize['DeleteInvoiceItem']          = __('Are you sure you wish to delete this item?', 'invoicing');
384
+        $localize['FillBillingDetails']         = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing');
385
+        $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');
386
+        $localize['AreYouSure']                 = __('Are you sure?', 'invoicing');
387
+        $localize['emptyInvoice']               = __('Add at least one item to save invoice!', 'invoicing');
388
+        $localize['errDeleteItem']              = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing');
389
+        $localize['delete_subscription']        = __('Are you sure you want to delete this subscription?', 'invoicing');
390
+        $localize['action_edit']                = __('Edit', 'invoicing');
391
+        $localize['action_cancel']              = __('Cancel', 'invoicing');
392
+
393
+        $localize = apply_filters('wpinv_admin_js_localize', $localize);
394
+
395
+        wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize);
396 396
 
397 397
         // Load payment form scripts on our admin pages only.
398
-        if ( ( $hook == 'post-new.php' || $hook == 'post.php' ) && 'wpi_payment_form' === $post->post_type ) {
398
+        if (($hook == 'post-new.php' || $hook == 'post.php') && 'wpi_payment_form' === $post->post_type) {
399 399
 
400
-            wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
401
-            wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
402
-            wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
400
+            wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION);
401
+            wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION);
402
+            wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION);
403 403
 
404
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
405
-            wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
404
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js');
405
+            wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version);
406 406
         
407
-            wp_localize_script( 'wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array(
407
+            wp_localize_script('wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array(
408 408
                 'elements'      => $this->form_elements->get_elements(),
409
-                'form_elements' => $this->form_elements->get_form_elements( $post->ID ),
409
+                'form_elements' => $this->form_elements->get_form_elements($post->ID),
410 410
                 'all_items'     => $this->form_elements->get_published_items(),
411 411
                 'currency'      => wpinv_currency_symbol(),
412 412
                 'position'      => wpinv_currency_position(),
413 413
                 'decimals'      => (int) wpinv_decimals(),
414 414
                 'thousands_sep' => wpinv_thousands_separator(),
415 415
                 'decimals_sep'  => wpinv_decimal_separator(),
416
-                'form_items'    => $this->form_elements->get_form_items( $post->ID ),
417
-            ) );
416
+                'form_items'    => $this->form_elements->get_form_items($post->ID),
417
+            ));
418 418
 
419
-            wp_enqueue_script( 'wpinv-admin-payment-form-script' );
419
+            wp_enqueue_script('wpinv-admin-payment-form-script');
420 420
         }
421 421
 
422
-        if ( $page == 'wpinv-subscriptions' ) {
423
-            wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
424
-            wp_enqueue_script( 'wpinv-sub-admin-script' );
422
+        if ($page == 'wpinv-subscriptions') {
423
+            wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION);
424
+            wp_enqueue_script('wpinv-sub-admin-script');
425 425
         }
426 426
 
427 427
     }
428 428
 
429
-    public function admin_body_class( $classes ) {
429
+    public function admin_body_class($classes) {
430 430
         global $pagenow, $post, $current_screen;
431 431
         
432
-        if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote' ) ) {
432
+        if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote')) {
433 433
             $classes .= ' wpinv-cpt';
434 434
         }
435 435
         
436
-        $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
436
+        $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
437 437
 
438
-        $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false;
439
-        if ( $add_class ) {
440
-            $classes .= ' wpi-' . wpinv_sanitize_key( $page );
438
+        $add_class = $page && $pagenow == 'admin.php' && strpos($page, 'wpinv-') === 0 ? true : false;
439
+        if ($add_class) {
440
+            $classes .= ' wpi-' . wpinv_sanitize_key($page);
441 441
         }
442 442
         
443 443
         $settings_class = array();
444
-        if ( $page == 'wpinv-settings' ) {
445
-            if ( !empty( $_REQUEST['tab'] ) ) {
446
-                $settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
444
+        if ($page == 'wpinv-settings') {
445
+            if (!empty($_REQUEST['tab'])) {
446
+                $settings_class[] = sanitize_text_field($_REQUEST['tab']);
447 447
             }
448 448
             
449
-            if ( !empty( $_REQUEST['section'] ) ) {
450
-                $settings_class[] = sanitize_text_field( $_REQUEST['section'] );
449
+            if (!empty($_REQUEST['section'])) {
450
+                $settings_class[] = sanitize_text_field($_REQUEST['section']);
451 451
             }
452 452
             
453
-            $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
453
+            $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main';
454 454
         }
455 455
         
456
-        if ( !empty( $settings_class ) ) {
457
-            $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
456
+        if (!empty($settings_class)) {
457
+            $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-'));
458 458
         }
459 459
         
460 460
         $post_type = wpinv_admin_post_type();
461 461
 
462
-        if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
462
+        if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) {
463 463
             return $classes .= ' wpinv';
464 464
         }
465 465
         
466
-        if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) {
466
+        if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) {
467 467
             $classes .= ' wpi-editable-n';
468 468
         }
469 469
 
@@ -475,21 +475,21 @@  discard block
 block discarded – undo
475 475
     }
476 476
     
477 477
     public function wpinv_actions() {
478
-        if ( isset( $_REQUEST['wpi_action'] ) ) {
479
-            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
478
+        if (isset($_REQUEST['wpi_action'])) {
479
+            do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
480 480
         }
481 481
     }
482 482
     
483
-    public function pre_get_posts( $wp_query ) {
484
-        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() ) {
485
-            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
483
+    public function pre_get_posts($wp_query) {
484
+        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()) {
485
+            $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses());
486 486
         }
487 487
         
488 488
         return $wp_query;
489 489
     }
490 490
     
491 491
     public function bp_invoicing_init() {
492
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
492
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php');
493 493
     }
494 494
 
495 495
 	/**
@@ -497,13 +497,13 @@  discard block
 block discarded – undo
497 497
 	 *
498 498
 	 */
499 499
 	public function register_widgets() {
500
-		register_widget( "WPInv_Checkout_Widget" );
501
-		register_widget( "WPInv_History_Widget" );
502
-		register_widget( "WPInv_Receipt_Widget" );
503
-		register_widget( "WPInv_Subscriptions_Widget" );
504
-		register_widget( "WPInv_Buy_Item_Widget" );
505
-        register_widget( "WPInv_Messages_Widget" );
506
-        register_widget( 'WPInv_Payment_Form_Widget' );
500
+		register_widget("WPInv_Checkout_Widget");
501
+		register_widget("WPInv_History_Widget");
502
+		register_widget("WPInv_Receipt_Widget");
503
+		register_widget("WPInv_Subscriptions_Widget");
504
+		register_widget("WPInv_Buy_Item_Widget");
505
+        register_widget("WPInv_Messages_Widget");
506
+        register_widget('WPInv_Payment_Form_Widget');
507 507
 	}
508 508
     
509 509
     /**
@@ -512,10 +512,10 @@  discard block
 block discarded – undo
512 512
      * @since 1.0.19
513 513
      * @param int[] $excluded_posts_ids
514 514
      */
515
-    function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
515
+    function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) {
516 516
 
517 517
         // Ensure that we have an array.
518
-        if ( ! is_array( $excluded_posts_ids ) ) {
518
+        if (!is_array($excluded_posts_ids)) {
519 519
             $excluded_posts_ids = array();
520 520
         }
521 521
 
@@ -523,24 +523,24 @@  discard block
 block discarded – undo
523 523
         $our_pages = array();
524 524
     
525 525
         // Checkout page.
526
-        $our_pages[] = wpinv_get_option( 'checkout_page', false );
526
+        $our_pages[] = wpinv_get_option('checkout_page', false);
527 527
 
528 528
         // Success page.
529
-        $our_pages[] = wpinv_get_option( 'success_page', false );
529
+        $our_pages[] = wpinv_get_option('success_page', false);
530 530
 
531 531
         // Failure page.
532
-        $our_pages[] = wpinv_get_option( 'failure_page', false );
532
+        $our_pages[] = wpinv_get_option('failure_page', false);
533 533
 
534 534
         // History page.
535
-        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
535
+        $our_pages[] = wpinv_get_option('invoice_history_page', false);
536 536
 
537 537
         // Subscriptions page.
538
-        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
538
+        $our_pages[] = wpinv_get_option('invoice_subscription_page', false);
539 539
 
540
-        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
540
+        $our_pages   = array_map('intval', array_filter($our_pages));
541 541
 
542 542
         $excluded_posts_ids = $excluded_posts_ids + $our_pages;
543
-        return array_unique( $excluded_posts_ids );
543
+        return array_unique($excluded_posts_ids);
544 544
 
545 545
     }
546 546
 }
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 1 patch
Spacing   +743 added lines, -743 removed lines patch added patch discarded remove patch
@@ -7,91 +7,91 @@  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', wpinv_get_theme_template_dir_name() );
22
+    return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name());
23 23
 }
24 24
 
25
-function wpinv_display_invoice_top_bar( $invoice ) {
26
-    if ( empty( $invoice ) ) {
25
+function wpinv_display_invoice_top_bar($invoice) {
26
+    if (empty($invoice)) {
27 27
         return;
28 28
     }
29 29
     ?>
30 30
     <div class="row wpinv-top-bar no-print">
31 31
         <div class="container">
32 32
             <div class="col-xs-6">
33
-                <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?>
33
+                <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?>
34 34
             </div>
35 35
             <div class="col-xs-6 text-right">
36
-                <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?>
36
+                <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?>
37 37
             </div>
38 38
         </div>
39 39
     </div>
40 40
     <?php
41 41
 }
42 42
 
43
-function wpinv_invoice_display_left_actions( $invoice ) {
44
-    if ( empty( $invoice ) ) {
43
+function wpinv_invoice_display_left_actions($invoice) {
44
+    if (empty($invoice)) {
45 45
         return; // Exit if invoice is not set.
46 46
     }
47 47
     
48
-    if ( $invoice->post_type == 'wpi_invoice' ) {
49
-        if ( $invoice->needs_payment() ) {
50
-            ?> <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><?php
48
+    if ($invoice->post_type == 'wpi_invoice') {
49
+        if ($invoice->needs_payment()) {
50
+            ?> <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><?php
51 51
         }
52 52
     }
53 53
     do_action('wpinv_invoice_display_left_actions', $invoice);
54 54
 }
55 55
 
56
-function wpinv_invoice_display_right_actions( $invoice ) {
57
-    if ( empty( $invoice ) ) {
56
+function wpinv_invoice_display_right_actions($invoice) {
57
+    if (empty($invoice)) {
58 58
         return; // Exit if invoice is not set.
59 59
     }
60 60
 
61
-    if ( $invoice->post_type == 'wpi_invoice' ) { ?>
62
-        <a class="btn btn-primary btn-sm btn-print-invoice" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a>
63
-        <?php if ( is_user_logged_in() ) { ?>
64
-        &nbsp;&nbsp;<a class="btn btn-warning btn-sm btn-invoice-history" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a>
61
+    if ($invoice->post_type == 'wpi_invoice') { ?>
62
+        <a class="btn btn-primary btn-sm btn-print-invoice" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a>
63
+        <?php if (is_user_logged_in()) { ?>
64
+        &nbsp;&nbsp;<a class="btn btn-warning btn-sm btn-invoice-history" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a>
65 65
         <?php }
66 66
     }
67 67
     do_action('wpinv_invoice_display_right_actions', $invoice);
68 68
 }
69 69
 
70
-function wpinv_before_invoice_content( $content ) {
70
+function wpinv_before_invoice_content($content) {
71 71
     global $post;
72 72
 
73
-    if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
73
+    if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
74 74
         ob_start();
75
-        do_action( 'wpinv_before_invoice_content', $post->ID );
75
+        do_action('wpinv_before_invoice_content', $post->ID);
76 76
         $content = ob_get_clean() . $content;
77 77
     }
78 78
 
79 79
     return $content;
80 80
 }
81
-add_filter( 'the_content', 'wpinv_before_invoice_content' );
81
+add_filter('the_content', 'wpinv_before_invoice_content');
82 82
 
83
-function wpinv_after_invoice_content( $content ) {
83
+function wpinv_after_invoice_content($content) {
84 84
     global $post;
85 85
 
86
-    if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
86
+    if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
87 87
         ob_start();
88
-        do_action( 'wpinv_after_invoice_content', $post->ID );
88
+        do_action('wpinv_after_invoice_content', $post->ID);
89 89
         $content .= ob_get_clean();
90 90
     }
91 91
 
92 92
     return $content;
93 93
 }
94
-add_filter( 'the_content', 'wpinv_after_invoice_content' );
94
+add_filter('the_content', 'wpinv_after_invoice_content');
95 95
 
96 96
 function wpinv_get_templates_dir() {
97 97
     return WPINV_PLUGIN_DIR . 'templates';
@@ -101,105 +101,105 @@  discard block
 block discarded – undo
101 101
     return WPINV_PLUGIN_URL . 'templates';
102 102
 }
103 103
 
104
-function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
105
-    if ( ! empty( $args ) && is_array( $args ) ) {
106
-		extract( $args );
104
+function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
105
+    if (!empty($args) && is_array($args)) {
106
+		extract($args);
107 107
 	}
108 108
 
109
-	$located = wpinv_locate_template( $template_name, $template_path, $default_path );
109
+	$located = wpinv_locate_template($template_name, $template_path, $default_path);
110 110
 	// Allow 3rd party plugin filter template file from their plugin.
111
-	$located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path );
111
+	$located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path);
112 112
 
113
-	if ( ! file_exists( $located ) ) {
114
-        _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
113
+	if (!file_exists($located)) {
114
+        _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1');
115 115
 		return;
116 116
 	}
117 117
 
118
-	do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args );
118
+	do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args);
119 119
 
120
-	include( $located );
120
+	include($located);
121 121
 
122
-	do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args );
122
+	do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args);
123 123
 }
124 124
 
125
-function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
125
+function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') {
126 126
 	ob_start();
127
-	wpinv_get_template( $template_name, $args, $template_path, $default_path );
127
+	wpinv_get_template($template_name, $args, $template_path, $default_path);
128 128
 	return ob_get_clean();
129 129
 }
130 130
 
131
-function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
132
-    if ( ! $template_path ) {
131
+function wpinv_locate_template($template_name, $template_path = '', $default_path = '') {
132
+    if (!$template_path) {
133 133
         $template_path = wpinv_template_path();
134 134
     }
135 135
 
136
-    if ( ! $default_path ) {
136
+    if (!$default_path) {
137 137
         $default_path = WPINV_PLUGIN_DIR . 'templates/';
138 138
     }
139 139
 
140 140
     // Look within passed path within the theme - this is priority.
141 141
     $template = locate_template(
142 142
         array(
143
-            trailingslashit( $template_path ) . $template_name,
143
+            trailingslashit($template_path) . $template_name,
144 144
             $template_name
145 145
         )
146 146
     );
147 147
 
148 148
     // Get default templates/
149
-    if ( !$template && $default_path ) {
150
-        $template = trailingslashit( $default_path ) . $template_name;
149
+    if (!$template && $default_path) {
150
+        $template = trailingslashit($default_path) . $template_name;
151 151
     }
152 152
 
153 153
     // Return what we found.
154
-    return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path );
154
+    return apply_filters('wpinv_locate_template', $template, $template_name, $template_path);
155 155
 }
156 156
 
157
-function wpinv_get_template_part( $slug, $name = null, $load = true ) {
158
-	do_action( 'get_template_part_' . $slug, $slug, $name );
157
+function wpinv_get_template_part($slug, $name = null, $load = true) {
158
+	do_action('get_template_part_' . $slug, $slug, $name);
159 159
 
160 160
 	// Setup possible parts
161 161
 	$templates = array();
162
-	if ( isset( $name ) )
162
+	if (isset($name))
163 163
 		$templates[] = $slug . '-' . $name . '.php';
164 164
 	$templates[] = $slug . '.php';
165 165
 
166 166
 	// Allow template parts to be filtered
167
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
167
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
168 168
 
169 169
 	// Return the part that is found
170
-	return wpinv_locate_tmpl( $templates, $load, false );
170
+	return wpinv_locate_tmpl($templates, $load, false);
171 171
 }
172 172
 
173
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
173
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
174 174
 	// No file found yet
175 175
 	$located = false;
176 176
 
177 177
 	// Try to find a template file
178
-	foreach ( (array)$template_names as $template_name ) {
178
+	foreach ((array) $template_names as $template_name) {
179 179
 
180 180
 		// Continue if template is empty
181
-		if ( empty( $template_name ) )
181
+		if (empty($template_name))
182 182
 			continue;
183 183
 
184 184
 		// Trim off any slashes from the template name
185
-		$template_name = ltrim( $template_name, '/' );
185
+		$template_name = ltrim($template_name, '/');
186 186
 
187 187
 		// try locating this template file by looping through the template paths
188
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
188
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
189 189
 
190
-			if( file_exists( $template_path . $template_name ) ) {
190
+			if (file_exists($template_path . $template_name)) {
191 191
 				$located = $template_path . $template_name;
192 192
 				break;
193 193
 			}
194 194
 		}
195 195
 
196
-		if( !empty( $located ) ) {
196
+		if (!empty($located)) {
197 197
 			break;
198 198
 		}
199 199
 	}
200 200
 
201
-	if ( ( true == $load ) && ! empty( $located ) )
202
-		load_template( $located, $require_once );
201
+	if ((true == $load) && !empty($located))
202
+		load_template($located, $require_once);
203 203
 
204 204
 	return $located;
205 205
 }
@@ -208,159 +208,159 @@  discard block
 block discarded – undo
208 208
 	$template_dir = wpinv_get_theme_template_dir_name();
209 209
 
210 210
 	$file_paths = array(
211
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
212
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
211
+		1 => trailingslashit(get_stylesheet_directory()) . $template_dir,
212
+		10 => trailingslashit(get_template_directory()) . $template_dir,
213 213
 		100 => wpinv_get_templates_dir()
214 214
 	);
215 215
 
216
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
216
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
217 217
 
218 218
 	// sort the file paths based on priority
219
-	ksort( $file_paths, SORT_NUMERIC );
219
+	ksort($file_paths, SORT_NUMERIC);
220 220
 
221
-	return array_map( 'trailingslashit', $file_paths );
221
+	return array_map('trailingslashit', $file_paths);
222 222
 }
223 223
 
224 224
 function wpinv_get_theme_template_dir_name() {
225
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
225
+	return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing'));
226 226
 }
227 227
 
228 228
 function wpinv_checkout_meta_tags() {
229 229
 
230 230
 	$pages   = array();
231
-	$pages[] = wpinv_get_option( 'success_page' );
232
-	$pages[] = wpinv_get_option( 'failure_page' );
233
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
234
-	$pages[] = wpinv_get_option( 'invoice_subscription_page' );
231
+	$pages[] = wpinv_get_option('success_page');
232
+	$pages[] = wpinv_get_option('failure_page');
233
+	$pages[] = wpinv_get_option('invoice_history_page');
234
+	$pages[] = wpinv_get_option('invoice_subscription_page');
235 235
 
236
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
236
+	if (!wpinv_is_checkout() && !is_page($pages)) {
237 237
 		return;
238 238
 	}
239 239
 
240 240
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
241 241
 }
242
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
242
+add_action('wp_head', 'wpinv_checkout_meta_tags');
243 243
 
244
-function wpinv_add_body_classes( $class ) {
245
-	$classes = (array)$class;
244
+function wpinv_add_body_classes($class) {
245
+	$classes = (array) $class;
246 246
 
247
-	if( wpinv_is_checkout() ) {
247
+	if (wpinv_is_checkout()) {
248 248
 		$classes[] = 'wpinv-checkout';
249 249
 		$classes[] = 'wpinv-page';
250 250
 	}
251 251
 
252
-	if( wpinv_is_success_page() ) {
252
+	if (wpinv_is_success_page()) {
253 253
 		$classes[] = 'wpinv-success';
254 254
 		$classes[] = 'wpinv-page';
255 255
 	}
256 256
 
257
-	if( wpinv_is_failed_transaction_page() ) {
257
+	if (wpinv_is_failed_transaction_page()) {
258 258
 		$classes[] = 'wpinv-failed-transaction';
259 259
 		$classes[] = 'wpinv-page';
260 260
 	}
261 261
 
262
-	if( wpinv_is_invoice_history_page() ) {
262
+	if (wpinv_is_invoice_history_page()) {
263 263
 		$classes[] = 'wpinv-history';
264 264
 		$classes[] = 'wpinv-page';
265 265
 	}
266 266
 
267
-	if( wpinv_is_subscriptions_history_page() ) {
267
+	if (wpinv_is_subscriptions_history_page()) {
268 268
 		$classes[] = 'wpinv-subscription';
269 269
 		$classes[] = 'wpinv-page';
270 270
 	}
271 271
 
272
-	if( wpinv_is_test_mode() ) {
272
+	if (wpinv_is_test_mode()) {
273 273
 		$classes[] = 'wpinv-test-mode';
274 274
 		$classes[] = 'wpinv-page';
275 275
 	}
276 276
 
277
-	return array_unique( $classes );
277
+	return array_unique($classes);
278 278
 }
279
-add_filter( 'body_class', 'wpinv_add_body_classes' );
279
+add_filter('body_class', 'wpinv_add_body_classes');
280 280
 
281
-function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) {
282
-    $args = array( 'nopaging' => true );
281
+function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') {
282
+    $args = array('nopaging' => true);
283 283
 
284
-    if ( ! empty( $status ) )
284
+    if (!empty($status))
285 285
         $args['post_status'] = $status;
286 286
 
287
-    $discounts = wpinv_get_discounts( $args );
287
+    $discounts = wpinv_get_discounts($args);
288 288
     $options   = array();
289 289
 
290
-    if ( $discounts ) {
291
-        foreach ( $discounts as $discount ) {
292
-            $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) );
290
+    if ($discounts) {
291
+        foreach ($discounts as $discount) {
292
+            $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID));
293 293
         }
294 294
     } else {
295
-        $options[0] = __( 'No discounts found', 'invoicing' );
295
+        $options[0] = __('No discounts found', 'invoicing');
296 296
     }
297 297
 
298
-    $output = wpinv_html_select( array(
298
+    $output = wpinv_html_select(array(
299 299
         'name'             => $name,
300 300
         'selected'         => $selected,
301 301
         'options'          => $options,
302 302
         'show_option_all'  => false,
303 303
         'show_option_none' => false,
304
-    ) );
304
+    ));
305 305
 
306 306
     return $output;
307 307
 }
308 308
 
309
-function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
310
-    $current     = date( 'Y' );
311
-    $start_year  = $current - absint( $years_before );
312
-    $end_year    = $current + absint( $years_after );
313
-    $selected    = empty( $selected ) ? date( 'Y' ) : $selected;
309
+function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
310
+    $current     = date('Y');
311
+    $start_year  = $current - absint($years_before);
312
+    $end_year    = $current + absint($years_after);
313
+    $selected    = empty($selected) ? date('Y') : $selected;
314 314
     $options     = array();
315 315
 
316
-    while ( $start_year <= $end_year ) {
317
-        $options[ absint( $start_year ) ] = $start_year;
316
+    while ($start_year <= $end_year) {
317
+        $options[absint($start_year)] = $start_year;
318 318
         $start_year++;
319 319
     }
320 320
 
321
-    $output = wpinv_html_select( array(
321
+    $output = wpinv_html_select(array(
322 322
         'name'             => $name,
323 323
         'selected'         => $selected,
324 324
         'options'          => $options,
325 325
         'show_option_all'  => false,
326 326
         'show_option_none' => false
327
-    ) );
327
+    ));
328 328
 
329 329
     return $output;
330 330
 }
331 331
 
332
-function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) {
332
+function wpinv_html_month_dropdown($name = 'month', $selected = 0) {
333 333
 
334 334
     $options = array(
335
-        '1'  => __( 'January', 'invoicing' ),
336
-        '2'  => __( 'February', 'invoicing' ),
337
-        '3'  => __( 'March', 'invoicing' ),
338
-        '4'  => __( 'April', 'invoicing' ),
339
-        '5'  => __( 'May', 'invoicing' ),
340
-        '6'  => __( 'June', 'invoicing' ),
341
-        '7'  => __( 'July', 'invoicing' ),
342
-        '8'  => __( 'August', 'invoicing' ),
343
-        '9'  => __( 'September', 'invoicing' ),
344
-        '10' => __( 'October', 'invoicing' ),
345
-        '11' => __( 'November', 'invoicing' ),
346
-        '12' => __( 'December', 'invoicing' ),
335
+        '1'  => __('January', 'invoicing'),
336
+        '2'  => __('February', 'invoicing'),
337
+        '3'  => __('March', 'invoicing'),
338
+        '4'  => __('April', 'invoicing'),
339
+        '5'  => __('May', 'invoicing'),
340
+        '6'  => __('June', 'invoicing'),
341
+        '7'  => __('July', 'invoicing'),
342
+        '8'  => __('August', 'invoicing'),
343
+        '9'  => __('September', 'invoicing'),
344
+        '10' => __('October', 'invoicing'),
345
+        '11' => __('November', 'invoicing'),
346
+        '12' => __('December', 'invoicing'),
347 347
     );
348 348
 
349 349
     // If no month is selected, default to the current month
350
-    $selected = empty( $selected ) ? date( 'n' ) : $selected;
350
+    $selected = empty($selected) ? date('n') : $selected;
351 351
 
352
-    $output = wpinv_html_select( array(
352
+    $output = wpinv_html_select(array(
353 353
         'name'             => $name,
354 354
         'selected'         => $selected,
355 355
         'options'          => $options,
356 356
         'show_option_all'  => false,
357 357
         'show_option_none' => false
358
-    ) );
358
+    ));
359 359
 
360 360
     return $output;
361 361
 }
362 362
 
363
-function wpinv_html_select( $args = array() ) {
363
+function wpinv_html_select($args = array()) {
364 364
     $defaults = array(
365 365
         'options'          => array(),
366 366
         'name'             => null,
@@ -369,8 +369,8 @@  discard block
 block discarded – undo
369 369
         'selected'         => 0,
370 370
         'placeholder'      => null,
371 371
         'multiple'         => false,
372
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
373
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
372
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
373
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
374 374
         'data'             => array(),
375 375
         'onchange'         => null,
376 376
         'required'         => false,
@@ -378,74 +378,74 @@  discard block
 block discarded – undo
378 378
         'readonly'         => false,
379 379
     );
380 380
 
381
-    $args = wp_parse_args( $args, $defaults );
381
+    $args = wp_parse_args($args, $defaults);
382 382
 
383 383
     $data_elements = '';
384
-    foreach ( $args['data'] as $key => $value ) {
385
-        $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
384
+    foreach ($args['data'] as $key => $value) {
385
+        $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
386 386
     }
387 387
 
388
-    if( $args['multiple'] ) {
388
+    if ($args['multiple']) {
389 389
         $multiple = ' MULTIPLE';
390 390
     } else {
391 391
         $multiple = '';
392 392
     }
393 393
 
394
-    if( $args['placeholder'] ) {
394
+    if ($args['placeholder']) {
395 395
         $placeholder = $args['placeholder'];
396 396
     } else {
397 397
         $placeholder = '';
398 398
     }
399 399
     
400 400
     $options = '';
401
-    if( !empty( $args['onchange'] ) ) {
402
-        $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"';
401
+    if (!empty($args['onchange'])) {
402
+        $options .= ' onchange="' . esc_attr($args['onchange']) . '"';
403 403
     }
404 404
     
405
-    if( !empty( $args['required'] ) ) {
405
+    if (!empty($args['required'])) {
406 406
         $options .= ' required="required"';
407 407
     }
408 408
     
409
-    if( !empty( $args['disabled'] ) ) {
409
+    if (!empty($args['disabled'])) {
410 410
         $options .= ' disabled';
411 411
     }
412 412
     
413
-    if( !empty( $args['readonly'] ) ) {
413
+    if (!empty($args['readonly'])) {
414 414
         $options .= ' readonly';
415 415
     }
416 416
 
417
-    $class  = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
418
-    $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>';
417
+    $class  = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
418
+    $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>';
419 419
 
420
-    if ( $args['show_option_all'] ) {
421
-        if( $args['multiple'] ) {
422
-            $selected = selected( true, in_array( 0, $args['selected'] ), false );
420
+    if ($args['show_option_all']) {
421
+        if ($args['multiple']) {
422
+            $selected = selected(true, in_array(0, $args['selected']), false);
423 423
         } else {
424
-            $selected = selected( $args['selected'], 0, false );
424
+            $selected = selected($args['selected'], 0, false);
425 425
         }
426
-        $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
426
+        $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>';
427 427
     }
428 428
 
429
-    if ( !empty( $args['options'] ) ) {
429
+    if (!empty($args['options'])) {
430 430
 
431
-        if ( $args['show_option_none'] ) {
432
-            if( $args['multiple'] ) {
433
-                $selected = selected( true, in_array( "", $args['selected'] ), false );
431
+        if ($args['show_option_none']) {
432
+            if ($args['multiple']) {
433
+                $selected = selected(true, in_array("", $args['selected']), false);
434 434
             } else {
435
-                $selected = selected( $args['selected'] === "", true, false );
435
+                $selected = selected($args['selected'] === "", true, false);
436 436
             }
437
-            $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
437
+            $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>';
438 438
         }
439 439
 
440
-        foreach( $args['options'] as $key => $option ) {
440
+        foreach ($args['options'] as $key => $option) {
441 441
 
442
-            if( $args['multiple'] && is_array( $args['selected'] ) ) {
443
-                $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false );
442
+            if ($args['multiple'] && is_array($args['selected'])) {
443
+                $selected = selected(true, (bool) in_array($key, $args['selected']), false);
444 444
             } else {
445
-                $selected = selected( $args['selected'], $key, false );
445
+                $selected = selected($args['selected'], $key, false);
446 446
             }
447 447
 
448
-            $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
448
+            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>';
449 449
         }
450 450
     }
451 451
 
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
     return $output;
455 455
 }
456 456
 
457
-function wpinv_item_dropdown( $args = array() ) {
457
+function wpinv_item_dropdown($args = array()) {
458 458
     $defaults = array(
459 459
         'name'              => 'wpi_item',
460 460
         'id'                => 'wpi_item',
@@ -462,14 +462,14 @@  discard block
 block discarded – undo
462 462
         'multiple'          => false,
463 463
         'selected'          => 0,
464 464
         'number'            => 100,
465
-        'placeholder'       => __( 'Choose a item', 'invoicing' ),
466
-        'data'              => array( 'search-type' => 'item' ),
465
+        'placeholder'       => __('Choose a item', 'invoicing'),
466
+        'data'              => array('search-type' => 'item'),
467 467
         'show_option_all'   => false,
468 468
         'show_option_none'  => false,
469 469
         'show_recurring'    => false,
470 470
     );
471 471
 
472
-    $args = wp_parse_args( $args, $defaults );
472
+    $args = wp_parse_args($args, $defaults);
473 473
 
474 474
     $item_args = array(
475 475
         'post_type'      => 'wpi_item',
@@ -478,44 +478,44 @@  discard block
 block discarded – undo
478 478
         'posts_per_page' => $args['number']
479 479
     );
480 480
     
481
-    $item_args  = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults );
481
+    $item_args  = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults);
482 482
 
483
-    $items      = get_posts( $item_args );
483
+    $items      = get_posts($item_args);
484 484
     $options    = array();
485
-    if ( $items ) {
486
-        foreach ( $items as $item ) {
487
-            $title = esc_html( $item->post_title );
485
+    if ($items) {
486
+        foreach ($items as $item) {
487
+            $title = esc_html($item->post_title);
488 488
             
489
-            if ( !empty( $args['show_recurring'] ) ) {
490
-                $title .= wpinv_get_item_suffix( $item->ID, false );
489
+            if (!empty($args['show_recurring'])) {
490
+                $title .= wpinv_get_item_suffix($item->ID, false);
491 491
             }
492 492
             
493
-            $options[ absint( $item->ID ) ] = $title;
493
+            $options[absint($item->ID)] = $title;
494 494
         }
495 495
     }
496 496
 
497 497
     // This ensures that any selected items are included in the drop down
498
-    if( is_array( $args['selected'] ) ) {
499
-        foreach( $args['selected'] as $item ) {
500
-            if( ! in_array( $item, $options ) ) {
501
-                $title = get_the_title( $item );
502
-                if ( !empty( $args['show_recurring'] ) ) {
503
-                    $title .= wpinv_get_item_suffix( $item, false );
498
+    if (is_array($args['selected'])) {
499
+        foreach ($args['selected'] as $item) {
500
+            if (!in_array($item, $options)) {
501
+                $title = get_the_title($item);
502
+                if (!empty($args['show_recurring'])) {
503
+                    $title .= wpinv_get_item_suffix($item, false);
504 504
                 }
505 505
                 $options[$item] = $title;
506 506
             }
507 507
         }
508
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
509
-        if ( ! in_array( $args['selected'], $options ) ) {
510
-            $title = get_the_title( $args['selected'] );
511
-            if ( !empty( $args['show_recurring'] ) ) {
512
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
508
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
509
+        if (!in_array($args['selected'], $options)) {
510
+            $title = get_the_title($args['selected']);
511
+            if (!empty($args['show_recurring'])) {
512
+                $title .= wpinv_get_item_suffix($args['selected'], false);
513 513
             }
514
-            $options[$args['selected']] = get_the_title( $args['selected'] );
514
+            $options[$args['selected']] = get_the_title($args['selected']);
515 515
         }
516 516
     }
517 517
 
518
-    $output = wpinv_html_select( array(
518
+    $output = wpinv_html_select(array(
519 519
         'name'             => $args['name'],
520 520
         'selected'         => $args['selected'],
521 521
         'id'               => $args['id'],
@@ -526,12 +526,12 @@  discard block
 block discarded – undo
526 526
         'show_option_all'  => $args['show_option_all'],
527 527
         'show_option_none' => $args['show_option_none'],
528 528
         'data'             => $args['data'],
529
-    ) );
529
+    ));
530 530
 
531 531
     return $output;
532 532
 }
533 533
 
534
-function wpinv_html_checkbox( $args = array() ) {
534
+function wpinv_html_checkbox($args = array()) {
535 535
     $defaults = array(
536 536
         'name'     => null,
537 537
         'current'  => null,
@@ -542,38 +542,38 @@  discard block
 block discarded – undo
542 542
         )
543 543
     );
544 544
 
545
-    $args = wp_parse_args( $args, $defaults );
545
+    $args = wp_parse_args($args, $defaults);
546 546
 
547
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
547
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
548 548
     $options = '';
549
-    if ( ! empty( $args['options']['disabled'] ) ) {
549
+    if (!empty($args['options']['disabled'])) {
550 550
         $options .= ' disabled="disabled"';
551
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
551
+    } elseif (!empty($args['options']['readonly'])) {
552 552
         $options .= ' readonly';
553 553
     }
554 554
 
555
-    $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 ) . ' />';
555
+    $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) . ' />';
556 556
 
557 557
     return $output;
558 558
 }
559 559
 
560
-function wpinv_html_text( $args = array() ) {
560
+function wpinv_html_text($args = array()) {
561 561
     // Backwards compatibility
562
-    if ( func_num_args() > 1 ) {
562
+    if (func_num_args() > 1) {
563 563
         $args = func_get_args();
564 564
 
565 565
         $name  = $args[0];
566
-        $value = isset( $args[1] ) ? $args[1] : '';
567
-        $label = isset( $args[2] ) ? $args[2] : '';
568
-        $desc  = isset( $args[3] ) ? $args[3] : '';
566
+        $value = isset($args[1]) ? $args[1] : '';
567
+        $label = isset($args[2]) ? $args[2] : '';
568
+        $desc  = isset($args[3]) ? $args[3] : '';
569 569
     }
570 570
 
571 571
     $defaults = array(
572 572
         'id'           => '',
573
-        'name'         => isset( $name )  ? $name  : 'text',
574
-        'value'        => isset( $value ) ? $value : null,
575
-        'label'        => isset( $label ) ? $label : null,
576
-        'desc'         => isset( $desc )  ? $desc  : null,
573
+        'name'         => isset($name) ? $name : 'text',
574
+        'value'        => isset($value) ? $value : null,
575
+        'label'        => isset($label) ? $label : null,
576
+        'desc'         => isset($desc) ? $desc : null,
577 577
         'placeholder'  => '',
578 578
         'class'        => 'regular-text',
579 579
         'disabled'     => false,
@@ -583,51 +583,51 @@  discard block
 block discarded – undo
583 583
         'data'         => false
584 584
     );
585 585
 
586
-    $args = wp_parse_args( $args, $defaults );
586
+    $args = wp_parse_args($args, $defaults);
587 587
 
588
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
588
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
589 589
     $options = '';
590
-    if( $args['required'] ) {
590
+    if ($args['required']) {
591 591
         $options .= ' required="required"';
592 592
     }
593
-    if( $args['readonly'] ) {
593
+    if ($args['readonly']) {
594 594
         $options .= ' readonly';
595 595
     }
596
-    if( $args['readonly'] ) {
596
+    if ($args['readonly']) {
597 597
         $options .= ' readonly';
598 598
     }
599 599
 
600 600
     $data = '';
601
-    if ( !empty( $args['data'] ) ) {
602
-        foreach ( $args['data'] as $key => $value ) {
603
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
601
+    if (!empty($args['data'])) {
602
+        foreach ($args['data'] as $key => $value) {
603
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
604 604
         }
605 605
     }
606 606
 
607
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
608
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
609
-    if ( ! empty( $args['desc'] ) ) {
610
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
607
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
608
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
609
+    if (!empty($args['desc'])) {
610
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
611 611
     }
612 612
 
613
-    $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 ) . '/>';
613
+    $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) . '/>';
614 614
 
615 615
     $output .= '</span>';
616 616
 
617 617
     return $output;
618 618
 }
619 619
 
620
-function wpinv_html_date_field( $args = array() ) {
621
-    if( empty( $args['class'] ) ) {
620
+function wpinv_html_date_field($args = array()) {
621
+    if (empty($args['class'])) {
622 622
         $args['class'] = 'wpiDatepicker';
623
-    } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) {
623
+    } elseif (!strpos($args['class'], 'wpiDatepicker')) {
624 624
         $args['class'] .= ' wpiDatepicker';
625 625
     }
626 626
 
627
-    return wpinv_html_text( $args );
627
+    return wpinv_html_text($args);
628 628
 }
629 629
 
630
-function wpinv_html_textarea( $args = array() ) {
630
+function wpinv_html_textarea($args = array()) {
631 631
     $defaults = array(
632 632
         'name'        => 'textarea',
633 633
         'value'       => null,
@@ -638,31 +638,31 @@  discard block
 block discarded – undo
638 638
         'placeholder' => '',
639 639
     );
640 640
 
641
-    $args = wp_parse_args( $args, $defaults );
641
+    $args = wp_parse_args($args, $defaults);
642 642
 
643
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
643
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
644 644
     $disabled = '';
645
-    if( $args['disabled'] ) {
645
+    if ($args['disabled']) {
646 646
         $disabled = ' disabled="disabled"';
647 647
     }
648 648
 
649
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
650
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
651
-    $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
649
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
650
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
651
+    $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>';
652 652
 
653
-    if ( ! empty( $args['desc'] ) ) {
654
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
653
+    if (!empty($args['desc'])) {
654
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
655 655
     }
656 656
     $output .= '</span>';
657 657
 
658 658
     return $output;
659 659
 }
660 660
 
661
-function wpinv_html_ajax_user_search( $args = array() ) {
661
+function wpinv_html_ajax_user_search($args = array()) {
662 662
     $defaults = array(
663 663
         'name'        => 'user_id',
664 664
         'value'       => null,
665
-        'placeholder' => __( 'Enter username', 'invoicing' ),
665
+        'placeholder' => __('Enter username', 'invoicing'),
666 666
         'label'       => null,
667 667
         'desc'        => null,
668 668
         'class'       => '',
@@ -671,13 +671,13 @@  discard block
 block discarded – undo
671 671
         'data'        => false
672 672
     );
673 673
 
674
-    $args = wp_parse_args( $args, $defaults );
674
+    $args = wp_parse_args($args, $defaults);
675 675
 
676 676
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
677 677
 
678 678
     $output  = '<span class="wpinv_user_search_wrap">';
679
-        $output .= wpinv_html_text( $args );
680
-        $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>';
679
+        $output .= wpinv_html_text($args);
680
+        $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>';
681 681
     $output .= '</span>';
682 682
 
683 683
     return $output;
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
 function wpinv_ip_geolocation() {
687 687
     global $wpinv_euvat;
688 688
     
689
-    $ip         = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : '';    
689
+    $ip         = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : '';    
690 690
     $content    = '';
691 691
     $iso        = '';
692 692
     $country    = '';
@@ -697,69 +697,69 @@  discard block
 block discarded – undo
697 697
     $credit     = '';
698 698
     $address    = '';
699 699
     
700
-    if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) {
700
+    if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) {
701 701
         try {
702 702
             $iso        = $geoip2_city->country->isoCode;
703 703
             $country    = $geoip2_city->country->name;
704
-            $region     = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : '';
704
+            $region     = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : '';
705 705
             $city       = $geoip2_city->city->name;
706 706
             $longitude  = $geoip2_city->location->longitude;
707 707
             $latitude   = $geoip2_city->location->latitude;
708
-            $credit     = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' );
709
-        } catch( Exception $e ) { }
708
+            $credit     = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing');
709
+        } catch (Exception $e) { }
710 710
     }
711 711
     
712
-    if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) {
712
+    if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) {
713 713
         try {
714
-            $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
714
+            $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
715 715
             
716
-            if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) {
716
+            if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) {
717 717
                 $iso        = $load_xml->geoplugin_countryCode;
718 718
                 $country    = $load_xml->geoplugin_countryName;
719
-                $region     = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : '';
720
-                $city       = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : '';
719
+                $region     = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : '';
720
+                $city       = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : '';
721 721
                 $longitude  = $load_xml->geoplugin_longitude;
722 722
                 $latitude   = $load_xml->geoplugin_latitude;
723 723
                 $credit     = $load_xml->geoplugin_credit;
724
-                $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;
724
+                $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;
725 725
             }
726
-        } catch( Exception $e ) { }
726
+        } catch (Exception $e) { }
727 727
     }
728 728
     
729
-    if ( $iso && $longitude && $latitude ) {
730
-        if ( $city ) {
729
+    if ($iso && $longitude && $latitude) {
730
+        if ($city) {
731 731
             $address .= $city . ', ';
732 732
         }
733 733
         
734
-        if ( $region ) {
734
+        if ($region) {
735 735
             $address .= $region . ', ';
736 736
         }
737 737
         
738 738
         $address .= $country . ' (' . $iso . ')';
739
-        $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>';
740
-        $content .= '<p>'. $credit . '</p>';
739
+        $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>';
740
+        $content .= '<p>' . $credit . '</p>';
741 741
     } else {
742
-        $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>';
742
+        $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>';
743 743
     }
744 744
     ?>
745 745
 <!DOCTYPE html>
746
-<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>
746
+<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>
747 747
 <body>
748
-    <?php if ( $latitude && $latitude ) { ?>
748
+    <?php if ($latitude && $latitude) { ?>
749 749
     <div id="map"></div>
750 750
         <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script>
751 751
         <script type="text/javascript">
752 752
         var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
753 753
             osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
754 754
             osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}),
755
-            latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>);
755
+            latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>);
756 756
 
757 757
         var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]});
758 758
 
759 759
         var marker = new L.Marker(latlng);
760 760
         map.addLayer(marker);
761 761
 
762
-        marker.bindPopup("<p><?php esc_attr_e( $address );?></p>");
762
+        marker.bindPopup("<p><?php esc_attr_e($address); ?></p>");
763 763
     </script>
764 764
     <?php } ?>
765 765
     <div style="height:100px"><?php echo $content; ?></div>
@@ -767,18 +767,18 @@  discard block
 block discarded – undo
767 767
 <?php
768 768
     exit;
769 769
 }
770
-add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
771
-add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
770
+add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
771
+add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
772 772
 
773 773
 // Set up the template for the invoice.
774
-function wpinv_template( $template ) {
774
+function wpinv_template($template) {
775 775
     global $post, $wp_query;
776 776
     
777
-    if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) {
778
-        if ( wpinv_user_can_view_invoice( $post->ID ) ) {
779
-            $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false );
777
+    if ((is_single() || is_404()) && !empty($post->ID) && (get_post_type($post->ID) == 'wpi_invoice' or get_post_type($post->ID) == 'wpi_quote')) {
778
+        if (wpinv_user_can_view_invoice($post->ID)) {
779
+            $template = wpinv_get_template_part('wpinv-invoice-print', false, false);
780 780
         } else {
781
-            $template = wpinv_get_template_part( 'wpinv-invalid-access', false, false );
781
+            $template = wpinv_get_template_part('wpinv-invalid-access', false, false);
782 782
         }
783 783
     }
784 784
 
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
 
788 788
 function wpinv_get_business_address() {
789 789
     $business_address   = wpinv_store_address();
790
-    $business_address   = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
790
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
791 791
     
792 792
     /*
793 793
     $default_country    = wpinv_get_default_country();
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
     
812 812
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
813 813
     
814
-    return apply_filters( 'wpinv_get_business_address', $business_address );
814
+    return apply_filters('wpinv_get_business_address', $business_address);
815 815
 }
816 816
 
817 817
 function wpinv_display_from_address() {
@@ -821,107 +821,107 @@  discard block
 block discarded – undo
821 821
     if (empty($from_name)) {
822 822
         $from_name = wpinv_get_business_name();
823 823
     }
824
-    ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div>
824
+    ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div>
825 825
     <div class="wrapper col-xs-10">
826
-        <div class="name"><?php echo esc_html( $from_name ); ?></div>
827
-        <?php if ( $address = wpinv_get_business_address() ) { ?>
828
-        <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div>
826
+        <div class="name"><?php echo esc_html($from_name); ?></div>
827
+        <?php if ($address = wpinv_get_business_address()) { ?>
828
+        <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div>
829 829
         <?php } ?>
830
-        <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?>
831
-        <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s', 'invoicing' ), $email_from );?></div>
830
+        <?php if ($email_from = wpinv_mail_get_from_address()) { ?>
831
+        <div class="email_from"><?php echo wp_sprintf(__('Email: %s', 'invoicing'), $email_from); ?></div>
832 832
         <?php } ?>
833 833
     </div>
834 834
     <?php
835 835
 }
836 836
 
837
-function wpinv_watermark( $id = 0 ) {
838
-    $output = wpinv_get_watermark( $id );
837
+function wpinv_watermark($id = 0) {
838
+    $output = wpinv_get_watermark($id);
839 839
     
840
-    return apply_filters( 'wpinv_get_watermark', $output, $id );
840
+    return apply_filters('wpinv_get_watermark', $output, $id);
841 841
 }
842 842
 
843
-function wpinv_get_watermark( $id ) {
844
-    if ( !$id > 0 ) {
843
+function wpinv_get_watermark($id) {
844
+    if (!$id > 0) {
845 845
         return NULL;
846 846
     }
847
-    $invoice = wpinv_get_invoice( $id );
847
+    $invoice = wpinv_get_invoice($id);
848 848
     
849
-    if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) {
850
-        if ( $invoice->is_paid() ) {
851
-            return __( 'Paid', 'invoicing' );
849
+    if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) {
850
+        if ($invoice->is_paid()) {
851
+            return __('Paid', 'invoicing');
852 852
         }
853
-        if ( $invoice->is_refunded() ) {
854
-            return __( 'Refunded', 'invoicing' );
853
+        if ($invoice->is_refunded()) {
854
+            return __('Refunded', 'invoicing');
855 855
         }
856
-        if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) {
857
-            return __( 'Cancelled', 'invoicing' );
856
+        if ($invoice->has_status(array('wpi-cancelled'))) {
857
+            return __('Cancelled', 'invoicing');
858 858
         }
859 859
     }
860 860
     
861 861
     return NULL;
862 862
 }
863 863
 
864
-function wpinv_display_invoice_details( $invoice ) {
864
+function wpinv_display_invoice_details($invoice) {
865 865
     global $wpinv_euvat;
866 866
     
867 867
     $invoice_id = $invoice->ID;
868 868
     $vat_name   = $wpinv_euvat->get_vat_name();
869 869
     $use_taxes  = wpinv_use_taxes();
870 870
     
871
-    $invoice_status = wpinv_get_invoice_status( $invoice_id );
871
+    $invoice_status = wpinv_get_invoice_status($invoice_id);
872 872
     ?>
873 873
     <table class="table table-bordered table-sm">
874
-        <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?>
874
+        <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?>
875 875
             <tr class="wpi-row-number">
876
-                <th><?php echo apply_filters( 'wpinv_invoice_number_label', __( 'Invoice Number', 'invoicing' ), $invoice ); ?></th>
877
-                <td><?php echo esc_html( $invoice_number ); ?></td>
876
+                <th><?php echo apply_filters('wpinv_invoice_number_label', __('Invoice Number', 'invoicing'), $invoice); ?></th>
877
+                <td><?php echo esc_html($invoice_number); ?></td>
878 878
             </tr>
879 879
         <?php } ?>
880 880
         <tr class="wpi-row-status">
881
-            <th><?php echo apply_filters( 'wpinv_invoice_status_label', __( 'Invoice Status', 'invoicing' ), $invoice ); ?></th>
882
-            <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td>
881
+            <th><?php echo apply_filters('wpinv_invoice_status_label', __('Invoice Status', 'invoicing'), $invoice); ?></th>
882
+            <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td>
883 883
         </tr>
884
-        <?php if ( $invoice->is_renewal() ) { ?>
884
+        <?php if ($invoice->is_renewal()) { ?>
885 885
         <tr class="wpi-row-parent">
886
-            <th><?php echo apply_filters( 'wpinv_invoice_parent_invoice_label', __( 'Parent Invoice', 'invoicing' ), $invoice ); ?></th>
887
-            <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td>
886
+            <th><?php echo apply_filters('wpinv_invoice_parent_invoice_label', __('Parent Invoice', 'invoicing'), $invoice); ?></th>
887
+            <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td>
888 888
         </tr>
889 889
         <?php } ?>
890
-        <?php if ( ( $gateway_name = wpinv_get_payment_gateway_name( $invoice_id ) ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) { ?>
890
+        <?php if (($gateway_name = wpinv_get_payment_gateway_name($invoice_id)) && ($invoice->is_paid() || $invoice->is_refunded())) { ?>
891 891
             <tr class="wpi-row-gateway">
892
-                <th><?php echo apply_filters( 'wpinv_invoice_payment_method_label', __( 'Payment Method', 'invoicing' ), $invoice ); ?></th>
892
+                <th><?php echo apply_filters('wpinv_invoice_payment_method_label', __('Payment Method', 'invoicing'), $invoice); ?></th>
893 893
                 <td><?php echo $gateway_name; ?></td>
894 894
             </tr>
895 895
         <?php } ?>
896
-        <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?>
896
+        <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?>
897 897
             <tr class="wpi-row-date">
898
-                <th><?php echo apply_filters( 'wpinv_invoice_date_label', __( 'Invoice Date', 'invoicing' ), $invoice ); ?></th>
898
+                <th><?php echo apply_filters('wpinv_invoice_date_label', __('Invoice Date', 'invoicing'), $invoice); ?></th>
899 899
                 <td><?php echo $invoice_date; ?></td>
900 900
             </tr>
901 901
         <?php } ?>
902
-        <?php do_action( 'wpinv_display_details_before_due_date', $invoice_id ); ?>
903
-        <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?>
902
+        <?php do_action('wpinv_display_details_before_due_date', $invoice_id); ?>
903
+        <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?>
904 904
             <tr class="wpi-row-date">
905
-                <th><?php echo apply_filters( 'wpinv_invoice_due_date_label', __( 'Due Date', 'invoicing' ), $invoice ); ?></th>
905
+                <th><?php echo apply_filters('wpinv_invoice_due_date_label', __('Due Date', 'invoicing'), $invoice); ?></th>
906 906
                 <td><?php echo $due_date; ?></td>
907 907
             </tr>
908 908
         <?php } ?>
909
-        <?php do_action( 'wpinv_display_details_after_due_date', $invoice_id ); ?>
910
-        <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?>
909
+        <?php do_action('wpinv_display_details_after_due_date', $invoice_id); ?>
910
+        <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?>
911 911
             <tr class="wpi-row-ovatno">
912
-                <th><?php echo apply_filters( 'wpinv_invoice_owner_vat_number_label', wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ), $invoice, $vat_name ); ?></th>
912
+                <th><?php echo apply_filters('wpinv_invoice_owner_vat_number_label', wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name), $invoice, $vat_name); ?></th>
913 913
                 <td><?php echo $owner_vat_number; ?></td>
914 914
             </tr>
915 915
         <?php } ?>
916
-        <?php if ( $use_taxes && ( $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) ) { ?>
916
+        <?php if ($use_taxes && ($user_vat_number = wpinv_get_invoice_vat_number($invoice_id))) { ?>
917 917
             <tr class="wpi-row-uvatno">
918
-                <th><?php echo apply_filters( 'wpinv_invoice_user_vat_number_label', wp_sprintf( __( 'Invoice %s Number', 'invoicing' ), $vat_name ), $invoice, $vat_name ); ?></th>
918
+                <th><?php echo apply_filters('wpinv_invoice_user_vat_number_label', wp_sprintf(__('Invoice %s Number', 'invoicing'), $vat_name), $invoice, $vat_name); ?></th>
919 919
                 <td><?php echo $user_vat_number; ?></td>
920 920
             </tr>
921 921
         <?php } ?>
922 922
         <tr class="table-active tr-total wpi-row-total">
923
-            <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th>
924
-            <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td>
923
+            <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th>
924
+            <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td>
925 925
         </tr>
926 926
     </table>
927 927
 <?php
@@ -937,84 +937,84 @@  discard block
 block discarded – undo
937 937
  * @param  string $separator How to separate address lines.
938 938
  * @return string
939 939
  */
940
-function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) {
940
+function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') {
941 941
 
942 942
     // Retrieve the address markup...
943
-    $country= empty( $billing_details['country'] ) ? '' : $billing_details['country'];
944
-    $format = wpinv_get_full_address_format( $country );
943
+    $country = empty($billing_details['country']) ? '' : $billing_details['country'];
944
+    $format = wpinv_get_full_address_format($country);
945 945
 
946 946
     // ... and the replacements.
947
-    $replacements = wpinv_get_invoice_address_replacements( $billing_details );
947
+    $replacements = wpinv_get_invoice_address_replacements($billing_details);
948 948
 
949
-    $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format );
949
+    $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format);
950 950
     
951 951
 	// Remove unavailable tags.
952
-    $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address );
952
+    $formatted_address = preg_replace("/\{\{\w+\}\}/", '', $formatted_address);
953 953
 
954 954
     // Clean up white space.
955
-	$formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
956
-    $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
955
+	$formatted_address = preg_replace('/  +/', ' ', trim($formatted_address));
956
+    $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address);
957 957
     
958 958
     // Break newlines apart and remove empty lines/trim commas and white space.
959
-	$formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
959
+	$formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address)));
960 960
 
961 961
     // Add html breaks.
962
-	$formatted_address = implode( $separator, $formatted_address );
962
+	$formatted_address = implode($separator, $formatted_address);
963 963
 
964 964
 	// We're done!
965 965
 	return $formatted_address;
966 966
     
967 967
 }
968 968
 
969
-function wpinv_display_to_address( $invoice_id = 0 ) {
970
-    $invoice = wpinv_get_invoice( $invoice_id );
969
+function wpinv_display_to_address($invoice_id = 0) {
970
+    $invoice = wpinv_get_invoice($invoice_id);
971 971
     
972
-    if ( empty( $invoice ) ) {
972
+    if (empty($invoice)) {
973 973
         return NULL;
974 974
     }
975 975
     
976 976
     $billing_details = $invoice->get_user_info();
977
-    $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>';
977
+    $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>';
978 978
     $output .= '<div class="wrapper col-xs-10">';
979 979
     
980 980
     ob_start();
981
-    do_action( 'wpinv_display_to_address_top', $invoice );
981
+    do_action('wpinv_display_to_address_top', $invoice);
982 982
     $output .= ob_get_clean();
983 983
     
984
-    $address_row = wpinv_get_invoice_address_markup( $billing_details );
984
+    $address_row = wpinv_get_invoice_address_markup($billing_details);
985 985
 
986
-    if ( $address_row ) {
986
+    if ($address_row) {
987 987
         $output .= '<div class="address">' . $address_row . '</div>';
988 988
     }
989 989
 
990
-    if ( $phone = $invoice->get_phone() ) {
991
-        $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s', 'invoicing' ), esc_html( $phone ) ) . '</div>';
990
+    if ($phone = $invoice->get_phone()) {
991
+        $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s', 'invoicing'), esc_html($phone)) . '</div>';
992 992
     }
993
-    if ( $email = $invoice->get_email() ) {
994
-        $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' , 'invoicing'), esc_html( $email ) ) . '</div>';
993
+    if ($email = $invoice->get_email()) {
994
+        $output .= '<div class="email">' . wp_sprintf(__('Email: %s', 'invoicing'), esc_html($email)) . '</div>';
995 995
     }
996 996
 
997 997
     ob_start();
998
-    do_action( 'wpinv_display_to_address_bottom', $invoice );
998
+    do_action('wpinv_display_to_address_bottom', $invoice);
999 999
     $output .= ob_get_clean();
1000 1000
     
1001 1001
     $output .= '</div>';
1002
-    $output = apply_filters( 'wpinv_display_to_address', $output, $invoice );
1002
+    $output = apply_filters('wpinv_display_to_address', $output, $invoice);
1003 1003
 
1004 1004
     echo $output;
1005 1005
 }
1006 1006
 
1007
-function wpinv_display_line_items( $invoice_id = 0 ) {
1007
+function wpinv_display_line_items($invoice_id = 0) {
1008 1008
     global $wpinv_euvat, $ajax_cart_details;
1009
-    $invoice            = wpinv_get_invoice( $invoice_id );
1009
+    $invoice            = wpinv_get_invoice($invoice_id);
1010 1010
     $quantities_enabled = wpinv_item_quantities_enabled();
1011 1011
     $use_taxes          = wpinv_use_taxes();
1012
-    if ( !$use_taxes && (float)$invoice->get_tax() > 0 ) {
1012
+    if (!$use_taxes && (float) $invoice->get_tax() > 0) {
1013 1013
         $use_taxes = true;
1014 1014
     }
1015
-    $zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
1016
-    $tax_label           = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' );
1017
-    $tax_title          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
1015
+    $zero_tax           = !(float) $invoice->get_tax() > 0 ? true : false;
1016
+    $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing');
1017
+    $tax_title          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
1018 1018
 
1019 1019
     $cart_details       = $invoice->get_cart_details();
1020 1020
     $ajax_cart_details  = $cart_details;
@@ -1023,67 +1023,67 @@  discard block
 block discarded – undo
1023 1023
     <table class="table table-sm table-bordered">
1024 1024
         <thead>
1025 1025
             <tr>
1026
-                <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th>
1027
-                <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th>
1026
+                <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th>
1027
+                <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th>
1028 1028
                 <?php if ($quantities_enabled) { ?>
1029
-                    <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th>
1029
+                    <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th>
1030 1030
                 <?php } ?>
1031 1031
                 <?php if ($use_taxes && !$zero_tax) { ?>
1032 1032
                     <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th>
1033 1033
                 <?php } ?>
1034
-                <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th>
1034
+                <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th>
1035 1035
             </tr>
1036 1036
         </thead>
1037 1037
         <tbody>
1038 1038
         <?php 
1039
-            if ( !empty( $cart_details ) ) {
1040
-                do_action( 'wpinv_display_line_items_start', $invoice );
1039
+            if (!empty($cart_details)) {
1040
+                do_action('wpinv_display_line_items_start', $invoice);
1041 1041
 
1042 1042
                 $count = 0;
1043 1043
                 $cols  = 3;
1044
-                foreach ( $cart_details as $key => $cart_item ) {
1045
-                    $item_id    = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : '';
1046
-                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount( $cart_item["item_price"] ) : 0;
1047
-                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount( $cart_item["subtotal"] ) : 0;
1048
-                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1;
1044
+                foreach ($cart_details as $key => $cart_item) {
1045
+                    $item_id    = !empty($cart_item['id']) ? absint($cart_item['id']) : '';
1046
+                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount($cart_item["item_price"]) : 0;
1047
+                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount($cart_item["subtotal"]) : 0;
1048
+                    $quantity   = !empty($cart_item['quantity']) && (int) $cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1;
1049 1049
 
1050
-                    $item       = $item_id ? new WPInv_Item( $item_id ) : NULL;
1050
+                    $item       = $item_id ? new WPInv_Item($item_id) : NULL;
1051 1051
                     $summary    = '';
1052
-	                $item_name    = '';
1052
+	                $item_name = '';
1053 1053
                     $cols       = 3;
1054
-                    if ( !empty($item) ) {
1054
+                    if (!empty($item)) {
1055 1055
                         $item_name  = $item->get_name();
1056 1056
                         $summary    = $item->get_summary();
1057 1057
                     }
1058
-                    $item_name  = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1058
+                    $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1059 1059
 
1060
-                    $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice );
1060
+                    $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice);
1061 1061
 
1062 1062
                     $item_tax       = '';
1063 1063
                     $tax_rate       = '';
1064
-                    if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1065
-                        $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ), $invoice->get_currency() );
1066
-                        $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1067
-                        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1064
+                    if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1065
+                        $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']), $invoice->get_currency());
1066
+                        $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1067
+                        $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : '';
1068 1068
                         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : '';
1069 1069
                     }
1070 1070
 
1071 1071
                     $line_item_tax = $item_tax . $tax_rate;
1072 1072
 
1073
-                    if ( $line_item_tax === '' ) {
1073
+                    if ($line_item_tax === '') {
1074 1074
                         $line_item_tax = 0; // Zero tax
1075 1075
                     }
1076 1076
 
1077
-                    $action = apply_filters( 'wpinv_display_line_item_action', '', $cart_item, $invoice, $cols );
1077
+                    $action = apply_filters('wpinv_display_line_item_action', '', $cart_item, $invoice, $cols);
1078 1078
 
1079
-                    $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">';
1080
-                        $line_item .= '<td class="name">' . $action. esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item );
1081
-                        if ( $summary !== '' ) {
1082
-                            $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>';
1079
+                    $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">';
1080
+                        $line_item .= '<td class="name">' . $action . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item);
1081
+                        if ($summary !== '') {
1082
+                            $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>';
1083 1083
                         }
1084 1084
                         $line_item .= '</td>';
1085 1085
 
1086
-                        $line_item .= '<td class="rate">' . esc_html__( wpinv_price( wpinv_format_amount( $item_price ), $invoice->get_currency() ) ) . '</td>';
1086
+                        $line_item .= '<td class="rate">' . esc_html__(wpinv_price(wpinv_format_amount($item_price), $invoice->get_currency())) . '</td>';
1087 1087
                         if ($quantities_enabled) {
1088 1088
                             $cols++;
1089 1089
                             $line_item .= '<td class="qty">' . $quantity . '</td>';
@@ -1092,55 +1092,55 @@  discard block
 block discarded – undo
1092 1092
                             $cols++;
1093 1093
                             $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1094 1094
                         }
1095
-                        $line_item .= '<td class="total">' . esc_html__( wpinv_price( wpinv_format_amount( $line_total ), $invoice->get_currency() ) ) . '</td>';
1095
+                        $line_item .= '<td class="total">' . esc_html__(wpinv_price(wpinv_format_amount($line_total), $invoice->get_currency())) . '</td>';
1096 1096
                     $line_item .= '</tr>';
1097 1097
 
1098
-                    echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols );
1098
+                    echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols);
1099 1099
 
1100 1100
                     $count++;
1101 1101
                 }
1102 1102
 
1103
-                do_action( 'wpinv_display_before_subtotal', $invoice, $cols );
1103
+                do_action('wpinv_display_before_subtotal', $invoice, $cols);
1104 1104
                 ?>
1105 1105
                 <tr class="row-sub-total row_odd">
1106
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1107
-                    <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1106
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1107
+                    <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1108 1108
                 </tr>
1109 1109
                 <?php
1110
-                do_action( 'wpinv_display_after_subtotal', $invoice, $cols );
1110
+                do_action('wpinv_display_after_subtotal', $invoice, $cols);
1111 1111
                 
1112
-                if ( wpinv_discount( $invoice_id, false ) > 0 ) {
1113
-                    do_action( 'wpinv_display_before_discount', $invoice, $cols );
1112
+                if (wpinv_discount($invoice_id, false) > 0) {
1113
+                    do_action('wpinv_display_before_discount', $invoice, $cols);
1114 1114
                     ?>
1115 1115
                         <tr class="row-discount">
1116
-                            <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td>
1117
-                            <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1116
+                            <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td>
1117
+                            <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1118 1118
                         </tr>
1119 1119
                     <?php
1120
-                    do_action( 'wpinv_display_after_discount', $invoice, $cols );
1120
+                    do_action('wpinv_display_after_discount', $invoice, $cols);
1121 1121
                 }
1122 1122
 
1123
-                if ( $use_taxes ) {
1124
-                    do_action( 'wpinv_display_before_tax', $invoice, $cols );
1123
+                if ($use_taxes) {
1124
+                    do_action('wpinv_display_before_tax', $invoice, $cols);
1125 1125
                     ?>
1126 1126
                     <tr class="row-tax">
1127
-                        <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td>
1128
-                        <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1127
+                        <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td>
1128
+                        <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1129 1129
                     </tr>
1130 1130
                     <?php
1131
-                    do_action( 'wpinv_display_after_tax', $invoice, $cols );
1131
+                    do_action('wpinv_display_after_tax', $invoice, $cols);
1132 1132
                 }
1133 1133
 
1134
-                do_action( 'wpinv_display_before_total', $invoice, $cols );
1134
+                do_action('wpinv_display_before_total', $invoice, $cols);
1135 1135
                 ?>
1136 1136
                 <tr class="table-active row-total">
1137
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1138
-                    <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1137
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1138
+                    <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1139 1139
                 </tr>
1140 1140
                 <?php
1141
-                do_action( 'wpinv_display_after_total', $invoice, $cols );
1141
+                do_action('wpinv_display_after_total', $invoice, $cols);
1142 1142
 
1143
-                do_action( 'wpinv_display_line_end', $invoice, $cols );
1143
+                do_action('wpinv_display_line_end', $invoice, $cols);
1144 1144
             }
1145 1145
         ?>
1146 1146
         </tbody>
@@ -1152,56 +1152,56 @@  discard block
 block discarded – undo
1152 1152
 /**
1153 1153
  * @param WPInv_Invoice $invoice
1154 1154
  */
1155
-function wpinv_display_invoice_notes( $invoice ) {
1155
+function wpinv_display_invoice_notes($invoice) {
1156 1156
 
1157
-    $notes = wpinv_get_invoice_notes( $invoice->ID, 'customer' );
1157
+    $notes = wpinv_get_invoice_notes($invoice->ID, 'customer');
1158 1158
 
1159
-    if ( empty( $notes ) ) {
1159
+    if (empty($notes)) {
1160 1160
         return;
1161 1161
     }
1162 1162
 
1163 1163
     echo '<div class="wpi_invoice_notes_container">';
1164
-    echo '<h2>' . __( 'Invoice Notes', 'invoicing' ) .'</h2>';
1164
+    echo '<h2>' . __('Invoice Notes', 'invoicing') . '</h2>';
1165 1165
     echo '<ul class="wpi_invoice_notes">';
1166 1166
 
1167
-    foreach( $notes as $note ) {
1168
-        wpinv_get_invoice_note_line_item( $note );
1167
+    foreach ($notes as $note) {
1168
+        wpinv_get_invoice_note_line_item($note);
1169 1169
     }
1170 1170
 
1171 1171
     echo '</ul>';
1172 1172
     echo '</div>';
1173 1173
 }
1174
-add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_display_invoice_notes' );
1174
+add_action('wpinv_invoice_print_after_line_items', 'wpinv_display_invoice_notes');
1175 1175
 
1176
-function wpinv_display_invoice_totals( $invoice_id = 0 ) {
1176
+function wpinv_display_invoice_totals($invoice_id = 0) {
1177 1177
     $use_taxes = wpinv_use_taxes();
1178 1178
 
1179
-    do_action( 'wpinv_before_display_totals_table', $invoice_id ); 
1179
+    do_action('wpinv_before_display_totals_table', $invoice_id); 
1180 1180
     ?>
1181 1181
     <table class="table table-sm table-bordered table-responsive">
1182 1182
         <tbody>
1183
-            <?php do_action( 'wpinv_before_display_totals' ); ?>
1183
+            <?php do_action('wpinv_before_display_totals'); ?>
1184 1184
             <tr class="row-sub-total">
1185
-                <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td>
1186
-                <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1185
+                <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td>
1186
+                <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1187 1187
             </tr>
1188
-            <?php do_action( 'wpinv_after_display_totals' ); ?>
1189
-            <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?>
1188
+            <?php do_action('wpinv_after_display_totals'); ?>
1189
+            <?php if (wpinv_discount($invoice_id, false) > 0) { ?>
1190 1190
                 <tr class="row-discount">
1191
-                    <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td>
1192
-                    <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1191
+                    <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td>
1192
+                    <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1193 1193
                 </tr>
1194
-            <?php do_action( 'wpinv_after_display_discount' ); ?>
1194
+            <?php do_action('wpinv_after_display_discount'); ?>
1195 1195
             <?php } ?>
1196
-            <?php if ( $use_taxes ) { ?>
1196
+            <?php if ($use_taxes) { ?>
1197 1197
             <tr class="row-tax">
1198
-                <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td>
1199
-                <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1198
+                <td class="rate"><?php _e('Tax', 'invoicing'); ?></td>
1199
+                <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1200 1200
             </tr>
1201
-            <?php do_action( 'wpinv_after_display_tax' ); ?>
1201
+            <?php do_action('wpinv_after_display_tax'); ?>
1202 1202
             <?php } ?>
1203
-            <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?>
1204
-                <?php foreach ( $fees as $fee ) { ?>
1203
+            <?php if ($fees = wpinv_get_fees($invoice_id)) { ?>
1204
+                <?php foreach ($fees as $fee) { ?>
1205 1205
                     <tr class="row-fee">
1206 1206
                         <td class="rate"><?php echo $fee['label']; ?></td>
1207 1207
                         <td class="total"><?php echo $fee['amount_display']; ?></td>
@@ -1209,82 +1209,82 @@  discard block
 block discarded – undo
1209 1209
                 <?php } ?>
1210 1210
             <?php } ?>
1211 1211
             <tr class="table-active row-total">
1212
-                <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td>
1213
-                <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1212
+                <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td>
1213
+                <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1214 1214
             </tr>
1215
-            <?php do_action( 'wpinv_after_totals' ); ?>
1215
+            <?php do_action('wpinv_after_totals'); ?>
1216 1216
         </tbody>
1217 1217
 
1218 1218
     </table>
1219 1219
 
1220
-    <?php do_action( 'wpinv_after_totals_table' );
1220
+    <?php do_action('wpinv_after_totals_table');
1221 1221
 }
1222 1222
 
1223
-function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) {
1224
-    $invoice = wpinv_get_invoice( $invoice_id );
1223
+function wpinv_display_payments_info($invoice_id = 0, $echo = true) {
1224
+    $invoice = wpinv_get_invoice($invoice_id);
1225 1225
 
1226 1226
     ob_start();
1227
-    do_action( 'wpinv_before_display_payments_info', $invoice_id );
1228
-    if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() || $invoice->is_refunded() ) {
1227
+    do_action('wpinv_before_display_payments_info', $invoice_id);
1228
+    if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid() || $invoice->is_refunded()) {
1229 1229
         ?>
1230 1230
         <div class="wpi-payment-info">
1231
-            <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p>
1232
-            <?php if ( $gateway_title ) { ?>
1233
-            <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p>
1231
+            <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p>
1232
+            <?php if ($gateway_title) { ?>
1233
+            <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p>
1234 1234
             <?php } ?>
1235 1235
         </div>
1236 1236
         <?php
1237 1237
     }
1238
-    do_action( 'wpinv_after_display_payments_info', $invoice_id );
1238
+    do_action('wpinv_after_display_payments_info', $invoice_id);
1239 1239
     $outout = ob_get_clean();
1240 1240
 
1241
-    if ( $echo ) {
1241
+    if ($echo) {
1242 1242
         echo $outout;
1243 1243
     } else {
1244 1244
         return $outout;
1245 1245
     }
1246 1246
 }
1247 1247
 
1248
-function wpinv_display_style( $invoice ) {
1249
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION );
1248
+function wpinv_display_style($invoice) {
1249
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION);
1250 1250
 
1251
-    wp_print_styles( 'open-sans' );
1252
-    wp_print_styles( 'wpinv-single-style' );
1251
+    wp_print_styles('open-sans');
1252
+    wp_print_styles('wpinv-single-style');
1253 1253
 
1254 1254
     $custom_css = wpinv_get_option('template_custom_css');
1255
-    if(isset($custom_css) && !empty($custom_css)){
1256
-        $custom_css     = wp_kses( $custom_css, array( '\'', '\"' ) );
1257
-        $custom_css     = str_replace( '&gt;', '>', $custom_css );
1255
+    if (isset($custom_css) && !empty($custom_css)) {
1256
+        $custom_css     = wp_kses($custom_css, array('\'', '\"'));
1257
+        $custom_css     = str_replace('&gt;', '>', $custom_css);
1258 1258
         echo '<style type="text/css">';
1259 1259
         echo $custom_css;
1260 1260
         echo '</style>';
1261 1261
     }
1262 1262
 }
1263
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
1264
-add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' );
1263
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
1264
+add_action('wpinv_invalid_invoice_head', 'wpinv_display_style');
1265 1265
 
1266 1266
 function wpinv_checkout_billing_details() {
1267
-    $invoice_id = (int)wpinv_get_invoice_cart_id();
1267
+    $invoice_id = (int) wpinv_get_invoice_cart_id();
1268 1268
     if (empty($invoice_id)) {
1269
-        wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ );
1269
+        wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__);
1270 1270
         return null;
1271 1271
     }
1272 1272
 
1273
-    $invoice = wpinv_get_invoice_cart( $invoice_id );
1273
+    $invoice = wpinv_get_invoice_cart($invoice_id);
1274 1274
     if (empty($invoice)) {
1275
-        wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ );
1275
+        wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__);
1276 1276
         return null;
1277 1277
     }
1278 1278
     $user_id        = $invoice->get_user_id();
1279 1279
     $user_info      = $invoice->get_user_info();
1280
-    $address_info   = wpinv_get_user_address( $user_id );
1280
+    $address_info   = wpinv_get_user_address($user_id);
1281 1281
 
1282
-    if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) {
1282
+    if (empty($user_info['first_name']) && !empty($user_info['first_name'])) {
1283 1283
         $user_info['first_name'] = $user_info['first_name'];
1284 1284
         $user_info['last_name'] = $user_info['last_name'];
1285 1285
     }
1286 1286
 
1287
-    if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) {
1287
+    if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) {
1288 1288
         $user_info['country']   = $address_info['country'];
1289 1289
         $user_info['state']     = $address_info['state'];
1290 1290
         $user_info['city']      = $address_info['city'];
@@ -1300,99 +1300,99 @@  discard block
 block discarded – undo
1300 1300
         'address'
1301 1301
     );
1302 1302
 
1303
-    foreach ( $address_fields as $field ) {
1304
-        if ( empty( $user_info[$field] ) ) {
1303
+    foreach ($address_fields as $field) {
1304
+        if (empty($user_info[$field])) {
1305 1305
             $user_info[$field] = $address_info[$field];
1306 1306
         }
1307 1307
     }
1308 1308
 
1309
-    return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice );
1309
+    return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice);
1310 1310
 }
1311 1311
 
1312 1312
 function wpinv_admin_get_line_items($invoice = array()) {
1313 1313
     $item_quantities    = wpinv_item_quantities_enabled();
1314 1314
     $use_taxes          = wpinv_use_taxes();
1315 1315
 
1316
-    if ( empty( $invoice ) ) {
1316
+    if (empty($invoice)) {
1317 1317
         return NULL;
1318 1318
     }
1319 1319
 
1320 1320
     $cart_items = $invoice->get_cart_details();
1321
-    if ( empty( $cart_items ) ) {
1321
+    if (empty($cart_items)) {
1322 1322
         return NULL;
1323 1323
     }
1324 1324
 
1325 1325
     ob_start();
1326 1326
 
1327
-    do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice );
1327
+    do_action('wpinv_admin_before_line_items', $cart_items, $invoice);
1328 1328
 
1329 1329
     $count = 0;
1330
-    foreach ( $cart_items as $key => $cart_item ) {
1330
+    foreach ($cart_items as $key => $cart_item) {
1331 1331
         $item_id    = $cart_item['id'];
1332
-        $wpi_item   = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL;
1332
+        $wpi_item   = $item_id > 0 ? new WPInv_Item($item_id) : NULL;
1333 1333
 
1334 1334
         if (empty($wpi_item)) {
1335 1335
             continue;
1336 1336
         }
1337 1337
 
1338
-        $item_price     = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ), $invoice->get_currency() );
1339
-        $quantity       = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1340
-        $item_subtotal  = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ), $invoice->get_currency() );
1338
+        $item_price     = wpinv_price(wpinv_format_amount($cart_item['item_price']), $invoice->get_currency());
1339
+        $quantity       = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1340
+        $item_subtotal  = wpinv_price(wpinv_format_amount($cart_item['subtotal']), $invoice->get_currency());
1341 1341
         $can_remove     = true;
1342 1342
 
1343
-        $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', '', $cart_item, $wpi_item, $invoice );
1343
+        $summary = apply_filters('wpinv_admin_invoice_line_item_summary', '', $cart_item, $wpi_item, $invoice);
1344 1344
 
1345 1345
         $item_tax       = '';
1346 1346
         $tax_rate       = '';
1347
-        if ( $invoice->is_taxable() && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1348
-            $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ), $invoice->get_currency() );
1349
-            $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1350
-            $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1347
+        if ($invoice->is_taxable() && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1348
+            $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']), $invoice->get_currency());
1349
+            $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1350
+            $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : '';
1351 1351
             $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : '';
1352 1352
         }
1353 1353
         $line_item_tax = $item_tax . $tax_rate;
1354 1354
 
1355
-        if ( $line_item_tax === '' ) {
1355
+        if ($line_item_tax === '') {
1356 1356
             $line_item_tax = 0; // Zero tax
1357 1357
         }
1358 1358
 
1359
-        $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">';
1359
+        $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">';
1360 1360
             $line_item .= '<td class="id">' . $item_id . '</td>';
1361
-            $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 );
1362
-            if ( $summary !== '' ) {
1363
-                $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>';
1361
+            $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);
1362
+            if ($summary !== '') {
1363
+                $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>';
1364 1364
             }
1365 1365
             $line_item .= '</td>';
1366 1366
             $line_item .= '<td class="price">' . $item_price . '</td>';
1367 1367
             
1368
-            if ( $item_quantities ) {
1369
-                if ( count( $cart_items ) == 1 && $quantity <= 1 ) {
1368
+            if ($item_quantities) {
1369
+                if (count($cart_items) == 1 && $quantity <= 1) {
1370 1370
                     $can_remove = false;
1371 1371
                 }
1372 1372
                 $line_item .= '<td class="qty" data-quantity="' . $quantity . '">&nbsp;&times;&nbsp;' . $quantity . '</td>';
1373 1373
             } else {
1374
-                if ( count( $cart_items ) == 1 ) {
1374
+                if (count($cart_items) == 1) {
1375 1375
                     $can_remove = false;
1376 1376
                 }
1377 1377
             }
1378 1378
             $line_item .= '<td class="total">' . $item_subtotal . '</td>';
1379 1379
             
1380
-            if ( $use_taxes ) {
1380
+            if ($use_taxes) {
1381 1381
                 $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1382 1382
             }
1383 1383
             $line_item .= '<td class="action">';
1384
-            if ( !$invoice->is_paid() && !$invoice->is_refunded() ) {
1384
+            if (!$invoice->is_paid() && !$invoice->is_refunded()) {
1385 1385
                 $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>';
1386 1386
             }
1387 1387
             $line_item .= '</td>';
1388 1388
         $line_item .= '</tr>';
1389 1389
 
1390
-        echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice );
1390
+        echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice);
1391 1391
 
1392 1392
         $count++;
1393 1393
     } 
1394 1394
 
1395
-    do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice );
1395
+    do_action('wpinv_admin_after_line_items', $cart_items, $invoice);
1396 1396
 
1397 1397
     return ob_get_clean();
1398 1398
 }
@@ -1404,32 +1404,32 @@  discard block
 block discarded – undo
1404 1404
     $wpi_checkout_id = wpinv_get_invoice_cart_id();
1405 1405
 
1406 1406
     //Maybe update the prices
1407
-    if(! empty( $_GET['wpi_dynamic_item'] ) && ! empty( $_GET['wpi_dynamic_price'] ) ) {
1407
+    if (!empty($_GET['wpi_dynamic_item']) && !empty($_GET['wpi_dynamic_price'])) {
1408 1408
 
1409 1409
         //If the invoice exists, update it with new pricing details
1410
-        if (! empty( $wpi_checkout_id ) ) {
1410
+        if (!empty($wpi_checkout_id)) {
1411 1411
 
1412 1412
             $_invoice       = wpinv_get_invoice_cart();
1413 1413
             $_cart_details  = $_invoice->get_cart_details();
1414
-            $_dynamic_item  = sanitize_text_field( $_GET['wpi_dynamic_item'] );
1414
+            $_dynamic_item  = sanitize_text_field($_GET['wpi_dynamic_item']);
1415 1415
 
1416 1416
             //First, fetch the item
1417
-            $item    = new WPInv_Item( $_dynamic_item );
1417
+            $item = new WPInv_Item($_dynamic_item);
1418 1418
     
1419 1419
             //Next, ensure it supports dynamic pricing...
1420
-            if( $item->supports_dynamic_pricing() && $item->get_is_dynamic_pricing() ) {
1420
+            if ($item->supports_dynamic_pricing() && $item->get_is_dynamic_pricing()) {
1421 1421
                 
1422 1422
                 //... and that the new price is not lower than the minimum price
1423
-                $_dynamic_price = (float) wpinv_sanitize_amount( sanitize_text_field( $_GET['wpi_dynamic_price'] ) );
1424
-                if( $_dynamic_price < $item->get_minimum_price() ) {
1423
+                $_dynamic_price = (float) wpinv_sanitize_amount(sanitize_text_field($_GET['wpi_dynamic_price']));
1424
+                if ($_dynamic_price < $item->get_minimum_price()) {
1425 1425
                     $_dynamic_price = $item->get_minimum_price();
1426 1426
                 }
1427 1427
 
1428 1428
                 //Finally, update our invoice with the new price
1429
-                if ( !empty( $_cart_details ) ) {
1429
+                if (!empty($_cart_details)) {
1430 1430
 
1431
-                    foreach ( $_cart_details as $key => $item ) {
1432
-                        if ( !empty( $item['id'] ) && $_dynamic_item == $item['id'] ) {
1431
+                    foreach ($_cart_details as $key => $item) {
1432
+                        if (!empty($item['id']) && $_dynamic_item == $item['id']) {
1433 1433
                             $_cart_details[$key]['custom_price'] = $_dynamic_price;
1434 1434
                             $_cart_details[$key]['item_price']   = $_dynamic_price;
1435 1435
                         }
@@ -1437,8 +1437,8 @@  discard block
 block discarded – undo
1437 1437
 
1438 1438
                     $_meta = $_invoice->get_meta();
1439 1439
                     $_meta['cart_details'] = $_cart_details;
1440
-                    $_invoice->set( 'payment_meta', $_meta );
1441
-                    $_invoice->set( 'cart_details', $_cart_details );
1440
+                    $_invoice->set('payment_meta', $_meta);
1441
+                    $_invoice->set('cart_details', $_cart_details);
1442 1442
                     $_invoice->recalculate_totals();
1443 1443
 
1444 1444
                 }
@@ -1449,60 +1449,60 @@  discard block
 block discarded – undo
1449 1449
 
1450 1450
     }
1451 1451
 
1452
-    $form_action  = esc_url( wpinv_get_checkout_uri() );
1452
+    $form_action = esc_url(wpinv_get_checkout_uri());
1453 1453
 
1454 1454
     ob_start();
1455
-	    do_action( 'wpinv_checkout_content_before' );
1455
+	    do_action('wpinv_checkout_content_before');
1456 1456
         echo '<div id="wpinv_checkout_wrap">';
1457 1457
 
1458
-        if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) {
1458
+        if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) {
1459 1459
             ?>
1460 1460
             <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive">
1461
-                <?php do_action( 'wpinv_before_checkout_form' ); ?>
1461
+                <?php do_action('wpinv_before_checkout_form'); ?>
1462 1462
                 <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST">
1463 1463
                     <?php
1464
-                    do_action( 'wpinv_checkout_form_top' );
1465
-                    do_action( 'wpinv_checkout_billing_info' );
1466
-                    do_action( 'wpinv_checkout_cart' );
1467
-                    do_action( 'wpinv_payment_mode_select'  );
1468
-                    do_action( 'wpinv_checkout_form_bottom' )
1464
+                    do_action('wpinv_checkout_form_top');
1465
+                    do_action('wpinv_checkout_billing_info');
1466
+                    do_action('wpinv_checkout_cart');
1467
+                    do_action('wpinv_payment_mode_select');
1468
+                    do_action('wpinv_checkout_form_bottom')
1469 1469
                     ?>
1470 1470
                 </form>
1471
-                <?php do_action( 'wpinv_after_purchase_form' ); ?>
1471
+                <?php do_action('wpinv_after_purchase_form'); ?>
1472 1472
             </div><!--end #wpinv_checkout_form_wrap-->
1473 1473
         <?php
1474 1474
         } else {
1475
-            do_action( 'wpinv_cart_empty' );
1475
+            do_action('wpinv_cart_empty');
1476 1476
         }
1477 1477
         echo '</div><!--end #wpinv_checkout_wrap-->';
1478
-	    do_action( 'wpinv_checkout_content_after' );
1478
+	    do_action('wpinv_checkout_content_after');
1479 1479
     return ob_get_clean();
1480 1480
 }
1481 1481
 
1482
-function wpinv_checkout_cart( $cart_details = array(), $echo = true ) {
1482
+function wpinv_checkout_cart($cart_details = array(), $echo = true) {
1483 1483
     global $ajax_cart_details;
1484 1484
     $ajax_cart_details = $cart_details;
1485 1485
 
1486 1486
     ob_start();
1487
-    do_action( 'wpinv_before_checkout_cart' );
1487
+    do_action('wpinv_before_checkout_cart');
1488 1488
     echo '<div id="wpinv_checkout_cart_form" method="post">';
1489 1489
         echo '<div id="wpinv_checkout_cart_wrap">';
1490
-            wpinv_get_template_part( 'wpinv-checkout-cart' );
1490
+            wpinv_get_template_part('wpinv-checkout-cart');
1491 1491
         echo '</div>';
1492 1492
     echo '</div>';
1493
-    do_action( 'wpinv_after_checkout_cart' );
1493
+    do_action('wpinv_after_checkout_cart');
1494 1494
     $content = ob_get_clean();
1495 1495
 
1496
-    if ( $echo ) {
1496
+    if ($echo) {
1497 1497
         echo $content;
1498 1498
     } else {
1499 1499
         return $content;
1500 1500
     }
1501 1501
 }
1502
-add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 );
1502
+add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10);
1503 1503
 
1504 1504
 function wpinv_empty_cart_message() {
1505
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1505
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1506 1506
 }
1507 1507
 
1508 1508
 /**
@@ -1514,83 +1514,83 @@  discard block
 block discarded – undo
1514 1514
 function wpinv_empty_checkout_cart() {
1515 1515
 	echo wpinv_empty_cart_message();
1516 1516
 }
1517
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1517
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1518 1518
 
1519 1519
 function wpinv_update_cart_button() {
1520
-    if ( !wpinv_item_quantities_enabled() )
1520
+    if (!wpinv_item_quantities_enabled())
1521 1521
         return;
1522 1522
 ?>
1523
-    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/>
1523
+    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/>
1524 1524
     <input type="hidden" name="wpi_action" value="update_cart"/>
1525 1525
 <?php
1526 1526
 }
1527 1527
 
1528 1528
 function wpinv_checkout_cart_columns() {
1529 1529
     $default = 3;
1530
-    if ( wpinv_item_quantities_enabled() ) {
1530
+    if (wpinv_item_quantities_enabled()) {
1531 1531
         $default++;
1532 1532
     }
1533 1533
     
1534
-    if ( wpinv_use_taxes() ) {
1534
+    if (wpinv_use_taxes()) {
1535 1535
         $default++;
1536 1536
     }
1537 1537
 
1538
-    return apply_filters( 'wpinv_checkout_cart_columns', $default );
1538
+    return apply_filters('wpinv_checkout_cart_columns', $default);
1539 1539
 }
1540 1540
 
1541 1541
 function wpinv_display_cart_messages() {
1542 1542
     global $wpi_session;
1543 1543
 
1544
-    $messages = $wpi_session->get( 'wpinv_cart_messages' );
1544
+    $messages = $wpi_session->get('wpinv_cart_messages');
1545 1545
 
1546
-    if ( $messages ) {
1547
-        foreach ( $messages as $message_id => $message ) {
1546
+    if ($messages) {
1547
+        foreach ($messages as $message_id => $message) {
1548 1548
             // Try and detect what type of message this is
1549
-            if ( strpos( strtolower( $message ), 'error' ) ) {
1549
+            if (strpos(strtolower($message), 'error')) {
1550 1550
                 $type = 'error';
1551
-            } elseif ( strpos( strtolower( $message ), 'success' ) ) {
1551
+            } elseif (strpos(strtolower($message), 'success')) {
1552 1552
                 $type = 'success';
1553 1553
             } else {
1554 1554
                 $type = 'info';
1555 1555
             }
1556 1556
 
1557
-            $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) );
1557
+            $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type));
1558 1558
 
1559
-            echo '<div class="' . implode( ' ', $classes ) . '">';
1559
+            echo '<div class="' . implode(' ', $classes) . '">';
1560 1560
                 // Loop message codes and display messages
1561 1561
                     echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>';
1562 1562
             echo '</div>';
1563 1563
         }
1564 1564
 
1565 1565
         // Remove all of the cart saving messages
1566
-        $wpi_session->set( 'wpinv_cart_messages', null );
1566
+        $wpi_session->set('wpinv_cart_messages', null);
1567 1567
     }
1568 1568
 }
1569
-add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' );
1569
+add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages');
1570 1570
 
1571 1571
 function wpinv_discount_field() {
1572
-    if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) {
1572
+    if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) {
1573 1573
         return; // Only show before a payment method has been selected if ajax is disabled
1574 1574
     }
1575 1575
 
1576
-    if ( !wpinv_is_checkout() ) {
1576
+    if (!wpinv_is_checkout()) {
1577 1577
         return;
1578 1578
     }
1579 1579
 
1580
-    if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) {
1580
+    if (wpinv_has_active_discounts() && wpinv_get_cart_total()) {
1581 1581
     ?>
1582 1582
     <div id="wpinv-discount-field" class="panel panel-default">
1583 1583
         <div class="panel-body">
1584 1584
             <p>
1585
-                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label>
1586
-                <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span>
1585
+                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label>
1586
+                <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span>
1587 1587
             </p>
1588 1588
             <div class="form-group row">
1589 1589
                 <div class="col-sm-4">
1590
-                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/>
1590
+                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/>
1591 1591
                 </div>
1592 1592
                 <div class="col-sm-3">
1593
-                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button>
1593
+                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button>
1594 1594
                 </div>
1595 1595
                 <div style="clear:both"></div>
1596 1596
                 <div class="col-sm-12 wpinv-discount-msg">
@@ -1603,10 +1603,10 @@  discard block
 block discarded – undo
1603 1603
 <?php
1604 1604
     }
1605 1605
 }
1606
-add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 );
1606
+add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10);
1607 1607
 
1608 1608
 function wpinv_agree_to_terms_js() {
1609
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
1609
+    if (wpinv_get_option('show_agree_to_terms', false)) {
1610 1610
 ?>
1611 1611
 <script type="text/javascript">
1612 1612
     jQuery(document).ready(function($){
@@ -1621,125 +1621,125 @@  discard block
 block discarded – undo
1621 1621
 <?php
1622 1622
     }
1623 1623
 }
1624
-add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' );
1624
+add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js');
1625 1625
 
1626 1626
 function wpinv_payment_mode_select() {
1627
-    $gateways = wpinv_get_enabled_payment_gateways( true );
1628
-    $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways );
1629
-    $invoice = wpinv_get_invoice( 0, true );
1627
+    $gateways = wpinv_get_enabled_payment_gateways(true);
1628
+    $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways);
1629
+    $invoice = wpinv_get_invoice(0, true);
1630 1630
 
1631 1631
     do_action('wpinv_payment_mode_top');
1632
-    $invoice_id = $invoice ? (int)$invoice->ID : 0;
1633
-    $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id );
1632
+    $invoice_id = $invoice ? (int) $invoice->ID : 0;
1633
+    $chosen_gateway = wpinv_get_chosen_gateway($invoice_id);
1634 1634
     ?>
1635
-    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ( ( $invoice && $invoice->is_free() ) ? 'style="display:none;" data-free="1"' : '' ); ?>>
1636
-            <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?>
1635
+    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo (($invoice && $invoice->is_free()) ? 'style="display:none;" data-free="1"' : ''); ?>>
1636
+            <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?>
1637 1637
             <div id="wpinv-payment-mode-wrap" class="panel panel-default">
1638
-                <div class="panel-heading wpi-payment_methods_title"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div>
1638
+                <div class="panel-heading wpi-payment_methods_title"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div>
1639 1639
                 <div class="panel-body list-group wpi-payment_methods">
1640 1640
                     <?php
1641
-                    do_action( 'wpinv_payment_mode_before_gateways' );
1642
-
1643
-                    if ( !empty( $gateways ) ) {
1644
-                        foreach ( $gateways as $gateway_id => $gateway ) {
1645
-                            $checked       = checked( $gateway_id, $chosen_gateway, false );
1646
-                            $button_label  = wpinv_get_gateway_button_label( $gateway_id );
1647
-                            $gateway_label = wpinv_get_gateway_checkout_label( $gateway_id );
1648
-                            $description   = wpinv_get_gateway_description( $gateway_id );
1641
+                    do_action('wpinv_payment_mode_before_gateways');
1642
+
1643
+                    if (!empty($gateways)) {
1644
+                        foreach ($gateways as $gateway_id => $gateway) {
1645
+                            $checked       = checked($gateway_id, $chosen_gateway, false);
1646
+                            $button_label  = wpinv_get_gateway_button_label($gateway_id);
1647
+                            $gateway_label = wpinv_get_gateway_checkout_label($gateway_id);
1648
+                            $description   = wpinv_get_gateway_description($gateway_id);
1649 1649
                             ?>
1650 1650
                             <div class="list-group-item">
1651 1651
                                 <div class="radio">
1652
-                                    <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_label ); ?></label>
1652
+                                    <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_label); ?></label>
1653 1653
                                 </div>
1654
-                                <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert">
1655
-                                    <?php if ( !empty( $description ) ) { ?>
1656
-                                        <div class="wpi-gateway-desc alert alert-info"><?php _e( $description, 'invoicing' ); ?></div>
1654
+                                <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert">
1655
+                                    <?php if (!empty($description)) { ?>
1656
+                                        <div class="wpi-gateway-desc alert alert-info"><?php _e($description, 'invoicing'); ?></div>
1657 1657
                                     <?php } ?>
1658
-                                    <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?>
1658
+                                    <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?>
1659 1659
                                 </div>
1660 1660
                             </div>
1661 1661
                             <?php
1662 1662
                         }
1663 1663
                     } else {
1664
-                        echo '<div class="alert alert-warning">'. __( 'No payment gateway active', 'invoicing' ) .'</div>';
1664
+                        echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>';
1665 1665
                     }
1666 1666
 
1667
-                    do_action( 'wpinv_payment_mode_after_gateways' );
1667
+                    do_action('wpinv_payment_mode_after_gateways');
1668 1668
                     ?>
1669 1669
                 </div>
1670 1670
             </div>
1671
-            <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?>
1671
+            <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?>
1672 1672
     </div>
1673 1673
     <?php
1674 1674
     do_action('wpinv_payment_mode_bottom');
1675 1675
 }
1676
-add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' );
1676
+add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select');
1677 1677
 
1678 1678
 function wpinv_checkout_billing_info() {
1679
-    if ( wpinv_is_checkout() ) {
1679
+    if (wpinv_is_checkout()) {
1680 1680
         $billing_details    = wpinv_checkout_billing_details();
1681
-        $selected_country   = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country();
1681
+        $selected_country   = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country();
1682 1682
         ?>
1683 1683
         <div id="wpinv-fields" class="clearfix">
1684 1684
             <div id="wpi-billing" class="wpi-billing clearfix panel panel-default">
1685
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div>
1685
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div>
1686 1686
                 <div id="wpinv-fields-box" class="panel-body">
1687
-                    <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?>
1687
+                    <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?>
1688 1688
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1689
-                        <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><?php if ( wpinv_get_option( 'fname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1689
+                        <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><?php if (wpinv_get_option('fname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1690 1690
                         <?php
1691
-                        echo wpinv_html_text( array(
1691
+                        echo wpinv_html_text(array(
1692 1692
                                 'id'            => 'wpinv_first_name',
1693 1693
                                 'name'          => 'wpinv_first_name',
1694 1694
                                 'value'         => $billing_details['first_name'],
1695 1695
                                 'class'         => 'wpi-input form-control',
1696
-                                'placeholder'   => __( 'First name', 'invoicing' ),
1697
-                                'required'      => (bool)wpinv_get_option( 'fname_mandatory' ),
1698
-                            ) );
1696
+                                'placeholder'   => __('First name', 'invoicing'),
1697
+                                'required'      => (bool) wpinv_get_option('fname_mandatory'),
1698
+                            ));
1699 1699
                         ?>
1700 1700
                     </p>
1701 1701
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1702
-                        <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?><?php if ( wpinv_get_option( 'lname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1702
+                        <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?><?php if (wpinv_get_option('lname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1703 1703
                         <?php
1704
-                        echo wpinv_html_text( array(
1704
+                        echo wpinv_html_text(array(
1705 1705
                                 'id'            => 'wpinv_last_name',
1706 1706
                                 'name'          => 'wpinv_last_name',
1707 1707
                                 'value'         => $billing_details['last_name'],
1708 1708
                                 'class'         => 'wpi-input form-control',
1709
-                                'placeholder'   => __( 'Last name', 'invoicing' ),
1710
-                                'required'      => (bool)wpinv_get_option( 'lname_mandatory' ),
1711
-                            ) );
1709
+                                'placeholder'   => __('Last name', 'invoicing'),
1710
+                                'required'      => (bool) wpinv_get_option('lname_mandatory'),
1711
+                            ));
1712 1712
                         ?>
1713 1713
                     </p>
1714 1714
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1715
-                        <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><?php if ( wpinv_get_option( 'address_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1715
+                        <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><?php if (wpinv_get_option('address_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1716 1716
                         <?php
1717
-                        echo wpinv_html_text( array(
1717
+                        echo wpinv_html_text(array(
1718 1718
                                 'id'            => 'wpinv_address',
1719 1719
                                 'name'          => 'wpinv_address',
1720 1720
                                 'value'         => $billing_details['address'],
1721 1721
                                 'class'         => 'wpi-input form-control',
1722
-                                'placeholder'   => __( 'Address', 'invoicing' ),
1723
-                                'required'      => (bool)wpinv_get_option( 'address_mandatory' ),
1724
-                            ) );
1722
+                                'placeholder'   => __('Address', 'invoicing'),
1723
+                                'required'      => (bool) wpinv_get_option('address_mandatory'),
1724
+                            ));
1725 1725
                         ?>
1726 1726
                     </p>
1727 1727
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1728
-                        <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><?php if ( wpinv_get_option( 'city_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1728
+                        <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><?php if (wpinv_get_option('city_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1729 1729
                         <?php
1730
-                        echo wpinv_html_text( array(
1730
+                        echo wpinv_html_text(array(
1731 1731
                                 'id'            => 'wpinv_city',
1732 1732
                                 'name'          => 'wpinv_city',
1733 1733
                                 'value'         => $billing_details['city'],
1734 1734
                                 'class'         => 'wpi-input form-control',
1735
-                                'placeholder'   => __( 'City', 'invoicing' ),
1736
-                                'required'      => (bool)wpinv_get_option( 'city_mandatory' ),
1737
-                            ) );
1735
+                                'placeholder'   => __('City', 'invoicing'),
1736
+                                'required'      => (bool) wpinv_get_option('city_mandatory'),
1737
+                            ));
1738 1738
                         ?>
1739 1739
                     </p>
1740 1740
                     <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf">
1741
-                        <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><?php if ( wpinv_get_option( 'country_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1742
-                        <?php echo wpinv_html_select( array(
1741
+                        <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><?php if (wpinv_get_option('country_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1742
+                        <?php echo wpinv_html_select(array(
1743 1743
                             'options'          => wpinv_get_country_list(),
1744 1744
                             'name'             => 'wpinv_country',
1745 1745
                             'id'               => 'wpinv_country',
@@ -1747,16 +1747,16 @@  discard block
 block discarded – undo
1747 1747
                             'show_option_all'  => false,
1748 1748
                             'show_option_none' => false,
1749 1749
                             'class'            => 'wpi-input form-control wpi_select2',
1750
-                            'placeholder'      => __( 'Choose a country', 'invoicing' ),
1751
-                            'required'         => (bool)wpinv_get_option( 'country_mandatory' ),
1752
-                        ) ); ?>
1750
+                            'placeholder'      => __('Choose a country', 'invoicing'),
1751
+                            'required'         => (bool) wpinv_get_option('country_mandatory'),
1752
+                        )); ?>
1753 1753
                     </p>
1754 1754
                     <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll">
1755
-                        <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><?php if ( wpinv_get_option( 'state_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1755
+                        <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><?php if (wpinv_get_option('state_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1756 1756
                         <?php
1757
-                        $states = wpinv_get_country_states( $selected_country );
1758
-                        if( !empty( $states ) ) {
1759
-                            echo wpinv_html_select( array(
1757
+                        $states = wpinv_get_country_states($selected_country);
1758
+                        if (!empty($states)) {
1759
+                            echo wpinv_html_select(array(
1760 1760
                                 'options'          => $states,
1761 1761
                                 'name'             => 'wpinv_state',
1762 1762
                                 'id'               => 'wpinv_state',
@@ -1764,61 +1764,61 @@  discard block
 block discarded – undo
1764 1764
                                 'show_option_all'  => false,
1765 1765
                                 'show_option_none' => false,
1766 1766
                                 'class'            => 'wpi-input form-control wpi_select2',
1767
-                                'placeholder'      => __( 'Choose a state', 'invoicing' ),
1768
-                                'required'         => (bool)wpinv_get_option( 'state_mandatory' ),
1769
-                            ) );
1767
+                                'placeholder'      => __('Choose a state', 'invoicing'),
1768
+                                'required'         => (bool) wpinv_get_option('state_mandatory'),
1769
+                            ));
1770 1770
                         } else {
1771
-                            echo wpinv_html_text( array(
1771
+                            echo wpinv_html_text(array(
1772 1772
                                 'name'          => 'wpinv_state',
1773 1773
                                 'value'         => $billing_details['state'],
1774 1774
                                 'id'            => 'wpinv_state',
1775 1775
                                 'class'         => 'wpi-input form-control',
1776
-                                'placeholder'   => __( 'State / Province', 'invoicing' ),
1777
-                                'required'      => (bool)wpinv_get_option( 'state_mandatory' ),
1778
-                            ) );
1776
+                                'placeholder'   => __('State / Province', 'invoicing'),
1777
+                                'required'      => (bool) wpinv_get_option('state_mandatory'),
1778
+                            ));
1779 1779
                         }
1780 1780
                         ?>
1781 1781
                     </p>
1782 1782
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1783
-                        <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?><?php if ( wpinv_get_option( 'zip_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1783
+                        <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?><?php if (wpinv_get_option('zip_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1784 1784
                         <?php
1785
-                        echo wpinv_html_text( array(
1785
+                        echo wpinv_html_text(array(
1786 1786
                                 'name'          => 'wpinv_zip',
1787 1787
                                 'value'         => $billing_details['zip'],
1788 1788
                                 'id'            => 'wpinv_zip',
1789 1789
                                 'class'         => 'wpi-input form-control',
1790
-                                'placeholder'   => __( 'ZIP / Postcode', 'invoicing' ),
1791
-                                'required'      => (bool)wpinv_get_option( 'zip_mandatory' ),
1792
-                            ) );
1790
+                                'placeholder'   => __('ZIP / Postcode', 'invoicing'),
1791
+                                'required'      => (bool) wpinv_get_option('zip_mandatory'),
1792
+                            ));
1793 1793
                         ?>
1794 1794
                     </p>
1795 1795
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1796
-                        <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>
1796
+                        <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>
1797 1797
                         <?php
1798
-                        echo wpinv_html_text( array(
1798
+                        echo wpinv_html_text(array(
1799 1799
                                 'id'            => 'wpinv_phone',
1800 1800
                                 'name'          => 'wpinv_phone',
1801 1801
                                 'value'         => $billing_details['phone'],
1802 1802
                                 'class'         => 'wpi-input form-control',
1803
-                                'placeholder'   => __( 'Phone', 'invoicing' ),
1804
-                                'required'      => (bool)wpinv_get_option( 'phone_mandatory' ),
1805
-                            ) );
1803
+                                'placeholder'   => __('Phone', 'invoicing'),
1804
+                                'required'      => (bool) wpinv_get_option('phone_mandatory'),
1805
+                            ));
1806 1806
                         ?>
1807 1807
                     </p>
1808
-                    <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?>
1808
+                    <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?>
1809 1809
                     <div class="clearfix"></div>
1810 1810
                 </div>
1811 1811
             </div>
1812
-            <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?>
1812
+            <?php do_action('wpinv_after_billing_fields', $billing_details); ?>
1813 1813
         </div>
1814 1814
         <?php
1815 1815
     }
1816 1816
 }
1817
-add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' );
1817
+add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info');
1818 1818
 
1819 1819
 function wpinv_checkout_hidden_fields() {
1820 1820
 ?>
1821
-    <?php if ( is_user_logged_in() ) { ?>
1821
+    <?php if (is_user_logged_in()) { ?>
1822 1822
     <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/>
1823 1823
     <?php } ?>
1824 1824
     <input type="hidden" name="wpi_action" value="payment" />
@@ -1828,9 +1828,9 @@  discard block
 block discarded – undo
1828 1828
 function wpinv_checkout_button_purchase() {
1829 1829
     ob_start();
1830 1830
 ?>
1831
-    <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' ) ?>"/>
1831
+    <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') ?>"/>
1832 1832
 <?php
1833
-    return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() );
1833
+    return apply_filters('wpinv_checkout_button_purchase', ob_get_clean());
1834 1834
 }
1835 1835
 
1836 1836
 function wpinv_checkout_total() {
@@ -1839,84 +1839,84 @@  discard block
 block discarded – undo
1839 1839
 <div id="wpinv_checkout_total" class="panel panel-info">
1840 1840
     <div class="panel-body">
1841 1841
     <?php
1842
-    do_action( 'wpinv_purchase_form_before_checkout_total' );
1842
+    do_action('wpinv_purchase_form_before_checkout_total');
1843 1843
     ?>
1844
-    <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span>
1844
+    <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span>
1845 1845
     <?php
1846
-    do_action( 'wpinv_purchase_form_after_checkout_total' );
1846
+    do_action('wpinv_purchase_form_after_checkout_total');
1847 1847
     ?>
1848 1848
     </div>
1849 1849
 </div>
1850 1850
 <?php
1851 1851
 }
1852
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 );
1852
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998);
1853 1853
 
1854 1854
 function wpinv_checkout_accept_tandc() {
1855
-    $page = wpinv_get_option( 'tandc_page' );
1855
+    $page = wpinv_get_option('tandc_page');
1856 1856
     ?>
1857 1857
     <div id="wpinv_checkout_tandc" class="panel panel-success">
1858 1858
         <div class="panel-body">
1859 1859
             <?php echo wpinv_get_policy_text(); ?>
1860 1860
             <?php
1861
-            if(isset($page) && (int)$page > 0 && apply_filters( 'wpinv_checkout_show_terms', true )){
1862
-                $terms_link = esc_url( get_permalink( $page ) );
1861
+            if (isset($page) && (int) $page > 0 && apply_filters('wpinv_checkout_show_terms', true)) {
1862
+                $terms_link = esc_url(get_permalink($page));
1863 1863
                 ?>
1864 1864
                 <label class="">
1865
-                    <input type="checkbox" class="wpi-terms-checkbox" name="wpi_terms" id="wpi-terms" <?php checked( apply_filters( 'wpinv_terms_is_checked_default', isset( $_POST['wpi_terms'] ) ), true ); ?>> <span><?php printf( __( 'I&rsquo;ve read and accept the <a href="%s" target="_blank" class="wpi-terms-and-conditions-link">terms &amp; conditions</a>', 'invoicing' ), $terms_link ); ?></span> <span class="wpi-required">*</span>
1865
+                    <input type="checkbox" class="wpi-terms-checkbox" name="wpi_terms" id="wpi-terms" <?php checked(apply_filters('wpinv_terms_is_checked_default', isset($_POST['wpi_terms'])), true); ?>> <span><?php printf(__('I&rsquo;ve read and accept the <a href="%s" target="_blank" class="wpi-terms-and-conditions-link">terms &amp; conditions</a>', 'invoicing'), $terms_link); ?></span> <span class="wpi-required">*</span>
1866 1866
                 </label>
1867 1867
             <?php } ?>
1868 1868
         </div>
1869 1869
     </div>
1870 1870
     <?php
1871 1871
 }
1872
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_accept_tandc', 9995 );
1872
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_accept_tandc', 9995);
1873 1873
 
1874 1874
 function wpinv_checkout_submit() {
1875 1875
 ?>
1876 1876
 <div id="wpinv_purchase_submit" class="panel panel-success">
1877 1877
     <div class="panel-body text-center">
1878 1878
     <?php
1879
-    do_action( 'wpinv_purchase_form_before_submit' );
1879
+    do_action('wpinv_purchase_form_before_submit');
1880 1880
     wpinv_checkout_hidden_fields();
1881 1881
     echo wpinv_checkout_button_purchase();
1882
-    do_action( 'wpinv_purchase_form_after_submit' );
1882
+    do_action('wpinv_purchase_form_after_submit');
1883 1883
     ?>
1884 1884
     </div>
1885 1885
 </div>
1886 1886
 <?php
1887 1887
 }
1888
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 );
1888
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999);
1889 1889
 
1890
-function wpinv_receipt_billing_address( $invoice_id = 0 ) {
1891
-    $invoice = wpinv_get_invoice( $invoice_id );
1890
+function wpinv_receipt_billing_address($invoice_id = 0) {
1891
+    $invoice = wpinv_get_invoice($invoice_id);
1892 1892
 
1893
-    if ( empty( $invoice ) ) {
1893
+    if (empty($invoice)) {
1894 1894
         return NULL;
1895 1895
     }
1896 1896
 
1897 1897
     $billing_details = $invoice->get_user_info();
1898
-    $address_row = wpinv_get_invoice_address_markup( $billing_details );
1898
+    $address_row = wpinv_get_invoice_address_markup($billing_details);
1899 1899
 
1900 1900
     ob_start();
1901 1901
     ?>
1902 1902
     <table class="table table-bordered table-sm wpi-billing-details">
1903 1903
         <tbody>
1904 1904
             <tr class="wpi-receipt-name">
1905
-                <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th>
1906
-                <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td>
1905
+                <th class="text-left"><?php _e('Name', 'invoicing'); ?></th>
1906
+                <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td>
1907 1907
             </tr>
1908 1908
             <tr class="wpi-receipt-email">
1909
-                <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th>
1910
-                <td><?php echo $billing_details['email'] ;?></td>
1909
+                <th class="text-left"><?php _e('Email', 'invoicing'); ?></th>
1910
+                <td><?php echo $billing_details['email']; ?></td>
1911 1911
             </tr>
1912 1912
             <tr class="wpi-receipt-address">
1913
-                <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th>
1914
-                <td><?php echo $address_row ;?></td>
1913
+                <th class="text-left"><?php _e('Address', 'invoicing'); ?></th>
1914
+                <td><?php echo $address_row; ?></td>
1915 1915
             </tr>
1916
-            <?php if ( $billing_details['phone'] ) { ?>
1916
+            <?php if ($billing_details['phone']) { ?>
1917 1917
             <tr class="wpi-receipt-phone">
1918
-                <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th>
1919
-                <td><?php echo esc_html( $billing_details['phone'] ) ;?></td>
1918
+                <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th>
1919
+                <td><?php echo esc_html($billing_details['phone']); ?></td>
1920 1920
             </tr>
1921 1921
             <?php } ?>
1922 1922
         </tbody>
@@ -1924,74 +1924,74 @@  discard block
 block discarded – undo
1924 1924
     <?php
1925 1925
     $output = ob_get_clean();
1926 1926
     
1927
-    $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id );
1927
+    $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id);
1928 1928
 
1929 1929
     echo $output;
1930 1930
 }
1931 1931
 
1932
-function wpinv_filter_success_page_content( $content ) {
1933
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1934
-        if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) {
1935
-            $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content );
1932
+function wpinv_filter_success_page_content($content) {
1933
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1934
+        if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) {
1935
+            $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content);
1936 1936
         }
1937 1937
     }
1938 1938
 
1939 1939
     return $content;
1940 1940
 }
1941
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1941
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1942 1942
 
1943
-function wpinv_receipt_actions( $invoice ) {
1944
-    if ( !empty( $invoice ) ) {
1943
+function wpinv_receipt_actions($invoice) {
1944
+    if (!empty($invoice)) {
1945 1945
         $actions = array();
1946 1946
 
1947
-        if ( wpinv_user_can_view_invoice( $invoice->ID ) ) {
1948
-            $actions['print']   = array(
1949
-                'url'  => $invoice->get_view_url( true ),
1950
-                'name' => __( 'Print Invoice', 'invoicing' ),
1947
+        if (wpinv_user_can_view_invoice($invoice->ID)) {
1948
+            $actions['print'] = array(
1949
+                'url'  => $invoice->get_view_url(true),
1950
+                'name' => __('Print Invoice', 'invoicing'),
1951 1951
                 'class' => 'btn-primary',
1952 1952
             );
1953 1953
         }
1954 1954
 
1955
-        if ( is_user_logged_in() ) {
1955
+        if (is_user_logged_in()) {
1956 1956
             $actions['history'] = array(
1957 1957
                 'url'  => wpinv_get_history_page_uri(),
1958
-                'name' => __( 'Invoice History', 'invoicing' ),
1958
+                'name' => __('Invoice History', 'invoicing'),
1959 1959
                 'class' => 'btn-warning',
1960 1960
             );
1961 1961
         }
1962 1962
 
1963
-        $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice );
1963
+        $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice);
1964 1964
 
1965
-        if ( !empty( $actions ) ) {
1965
+        if (!empty($actions)) {
1966 1966
         ?>
1967 1967
         <div class="wpinv-receipt-actions text-right">
1968
-            <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?>
1969
-            <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>
1968
+            <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?>
1969
+            <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>
1970 1970
             <?php } ?>
1971 1971
         </div>
1972 1972
         <?php
1973 1973
         }
1974 1974
     }
1975 1975
 }
1976
-add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 );
1976
+add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1);
1977 1977
 
1978
-function wpinv_invoice_link( $invoice_id ) {
1979
-    $invoice = wpinv_get_invoice( $invoice_id );
1978
+function wpinv_invoice_link($invoice_id) {
1979
+    $invoice = wpinv_get_invoice($invoice_id);
1980 1980
 
1981
-    if ( empty( $invoice ) ) {
1981
+    if (empty($invoice)) {
1982 1982
         return NULL;
1983 1983
     }
1984 1984
 
1985
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1985
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1986 1986
 
1987
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1987
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1988 1988
 }
1989 1989
 
1990
-function wpinv_invoice_subscription_details( $invoice ) {
1991
-    if ( !empty( $invoice ) && $invoice->is_recurring() && ! wpinv_is_subscription_payment( $invoice ) ) {
1992
-        $subscription = wpinv_get_subscription( $invoice, true );
1990
+function wpinv_invoice_subscription_details($invoice) {
1991
+    if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) {
1992
+        $subscription = wpinv_get_subscription($invoice, true);
1993 1993
 
1994
-        if ( empty( $subscription ) ) {
1994
+        if (empty($subscription)) {
1995 1995
             return;
1996 1996
         }
1997 1997
 
@@ -2002,15 +2002,15 @@  discard block
 block discarded – undo
2002 2002
         $payments = $subscription->get_child_payments();
2003 2003
         ?>
2004 2004
         <div class="wpinv-subscriptions-details">
2005
-            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3>
2005
+            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3>
2006 2006
             <table class="table">
2007 2007
                 <thead>
2008 2008
                     <tr>
2009
-                        <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th>
2010
-                        <th><?php _e( 'Start Date', 'invoicing' ) ;?></th>
2011
-                        <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th>
2012
-                        <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th>
2013
-                        <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th>
2009
+                        <th><?php _e('Billing Cycle', 'invoicing'); ?></th>
2010
+                        <th><?php _e('Start Date', 'invoicing'); ?></th>
2011
+                        <th><?php _e('Expiration Date', 'invoicing'); ?></th>
2012
+                        <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th>
2013
+                        <th class="text-center"><?php _e('Status', 'invoicing'); ?></th>
2014 2014
                     </tr>
2015 2015
                 </thead>
2016 2016
                 <tbody>
@@ -2024,29 +2024,29 @@  discard block
 block discarded – undo
2024 2024
                 </tbody>
2025 2025
             </table>
2026 2026
         </div>
2027
-        <?php if ( !empty( $payments ) ) { ?>
2027
+        <?php if (!empty($payments)) { ?>
2028 2028
         <div class="wpinv-renewal-payments">
2029
-            <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3>
2029
+            <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3>
2030 2030
             <table class="table">
2031 2031
                 <thead>
2032 2032
                     <tr>
2033 2033
                         <th>#</th>
2034
-                        <th><?php _e( 'Invoice', 'invoicing' ) ;?></th>
2035
-                        <th><?php _e( 'Date', 'invoicing' ) ;?></th>
2036
-                        <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th>
2034
+                        <th><?php _e('Invoice', 'invoicing'); ?></th>
2035
+                        <th><?php _e('Date', 'invoicing'); ?></th>
2036
+                        <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th>
2037 2037
                     </tr>
2038 2038
                 </thead>
2039 2039
                 <tbody>
2040 2040
                     <?php
2041 2041
                         $i = 1;
2042
-                        foreach ( $payments as $payment ) {
2042
+                        foreach ($payments as $payment) {
2043 2043
                             $invoice_id = $payment->ID;
2044 2044
                     ?>
2045 2045
                     <tr>
2046
-                        <th scope="row"><?php echo $i;?></th>
2047
-                        <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td>
2048
-                        <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td>
2049
-                        <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td>
2046
+                        <th scope="row"><?php echo $i; ?></th>
2047
+                        <td><?php echo wpinv_invoice_link($invoice_id); ?></td>
2048
+                        <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td>
2049
+                        <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td>
2050 2050
                     </tr>
2051 2051
                     <?php $i++; } ?>
2052 2052
                 </tbody>
@@ -2057,52 +2057,52 @@  discard block
 block discarded – undo
2057 2057
     }
2058 2058
 }
2059 2059
 
2060
-function wpinv_cart_total_label( $label, $invoice ) {
2061
-    if ( empty( $invoice ) ) {
2060
+function wpinv_cart_total_label($label, $invoice) {
2061
+    if (empty($invoice)) {
2062 2062
         return $label;
2063 2063
     }
2064 2064
 
2065 2065
     $prefix_label = '';
2066
-    if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) {
2067
-        $prefix_label   = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice );
2068
-    } else if ( $invoice->is_renewal() ) {
2069
-        $prefix_label   = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> ';        
2066
+    if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) {
2067
+        $prefix_label   = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice);
2068
+    } else if ($invoice->is_renewal()) {
2069
+        $prefix_label   = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> ';        
2070 2070
     }
2071 2071
 
2072
-    if ( $prefix_label != '' ) {
2073
-        $label  = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2072
+    if ($prefix_label != '') {
2073
+        $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2074 2074
     }
2075 2075
 
2076 2076
     return $label;
2077 2077
 }
2078
-add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2079
-add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2080
-add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2078
+add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2079
+add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2080
+add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2081 2081
 
2082
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 );
2082
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1);
2083 2083
 
2084
-function wpinv_invoice_print_description( $invoice ) {
2085
-    if ( empty( $invoice ) ) {
2084
+function wpinv_invoice_print_description($invoice) {
2085
+    if (empty($invoice)) {
2086 2086
         return NULL;
2087 2087
     }
2088
-    if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) {
2088
+    if ($description = wpinv_get_invoice_description($invoice->ID)) {
2089 2089
         ?>
2090 2090
         <div class="row wpinv-lower">
2091 2091
             <div class="col-sm-12 wpinv-description">
2092
-                <?php echo wpautop( $description ); ?>
2092
+                <?php echo wpautop($description); ?>
2093 2093
             </div>
2094 2094
         </div>
2095 2095
         <?php
2096 2096
     }
2097 2097
 }
2098
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 );
2098
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1);
2099 2099
 
2100
-function wpinv_invoice_print_payment_info( $invoice ) {
2101
-    if ( empty( $invoice ) ) {
2100
+function wpinv_invoice_print_payment_info($invoice) {
2101
+    if (empty($invoice)) {
2102 2102
         return NULL;
2103 2103
     }
2104 2104
 
2105
-    if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) {
2105
+    if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) {
2106 2106
         ?>
2107 2107
         <div class="row wpinv-payments">
2108 2108
             <div class="col-sm-12">
@@ -2114,43 +2114,43 @@  discard block
 block discarded – undo
2114 2114
 }
2115 2115
 // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 );
2116 2116
 
2117
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
2118
-    if ( empty( $note ) ) {
2117
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
2118
+    if (empty($note)) {
2119 2119
         return NULL;
2120 2120
     }
2121 2121
 
2122
-    if ( is_int( $note ) ) {
2123
-        $note = get_comment( $note );
2122
+    if (is_int($note)) {
2123
+        $note = get_comment($note);
2124 2124
     }
2125 2125
 
2126
-    if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
2126
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
2127 2127
         return NULL;
2128 2128
     }
2129 2129
 
2130
-    $note_classes   = array( 'note' );
2131
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
2130
+    $note_classes   = array('note');
2131
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
2132 2132
     $note_classes[] = $note->comment_author === 'System' ? 'system-note' : '';
2133
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
2134
-    $note_classes   = !empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
2133
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
2134
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
2135 2135
 
2136 2136
     ob_start();
2137 2137
     ?>
2138
-    <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>">
2138
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>">
2139 2139
         <div class="note_content">
2140
-            <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
2140
+            <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?>
2141 2141
         </div>
2142 2142
         <p class="meta">
2143
-            <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;
2144
-            <?php if ( is_admin() && ( $note->comment_author !== 'System' || wpinv_current_user_can_manage_invoicing() ) ) { ?>
2145
-                <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a>
2143
+            <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;
2144
+            <?php if (is_admin() && ($note->comment_author !== 'System' || wpinv_current_user_can_manage_invoicing())) { ?>
2145
+                <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
2146 2146
             <?php } ?>
2147 2147
         </p>
2148 2148
     </li>
2149 2149
     <?php
2150 2150
     $note_content = ob_get_clean();
2151
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
2151
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
2152 2152
 
2153
-    if ( $echo ) {
2153
+    if ($echo) {
2154 2154
         echo $note_content;
2155 2155
     } else {
2156 2156
         return $note_content;
@@ -2160,43 +2160,43 @@  discard block
 block discarded – undo
2160 2160
 function wpinv_invalid_invoice_content() {
2161 2161
     global $post;
2162 2162
 
2163
-    $invoice = wpinv_get_invoice( $post->ID );
2163
+    $invoice = wpinv_get_invoice($post->ID);
2164 2164
 
2165
-    $error = __( 'This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing' );
2166
-    if ( !empty( $invoice->ID ) && $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) {
2167
-        if ( is_user_logged_in() ) {
2168
-            if ( wpinv_require_login_to_checkout() ) {
2169
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2170
-                    $error = __( 'You are not allowed to view this invoice.', 'invoicing' );
2165
+    $error = __('This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing');
2166
+    if (!empty($invoice->ID) && $invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) {
2167
+        if (is_user_logged_in()) {
2168
+            if (wpinv_require_login_to_checkout()) {
2169
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2170
+                    $error = __('You are not allowed to view this invoice.', 'invoicing');
2171 2171
                 }
2172 2172
             }
2173 2173
         } else {
2174
-            if ( wpinv_require_login_to_checkout() ) {
2175
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2176
-                    $error = __( 'You must be logged in to view this invoice.', 'invoicing' );
2174
+            if (wpinv_require_login_to_checkout()) {
2175
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2176
+                    $error = __('You must be logged in to view this invoice.', 'invoicing');
2177 2177
                 }
2178 2178
             }
2179 2179
         }
2180 2180
     } else {
2181
-        $error = __( 'This invoice is deleted or does not exist.', 'invoicing' );
2181
+        $error = __('This invoice is deleted or does not exist.', 'invoicing');
2182 2182
     }
2183 2183
     ?>
2184 2184
     <div class="row wpinv-row-invalid">
2185 2185
         <div class="col-md-6 col-md-offset-3 wpinv-message error">
2186
-            <h3><?php _e( 'Access Denied', 'invoicing' ); ?></h3>
2186
+            <h3><?php _e('Access Denied', 'invoicing'); ?></h3>
2187 2187
             <p class="wpinv-msg-text"><?php echo $error; ?></p>
2188 2188
         </div>
2189 2189
     </div>
2190 2190
     <?php
2191 2191
 }
2192
-add_action( 'wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content' );
2192
+add_action('wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content');
2193 2193
 
2194
-add_action( 'wpinv_checkout_billing_fields_last', 'wpinv_force_company_name_field');
2195
-function wpinv_force_company_name_field(){
2194
+add_action('wpinv_checkout_billing_fields_last', 'wpinv_force_company_name_field');
2195
+function wpinv_force_company_name_field() {
2196 2196
     $invoice = wpinv_get_invoice_cart();
2197
-    $user_id = wpinv_get_user_id( $invoice->ID );
2198
-    $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true );
2199
-    if ( 1 == wpinv_get_option( 'force_show_company' ) && !wpinv_use_taxes() ) {
2197
+    $user_id = wpinv_get_user_id($invoice->ID);
2198
+    $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true);
2199
+    if (1 == wpinv_get_option('force_show_company') && !wpinv_use_taxes()) {
2200 2200
         ?>
2201 2201
         <p class="wpi-cart-field wpi-col2 wpi-colf">
2202 2202
             <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label>
@@ -2222,21 +2222,21 @@  discard block
 block discarded – undo
2222 2222
  * @return string
2223 2223
  */
2224 2224
 function wpinv_get_policy_text() {
2225
-    $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 );
2225
+    $privacy_page_id = get_option('wp_page_for_privacy_policy', 0);
2226 2226
 
2227
-    $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' ));
2227
+    $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]'));
2228 2228
 
2229
-    if(!$privacy_page_id){
2230
-        $privacy_page_id = wpinv_get_option( 'privacy_page', 0 );
2229
+    if (!$privacy_page_id) {
2230
+        $privacy_page_id = wpinv_get_option('privacy_page', 0);
2231 2231
     }
2232 2232
 
2233
-    $privacy_link    = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' );
2233
+    $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing');
2234 2234
 
2235 2235
     $find_replace = array(
2236 2236
         '[wpinv_privacy_policy]' => $privacy_link,
2237 2237
     );
2238 2238
 
2239
-    $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text );
2239
+    $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text);
2240 2240
 
2241 2241
     return wp_kses_post(wpautop($privacy_text));
2242 2242
 }
@@ -2245,25 +2245,25 @@  discard block
 block discarded – undo
2245 2245
 /**
2246 2246
  * Allows the user to set their own price for an invoice item
2247 2247
  */
2248
-function wpinv_checkout_cart_item_name_your_price( $cart_item, $key ) {
2248
+function wpinv_checkout_cart_item_name_your_price($cart_item, $key) {
2249 2249
     
2250 2250
     //Ensure we have an item id
2251
-    if(! is_array( $cart_item ) || empty( $cart_item['id'] ) ) {
2251
+    if (!is_array($cart_item) || empty($cart_item['id'])) {
2252 2252
         return;
2253 2253
     }
2254 2254
 
2255 2255
     //Fetch the item
2256 2256
     $item_id = $cart_item['id'];
2257
-    $item    = new WPInv_Item( $item_id );
2257
+    $item    = new WPInv_Item($item_id);
2258 2258
     
2259
-    if(! $item->supports_dynamic_pricing() || !$item->get_is_dynamic_pricing() ) {
2259
+    if (!$item->supports_dynamic_pricing() || !$item->get_is_dynamic_pricing()) {
2260 2260
         return;
2261 2261
     }
2262 2262
 
2263 2263
     //Fetch the dynamic pricing "strings"
2264
-    $suggested_price_text = esc_html( wpinv_get_option( 'suggested_price_text', __( 'Suggested Price:', 'invoicing' ) ) );
2265
-    $minimum_price_text   = esc_html( wpinv_get_option( 'minimum_price_text', __( 'Minimum Price:', 'invoicing' ) ) );
2266
-    $name_your_price_text = esc_html( wpinv_get_option( 'name_your_price_text', __( 'Name Your Price', 'invoicing' ) ) );
2264
+    $suggested_price_text = esc_html(wpinv_get_option('suggested_price_text', __('Suggested Price:', 'invoicing')));
2265
+    $minimum_price_text   = esc_html(wpinv_get_option('minimum_price_text', __('Minimum Price:', 'invoicing')));
2266
+    $name_your_price_text = esc_html(wpinv_get_option('name_your_price_text', __('Name Your Price', 'invoicing')));
2267 2267
 
2268 2268
     //Display a "name_your_price" button
2269 2269
     echo " &mdash; <a href='#' class='wpinv-name-your-price-frontend small'>$name_your_price_text</a></div>";
@@ -2272,7 +2272,7 @@  discard block
 block discarded – undo
2272 2272
     echo '<div class="name-your-price-miniform">';
2273 2273
     
2274 2274
     //Maybe display the recommended price
2275
-    if( $item->get_price() > 0 && !empty( $suggested_price_text ) ) {
2275
+    if ($item->get_price() > 0 && !empty($suggested_price_text)) {
2276 2276
         $suggested_price = $item->get_the_price();
2277 2277
         echo "<div>$suggested_price_text &mdash; $suggested_price</div>";
2278 2278
     }
@@ -2280,50 +2280,50 @@  discard block
 block discarded – undo
2280 2280
     //Display the update price form
2281 2281
     $symbol         = wpinv_currency_symbol();
2282 2282
     $position       = wpinv_currency_position();
2283
-    $minimum        = esc_attr( $item->get_minimum_price() );
2284
-    $price          = esc_attr( $cart_item['item_price'] );
2285
-    $update         = esc_attr__( "Update", 'invoicing' );
2283
+    $minimum        = esc_attr($item->get_minimum_price());
2284
+    $price          = esc_attr($cart_item['item_price']);
2285
+    $update         = esc_attr__("Update", 'invoicing');
2286 2286
 
2287 2287
     //Ensure it supports dynamic prici
2288
-    if( $price < $minimum ) {
2288
+    if ($price < $minimum) {
2289 2289
         $price = $minimum;
2290 2290
     }
2291 2291
 
2292 2292
     echo '<label>';
2293 2293
     echo $position != 'right' ? $symbol . '&nbsp;' : '';
2294 2294
     echo "<input type='number' min='$minimum' placeholder='$price' value='$price' class='wpi-field-price' />";
2295
-    echo $position == 'right' ? '&nbsp;' . $symbol : '' ;
2295
+    echo $position == 'right' ? '&nbsp;' . $symbol : '';
2296 2296
     echo "</label>";
2297 2297
     echo "<input type='hidden' value='$item_id' class='wpi-field-item' />";
2298 2298
     echo "<a class='btn btn-success wpinv-submit wpinv-update-dynamic-price-frontend'>$update</a>";
2299 2299
 
2300 2300
     //Maybe display the minimum price
2301
-    if( $item->get_minimum_price() > 0 && !empty( $minimum_price_text ) ) {
2302
-        $minimum_price = wpinv_price( wpinv_format_amount( $item->get_minimum_price() ) );
2301
+    if ($item->get_minimum_price() > 0 && !empty($minimum_price_text)) {
2302
+        $minimum_price = wpinv_price(wpinv_format_amount($item->get_minimum_price()));
2303 2303
         echo "<div>$minimum_price_text &mdash; $minimum_price</div>";
2304 2304
     }
2305 2305
 
2306 2306
     echo "</div>";
2307 2307
 
2308 2308
 }
2309
-add_action( 'wpinv_checkout_cart_item_price_after', 'wpinv_checkout_cart_item_name_your_price', 10, 2 );
2309
+add_action('wpinv_checkout_cart_item_price_after', 'wpinv_checkout_cart_item_name_your_price', 10, 2);
2310 2310
 
2311 2311
 function wpinv_oxygen_fix_conflict() {
2312 2312
     global $ct_ignore_post_types;
2313 2313
 
2314
-    if ( ! is_array( $ct_ignore_post_types ) ) {
2314
+    if (!is_array($ct_ignore_post_types)) {
2315 2315
         $ct_ignore_post_types = array();
2316 2316
     }
2317 2317
 
2318
-    $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item' );
2318
+    $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item');
2319 2319
 
2320
-    foreach ( $post_types as $post_type ) {
2320
+    foreach ($post_types as $post_type) {
2321 2321
         $ct_ignore_post_types[] = $post_type;
2322 2322
 
2323 2323
         // Ignore post type
2324
-        add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 );
2324
+        add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999);
2325 2325
     }
2326 2326
 
2327
-    remove_filter( 'template_include', 'wpinv_template', 10, 1 );
2328
-    add_filter( 'template_include', 'wpinv_template', 999, 1 );
2327
+    remove_filter('template_include', 'wpinv_template', 10, 1);
2328
+    add_filter('template_include', 'wpinv_template', 999, 1);
2329 2329
 }
Please login to merge, or discard this patch.
widgets/payment-form.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) {
3
+if (!defined('ABSPATH')) {
4 4
     exit; // Exit if accessed directly
5 5
 }
6 6
 
@@ -22,16 +22,16 @@  discard block
 block discarded – undo
22 22
 				'orderby'        => 'title',
23 23
 				'order'          => 'ASC',
24 24
 				'posts_per_page' => -1,
25
-				'post_status'    => array( 'publish' ),
25
+				'post_status'    => array('publish'),
26 26
 			)
27 27
 		);
28 28
 
29 29
 		$options = array(
30
-			'' => __('Select a Form','invoicing')
30
+			'' => __('Select a Form', 'invoicing')
31 31
 		);
32 32
 
33
-		foreach( $forms as $form ) {
34
-			$options[ $form->ID ] = $form->post_title;
33
+		foreach ($forms as $form) {
34
+			$options[$form->ID] = $form->post_title;
35 35
 		}
36 36
 
37 37
         $options = array(
@@ -41,15 +41,15 @@  discard block
 block discarded – undo
41 41
             'block-keywords'=> "['invoicing','buy', 'buy item', 'pay', 'payment form']",
42 42
             'class_name'     => __CLASS__,
43 43
             'base_id'       => 'wpinv_payment_form',
44
-            'name'          => __('Invoicing > Payment Form','invoicing'),
44
+            'name'          => __('Invoicing > Payment Form', 'invoicing'),
45 45
             'widget_ops'    => array(
46 46
                 'classname'   => 'wpinv-payment-form-class bsui',
47
-                'description' => esc_html__('Displays a payment form.','invoicing'),
47
+                'description' => esc_html__('Displays a payment form.', 'invoicing'),
48 48
             ),
49 49
             'arguments'           => array(
50 50
                 'form'            => array(
51
-                    'title'       => __( 'Payment Form', 'invoicing' ),
52
-                    'desc'        => __( 'Select your payment form.', 'invoicing' ),
51
+                    'title'       => __('Payment Form', 'invoicing'),
52
+                    'desc'        => __('Select your payment form.', 'invoicing'),
53 53
 					'type'        => 'select',
54 54
 					'options'     =>  $options,
55 55
                     'desc_tip'    => true,
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
         );
62 62
 
63 63
 
64
-        parent::__construct( $options );
64
+        parent::__construct($options);
65 65
     }
66 66
 
67 67
 	/**
@@ -73,43 +73,43 @@  discard block
 block discarded – undo
73 73
 	 *
74 74
 	 * @return string
75 75
 	 */
76
-    public function output( $args = array(), $widget_args = array(), $content = '' ) {
76
+    public function output($args = array(), $widget_args = array(), $content = '') {
77 77
 		global $invoicing;
78 78
 
79 79
 		// Do we have a payment form?
80
-		if ( empty( $args['form'] ) ) {
80
+		if (empty($args['form'])) {
81 81
 			return aui()->alert(
82 82
 				array(
83 83
 					'type'    => 'warning',
84
-					'content' => __( 'No payment form selected', 'invoicing' ),
84
+					'content' => __('No payment form selected', 'invoicing'),
85 85
 				)
86 86
 			);
87 87
 
88 88
 		}
89 89
 
90 90
 		// If yes, ensure that it is published.
91
-		if ( 'publish' != get_post_status( $args['form'] ) ) {
91
+		if ('publish' != get_post_status($args['form'])) {
92 92
 			return aui()->alert(
93 93
 				array(
94 94
 					'type'    => 'warning',
95
-					'content' => __( 'This payment form is no longer active', 'invoicing' ),
95
+					'content' => __('This payment form is no longer active', 'invoicing'),
96 96
 				)
97 97
 			);
98 98
 		}
99 99
 
100 100
 		// Get the form elements and items.
101
-		$elements = $invoicing->form_elements->get_form_elements( $args['form'] );
102
-		$items    = $invoicing->form_elements->get_form_items( $args['form'] );
101
+		$elements = $invoicing->form_elements->get_form_elements($args['form']);
102
+		$items    = $invoicing->form_elements->get_form_items($args['form']);
103 103
 
104 104
 		ob_start();
105 105
 		echo "<form class='wpinv_payment_form'>";
106 106
 		echo "<input type='hidden' name='form_id' value='{$args['form']}'/>";
107
-		wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' );
108
-		wp_nonce_field( 'vat_validation', '_wpi_nonce' );
107
+		wp_nonce_field('wpinv_payment_form', 'wpinv_payment_form');
108
+		wp_nonce_field('vat_validation', '_wpi_nonce');
109 109
 
110
-		foreach ( $elements as $element ) {
111
-			do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $args['form'] );
112
-			do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $args['form'] );
110
+		foreach ($elements as $element) {
111
+			do_action('wpinv_frontend_render_payment_form_element', $element, $items, $args['form']);
112
+			do_action("wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $args['form']);
113 113
 		}
114 114
 
115 115
 		echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>";
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 
118 118
 		$content = ob_get_clean();
119 119
 		
120
-		return str_replace( 'sr-only', '', $content );
120
+		return str_replace('sr-only', '', $content);
121 121
 
122 122
     }
123 123
 
Please login to merge, or discard this patch.
includes/libraries/wpinv-euvat/class-wpinv-euvat.php 1 patch
Spacing   +725 added lines, -725 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  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 5
 class WPInv_EUVat {
6 6
     private static $is_ajax = false;
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
     private static $instance = false;
9 9
     
10 10
     public static function get_instance() {
11
-        if ( !self::$instance ) {
11
+        if (!self::$instance) {
12 12
             self::$instance = new self();
13 13
             self::$instance->actions();
14 14
         }
@@ -17,137 +17,137 @@  discard block
 block discarded – undo
17 17
     }
18 18
     
19 19
     public function __construct() {
20
-        self::$is_ajax          = defined( 'DOING_AJAX' ) && DOING_AJAX;
20
+        self::$is_ajax          = defined('DOING_AJAX') && DOING_AJAX;
21 21
         self::$default_country  = wpinv_get_default_country();
22 22
     }
23 23
     
24 24
     public static function actions() {
25
-        if ( is_admin() ) {
26
-            add_action( 'admin_enqueue_scripts', array( self::$instance, 'enqueue_admin_scripts' ) );
27
-            add_action( 'wpinv_settings_sections_taxes', array( self::$instance, 'section_vat_settings' ) ); 
28
-            add_action( 'wpinv_settings_taxes', array( self::$instance, 'vat_settings' ) );
29
-            add_filter( 'wpinv_settings_taxes-vat_sanitize', array( self::$instance, 'sanitize_vat_settings' ) );
30
-            add_filter( 'wpinv_settings_taxes-vat_rates_sanitize', array( self::$instance, 'sanitize_vat_rates' ) );
31
-            add_action( 'wp_ajax_wpinv_add_vat_class', array( self::$instance, 'add_class' ) );
32
-            add_action( 'wp_ajax_nopriv_wpinv_add_vat_class', array( self::$instance, 'add_class' ) );
33
-            add_action( 'wp_ajax_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) );
34
-            add_action( 'wp_ajax_nopriv_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) );
35
-            add_action( 'wp_ajax_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) );
36
-            add_action( 'wp_ajax_nopriv_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) );
37
-            add_action( 'wp_ajax_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) );
38
-            add_action( 'wp_ajax_nopriv_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) );
39
-        }
40
-        
41
-        add_action( 'wp_enqueue_scripts', array( self::$instance, 'enqueue_vat_scripts' ) );
42
-        add_filter( 'wpinv_default_billing_country', array( self::$instance, 'get_user_country' ), 10 );
43
-        add_filter( 'wpinv_get_user_country', array( self::$instance, 'set_user_country' ), 10 );
44
-        add_action( 'wp_ajax_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) );
45
-        add_action( 'wp_ajax_nopriv_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) );
46
-        add_action( 'wp_ajax_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) );
47
-        add_action( 'wp_ajax_nopriv_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) );
48
-        add_action( 'wpinv_invoice_print_after_line_items', array( self::$instance, 'show_vat_notice' ), 999, 1 );
49
-        if ( wpinv_use_taxes() ) {
50
-            add_action( 'wpinv_after_billing_fields', array( self::$instance, 'checkout_vat_fields' ) );
51
-            if ( self::allow_vat_rules() ) {
52
-                add_action( 'wpinv_checkout_error_checks', array( self::$instance, 'checkout_vat_validate' ), 10, 2 );
53
-                add_filter( 'wpinv_tax_rate', array( self::$instance, 'get_rate' ), 10, 4 );
25
+        if (is_admin()) {
26
+            add_action('admin_enqueue_scripts', array(self::$instance, 'enqueue_admin_scripts'));
27
+            add_action('wpinv_settings_sections_taxes', array(self::$instance, 'section_vat_settings')); 
28
+            add_action('wpinv_settings_taxes', array(self::$instance, 'vat_settings'));
29
+            add_filter('wpinv_settings_taxes-vat_sanitize', array(self::$instance, 'sanitize_vat_settings'));
30
+            add_filter('wpinv_settings_taxes-vat_rates_sanitize', array(self::$instance, 'sanitize_vat_rates'));
31
+            add_action('wp_ajax_wpinv_add_vat_class', array(self::$instance, 'add_class'));
32
+            add_action('wp_ajax_nopriv_wpinv_add_vat_class', array(self::$instance, 'add_class'));
33
+            add_action('wp_ajax_wpinv_delete_vat_class', array(self::$instance, 'delete_class'));
34
+            add_action('wp_ajax_nopriv_wpinv_delete_vat_class', array(self::$instance, 'delete_class'));
35
+            add_action('wp_ajax_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates'));
36
+            add_action('wp_ajax_nopriv_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates'));
37
+            add_action('wp_ajax_wpinv_geoip2', array(self::$instance, 'geoip2_download_database'));
38
+            add_action('wp_ajax_nopriv_wpinv_geoip2', array(self::$instance, 'geoip2_download_database'));
39
+        }
40
+        
41
+        add_action('wp_enqueue_scripts', array(self::$instance, 'enqueue_vat_scripts'));
42
+        add_filter('wpinv_default_billing_country', array(self::$instance, 'get_user_country'), 10);
43
+        add_filter('wpinv_get_user_country', array(self::$instance, 'set_user_country'), 10);
44
+        add_action('wp_ajax_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate'));
45
+        add_action('wp_ajax_nopriv_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate'));
46
+        add_action('wp_ajax_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset'));
47
+        add_action('wp_ajax_nopriv_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset'));
48
+        add_action('wpinv_invoice_print_after_line_items', array(self::$instance, 'show_vat_notice'), 999, 1);
49
+        if (wpinv_use_taxes()) {
50
+            add_action('wpinv_after_billing_fields', array(self::$instance, 'checkout_vat_fields'));
51
+            if (self::allow_vat_rules()) {
52
+                add_action('wpinv_checkout_error_checks', array(self::$instance, 'checkout_vat_validate'), 10, 2);
53
+                add_filter('wpinv_tax_rate', array(self::$instance, 'get_rate'), 10, 4);
54 54
             }
55 55
         }
56 56
     }        
57 57
     
58
-    public static function get_eu_states( $sort = true ) {
59
-        $eu_states = array( 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE' );
60
-        if ( $sort ) {
61
-            $sort = sort( $eu_states );
58
+    public static function get_eu_states($sort = true) {
59
+        $eu_states = array('AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE');
60
+        if ($sort) {
61
+            $sort = sort($eu_states);
62 62
         }
63 63
         
64
-        return apply_filters( 'wpinv_get_eu_states', $eu_states, $sort );
64
+        return apply_filters('wpinv_get_eu_states', $eu_states, $sort);
65 65
     }
66 66
     
67
-    public static function get_gst_countries( $sort = true ) {
68
-        $gst_countries  = array( 'AU', 'NZ', 'CA', 'CN' );
67
+    public static function get_gst_countries($sort = true) {
68
+        $gst_countries = array('AU', 'NZ', 'CA', 'CN');
69 69
         
70
-        if ( $sort ) {
71
-            $sort = sort( $gst_countries );
70
+        if ($sort) {
71
+            $sort = sort($gst_countries);
72 72
         }
73 73
         
74
-        return apply_filters( 'wpinv_get_gst_countries', $gst_countries, $sort );
74
+        return apply_filters('wpinv_get_gst_countries', $gst_countries, $sort);
75 75
     }
76 76
     
77
-    public static function is_eu_state( $country_code ) {
78
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_eu_states() ) ? true : false;
77
+    public static function is_eu_state($country_code) {
78
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_eu_states()) ? true : false;
79 79
                 
80
-        return apply_filters( 'wpinv_is_eu_state', $return, $country_code );
80
+        return apply_filters('wpinv_is_eu_state', $return, $country_code);
81 81
     }
82 82
     
83
-    public static function is_gst_country( $country_code ) {
84
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_gst_countries() ) ? true : false;
83
+    public static function is_gst_country($country_code) {
84
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_gst_countries()) ? true : false;
85 85
                 
86
-        return apply_filters( 'wpinv_is_gst_country', $return, $country_code );
86
+        return apply_filters('wpinv_is_gst_country', $return, $country_code);
87 87
     }
88 88
     
89 89
     public static function enqueue_vat_scripts() {
90
-        if( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ) {
90
+        if (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules')) {
91 91
             self::load_vat_scripts();
92 92
         }
93 93
     }
94 94
 
95
-    public static function load_vat_scripts(){
96
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
95
+    public static function load_vat_scripts() {
96
+        $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
97 97
 
98
-        wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
99
-        wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
98
+        wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
99
+        wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
100 100
 
101
-        $vat_name   = self::get_vat_name();
101
+        $vat_name = self::get_vat_name();
102 102
 
103 103
         $vars = array();
104 104
         $vars['UseTaxes'] = wpinv_use_taxes();
105 105
         $vars['EUStates'] = self::get_eu_states();
106
-        $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' );
107
-        $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' );
108
-        $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
109
-        $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name );
110
-        $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name );
111
-        $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name );
112
-        $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name );
113
-        $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' );
106
+        $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing');
107
+        $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing');
108
+        $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
109
+        $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name);
110
+        $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name);
111
+        $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name);
112
+        $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name);
113
+        $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing');
114 114
         $vars['ApplyVATRules'] = $vars['UseTaxes'] ? self::allow_vat_rules() : false;
115 115
         $vars['HideVatFields'] = $vars['ApplyVATRules'] ? self::hide_vat_fields() : true;
116
-        $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' );
117
-        $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' );
118
-        $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' );
119
-        $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' );
120
-        $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' );
121
-        $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' );
122
-        $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' );
123
-        $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' );
124
-        $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name );
125
-        $vars['VatReseting'] = __( 'Reseting...', 'invoicing' );
126
-        $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
127
-        $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
128
-        $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' );
116
+        $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing');
117
+        $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing');
118
+        $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing');
119
+        $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing');
120
+        $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing');
121
+        $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing');
122
+        $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing');
123
+        $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing');
124
+        $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name);
125
+        $vars['VatReseting'] = __('Reseting...', 'invoicing');
126
+        $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
127
+        $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
128
+        $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing');
129 129
         $vars['isFront'] = is_admin() ? false : true;
130 130
         $vars['baseCountry'] = wpinv_get_default_country();
131
-        $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false );
132
-        $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false;
131
+        $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false);
132
+        $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false;
133 133
 
134
-        wp_enqueue_script( 'wpinv-vat-validation-script' );
135
-        wp_enqueue_script( 'wpinv-vat-script' );
136
-        wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars );
134
+        wp_enqueue_script('wpinv-vat-validation-script');
135
+        wp_enqueue_script('wpinv-vat-script');
136
+        wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars);
137 137
     }
138 138
 
139 139
     public static function enqueue_admin_scripts() {
140
-        if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) {
140
+        if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) {
141 141
             self::load_vat_scripts();
142 142
         }
143 143
     }
144 144
     
145
-    public static function section_vat_settings( $sections ) {
146
-        if ( !empty( $sections ) ) {
147
-            $sections['vat'] = __( 'EU VAT Settings', 'invoicing' );
145
+    public static function section_vat_settings($sections) {
146
+        if (!empty($sections)) {
147
+            $sections['vat'] = __('EU VAT Settings', 'invoicing');
148 148
             
149
-            if ( self::allow_vat_classes() ) {
150
-                $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' );
149
+            if (self::allow_vat_classes()) {
150
+                $sections['vat_rates'] = __('EU VAT Rates', 'invoicing');
151 151
             }
152 152
         }
153 153
         return $sections;
@@ -156,52 +156,52 @@  discard block
 block discarded – undo
156 156
     public static function vat_rates_settings() {
157 157
         $vat_classes = self::get_rate_classes();
158 158
         $vat_rates = array();
159
-        $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new';
160
-        $current_url = remove_query_arg( 'wpi_sub' );
159
+        $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new';
160
+        $current_url = remove_query_arg('wpi_sub');
161 161
         
162 162
         $vat_rates['vat_rates_header'] = array(
163 163
             'id' => 'vat_rates_header',
164
-            'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>',
164
+            'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>',
165 165
             'desc' => '',
166 166
             'type' => 'header',
167 167
             'size' => 'regular'
168 168
         );
169 169
         $vat_rates['vat_rates_class'] = array(
170 170
             'id'          => 'vat_rates_class',
171
-            'name'        => __( 'Edit VAT Rates', 'invoicing' ),
172
-            'desc'        => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ),
171
+            'name'        => __('Edit VAT Rates', 'invoicing'),
172
+            'desc'        => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'),
173 173
             'type'        => 'select',
174
-            'options'     => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ),
175
-            'placeholder' => __( 'Select a VAT Rate', 'invoicing' ),
174
+            'options'     => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))),
175
+            'placeholder' => __('Select a VAT Rate', 'invoicing'),
176 176
             'selected'    => $vat_class,
177 177
             'class'       => 'wpi_select2',
178 178
             'onchange'    => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;',
179 179
         );
180 180
         
181
-        if ( $vat_class != '_standard' && $vat_class != '_new' ) {
181
+        if ($vat_class != '_standard' && $vat_class != '_new') {
182 182
             $vat_rates['vat_rate_delete'] = array(
183 183
                 'id'   => 'vat_rate_delete',
184 184
                 'type' => 'vat_rate_delete',
185 185
             );
186 186
         }
187 187
                     
188
-        if ( $vat_class == '_new' ) {
188
+        if ($vat_class == '_new') {
189 189
             $vat_rates['vat_rates_settings'] = array(
190 190
                 'id' => 'vat_rates_settings',
191
-                'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>',
191
+                'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>',
192 192
                 'type' => 'header',
193 193
             );
194 194
             $vat_rates['vat_rate_name'] = array(
195 195
                 'id'   => 'vat_rate_name',
196
-                'name' => __( 'Name', 'invoicing' ),
197
-                'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ),
196
+                'name' => __('Name', 'invoicing'),
197
+                'desc' => __('A short name for the new VAT Rate class', 'invoicing'),
198 198
                 'type' => 'text',
199 199
                 'size' => 'regular',
200 200
             );
201 201
             $vat_rates['vat_rate_desc'] = array(
202 202
                 'id'   => 'vat_rate_desc',
203
-                'name' => __( 'Description', 'invoicing' ),
204
-                'desc' => __( 'Manage VAT Rate class', 'invoicing' ),
203
+                'name' => __('Description', 'invoicing'),
204
+                'desc' => __('Manage VAT Rate class', 'invoicing'),
205 205
                 'type' => 'text',
206 206
                 'size' => 'regular',
207 207
             );
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
             $vat_rates['vat_rates'] = array(
214 214
                 'id'   => 'vat_rates',
215 215
                 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>',
216
-                'desc' => self::get_class_desc( $vat_class ),
216
+                'desc' => self::get_class_desc($vat_class),
217 217
                 'type' => 'vat_rates',
218 218
             );
219 219
         }
@@ -221,12 +221,12 @@  discard block
 block discarded – undo
221 221
         return $vat_rates;
222 222
     }
223 223
     
224
-    public static function vat_settings( $settings ) {
225
-        if ( !empty( $settings ) ) {    
224
+    public static function vat_settings($settings) {
225
+        if (!empty($settings)) {    
226 226
             $vat_settings = array();
227 227
             $vat_settings['vat_company_title'] = array(
228 228
                 'id' => 'vat_company_title',
229
-                'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>',
229
+                'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>',
230 230
                 'desc' => '',
231 231
                 'type' => 'header',
232 232
                 'size' => 'regular'
@@ -234,22 +234,22 @@  discard block
 block discarded – undo
234 234
             
235 235
             $vat_settings['vat_company_name'] = array(
236 236
                 'id' => 'vat_company_name',
237
-                'name' => __( 'Your Company Name', 'invoicing' ),
238
-                'desc' => wp_sprintf(__( 'Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
237
+                'name' => __('Your Company Name', 'invoicing'),
238
+                'desc' => wp_sprintf(__('Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
239 239
                 'type' => 'text',
240 240
                 'size' => 'regular',
241 241
             );
242 242
             
243 243
             $vat_settings['vat_number'] = array(
244 244
                 'id'   => 'vat_number',
245
-                'name' => __( 'Your VAT Number', 'invoicing' ),
245
+                'name' => __('Your VAT Number', 'invoicing'),
246 246
                 'type' => 'vat_number',
247 247
                 'size' => 'regular',
248 248
             );
249 249
 
250 250
             $vat_settings['vat_settings_title'] = array(
251 251
                 'id' => 'vat_settings_title',
252
-                'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>',
252
+                'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>',
253 253
                 'desc' => '',
254 254
                 'type' => 'header',
255 255
                 'size' => 'regular'
@@ -257,8 +257,8 @@  discard block
 block discarded – undo
257 257
 
258 258
             $vat_settings['apply_vat_rules'] = array(
259 259
                 'id' => 'apply_vat_rules',
260
-                'name' => __( 'Enable VAT Rules', 'invoicing' ),
261
-                'desc' => __( 'Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable unless you know what you are doing.', 'invoicing' ) . '</font>',
260
+                'name' => __('Enable VAT Rules', 'invoicing'),
261
+                'desc' => __('Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable unless you know what you are doing.', 'invoicing') . '</font>',
262 262
                 'type' => 'checkbox',
263 263
                 'std' => '1'
264 264
             );
@@ -274,8 +274,8 @@  discard block
 block discarded – undo
274 274
 
275 275
             $vat_settings['vat_prevent_b2c_purchase'] = array(
276 276
                 'id' => 'vat_prevent_b2c_purchase',
277
-                'name' => __( 'Prevent EU B2C Sales', 'invoicing' ),
278
-                'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ),
277
+                'name' => __('Prevent EU B2C Sales', 'invoicing'),
278
+                'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'),
279 279
                 'type' => 'checkbox'
280 280
             );
281 281
 
@@ -283,22 +283,22 @@  discard block
 block discarded – undo
283 283
 
284 284
             $vat_settings['vat_same_country_rule'] = array(
285 285
                 'id'          => 'vat_same_country_rule',
286
-                'name'        => __( 'Same Country Rule', 'invoicing' ),
287
-                'desc'        => __( 'Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing' ),
286
+                'name'        => __('Same Country Rule', 'invoicing'),
287
+                'desc'        => __('Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing'),
288 288
                 'type'        => 'select',
289 289
                 'options'     => array(
290
-                    ''          => __( 'Normal', 'invoicing' ),
291
-                    'no'        => __( 'No VAT', 'invoicing' ),
292
-                    'always'    => __( 'Always apply VAT', 'invoicing' ),
290
+                    ''          => __('Normal', 'invoicing'),
291
+                    'no'        => __('No VAT', 'invoicing'),
292
+                    'always'    => __('Always apply VAT', 'invoicing'),
293 293
                 ),
294
-                'placeholder' => __( 'Select an option', 'invoicing' ),
294
+                'placeholder' => __('Select an option', 'invoicing'),
295 295
                 'std'         => '',
296 296
                 'class'   => 'wpi_select2',
297 297
             );
298 298
 
299 299
             $vat_settings['vat_checkout_title'] = array(
300 300
                 'id' => 'vat_checkout_title',
301
-                'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>',
301
+                'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>',
302 302
                 'desc' => '',
303 303
                 'type' => 'header',
304 304
                 'size' => 'regular'
@@ -306,14 +306,14 @@  discard block
 block discarded – undo
306 306
 
307 307
             $vat_settings['vat_disable_fields'] = array(
308 308
                 'id' => 'vat_disable_fields',
309
-                'name' => __( 'Disable VAT Fields', 'invoicing' ),
310
-                'desc' => __( 'Disable VAT fields if Invoicing is being used for GST.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing' ) . '</font>',
309
+                'name' => __('Disable VAT Fields', 'invoicing'),
310
+                'desc' => __('Disable VAT fields if Invoicing is being used for GST.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing') . '</font>',
311 311
                 'type' => 'checkbox'
312 312
             );
313 313
 
314 314
             $vat_settings['vat_ip_lookup'] = array(
315 315
                 'id'   => 'vat_ip_lookup',
316
-                'name' => __( 'IP Country Look-up', 'invoicing' ),
316
+                'name' => __('IP Country Look-up', 'invoicing'),
317 317
                 'type' => 'vat_ip_lookup',
318 318
                 'size' => 'regular',
319 319
                 'std' => 'default',
@@ -322,21 +322,21 @@  discard block
 block discarded – undo
322 322
 
323 323
             $vat_settings['hide_ip_address'] = array(
324 324
                 'id' => 'hide_ip_address',
325
-                'name' => __( 'Hide IP Info at Checkout', 'invoicing' ),
326
-                'desc' => __( 'Hide the user IP info at checkout.', 'invoicing' ),
325
+                'name' => __('Hide IP Info at Checkout', 'invoicing'),
326
+                'desc' => __('Hide the user IP info at checkout.', 'invoicing'),
327 327
                 'type' => 'checkbox'
328 328
             );
329 329
 
330 330
             $vat_settings['vat_ip_country_default'] = array(
331 331
                 'id' => 'vat_ip_country_default',
332
-                'name' => __( 'Enable IP Country as Default', 'invoicing' ),
333
-                'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ),
332
+                'name' => __('Enable IP Country as Default', 'invoicing'),
333
+                'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'),
334 334
                 'type' => 'checkbox'
335 335
             );
336 336
 
337 337
             $vat_settings['vies_validation_title'] = array(
338 338
                 'id' => 'vies_validation_title',
339
-                'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>',
339
+                'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>',
340 340
                 'desc' => '',
341 341
                 'type' => 'header',
342 342
                 'size' => 'regular'
@@ -344,37 +344,37 @@  discard block
 block discarded – undo
344 344
 
345 345
             $vat_settings['vat_vies_check'] = array(
346 346
                 'id' => 'vat_vies_check',
347
-                'name' => __( 'Disable VIES VAT ID Check', 'invoicing' ),
348
-                'desc' => wp_sprintf( __( 'Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
347
+                'name' => __('Disable VIES VAT ID Check', 'invoicing'),
348
+                'desc' => wp_sprintf(__('Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
349 349
                 'type' => 'checkbox'
350 350
             );
351 351
 
352 352
             $vat_settings['vat_disable_company_name_check'] = array(
353 353
                 'id' => 'vat_disable_company_name_check',
354
-                'name' => __( 'Disable VIES Name Check', 'invoicing' ),
355
-                'desc' => wp_sprintf( __( 'Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
354
+                'name' => __('Disable VIES Name Check', 'invoicing'),
355
+                'desc' => wp_sprintf(__('Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
356 356
                 'type' => 'checkbox'
357 357
             );
358 358
 
359 359
             $vat_settings['vat_offline_check'] = array(
360 360
                 'id' => 'vat_offline_check',
361
-                'name' => __( 'Disable Basic Checks', 'invoicing' ),
362
-                'desc' => __( 'Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing' ),
361
+                'name' => __('Disable Basic Checks', 'invoicing'),
362
+                'desc' => __('Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing'),
363 363
                 'type' => 'checkbox'
364 364
             );
365 365
             
366 366
 
367 367
             $settings['vat'] = $vat_settings;
368 368
             
369
-            if ( self::allow_vat_classes() ) {
369
+            if (self::allow_vat_classes()) {
370 370
                 $settings['vat_rates'] = self::vat_rates_settings();
371 371
             }
372 372
             
373 373
             $eu_fallback_rate = array(
374 374
                 'id'   => 'eu_fallback_rate',
375
-                'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>',
375
+                'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>',
376 376
                 'type' => 'eu_fallback_rate',
377
-                'desc' => __( 'Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing' ),
377
+                'desc' => __('Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing'),
378 378
                 'std'  => '20',
379 379
                 'size' => 'small'
380 380
             );
@@ -390,11 +390,11 @@  discard block
 block discarded – undo
390 390
         $database_url       = 'http' . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on' ? 's' : '') . '://geolite.maxmind.com/download/geoip/database/';
391 391
         $destination_dir    = $upload_dir['basedir'] . '/invoicing';
392 392
         
393
-        if ( !is_dir( $destination_dir ) ) { 
394
-            mkdir( $destination_dir );
393
+        if (!is_dir($destination_dir)) { 
394
+            mkdir($destination_dir);
395 395
         }
396 396
         
397
-        $database_files     = array(
397
+        $database_files = array(
398 398
             'country'   => array(
399 399
                 'source'        => $database_url . 'GeoLite2-Country.mmdb.gz',
400 400
                 'destination'   => $destination_dir . '/GeoLite2-Country.mmdb',
@@ -405,57 +405,57 @@  discard block
 block discarded – undo
405 405
             )
406 406
         );
407 407
 
408
-        foreach( $database_files as $database => $files ) {
409
-            $result = self::geoip2_download_file( $files['source'], $files['destination'] );
408
+        foreach ($database_files as $database => $files) {
409
+            $result = self::geoip2_download_file($files['source'], $files['destination']);
410 410
             
411
-            if ( empty( $result['success'] ) ) {
411
+            if (empty($result['success'])) {
412 412
                 echo $result['message'];
413 413
                 exit;
414 414
             }
415 415
             
416
-            wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) );
417
-            echo sprintf(__( 'GeoIP2 %s database updated successfully.', 'invoicing' ), $database ) . ' ';
416
+            wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp'));
417
+            echo sprintf(__('GeoIP2 %s database updated successfully.', 'invoicing'), $database) . ' ';
418 418
         }
419 419
         
420 420
         exit;
421 421
     }
422 422
     
423
-    public static function geoip2_download_file( $source_url, $destination_file ) {
423
+    public static function geoip2_download_file($source_url, $destination_file) {
424 424
         $success    = false;
425 425
         $message    = '';
426 426
         
427
-        if ( !function_exists( 'download_url' ) ) {
428
-            require_once( ABSPATH . 'wp-admin/includes/file.php' );
427
+        if (!function_exists('download_url')) {
428
+            require_once(ABSPATH . 'wp-admin/includes/file.php');
429 429
         }
430 430
 
431
-        $temp_file  = download_url( $source_url );
431
+        $temp_file = download_url($source_url);
432 432
         
433
-        if ( is_wp_error( $temp_file ) ) {
434
-            $message = sprintf( __( 'Error while downloading GeoIp2 database( %s ): %s', 'invoicing' ), $source_url, $temp_file->get_error_message() );
433
+        if (is_wp_error($temp_file)) {
434
+            $message = sprintf(__('Error while downloading GeoIp2 database( %s ): %s', 'invoicing'), $source_url, $temp_file->get_error_message());
435 435
         } else {
436
-            $handle = gzopen( $temp_file, 'rb' );
436
+            $handle = gzopen($temp_file, 'rb');
437 437
             
438
-            if ( $handle ) {
439
-                $fopen  = fopen( $destination_file, 'wb' );
440
-                if ( $fopen ) {
441
-                    while ( ( $data = gzread( $handle, 4096 ) ) != false ) {
442
-                        fwrite( $fopen, $data );
438
+            if ($handle) {
439
+                $fopen = fopen($destination_file, 'wb');
440
+                if ($fopen) {
441
+                    while (($data = gzread($handle, 4096)) != false) {
442
+                        fwrite($fopen, $data);
443 443
                     }
444 444
 
445
-                    gzclose( $handle );
446
-                    fclose( $fopen );
445
+                    gzclose($handle);
446
+                    fclose($fopen);
447 447
                         
448 448
                     $success = true;
449 449
                 } else {
450
-                    gzclose( $handle );
451
-                    $message = sprintf( __( 'Error could not open destination GeoIp2 database file for writing: %s', 'invoicing' ), $destination_file );
450
+                    gzclose($handle);
451
+                    $message = sprintf(__('Error could not open destination GeoIp2 database file for writing: %s', 'invoicing'), $destination_file);
452 452
                 }
453 453
             } else {
454
-                $message = sprintf( __( 'Error could not open GeoIp2 database file for reading: %s', 'invoicing' ), $temp_file );
454
+                $message = sprintf(__('Error could not open GeoIp2 database file for reading: %s', 'invoicing'), $temp_file);
455 455
             }
456 456
             
457
-            if ( file_exists( $temp_file ) ) {
458
-                unlink( $temp_file );
457
+            if (file_exists($temp_file)) {
458
+                unlink($temp_file);
459 459
             }
460 460
         }
461 461
         
@@ -467,11 +467,11 @@  discard block
 block discarded – undo
467 467
     }
468 468
     
469 469
     public static function load_geoip2() {
470
-        if ( defined( 'WPINV_GEOIP2_LODDED' ) ) {
470
+        if (defined('WPINV_GEOIP2_LODDED')) {
471 471
             return;
472 472
         }
473 473
         
474
-        if ( !class_exists( '\MaxMind\Db\Reader' ) ) {
474
+        if (!class_exists('\MaxMind\Db\Reader')) {
475 475
             $maxmind_db_files = array(
476 476
                 'Reader/Decoder.php',
477 477
                 'Reader/InvalidDatabaseException.php',
@@ -480,12 +480,12 @@  discard block
 block discarded – undo
480 480
                 'Reader.php',
481 481
             );
482 482
             
483
-            foreach ( $maxmind_db_files as $key => $file ) {
484
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file );
483
+            foreach ($maxmind_db_files as $key => $file) {
484
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file);
485 485
             }
486 486
         }
487 487
         
488
-        if ( !class_exists( '\GeoIp2\Database\Reader' ) ) {        
488
+        if (!class_exists('\GeoIp2\Database\Reader')) {        
489 489
             $geoip2_files = array(
490 490
                 'ProviderInterface.php',
491 491
                 'Compat/JsonSerializable.php',
@@ -519,23 +519,23 @@  discard block
 block discarded – undo
519 519
                 'WebService/Client.php',
520 520
             );
521 521
             
522
-            foreach ( $geoip2_files as $key => $file ) {
523
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file );
522
+            foreach ($geoip2_files as $key => $file) {
523
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file);
524 524
             }
525 525
         }
526 526
 
527
-        define( 'WPINV_GEOIP2_LODDED', true );
527
+        define('WPINV_GEOIP2_LODDED', true);
528 528
     }
529 529
 
530 530
     public static function geoip2_country_dbfile() {
531 531
         $upload_dir = wp_upload_dir();
532 532
 
533
-        if ( !isset( $upload_dir['basedir'] ) ) {
533
+        if (!isset($upload_dir['basedir'])) {
534 534
             return false;
535 535
         }
536 536
 
537 537
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb';
538
-        if ( !file_exists( $filename ) ) {
538
+        if (!file_exists($filename)) {
539 539
             return false;
540 540
         }
541 541
         
@@ -545,12 +545,12 @@  discard block
 block discarded – undo
545 545
     public static function geoip2_city_dbfile() {
546 546
         $upload_dir = wp_upload_dir();
547 547
 
548
-        if ( !isset( $upload_dir['basedir'] ) ) {
548
+        if (!isset($upload_dir['basedir'])) {
549 549
             return false;
550 550
         }
551 551
 
552 552
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb';
553
-        if ( !file_exists( $filename ) ) {
553
+        if (!file_exists($filename)) {
554 554
             return false;
555 555
         }
556 556
         
@@ -561,10 +561,10 @@  discard block
 block discarded – undo
561 561
         try {
562 562
             self::load_geoip2();
563 563
 
564
-            if ( $filename = self::geoip2_country_dbfile() ) {
565
-                return new \GeoIp2\Database\Reader( $filename );
564
+            if ($filename = self::geoip2_country_dbfile()) {
565
+                return new \GeoIp2\Database\Reader($filename);
566 566
             }
567
-        } catch( Exception $e ) {
567
+        } catch (Exception $e) {
568 568
             return false;
569 569
         }
570 570
         
@@ -575,183 +575,183 @@  discard block
 block discarded – undo
575 575
         try {
576 576
             self::load_geoip2();
577 577
 
578
-            if ( $filename = self::geoip2_city_dbfile() ) {
579
-                return new \GeoIp2\Database\Reader( $filename );
578
+            if ($filename = self::geoip2_city_dbfile()) {
579
+                return new \GeoIp2\Database\Reader($filename);
580 580
             }
581
-        } catch( Exception $e ) {
581
+        } catch (Exception $e) {
582 582
             return false;
583 583
         }
584 584
         
585 585
         return false;
586 586
     }
587 587
 
588
-    public static function geoip2_country_record( $ip_address ) {
588
+    public static function geoip2_country_record($ip_address) {
589 589
         try {
590 590
             $reader = self::geoip2_country_reader();
591 591
 
592
-            if ( $reader ) {
593
-                $record = $reader->country( $ip_address );
592
+            if ($reader) {
593
+                $record = $reader->country($ip_address);
594 594
                 
595
-                if ( !empty( $record->country->isoCode ) ) {
595
+                if (!empty($record->country->isoCode)) {
596 596
                     return $record;
597 597
                 }
598 598
             }
599
-        } catch(\InvalidArgumentException $e) {
600
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
599
+        } catch (\InvalidArgumentException $e) {
600
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
601 601
             
602 602
             return false;
603
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
604
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
603
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
604
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
605 605
             
606 606
             return false;
607
-        } catch( Exception $e ) {
607
+        } catch (Exception $e) {
608 608
             return false;
609 609
         }
610 610
         
611 611
         return false;
612 612
     }
613 613
 
614
-    public static function geoip2_city_record( $ip_address ) {
614
+    public static function geoip2_city_record($ip_address) {
615 615
         try {
616 616
             $reader = self::geoip2_city_reader();
617 617
 
618
-            if ( $reader ) {
619
-                $record = $reader->city( $ip_address );
618
+            if ($reader) {
619
+                $record = $reader->city($ip_address);
620 620
                 
621
-                if ( !empty( $record->country->isoCode ) ) {
621
+                if (!empty($record->country->isoCode)) {
622 622
                     return $record;
623 623
                 }
624 624
             }
625
-        } catch(\InvalidArgumentException $e) {
626
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
625
+        } catch (\InvalidArgumentException $e) {
626
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
627 627
             
628 628
             return false;
629
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
630
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
629
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
630
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
631 631
             
632 632
             return false;
633
-        } catch( Exception $e ) {
633
+        } catch (Exception $e) {
634 634
             return false;
635 635
         }
636 636
         
637 637
         return false;
638 638
     }
639 639
 
640
-    public static function geoip2_country_code( $ip_address ) {
641
-        $record = self::geoip2_country_record( $ip_address );
642
-        return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country();
640
+    public static function geoip2_country_code($ip_address) {
641
+        $record = self::geoip2_country_record($ip_address);
642
+        return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country();
643 643
     }
644 644
 
645 645
     // Find country by IP address.
646
-    public static function get_country_by_ip( $ip = '' ) {
646
+    public static function get_country_by_ip($ip = '') {
647 647
         global $wpinv_ip_address_country;
648 648
         return '';
649
-        if ( !empty( $wpinv_ip_address_country ) ) {
649
+        if (!empty($wpinv_ip_address_country)) {
650 650
             return $wpinv_ip_address_country;
651 651
         }
652 652
         
653
-        if ( empty( $ip ) ) {
653
+        if (empty($ip)) {
654 654
             $ip = wpinv_get_ip();
655 655
         }
656 656
 
657
-        $ip_country_service = wpinv_get_option( 'vat_ip_lookup' );
658
-        $is_default         = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false;
657
+        $ip_country_service = wpinv_get_option('vat_ip_lookup');
658
+        $is_default         = empty($ip_country_service) || $ip_country_service === 'default' ? true : false;
659 659
 
660
-        if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country.
661
-            if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) {
660
+        if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country.
661
+            if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) {
662 662
                 try {
663
-                    $wpinv_ip_address_country = geoip_country_code_by_name( $ip );
664
-                } catch( Exception $e ) {
665
-                    wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' );
663
+                    $wpinv_ip_address_country = geoip_country_code_by_name($ip);
664
+                } catch (Exception $e) {
665
+                    wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )');
666 666
                 }
667
-            } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) {
668
-                $wpinv_ip_address_country = self::geoip2_country_code( $ip );
669
-            } else if ( function_exists( 'simplexml_load_file' ) && ini_get('allow_url_fopen') && ( $ip_country_service === 'geoplugin' || $is_default ) ) {
670
-                $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
667
+            } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) {
668
+                $wpinv_ip_address_country = self::geoip2_country_code($ip);
669
+            } else if (function_exists('simplexml_load_file') && ini_get('allow_url_fopen') && ($ip_country_service === 'geoplugin' || $is_default)) {
670
+                $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
671 671
                 
672
-                if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) {
673
-                    $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode;
672
+                if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) {
673
+                    $wpinv_ip_address_country = (string) $load_xml->geoplugin_countryCode;
674 674
                 }
675
-            }elseif(!empty( $ip )){
675
+            }elseif (!empty($ip)) {
676 676
                 $url = 'http://ip-api.com/json/' . $ip;
677 677
                 $response = wp_remote_get($url);
678 678
 
679
-                if ( is_array( $response ) && wp_remote_retrieve_response_code( $response ) == '200' ) {
680
-                    $data = json_decode(wp_remote_retrieve_body( $response ),true);
681
-                    if(!empty($data['countryCode'])){
682
-                        $wpinv_ip_address_country = (string)$data['countryCode'];
679
+                if (is_array($response) && wp_remote_retrieve_response_code($response) == '200') {
680
+                    $data = json_decode(wp_remote_retrieve_body($response), true);
681
+                    if (!empty($data['countryCode'])) {
682
+                        $wpinv_ip_address_country = (string) $data['countryCode'];
683 683
                     }
684 684
                 }
685 685
             }
686 686
         }
687 687
 
688
-        if ( empty( $wpinv_ip_address_country ) ) {
688
+        if (empty($wpinv_ip_address_country)) {
689 689
             $wpinv_ip_address_country = wpinv_get_default_country();
690 690
         }
691 691
 
692 692
         return $wpinv_ip_address_country;
693 693
     }
694 694
     
695
-    public static function sanitize_vat_settings( $input ) {
695
+    public static function sanitize_vat_settings($input) {
696 696
         global $wpinv_options;
697 697
         
698 698
         $valid      = false;
699 699
         $message    = '';
700 700
         
701
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
702
-            if ( empty( $wpinv_options['vat_offline_check'] ) ) {
703
-                $valid = self::offline_check( $input['vat_number'] );
701
+        if (!empty($wpinv_options['vat_vies_check'])) {
702
+            if (empty($wpinv_options['vat_offline_check'])) {
703
+                $valid = self::offline_check($input['vat_number']);
704 704
             } else {
705 705
                 $valid = true;
706 706
             }
707 707
             
708
-            $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' );
708
+            $message = $valid ? '' : __('VAT number not validated', 'invoicing');
709 709
         } else {
710
-            $result = self::check_vat( $input['vat_number'] );
710
+            $result = self::check_vat($input['vat_number']);
711 711
             
712
-            if ( empty( $result['valid'] ) ) {
712
+            if (empty($result['valid'])) {
713 713
                 $valid      = false;
714 714
                 $message    = $result['message'];
715 715
             } else {
716
-                $valid      = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] );
717
-                $message    = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' );
716
+                $valid      = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']);
717
+                $message    = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing');
718 718
             }
719 719
         }
720 720
 
721
-        if ( $message && self::is_vat_validated() != $valid ) {
722
-            add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) );
721
+        if ($message && self::is_vat_validated() != $valid) {
722
+            add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error'));
723 723
         }
724 724
 
725 725
         $input['vat_valid'] = $valid;
726 726
         return $input;
727 727
     }
728 728
     
729
-    public static function sanitize_vat_rates( $input ) {
730
-        if( !wpinv_current_user_can_manage_invoicing() ) {
731
-            add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' );
729
+    public static function sanitize_vat_rates($input) {
730
+        if (!wpinv_current_user_can_manage_invoicing()) {
731
+            add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error');
732 732
             return $input;
733 733
         }
734 734
         
735 735
         $vat_classes = self::get_rate_classes();
736
-        $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : '';
736
+        $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : '';
737 737
         
738
-        if ( empty( $vat_class ) ) {
739
-            add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' );
738
+        if (empty($vat_class)) {
739
+            add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error');
740 740
             
741 741
             return $input;
742 742
         }
743 743
 
744
-        $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array();
744
+        $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array();
745 745
 
746
-        if ( $vat_class === '_standard' ) {
746
+        if ($vat_class === '_standard') {
747 747
             // Save the active rates in the invoice settings
748
-            update_option( 'wpinv_tax_rates', $new_rates );
748
+            update_option('wpinv_tax_rates', $new_rates);
749 749
         } else {
750 750
             // Get the existing set of rates
751 751
             $rates = self::get_non_standard_rates();
752 752
             $rates[$vat_class] = $new_rates;
753 753
 
754
-            update_option( 'wpinv_vat_rates', $rates );
754
+            update_option('wpinv_vat_rates', $rates);
755 755
         }
756 756
         
757 757
         return $input;
@@ -761,71 +761,71 @@  discard block
 block discarded – undo
761 761
         $response = array();
762 762
         $response['success'] = false;
763 763
         
764
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
765
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
766
-            wp_send_json( $response );
764
+        if (!wpinv_current_user_can_manage_invoicing()) {
765
+            $response['error'] = __('Invalid access!', 'invoicing');
766
+            wp_send_json($response);
767 767
         }
768 768
         
769
-        $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false;
770
-        $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false;
769
+        $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false;
770
+        $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false;
771 771
         
772
-        if ( empty( $vat_class_name ) ) {
773
-            $response['error'] = __( 'Select the VAT rate name', 'invoicing' );
774
-            wp_send_json( $response );
772
+        if (empty($vat_class_name)) {
773
+            $response['error'] = __('Select the VAT rate name', 'invoicing');
774
+            wp_send_json($response);
775 775
         }
776 776
         
777
-        $vat_classes = (array)self::get_rate_classes();
777
+        $vat_classes = (array) self::get_rate_classes();
778 778
 
779
-        if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) {
780
-            $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name );
781
-            wp_send_json( $response );
779
+        if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) {
780
+            $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name);
781
+            wp_send_json($response);
782 782
         }
783 783
         
784
-        $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name );
785
-        $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) );
784
+        $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name);
785
+        $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key));
786 786
         
787
-        $vat_classes = (array)self::get_rate_classes( true );
788
-        $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc );
787
+        $vat_classes = (array) self::get_rate_classes(true);
788
+        $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc);
789 789
         
790
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
790
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
791 791
         
792 792
         $response['success'] = true;
793
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key );
793
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key);
794 794
         
795
-        wp_send_json( $response );
795
+        wp_send_json($response);
796 796
     }
797 797
     
798 798
     public static function delete_class() {
799 799
         $response = array();
800 800
         $response['success'] = false;
801 801
         
802
-        if ( !wpinv_current_user_can_manage_invoicing() || !isset( $_POST['class'] ) ) {
803
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
804
-            wp_send_json( $response );
802
+        if (!wpinv_current_user_can_manage_invoicing() || !isset($_POST['class'])) {
803
+            $response['error'] = __('Invalid access!', 'invoicing');
804
+            wp_send_json($response);
805 805
         }
806 806
         
807
-        $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false;
808
-        $vat_classes = (array)self::get_rate_classes();
807
+        $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false;
808
+        $vat_classes = (array) self::get_rate_classes();
809 809
 
810
-        if ( !isset( $vat_classes[$vat_class] ) ) {
811
-            $response['error'] = __( 'Requested class does not exists', 'invoicing' );
812
-            wp_send_json( $response );
810
+        if (!isset($vat_classes[$vat_class])) {
811
+            $response['error'] = __('Requested class does not exists', 'invoicing');
812
+            wp_send_json($response);
813 813
         }
814 814
         
815
-        if ( $vat_class == '_new' || $vat_class == '_standard' ) {
816
-            $response['error'] = __( 'You can not delete standard rates class', 'invoicing' );
817
-            wp_send_json( $response );
815
+        if ($vat_class == '_new' || $vat_class == '_standard') {
816
+            $response['error'] = __('You can not delete standard rates class', 'invoicing');
817
+            wp_send_json($response);
818 818
         }
819 819
             
820
-        $vat_classes = (array)self::get_rate_classes( true );
821
-        unset( $vat_classes[$vat_class] );
820
+        $vat_classes = (array) self::get_rate_classes(true);
821
+        unset($vat_classes[$vat_class]);
822 822
         
823
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
823
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
824 824
         
825 825
         $response['success'] = true;
826
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new' );
826
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new');
827 827
         
828
-        wp_send_json( $response );
828
+        wp_send_json($response);
829 829
     }
830 830
     
831 831
     public static function update_eu_rates() {        
@@ -834,72 +834,72 @@  discard block
 block discarded – undo
834 834
         $response['error']      = null;
835 835
         $response['data']       = null;
836 836
         
837
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
838
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
839
-            wp_send_json( $response );
837
+        if (!wpinv_current_user_can_manage_invoicing()) {
838
+            $response['error'] = __('Invalid access!', 'invoicing');
839
+            wp_send_json($response);
840 840
         }
841 841
         
842
-        $group      = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : '';
843
-        $euvatrates = self::request_euvatrates( $group );
842
+        $group      = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : '';
843
+        $euvatrates = self::request_euvatrates($group);
844 844
         
845
-        if ( !empty( $euvatrates ) ) {
846
-            if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) {
845
+        if (!empty($euvatrates)) {
846
+            if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) {
847 847
                 $response['success']        = true;
848 848
                 $response['data']['rates']  = $euvatrates['rates'];
849
-            } else if ( !empty( $euvatrates['error'] ) ) {
849
+            } else if (!empty($euvatrates['error'])) {
850 850
                 $response['error']          = $euvatrates['error'];
851 851
             }
852 852
         }
853 853
             
854
-        wp_send_json( $response );
854
+        wp_send_json($response);
855 855
     }
856 856
     
857 857
     public static function hide_vat_fields() {
858
-        $hide = wpinv_get_option( 'vat_disable_fields' );
858
+        $hide = wpinv_get_option('vat_disable_fields');
859 859
         
860
-        return apply_filters( 'wpinv_hide_vat_fields', $hide );
860
+        return apply_filters('wpinv_hide_vat_fields', $hide);
861 861
     }
862 862
     
863 863
     public static function same_country_rule() {
864
-        $same_country_rule = wpinv_get_option( 'vat_same_country_rule' );
864
+        $same_country_rule = wpinv_get_option('vat_same_country_rule');
865 865
         
866
-        return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule );
866
+        return apply_filters('wpinv_vat_same_country_rule', $same_country_rule);
867 867
     }
868 868
     
869 869
     public static function get_vat_name() {
870
-        $vat_name   = wpinv_get_option( 'vat_name' );
871
-        $vat_name   = !empty( $vat_name ) ? $vat_name : 'VAT';
870
+        $vat_name   = wpinv_get_option('vat_name');
871
+        $vat_name   = !empty($vat_name) ? $vat_name : 'VAT';
872 872
         
873
-        return apply_filters( 'wpinv_get_owner_vat_name', $vat_name );
873
+        return apply_filters('wpinv_get_owner_vat_name', $vat_name);
874 874
     }
875 875
     
876 876
     public static function get_company_name() {
877
-        $company_name = wpinv_get_option( 'vat_company_name' );
877
+        $company_name = wpinv_get_option('vat_company_name');
878 878
         
879
-        return apply_filters( 'wpinv_get_owner_company_name', $company_name );
879
+        return apply_filters('wpinv_get_owner_company_name', $company_name);
880 880
     }
881 881
     
882 882
     public static function get_vat_number() {
883
-        $vat_number = wpinv_get_option( 'vat_number' );
883
+        $vat_number = wpinv_get_option('vat_number');
884 884
         
885
-        return apply_filters( 'wpinv_get_owner_vat_number', $vat_number );
885
+        return apply_filters('wpinv_get_owner_vat_number', $vat_number);
886 886
     }
887 887
     
888 888
     public static function is_vat_validated() {
889
-        $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' );
889
+        $validated = self::get_vat_number() && wpinv_get_option('vat_valid');
890 890
         
891
-        return apply_filters( 'wpinv_is_owner_vat_validated', $validated );
891
+        return apply_filters('wpinv_is_owner_vat_validated', $validated);
892 892
     }
893 893
     
894
-    public static function sanitize_vat( $vat_number, $country_code = '' ) {        
895
-        $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) );
894
+    public static function sanitize_vat($vat_number, $country_code = '') {        
895
+        $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number)));
896 896
         
897
-        if ( empty( $country_code ) ) {
898
-            $country_code = substr( $vat_number, 0, 2 );
897
+        if (empty($country_code)) {
898
+            $country_code = substr($vat_number, 0, 2);
899 899
         }
900 900
         
901
-        if ( strpos( $vat_number , $country_code ) === 0 ) {
902
-            $vat = str_replace( $country_code, '', $vat_number );
901
+        if (strpos($vat_number, $country_code) === 0) {
902
+            $vat = str_replace($country_code, '', $vat_number);
903 903
         } else {
904 904
             $vat = $country_code . $vat_number;
905 905
         }
@@ -912,140 +912,140 @@  discard block
 block discarded – undo
912 912
         return $return;
913 913
     }
914 914
     
915
-    public static function offline_check( $vat_number, $country_code = '', $formatted = false ) {
916
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
915
+    public static function offline_check($vat_number, $country_code = '', $formatted = false) {
916
+        $vat            = self::sanitize_vat($vat_number, $country_code);
917 917
         $vat_number     = $vat['vat_number'];
918 918
         $country_code   = $vat['iso'];
919 919
         $regex          = array();
920 920
         
921
-        switch ( $country_code ) {
921
+        switch ($country_code) {
922 922
             case 'AT':
923
-                $regex[] = '/^(AT)U(\d{8})$/';                           // Austria
923
+                $regex[] = '/^(AT)U(\d{8})$/'; // Austria
924 924
                 break;
925 925
             case 'BE':
926
-                $regex[] = '/^(BE)(0?\d{9})$/';                          // Belgium
926
+                $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium
927 927
                 break;
928 928
             case 'BG':
929
-                $regex[] = '/^(BG)(\d{9,10})$/';                         // Bulgaria
929
+                $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria
930 930
                 break;
931 931
             case 'CH':
932 932
             case 'CHE':
933
-                $regex[] = '/^(CHE)(\d{9})MWST$/';                       // Switzerland (Not EU)
933
+                $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU)
934 934
                 break;
935 935
             case 'CY':
936
-                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/';                // Cyprus
936
+                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus
937 937
                 break;
938 938
             case 'CZ':
939
-                $regex[] = '/^(CZ)(\d{8,13})$/';                         // Czech Republic
939
+                $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic
940 940
                 break;
941 941
             case 'DE':
942
-                $regex[] = '/^(DE)([1-9]\d{8})$/';                       // Germany
942
+                $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany
943 943
                 break;
944 944
             case 'DK':
945
-                $regex[] = '/^(DK)(\d{8})$/';                            // Denmark
945
+                $regex[] = '/^(DK)(\d{8})$/'; // Denmark
946 946
                 break;
947 947
             case 'EE':
948
-                $regex[] = '/^(EE)(10\d{7})$/';                          // Estonia
948
+                $regex[] = '/^(EE)(10\d{7})$/'; // Estonia
949 949
                 break;
950 950
             case 'EL':
951
-                $regex[] = '/^(EL)(\d{9})$/';                            // Greece
951
+                $regex[] = '/^(EL)(\d{9})$/'; // Greece
952 952
                 break;
953 953
             case 'ES':
954
-                $regex[] = '/^(ES)([A-Z]\d{8})$/';                       // Spain (National juridical entities)
955
-                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/';            // Spain (Other juridical entities)
956
-                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/';              // Spain (Personal entities type 1)
957
-                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/';              // Spain (Personal entities type 2)
954
+                $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities)
955
+                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities)
956
+                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1)
957
+                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2)
958 958
                 break;
959 959
             case 'EU':
960
-                $regex[] = '/^(EU)(\d{9})$/';                            // EU-type
960
+                $regex[] = '/^(EU)(\d{9})$/'; // EU-type
961 961
                 break;
962 962
             case 'FI':
963
-                $regex[] = '/^(FI)(\d{8})$/';                            // Finland
963
+                $regex[] = '/^(FI)(\d{8})$/'; // Finland
964 964
                 break;
965 965
             case 'FR':
966
-                $regex[] = '/^(FR)(\d{11})$/';                           // France (1)
967
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/';        // France (2)
968
-                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/';       // France (3)
969
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/';      // France (4)
966
+                $regex[] = '/^(FR)(\d{11})$/'; // France (1)
967
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2)
968
+                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3)
969
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4)
970 970
                 break;
971 971
             case 'GB':
972
-                $regex[] = '/^(GB)?(\d{9})$/';                           // UK (Standard)
973
-                $regex[] = '/^(GB)?(\d{12})$/';                          // UK (Branches)
974
-                $regex[] = '/^(GB)?(GD\d{3})$/';                         // UK (Government)
975
-                $regex[] = '/^(GB)?(HA\d{3})$/';                         // UK (Health authority)
972
+                $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard)
973
+                $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches)
974
+                $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government)
975
+                $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority)
976 976
                 break;
977 977
             case 'GR':
978
-                $regex[] = '/^(GR)(\d{8,9})$/';                          // Greece
978
+                $regex[] = '/^(GR)(\d{8,9})$/'; // Greece
979 979
                 break;
980 980
             case 'HR':
981
-                $regex[] = '/^(HR)(\d{11})$/';                           // Croatia
981
+                $regex[] = '/^(HR)(\d{11})$/'; // Croatia
982 982
                 break;
983 983
             case 'HU':
984
-                $regex[] = '/^(HU)(\d{8})$/';                            // Hungary
984
+                $regex[] = '/^(HU)(\d{8})$/'; // Hungary
985 985
                 break;
986 986
             case 'IE':
987
-                $regex[] = '/^(IE)(\d{7}[A-W])$/';                       // Ireland (1)
988
-                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/';        // Ireland (2)
989
-                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/';                   // Ireland (3) (new format from 1 Jan 2013)
987
+                $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1)
988
+                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2)
989
+                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013)
990 990
                 break;
991 991
             case 'IT':
992
-                $regex[] = '/^(IT)(\d{11})$/';                           // Italy
992
+                $regex[] = '/^(IT)(\d{11})$/'; // Italy
993 993
                 break;
994 994
             case 'LV':
995
-                $regex[] = '/^(LV)(\d{11})$/';                           // Latvia
995
+                $regex[] = '/^(LV)(\d{11})$/'; // Latvia
996 996
                 break;
997 997
             case 'LT':
998
-                $regex[] = '/^(LT)(\d{9}|\d{12})$/';                     // Lithuania
998
+                $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania
999 999
                 break;
1000 1000
             case 'LU':
1001
-                $regex[] = '/^(LU)(\d{8})$/';                            // Luxembourg
1001
+                $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg
1002 1002
                 break;
1003 1003
             case 'MT':
1004
-                $regex[] = '/^(MT)([1-9]\d{7})$/';                       // Malta
1004
+                $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta
1005 1005
                 break;
1006 1006
             case 'NL':
1007
-                $regex[] = '/^(NL)(\d{9})B\d{2}$/';                      // Netherlands
1007
+                $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands
1008 1008
                 break;
1009 1009
             case 'NO':
1010
-                $regex[] = '/^(NO)(\d{9})$/';                            // Norway (Not EU)
1010
+                $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU)
1011 1011
                 break;
1012 1012
             case 'PL':
1013
-                $regex[] = '/^(PL)(\d{10})$/';                           // Poland
1013
+                $regex[] = '/^(PL)(\d{10})$/'; // Poland
1014 1014
                 break;
1015 1015
             case 'PT':
1016
-                $regex[] = '/^(PT)(\d{9})$/';                            // Portugal
1016
+                $regex[] = '/^(PT)(\d{9})$/'; // Portugal
1017 1017
                 break;
1018 1018
             case 'RO':
1019
-                $regex[] = '/^(RO)([1-9]\d{1,9})$/';                     // Romania
1019
+                $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania
1020 1020
                 break;
1021 1021
             case 'RS':
1022
-                $regex[] = '/^(RS)(\d{9})$/';                            // Serbia (Not EU)
1022
+                $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU)
1023 1023
                 break;
1024 1024
             case 'SI':
1025
-                $regex[] = '/^(SI)([1-9]\d{7})$/';                       // Slovenia
1025
+                $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia
1026 1026
                 break;
1027 1027
             case 'SK':
1028
-                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/';        // Slovakia Republic
1028
+                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic
1029 1029
                 break;
1030 1030
             case 'SE':
1031
-                $regex[] = '/^(SE)(\d{10}01)$/';                         // Sweden
1031
+                $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden
1032 1032
                 break;
1033 1033
             default:
1034 1034
                 $regex = array();
1035 1035
             break;
1036 1036
         }
1037 1037
         
1038
-        if ( empty( $regex ) ) {
1038
+        if (empty($regex)) {
1039 1039
             return false;
1040 1040
         }
1041 1041
         
1042
-        foreach ( $regex as $pattern ) {
1042
+        foreach ($regex as $pattern) {
1043 1043
             $matches = null;
1044
-            preg_match_all( $pattern, $vat_number, $matches );
1044
+            preg_match_all($pattern, $vat_number, $matches);
1045 1045
             
1046
-            if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) {
1047
-                if ( $formatted ) {
1048
-                    return array( 'code' => $matches[1][0], 'number' => $matches[2][0] );
1046
+            if (!empty($matches[1][0]) && !empty($matches[2][0])) {
1047
+                if ($formatted) {
1048
+                    return array('code' => $matches[1][0], 'number' => $matches[2][0]);
1049 1049
                 } else {
1050 1050
                     return true;
1051 1051
                 }
@@ -1055,75 +1055,75 @@  discard block
 block discarded – undo
1055 1055
         return false;
1056 1056
     }
1057 1057
     
1058
-    public static function vies_check( $vat_number, $country_code = '', $result = false ) {
1059
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
1058
+    public static function vies_check($vat_number, $country_code = '', $result = false) {
1059
+        $vat            = self::sanitize_vat($vat_number, $country_code);
1060 1060
         $vat_number     = $vat['vat'];
1061 1061
         $iso            = $vat['iso'];
1062 1062
         
1063
-        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number );
1063
+        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number);
1064 1064
         
1065
-        if ( ini_get( 'allow_url_fopen' ) ) {
1066
-            $response = file_get_contents( $url );
1067
-        } else if ( function_exists( 'curl_init' ) ) {
1065
+        if (ini_get('allow_url_fopen')) {
1066
+            $response = file_get_contents($url);
1067
+        } else if (function_exists('curl_init')) {
1068 1068
             $ch = curl_init();
1069 1069
             
1070
-            curl_setopt( $ch, CURLOPT_URL, $url );
1071
-            curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 );
1072
-            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
1073
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
1074
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
1070
+            curl_setopt($ch, CURLOPT_URL, $url);
1071
+            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
1072
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1073
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
1074
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
1075 1075
             
1076
-            $response = curl_exec( $ch );
1076
+            $response = curl_exec($ch);
1077 1077
             
1078
-            if ( curl_errno( $ch ) ) {
1079
-                wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' );
1078
+            if (curl_errno($ch)) {
1079
+                wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR');
1080 1080
                 $response = '';
1081 1081
             }
1082 1082
             
1083
-            curl_close( $ch );
1083
+            curl_close($ch);
1084 1084
         } else {
1085
-            wpinv_error_log( 'To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR' );
1085
+            wpinv_error_log('To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR');
1086 1086
         }
1087 1087
         
1088
-        if ( empty( $response ) ) {
1088
+        if (empty($response)) {
1089 1089
             return $result;
1090 1090
         }
1091 1091
 
1092
-        if ( preg_match( '/invalid VAT number/i', $response ) ) {
1092
+        if (preg_match('/invalid VAT number/i', $response)) {
1093 1093
             return false;
1094
-        } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) {
1095
-            $content = explode( "valid VAT number", htmlentities( $response ) );
1094
+        } else if (preg_match('/valid VAT number/i', $response, $matches)) {
1095
+            $content = explode("valid VAT number", htmlentities($response));
1096 1096
             
1097
-            if ( !empty( $content[1] ) ) {
1098
-                preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches );
1097
+            if (!empty($content[1])) {
1098
+                preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches);
1099 1099
                 
1100
-                if ( !empty( $matches[2] ) && $matches[3] ) {
1100
+                if (!empty($matches[2]) && $matches[3]) {
1101 1101
                     $return = array();
1102 1102
                     
1103
-                    foreach ( $matches[2] as $key => $label ) {
1104
-                        $label = trim( $label );
1103
+                    foreach ($matches[2] as $key => $label) {
1104
+                        $label = trim($label);
1105 1105
                         
1106
-                        switch ( strtolower( $label ) ) {
1106
+                        switch (strtolower($label)) {
1107 1107
                             case 'member state':
1108
-                                $return['state'] = trim( strip_tags( $matches[3][$key] ) );
1108
+                                $return['state'] = trim(strip_tags($matches[3][$key]));
1109 1109
                             break;
1110 1110
                             case 'vat number':
1111
-                                $return['number'] = trim( strip_tags( $matches[3][$key] ) );
1111
+                                $return['number'] = trim(strip_tags($matches[3][$key]));
1112 1112
                             break;
1113 1113
                             case 'name':
1114
-                                $return['company'] = trim( strip_tags( $matches[3][$key] ) );
1114
+                                $return['company'] = trim(strip_tags($matches[3][$key]));
1115 1115
                             break;
1116 1116
                             case 'address':
1117
-                                $address           = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) );
1118
-                                $return['address'] = trim( strip_tags( $address, '<br>' ) );
1117
+                                $address           = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key])));
1118
+                                $return['address'] = trim(strip_tags($address, '<br>'));
1119 1119
                             break;
1120 1120
                             case 'consultation number':
1121
-                                $return['consultation'] = trim( strip_tags( $matches[3][$key] ) );
1121
+                                $return['consultation'] = trim(strip_tags($matches[3][$key]));
1122 1122
                             break;
1123 1123
                         }
1124 1124
                     }
1125 1125
                     
1126
-                    if ( !empty( $return ) ) {
1126
+                    if (!empty($return)) {
1127 1127
                         return $return;
1128 1128
                     }
1129 1129
                 }
@@ -1135,62 +1135,62 @@  discard block
 block discarded – undo
1135 1135
         }
1136 1136
     }
1137 1137
     
1138
-    public static function check_vat( $vat_number, $country_code = '' ) {        
1138
+    public static function check_vat($vat_number, $country_code = '') {        
1139 1139
         $vat_name           = self::get_vat_name();
1140 1140
         
1141 1141
         $return             = array();
1142 1142
         $return['valid']    = false;
1143
-        $return['message']  = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1143
+        $return['message']  = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1144 1144
                 
1145
-        if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) {
1145
+        if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) {
1146 1146
             return $return;
1147 1147
         }
1148 1148
             
1149
-        $response = self::vies_check( $vat_number, $country_code );
1149
+        $response = self::vies_check($vat_number, $country_code);
1150 1150
         
1151
-        if ( $response ) {
1152
-            $return['valid']    = true;
1151
+        if ($response) {
1152
+            $return['valid'] = true;
1153 1153
             
1154
-            if ( is_array( $response ) ) {
1155
-                $return['company'] = isset( $response['company'] ) ? $response['company'] : '';
1156
-                $return['address'] = isset( $response['address'] ) ? $response['address'] : '';
1154
+            if (is_array($response)) {
1155
+                $return['company'] = isset($response['company']) ? $response['company'] : '';
1156
+                $return['address'] = isset($response['address']) ? $response['address'] : '';
1157 1157
                 $return['message'] = $return['company'] . '<br/>' . $return['address'];
1158 1158
             }
1159 1159
         } else {
1160 1160
             $return['valid']    = false;
1161
-            $return['message']  = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1161
+            $return['message']  = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1162 1162
         }
1163 1163
         
1164 1164
         return $return;
1165 1165
     }
1166 1166
 
1167
-    public static function request_euvatrates( $group ) {
1167
+    public static function request_euvatrates($group) {
1168 1168
         $response               = array();
1169 1169
         $response['success']    = false;
1170 1170
         $response['error']      = null;
1171 1171
         $response['eurates']    = null;
1172 1172
         
1173 1173
         $euvatrates_url = 'https://euvatrates.com/rates.json';
1174
-        $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url );
1175
-        $api_response   = wp_remote_get( $euvatrates_url );
1174
+        $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url);
1175
+        $api_response   = wp_remote_get($euvatrates_url);
1176 1176
 
1177 1177
         try {
1178
-            if ( is_wp_error( $api_response ) ) {
1179
-                $response['error']      = __( $api_response->get_error_message(), 'invoicing' );
1178
+            if (is_wp_error($api_response)) {
1179
+                $response['error'] = __($api_response->get_error_message(), 'invoicing');
1180 1180
             } else {
1181
-                $body = json_decode( $api_response['body'] );
1182
-                if ( isset( $body->rates ) ) {
1181
+                $body = json_decode($api_response['body']);
1182
+                if (isset($body->rates)) {
1183 1183
                     $rates = array();
1184 1184
                     
1185
-                    foreach ( $body->rates as $country_code => $rate ) {
1185
+                    foreach ($body->rates as $country_code => $rate) {
1186 1186
                         $vat_rate = array();
1187 1187
                         $vat_rate['country']        = $rate->country;
1188
-                        $vat_rate['standard']       = (float)$rate->standard_rate;
1189
-                        $vat_rate['reduced']        = (float)$rate->reduced_rate;
1190
-                        $vat_rate['superreduced']   = (float)$rate->super_reduced_rate;
1191
-                        $vat_rate['parking']        = (float)$rate->parking_rate;
1188
+                        $vat_rate['standard']       = (float) $rate->standard_rate;
1189
+                        $vat_rate['reduced']        = (float) $rate->reduced_rate;
1190
+                        $vat_rate['superreduced']   = (float) $rate->super_reduced_rate;
1191
+                        $vat_rate['parking']        = (float) $rate->parking_rate;
1192 1192
                         
1193
-                        if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) {
1193
+                        if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) {
1194 1194
                             $vat_rate_group = array();
1195 1195
                             $vat_rate_group['country'] = $rate->country;
1196 1196
                             $vat_rate_group[$group]    = $vat_rate[$group];
@@ -1202,79 +1202,79 @@  discard block
 block discarded – undo
1202 1202
                     }
1203 1203
                     
1204 1204
                     $response['success']    = true;                                
1205
-                    $response['rates']      = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group );
1205
+                    $response['rates']      = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group);
1206 1206
                 } else {
1207
-                    $response['error']      = __( 'No EU rates found!', 'invoicing' );
1207
+                    $response['error']      = __('No EU rates found!', 'invoicing');
1208 1208
                 }
1209 1209
             }
1210
-        } catch ( Exception $e ) {
1211
-            $response['error'] = __( $e->getMessage(), 'invoicing' );
1210
+        } catch (Exception $e) {
1211
+            $response['error'] = __($e->getMessage(), 'invoicing');
1212 1212
         }
1213 1213
         
1214
-        return apply_filters( 'wpinv_response_euvatrates', $response, $group );
1214
+        return apply_filters('wpinv_response_euvatrates', $response, $group);
1215 1215
     }    
1216 1216
     
1217
-    public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) {
1217
+    public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) {
1218 1218
         global $wpi_item_id, $wpi_country;
1219 1219
         
1220
-        if ( !empty( $_POST['wpinv_country'] ) ) {
1221
-            $country_code = trim( $_POST['wpinv_country'] );
1222
-        } else if ( !empty( $_POST['country'] ) ) {
1223
-            $country_code = trim( $_POST['country'] );
1224
-        } else if ( !empty( $wpi_country ) ) {
1220
+        if (!empty($_POST['wpinv_country'])) {
1221
+            $country_code = trim($_POST['wpinv_country']);
1222
+        } else if (!empty($_POST['country'])) {
1223
+            $country_code = trim($_POST['country']);
1224
+        } else if (!empty($wpi_country)) {
1225 1225
             $country_code = $wpi_country;
1226 1226
         } else {
1227
-            $country_code = self::get_user_country( '', $user_id );
1227
+            $country_code = self::get_user_country('', $user_id);
1228 1228
         }
1229 1229
         
1230
-        if ( $is_digital === null && $wpi_item_id ) {
1231
-            $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules();
1230
+        if ($is_digital === null && $wpi_item_id) {
1231
+            $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules();
1232 1232
         }
1233 1233
         
1234
-        if ( !empty( $country_code ) ) {
1235
-            $requires_vat = ( self::is_eu_state( $country_code ) && ( self::is_eu_state( self::$default_country ) || $is_digital ) ) || ( self::is_gst_country( $country_code ) && self::is_gst_country( self::$default_country ) );
1234
+        if (!empty($country_code)) {
1235
+            $requires_vat = (self::is_eu_state($country_code) && (self::is_eu_state(self::$default_country) || $is_digital)) || (self::is_gst_country($country_code) && self::is_gst_country(self::$default_country));
1236 1236
         }
1237 1237
         
1238
-        return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id );
1238
+        return apply_filters('wpinv_requires_vat', $requires_vat, $user_id);
1239 1239
     }
1240 1240
     
1241
-    public static function tax_label( $label = '' ) {
1241
+    public static function tax_label($label = '') {
1242 1242
         global $wpi_requires_vat;
1243 1243
         
1244
-        if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) {
1245
-            $wpi_requires_vat = self::requires_vat( 0, false );
1244
+        if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) {
1245
+            $wpi_requires_vat = self::requires_vat(0, false);
1246 1246
         }
1247 1247
         
1248
-        return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) );
1248
+        return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing'));
1249 1249
     }
1250 1250
     
1251 1251
     public static function standard_rates_label() {
1252
-        return __( 'Standard Rates', 'invoicing' );
1252
+        return __('Standard Rates', 'invoicing');
1253 1253
     }
1254 1254
     
1255
-    public static function get_rate_classes( $with_desc = false ) {        
1256
-        $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true );
1257
-        $classes = maybe_unserialize( $rate_classes_option );
1255
+    public static function get_rate_classes($with_desc = false) {        
1256
+        $rate_classes_option = get_option('_wpinv_vat_rate_classes', true);
1257
+        $classes = maybe_unserialize($rate_classes_option);
1258 1258
 
1259
-        if ( empty( $classes ) || !is_array( $classes ) ) {
1259
+        if (empty($classes) || !is_array($classes)) {
1260 1260
             $classes = array();
1261 1261
         }
1262 1262
 
1263 1263
         $rate_classes = array();
1264
-        if ( !array_key_exists( '_standard', $classes ) ) {
1265
-            if ( $with_desc ) {
1266
-                $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) );
1264
+        if (!array_key_exists('_standard', $classes)) {
1265
+            if ($with_desc) {
1266
+                $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing'));
1267 1267
             } else {
1268 1268
                 $rate_classes['_standard'] = self::standard_rates_label();
1269 1269
             }
1270 1270
         }
1271 1271
         
1272
-        foreach ( $classes as $key => $class ) {
1273
-            $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key;
1274
-            $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : '';
1272
+        foreach ($classes as $key => $class) {
1273
+            $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key;
1274
+            $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : '';
1275 1275
             
1276
-            if ( $with_desc ) {
1277
-                $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc );
1276
+            if ($with_desc) {
1277
+                $rate_classes[$key] = array('name' => $name, 'desc' => $desc);
1278 1278
             } else {
1279 1279
                 $rate_classes[$key] = $name;
1280 1280
             }
@@ -1285,15 +1285,15 @@  discard block
 block discarded – undo
1285 1285
     
1286 1286
     public static function get_all_classes() {        
1287 1287
         $classes            = self::get_rate_classes();
1288
-        $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' );
1288
+        $classes['_exempt'] = __('Exempt (0%)', 'invoicing');
1289 1289
         
1290
-        return apply_filters( 'wpinv_vat_get_all_classes', $classes );
1290
+        return apply_filters('wpinv_vat_get_all_classes', $classes);
1291 1291
     }
1292 1292
     
1293
-    public static function get_class_desc( $rate_class ) {        
1294
-        $rate_classes = self::get_rate_classes( true );
1293
+    public static function get_class_desc($rate_class) {        
1294
+        $rate_classes = self::get_rate_classes(true);
1295 1295
 
1296
-        if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) {
1296
+        if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) {
1297 1297
             return $rate_classes[$rate_class]['desc'];
1298 1298
         }
1299 1299
         
@@ -1309,107 +1309,107 @@  discard block
 block discarded – undo
1309 1309
             'increased'     => 'Increased'
1310 1310
         );
1311 1311
         
1312
-        return apply_filters( 'wpinv_get_vat_groups', $vat_groups );
1312
+        return apply_filters('wpinv_get_vat_groups', $vat_groups);
1313 1313
     }
1314 1314
 
1315 1315
     public static function get_rules() {
1316 1316
         $vat_rules = array(
1317
-            'digital' => __( 'Digital Product', 'invoicing' ),
1318
-            'physical' => __( 'Physical Product', 'invoicing' ),    
1319
-            '_exempt' => __( 'Tax-Free Product', 'invoicing' ),
1317
+            'digital' => __('Digital Product', 'invoicing'),
1318
+            'physical' => __('Physical Product', 'invoicing'),    
1319
+            '_exempt' => __('Tax-Free Product', 'invoicing'),
1320 1320
         );
1321
-        return apply_filters( 'wpinv_get_vat_rules', $vat_rules );
1321
+        return apply_filters('wpinv_get_vat_rules', $vat_rules);
1322 1322
     }
1323 1323
 
1324
-    public static function get_vat_rates( $class ) {
1325
-        if ( $class === '_standard' ) {
1324
+    public static function get_vat_rates($class) {
1325
+        if ($class === '_standard') {
1326 1326
             return wpinv_get_tax_rates();
1327 1327
         }
1328 1328
 
1329 1329
         $rates = self::get_non_standard_rates();
1330 1330
 
1331
-        return array_key_exists( $class, $rates ) ? $rates[$class] : array();
1331
+        return array_key_exists($class, $rates) ? $rates[$class] : array();
1332 1332
     }
1333 1333
 
1334 1334
     public static function get_non_standard_rates() {
1335
-        $option = get_option( 'wpinv_vat_rates', array());
1336
-        return is_array( $option ) ? $option : array();
1335
+        $option = get_option('wpinv_vat_rates', array());
1336
+        return is_array($option) ? $option : array();
1337 1337
     }
1338 1338
     
1339 1339
     public static function allow_vat_rules() {
1340
-        return ( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ? true : false );
1340
+        return (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules') ? true : false);
1341 1341
     }
1342 1342
     
1343 1343
     public static function allow_vat_classes() {
1344 1344
         return false; // TODO
1345
-        return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false );
1345
+        return (wpinv_get_option('vat_allow_classes') ? true : false);
1346 1346
     }
1347 1347
     
1348
-    public static function get_item_class( $postID ) {
1349
-        $class = get_post_meta( $postID, '_wpinv_vat_class', true );
1348
+    public static function get_item_class($postID) {
1349
+        $class = get_post_meta($postID, '_wpinv_vat_class', true);
1350 1350
 
1351
-        if ( empty( $class ) ) {
1351
+        if (empty($class)) {
1352 1352
             $class = '_standard';
1353 1353
         }
1354 1354
         
1355
-        return apply_filters( 'wpinv_get_item_vat_class', $class, $postID );
1355
+        return apply_filters('wpinv_get_item_vat_class', $class, $postID);
1356 1356
     }
1357 1357
     
1358
-    public static function item_class_label( $postID ) {        
1358
+    public static function item_class_label($postID) {        
1359 1359
         $vat_classes = self::get_all_classes();
1360 1360
         
1361
-        $class = self::get_item_class( $postID );
1362
-        $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' );
1361
+        $class = self::get_item_class($postID);
1362
+        $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing');
1363 1363
         
1364
-        return apply_filters( 'wpinv_item_class_label', $class, $postID );
1364
+        return apply_filters('wpinv_item_class_label', $class, $postID);
1365 1365
     }
1366 1366
     
1367
-    public static function get_item_rule( $postID ) {        
1368
-        $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true );
1367
+    public static function get_item_rule($postID) {        
1368
+        $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true);
1369 1369
 
1370
-        if ( empty( $rule_type ) ) {        
1370
+        if (empty($rule_type)) {        
1371 1371
             $rule_type = self::allow_vat_rules() ? 'digital' : 'physical';
1372 1372
         }
1373 1373
         
1374
-        return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID );
1374
+        return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID);
1375 1375
     }
1376 1376
     
1377
-    public static function item_rule_label( $postID ) {
1377
+    public static function item_rule_label($postID) {
1378 1378
         $vat_rules  = self::get_rules();
1379
-        $vat_rule   = self::get_item_rule( $postID );
1380
-        $vat_rule   = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule;
1379
+        $vat_rule   = self::get_item_rule($postID);
1380
+        $vat_rule   = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule;
1381 1381
         
1382
-        return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID );
1382
+        return apply_filters('wpinv_item_rule_label', $vat_rule, $postID);
1383 1383
     }
1384 1384
     
1385
-    public static function item_has_digital_rule( $item_id = 0 ) {        
1386
-        return self::get_item_rule( $item_id ) == 'digital' ? true : false;
1385
+    public static function item_has_digital_rule($item_id = 0) {        
1386
+        return self::get_item_rule($item_id) == 'digital' ? true : false;
1387 1387
     }
1388 1388
 
1389
-    public static function invoice_has_digital_rule( $invoice = 0 ) {        
1390
-        if ( !self::allow_vat_rules() ) {
1389
+    public static function invoice_has_digital_rule($invoice = 0) {        
1390
+        if (!self::allow_vat_rules()) {
1391 1391
             return false;
1392 1392
         }
1393 1393
         
1394
-        if ( empty( $invoice ) ) {
1394
+        if (empty($invoice)) {
1395 1395
             return true;
1396 1396
         }
1397 1397
         
1398
-        if ( is_int( $invoice ) ) {
1399
-            $invoice = new WPInv_Invoice( $invoice );
1398
+        if (is_int($invoice)) {
1399
+            $invoice = new WPInv_Invoice($invoice);
1400 1400
         }
1401 1401
         
1402
-        if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) {
1402
+        if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) {
1403 1403
             return true;
1404 1404
         }
1405 1405
         
1406
-        $cart_items  = $invoice->get_cart_details();
1406
+        $cart_items = $invoice->get_cart_details();
1407 1407
         
1408
-        if ( !empty( $cart_items ) ) {
1408
+        if (!empty($cart_items)) {
1409 1409
             $has_digital_rule = false;
1410 1410
             
1411
-            foreach ( $cart_items as $key => $item ) {
1412
-                if ( self::item_has_digital_rule( $item['id'] ) ) {
1411
+            foreach ($cart_items as $key => $item) {
1412
+                if (self::item_has_digital_rule($item['id'])) {
1413 1413
                     $has_digital_rule = true;
1414 1414
                     break;
1415 1415
                 }
@@ -1421,71 +1421,71 @@  discard block
 block discarded – undo
1421 1421
         return $has_digital_rule;
1422 1422
     }
1423 1423
     
1424
-    public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) {        
1425
-        if ( !wpinv_use_taxes() ) {
1424
+    public static function item_is_taxable($item_id = 0, $country = false, $state = false) {        
1425
+        if (!wpinv_use_taxes()) {
1426 1426
             return false;
1427 1427
         }
1428 1428
 
1429 1429
         $is_taxable = true;
1430 1430
 
1431
-        if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) {
1431
+        if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') {
1432 1432
             $is_taxable = false;
1433 1433
         }
1434 1434
 
1435
-        if ( !empty( $item_id ) && self::get_item_rule( $item_id ) == '_exempt' ) {
1435
+        if (!empty($item_id) && self::get_item_rule($item_id) == '_exempt') {
1436 1436
             $is_taxable = false;
1437 1437
         }
1438 1438
 
1439
-        return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state );
1439
+        return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state);
1440 1440
     }
1441 1441
     
1442
-    public static function find_rate( $country, $state, $rate, $class ) {
1442
+    public static function find_rate($country, $state, $rate, $class) {
1443 1443
         global $wpi_zero_tax;
1444 1444
 
1445
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1445
+        if ($class === '_exempt' || $wpi_zero_tax) {
1446 1446
             return 0;
1447 1447
         }
1448 1448
 
1449
-        $tax_rates   = wpinv_get_tax_rates();
1449
+        $tax_rates = wpinv_get_tax_rates();
1450 1450
         
1451
-        if ( $class !== '_standard' ) {
1452
-            $class_rates = self::get_vat_rates( $class );
1451
+        if ($class !== '_standard') {
1452
+            $class_rates = self::get_vat_rates($class);
1453 1453
             
1454
-            if ( is_array( $class_rates ) ) {
1454
+            if (is_array($class_rates)) {
1455 1455
                 $indexed_class_rates = array();
1456 1456
                 
1457
-                foreach ( $class_rates as $key => $cr ) {
1457
+                foreach ($class_rates as $key => $cr) {
1458 1458
                     $indexed_class_rates[$cr['country']] = $cr;
1459 1459
                 }
1460 1460
 
1461
-                $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) {
1461
+                $tax_rates = array_map(function($tr) use($indexed_class_rates) {
1462 1462
                     $tr_country = $tr['country'];
1463
-                    if ( !isset( $indexed_class_rates[$tr_country] ) ) {
1463
+                    if (!isset($indexed_class_rates[$tr_country])) {
1464 1464
                         return $tr;
1465 1465
                     }
1466 1466
                     $icr = $indexed_class_rates[$tr_country];
1467
-                    return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr;
1467
+                    return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr;
1468 1468
 
1469
-                }, $tax_rates, $class_rates );
1469
+                }, $tax_rates, $class_rates);
1470 1470
             }
1471 1471
         }
1472 1472
 
1473
-        if ( !empty( $tax_rates ) ) {
1474
-            foreach ( $tax_rates as $key => $tax_rate ) {
1475
-                if ( $country != $tax_rate['country'] )
1473
+        if (!empty($tax_rates)) {
1474
+            foreach ($tax_rates as $key => $tax_rate) {
1475
+                if ($country != $tax_rate['country'])
1476 1476
                     continue;
1477 1477
 
1478
-                if ( !empty( $tax_rate['global'] ) ) {
1479
-                    if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) {
1480
-                        $rate = number_format( $tax_rate['rate'], 4 );
1478
+                if (!empty($tax_rate['global'])) {
1479
+                    if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) {
1480
+                        $rate = number_format($tax_rate['rate'], 4);
1481 1481
                     }
1482 1482
                 } else {
1483
-                    if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
1483
+                    if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state']))
1484 1484
                         continue;
1485 1485
 
1486 1486
                     $state_rate = $tax_rate['rate'];
1487
-                    if ( 0 !== $state_rate || !empty( $state_rate ) ) {
1488
-                        $rate = number_format( $state_rate, 4 );
1487
+                    if (0 !== $state_rate || !empty($state_rate)) {
1488
+                        $rate = number_format($state_rate, 4);
1489 1489
                     }
1490 1490
                 }
1491 1491
             }
@@ -1494,84 +1494,84 @@  discard block
 block discarded – undo
1494 1494
         return $rate;
1495 1495
     }
1496 1496
     
1497
-    public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) {
1497
+    public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) {
1498 1498
         global $wpinv_options, $wpi_session, $wpi_item_id, $wpi_zero_tax;
1499 1499
         
1500 1500
         $item_id = $item_id > 0 ? $item_id : $wpi_item_id;
1501 1501
         $allow_vat_classes = self::allow_vat_classes();
1502
-        $class = $item_id ? self::get_item_class( $item_id ) : '_standard';
1502
+        $class = $item_id ? self::get_item_class($item_id) : '_standard';
1503 1503
 
1504
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1504
+        if ($class === '_exempt' || $wpi_zero_tax) {
1505 1505
             return 0;
1506
-        } else if ( !$allow_vat_classes ) {
1506
+        } else if (!$allow_vat_classes) {
1507 1507
             $class = '_standard';
1508 1508
         }
1509 1509
 
1510
-        if( !empty( $_POST['wpinv_country'] ) ) {
1510
+        if (!empty($_POST['wpinv_country'])) {
1511 1511
             $post_country = $_POST['wpinv_country'];
1512
-        } elseif( !empty( $_POST['wpinv_country'] ) ) {
1512
+        } elseif (!empty($_POST['wpinv_country'])) {
1513 1513
             $post_country = $_POST['wpinv_country'];
1514
-        } elseif( !empty( $_POST['country'] ) ) {
1514
+        } elseif (!empty($_POST['country'])) {
1515 1515
             $post_country = $_POST['country'];
1516 1516
         } else {
1517 1517
             $post_country = '';
1518 1518
         }
1519 1519
 
1520
-        $country        = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country );
1521
-        $base_country   = wpinv_is_base_country( $country );
1520
+        $country        = !empty($post_country) ? $post_country : wpinv_default_billing_country($country);
1521
+        $base_country   = wpinv_is_base_country($country);
1522 1522
         
1523
-        $requires_vat   = self::requires_vat( 0, false );
1524
-        $is_digital     = self::get_item_rule( $item_id ) == 'digital' ;
1525
-        $rate           = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate;
1523
+        $requires_vat   = self::requires_vat(0, false);
1524
+        $is_digital     = self::get_item_rule($item_id) == 'digital';
1525
+        $rate           = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate;
1526 1526
           
1527
-        if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country
1527
+        if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country
1528 1528
             $rate = 0;
1529
-        } else if ( $requires_vat ) {
1530
-            $vat_number = self::get_user_vat_number( '', 0, true );
1529
+        } else if ($requires_vat) {
1530
+            $vat_number = self::get_user_vat_number('', 0, true);
1531 1531
             $vat_info   = self::current_vat_data();
1532 1532
             
1533
-            if ( is_array( $vat_info ) ) {
1534
-                $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : "";
1533
+            if (is_array($vat_info)) {
1534
+                $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : "";
1535 1535
             }
1536 1536
             
1537
-            if ( $country == 'UK' ) {
1537
+            if ($country == 'UK') {
1538 1538
                 $country = 'GB';
1539 1539
             }
1540 1540
 
1541
-            if ( !empty( $vat_number ) ) {
1541
+            if (!empty($vat_number)) {
1542 1542
                 $rate = 0;
1543 1543
             } else {
1544
-                $rate = self::find_rate( $country, $state, $rate, $class ); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate
1544
+                $rate = self::find_rate($country, $state, $rate, $class); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate
1545 1545
             }
1546 1546
 
1547
-            if ( empty( $vat_number ) && !$is_digital ) {
1548
-                if ( $base_country ) {
1549
-                    $rate = self::find_rate( $country, null, $rate, $class );
1547
+            if (empty($vat_number) && !$is_digital) {
1548
+                if ($base_country) {
1549
+                    $rate = self::find_rate($country, null, $rate, $class);
1550 1550
                 } else {
1551
-                    if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1551
+                    if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1552 1552
                         $rate = $wpinv_options['eu_fallback_rate'];
1553
-                    } else if( !empty( $country ) ) {
1554
-                        $rate = self::find_rate( $country, $state, $rate, $class );
1553
+                    } else if (!empty($country)) {
1554
+                        $rate = self::find_rate($country, $state, $rate, $class);
1555 1555
                     }
1556 1556
                 }
1557
-            } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) {
1558
-                if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1557
+            } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) {
1558
+                if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1559 1559
                     $rate = $wpinv_options['eu_fallback_rate'];
1560
-                } else if( !empty( $country ) ) {
1561
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1560
+                } else if (!empty($country)) {
1561
+                    $rate = self::find_rate($country, $state, $rate, $class);
1562 1562
                 }
1563 1563
             }
1564 1564
         } else {
1565
-            if ( $is_digital ) {
1565
+            if ($is_digital) {
1566 1566
                 $ip_country_code = self::get_country_by_ip();
1567 1567
                 
1568
-                if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) {
1569
-                    $rate = self::find_rate( $ip_country_code, '', 0, $class );
1568
+                if ($ip_country_code && self::is_eu_state($ip_country_code)) {
1569
+                    $rate = self::find_rate($ip_country_code, '', 0, $class);
1570 1570
                 } else {
1571
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1571
+                    $rate = self::find_rate($country, $state, $rate, $class);
1572 1572
                 }
1573 1573
             } else {
1574
-                $rate = self::find_rate( $country, $state, $rate, $class );
1574
+                $rate = self::find_rate($country, $state, $rate, $class);
1575 1575
             }
1576 1576
         }
1577 1577
 
@@ -1581,48 +1581,48 @@  discard block
 block discarded – undo
1581 1581
     public static function current_vat_data() {
1582 1582
         global $wpi_session;
1583 1583
         
1584
-        return $wpi_session->get( 'user_vat_data' );
1584
+        return $wpi_session->get('user_vat_data');
1585 1585
     }
1586 1586
     
1587
-    public static function get_user_country( $country = '', $user_id = 0 ) {
1588
-        $user_address = wpinv_get_user_address( $user_id, false );
1587
+    public static function get_user_country($country = '', $user_id = 0) {
1588
+        $user_address = wpinv_get_user_address($user_id, false);
1589 1589
         
1590
-        if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1590
+        if (wpinv_get_option('vat_ip_country_default')) {
1591 1591
             $country = '';
1592 1592
         }
1593 1593
         
1594
-        $country    = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country'];
1595
-        $result     = apply_filters( 'wpinv_get_user_country', $country, $user_id );
1594
+        $country    = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country'];
1595
+        $result     = apply_filters('wpinv_get_user_country', $country, $user_id);
1596 1596
 
1597
-        if ( empty( $result ) ) {
1597
+        if (empty($result)) {
1598 1598
             $result = self::get_country_by_ip();
1599 1599
         }
1600 1600
 
1601 1601
         return $result;
1602 1602
     }
1603 1603
     
1604
-    public static function set_user_country( $country = '', $user_id = 0 ) {
1604
+    public static function set_user_country($country = '', $user_id = 0) {
1605 1605
         global $wpi_userID;
1606 1606
         
1607
-        if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) {
1607
+        if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) {
1608 1608
             $country = wpinv_get_default_country();
1609 1609
         }
1610 1610
         
1611 1611
         return $country;
1612 1612
     }
1613 1613
     
1614
-    public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) {
1614
+    public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) {
1615 1615
         global $wpi_current_id, $wpi_userID;
1616 1616
         
1617
-        if ( !empty( $_POST['new_user'] ) ) {
1617
+        if (!empty($_POST['new_user'])) {
1618 1618
             return '';
1619 1619
         }
1620 1620
         
1621
-        if ( empty( $user_id ) ) {
1622
-            $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() );
1621
+        if (empty($user_id)) {
1622
+            $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id());
1623 1623
         }
1624 1624
 
1625
-        $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true );
1625
+        $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true);
1626 1626
         
1627 1627
         /* TODO
1628 1628
         if ( $is_valid && $vat_number ) {
@@ -1633,38 +1633,38 @@  discard block
 block discarded – undo
1633 1633
         }
1634 1634
         */
1635 1635
 
1636
-        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid );
1636
+        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid);
1637 1637
     }
1638 1638
     
1639
-    public static function get_user_company( $company = '', $user_id = 0 ) {
1639
+    public static function get_user_company($company = '', $user_id = 0) {
1640 1640
         global $wpi_current_id, $wpi_userID;
1641 1641
         
1642
-        if ( empty( $user_id ) ) {
1643
-            $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() );
1642
+        if (empty($user_id)) {
1643
+            $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id());
1644 1644
         }
1645 1645
 
1646
-        $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true );
1646
+        $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true);
1647 1647
 
1648
-        return apply_filters( 'wpinv_user_company', $company, $user_id );
1648
+        return apply_filters('wpinv_user_company', $company, $user_id);
1649 1649
     }
1650 1650
     
1651
-    public static function save_user_vat_details( $company = '', $vat_number = '' ) {
1652
-        $save = apply_filters( 'wpinv_allow_save_user_vat_details', true );
1651
+    public static function save_user_vat_details($company = '', $vat_number = '') {
1652
+        $save = apply_filters('wpinv_allow_save_user_vat_details', true);
1653 1653
 
1654
-        if ( is_user_logged_in() && $save ) {
1654
+        if (is_user_logged_in() && $save) {
1655 1655
             $user_id = get_current_user_id();
1656 1656
 
1657
-            if ( !empty( $vat_number ) ) {
1658
-                update_user_meta( $user_id, '_wpinv_vat_number', $vat_number );
1657
+            if (!empty($vat_number)) {
1658
+                update_user_meta($user_id, '_wpinv_vat_number', $vat_number);
1659 1659
             } else {
1660
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1660
+                delete_user_meta($user_id, '_wpinv_vat_number');
1661 1661
             }
1662 1662
 
1663
-            if ( !empty( $company ) ) {
1664
-                update_user_meta( $user_id, '_wpinv_company', $company );
1663
+            if (!empty($company)) {
1664
+                update_user_meta($user_id, '_wpinv_company', $company);
1665 1665
             } else {
1666
-                delete_user_meta( $user_id, '_wpinv_company');
1667
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1666
+                delete_user_meta($user_id, '_wpinv_company');
1667
+                delete_user_meta($user_id, '_wpinv_vat_number');
1668 1668
             }
1669 1669
         }
1670 1670
 
@@ -1674,113 +1674,113 @@  discard block
 block discarded – undo
1674 1674
     public static function ajax_vat_validate() {
1675 1675
         global $wpinv_options, $wpi_session;
1676 1676
         
1677
-        $is_checkout            = ( !empty( $_POST['source'] ) && $_POST['source'] == 'checkout' ) ? true : false;
1677
+        $is_checkout            = (!empty($_POST['source']) && $_POST['source'] == 'checkout') ? true : false;
1678 1678
         $response               = array();
1679 1679
         $response['success']    = false;
1680 1680
         
1681
-        if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) {
1682
-            $response['error'] = __( 'Invalid security nonce', 'invoicing' );
1683
-            wp_send_json( $response );
1681
+        if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) {
1682
+            $response['error'] = __('Invalid security nonce', 'invoicing');
1683
+            wp_send_json($response);
1684 1684
         }
1685 1685
         
1686
-        $vat_name   = self::get_vat_name();
1686
+        $vat_name = self::get_vat_name();
1687 1687
         
1688
-        if ( $is_checkout ) {
1688
+        if ($is_checkout) {
1689 1689
             $invoice = wpinv_get_invoice_cart();
1690 1690
             
1691
-            if ( !self::requires_vat( false, 0, self::invoice_has_digital_rule( $invoice ) ) ) {
1691
+            if (!self::requires_vat(false, 0, self::invoice_has_digital_rule($invoice))) {
1692 1692
                 $vat_info = array();
1693
-                $wpi_session->set( 'user_vat_data', $vat_info );
1693
+                $wpi_session->set('user_vat_data', $vat_info);
1694 1694
 
1695 1695
                 self::save_user_vat_details();
1696 1696
                 
1697 1697
                 $response['success'] = true;
1698
-                $response['message'] = wp_sprintf( __( 'Ignore %s', 'invoicing' ), $vat_name );
1699
-                wp_send_json( $response );
1698
+                $response['message'] = wp_sprintf(__('Ignore %s', 'invoicing'), $vat_name);
1699
+                wp_send_json($response);
1700 1700
             }
1701 1701
         }
1702 1702
         
1703
-        $company    = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : '';
1704
-        $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : '';
1703
+        $company    = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : '';
1704
+        $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : '';
1705 1705
         
1706
-        $vat_info = $wpi_session->get( 'user_vat_data' );
1707
-        if ( !is_array( $vat_info ) || empty( $vat_info ) ) {
1708
-            $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true );
1706
+        $vat_info = $wpi_session->get('user_vat_data');
1707
+        if (!is_array($vat_info) || empty($vat_info)) {
1708
+            $vat_info = array('company'=> $company, 'number' => '', 'valid' => true);
1709 1709
         }
1710 1710
         
1711
-        if ( empty( $vat_number ) ) {
1712
-            if ( $is_checkout ) {
1711
+        if (empty($vat_number)) {
1712
+            if ($is_checkout) {
1713 1713
                 $response['success'] = true;
1714
-                $response['message'] = wp_sprintf( __( 'No %s number has been applied. %s will be added to invoice totals', 'invoicing' ), $vat_name, $vat_name );
1714
+                $response['message'] = wp_sprintf(__('No %s number has been applied. %s will be added to invoice totals', 'invoicing'), $vat_name, $vat_name);
1715 1715
                 
1716
-                $vat_info = $wpi_session->get( 'user_vat_data' );
1716
+                $vat_info = $wpi_session->get('user_vat_data');
1717 1717
                 $vat_info['number'] = "";
1718 1718
                 $vat_info['valid'] = true;
1719 1719
                 
1720
-                self::save_user_vat_details( $company );
1720
+                self::save_user_vat_details($company);
1721 1721
             } else {
1722
-                $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
1722
+                $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
1723 1723
                 
1724 1724
                 $vat_info['valid'] = false;
1725 1725
             }
1726 1726
 
1727
-            $wpi_session->set( 'user_vat_data', $vat_info );
1728
-            wp_send_json( $response );
1727
+            $wpi_session->set('user_vat_data', $vat_info);
1728
+            wp_send_json($response);
1729 1729
         }
1730 1730
         
1731
-        if ( empty( $company ) ) {
1731
+        if (empty($company)) {
1732 1732
             $vat_info['valid'] = false;
1733
-            $wpi_session->set( 'user_vat_data', $vat_info );
1733
+            $wpi_session->set('user_vat_data', $vat_info);
1734 1734
             
1735
-            $response['error'] = __( 'Please enter your registered company name!', 'invoicing' );
1736
-            wp_send_json( $response );
1735
+            $response['error'] = __('Please enter your registered company name!', 'invoicing');
1736
+            wp_send_json($response);
1737 1737
         }
1738 1738
         
1739
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
1740
-            if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1739
+        if (!empty($wpinv_options['vat_vies_check'])) {
1740
+            if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1741 1741
                 $vat_info['valid'] = false;
1742
-                $wpi_session->set( 'user_vat_data', $vat_info );
1742
+                $wpi_session->set('user_vat_data', $vat_info);
1743 1743
                 
1744
-                $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1745
-                wp_send_json( $response );
1744
+                $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1745
+                wp_send_json($response);
1746 1746
             }
1747 1747
             
1748 1748
             $response['success'] = true;
1749
-            $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1749
+            $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1750 1750
         } else {
1751
-            $result = self::check_vat( $vat_number );
1751
+            $result = self::check_vat($vat_number);
1752 1752
             
1753
-            if ( empty( $result['valid'] ) ) {
1753
+            if (empty($result['valid'])) {
1754 1754
                 $response['error'] = $result['message'];
1755
-                wp_send_json( $response );
1755
+                wp_send_json($response);
1756 1756
             }
1757 1757
             
1758
-            $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1759
-            $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1758
+            $vies_company = !empty($result['company']) ? $result['company'] : '';
1759
+            $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1760 1760
             
1761
-            $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1761
+            $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1762 1762
 
1763
-            if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) {
1763
+            if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) {
1764 1764
                 $response['success'] = true;
1765
-                $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1765
+                $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1766 1766
             } else {           
1767 1767
                 $vat_info['valid'] = false;
1768
-                $wpi_session->set( 'user_vat_data', $vat_info );
1768
+                $wpi_session->set('user_vat_data', $vat_info);
1769 1769
                 
1770 1770
                 $response['success'] = false;
1771
-                $response['message'] = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name );
1772
-                wp_send_json( $response );
1771
+                $response['message'] = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name);
1772
+                wp_send_json($response);
1773 1773
             }
1774 1774
         }
1775 1775
         
1776
-        if ( $is_checkout ) {
1777
-            self::save_user_vat_details( $company, $vat_number );
1776
+        if ($is_checkout) {
1777
+            self::save_user_vat_details($company, $vat_number);
1778 1778
 
1779
-            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true );
1780
-            $wpi_session->set( 'user_vat_data', $vat_info );
1779
+            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true);
1780
+            $wpi_session->set('user_vat_data', $vat_info);
1781 1781
         }
1782 1782
 
1783
-        wp_send_json( $response );
1783
+        wp_send_json($response);
1784 1784
     }
1785 1785
     
1786 1786
     public static function ajax_vat_reset() {
@@ -1789,161 +1789,161 @@  discard block
 block discarded – undo
1789 1789
         $company    = is_user_logged_in() ? self::get_user_company() : '';
1790 1790
         $vat_number = self::get_user_vat_number();
1791 1791
         
1792
-        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false );
1793
-        $wpi_session->set( 'user_vat_data', $vat_info );
1792
+        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false);
1793
+        $wpi_session->set('user_vat_data', $vat_info);
1794 1794
         
1795 1795
         $response                       = array();
1796 1796
         $response['success']            = true;
1797 1797
         $response['data']['company']    = $company;
1798 1798
         $response['data']['number']     = $vat_number;
1799 1799
         
1800
-        wp_send_json( $response );
1800
+        wp_send_json($response);
1801 1801
     }
1802 1802
     
1803
-    public static function checkout_vat_validate( $valid_data, $post ) {
1803
+    public static function checkout_vat_validate($valid_data, $post) {
1804 1804
         global $wpinv_options, $wpi_session;
1805 1805
 
1806
-        $vat_name  = __( self::get_vat_name(), 'invoicing' );
1806
+        $vat_name = __(self::get_vat_name(), 'invoicing');
1807 1807
 
1808
-        if ( !isset( $_POST['_wpi_nonce'] ) || !wp_verify_nonce( $_POST['_wpi_nonce'], 'vat_validation' ) ) {
1809
-            wpinv_set_error( 'vat_validation', wp_sprintf( __( "Invalid %s validation request.", 'invoicing' ), $vat_name ) );
1808
+        if (!isset($_POST['_wpi_nonce']) || !wp_verify_nonce($_POST['_wpi_nonce'], 'vat_validation')) {
1809
+            wpinv_set_error('vat_validation', wp_sprintf(__("Invalid %s validation request.", 'invoicing'), $vat_name));
1810 1810
             return;
1811 1811
         }
1812 1812
 
1813
-        $vat_saved = $wpi_session->get( 'user_vat_data' );
1814
-        $wpi_session->set( 'user_vat_data', null );
1813
+        $vat_saved = $wpi_session->get('user_vat_data');
1814
+        $wpi_session->set('user_vat_data', null);
1815 1815
         
1816 1816
         $invoice        = wpinv_get_invoice_cart();
1817 1817
         $amount         = $invoice->get_total();
1818
-        $is_digital     = self::invoice_has_digital_rule( $invoice );
1819
-        $no_vat         = !self::requires_vat( 0, false, $is_digital );
1818
+        $is_digital     = self::invoice_has_digital_rule($invoice);
1819
+        $no_vat         = !self::requires_vat(0, false, $is_digital);
1820 1820
         
1821
-        $company        = !empty( $_POST['wpinv_company'] ) ? $_POST['wpinv_company'] : null;
1822
-        $vat_number     = !empty( $_POST['wpinv_vat_number'] ) ? $_POST['wpinv_vat_number'] : null;
1823
-        $country        = !empty( $_POST['wpinv_country'] ) ? $_POST['wpinv_country'] : $invoice->country;
1824
-        if ( empty( $country ) ) {
1821
+        $company        = !empty($_POST['wpinv_company']) ? $_POST['wpinv_company'] : null;
1822
+        $vat_number     = !empty($_POST['wpinv_vat_number']) ? $_POST['wpinv_vat_number'] : null;
1823
+        $country        = !empty($_POST['wpinv_country']) ? $_POST['wpinv_country'] : $invoice->country;
1824
+        if (empty($country)) {
1825 1825
             $country = wpinv_default_billing_country();
1826 1826
         }
1827 1827
         
1828
-        if ( !$is_digital && $no_vat ) {
1828
+        if (!$is_digital && $no_vat) {
1829 1829
             return;
1830 1830
         }
1831 1831
             
1832
-        $vat_data           = array( 'company' => '', 'number' => '', 'valid' => false );
1832
+        $vat_data           = array('company' => '', 'number' => '', 'valid' => false);
1833 1833
         
1834 1834
         $ip_country_code    = self::get_country_by_ip();
1835
-        $is_eu_state        = self::is_eu_state( $country );
1836
-        $is_eu_state_ip     = self::is_eu_state( $ip_country_code );
1835
+        $is_eu_state        = self::is_eu_state($country);
1836
+        $is_eu_state_ip     = self::is_eu_state($ip_country_code);
1837 1837
         $is_non_eu_user     = !$is_eu_state && !$is_eu_state_ip;
1838 1838
 
1839
-        if ( $is_digital && !$is_non_eu_user && empty( $vat_number ) && apply_filters( 'wpinv_checkout_requires_country', true, $amount ) ) {
1839
+        if ($is_digital && !$is_non_eu_user && empty($vat_number) && apply_filters('wpinv_checkout_requires_country', true, $amount)) {
1840 1840
             $vat_data['adddress_confirmed'] = false;
1841 1841
             
1842
-            if ( !isset( $_POST['wpinv_adddress_confirmed'] ) ) {
1843
-                if ( $ip_country_code != $country ) {
1844
-                    wpinv_set_error( 'vat_validation', sprintf( __( 'The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing' ), '<a href="#wpinv_adddress_confirm">', '</a>' ) );
1842
+            if (!isset($_POST['wpinv_adddress_confirmed'])) {
1843
+                if ($ip_country_code != $country) {
1844
+                    wpinv_set_error('vat_validation', sprintf(__('The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing'), '<a href="#wpinv_adddress_confirm">', '</a>'));
1845 1845
                 }
1846 1846
             } else {
1847 1847
                 $vat_data['adddress_confirmed'] = true;
1848 1848
             }
1849 1849
         }
1850 1850
 
1851
-        if ( !empty( $wpinv_options['vat_prevent_b2c_purchase'] ) && !$is_non_eu_user && ( empty( $vat_number ) || $no_vat ) ) {
1852
-            if ( $is_eu_state ) {
1853
-                wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing' ), $vat_name ) );
1854
-            } else if ( $is_digital && $is_eu_state_ip ) {
1855
-                wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing' ), $vat_name ) );
1851
+        if (!empty($wpinv_options['vat_prevent_b2c_purchase']) && !$is_non_eu_user && (empty($vat_number) || $no_vat)) {
1852
+            if ($is_eu_state) {
1853
+                wpinv_set_error('vat_validation', wp_sprintf(__('Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing'), $vat_name));
1854
+            } else if ($is_digital && $is_eu_state_ip) {
1855
+                wpinv_set_error('vat_validation', wp_sprintf(__('Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing'), $vat_name));
1856 1856
             }
1857 1857
         }
1858 1858
 
1859
-        if ( !$is_eu_state || $no_vat || empty( $vat_number ) ) {
1859
+        if (!$is_eu_state || $no_vat || empty($vat_number)) {
1860 1860
             return;
1861 1861
         }
1862 1862
 
1863
-        if ( !empty( $vat_saved ) && isset( $vat_saved['valid'] ) ) {
1864
-            $vat_data['valid']  = $vat_saved['valid'];
1863
+        if (!empty($vat_saved) && isset($vat_saved['valid'])) {
1864
+            $vat_data['valid'] = $vat_saved['valid'];
1865 1865
         }
1866 1866
             
1867
-        if ( $company !== null ) {
1867
+        if ($company !== null) {
1868 1868
             $vat_data['company'] = $company;
1869 1869
         }
1870 1870
 
1871 1871
         $message = '';
1872
-        if ( $vat_number !== null ) {
1872
+        if ($vat_number !== null) {
1873 1873
             $vat_data['number'] = $vat_number;
1874 1874
             
1875
-            if ( !$vat_data['valid'] || ( $vat_saved['number'] !== $vat_data['number'] ) || ( $vat_saved['company'] !== $vat_data['company'] ) ) {
1876
-                if ( !empty( $wpinv_options['vat_vies_check'] ) ) {            
1877
-                    if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1875
+            if (!$vat_data['valid'] || ($vat_saved['number'] !== $vat_data['number']) || ($vat_saved['company'] !== $vat_data['company'])) {
1876
+                if (!empty($wpinv_options['vat_vies_check'])) {            
1877
+                    if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1878 1878
                         $vat_data['valid'] = false;
1879 1879
                     }
1880 1880
                 } else {
1881
-                    $result = self::check_vat( $vat_number );
1881
+                    $result = self::check_vat($vat_number);
1882 1882
                     
1883
-                    if ( !empty( $result['valid'] ) ) {                
1883
+                    if (!empty($result['valid'])) {                
1884 1884
                         $vat_data['valid'] = true;
1885
-                        $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1886
-                        $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1885
+                        $vies_company = !empty($result['company']) ? $result['company'] : '';
1886
+                        $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1887 1887
                     
1888
-                        $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1888
+                        $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1889 1889
 
1890
-                        if ( !( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) ) {         
1890
+                        if (!(!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company)) {         
1891 1891
                             $vat_data['valid'] = false;
1892 1892
                             
1893
-                            $message = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name );
1893
+                            $message = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name);
1894 1894
                         }
1895 1895
                     } else {
1896
-                        $message = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1896
+                        $message = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1897 1897
                     }
1898 1898
                 }
1899 1899
                 
1900
-                if ( !$vat_data['valid'] ) {
1901
-                    $error = wp_sprintf( __( 'The %s %s number %s you have entered has not been validated', 'invoicing' ), '<a href="#wpi-vat-details">', $vat_name, '</a>' ) . ( $message ? ' ( ' . $message . ' )' : '' );
1902
-                    wpinv_set_error( 'vat_validation', $error );
1900
+                if (!$vat_data['valid']) {
1901
+                    $error = wp_sprintf(__('The %s %s number %s you have entered has not been validated', 'invoicing'), '<a href="#wpi-vat-details">', $vat_name, '</a>') . ($message ? ' ( ' . $message . ' )' : '');
1902
+                    wpinv_set_error('vat_validation', $error);
1903 1903
                 }
1904 1904
             }
1905 1905
         }
1906 1906
 
1907
-        $wpi_session->set( 'user_vat_data', $vat_data );
1907
+        $wpi_session->set('user_vat_data', $vat_data);
1908 1908
     }
1909 1909
     
1910
-    public static function checkout_vat_fields( $billing_details ) {
1910
+    public static function checkout_vat_fields($billing_details) {
1911 1911
         global $wpi_session, $wpinv_options, $wpi_country, $wpi_requires_vat;
1912 1912
         
1913 1913
         $ip_address         = wpinv_get_ip();
1914 1914
         $ip_country_code    = self::get_country_by_ip();
1915 1915
         
1916
-        $tax_label          = __( self::get_vat_name(), 'invoicing' );
1916
+        $tax_label          = __(self::get_vat_name(), 'invoicing');
1917 1917
         $invoice            = wpinv_get_invoice_cart();
1918
-        $is_digital         = self::invoice_has_digital_rule( $invoice );
1918
+        $is_digital         = self::invoice_has_digital_rule($invoice);
1919 1919
         $wpi_country        = $invoice->country;
1920 1920
         
1921
-        $requires_vat       = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat( 0, false, $is_digital );
1921
+        $requires_vat       = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat(0, false, $is_digital);
1922 1922
         $wpi_requires_vat   = $requires_vat;
1923 1923
         
1924 1924
         $company            = self::get_user_company();
1925 1925
         $vat_number         = self::get_user_vat_number();
1926 1926
         
1927
-        $validated          = $vat_number ? self::get_user_vat_number( '', 0, true ) : 1;
1928
-        $vat_info           = $wpi_session->get( 'user_vat_data' );
1927
+        $validated          = $vat_number ? self::get_user_vat_number('', 0, true) : 1;
1928
+        $vat_info           = $wpi_session->get('user_vat_data');
1929 1929
 
1930
-        if ( is_array( $vat_info ) ) {
1931
-            $company    = isset( $vat_info['company'] ) ? $vat_info['company'] : '';
1932
-            $vat_number = isset( $vat_info['number'] ) ? $vat_info['number'] : '';
1933
-            $validated  = isset( $vat_info['valid'] ) ? $vat_info['valid'] : false;
1930
+        if (is_array($vat_info)) {
1931
+            $company    = isset($vat_info['company']) ? $vat_info['company'] : '';
1932
+            $vat_number = isset($vat_info['number']) ? $vat_info['number'] : '';
1933
+            $validated  = isset($vat_info['valid']) ? $vat_info['valid'] : false;
1934 1934
         }
1935 1935
         
1936 1936
         $selected_country = $invoice->country ? $invoice->country : wpinv_default_billing_country();
1937 1937
 
1938
-        if ( $ip_country_code == 'UK' ) {
1938
+        if ($ip_country_code == 'UK') {
1939 1939
             $ip_country_code = 'GB';
1940 1940
         }
1941 1941
         
1942
-        if ( $selected_country == 'UK' ) {
1942
+        if ($selected_country == 'UK') {
1943 1943
             $selected_country = 'GB';
1944 1944
         }
1945 1945
         
1946
-        if ( $requires_vat && ( self::same_country_rule() == 'no' && wpinv_is_base_country( $selected_country ) || !self::allow_vat_rules() ) ) {
1946
+        if ($requires_vat && (self::same_country_rule() == 'no' && wpinv_is_base_country($selected_country) || !self::allow_vat_rules())) {
1947 1947
             $requires_vat = false;
1948 1948
         }
1949 1949
 
@@ -1951,52 +1951,52 @@  discard block
 block discarded – undo
1951 1951
         $display_validate_btn   = 'none';
1952 1952
         $display_reset_btn      = 'none';
1953 1953
         
1954
-        if ( !empty( $vat_number ) && $validated ) {
1955
-            $vat_vailidated_text    = wp_sprintf( __( '%s number validated', 'invoicing' ), $tax_label );
1954
+        if (!empty($vat_number) && $validated) {
1955
+            $vat_vailidated_text    = wp_sprintf(__('%s number validated', 'invoicing'), $tax_label);
1956 1956
             $vat_vailidated_class   = 'wpinv-vat-stat-1';
1957 1957
             $display_reset_btn      = 'block';
1958 1958
         } else {
1959
-            $vat_vailidated_text    = empty( $vat_number ) ? '' : wp_sprintf( __( '%s number not validated', 'invoicing' ), $tax_label );
1960
-            $vat_vailidated_class   = empty( $vat_number ) ? '' : 'wpinv-vat-stat-0';
1959
+            $vat_vailidated_text    = empty($vat_number) ? '' : wp_sprintf(__('%s number not validated', 'invoicing'), $tax_label);
1960
+            $vat_vailidated_class   = empty($vat_number) ? '' : 'wpinv-vat-stat-0';
1961 1961
             $display_validate_btn   = 'block';
1962 1962
         }
1963 1963
         
1964
-        $show_ip_country        = $is_digital && ( empty( $vat_number ) || !$requires_vat ) && $ip_country_code != $selected_country ? 'block' : 'none';
1964
+        $show_ip_country = $is_digital && (empty($vat_number) || !$requires_vat) && $ip_country_code != $selected_country ? 'block' : 'none';
1965 1965
         ?>
1966 1966
         <div id="wpi-vat-details" class="wpi-vat-details clearfix" style="display:<?php echo $display_vat_details; ?>">
1967 1967
             <div id="wpi_vat_info" class="clearfix panel panel-default">
1968
-                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf( __( '%s Details', 'invoicing' ), $tax_label );?></h3></div>
1968
+                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf(__('%s Details', 'invoicing'), $tax_label); ?></h3></div>
1969 1969
                 <div id="wpinv-fields-box" class="panel-body">
1970 1970
                     <p id="wpi_show_vat_note">
1971
-                        <?php echo wp_sprintf( __( 'Validate your registered %s number to exclude tax.', 'invoicing' ), $tax_label ); ?>
1971
+                        <?php echo wp_sprintf(__('Validate your registered %s number to exclude tax.', 'invoicing'), $tax_label); ?>
1972 1972
                     </p>
1973 1973
                     <div id="wpi_vat_fields" class="wpi_vat_info">
1974 1974
                         <p class="wpi-cart-field wpi-col2 wpi-colf">
1975
-                            <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?></label>
1975
+                            <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label>
1976 1976
                             <?php
1977
-                            echo wpinv_html_text( array(
1977
+                            echo wpinv_html_text(array(
1978 1978
                                     'id'            => 'wpinv_company',
1979 1979
                                     'name'          => 'wpinv_company',
1980 1980
                                     'value'         => $company,
1981 1981
                                     'class'         => 'wpi-input form-control',
1982
-                                    'placeholder'   => __( 'Company name', 'invoicing' ),
1983
-                                ) );
1982
+                                    'placeholder'   => __('Company name', 'invoicing'),
1983
+                                ));
1984 1984
                             ?>
1985 1985
                         </p>
1986 1986
                         <p class="wpi-cart-field wpi-col2 wpi-coll wpi-cart-field-vat">
1987
-                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf( __( '%s Number', 'invoicing' ), $tax_label );?></label>
1987
+                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf(__('%s Number', 'invoicing'), $tax_label); ?></label>
1988 1988
                             <span id="wpinv_vat_number-wrap">
1989 1989
                                 <label for="wpinv_vat_number" class="wpinv-label"></label>
1990
-                                <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr( wp_sprintf( __( '%s number', 'invoicing' ), $tax_label ) );?>" value="<?php esc_attr_e( $vat_number );?>" id="wpinv_vat_number" name="wpinv_vat_number">
1991
-                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class;?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text;?></font></span>
1990
+                                <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr(wp_sprintf(__('%s number', 'invoicing'), $tax_label)); ?>" value="<?php esc_attr_e($vat_number); ?>" id="wpinv_vat_number" name="wpinv_vat_number">
1991
+                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class; ?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text; ?></font></span>
1992 1992
                             </span>
1993 1993
                         </p>
1994 1994
                         <p class="wpi-cart-field wpi-col wpi-colf wpi-cart-field-actions">
1995
-                            <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf( __("Validate %s Number", 'invoicing'), $tax_label ); ?></button>
1996
-                            <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf( __("Reset %s", 'invoicing'), $tax_label ); ?></button>
1995
+                            <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf(__("Validate %s Number", 'invoicing'), $tax_label); ?></button>
1996
+                            <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf(__("Reset %s", 'invoicing'), $tax_label); ?></button>
1997 1997
                             <span class="wpi-vat-box wpi-vat-box-info"><span id="text"></span></span>
1998 1998
                             <span class="wpi-vat-box wpi-vat-box-error"><span id="text"></span></span>
1999
-                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce( 'vat_validation' ) ?>" />
1999
+                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce('vat_validation') ?>" />
2000 2000
                         </p>
2001 2001
                     </div>
2002 2002
                 </div>
@@ -2010,32 +2010,32 @@  discard block
 block discarded – undo
2010 2010
                 </span>
2011 2011
             </div>
2012 2012
         </div>
2013
-        <?php if ( empty( $wpinv_options['hide_ip_address'] ) ) { 
2014
-            $ip_link = '<a title="' . esc_attr( __( 'View more details on map', 'invoicing' ) ) . '" target="_blank" href="' . esc_url( admin_url( 'admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address ) ) . '" class="wpi-ip-address-link">' . $ip_address . '&nbsp;&nbsp;<i class="fa fa-external-link-square" aria-hidden="true"></i></a>';
2013
+        <?php if (empty($wpinv_options['hide_ip_address'])) { 
2014
+            $ip_link = '<a title="' . esc_attr(__('View more details on map', 'invoicing')) . '" target="_blank" href="' . esc_url(admin_url('admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address)) . '" class="wpi-ip-address-link">' . $ip_address . '&nbsp;&nbsp;<i class="fa fa-external-link-square" aria-hidden="true"></i></a>';
2015 2015
         ?>
2016 2016
         <div class="wpi-ip-info clearfix panel panel-info">
2017 2017
             <div id="wpinv-fields-box" class="panel-body">
2018
-                <span><?php echo wp_sprintf( __( "Your IP address is: %s", 'invoicing' ), $ip_link ); ?></span>
2018
+                <span><?php echo wp_sprintf(__("Your IP address is: %s", 'invoicing'), $ip_link); ?></span>
2019 2019
             </div>
2020 2020
         </div>
2021 2021
         <?php }
2022 2022
     }
2023 2023
     
2024
-    public static function show_vat_notice( $invoice ) {
2025
-        if ( empty( $invoice ) ) {
2024
+    public static function show_vat_notice($invoice) {
2025
+        if (empty($invoice)) {
2026 2026
             return NULL;
2027 2027
         }
2028 2028
         
2029
-        $label      = wpinv_get_option( 'vat_invoice_notice_label' );
2030
-        $notice     = wpinv_get_option( 'vat_invoice_notice' );
2031
-        if ( $label || $notice ) {
2029
+        $label      = wpinv_get_option('vat_invoice_notice_label');
2030
+        $notice     = wpinv_get_option('vat_invoice_notice');
2031
+        if ($label || $notice) {
2032 2032
         ?>
2033 2033
         <div class="row wpinv-vat-notice">
2034 2034
             <div class="col-sm-12">
2035
-                <?php if ( $label ) { ?>
2036
-                <strong><?php _e( $label, 'invoicing' ); ?></strong>
2037
-                <?php } if ( $notice ) { ?>
2038
-                <?php echo wpautop( wptexturize( __( $notice, 'invoicing' ) ) ) ?>
2035
+                <?php if ($label) { ?>
2036
+                <strong><?php _e($label, 'invoicing'); ?></strong>
2037
+                <?php } if ($notice) { ?>
2038
+                <?php echo wpautop(wptexturize(__($notice, 'invoicing'))) ?>
2039 2039
                 <?php } ?>
2040 2040
             </div>
2041 2041
         </div>
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 1 patch
Spacing   +364 added lines, -364 removed lines patch added patch discarded remove patch
@@ -7,28 +7,28 @@  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_Ajax {
15 15
     public static function init() {
16
-        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
17
-        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
16
+        add_action('init', array(__CLASS__, 'define_ajax'), 0);
17
+        add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
18 18
         self::add_ajax_events();
19 19
     }
20 20
 
21 21
     public static function define_ajax() {
22
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
23
-            if ( ! defined( 'DOING_AJAX' ) ) {
24
-                define( 'DOING_AJAX', true );
22
+        if (!empty($_GET['wpinv-ajax'])) {
23
+            if (!defined('DOING_AJAX')) {
24
+                define('DOING_AJAX', true);
25 25
             }
26
-            if ( ! defined( 'WC_DOING_AJAX' ) ) {
27
-                define( 'WC_DOING_AJAX', true );
26
+            if (!defined('WC_DOING_AJAX')) {
27
+                define('WC_DOING_AJAX', true);
28 28
             }
29 29
             // Turn off display_errors during AJAX events to prevent malformed JSON
30
-            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
31
-                /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
30
+            if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
31
+                /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0);
32 32
             }
33 33
             $GLOBALS['wpdb']->hide_errors();
34 34
         }
@@ -37,24 +37,24 @@  discard block
 block discarded – undo
37 37
     public static function do_wpinv_ajax() {
38 38
         global $wp_query;
39 39
 
40
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
41
-            $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) );
40
+        if (!empty($_GET['wpinv-ajax'])) {
41
+            $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax']));
42 42
         }
43 43
 
44
-        if ( $action = $wp_query->get( 'wpinv-ajax' ) ) {
44
+        if ($action = $wp_query->get('wpinv-ajax')) {
45 45
             self::wpinv_ajax_headers();
46
-            do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) );
46
+            do_action('wpinv_ajax_' . sanitize_text_field($action));
47 47
             die();
48 48
         }
49 49
     }
50 50
     
51 51
     private static function wpinv_ajax_headers() {
52 52
         send_origin_headers();
53
-        /** @scrutinizer ignore-unhandled */ @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
54
-        /** @scrutinizer ignore-unhandled */ @header( 'X-Robots-Tag: noindex' );
53
+        /** @scrutinizer ignore-unhandled */ @header('Content-Type: text/html; charset=' . get_option('blog_charset'));
54
+        /** @scrutinizer ignore-unhandled */ @header('X-Robots-Tag: noindex');
55 55
         send_nosniff_header();
56 56
         nocache_headers();
57
-        status_header( 200 );
57
+        status_header(200);
58 58
     }
59 59
     
60 60
     public static function add_ajax_events() {
@@ -80,39 +80,39 @@  discard block
 block discarded – undo
80 80
             'buy_items' => true,
81 81
         );
82 82
 
83
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
84
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
83
+        foreach ($ajax_events as $ajax_event => $nopriv) {
84
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
85 85
             
86
-            if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) {
87
-                define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 );
86
+            if (!defined('WPI_AJAX_' . strtoupper($nopriv))) {
87
+                define('WPI_AJAX_' . strtoupper($nopriv), 1);
88 88
             }
89 89
 
90
-            if ( $nopriv ) {
91
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
90
+            if ($nopriv) {
91
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
92 92
 
93
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
93
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
94 94
             }
95 95
         }
96 96
     }
97 97
     
98 98
     public static function add_note() {
99
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
99
+        check_ajax_referer('add-invoice-note', '_nonce');
100 100
 
101
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
101
+        if (!wpinv_current_user_can_manage_invoicing()) {
102 102
             die(-1);
103 103
         }
104 104
 
105
-        $post_id   = absint( $_POST['post_id'] );
106
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
107
-        $note_type = sanitize_text_field( $_POST['note_type'] );
105
+        $post_id   = absint($_POST['post_id']);
106
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
107
+        $note_type = sanitize_text_field($_POST['note_type']);
108 108
 
109 109
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
110 110
 
111
-        if ( $post_id > 0 ) {
112
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
111
+        if ($post_id > 0) {
112
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
113 113
 
114
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
115
-                wpinv_get_invoice_note_line_item( $note_id );
114
+            if ($note_id > 0 && !is_wp_error($note_id)) {
115
+                wpinv_get_invoice_note_line_item($note_id);
116 116
             }
117 117
         }
118 118
 
@@ -120,16 +120,16 @@  discard block
 block discarded – undo
120 120
     }
121 121
 
122 122
     public static function delete_note() {
123
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
123
+        check_ajax_referer('delete-invoice-note', '_nonce');
124 124
 
125
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
125
+        if (!wpinv_current_user_can_manage_invoicing()) {
126 126
             die(-1);
127 127
         }
128 128
 
129
-        $note_id = (int)$_POST['note_id'];
129
+        $note_id = (int) $_POST['note_id'];
130 130
 
131
-        if ( $note_id > 0 ) {
132
-            wp_delete_comment( $note_id, true );
131
+        if ($note_id > 0) {
132
+            wp_delete_comment($note_id, true);
133 133
         }
134 134
 
135 135
         die();
@@ -142,8 +142,8 @@  discard block
 block discarded – undo
142 142
     }
143 143
     
144 144
     public static function checkout() {
145
-        if ( ! defined( 'WPINV_CHECKOUT' ) ) {
146
-            define( 'WPINV_CHECKOUT', true );
145
+        if (!defined('WPINV_CHECKOUT')) {
146
+            define('WPINV_CHECKOUT', true);
147 147
         }
148 148
 
149 149
         wpinv_process_checkout();
@@ -152,53 +152,53 @@  discard block
 block discarded – undo
152 152
     
153 153
     public static function add_invoice_item() {
154 154
         global $wpi_userID, $wpinv_ip_address_country;
155
-        check_ajax_referer( 'invoice-item', '_nonce' );
156
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
155
+        check_ajax_referer('invoice-item', '_nonce');
156
+        if (!wpinv_current_user_can_manage_invoicing()) {
157 157
             die(-1);
158 158
         }
159 159
         
160
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
161
-        $invoice_id = absint( $_POST['invoice_id'] );
160
+        $item_id    = sanitize_text_field($_POST['item_id']);
161
+        $invoice_id = absint($_POST['invoice_id']);
162 162
         
163
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
163
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
164 164
             die();
165 165
         }
166 166
         
167
-        $invoice    = wpinv_get_invoice( $invoice_id );
168
-        if ( empty( $invoice ) ) {
167
+        $invoice = wpinv_get_invoice($invoice_id);
168
+        if (empty($invoice)) {
169 169
             die();
170 170
         }
171 171
         
172
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
172
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
173 173
             die(); // Don't allow modify items for paid invoice.
174 174
         }
175 175
         
176
-        if ( !empty( $_POST['user_id'] ) ) {
177
-            $wpi_userID = absint( $_POST['user_id'] ); 
176
+        if (!empty($_POST['user_id'])) {
177
+            $wpi_userID = absint($_POST['user_id']); 
178 178
         }
179 179
 
180
-        $item = new WPInv_Item( $item_id );
181
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
180
+        $item = new WPInv_Item($item_id);
181
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
182 182
             die();
183 183
         }
184 184
         
185 185
         // Validate item before adding to invoice because recurring item must be paid individually.
186
-        if ( !empty( $invoice->cart_details ) ) {
186
+        if (!empty($invoice->cart_details)) {
187 187
             $valid = true;
188 188
             
189
-            if ( $recurring_item = $invoice->get_recurring() ) {
190
-                if ( $recurring_item != $item_id ) {
189
+            if ($recurring_item = $invoice->get_recurring()) {
190
+                if ($recurring_item != $item_id) {
191 191
                     $valid = false;
192 192
                 }
193
-            } else if ( wpinv_is_recurring_item( $item_id ) ) {
193
+            } else if (wpinv_is_recurring_item($item_id)) {
194 194
                 $valid = false;
195 195
             }
196 196
             
197
-            if ( !$valid ) {
197
+            if (!$valid) {
198 198
                 $response               = array();
199 199
                 $response['success']    = false;
200
-                $response['msg']        = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' );
201
-                wp_send_json( $response );
200
+                $response['msg']        = __('You can not add item because recurring item must be paid individually!', 'invoicing');
201
+                wp_send_json($response);
202 202
             }
203 203
         }
204 204
         
@@ -206,11 +206,11 @@  discard block
 block discarded – undo
206 206
         
207 207
         $data                   = array();
208 208
         $data['invoice_id']     = $invoice_id;
209
-        $data['cart_discounts'] = $invoice->get_discounts( true );
209
+        $data['cart_discounts'] = $invoice->get_discounts(true);
210 210
         
211
-        wpinv_set_checkout_session( $data );
211
+        wpinv_set_checkout_session($data);
212 212
         
213
-        $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1;
213
+        $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int) $_POST['qty'] > 0 ? (int) $_POST['qty'] : 1;
214 214
 
215 215
         $args = array(
216 216
             'id'            => $item_id,
@@ -223,21 +223,21 @@  discard block
 block discarded – undo
223 223
             'fees'          => array()
224 224
         );
225 225
 
226
-        $invoice->add_item( $item_id, $args );
226
+        $invoice->add_item($item_id, $args);
227 227
         $invoice->save();
228 228
         
229
-        if ( empty( $_POST['country'] ) ) {
229
+        if (empty($_POST['country'])) {
230 230
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
231 231
         }
232
-        if ( empty( $_POST['state'] ) ) {
232
+        if (empty($_POST['state'])) {
233 233
             $_POST['state'] = $invoice->state;
234 234
         }
235 235
          
236
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
237
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
236
+        $invoice->country   = sanitize_text_field($_POST['country']);
237
+        $invoice->state     = sanitize_text_field($_POST['state']);
238 238
         
239
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
240
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
239
+        $invoice->set('country', sanitize_text_field($_POST['country']));
240
+        $invoice->set('state', sanitize_text_field($_POST['state']));
241 241
         
242 242
         $wpinv_ip_address_country = $invoice->country;
243 243
 
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
         
246 246
         $response                       = array();
247 247
         $response['success']            = true;
248
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
248
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
249 249
         $response['data']['subtotal']   = $invoice->get_subtotal();
250 250
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
251 251
         $response['data']['tax']        = $invoice->get_tax();
@@ -257,41 +257,41 @@  discard block
 block discarded – undo
257 257
         
258 258
         wpinv_set_checkout_session($checkout_session);
259 259
         
260
-        wp_send_json( $response );
260
+        wp_send_json($response);
261 261
     }
262 262
 
263 263
 
264 264
     public static function remove_invoice_item() {
265 265
         global $wpi_userID, $wpinv_ip_address_country;
266 266
         
267
-        check_ajax_referer( 'invoice-item', '_nonce' );
268
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
267
+        check_ajax_referer('invoice-item', '_nonce');
268
+        if (!wpinv_current_user_can_manage_invoicing()) {
269 269
             die(-1);
270 270
         }
271 271
         
272
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
273
-        $invoice_id = absint( $_POST['invoice_id'] );
274
-        $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false;
272
+        $item_id    = sanitize_text_field($_POST['item_id']);
273
+        $invoice_id = absint($_POST['invoice_id']);
274
+        $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false;
275 275
         
276
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
276
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
277 277
             die();
278 278
         }
279 279
 
280
-        $invoice    = wpinv_get_invoice( $invoice_id );
281
-        if ( empty( $invoice ) ) {
280
+        $invoice = wpinv_get_invoice($invoice_id);
281
+        if (empty($invoice)) {
282 282
             die();
283 283
         }
284 284
         
285
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
285
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
286 286
             die(); // Don't allow modify items for paid invoice.
287 287
         }
288 288
         
289
-        if ( !empty( $_POST['user_id'] ) ) {
290
-            $wpi_userID = absint( $_POST['user_id'] ); 
289
+        if (!empty($_POST['user_id'])) {
290
+            $wpi_userID = absint($_POST['user_id']); 
291 291
         }
292 292
 
293
-        $item       = new WPInv_Item( $item_id );
294
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
293
+        $item = new WPInv_Item($item_id);
294
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
295 295
             die();
296 296
         }
297 297
         
@@ -299,9 +299,9 @@  discard block
 block discarded – undo
299 299
         
300 300
         $data                   = array();
301 301
         $data['invoice_id']     = $invoice_id;
302
-        $data['cart_discounts'] = $invoice->get_discounts( true );
302
+        $data['cart_discounts'] = $invoice->get_discounts(true);
303 303
         
304
-        wpinv_set_checkout_session( $data );
304
+        wpinv_set_checkout_session($data);
305 305
 
306 306
         $args = array(
307 307
             'id'         => $item_id,
@@ -309,21 +309,21 @@  discard block
 block discarded – undo
309 309
             'cart_index' => $cart_index
310 310
         );
311 311
 
312
-        $invoice->remove_item( $item_id, $args );
312
+        $invoice->remove_item($item_id, $args);
313 313
         $invoice->save();
314 314
         
315
-        if ( empty( $_POST['country'] ) ) {
315
+        if (empty($_POST['country'])) {
316 316
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
317 317
         }
318
-        if ( empty( $_POST['state'] ) ) {
318
+        if (empty($_POST['state'])) {
319 319
             $_POST['state'] = $invoice->state;
320 320
         }
321 321
          
322
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
323
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
322
+        $invoice->country   = sanitize_text_field($_POST['country']);
323
+        $invoice->state     = sanitize_text_field($_POST['state']);
324 324
         
325
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
326
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
325
+        $invoice->set('country', sanitize_text_field($_POST['country']));
326
+        $invoice->set('state', sanitize_text_field($_POST['state']));
327 327
         
328 328
         $wpinv_ip_address_country = $invoice->country;
329 329
         
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
         
332 332
         $response                       = array();
333 333
         $response['success']            = true;
334
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
334
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
335 335
         $response['data']['subtotal']   = $invoice->get_subtotal();
336 336
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
337 337
         $response['data']['tax']        = $invoice->get_tax();
@@ -343,55 +343,55 @@  discard block
 block discarded – undo
343 343
         
344 344
         wpinv_set_checkout_session($checkout_session);
345 345
         
346
-        wp_send_json( $response );
346
+        wp_send_json($response);
347 347
     }
348 348
     
349 349
     public static function create_invoice_item() {
350
-        check_ajax_referer( 'invoice-item', '_nonce' );
351
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
350
+        check_ajax_referer('invoice-item', '_nonce');
351
+        if (!wpinv_current_user_can_manage_invoicing()) {
352 352
             die(-1);
353 353
         }
354 354
         
355
-        $invoice_id = absint( $_POST['invoice_id'] );
355
+        $invoice_id = absint($_POST['invoice_id']);
356 356
 
357 357
         // Find the item
358
-        if ( !is_numeric( $invoice_id ) ) {
358
+        if (!is_numeric($invoice_id)) {
359 359
             die();
360 360
         }        
361 361
         
362
-        $invoice     = wpinv_get_invoice( $invoice_id );
363
-        if ( empty( $invoice ) ) {
362
+        $invoice = wpinv_get_invoice($invoice_id);
363
+        if (empty($invoice)) {
364 364
             die();
365 365
         }
366 366
         
367 367
         // Validate item before adding to invoice because recurring item must be paid individually.
368
-        if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) {
368
+        if (!empty($invoice->cart_details) && $invoice->get_recurring()) {
369 369
             $response               = array();
370 370
             $response['success']    = false;
371
-            $response['msg']        = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' );
372
-            wp_send_json( $response );
371
+            $response['msg']        = __('You can not add item because recurring item must be paid individually!', 'invoicing');
372
+            wp_send_json($response);
373 373
         }        
374 374
         
375
-        $save_item = wp_unslash( $_POST['_wpinv_quick'] );
375
+        $save_item = wp_unslash($_POST['_wpinv_quick']);
376 376
         
377 377
         $meta               = array();
378 378
         $meta['type']       = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom';
379
-        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0;
379
+        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0;
380 380
         $meta['vat_rule']   = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital';
381 381
         $meta['vat_class']  = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard';
382 382
         
383 383
         $data                   = array();
384 384
         $data['post_title']     = sanitize_text_field($save_item['name']);
385 385
         $data['post_status']    = 'publish';
386
-        $data['post_excerpt']   = ! empty( $save_item['excerpt'] ) ? wp_kses_post( $save_item['excerpt'] ) : '';
386
+        $data['post_excerpt']   = !empty($save_item['excerpt']) ? wp_kses_post($save_item['excerpt']) : '';
387 387
         $data['meta']           = $meta;
388 388
         
389 389
         $item = new WPInv_Item();
390
-        $item->create( $data );
390
+        $item->create($data);
391 391
         
392
-        if ( !empty( $item ) ) {
392
+        if (!empty($item)) {
393 393
             $_POST['item_id']   = $item->ID;
394
-            $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1;
394
+            $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int) $save_item['qty'] : 1;
395 395
             
396 396
             self::add_invoice_item();
397 397
         }
@@ -399,15 +399,15 @@  discard block
 block discarded – undo
399 399
     }
400 400
     
401 401
     public static function get_billing_details() {
402
-        check_ajax_referer( 'get-billing-details', '_nonce' );
402
+        check_ajax_referer('get-billing-details', '_nonce');
403 403
         
404
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
404
+        if (!wpinv_current_user_can_manage_invoicing()) {
405 405
             die(-1);
406 406
         }
407 407
 
408
-        $user_id            = (int)$_POST['user_id'];
408
+        $user_id            = (int) $_POST['user_id'];
409 409
         $billing_details    = wpinv_get_user_address($user_id);
410
-        $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
410
+        $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
411 411
         
412 412
         if (isset($billing_details['user_id'])) {
413 413
             unset($billing_details['user_id']);
@@ -421,20 +421,20 @@  discard block
 block discarded – undo
421 421
         $response['success']                    = true;
422 422
         $response['data']['billing_details']    = $billing_details;
423 423
         
424
-        wp_send_json( $response );
424
+        wp_send_json($response);
425 425
     }
426 426
     
427 427
     public static function admin_recalculate_totals() {
428 428
         global $wpi_userID, $wpinv_ip_address_country;
429 429
         
430
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
431
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
430
+        check_ajax_referer('wpinv-nonce', '_nonce');
431
+        if (!wpinv_current_user_can_manage_invoicing()) {
432 432
             die(-1);
433 433
         }
434 434
         
435
-        $invoice_id = absint( $_POST['invoice_id'] );        
436
-        $invoice    = wpinv_get_invoice( $invoice_id );
437
-        if ( empty( $invoice ) ) {
435
+        $invoice_id = absint($_POST['invoice_id']);        
436
+        $invoice    = wpinv_get_invoice($invoice_id);
437
+        if (empty($invoice)) {
438 438
             die();
439 439
         }
440 440
 
@@ -442,29 +442,29 @@  discard block
 block discarded – undo
442 442
 
443 443
         $data                   = array();
444 444
         $data['invoice_id']     = $invoice_id;
445
-        $data['cart_discounts'] = $invoice->get_discounts( true );
445
+        $data['cart_discounts'] = $invoice->get_discounts(true);
446 446
 
447
-        wpinv_set_checkout_session( $data );
447
+        wpinv_set_checkout_session($data);
448 448
         
449
-        if ( !empty( $_POST['user_id'] ) ) {
450
-            $wpi_userID = absint( $_POST['user_id'] ); 
449
+        if (!empty($_POST['user_id'])) {
450
+            $wpi_userID = absint($_POST['user_id']); 
451 451
         }
452 452
         
453
-        if ( empty( $_POST['country'] ) ) {
453
+        if (empty($_POST['country'])) {
454 454
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
455 455
         }
456 456
 
457 457
         $disable_taxes = 0;
458
-        if ( ! empty( $_POST['disable_taxes'] ) ) {
458
+        if (!empty($_POST['disable_taxes'])) {
459 459
             $disable_taxes = 1;
460 460
         }
461
-        $invoice->set( 'disable_taxes', $disable_taxes );
461
+        $invoice->set('disable_taxes', $disable_taxes);
462 462
 
463
-        $invoice->country = sanitize_text_field( $_POST['country'] );
464
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
465
-        if ( isset( $_POST['state'] ) ) {
466
-            $invoice->state = sanitize_text_field( $_POST['state'] );
467
-            $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
463
+        $invoice->country = sanitize_text_field($_POST['country']);
464
+        $invoice->set('country', sanitize_text_field($_POST['country']));
465
+        if (isset($_POST['state'])) {
466
+            $invoice->state = sanitize_text_field($_POST['state']);
467
+            $invoice->set('state', sanitize_text_field($_POST['state']));
468 468
         }
469 469
         
470 470
         $wpinv_ip_address_country = $invoice->country;
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
         
474 474
         $response                       = array();
475 475
         $response['success']            = true;
476
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
476
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
477 477
         $response['data']['subtotal']   = $invoice->get_subtotal();
478 478
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
479 479
         $response['data']['tax']        = $invoice->get_tax();
@@ -485,25 +485,25 @@  discard block
 block discarded – undo
485 485
         
486 486
         wpinv_set_checkout_session($checkout_session);
487 487
 
488
-        wp_send_json( $response );
488
+        wp_send_json($response);
489 489
     }
490 490
     
491 491
     public static function admin_apply_discount() {
492 492
         global $wpi_userID;
493 493
         
494
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
495
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
494
+        check_ajax_referer('wpinv-nonce', '_nonce');
495
+        if (!wpinv_current_user_can_manage_invoicing()) {
496 496
             die(-1);
497 497
         }
498 498
         
499
-        $invoice_id = absint( $_POST['invoice_id'] );
500
-        $discount_code = sanitize_text_field( $_POST['code'] );
501
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
499
+        $invoice_id = absint($_POST['invoice_id']);
500
+        $discount_code = sanitize_text_field($_POST['code']);
501
+        if (empty($invoice_id) || empty($discount_code)) {
502 502
             die();
503 503
         }
504 504
         
505
-        $invoice = wpinv_get_invoice( $invoice_id );
506
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
505
+        $invoice = wpinv_get_invoice($invoice_id);
506
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
507 507
             die();
508 508
         }
509 509
         
@@ -511,49 +511,49 @@  discard block
 block discarded – undo
511 511
         
512 512
         $data                   = array();
513 513
         $data['invoice_id']     = $invoice_id;
514
-        $data['cart_discounts'] = $invoice->get_discounts( true );
514
+        $data['cart_discounts'] = $invoice->get_discounts(true);
515 515
         
516
-        wpinv_set_checkout_session( $data );
516
+        wpinv_set_checkout_session($data);
517 517
         
518 518
         $response               = array();
519 519
         $response['success']    = false;
520
-        $response['msg']        = __( 'This discount is invalid.', 'invoicing' );
520
+        $response['msg']        = __('This discount is invalid.', 'invoicing');
521 521
         $response['data']['code'] = $discount_code;
522 522
         
523
-        if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) {
524
-            $discounts = wpinv_set_cart_discount( $discount_code );
523
+        if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) {
524
+            $discounts = wpinv_set_cart_discount($discount_code);
525 525
             
526 526
             $response['success'] = true;
527
-            $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' );
528
-        }  else {
527
+            $response['msg'] = __('Discount has been applied successfully.', 'invoicing');
528
+        } else {
529 529
             $errors = wpinv_get_errors();
530
-            if ( !empty( $errors['wpinv-discount-error'] ) ) {
530
+            if (!empty($errors['wpinv-discount-error'])) {
531 531
                 $response['msg'] = $errors['wpinv-discount-error'];
532 532
             }
533
-            wpinv_unset_error( 'wpinv-discount-error' );
533
+            wpinv_unset_error('wpinv-discount-error');
534 534
         }
535 535
         
536 536
         wpinv_set_checkout_session($checkout_session);
537 537
         
538
-        wp_send_json( $response );
538
+        wp_send_json($response);
539 539
     }
540 540
     
541 541
     public static function admin_remove_discount() {
542 542
         global $wpi_userID;
543 543
         
544
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
545
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
544
+        check_ajax_referer('wpinv-nonce', '_nonce');
545
+        if (!wpinv_current_user_can_manage_invoicing()) {
546 546
             die(-1);
547 547
         }
548 548
         
549
-        $invoice_id = absint( $_POST['invoice_id'] );
550
-        $discount_code = sanitize_text_field( $_POST['code'] );
551
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
549
+        $invoice_id = absint($_POST['invoice_id']);
550
+        $discount_code = sanitize_text_field($_POST['code']);
551
+        if (empty($invoice_id) || empty($discount_code)) {
552 552
             die();
553 553
         }
554 554
         
555
-        $invoice = wpinv_get_invoice( $invoice_id );
556
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
555
+        $invoice = wpinv_get_invoice($invoice_id);
556
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
557 557
             die();
558 558
         }
559 559
         
@@ -561,38 +561,38 @@  discard block
 block discarded – undo
561 561
         
562 562
         $data                   = array();
563 563
         $data['invoice_id']     = $invoice_id;
564
-        $data['cart_discounts'] = $invoice->get_discounts( true );
564
+        $data['cart_discounts'] = $invoice->get_discounts(true);
565 565
         
566
-        wpinv_set_checkout_session( $data );
566
+        wpinv_set_checkout_session($data);
567 567
         
568 568
         $response               = array();
569 569
         $response['success']    = false;
570 570
         $response['msg']        = NULL;
571 571
         
572
-        $discounts  = wpinv_unset_cart_discount( $discount_code );
572
+        $discounts = wpinv_unset_cart_discount($discount_code);
573 573
         $response['success'] = true;
574
-        $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' );
574
+        $response['msg'] = __('Discount has been removed successfully.', 'invoicing');
575 575
         
576 576
         wpinv_set_checkout_session($checkout_session);
577 577
         
578
-        wp_send_json( $response );
578
+        wp_send_json($response);
579 579
     }
580 580
     
581 581
     public static function check_email() {
582
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
583
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
582
+        check_ajax_referer('wpinv-nonce', '_nonce');
583
+        if (!wpinv_current_user_can_manage_invoicing()) {
584 584
             die(-1);
585 585
         }
586 586
         
587
-        $email = sanitize_text_field( $_POST['email'] );
587
+        $email = sanitize_text_field($_POST['email']);
588 588
         
589 589
         $response = array();
590
-        if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) {
590
+        if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) {
591 591
             $user_id            = $user_data->ID;
592 592
             $user_login         = $user_data->user_login;
593 593
             $display_name       = $user_data->display_name ? $user_data->display_name : $user_login;
594 594
             $billing_details    = wpinv_get_user_address($user_id);
595
-            $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
595
+            $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
596 596
             
597 597
             if (isset($billing_details['user_id'])) {
598 598
                 unset($billing_details['user_id']);
@@ -608,54 +608,54 @@  discard block
 block discarded – undo
608 608
             $response['data']['billing_details']    = $billing_details;
609 609
         }
610 610
         
611
-        wp_send_json( $response );
611
+        wp_send_json($response);
612 612
     }
613 613
     
614 614
     public static function run_tool() {
615
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
616
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
615
+        check_ajax_referer('wpinv-nonce', '_nonce');
616
+        if (!wpinv_current_user_can_manage_invoicing()) {
617 617
             die(-1);
618 618
         }
619 619
         
620
-        $tool = sanitize_text_field( $_POST['tool'] );
620
+        $tool = sanitize_text_field($_POST['tool']);
621 621
         
622
-        do_action( 'wpinv_run_tool' );
622
+        do_action('wpinv_run_tool');
623 623
         
624
-        if ( !empty( $tool ) ) {
625
-            do_action( 'wpinv_tool_' . $tool );
624
+        if (!empty($tool)) {
625
+            do_action('wpinv_tool_' . $tool);
626 626
         }
627 627
     }
628 628
     
629 629
     public static function apply_discount() {
630 630
         global $wpi_userID;
631 631
         
632
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
632
+        check_ajax_referer('wpinv-nonce', '_nonce');
633 633
         
634 634
         $response = array();
635 635
         
636
-        if ( isset( $_POST['code'] ) ) {
637
-            $discount_code = sanitize_text_field( $_POST['code'] );
636
+        if (isset($_POST['code'])) {
637
+            $discount_code = sanitize_text_field($_POST['code']);
638 638
 
639 639
             $response['success']        = false;
640 640
             $response['msg']            = '';
641 641
             $response['data']['code']   = $discount_code;
642 642
             
643 643
             $invoice = wpinv_get_invoice_cart();
644
-            if ( empty( $invoice->ID ) ) {
645
-                $response['msg'] = __( 'Invalid checkout request.', 'invoicing' );
646
-                wp_send_json( $response );
644
+            if (empty($invoice->ID)) {
645
+                $response['msg'] = __('Invalid checkout request.', 'invoicing');
646
+                wp_send_json($response);
647 647
             }
648 648
 
649 649
             $wpi_userID = $invoice->get_user_id();
650 650
 
651
-            if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) {
652
-                $discount       = wpinv_get_discount_by_code( $discount_code );
653
-                $discounts      = wpinv_set_cart_discount( $discount_code );
654
-                $amount         = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
655
-                $total          = wpinv_get_cart_total( null, $discounts );
656
-                $cart_totals    = wpinv_recalculate_tax( true );
651
+            if (wpinv_is_discount_valid($discount_code, $wpi_userID)) {
652
+                $discount       = wpinv_get_discount_by_code($discount_code);
653
+                $discounts      = wpinv_set_cart_discount($discount_code);
654
+                $amount         = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
655
+                $total          = wpinv_get_cart_total(null, $discounts);
656
+                $cart_totals    = wpinv_recalculate_tax(true);
657 657
             
658
-                if ( !empty( $cart_totals ) ) {
658
+                if (!empty($cart_totals)) {
659 659
                     $response['success']        = true;
660 660
                     $response['data']           = $cart_totals;
661 661
                     $response['data']['code']   = $discount_code;
@@ -664,29 +664,29 @@  discard block
 block discarded – undo
664 664
                 }
665 665
             } else {
666 666
                 $errors = wpinv_get_errors();
667
-                $response['msg']  = $errors['wpinv-discount-error'];
668
-                wpinv_unset_error( 'wpinv-discount-error' );
667
+                $response['msg'] = $errors['wpinv-discount-error'];
668
+                wpinv_unset_error('wpinv-discount-error');
669 669
             }
670 670
 
671 671
             // Allow for custom discount code handling
672
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
672
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
673 673
         }
674 674
         
675
-        wp_send_json( $response );
675
+        wp_send_json($response);
676 676
     }
677 677
     
678 678
     public static function remove_discount() {
679
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
679
+        check_ajax_referer('wpinv-nonce', '_nonce');
680 680
         
681 681
         $response = array();
682 682
         
683
-        if ( isset( $_POST['code'] ) ) {
684
-            $discount_code  = sanitize_text_field( $_POST['code'] );
685
-            $discounts      = wpinv_unset_cart_discount( $discount_code );
686
-            $total          = wpinv_get_cart_total( null, $discounts );
687
-            $cart_totals    = wpinv_recalculate_tax( true );
683
+        if (isset($_POST['code'])) {
684
+            $discount_code  = sanitize_text_field($_POST['code']);
685
+            $discounts      = wpinv_unset_cart_discount($discount_code);
686
+            $total          = wpinv_get_cart_total(null, $discounts);
687
+            $cart_totals    = wpinv_recalculate_tax(true);
688 688
             
689
-            if ( !empty( $cart_totals ) ) {
689
+            if (!empty($cart_totals)) {
690 690
                 $response['success']        = true;
691 691
                 $response['data']           = $cart_totals;
692 692
                 $response['data']['code']   = $discount_code;
@@ -695,10 +695,10 @@  discard block
 block discarded – undo
695 695
             }
696 696
             
697 697
             // Allow for custom discount code handling
698
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
698
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
699 699
         }
700 700
         
701
-        wp_send_json( $response );
701
+        wp_send_json($response);
702 702
     }
703 703
 
704 704
     /**
@@ -710,75 +710,75 @@  discard block
 block discarded – undo
710 710
         global $invoicing, $wpi_checkout_id, $cart_total;
711 711
 
712 712
         // Check nonce.
713
-        if ( ! isset( $_POST['wpinv_payment_form'] ) || ! wp_verify_nonce( $_POST['wpinv_payment_form'], 'wpinv_payment_form' ) ) {
714
-            wp_send_json_error( __( 'Security checks failed.', 'invoicing' ) );
713
+        if (!isset($_POST['wpinv_payment_form']) || !wp_verify_nonce($_POST['wpinv_payment_form'], 'wpinv_payment_form')) {
714
+            wp_send_json_error(__('Security checks failed.', 'invoicing'));
715 715
         }
716 716
 
717 717
         // Prepare submitted data...
718
-        $data = wp_unslash( $_POST );
718
+        $data = wp_unslash($_POST);
719 719
 
720 720
         // ... form fields...
721
-        if ( empty( $data['form_id'] ) || 'publish' != get_post_status( $data['form_id'] ) ) {
722
-            wp_send_json_error( __( 'This payment form is no longer active.', 'invoicing' ) );
721
+        if (empty($data['form_id']) || 'publish' != get_post_status($data['form_id'])) {
722
+            wp_send_json_error(__('This payment form is no longer active.', 'invoicing'));
723 723
         }
724 724
 
725
-        if ( empty( $data['billing_email'] ) || ! is_email( $data['billing_email'] ) ) {
726
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
725
+        if (empty($data['billing_email']) || !is_email($data['billing_email'])) {
726
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
727 727
         }
728 728
 
729 729
         $prepared = array(
730
-            'billing_email'                    => sanitize_email( $data['billing_email'] ),
731
-            __( 'Billing Email', 'invoicing' ) => sanitize_email( $data['billing_email'] ),
732
-            __( 'Form Id', 'invoicing' )       => absint( $data['form_id'] ),
730
+            'billing_email'                    => sanitize_email($data['billing_email']),
731
+            __('Billing Email', 'invoicing') => sanitize_email($data['billing_email']),
732
+            __('Form Id', 'invoicing')       => absint($data['form_id']),
733 733
         );
734 734
 
735
-        $prepared['billing_email'] = sanitize_email( $data['billing_email'] );
735
+        $prepared['billing_email'] = sanitize_email($data['billing_email']);
736 736
 
737
-        $fields = $invoicing->form_elements->get_form_elements( $data['form_id'] );
737
+        $fields = $invoicing->form_elements->get_form_elements($data['form_id']);
738 738
 
739 739
         // ... and form items.
740
-        $items          = $invoicing->form_elements->get_form_items( $data['form_id'] );
740
+        $items          = $invoicing->form_elements->get_form_items($data['form_id']);
741 741
         $prepared_items = array();
742 742
         $address_fields = array();
743 743
 
744
-        if ( ! empty( $data['wpinv-items'] ) ) {
744
+        if (!empty($data['wpinv-items'])) {
745 745
 
746
-            $selected_items = wpinv_clean( $data['wpinv-items'] );
746
+            $selected_items = wpinv_clean($data['wpinv-items']);
747 747
 
748
-            foreach ( $items as $item ) {
748
+            foreach ($items as $item) {
749 749
 
750
-                if ( ! empty( $item['required'] ) && ! isset( $selected_items[ $item['id'] ] ) ) {
751
-                    wp_send_json_error( __( 'A required item is missing.', 'invoicing' ) );
750
+                if (!empty($item['required']) && !isset($selected_items[$item['id']])) {
751
+                    wp_send_json_error(__('A required item is missing.', 'invoicing'));
752 752
                 }
753 753
 
754
-                if ( ! isset( $selected_items[ $item['id'] ] ) ) {
754
+                if (!isset($selected_items[$item['id']])) {
755 755
                     continue;
756 756
                 }
757 757
 
758 758
                 $quantity = 1;
759 759
 
760
-                if ( ! empty( $item['allow_quantities'] ) && ! empty( $data["wpinv-item-{$item['id']}-quantity"] ) ) {
760
+                if (!empty($item['allow_quantities']) && !empty($data["wpinv-item-{$item['id']}-quantity"])) {
761 761
 
762
-                    $quantity = intval( $data["wpinv-item-{$item['id']}-quantity"] );
762
+                    $quantity = intval($data["wpinv-item-{$item['id']}-quantity"]);
763 763
 
764
-                    if ( empty( $quantity ) ) {
764
+                    if (empty($quantity)) {
765 765
                         $quantity = 1;
766 766
                     }
767 767
                 }
768 768
 
769 769
                 // Custom pricing.
770
-                if ( ! empty( $item['custom_price'] ) ) {
770
+                if (!empty($item['custom_price'])) {
771 771
 
772
-                    $minimum_price = wpinv_sanitize_amount( $item['minimum_price'] );
773
-                    $set_price     = wpinv_sanitize_amount( $selected_items[ $item['id'] ] );
772
+                    $minimum_price = wpinv_sanitize_amount($item['minimum_price']);
773
+                    $set_price     = wpinv_sanitize_amount($selected_items[$item['id']]);
774 774
 
775
-                    if ( $set_price < $minimum_price ) {
776
-                        wp_send_json_error( __( 'The provided amount is less than the minimum allowed value.', 'invoicing' ) );
775
+                    if ($set_price < $minimum_price) {
776
+                        wp_send_json_error(__('The provided amount is less than the minimum allowed value.', 'invoicing'));
777 777
                     }
778 778
 
779 779
                     $prepared_items[] = array(
780 780
                         'id'           =>$item['id'],
781
-                        'item_price'   => wpinv_sanitize_amount( $item['price'] ),
781
+                        'item_price'   => wpinv_sanitize_amount($item['price']),
782 782
                         'custom_price' => $set_price,
783 783
                         'name'         => $item['title'],
784 784
                         'quantity'     => $quantity,
@@ -788,8 +788,8 @@  discard block
 block discarded – undo
788 788
 
789 789
                     $prepared_items[] = array(
790 790
                         'id'           => $item['id'],
791
-                        'item_price'   => wpinv_sanitize_amount( $item['price'] ),
792
-                        'custom_price' => wpinv_sanitize_amount( $item['price'] ),
791
+                        'item_price'   => wpinv_sanitize_amount($item['price']),
792
+                        'custom_price' => wpinv_sanitize_amount($item['price']),
793 793
                         'name'         => $item['title'],
794 794
                         'quantity'     => $quantity,
795 795
                     );
@@ -800,64 +800,64 @@  discard block
 block discarded – undo
800 800
 
801 801
         } else {
802 802
 
803
-            wp_send_json_error( __( 'You have not selected any items.', 'invoicing' ) );
803
+            wp_send_json_error(__('You have not selected any items.', 'invoicing'));
804 804
 
805 805
         }
806 806
 
807 807
         // Are all required fields provided?
808
-        foreach ( $fields as $field ) {
808
+        foreach ($fields as $field) {
809 809
 
810
-            if ( ! empty( $field['premade'] ) ) {
810
+            if (!empty($field['premade'])) {
811 811
                 continue;
812 812
             }
813 813
 
814
-            if ( ! empty( $field['required'] ) && empty( $data[ $field['id'] ] ) ) {
815
-                wp_send_json_error( __( 'Some required fields have not been filled.', 'invoicing' ) );
814
+            if (!empty($field['required']) && empty($data[$field['id']])) {
815
+                wp_send_json_error(__('Some required fields have not been filled.', 'invoicing'));
816 816
             }
817 817
 
818
-            if ( $field['type'] == 'address' ) {
818
+            if ($field['type'] == 'address') {
819 819
 
820
-                foreach ( $field['fields'] as $address_field ) {
820
+                foreach ($field['fields'] as $address_field) {
821 821
 
822
-                    if ( empty( $address_field['visible'] ) ) {
822
+                    if (empty($address_field['visible'])) {
823 823
                         continue;
824 824
                     }
825 825
 
826
-                    if ( ! empty( $address_field['required'] ) && empty( $data[ $address_field['name'] ] ) ) {
827
-                        wp_send_json_error( __( 'Some required fields have not been filled.', 'invoicing' ) );
826
+                    if (!empty($address_field['required']) && empty($data[$address_field['name']])) {
827
+                        wp_send_json_error(__('Some required fields have not been filled.', 'invoicing'));
828 828
                     }
829 829
 
830
-                    if ( isset( $data[ $address_field['name'] ] ) ) {
831
-                        $label = str_replace( 'wpinv_', '', $address_field['name'] );
832
-                        $address_fields[ $label ] = wpinv_clean( $data[ $address_field['name'] ] );
830
+                    if (isset($data[$address_field['name']])) {
831
+                        $label = str_replace('wpinv_', '', $address_field['name']);
832
+                        $address_fields[$label] = wpinv_clean($data[$address_field['name']]);
833 833
                     }
834 834
 
835 835
                 }
836 836
 
837
-            } else if ( isset( $data[ $field['id'] ] ) ) {
837
+            } else if (isset($data[$field['id']])) {
838 838
                 $label = $field['id'];
839 839
 
840
-                if ( isset( $field['label'] ) ) {
840
+                if (isset($field['label'])) {
841 841
                     $label = $field['label'];
842 842
                 }
843 843
 
844
-                $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] );
844
+                $prepared[wpinv_clean($label)] = wpinv_clean($data[$field['id']]);
845 845
             }
846 846
 
847 847
         }
848 848
 
849
-        $user = get_user_by( 'email', $prepared['billing_email'] );
849
+        $user = get_user_by('email', $prepared['billing_email']);
850 850
 
851
-        if ( empty( $user ) ) {
852
-            $user = wpinv_create_user( $prepared['billing_email'] );
851
+        if (empty($user)) {
852
+            $user = wpinv_create_user($prepared['billing_email']);
853 853
         }
854 854
 
855
-        if ( is_wp_error( $user ) ) {
856
-            wp_send_json_error( $user->get_error_message() );
855
+        if (is_wp_error($user)) {
856
+            wp_send_json_error($user->get_error_message());
857 857
         }
858 858
 
859
-        if ( is_numeric( $user ) ) {
860
-            $user = get_user_by( 'id', $user );
859
+        if (is_numeric($user)) {
860
+            $user = get_user_by('id', $user);
861 861
         }
862 862
 
863 863
         // Create the invoice.
@@ -872,34 +872,34 @@  discard block
 block discarded – undo
872 872
             true
873 873
         );
874 874
 
875
-        if ( is_wp_error( $created ) ) {
876
-            wp_send_json_error( $created->get_error_message() );
875
+        if (is_wp_error($created)) {
876
+            wp_send_json_error($created->get_error_message());
877 877
         }
878 878
 
879
-        if ( empty( $created ) ) {
880
-            wp_send_json_error( __( 'Could not create your invoice.', 'invoicing' ) );
879
+        if (empty($created)) {
880
+            wp_send_json_error(__('Could not create your invoice.', 'invoicing'));
881 881
         }
882 882
 
883
-        unset( $prepared['billing_email'] );
884
-        update_post_meta( $created->ID, 'payment_form_data', $prepared );
883
+        unset($prepared['billing_email']);
884
+        update_post_meta($created->ID, 'payment_form_data', $prepared);
885 885
 
886 886
         $wpi_checkout_id = $created->ID;
887 887
         $cart_total = wpinv_price(
888 888
             wpinv_format_amount(
889
-                wpinv_get_cart_total( $created->get_cart_details(), NULL, $created ) ),
889
+                wpinv_get_cart_total($created->get_cart_details(), NULL, $created) ),
890 890
                 $created->get_currency()
891 891
         );
892 892
 
893 893
         $data                   = array();
894 894
         $data['invoice_id']     = $created->ID;
895
-        $data['cart_discounts'] = $created->get_discounts( true );
895
+        $data['cart_discounts'] = $created->get_discounts(true);
896 896
 
897
-        wpinv_set_checkout_session( $data );
898
-        add_filter( 'wp_redirect', array( $invoicing->form_elements, 'send_redirect_response' ) );
899
-        add_action( 'wpinv_pre_send_back_to_checkout', array( $invoicing->form_elements, 'checkout_error' ) );
897
+        wpinv_set_checkout_session($data);
898
+        add_filter('wp_redirect', array($invoicing->form_elements, 'send_redirect_response'));
899
+        add_action('wpinv_pre_send_back_to_checkout', array($invoicing->form_elements, 'checkout_error'));
900 900
         
901
-        if ( ! defined( 'WPINV_CHECKOUT' ) ) {
902
-            define( 'WPINV_CHECKOUT', true );
901
+        if (!defined('WPINV_CHECKOUT')) {
902
+            define('WPINV_CHECKOUT', true);
903 903
         }
904 904
 
905 905
         wpinv_process_checkout();
@@ -917,51 +917,51 @@  discard block
 block discarded – undo
917 917
     public static function get_payment_form_states_field() {
918 918
         global $invoicing;
919 919
 
920
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
920
+        if (empty($_GET['country']) || empty($_GET['form'])) {
921 921
             exit;
922 922
         }
923 923
 
924
-        $elements = $invoicing->form_elements->get_form_elements( $_GET['form'] );
924
+        $elements = $invoicing->form_elements->get_form_elements($_GET['form']);
925 925
 
926
-        if ( empty( $elements ) ) {
926
+        if (empty($elements)) {
927 927
             exit;
928 928
         }
929 929
 
930 930
         $address_fields = array();
931
-        foreach ( $elements as $element ) {
932
-            if ( 'address' === $element['type'] ) {
931
+        foreach ($elements as $element) {
932
+            if ('address' === $element['type']) {
933 933
                 $address_fields = $element;
934 934
                 break;
935 935
             }
936 936
         }
937 937
 
938
-        if ( empty( $address_fields ) ) {
938
+        if (empty($address_fields)) {
939 939
             exit;
940 940
         }
941 941
 
942
-        foreach( $address_fields['fields'] as $address_field ) {
942
+        foreach ($address_fields['fields'] as $address_field) {
943 943
 
944
-            if ( 'wpinv_state' == $address_field['name'] ) {
944
+            if ('wpinv_state' == $address_field['name']) {
945 945
 
946 946
                 $label = $address_field['label'];
947 947
 
948
-                if ( ! empty( $address_field['required'] ) ) {
948
+                if (!empty($address_field['required'])) {
949 949
                     $label .= "<span class='text-danger'> *</span>";
950 950
                 }
951 951
 
952
-                $states = wpinv_get_country_states( $_GET['country'] );
952
+                $states = wpinv_get_country_states($_GET['country']);
953 953
 
954
-                if ( ! empty( $states ) ) {
954
+                if (!empty($states)) {
955 955
 
956 956
                     $html = aui()->select(
957 957
                             array(
958 958
                                 'options'          => $states,
959
-                                'name'             => esc_attr( $address_field['name'] ),
960
-                                'id'               => esc_attr( $address_field['name'] ),
961
-                                'placeholder'      => esc_attr( $address_field['placeholder'] ),
959
+                                'name'             => esc_attr($address_field['name']),
960
+                                'id'               => esc_attr($address_field['name']),
961
+                                'placeholder'      => esc_attr($address_field['placeholder']),
962 962
                                 'required'         => (bool) $address_field['required'],
963 963
                                 'no_wrap'          => true,
964
-                                'label'            => wp_kses_post( $label ),
964
+                                'label'            => wp_kses_post($label),
965 965
                                 'select2'          => false,
966 966
                             )
967 967
                         );
@@ -970,10 +970,10 @@  discard block
 block discarded – undo
970 970
 
971 971
                     $html = aui()->input(
972 972
                             array(
973
-                                'name'       => esc_attr( $address_field['name'] ),
974
-                                'id'         => esc_attr( $address_field['name'] ),
973
+                                'name'       => esc_attr($address_field['name']),
974
+                                'id'         => esc_attr($address_field['name']),
975 975
                                 'required'   => (bool) $address_field['required'],
976
-                                'label'      => wp_kses_post( $label ),
976
+                                'label'      => wp_kses_post($label),
977 977
                                 'no_wrap'    => true,
978 978
                                 'type'       => 'text',
979 979
                             )
@@ -981,7 +981,7 @@  discard block
 block discarded – undo
981 981
 
982 982
                 }
983 983
 
984
-                wp_send_json_success( str_replace( 'sr-only', '', $html ) );
984
+                wp_send_json_success(str_replace('sr-only', '', $html));
985 985
                 exit;
986 986
 
987 987
             }
@@ -1000,77 +1000,77 @@  discard block
 block discarded – undo
1000 1000
         global $invoicing;
1001 1001
 
1002 1002
         // Check nonce.
1003
-        check_ajax_referer( 'wpinv_payment_form', 'wpinv_payment_form' );
1003
+        check_ajax_referer('wpinv_payment_form', 'wpinv_payment_form');
1004 1004
 
1005 1005
         // Prepare submitted data...
1006
-        $data = wp_unslash( $_POST );
1006
+        $data = wp_unslash($_POST);
1007 1007
 
1008 1008
         // ... form fields...
1009
-        if ( empty( $data['form_id'] ) || 'publish' != get_post_status( $data['form_id'] ) ) {
1009
+        if (empty($data['form_id']) || 'publish' != get_post_status($data['form_id'])) {
1010 1010
             exit;
1011 1011
         }
1012 1012
 
1013 1013
         // ... and form items.
1014
-        $items     = $invoicing->form_elements->get_form_items( $data['form_id'] );
1014
+        $items     = $invoicing->form_elements->get_form_items($data['form_id']);
1015 1015
         $total     = 0;
1016 1016
         $tax       = 0;
1017 1017
         $sub_total = 0;
1018 1018
         $country   = wpinv_default_billing_country();
1019 1019
         $state     = false;
1020 1020
 
1021
-        if ( ! empty( $_POST['wpinv_country'] ) ) {
1021
+        if (!empty($_POST['wpinv_country'])) {
1022 1022
             $country = $_POST['wpinv_country'];
1023 1023
         }
1024 1024
 
1025
-        if ( ! empty( $_POST['wpinv_state'] ) ) {
1025
+        if (!empty($_POST['wpinv_state'])) {
1026 1026
             $state = $_POST['wpinv_state'];
1027 1027
         }
1028 1028
 
1029
-        if ( ! empty( $data['wpinv-items'] ) ) {
1029
+        if (!empty($data['wpinv-items'])) {
1030 1030
 
1031
-            $selected_items = wpinv_clean( $data['wpinv-items'] );
1031
+            $selected_items = wpinv_clean($data['wpinv-items']);
1032 1032
 
1033
-            foreach ( $items as $item ) {
1033
+            foreach ($items as $item) {
1034 1034
 
1035
-                if ( ! isset( $selected_items[ $item['id'] ] ) ) {
1035
+                if (!isset($selected_items[$item['id']])) {
1036 1036
                     continue;
1037 1037
                 }
1038 1038
 
1039 1039
                 $quantity = 1;
1040 1040
 
1041
-                if ( ! empty( $item['allow_quantities'] ) && ! empty( $data["wpinv-item-{$item['id']}-quantity"] ) ) {
1041
+                if (!empty($item['allow_quantities']) && !empty($data["wpinv-item-{$item['id']}-quantity"])) {
1042 1042
 
1043
-                    $quantity = intval( $data["wpinv-item-{$item['id']}-quantity"] );
1043
+                    $quantity = intval($data["wpinv-item-{$item['id']}-quantity"]);
1044 1044
 
1045
-                    if ( 1 > $quantity ) {
1045
+                    if (1 > $quantity) {
1046 1046
                         $quantity = 1;
1047 1047
                     }
1048 1048
 
1049 1049
                 }
1050 1050
 
1051 1051
                 // Custom pricing.
1052
-                $price = wpinv_sanitize_amount( $item['price'] );
1053
-                if ( ! empty( $item['custom_price'] ) ) {
1052
+                $price = wpinv_sanitize_amount($item['price']);
1053
+                if (!empty($item['custom_price'])) {
1054 1054
 
1055
-                    $minimum_price = wpinv_sanitize_amount( $item['minimum_price'] );
1056
-                    $set_price     = wpinv_sanitize_amount( $selected_items[ $item['id'] ] );
1055
+                    $minimum_price = wpinv_sanitize_amount($item['minimum_price']);
1056
+                    $set_price     = wpinv_sanitize_amount($selected_items[$item['id']]);
1057 1057
 
1058
-                    if ( $set_price < $minimum_price ) {
1058
+                    if ($set_price < $minimum_price) {
1059 1059
                         $set_price = $minimum_price;
1060 1060
                     }
1061 1061
 
1062
-                    $price = wpinv_sanitize_amount( $set_price );
1062
+                    $price = wpinv_sanitize_amount($set_price);
1063 1063
 
1064 1064
                 }
1065 1065
 
1066
-                $price  = $quantity * floatval( $price );
1066
+                $price = $quantity * floatval($price);
1067 1067
 
1068
-                if ( wpinv_use_taxes() ) {
1068
+                if (wpinv_use_taxes()) {
1069 1069
 
1070
-                    $rate = wpinv_get_tax_rate( $country, $state, (int) $item['id'] );
1070
+                    $rate = wpinv_get_tax_rate($country, $state, (int) $item['id']);
1071 1071
 
1072
-                    if ( wpinv_prices_include_tax() ) {
1073
-                        $pre_tax  = ( $price - $price * $rate * 0.01 );
1072
+                    if (wpinv_prices_include_tax()) {
1073
+                        $pre_tax  = ($price - $price * $rate * 0.01);
1074 1074
                         $item_tax = $price - $pre_tax;
1075 1075
                     } else {
1076 1076
                         $pre_tax  = $price;
@@ -1082,17 +1082,17 @@  discard block
 block discarded – undo
1082 1082
                     $total     = $sub_total + $tax;
1083 1083
 
1084 1084
                 } else {
1085
-                    $total  = $total + $price;
1085
+                    $total = $total + $price;
1086 1086
                 }
1087 1087
 
1088 1088
             }
1089 1089
 
1090 1090
         }
1091 1091
 
1092
-        wp_send_json_success( array(
1093
-            'total'     => wpinv_price( wpinv_format_amount( $total ) ),
1094
-            'tax'       => wpinv_price( wpinv_format_amount( $tax ) ),
1095
-            'sub_total' => wpinv_price( wpinv_format_amount( $sub_total ) ),
1092
+        wp_send_json_success(array(
1093
+            'total'     => wpinv_price(wpinv_format_amount($total)),
1094
+            'tax'       => wpinv_price(wpinv_format_amount($tax)),
1095
+            'sub_total' => wpinv_price(wpinv_format_amount($sub_total)),
1096 1096
         ));
1097 1097
         exit;
1098 1098
     }
@@ -1105,53 +1105,53 @@  discard block
 block discarded – undo
1105 1105
     public static function buy_items() {
1106 1106
         $user_id = get_current_user_id();
1107 1107
 
1108
-        if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page
1109
-            wp_send_json( array(
1110
-                'success' => wp_login_url( wp_get_referer() )
1111
-            ) );
1108
+        if (empty($user_id)) { // If not logged in then lets redirect to the login page
1109
+            wp_send_json(array(
1110
+                'success' => wp_login_url(wp_get_referer())
1111
+            ));
1112 1112
         } else {
1113 1113
             // Only check nonce if logged in as it could be cached when logged out.
1114
-            if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) {
1115
-                wp_send_json( array(
1116
-                    'error' => __( 'Security checks failed.', 'invoicing' )
1117
-                ) );
1114
+            if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) {
1115
+                wp_send_json(array(
1116
+                    'error' => __('Security checks failed.', 'invoicing')
1117
+                ));
1118 1118
                 wp_die();
1119 1119
             }
1120 1120
 
1121 1121
             // allow to set a custom price through post_id
1122 1122
             $items = $_POST['items'];
1123
-            $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0;
1124
-            $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0;
1123
+            $related_post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0;
1124
+            $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0;
1125 1125
 
1126 1126
             $cart_items = array();
1127
-            if ( $items ) {
1128
-                $items = explode( ',', $items );
1127
+            if ($items) {
1128
+                $items = explode(',', $items);
1129 1129
 
1130
-                foreach( $items as $item ) {
1130
+                foreach ($items as $item) {
1131 1131
                     $item_id = $item;
1132 1132
                     $quantity = 1;
1133 1133
 
1134
-                    if ( strpos( $item, '|' ) !== false ) {
1135
-                        $item_parts = explode( '|', $item );
1134
+                    if (strpos($item, '|') !== false) {
1135
+                        $item_parts = explode('|', $item);
1136 1136
                         $item_id = $item_parts[0];
1137 1137
                         $quantity = $item_parts[1];
1138 1138
                     }
1139 1139
 
1140
-                    if ( $item_id && $quantity ) {
1140
+                    if ($item_id && $quantity) {
1141 1141
                         $cart_items_arr = array(
1142
-                            'id'            => (int)$item_id,
1143
-                            'quantity'      => (int)$quantity
1142
+                            'id'            => (int) $item_id,
1143
+                            'quantity'      => (int) $quantity
1144 1144
                         );
1145 1145
 
1146 1146
                         // If there is a related post id then add it to meta
1147
-                        if ( $related_post_id ) {
1147
+                        if ($related_post_id) {
1148 1148
                             $cart_items_arr['meta'] = array(
1149 1149
                                 'post_id'   => $related_post_id
1150 1150
                             );
1151 1151
                         }
1152 1152
 
1153 1153
                         // If there is a custom price then set it.
1154
-                        if ( $custom_item_price ) {
1154
+                        if ($custom_item_price) {
1155 1155
                             $cart_items_arr['custom_price'] = $custom_item_price;
1156 1156
                         }
1157 1157
 
@@ -1167,37 +1167,37 @@  discard block
 block discarded – undo
1167 1167
              * @param int $related_post_id The related post id if any.
1168 1168
              * @since 1.0.0
1169 1169
              */
1170
-            $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id );
1170
+            $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id);
1171 1171
 
1172 1172
             // Make sure its not in the cart already, if it is then redirect to checkout.
1173 1173
             $cart_invoice = wpinv_get_invoice_cart();
1174 1174
 
1175
-            if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) {
1176
-                wp_send_json( array(
1175
+            if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) {
1176
+                wp_send_json(array(
1177 1177
                     'success' =>  $cart_invoice->get_checkout_payment_url()
1178
-                ) );
1178
+                ));
1179 1179
                 wp_die();
1180 1180
             }
1181 1181
 
1182 1182
             // Check if user has invoice with same items waiting to be paid.
1183
-            $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' );
1184
-            if ( !empty( $user_invoices ) ) {
1185
-                foreach( $user_invoices as $user_invoice ) {
1183
+            $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending');
1184
+            if (!empty($user_invoices)) {
1185
+                foreach ($user_invoices as $user_invoice) {
1186 1186
                     $user_cart_details = array();
1187
-                    $invoice  = wpinv_get_invoice( $user_invoice->ID );
1187
+                    $invoice = wpinv_get_invoice($user_invoice->ID);
1188 1188
                     $cart_details = $invoice->get_cart_details();
1189 1189
 
1190
-                    if ( !empty( $cart_details ) ) {
1191
-                        foreach ( $cart_details as $invoice_item ) {
1190
+                    if (!empty($cart_details)) {
1191
+                        foreach ($cart_details as $invoice_item) {
1192 1192
                             $ii_arr = array();
1193
-                            $ii_arr['id'] = (int)$invoice_item['id'];
1194
-                            $ii_arr['quantity'] = (int)$invoice_item['quantity'];
1193
+                            $ii_arr['id'] = (int) $invoice_item['id'];
1194
+                            $ii_arr['quantity'] = (int) $invoice_item['quantity'];
1195 1195
 
1196
-                            if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) {
1196
+                            if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) {
1197 1197
                                 $ii_arr['meta'] = $invoice_item['meta'];
1198 1198
                             }
1199 1199
 
1200
-                            if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) {
1200
+                            if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) {
1201 1201
                                 $ii_arr['custom_price'] = $invoice_item['custom_price'];
1202 1202
                             }
1203 1203
 
@@ -1205,17 +1205,17 @@  discard block
 block discarded – undo
1205 1205
                         }
1206 1206
                     }
1207 1207
 
1208
-                    if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) {
1209
-                        wp_send_json( array(
1208
+                    if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) {
1209
+                        wp_send_json(array(
1210 1210
                             'success' =>  $invoice->get_checkout_payment_url()
1211
-                        ) );
1211
+                        ));
1212 1212
                         wp_die();
1213 1213
                     }
1214 1214
                 }
1215 1215
             }
1216 1216
 
1217 1217
             // Create invoice and send user to checkout
1218
-            if ( !empty( $cart_items ) ) {
1218
+            if (!empty($cart_items)) {
1219 1219
                 $invoice_data = array(
1220 1220
                     'status'        =>  'wpi-pending',
1221 1221
                     'created_via'   =>  'wpi',
@@ -1223,21 +1223,21 @@  discard block
 block discarded – undo
1223 1223
                     'cart_details'  =>  $cart_items,
1224 1224
                 );
1225 1225
 
1226
-                $invoice = wpinv_insert_invoice( $invoice_data, true );
1226
+                $invoice = wpinv_insert_invoice($invoice_data, true);
1227 1227
 
1228
-                if ( !empty( $invoice ) && isset( $invoice->ID ) ) {
1229
-                    wp_send_json( array(
1228
+                if (!empty($invoice) && isset($invoice->ID)) {
1229
+                    wp_send_json(array(
1230 1230
                         'success' =>  $invoice->get_checkout_payment_url()
1231
-                    ) );
1231
+                    ));
1232 1232
                 } else {
1233
-                    wp_send_json( array(
1234
-                        'error' => __( 'Invoice failed to create', 'invoicing' )
1235
-                    ) );
1233
+                    wp_send_json(array(
1234
+                        'error' => __('Invoice failed to create', 'invoicing')
1235
+                    ));
1236 1236
                 }
1237 1237
             } else {
1238
-                wp_send_json( array(
1239
-                    'error' => __( 'Items not valid.', 'invoicing' )
1240
-                ) );
1238
+                wp_send_json(array(
1239
+                    'error' => __('Items not valid.', 'invoicing')
1240
+                ));
1241 1241
             }
1242 1242
         }
1243 1243
 
Please login to merge, or discard this patch.
includes/admin/wpinv-admin-functions.php 1 patch
Spacing   +246 added lines, -246 removed lines patch added patch discarded remove patch
@@ -7,245 +7,245 @@  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
-function wpinv_columns( $columns ) {
14
+function wpinv_columns($columns) {
15 15
     $columns = array(
16 16
         'cb'                => $columns['cb'],
17
-        'number'            => __( 'Number', 'invoicing' ),
18
-        'customer'          => __( 'Customer', 'invoicing' ),
19
-        'amount'            => __( 'Amount', 'invoicing' ),
20
-        'invoice_date'      => __( 'Created Date', 'invoicing' ),
21
-        'payment_date'      => __( 'Payment Date', 'invoicing' ),
22
-        'status'            => __( 'Status', 'invoicing' ),
23
-        'ID'                => __( 'ID', 'invoicing' ),
24
-        'wpi_actions'       => __( 'Actions', 'invoicing' ),
17
+        'number'            => __('Number', 'invoicing'),
18
+        'customer'          => __('Customer', 'invoicing'),
19
+        'amount'            => __('Amount', 'invoicing'),
20
+        'invoice_date'      => __('Created Date', 'invoicing'),
21
+        'payment_date'      => __('Payment Date', 'invoicing'),
22
+        'status'            => __('Status', 'invoicing'),
23
+        'ID'                => __('ID', 'invoicing'),
24
+        'wpi_actions'       => __('Actions', 'invoicing'),
25 25
     );
26 26
 
27
-    return apply_filters( 'wpi_invoice_table_columns', $columns );
27
+    return apply_filters('wpi_invoice_table_columns', $columns);
28 28
 }
29
-add_filter( 'manage_wpi_invoice_posts_columns', 'wpinv_columns' );
29
+add_filter('manage_wpi_invoice_posts_columns', 'wpinv_columns');
30 30
 
31
-function wpinv_bulk_actions( $actions ) {
32
-    if ( isset( $actions['edit'] ) ) {
33
-        unset( $actions['edit'] );
31
+function wpinv_bulk_actions($actions) {
32
+    if (isset($actions['edit'])) {
33
+        unset($actions['edit']);
34 34
     }
35 35
 
36 36
     return $actions;
37 37
 }
38
-add_filter( 'bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions' );
39
-add_filter( 'bulk_actions-edit-wpi_item', 'wpinv_bulk_actions' );
38
+add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions');
39
+add_filter('bulk_actions-edit-wpi_item', 'wpinv_bulk_actions');
40 40
 
41
-function wpinv_sortable_columns( $columns ) {
41
+function wpinv_sortable_columns($columns) {
42 42
     $columns = array(
43
-        'ID'            => array( 'ID', true ),
44
-        'number'        => array( 'number', false ),
45
-        'amount'        => array( 'amount', false ),
46
-        'invoice_date'  => array( 'date', false ),
47
-        'payment_date'  => array( 'payment_date', true ),
48
-        'customer'      => array( 'customer', false ),
49
-        'status'        => array( 'status', false ),
43
+        'ID'            => array('ID', true),
44
+        'number'        => array('number', false),
45
+        'amount'        => array('amount', false),
46
+        'invoice_date'  => array('date', false),
47
+        'payment_date'  => array('payment_date', true),
48
+        'customer'      => array('customer', false),
49
+        'status'        => array('status', false),
50 50
     );
51 51
     
52
-    return apply_filters( 'wpi_invoice_table_sortable_columns', $columns );
52
+    return apply_filters('wpi_invoice_table_sortable_columns', $columns);
53 53
 }
54
-add_filter( 'manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns' );
54
+add_filter('manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns');
55 55
 
56
-add_action( 'manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
57
-function wpinv_posts_custom_column( $column_name, $post_id = 0 ) {
56
+add_action('manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
57
+function wpinv_posts_custom_column($column_name, $post_id = 0) {
58 58
     global $post, $wpi_invoice;
59 59
     
60
-    if ( empty( $wpi_invoice ) || ( !empty( $wpi_invoice ) && $post->ID != $wpi_invoice->ID ) ) {
61
-        $wpi_invoice = new WPInv_Invoice( $post->ID );
60
+    if (empty($wpi_invoice) || (!empty($wpi_invoice) && $post->ID != $wpi_invoice->ID)) {
61
+        $wpi_invoice = new WPInv_Invoice($post->ID);
62 62
     }
63 63
 
64 64
     $value = NULL;
65 65
     
66
-    switch ( $column_name ) {
66
+    switch ($column_name) {
67 67
         case 'email' :
68
-            $value   = $wpi_invoice->get_email();
68
+            $value = $wpi_invoice->get_email();
69 69
             break;
70 70
         case 'customer' :
71 71
             $customer_name = $wpi_invoice->get_user_full_name();
72
-            $customer_name = $customer_name != '' ? $customer_name : __( 'Customer', 'invoicing' );
73
-            $value = '<a href="' . esc_url( get_edit_user_link( $wpi_invoice->get_user_id() ) ) . '">' . $customer_name . '</a>';
74
-            if ( $email = $wpi_invoice->get_email() ) {
72
+            $customer_name = $customer_name != '' ? $customer_name : __('Customer', 'invoicing');
73
+            $value = '<a href="' . esc_url(get_edit_user_link($wpi_invoice->get_user_id())) . '">' . $customer_name . '</a>';
74
+            if ($email = $wpi_invoice->get_email()) {
75 75
                 $value .= '<br><a class="email" href="mailto:' . $email . '">' . $email . '</a>';
76 76
             }
77 77
             break;
78 78
         case 'amount' :
79
-            echo $wpi_invoice->get_total( true );
79
+            echo $wpi_invoice->get_total(true);
80 80
             break;
81 81
         case 'invoice_date' :
82
-            $date_format = get_option( 'date_format' );
82
+            $date_format = get_option('date_format');
83 83
             
84 84
             $m_time = $post->post_date;
85
-            $h_time = mysql2date( $date_format, $m_time );
85
+            $h_time = mysql2date($date_format, $m_time);
86 86
             
87
-            $value   = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
87
+            $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
88 88
             break;
89 89
         case 'payment_date' :
90
-            if ( $date_completed = $wpi_invoice->get_meta( '_wpinv_completed_date', true ) ) {
91
-                $date_format = get_option( 'date_format' );
90
+            if ($date_completed = $wpi_invoice->get_meta('_wpinv_completed_date', true)) {
91
+                $date_format = get_option('date_format');
92 92
                 
93 93
                 $m_time = $date_completed;
94
-                $h_time = mysql2date( $date_format, $m_time );
94
+                $h_time = mysql2date($date_format, $m_time);
95 95
                 
96
-                $value   = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
96
+                $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
97 97
             } else {
98 98
                 $value = '-';
99 99
             }
100 100
             break;
101 101
         case 'status' :
102
-            $value   = $wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' );
103
-            $is_viewed = wpinv_is_invoice_viewed( $wpi_invoice->ID );
104
-	        $gateway_title = wpinv_get_gateway_admin_label( $wpi_invoice->get_gateway() );
102
+            $value = $wpi_invoice->get_status(true) . ($wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '');
103
+            $is_viewed = wpinv_is_invoice_viewed($wpi_invoice->ID);
104
+	        $gateway_title = wpinv_get_gateway_admin_label($wpi_invoice->get_gateway());
105 105
 	        $offline_gateways = apply_filters('wpinv_offline_payments', array('bank_transfer', 'cheque', 'cod'));
106 106
 	        $is_offline_payment = in_array($wpi_invoice->get_gateway(), $offline_gateways) ? true : false;
107 107
 
108
-            if ( 1 == $is_viewed ) {
109
-                $value .= '&nbsp;&nbsp;<i class="fa fa-eye" title="'.__( 'Viewed by Customer', 'invoicing' ).'"></i>';
108
+            if (1 == $is_viewed) {
109
+                $value .= '&nbsp;&nbsp;<i class="fa fa-eye" title="' . __('Viewed by Customer', 'invoicing') . '"></i>';
110 110
             }
111
-            if ( ( $wpi_invoice->is_paid() || $wpi_invoice->is_refunded() || $is_offline_payment ) && ( isset( $gateway_title ) ) ) {
112
-                $value .= '<br><small class="meta gateway">' . wp_sprintf( __( 'Via %s', 'invoicing' ), $gateway_title ) . '</small>';
111
+            if (($wpi_invoice->is_paid() || $wpi_invoice->is_refunded() || $is_offline_payment) && (isset($gateway_title))) {
112
+                $value .= '<br><small class="meta gateway">' . wp_sprintf(__('Via %s', 'invoicing'), $gateway_title) . '</small>';
113 113
             }
114 114
             break;
115 115
         case 'number' :
116
-            $edit_link = get_edit_post_link( $post->ID );
117
-            $value = '<a title="' . esc_attr__( 'View Invoice Details', 'invoicing' ) . '" href="' . esc_url( $edit_link ) . '">' . $wpi_invoice->get_number() . '</a>';
116
+            $edit_link = get_edit_post_link($post->ID);
117
+            $value = '<a title="' . esc_attr__('View Invoice Details', 'invoicing') . '" href="' . esc_url($edit_link) . '">' . $wpi_invoice->get_number() . '</a>';
118 118
             break;
119 119
         case 'wpi_actions' :
120 120
             $value = '';
121
-            if ( !empty( $post->post_name ) ) {
122
-                $value .= '<a title="' . esc_attr__( 'Print invoice', 'invoicing' ) . '" href="' . esc_url( get_permalink( $post->ID ) ) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
121
+            if (!empty($post->post_name)) {
122
+                $value .= '<a title="' . esc_attr__('Print invoice', 'invoicing') . '" href="' . esc_url(get_permalink($post->ID)) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
123 123
             }
124 124
             
125
-            if ( $email = $wpi_invoice->get_email() ) {
126
-                $value .= '<a title="' . esc_attr__( 'Send invoice to customer', 'invoicing' ) . '" href="' . esc_url( add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) ) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
125
+            if ($email = $wpi_invoice->get_email()) {
126
+                $value .= '<a title="' . esc_attr__('Send invoice to customer', 'invoicing') . '" href="' . esc_url(add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID))) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
127 127
             }
128 128
             
129 129
             break;
130 130
         default:
131
-            $value = isset( $post->$column_name ) ? $post->$column_name : '';
131
+            $value = isset($post->$column_name) ? $post->$column_name : '';
132 132
             break;
133 133
 
134 134
     }
135
-    $value = apply_filters( 'wpinv_payments_table_column', $value, $post->ID, $column_name );
135
+    $value = apply_filters('wpinv_payments_table_column', $value, $post->ID, $column_name);
136 136
     
137
-    if ( $value !== NULL ) {
137
+    if ($value !== NULL) {
138 138
         echo $value;
139 139
     }
140 140
 }
141 141
 
142
-function wpinv_admin_post_id( $id = 0 ) {
142
+function wpinv_admin_post_id($id = 0) {
143 143
     global $post;
144 144
 
145
-    if ( isset( $id ) && ! empty( $id ) ) {
146
-        return (int)$id;
147
-    } else if ( get_the_ID() ) {
145
+    if (isset($id) && !empty($id)) {
146
+        return (int) $id;
147
+    } else if (get_the_ID()) {
148 148
         return (int) get_the_ID();
149
-    } else if ( isset( $post->ID ) && !empty( $post->ID ) ) {
149
+    } else if (isset($post->ID) && !empty($post->ID)) {
150 150
         return (int) $post->ID;
151
-    } else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) {
151
+    } else if (isset($_GET['post']) && !empty($_GET['post'])) {
152 152
         return (int) $_GET['post'];
153
-    } else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) {
153
+    } else if (isset($_GET['id']) && !empty($_GET['id'])) {
154 154
         return (int) $_GET['id'];
155
-    } else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) {
155
+    } else if (isset($_POST['id']) && !empty($_POST['id'])) {
156 156
         return (int) $_POST['id'];
157 157
     } 
158 158
 
159 159
     return null;
160 160
 }
161 161
     
162
-function wpinv_admin_post_type( $id = 0 ) {
163
-    if ( !$id ) {
162
+function wpinv_admin_post_type($id = 0) {
163
+    if (!$id) {
164 164
         $id = wpinv_admin_post_id();
165 165
     }
166 166
     
167
-    $type = get_post_type( $id );
167
+    $type = get_post_type($id);
168 168
     
169
-    if ( !$type ) {
170
-        $type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null;
169
+    if (!$type) {
170
+        $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? $_GET['post_type'] : null;
171 171
     }
172 172
     
173
-    return apply_filters( 'wpinv_admin_post_type', $type, $id );
173
+    return apply_filters('wpinv_admin_post_type', $type, $id);
174 174
 }
175 175
 
176 176
 function wpinv_admin_messages() {
177 177
 	global $wpinv_options, $pagenow, $post;
178 178
 
179
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
180
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' );
179
+	if (isset($_GET['wpinv-message']) && 'discount_added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
180
+		 add_settings_error('wpinv-notices', 'wpinv-discount-added', __('Discount code added.', 'invoicing'), 'updated');
181 181
 	}
182 182
 
183
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
184
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' );
183
+	if (isset($_GET['wpinv-message']) && 'discount_add_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
184
+		add_settings_error('wpinv-notices', 'wpinv-discount-add-fail', __('There was a problem adding your discount code, please try again.', 'invoicing'), 'error');
185 185
 	}
186 186
 
187
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
188
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' );
187
+	if (isset($_GET['wpinv-message']) && 'discount_exists' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
188
+		add_settings_error('wpinv-notices', 'wpinv-discount-exists', __('A discount with that code already exists, please use a different code.', 'invoicing'), 'error');
189 189
 	}
190 190
 
191
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
192
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' );
191
+	if (isset($_GET['wpinv-message']) && 'discount_updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
192
+		 add_settings_error('wpinv-notices', 'wpinv-discount-updated', __('Discount code updated.', 'invoicing'), 'updated');
193 193
 	}
194 194
 
195
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
196
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' );
195
+	if (isset($_GET['wpinv-message']) && 'discount_update_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
196
+		add_settings_error('wpinv-notices', 'wpinv-discount-updated-fail', __('There was a problem updating your discount code, please try again.', 'invoicing'), 'error');
197 197
 	}
198 198
 
199
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
200
-		add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' );
199
+	if (isset($_GET['wpinv-message']) && 'invoice_deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
200
+		add_settings_error('wpinv-notices', 'wpinv-deleted', __('The invoice has been deleted.', 'invoicing'), 'updated');
201 201
 	}
202 202
 
203
-	if ( isset( $_GET['wpinv-message'] ) && 'email_disabled' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
204
-		add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Email notification is disabled. Please check settings.', 'invoicing' ), 'error' );
203
+	if (isset($_GET['wpinv-message']) && 'email_disabled' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
204
+		add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Email notification is disabled. Please check settings.', 'invoicing'), 'error');
205 205
 	}
206 206
 
207
-	if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
208
-		add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' );
207
+	if (isset($_GET['wpinv-message']) && 'email_sent' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
208
+		add_settings_error('wpinv-notices', 'wpinv-sent', __('The email has been sent to customer.', 'invoicing'), 'updated');
209 209
     }
210 210
     
211
-    if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
212
-		add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' );
211
+    if (isset($_GET['wpinv-message']) && 'email_fail' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
212
+		add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Fail to send email to the customer.', 'invoicing'), 'error');
213 213
     }
214 214
 
215
-    if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
216
-        add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' );
215
+    if (isset($_GET['wpinv-message']) && 'invoice-note-deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
216
+        add_settings_error('wpinv-notices', 'wpinv-note-deleted', __('The invoice note has been deleted.', 'invoicing'), 'updated');
217 217
     }
218 218
 
219
-	if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
220
-		add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' );
219
+	if (isset($_GET['wpinv-message']) && 'settings-imported' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
220
+		add_settings_error('wpinv-notices', 'wpinv-settings-imported', __('The settings have been imported.', 'invoicing'), 'updated');
221 221
 	}
222 222
 
223
-	if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
224
-		add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' );
223
+	if (isset($_GET['wpinv-message']) && 'note-added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
224
+		add_settings_error('wpinv-notices', 'wpinv-note-added', __('The invoice note has been added successfully.', 'invoicing'), 'updated');
225 225
 	}
226 226
 
227
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
228
-		add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' );
227
+	if (isset($_GET['wpinv-message']) && 'invoice-updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
228
+		add_settings_error('wpinv-notices', 'wpinv-updated', __('The invoice has been successfully updated.', 'invoicing'), 'updated');
229 229
 	}
230 230
     
231
-	if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) {
232
-		$message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID );
231
+	if ($pagenow == 'post.php' && !empty($post->post_type) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable($post)) {
232
+		$message = apply_filters('wpinv_item_non_editable_message', __('This item in not editable.', 'invoicing'), $post->ID);
233 233
 
234
-		if ( !empty( $message ) ) {
235
-			add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' );
234
+		if (!empty($message)) {
235
+			add_settings_error('wpinv-notices', 'wpinv-edit-n', $message, 'updated');
236 236
 		}
237 237
 	}
238 238
 
239
-	settings_errors( 'wpinv-notices' );
239
+	settings_errors('wpinv-notices');
240 240
 }
241
-add_action( 'admin_notices', 'wpinv_admin_messages' );
241
+add_action('admin_notices', 'wpinv_admin_messages');
242 242
 
243
-add_action( 'admin_init', 'wpinv_show_test_payment_gateway_notice' );
244
-function wpinv_show_test_payment_gateway_notice(){
245
-    add_action( 'admin_notices', 'wpinv_test_payment_gateway_messages' );
243
+add_action('admin_init', 'wpinv_show_test_payment_gateway_notice');
244
+function wpinv_show_test_payment_gateway_notice() {
245
+    add_action('admin_notices', 'wpinv_test_payment_gateway_messages');
246 246
 }
247 247
 
248
-function wpinv_test_payment_gateway_messages(){
248
+function wpinv_test_payment_gateway_messages() {
249 249
     $gateways = wpinv_get_enabled_payment_gateways();
250 250
     $name = array(); $test_gateways = '';
251 251
     if ($gateways) {
@@ -256,9 +256,9 @@  discard block
 block discarded – undo
256 256
         }
257 257
         $test_gateways = implode(', ', $name);
258 258
     }
259
-    if(isset($test_gateways) && !empty($test_gateways)){
259
+    if (isset($test_gateways) && !empty($test_gateways)) {
260 260
         $link = admin_url('admin.php?page=wpinv-settings&tab=gateways');
261
-        $notice = wp_sprintf( __('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link );
261
+        $notice = wp_sprintf(__('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link);
262 262
         ?>
263 263
         <div class="notice notice-warning is-dismissible">
264 264
             <p><?php echo $notice; ?></p>
@@ -267,29 +267,29 @@  discard block
 block discarded – undo
267 267
     }
268 268
 }
269 269
 
270
-function wpinv_items_columns( $existing_columns ) {
270
+function wpinv_items_columns($existing_columns) {
271 271
     global $wpinv_euvat;
272 272
     
273 273
     $columns                = array();
274 274
     $columns['cb']          = $existing_columns['cb'];
275
-    $columns['title']       = __( 'Title', 'invoicing' );
276
-    $columns['price']       = __( 'Price', 'invoicing' );
277
-    if ( $wpinv_euvat->allow_vat_rules() ) {
278
-        $columns['vat_rule']    = __( 'VAT rule type', 'invoicing' );
275
+    $columns['title']       = __('Title', 'invoicing');
276
+    $columns['price']       = __('Price', 'invoicing');
277
+    if ($wpinv_euvat->allow_vat_rules()) {
278
+        $columns['vat_rule']    = __('VAT rule type', 'invoicing');
279 279
     }
280
-    if ( $wpinv_euvat->allow_vat_classes() ) {
281
-        $columns['vat_class']   = __( 'VAT class', 'invoicing' );
280
+    if ($wpinv_euvat->allow_vat_classes()) {
281
+        $columns['vat_class']   = __('VAT class', 'invoicing');
282 282
     }
283
-    $columns['type']        = __( 'Type', 'invoicing' );
284
-    $columns['recurring']   = __( 'Recurring', 'invoicing' );
285
-    $columns['date']        = __( 'Date', 'invoicing' );
286
-    $columns['id']          = __( 'ID', 'invoicing' );
283
+    $columns['type']        = __('Type', 'invoicing');
284
+    $columns['recurring']   = __('Recurring', 'invoicing');
285
+    $columns['date']        = __('Date', 'invoicing');
286
+    $columns['id']          = __('ID', 'invoicing');
287 287
 
288
-    return apply_filters( 'wpinv_items_columns', $columns );
288
+    return apply_filters('wpinv_items_columns', $columns);
289 289
 }
290
-add_filter( 'manage_wpi_item_posts_columns', 'wpinv_items_columns' );
290
+add_filter('manage_wpi_item_posts_columns', 'wpinv_items_columns');
291 291
 
292
-function wpinv_items_sortable_columns( $columns ) {
292
+function wpinv_items_sortable_columns($columns) {
293 293
     $columns['price']       = 'price';
294 294
     $columns['vat_rule']    = 'vat_rule';
295 295
     $columns['vat_class']   = 'vat_class';
@@ -299,175 +299,175 @@  discard block
 block discarded – undo
299 299
 
300 300
     return $columns;
301 301
 }
302
-add_filter( 'manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns' );
302
+add_filter('manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns');
303 303
 
304
-function wpinv_items_table_custom_column( $column ) {
304
+function wpinv_items_table_custom_column($column) {
305 305
     global $wpinv_euvat, $post, $wpi_item;
306 306
     
307
-    if ( empty( $wpi_item ) || ( !empty( $wpi_item ) && $post->ID != $wpi_item->ID ) ) {
308
-        $wpi_item = new WPInv_Item( $post->ID );
307
+    if (empty($wpi_item) || (!empty($wpi_item) && $post->ID != $wpi_item->ID)) {
308
+        $wpi_item = new WPInv_Item($post->ID);
309 309
     }
310 310
 
311
-    switch ( $column ) {
311
+    switch ($column) {
312 312
         case 'price' :
313
-            echo wpinv_item_price( $post->ID );
313
+            echo wpinv_item_price($post->ID);
314 314
         break;
315 315
         case 'vat_rule' :
316
-            echo $wpinv_euvat->item_rule_label( $post->ID );
316
+            echo $wpinv_euvat->item_rule_label($post->ID);
317 317
         break;
318 318
         case 'vat_class' :
319
-            echo $wpinv_euvat->item_class_label( $post->ID );
319
+            echo $wpinv_euvat->item_class_label($post->ID);
320 320
         break;
321 321
         case 'type' :
322
-            echo wpinv_item_type( $post->ID ) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>';
322
+            echo wpinv_item_type($post->ID) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>';
323 323
         break;
324 324
         case 'recurring' :
325
-            echo ( wpinv_is_recurring_item( $post->ID ) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>' );
325
+            echo (wpinv_is_recurring_item($post->ID) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>');
326 326
         break;
327 327
         case 'id' :
328 328
            echo $post->ID;
329 329
            echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '">
330
-                    <div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>';
331
-                    if ( $wpinv_euvat->allow_vat_rules() ) {
332
-                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</div>';
330
+                    <div class="price">' . wpinv_get_item_price($post->ID) . '</div>';
331
+                    if ($wpinv_euvat->allow_vat_rules()) {
332
+                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule($post->ID) . '</div>';
333 333
                     }
334
-                    if ( $wpinv_euvat->allow_vat_classes() ) {
335
-                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class( $post->ID ) . '</div>';
334
+                    if ($wpinv_euvat->allow_vat_classes()) {
335
+                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class($post->ID) . '</div>';
336 336
                     }
337
-                    echo '<div class="type">' . wpinv_get_item_type( $post->ID ) . '</div>
337
+                    echo '<div class="type">' . wpinv_get_item_type($post->ID) . '</div>
338 338
                 </div>';
339 339
         break;
340 340
     }
341 341
     
342
-    do_action( 'wpinv_items_table_column_item_' . $column, $wpi_item, $post );
342
+    do_action('wpinv_items_table_column_item_' . $column, $wpi_item, $post);
343 343
 }
344
-add_action( 'manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column' );
344
+add_action('manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column');
345 345
 
346 346
 function wpinv_add_items_filters() {
347 347
     global $wpinv_euvat, $typenow;
348 348
 
349 349
     // Checks if the current post type is 'item'
350
-    if ( $typenow == 'wpi_item') {
351
-        if ( $wpinv_euvat->allow_vat_rules() ) {
350
+    if ($typenow == 'wpi_item') {
351
+        if ($wpinv_euvat->allow_vat_rules()) {
352 352
 
353 353
             // Sanitize selected vat rule.
354
-            $vat_rule   = '';
355
-            if( isset( $_GET['vat_rule'] ) && array_key_exists(  $_GET['type'], $wpinv_euvat->get_rules() ) ) {
356
-                $class   =  $_GET['type'];
354
+            $vat_rule = '';
355
+            if (isset($_GET['vat_rule']) && array_key_exists($_GET['type'], $wpinv_euvat->get_rules())) {
356
+                $class = $_GET['type'];
357 357
             }
358 358
 
359
-            echo wpinv_html_select( array(
360
-                    'options'          => array_merge( array( '' => __( 'All VAT rules', 'invoicing' ) ), $wpinv_euvat->get_rules() ),
359
+            echo wpinv_html_select(array(
360
+                    'options'          => array_merge(array('' => __('All VAT rules', 'invoicing')), $wpinv_euvat->get_rules()),
361 361
                     'name'             => 'vat_rule',
362 362
                     'id'               => 'vat_rule',
363
-                    'selected'         => ( isset( $_GET['vat_rule'] ) ? $_GET['vat_rule'] : '' ),
363
+                    'selected'         => (isset($_GET['vat_rule']) ? $_GET['vat_rule'] : ''),
364 364
                     'show_option_all'  => false,
365 365
                     'show_option_none' => false,
366 366
                     'class'            => 'gdmbx2-text-medium wpi_select2',
367
-                    'placeholder'      => __( 'Select VAT rule', 'invoicing' ),
368
-                ) );
367
+                    'placeholder'      => __('Select VAT rule', 'invoicing'),
368
+                ));
369 369
         }
370 370
 
371
-        if ( $wpinv_euvat->allow_vat_classes() ) {
371
+        if ($wpinv_euvat->allow_vat_classes()) {
372 372
 
373 373
             $classes = $wpinv_euvat->get_all_classes();
374 374
 
375 375
             // Sanitize selected vat class.
376 376
             $class   = '';
377
-            if( isset( $_GET['vat_class'] ) && array_key_exists(  $_GET['vat_class'], $classes ) ) {
378
-                $class   =  $_GET['vat_class'];
377
+            if (isset($_GET['vat_class']) && array_key_exists($_GET['vat_class'], $classes)) {
378
+                $class = $_GET['vat_class'];
379 379
             }
380 380
 
381
-            echo wpinv_html_select( array(
382
-                    'options'          => array_merge( array( '' => __( 'All VAT classes', 'invoicing' ) ), $classes ),
381
+            echo wpinv_html_select(array(
382
+                    'options'          => array_merge(array('' => __('All VAT classes', 'invoicing')), $classes),
383 383
                     'name'             => 'vat_class',
384 384
                     'id'               => 'vat_class',
385 385
                     'selected'         => $class,
386 386
                     'show_option_all'  => false,
387 387
                     'show_option_none' => false,
388 388
                     'class'            => 'gdmbx2-text-medium wpi_select2',
389
-                    'placeholder'      => __( 'Select VAT class', 'invoicing' ),
390
-                ) );
389
+                    'placeholder'      => __('Select VAT class', 'invoicing'),
390
+                ));
391 391
         }
392 392
         
393 393
         // Sanitize selected item type.
394
-        $type   = '';
395
-        if( isset( $_GET['type'] ) && array_key_exists(  $_GET['type'], wpinv_get_item_types() ) ) {
396
-            $class   =  $_GET['type'];
394
+        $type = '';
395
+        if (isset($_GET['type']) && array_key_exists($_GET['type'], wpinv_get_item_types())) {
396
+            $class = $_GET['type'];
397 397
         }
398 398
 
399
-        echo wpinv_html_select( array(
400
-                'options'          => array_merge( array( '' => __( 'All item types', 'invoicing' ) ), wpinv_get_item_types() ),
399
+        echo wpinv_html_select(array(
400
+                'options'          => array_merge(array('' => __('All item types', 'invoicing')), wpinv_get_item_types()),
401 401
                 'name'             => 'type',
402 402
                 'id'               => 'type',
403 403
                 'selected'         => $type,
404 404
                 'show_option_all'  => false,
405 405
                 'show_option_none' => false,
406 406
                 'class'            => 'gdmbx2-text-medium',
407
-            ) );
407
+            ));
408 408
 
409
-        if ( isset( $_REQUEST['all_posts'] ) && '1' === $_REQUEST['all_posts'] ) {
409
+        if (isset($_REQUEST['all_posts']) && '1' === $_REQUEST['all_posts']) {
410 410
             echo '<input type="hidden" name="all_posts" value="1" />';
411 411
         }
412 412
     }
413 413
 }
414
-add_action( 'restrict_manage_posts', 'wpinv_add_items_filters', 100 );
414
+add_action('restrict_manage_posts', 'wpinv_add_items_filters', 100);
415 415
 
416
-function wpinv_send_invoice_after_save( $invoice ) {
417
-    if ( empty( $_POST['wpi_save_send'] ) ) {
416
+function wpinv_send_invoice_after_save($invoice) {
417
+    if (empty($_POST['wpi_save_send'])) {
418 418
         return;
419 419
     }
420 420
     
421
-    if ( !empty( $invoice->ID ) && !empty( $invoice->post_type ) && 'wpi_invoice' == $invoice->post_type ) {
422
-        wpinv_user_invoice_notification( $invoice->ID );
421
+    if (!empty($invoice->ID) && !empty($invoice->post_type) && 'wpi_invoice' == $invoice->post_type) {
422
+        wpinv_user_invoice_notification($invoice->ID);
423 423
     }
424 424
 }
425
-add_action( 'wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1 );
425
+add_action('wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1);
426 426
 
427
-function wpinv_send_register_new_user( $data, $postarr ) {
428
-    if ( wpinv_current_user_can_manage_invoicing() && !empty( $data['post_type'] ) && ( 'wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'] ) ) {
429
-        $is_new_user = !empty( $postarr['wpinv_new_user'] ) ? true : false;
430
-        $email = !empty( $postarr['wpinv_email'] ) && $postarr['wpinv_email'] && is_email( $postarr['wpinv_email'] ) ? $postarr['wpinv_email'] : NULL;
427
+function wpinv_send_register_new_user($data, $postarr) {
428
+    if (wpinv_current_user_can_manage_invoicing() && !empty($data['post_type']) && ('wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'])) {
429
+        $is_new_user = !empty($postarr['wpinv_new_user']) ? true : false;
430
+        $email = !empty($postarr['wpinv_email']) && $postarr['wpinv_email'] && is_email($postarr['wpinv_email']) ? $postarr['wpinv_email'] : NULL;
431 431
         
432
-        if ( $is_new_user && $email && !email_exists( $email ) ) {
433
-            $first_name = !empty( $postarr['wpinv_first_name'] ) ? sanitize_text_field( $postarr['wpinv_first_name'] ) : '';
434
-            $last_name = !empty( $postarr['wpinv_last_name'] ) ? sanitize_text_field( $postarr['wpinv_last_name'] ) : '';
435
-            $display_name = $first_name || $last_name ? trim( $first_name . ' ' . $last_name ) : '';
436
-            $user_nicename = $display_name ? trim( $display_name ) : $email;
437
-            $user_company = !empty( $postarr['wpinv_company'] ) ? sanitize_text_field( $postarr['wpinv_company'] ) : '';
432
+        if ($is_new_user && $email && !email_exists($email)) {
433
+            $first_name = !empty($postarr['wpinv_first_name']) ? sanitize_text_field($postarr['wpinv_first_name']) : '';
434
+            $last_name = !empty($postarr['wpinv_last_name']) ? sanitize_text_field($postarr['wpinv_last_name']) : '';
435
+            $display_name = $first_name || $last_name ? trim($first_name . ' ' . $last_name) : '';
436
+            $user_nicename = $display_name ? trim($display_name) : $email;
437
+            $user_company = !empty($postarr['wpinv_company']) ? sanitize_text_field($postarr['wpinv_company']) : '';
438 438
             
439
-            $user_login = sanitize_user( str_replace( ' ', '', $display_name ), true );
440
-            if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
439
+            $user_login = sanitize_user(str_replace(' ', '', $display_name), true);
440
+            if (!(validate_username($user_login) && !username_exists($user_login))) {
441 441
                 $new_user_login = strstr($email, '@', true);
442
-                if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
443
-                    $user_login = sanitize_user($new_user_login, true );
442
+                if (validate_username($user_login) && username_exists($user_login)) {
443
+                    $user_login = sanitize_user($new_user_login, true);
444 444
                 }
445
-                if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
446
-                    $user_append_text = rand(10,1000);
447
-                    $user_login = sanitize_user($new_user_login.$user_append_text, true );
445
+                if (validate_username($user_login) && username_exists($user_login)) {
446
+                    $user_append_text = rand(10, 1000);
447
+                    $user_login = sanitize_user($new_user_login . $user_append_text, true);
448 448
                 }
449 449
                 
450
-                if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
450
+                if (!(validate_username($user_login) && !username_exists($user_login))) {
451 451
                     $user_login = $email;
452 452
                 }
453 453
             }
454 454
             
455 455
             $userdata = array(
456 456
                 'user_login' => $user_login,
457
-                'user_pass' => wp_generate_password( 12, false ),
458
-                'user_email' => sanitize_text_field( $email ),
457
+                'user_pass' => wp_generate_password(12, false),
458
+                'user_email' => sanitize_text_field($email),
459 459
                 'first_name' => $first_name,
460 460
                 'last_name' => $last_name,
461
-                'user_nicename' => wpinv_utf8_substr( $user_nicename, 0, 50 ),
461
+                'user_nicename' => wpinv_utf8_substr($user_nicename, 0, 50),
462 462
                 'nickname' => $display_name,
463 463
                 'display_name' => $display_name,
464 464
             );
465 465
 
466
-            $userdata = apply_filters( 'wpinv_register_new_user_data', $userdata );
466
+            $userdata = apply_filters('wpinv_register_new_user_data', $userdata);
467 467
             
468
-            $new_user_id = wp_insert_user( $userdata );
468
+            $new_user_id = wp_insert_user($userdata);
469 469
             
470
-            if ( !is_wp_error( $new_user_id ) ) {
470
+            if (!is_wp_error($new_user_id)) {
471 471
                 $data['post_author'] = $new_user_id;
472 472
                 $_POST['post_author'] = $new_user_id;
473 473
                 $_POST['post_author_override'] = $new_user_id;
@@ -488,86 +488,86 @@  discard block
 block discarded – undo
488 488
                 
489 489
                 $meta = array();
490 490
                 ///$meta['_wpinv_user_id'] = $new_user_id;
491
-                foreach ( $meta_fields as $field ) {
492
-                    $meta['_wpinv_' . $field] = isset( $postarr['wpinv_' . $field] ) ? sanitize_text_field( $postarr['wpinv_' . $field] ) : '';
491
+                foreach ($meta_fields as $field) {
492
+                    $meta['_wpinv_' . $field] = isset($postarr['wpinv_' . $field]) ? sanitize_text_field($postarr['wpinv_' . $field]) : '';
493 493
                 }
494 494
                 
495
-                $meta = apply_filters( 'wpinv_register_new_user_meta', $meta, $new_user_id );
495
+                $meta = apply_filters('wpinv_register_new_user_meta', $meta, $new_user_id);
496 496
 
497 497
                 // Update user meta.
498
-                foreach ( $meta as $key => $value ) {
499
-                    update_user_meta( $new_user_id, $key, $value );
498
+                foreach ($meta as $key => $value) {
499
+                    update_user_meta($new_user_id, $key, $value);
500 500
                 }
501 501
                 
502
-                if ( function_exists( 'wp_send_new_user_notifications' ) ) {
502
+                if (function_exists('wp_send_new_user_notifications')) {
503 503
                     // Send email notifications related to the creation of new user.
504
-                    wp_send_new_user_notifications( $new_user_id, 'user' );
504
+                    wp_send_new_user_notifications($new_user_id, 'user');
505 505
                 }
506 506
             } else {
507
-                wpinv_error_log( $new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__ );
507
+                wpinv_error_log($new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__);
508 508
             }
509 509
         }
510 510
     }
511 511
     
512 512
     return $data;
513 513
 }
514
-add_filter( 'wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2 );
514
+add_filter('wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2);
515 515
 
516
-function wpinv_show_recurring_supported_gateways( $item_ID ) {
516
+function wpinv_show_recurring_supported_gateways($item_ID) {
517 517
     $all_gateways = wpinv_get_payment_gateways();
518 518
 
519
-    if ( !empty( $all_gateways ) ) {
519
+    if (!empty($all_gateways)) {
520 520
         $gateways = array();
521 521
 
522
-        foreach ( $all_gateways as $key => $gateway ) {
523
-            if ( wpinv_gateway_support_subscription( $key ) ) {
522
+        foreach ($all_gateways as $key => $gateway) {
523
+            if (wpinv_gateway_support_subscription($key)) {
524 524
                 $gateways[] = $gateway['admin_label'];
525 525
             }
526 526
         }
527 527
 
528
-        if ( !empty( $gateways ) ) {
528
+        if (!empty($gateways)) {
529 529
             ?>
530
-            <span class="description"><?php echo wp_sprintf( __( 'Recurring payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ); ?></span>
530
+            <span class="description"><?php echo wp_sprintf(__('Recurring payments only supported by: %s', 'invoicing'), implode(', ', $gateways)); ?></span>
531 531
             <?php
532 532
         }
533 533
     }
534 534
 }
535
-add_action( 'wpinv_item_price_field', 'wpinv_show_recurring_supported_gateways', -10, 1 );
535
+add_action('wpinv_item_price_field', 'wpinv_show_recurring_supported_gateways', -10, 1);
536 536
 
537
-function wpinv_post_updated_messages( $messages ) {
537
+function wpinv_post_updated_messages($messages) {
538 538
     global $post, $post_ID;
539 539
 
540 540
     $messages['wpi_discount'] = array(
541 541
         0   => '',
542
-        1   => __( 'Discount updated.', 'invoicing' ),
543
-        2   => __( 'Custom field updated.', 'invoicing' ),
544
-        3   => __( 'Custom field deleted.', 'invoicing' ),
545
-        4   => __( 'Discount updated.', 'invoicing' ),
546
-        5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
547
-        6   => __( 'Discount updated.', 'invoicing' ),
548
-        7   => __( 'Discount saved.', 'invoicing' ),
549
-        8   => __( 'Discount submitted.', 'invoicing' ),
550
-        9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
551
-        10  => __( 'Discount draft updated.', 'invoicing' ),
542
+        1   => __('Discount updated.', 'invoicing'),
543
+        2   => __('Custom field updated.', 'invoicing'),
544
+        3   => __('Custom field deleted.', 'invoicing'),
545
+        4   => __('Discount updated.', 'invoicing'),
546
+        5   => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
547
+        6   => __('Discount updated.', 'invoicing'),
548
+        7   => __('Discount saved.', 'invoicing'),
549
+        8   => __('Discount submitted.', 'invoicing'),
550
+        9   => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
551
+        10  => __('Discount draft updated.', 'invoicing'),
552 552
     );
553 553
 
554 554
     $messages['wpi_payment_form'] = array(
555 555
         0   => '',
556
-        1   => __( 'Payment Form updated.', 'invoicing' ),
557
-        2   => __( 'Custom field updated.', 'invoicing' ),
558
-        3   => __( 'Custom field deleted.', 'invoicing' ),
559
-        4   => __( 'Payment Form updated.', 'invoicing' ),
560
-        5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
561
-        6   => __( 'Payment Form updated.', 'invoicing' ),
562
-        7   => __( 'Payment Form saved.', 'invoicing' ),
563
-        8   => __( 'Payment Form submitted.', 'invoicing' ),
564
-        9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
565
-        10  => __( 'Payment Form draft updated.', 'invoicing' ),
556
+        1   => __('Payment Form updated.', 'invoicing'),
557
+        2   => __('Custom field updated.', 'invoicing'),
558
+        3   => __('Custom field deleted.', 'invoicing'),
559
+        4   => __('Payment Form updated.', 'invoicing'),
560
+        5   => isset($_GET['revision']) ? wp_sprintf(__('Payment Form restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
561
+        6   => __('Payment Form updated.', 'invoicing'),
562
+        7   => __('Payment Form saved.', 'invoicing'),
563
+        8   => __('Payment Form submitted.', 'invoicing'),
564
+        9   => wp_sprintf(__('Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
565
+        10  => __('Payment Form draft updated.', 'invoicing'),
566 566
     );
567 567
 
568 568
     return $messages;
569 569
 }
570
-add_filter( 'post_updated_messages', 'wpinv_post_updated_messages', 10, 1 );
570
+add_filter('post_updated_messages', 'wpinv_post_updated_messages', 10, 1);
571 571
 
572 572
 add_action('admin_init', 'admin_init_example_type');
573 573
 
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
 function admin_init_example_type() {
578 578
     global $typenow;
579 579
 
580
-    if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote' ) {
580
+    if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote') {
581 581
         add_filter('posts_search', 'posts_search_example_type', 10, 2);
582 582
     }
583 583
 }
@@ -592,9 +592,9 @@  discard block
 block discarded – undo
592 592
     global $wpdb;
593 593
 
594 594
     if ($query->is_main_query() && !empty($query->query['s'])) {
595
-        $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql( $query->query['s'] ) . "%' )";
596
-        if ( ! empty( $search ) ) {
597
-            $search = preg_replace( '/^ AND /', '', $search );
595
+        $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql($query->query['s']) . "%' )";
596
+        if (!empty($search)) {
597
+            $search = preg_replace('/^ AND /', '', $search);
598 598
             $search = " AND ( {$search} OR ( {$conditions_str} ) )";
599 599
         } else {
600 600
             $search = " AND ( {$conditions_str} )";
@@ -604,9 +604,9 @@  discard block
 block discarded – undo
604 604
     return $search;
605 605
 }
606 606
 
607
-add_action( 'admin_init', 'wpinv_reset_invoice_count' );
608
-function wpinv_reset_invoice_count(){
609
-    if(isset($_GET['reset_invoice_count']) && 1 == $_GET['reset_invoice_count'] && isset($_GET['_nonce']) && wp_verify_nonce($_GET['_nonce'], 'reset_invoice_count')) {
607
+add_action('admin_init', 'wpinv_reset_invoice_count');
608
+function wpinv_reset_invoice_count() {
609
+    if (isset($_GET['reset_invoice_count']) && 1 == $_GET['reset_invoice_count'] && isset($_GET['_nonce']) && wp_verify_nonce($_GET['_nonce'], 'reset_invoice_count')) {
610 610
         wpinv_update_option('invoice_sequence_start', 1);
611 611
         delete_option('wpinv_last_invoice_number');
612 612
         $url = add_query_arg(array('reset_invoice_done' => 1));
@@ -617,8 +617,8 @@  discard block
 block discarded – undo
617 617
 }
618 618
 
619 619
 add_action('admin_notices', 'wpinv_invoice_count_reset_message');
620
-function wpinv_invoice_count_reset_message(){
621
-    if(isset($_GET['reset_invoice_done']) && 1 == $_GET['reset_invoice_done']) {
620
+function wpinv_invoice_count_reset_message() {
621
+    if (isset($_GET['reset_invoice_done']) && 1 == $_GET['reset_invoice_done']) {
622 622
         $notice = __('Invoice number sequence reset successfully.', 'invoicing');
623 623
         ?>
624 624
         <div class="notice notice-success is-dismissible">
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-mb-payment-form.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 class WPInv_Meta_Box_Payment_Form {
@@ -11,23 +11,23 @@  discard block
 block discarded – undo
11 11
      *
12 12
      * @param WP_Post $post
13 13
      */
14
-    public static function output_details( $post ) {
15
-        $details = get_post_meta( $post->ID, 'payment_form_data', true );
14
+    public static function output_details($post) {
15
+        $details = get_post_meta($post->ID, 'payment_form_data', true);
16 16
 
17
-        if ( ! is_array( $details ) ) {
17
+        if (!is_array($details)) {
18 18
             return;
19 19
         }
20 20
 
21 21
         echo '<div class="gdmbx2-wrap form-table"> <div class="gdmbx2-metabox gdmbx-field-list">';
22 22
 
23
-        foreach ( $details as $key => $value ) {
24
-            $key = sanitize_text_field( $key );
23
+        foreach ($details as $key => $value) {
24
+            $key = sanitize_text_field($key);
25 25
 
26
-            if ( is_array( $value ) ) {
27
-                $value = implode( ',', $value );
26
+            if (is_array($value)) {
27
+                $value = implode(',', $value);
28 28
             }
29 29
 
30
-            $value = esc_html( $value );
30
+            $value = esc_html($value);
31 31
 
32 32
             echo "<div class='gdmbx-row gdmbx-type-select'>";
33 33
             echo "<div class='gdmbx-th'><label>$key:</label></div>";
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
      *
44 44
      * @param WP_Post $post
45 45
      */
46
-    public static function output_shortcode( $post ) {
46
+    public static function output_shortcode($post) {
47 47
 
48
-        if ( ! is_numeric( $post ) ) {
48
+        if (!is_numeric($post)) {
49 49
             $post = $post->ID;
50 50
         }
51 51
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
      *
58 58
      * @param WP_Post $post
59 59
      */
60
-    public static function output ( $post ) {
61
-        $success_page        = get_post_meta( $post->ID, 'wpinv_success_page', true );
62
-        $success_page        = empty( $success_page ) ? wpinv_get_success_page_uri() : $success_page
60
+    public static function output($post) {
61
+        $success_page        = get_post_meta($post->ID, 'wpinv_success_page', true);
62
+        $success_page        = empty($success_page) ? wpinv_get_success_page_uri() : $success_page
63 63
         ?>
64 64
 
65 65
         <div id="wpinv-form-builder" style="display: flex; flex-flow: wrap;">
@@ -67,20 +67,20 @@  discard block
 block discarded – undo
67 67
             <div class="wpinv-form-builder-left bsui" style="flex: 0 0 320px;">
68 68
                 <ul class="wpinv-form-builder-tabs  nav nav-tabs">
69 69
                     <li class='nav-item' v-if="active_tab!='new_item'">
70
-                        <a @click.prevent="active_tab='new_item'" class="nav-link p-3" :class="{ 'active': active_tab=='new_item' }" href="#"><?php _e( 'Add new element', 'invoicing' ); ?></a>
70
+                        <a @click.prevent="active_tab='new_item'" class="nav-link p-3" :class="{ 'active': active_tab=='new_item' }" href="#"><?php _e('Add new element', 'invoicing'); ?></a>
71 71
                     </li>
72 72
                     <li class='nav-item' v-if='false'>
73
-                        <a @click.prevent="active_tab='edit_item'" class="nav-link p-3" :class="{ 'active': active_tab=='edit_item' }" href="#"><?php _e( 'Edit element', 'invoicing' ); ?></a>
73
+                        <a @click.prevent="active_tab='edit_item'" class="nav-link p-3" :class="{ 'active': active_tab=='edit_item' }" href="#"><?php _e('Edit element', 'invoicing'); ?></a>
74 74
                     </li>
75 75
                     <li class='nav-item' v-if='false'>
76
-                        <a @click.prevent="active_tab='settings'" class="nav-link p-3" :class="{ 'active': active_tab=='settings' }" href="#"><?php _e( 'Settings', 'invoicing' ); ?></a>
76
+                        <a @click.prevent="active_tab='settings'" class="nav-link p-3" :class="{ 'active': active_tab=='settings' }" href="#"><?php _e('Settings', 'invoicing'); ?></a>
77 77
                     </li>
78 78
                 </ul>
79 79
 
80 80
                 <div class="wpinv-form-builder-tab-content bsui" style="margin-top: 16px;">
81 81
                     <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='new_item'">
82 82
                         <div class="wpinv-form-builder-add-field-types">
83
-                            <small class='form-text text-muted'><?php _e( 'Add an element by dragging it to the payment form.', 'invoicing' ); ?></small>
83
+                            <small class='form-text text-muted'><?php _e('Add an element by dragging it to the payment form.', 'invoicing'); ?></small>
84 84
                             <draggable class="section mt-2" style="display: flex; flex-flow: wrap; justify-content: space-between;" v-model="elements" :group="{ name: 'fields', pull: 'clone', put: false }" :sort="false" :clone="addDraggedField" tag="ul" filter=".wpinv-undraggable">
85 85
                                 <li v-for="element in elements" class= "wpinv-payment-form-left-fields-field" @click.prevent="addField(element)" :class="{ 'd-none': element.defaults.premade }">
86 86
                                     <button class="button btn">
@@ -95,9 +95,9 @@  discard block
 block discarded – undo
95 95
 
96 96
                     <div class="wpinv-form-builder-tab-pane bsui" v-if="active_tab=='edit_item'" style="font-size: 16px;">
97 97
                         <div class="wpinv-form-builder-edit-field-wrapper">
98
-                            <?php do_action( 'wpinv_payment_form_edit_element_template', 'active_form_element', $post ); ?>
98
+                            <?php do_action('wpinv_payment_form_edit_element_template', 'active_form_element', $post); ?>
99 99
                             <div>
100
-                                <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e( 'Delete Field', 'invoicing' ); ?></button>
100
+                                <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e('Delete Field', 'invoicing'); ?></button>
101 101
                             </div>
102 102
                         </div>
103 103
                     </div>
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
                         <div class="wpinv-form-builder-settings-wrapper">
107 107
                         
108 108
                             <div class='form-group'>
109
-                                <label for="wpi-success-page"><?php _e( 'Success Page', 'invoicing' ); ?></label>
110
-                                <input  placeholder="https://" id='wpi-success-page' value="<?php echo esc_url( $success_page ); ?>" class='form-control' type='text'>
111
-                                <small class='form-text text-muted'><?php _e( 'Where should we redirect users after successfuly completing their payment?', 'invoicing' ); ?></small>
109
+                                <label for="wpi-success-page"><?php _e('Success Page', 'invoicing'); ?></label>
110
+                                <input  placeholder="https://" id='wpi-success-page' value="<?php echo esc_url($success_page); ?>" class='form-control' type='text'>
111
+                                <small class='form-text text-muted'><?php _e('Where should we redirect users after successfuly completing their payment?', 'invoicing'); ?></small>
112 112
                             </div>
113 113
 
114 114
                         </div>
@@ -119,12 +119,12 @@  discard block
 block discarded – undo
119 119
 
120 120
             <div class="wpinv-form-builder-right" style="flex: 1; padding-top: 40px;border-left: 1px solid #ddd;padding-left: 20px;min-height: 520px;margin-left: 10px;">
121 121
 
122
-                <small class='form-text text-muted' v-if='form_elements.length'><?php _e( 'Click on any element to edit or delete it.', 'invoicing' ); ?></small>
123
-                <p class='form-text text-muted' v-if='! form_elements.length'><?php _e( 'This form is empty. Add new elements by dragging them from the right.', 'invoicing' ); ?></p>
122
+                <small class='form-text text-muted' v-if='form_elements.length'><?php _e('Click on any element to edit or delete it.', 'invoicing'); ?></small>
123
+                <p class='form-text text-muted' v-if='! form_elements.length'><?php _e('This form is empty. Add new elements by dragging them from the right.', 'invoicing'); ?></p>
124 124
 
125 125
                 <draggable class="section bsui" v-model="form_elements" @add="highlightLastDroppedField" group="fields" tag="div" style="min-height: 100%; font-size: 16px;">
126 126
                     <div v-for="form_element in form_elements" class="wpinv-form-builder-element-preview" :class="{ active: active_form_element==form_element &&  active_tab=='edit_item' }" @click="active_tab = 'edit_item'; active_form_element = form_element">
127
-                        <?php do_action( 'wpinv_payment_form_render_element_template', 'form_element', $post ); ?>
127
+                        <?php do_action('wpinv_payment_form_render_element_template', 'form_element', $post); ?>
128 128
                     </div>
129 129
                 </draggable>
130 130
             </div>
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
             <textarea style="display:none;" name="wpinv_form_items" v-model="itemString"></textarea>
134 134
         </div>
135 135
         
136
-        <?php wp_nonce_field( 'wpinv_save_payment_form', 'wpinv_save_payment_form' ) ;?>
136
+        <?php wp_nonce_field('wpinv_save_payment_form', 'wpinv_save_payment_form'); ?>
137 137
 
138 138
         <?php
139 139
     }
@@ -141,83 +141,83 @@  discard block
 block discarded – undo
141 141
     /**
142 142
      * Saves our payment forms.
143 143
      */
144
-    public static function save( $post_id, $post ) {
144
+    public static function save($post_id, $post) {
145 145
 
146
-        remove_action( 'save_post', 'WPInv_Meta_Box_Payment_Form::save' );
146
+        remove_action('save_post', 'WPInv_Meta_Box_Payment_Form::save');
147 147
 
148 148
         // $post_id and $post are required.
149
-        if ( empty( $post_id ) || empty( $post ) ) {
149
+        if (empty($post_id) || empty($post)) {
150 150
             return;
151 151
         }
152 152
         
153 153
         // Ensure that this user can edit the post.
154
-        if ( ! current_user_can( 'edit_post', $post_id ) ) {
154
+        if (!current_user_can('edit_post', $post_id)) {
155 155
             return;
156 156
         }
157 157
 
158 158
         // Dont' save meta boxes for revisions or autosaves
159
-        if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
159
+        if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
160 160
             return;
161 161
         }
162 162
 
163 163
         // Do not save for ajax requests.
164
-        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
164
+        if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
165 165
             return;
166 166
         }
167 167
 
168 168
         // Confirm the security nonce.
169
-        if ( empty( $_POST['wpinv_save_payment_form'] ) || ! wp_verify_nonce( $_POST['wpinv_save_payment_form'], 'wpinv_save_payment_form' ) ) {
169
+        if (empty($_POST['wpinv_save_payment_form']) || !wp_verify_nonce($_POST['wpinv_save_payment_form'], 'wpinv_save_payment_form')) {
170 170
             return;
171 171
         }
172 172
 
173 173
         // Save form items.
174
-        $form_items = json_decode( wp_unslash( $_POST['wpinv_form_items'] ), true );
174
+        $form_items = json_decode(wp_unslash($_POST['wpinv_form_items']), true);
175 175
 
176
-        if ( empty( $form_items ) ) {
176
+        if (empty($form_items)) {
177 177
             $form_items = array();
178 178
         }
179 179
 
180
-        update_post_meta( $post_id, 'wpinv_form_items', self::maybe_save_items( $form_items ) );
180
+        update_post_meta($post_id, 'wpinv_form_items', self::maybe_save_items($form_items));
181 181
 
182 182
         // Save form elements.
183
-        $wpinv_form_elements = json_decode( wp_unslash( $_POST['wpinv_form_elements'] ), true );
184
-        if ( empty( $wpinv_form_elements ) ) {
183
+        $wpinv_form_elements = json_decode(wp_unslash($_POST['wpinv_form_elements']), true);
184
+        if (empty($wpinv_form_elements)) {
185 185
             $wpinv_form_elements = array();
186 186
         }
187 187
 
188
-        update_post_meta( $post_id, 'wpinv_form_elements', $wpinv_form_elements );
188
+        update_post_meta($post_id, 'wpinv_form_elements', $wpinv_form_elements);
189 189
     }
190 190
 
191 191
     /**
192 192
      * Saves unsaved form items.
193 193
      */
194
-    public static function maybe_save_items( $items ) {
194
+    public static function maybe_save_items($items) {
195 195
 
196 196
         $saved = array();
197 197
 
198
-        foreach( $items as $item ) {
198
+        foreach ($items as $item) {
199 199
 
200
-            if ( is_numeric( $item['id'] ) ) {
200
+            if (is_numeric($item['id'])) {
201 201
                 $saved[] = $item;
202 202
                 continue;
203 203
             }
204 204
 
205 205
             $data = array(
206
-                'post_title'   => sanitize_text_field( $item['title'] ),
207
-                'post_excerpt' => wp_kses_post( $item['description'] ),
206
+                'post_title'   => sanitize_text_field($item['title']),
207
+                'post_excerpt' => wp_kses_post($item['description']),
208 208
                 'post_status'  => 'publish',
209 209
                 'meta'         => array(
210 210
                     'type'      => 'custom',
211
-                    'price'     => wpinv_sanitize_amount( $item['price'] ),
211
+                    'price'     => wpinv_sanitize_amount($item['price']),
212 212
                     'vat_rule'  => 'digital',
213 213
                     'vat_class' => '_standard',
214 214
                 )
215 215
             );
216 216
             
217
-            $new_item  = new WPInv_Item();
218
-            $new_item->create( $data );
217
+            $new_item = new WPInv_Item();
218
+            $new_item->create($data);
219 219
     
220
-            if ( ! empty( $new_item ) ) {
220
+            if (!empty($new_item)) {
221 221
                 $item['id'] = $new_item->ID;
222 222
                 $saved[] = $item;
223 223
             }
@@ -230,5 +230,5 @@  discard block
 block discarded – undo
230 230
 
231 231
 }
232 232
 
233
-add_action( 'save_post_wpi_payment_form', 'WPInv_Meta_Box_Payment_Form::save', 10, 2 );
233
+add_action('save_post_wpi_payment_form', 'WPInv_Meta_Box_Payment_Form::save', 10, 2);
234 234
 
Please login to merge, or discard this patch.