Passed
Pull Request — master (#47)
by Kiran
04:02
created
includes/class-wpinv-invoice.php 1 patch
Spacing   +787 added lines, -787 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 final class WPInv_Invoice {
15
-    public $ID  = 0;
15
+    public $ID = 0;
16 16
     public $title;
17 17
     public $post_type;
18 18
     
@@ -65,17 +65,17 @@  discard block
 block discarded – undo
65 65
     public $full_name = '';
66 66
     public $parent_invoice = 0;
67 67
     
68
-    public function __construct( $invoice_id = false ) {
69
-        if( empty( $invoice_id ) ) {
68
+    public function __construct($invoice_id = false) {
69
+        if (empty($invoice_id)) {
70 70
             return false;
71 71
         }
72 72
 
73
-        $this->setup_invoice( $invoice_id );
73
+        $this->setup_invoice($invoice_id);
74 74
     }
75 75
 
76
-    public function get( $key ) {
77
-        if ( method_exists( $this, 'get_' . $key ) ) {
78
-            $value = call_user_func( array( $this, 'get_' . $key ) );
76
+    public function get($key) {
77
+        if (method_exists($this, 'get_' . $key)) {
78
+            $value = call_user_func(array($this, 'get_' . $key));
79 79
         } else {
80 80
             $value = $this->$key;
81 81
         }
@@ -83,51 +83,51 @@  discard block
 block discarded – undo
83 83
         return $value;
84 84
     }
85 85
 
86
-    public function set( $key, $value ) {
87
-        $ignore = array( 'items', 'cart_details', 'fees', '_ID' );
86
+    public function set($key, $value) {
87
+        $ignore = array('items', 'cart_details', 'fees', '_ID');
88 88
 
89
-        if ( $key === 'status' ) {
89
+        if ($key === 'status') {
90 90
             $this->old_status = $this->status;
91 91
         }
92 92
 
93
-        if ( ! in_array( $key, $ignore ) ) {
94
-            $this->pending[ $key ] = $value;
93
+        if (!in_array($key, $ignore)) {
94
+            $this->pending[$key] = $value;
95 95
         }
96 96
 
97
-        if( '_ID' !== $key ) {
97
+        if ('_ID' !== $key) {
98 98
             $this->$key = $value;
99 99
         }
100 100
     }
101 101
 
102
-    public function _isset( $name ) {
103
-        if ( property_exists( $this, $name) ) {
104
-            return false === empty( $this->$name );
102
+    public function _isset($name) {
103
+        if (property_exists($this, $name)) {
104
+            return false === empty($this->$name);
105 105
         } else {
106 106
             return null;
107 107
         }
108 108
     }
109 109
 
110
-    private function setup_invoice( $invoice_id ) {
110
+    private function setup_invoice($invoice_id) {
111 111
         $this->pending = array();
112 112
 
113
-        if ( empty( $invoice_id ) ) {
113
+        if (empty($invoice_id)) {
114 114
             return false;
115 115
         }
116 116
 
117
-        $invoice = get_post( $invoice_id );
117
+        $invoice = get_post($invoice_id);
118 118
 
119
-        if( !$invoice || is_wp_error( $invoice ) ) {
119
+        if (!$invoice || is_wp_error($invoice)) {
120 120
             return false;
121 121
         }
122 122
 
123
-        if( !('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type) ) {
123
+        if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) {
124 124
             return false;
125 125
         }
126 126
 
127
-        do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id );
127
+        do_action('wpinv_pre_setup_invoice', $this, $invoice_id);
128 128
         
129 129
         // Primary Identifier
130
-        $this->ID              = absint( $invoice_id );
130
+        $this->ID              = absint($invoice_id);
131 131
         $this->post_type       = $invoice->post_type;
132 132
         
133 133
         // We have a payment, get the generic payment_meta item to reduce calls to it
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
         $this->post_status     = $this->status;
140 140
         $this->mode            = $this->setup_mode();
141 141
         $this->parent_invoice  = $invoice->post_parent;
142
-        $this->post_name       = $this->setup_post_name( $invoice );
142
+        $this->post_name       = $this->setup_post_name($invoice);
143 143
         $this->status_nicename = $this->setup_status_nicename();
144 144
 
145 145
         // Items
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
         
162 162
         // User based
163 163
         $this->ip              = $this->setup_ip();
164
-        $this->user_id         = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id();
165
-        $this->email           = get_the_author_meta( 'email', $this->user_id );
164
+        $this->user_id         = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id();
165
+        $this->email           = get_the_author_meta('email', $this->user_id);
166 166
         
167 167
         $this->user_info       = $this->setup_user_info();
168 168
                 
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
         $this->company         = $this->user_info['company'];
172 172
         $this->vat_number      = $this->user_info['vat_number'];
173 173
         $this->vat_rate        = $this->user_info['vat_rate'];
174
-        $this->adddress_confirmed  = $this->user_info['adddress_confirmed'];
174
+        $this->adddress_confirmed = $this->user_info['adddress_confirmed'];
175 175
         $this->address         = $this->user_info['address'];
176 176
         $this->city            = $this->user_info['city'];
177 177
         $this->country         = $this->user_info['country'];
@@ -186,48 +186,48 @@  discard block
 block discarded – undo
186 186
         // Other Identifiers
187 187
         $this->key             = $this->setup_invoice_key();
188 188
         $this->number          = $this->setup_invoice_number();
189
-        $this->title           = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number;
189
+        $this->title           = !empty($invoice->post_title) ? $invoice->post_title : $this->number;
190 190
         
191
-        $this->full_name       = trim( $this->first_name . ' '. $this->last_name );
191
+        $this->full_name       = trim($this->first_name . ' ' . $this->last_name);
192 192
         
193 193
         // Allow extensions to add items to this object via hook
194
-        do_action( 'wpinv_setup_invoice', $this, $invoice_id );
194
+        do_action('wpinv_setup_invoice', $this, $invoice_id);
195 195
 
196 196
         return true;
197 197
     }
198 198
     
199 199
     private function setup_status_nicename() {
200
-        $all_invoice_statuses  = wpinv_get_invoice_statuses();
200
+        $all_invoice_statuses = wpinv_get_invoice_statuses();
201 201
         
202
-        $status = array_key_exists( $this->status, $all_invoice_statuses ) ? $all_invoice_statuses[$this->status] : ucfirst( $this->status );
202
+        $status = array_key_exists($this->status, $all_invoice_statuses) ? $all_invoice_statuses[$this->status] : ucfirst($this->status);
203 203
 
204 204
         return $status;
205 205
     }
206 206
     
207
-    private function setup_post_name( $post = NULL ) {
207
+    private function setup_post_name($post = NULL) {
208 208
         $post_name = '';
209 209
         
210
-        if ( !empty( $post ) ) {
211
-            if( !empty( $post->post_name ) ) {
210
+        if (!empty($post)) {
211
+            if (!empty($post->post_name)) {
212 212
                 $post_name = $post->post_name;
213
-            } else if ( !empty( $post->ID ) && !empty( $post->post_title ) ) {
214
-                $post_name = sanitize_title( $post->post_title );
213
+            } else if (!empty($post->ID) && !empty($post->post_title)) {
214
+                $post_name = sanitize_title($post->post_title);
215 215
                 
216 216
                 global $wpdb;
217
-                $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) );
217
+                $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID));
218 218
             }
219 219
         }
220 220
 
221
-        $this->post_name   = $post_name;
221
+        $this->post_name = $post_name;
222 222
     }
223 223
     
224 224
     private function setup_due_date() {
225
-        $due_date = $this->get_meta( '_wpinv_due_date' );
225
+        $due_date = $this->get_meta('_wpinv_due_date');
226 226
         
227
-        if ( empty( $due_date ) ) {
228
-            $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) );
229
-            $due_date = date_i18n( 'Y-m-d', $overdue_time );
230
-        } else if ( $due_date == 'none' ) {
227
+        if (empty($due_date)) {
228
+            $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days')));
229
+            $due_date = date_i18n('Y-m-d', $overdue_time);
230
+        } else if ($due_date == 'none') {
231 231
             $due_date = '';
232 232
         }
233 233
         
@@ -235,63 +235,63 @@  discard block
 block discarded – undo
235 235
     }
236 236
     
237 237
     private function setup_completed_date() {
238
-        $invoice = get_post( $this->ID );
238
+        $invoice = get_post($this->ID);
239 239
 
240
-        if ( 'pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) {
240
+        if ('pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) {
241 241
             return false; // This invoice was never paid
242 242
         }
243 243
 
244
-        $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date;
244
+        $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date;
245 245
 
246 246
         return $date;
247 247
     }
248 248
     
249 249
     private function setup_cart_details() {
250
-        $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array();
250
+        $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array();
251 251
         return $cart_details;
252 252
     }
253 253
     
254 254
     public function array_convert() {
255
-        return get_object_vars( $this );
255
+        return get_object_vars($this);
256 256
     }
257 257
     
258 258
     private function setup_items() {
259
-        $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array();
259
+        $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array();
260 260
         return $items;
261 261
     }
262 262
     
263 263
     private function setup_fees() {
264
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
264
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
265 265
         return $payment_fees;
266 266
     }
267 267
         
268 268
     private function setup_currency() {
269
-        $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this );
269
+        $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this);
270 270
         return $currency;
271 271
     }
272 272
     
273 273
     private function setup_discount() {
274 274
         //$discount = $this->get_meta( '_wpinv_discount', true );
275
-        $discount = (float)$this->subtotal - ( (float)$this->total - (float)$this->tax - (float)$this->fees_total );
276
-        if ( $discount < 0 ) {
275
+        $discount = (float)$this->subtotal - ((float)$this->total - (float)$this->tax - (float)$this->fees_total);
276
+        if ($discount < 0) {
277 277
             $discount = 0;
278 278
         }
279
-        $discount = wpinv_round_amount( $discount );
279
+        $discount = wpinv_round_amount($discount);
280 280
         
281 281
         return $discount;
282 282
     }
283 283
     
284 284
     private function setup_discount_code() {
285
-        $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true );
285
+        $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true);
286 286
         return $discount_code;
287 287
     }
288 288
     
289 289
     private function setup_tax() {
290
-        $tax = $this->get_meta( '_wpinv_tax', true );
290
+        $tax = $this->get_meta('_wpinv_tax', true);
291 291
 
292 292
         // We don't have tax as it's own meta and no meta was passed
293
-        if ( '' === $tax ) {            
294
-            $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0;
293
+        if ('' === $tax) {            
294
+            $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0;
295 295
         }
296 296
 
297 297
         return $tax;
@@ -301,9 +301,9 @@  discard block
 block discarded – undo
301 301
         $subtotal     = 0;
302 302
         $cart_details = $this->cart_details;
303 303
 
304
-        if ( is_array( $cart_details ) ) {
305
-            foreach ( $cart_details as $item ) {
306
-                if ( isset( $item['subtotal'] ) ) {
304
+        if (is_array($cart_details)) {
305
+            foreach ($cart_details as $item) {
306
+                if (isset($item['subtotal'])) {
307 307
                     $subtotal += $item['subtotal'];
308 308
                 }
309 309
             }
@@ -317,18 +317,18 @@  discard block
 block discarded – undo
317 317
     }
318 318
     
319 319
     private function setup_discounts() {
320
-        $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array();
320
+        $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array();
321 321
         return $discounts;
322 322
     }
323 323
     
324 324
     private function setup_total() {
325
-        $amount = $this->get_meta( '_wpinv_total', true );
325
+        $amount = $this->get_meta('_wpinv_total', true);
326 326
 
327
-        if ( empty( $amount ) && '0.00' != $amount ) {
328
-            $meta   = $this->get_meta( '_wpinv_payment_meta', true );
329
-            $meta   = maybe_unserialize( $meta );
327
+        if (empty($amount) && '0.00' != $amount) {
328
+            $meta   = $this->get_meta('_wpinv_payment_meta', true);
329
+            $meta   = maybe_unserialize($meta);
330 330
 
331
-            if ( isset( $meta['amount'] ) ) {
331
+            if (isset($meta['amount'])) {
332 332
                 $amount = $meta['amount'];
333 333
             }
334 334
         }
@@ -337,13 +337,13 @@  discard block
 block discarded – undo
337 337
     }
338 338
     
339 339
     private function setup_mode() {
340
-        return $this->get_meta( '_wpinv_mode' );
340
+        return $this->get_meta('_wpinv_mode');
341 341
     }
342 342
 
343 343
     private function setup_gateway() {
344
-        $gateway = $this->get_meta( '_wpinv_gateway' );
344
+        $gateway = $this->get_meta('_wpinv_gateway');
345 345
         
346
-        if ( empty( $gateway ) && 'publish' === $this->status ) {
346
+        if (empty($gateway) && 'publish' === $this->status) {
347 347
             $gateway = 'manual';
348 348
         }
349 349
         
@@ -351,23 +351,23 @@  discard block
 block discarded – undo
351 351
     }
352 352
     
353 353
     private function setup_gateway_title() {
354
-        $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway );
354
+        $gateway_title = wpinv_get_gateway_checkout_label($this->gateway);
355 355
         return $gateway_title;
356 356
     }
357 357
 
358 358
     private function setup_transaction_id() {
359
-        $transaction_id = $this->get_meta( '_wpinv_transaction_id' );
359
+        $transaction_id = $this->get_meta('_wpinv_transaction_id');
360 360
 
361
-        if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) {
361
+        if (empty($transaction_id) || (int)$transaction_id === (int)$this->ID) {
362 362
             $gateway        = $this->gateway;
363
-            $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID );
363
+            $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID);
364 364
         }
365 365
 
366 366
         return $transaction_id;
367 367
     }
368 368
 
369 369
     private function setup_ip() {
370
-        $ip = $this->get_meta( '_wpinv_user_ip' );
370
+        $ip = $this->get_meta('_wpinv_user_ip');
371 371
         return $ip;
372 372
     }
373 373
 
@@ -377,62 +377,62 @@  discard block
 block discarded – undo
377 377
     ///}
378 378
         
379 379
     private function setup_first_name() {
380
-        $first_name = $this->get_meta( '_wpinv_first_name' );
380
+        $first_name = $this->get_meta('_wpinv_first_name');
381 381
         return $first_name;
382 382
     }
383 383
     
384 384
     private function setup_last_name() {
385
-        $last_name = $this->get_meta( '_wpinv_last_name' );
385
+        $last_name = $this->get_meta('_wpinv_last_name');
386 386
         return $last_name;
387 387
     }
388 388
     
389 389
     private function setup_company() {
390
-        $company = $this->get_meta( '_wpinv_company' );
390
+        $company = $this->get_meta('_wpinv_company');
391 391
         return $company;
392 392
     }
393 393
     
394 394
     private function setup_vat_number() {
395
-        $vat_number = $this->get_meta( '_wpinv_vat_number' );
395
+        $vat_number = $this->get_meta('_wpinv_vat_number');
396 396
         return $vat_number;
397 397
     }
398 398
     
399 399
     private function setup_vat_rate() {
400
-        $vat_rate = $this->get_meta( '_wpinv_vat_rate' );
400
+        $vat_rate = $this->get_meta('_wpinv_vat_rate');
401 401
         return $vat_rate;
402 402
     }
403 403
     
404 404
     private function setup_adddress_confirmed() {
405
-        $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' );
405
+        $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed');
406 406
         return $adddress_confirmed;
407 407
     }
408 408
     
409 409
     private function setup_phone() {
410
-        $phone = $this->get_meta( '_wpinv_phone' );
410
+        $phone = $this->get_meta('_wpinv_phone');
411 411
         return $phone;
412 412
     }
413 413
     
414 414
     private function setup_address() {
415
-        $address = $this->get_meta( '_wpinv_address', true );
415
+        $address = $this->get_meta('_wpinv_address', true);
416 416
         return $address;
417 417
     }
418 418
     
419 419
     private function setup_city() {
420
-        $city = $this->get_meta( '_wpinv_city', true );
420
+        $city = $this->get_meta('_wpinv_city', true);
421 421
         return $city;
422 422
     }
423 423
     
424 424
     private function setup_country() {
425
-        $country = $this->get_meta( '_wpinv_country', true );
425
+        $country = $this->get_meta('_wpinv_country', true);
426 426
         return $country;
427 427
     }
428 428
     
429 429
     private function setup_state() {
430
-        $state = $this->get_meta( '_wpinv_state', true );
430
+        $state = $this->get_meta('_wpinv_state', true);
431 431
         return $state;
432 432
     }
433 433
     
434 434
     private function setup_zip() {
435
-        $zip = $this->get_meta( '_wpinv_zip', true );
435
+        $zip = $this->get_meta('_wpinv_zip', true);
436 436
         return $zip;
437 437
     }
438 438
 
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
             'user_id'        => $this->user_id,
442 442
             'first_name'     => $this->first_name,
443 443
             'last_name'      => $this->last_name,
444
-            'email'          => get_the_author_meta( 'email', $this->user_id ),
444
+            'email'          => get_the_author_meta('email', $this->user_id),
445 445
             'phone'          => $this->phone,
446 446
             'address'        => $this->address,
447 447
             'city'           => $this->city,
@@ -456,12 +456,12 @@  discard block
 block discarded – undo
456 456
         );
457 457
         
458 458
         $user_info = array();
459
-        if ( isset( $this->payment_meta['user_info'] ) ) {
460
-            $user_info = maybe_unserialize( $this->payment_meta['user_info'] );
459
+        if (isset($this->payment_meta['user_info'])) {
460
+            $user_info = maybe_unserialize($this->payment_meta['user_info']);
461 461
             
462
-            if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) {
462
+            if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) {
463 463
                 $this->user_id = $post->post_author;
464
-                $this->email = get_the_author_meta( 'email', $this->user_id );
464
+                $this->email = get_the_author_meta('email', $this->user_id);
465 465
                 
466 466
                 $user_info['user_id'] = $this->user_id;
467 467
                 $user_info['email'] = $this->email;
@@ -470,13 +470,13 @@  discard block
 block discarded – undo
470 470
             }
471 471
         }
472 472
         
473
-        $user_info    = wp_parse_args( $user_info, $defaults );
473
+        $user_info = wp_parse_args($user_info, $defaults);
474 474
         
475 475
         // Get the user, but only if it's been created
476
-        $user = get_userdata( $this->user_id );
476
+        $user = get_userdata($this->user_id);
477 477
         
478
-        if ( !empty( $user ) && $user->ID > 0 ) {
479
-            if ( empty( $user_info ) ) {
478
+        if (!empty($user) && $user->ID > 0) {
479
+            if (empty($user_info)) {
480 480
                 $user_info = array(
481 481
                     'user_id'    => $user->ID,
482 482
                     'first_name' => $user->first_name,
@@ -485,23 +485,23 @@  discard block
 block discarded – undo
485 485
                     'discount'   => '',
486 486
                 );
487 487
             } else {
488
-                foreach ( $user_info as $key => $value ) {
489
-                    if ( ! empty( $value ) ) {
488
+                foreach ($user_info as $key => $value) {
489
+                    if (!empty($value)) {
490 490
                         continue;
491 491
                     }
492 492
 
493
-                    switch( $key ) {
493
+                    switch ($key) {
494 494
                         case 'user_id':
495
-                            $user_info[ $key ] = $user->ID;
495
+                            $user_info[$key] = $user->ID;
496 496
                             break;
497 497
                         case 'first_name':
498
-                            $user_info[ $key ] = $user->first_name;
498
+                            $user_info[$key] = $user->first_name;
499 499
                             break;
500 500
                         case 'last_name':
501
-                            $user_info[ $key ] = $user->last_name;
501
+                            $user_info[$key] = $user->last_name;
502 502
                             break;
503 503
                         case 'email':
504
-                            $user_info[ $key ] = $user->user_email;
504
+                            $user_info[$key] = $user->user_email;
505 505
                             break;
506 506
                     }
507 507
                 }
@@ -512,16 +512,16 @@  discard block
 block discarded – undo
512 512
     }
513 513
 
514 514
     private function setup_invoice_key() {
515
-        $key = $this->get_meta( '_wpinv_key', true );
515
+        $key = $this->get_meta('_wpinv_key', true);
516 516
         
517 517
         return $key;
518 518
     }
519 519
 
520 520
     private function setup_invoice_number() {
521
-        $number = $this->get_meta( '_wpinv_number', true );
521
+        $number = $this->get_meta('_wpinv_number', true);
522 522
 
523
-        if ( !$number ) {
524
-            $number = wpinv_format_invoice_number( $this->ID );
523
+        if (!$number) {
524
+            $number = wpinv_format_invoice_number($this->ID);
525 525
         }
526 526
 
527 527
         return $number;
@@ -532,18 +532,18 @@  discard block
 block discarded – undo
532 532
 
533 533
         if ($number = $this->get_number()) {
534 534
             $invoice_title = $number;
535
-        } else if ( ! empty( $this->ID ) ) {
536
-            $invoice_title = wpinv_format_invoice_number( $this->ID );
535
+        } else if (!empty($this->ID)) {
536
+            $invoice_title = wpinv_format_invoice_number($this->ID);
537 537
         } else {
538
-            $invoice_title = wpinv_format_invoice_number( 0 );
538
+            $invoice_title = wpinv_format_invoice_number(0);
539 539
         }
540 540
 
541
-        if ( empty( $this->key ) ) {
541
+        if (empty($this->key)) {
542 542
             $this->key = self::generate_key();
543 543
             $this->pending['key'] = $this->key;
544 544
         }
545 545
 
546
-        if ( empty( $this->ip ) ) {
546
+        if (empty($this->ip)) {
547 547
             $this->ip = wpinv_get_ip();
548 548
             $this->pending['ip'] = $this->ip;
549 549
         }
@@ -575,75 +575,75 @@  discard block
 block discarded – undo
575 575
             'fees'         => $this->fees,
576 576
         );
577 577
         
578
-        $post_name      = sanitize_title( $invoice_title );
578
+        $post_name = sanitize_title($invoice_title);
579 579
 
580 580
         $post_data = array(
581 581
                         'post_title'    => $invoice_title,
582 582
                         'post_status'   => $this->status,
583 583
                         'post_author'   => $this->user_id,
584 584
                         'post_type'     => $this->post_type,
585
-                        'post_date'     => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ),
586
-                        'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ),
585
+                        'post_date'     => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'),
586
+                        'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1),
587 587
                         'post_parent'   => $this->parent_invoice,
588 588
                     );
589
-        $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this );
589
+        $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this);
590 590
 
591 591
         // Create a blank invoice
592
-        if ( !empty( $this->ID ) ) {
592
+        if (!empty($this->ID)) {
593 593
             $args['ID']         = $this->ID;
594 594
             $args['post_name']  = $post_name;
595 595
             
596
-            $invoice_id = wp_update_post( $args );
596
+            $invoice_id = wp_update_post($args);
597 597
         } else {
598
-            $invoice_id = wp_insert_post( $args );
598
+            $invoice_id = wp_insert_post($args);
599 599
             
600
-            $post_title = wpinv_format_invoice_number( $invoice_id );
600
+            $post_title = wpinv_format_invoice_number($invoice_id);
601 601
             global $wpdb;
602
-            $wpdb->update( $wpdb->posts, array( 'post_title' => $post_title, 'post_name' => sanitize_title( $post_title ) ), array( 'ID' => $invoice_id ) );
603
-            clean_post_cache( $invoice_id );
602
+            $wpdb->update($wpdb->posts, array('post_title' => $post_title, 'post_name' => sanitize_title($post_title)), array('ID' => $invoice_id));
603
+            clean_post_cache($invoice_id);
604 604
         }
605 605
 
606
-        if ( !empty( $invoice_id ) ) {             
606
+        if (!empty($invoice_id)) {             
607 607
             $this->ID  = $invoice_id;
608 608
             $this->_ID = $invoice_id;
609 609
             
610 610
             ///$this->pending['user_id'] = $this->user_id;
611
-            if ( isset( $this->pending['number'] ) ) {
611
+            if (isset($this->pending['number'])) {
612 612
                 $this->pending['number'] = $post_name;
613 613
             }
614 614
             
615
-            $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data );
616
-            if ( ! empty( $this->payment_meta['fees'] ) ) {
617
-                $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] );
618
-                foreach( $this->fees as $fee ) {
619
-                    $this->increase_fees( $fee['amount'] );
615
+            $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data);
616
+            if (!empty($this->payment_meta['fees'])) {
617
+                $this->fees = array_merge($this->fees, $this->payment_meta['fees']);
618
+                foreach ($this->fees as $fee) {
619
+                    $this->increase_fees($fee['amount']);
620 620
                 }
621 621
             }
622 622
 
623
-            $this->update_meta( '_wpinv_payment_meta', $this->payment_meta );            
623
+            $this->update_meta('_wpinv_payment_meta', $this->payment_meta);            
624 624
             $this->new = true;
625 625
         }
626 626
 
627 627
         return $this->ID;
628 628
     }
629 629
 
630
-    public function save( $setup = false ) {
630
+    public function save($setup = false) {
631 631
         global $wpi_session;
632 632
         
633 633
         $saved = false;
634
-        if ( empty( $this->items ) ) {
634
+        if (empty($this->items)) {
635 635
             return $saved; // Don't save empty invoice.
636 636
         }
637 637
         
638
-        if ( empty( $this->key ) ) {
638
+        if (empty($this->key)) {
639 639
             $this->key = self::generate_key();
640 640
             $this->pending['key'] = $this->key;
641 641
         }
642 642
         
643
-        if ( empty( $this->ID ) ) {
643
+        if (empty($this->ID)) {
644 644
             $invoice_id = $this->insert_invoice();
645 645
 
646
-            if ( false === $invoice_id ) {
646
+            if (false === $invoice_id) {
647 647
                 $saved = false;
648 648
             } else {
649 649
                 $this->ID = $invoice_id;
@@ -651,27 +651,27 @@  discard block
 block discarded – undo
651 651
         }        
652 652
 
653 653
         // If we have something pending, let's save it
654
-        if ( !empty( $this->pending ) ) {
654
+        if (!empty($this->pending)) {
655 655
             $total_increase = 0;
656 656
             $total_decrease = 0;
657 657
 
658
-            foreach ( $this->pending as $key => $value ) {
659
-                switch( $key ) {
658
+            foreach ($this->pending as $key => $value) {
659
+                switch ($key) {
660 660
                     case 'items':
661 661
                         // Update totals for pending items
662
-                        foreach ( $this->pending[ $key ] as $item ) {
663
-                            switch( $item['action'] ) {
662
+                        foreach ($this->pending[$key] as $item) {
663
+                            switch ($item['action']) {
664 664
                                 case 'add':
665 665
                                     $price = $item['price'];
666 666
                                     $taxes = $item['tax'];
667 667
 
668
-                                    if ( 'publish' === $this->status ) {
668
+                                    if ('publish' === $this->status) {
669 669
                                         $total_increase += $price;
670 670
                                     }
671 671
                                     break;
672 672
 
673 673
                                 case 'remove':
674
-                                    if ( 'publish' === $this->status ) {
674
+                                    if ('publish' === $this->status) {
675 675
                                         $total_decrease += $item['price'];
676 676
                                     }
677 677
                                     break;
@@ -679,16 +679,16 @@  discard block
 block discarded – undo
679 679
                         }
680 680
                         break;
681 681
                     case 'fees':
682
-                        if ( 'publish' !== $this->status ) {
682
+                        if ('publish' !== $this->status) {
683 683
                             break;
684 684
                         }
685 685
 
686
-                        if ( empty( $this->pending[ $key ] ) ) {
686
+                        if (empty($this->pending[$key])) {
687 687
                             break;
688 688
                         }
689 689
 
690
-                        foreach ( $this->pending[ $key ] as $fee ) {
691
-                            switch( $fee['action'] ) {
690
+                        foreach ($this->pending[$key] as $fee) {
691
+                            switch ($fee['action']) {
692 692
                                 case 'add':
693 693
                                     $total_increase += $fee['amount'];
694 694
                                     break;
@@ -700,86 +700,86 @@  discard block
 block discarded – undo
700 700
                         }
701 701
                         break;
702 702
                     case 'status':
703
-                        $this->update_status( $this->status );
703
+                        $this->update_status($this->status);
704 704
                         break;
705 705
                     case 'gateway':
706
-                        $this->update_meta( '_wpinv_gateway', $this->gateway );
706
+                        $this->update_meta('_wpinv_gateway', $this->gateway);
707 707
                         break;
708 708
                     case 'mode':
709
-                        $this->update_meta( '_wpinv_mode', $this->mode );
709
+                        $this->update_meta('_wpinv_mode', $this->mode);
710 710
                         break;
711 711
                     case 'transaction_id':
712
-                        $this->update_meta( '_wpinv_transaction_id', $this->transaction_id );
712
+                        $this->update_meta('_wpinv_transaction_id', $this->transaction_id);
713 713
                         break;
714 714
                     case 'ip':
715
-                        $this->update_meta( '_wpinv_user_ip', $this->ip );
715
+                        $this->update_meta('_wpinv_user_ip', $this->ip);
716 716
                         break;
717 717
                     ///case 'user_id':
718 718
                         ///$this->update_meta( '_wpinv_user_id', $this->user_id );
719 719
                         ///$this->user_info['user_id'] = $this->user_id;
720 720
                         ///break;
721 721
                     case 'first_name':
722
-                        $this->update_meta( '_wpinv_first_name', $this->first_name );
722
+                        $this->update_meta('_wpinv_first_name', $this->first_name);
723 723
                         $this->user_info['first_name'] = $this->first_name;
724 724
                         break;
725 725
                     case 'last_name':
726
-                        $this->update_meta( '_wpinv_last_name', $this->last_name );
726
+                        $this->update_meta('_wpinv_last_name', $this->last_name);
727 727
                         $this->user_info['last_name'] = $this->last_name;
728 728
                         break;
729 729
                     case 'phone':
730
-                        $this->update_meta( '_wpinv_phone', $this->phone );
730
+                        $this->update_meta('_wpinv_phone', $this->phone);
731 731
                         $this->user_info['phone'] = $this->phone;
732 732
                         break;
733 733
                     case 'address':
734
-                        $this->update_meta( '_wpinv_address', $this->address );
734
+                        $this->update_meta('_wpinv_address', $this->address);
735 735
                         $this->user_info['address'] = $this->address;
736 736
                         break;
737 737
                     case 'city':
738
-                        $this->update_meta( '_wpinv_city', $this->city );
738
+                        $this->update_meta('_wpinv_city', $this->city);
739 739
                         $this->user_info['city'] = $this->city;
740 740
                         break;
741 741
                     case 'country':
742
-                        $this->update_meta( '_wpinv_country', $this->country );
742
+                        $this->update_meta('_wpinv_country', $this->country);
743 743
                         $this->user_info['country'] = $this->country;
744 744
                         break;
745 745
                     case 'state':
746
-                        $this->update_meta( '_wpinv_state', $this->state );
746
+                        $this->update_meta('_wpinv_state', $this->state);
747 747
                         $this->user_info['state'] = $this->state;
748 748
                         break;
749 749
                     case 'zip':
750
-                        $this->update_meta( '_wpinv_zip', $this->zip );
750
+                        $this->update_meta('_wpinv_zip', $this->zip);
751 751
                         $this->user_info['zip'] = $this->zip;
752 752
                         break;
753 753
                     case 'company':
754
-                        $this->update_meta( '_wpinv_company', $this->company );
754
+                        $this->update_meta('_wpinv_company', $this->company);
755 755
                         $this->user_info['company'] = $this->company;
756 756
                         break;
757 757
                     case 'vat_number':
758
-                        $this->update_meta( '_wpinv_vat_number', $this->vat_number );
758
+                        $this->update_meta('_wpinv_vat_number', $this->vat_number);
759 759
                         $this->user_info['vat_number'] = $this->vat_number;
760 760
                         
761
-                        $vat_info = $wpi_session->get( 'user_vat_data' );
762
-                        if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) {
763
-                            $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false;
764
-                            $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed );
761
+                        $vat_info = $wpi_session->get('user_vat_data');
762
+                        if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) {
763
+                            $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
764
+                            $this->update_meta('_wpinv_adddress_confirmed', (bool)$adddress_confirmed);
765 765
                             $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed;
766 766
                         }
767 767
     
768 768
                         break;
769 769
                     case 'vat_rate':
770
-                        $this->update_meta( '_wpinv_vat_rate', $this->vat_rate );
770
+                        $this->update_meta('_wpinv_vat_rate', $this->vat_rate);
771 771
                         $this->user_info['vat_rate'] = $this->vat_rate;
772 772
                         break;
773 773
                     case 'adddress_confirmed':
774
-                        $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed );
774
+                        $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed);
775 775
                         $this->user_info['adddress_confirmed'] = $this->adddress_confirmed;
776 776
                         break;
777 777
                     
778 778
                     case 'key':
779
-                        $this->update_meta( '_wpinv_key', $this->key );
779
+                        $this->update_meta('_wpinv_key', $this->key);
780 780
                         break;
781 781
                     case 'number':
782
-                        $this->update_meta( '_wpinv_number', $this->number );
782
+                        $this->update_meta('_wpinv_number', $this->number);
783 783
                         break;
784 784
                     case 'date':
785 785
                         $args = array(
@@ -788,34 +788,34 @@  discard block
 block discarded – undo
788 788
                             'edit_date' => true,
789 789
                         );
790 790
 
791
-                        wp_update_post( $args );
791
+                        wp_update_post($args);
792 792
                         break;
793 793
                     case 'due_date':
794
-                        if ( empty( $this->due_date ) ) {
794
+                        if (empty($this->due_date)) {
795 795
                             $this->due_date = 'none';
796 796
                         }
797 797
                         
798
-                        $this->update_meta( '_wpinv_due_date', $this->due_date );
798
+                        $this->update_meta('_wpinv_due_date', $this->due_date);
799 799
                         break;
800 800
                     case 'completed_date':
801
-                        $this->update_meta( '_wpinv_completed_date', $this->completed_date );
801
+                        $this->update_meta('_wpinv_completed_date', $this->completed_date);
802 802
                         break;
803 803
                     case 'discounts':
804
-                        if ( ! is_array( $this->discounts ) ) {
805
-                            $this->discounts = explode( ',', $this->discounts );
804
+                        if (!is_array($this->discounts)) {
805
+                            $this->discounts = explode(',', $this->discounts);
806 806
                         }
807 807
 
808
-                        $this->user_info['discount'] = implode( ',', $this->discounts );
808
+                        $this->user_info['discount'] = implode(',', $this->discounts);
809 809
                         break;
810 810
                         
811 811
                     //case 'tax':
812 812
                         //$this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
813 813
                         //break;
814 814
                     case 'discount':
815
-                        $this->update_meta( '_wpinv_discount', wpinv_round_amount( $this->discount ) );
815
+                        $this->update_meta('_wpinv_discount', wpinv_round_amount($this->discount));
816 816
                         break;
817 817
                     case 'discount_code':
818
-                        $this->update_meta( '_wpinv_discount_code', $this->discount_code );
818
+                        $this->update_meta('_wpinv_discount_code', $this->discount_code);
819 819
                         break;
820 820
                     //case 'fees':
821 821
                         //$this->update_meta( '_wpinv_fees', $this->fees );
@@ -825,19 +825,19 @@  discard block
 block discarded – undo
825 825
                             'ID'          => $this->ID,
826 826
                             'post_parent' => $this->parent_invoice,
827 827
                         );
828
-                        wp_update_post( $args );
828
+                        wp_update_post($args);
829 829
                         break;
830 830
                     default:
831
-                        do_action( 'wpinv_save', $this, $key );
831
+                        do_action('wpinv_save', $this, $key);
832 832
                         break;
833 833
                 }
834 834
             }       
835 835
 
836
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
837
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
838
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
836
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
837
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
838
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
839 839
             
840
-            $this->items    = array_values( $this->items );
840
+            $this->items = array_values($this->items);
841 841
             
842 842
             $new_meta = array(
843 843
                 'items'         => $this->items,
@@ -848,12 +848,12 @@  discard block
 block discarded – undo
848 848
             );
849 849
             
850 850
             $meta        = $this->get_meta();
851
-            $merged_meta = array_merge( $meta, $new_meta );
851
+            $merged_meta = array_merge($meta, $new_meta);
852 852
 
853 853
             // Only save the payment meta if it's changed
854
-            if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) {
855
-                $updated     = $this->update_meta( '_wpinv_payment_meta', $merged_meta );
856
-                if ( false !== $updated ) {
854
+            if (md5(serialize($meta)) !== md5(serialize($merged_meta))) {
855
+                $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta);
856
+                if (false !== $updated) {
857 857
                     $saved = true;
858 858
                 }
859 859
             }
@@ -861,15 +861,15 @@  discard block
 block discarded – undo
861 861
             $this->pending = array();
862 862
             $saved         = true;
863 863
         } else {
864
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
865
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
866
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
864
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
865
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
866
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
867 867
         }
868 868
         
869
-        do_action( 'wpinv_invoice_save', $this, $saved );
869
+        do_action('wpinv_invoice_save', $this, $saved);
870 870
 
871
-        if ( true === $saved || $setup ) {
872
-            $this->setup_invoice( $this->ID );
871
+        if (true === $saved || $setup) {
872
+            $this->setup_invoice($this->ID);
873 873
         }
874 874
         
875 875
         $this->refresh_item_ids();
@@ -877,7 +877,7 @@  discard block
 block discarded – undo
877 877
         return $saved;
878 878
     }
879 879
     
880
-    public function add_fee( $args, $global = true ) {
880
+    public function add_fee($args, $global = true) {
881 881
         $default_args = array(
882 882
             'label'       => '',
883 883
             'amount'      => 0,
@@ -887,75 +887,75 @@  discard block
 block discarded – undo
887 887
             'item_id'     => 0,
888 888
         );
889 889
 
890
-        $fee = wp_parse_args( $args, $default_args );
890
+        $fee = wp_parse_args($args, $default_args);
891 891
         
892
-        if ( !empty( $fee['label'] ) ) {
892
+        if (!empty($fee['label'])) {
893 893
             return false;
894 894
         }
895 895
         
896
-        $fee['id']  = sanitize_title( $fee['label'] );
896
+        $fee['id'] = sanitize_title($fee['label']);
897 897
         
898
-        $this->fees[]               = $fee;
898
+        $this->fees[] = $fee;
899 899
         
900 900
         $added_fee               = $fee;
901 901
         $added_fee['action']     = 'add';
902 902
         $this->pending['fees'][] = $added_fee;
903
-        reset( $this->fees );
903
+        reset($this->fees);
904 904
 
905
-        $this->increase_fees( $fee['amount'] );
905
+        $this->increase_fees($fee['amount']);
906 906
         return true;
907 907
     }
908 908
 
909
-    public function remove_fee( $key ) {
909
+    public function remove_fee($key) {
910 910
         $removed = false;
911 911
 
912
-        if ( is_numeric( $key ) ) {
913
-            $removed = $this->remove_fee_by( 'index', $key );
912
+        if (is_numeric($key)) {
913
+            $removed = $this->remove_fee_by('index', $key);
914 914
         }
915 915
 
916 916
         return $removed;
917 917
     }
918 918
 
919
-    public function remove_fee_by( $key, $value, $global = false ) {
920
-        $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array(
919
+    public function remove_fee_by($key, $value, $global = false) {
920
+        $allowed_fee_keys = apply_filters('wpinv_fee_keys', array(
921 921
             'index', 'label', 'amount', 'type',
922
-        ) );
922
+        ));
923 923
 
924
-        if ( ! in_array( $key, $allowed_fee_keys ) ) {
924
+        if (!in_array($key, $allowed_fee_keys)) {
925 925
             return false;
926 926
         }
927 927
 
928 928
         $removed = false;
929
-        if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) {
930
-            $removed_fee             = $this->fees[ $value ];
929
+        if ('index' === $key && array_key_exists($value, $this->fees)) {
930
+            $removed_fee             = $this->fees[$value];
931 931
             $removed_fee['action']   = 'remove';
932 932
             $this->pending['fees'][] = $removed_fee;
933 933
 
934
-            $this->decrease_fees( $removed_fee['amount'] );
934
+            $this->decrease_fees($removed_fee['amount']);
935 935
 
936
-            unset( $this->fees[ $value ] );
936
+            unset($this->fees[$value]);
937 937
             $removed = true;
938
-        } else if ( 'index' !== $key ) {
939
-            foreach ( $this->fees as $index => $fee ) {
940
-                if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) {
938
+        } else if ('index' !== $key) {
939
+            foreach ($this->fees as $index => $fee) {
940
+                if (isset($fee[$key]) && $fee[$key] == $value) {
941 941
                     $removed_fee             = $fee;
942 942
                     $removed_fee['action']   = 'remove';
943 943
                     $this->pending['fees'][] = $removed_fee;
944 944
 
945
-                    $this->decrease_fees( $removed_fee['amount'] );
945
+                    $this->decrease_fees($removed_fee['amount']);
946 946
 
947
-                    unset( $this->fees[ $index ] );
947
+                    unset($this->fees[$index]);
948 948
                     $removed = true;
949 949
 
950
-                    if ( false === $global ) {
950
+                    if (false === $global) {
951 951
                         break;
952 952
                     }
953 953
                 }
954 954
             }
955 955
         }
956 956
 
957
-        if ( true === $removed ) {
958
-            $this->fees = array_values( $this->fees );
957
+        if (true === $removed) {
958
+            $this->fees = array_values($this->fees);
959 959
         }
960 960
 
961 961
         return $removed;
@@ -963,35 +963,35 @@  discard block
 block discarded – undo
963 963
 
964 964
     
965 965
 
966
-    public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
966
+    public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) {
967 967
         // Bail if no note specified
968
-        if( !$note ) {
968
+        if (!$note) {
969 969
             return false;
970 970
         }
971 971
 
972
-        if ( empty( $this->ID ) )
972
+        if (empty($this->ID))
973 973
             return false;
974 974
         
975
-        if ( ( ( is_user_logged_in() && current_user_can( 'manage_options' ) ) || $added_by_user ) && !$system ) {
976
-            $user                 = get_user_by( 'id', get_current_user_id() );
975
+        if (((is_user_logged_in() && current_user_can('manage_options')) || $added_by_user) && !$system) {
976
+            $user                 = get_user_by('id', get_current_user_id());
977 977
             $comment_author       = $user->display_name;
978 978
             $comment_author_email = $user->user_email;
979 979
         } else {
980
-            $comment_author       = __( 'System', 'invoicing' );
981
-            $comment_author_email = strtolower( __( 'System', 'invoicing' ) ) . '@';
982
-            $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com';
983
-            $comment_author_email = sanitize_email( $comment_author_email );
980
+            $comment_author       = __('System', 'invoicing');
981
+            $comment_author_email = strtolower(__('System', 'invoicing')) . '@';
982
+            $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com';
983
+            $comment_author_email = sanitize_email($comment_author_email);
984 984
         }
985 985
 
986
-        do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type );
986
+        do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type);
987 987
 
988
-        $note_id = wp_insert_comment( wp_filter_comment( array(
988
+        $note_id = wp_insert_comment(wp_filter_comment(array(
989 989
             'comment_post_ID'      => $this->ID,
990 990
             'comment_content'      => $note,
991 991
             'comment_agent'        => 'GeoDirectory',
992 992
             'user_id'              => is_admin() ? get_current_user_id() : 0,
993
-            'comment_date'         => current_time( 'mysql' ),
994
-            'comment_date_gmt'     => current_time( 'mysql', 1 ),
993
+            'comment_date'         => current_time('mysql'),
994
+            'comment_date_gmt'     => current_time('mysql', 1),
995 995
             'comment_approved'     => 1,
996 996
             'comment_parent'       => 0,
997 997
             'comment_author'       => $comment_author,
@@ -999,53 +999,53 @@  discard block
 block discarded – undo
999 999
             'comment_author_url'   => '',
1000 1000
             'comment_author_email' => $comment_author_email,
1001 1001
             'comment_type'         => 'wpinv_note'
1002
-        ) ) );
1002
+        )));
1003 1003
 
1004
-        do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note );
1004
+        do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note);
1005 1005
         
1006
-        if ( $customer_type ) {
1007
-            add_comment_meta( $note_id, '_wpi_customer_note', 1 );
1006
+        if ($customer_type) {
1007
+            add_comment_meta($note_id, '_wpi_customer_note', 1);
1008 1008
 
1009
-            do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) );
1009
+            do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note));
1010 1010
         }
1011 1011
 
1012 1012
         return $note_id;
1013 1013
     }
1014 1014
 
1015
-    private function increase_subtotal( $amount = 0.00 ) {
1016
-        $amount          = (float) $amount;
1015
+    private function increase_subtotal($amount = 0.00) {
1016
+        $amount          = (float)$amount;
1017 1017
         $this->subtotal += $amount;
1018
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1018
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1019 1019
 
1020 1020
         $this->recalculate_total();
1021 1021
     }
1022 1022
 
1023
-    private function decrease_subtotal( $amount = 0.00 ) {
1024
-        $amount          = (float) $amount;
1023
+    private function decrease_subtotal($amount = 0.00) {
1024
+        $amount          = (float)$amount;
1025 1025
         $this->subtotal -= $amount;
1026
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1026
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1027 1027
 
1028
-        if ( $this->subtotal < 0 ) {
1028
+        if ($this->subtotal < 0) {
1029 1029
             $this->subtotal = 0;
1030 1030
         }
1031 1031
 
1032 1032
         $this->recalculate_total();
1033 1033
     }
1034 1034
 
1035
-    private function increase_fees( $amount = 0.00 ) {
1035
+    private function increase_fees($amount = 0.00) {
1036 1036
         $amount            = (float)$amount;
1037 1037
         $this->fees_total += $amount;
1038
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1038
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1039 1039
 
1040 1040
         $this->recalculate_total();
1041 1041
     }
1042 1042
 
1043
-    private function decrease_fees( $amount = 0.00 ) {
1044
-        $amount            = (float) $amount;
1043
+    private function decrease_fees($amount = 0.00) {
1044
+        $amount            = (float)$amount;
1045 1045
         $this->fees_total -= $amount;
1046
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1046
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1047 1047
 
1048
-        if ( $this->fees_total < 0 ) {
1048
+        if ($this->fees_total < 0) {
1049 1049
             $this->fees_total = 0;
1050 1050
         }
1051 1051
 
@@ -1056,54 +1056,54 @@  discard block
 block discarded – undo
1056 1056
         global $wpi_nosave;
1057 1057
         
1058 1058
         $this->total = $this->subtotal + $this->tax + $this->fees_total;
1059
-        $this->total = wpinv_round_amount( $this->total );
1059
+        $this->total = wpinv_round_amount($this->total);
1060 1060
         
1061
-        do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave );
1061
+        do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave);
1062 1062
     }
1063 1063
     
1064
-    public function increase_tax( $amount = 0.00 ) {
1065
-        $amount       = (float) $amount;
1064
+    public function increase_tax($amount = 0.00) {
1065
+        $amount       = (float)$amount;
1066 1066
         $this->tax   += $amount;
1067 1067
 
1068 1068
         $this->recalculate_total();
1069 1069
     }
1070 1070
 
1071
-    public function decrease_tax( $amount = 0.00 ) {
1072
-        $amount     = (float) $amount;
1071
+    public function decrease_tax($amount = 0.00) {
1072
+        $amount     = (float)$amount;
1073 1073
         $this->tax -= $amount;
1074 1074
 
1075
-        if ( $this->tax < 0 ) {
1075
+        if ($this->tax < 0) {
1076 1076
             $this->tax = 0;
1077 1077
         }
1078 1078
 
1079 1079
         $this->recalculate_total();
1080 1080
     }
1081 1081
 
1082
-    public function update_status( $new_status = false, $note = '', $manual = false ) {
1083
-        $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID );
1082
+    public function update_status($new_status = false, $note = '', $manual = false) {
1083
+        $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID);
1084 1084
         
1085
-        if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses() ) ) ) {
1085
+        if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses()))) {
1086 1086
             return false; // Don't permit status changes that aren't changes
1087 1087
         }
1088 1088
 
1089
-        $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status );
1089
+        $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status);
1090 1090
         $updated = false;
1091 1091
 
1092
-        if ( $do_change ) {
1093
-            do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status );
1092
+        if ($do_change) {
1093
+            do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status);
1094 1094
 
1095 1095
             $update_post_data                   = array();
1096 1096
             $update_post_data['ID']             = $this->ID;
1097 1097
             $update_post_data['post_status']    = $new_status;
1098
-            $update_post_data['edit_date']      = current_time( 'mysql', 0 );
1099
-            $update_post_data['edit_date_gmt']  = current_time( 'mysql', 1 );
1098
+            $update_post_data['edit_date']      = current_time('mysql', 0);
1099
+            $update_post_data['edit_date_gmt']  = current_time('mysql', 1);
1100 1100
             
1101
-            $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID );
1101
+            $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID);
1102 1102
 
1103
-            $updated = wp_update_post( $update_post_data );     
1103
+            $updated = wp_update_post($update_post_data);     
1104 1104
            
1105 1105
             // Process any specific status functions
1106
-            switch( $new_status ) {
1106
+            switch ($new_status) {
1107 1107
                 case 'wpi-refunded':
1108 1108
                     $this->process_refund();
1109 1109
                     break;
@@ -1116,9 +1116,9 @@  discard block
 block discarded – undo
1116 1116
             }
1117 1117
             
1118 1118
             // Status was changed.
1119
-            do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status );
1120
-            do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status );
1121
-            do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status );
1119
+            do_action('wpinv_status_' . $new_status, $this->ID, $old_status);
1120
+            do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status);
1121
+            do_action('wpinv_update_status', $this->ID, $new_status, $old_status);
1122 1122
         }
1123 1123
 
1124 1124
         return $updated;
@@ -1132,72 +1132,72 @@  discard block
 block discarded – undo
1132 1132
         $this->save();
1133 1133
     }
1134 1134
 
1135
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
1136
-        if ( empty( $meta_key ) ) {
1135
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
1136
+        if (empty($meta_key)) {
1137 1137
             return false;
1138 1138
         }
1139 1139
 
1140
-        if ( $meta_key == 'key' || $meta_key == 'date' ) {
1140
+        if ($meta_key == 'key' || $meta_key == 'date') {
1141 1141
             $current_meta = $this->get_meta();
1142
-            $current_meta[ $meta_key ] = $meta_value;
1142
+            $current_meta[$meta_key] = $meta_value;
1143 1143
 
1144 1144
             $meta_key     = '_wpinv_payment_meta';
1145 1145
             $meta_value   = $current_meta;
1146 1146
         }
1147 1147
 
1148
-        $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID );
1148
+        $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID);
1149 1149
         
1150
-        if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) {
1150
+        if ($meta_key == '_wpinv_completed_date' && !empty($meta_value)) {
1151 1151
             $args = array(
1152 1152
                 'ID'                => $this->ID,
1153 1153
                 'post_date'         => $meta_value,
1154 1154
                 'edit_date'         => true,
1155
-                'post_date_gmt'     => get_gmt_from_date( $meta_value ),
1155
+                'post_date_gmt'     => get_gmt_from_date($meta_value),
1156 1156
                 'post_modified'     => $meta_value,
1157
-                'post_modified_gmt' => get_gmt_from_date( $meta_value )
1157
+                'post_modified_gmt' => get_gmt_from_date($meta_value)
1158 1158
             );
1159
-            wp_update_post( $args );
1159
+            wp_update_post($args);
1160 1160
         }
1161 1161
         
1162
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
1162
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
1163 1163
     }
1164 1164
 
1165 1165
     private function process_refund() {
1166 1166
         $process_refund = true;
1167 1167
 
1168 1168
         // If the payment was not in publish, don't decrement stats as they were never incremented
1169
-        if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) {
1169
+        if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) {
1170 1170
             $process_refund = false;
1171 1171
         }
1172 1172
 
1173 1173
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1174
-        $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this );
1174
+        $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this);
1175 1175
 
1176
-        if ( false === $process_refund ) {
1176
+        if (false === $process_refund) {
1177 1177
             return;
1178 1178
         }
1179 1179
 
1180
-        do_action( 'wpinv_pre_refund_invoice', $this );
1180
+        do_action('wpinv_pre_refund_invoice', $this);
1181 1181
         
1182
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this );
1183
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this );
1184
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this );
1182
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this);
1183
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this);
1184
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this);
1185 1185
         
1186
-        do_action( 'wpinv_post_refund_invoice', $this );
1186
+        do_action('wpinv_post_refund_invoice', $this);
1187 1187
     }
1188 1188
 
1189 1189
     private function process_failure() {
1190 1190
         $discounts = $this->discounts;
1191
-        if ( empty( $discounts ) ) {
1191
+        if (empty($discounts)) {
1192 1192
             return;
1193 1193
         }
1194 1194
 
1195
-        if ( ! is_array( $discounts ) ) {
1196
-            $discounts = array_map( 'trim', explode( ',', $discounts ) );
1195
+        if (!is_array($discounts)) {
1196
+            $discounts = array_map('trim', explode(',', $discounts));
1197 1197
         }
1198 1198
 
1199
-        foreach ( $discounts as $discount ) {
1200
-            wpinv_decrease_discount_usage( $discount );
1199
+        foreach ($discounts as $discount) {
1200
+            wpinv_decrease_discount_usage($discount);
1201 1201
         }
1202 1202
     }
1203 1203
     
@@ -1205,92 +1205,92 @@  discard block
 block discarded – undo
1205 1205
         $process_pending = true;
1206 1206
 
1207 1207
         // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented
1208
-        if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'pending' != $this->status ) {
1208
+        if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'pending' != $this->status) {
1209 1209
             $process_pending = false;
1210 1210
         }
1211 1211
 
1212 1212
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1213
-        $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this );
1213
+        $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this);
1214 1214
 
1215
-        if ( false === $process_pending ) {
1215
+        if (false === $process_pending) {
1216 1216
             return;
1217 1217
         }
1218 1218
 
1219
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this );
1220
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this );
1221
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this );
1219
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this);
1220
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this);
1221
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this);
1222 1222
 
1223 1223
         $this->completed_date = '';
1224
-        $this->update_meta( '_wpinv_completed_date', '' );
1224
+        $this->update_meta('_wpinv_completed_date', '');
1225 1225
     }
1226 1226
     
1227 1227
     // get data
1228
-    public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) {
1229
-        $meta = get_post_meta( $this->ID, $meta_key, $single );
1228
+    public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) {
1229
+        $meta = get_post_meta($this->ID, $meta_key, $single);
1230 1230
 
1231
-        if ( $meta_key === '_wpinv_payment_meta' ) {
1231
+        if ($meta_key === '_wpinv_payment_meta') {
1232 1232
 
1233
-            if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is.
1233
+            if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is.
1234 1234
 
1235
-            if ( empty( $meta['key'] ) ) {
1235
+            if (empty($meta['key'])) {
1236 1236
                 $meta['key'] = $this->setup_invoice_key();
1237 1237
             }
1238 1238
 
1239
-            if ( empty( $meta['date'] ) ) {
1240
-                $meta['date'] = get_post_field( 'post_date', $this->ID );
1239
+            if (empty($meta['date'])) {
1240
+                $meta['date'] = get_post_field('post_date', $this->ID);
1241 1241
             }
1242 1242
         }
1243 1243
 
1244
-        $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID );
1244
+        $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID);
1245 1245
 
1246
-        return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key );
1246
+        return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key);
1247 1247
     }
1248 1248
     
1249 1249
     public function get_description() {
1250
-        $post = get_post( $this->ID );
1250
+        $post = get_post($this->ID);
1251 1251
         
1252
-        $description = !empty( $post ) ? $post->post_content : '';
1253
-        return apply_filters( 'wpinv_get_description', $description, $this->ID, $this );
1252
+        $description = !empty($post) ? $post->post_content : '';
1253
+        return apply_filters('wpinv_get_description', $description, $this->ID, $this);
1254 1254
     }
1255 1255
     
1256
-    public function get_status( $nicename = false ) {
1257
-        if ( !$nicename ) {
1256
+    public function get_status($nicename = false) {
1257
+        if (!$nicename) {
1258 1258
             $status = $this->status;
1259 1259
         } else {
1260 1260
             $status = $this->status_nicename;
1261 1261
         }
1262 1262
         
1263
-        return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this );
1263
+        return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this);
1264 1264
     }
1265 1265
     
1266 1266
     public function get_cart_details() {
1267
-        return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this );
1267
+        return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this);
1268 1268
     }
1269 1269
     
1270
-    public function get_subtotal( $currency = false ) {
1271
-        $subtotal = wpinv_round_amount( $this->subtotal );
1270
+    public function get_subtotal($currency = false) {
1271
+        $subtotal = wpinv_round_amount($this->subtotal);
1272 1272
         
1273
-        if ( $currency ) {
1274
-            $subtotal = wpinv_price( wpinv_format_amount( $subtotal, NULL, !$currency ), $this->get_currency() );
1273
+        if ($currency) {
1274
+            $subtotal = wpinv_price(wpinv_format_amount($subtotal, NULL, !$currency), $this->get_currency());
1275 1275
         }
1276 1276
         
1277
-        return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency );
1277
+        return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency);
1278 1278
     }
1279 1279
     
1280
-    public function get_total( $currency = false ) {        
1281
-        if ( $this->is_free_trial() ) {
1282
-            $total = wpinv_round_amount( 0 );
1280
+    public function get_total($currency = false) {        
1281
+        if ($this->is_free_trial()) {
1282
+            $total = wpinv_round_amount(0);
1283 1283
         } else {
1284
-            $total = wpinv_round_amount( $this->total );
1284
+            $total = wpinv_round_amount($this->total);
1285 1285
         }
1286
-        if ( $currency ) {
1287
-            $total = wpinv_price( wpinv_format_amount( $total, NULL, !$currency ), $this->get_currency() );
1286
+        if ($currency) {
1287
+            $total = wpinv_price(wpinv_format_amount($total, NULL, !$currency), $this->get_currency());
1288 1288
         }
1289 1289
         
1290
-        return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency );
1290
+        return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency);
1291 1291
     }
1292 1292
     
1293
-    public function get_recurring_details( $field = '', $currency = false ) {        
1293
+    public function get_recurring_details($field = '', $currency = false) {        
1294 1294
         $data                 = array();
1295 1295
         $data['cart_details'] = $this->cart_details;
1296 1296
         $data['subtotal']     = $this->get_subtotal();
@@ -1298,45 +1298,45 @@  discard block
 block discarded – undo
1298 1298
         $data['tax']          = $this->get_tax();
1299 1299
         $data['total']        = $this->get_total();
1300 1300
     
1301
-        if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) {
1301
+        if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) {
1302 1302
             $is_free_trial = $this->is_free_trial();
1303
-            $discounts = $this->get_discounts( true );
1303
+            $discounts = $this->get_discounts(true);
1304 1304
             
1305
-            if ( $is_free_trial || !empty( $discounts ) ) {
1305
+            if ($is_free_trial || !empty($discounts)) {
1306 1306
                 $first_use_only = false;
1307 1307
                 
1308
-                if ( !empty( $discounts ) ) {
1309
-                    foreach ( $discounts as $key => $code ) {
1310
-                        if ( wpinv_discount_is_recurring( $code, true ) ) {
1308
+                if (!empty($discounts)) {
1309
+                    foreach ($discounts as $key => $code) {
1310
+                        if (wpinv_discount_is_recurring($code, true)) {
1311 1311
                             $first_use_only = true;
1312 1312
                             break;
1313 1313
                         }
1314 1314
                     }
1315 1315
                 }
1316 1316
                     
1317
-                if ( !$first_use_only ) {
1318
-                    $data['subtotal'] = wpinv_round_amount( $this->subtotal );
1319
-                    $data['discount'] = wpinv_round_amount( $this->discount );
1320
-                    $data['tax']      = wpinv_round_amount( $this->tax );
1321
-                    $data['total']    = wpinv_round_amount( $this->total );
1317
+                if (!$first_use_only) {
1318
+                    $data['subtotal'] = wpinv_round_amount($this->subtotal);
1319
+                    $data['discount'] = wpinv_round_amount($this->discount);
1320
+                    $data['tax']      = wpinv_round_amount($this->tax);
1321
+                    $data['total']    = wpinv_round_amount($this->total);
1322 1322
                 } else {
1323 1323
                     $cart_subtotal   = 0;
1324 1324
                     $cart_discount   = 0;
1325 1325
                     $cart_tax        = 0;
1326 1326
 
1327
-                    foreach ( $this->cart_details as $key => $item ) {
1328
-                        $item_quantity  = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1329
-                        $item_subtotal  = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1327
+                    foreach ($this->cart_details as $key => $item) {
1328
+                        $item_quantity  = $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1329
+                        $item_subtotal  = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1330 1330
                         $item_discount  = 0;
1331
-                        $item_tax       = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0;
1331
+                        $item_tax       = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float)$item['vat_rate']) : 0;
1332 1332
                         
1333
-                        if ( wpinv_prices_include_tax() ) {
1334
-                            $item_subtotal -= wpinv_round_amount( $item_tax );
1333
+                        if (wpinv_prices_include_tax()) {
1334
+                            $item_subtotal -= wpinv_round_amount($item_tax);
1335 1335
                         }
1336 1336
                         
1337 1337
                         $item_total     = $item_subtotal - $item_discount + $item_tax;
1338 1338
                         // Do not allow totals to go negative
1339
-                        if ( $item_total < 0 ) {
1339
+                        if ($item_total < 0) {
1340 1340
                             $item_total = 0;
1341 1341
                         }
1342 1342
                         
@@ -1344,107 +1344,107 @@  discard block
 block discarded – undo
1344 1344
                         $cart_discount  += (float)($item_discount);
1345 1345
                         $cart_tax       += (float)($item_tax);
1346 1346
                         
1347
-                        $data['cart_details'][$key]['discount']   = wpinv_round_amount( $item_discount );
1348
-                        $data['cart_details'][$key]['tax']        = wpinv_round_amount( $item_tax );
1349
-                        $data['cart_details'][$key]['price']      = wpinv_round_amount( $item_total );
1347
+                        $data['cart_details'][$key]['discount']   = wpinv_round_amount($item_discount);
1348
+                        $data['cart_details'][$key]['tax']        = wpinv_round_amount($item_tax);
1349
+                        $data['cart_details'][$key]['price']      = wpinv_round_amount($item_total);
1350 1350
                     }
1351 1351
                     
1352
-                    $data['subtotal'] = wpinv_round_amount( $cart_subtotal );
1353
-                    $data['discount'] = wpinv_round_amount( $cart_discount );
1354
-                    $data['tax']      = wpinv_round_amount( $cart_tax );
1355
-                    $data['total']    = wpinv_round_amount( $data['subtotal'] + $data['tax'] );
1352
+                    $data['subtotal'] = wpinv_round_amount($cart_subtotal);
1353
+                    $data['discount'] = wpinv_round_amount($cart_discount);
1354
+                    $data['tax']      = wpinv_round_amount($cart_tax);
1355
+                    $data['total']    = wpinv_round_amount($data['subtotal'] + $data['tax']);
1356 1356
                 }
1357 1357
             }
1358 1358
         }
1359 1359
         
1360
-        $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency );
1360
+        $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency);
1361 1361
 
1362
-        if ( isset( $data[$field] ) ) {
1363
-            return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
1362
+        if (isset($data[$field])) {
1363
+            return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]);
1364 1364
         }
1365 1365
         
1366 1366
         return $data;
1367 1367
     }
1368 1368
     
1369
-    public function get_final_tax( $currency = false ) {        
1370
-        $final_total = wpinv_round_amount( $this->tax );
1371
-        if ( $currency ) {
1372
-            $final_total = wpinv_price( wpinv_format_amount( $final_total, NULL, !$currency ), $this->get_currency() );
1369
+    public function get_final_tax($currency = false) {        
1370
+        $final_total = wpinv_round_amount($this->tax);
1371
+        if ($currency) {
1372
+            $final_total = wpinv_price(wpinv_format_amount($final_total, NULL, !$currency), $this->get_currency());
1373 1373
         }
1374 1374
         
1375
-        return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency );
1375
+        return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency);
1376 1376
     }
1377 1377
     
1378
-    public function get_discounts( $array = false ) {
1378
+    public function get_discounts($array = false) {
1379 1379
         $discounts = $this->discounts;
1380
-        if ( $array && $discounts ) {
1381
-            $discounts = explode( ',', $discounts );
1380
+        if ($array && $discounts) {
1381
+            $discounts = explode(',', $discounts);
1382 1382
         }
1383
-        return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array );
1383
+        return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array);
1384 1384
     }
1385 1385
     
1386
-    public function get_discount( $currency = false, $dash = false ) {
1387
-        if ( !empty( $this->discounts ) ) {
1386
+    public function get_discount($currency = false, $dash = false) {
1387
+        if (!empty($this->discounts)) {
1388 1388
             global $ajax_cart_details;
1389 1389
             $ajax_cart_details = $this->get_cart_details();
1390 1390
 
1391
-            $this->discount = wpinv_get_cart_items_discount_amount( $this->items , $this->discounts );
1391
+            $this->discount = wpinv_get_cart_items_discount_amount($this->items, $this->discounts);
1392 1392
         }
1393
-        $discount   = wpinv_round_amount( $this->discount );
1393
+        $discount   = wpinv_round_amount($this->discount);
1394 1394
         $dash       = $dash && $discount > 0 ? '&ndash;' : '';
1395 1395
         
1396
-        if ( $currency ) {
1397
-            $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() );
1396
+        if ($currency) {
1397
+            $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency());
1398 1398
         }
1399 1399
         
1400
-        $discount   = $dash . $discount;
1400
+        $discount = $dash . $discount;
1401 1401
         
1402
-        return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash );
1402
+        return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash);
1403 1403
     }
1404 1404
     
1405 1405
     public function get_discount_code() {
1406 1406
         return $this->discount_code;
1407 1407
     }
1408 1408
     
1409
-    public function get_tax( $currency = false ) {
1410
-        $tax = wpinv_round_amount( $this->tax );
1409
+    public function get_tax($currency = false) {
1410
+        $tax = wpinv_round_amount($this->tax);
1411 1411
         
1412
-        if ( $currency ) {
1413
-            $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() );
1412
+        if ($currency) {
1413
+            $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency());
1414 1414
         }
1415 1415
         
1416
-        return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency );
1416
+        return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency);
1417 1417
     }
1418 1418
     
1419
-    public function get_fees( $type = 'all' ) {
1420
-        $fees    = array();
1419
+    public function get_fees($type = 'all') {
1420
+        $fees = array();
1421 1421
 
1422
-        if ( ! empty( $this->fees ) && is_array( $this->fees ) ) {
1423
-            foreach ( $this->fees as $fee ) {
1424
-                if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) {
1422
+        if (!empty($this->fees) && is_array($this->fees)) {
1423
+            foreach ($this->fees as $fee) {
1424
+                if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) {
1425 1425
                     continue;
1426 1426
                 }
1427 1427
 
1428
-                $fee['label'] = stripslashes( $fee['label'] );
1429
-                $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() );
1430
-                $fees[]    = $fee;
1428
+                $fee['label'] = stripslashes($fee['label']);
1429
+                $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency());
1430
+                $fees[] = $fee;
1431 1431
             }
1432 1432
         }
1433 1433
 
1434
-        return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this );
1434
+        return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this);
1435 1435
     }
1436 1436
     
1437
-    public function get_fees_total( $type = 'all' ) {
1438
-        $fees_total = (float) 0.00;
1437
+    public function get_fees_total($type = 'all') {
1438
+        $fees_total = (float)0.00;
1439 1439
 
1440
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
1441
-        if ( ! empty( $payment_fees ) ) {
1442
-            foreach ( $payment_fees as $fee ) {
1443
-                $fees_total += (float) $fee['amount'];
1440
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
1441
+        if (!empty($payment_fees)) {
1442
+            foreach ($payment_fees as $fee) {
1443
+                $fees_total += (float)$fee['amount'];
1444 1444
             }
1445 1445
         }
1446 1446
 
1447
-        return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this );
1447
+        return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this);
1448 1448
         /*
1449 1449
         $fees = $this->get_fees( $type );
1450 1450
 
@@ -1464,116 +1464,116 @@  discard block
 block discarded – undo
1464 1464
     }
1465 1465
 
1466 1466
     public function get_user_id() {
1467
-        return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this );
1467
+        return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this);
1468 1468
     }
1469 1469
     
1470 1470
     public function get_first_name() {
1471
-        return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this );
1471
+        return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this);
1472 1472
     }
1473 1473
     
1474 1474
     public function get_last_name() {
1475
-        return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this );
1475
+        return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this);
1476 1476
     }
1477 1477
     
1478 1478
     public function get_user_full_name() {
1479
-        return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this );
1479
+        return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this);
1480 1480
     }
1481 1481
     
1482 1482
     public function get_user_info() {
1483
-        return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this );
1483
+        return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this);
1484 1484
     }
1485 1485
     
1486 1486
     public function get_email() {
1487
-        return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this );
1487
+        return apply_filters('wpinv_user_email', $this->email, $this->ID, $this);
1488 1488
     }
1489 1489
     
1490 1490
     public function get_address() {
1491
-        return apply_filters( 'wpinv_address', $this->address, $this->ID, $this );
1491
+        return apply_filters('wpinv_address', $this->address, $this->ID, $this);
1492 1492
     }
1493 1493
     
1494 1494
     public function get_phone() {
1495
-        return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this );
1495
+        return apply_filters('wpinv_phone', $this->phone, $this->ID, $this);
1496 1496
     }
1497 1497
     
1498 1498
     public function get_number() {
1499
-        return apply_filters( 'wpinv_number', $this->number, $this->ID, $this );
1499
+        return apply_filters('wpinv_number', $this->number, $this->ID, $this);
1500 1500
     }
1501 1501
     
1502 1502
     public function get_items() {
1503
-        return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this );
1503
+        return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this);
1504 1504
     }
1505 1505
     
1506 1506
     public function get_key() {
1507
-        return apply_filters( 'wpinv_key', $this->key, $this->ID, $this );
1507
+        return apply_filters('wpinv_key', $this->key, $this->ID, $this);
1508 1508
     }
1509 1509
     
1510 1510
     public function get_transaction_id() {
1511
-        return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this );
1511
+        return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this);
1512 1512
     }
1513 1513
     
1514 1514
     public function get_gateway() {
1515
-        return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this );
1515
+        return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this);
1516 1516
     }
1517 1517
     
1518 1518
     public function get_gateway_title() {
1519
-        $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway );
1519
+        $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway);
1520 1520
         
1521
-        return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this );
1521
+        return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this);
1522 1522
     }
1523 1523
     
1524 1524
     public function get_currency() {
1525
-        return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this );
1525
+        return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this);
1526 1526
     }
1527 1527
     
1528 1528
     public function get_created_date() {
1529
-        return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this );
1529
+        return apply_filters('wpinv_created_date', $this->date, $this->ID, $this);
1530 1530
     }
1531 1531
     
1532
-    public function get_due_date( $display = false ) {
1533
-        $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this );
1532
+    public function get_due_date($display = false) {
1533
+        $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this);
1534 1534
         
1535
-        if ( !$display || empty( $due_date ) ) {
1535
+        if (!$display || empty($due_date)) {
1536 1536
             return $due_date;
1537 1537
         }
1538 1538
         
1539
-        return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) );
1539
+        return date_i18n(get_option('date_format'), strtotime($due_date));
1540 1540
     }
1541 1541
     
1542 1542
     public function get_completed_date() {
1543
-        return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this );
1543
+        return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this);
1544 1544
     }
1545 1545
     
1546
-    public function get_invoice_date( $formatted = true ) {
1546
+    public function get_invoice_date($formatted = true) {
1547 1547
         $date_completed = $this->completed_date;
1548 1548
         $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
1549 1549
         
1550
-        if ( $invoice_date == '' ) {
1550
+        if ($invoice_date == '') {
1551 1551
             $date_created   = $this->date;
1552 1552
             $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : '';
1553 1553
         }
1554 1554
         
1555
-        if ( $formatted && $invoice_date ) {
1556
-            $invoice_date   = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );
1555
+        if ($formatted && $invoice_date) {
1556
+            $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date));
1557 1557
         }
1558 1558
 
1559
-        return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this );
1559
+        return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this);
1560 1560
     }
1561 1561
     
1562 1562
     public function get_ip() {
1563
-        return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this );
1563
+        return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this);
1564 1564
     }
1565 1565
         
1566
-    public function has_status( $status ) {
1567
-        return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status );
1566
+    public function has_status($status) {
1567
+        return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status);
1568 1568
     }
1569 1569
     
1570
-    public function add_item( $item_id = 0, $args = array() ) {
1570
+    public function add_item($item_id = 0, $args = array()) {
1571 1571
         global $wpi_current_id, $wpi_item_id;
1572 1572
         
1573
-        $item = new WPInv_Item( $item_id );
1573
+        $item = new WPInv_Item($item_id);
1574 1574
 
1575 1575
         // Bail if this post isn't a item
1576
-        if( !$item || $item->post_type !== 'wpi_item' ) {
1576
+        if (!$item || $item->post_type !== 'wpi_item') {
1577 1577
             return false;
1578 1578
         }
1579 1579
         
@@ -1592,8 +1592,8 @@  discard block
 block discarded – undo
1592 1592
             'fees'          => array()
1593 1593
         );
1594 1594
 
1595
-        $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults );
1596
-        $args['quantity']   = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1;
1595
+        $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults);
1596
+        $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1;
1597 1597
 
1598 1598
         $wpi_current_id         = $this->ID;
1599 1599
         $wpi_item_id            = $item->ID;
@@ -1605,19 +1605,19 @@  discard block
 block discarded – undo
1605 1605
         $found_cart_key         = false;
1606 1606
         
1607 1607
         if ($has_quantities) {
1608
-            $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1608
+            $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1609 1609
             
1610
-            foreach ( $this->items as $key => $cart_item ) {
1611
-                if ( (int)$item_id !== (int)$cart_item['id'] ) {
1610
+            foreach ($this->items as $key => $cart_item) {
1611
+                if ((int)$item_id !== (int)$cart_item['id']) {
1612 1612
                     continue;
1613 1613
                 }
1614 1614
 
1615
-                $this->items[ $key ]['quantity'] += $args['quantity'];
1615
+                $this->items[$key]['quantity'] += $args['quantity'];
1616 1616
                 break;
1617 1617
             }
1618 1618
             
1619
-            foreach ( $this->cart_details as $cart_key => $cart_item ) {
1620
-                if ( $item_id != $cart_item['id'] ) {
1619
+            foreach ($this->cart_details as $cart_key => $cart_item) {
1620
+                if ($item_id != $cart_item['id']) {
1621 1621
                     continue;
1622 1622
                 }
1623 1623
 
@@ -1629,29 +1629,29 @@  discard block
 block discarded – undo
1629 1629
         if ($has_quantities && $found_cart_key !== false) {
1630 1630
             $cart_item          = $this->cart_details[$found_cart_key];
1631 1631
             $item_price         = $cart_item['item_price'];
1632
-            $quantity           = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1633
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1632
+            $quantity           = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1633
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1634 1634
             
1635 1635
             $new_quantity       = $quantity + $args['quantity'];
1636 1636
             $subtotal           = $item_price * $new_quantity;
1637 1637
             
1638 1638
             $args['quantity']   = $new_quantity;
1639
-            $discount           = !empty( $args['discount'] ) ? $args['discount'] : 0;
1640
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1639
+            $discount           = !empty($args['discount']) ? $args['discount'] : 0;
1640
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1641 1641
             
1642 1642
             $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0;
1643 1643
             $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0;
1644 1644
             // The total increase equals the number removed * the item_price
1645
-            $total_increased    = wpinv_round_amount( $item_price );
1645
+            $total_increased    = wpinv_round_amount($item_price);
1646 1646
             
1647
-            if ( wpinv_prices_include_tax() ) {
1648
-                $subtotal -= wpinv_round_amount( $tax );
1647
+            if (wpinv_prices_include_tax()) {
1648
+                $subtotal -= wpinv_round_amount($tax);
1649 1649
             }
1650 1650
 
1651
-            $total              = $subtotal - $discount + $tax;
1651
+            $total = $subtotal - $discount + $tax;
1652 1652
 
1653 1653
             // Do not allow totals to go negative
1654
-            if( $total < 0 ) {
1654
+            if ($total < 0) {
1655 1655
                 $total = 0;
1656 1656
             }
1657 1657
             
@@ -1667,20 +1667,20 @@  discard block
 block discarded – undo
1667 1667
             $this->cart_details[$found_cart_key] = $cart_item;
1668 1668
         } else {
1669 1669
             // Allow overriding the price
1670
-            if( false !== $args['item_price'] ) {
1670
+            if (false !== $args['item_price']) {
1671 1671
                 $item_price = $args['item_price'];
1672 1672
             } else {
1673
-                $item_price = wpinv_get_item_price( $item->ID );
1673
+                $item_price = wpinv_get_item_price($item->ID);
1674 1674
             }
1675 1675
 
1676 1676
             // Sanitizing the price here so we don't have a dozen calls later
1677
-            $item_price = wpinv_sanitize_amount( $item_price );
1678
-            $subtotal   = wpinv_round_amount( $item_price * $args['quantity'] );
1677
+            $item_price = wpinv_sanitize_amount($item_price);
1678
+            $subtotal   = wpinv_round_amount($item_price * $args['quantity']);
1679 1679
         
1680
-            $discount   = !empty( $args['discount'] ) ? $args['discount'] : 0;
1681
-            $tax_class  = !empty( $args['vat_class'] ) ? $args['vat_class'] : '';
1682
-            $tax_rate   = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0;
1683
-            $tax        = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1680
+            $discount   = !empty($args['discount']) ? $args['discount'] : 0;
1681
+            $tax_class  = !empty($args['vat_class']) ? $args['vat_class'] : '';
1682
+            $tax_rate   = !empty($args['vat_rate']) ? $args['vat_rate'] : 0;
1683
+            $tax        = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1684 1684
 
1685 1685
             // Setup the items meta item
1686 1686
             $new_item = array(
@@ -1688,29 +1688,29 @@  discard block
 block discarded – undo
1688 1688
                 'quantity' => $args['quantity'],
1689 1689
             );
1690 1690
 
1691
-            $this->items[]  = $new_item;
1691
+            $this->items[] = $new_item;
1692 1692
 
1693
-            if ( wpinv_prices_include_tax() ) {
1694
-                $subtotal -= wpinv_round_amount( $tax );
1693
+            if (wpinv_prices_include_tax()) {
1694
+                $subtotal -= wpinv_round_amount($tax);
1695 1695
             }
1696 1696
 
1697
-            $total      = $subtotal - $discount + $tax;
1697
+            $total = $subtotal - $discount + $tax;
1698 1698
 
1699 1699
             // Do not allow totals to go negative
1700
-            if( $total < 0 ) {
1700
+            if ($total < 0) {
1701 1701
                 $total = 0;
1702 1702
             }
1703 1703
         
1704 1704
             $this->cart_details[] = array(
1705 1705
                 'name'          => !empty($args['name']) ? $args['name'] : $item->get_name(),
1706 1706
                 'id'            => $item->ID,
1707
-                'item_price'    => wpinv_round_amount( $item_price ),
1707
+                'item_price'    => wpinv_round_amount($item_price),
1708 1708
                 'custom_price'  => $args['custom_price'],
1709 1709
                 'quantity'      => $args['quantity'],
1710 1710
                 'discount'      => $discount,
1711
-                'subtotal'      => wpinv_round_amount( $subtotal ),
1712
-                'tax'           => wpinv_round_amount( $tax ),
1713
-                'price'         => wpinv_round_amount( $total ),
1711
+                'subtotal'      => wpinv_round_amount($subtotal),
1712
+                'tax'           => wpinv_round_amount($tax),
1713
+                'price'         => wpinv_round_amount($total),
1714 1714
                 'vat_rate'      => $tax_rate,
1715 1715
                 'vat_class'     => $tax_class,
1716 1716
                 'meta'          => $args['meta'],
@@ -1720,18 +1720,18 @@  discard block
 block discarded – undo
1720 1720
             $subtotal = $subtotal - $discount;
1721 1721
         }
1722 1722
         
1723
-        $added_item = end( $this->cart_details );
1724
-        $added_item['action']  = 'add';
1723
+        $added_item = end($this->cart_details);
1724
+        $added_item['action'] = 'add';
1725 1725
         
1726 1726
         $this->pending['items'][] = $added_item;
1727 1727
         
1728
-        $this->increase_subtotal( $subtotal );
1729
-        $this->increase_tax( $tax );
1728
+        $this->increase_subtotal($subtotal);
1729
+        $this->increase_tax($tax);
1730 1730
 
1731 1731
         return true;
1732 1732
     }
1733 1733
     
1734
-    public function remove_item( $item_id, $args = array() ) {
1734
+    public function remove_item($item_id, $args = array()) {
1735 1735
         // Set some defaults
1736 1736
         $defaults = array(
1737 1737
             'quantity'      => 1,
@@ -1739,51 +1739,51 @@  discard block
 block discarded – undo
1739 1739
             'custom_price'  => '',
1740 1740
             'cart_index'    => false,
1741 1741
         );
1742
-        $args = wp_parse_args( $args, $defaults );
1742
+        $args = wp_parse_args($args, $defaults);
1743 1743
 
1744 1744
         // Bail if this post isn't a item
1745
-        if ( get_post_type( $item_id ) !== 'wpi_item' ) {
1745
+        if (get_post_type($item_id) !== 'wpi_item') {
1746 1746
             return false;
1747 1747
         }
1748 1748
         
1749
-        $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1749
+        $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1750 1750
 
1751
-        foreach ( $this->items as $key => $item ) {
1752
-            if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) {
1751
+        foreach ($this->items as $key => $item) {
1752
+            if (!empty($item['id']) && (int)$item_id !== (int)$item['id']) {
1753 1753
                 continue;
1754 1754
             }
1755 1755
 
1756
-            if ( false !== $args['cart_index'] ) {
1757
-                $cart_index = absint( $args['cart_index'] );
1758
-                $cart_item  = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false;
1756
+            if (false !== $args['cart_index']) {
1757
+                $cart_index = absint($args['cart_index']);
1758
+                $cart_item  = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false;
1759 1759
 
1760
-                if ( ! empty( $cart_item ) ) {
1760
+                if (!empty($cart_item)) {
1761 1761
                     // If the cart index item isn't the same item ID, don't remove it
1762
-                    if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) {
1762
+                    if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) {
1763 1763
                         continue;
1764 1764
                     }
1765 1765
                 }
1766 1766
             }
1767 1767
 
1768
-            $item_quantity = $this->items[ $key ]['quantity'];
1769
-            if ( $item_quantity > $args['quantity'] ) {
1770
-                $this->items[ $key ]['quantity'] -= $args['quantity'];
1768
+            $item_quantity = $this->items[$key]['quantity'];
1769
+            if ($item_quantity > $args['quantity']) {
1770
+                $this->items[$key]['quantity'] -= $args['quantity'];
1771 1771
                 break;
1772 1772
             } else {
1773
-                unset( $this->items[ $key ] );
1773
+                unset($this->items[$key]);
1774 1774
                 break;
1775 1775
             }
1776 1776
         }
1777 1777
 
1778 1778
         $found_cart_key = false;
1779
-        if ( false === $args['cart_index'] ) {
1780
-            foreach ( $this->cart_details as $cart_key => $item ) {
1781
-                if ( $item_id != $item['id'] ) {
1779
+        if (false === $args['cart_index']) {
1780
+            foreach ($this->cart_details as $cart_key => $item) {
1781
+                if ($item_id != $item['id']) {
1782 1782
                     continue;
1783 1783
                 }
1784 1784
 
1785
-                if ( false !== $args['item_price'] ) {
1786
-                    if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) {
1785
+                if (false !== $args['item_price']) {
1786
+                    if (isset($item['item_price']) && (float)$args['item_price'] != (float)$item['item_price']) {
1787 1787
                         continue;
1788 1788
                     }
1789 1789
                 }
@@ -1792,13 +1792,13 @@  discard block
 block discarded – undo
1792 1792
                 break;
1793 1793
             }
1794 1794
         } else {
1795
-            $cart_index = absint( $args['cart_index'] );
1795
+            $cart_index = absint($args['cart_index']);
1796 1796
 
1797
-            if ( ! array_key_exists( $cart_index, $this->cart_details ) ) {
1797
+            if (!array_key_exists($cart_index, $this->cart_details)) {
1798 1798
                 return false; // Invalid cart index passed.
1799 1799
             }
1800 1800
 
1801
-            if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) {
1801
+            if ((int)$this->cart_details[$cart_index]['id'] > 0 && (int)$this->cart_details[$cart_index]['id'] !== (int)$item_id) {
1802 1802
                 return false; // We still need the proper Item ID to be sure.
1803 1803
             }
1804 1804
 
@@ -1806,41 +1806,41 @@  discard block
 block discarded – undo
1806 1806
         }
1807 1807
         
1808 1808
         $cart_item  = $this->cart_details[$found_cart_key];
1809
-        $quantity   = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1809
+        $quantity   = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1810 1810
         
1811
-        if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) {
1811
+        if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) {
1812 1812
             return false; // Invoice must contain at least one item.
1813 1813
         }
1814 1814
         
1815
-        $discounts  = $this->get_discounts();
1815
+        $discounts = $this->get_discounts();
1816 1816
         
1817
-        if ( $quantity > $args['quantity'] ) {
1817
+        if ($quantity > $args['quantity']) {
1818 1818
             $item_price         = $cart_item['item_price'];
1819
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1819
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1820 1820
             
1821
-            $new_quantity       = max( $quantity - $args['quantity'], 1);
1821
+            $new_quantity       = max($quantity - $args['quantity'], 1);
1822 1822
             $subtotal           = $item_price * $new_quantity;
1823 1823
             
1824 1824
             $args['quantity']   = $new_quantity;
1825
-            $discount           = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1826
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1825
+            $discount           = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1826
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1827 1827
             
1828
-            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0;
1828
+            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float)$cart_item['discount'] / $quantity)) : 0;
1829 1829
             $discount_decrease  = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; 
1830
-            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0;
1830
+            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float)$cart_item['tax'] / $quantity)) : 0;
1831 1831
             $tax_decrease       = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease;
1832 1832
             
1833 1833
             // The total increase equals the number removed * the item_price
1834
-            $total_decrease     = wpinv_round_amount( $item_price );
1834
+            $total_decrease     = wpinv_round_amount($item_price);
1835 1835
             
1836
-            if ( wpinv_prices_include_tax() ) {
1837
-                $subtotal -= wpinv_round_amount( $tax );
1836
+            if (wpinv_prices_include_tax()) {
1837
+                $subtotal -= wpinv_round_amount($tax);
1838 1838
             }
1839 1839
 
1840
-            $total              = $subtotal - $discount + $tax;
1840
+            $total = $subtotal - $discount + $tax;
1841 1841
 
1842 1842
             // Do not allow totals to go negative
1843
-            if( $total < 0 ) {
1843
+            if ($total < 0) {
1844 1844
                 $total = 0;
1845 1845
             }
1846 1846
             
@@ -1859,16 +1859,16 @@  discard block
 block discarded – undo
1859 1859
             
1860 1860
             $this->cart_details[$found_cart_key] = $cart_item;
1861 1861
             
1862
-            $remove_item = end( $this->cart_details );
1862
+            $remove_item = end($this->cart_details);
1863 1863
         } else {
1864 1864
             $item_price     = $cart_item['item_price'];
1865
-            $discount       = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1866
-            $tax            = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0;
1865
+            $discount       = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1866
+            $tax            = !empty($cart_item['tax']) ? $cart_item['tax'] : 0;
1867 1867
         
1868
-            $subtotal_decrease  = ( $item_price * $quantity ) - $discount;
1868
+            $subtotal_decrease  = ($item_price * $quantity) - $discount;
1869 1869
             $tax_decrease       = $tax;
1870 1870
 
1871
-            unset( $this->cart_details[$found_cart_key] );
1871
+            unset($this->cart_details[$found_cart_key]);
1872 1872
             
1873 1873
             $remove_item             = $args;
1874 1874
             $remove_item['id']       = $item_id;
@@ -1879,8 +1879,8 @@  discard block
 block discarded – undo
1879 1879
         $remove_item['action']      = 'remove';
1880 1880
         $this->pending['items'][]   = $remove_item;
1881 1881
                
1882
-        $this->decrease_subtotal( $subtotal_decrease );
1883
-        $this->decrease_tax( $tax_decrease );
1882
+        $this->decrease_subtotal($subtotal_decrease);
1883
+        $this->decrease_tax($tax_decrease);
1884 1884
         
1885 1885
         return true;
1886 1886
     }
@@ -1888,7 +1888,7 @@  discard block
 block discarded – undo
1888 1888
     public function update_items($temp = false) {
1889 1889
         global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave;
1890 1890
         
1891
-        if ( !empty( $this->cart_details ) ) {
1891
+        if (!empty($this->cart_details)) {
1892 1892
             $wpi_nosave             = $temp;
1893 1893
             $cart_subtotal          = 0;
1894 1894
             $cart_discount          = 0;
@@ -1898,42 +1898,42 @@  discard block
 block discarded – undo
1898 1898
             $_POST['wpinv_country'] = $this->country;
1899 1899
             $_POST['wpinv_state']   = $this->state;
1900 1900
             
1901
-            foreach ( $this->cart_details as $key => $item ) {
1901
+            foreach ($this->cart_details as $key => $item) {
1902 1902
                 $item_price = $item['item_price'];
1903
-                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1904
-                $amount     = wpinv_round_amount( $item_price * $quantity );
1903
+                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1904
+                $amount     = wpinv_round_amount($item_price * $quantity);
1905 1905
                 $subtotal   = $item_price * $quantity;
1906 1906
                 
1907 1907
                 $wpi_current_id         = $this->ID;
1908 1908
                 $wpi_item_id            = $item['id'];
1909 1909
                 
1910
-                $discount   = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() );
1910
+                $discount   = wpinv_get_cart_item_discount_amount($item, $this->get_discounts());
1911 1911
                 
1912
-                $tax_rate   = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id );
1913
-                $tax_class  = $wpinv_euvat->get_item_class( $wpi_item_id );
1914
-                $tax        = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1912
+                $tax_rate   = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id);
1913
+                $tax_class  = $wpinv_euvat->get_item_class($wpi_item_id);
1914
+                $tax        = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1915 1915
 
1916
-                if ( wpinv_prices_include_tax() ) {
1917
-                    $subtotal -= wpinv_round_amount( $tax );
1916
+                if (wpinv_prices_include_tax()) {
1917
+                    $subtotal -= wpinv_round_amount($tax);
1918 1918
                 }
1919 1919
 
1920
-                $total      = $subtotal - $discount + $tax;
1920
+                $total = $subtotal - $discount + $tax;
1921 1921
 
1922 1922
                 // Do not allow totals to go negative
1923
-                if( $total < 0 ) {
1923
+                if ($total < 0) {
1924 1924
                     $total = 0;
1925 1925
                 }
1926 1926
 
1927 1927
                 $cart_details[] = array(
1928 1928
                     'id'          => $item['id'],
1929 1929
                     'name'        => $item['name'],
1930
-                    'item_price'  => wpinv_round_amount( $item_price ),
1930
+                    'item_price'  => wpinv_round_amount($item_price),
1931 1931
                     'custom_price'=> isset($item['custom_price']) ? $item['custom_price'] : '',
1932 1932
                     'quantity'    => $quantity,
1933 1933
                     'discount'    => $discount,
1934
-                    'subtotal'    => wpinv_round_amount( $subtotal ),
1935
-                    'tax'         => wpinv_round_amount( $tax ),
1936
-                    'price'       => wpinv_round_amount( $total ),
1934
+                    'subtotal'    => wpinv_round_amount($subtotal),
1935
+                    'tax'         => wpinv_round_amount($tax),
1936
+                    'price'       => wpinv_round_amount($total),
1937 1937
                     'vat_rate'    => $tax_rate,
1938 1938
                     'vat_class'   => $tax_class,
1939 1939
                     'meta'        => isset($item['meta']) ? $item['meta'] : array(),
@@ -1944,9 +1944,9 @@  discard block
 block discarded – undo
1944 1944
                 $cart_discount  += (float)($discount);
1945 1945
                 $cart_tax       += (float)($tax);
1946 1946
             }
1947
-            $this->subtotal = wpinv_round_amount( $cart_subtotal );
1948
-            $this->tax      = wpinv_round_amount( $cart_tax );
1949
-            $this->discount = wpinv_round_amount( $cart_discount );
1947
+            $this->subtotal = wpinv_round_amount($cart_subtotal);
1948
+            $this->tax      = wpinv_round_amount($cart_tax);
1949
+            $this->discount = wpinv_round_amount($cart_discount);
1950 1950
             
1951 1951
             $this->recalculate_total();
1952 1952
             
@@ -1958,221 +1958,221 @@  discard block
 block discarded – undo
1958 1958
     
1959 1959
     public function recalculate_totals($temp = false) {        
1960 1960
         $this->update_items($temp);
1961
-        $this->save( true );
1961
+        $this->save(true);
1962 1962
         
1963 1963
         return $this;
1964 1964
     }
1965 1965
     
1966 1966
     public function needs_payment() {
1967
-        $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'pending' ), $this );
1967
+        $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('pending'), $this);
1968 1968
 
1969
-        if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() ) ) {
1969
+        if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free())) {
1970 1970
             $needs_payment = true;
1971 1971
         } else {
1972 1972
             $needs_payment = false;
1973 1973
         }
1974 1974
 
1975
-        return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses );
1975
+        return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses);
1976 1976
     }
1977 1977
     
1978
-    public function get_checkout_payment_url( $on_checkout = false, $secret = false ) {
1978
+    public function get_checkout_payment_url($on_checkout = false, $secret = false) {
1979 1979
         $pay_url = wpinv_get_checkout_uri();
1980 1980
 
1981
-        if ( is_ssl() ) {
1982
-            $pay_url = str_replace( 'http:', 'https:', $pay_url );
1981
+        if (is_ssl()) {
1982
+            $pay_url = str_replace('http:', 'https:', $pay_url);
1983 1983
         }
1984 1984
         
1985 1985
         $key = $this->get_key();
1986 1986
 
1987
-        if ( $on_checkout ) {
1988
-            $pay_url = add_query_arg( 'invoice_key', $key, $pay_url );
1987
+        if ($on_checkout) {
1988
+            $pay_url = add_query_arg('invoice_key', $key, $pay_url);
1989 1989
         } else {
1990
-            $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url );
1990
+            $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url);
1991 1991
         }
1992 1992
         
1993
-        if ( $secret ) {
1994
-            $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url );
1993
+        if ($secret) {
1994
+            $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url);
1995 1995
         }
1996 1996
 
1997
-        return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this );
1997
+        return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this);
1998 1998
     }
1999 1999
     
2000
-    public function get_view_url( $secret = false ) {
2001
-        $print_url = get_permalink( $this->ID );
2000
+    public function get_view_url($secret = false) {
2001
+        $print_url = get_permalink($this->ID);
2002 2002
         
2003
-        if ( $secret ) {
2004
-            $print_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $print_url );
2003
+        if ($secret) {
2004
+            $print_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key())), $print_url);
2005 2005
         }
2006 2006
 
2007
-        return apply_filters( 'wpinv_get_view_url', $print_url, $this );
2007
+        return apply_filters('wpinv_get_view_url', $print_url, $this);
2008 2008
     }
2009 2009
     
2010
-    public function generate_key( $string = '' ) {
2011
-        $auth_key  = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
2012
-        return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) );  // Unique key
2010
+    public function generate_key($string = '') {
2011
+        $auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
2012
+        return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key
2013 2013
     }
2014 2014
     
2015 2015
     public function is_recurring() {
2016
-        if ( empty( $this->cart_details ) ) {
2016
+        if (empty($this->cart_details)) {
2017 2017
             return false;
2018 2018
         }
2019 2019
         
2020 2020
         $has_subscription = false;
2021
-        foreach( $this->cart_details as $cart_item ) {
2022
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2021
+        foreach ($this->cart_details as $cart_item) {
2022
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2023 2023
                 $has_subscription = true;
2024 2024
                 break;
2025 2025
             }
2026 2026
         }
2027 2027
         
2028
-        if ( count( $this->cart_details ) > 1 ) {
2028
+        if (count($this->cart_details) > 1) {
2029 2029
             $has_subscription = false;
2030 2030
         }
2031 2031
 
2032
-        return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details );
2032
+        return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details);
2033 2033
     }
2034 2034
     
2035 2035
     public function is_free_trial() {
2036 2036
         $is_free_trial = false;
2037 2037
         
2038
-        if ( $this->is_parent() && $item = $this->get_recurring( true ) ) {
2039
-            if ( !empty( $item ) && $item->has_free_trial() ) {
2038
+        if ($this->is_parent() && $item = $this->get_recurring(true)) {
2039
+            if (!empty($item) && $item->has_free_trial()) {
2040 2040
                 $is_free_trial = true;
2041 2041
             }
2042 2042
         }
2043 2043
 
2044
-        return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details );
2044
+        return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details);
2045 2045
     }
2046 2046
     
2047
-    public function get_recurring( $object = false ) {
2047
+    public function get_recurring($object = false) {
2048 2048
         $item = NULL;
2049 2049
         
2050
-        if ( empty( $this->cart_details ) ) {
2050
+        if (empty($this->cart_details)) {
2051 2051
             return $item;
2052 2052
         }
2053 2053
         
2054
-        foreach( $this->cart_details as $cart_item ) {
2055
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2054
+        foreach ($this->cart_details as $cart_item) {
2055
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2056 2056
                 $item = $cart_item['id'];
2057 2057
                 break;
2058 2058
             }
2059 2059
         }
2060 2060
         
2061
-        if ( $object ) {
2062
-            $item = $item ? new WPInv_Item( $item ) : NULL;
2061
+        if ($object) {
2062
+            $item = $item ? new WPInv_Item($item) : NULL;
2063 2063
             
2064
-            apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this );
2064
+            apply_filters('wpinv_invoice_get_recurring_item', $item, $this);
2065 2065
         }
2066 2066
 
2067
-        return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this );
2067
+        return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this);
2068 2068
     }
2069 2069
     
2070 2070
     public function get_subscription_name() {
2071
-        $item = $this->get_recurring( true );
2071
+        $item = $this->get_recurring(true);
2072 2072
         
2073
-        if ( empty( $item ) ) {
2073
+        if (empty($item)) {
2074 2074
             return NULL;
2075 2075
         }
2076 2076
         
2077
-        if ( !($name = $item->get_name()) ) {
2077
+        if (!($name = $item->get_name())) {
2078 2078
             $name = $item->post_name;
2079 2079
         }
2080 2080
 
2081
-        return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this );
2081
+        return apply_filters('wpinv_invoice_get_subscription_name', $name, $this);
2082 2082
     }
2083 2083
         
2084 2084
     public function get_expiration() {
2085
-        $expiration = $this->get_meta( '_wpinv_subscr_expiration', true );
2085
+        $expiration = $this->get_meta('_wpinv_subscr_expiration', true);
2086 2086
         return $expiration;
2087 2087
     }
2088 2088
     
2089
-    public function get_cancelled_date( $formatted = true ) {
2090
-        $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta( '_wpinv_subscr_cancelled_on', true ) : '';
2089
+    public function get_cancelled_date($formatted = true) {
2090
+        $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta('_wpinv_subscr_cancelled_on', true) : '';
2091 2091
         
2092
-        if ( $formatted && $cancelled_date ) {
2093
-            $cancelled_date = date_i18n( get_option( 'date_format' ), strtotime( $cancelled_date ) );
2092
+        if ($formatted && $cancelled_date) {
2093
+            $cancelled_date = date_i18n(get_option('date_format'), strtotime($cancelled_date));
2094 2094
         }
2095 2095
         
2096 2096
         return $cancelled_date;
2097 2097
     }
2098 2098
     
2099
-    public function get_trial_end_date( $formatted = true ) {
2100
-        if ( !$this->is_free_trial() || !$this->is_paid() ) {
2099
+    public function get_trial_end_date($formatted = true) {
2100
+        if (!$this->is_free_trial() || !$this->is_paid()) {
2101 2101
             return NULL;
2102 2102
         }
2103 2103
         
2104
-        $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta( '_wpinv_subscr_trial_end', true ) : '';
2104
+        $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta('_wpinv_subscr_trial_end', true) : '';
2105 2105
         
2106
-        if ( empty( $trial_end_date ) ) {
2107
-            $trial_start_time = strtotime( $this->get_subscription_start() );
2108
-            $trial_start_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;
2106
+        if (empty($trial_end_date)) {
2107
+            $trial_start_time = strtotime($this->get_subscription_start());
2108
+            $trial_start_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);
2109 2109
             
2110
-            $trial_end_date = date_i18n( 'Y-m-d H:i:s', $trial_start_time );
2110
+            $trial_end_date = date_i18n('Y-m-d H:i:s', $trial_start_time);
2111 2111
         }
2112 2112
         
2113
-        if ( $formatted && $trial_end_date ) {
2114
-            $trial_end_date = date_i18n( get_option( 'date_format' ), strtotime( $trial_end_date ) );
2113
+        if ($formatted && $trial_end_date) {
2114
+            $trial_end_date = date_i18n(get_option('date_format'), strtotime($trial_end_date));
2115 2115
         }
2116 2116
         
2117 2117
         return $trial_end_date;
2118 2118
     }
2119 2119
     
2120
-    public function get_subscription_created( $default = true ) {
2121
-        $created = $this->get_meta( '_wpinv_subscr_created', true );
2120
+    public function get_subscription_created($default = true) {
2121
+        $created = $this->get_meta('_wpinv_subscr_created', true);
2122 2122
         
2123
-        if ( empty( $created ) && $default ) {
2123
+        if (empty($created) && $default) {
2124 2124
             $created = $this->date;
2125 2125
         }
2126 2126
         return $created;
2127 2127
     }
2128 2128
     
2129
-    public function get_subscription_start( $formatted = true ) {
2130
-        if ( !$this->is_paid() ) {
2129
+    public function get_subscription_start($formatted = true) {
2130
+        if (!$this->is_paid()) {
2131 2131
             return '-';
2132 2132
         }
2133
-        $start   = $this->get_subscription_created();
2133
+        $start = $this->get_subscription_created();
2134 2134
         
2135
-        if ( $formatted ) {
2136
-            $date = date_i18n( get_option( 'date_format' ), strtotime( $start ) );
2135
+        if ($formatted) {
2136
+            $date = date_i18n(get_option('date_format'), strtotime($start));
2137 2137
         } else {
2138
-            $date = date_i18n( 'Y-m-d H:i:s', strtotime( $start ) );
2138
+            $date = date_i18n('Y-m-d H:i:s', strtotime($start));
2139 2139
         }
2140 2140
 
2141 2141
         return $date;
2142 2142
     }
2143 2143
     
2144
-    public function get_subscription_end( $formatted = true ) {
2145
-        if ( !$this->is_paid() ) {
2144
+    public function get_subscription_end($formatted = true) {
2145
+        if (!$this->is_paid()) {
2146 2146
             return '-';
2147 2147
         }
2148 2148
         $start          = $this->get_subscription_created();
2149 2149
         $interval       = $this->get_subscription_interval();
2150
-        $period         = $this->get_subscription_period( true );
2150
+        $period         = $this->get_subscription_period(true);
2151 2151
         $bill_times     = (int)$this->get_bill_times();
2152 2152
         
2153
-        if ( $bill_times == 0 ) {
2154
-            return $formatted ? __( 'Until cancelled', 'invoicing' ) : $bill_times;
2153
+        if ($bill_times == 0) {
2154
+            return $formatted ? __('Until cancelled', 'invoicing') : $bill_times;
2155 2155
         }
2156 2156
         
2157
-        $total_period = $start . '+' . ( $interval * $bill_times ) . ' ' . $period;
2157
+        $total_period = $start . '+' . ($interval * $bill_times) . ' ' . $period;
2158 2158
         
2159
-        $end_time = strtotime( $start . '+' . ( $interval * $bill_times ) . ' ' . $period );
2159
+        $end_time = strtotime($start . '+' . ($interval * $bill_times) . ' ' . $period);
2160 2160
         
2161
-        if ( $this->is_free_trial() ) {
2162
-            $end_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;
2161
+        if ($this->is_free_trial()) {
2162
+            $end_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);
2163 2163
         }
2164 2164
         
2165
-        if ( $formatted ) {
2166
-            $date = date_i18n( get_option( 'date_format' ), $end_time );
2165
+        if ($formatted) {
2166
+            $date = date_i18n(get_option('date_format'), $end_time);
2167 2167
         } else {
2168
-            $date = date_i18n( 'Y-m-d H:i:s', $end_time );
2168
+            $date = date_i18n('Y-m-d H:i:s', $end_time);
2169 2169
         }
2170 2170
 
2171 2171
         return $date;
2172 2172
     }
2173 2173
     
2174 2174
     public function get_expiration_time() {
2175
-        return strtotime( $this->get_expiration(), current_time( 'timestamp' ) );
2175
+        return strtotime($this->get_expiration(), current_time('timestamp'));
2176 2176
     }
2177 2177
     
2178 2178
     public function get_original_invoice_id() {        
@@ -2184,125 +2184,125 @@  discard block
 block discarded – undo
2184 2184
         return $subscription_data['bill_times'];
2185 2185
     }
2186 2186
 
2187
-    public function get_child_payments( $self = false ) {
2188
-        $invoices = get_posts( array(
2187
+    public function get_child_payments($self = false) {
2188
+        $invoices = get_posts(array(
2189 2189
             'post_type'         => $this->post_type,
2190 2190
             'post_parent'       => (int)$this->ID,
2191 2191
             'posts_per_page'    => '999',
2192
-            'post_status'       => array( 'publish', 'wpi-processing', 'wpi-renewal' ),
2192
+            'post_status'       => array('publish', 'wpi-processing', 'wpi-renewal'),
2193 2193
             'orderby'           => 'ID',
2194 2194
             'order'             => 'DESC',
2195 2195
             'fields'            => 'ids'
2196
-        ) );
2196
+        ));
2197 2197
         
2198
-        if ( $this->is_free_trial() ) {
2198
+        if ($this->is_free_trial()) {
2199 2199
             $self = false;
2200 2200
         }
2201 2201
         
2202
-        if ( $self && $this->is_paid() ) {
2203
-            if ( !empty( $invoices ) ) {
2202
+        if ($self && $this->is_paid()) {
2203
+            if (!empty($invoices)) {
2204 2204
                 $invoices[] = (int)$this->ID;
2205 2205
             } else {
2206
-                $invoices = array( $this->ID );
2206
+                $invoices = array($this->ID);
2207 2207
             }
2208 2208
             
2209
-            $invoices = array_unique( $invoices );
2209
+            $invoices = array_unique($invoices);
2210 2210
         }
2211 2211
 
2212 2212
         return $invoices;
2213 2213
     }
2214 2214
 
2215
-    public function get_total_payments( $self = true ) {
2216
-        return count( $this->get_child_payments( $self ) );
2215
+    public function get_total_payments($self = true) {
2216
+        return count($this->get_child_payments($self));
2217 2217
     }
2218 2218
     
2219
-    public function get_subscriptions( $limit = -1 ) {
2220
-        $subscriptions = wpinv_get_subscriptions( array( 'parent_invoice_id' => $this->ID, 'numberposts' => $limit ) );
2219
+    public function get_subscriptions($limit = -1) {
2220
+        $subscriptions = wpinv_get_subscriptions(array('parent_invoice_id' => $this->ID, 'numberposts' => $limit));
2221 2221
 
2222 2222
         return $subscriptions;
2223 2223
     }
2224 2224
     
2225 2225
     public function get_subscription_id() {
2226
-        $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true );
2226
+        $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true);
2227 2227
         
2228
-        if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) {
2229
-            $parent_invoice = wpinv_get_invoice( $this->parent_invoice );
2228
+        if (empty($subscription_id) && !empty($this->parent_invoice)) {
2229
+            $parent_invoice = wpinv_get_invoice($this->parent_invoice);
2230 2230
             
2231
-            $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true );
2231
+            $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true);
2232 2232
         }
2233 2233
         
2234 2234
         return $subscription_id;
2235 2235
     }
2236 2236
     
2237 2237
     public function get_subscription_status() {
2238
-        $subscription_status = $this->get_meta( '_wpinv_subscr_status', true );
2238
+        $subscription_status = $this->get_meta('_wpinv_subscr_status', true);
2239 2239
 
2240
-        if ( empty( $subscription_status ) ) {
2240
+        if (empty($subscription_status)) {
2241 2241
             $status = 'pending';
2242 2242
             
2243
-            if ( $this->is_paid() ) {        
2243
+            if ($this->is_paid()) {        
2244 2244
                 $bill_times   = (int)$this->get_bill_times();
2245 2245
                 $times_billed = (int)$this->get_total_payments();
2246
-                $expiration = $this->get_subscription_end( false );
2247
-                $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime( date_i18n( 'Y-m-d', strtotime( $expiration ) ) ) < strtotime( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) ) ? true : false;
2246
+                $expiration = $this->get_subscription_end(false);
2247
+                $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime(date_i18n('Y-m-d', strtotime($expiration))) < strtotime(date_i18n('Y-m-d', current_time('timestamp'))) ? true : false;
2248 2248
                 
2249
-                if ( (int)$bill_times == 0 ) {
2249
+                if ((int)$bill_times == 0) {
2250 2250
                     $status = $expired ? 'expired' : 'active';
2251
-                } else if ( $bill_times > 0 && $times_billed >= $bill_times ) {
2251
+                } else if ($bill_times > 0 && $times_billed >= $bill_times) {
2252 2252
                     $status = 'completed';
2253
-                } else if ( $expired ) {
2253
+                } else if ($expired) {
2254 2254
                     $status = 'expired';
2255
-                } else if ( $bill_times > 0 ) {
2255
+                } else if ($bill_times > 0) {
2256 2256
                     $status = 'active';
2257 2257
                 } else {
2258 2258
                     $status = 'pending';
2259 2259
                 }
2260 2260
             }
2261 2261
             
2262
-            if ( $status && $status != $subscription_status ) {
2262
+            if ($status && $status != $subscription_status) {
2263 2263
                 $subscription_status = $status;
2264 2264
                 
2265
-                $this->update_meta( '_wpinv_subscr_status', $status );
2265
+                $this->update_meta('_wpinv_subscr_status', $status);
2266 2266
             }
2267 2267
         }
2268 2268
         
2269 2269
         return $subscription_status;
2270 2270
     }
2271 2271
     
2272
-    public function get_subscription_status_label( $status = '' ) {
2273
-        $status = !empty( $status ) ? $status : $this->get_subscription_status();
2272
+    public function get_subscription_status_label($status = '') {
2273
+        $status = !empty($status) ? $status : $this->get_subscription_status();
2274 2274
 
2275
-        switch( $status ) {
2275
+        switch ($status) {
2276 2276
             case 'active' :
2277
-                $status_label = __( 'Active', 'invoicing' );
2277
+                $status_label = __('Active', 'invoicing');
2278 2278
                 break;
2279 2279
 
2280 2280
             case 'cancelled' :
2281
-                $status_label = __( 'Cancelled', 'invoicing' );
2281
+                $status_label = __('Cancelled', 'invoicing');
2282 2282
                 break;
2283 2283
                 
2284 2284
             case 'completed' :
2285
-                $status_label = __( 'Completed', 'invoicing' );
2285
+                $status_label = __('Completed', 'invoicing');
2286 2286
                 break;
2287 2287
 
2288 2288
             case 'expired' :
2289
-                $status_label = __( 'Expired', 'invoicing' );
2289
+                $status_label = __('Expired', 'invoicing');
2290 2290
                 break;
2291 2291
 
2292 2292
             case 'pending' :
2293
-                $status_label = __( 'Pending', 'invoicing' );
2293
+                $status_label = __('Pending', 'invoicing');
2294 2294
                 break;
2295 2295
 
2296 2296
             case 'failing' :
2297
-                $status_label = __( 'Failing', 'invoicing' );
2297
+                $status_label = __('Failing', 'invoicing');
2298 2298
                 break;
2299 2299
                 
2300 2300
             case 'stopped' :
2301
-                $status_label = __( 'Stopped', 'invoicing' );
2301
+                $status_label = __('Stopped', 'invoicing');
2302 2302
                 break;
2303 2303
                 
2304 2304
             case 'trialing' :
2305
-                $status_label = __( 'Trialing', 'invoicing' );
2305
+                $status_label = __('Trialing', 'invoicing');
2306 2306
                 break;
2307 2307
 
2308 2308
             default:
@@ -2313,26 +2313,26 @@  discard block
 block discarded – undo
2313 2313
         return $status_label;
2314 2314
     }
2315 2315
     
2316
-    public function get_subscription_period( $full = false ) {
2317
-        $period = $this->get_meta( '_wpinv_subscr_period', true );
2316
+    public function get_subscription_period($full = false) {
2317
+        $period = $this->get_meta('_wpinv_subscr_period', true);
2318 2318
         
2319 2319
         // Fix period for old invoices
2320
-        if ( $period == 'day' ) {
2320
+        if ($period == 'day') {
2321 2321
             $period = 'D';
2322
-        } else if ( $period == 'week' ) {
2322
+        } else if ($period == 'week') {
2323 2323
             $period = 'W';
2324
-        } else if ( $period == 'month' ) {
2324
+        } else if ($period == 'month') {
2325 2325
             $period = 'M';
2326
-        } else if ( $period == 'year' ) {
2326
+        } else if ($period == 'year') {
2327 2327
             $period = 'Y';
2328 2328
         }
2329 2329
         
2330
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2330
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
2331 2331
             $period = 'D';
2332 2332
         }
2333 2333
         
2334
-        if ( $full ) {
2335
-            switch( $period ) {
2334
+        if ($full) {
2335
+            switch ($period) {
2336 2336
                 case 'D':
2337 2337
                     $period = 'day';
2338 2338
                 break;
@@ -2352,39 +2352,39 @@  discard block
 block discarded – undo
2352 2352
     }
2353 2353
     
2354 2354
     public function get_subscription_interval() {
2355
-        $interval = (int)$this->get_meta( '_wpinv_subscr_interval', true );
2355
+        $interval = (int)$this->get_meta('_wpinv_subscr_interval', true);
2356 2356
         
2357
-        if ( !$interval > 0 ) {
2357
+        if (!$interval > 0) {
2358 2358
             $interval = 1;
2359 2359
         }
2360 2360
         
2361 2361
         return $interval;
2362 2362
     }
2363 2363
     
2364
-    public function get_subscription_trial_period( $full = false ) {
2365
-        if ( !$this->is_free_trial() ) {
2364
+    public function get_subscription_trial_period($full = false) {
2365
+        if (!$this->is_free_trial()) {
2366 2366
             return '';
2367 2367
         }
2368 2368
         
2369
-        $period = $this->get_meta( '_wpinv_subscr_trial_period', true );
2369
+        $period = $this->get_meta('_wpinv_subscr_trial_period', true);
2370 2370
         
2371 2371
         // Fix period for old invoices
2372
-        if ( $period == 'day' ) {
2372
+        if ($period == 'day') {
2373 2373
             $period = 'D';
2374
-        } else if ( $period == 'week' ) {
2374
+        } else if ($period == 'week') {
2375 2375
             $period = 'W';
2376
-        } else if ( $period == 'month' ) {
2376
+        } else if ($period == 'month') {
2377 2377
             $period = 'M';
2378
-        } else if ( $period == 'year' ) {
2378
+        } else if ($period == 'year') {
2379 2379
             $period = 'Y';
2380 2380
         }
2381 2381
         
2382
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2382
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
2383 2383
             $period = 'D';
2384 2384
         }
2385 2385
         
2386
-        if ( $full ) {
2387
-            switch( $period ) {
2386
+        if ($full) {
2387
+            switch ($period) {
2388 2388
                 case 'D':
2389 2389
                     $period = 'day';
2390 2390
                 break;
@@ -2404,13 +2404,13 @@  discard block
 block discarded – undo
2404 2404
     }
2405 2405
     
2406 2406
     public function get_subscription_trial_interval() {
2407
-        if ( !$this->is_free_trial() ) {
2407
+        if (!$this->is_free_trial()) {
2408 2408
             return 0;
2409 2409
         }
2410 2410
         
2411
-        $interval = (int)$this->get_meta( '_wpinv_subscr_trial_interval', true );
2411
+        $interval = (int)$this->get_meta('_wpinv_subscr_trial_interval', true);
2412 2412
         
2413
-        if ( !$interval > 0 ) {
2413
+        if (!$interval > 0) {
2414 2414
             $interval = 1;
2415 2415
         }
2416 2416
         
@@ -2422,8 +2422,8 @@  discard block
 block discarded – undo
2422 2422
             'status' => 'failing'
2423 2423
         );
2424 2424
 
2425
-        if ( $this->update_subscription( $args ) ) {
2426
-            do_action( 'wpinv_subscription_failing', $this->ID, $this );
2425
+        if ($this->update_subscription($args)) {
2426
+            do_action('wpinv_subscription_failing', $this->ID, $this);
2427 2427
             return true;
2428 2428
         }
2429 2429
 
@@ -2435,8 +2435,8 @@  discard block
 block discarded – undo
2435 2435
             'status' => 'stopped'
2436 2436
         );
2437 2437
 
2438
-        if ( $this->update_subscription( $args ) ) {
2439
-            do_action( 'wpinv_subscription_stopped', $this->ID, $this );
2438
+        if ($this->update_subscription($args)) {
2439
+            do_action('wpinv_subscription_stopped', $this->ID, $this);
2440 2440
             return true;
2441 2441
         }
2442 2442
 
@@ -2448,8 +2448,8 @@  discard block
 block discarded – undo
2448 2448
             'status' => 'active'
2449 2449
         );
2450 2450
 
2451
-        if ( $this->update_subscription( $args ) ) {
2452
-            do_action( 'wpinv_subscription_restarted', $this->ID, $this );
2451
+        if ($this->update_subscription($args)) {
2452
+            do_action('wpinv_subscription_restarted', $this->ID, $this);
2453 2453
             return true;
2454 2454
         }
2455 2455
 
@@ -2461,23 +2461,23 @@  discard block
 block discarded – undo
2461 2461
             'status' => 'cancelled'
2462 2462
         );
2463 2463
 
2464
-        if ( $this->update_subscription( $args ) ) {
2465
-            if ( is_user_logged_in() ) {
2466
-                $userdata = get_userdata( get_current_user_id() );
2464
+        if ($this->update_subscription($args)) {
2465
+            if (is_user_logged_in()) {
2466
+                $userdata = get_userdata(get_current_user_id());
2467 2467
                 $user     = $userdata->user_login;
2468 2468
             } else {
2469
-                $user = __( 'gateway', 'invoicing' );
2469
+                $user = __('gateway', 'invoicing');
2470 2470
             }
2471 2471
             
2472 2472
             $subscription_id = $this->get_subscription_id();
2473
-            if ( !$subscription_id ) {
2473
+            if (!$subscription_id) {
2474 2474
                 $subscription_id = $this->ID;
2475 2475
             }
2476 2476
 
2477
-            $note = sprintf( __( 'Subscription %s has been cancelled by %s', 'invoicing' ), $subscription_id, $user );
2478
-            $this->add_note( $note );
2477
+            $note = sprintf(__('Subscription %s has been cancelled by %s', 'invoicing'), $subscription_id, $user);
2478
+            $this->add_note($note);
2479 2479
 
2480
-            do_action( 'wpinv_subscription_cancelled', $this->ID, $this );
2480
+            do_action('wpinv_subscription_cancelled', $this->ID, $this);
2481 2481
             return true;
2482 2482
         }
2483 2483
 
@@ -2485,11 +2485,11 @@  discard block
 block discarded – undo
2485 2485
     }
2486 2486
 
2487 2487
     public function can_cancel() {
2488
-        return apply_filters( 'wpinv_subscription_can_cancel', false, $this );
2488
+        return apply_filters('wpinv_subscription_can_cancel', false, $this);
2489 2489
     }
2490 2490
     
2491
-    public function add_subscription( $data = array() ) {
2492
-        if ( empty( $this->ID ) ) {
2491
+    public function add_subscription($data = array()) {
2492
+        if (empty($this->ID)) {
2493 2493
             return false;
2494 2494
         }
2495 2495
 
@@ -2508,85 +2508,85 @@  discard block
 block discarded – undo
2508 2508
             'profile_id'        => '',
2509 2509
         );
2510 2510
 
2511
-        $args = wp_parse_args( $data, $defaults );
2511
+        $args = wp_parse_args($data, $defaults);
2512 2512
 
2513
-        if ( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
2514
-            if ( 'active' == $args['status'] || $args['status'] == 'trialing' ) {
2513
+        if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
2514
+            if ('active' == $args['status'] || $args['status'] == 'trialing') {
2515 2515
                 $args['status'] = 'expired';
2516 2516
             }
2517 2517
         }
2518 2518
 
2519
-        do_action( 'wpinv_subscription_pre_create', $args, $data, $this );
2519
+        do_action('wpinv_subscription_pre_create', $args, $data, $this);
2520 2520
         
2521
-        if ( !empty( $args ) ) {
2522
-            foreach ( $args as $key => $value ) {
2523
-                $this->update_meta( '_wpinv_subscr_' . $key, $value );
2521
+        if (!empty($args)) {
2522
+            foreach ($args as $key => $value) {
2523
+                $this->update_meta('_wpinv_subscr_' . $key, $value);
2524 2524
             }
2525 2525
         }
2526 2526
 
2527
-        do_action( 'wpinv_subscription_post_create', $args, $data, $this );
2527
+        do_action('wpinv_subscription_post_create', $args, $data, $this);
2528 2528
 
2529 2529
         return true;
2530 2530
     }
2531 2531
     
2532
-    public function update_subscription( $args = array() ) {
2533
-        if ( empty( $this->ID ) ) {
2532
+    public function update_subscription($args = array()) {
2533
+        if (empty($this->ID)) {
2534 2534
             return false;
2535 2535
         }
2536 2536
 
2537
-        if ( !empty( $args['expiration'] ) && $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
2538
-            if ( !isset( $args['status'] ) || ( isset( $args['status'] ) && ( 'active' == $args['status'] || $args['status'] == 'trialing' ) ) ) {
2537
+        if (!empty($args['expiration']) && $args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
2538
+            if (!isset($args['status']) || (isset($args['status']) && ('active' == $args['status'] || $args['status'] == 'trialing'))) {
2539 2539
                 $args['status'] = 'expired';
2540 2540
             }
2541 2541
         }
2542 2542
 
2543
-        if ( isset( $args['status'] ) && $args['status'] == 'cancelled' && empty( $args['cancelled_on'] ) ) {
2544
-            $args['cancelled_on'] = date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) );
2543
+        if (isset($args['status']) && $args['status'] == 'cancelled' && empty($args['cancelled_on'])) {
2544
+            $args['cancelled_on'] = date_i18n('Y-m-d H:i:s', current_time('timestamp'));
2545 2545
         }
2546 2546
 
2547
-        do_action( 'wpinv_subscription_pre_update', $args, $this );
2547
+        do_action('wpinv_subscription_pre_update', $args, $this);
2548 2548
         
2549
-        if ( !empty( $args ) ) {
2550
-            foreach ( $args as $key => $value ) {
2551
-                $this->update_meta( '_wpinv_subscr_' . $key, $value );
2549
+        if (!empty($args)) {
2550
+            foreach ($args as $key => $value) {
2551
+                $this->update_meta('_wpinv_subscr_' . $key, $value);
2552 2552
             }
2553 2553
         }
2554 2554
 
2555
-        do_action( 'wpinv_subscription_post_update', $args, $this );
2555
+        do_action('wpinv_subscription_post_update', $args, $this);
2556 2556
 
2557 2557
         return true;
2558 2558
     }
2559 2559
     
2560 2560
     public function renew_subscription() {
2561 2561
         $parent_invoice = $this->get_parent_payment();
2562
-        $parent_invoice = empty( $parent_invoice ) ? $this : $parent_invoice;
2562
+        $parent_invoice = empty($parent_invoice) ? $this : $parent_invoice;
2563 2563
         
2564
-        $current_time   = current_time( 'timestamp' );
2564
+        $current_time   = current_time('timestamp');
2565 2565
         $start          = $this->get_subscription_created();
2566
-        $start          = $start ? strtotime( $start ) : $current_time;
2566
+        $start          = $start ? strtotime($start) : $current_time;
2567 2567
         $expires        = $this->get_expiration_time();
2568 2568
         
2569
-        if ( !$expires ) {
2570
-            $expires    = strtotime( '+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period( true ), $start );
2569
+        if (!$expires) {
2570
+            $expires    = strtotime('+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period(true), $start);
2571 2571
         }
2572 2572
         
2573
-        $expiration     = date_i18n( 'Y-m-d 23:59:59', $expires );
2574
-        $expiration     = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this );
2573
+        $expiration     = date_i18n('Y-m-d 23:59:59', $expires);
2574
+        $expiration     = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this);
2575 2575
         $bill_times     = $parent_invoice->get_bill_times();
2576 2576
         $times_billed   = $parent_invoice->get_total_payments();
2577 2577
         
2578
-        if ( $parent_invoice->get_subscription_status() == 'trialing' && ( $times_billed > 0 || strtotime( date_i18n( 'Y-m-d' ) ) < strtotime( $parent_invoice->get_trial_end_date( false ) ) ) ) {
2578
+        if ($parent_invoice->get_subscription_status() == 'trialing' && ($times_billed > 0 || strtotime(date_i18n('Y-m-d')) < strtotime($parent_invoice->get_trial_end_date(false)))) {
2579 2579
             $args = array(
2580 2580
                 'status'     => 'active',
2581 2581
             );
2582 2582
 
2583
-            $parent_invoice->update_subscription( $args );
2583
+            $parent_invoice->update_subscription($args);
2584 2584
         }
2585 2585
         
2586
-        do_action( 'wpinv_subscription_pre_renew', $this->ID, $expiration, $this );
2586
+        do_action('wpinv_subscription_pre_renew', $this->ID, $expiration, $this);
2587 2587
 
2588
-        $status       = 'active';
2589
-        if ( $bill_times > 0 && $times_billed >= $bill_times ) {
2588
+        $status = 'active';
2589
+        if ($bill_times > 0 && $times_billed >= $bill_times) {
2590 2590
             $this->complete_subscription();
2591 2591
             $status = 'completed';
2592 2592
         }
@@ -2596,10 +2596,10 @@  discard block
 block discarded – undo
2596 2596
             'status'     => $status,
2597 2597
         );
2598 2598
 
2599
-        $this->update_subscription( $args );
2599
+        $this->update_subscription($args);
2600 2600
 
2601
-        do_action( 'wpinv_subscription_post_renew', $this->ID, $expiration, $this );
2602
-        do_action( 'wpinv_recurring_set_subscription_status', $this->ID, $status, $this );
2601
+        do_action('wpinv_subscription_post_renew', $this->ID, $expiration, $this);
2602
+        do_action('wpinv_recurring_set_subscription_status', $this->ID, $status, $this);
2603 2603
     }
2604 2604
     
2605 2605
     public function complete_subscription() {
@@ -2607,8 +2607,8 @@  discard block
 block discarded – undo
2607 2607
             'status' => 'completed'
2608 2608
         );
2609 2609
 
2610
-        if ( $this->update_subscription( $args ) ) {
2611
-            do_action( 'wpinv_subscription_completed', $this->ID, $this );
2610
+        if ($this->update_subscription($args)) {
2611
+            do_action('wpinv_subscription_completed', $this->ID, $this);
2612 2612
         }
2613 2613
     }
2614 2614
     
@@ -2617,44 +2617,44 @@  discard block
 block discarded – undo
2617 2617
             'status' => 'expired'
2618 2618
         );
2619 2619
 
2620
-        if ( $this->update_subscription( $args ) ) {
2621
-            do_action( 'wpinv_subscription_expired', $this->ID, $this );
2620
+        if ($this->update_subscription($args)) {
2621
+            do_action('wpinv_subscription_expired', $this->ID, $this);
2622 2622
         }
2623 2623
     }
2624 2624
 
2625 2625
     public function get_cancel_url() {
2626
-        $url = wp_nonce_url( add_query_arg( array( 'wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID ) ), 'wpinv-recurring-cancel' );
2626
+        $url = wp_nonce_url(add_query_arg(array('wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID)), 'wpinv-recurring-cancel');
2627 2627
 
2628
-        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
2628
+        return apply_filters('wpinv_subscription_cancel_url', $url, $this);
2629 2629
     }
2630 2630
 
2631 2631
     public function can_update() {
2632
-        return apply_filters( 'wpinv_subscription_can_update', false, $this );
2632
+        return apply_filters('wpinv_subscription_can_update', false, $this);
2633 2633
     }
2634 2634
 
2635 2635
     public function get_update_url() {
2636
-        $url = add_query_arg( array( 'action' => 'update', 'sub_id' => $this->ID ) );
2636
+        $url = add_query_arg(array('action' => 'update', 'sub_id' => $this->ID));
2637 2637
 
2638
-        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
2638
+        return apply_filters('wpinv_subscription_update_url', $url, $this);
2639 2639
     }
2640 2640
 
2641 2641
     public function is_parent() {
2642
-        $is_parent = empty( $this->parent_invoice ) ? true : false;
2642
+        $is_parent = empty($this->parent_invoice) ? true : false;
2643 2643
 
2644
-        return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this );
2644
+        return apply_filters('wpinv_invoice_is_parent', $is_parent, $this);
2645 2645
     }
2646 2646
     
2647 2647
     public function is_renewal() {
2648 2648
         $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false;
2649 2649
 
2650
-        return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this );
2650
+        return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this);
2651 2651
     }
2652 2652
     
2653 2653
     public function get_parent_payment() {
2654 2654
         $parent_payment = NULL;
2655 2655
         
2656
-        if ( $this->is_renewal() ) {
2657
-            $parent_payment = wpinv_get_invoice( $this->parent_invoice );
2656
+        if ($this->is_renewal()) {
2657
+            $parent_payment = wpinv_get_invoice($this->parent_invoice);
2658 2658
         }
2659 2659
         
2660 2660
         return $parent_payment;
@@ -2665,100 +2665,100 @@  discard block
 block discarded – undo
2665 2665
         
2666 2666
         $subscription_status = $this->get_subscription_status();
2667 2667
 
2668
-        if( ! $this->is_subscription_expired() && ( $subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing' ) ) {
2668
+        if (!$this->is_subscription_expired() && ($subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing')) {
2669 2669
             $ret = true;
2670 2670
         }
2671 2671
 
2672
-        return apply_filters( 'wpinv_subscription_is_active', $ret, $this->ID, $this );
2672
+        return apply_filters('wpinv_subscription_is_active', $ret, $this->ID, $this);
2673 2673
     }
2674 2674
 
2675 2675
     public function is_subscription_expired() {
2676 2676
         $ret = false;
2677 2677
         $subscription_status = $this->get_subscription_status();
2678 2678
 
2679
-        if ( $subscription_status == 'expired' ) {
2679
+        if ($subscription_status == 'expired') {
2680 2680
             $ret = true;
2681
-        } else if ( 'active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status ) {
2681
+        } else if ('active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status) {
2682 2682
             $ret        = false;
2683 2683
             $expiration = $this->get_expiration_time();
2684 2684
 
2685
-            if ( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) {
2685
+            if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) {
2686 2686
                 $ret = true;
2687 2687
 
2688
-                if ( 'active' === $subscription_status || 'trialing' === $subscription_status ) {
2688
+                if ('active' === $subscription_status || 'trialing' === $subscription_status) {
2689 2689
                     $this->expire_subscription();
2690 2690
                 }
2691 2691
             }
2692 2692
         }
2693 2693
 
2694
-        return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->ID, $this );
2694
+        return apply_filters('wpinv_subscription_is_expired', $ret, $this->ID, $this);
2695 2695
     }
2696 2696
     
2697
-    public function get_new_expiration( $item_id = 0, $trial = true ) {
2698
-        $item   = new WPInv_Item( $item_id );
2697
+    public function get_new_expiration($item_id = 0, $trial = true) {
2698
+        $item   = new WPInv_Item($item_id);
2699 2699
         $interval = $item->get_recurring_interval();
2700
-        $period = $item->get_recurring_period( true );
2700
+        $period = $item->get_recurring_period(true);
2701 2701
         
2702
-        $expiration_time = strtotime( '+' . $interval . ' ' . $period );
2702
+        $expiration_time = strtotime('+' . $interval . ' ' . $period);
2703 2703
         
2704
-        if ( $trial && $this->is_free_trial() && $item->has_free_trial() ) {
2705
-            $expiration_time += ( wpinv_period_in_days( $item->get_trial_interval(), $item->get_trial_period() ) * DAY_IN_SECONDS ) ;
2704
+        if ($trial && $this->is_free_trial() && $item->has_free_trial()) {
2705
+            $expiration_time += (wpinv_period_in_days($item->get_trial_interval(), $item->get_trial_period()) * DAY_IN_SECONDS);
2706 2706
         }
2707 2707
 
2708
-        return date_i18n( 'Y-m-d 23:59:59', $expiration_time );
2708
+        return date_i18n('Y-m-d 23:59:59', $expiration_time);
2709 2709
     }
2710 2710
     
2711
-    public function get_subscription_data( $filed = '' ) {
2712
-        $fields = array( 'item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on' );
2711
+    public function get_subscription_data($filed = '') {
2712
+        $fields = array('item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on');
2713 2713
         
2714 2714
         $subscription_meta = array();
2715
-        foreach ( $fields as $field ) {
2716
-            $subscription_meta[ $field ] = $this->get_meta( '_wpinv_subscr_' . $field );
2715
+        foreach ($fields as $field) {
2716
+            $subscription_meta[$field] = $this->get_meta('_wpinv_subscr_' . $field);
2717 2717
         }
2718 2718
         
2719
-        $item = $this->get_recurring( true );
2719
+        $item = $this->get_recurring(true);
2720 2720
         
2721
-        if ( !empty( $item ) ) {
2722
-            if ( empty( $subscription_meta['item_id'] ) ) {
2721
+        if (!empty($item)) {
2722
+            if (empty($subscription_meta['item_id'])) {
2723 2723
                 $subscription_meta['item_id'] = $item->ID;
2724 2724
             }
2725
-            if ( empty( $subscription_meta['period'] ) ) {
2725
+            if (empty($subscription_meta['period'])) {
2726 2726
                 $subscription_meta['period'] = $item->get_recurring_period();
2727 2727
             }
2728
-            if ( empty( $subscription_meta['interval'] ) ) {
2728
+            if (empty($subscription_meta['interval'])) {
2729 2729
                 $subscription_meta['interval'] = $item->get_recurring_interval();
2730 2730
             }
2731
-            if ( $item->has_free_trial() ) {
2732
-                if ( empty( $subscription_meta['trial_period'] ) ) {
2731
+            if ($item->has_free_trial()) {
2732
+                if (empty($subscription_meta['trial_period'])) {
2733 2733
                     $subscription_meta['trial_period'] = $item->get_trial_period();
2734 2734
                 }
2735
-                if ( empty( $subscription_meta['trial_interval'] ) ) {
2735
+                if (empty($subscription_meta['trial_interval'])) {
2736 2736
                     $subscription_meta['trial_interval'] = $item->get_trial_interval();
2737 2737
                 }
2738 2738
             } else {
2739 2739
                 $subscription_meta['trial_period']      = '';
2740 2740
                 $subscription_meta['trial_interval']    = 0;
2741 2741
             }
2742
-            if ( !$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0 ) {
2742
+            if (!$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0) {
2743 2743
                 $subscription_meta['bill_times'] = $item->get_recurring_limit();
2744 2744
             }
2745
-            if ( $subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '' ) {
2746
-                $subscription_meta['initial_amount']    = wpinv_round_amount( $this->get_total() );
2747
-                $subscription_meta['recurring_amount']  = wpinv_round_amount( $this->get_recurring_details( 'total' ) );
2745
+            if ($subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '') {
2746
+                $subscription_meta['initial_amount']    = wpinv_round_amount($this->get_total());
2747
+                $subscription_meta['recurring_amount']  = wpinv_round_amount($this->get_recurring_details('total'));
2748 2748
             }
2749 2749
         }
2750 2750
         
2751
-        if ( $filed === '' ) {
2752
-            return apply_filters( 'wpinv_get_invoice_subscription_data', $subscription_meta, $this );
2751
+        if ($filed === '') {
2752
+            return apply_filters('wpinv_get_invoice_subscription_data', $subscription_meta, $this);
2753 2753
         }
2754 2754
         
2755
-        $value = isset( $subscription_meta[$filed] ) ? $subscription_meta[$filed] : '';
2755
+        $value = isset($subscription_meta[$filed]) ? $subscription_meta[$filed] : '';
2756 2756
         
2757
-        return apply_filters( 'wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this );
2757
+        return apply_filters('wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this);
2758 2758
     }
2759 2759
     
2760 2760
     public function is_paid() {
2761
-        if ( $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
2761
+        if ($this->has_status(array('publish', 'wpi-processing', 'wpi-renewal'))) {
2762 2762
             return true;
2763 2763
         }
2764 2764
         
@@ -2768,15 +2768,15 @@  discard block
 block discarded – undo
2768 2768
     public function is_free() {
2769 2769
         $is_free = false;
2770 2770
         
2771
-        if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) {
2772
-            if ( $this->is_parent() && $this->is_recurring() ) {
2773
-                $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true;
2771
+        if (!((float)wpinv_round_amount($this->get_total()) > 0)) {
2772
+            if ($this->is_parent() && $this->is_recurring()) {
2773
+                $is_free = (float)wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true;
2774 2774
             } else {
2775 2775
                 $is_free = true;
2776 2776
             }
2777 2777
         }
2778 2778
         
2779
-        return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2779
+        return apply_filters('wpinv_invoice_is_free', $is_free, $this);
2780 2780
     }
2781 2781
     
2782 2782
     public function has_vat() {
@@ -2784,28 +2784,28 @@  discard block
 block discarded – undo
2784 2784
         
2785 2785
         $requires_vat = false;
2786 2786
         
2787
-        if ( $this->country ) {
2787
+        if ($this->country) {
2788 2788
             $wpi_country        = $this->country;
2789 2789
             
2790
-            $requires_vat       = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) );
2790
+            $requires_vat       = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this));
2791 2791
         }
2792 2792
         
2793
-        return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2793
+        return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this);
2794 2794
     }
2795 2795
     
2796 2796
     public function refresh_item_ids() {
2797 2797
         $item_ids = array();
2798 2798
         
2799
-        if ( !empty( $this->cart_details ) ) {
2800
-            foreach ( $this->cart_details as $key => $item ) {
2801
-                if ( !empty( $item['id'] ) ) {
2799
+        if (!empty($this->cart_details)) {
2800
+            foreach ($this->cart_details as $key => $item) {
2801
+                if (!empty($item['id'])) {
2802 2802
                     $item_ids[] = $item['id'];
2803 2803
                 }
2804 2804
             }
2805 2805
         }
2806 2806
         
2807
-        $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : '';
2807
+        $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : '';
2808 2808
         
2809
-        update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids );
2809
+        update_post_meta($this->ID, '_wpinv_item_ids', $item_ids);
2810 2810
     }
2811 2811
 }
Please login to merge, or discard this patch.
includes/wpinv-invoice-functions.php 1 patch
Spacing   +559 added lines, -559 removed lines patch added patch discarded remove patch
@@ -7,40 +7,40 @@  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
     
21 21
     return NULL;
22 22
 }
23 23
 
24
-function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) {
25
-    if ( empty( $invoice_data ) ) {
24
+function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) {
25
+    if (empty($invoice_data)) {
26 26
         return false;
27 27
     }
28 28
     
29
-    if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) {
30
-        return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast on item.', 'invoicing' ) ) : 0;
29
+    if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) {
30
+        return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast on item.', 'invoicing')) : 0;
31 31
     }
32 32
     
33
-    if ( empty( $invoice_data['user_id'] ) ) {
33
+    if (empty($invoice_data['user_id'])) {
34 34
         $invoice_data['user_id'] = get_current_user_id();
35 35
     }
36 36
     
37
-    $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0;
37
+    $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int)$invoice_data['invoice_id'] : 0;
38 38
     
39
-    if ( empty( $invoice_data['status'] ) ) {
39
+    if (empty($invoice_data['status'])) {
40 40
         $invoice_data['status'] = 'pending';
41 41
     }
42 42
     
43
-    if ( empty( $invoice_data['ip'] ) ) {
43
+    if (empty($invoice_data['ip'])) {
44 44
         $invoice_data['ip'] = wpinv_get_ip();
45 45
     }
46 46
 
@@ -51,12 +51,12 @@  discard block
 block discarded – undo
51 51
         'status'        => $invoice_data['status'],
52 52
     );
53 53
 
54
-    $invoice = wpinv_create_invoice( $default_args, $invoice_data, true );
55
-    if ( is_wp_error( $invoice ) ) {
54
+    $invoice = wpinv_create_invoice($default_args, $invoice_data, true);
55
+    if (is_wp_error($invoice)) {
56 56
         return $wp_error ? $invoice : 0;
57 57
     }
58 58
     
59
-    if ( empty( $invoice_data['invoice_id'] ) ) {
59
+    if (empty($invoice_data['invoice_id'])) {
60 60
         //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );
61 61
     }
62 62
     
@@ -79,20 +79,20 @@  discard block
 block discarded – undo
79 79
         'discount'              => array(),
80 80
     );
81 81
 
82
-    if ( $user_id = (int)$invoice->get_user_id() ) {
83
-        if ( $user_address = wpinv_get_user_address( $user_id ) ) {
84
-            $default_user_info = wp_parse_args( $user_address, $default_user_info );
82
+    if ($user_id = (int)$invoice->get_user_id()) {
83
+        if ($user_address = wpinv_get_user_address($user_id)) {
84
+            $default_user_info = wp_parse_args($user_address, $default_user_info);
85 85
         }
86 86
     }
87 87
     
88
-    $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info );
88
+    $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info);
89 89
     
90
-    if ( empty( $user_info['first_name'] ) ) {
90
+    if (empty($user_info['first_name'])) {
91 91
         $user_info['first_name'] = $default_user_info['first_name'];
92 92
         $user_info['last_name'] = $default_user_info['last_name'];
93 93
     }
94 94
     
95
-    if ( empty( $user_info['country'] ) ) {
95
+    if (empty($user_info['country'])) {
96 96
         $user_info['country'] = $default_user_info['country'];
97 97
         $user_info['state'] = $default_user_info['state'];
98 98
         $user_info['city'] = $default_user_info['city'];
@@ -101,13 +101,13 @@  discard block
 block discarded – undo
101 101
         $user_info['phone'] = $default_user_info['phone'];
102 102
     }
103 103
     
104
-    if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) {
104
+    if (!empty($user_info['discount']) && !is_array($user_info['discount'])) {
105 105
         $user_info['discount'] = (array)$user_info['discount'];
106 106
     }
107 107
 
108 108
     // Payment details
109 109
     $payment_details = array();
110
-    if ( !empty( $invoice_data['payment_details'] ) ) {
110
+    if (!empty($invoice_data['payment_details'])) {
111 111
         $default_payment_details = array(
112 112
             'gateway'           => 'manual',
113 113
             'gateway_title'     => '',
@@ -115,59 +115,59 @@  discard block
 block discarded – undo
115 115
             'transaction_id'    => '',
116 116
         );
117 117
         
118
-        $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details );
118
+        $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details);
119 119
         
120
-        if ( empty( $payment_details['gateway'] ) ) {
120
+        if (empty($payment_details['gateway'])) {
121 121
             $payment_details['gateway'] = 'manual';
122 122
         }
123 123
         
124
-        if ( empty( $payment_details['currency'] ) ) {
124
+        if (empty($payment_details['currency'])) {
125 125
             $payment_details['currency'] = geodir_get_currency_type();
126 126
         }
127 127
         
128
-        if ( empty( $payment_details['gateway_title'] ) ) {
129
-            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] );
128
+        if (empty($payment_details['gateway_title'])) {
129
+            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']);
130 130
         }
131 131
     }
132 132
     
133
-    $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'pending' ) );
134
-    
135
-    if ( !empty( $payment_details ) ) {
136
-        $invoice->set( 'currency', $payment_details['currency'] );
137
-        $invoice->set( 'gateway', $payment_details['gateway'] );
138
-        $invoice->set( 'gateway_title', $payment_details['gateway_title'] );
139
-        $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
140
-    }
141
-    
142
-    $invoice->set( 'user_info', $user_info );
143
-    $invoice->set( 'first_name', $user_info['first_name'] );
144
-    $invoice->set( 'last_name', $user_info['last_name'] );
145
-    $invoice->set( 'address', $user_info['address'] );
146
-    $invoice->set( 'company', $user_info['company'] );
147
-    $invoice->set( 'vat_number', $user_info['vat_number'] );
148
-    $invoice->set( 'phone', $user_info['phone'] );
149
-    $invoice->set( 'city', $user_info['city'] );
150
-    $invoice->set( 'country', $user_info['country'] );
151
-    $invoice->set( 'state', $user_info['state'] );
152
-    $invoice->set( 'zip', $user_info['zip'] );
153
-    $invoice->set( 'discounts', $user_info['discount'] );
154
-    $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) );
155
-    if ( !empty( $invoice_data['invoice_key'] ) ) {
156
-        $invoice->set( 'key', $invoice_data['invoice_key'] );
157
-    }
158
-    $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) );
159
-    $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) );
160
-    
161
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) {
162
-        foreach ( $invoice_data['cart_details'] as $key => $item ) {
163
-            $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
164
-            $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
165
-            $name           = !empty( $item['name'] ) ? $item['name'] : '';
166
-            $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : '';
133
+    $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'pending'));
134
+    
135
+    if (!empty($payment_details)) {
136
+        $invoice->set('currency', $payment_details['currency']);
137
+        $invoice->set('gateway', $payment_details['gateway']);
138
+        $invoice->set('gateway_title', $payment_details['gateway_title']);
139
+        $invoice->set('transaction_id', $payment_details['transaction_id']);
140
+    }
141
+    
142
+    $invoice->set('user_info', $user_info);
143
+    $invoice->set('first_name', $user_info['first_name']);
144
+    $invoice->set('last_name', $user_info['last_name']);
145
+    $invoice->set('address', $user_info['address']);
146
+    $invoice->set('company', $user_info['company']);
147
+    $invoice->set('vat_number', $user_info['vat_number']);
148
+    $invoice->set('phone', $user_info['phone']);
149
+    $invoice->set('city', $user_info['city']);
150
+    $invoice->set('country', $user_info['country']);
151
+    $invoice->set('state', $user_info['state']);
152
+    $invoice->set('zip', $user_info['zip']);
153
+    $invoice->set('discounts', $user_info['discount']);
154
+    $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip()));
155
+    if (!empty($invoice_data['invoice_key'])) {
156
+        $invoice->set('key', $invoice_data['invoice_key']);
157
+    }
158
+    $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live'));
159
+    $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : ''));
160
+    
161
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) {
162
+        foreach ($invoice_data['cart_details'] as $key => $item) {
163
+            $item_id        = !empty($item['id']) ? $item['id'] : 0;
164
+            $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
165
+            $name           = !empty($item['name']) ? $item['name'] : '';
166
+            $item_price     = isset($item['item_price']) ? $item['item_price'] : '';
167 167
             
168
-            $post_item  = new WPInv_Item( $item_id );
169
-            if ( !empty( $post_item ) ) {
170
-                $name       = !empty( $name ) ? $name : $post_item->get_name();
168
+            $post_item = new WPInv_Item($item_id);
169
+            if (!empty($post_item)) {
170
+                $name       = !empty($name) ? $name : $post_item->get_name();
171 171
                 $item_price = $item_price !== '' ? $item_price : $post_item->get_price();
172 172
             } else {
173 173
                 continue;
@@ -177,494 +177,494 @@  discard block
 block discarded – undo
177 177
                 'name'          => $name,
178 178
                 'quantity'      => $quantity,
179 179
                 'item_price'    => $item_price,
180
-                'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
181
-                'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0.00,
182
-                'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
183
-                'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
184
-                'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
180
+                'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
181
+                'tax'           => !empty($item['tax']) ? $item['tax'] : 0.00,
182
+                'discount'      => isset($item['discount']) ? $item['discount'] : 0,
183
+                'meta'          => isset($item['meta']) ? $item['meta'] : array(),
184
+                'fees'          => isset($item['fees']) ? $item['fees'] : array(),
185 185
             );
186 186
 
187
-            $invoice->add_item( $item_id, $args );
187
+            $invoice->add_item($item_id, $args);
188 188
         }
189 189
     }
190 190
 
191
-    $invoice->increase_tax( wpinv_get_cart_fee_tax() );
191
+    $invoice->increase_tax(wpinv_get_cart_fee_tax());
192 192
 
193
-    if ( isset( $invoice_data['post_date'] ) ) {
194
-        $invoice->set( 'date', $invoice_data['post_date'] );
193
+    if (isset($invoice_data['post_date'])) {
194
+        $invoice->set('date', $invoice_data['post_date']);
195 195
     }
196 196
 
197
-    $number = wpinv_format_invoice_number( $invoice->ID );
198
-    $invoice->set( 'number', $number );
199
-    update_option( 'wpinv_last_invoice_number', $number );
197
+    $number = wpinv_format_invoice_number($invoice->ID);
198
+    $invoice->set('number', $number);
199
+    update_option('wpinv_last_invoice_number', $number);
200 200
     
201 201
     $invoice->save();
202 202
     
203 203
     // Add notes
204
-    if ( !empty( $invoice_data['private_note'] ) ) {
205
-        $invoice->add_note( $invoice_data['private_note'] );
204
+    if (!empty($invoice_data['private_note'])) {
205
+        $invoice->add_note($invoice_data['private_note']);
206 206
     }
207
-    if ( !empty( $invoice_data['user_note'] ) ) {
208
-        $invoice->add_note( $invoice_data['user_note'], true );
207
+    if (!empty($invoice_data['user_note'])) {
208
+        $invoice->add_note($invoice_data['user_note'], true);
209 209
     }
210 210
     
211
-    do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data );
211
+    do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data);
212 212
 
213
-    if ( ! empty( $invoice->ID ) ) {
213
+    if (!empty($invoice->ID)) {
214 214
         global $wpi_userID, $wpinv_ip_address_country;
215 215
         
216 216
         $checkout_session = wpinv_get_checkout_session();
217 217
         
218 218
         $data_session                   = array();
219 219
         $data_session['invoice_id']     = $invoice->ID;
220
-        $data_session['cart_discounts'] = $invoice->get_discounts( true );
220
+        $data_session['cart_discounts'] = $invoice->get_discounts(true);
221 221
         
222
-        wpinv_set_checkout_session( $data_session );
222
+        wpinv_set_checkout_session($data_session);
223 223
         
224 224
         $wpi_userID         = (int)$invoice->get_user_id();
225 225
         
226
-        $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
226
+        $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
227 227
         $_POST['state']     = $invoice->state;
228 228
 
229
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
230
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
229
+        $invoice->set('country', sanitize_text_field($_POST['country']));
230
+        $invoice->set('state', sanitize_text_field($_POST['state']));
231 231
         
232 232
         $wpinv_ip_address_country = $invoice->country;
233 233
         
234
-        $invoice = $invoice->recalculate_totals( true );
234
+        $invoice = $invoice->recalculate_totals(true);
235 235
         
236
-        wpinv_set_checkout_session( $checkout_session );
236
+        wpinv_set_checkout_session($checkout_session);
237 237
                     
238 238
         return $invoice;
239 239
     }
240 240
     
241
-    if ( $wp_error ) {
242
-        if ( is_wp_error( $invoice ) ) {
241
+    if ($wp_error) {
242
+        if (is_wp_error($invoice)) {
243 243
             return $invoice;
244 244
         } else {
245
-            return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) );
245
+            return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing'));
246 246
         }
247 247
     } else {
248 248
         return 0;
249 249
     }
250 250
 }
251 251
 
252
-function wpinv_get_invoice( $invoice_id = 0, $cart = false ) {
253
-    if ( $cart && empty( $invoice_id ) ) {
252
+function wpinv_get_invoice($invoice_id = 0, $cart = false) {
253
+    if ($cart && empty($invoice_id)) {
254 254
         $invoice_id = (int)wpinv_get_invoice_cart_id();
255 255
     }
256 256
 
257
-    $invoice = new WPInv_Invoice( $invoice_id );
257
+    $invoice = new WPInv_Invoice($invoice_id);
258 258
     return $invoice;
259 259
 }
260 260
 
261
-function wpinv_get_invoice_cart( $invoice_id = 0 ) {
262
-    return wpinv_get_invoice( $invoice_id, true );
261
+function wpinv_get_invoice_cart($invoice_id = 0) {
262
+    return wpinv_get_invoice($invoice_id, true);
263 263
 }
264 264
 
265
-function wpinv_get_invoice_description( $invoice_id = 0 ) {
266
-    $invoice = new WPInv_Invoice( $invoice_id );
265
+function wpinv_get_invoice_description($invoice_id = 0) {
266
+    $invoice = new WPInv_Invoice($invoice_id);
267 267
     return $invoice->get_description();
268 268
 }
269 269
 
270
-function wpinv_get_invoice_currency_code( $invoice_id = 0 ) {
271
-    $invoice = new WPInv_Invoice( $invoice_id );
270
+function wpinv_get_invoice_currency_code($invoice_id = 0) {
271
+    $invoice = new WPInv_Invoice($invoice_id);
272 272
     return $invoice->get_currency();
273 273
 }
274 274
 
275
-function wpinv_get_payment_user_email( $invoice_id ) {
276
-    $invoice = new WPInv_Invoice( $invoice_id );
275
+function wpinv_get_payment_user_email($invoice_id) {
276
+    $invoice = new WPInv_Invoice($invoice_id);
277 277
     return $invoice->get_email();
278 278
 }
279 279
 
280
-function wpinv_get_user_id( $invoice_id ) {
281
-    $invoice = new WPInv_Invoice( $invoice_id );
280
+function wpinv_get_user_id($invoice_id) {
281
+    $invoice = new WPInv_Invoice($invoice_id);
282 282
     return $invoice->get_user_id();
283 283
 }
284 284
 
285
-function wpinv_get_invoice_status( $invoice_id, $return_label = false ) {
286
-    $invoice = new WPInv_Invoice( $invoice_id );
285
+function wpinv_get_invoice_status($invoice_id, $return_label = false) {
286
+    $invoice = new WPInv_Invoice($invoice_id);
287 287
     
288
-    return $invoice->get_status( $return_label );
288
+    return $invoice->get_status($return_label);
289 289
 }
290 290
 
291
-function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) {
292
-    $invoice = new WPInv_Invoice( $invoice_id );
291
+function wpinv_get_payment_gateway($invoice_id, $return_label = false) {
292
+    $invoice = new WPInv_Invoice($invoice_id);
293 293
     
294
-    return $invoice->get_gateway( $return_label );
294
+    return $invoice->get_gateway($return_label);
295 295
 }
296 296
 
297
-function wpinv_get_payment_gateway_name( $invoice_id ) {
298
-    $invoice = new WPInv_Invoice( $invoice_id );
297
+function wpinv_get_payment_gateway_name($invoice_id) {
298
+    $invoice = new WPInv_Invoice($invoice_id);
299 299
     
300 300
     return $invoice->get_gateway_title();
301 301
 }
302 302
 
303
-function wpinv_get_payment_transaction_id( $invoice_id ) {
304
-    $invoice = new WPInv_Invoice( $invoice_id );
303
+function wpinv_get_payment_transaction_id($invoice_id) {
304
+    $invoice = new WPInv_Invoice($invoice_id);
305 305
     
306 306
     return $invoice->get_transaction_id();
307 307
 }
308 308
 
309
-function wpinv_get_id_by_transaction_id( $key ) {
309
+function wpinv_get_id_by_transaction_id($key) {
310 310
     global $wpdb;
311 311
 
312
-    $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 ) );
312
+    $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));
313 313
 
314
-    if ( $invoice_id != NULL )
314
+    if ($invoice_id != NULL)
315 315
         return $invoice_id;
316 316
 
317 317
     return 0;
318 318
 }
319 319
 
320
-function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) {
321
-    $invoice = new WPInv_Invoice( $invoice_id );
320
+function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) {
321
+    $invoice = new WPInv_Invoice($invoice_id);
322 322
 
323
-    return $invoice->get_meta( $meta_key, $single );
323
+    return $invoice->get_meta($meta_key, $single);
324 324
 }
325 325
 
326
-function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) {
327
-    $invoice = new WPInv_Invoice( $invoice_id );
326
+function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') {
327
+    $invoice = new WPInv_Invoice($invoice_id);
328 328
     
329
-    return $invoice->update_meta( $meta_key, $meta_value, $prev_value );
329
+    return $invoice->update_meta($meta_key, $meta_value, $prev_value);
330 330
 }
331 331
 
332
-function wpinv_get_items( $invoice_id = 0 ) {
333
-    $invoice            = wpinv_get_invoice( $invoice_id );
332
+function wpinv_get_items($invoice_id = 0) {
333
+    $invoice            = wpinv_get_invoice($invoice_id);
334 334
     
335 335
     $items              = $invoice->get_items();
336 336
     $invoice_currency   = $invoice->get_currency();
337 337
 
338
-    if ( !empty( $items ) && is_array( $items ) ) {
339
-        foreach ( $items as $key => $item ) {
338
+    if (!empty($items) && is_array($items)) {
339
+        foreach ($items as $key => $item) {
340 340
             $items[$key]['currency'] = $invoice_currency;
341 341
 
342
-            if ( !isset( $cart_item['subtotal'] ) ) {
342
+            if (!isset($cart_item['subtotal'])) {
343 343
                 $items[$key]['subtotal'] = $items[$key]['amount'] * 1;
344 344
             }
345 345
         }
346 346
     }
347 347
 
348
-    return apply_filters( 'wpinv_get_items', $items, $invoice_id );
348
+    return apply_filters('wpinv_get_items', $items, $invoice_id);
349 349
 }
350 350
 
351
-function wpinv_get_fees( $invoice_id = 0 ) {
352
-    $invoice           = wpinv_get_invoice( $invoice_id );
351
+function wpinv_get_fees($invoice_id = 0) {
352
+    $invoice           = wpinv_get_invoice($invoice_id);
353 353
     $fees              = $invoice->get_fees();
354 354
 
355
-    return apply_filters( 'wpinv_get_fees', $fees, $invoice_id );
355
+    return apply_filters('wpinv_get_fees', $fees, $invoice_id);
356 356
 }
357 357
 
358
-function wpinv_get_invoice_ip( $invoice_id ) {
359
-    $invoice = new WPInv_Invoice( $invoice_id );
358
+function wpinv_get_invoice_ip($invoice_id) {
359
+    $invoice = new WPInv_Invoice($invoice_id);
360 360
     return $invoice->get_ip();
361 361
 }
362 362
 
363
-function wpinv_get_invoice_user_info( $invoice_id ) {
364
-    $invoice = new WPInv_Invoice( $invoice_id );
363
+function wpinv_get_invoice_user_info($invoice_id) {
364
+    $invoice = new WPInv_Invoice($invoice_id);
365 365
     return $invoice->get_user_info();
366 366
 }
367 367
 
368
-function wpinv_subtotal( $invoice_id = 0, $currency = false ) {
369
-    $invoice = new WPInv_Invoice( $invoice_id );
368
+function wpinv_subtotal($invoice_id = 0, $currency = false) {
369
+    $invoice = new WPInv_Invoice($invoice_id);
370 370
 
371
-    return $invoice->get_subtotal( $currency );
371
+    return $invoice->get_subtotal($currency);
372 372
 }
373 373
 
374
-function wpinv_tax( $invoice_id = 0, $currency = false ) {
375
-    $invoice = new WPInv_Invoice( $invoice_id );
374
+function wpinv_tax($invoice_id = 0, $currency = false) {
375
+    $invoice = new WPInv_Invoice($invoice_id);
376 376
 
377
-    return $invoice->get_tax( $currency );
377
+    return $invoice->get_tax($currency);
378 378
 }
379 379
 
380
-function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) {
381
-    $invoice = wpinv_get_invoice( $invoice_id );
380
+function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) {
381
+    $invoice = wpinv_get_invoice($invoice_id);
382 382
 
383
-    return $invoice->get_discount( $currency, $dash );
383
+    return $invoice->get_discount($currency, $dash);
384 384
 }
385 385
 
386
-function wpinv_discount_code( $invoice_id = 0 ) {
387
-    $invoice = new WPInv_Invoice( $invoice_id );
386
+function wpinv_discount_code($invoice_id = 0) {
387
+    $invoice = new WPInv_Invoice($invoice_id);
388 388
 
389 389
     return $invoice->get_discount_code();
390 390
 }
391 391
 
392
-function wpinv_payment_total( $invoice_id = 0, $currency = false ) {
393
-    $invoice = new WPInv_Invoice( $invoice_id );
392
+function wpinv_payment_total($invoice_id = 0, $currency = false) {
393
+    $invoice = new WPInv_Invoice($invoice_id);
394 394
 
395
-    return $invoice->get_total( $currency );
395
+    return $invoice->get_total($currency);
396 396
 }
397 397
 
398
-function wpinv_get_date_created( $invoice_id = 0 ) {
399
-    $invoice = new WPInv_Invoice( $invoice_id );
398
+function wpinv_get_date_created($invoice_id = 0) {
399
+    $invoice = new WPInv_Invoice($invoice_id);
400 400
     
401 401
     $date_created   = $invoice->get_created_date();
402
-    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ), strtotime( $date_created ) ) : '';
402
+    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format'), strtotime($date_created)) : '';
403 403
 
404 404
     return $date_created;
405 405
 }
406 406
 
407
-function wpinv_get_invoice_date( $invoice_id = 0, $format = '' ) {
408
-    $invoice = new WPInv_Invoice( $invoice_id );
407
+function wpinv_get_invoice_date($invoice_id = 0, $format = '') {
408
+    $invoice = new WPInv_Invoice($invoice_id);
409 409
     
410
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
410
+    $format         = !empty($format) ? $format : get_option('date_format');
411 411
     $date_completed = $invoice->get_completed_date();
412
-    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : '';
413
-    if ( $invoice_date == '' ) {
412
+    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : '';
413
+    if ($invoice_date == '') {
414 414
         $date_created   = $invoice->get_created_date();
415
-        $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : '';
415
+        $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : '';
416 416
     }
417 417
 
418 418
     return $invoice_date;
419 419
 }
420 420
 
421
-function wpinv_get_invoice_vat_number( $invoice_id = 0 ) {
422
-    $invoice = new WPInv_Invoice( $invoice_id );
421
+function wpinv_get_invoice_vat_number($invoice_id = 0) {
422
+    $invoice = new WPInv_Invoice($invoice_id);
423 423
     
424 424
     return $invoice->vat_number;
425 425
 }
426 426
 
427
-function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false ) {
428
-    $invoice = new WPInv_Invoice( $invoice_id );
427
+function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false) {
428
+    $invoice = new WPInv_Invoice($invoice_id);
429 429
 
430
-    return $invoice->add_note( $note, $user_type, $added_by_user );
430
+    return $invoice->add_note($note, $user_type, $added_by_user);
431 431
 }
432 432
 
433
-function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) {
433
+function wpinv_get_invoice_notes($invoice_id = 0, $type = '') {
434 434
     global $invoicing;
435 435
     
436
-    if ( empty( $invoice_id ) ) {
436
+    if (empty($invoice_id)) {
437 437
         return NULL;
438 438
     }
439 439
     
440
-    $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type );
440
+    $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type);
441 441
     
442
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type );
442
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type);
443 443
 }
444 444
 
445
-function wpinv_get_payment_key( $invoice_id = 0 ) {
446
-	$invoice = new WPInv_Invoice( $invoice_id );
445
+function wpinv_get_payment_key($invoice_id = 0) {
446
+	$invoice = new WPInv_Invoice($invoice_id);
447 447
     return $invoice->get_key();
448 448
 }
449 449
 
450
-function wpinv_get_invoice_number( $invoice_id = 0 ) {
451
-    $invoice = new WPInv_Invoice( $invoice_id );
450
+function wpinv_get_invoice_number($invoice_id = 0) {
451
+    $invoice = new WPInv_Invoice($invoice_id);
452 452
     return $invoice->get_number();
453 453
 }
454 454
 
455
-function wpinv_get_cart_discountable_subtotal( $code_id ) {
455
+function wpinv_get_cart_discountable_subtotal($code_id) {
456 456
     $cart_items = wpinv_get_cart_content_details();
457 457
     $items      = array();
458 458
 
459
-    $excluded_items = wpinv_get_discount_excluded_items( $code_id );
459
+    $excluded_items = wpinv_get_discount_excluded_items($code_id);
460 460
 
461
-    if( $cart_items ) {
461
+    if ($cart_items) {
462 462
 
463
-        foreach( $cart_items as $item ) {
463
+        foreach ($cart_items as $item) {
464 464
 
465
-            if( ! in_array( $item['id'], $excluded_items ) ) {
466
-                $items[] =  $item;
465
+            if (!in_array($item['id'], $excluded_items)) {
466
+                $items[] = $item;
467 467
             }
468 468
         }
469 469
     }
470 470
 
471
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
471
+    $subtotal = wpinv_get_cart_items_subtotal($items);
472 472
 
473
-    return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal );
473
+    return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal);
474 474
 }
475 475
 
476
-function wpinv_get_cart_items_subtotal( $items ) {
476
+function wpinv_get_cart_items_subtotal($items) {
477 477
     $subtotal = 0.00;
478 478
 
479
-    if ( is_array( $items ) && ! empty( $items ) ) {
480
-        $prices = wp_list_pluck( $items, 'subtotal' );
479
+    if (is_array($items) && !empty($items)) {
480
+        $prices = wp_list_pluck($items, 'subtotal');
481 481
 
482
-        if( is_array( $prices ) ) {
483
-            $subtotal = array_sum( $prices );
482
+        if (is_array($prices)) {
483
+            $subtotal = array_sum($prices);
484 484
         } else {
485 485
             $subtotal = 0.00;
486 486
         }
487 487
 
488
-        if( $subtotal < 0 ) {
488
+        if ($subtotal < 0) {
489 489
             $subtotal = 0.00;
490 490
         }
491 491
     }
492 492
 
493
-    return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal );
493
+    return apply_filters('wpinv_get_cart_items_subtotal', $subtotal);
494 494
 }
495 495
 
496
-function wpinv_get_cart_subtotal( $items = array() ) {
497
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
498
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
496
+function wpinv_get_cart_subtotal($items = array()) {
497
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
498
+    $subtotal = wpinv_get_cart_items_subtotal($items);
499 499
 
500
-    return apply_filters( 'wpinv_get_cart_subtotal', $subtotal );
500
+    return apply_filters('wpinv_get_cart_subtotal', $subtotal);
501 501
 }
502 502
 
503
-function wpinv_cart_subtotal( $items = array() ) {
504
-    $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ) );
503
+function wpinv_cart_subtotal($items = array()) {
504
+    $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items)));
505 505
 
506 506
     return $price;
507 507
 }
508 508
 
509
-function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) {
510
-    $subtotal  = (float)wpinv_get_cart_subtotal( $items );
511
-    $discounts = (float)wpinv_get_cart_discounted_amount( $items );
512
-    $cart_tax  = (float)wpinv_get_cart_tax( $items );
509
+function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) {
510
+    $subtotal  = (float)wpinv_get_cart_subtotal($items);
511
+    $discounts = (float)wpinv_get_cart_discounted_amount($items);
512
+    $cart_tax  = (float)wpinv_get_cart_tax($items);
513 513
     $fees      = (float)wpinv_get_cart_fee_total();
514
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
514
+    if (!empty($invoice) && $invoice->is_free_trial()) {
515 515
         $total = 0;
516 516
     } else {
517
-        $total     = $subtotal - $discounts + $cart_tax + $fees;
517
+        $total = $subtotal - $discounts + $cart_tax + $fees;
518 518
     }
519 519
 
520
-    if ( $total < 0 ) {
520
+    if ($total < 0) {
521 521
         $total = 0.00;
522 522
     }
523 523
     
524
-    $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items );
524
+    $total = (float)apply_filters('wpinv_get_cart_total', $total, $items);
525 525
 
526
-    return wpinv_sanitize_amount( $total );
526
+    return wpinv_sanitize_amount($total);
527 527
 }
528 528
 
529
-function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) {
529
+function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) {
530 530
     global $cart_total;
531
-    $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ) );
532
-    $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice );
531
+    $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice)));
532
+    $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice);
533 533
     
534 534
     $cart_total = $total;
535 535
 
536
-    if ( !$echo ) {
536
+    if (!$echo) {
537 537
         return $total;
538 538
     }
539 539
 
540 540
     echo $total;
541 541
 }
542 542
 
543
-function wpinv_get_cart_tax( $items = array() ) {
543
+function wpinv_get_cart_tax($items = array()) {
544 544
     $cart_tax = 0;
545
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
545
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
546 546
 
547
-    if ( $items ) {
548
-        $taxes = wp_list_pluck( $items, 'tax' );
547
+    if ($items) {
548
+        $taxes = wp_list_pluck($items, 'tax');
549 549
 
550
-        if( is_array( $taxes ) ) {
551
-            $cart_tax = array_sum( $taxes );
550
+        if (is_array($taxes)) {
551
+            $cart_tax = array_sum($taxes);
552 552
         }
553 553
     }
554 554
 
555 555
     $cart_tax += wpinv_get_cart_fee_tax();
556 556
 
557
-    return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) );
557
+    return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax));
558 558
 }
559 559
 
560
-function wpinv_cart_tax( $items = array(), $echo = false ) {
561
-    $cart_tax = wpinv_get_cart_tax( $items );
562
-    $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ) );
560
+function wpinv_cart_tax($items = array(), $echo = false) {
561
+    $cart_tax = wpinv_get_cart_tax($items);
562
+    $cart_tax = wpinv_price(wpinv_format_amount($cart_tax));
563 563
 
564
-    $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items );
564
+    $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items);
565 565
 
566
-    if ( !$echo ) {
566
+    if (!$echo) {
567 567
         return $tax;
568 568
     }
569 569
 
570 570
     echo $tax;
571 571
 }
572 572
 
573
-function wpinv_get_cart_discount_code( $items = array() ) {
573
+function wpinv_get_cart_discount_code($items = array()) {
574 574
     $invoice = wpinv_get_invoice_cart();
575
-    $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : '';
575
+    $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : '';
576 576
     
577
-    return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code );
577
+    return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code);
578 578
 }
579 579
 
580
-function wpinv_cart_discount_code( $items = array(), $echo = false ) {
581
-    $cart_discount_code = wpinv_get_cart_discount_code( $items );
580
+function wpinv_cart_discount_code($items = array(), $echo = false) {
581
+    $cart_discount_code = wpinv_get_cart_discount_code($items);
582 582
 
583
-    if ( $cart_discount_code != '' ) {
583
+    if ($cart_discount_code != '') {
584 584
         $cart_discount_code = ' (' . $cart_discount_code . ')';
585 585
     }
586 586
     
587
-    $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items );
587
+    $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items);
588 588
 
589
-    if ( !$echo ) {
589
+    if (!$echo) {
590 590
         return $discount_code;
591 591
     }
592 592
 
593 593
     echo $discount_code;
594 594
 }
595 595
 
596
-function wpinv_get_cart_discount( $items = array() ) {
596
+function wpinv_get_cart_discount($items = array()) {
597 597
     $invoice = wpinv_get_invoice_cart();
598
-    $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0;
598
+    $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0;
599 599
     
600
-    return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items );
600
+    return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items);
601 601
 }
602 602
 
603
-function wpinv_cart_discount( $items = array(), $echo = false ) {
604
-    $cart_discount = wpinv_get_cart_discount( $items );
605
-    $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) );
603
+function wpinv_cart_discount($items = array(), $echo = false) {
604
+    $cart_discount = wpinv_get_cart_discount($items);
605
+    $cart_discount = wpinv_price(wpinv_format_amount($cart_discount));
606 606
 
607
-    $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items );
607
+    $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items);
608 608
 
609
-    if ( !$echo ) {
609
+    if (!$echo) {
610 610
         return $discount;
611 611
     }
612 612
 
613 613
     echo $discount;
614 614
 }
615 615
 
616
-function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) {
617
-    $item = new WPInv_Item( $item_id );
616
+function wpinv_get_cart_fees($type = 'all', $item_id = 0) {
617
+    $item = new WPInv_Item($item_id);
618 618
     
619
-    return $item->get_fees( $type, $item_id );
619
+    return $item->get_fees($type, $item_id);
620 620
 }
621 621
 
622 622
 function wpinv_get_cart_fee_total() {
623
-    $total  = 0;
623
+    $total = 0;
624 624
     $fees = wpinv_get_cart_fees();
625 625
     
626
-    if ( $fees ) {
627
-        foreach ( $fees as $fee_id => $fee ) {
626
+    if ($fees) {
627
+        foreach ($fees as $fee_id => $fee) {
628 628
             $total += $fee['amount'];
629 629
         }
630 630
     }
631 631
 
632
-    return apply_filters( 'wpinv_get_cart_fee_total', $total );
632
+    return apply_filters('wpinv_get_cart_fee_total', $total);
633 633
 }
634 634
 
635 635
 function wpinv_get_cart_fee_tax() {
636 636
     $tax  = 0;
637 637
     $fees = wpinv_get_cart_fees();
638 638
 
639
-    if ( $fees ) {
640
-        foreach ( $fees as $fee_id => $fee ) {
641
-            if( ! empty( $fee['no_tax'] ) ) {
639
+    if ($fees) {
640
+        foreach ($fees as $fee_id => $fee) {
641
+            if (!empty($fee['no_tax'])) {
642 642
                 continue;
643 643
             }
644 644
 
645
-            $tax += wpinv_calculate_tax( $fee['amount'] );
645
+            $tax += wpinv_calculate_tax($fee['amount']);
646 646
         }
647 647
     }
648 648
 
649
-    return apply_filters( 'wpinv_get_cart_fee_tax', $tax );
649
+    return apply_filters('wpinv_get_cart_fee_tax', $tax);
650 650
 }
651 651
 
652 652
 function wpinv_cart_has_recurring_item() {
653 653
     $cart_items = wpinv_get_cart_contents();
654 654
     
655
-    if ( empty( $cart_items ) ) {
655
+    if (empty($cart_items)) {
656 656
         return false;
657 657
     }
658 658
     
659 659
     $has_subscription = false;
660
-    foreach( $cart_items as $cart_item ) {
661
-        if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
660
+    foreach ($cart_items as $cart_item) {
661
+        if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
662 662
             $has_subscription = true;
663 663
             break;
664 664
         }
665 665
     }
666 666
     
667
-    return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items );
667
+    return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items);
668 668
 }
669 669
 
670 670
 function wpinv_cart_has_free_trial() {
@@ -672,86 +672,86 @@  discard block
 block discarded – undo
672 672
     
673 673
     $free_trial = false;
674 674
     
675
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
675
+    if (!empty($invoice) && $invoice->is_free_trial()) {
676 676
         $free_trial = true;
677 677
     }
678 678
     
679
-    return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice );
679
+    return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice);
680 680
 }
681 681
 
682 682
 function wpinv_get_cart_contents() {
683 683
     $cart_details = wpinv_get_cart_details();
684 684
     
685
-    return apply_filters( 'wpinv_get_cart_contents', $cart_details );
685
+    return apply_filters('wpinv_get_cart_contents', $cart_details);
686 686
 }
687 687
 
688 688
 function wpinv_get_cart_content_details() {
689 689
     global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
690 690
     $cart_items = wpinv_get_cart_contents();
691 691
     
692
-    if ( empty( $cart_items ) ) {
692
+    if (empty($cart_items)) {
693 693
         return false;
694 694
     }
695 695
     $invoice = wpinv_get_invoice_cart();
696 696
 
697 697
     $details = array();
698
-    $length  = count( $cart_items ) - 1;
698
+    $length  = count($cart_items) - 1;
699 699
     
700
-    if ( empty( $_POST['country'] ) ) {
700
+    if (empty($_POST['country'])) {
701 701
         $_POST['country'] = $invoice->country;
702 702
     }
703
-    if ( !isset( $_POST['state'] ) ) {
703
+    if (!isset($_POST['state'])) {
704 704
         $_POST['state'] = $invoice->state;
705 705
     }
706 706
 
707
-    foreach( $cart_items as $key => $item ) {
708
-        $item_id            = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '';
709
-        if ( empty( $item_id ) ) {
707
+    foreach ($cart_items as $key => $item) {
708
+        $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : '';
709
+        if (empty($item_id)) {
710 710
             continue;
711 711
         }
712 712
         
713 713
         $wpi_current_id         = $invoice->ID;
714 714
         $wpi_item_id            = $item_id;
715 715
         
716
-        $item_price         = wpinv_get_item_price( $item_id );
717
-        $discount           = wpinv_get_cart_item_discount_amount( $item );
718
-        $discount           = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item );
719
-        $quantity           = wpinv_get_cart_item_quantity( $item );
720
-        $fees               = wpinv_get_cart_fees( 'fee', $item_id );
716
+        $item_price         = wpinv_get_item_price($item_id);
717
+        $discount           = wpinv_get_cart_item_discount_amount($item);
718
+        $discount           = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item);
719
+        $quantity           = wpinv_get_cart_item_quantity($item);
720
+        $fees               = wpinv_get_cart_fees('fee', $item_id);
721 721
         
722 722
         $subtotal           = $item_price * $quantity;
723
-        $tax_rate           = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id );
724
-        $tax_class          = $wpinv_euvat->get_item_class( $item_id );
725
-        $tax                = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount );
723
+        $tax_rate           = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id);
724
+        $tax_class          = $wpinv_euvat->get_item_class($item_id);
725
+        $tax                = wpinv_get_cart_item_tax($item_id, $subtotal - $discount);
726 726
         
727
-        if ( wpinv_prices_include_tax() ) {
728
-            $subtotal -= wpinv_round_amount( $tax );
727
+        if (wpinv_prices_include_tax()) {
728
+            $subtotal -= wpinv_round_amount($tax);
729 729
         }
730 730
         
731
-        $total              = $subtotal - $discount + $tax;
731
+        $total = $subtotal - $discount + $tax;
732 732
         
733 733
         // Do not allow totals to go negatve
734
-        if( $total < 0 ) {
734
+        if ($total < 0) {
735 735
             $total = 0;
736 736
         }
737 737
         
738
-        $details[ $key ]  = array(
738
+        $details[$key] = array(
739 739
             'id'                => $item_id,
740
-            'name'              => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ),
741
-            'item_price'        => wpinv_round_amount( $item_price ),
742
-            'custom_price'      => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
740
+            'name'              => !empty($item['name']) ? $item['name'] : get_the_title($item_id),
741
+            'item_price'        => wpinv_round_amount($item_price),
742
+            'custom_price'      => isset($item['custom_price']) ? $item['custom_price'] : '',
743 743
             'quantity'          => $quantity,
744
-            'discount'          => wpinv_round_amount( $discount ),
745
-            'subtotal'          => wpinv_round_amount( $subtotal ),
746
-            'tax'               => wpinv_round_amount( $tax ),
747
-            'price'             => wpinv_round_amount( $total ),
744
+            'discount'          => wpinv_round_amount($discount),
745
+            'subtotal'          => wpinv_round_amount($subtotal),
746
+            'tax'               => wpinv_round_amount($tax),
747
+            'price'             => wpinv_round_amount($total),
748 748
             'vat_rates_class'   => $tax_class,
749 749
             'vat_rate'          => $tax_rate,
750
-            'meta'              => isset( $item['meta'] ) ? $item['meta'] : array(),
750
+            'meta'              => isset($item['meta']) ? $item['meta'] : array(),
751 751
             'fees'              => $fees,
752 752
         );
753 753
         
754
-        if ( $wpinv_is_last_cart_item ) {
754
+        if ($wpinv_is_last_cart_item) {
755 755
             $wpinv_is_last_cart_item   = false;
756 756
             $wpinv_flat_discount_total = 0.00;
757 757
         }
@@ -760,56 +760,56 @@  discard block
 block discarded – undo
760 760
     return $details;
761 761
 }
762 762
 
763
-function wpinv_get_cart_details( $invoice_id = 0 ) {
763
+function wpinv_get_cart_details($invoice_id = 0) {
764 764
     global $ajax_cart_details;
765 765
 
766
-    $invoice      = wpinv_get_invoice_cart( $invoice_id );
767
-    $cart_details = !empty( $ajax_cart_details ) ? $ajax_cart_details : $invoice->cart_details;
766
+    $invoice      = wpinv_get_invoice_cart($invoice_id);
767
+    $cart_details = !empty($ajax_cart_details) ? $ajax_cart_details : $invoice->cart_details;
768 768
 
769 769
     $invoice_currency = $invoice->currency;
770 770
 
771
-    if ( ! empty( $cart_details ) && is_array( $cart_details ) ) {
772
-        foreach ( $cart_details as $key => $cart_item ) {
773
-            $cart_details[ $key ]['currency'] = $invoice_currency;
771
+    if (!empty($cart_details) && is_array($cart_details)) {
772
+        foreach ($cart_details as $key => $cart_item) {
773
+            $cart_details[$key]['currency'] = $invoice_currency;
774 774
 
775
-            if ( ! isset( $cart_item['subtotal'] ) ) {
776
-                $cart_details[ $key ]['subtotal'] = $cart_item['price'];
775
+            if (!isset($cart_item['subtotal'])) {
776
+                $cart_details[$key]['subtotal'] = $cart_item['price'];
777 777
             }
778 778
         }
779 779
     }
780 780
 
781
-    return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id );
781
+    return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id);
782 782
 }
783 783
 
784
-function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) {
785
-    $invoice    = wpinv_get_invoice( $invoice_id );
784
+function wpinv_record_status_change($invoice_id, $new_status, $old_status) {
785
+    $invoice    = wpinv_get_invoice($invoice_id);
786 786
     
787
-    $old_status = wpinv_status_nicename( $old_status );
788
-    $new_status = wpinv_status_nicename( $new_status );
787
+    $old_status = wpinv_status_nicename($old_status);
788
+    $new_status = wpinv_status_nicename($new_status);
789 789
 
790
-    $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status );
790
+    $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status);
791 791
     
792 792
     // Add note
793
-    return $invoice->add_note( $status_change, 0 );
793
+    return $invoice->add_note($status_change, 0);
794 794
 }
795
-add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 );
795
+add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3);
796 796
 
797
-function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) {
797
+function wpinv_complete_payment($invoice_id, $new_status, $old_status) {
798 798
     global $wpi_has_free_trial;
799 799
     
800 800
     $wpi_has_free_trial = false;
801 801
     
802
-    if ( $old_status == 'publish' ) {
802
+    if ($old_status == 'publish') {
803 803
         return; // Make sure that payments are only paid once
804 804
     }
805 805
 
806 806
     // Make sure the payment completion is only processed when new status is paid
807
-    if ( $new_status != 'publish' ) {
807
+    if ($new_status != 'publish') {
808 808
         return;
809 809
     }
810 810
 
811
-    $invoice = new WPInv_Invoice( $invoice_id );
812
-    if ( empty( $invoice ) ) {
811
+    $invoice = new WPInv_Invoice($invoice_id);
812
+    if (empty($invoice)) {
813 813
         return;
814 814
     }
815 815
 
@@ -817,58 +817,58 @@  discard block
 block discarded – undo
817 817
     $completed_date = $invoice->completed_date;
818 818
     $cart_details   = $invoice->cart_details;
819 819
 
820
-    do_action( 'wpinv_pre_complete_payment', $invoice_id );
820
+    do_action('wpinv_pre_complete_payment', $invoice_id);
821 821
 
822
-    if ( is_array( $cart_details ) ) {
822
+    if (is_array($cart_details)) {
823 823
         // Increase purchase count and earnings
824
-        foreach ( $cart_details as $cart_index => $item ) {
824
+        foreach ($cart_details as $cart_index => $item) {
825 825
             // Ensure these actions only run once, ever
826
-            if ( empty( $completed_date ) ) {
827
-                do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index );
826
+            if (empty($completed_date)) {
827
+                do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index);
828 828
             }
829 829
         }
830 830
     }
831 831
     
832 832
     // Check for discount codes and increment their use counts
833
-    if ( $discounts = $invoice->get_discounts( true ) ) {
834
-        if( ! empty( $discounts ) ) {
835
-            foreach( $discounts as $code ) {
836
-                wpinv_increase_discount_usage( $code );
833
+    if ($discounts = $invoice->get_discounts(true)) {
834
+        if (!empty($discounts)) {
835
+            foreach ($discounts as $code) {
836
+                wpinv_increase_discount_usage($code);
837 837
             }
838 838
         }
839 839
     }
840 840
     
841 841
     // Ensure this action only runs once ever
842
-    if( empty( $completed_date ) ) {
842
+    if (empty($completed_date)) {
843 843
         // Save the completed date
844
-        $invoice->set( 'completed_date', current_time( 'mysql', 0 ) );
844
+        $invoice->set('completed_date', current_time('mysql', 0));
845 845
         $invoice->save();
846 846
 
847
-        do_action( 'wpinv_complete_payment', $invoice_id );
847
+        do_action('wpinv_complete_payment', $invoice_id);
848 848
     }
849 849
 
850 850
     // Empty the shopping cart
851 851
     wpinv_empty_cart();
852 852
 }
853
-add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 );
853
+add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3);
854 854
 
855
-function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) {    
856
-    $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id );
855
+function wpinv_update_payment_status($invoice_id, $new_status = 'publish') {    
856
+    $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int)$invoice_id);
857 857
     
858
-    if ( empty( $invoice ) ) {
858
+    if (empty($invoice)) {
859 859
         return false;
860 860
     }
861 861
     
862
-    return $invoice->update_status( $new_status );
862
+    return $invoice->update_status($new_status);
863 863
 }
864 864
 
865
-function wpinv_cart_has_fees( $type = 'all' ) {
865
+function wpinv_cart_has_fees($type = 'all') {
866 866
     return false;
867 867
 }
868 868
 
869 869
 function wpinv_validate_checkout_fields() {    
870 870
     // Check if there is $_POST
871
-    if ( empty( $_POST ) ) {
871
+    if (empty($_POST)) {
872 872
         return false;
873 873
     }
874 874
     
@@ -880,11 +880,11 @@  discard block
 block discarded – undo
880 880
     );
881 881
     
882 882
     // Validate agree to terms
883
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
883
+    if (wpinv_get_option('show_agree_to_terms', false)) {
884 884
         wpinv_checkout_validate_agree_to_terms();
885 885
     }
886 886
     
887
-    $valid_data['logged_in_user']   = wpinv_checkout_validate_logged_in_user();
887
+    $valid_data['logged_in_user'] = wpinv_checkout_validate_logged_in_user();
888 888
     
889 889
     // Return collected data
890 890
     return $valid_data;
@@ -895,26 +895,26 @@  discard block
 block discarded – undo
895 895
     
896 896
     $invoice = wpinv_get_invoice_cart();
897 897
     $has_subscription = $invoice->is_recurring();
898
-    if ( empty( $invoice ) ) {
899
-        wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) );
898
+    if (empty($invoice)) {
899
+        wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing'));
900 900
         return $gateway;
901 901
     }
902 902
 
903 903
     // Check if a gateway value is present
904
-    if ( !empty( $_REQUEST['wpi-gateway'] ) ) {
905
-        $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] );
904
+    if (!empty($_REQUEST['wpi-gateway'])) {
905
+        $gateway = sanitize_text_field($_REQUEST['wpi-gateway']);
906 906
 
907
-        if ( $invoice->is_free() ) {
907
+        if ($invoice->is_free()) {
908 908
             $gateway = 'manual';
909
-        } elseif ( !wpinv_is_gateway_active( $gateway ) ) {
910
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) );
911
-        } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) {
912
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) );
909
+        } elseif (!wpinv_is_gateway_active($gateway)) {
910
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing'));
911
+        } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) {
912
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing'));
913 913
         }
914 914
     }
915 915
 
916
-    if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) {
917
-        wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) );
916
+    if ($has_subscription && count(wpinv_get_cart_contents()) > 1) {
917
+        wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing'));
918 918
     }
919 919
 
920 920
     return $gateway;
@@ -926,10 +926,10 @@  discard block
 block discarded – undo
926 926
     
927 927
     $error = false;
928 928
     // If we have discounts, loop through them
929
-    if ( ! empty( $discounts ) ) {
930
-        foreach ( $discounts as $discount ) {
929
+    if (!empty($discounts)) {
930
+        foreach ($discounts as $discount) {
931 931
             // Check if valid
932
-            if (  !wpinv_is_discount_valid( $discount, get_current_user_id() ) ) {
932
+            if (!wpinv_is_discount_valid($discount, get_current_user_id())) {
933 933
                 // Discount is not valid
934 934
                 $error = true;
935 935
             }
@@ -939,20 +939,20 @@  discard block
 block discarded – undo
939 939
         return NULL;
940 940
     }
941 941
 
942
-    if ( $error && !wpinv_get_errors() ) {
943
-        wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) );
942
+    if ($error && !wpinv_get_errors()) {
943
+        wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing'));
944 944
     }
945 945
 
946
-    return implode( ',', $discounts );
946
+    return implode(',', $discounts);
947 947
 }
948 948
 
949 949
 function wpinv_checkout_validate_cc() {
950 950
     $card_data = wpinv_checkout_get_cc_info();
951 951
 
952 952
     // Validate the card zip
953
-    if ( !empty( $card_data['wpinv_zip'] ) ) {
954
-        if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) {
955
-            wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) );
953
+    if (!empty($card_data['wpinv_zip'])) {
954
+        if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) {
955
+            wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing'));
956 956
         }
957 957
     }
958 958
 
@@ -962,28 +962,28 @@  discard block
 block discarded – undo
962 962
 
963 963
 function wpinv_checkout_get_cc_info() {
964 964
 	$cc_info = array();
965
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
966
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
967
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
968
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
969
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
970
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
971
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
972
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
973
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
974
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
965
+	$cc_info['card_name']      = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : '';
966
+	$cc_info['card_number']    = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : '';
967
+	$cc_info['card_cvc']       = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : '';
968
+	$cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : '';
969
+	$cc_info['card_exp_year']  = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : '';
970
+	$cc_info['card_address']   = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : '';
971
+	$cc_info['card_city']      = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : '';
972
+	$cc_info['card_state']     = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : '';
973
+	$cc_info['card_country']   = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : '';
974
+	$cc_info['card_zip']       = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : '';
975 975
 
976 976
 	// Return cc info
977 977
 	return $cc_info;
978 978
 }
979 979
 
980
-function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
980
+function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') {
981 981
     $ret = false;
982 982
 
983
-    if ( empty( $zip ) || empty( $country_code ) )
983
+    if (empty($zip) || empty($country_code))
984 984
         return $ret;
985 985
 
986
-    $country_code = strtoupper( $country_code );
986
+    $country_code = strtoupper($country_code);
987 987
 
988 988
     $zip_regex = array(
989 989
         "AD" => "AD\d{3}",
@@ -1143,17 +1143,17 @@  discard block
 block discarded – undo
1143 1143
         "ZM" => "\d{5}"
1144 1144
     );
1145 1145
 
1146
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
1146
+    if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip))
1147 1147
         $ret = true;
1148 1148
 
1149
-    return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
1149
+    return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code);
1150 1150
 }
1151 1151
 
1152 1152
 function wpinv_checkout_validate_agree_to_terms() {
1153 1153
     // Validate agree to terms
1154
-    if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) {
1154
+    if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) {
1155 1155
         // User did not agree
1156
-        wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) );
1156
+        wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing')));
1157 1157
     }
1158 1158
 }
1159 1159
 
@@ -1166,36 +1166,36 @@  discard block
 block discarded – undo
1166 1166
     );
1167 1167
     
1168 1168
     // Verify there is a user_ID
1169
-    if ( $user_ID > 0 ) {
1169
+    if ($user_ID > 0) {
1170 1170
         // Get the logged in user data
1171
-        $user_data = get_userdata( $user_ID );
1172
-        $required_fields  = wpinv_checkout_required_fields();
1171
+        $user_data = get_userdata($user_ID);
1172
+        $required_fields = wpinv_checkout_required_fields();
1173 1173
 
1174 1174
         // Loop through required fields and show error messages
1175
-         if ( !empty( $required_fields ) ) {
1176
-            foreach ( $required_fields as $field_name => $value ) {
1177
-                if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
1178
-                    wpinv_set_error( $value['error_id'], $value['error_message'] );
1175
+         if (!empty($required_fields)) {
1176
+            foreach ($required_fields as $field_name => $value) {
1177
+                if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) {
1178
+                    wpinv_set_error($value['error_id'], $value['error_message']);
1179 1179
                 }
1180 1180
             }
1181 1181
         }
1182 1182
 
1183 1183
         // Verify data
1184
-        if ( $user_data ) {
1184
+        if ($user_data) {
1185 1185
             // Collected logged in user data
1186 1186
             $valid_user_data = array(
1187 1187
                 'user_id'     => $user_ID,
1188
-                'email'       => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email,
1189
-                'first_name'  => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name,
1190
-                'last_name'   => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name']  ) ? sanitize_text_field( $_POST['wpinv_last_name']  ) : $user_data->last_name,
1188
+                'email'       => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email,
1189
+                'first_name'  => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name,
1190
+                'last_name'   => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name,
1191 1191
             );
1192 1192
 
1193
-            if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) {
1194
-                wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) );
1193
+            if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) {
1194
+                wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing'));
1195 1195
             }
1196 1196
         } else {
1197 1197
             // Set invalid user error
1198
-            wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) );
1198
+            wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing'));
1199 1199
         }
1200 1200
     }
1201 1201
 
@@ -1203,21 +1203,21 @@  discard block
 block discarded – undo
1203 1203
     return $valid_user_data;
1204 1204
 }
1205 1205
 
1206
-function wpinv_checkout_form_get_user( $valid_data = array() ) {
1206
+function wpinv_checkout_form_get_user($valid_data = array()) {
1207 1207
     // Initialize user
1208 1208
     $user    = false;
1209
-    $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
1209
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1210 1210
 
1211 1211
     /*if ( $is_ajax ) {
1212 1212
         // Do not create or login the user during the ajax submission (check for errors only)
1213 1213
         return true;
1214
-    } else */if ( is_user_logged_in() ) {
1214
+    } else */if (is_user_logged_in()) {
1215 1215
         // Set the valid user as the logged in collected data
1216 1216
         $user = $valid_data['logged_in_user'];
1217 1217
     }
1218 1218
 
1219 1219
     // Verify we have an user
1220
-    if ( false === $user || empty( $user ) ) {
1220
+    if (false === $user || empty($user)) {
1221 1221
         // Return false
1222 1222
         return false;
1223 1223
     }
@@ -1236,11 +1236,11 @@  discard block
 block discarded – undo
1236 1236
         'zip',
1237 1237
     );
1238 1238
     
1239
-    foreach ( $address_fields as $field ) {
1240
-        $user[$field]  = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false;
1239
+    foreach ($address_fields as $field) {
1240
+        $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false;
1241 1241
         
1242
-        if ( !empty( $user['user_id'] ) ) {
1243
-            update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] );
1242
+        if (!empty($user['user_id'])) {
1243
+            update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]);
1244 1244
         }
1245 1245
     }
1246 1246
 
@@ -1248,28 +1248,28 @@  discard block
 block discarded – undo
1248 1248
     return $user;
1249 1249
 }
1250 1250
 
1251
-function wpinv_set_checkout_session( $invoice_data = array() ) {
1251
+function wpinv_set_checkout_session($invoice_data = array()) {
1252 1252
     global $wpi_session;
1253 1253
     
1254
-    return $wpi_session->set( 'wpinv_checkout', $invoice_data );
1254
+    return $wpi_session->set('wpinv_checkout', $invoice_data);
1255 1255
 }
1256 1256
 
1257 1257
 function wpinv_get_checkout_session() {
1258 1258
 	global $wpi_session;
1259 1259
     
1260
-    return $wpi_session->get( 'wpinv_checkout' );
1260
+    return $wpi_session->get('wpinv_checkout');
1261 1261
 }
1262 1262
 
1263 1263
 function wpinv_empty_cart() {
1264 1264
     global $wpi_session;
1265 1265
 
1266 1266
     // Remove cart contents
1267
-    $wpi_session->set( 'wpinv_checkout', NULL );
1267
+    $wpi_session->set('wpinv_checkout', NULL);
1268 1268
 
1269 1269
     // Remove all cart fees
1270
-    $wpi_session->set( 'wpi_cart_fees', NULL );
1270
+    $wpi_session->set('wpi_cart_fees', NULL);
1271 1271
 
1272
-    do_action( 'wpinv_empty_cart' );
1272
+    do_action('wpinv_empty_cart');
1273 1273
 }
1274 1274
 
1275 1275
 function wpinv_process_checkout() {
@@ -1281,42 +1281,42 @@  discard block
 block discarded – undo
1281 1281
     
1282 1282
     $wpi_checkout_id = $invoice->ID;
1283 1283
     
1284
-    do_action( 'wpinv_pre_process_checkout' );
1284
+    do_action('wpinv_pre_process_checkout');
1285 1285
     
1286
-    if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty
1286
+    if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty
1287 1287
         $valid_data = false;
1288
-        wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) );
1288
+        wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing'));
1289 1289
     } else {
1290 1290
         // Validate the form $_POST data
1291 1291
         $valid_data = wpinv_validate_checkout_fields();
1292 1292
         
1293 1293
         // Allow themes and plugins to hook to errors
1294
-        do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST );
1294
+        do_action('wpinv_checkout_error_checks', $valid_data, $_POST);
1295 1295
     }
1296 1296
     
1297
-    $is_ajax    = defined( 'DOING_AJAX' ) && DOING_AJAX;
1297
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1298 1298
     
1299 1299
     // Validate the user
1300
-    $user = wpinv_checkout_form_get_user( $valid_data );
1300
+    $user = wpinv_checkout_form_get_user($valid_data);
1301 1301
 
1302 1302
     // Let extensions validate fields after user is logged in if user has used login/registration form
1303
-    do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST );
1303
+    do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST);
1304 1304
     
1305
-    if ( false === $valid_data || wpinv_get_errors() || ! $user ) {
1306
-        if ( $is_ajax ) {
1307
-            do_action( 'wpinv_ajax_checkout_errors' );
1305
+    if (false === $valid_data || wpinv_get_errors() || !$user) {
1306
+        if ($is_ajax) {
1307
+            do_action('wpinv_ajax_checkout_errors');
1308 1308
             die();
1309 1309
         } else {
1310 1310
             return false;
1311 1311
         }
1312 1312
     }
1313 1313
 
1314
-    if ( $is_ajax ) {
1314
+    if ($is_ajax) {
1315 1315
         // Save address fields.
1316
-        $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' );
1317
-        foreach ( $address_fields as $field ) {
1318
-            if ( isset( $user[$field] ) ) {
1319
-                $invoice->set( $field, $user[$field] );
1316
+        $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company');
1317
+        foreach ($address_fields as $field) {
1318
+            if (isset($user[$field])) {
1319
+                $invoice->set($field, $user[$field]);
1320 1320
             }
1321 1321
             
1322 1322
             $invoice->save();
@@ -1324,15 +1324,15 @@  discard block
 block discarded – undo
1324 1324
 
1325 1325
         $response['success']            = true;
1326 1326
         $response['data']['subtotal']   = $invoice->get_subtotal();
1327
-        $response['data']['subtotalf']  = $invoice->get_subtotal( true );
1327
+        $response['data']['subtotalf']  = $invoice->get_subtotal(true);
1328 1328
         $response['data']['discount']   = $invoice->get_discount();
1329
-        $response['data']['discountf']  = $invoice->get_discount( true );
1329
+        $response['data']['discountf']  = $invoice->get_discount(true);
1330 1330
         $response['data']['tax']        = $invoice->get_tax();
1331
-        $response['data']['taxf']       = $invoice->get_tax( true );
1331
+        $response['data']['taxf']       = $invoice->get_tax(true);
1332 1332
         $response['data']['total']      = $invoice->get_total();
1333
-        $response['data']['totalf']     = $invoice->get_total( true );
1333
+        $response['data']['totalf']     = $invoice->get_total(true);
1334 1334
         
1335
-        wp_send_json( $response );
1335
+        wp_send_json($response);
1336 1336
     }
1337 1337
     
1338 1338
     $user_info = array(
@@ -1354,42 +1354,42 @@  discard block
 block discarded – undo
1354 1354
     
1355 1355
     // Setup invoice information
1356 1356
     $invoice_data = array(
1357
-        'invoice_id'        => !empty( $invoice ) ? $invoice->ID : 0,
1357
+        'invoice_id'        => !empty($invoice) ? $invoice->ID : 0,
1358 1358
         'items'             => $cart_items,
1359 1359
         'cart_discounts'    => $discounts,
1360
-        'fees'              => wpinv_get_cart_fees(),        // Any arbitrary fees that have been added to the cart
1361
-        'subtotal'          => wpinv_get_cart_subtotal( $cart_items ),    // Amount before taxes and discounts
1362
-        'discount'          => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount
1363
-        'tax'               => wpinv_get_cart_tax( $cart_items ),               // Taxed amount
1364
-        'price'             => wpinv_get_cart_total( $cart_items, $discounts ),    // Amount after taxes
1360
+        'fees'              => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart
1361
+        'subtotal'          => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts
1362
+        'discount'          => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount
1363
+        'tax'               => wpinv_get_cart_tax($cart_items), // Taxed amount
1364
+        'price'             => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes
1365 1365
         'invoice_key'       => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(),
1366 1366
         'user_email'        => $user['email'],
1367
-        'date'              => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
1368
-        'user_info'         => stripslashes_deep( $user_info ),
1367
+        'date'              => date('Y-m-d H:i:s', current_time('timestamp')),
1368
+        'user_info'         => stripslashes_deep($user_info),
1369 1369
         'post_data'         => $_POST,
1370 1370
         'cart_details'      => $cart_items,
1371 1371
         'gateway'           => $valid_data['gateway'],
1372 1372
         'card_info'         => $valid_data['cc_info']
1373 1373
     );
1374 1374
     
1375
-    $vat_info   = $wpinv_euvat->current_vat_data();
1376
-    if ( is_array( $vat_info ) ) {
1375
+    $vat_info = $wpinv_euvat->current_vat_data();
1376
+    if (is_array($vat_info)) {
1377 1377
         $invoice_data['user_info']['vat_number']        = $vat_info['number'];
1378 1378
         $invoice_data['user_info']['vat_rate']          = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']);
1379
-        $invoice_data['user_info']['adddress_confirmed']    = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1379
+        $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1380 1380
 
1381 1381
         // Add the VAT rate to each item in the cart
1382
-        foreach( $invoice_data['cart_details'] as $key => $item_data) {
1382
+        foreach ($invoice_data['cart_details'] as $key => $item_data) {
1383 1383
             $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']);
1384
-            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 );
1384
+            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4);
1385 1385
         }
1386 1386
     }
1387 1387
     
1388 1388
     // Save vat fields.
1389
-    $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' );
1390
-    foreach ( $address_fields as $field ) {
1391
-        if ( isset( $invoice_data['user_info'][$field] ) ) {
1392
-            $invoice->set( $field, $invoice_data['user_info'][$field] );
1389
+    $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed');
1390
+    foreach ($address_fields as $field) {
1391
+        if (isset($invoice_data['user_info'][$field])) {
1392
+            $invoice->set($field, $invoice_data['user_info'][$field]);
1393 1393
         }
1394 1394
         
1395 1395
         $invoice->save();
@@ -1399,49 +1399,49 @@  discard block
 block discarded – undo
1399 1399
     $valid_data['user'] = $user;
1400 1400
     
1401 1401
     // Allow themes and plugins to hook before the gateway
1402
-    do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data );
1402
+    do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data);
1403 1403
     
1404 1404
     // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice
1405
-    if ( !$invoice_data['price'] ) {
1405
+    if (!$invoice_data['price']) {
1406 1406
         // Revert to manual
1407 1407
         $invoice_data['gateway'] = 'manual';
1408 1408
         $_POST['wpi-gateway'] = 'manual';
1409 1409
     }
1410 1410
     
1411 1411
     // Allow the invoice data to be modified before it is sent to the gateway
1412
-    $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data );
1412
+    $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data);
1413 1413
     
1414 1414
     // Setup the data we're storing in the purchase session
1415 1415
     $session_data = $invoice_data;
1416 1416
     // Make sure credit card numbers are never stored in sessions
1417
-    if ( !empty( $session_data['card_info']['card_number'] ) ) {
1418
-        unset( $session_data['card_info']['card_number'] );
1417
+    if (!empty($session_data['card_info']['card_number'])) {
1418
+        unset($session_data['card_info']['card_number']);
1419 1419
     }
1420 1420
     
1421 1421
     // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data.
1422
-    wpinv_set_checkout_session( $invoice_data );
1422
+    wpinv_set_checkout_session($invoice_data);
1423 1423
     
1424 1424
     // Set gateway
1425
-    $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] );
1426
-    $invoice->update_meta( '_wpinv_mode', ( wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live' ) );
1427
-    $invoice->update_meta( '_wpinv_checkout', true );
1425
+    $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']);
1426
+    $invoice->update_meta('_wpinv_mode', (wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live'));
1427
+    $invoice->update_meta('_wpinv_checkout', true);
1428 1428
     
1429
-    do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data );
1429
+    do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data);
1430 1430
 
1431 1431
     // Send info to the gateway for payment processing
1432
-    wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data );
1432
+    wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data);
1433 1433
     die();
1434 1434
 }
1435
-add_action( 'wpinv_payment', 'wpinv_process_checkout' );
1435
+add_action('wpinv_payment', 'wpinv_process_checkout');
1436 1436
 
1437
-function wpinv_get_invoices( $args ) {
1438
-    $args = wp_parse_args( $args, array(
1439
-        'status'   => array_keys( wpinv_get_invoice_statuses() ),
1437
+function wpinv_get_invoices($args) {
1438
+    $args = wp_parse_args($args, array(
1439
+        'status'   => array_keys(wpinv_get_invoice_statuses()),
1440 1440
         'type'     => 'wpi_invoice',
1441 1441
         'parent'   => null,
1442 1442
         'user'     => null,
1443 1443
         'email'    => '',
1444
-        'limit'    => get_option( 'posts_per_page' ),
1444
+        'limit'    => get_option('posts_per_page'),
1445 1445
         'offset'   => null,
1446 1446
         'page'     => 1,
1447 1447
         'exclude'  => array(),
@@ -1449,7 +1449,7 @@  discard block
 block discarded – undo
1449 1449
         'order'    => 'DESC',
1450 1450
         'return'   => 'objects',
1451 1451
         'paginate' => false,
1452
-    ) );
1452
+    ));
1453 1453
     
1454 1454
     // Handle some BW compatibility arg names where wp_query args differ in naming.
1455 1455
     $map_legacy = array(
@@ -1462,18 +1462,18 @@  discard block
 block discarded – undo
1462 1462
         'paged'          => 'page',
1463 1463
     );
1464 1464
 
1465
-    foreach ( $map_legacy as $from => $to ) {
1466
-        if ( isset( $args[ $from ] ) ) {
1467
-            $args[ $to ] = $args[ $from ];
1465
+    foreach ($map_legacy as $from => $to) {
1466
+        if (isset($args[$from])) {
1467
+            $args[$to] = $args[$from];
1468 1468
         }
1469 1469
     }
1470 1470
     
1471
-    if ( get_query_var( 'paged' ) )
1471
+    if (get_query_var('paged'))
1472 1472
         $args['page'] = get_query_var('paged');
1473
-    else if ( get_query_var( 'page' ) )
1474
-        $args['page'] = get_query_var( 'page' );
1475
-    else if ( !empty( $args[ 'page' ] ) )
1476
-        $args['page'] = $args[ 'page' ];
1473
+    else if (get_query_var('page'))
1474
+        $args['page'] = get_query_var('page');
1475
+    else if (!empty($args['page']))
1476
+        $args['page'] = $args['page'];
1477 1477
     else
1478 1478
         $args['page'] = 1;
1479 1479
 
@@ -1486,47 +1486,47 @@  discard block
 block discarded – undo
1486 1486
         'post_status'    => $args['status'],
1487 1487
         'posts_per_page' => $args['limit'],
1488 1488
         'meta_query'     => array(),
1489
-        'date_query'     => !empty( $args['date_query'] ) ? $args['date_query'] : array(),
1489
+        'date_query'     => !empty($args['date_query']) ? $args['date_query'] : array(),
1490 1490
         'fields'         => 'ids',
1491 1491
         'orderby'        => $args['orderby'],
1492 1492
         'order'          => $args['order'],
1493 1493
     );
1494 1494
     
1495
-    if ( !empty( $args['user'] ) ) {
1496
-        $wp_query_args['author'] = absint( $args['user'] );
1495
+    if (!empty($args['user'])) {
1496
+        $wp_query_args['author'] = absint($args['user']);
1497 1497
     }
1498 1498
 
1499
-    if ( ! is_null( $args['parent'] ) ) {
1500
-        $wp_query_args['post_parent'] = absint( $args['parent'] );
1499
+    if (!is_null($args['parent'])) {
1500
+        $wp_query_args['post_parent'] = absint($args['parent']);
1501 1501
     }
1502 1502
 
1503
-    if ( ! is_null( $args['offset'] ) ) {
1504
-        $wp_query_args['offset'] = absint( $args['offset'] );
1503
+    if (!is_null($args['offset'])) {
1504
+        $wp_query_args['offset'] = absint($args['offset']);
1505 1505
     } else {
1506
-        $wp_query_args['paged'] = absint( $args['page'] );
1506
+        $wp_query_args['paged'] = absint($args['page']);
1507 1507
     }
1508 1508
 
1509
-    if ( ! empty( $args['exclude'] ) ) {
1510
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
1509
+    if (!empty($args['exclude'])) {
1510
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
1511 1511
     }
1512 1512
 
1513
-    if ( ! $args['paginate' ] ) {
1513
+    if (!$args['paginate']) {
1514 1514
         $wp_query_args['no_found_rows'] = true;
1515 1515
     }
1516 1516
 
1517 1517
     // Get results.
1518
-    $invoices = new WP_Query( $wp_query_args );
1518
+    $invoices = new WP_Query($wp_query_args);
1519 1519
 
1520
-    if ( 'objects' === $args['return'] ) {
1521
-        $return = array_map( 'wpinv_get_invoice', $invoices->posts );
1522
-    } elseif ( 'self' === $args['return'] ) {
1520
+    if ('objects' === $args['return']) {
1521
+        $return = array_map('wpinv_get_invoice', $invoices->posts);
1522
+    } elseif ('self' === $args['return']) {
1523 1523
         return $invoices;
1524 1524
     } else {
1525 1525
         $return = $invoices->posts;
1526 1526
     }
1527 1527
 
1528
-    if ( $args['paginate' ] ) {
1529
-        return (object) array(
1528
+    if ($args['paginate']) {
1529
+        return (object)array(
1530 1530
             'invoices'      => $return,
1531 1531
             'total'         => $invoices->found_posts,
1532 1532
             'max_num_pages' => $invoices->max_num_pages,
@@ -1538,21 +1538,21 @@  discard block
 block discarded – undo
1538 1538
 
1539 1539
 function wpinv_get_user_invoices_columns() {
1540 1540
     $columns = array(
1541
-            'invoice-number'  => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ),
1542
-            'invoice-date'    => array( 'title' => __( 'Date', 'invoicing' ), 'class' => 'text-left' ),
1543
-            'invoice-status'  => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ),
1544
-            'invoice-total'   => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ),
1545
-            'invoice-actions' => array( 'title' => '&nbsp;', 'class' => 'text-center' ),
1541
+            'invoice-number'  => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'),
1542
+            'invoice-date'    => array('title' => __('Date', 'invoicing'), 'class' => 'text-left'),
1543
+            'invoice-status'  => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'),
1544
+            'invoice-total'   => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'),
1545
+            'invoice-actions' => array('title' => '&nbsp;', 'class' => 'text-center'),
1546 1546
         );
1547 1547
 
1548
-    return apply_filters( 'wpinv_user_invoices_columns', $columns );
1548
+    return apply_filters('wpinv_user_invoices_columns', $columns);
1549 1549
 }
1550 1550
 
1551
-function wpinv_payment_receipt( $atts, $content = null ) {
1551
+function wpinv_payment_receipt($atts, $content = null) {
1552 1552
     global $wpinv_receipt_args;
1553 1553
 
1554
-    $wpinv_receipt_args = shortcode_atts( array(
1555
-        'error'           => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ),
1554
+    $wpinv_receipt_args = shortcode_atts(array(
1555
+        'error'           => __('Sorry, trouble retrieving payment receipt.', 'invoicing'),
1556 1556
         'price'           => true,
1557 1557
         'discount'        => true,
1558 1558
         'items'           => true,
@@ -1561,185 +1561,185 @@  discard block
 block discarded – undo
1561 1561
         'invoice_key'     => false,
1562 1562
         'payment_method'  => true,
1563 1563
         'invoice_id'      => true
1564
-    ), $atts, 'wpinv_receipt' );
1564
+    ), $atts, 'wpinv_receipt');
1565 1565
 
1566 1566
     $session = wpinv_get_checkout_session();
1567
-    if ( isset( $_GET['invoice_key'] ) ) {
1568
-        $invoice_key = urldecode( $_GET['invoice_key'] );
1569
-    } else if ( $session && isset( $session['invoice_key'] ) ) {
1567
+    if (isset($_GET['invoice_key'])) {
1568
+        $invoice_key = urldecode($_GET['invoice_key']);
1569
+    } else if ($session && isset($session['invoice_key'])) {
1570 1570
         $invoice_key = $session['invoice_key'];
1571
-    } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) {
1571
+    } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) {
1572 1572
         $invoice_key = $wpinv_receipt_args['invoice_key'];
1573
-    } else if ( isset( $_GET['invoice-id'] ) ) {
1574
-        $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] );
1573
+    } else if (isset($_GET['invoice-id'])) {
1574
+        $invoice_key = wpinv_get_payment_key((int)$_GET['invoice-id']);
1575 1575
     }
1576 1576
 
1577 1577
     // No key found
1578
-    if ( ! isset( $invoice_key ) ) {
1578
+    if (!isset($invoice_key)) {
1579 1579
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1580 1580
     }
1581 1581
 
1582
-    $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1583
-    $user_can_view = wpinv_can_view_receipt( $invoice_key );
1584
-    if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1582
+    $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1583
+    $user_can_view = wpinv_can_view_receipt($invoice_key);
1584
+    if ($user_can_view && isset($_GET['invoice-id'])) {
1585 1585
         $invoice_id     = (int)$_GET['invoice-id'];
1586
-        $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1586
+        $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1587 1587
     }
1588 1588
 
1589 1589
     // Key was provided, but user is logged out. Offer them the ability to login and view the receipt
1590
-    if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) {
1590
+    if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) {
1591 1591
         // login redirect
1592
-        return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>';
1592
+        return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>';
1593 1593
     }
1594 1594
 
1595
-    if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) {
1595
+    if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) {
1596 1596
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1597 1597
     }
1598 1598
 
1599 1599
     ob_start();
1600 1600
 
1601
-    wpinv_get_template_part( 'wpinv-invoice-receipt' );
1601
+    wpinv_get_template_part('wpinv-invoice-receipt');
1602 1602
 
1603 1603
     $display = ob_get_clean();
1604 1604
 
1605 1605
     return $display;
1606 1606
 }
1607 1607
 
1608
-function wpinv_get_invoice_id_by_key( $key ) {
1608
+function wpinv_get_invoice_id_by_key($key) {
1609 1609
 	global $wpdb;
1610 1610
 
1611
-	$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 ) );
1611
+	$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));
1612 1612
 
1613
-	if ( $invoice_id != NULL )
1613
+	if ($invoice_id != NULL)
1614 1614
 		return $invoice_id;
1615 1615
 
1616 1616
 	return 0;
1617 1617
 }
1618 1618
 
1619
-function wpinv_can_view_receipt( $invoice_key = '' ) {
1619
+function wpinv_can_view_receipt($invoice_key = '') {
1620 1620
 	$return = false;
1621 1621
 
1622
-	if ( empty( $invoice_key ) ) {
1622
+	if (empty($invoice_key)) {
1623 1623
 		return $return;
1624 1624
 	}
1625 1625
 
1626 1626
 	global $wpinv_receipt_args;
1627 1627
 
1628
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1629
-	if ( isset( $_GET['invoice-id'] ) ) {
1630
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1628
+	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key);
1629
+	if (isset($_GET['invoice-id'])) {
1630
+		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? (int)$_GET['invoice-id'] : 0;
1631 1631
 	}
1632 1632
 
1633
-	$user_id = (int) wpinv_get_user_id( $wpinv_receipt_args['id'] );
1634
-    $invoice_meta = wpinv_get_invoice_meta( $wpinv_receipt_args['id'] );
1633
+	$user_id = (int)wpinv_get_user_id($wpinv_receipt_args['id']);
1634
+    $invoice_meta = wpinv_get_invoice_meta($wpinv_receipt_args['id']);
1635 1635
 
1636
-	if ( is_user_logged_in() ) {
1637
-		if ( $user_id === (int) get_current_user_id() ) {
1636
+	if (is_user_logged_in()) {
1637
+		if ($user_id === (int)get_current_user_id()) {
1638 1638
 			$return = true;
1639 1639
 		}
1640 1640
 	}
1641 1641
 
1642 1642
 	$session = wpinv_get_checkout_session();
1643
-	if ( ! empty( $session ) && ! is_user_logged_in() ) {
1644
-		if ( $session['invoice_key'] === $invoice_meta['key'] ) {
1643
+	if (!empty($session) && !is_user_logged_in()) {
1644
+		if ($session['invoice_key'] === $invoice_meta['key']) {
1645 1645
 			$return = true;
1646 1646
 		}
1647 1647
 	}
1648 1648
 
1649
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1649
+	return (bool)apply_filters('wpinv_can_view_receipt', $return, $invoice_key);
1650 1650
 }
1651 1651
 
1652 1652
 function wpinv_pay_for_invoice() {
1653 1653
     global $wpinv_euvat;
1654 1654
     
1655
-    if ( isset( $_GET['invoice_key'] ) ) {
1655
+    if (isset($_GET['invoice_key'])) {
1656 1656
         $checkout_uri   = wpinv_get_checkout_uri();
1657
-        $invoice_key    = sanitize_text_field( $_GET['invoice_key'] );
1657
+        $invoice_key    = sanitize_text_field($_GET['invoice_key']);
1658 1658
         
1659
-        if ( empty( $invoice_key ) ) {
1660
-            wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) );
1661
-            wp_redirect( $checkout_uri );
1659
+        if (empty($invoice_key)) {
1660
+            wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing'));
1661
+            wp_redirect($checkout_uri);
1662 1662
             wpinv_die();
1663 1663
         }
1664 1664
         
1665
-        do_action( 'wpinv_check_pay_for_invoice', $invoice_key );
1665
+        do_action('wpinv_check_pay_for_invoice', $invoice_key);
1666 1666
 
1667
-        $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1668
-        $user_can_view = wpinv_can_view_receipt( $invoice_key );
1669
-        if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1667
+        $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1668
+        $user_can_view = wpinv_can_view_receipt($invoice_key);
1669
+        if ($user_can_view && isset($_GET['invoice-id'])) {
1670 1670
             $invoice_id     = (int)$_GET['invoice-id'];
1671
-            $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1671
+            $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1672 1672
         }
1673 1673
         
1674
-        if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) {
1675
-            if ( $invoice->needs_payment() ) {
1674
+        if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) {
1675
+            if ($invoice->needs_payment()) {
1676 1676
                 $data                   = array();
1677 1677
                 $data['invoice_id']     = $invoice_id;
1678
-                $data['cart_discounts'] = $invoice->get_discounts( true );
1678
+                $data['cart_discounts'] = $invoice->get_discounts(true);
1679 1679
                 
1680
-                wpinv_set_checkout_session( $data );
1680
+                wpinv_set_checkout_session($data);
1681 1681
                 
1682
-                if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1682
+                if (wpinv_get_option('vat_ip_country_default')) {
1683 1683
                     $_POST['country']   = $wpinv_euvat->get_country_by_ip();
1684 1684
                     $_POST['state']     = $_POST['country'] == $invoice->country ? $invoice->state : '';
1685 1685
                     
1686
-                    wpinv_recalculate_tax( true );
1686
+                    wpinv_recalculate_tax(true);
1687 1687
                 }
1688 1688
                 
1689 1689
             } else {
1690 1690
                 $checkout_uri = $invoice->get_view_url();
1691 1691
             }
1692 1692
         } else {
1693
-            wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) );
1693
+            wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing'));
1694 1694
             
1695
-            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
1695
+            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
1696 1696
         }
1697 1697
         
1698
-        wp_redirect( $checkout_uri );
1698
+        wp_redirect($checkout_uri);
1699 1699
         wpinv_die();
1700 1700
     }
1701 1701
 }
1702
-add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' );
1702
+add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice');
1703 1703
 
1704
-function wpinv_handle_pay_via_invoice_link( $invoice_key ) {
1705
-    if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) {
1706
-        if ( $invoice = wpinv_get_invoice( $invoice_id ) ) {
1704
+function wpinv_handle_pay_via_invoice_link($invoice_key) {
1705
+    if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) {
1706
+        if ($invoice = wpinv_get_invoice($invoice_id)) {
1707 1707
             $user_id = $invoice->get_user_id();
1708
-            $secret = sanitize_text_field( $_GET['_wpipay'] );
1708
+            $secret = sanitize_text_field($_GET['_wpipay']);
1709 1709
             
1710
-            if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link
1711
-                $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
1710
+            if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link
1711
+                $redirect_to = remove_query_arg('_wpipay', get_permalink());
1712 1712
                 
1713
-                wpinv_guest_redirect( $redirect_to, $user_id );
1713
+                wpinv_guest_redirect($redirect_to, $user_id);
1714 1714
                 wpinv_die();
1715 1715
             }
1716 1716
         }
1717 1717
     }
1718 1718
 }
1719
-add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' );
1719
+add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link');
1720 1720
 
1721
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
1722
-    $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id;
1721
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
1722
+    $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id;
1723 1723
     
1724
-    if ( empty( $invoice_id ) && $invoice_id > 0 ) {
1724
+    if (empty($invoice_id) && $invoice_id > 0) {
1725 1725
         return false;
1726 1726
     }
1727 1727
     
1728
-    if ( empty( $transaction_id ) ) {
1728
+    if (empty($transaction_id)) {
1729 1729
         $transaction_id = $invoice_id;
1730 1730
     }
1731 1731
 
1732
-    $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id );
1732
+    $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id);
1733 1733
     
1734
-    return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id );
1734
+    return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id);
1735 1735
 }
1736 1736
 
1737
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
1738
-    if ( empty( $status_display ) ) {
1739
-        $status_display = wpinv_status_nicename( $status );
1737
+function wpinv_invoice_status_label($status, $status_display = '') {
1738
+    if (empty($status_display)) {
1739
+        $status_display = wpinv_status_nicename($status);
1740 1740
     }
1741 1741
     
1742
-    switch ( $status ) {
1742
+    switch ($status) {
1743 1743
         case 'publish' :
1744 1744
         case 'wpi-renewal' :
1745 1745
             $class = 'label-success';
@@ -1764,28 +1764,28 @@  discard block
 block discarded – undo
1764 1764
     
1765 1765
     $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>';
1766 1766
     
1767
-    return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display );
1767
+    return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display);
1768 1768
 }
1769 1769
 
1770
-function wpinv_format_invoice_number( $number ) {
1771
-    $padd  = wpinv_get_option( 'invoice_number_padd' );
1770
+function wpinv_format_invoice_number($number) {
1771
+    $padd = wpinv_get_option('invoice_number_padd');
1772 1772
     
1773 1773
     // TODO maintain old invoice numbers if invoice number settings not saved. Should be removed before stable release.
1774
-    if ( $padd === '' || $padd === false || $padd === NULL ) {
1775
-        return wp_sprintf( __( 'WPINV-%d', 'invoicing' ), $number );
1774
+    if ($padd === '' || $padd === false || $padd === NULL) {
1775
+        return wp_sprintf(__('WPINV-%d', 'invoicing'), $number);
1776 1776
     }
1777 1777
     
1778
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
1779
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
1778
+    $prefix  = wpinv_get_option('invoice_number_prefix');
1779
+    $postfix = wpinv_get_option('invoice_number_postfix');
1780 1780
     
1781
-    $padd = absint( $padd );
1782
-    $formatted_number = absint( $number );
1781
+    $padd = absint($padd);
1782
+    $formatted_number = absint($number);
1783 1783
     
1784
-    if ( $padd > 0 ) {
1785
-        $formatted_number = zeroise( $formatted_number, $padd );
1784
+    if ($padd > 0) {
1785
+        $formatted_number = zeroise($formatted_number, $padd);
1786 1786
     }    
1787 1787
 
1788 1788
     $formatted_number = $prefix . $formatted_number . $postfix;
1789 1789
 
1790
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
1790
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
1791 1791
 }
1792 1792
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/register-settings.php 1 patch
Spacing   +477 added lines, -477 removed lines patch added patch discarded remove patch
@@ -1,66 +1,66 @@  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
-function wpinv_get_option( $key = '', $default = false ) {
7
+function wpinv_get_option($key = '', $default = false) {
8 8
     global $wpinv_options;
9 9
 
10
-    $value = isset( $wpinv_options[ $key ] ) ? $wpinv_options[ $key ] : $default;
11
-    $value = apply_filters( 'wpinv_get_option', $value, $key, $default );
10
+    $value = isset($wpinv_options[$key]) ? $wpinv_options[$key] : $default;
11
+    $value = apply_filters('wpinv_get_option', $value, $key, $default);
12 12
 
13
-    return apply_filters( 'wpinv_get_option_' . $key, $value, $key, $default );
13
+    return apply_filters('wpinv_get_option_' . $key, $value, $key, $default);
14 14
 }
15 15
 
16
-function wpinv_update_option( $key = '', $value = false ) {
16
+function wpinv_update_option($key = '', $value = false) {
17 17
     // If no key, exit
18
-    if ( empty( $key ) ) {
18
+    if (empty($key)) {
19 19
         return false;
20 20
     }
21 21
 
22
-    if ( empty( $value ) ) {
23
-        $remove_option = wpinv_delete_option( $key );
22
+    if (empty($value)) {
23
+        $remove_option = wpinv_delete_option($key);
24 24
         return $remove_option;
25 25
     }
26 26
 
27 27
     // First let's grab the current settings
28
-    $options = get_option( 'wpinv_settings' );
28
+    $options = get_option('wpinv_settings');
29 29
 
30 30
     // Let's let devs alter that value coming in
31
-    $value = apply_filters( 'wpinv_update_option', $value, $key );
31
+    $value = apply_filters('wpinv_update_option', $value, $key);
32 32
 
33 33
     // Next let's try to update the value
34
-    $options[ $key ] = $value;
35
-    $did_update = update_option( 'wpinv_settings', $options );
34
+    $options[$key] = $value;
35
+    $did_update = update_option('wpinv_settings', $options);
36 36
 
37 37
     // If it updated, let's update the global variable
38
-    if ( $did_update ) {
38
+    if ($did_update) {
39 39
         global $wpinv_options;
40
-        $wpinv_options[ $key ] = $value;
40
+        $wpinv_options[$key] = $value;
41 41
     }
42 42
 
43 43
     return $did_update;
44 44
 }
45 45
 
46
-function wpinv_delete_option( $key = '' ) {
46
+function wpinv_delete_option($key = '') {
47 47
     // If no key, exit
48
-    if ( empty( $key ) ) {
48
+    if (empty($key)) {
49 49
         return false;
50 50
     }
51 51
 
52 52
     // First let's grab the current settings
53
-    $options = get_option( 'wpinv_settings' );
53
+    $options = get_option('wpinv_settings');
54 54
 
55 55
     // Next let's try to update the value
56
-    if( isset( $options[ $key ] ) ) {
57
-        unset( $options[ $key ] );
56
+    if (isset($options[$key])) {
57
+        unset($options[$key]);
58 58
     }
59 59
 
60
-    $did_update = update_option( 'wpinv_settings', $options );
60
+    $did_update = update_option('wpinv_settings', $options);
61 61
 
62 62
     // If it updated, let's update the global variable
63
-    if ( $did_update ){
63
+    if ($did_update) {
64 64
         global $wpinv_options;
65 65
         $wpinv_options = $options;
66 66
     }
@@ -69,37 +69,37 @@  discard block
 block discarded – undo
69 69
 }
70 70
 
71 71
 function wpinv_get_settings() {
72
-    $settings = get_option( 'wpinv_settings' );
72
+    $settings = get_option('wpinv_settings');
73 73
 
74
-    if ( empty( $settings ) ) {
74
+    if (empty($settings)) {
75 75
         // Update old settings with new single option
76
-        $general_settings   = is_array( get_option( 'wpinv_settings_general' ) )    ? get_option( 'wpinv_settings_general' )    : array();
77
-        $gateways_settings  = is_array( get_option( 'wpinv_settings_gateways' ) )   ? get_option( 'wpinv_settings_gateways' )   : array();
78
-        $email_settings     = is_array( get_option( 'wpinv_settings_emails' ) )     ? get_option( 'wpinv_settings_emails' )     : array();
79
-        $tax_settings       = is_array( get_option( 'wpinv_settings_taxes' ) )      ? get_option( 'wpinv_settings_taxes' )      : array();
80
-        $misc_settings      = is_array( get_option( 'wpinv_settings_misc' ) )       ? get_option( 'wpinv_settings_misc' )       : array();
81
-        $tool_settings      = is_array( get_option( 'wpinv_settings_tools' ) )      ? get_option( 'wpinv_settings_tools' )      : array();
76
+        $general_settings   = is_array(get_option('wpinv_settings_general')) ? get_option('wpinv_settings_general') : array();
77
+        $gateways_settings  = is_array(get_option('wpinv_settings_gateways')) ? get_option('wpinv_settings_gateways') : array();
78
+        $email_settings     = is_array(get_option('wpinv_settings_emails')) ? get_option('wpinv_settings_emails') : array();
79
+        $tax_settings       = is_array(get_option('wpinv_settings_taxes')) ? get_option('wpinv_settings_taxes') : array();
80
+        $misc_settings      = is_array(get_option('wpinv_settings_misc')) ? get_option('wpinv_settings_misc') : array();
81
+        $tool_settings      = is_array(get_option('wpinv_settings_tools')) ? get_option('wpinv_settings_tools') : array();
82 82
 
83
-        $settings = array_merge( $general_settings, $gateways_settings, $tax_settings, $tool_settings );
83
+        $settings = array_merge($general_settings, $gateways_settings, $tax_settings, $tool_settings);
84 84
 
85
-        update_option( 'wpinv_settings', $settings );
85
+        update_option('wpinv_settings', $settings);
86 86
 
87 87
     }
88
-    return apply_filters( 'wpinv_get_settings', $settings );
88
+    return apply_filters('wpinv_get_settings', $settings);
89 89
 }
90 90
 
91 91
 function wpinv_register_settings() {
92
-    if ( false == get_option( 'wpinv_settings' ) ) {
93
-        add_option( 'wpinv_settings' );
92
+    if (false == get_option('wpinv_settings')) {
93
+        add_option('wpinv_settings');
94 94
     }
95 95
     
96 96
     $register_settings = wpinv_get_registered_settings();
97 97
     
98
-    foreach ( $register_settings as $tab => $sections ) {
99
-        foreach ( $sections as $section => $settings) {
98
+    foreach ($register_settings as $tab => $sections) {
99
+        foreach ($sections as $section => $settings) {
100 100
             // Check for backwards compatibility
101
-            $section_tabs = wpinv_get_settings_tab_sections( $tab );
102
-            if ( ! is_array( $section_tabs ) || ! array_key_exists( $section, $section_tabs ) ) {
101
+            $section_tabs = wpinv_get_settings_tab_sections($tab);
102
+            if (!is_array($section_tabs) || !array_key_exists($section, $section_tabs)) {
103 103
                 $section = 'main';
104 104
                 $settings = $sections;
105 105
             }
@@ -111,42 +111,42 @@  discard block
 block discarded – undo
111 111
                 'wpinv_settings_' . $tab . '_' . $section
112 112
             );
113 113
 
114
-            foreach ( $settings as $option ) {
114
+            foreach ($settings as $option) {
115 115
                 // For backwards compatibility
116
-                if ( empty( $option['id'] ) ) {
116
+                if (empty($option['id'])) {
117 117
                     continue;
118 118
                 }
119 119
 
120
-                $name = isset( $option['name'] ) ? $option['name'] : '';
120
+                $name = isset($option['name']) ? $option['name'] : '';
121 121
 
122 122
                 add_settings_field(
123 123
                     'wpinv_settings[' . $option['id'] . ']',
124 124
                     $name,
125
-                    function_exists( 'wpinv_' . $option['type'] . '_callback' ) ? 'wpinv_' . $option['type'] . '_callback' : 'wpinv_missing_callback',
125
+                    function_exists('wpinv_' . $option['type'] . '_callback') ? 'wpinv_' . $option['type'] . '_callback' : 'wpinv_missing_callback',
126 126
                     'wpinv_settings_' . $tab . '_' . $section,
127 127
                     'wpinv_settings_' . $tab . '_' . $section,
128 128
                     array(
129 129
                         'section'     => $section,
130
-                        'id'          => isset( $option['id'] )          ? $option['id']          : null,
131
-                        'desc'        => ! empty( $option['desc'] )      ? $option['desc']        : '',
132
-                        'name'        => isset( $option['name'] )        ? $option['name']        : null,
133
-                        'size'        => isset( $option['size'] )        ? $option['size']        : null,
134
-                        'options'     => isset( $option['options'] )     ? $option['options']     : '',
135
-                        'selected'    => isset( $option['selected'] )    ? $option['selected']    : null,
136
-                        'std'         => isset( $option['std'] )         ? $option['std']         : '',
137
-                        'min'         => isset( $option['min'] )         ? $option['min']         : null,
138
-                        'max'         => isset( $option['max'] )         ? $option['max']         : null,
139
-                        'step'        => isset( $option['step'] )        ? $option['step']        : null,
140
-                        'chosen'      => isset( $option['chosen'] )      ? $option['chosen']      : null,
141
-                        'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : null,
142
-                        'allow_blank' => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true,
143
-                        'readonly'    => isset( $option['readonly'] )    ? $option['readonly']    : false,
144
-                        'faux'        => isset( $option['faux'] )        ? $option['faux']        : false,
145
-                        'onchange'    => !empty( $option['onchange'] )   ? $option['onchange']    : '',
146
-                        'custom'      => !empty( $option['custom'] )     ? $option['custom']      : '',
147
-                        'class'       =>  !empty( $option['class'] )     ? $option['class']      : '',
148
-                        'cols'        => !empty( $option['cols'] ) && (int)$option['cols'] > 0 ? (int)$option['cols'] : 50,
149
-                        'rows'        => !empty( $option['rows'] ) && (int)$option['rows'] > 0 ? (int)$option['rows'] : 5,
130
+                        'id'          => isset($option['id']) ? $option['id'] : null,
131
+                        'desc'        => !empty($option['desc']) ? $option['desc'] : '',
132
+                        'name'        => isset($option['name']) ? $option['name'] : null,
133
+                        'size'        => isset($option['size']) ? $option['size'] : null,
134
+                        'options'     => isset($option['options']) ? $option['options'] : '',
135
+                        'selected'    => isset($option['selected']) ? $option['selected'] : null,
136
+                        'std'         => isset($option['std']) ? $option['std'] : '',
137
+                        'min'         => isset($option['min']) ? $option['min'] : null,
138
+                        'max'         => isset($option['max']) ? $option['max'] : null,
139
+                        'step'        => isset($option['step']) ? $option['step'] : null,
140
+                        'chosen'      => isset($option['chosen']) ? $option['chosen'] : null,
141
+                        'placeholder' => isset($option['placeholder']) ? $option['placeholder'] : null,
142
+                        'allow_blank' => isset($option['allow_blank']) ? $option['allow_blank'] : true,
143
+                        'readonly'    => isset($option['readonly']) ? $option['readonly'] : false,
144
+                        'faux'        => isset($option['faux']) ? $option['faux'] : false,
145
+                        'onchange'    => !empty($option['onchange']) ? $option['onchange'] : '',
146
+                        'custom'      => !empty($option['custom']) ? $option['custom'] : '',
147
+                        'class'       =>  !empty($option['class']) ? $option['class'] : '',
148
+                        'cols'        => !empty($option['cols']) && (int)$option['cols'] > 0 ? (int)$option['cols'] : 50,
149
+                        'rows'        => !empty($option['rows']) && (int)$option['rows'] > 0 ? (int)$option['rows'] : 5,
150 150
                     )
151 151
                 );
152 152
             }
@@ -154,21 +154,21 @@  discard block
 block discarded – undo
154 154
     }
155 155
 
156 156
     // Creates our settings in the options table
157
-    register_setting( 'wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize' );
157
+    register_setting('wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize');
158 158
 }
159
-add_action( 'admin_init', 'wpinv_register_settings' );
159
+add_action('admin_init', 'wpinv_register_settings');
160 160
 
161 161
 function wpinv_get_registered_settings() {
162
-    $pages = wpinv_get_pages( true );
162
+    $pages = wpinv_get_pages(true);
163 163
     
164 164
     $due_payment_options       = array();
165
-    $due_payment_options[0]    = __( 'Now', 'invoicing' );
166
-    for ( $i = 1; $i <= 30; $i++ ) {
165
+    $due_payment_options[0]    = __('Now', 'invoicing');
166
+    for ($i = 1; $i <= 30; $i++) {
167 167
         $due_payment_options[$i] = $i;
168 168
     }
169 169
     
170 170
     $invoice_number_padd_options = array();
171
-    for ( $i = 0; $i <= 20; $i++ ) {
171
+    for ($i = 0; $i <= 20; $i++) {
172 172
         $invoice_number_padd_options[$i] = $i;
173 173
     }
174 174
     
@@ -177,141 +177,141 @@  discard block
 block discarded – undo
177 177
     $alert_wrapper_start = '<p style="color: #F00">';
178 178
     $alert_wrapper_close = '</p>';
179 179
     $wpinv_settings = array(
180
-        'general' => apply_filters( 'wpinv_settings_general',
180
+        'general' => apply_filters('wpinv_settings_general',
181 181
             array(
182 182
                 'main' => array(
183 183
                     'location_settings' => array(
184 184
                         'id'   => 'location_settings',
185
-                        'name' => '<h3>' . __( 'Default Location', 'invoicing' ) . '</h3>',
185
+                        'name' => '<h3>' . __('Default Location', 'invoicing') . '</h3>',
186 186
                         'desc' => '',
187 187
                         'type' => 'header',
188 188
                     ),
189 189
                     'default_country' => array(
190 190
                         'id'      => 'default_country',
191
-                        'name'    => __( 'Default Country', 'invoicing' ),
192
-                        'desc'    => __( 'Where does your store operate from?', 'invoicing' ),
191
+                        'name'    => __('Default Country', 'invoicing'),
192
+                        'desc'    => __('Where does your store operate from?', 'invoicing'),
193 193
                         'type'    => 'select',
194 194
                         'options' => wpinv_get_country_list(),
195 195
                         'std'     => 'GB',
196 196
                         'chosen'  => true,
197
-                        'placeholder' => __( 'Select a country', 'invoicing' ),
197
+                        'placeholder' => __('Select a country', 'invoicing'),
198 198
                     ),
199 199
                     'default_state' => array(
200 200
                         'id'      => 'default_state',
201
-                        'name'    => __( 'Default State / Province', 'invoicing' ),
202
-                        'desc'    => __( 'What state / province does your store operate from?', 'invoicing' ),
201
+                        'name'    => __('Default State / Province', 'invoicing'),
202
+                        'desc'    => __('What state / province does your store operate from?', 'invoicing'),
203 203
                         'type'    => 'country_states',
204
-                        'placeholder' => __( 'Select a state', 'invoicing' ),
204
+                        'placeholder' => __('Select a state', 'invoicing'),
205 205
                     ),
206 206
                     'store_name' => array(
207 207
                         'id'   => 'store_name',
208
-                        'name' => __( 'Store Name', 'invoicing' ),
209
-                        'desc' => __( 'Store name to print on invoices.', 'invoicing' ),
208
+                        'name' => __('Store Name', 'invoicing'),
209
+                        'desc' => __('Store name to print on invoices.', 'invoicing'),
210 210
                         'std'     => get_option('blogname'),
211 211
                         'type' => 'text',
212 212
                     ),
213 213
                     'logo' => array(
214 214
                         'id'   => 'logo',
215
-                        'name' => __( 'Logo URL', 'invoicing' ),
216
-                        'desc' => __( 'Store logo to print on invoices.', 'invoicing' ),
215
+                        'name' => __('Logo URL', 'invoicing'),
216
+                        'desc' => __('Store logo to print on invoices.', 'invoicing'),
217 217
                         'type' => 'text',
218 218
                     ),
219 219
                     'store_address' => array(
220 220
                         'id'   => 'store_address',
221
-                        'name' => __( 'Store Address', 'invoicing' ),
222
-                        'desc' => __( 'Enter the store address to display on invoice', 'invoicing' ),
221
+                        'name' => __('Store Address', 'invoicing'),
222
+                        'desc' => __('Enter the store address to display on invoice', 'invoicing'),
223 223
                         'type' => 'textarea',
224 224
                     ),
225 225
                     'page_settings' => array(
226 226
                         'id'   => 'page_settings',
227
-                        'name' => '<h3>' . __( 'Page Settings', 'invoicing' ) . '</h3>',
227
+                        'name' => '<h3>' . __('Page Settings', 'invoicing') . '</h3>',
228 228
                         'desc' => '',
229 229
                         'type' => 'header',
230 230
                     ),
231 231
                     'checkout_page' => array(
232 232
                         'id'          => 'checkout_page',
233
-                        'name'        => __( 'Checkout Page', 'invoicing' ),
234
-                        'desc'        => __( 'This is the checkout page where buyers will complete their payments. The <b>[wpinv_checkout]</b> short code must be on this page.', 'invoicing' ),
233
+                        'name'        => __('Checkout Page', 'invoicing'),
234
+                        'desc'        => __('This is the checkout page where buyers will complete their payments. The <b>[wpinv_checkout]</b> short code must be on this page.', 'invoicing'),
235 235
                         'type'        => 'select',
236 236
                         'options'     => $pages,
237 237
                         'chosen'      => true,
238
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
238
+                        'placeholder' => __('Select a page', 'invoicing'),
239 239
                     ),
240 240
                     'success_page' => array(
241 241
                         'id'          => 'success_page',
242
-                        'name'        => __( 'Success Page', 'invoicing' ),
243
-                        'desc'        => __( 'This is the page buyers are sent to after completing their payments. The <b>[wpinv_receipt]</b> short code should be on this page.', 'invoicing' ),
242
+                        'name'        => __('Success Page', 'invoicing'),
243
+                        'desc'        => __('This is the page buyers are sent to after completing their payments. The <b>[wpinv_receipt]</b> short code should be on this page.', 'invoicing'),
244 244
                         'type'        => 'select',
245 245
                         'options'     => $pages,
246 246
                         'chosen'      => true,
247
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
247
+                        'placeholder' => __('Select a page', 'invoicing'),
248 248
                     ),
249 249
                     'failure_page' => array(
250 250
                         'id'          => 'failure_page',
251
-                        'name'        => __( 'Failed Transaction Page', 'invoicing' ),
252
-                        'desc'        => __( 'This is the page buyers are sent to if their transaction is cancelled or fails', 'invoicing' ),
251
+                        'name'        => __('Failed Transaction Page', 'invoicing'),
252
+                        'desc'        => __('This is the page buyers are sent to if their transaction is cancelled or fails', 'invoicing'),
253 253
                         'type'        => 'select',
254 254
                         'options'     => $pages,
255 255
                         'chosen'      => true,
256
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
256
+                        'placeholder' => __('Select a page', 'invoicing'),
257 257
                     ),
258 258
                     'invoice_history_page' => array(
259 259
                         'id'          => 'invoice_history_page',
260
-                        'name'        => __( 'Invoice History Page', 'invoicing' ),
261
-                        'desc'        => __( 'This page shows a invoice history for the current user', 'invoicing' ),
260
+                        'name'        => __('Invoice History Page', 'invoicing'),
261
+                        'desc'        => __('This page shows a invoice history for the current user', 'invoicing'),
262 262
                         'type'        => 'select',
263 263
                         'options'     => $pages,
264 264
                         'chosen'      => true,
265
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
265
+                        'placeholder' => __('Select a page', 'invoicing'),
266 266
                     )
267 267
                 ),
268 268
                 'currency_section' => array(
269 269
                     'currency_settings' => array(
270 270
                         'id'   => 'currency_settings',
271
-                        'name' => '<h3>' . __( 'Currency Settings', 'invoicing' ) . '</h3>',
271
+                        'name' => '<h3>' . __('Currency Settings', 'invoicing') . '</h3>',
272 272
                         'desc' => '',
273 273
                         'type' => 'header',
274 274
                     ),
275 275
                     'currency' => array(
276 276
                         'id'      => 'currency',
277
-                        'name'    => __( 'Currency', 'invoicing' ),
278
-                        'desc'    => __( 'Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing' ),
277
+                        'name'    => __('Currency', 'invoicing'),
278
+                        'desc'    => __('Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing'),
279 279
                         'type'    => 'select',
280 280
                         'options' => wpinv_get_currencies(),
281 281
                         'chosen'  => true,
282 282
                     ),
283 283
                     'currency_position' => array(
284 284
                         'id'      => 'currency_position',
285
-                        'name'    => __( 'Currency Position', 'invoicing' ),
286
-                        'desc'    => __( 'Choose the location of the currency sign.', 'invoicing' ),
285
+                        'name'    => __('Currency Position', 'invoicing'),
286
+                        'desc'    => __('Choose the location of the currency sign.', 'invoicing'),
287 287
                         'type'    => 'select',
288 288
                         'options'  => array(
289
-                            'left'        => __( 'Left', 'invoicing' ) . ' (' . $currency_symbol . wpinv_format_amount( '99.99' ) . ')',
290
-                            'right'       => __( 'Right', 'invoicing' ) . ' ('. wpinv_format_amount( '99.99' ) . $currency_symbol . ')',
291
-                            'left_space'  => __( 'Left with space', 'invoicing' ) . ' (' . $currency_symbol . ' ' . wpinv_format_amount( '99.99' ) . ')',
292
-                            'right_space' => __( 'Right with space', 'invoicing' ) . ' (' . wpinv_format_amount( '99.99' ) . ' ' . $currency_symbol . ')'
289
+                            'left'        => __('Left', 'invoicing') . ' (' . $currency_symbol . wpinv_format_amount('99.99') . ')',
290
+                            'right'       => __('Right', 'invoicing') . ' (' . wpinv_format_amount('99.99') . $currency_symbol . ')',
291
+                            'left_space'  => __('Left with space', 'invoicing') . ' (' . $currency_symbol . ' ' . wpinv_format_amount('99.99') . ')',
292
+                            'right_space' => __('Right with space', 'invoicing') . ' (' . wpinv_format_amount('99.99') . ' ' . $currency_symbol . ')'
293 293
                         )
294 294
                     ),
295 295
                     'thousands_separator' => array(
296 296
                         'id'   => 'thousands_separator',
297
-                        'name' => __( 'Thousands Separator', 'invoicing' ),
298
-                        'desc' => __( 'The symbol (usually , or .) to separate thousands', 'invoicing' ),
297
+                        'name' => __('Thousands Separator', 'invoicing'),
298
+                        'desc' => __('The symbol (usually , or .) to separate thousands', 'invoicing'),
299 299
                         'type' => 'text',
300 300
                         'size' => 'small',
301 301
                         'std'  => ',',
302 302
                     ),
303 303
                     'decimal_separator' => array(
304 304
                         'id'   => 'decimal_separator',
305
-                        'name' => __( 'Decimal Separator', 'invoicing' ),
306
-                        'desc' => __( 'The symbol (usually , or .) to separate decimal points', 'invoicing' ),
305
+                        'name' => __('Decimal Separator', 'invoicing'),
306
+                        'desc' => __('The symbol (usually , or .) to separate decimal points', 'invoicing'),
307 307
                         'type' => 'text',
308 308
                         'size' => 'small',
309 309
                         'std'  => '.',
310 310
                     ),
311 311
                     'decimals' => array(
312 312
                         'id'   => 'decimals',
313
-                        'name' => __( 'Number of Decimals', 'invoicing' ),
314
-                        'desc' => __( 'This sets the number of decimal points shown in displayed prices.', 'invoicing' ),
313
+                        'name' => __('Number of Decimals', 'invoicing'),
314
+                        'desc' => __('This sets the number of decimal points shown in displayed prices.', 'invoicing'),
315 315
                         'type' => 'number',
316 316
                         'size' => 'small',
317 317
                         'std'  => '2',
@@ -323,29 +323,29 @@  discard block
 block discarded – undo
323 323
                 'labels' => array(
324 324
                     'labels' => array(
325 325
                         'id'   => 'labels_settings',
326
-                        'name' => '<h3>' . __( 'Invoice Labels', 'invoicing' ) . '</h3>',
326
+                        'name' => '<h3>' . __('Invoice Labels', 'invoicing') . '</h3>',
327 327
                         'desc' => '',
328 328
                         'type' => 'header',
329 329
                     ),
330 330
                     'vat_name' => array(
331 331
                         'id' => 'vat_name',
332
-                        'name' => __( 'VAT Name', 'invoicing' ),
333
-                        'desc' => __( 'Enter the VAT name', 'invoicing' ),
332
+                        'name' => __('VAT Name', 'invoicing'),
333
+                        'desc' => __('Enter the VAT name', 'invoicing'),
334 334
                         'type' => 'text',
335 335
                         'size' => 'regular',
336 336
                         'std' => 'VAT'
337 337
                     ),
338 338
                     'vat_invoice_notice_label' => array(
339 339
                         'id' => 'vat_invoice_notice_label',
340
-                        'name' => __( 'Invoice notice label', 'invoicing' ),
341
-                        'desc' => __( 'Use this to add a invoice notice section (label) to your invoices', 'invoicing' ),
340
+                        'name' => __('Invoice notice label', 'invoicing'),
341
+                        'desc' => __('Use this to add a invoice notice section (label) to your invoices', 'invoicing'),
342 342
                         'type' => 'text',
343 343
                         'size' => 'regular',
344 344
                     ),
345 345
                     'vat_invoice_notice' => array(
346 346
                         'id' => 'vat_invoice_notice',
347
-                        'name' => __( 'Invoice notice', 'invoicing' ),
348
-                        'desc' =>   __( 'Use this to add a invoice notice section (description) to your invoices', 'invoicing' ),
347
+                        'name' => __('Invoice notice', 'invoicing'),
348
+                        'desc' =>   __('Use this to add a invoice notice section (description) to your invoices', 'invoicing'),
349 349
                         'type' => 'text',
350 350
                         'size' => 'regular',
351 351
                     )
@@ -357,22 +357,22 @@  discard block
 block discarded – undo
357 357
                 'main' => array(
358 358
                     'gateway_settings' => array(
359 359
                         'id'   => 'api_header',
360
-                        'name' => '<h3>' . __( 'Gateway Settings', 'invoicing' ) . '</h3>',
360
+                        'name' => '<h3>' . __('Gateway Settings', 'invoicing') . '</h3>',
361 361
                         'desc' => '',
362 362
                         'type' => 'header',
363 363
                     ),
364 364
                     'gateways' => array(
365 365
                         'id'      => 'gateways',
366
-                        'name'    => __( 'Payment Gateways', 'invoicing' ),
367
-                        'desc'    => __( 'Choose the payment gateways you want to enable.', 'invoicing' ),
366
+                        'name'    => __('Payment Gateways', 'invoicing'),
367
+                        'desc'    => __('Choose the payment gateways you want to enable.', 'invoicing'),
368 368
                         'type'    => 'gateways',
369 369
                         'std'     => array('manual'=>1),
370 370
                         'options' => wpinv_get_payment_gateways(),
371 371
                     ),
372 372
                     'default_gateway' => array(
373 373
                         'id'      => 'default_gateway',
374
-                        'name'    => __( 'Default Gateway', 'invoicing' ),
375
-                        'desc'    => __( 'This gateway will be loaded automatically with the checkout page.', 'invoicing' ),
374
+                        'name'    => __('Default Gateway', 'invoicing'),
375
+                        'desc'    => __('This gateway will be loaded automatically with the checkout page.', 'invoicing'),
376 376
                         'type'    => 'gateway_select',
377 377
                         'std'     => 'manual',
378 378
                         'options' => wpinv_get_payment_gateways(),
@@ -386,19 +386,19 @@  discard block
 block discarded – undo
386 386
                 'main' => array(
387 387
                     'tax_settings' => array(
388 388
                         'id'   => 'tax_settings',
389
-                        'name' => '<h3>' . __( 'Tax Settings', 'invoicing' ) . '</h3>',
389
+                        'name' => '<h3>' . __('Tax Settings', 'invoicing') . '</h3>',
390 390
                         'type' => 'header',
391 391
                     ),
392 392
                     'enable_taxes' => array(
393 393
                         'id'   => 'enable_taxes',
394
-                        'name' => __( 'Enable Taxes', 'invoicing' ),
395
-                        'desc' => __( 'Check this to enable taxes on invoices.', 'invoicing' ),
394
+                        'name' => __('Enable Taxes', 'invoicing'),
395
+                        'desc' => __('Check this to enable taxes on invoices.', 'invoicing'),
396 396
                         'type' => 'checkbox',
397 397
                     ),
398 398
                     'tax_rate' => array(
399 399
                         'id'   => 'tax_rate',
400
-                        'name' => __( 'Fallback Tax Rate', 'invoicing' ),
401
-                        'desc' => __( 'Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing' ),
400
+                        'name' => __('Fallback Tax Rate', 'invoicing'),
401
+                        'desc' => __('Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing'),
402 402
                         'type' => 'number',
403 403
                         'size' => 'small',
404 404
                         'min'  => '0',
@@ -410,8 +410,8 @@  discard block
 block discarded – undo
410 410
                 'rates' => array(
411 411
                     'tax_rates' => array(
412 412
                         'id'   => 'tax_rates',
413
-                        'name' => '<h3>' . __( 'Tax Rates', 'invoicing' ) . '</h3>',
414
-                        'desc' => __( 'Enter tax rates for specific regions.', 'invoicing' ),
413
+                        'name' => '<h3>' . __('Tax Rates', 'invoicing') . '</h3>',
414
+                        'desc' => __('Enter tax rates for specific regions.', 'invoicing'),
415 415
                         'type' => 'tax_rates',
416 416
                     ),
417 417
                 )
@@ -423,62 +423,62 @@  discard block
 block discarded – undo
423 423
                 'main' => array(
424 424
                     'email_settings_header' => array(
425 425
                         'id'   => 'email_settings_header',
426
-                        'name' => '<h3>' . __( 'Email Sender Options', 'invoicing' ) . '</h3>',
426
+                        'name' => '<h3>' . __('Email Sender Options', 'invoicing') . '</h3>',
427 427
                         'type' => 'header',
428 428
                     ),
429 429
                     'email_from_name' => array(
430 430
                         'id'   => 'email_from_name',
431
-                        'name' => __( 'From Name', 'invoicing' ),
432
-                        'desc' => __( 'Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing' ),
433
-                        'std' => esc_attr( get_bloginfo( 'name', 'display' ) ),
431
+                        'name' => __('From Name', 'invoicing'),
432
+                        'desc' => __('Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing'),
433
+                        'std' => esc_attr(get_bloginfo('name', 'display')),
434 434
                         'type' => 'text',
435 435
                     ),
436 436
                     'email_from' => array(
437 437
                         'id'   => 'email_from',
438
-                        'name' => __( 'From Email', 'invoicing' ),
439
-                        'desc' => sprintf (__( 'Email address to send invoice emails from. This will act as the "from" and "reply-to" address. %s If emails are not being sent it may be that your hosting prevents emails being sent if the email domains do not match.%s', 'invoicing' ), $alert_wrapper_start, $alert_wrapper_close),
440
-                        'std' => get_option( 'admin_email' ),
438
+                        'name' => __('From Email', 'invoicing'),
439
+                        'desc' => sprintf(__('Email address to send invoice emails from. This will act as the "from" and "reply-to" address. %s If emails are not being sent it may be that your hosting prevents emails being sent if the email domains do not match.%s', 'invoicing'), $alert_wrapper_start, $alert_wrapper_close),
440
+                        'std' => get_option('admin_email'),
441 441
                         'type' => 'text',
442 442
                     ),
443 443
                     'overdue_settings_header' => array(
444 444
                         'id'   => 'overdue_settings_header',
445
-                        'name' => '<h3>' . __( 'Due Date Settings', 'invoicing' ) . '</h3>',
445
+                        'name' => '<h3>' . __('Due Date Settings', 'invoicing') . '</h3>',
446 446
                         'type' => 'header',
447 447
                     ),
448 448
                     'overdue_active' => array(
449 449
                         'id'   => 'overdue_active',
450
-                        'name' => __( 'Enable Due Date', 'invoicing' ),
451
-                        'desc' => __( 'Check this to enable due date option for invoices.', 'invoicing' ),
450
+                        'name' => __('Enable Due Date', 'invoicing'),
451
+                        'desc' => __('Check this to enable due date option for invoices.', 'invoicing'),
452 452
                         'type' => 'checkbox',
453 453
                         'std'  => false,
454 454
                     ),
455 455
                     'overdue_days' => array(
456 456
                         'id'          => 'overdue_days',
457
-                        'name'        => __( 'Default Due Date', 'invoicing' ),
458
-                        'desc'        => __( 'Number of days each Invoice is due after the created date. This will automatically set the date in the "Due Date" field. Can be overridden on individual Invoices.', 'invoicing' ),
457
+                        'name'        => __('Default Due Date', 'invoicing'),
458
+                        'desc'        => __('Number of days each Invoice is due after the created date. This will automatically set the date in the "Due Date" field. Can be overridden on individual Invoices.', 'invoicing'),
459 459
                         'type'        => 'select',
460 460
                         'options'     => $due_payment_options,
461 461
                         'chosen'      => true,
462 462
                         'std'         => 0,
463
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
463
+                        'placeholder' => __('Select a page', 'invoicing'),
464 464
                     ),
465 465
                     'email_template_header' => array(
466 466
                         'id'   => 'email_template_header',
467
-                        'name' => '<h3>' . __( 'Email Template', 'invoicing' ) . '</h3>',
467
+                        'name' => '<h3>' . __('Email Template', 'invoicing') . '</h3>',
468 468
                         'type' => 'header',
469 469
                     ),
470 470
                     'email_header_image' => array(
471 471
                         'id'   => 'email_header_image',
472
-                        'name' => __( 'Header Image', 'invoicing' ),
473
-                        'desc' => __( 'URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing' ),
472
+                        'name' => __('Header Image', 'invoicing'),
473
+                        'desc' => __('URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing'),
474 474
                         'std' => '',
475 475
                         'type' => 'text',
476 476
                     ),
477 477
                     'email_footer_text' => array(
478 478
                         'id'   => 'email_footer_text',
479
-                        'name' => __( 'Footer Text', 'invoicing' ),
480
-                        'desc' => __( 'The text to appear in the footer of all invoice emails.', 'invoicing' ),
481
-                        'std' => get_bloginfo( 'name', 'display' ) . ' - ' . __( 'Powered by GeoDirectory', 'invoicing' ),
479
+                        'name' => __('Footer Text', 'invoicing'),
480
+                        'desc' => __('The text to appear in the footer of all invoice emails.', 'invoicing'),
481
+                        'std' => get_bloginfo('name', 'display') . ' - ' . __('Powered by GeoDirectory', 'invoicing'),
482 482
                         'type' => 'textarea',
483 483
                         'class' => 'regular-text',
484 484
                         'rows' => 2,
@@ -486,29 +486,29 @@  discard block
 block discarded – undo
486 486
                     ),
487 487
                     'email_base_color' => array(
488 488
                         'id'   => 'email_base_color',
489
-                        'name' => __( 'Base Color', 'invoicing' ),
490
-                        'desc' => __( 'The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing' ),
489
+                        'name' => __('Base Color', 'invoicing'),
490
+                        'desc' => __('The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing'),
491 491
                         'std' => '#557da2',
492 492
                         'type' => 'color',
493 493
                     ),
494 494
                     'email_background_color' => array(
495 495
                         'id'   => 'email_background_color',
496
-                        'name' => __( 'Background Color', 'invoicing' ),
497
-                        'desc' => __( 'The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing' ),
496
+                        'name' => __('Background Color', 'invoicing'),
497
+                        'desc' => __('The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing'),
498 498
                         'std' => '#f5f5f5',
499 499
                         'type' => 'color',
500 500
                     ),
501 501
                     'email_body_background_color' => array(
502 502
                         'id'   => 'email_body_background_color',
503
-                        'name' => __( 'Body Background Color', 'invoicing' ),
504
-                        'desc' => __( 'The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing' ),
503
+                        'name' => __('Body Background Color', 'invoicing'),
504
+                        'desc' => __('The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing'),
505 505
                         'std' => '#fdfdfd',
506 506
                         'type' => 'color',
507 507
                     ),
508 508
                     'email_text_color' => array(
509 509
                         'id'   => 'email_text_color',
510
-                        'name' => __( 'Body Text Color', 'invoicing' ),
511
-                        'desc' => __( 'The main body text color. Default <code>#505050</code>.', 'invoicing' ),
510
+                        'name' => __('Body Text Color', 'invoicing'),
511
+                        'desc' => __('The main body text color. Default <code>#505050</code>.', 'invoicing'),
512 512
                         'std' => '#505050',
513 513
                         'type' => 'color',
514 514
                     ),
@@ -527,25 +527,25 @@  discard block
 block discarded – undo
527 527
                 'main' => array(
528 528
                     'fields_settings' => array(
529 529
                         'id'   => 'fields_settings',
530
-                        'name' => '<h3>' . __( 'Fields Settings', 'invoicing' ) . '</h3>',
530
+                        'name' => '<h3>' . __('Fields Settings', 'invoicing') . '</h3>',
531 531
                         'type' => 'header',
532 532
                     ),
533 533
                     'phone_mandatory' => array(
534 534
                         'id'   => 'phone_mandatory',
535
-                        'name' => __( 'Phone No. Mandatory?', 'invoicing' ),
536
-                        'desc' => __( 'Tick this to make phone number mandatory in invoice address fields.', 'invoicing' ),
535
+                        'name' => __('Phone No. Mandatory?', 'invoicing'),
536
+                        'desc' => __('Tick this to make phone number mandatory in invoice address fields.', 'invoicing'),
537 537
                         'type' => 'checkbox',
538 538
                         'std'  => true,
539 539
                     ),
540 540
                     'invoice_number_format_settings' => array(
541 541
                         'id'   => 'invoice_number_format_settings',
542
-                        'name' => '<h3>' . __( 'Invoice Number', 'invoicing' ) . '</h3>',
542
+                        'name' => '<h3>' . __('Invoice Number', 'invoicing') . '</h3>',
543 543
                         'type' => 'header',
544 544
                     ),
545 545
                     'invoice_number_padd' => array(
546 546
                         'id'      => 'invoice_number_padd',
547
-                        'name'    => __( 'Minimum digits', 'invoicing' ),
548
-                        'desc'    => __( 'If the invoice number has less digits than this number, it is left padded with 0s. Ex: invoice number 108 will padded to 00108 if digits set to 5. The default 0 means no padding.', 'invoicing' ),
547
+                        'name'    => __('Minimum digits', 'invoicing'),
548
+                        'desc'    => __('If the invoice number has less digits than this number, it is left padded with 0s. Ex: invoice number 108 will padded to 00108 if digits set to 5. The default 0 means no padding.', 'invoicing'),
549 549
                         'type'    => 'select',
550 550
                         'options' => $invoice_number_padd_options,
551 551
                         'std'     => 5,
@@ -553,8 +553,8 @@  discard block
 block discarded – undo
553 553
                     ),
554 554
                     'invoice_number_prefix' => array(
555 555
                         'id' => 'invoice_number_prefix',
556
-                        'name' => __( 'Invoice Number prefix', 'invoicing' ),
557
-                        'desc' => __( 'A prefix to prepend to all invoice numbers. Ex: WPINV-', 'invoicing' ),
556
+                        'name' => __('Invoice Number prefix', 'invoicing'),
557
+                        'desc' => __('A prefix to prepend to all invoice numbers. Ex: WPINV-', 'invoicing'),
558 558
                         'type' => 'text',
559 559
                         'size' => 'regular',
560 560
                         'std' => 'WPINV-',
@@ -562,25 +562,25 @@  discard block
 block discarded – undo
562 562
                     ),
563 563
                     'invoice_number_postfix' => array(
564 564
                         'id' => 'invoice_number_postfix',
565
-                        'name' => __( 'Invoice Number postfix', 'invoicing' ),
566
-                        'desc' => __( 'A postfix to append to all invoice numbers.', 'invoicing' ),
565
+                        'name' => __('Invoice Number postfix', 'invoicing'),
566
+                        'desc' => __('A postfix to append to all invoice numbers.', 'invoicing'),
567 567
                         'type' => 'text',
568 568
                         'size' => 'regular',
569 569
                         'std' => ''
570 570
                     ),
571 571
                     'guest_checkout_settings' => array(
572 572
                         'id'   => 'guest_checkout_settings',
573
-                        'name' => '<h3>' . __( 'Pay via Invoice Link', 'invoicing' ) . '</h3>',
573
+                        'name' => '<h3>' . __('Pay via Invoice Link', 'invoicing') . '</h3>',
574 574
                         'type' => 'header',
575 575
                     ),
576 576
                     'guest_checkout' => array(
577 577
                         'type'    => 'radio',
578 578
                         'id'      => 'guest_checkout',
579
-                        'name'    => __( 'Pay via Invoice Link for non logged in user', 'invoicing' ),
580
-                        'desc'    => __( 'Select how invoice should be paid when non logged in user clicks on the invoice link that sent to them via for pay for invoice.', 'invoicing' ),
579
+                        'name'    => __('Pay via Invoice Link for non logged in user', 'invoicing'),
580
+                        'desc'    => __('Select how invoice should be paid when non logged in user clicks on the invoice link that sent to them via for pay for invoice.', 'invoicing'),
581 581
                         'options' => array(
582
-                            0 => __( 'Ask them to log-in and redirect back to invoice checkout to pay.', 'invoicing' ),
583
-                            1 => __( 'Auto log-in the user via invoice link and take them to invoice checkout to pay.', 'invoicing' ),
582
+                            0 => __('Ask them to log-in and redirect back to invoice checkout to pay.', 'invoicing'),
583
+                            1 => __('Auto log-in the user via invoice link and take them to invoice checkout to pay.', 'invoicing'),
584 584
                         ),
585 585
                         'std'     => 0,
586 586
                     ),
@@ -593,8 +593,8 @@  discard block
 block discarded – undo
593 593
                 'main' => array(
594 594
                     'tool_settings' => array(
595 595
                         'id'   => 'tool_settings',
596
-                        'name' => '<h3>' . __( 'Diagnostic Tools', 'invoicing' ) . '</h3>',
597
-                        'desc' => __( 'Invoicing diagnostic tools', 'invoicing' ),
596
+                        'name' => '<h3>' . __('Diagnostic Tools', 'invoicing') . '</h3>',
597
+                        'desc' => __('Invoicing diagnostic tools', 'invoicing'),
598 598
                         'type' => 'tools',
599 599
                     ),
600 600
                 ),
@@ -602,135 +602,135 @@  discard block
 block discarded – undo
602 602
         )
603 603
     );
604 604
 
605
-    return apply_filters( 'wpinv_registered_settings', $wpinv_settings );
605
+    return apply_filters('wpinv_registered_settings', $wpinv_settings);
606 606
 }
607 607
 
608
-function wpinv_settings_sanitize( $input = array() ) {
608
+function wpinv_settings_sanitize($input = array()) {
609 609
     global $wpinv_options;
610 610
 
611
-    if ( empty( $_POST['_wp_http_referer'] ) ) {
611
+    if (empty($_POST['_wp_http_referer'])) {
612 612
         return $input;
613 613
     }
614 614
 
615
-    parse_str( $_POST['_wp_http_referer'], $referrer );
615
+    parse_str($_POST['_wp_http_referer'], $referrer);
616 616
 
617 617
     $settings = wpinv_get_registered_settings();
618
-    $tab      = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general';
619
-    $section  = isset( $referrer['section'] ) ? $referrer['section'] : 'main';
618
+    $tab      = isset($referrer['tab']) ? $referrer['tab'] : 'general';
619
+    $section  = isset($referrer['section']) ? $referrer['section'] : 'main';
620 620
 
621 621
     $input = $input ? $input : array();
622
-    $input = apply_filters( 'wpinv_settings_tab_' . $tab . '_sanitize', $input );
623
-    $input = apply_filters( 'wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input );
622
+    $input = apply_filters('wpinv_settings_tab_' . $tab . '_sanitize', $input);
623
+    $input = apply_filters('wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input);
624 624
 
625 625
     // Loop through each setting being saved and pass it through a sanitization filter
626
-    foreach ( $input as $key => $value ) {
626
+    foreach ($input as $key => $value) {
627 627
         // Get the setting type (checkbox, select, etc)
628
-        $type = isset( $settings[ $tab ][ $key ]['type'] ) ? $settings[ $tab ][ $key ]['type'] : false;
628
+        $type = isset($settings[$tab][$key]['type']) ? $settings[$tab][$key]['type'] : false;
629 629
 
630
-        if ( $type ) {
630
+        if ($type) {
631 631
             // Field type specific filter
632
-            $input[$key] = apply_filters( 'wpinv_settings_sanitize_' . $type, $value, $key );
632
+            $input[$key] = apply_filters('wpinv_settings_sanitize_' . $type, $value, $key);
633 633
         }
634 634
 
635 635
         // General filter
636
-        $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
636
+        $input[$key] = apply_filters('wpinv_settings_sanitize', $input[$key], $key);
637 637
     }
638 638
 
639 639
     // Loop through the whitelist and unset any that are empty for the tab being saved
640
-    $main_settings    = $section == 'main' ? $settings[ $tab ] : array(); // Check for extensions that aren't using new sections
641
-    $section_settings = ! empty( $settings[ $tab ][ $section ] ) ? $settings[ $tab ][ $section ] : array();
640
+    $main_settings    = $section == 'main' ? $settings[$tab] : array(); // Check for extensions that aren't using new sections
641
+    $section_settings = !empty($settings[$tab][$section]) ? $settings[$tab][$section] : array();
642 642
 
643
-    $found_settings = array_merge( $main_settings, $section_settings );
643
+    $found_settings = array_merge($main_settings, $section_settings);
644 644
 
645
-    if ( ! empty( $found_settings ) ) {
646
-        foreach ( $found_settings as $key => $value ) {
645
+    if (!empty($found_settings)) {
646
+        foreach ($found_settings as $key => $value) {
647 647
 
648 648
             // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work
649
-            if ( is_numeric( $key ) ) {
649
+            if (is_numeric($key)) {
650 650
                 $key = $value['id'];
651 651
             }
652 652
 
653
-            if ( empty( $input[ $key ] ) ) {
654
-                unset( $wpinv_options[ $key ] );
653
+            if (empty($input[$key])) {
654
+                unset($wpinv_options[$key]);
655 655
             }
656 656
         }
657 657
     }
658 658
 
659 659
     // Merge our new settings with the existing
660
-    $output = array_merge( $wpinv_options, $input );
660
+    $output = array_merge($wpinv_options, $input);
661 661
 
662
-    add_settings_error( 'wpinv-notices', '', __( 'Settings updated.', 'invoicing' ), 'updated' );
662
+    add_settings_error('wpinv-notices', '', __('Settings updated.', 'invoicing'), 'updated');
663 663
 
664 664
     return $output;
665 665
 }
666 666
 
667
-function wpinv_settings_sanitize_misc_accounting( $input ) {
667
+function wpinv_settings_sanitize_misc_accounting($input) {
668 668
     global $wpinv_options, $wpi_session;
669 669
 
670
-    if ( !current_user_can( 'manage_options' ) ) {
670
+    if (!current_user_can('manage_options')) {
671 671
         return $input;
672 672
     }
673 673
 
674
-    if( ! empty( $input['enable_sequential'] ) && !wpinv_get_option( 'enable_sequential' ) ) {
674
+    if (!empty($input['enable_sequential']) && !wpinv_get_option('enable_sequential')) {
675 675
         // Shows an admin notice about upgrading previous order numbers
676
-        $wpi_session->set( 'upgrade_sequential', '1' );
676
+        $wpi_session->set('upgrade_sequential', '1');
677 677
     }
678 678
 
679 679
     return $input;
680 680
 }
681
-add_filter( 'wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting' );
681
+add_filter('wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting');
682 682
 
683
-function wpinv_settings_sanitize_tax_rates( $input ) {
684
-    if( !current_user_can( 'manage_options' ) ) {
683
+function wpinv_settings_sanitize_tax_rates($input) {
684
+    if (!current_user_can('manage_options')) {
685 685
         return $input;
686 686
     }
687 687
 
688
-    $new_rates = !empty( $_POST['tax_rates'] ) ? array_values( $_POST['tax_rates'] ) : array();
688
+    $new_rates = !empty($_POST['tax_rates']) ? array_values($_POST['tax_rates']) : array();
689 689
 
690 690
     $tax_rates = array();
691 691
 
692
-    if ( !empty( $new_rates ) ) {
693
-        foreach ( $new_rates as $rate ) {
694
-            if ( isset( $rate['country'] ) && empty( $rate['country'] ) && empty( $rate['state'] ) ) {
692
+    if (!empty($new_rates)) {
693
+        foreach ($new_rates as $rate) {
694
+            if (isset($rate['country']) && empty($rate['country']) && empty($rate['state'])) {
695 695
                 continue;
696 696
             }
697 697
             
698
-            $rate['rate'] = wpinv_sanitize_amount( $rate['rate'], 4 );
698
+            $rate['rate'] = wpinv_sanitize_amount($rate['rate'], 4);
699 699
             
700 700
             $tax_rates[] = $rate;
701 701
         }
702 702
     }
703 703
 
704
-    update_option( 'wpinv_tax_rates', $tax_rates );
704
+    update_option('wpinv_tax_rates', $tax_rates);
705 705
 
706 706
     return $input;
707 707
 }
708
-add_filter( 'wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates' );
708
+add_filter('wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates');
709 709
 
710
-function wpinv_sanitize_text_field( $input ) {
711
-    return trim( $input );
710
+function wpinv_sanitize_text_field($input) {
711
+    return trim($input);
712 712
 }
713
-add_filter( 'wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field' );
713
+add_filter('wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field');
714 714
 
715 715
 function wpinv_get_settings_tabs() {
716 716
     $tabs             = array();
717
-    $tabs['general']  = __( 'General', 'invoicing' );
718
-    $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' );
719
-    $tabs['taxes']    = __( 'Taxes', 'invoicing' );
720
-    $tabs['emails']   = __( 'Emails', 'invoicing' );
721
-    $tabs['misc']     = __( 'Misc', 'invoicing' );
722
-    $tabs['tools']    = __( 'Tools', 'invoicing' );
723
-
724
-    return apply_filters( 'wpinv_settings_tabs', $tabs );
717
+    $tabs['general']  = __('General', 'invoicing');
718
+    $tabs['gateways'] = __('Payment Gateways', 'invoicing');
719
+    $tabs['taxes']    = __('Taxes', 'invoicing');
720
+    $tabs['emails']   = __('Emails', 'invoicing');
721
+    $tabs['misc']     = __('Misc', 'invoicing');
722
+    $tabs['tools']    = __('Tools', 'invoicing');
723
+
724
+    return apply_filters('wpinv_settings_tabs', $tabs);
725 725
 }
726 726
 
727
-function wpinv_get_settings_tab_sections( $tab = false ) {
727
+function wpinv_get_settings_tab_sections($tab = false) {
728 728
     $tabs     = false;
729 729
     $sections = wpinv_get_registered_settings_sections();
730 730
 
731
-    if( $tab && ! empty( $sections[ $tab ] ) ) {
732
-        $tabs = $sections[ $tab ];
733
-    } else if ( $tab ) {
731
+    if ($tab && !empty($sections[$tab])) {
732
+        $tabs = $sections[$tab];
733
+    } else if ($tab) {
734 734
         $tabs = false;
735 735
     }
736 736
 
@@ -740,135 +740,135 @@  discard block
 block discarded – undo
740 740
 function wpinv_get_registered_settings_sections() {
741 741
     static $sections = false;
742 742
 
743
-    if ( false !== $sections ) {
743
+    if (false !== $sections) {
744 744
         return $sections;
745 745
     }
746 746
 
747 747
     $sections = array(
748
-        'general' => apply_filters( 'wpinv_settings_sections_general', array(
749
-            'main' => __( 'General Settings', 'invoicing' ),
750
-            'currency_section' => __( 'Currency Settings', 'invoicing' ),
751
-            'labels' => __( 'Label Texts', 'invoicing' ),
752
-        ) ),
753
-        'gateways' => apply_filters( 'wpinv_settings_sections_gateways', array(
754
-            'main' => __( 'Gateway Settings', 'invoicing' ),
755
-        ) ),
756
-        'taxes' => apply_filters( 'wpinv_settings_sections_taxes', array(
757
-            'main' => __( 'Tax Settings', 'invoicing' ),
758
-            'rates' => __( 'Tax Rates', 'invoicing' ),
759
-        ) ),
760
-        'emails' => apply_filters( 'wpinv_settings_sections_emails', array(
761
-            'main' => __( 'Email Settings', 'invoicing' ),
762
-        ) ),
763
-        'misc' => apply_filters( 'wpinv_settings_sections_misc', array(
764
-            'main' => __( 'Misc Settings', 'invoicing' ),
765
-        ) ),
766
-        'tools' => apply_filters( 'wpinv_settings_sections_tools', array(
767
-            'main' => __( 'Diagnostic Tools', 'invoicing' ),
768
-        ) ),
748
+        'general' => apply_filters('wpinv_settings_sections_general', array(
749
+            'main' => __('General Settings', 'invoicing'),
750
+            'currency_section' => __('Currency Settings', 'invoicing'),
751
+            'labels' => __('Label Texts', 'invoicing'),
752
+        )),
753
+        'gateways' => apply_filters('wpinv_settings_sections_gateways', array(
754
+            'main' => __('Gateway Settings', 'invoicing'),
755
+        )),
756
+        'taxes' => apply_filters('wpinv_settings_sections_taxes', array(
757
+            'main' => __('Tax Settings', 'invoicing'),
758
+            'rates' => __('Tax Rates', 'invoicing'),
759
+        )),
760
+        'emails' => apply_filters('wpinv_settings_sections_emails', array(
761
+            'main' => __('Email Settings', 'invoicing'),
762
+        )),
763
+        'misc' => apply_filters('wpinv_settings_sections_misc', array(
764
+            'main' => __('Misc Settings', 'invoicing'),
765
+        )),
766
+        'tools' => apply_filters('wpinv_settings_sections_tools', array(
767
+            'main' => __('Diagnostic Tools', 'invoicing'),
768
+        )),
769 769
     );
770 770
 
771
-    $sections = apply_filters( 'wpinv_settings_sections', $sections );
771
+    $sections = apply_filters('wpinv_settings_sections', $sections);
772 772
 
773 773
     return $sections;
774 774
 }
775 775
 
776
-function wpinv_get_pages( $with_slug = false, $default_label = NULL ) {
776
+function wpinv_get_pages($with_slug = false, $default_label = NULL) {
777 777
 	$pages_options = array();
778 778
 
779
-	if( $default_label !== NULL && $default_label !== false ) {
780
-		$pages_options = array( '' => $default_label ); // Blank option
779
+	if ($default_label !== NULL && $default_label !== false) {
780
+		$pages_options = array('' => $default_label); // Blank option
781 781
 	}
782 782
 
783 783
 	$pages = get_pages();
784
-	if ( $pages ) {
785
-		foreach ( $pages as $page ) {
784
+	if ($pages) {
785
+		foreach ($pages as $page) {
786 786
 			$title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
787
-            $pages_options[ $page->ID ] = $title;
787
+            $pages_options[$page->ID] = $title;
788 788
 		}
789 789
 	}
790 790
 
791 791
 	return $pages_options;
792 792
 }
793 793
 
794
-function wpinv_header_callback( $args ) {
795
-	if ( !empty( $args['desc'] ) ) {
794
+function wpinv_header_callback($args) {
795
+	if (!empty($args['desc'])) {
796 796
         echo $args['desc'];
797 797
     }
798 798
 }
799 799
 
800
-function wpinv_hidden_callback( $args ) {
800
+function wpinv_hidden_callback($args) {
801 801
 	global $wpinv_options;
802 802
 
803
-	if ( isset( $args['set_value'] ) ) {
803
+	if (isset($args['set_value'])) {
804 804
 		$value = $args['set_value'];
805
-	} elseif ( isset( $wpinv_options[ $args['id'] ] ) ) {
806
-		$value = $wpinv_options[ $args['id'] ];
805
+	} elseif (isset($wpinv_options[$args['id']])) {
806
+		$value = $wpinv_options[$args['id']];
807 807
 	} else {
808
-		$value = isset( $args['std'] ) ? $args['std'] : '';
808
+		$value = isset($args['std']) ? $args['std'] : '';
809 809
 	}
810 810
 
811
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
811
+	if (isset($args['faux']) && true === $args['faux']) {
812 812
 		$args['readonly'] = true;
813
-		$value = isset( $args['std'] ) ? $args['std'] : '';
813
+		$value = isset($args['std']) ? $args['std'] : '';
814 814
 		$name  = '';
815 815
 	} else {
816
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
816
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
817 817
 	}
818 818
 
819
-	$html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
819
+	$html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key($args['id']) . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '" />';
820 820
     
821 821
 	echo $html;
822 822
 }
823 823
 
824
-function wpinv_checkbox_callback( $args ) {
824
+function wpinv_checkbox_callback($args) {
825 825
 	global $wpinv_options;
826 826
     
827
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
827
+    $sanitize_id = wpinv_sanitize_key($args['id']);
828 828
 
829
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
829
+	if (isset($args['faux']) && true === $args['faux']) {
830 830
 		$name = '';
831 831
 	} else {
832 832
 		$name = 'name="wpinv_settings[' . $sanitize_id . ']"';
833 833
 	}
834 834
 
835
-	$checked = isset( $wpinv_options[ $args['id'] ] ) ? checked( 1, $wpinv_options[ $args['id'] ], false ) : '';
835
+	$checked = isset($wpinv_options[$args['id']]) ? checked(1, $wpinv_options[$args['id']], false) : '';
836 836
 	$html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>';
837
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
837
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
838 838
 
839 839
 	echo $html;
840 840
 }
841 841
 
842
-function wpinv_multicheck_callback( $args ) {
842
+function wpinv_multicheck_callback($args) {
843 843
 	global $wpinv_options;
844 844
 	
845
-	$sanitize_id = wpinv_sanitize_key( $args['id'] );
845
+	$sanitize_id = wpinv_sanitize_key($args['id']);
846 846
 	
847
-	if ( ! empty( $args['options'] ) ) {
848
-		foreach( $args['options'] as $key => $option ):
849
-			$sanitize_key = wpinv_sanitize_key( $key );
850
-			if ( isset( $wpinv_options[$args['id']][$sanitize_key] ) ) { 
847
+	if (!empty($args['options'])) {
848
+		foreach ($args['options'] as $key => $option):
849
+			$sanitize_key = wpinv_sanitize_key($key);
850
+			if (isset($wpinv_options[$args['id']][$sanitize_key])) { 
851 851
 				$enabled = $sanitize_key;
852 852
 			} else { 
853 853
 				$enabled = NULL; 
854 854
 			}
855
-			echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
856
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label><br/>';
855
+			echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($sanitize_key) . '" ' . checked($sanitize_key, $enabled, false) . '/>&nbsp;';
856
+			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post($option) . '</label><br/>';
857 857
 		endforeach;
858 858
 		echo '<p class="description">' . $args['desc'] . '</p>';
859 859
 	}
860 860
 }
861 861
 
862
-function wpinv_payment_icons_callback( $args ) {
862
+function wpinv_payment_icons_callback($args) {
863 863
 	global $wpinv_options;
864 864
     
865
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
865
+    $sanitize_id = wpinv_sanitize_key($args['id']);
866 866
 
867
-	if ( ! empty( $args['options'] ) ) {
868
-		foreach( $args['options'] as $key => $option ) {
869
-            $sanitize_key = wpinv_sanitize_key( $key );
867
+	if (!empty($args['options'])) {
868
+		foreach ($args['options'] as $key => $option) {
869
+            $sanitize_key = wpinv_sanitize_key($key);
870 870
             
871
-			if( isset( $wpinv_options[$args['id']][$key] ) ) {
871
+			if (isset($wpinv_options[$args['id']][$key])) {
872 872
 				$enabled = $option;
873 873
 			} else {
874 874
 				$enabled = NULL;
@@ -876,194 +876,194 @@  discard block
 block discarded – undo
876 876
 
877 877
 			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
878 878
 
879
-				echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
879
+				echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($option) . '" ' . checked($option, $enabled, false) . '/>&nbsp;';
880 880
 
881
-				if ( wpinv_string_is_image_url( $key ) ) {
882
-					echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
881
+				if (wpinv_string_is_image_url($key)) {
882
+					echo '<img class="payment-icon" src="' . esc_url($key) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
883 883
 				} else {
884
-					$card = strtolower( str_replace( ' ', '', $option ) );
884
+					$card = strtolower(str_replace(' ', '', $option));
885 885
 
886
-					if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
887
-						$image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
886
+					if (has_filter('wpinv_accepted_payment_' . $card . '_image')) {
887
+						$image = apply_filters('wpinv_accepted_payment_' . $card . '_image', '');
888 888
 					} else {
889
-						$image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
889
+						$image       = wpinv_locate_template('images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false);
890 890
 						$content_dir = WP_CONTENT_DIR;
891 891
 
892
-						if ( function_exists( 'wp_normalize_path' ) ) {
892
+						if (function_exists('wp_normalize_path')) {
893 893
 							// Replaces backslashes with forward slashes for Windows systems
894
-							$image = wp_normalize_path( $image );
895
-							$content_dir = wp_normalize_path( $content_dir );
894
+							$image = wp_normalize_path($image);
895
+							$content_dir = wp_normalize_path($content_dir);
896 896
 						}
897 897
 
898
-						$image = str_replace( $content_dir, content_url(), $image );
898
+						$image = str_replace($content_dir, content_url(), $image);
899 899
 					}
900 900
 
901
-					echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
901
+					echo '<img class="payment-icon" src="' . esc_url($image) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
902 902
 				}
903 903
 			echo $option . '</label>';
904 904
 		}
905
-		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
905
+		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post($args['desc']) . '</p>';
906 906
 	}
907 907
 }
908 908
 
909
-function wpinv_radio_callback( $args ) {
909
+function wpinv_radio_callback($args) {
910 910
 	global $wpinv_options;
911 911
     
912
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
912
+    $sanitize_id = wpinv_sanitize_key($args['id']);
913 913
     
914
-    foreach ( $args['options'] as $key => $option ) :
915
-		$sanitize_key = wpinv_sanitize_key( $key );
914
+    foreach ($args['options'] as $key => $option) :
915
+		$sanitize_key = wpinv_sanitize_key($key);
916 916
         
917 917
         $checked = false;
918 918
 
919
-		if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key )
919
+		if (isset($wpinv_options[$args['id']]) && $wpinv_options[$args['id']] == $key)
920 920
 			$checked = true;
921
-		elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) )
921
+		elseif (isset($args['std']) && $args['std'] == $key && !isset($wpinv_options[$args['id']]))
922 922
 			$checked = true;
923 923
 
924 924
 		echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/>&nbsp;';
925
-		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>';
925
+		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option) . '</label><br/>';
926 926
 	endforeach;
927 927
 
928
-	echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
928
+	echo '<p class="description">' . wp_kses_post($args['desc']) . '</p>';
929 929
 }
930 930
 
931
-function wpinv_gateways_callback( $args ) {
931
+function wpinv_gateways_callback($args) {
932 932
 	global $wpinv_options;
933 933
     
934
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
934
+    $sanitize_id = wpinv_sanitize_key($args['id']);
935 935
 
936
-	foreach ( $args['options'] as $key => $option ) :
937
-		$sanitize_key = wpinv_sanitize_key( $key );
936
+	foreach ($args['options'] as $key => $option) :
937
+		$sanitize_key = wpinv_sanitize_key($key);
938 938
         
939
-        if ( isset( $wpinv_options['gateways'][ $key ] ) )
939
+        if (isset($wpinv_options['gateways'][$key]))
940 940
 			$enabled = '1';
941 941
 		else
942 942
 			$enabled = null;
943 943
 
944
-		echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/>&nbsp;';
945
-		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>';
944
+		echo '<input name="wpinv_settings[' . esc_attr($args['id']) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/>&nbsp;';
945
+		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option['admin_label']) . '</label><br/>';
946 946
 	endforeach;
947 947
 }
948 948
 
949 949
 function wpinv_gateway_select_callback($args) {
950 950
 	global $wpinv_options;
951 951
     
952
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
952
+    $sanitize_id = wpinv_sanitize_key($args['id']);
953 953
 
954 954
 	echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']">';
955 955
 
956
-	foreach ( $args['options'] as $key => $option ) :
957
-		if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
958
-            $selected = selected( $key, $args['selected'], false );
956
+	foreach ($args['options'] as $key => $option) :
957
+		if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) {
958
+            $selected = selected($key, $args['selected'], false);
959 959
         } else {
960
-            $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : '';
960
+            $selected = isset($wpinv_options[$args['id']]) ? selected($key, $wpinv_options[$args['id']], false) : '';
961 961
         }
962
-		echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
962
+		echo '<option value="' . wpinv_sanitize_key($key) . '"' . $selected . '>' . esc_html($option['admin_label']) . '</option>';
963 963
 	endforeach;
964 964
 
965 965
 	echo '</select>';
966
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
966
+	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
967 967
 }
968 968
 
969
-function wpinv_text_callback( $args ) {
969
+function wpinv_text_callback($args) {
970 970
 	global $wpinv_options;
971 971
     
972
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
972
+    $sanitize_id = wpinv_sanitize_key($args['id']);
973 973
 
974
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
975
-		$value = $wpinv_options[ $args['id'] ];
974
+	if (isset($wpinv_options[$args['id']])) {
975
+		$value = $wpinv_options[$args['id']];
976 976
 	} else {
977
-		$value = isset( $args['std'] ) ? $args['std'] : '';
977
+		$value = isset($args['std']) ? $args['std'] : '';
978 978
 	}
979 979
 
980
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
980
+	if (isset($args['faux']) && true === $args['faux']) {
981 981
 		$args['readonly'] = true;
982
-		$value = isset( $args['std'] ) ? $args['std'] : '';
982
+		$value = isset($args['std']) ? $args['std'] : '';
983 983
 		$name  = '';
984 984
 	} else {
985
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
985
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
986 986
 	}
987 987
 
988 988
 	$readonly = $args['readonly'] === true ? ' readonly="readonly"' : '';
989
-	$size     = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
990
-	$html     = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>';
991
-	$html    .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
989
+	$size     = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
990
+	$html     = '<input type="text" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"' . $readonly . '/>';
991
+	$html    .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
992 992
 
993 993
 	echo $html;
994 994
 }
995 995
 
996
-function wpinv_number_callback( $args ) {
996
+function wpinv_number_callback($args) {
997 997
 	global $wpinv_options;
998 998
     
999
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
999
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1000 1000
 
1001
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1002
-		$value = $wpinv_options[ $args['id'] ];
1001
+	if (isset($wpinv_options[$args['id']])) {
1002
+		$value = $wpinv_options[$args['id']];
1003 1003
 	} else {
1004
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1004
+		$value = isset($args['std']) ? $args['std'] : '';
1005 1005
 	}
1006 1006
 
1007
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
1007
+	if (isset($args['faux']) && true === $args['faux']) {
1008 1008
 		$args['readonly'] = true;
1009
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1009
+		$value = isset($args['std']) ? $args['std'] : '';
1010 1010
 		$name  = '';
1011 1011
 	} else {
1012
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
1012
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
1013 1013
 	}
1014 1014
 
1015
-	$max  = isset( $args['max'] ) ? $args['max'] : 999999;
1016
-	$min  = isset( $args['min'] ) ? $args['min'] : 0;
1017
-	$step = isset( $args['step'] ) ? $args['step'] : 1;
1015
+	$max  = isset($args['max']) ? $args['max'] : 999999;
1016
+	$min  = isset($args['min']) ? $args['min'] : 0;
1017
+	$step = isset($args['step']) ? $args['step'] : 1;
1018 1018
 
1019
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1020
-	$html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>';
1021
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1019
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1020
+	$html = '<input type="number" step="' . esc_attr($step) . '" max="' . esc_attr($max) . '" min="' . esc_attr($min) . '" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"/>';
1021
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1022 1022
 
1023 1023
 	echo $html;
1024 1024
 }
1025 1025
 
1026
-function wpinv_textarea_callback( $args ) {
1026
+function wpinv_textarea_callback($args) {
1027 1027
 	global $wpinv_options;
1028 1028
     
1029
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1029
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1030 1030
 
1031
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1032
-		$value = $wpinv_options[ $args['id'] ];
1031
+	if (isset($wpinv_options[$args['id']])) {
1032
+		$value = $wpinv_options[$args['id']];
1033 1033
 	} else {
1034
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1034
+		$value = isset($args['std']) ? $args['std'] : '';
1035 1035
 	}
1036 1036
     
1037
-    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1038
-    $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text';
1037
+    $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1038
+    $class = (isset($args['class']) && !is_null($args['class'])) ? $args['class'] : 'large-text';
1039 1039
 
1040
-	$html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
1041
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1040
+	$html = '<textarea class="' . sanitize_html_class($class) . ' txtarea-' . sanitize_html_class($size) . ' wpi-' . esc_attr(sanitize_html_class($sanitize_id)) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']">' . esc_textarea(stripslashes($value)) . '</textarea>';
1041
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1042 1042
 
1043 1043
 	echo $html;
1044 1044
 }
1045 1045
 
1046
-function wpinv_password_callback( $args ) {
1046
+function wpinv_password_callback($args) {
1047 1047
 	global $wpinv_options;
1048 1048
     
1049
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1049
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1050 1050
 
1051
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1052
-		$value = $wpinv_options[ $args['id'] ];
1051
+	if (isset($wpinv_options[$args['id']])) {
1052
+		$value = $wpinv_options[$args['id']];
1053 1053
 	} else {
1054
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1054
+		$value = isset($args['std']) ? $args['std'] : '';
1055 1055
 	}
1056 1056
 
1057
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1058
-	$html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
1059
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1057
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1058
+	$html = '<input type="password" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '"/>';
1059
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1060 1060
 
1061 1061
 	echo $html;
1062 1062
 }
1063 1063
 
1064 1064
 function wpinv_missing_callback($args) {
1065 1065
 	printf(
1066
-		__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
1066
+		__('The callback function used for the %s setting is missing.', 'invoicing'),
1067 1067
 		'<strong>' . $args['id'] . '</strong>'
1068 1068
 	);
1069 1069
 }
@@ -1071,137 +1071,137 @@  discard block
 block discarded – undo
1071 1071
 function wpinv_select_callback($args) {
1072 1072
 	global $wpinv_options;
1073 1073
     
1074
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1074
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1075 1075
 
1076
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1077
-		$value = $wpinv_options[ $args['id'] ];
1076
+	if (isset($wpinv_options[$args['id']])) {
1077
+		$value = $wpinv_options[$args['id']];
1078 1078
 	} else {
1079
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1079
+		$value = isset($args['std']) ? $args['std'] : '';
1080 1080
 	}
1081 1081
     
1082
-    if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
1082
+    if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) {
1083 1083
         $value = $args['selected'];
1084 1084
     }
1085 1085
 
1086
-	if ( isset( $args['placeholder'] ) ) {
1086
+	if (isset($args['placeholder'])) {
1087 1087
 		$placeholder = $args['placeholder'];
1088 1088
 	} else {
1089 1089
 		$placeholder = '';
1090 1090
 	}
1091 1091
 
1092
-	if ( isset( $args['chosen'] ) ) {
1092
+	if (isset($args['chosen'])) {
1093 1093
 		$chosen = 'class="wpinv-chosen"';
1094 1094
 	} else {
1095 1095
 		$chosen = '';
1096 1096
 	}
1097 1097
     
1098
-    if( !empty( $args['onchange'] ) ) {
1099
-        $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"';
1098
+    if (!empty($args['onchange'])) {
1099
+        $onchange = ' onchange="' . esc_attr($args['onchange']) . '"';
1100 1100
     } else {
1101 1101
         $onchange = '';
1102 1102
     }
1103 1103
 
1104
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" ' . $chosen . 'data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />';
1104
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" ' . $chosen . 'data-placeholder="' . esc_html($placeholder) . '"' . $onchange . ' />';
1105 1105
 
1106
-	foreach ( $args['options'] as $option => $name ) {
1107
-		$selected = selected( $option, $value, false );
1108
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
1106
+	foreach ($args['options'] as $option => $name) {
1107
+		$selected = selected($option, $value, false);
1108
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>';
1109 1109
 	}
1110 1110
 
1111 1111
 	$html .= '</select>';
1112
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1112
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1113 1113
 
1114 1114
 	echo $html;
1115 1115
 }
1116 1116
 
1117
-function wpinv_color_select_callback( $args ) {
1117
+function wpinv_color_select_callback($args) {
1118 1118
 	global $wpinv_options;
1119 1119
     
1120
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1120
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1121 1121
 
1122
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1123
-		$value = $wpinv_options[ $args['id'] ];
1122
+	if (isset($wpinv_options[$args['id']])) {
1123
+		$value = $wpinv_options[$args['id']];
1124 1124
 	} else {
1125
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1125
+		$value = isset($args['std']) ? $args['std'] : '';
1126 1126
 	}
1127 1127
 
1128
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
1128
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"/>';
1129 1129
 
1130
-	foreach ( $args['options'] as $option => $color ) {
1131
-		$selected = selected( $option, $value, false );
1132
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>';
1130
+	foreach ($args['options'] as $option => $color) {
1131
+		$selected = selected($option, $value, false);
1132
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($color['label']) . '</option>';
1133 1133
 	}
1134 1134
 
1135 1135
 	$html .= '</select>';
1136
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1136
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1137 1137
 
1138 1138
 	echo $html;
1139 1139
 }
1140 1140
 
1141
-function wpinv_rich_editor_callback( $args ) {
1141
+function wpinv_rich_editor_callback($args) {
1142 1142
 	global $wpinv_options, $wp_version;
1143 1143
     
1144
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1144
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1145 1145
 
1146
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1147
-		$value = $wpinv_options[ $args['id'] ];
1146
+	if (isset($wpinv_options[$args['id']])) {
1147
+		$value = $wpinv_options[$args['id']];
1148 1148
 
1149
-		if( empty( $args['allow_blank'] ) && empty( $value ) ) {
1150
-			$value = isset( $args['std'] ) ? $args['std'] : '';
1149
+		if (empty($args['allow_blank']) && empty($value)) {
1150
+			$value = isset($args['std']) ? $args['std'] : '';
1151 1151
 		}
1152 1152
 	} else {
1153
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1153
+		$value = isset($args['std']) ? $args['std'] : '';
1154 1154
 	}
1155 1155
 
1156
-	$rows = isset( $args['size'] ) ? $args['size'] : 20;
1156
+	$rows = isset($args['size']) ? $args['size'] : 20;
1157 1157
 
1158
-	if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
1158
+	if ($wp_version >= 3.3 && function_exists('wp_editor')) {
1159 1159
 		ob_start();
1160
-		wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ) ) );
1160
+		wp_editor(stripslashes($value), 'wpinv_settings_' . esc_attr($args['id']), array('textarea_name' => 'wpinv_settings[' . esc_attr($args['id']) . ']', 'textarea_rows' => absint($rows)));
1161 1161
 		$html = ob_get_clean();
1162 1162
 	} else {
1163
-		$html = '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
1163
+		$html = '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" class="wpi-' . esc_attr(sanitize_html_class($args['id'])) . '">' . esc_textarea(stripslashes($value)) . '</textarea>';
1164 1164
 	}
1165 1165
 
1166
-	$html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1166
+	$html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1167 1167
 
1168 1168
 	echo $html;
1169 1169
 }
1170 1170
 
1171
-function wpinv_upload_callback( $args ) {
1171
+function wpinv_upload_callback($args) {
1172 1172
 	global $wpinv_options;
1173 1173
     
1174
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1174
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1175 1175
 
1176
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1176
+	if (isset($wpinv_options[$args['id']])) {
1177 1177
 		$value = $wpinv_options[$args['id']];
1178 1178
 	} else {
1179 1179
 		$value = isset($args['std']) ? $args['std'] : '';
1180 1180
 	}
1181 1181
 
1182
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1183
-	$html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
1184
-	$html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
1185
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1182
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1183
+	$html = '<input type="text" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr(stripslashes($value)) . '"/>';
1184
+	$html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __('Upload File', 'invoicing') . '"/></span>';
1185
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1186 1186
 
1187 1187
 	echo $html;
1188 1188
 }
1189 1189
 
1190
-function wpinv_color_callback( $args ) {
1190
+function wpinv_color_callback($args) {
1191 1191
 	global $wpinv_options;
1192 1192
     
1193
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1193
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1194 1194
 
1195
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1196
-		$value = $wpinv_options[ $args['id'] ];
1195
+	if (isset($wpinv_options[$args['id']])) {
1196
+		$value = $wpinv_options[$args['id']];
1197 1197
 	} else {
1198
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1198
+		$value = isset($args['std']) ? $args['std'] : '';
1199 1199
 	}
1200 1200
 
1201
-	$default = isset( $args['std'] ) ? $args['std'] : '';
1201
+	$default = isset($args['std']) ? $args['std'] : '';
1202 1202
 
1203
-	$html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />';
1204
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1203
+	$html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '" data-default-color="' . esc_attr($default) . '" />';
1204
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1205 1205
 
1206 1206
 	echo $html;
1207 1207
 }
@@ -1209,9 +1209,9 @@  discard block
 block discarded – undo
1209 1209
 function wpinv_country_states_callback($args) {
1210 1210
 	global $wpinv_options;
1211 1211
     
1212
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1212
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1213 1213
 
1214
-	if ( isset( $args['placeholder'] ) ) {
1214
+	if (isset($args['placeholder'])) {
1215 1215
 		$placeholder = $args['placeholder'];
1216 1216
 	} else {
1217 1217
 		$placeholder = '';
@@ -1219,17 +1219,17 @@  discard block
 block discarded – undo
1219 1219
 
1220 1220
 	$states = wpinv_get_country_states();
1221 1221
 
1222
-	$chosen = ( $args['chosen'] ? ' wpinv-chosen' : '' );
1223
-	$class = empty( $states ) ? ' class="wpinv-no-states' . $chosen . '"' : 'class="' . $chosen . '"';
1224
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
1222
+	$chosen = ($args['chosen'] ? ' wpinv-chosen' : '');
1223
+	$class = empty($states) ? ' class="wpinv-no-states' . $chosen . '"' : 'class="' . $chosen . '"';
1224
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"' . $class . 'data-placeholder="' . esc_html($placeholder) . '"/>';
1225 1225
 
1226
-	foreach ( $states as $option => $name ) {
1227
-		$selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : '';
1228
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
1226
+	foreach ($states as $option => $name) {
1227
+		$selected = isset($wpinv_options[$args['id']]) ? selected($option, $wpinv_options[$args['id']], false) : '';
1228
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>';
1229 1229
 	}
1230 1230
 
1231 1231
 	$html .= '</select>';
1232
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1232
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1233 1233
 
1234 1234
 	echo $html;
1235 1235
 }
@@ -1244,25 +1244,25 @@  discard block
 block discarded – undo
1244 1244
 	<table id="wpinv_tax_rates" class="wp-list-table widefat fixed posts">
1245 1245
 		<thead>
1246 1246
 			<tr>
1247
-				<th scope="col" class="wpinv_tax_country"><?php _e( 'Country', 'invoicing' ); ?></th>
1248
-				<th scope="col" class="wpinv_tax_state"><?php _e( 'State / Province', 'invoicing' ); ?></th>
1249
-                <th scope="col" class="wpinv_tax_global" title="<?php esc_attr_e( 'Apply rate to whole country, regardless of state / province', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th>
1250
-                <th scope="col" class="wpinv_tax_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> 
1251
-                <th scope="col" class="wpinv_tax_name"><?php _e( 'Tax Name', 'invoicing' ); ?></th>
1252
-				<th scope="col" class="wpinv_tax_action"><?php _e( 'Remove', 'invoicing' ); ?></th>
1247
+				<th scope="col" class="wpinv_tax_country"><?php _e('Country', 'invoicing'); ?></th>
1248
+				<th scope="col" class="wpinv_tax_state"><?php _e('State / Province', 'invoicing'); ?></th>
1249
+                <th scope="col" class="wpinv_tax_global" title="<?php esc_attr_e('Apply rate to whole country, regardless of state / province', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th>
1250
+                <th scope="col" class="wpinv_tax_rate"><?php _e('Rate %', 'invoicing'); ?></th> 
1251
+                <th scope="col" class="wpinv_tax_name"><?php _e('Tax Name', 'invoicing'); ?></th>
1252
+				<th scope="col" class="wpinv_tax_action"><?php _e('Remove', 'invoicing'); ?></th>
1253 1253
 			</tr>
1254 1254
 		</thead>
1255 1255
         <tbody>
1256
-		<?php if( !empty( $rates ) ) : ?>
1257
-			<?php foreach( $rates as $key => $rate ) : ?>
1256
+		<?php if (!empty($rates)) : ?>
1257
+			<?php foreach ($rates as $key => $rate) : ?>
1258 1258
             <?php 
1259
-            $sanitized_key = wpinv_sanitize_key( $key );
1259
+            $sanitized_key = wpinv_sanitize_key($key);
1260 1260
             ?>
1261 1261
 			<tr>
1262 1262
 				<td class="wpinv_tax_country">
1263 1263
 					<?php
1264
-					echo wpinv_html_select( array(
1265
-						'options'          => wpinv_get_country_list( true ),
1264
+					echo wpinv_html_select(array(
1265
+						'options'          => wpinv_get_country_list(true),
1266 1266
 						'name'             => 'tax_rates[' . $sanitized_key . '][country]',
1267 1267
                         'id'               => 'tax_rates[' . $sanitized_key . '][country]',
1268 1268
 						'selected'         => $rate['country'],
@@ -1270,72 +1270,72 @@  discard block
 block discarded – undo
1270 1270
 						'show_option_none' => false,
1271 1271
 						'class'            => 'wpinv-tax-country',
1272 1272
 						'chosen'           => false,
1273
-						'placeholder'      => __( 'Choose a country', 'invoicing' )
1274
-					) );
1273
+						'placeholder'      => __('Choose a country', 'invoicing')
1274
+					));
1275 1275
 					?>
1276 1276
 				</td>
1277 1277
 				<td class="wpinv_tax_state">
1278 1278
 					<?php
1279
-					$states = wpinv_get_country_states( $rate['country'] );
1280
-					if( !empty( $states ) ) {
1281
-						echo wpinv_html_select( array(
1282
-							'options'          => array_merge( array( '' => '' ), $states ),
1279
+					$states = wpinv_get_country_states($rate['country']);
1280
+					if (!empty($states)) {
1281
+						echo wpinv_html_select(array(
1282
+							'options'          => array_merge(array('' => ''), $states),
1283 1283
 							'name'             => 'tax_rates[' . $sanitized_key . '][state]',
1284 1284
                             'id'               => 'tax_rates[' . $sanitized_key . '][state]',
1285 1285
 							'selected'         => $rate['state'],
1286 1286
 							'show_option_all'  => false,
1287 1287
 							'show_option_none' => false,
1288 1288
 							'chosen'           => false,
1289
-							'placeholder'      => __( 'Choose a state', 'invoicing' )
1290
-						) );
1289
+							'placeholder'      => __('Choose a state', 'invoicing')
1290
+						));
1291 1291
 					} else {
1292
-						echo wpinv_html_text( array(
1292
+						echo wpinv_html_text(array(
1293 1293
 							'name'  => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'],
1294
-							'value' => ! empty( $rate['state'] ) ? $rate['state'] : '',
1294
+							'value' => !empty($rate['state']) ? $rate['state'] : '',
1295 1295
                             'id'    => 'tax_rates[' . $sanitized_key . '][state]',
1296
-						) );
1296
+						));
1297 1297
 					}
1298 1298
 					?>
1299 1299
 				</td>
1300 1300
 				<td class="wpinv_tax_global">
1301
-					<input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked( true, ! empty( $rate['global'] ) ); ?>/>
1302
-					<label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label>
1301
+					<input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked(true, !empty($rate['global'])); ?>/>
1302
+					<label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label>
1303 1303
 				</td>
1304
-				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[<?php echo $sanitized_key; ?>][rate]" value="<?php echo esc_html( $rate['rate'] ); ?>"/></td>
1305
-                <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[<?php echo $sanitized_key; ?>][name]" value="<?php echo esc_html( $rate['name'] ); ?>"/></td>
1306
-				<td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td>
1304
+				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[<?php echo $sanitized_key; ?>][rate]" value="<?php echo esc_html($rate['rate']); ?>"/></td>
1305
+                <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[<?php echo $sanitized_key; ?>][name]" value="<?php echo esc_html($rate['name']); ?>"/></td>
1306
+				<td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td>
1307 1307
 			</tr>
1308 1308
 			<?php endforeach; ?>
1309 1309
 		<?php else : ?>
1310 1310
 			<tr>
1311 1311
 				<td class="wpinv_tax_country">
1312 1312
 					<?php
1313
-					echo wpinv_html_select( array(
1314
-						'options'          => wpinv_get_country_list( true ),
1313
+					echo wpinv_html_select(array(
1314
+						'options'          => wpinv_get_country_list(true),
1315 1315
 						'name'             => 'tax_rates[0][country]',
1316 1316
 						'show_option_all'  => false,
1317 1317
 						'show_option_none' => false,
1318 1318
 						'class'            => 'wpinv-tax-country',
1319 1319
 						'chosen'           => false,
1320
-						'placeholder'      => __( 'Choose a country', 'invoicing' )
1321
-					) ); ?>
1320
+						'placeholder'      => __('Choose a country', 'invoicing')
1321
+					)); ?>
1322 1322
 				</td>
1323 1323
 				<td class="wpinv_tax_state">
1324
-					<?php echo wpinv_html_text( array(
1324
+					<?php echo wpinv_html_text(array(
1325 1325
 						'name' => 'tax_rates[0][state]'
1326
-					) ); ?>
1326
+					)); ?>
1327 1327
 				</td>
1328 1328
 				<td class="wpinv_tax_global">
1329 1329
 					<input type="checkbox" name="tax_rates[0][global]" id="tax_rates[0][global]" value="1"/>
1330
-					<label for="tax_rates[0][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label>
1330
+					<label for="tax_rates[0][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label>
1331 1331
 				</td>
1332
-				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[0][rate]" placeholder="<?php echo (float)wpinv_get_option( 'tax_rate', 0 ) ;?>" value="<?php echo (float)wpinv_get_option( 'tax_rate', 0 ) ;?>"/></td>
1332
+				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[0][rate]" placeholder="<?php echo (float)wpinv_get_option('tax_rate', 0); ?>" value="<?php echo (float)wpinv_get_option('tax_rate', 0); ?>"/></td>
1333 1333
                 <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[0][name]" /></td>
1334
-				<td><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td>
1334
+				<td><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td>
1335 1335
 			</tr>
1336 1336
 		<?php endif; ?>
1337 1337
         </tbody>
1338
-        <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e( 'Add Tax Rate', 'invoicing' ); ?></span></td></tr></tfoot>
1338
+        <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e('Add Tax Rate', 'invoicing'); ?></span></td></tr></tfoot>
1339 1339
 	</table>
1340 1340
 	<?php
1341 1341
 	echo ob_get_clean();
@@ -1346,44 +1346,44 @@  discard block
 block discarded – undo
1346 1346
     ob_start(); ?>
1347 1347
     </td><tr>
1348 1348
     <td colspan="2" class="wpinv_tools_tdbox">
1349
-    <?php if ( $args['desc'] ) { ?><p><?php echo $args['desc']; ?></p><?php } ?>
1350
-    <?php do_action( 'wpinv_tools_before' ); ?>
1349
+    <?php if ($args['desc']) { ?><p><?php echo $args['desc']; ?></p><?php } ?>
1350
+    <?php do_action('wpinv_tools_before'); ?>
1351 1351
     <table id="wpinv_tools_table" class="wp-list-table widefat fixed posts">
1352 1352
         <thead>
1353 1353
             <tr>
1354
-                <th scope="col" class="wpinv-th-tool"><?php _e( 'Tool', 'invoicing' ); ?></th>
1355
-                <th scope="col" class="wpinv-th-desc"><?php _e( 'Description', 'invoicing' ); ?></th>
1356
-                <th scope="col" class="wpinv-th-action"><?php _e( 'Action', 'invoicing' ); ?></th>
1354
+                <th scope="col" class="wpinv-th-tool"><?php _e('Tool', 'invoicing'); ?></th>
1355
+                <th scope="col" class="wpinv-th-desc"><?php _e('Description', 'invoicing'); ?></th>
1356
+                <th scope="col" class="wpinv-th-action"><?php _e('Action', 'invoicing'); ?></th>
1357 1357
             </tr>
1358 1358
         </thead>
1359
-            <?php do_action( 'wpinv_tools_row' ); ?>
1359
+            <?php do_action('wpinv_tools_row'); ?>
1360 1360
         <tbody>
1361 1361
         </tbody>
1362 1362
     </table>
1363
-    <?php do_action( 'wpinv_tools_after' ); ?>
1363
+    <?php do_action('wpinv_tools_after'); ?>
1364 1364
     <?php
1365 1365
     echo ob_get_clean();
1366 1366
 }
1367 1367
 
1368
-function wpinv_descriptive_text_callback( $args ) {
1369
-	echo wp_kses_post( $args['desc'] );
1368
+function wpinv_descriptive_text_callback($args) {
1369
+	echo wp_kses_post($args['desc']);
1370 1370
 }
1371 1371
 
1372
-function wpinv_hook_callback( $args ) {
1373
-	do_action( 'wpinv_' . $args['id'], $args );
1372
+function wpinv_hook_callback($args) {
1373
+	do_action('wpinv_' . $args['id'], $args);
1374 1374
 }
1375 1375
 
1376 1376
 function wpinv_set_settings_cap() {
1377 1377
 	return 'manage_options';
1378 1378
 }
1379
-add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' );
1379
+add_filter('option_page_capability_wpinv_settings', 'wpinv_set_settings_cap');
1380 1380
 
1381
-function wpinv_settings_sanitize_input( $value, $key ) {
1382
-    if ( $key == 'tax_rate' || $key == 'eu_fallback_rate' ) {
1383
-        $value = wpinv_sanitize_amount( $value, 4 );
1381
+function wpinv_settings_sanitize_input($value, $key) {
1382
+    if ($key == 'tax_rate' || $key == 'eu_fallback_rate') {
1383
+        $value = wpinv_sanitize_amount($value, 4);
1384 1384
         $value = $value >= 100 ? 99 : $value;
1385 1385
     }
1386 1386
         
1387 1387
     return $value;
1388 1388
 }
1389
-add_filter( 'wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2 );
1390 1389
\ No newline at end of file
1390
+add_filter('wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2);
1391 1391
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/wpinv-admin-functions.php 1 patch
Spacing   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -7,228 +7,228 @@  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
-        'ID'                => __( 'ID', 'invoicing' ),
18
-        'details'           => __( 'Details', 'invoicing' ),
17
+        'ID'                => __('ID', 'invoicing'),
18
+        'details'           => __('Details', 'invoicing'),
19 19
         //'email'             => __( 'Email', 'invoicing' ),
20
-        'customer'          => __( 'Customer', 'invoicing' ),
21
-        'amount'            => __( 'Amount', 'invoicing' ),
22
-        'invoice_date'      => __( 'Date', 'invoicing' ),
23
-        'status'            => __( 'Status', 'invoicing' ),
24
-        'wpi_actions'       => __( 'Actions', 'invoicing' ),
20
+        'customer'          => __('Customer', 'invoicing'),
21
+        'amount'            => __('Amount', 'invoicing'),
22
+        'invoice_date'      => __('Date', 'invoicing'),
23
+        'status'            => __('Status', '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' );
38
+add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions');
39 39
 
40
-function wpinv_sortable_columns( $columns ) {
40
+function wpinv_sortable_columns($columns) {
41 41
     $columns = array(
42
-        'ID'     => array( 'ID', true ),
43
-        'amount' => array( 'amount', false ),
44
-        'invoice_date'   => array( 'date', false ),
45
-        'customer'   => array( 'customer', false ),
42
+        'ID'     => array('ID', true),
43
+        'amount' => array('amount', false),
44
+        'invoice_date'   => array('date', false),
45
+        'customer'   => array('customer', false),
46 46
         ///'email'   => array( 'email', false ),
47
-        'status'   => array( 'status', false ),
47
+        'status'   => array('status', false),
48 48
     );
49 49
     
50
-    return apply_filters( 'wpi_invoice_table_sortable_columns', $columns );
50
+    return apply_filters('wpi_invoice_table_sortable_columns', $columns);
51 51
 }
52
-add_filter( 'manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns' );
52
+add_filter('manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns');
53 53
 
54
-add_action( 'manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
55
-function wpinv_posts_custom_column( $column_name, $post_id = 0 ) {
54
+add_action('manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
55
+function wpinv_posts_custom_column($column_name, $post_id = 0) {
56 56
     global $post, $wpi_invoice;
57 57
     
58
-    if ( empty( $wpi_invoice ) || ( !empty( $wpi_invoice ) && $post->ID != $wpi_invoice->ID ) ) {
59
-        $wpi_invoice = new WPInv_Invoice( $post->ID );
58
+    if (empty($wpi_invoice) || (!empty($wpi_invoice) && $post->ID != $wpi_invoice->ID)) {
59
+        $wpi_invoice = new WPInv_Invoice($post->ID);
60 60
     }
61 61
 
62 62
     $value = NULL;
63 63
     
64
-    switch ( $column_name ) {
64
+    switch ($column_name) {
65 65
         case 'email' :
66
-            $value   = $wpi_invoice->get_email();
66
+            $value = $wpi_invoice->get_email();
67 67
             break;
68 68
         case 'customer' :
69 69
             $customer_name = $wpi_invoice->get_user_full_name();
70
-            $customer_name = $customer_name != '' ? $customer_name : __( 'Customer', 'invoicing' );
71
-            $value = '<a href="' . esc_url( get_edit_user_link( $wpi_invoice->get_user_id() ) ) . '">' . $customer_name . '</a>';
72
-            if ( $email = $wpi_invoice->get_email() ) {
70
+            $customer_name = $customer_name != '' ? $customer_name : __('Customer', 'invoicing');
71
+            $value = '<a href="' . esc_url(get_edit_user_link($wpi_invoice->get_user_id())) . '">' . $customer_name . '</a>';
72
+            if ($email = $wpi_invoice->get_email()) {
73 73
                 $value .= '<br><a class="email" href="mailto:' . $email . '">' . $email . '</a>';
74 74
             }
75 75
             break;
76 76
         case 'amount' :
77
-            echo $wpi_invoice->get_total( true );
77
+            echo $wpi_invoice->get_total(true);
78 78
             break;
79 79
         case 'invoice_date' :
80
-            $date_format = get_option( 'date_format' );
81
-            $time_format = get_option( 'time_format' );
82
-            $date_time_format = $date_format . ' '. $time_format;
80
+            $date_format = get_option('date_format');
81
+            $time_format = get_option('time_format');
82
+            $date_time_format = $date_format . ' ' . $time_format;
83 83
             
84
-            $t_time = get_the_time( $date_time_format );
84
+            $t_time = get_the_time($date_time_format);
85 85
             $m_time = $post->post_date;
86
-            $h_time = mysql2date( $date_format, $m_time );
86
+            $h_time = mysql2date($date_format, $m_time);
87 87
             
88 88
             $value   = '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';
89 89
             break;
90 90
         case 'status' :
91
-            $value   = $wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' );
91
+            $value   = $wpi_invoice->get_status(true) . ($wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '');
92 92
             break;
93 93
         case 'details' :
94
-            $edit_link = get_edit_post_link( $post->ID );
95
-            $value = '<a href="' . esc_url( $edit_link ) . '">' . __( 'View Invoice Details', 'invoicing' ) . '</a>';
94
+            $edit_link = get_edit_post_link($post->ID);
95
+            $value = '<a href="' . esc_url($edit_link) . '">' . __('View Invoice Details', 'invoicing') . '</a>';
96 96
             break;
97 97
         case 'wpi_actions' :
98 98
             $value = '';
99
-            if ( !empty( $post->post_name ) ) {
100
-                $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>';
99
+            if (!empty($post->post_name)) {
100
+                $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>';
101 101
             }
102 102
             
103
-            if ( $email = $wpi_invoice->get_email() ) {
104
-                $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>';
103
+            if ($email = $wpi_invoice->get_email()) {
104
+                $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>';
105 105
             }
106 106
             
107 107
             break;
108 108
         default:
109
-            $value = isset( $post->$column_name ) ? $post->$column_name : '';
109
+            $value = isset($post->$column_name) ? $post->$column_name : '';
110 110
             break;
111 111
 
112 112
     }
113
-    $value = apply_filters( 'wpinv_payments_table_column', $value, $post->ID, $column_name );
113
+    $value = apply_filters('wpinv_payments_table_column', $value, $post->ID, $column_name);
114 114
     
115
-    if ( $value !== NULL ) {
115
+    if ($value !== NULL) {
116 116
         echo $value;
117 117
     }
118 118
 }
119 119
 
120
-function wpinv_admin_post_id( $id = 0 ) {
120
+function wpinv_admin_post_id($id = 0) {
121 121
     global $post;
122 122
 
123
-    if ( isset( $id ) && ! empty( $id ) ) {
123
+    if (isset($id) && !empty($id)) {
124 124
         return (int)$id;
125
-    } else if ( get_the_ID() ) {
126
-        return (int) get_the_ID();
127
-    } else if ( isset( $post->ID ) && !empty( $post->ID ) ) {
128
-        return (int) $post->ID;
129
-    } else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) {
130
-        return (int) $_GET['post'];
131
-    } else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) {
132
-        return (int) $_GET['id'];
133
-    } else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) {
134
-        return (int) $_POST['id'];
125
+    } else if (get_the_ID()) {
126
+        return (int)get_the_ID();
127
+    } else if (isset($post->ID) && !empty($post->ID)) {
128
+        return (int)$post->ID;
129
+    } else if (isset($_GET['post']) && !empty($_GET['post'])) {
130
+        return (int)$_GET['post'];
131
+    } else if (isset($_GET['id']) && !empty($_GET['id'])) {
132
+        return (int)$_GET['id'];
133
+    } else if (isset($_POST['id']) && !empty($_POST['id'])) {
134
+        return (int)$_POST['id'];
135 135
     } 
136 136
 
137 137
     return null;
138 138
 }
139 139
     
140
-function wpinv_admin_post_type( $id = 0 ) {
141
-    if ( !$id ) {
140
+function wpinv_admin_post_type($id = 0) {
141
+    if (!$id) {
142 142
         $id = wpinv_admin_post_id();
143 143
     }
144 144
     
145
-    $type = get_post_type( $id );
145
+    $type = get_post_type($id);
146 146
     
147
-    if ( !$type ) {
148
-        $type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null;
147
+    if (!$type) {
148
+        $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? $_GET['post_type'] : null;
149 149
     }
150 150
     
151
-    return apply_filters( 'wpinv_admin_post_type', $type, $id );
151
+    return apply_filters('wpinv_admin_post_type', $type, $id);
152 152
 }
153 153
 
154 154
 function wpinv_admin_messages() {
155 155
 	global $wpinv_options;
156 156
 
157
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
158
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' );
157
+	if (isset($_GET['wpinv-message']) && 'discount_added' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
158
+		 add_settings_error('wpinv-notices', 'wpinv-discount-added', __('Discount code added.', 'invoicing'), 'updated');
159 159
 	}
160 160
 
161
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
162
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' );
161
+	if (isset($_GET['wpinv-message']) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
162
+		add_settings_error('wpinv-notices', 'wpinv-discount-add-fail', __('There was a problem adding your discount code, please try again.', 'invoicing'), 'error');
163 163
 	}
164 164
 
165
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
166
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' );
165
+	if (isset($_GET['wpinv-message']) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
166
+		add_settings_error('wpinv-notices', 'wpinv-discount-exists', __('A discount with that code already exists, please use a different code.', 'invoicing'), 'error');
167 167
 	}
168 168
 
169
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
170
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' );
169
+	if (isset($_GET['wpinv-message']) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
170
+		 add_settings_error('wpinv-notices', 'wpinv-discount-updated', __('Discount code updated.', 'invoicing'), 'updated');
171 171
 	}
172 172
 
173
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
174
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' );
173
+	if (isset($_GET['wpinv-message']) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
174
+		add_settings_error('wpinv-notices', 'wpinv-discount-updated-fail', __('There was a problem updating your discount code, please try again.', 'invoicing'), 'error');
175 175
 	}
176 176
 
177
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
178
-		add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' );
177
+	if (isset($_GET['wpinv-message']) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
178
+		add_settings_error('wpinv-notices', 'wpinv-deleted', __('The invoice has been deleted.', 'invoicing'), 'updated');
179 179
 	}
180 180
 
181
-	if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
182
-		add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' );
181
+	if (isset($_GET['wpinv-message']) && 'email_sent' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
182
+		add_settings_error('wpinv-notices', 'wpinv-sent', __('The email has been sent to customer.', 'invoicing'), 'updated');
183 183
     }
184 184
     
185
-    if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
186
-		add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' );
185
+    if (isset($_GET['wpinv-message']) && 'email_fail' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
186
+		add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Fail to send email to the customer.', 'invoicing'), 'error');
187 187
     }
188 188
 
189
-    if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
190
-        add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' );
189
+    if (isset($_GET['wpinv-message']) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
190
+        add_settings_error('wpinv-notices', 'wpinv-note-deleted', __('The invoice note has been deleted.', 'invoicing'), 'updated');
191 191
     }
192 192
 
193
-	if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
194
-		add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' );
193
+	if (isset($_GET['wpinv-message']) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
194
+		add_settings_error('wpinv-notices', 'wpinv-settings-imported', __('The settings have been imported.', 'invoicing'), 'updated');
195 195
 	}
196 196
 
197
-	if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
198
-		add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' );
197
+	if (isset($_GET['wpinv-message']) && 'note-added' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
198
+		add_settings_error('wpinv-notices', 'wpinv-note-added', __('The invoice note has been added successfully.', 'invoicing'), 'updated');
199 199
 	}
200 200
 
201
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
202
-		add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' );
201
+	if (isset($_GET['wpinv-message']) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
202
+		add_settings_error('wpinv-notices', 'wpinv-updated', __('The invoice has been successfully updated.', 'invoicing'), 'updated');
203 203
 	}
204 204
 
205
-	settings_errors( 'wpinv-notices' );
205
+	settings_errors('wpinv-notices');
206 206
 }
207
-add_action( 'admin_notices', 'wpinv_admin_messages' );
207
+add_action('admin_notices', 'wpinv_admin_messages');
208 208
 
209
-function wpinv_items_columns( $existing_columns ) {
209
+function wpinv_items_columns($existing_columns) {
210 210
     global $wpinv_euvat;
211 211
     
212 212
     $columns                = array();
213 213
     $columns['cb']          = $existing_columns['cb'];
214
-    $columns['title']       = __( 'Title', 'invoicing' );
215
-    $columns['price']       = __( 'Price', 'invoicing' );
216
-    if ( $wpinv_euvat->allow_vat_rules() ) {
217
-        $columns['vat_rule']    = __( 'VAT rule type', 'invoicing' );
214
+    $columns['title']       = __('Title', 'invoicing');
215
+    $columns['price']       = __('Price', 'invoicing');
216
+    if ($wpinv_euvat->allow_vat_rules()) {
217
+        $columns['vat_rule']    = __('VAT rule type', 'invoicing');
218 218
     }
219
-    if ( $wpinv_euvat->allow_vat_classes() ) {
220
-        $columns['vat_class']   = __( 'VAT class', 'invoicing' );
219
+    if ($wpinv_euvat->allow_vat_classes()) {
220
+        $columns['vat_class']   = __('VAT class', 'invoicing');
221 221
     }
222
-    $columns['type']        = __( 'Type', 'invoicing' );
223
-    $columns['recurring']   = __( 'Recurring', 'invoicing' );
224
-    $columns['date']        = __( 'Date', 'invoicing' );
225
-    $columns['id']          = __( 'ID', 'invoicing' );
222
+    $columns['type']        = __('Type', 'invoicing');
223
+    $columns['recurring']   = __('Recurring', 'invoicing');
224
+    $columns['date']        = __('Date', 'invoicing');
225
+    $columns['id']          = __('ID', 'invoicing');
226 226
 
227
-    return apply_filters( 'wpinv_items_columns', $columns );
227
+    return apply_filters('wpinv_items_columns', $columns);
228 228
 }
229
-add_filter( 'manage_wpi_item_posts_columns', 'wpinv_items_columns' );
229
+add_filter('manage_wpi_item_posts_columns', 'wpinv_items_columns');
230 230
 
231
-function wpinv_items_sortable_columns( $columns ) {
231
+function wpinv_items_sortable_columns($columns) {
232 232
     $columns['price']       = 'price';
233 233
     $columns['vat_rule']    = 'vat_rule';
234 234
     $columns['vat_class']   = 'vat_class';
@@ -238,10 +238,10 @@  discard block
 block discarded – undo
238 238
 
239 239
     return $columns;
240 240
 }
241
-add_filter( 'manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns' );
241
+add_filter('manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns');
242 242
 
243
-function wpinv_item_quick_edit( $column_name, $post_type ) {
244
-    if ( !( $post_type == 'wpi_item' && $column_name == 'price' ) ) {
243
+function wpinv_item_quick_edit($column_name, $post_type) {
244
+    if (!($post_type == 'wpi_item' && $column_name == 'price')) {
245 245
         return;
246 246
     }
247 247
     global $wpinv_euvat, $post;
@@ -249,23 +249,23 @@  discard block
 block discarded – undo
249 249
     $symbol    = wpinv_currency_symbol();
250 250
     $position  = wpinv_currency_position();
251 251
 
252
-    $price     = wpinv_get_item_price( $post->ID );
253
-    $item_type = wpinv_get_item_type( $post->ID );
252
+    $price     = wpinv_get_item_price($post->ID);
253
+    $item_type = wpinv_get_item_type($post->ID);
254 254
     ?>
255 255
     <fieldset class="inline-edit-col-right wpi-inline-item-col">
256 256
         <div class="inline-edit-col">
257 257
             <div class="inline-edit-group wp-clearfix">
258 258
                 <label class="inline-edit-wpinv-price">
259
-                    <span class="title"><?php _e( 'Item price', 'invoicing' );?></span>
260
-                    <span class="input-text-wrap"><?php echo ( $position != 'right' ? $symbol . '&nbsp;' : '' );?><input type="text" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" name="_wpinv_item_price" class="wpi-field-price wpi-price" id="wpinv_item_price-<?php echo $post->ID;?>"><?php echo ( $position == 'right' ? $symbol . '&nbsp;' : '' );?></span>
259
+                    <span class="title"><?php _e('Item price', 'invoicing'); ?></span>
260
+                    <span class="input-text-wrap"><?php echo ($position != 'right' ? $symbol . '&nbsp;' : ''); ?><input type="text" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" name="_wpinv_item_price" class="wpi-field-price wpi-price" id="wpinv_item_price-<?php echo $post->ID; ?>"><?php echo ($position == 'right' ? $symbol . '&nbsp;' : ''); ?></span>
261 261
                 </label>
262 262
             </div>
263
-            <?php if ( $wpinv_euvat->allow_vat_rules() ) { $rule_type = $wpinv_euvat->get_item_rule( $post->ID ); ?>
263
+            <?php if ($wpinv_euvat->allow_vat_rules()) { $rule_type = $wpinv_euvat->get_item_rule($post->ID); ?>
264 264
             <div class="inline-edit-group wp-clearfix">
265 265
                 <label class="inline-edit-wpinv-vat-rate">
266
-                    <span class="title"><?php _e( 'VAT rule type to use', 'invoicing' );?></span>
266
+                    <span class="title"><?php _e('VAT rule type to use', 'invoicing'); ?></span>
267 267
                     <span class="input-text-wrap">
268
-                        <?php echo wpinv_html_select( array(
268
+                        <?php echo wpinv_html_select(array(
269 269
                             'options'          => $wpinv_euvat->get_rules(),
270 270
                             'name'             => '_wpinv_vat_rules',
271 271
                             'id'               => 'wpinv_vat_rules-' . $post->ID,
@@ -273,16 +273,16 @@  discard block
 block discarded – undo
273 273
                             'show_option_all'  => false,
274 274
                             'show_option_none' => false,
275 275
                             'class'            => 'gdmbx2-text-medium wpinv-vat-rules',
276
-                        ) ); ?>
276
+                        )); ?>
277 277
                     </span>
278 278
                 </label>
279 279
             </div>
280
-            <?php } if ( $wpinv_euvat->allow_vat_classes() ) { $vat_class = $wpinv_euvat->get_item_class( $post->ID ); ?>
280
+            <?php } if ($wpinv_euvat->allow_vat_classes()) { $vat_class = $wpinv_euvat->get_item_class($post->ID); ?>
281 281
             <div class="inline-edit-group wp-clearfix">
282 282
                 <label class="inline-edit-wpinv-vat-class">
283
-                    <span class="title"><?php _e( 'VAT class to use', 'invoicing' );?></span>
283
+                    <span class="title"><?php _e('VAT class to use', 'invoicing'); ?></span>
284 284
                     <span class="input-text-wrap">
285
-                        <?php echo wpinv_html_select( array(
285
+                        <?php echo wpinv_html_select(array(
286 286
                             'options'          => $wpinv_euvat->get_all_classes(),
287 287
                             'name'             => '_wpinv_vat_class',
288 288
                             'id'               => 'wpinv_vat_class-' . $post->ID,
@@ -290,16 +290,16 @@  discard block
 block discarded – undo
290 290
                             'show_option_all'  => false,
291 291
                             'show_option_none' => false,
292 292
                             'class'            => 'gdmbx2-text-medium wpinv-vat-class',
293
-                        ) ); ?>
293
+                        )); ?>
294 294
                     </span>
295 295
                 </label>
296 296
             </div>
297 297
             <?php } ?>
298 298
             <div class="inline-edit-group wp-clearfix">
299 299
                 <label class="inline-edit-wpinv-type">
300
-                    <span class="title"><?php _e( 'Item type', 'invoicing' );?></span>
300
+                    <span class="title"><?php _e('Item type', 'invoicing'); ?></span>
301 301
                     <span class="input-text-wrap">
302
-                        <?php echo wpinv_html_select( array(
302
+                        <?php echo wpinv_html_select(array(
303 303
                             'options'          => wpinv_get_item_types(),
304 304
                             'name'             => '_wpinv_item_type',
305 305
                             'id'               => 'wpinv_item_type-' . $post->ID,
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
                             'show_option_all'  => false,
308 308
                             'show_option_none' => false,
309 309
                             'class'            => 'gdmbx2-text-medium wpinv-item-type',
310
-                        ) ); ?>
310
+                        )); ?>
311 311
                     </span>
312 312
                 </label>
313 313
             </div>
@@ -315,150 +315,150 @@  discard block
 block discarded – undo
315 315
     </fieldset>
316 316
     <?php
317 317
 }
318
-add_action( 'quick_edit_custom_box', 'wpinv_item_quick_edit', 10, 2 );
319
-add_action( 'bulk_edit_custom_box', 'wpinv_item_quick_edit', 10, 2 );
318
+add_action('quick_edit_custom_box', 'wpinv_item_quick_edit', 10, 2);
319
+add_action('bulk_edit_custom_box', 'wpinv_item_quick_edit', 10, 2);
320 320
 
321
-function wpinv_items_table_custom_column( $column ) {
321
+function wpinv_items_table_custom_column($column) {
322 322
     global $wpinv_euvat, $post, $wpi_item;
323 323
     
324
-    if ( empty( $wpi_item ) || ( !empty( $wpi_item ) && $post->ID != $wpi_item->ID ) ) {
325
-        $wpi_item = new WPInv_Item( $post->ID );
324
+    if (empty($wpi_item) || (!empty($wpi_item) && $post->ID != $wpi_item->ID)) {
325
+        $wpi_item = new WPInv_Item($post->ID);
326 326
     }
327 327
 
328
-    switch ( $column ) {
328
+    switch ($column) {
329 329
         case 'price' :
330
-            echo wpinv_item_price( $post->ID );
330
+            echo wpinv_item_price($post->ID);
331 331
         break;
332 332
         case 'vat_rule' :
333
-            echo $wpinv_euvat->item_rule_label( $post->ID );
333
+            echo $wpinv_euvat->item_rule_label($post->ID);
334 334
         break;
335 335
         case 'vat_class' :
336
-            echo $wpinv_euvat->item_class_label( $post->ID );
336
+            echo $wpinv_euvat->item_class_label($post->ID);
337 337
         break;
338 338
         case 'type' :
339
-            echo wpinv_item_type( $post->ID ) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>';
339
+            echo wpinv_item_type($post->ID) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>';
340 340
         break;
341 341
         case 'recurring' :
342
-            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>' );
342
+            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>');
343 343
         break;
344 344
         case 'id' :
345 345
            echo $post->ID;
346 346
            echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '">
347
-                    <div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>';
348
-                    if ( $wpinv_euvat->allow_vat_rules() ) {
349
-                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</div>';
347
+                    <div class="price">' . wpinv_get_item_price($post->ID) . '</div>';
348
+                    if ($wpinv_euvat->allow_vat_rules()) {
349
+                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule($post->ID) . '</div>';
350 350
                     }
351
-                    if ( $wpinv_euvat->allow_vat_classes() ) {
352
-                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class( $post->ID ) . '</div>';
351
+                    if ($wpinv_euvat->allow_vat_classes()) {
352
+                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class($post->ID) . '</div>';
353 353
                     }
354
-                    echo '<div class="type">' . wpinv_get_item_type( $post->ID ) . '</div>
354
+                    echo '<div class="type">' . wpinv_get_item_type($post->ID) . '</div>
355 355
                 </div>';
356 356
         break;
357 357
     }
358 358
     
359
-    do_action( 'wpinv_items_table_column_item_' . $column, $wpi_item, $post );
359
+    do_action('wpinv_items_table_column_item_' . $column, $wpi_item, $post);
360 360
 }
361
-add_action( 'manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column' );
361
+add_action('manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column');
362 362
 
363 363
 function wpinv_add_items_filters() {
364 364
     global $wpinv_euvat, $typenow;
365 365
 
366 366
     // Checks if the current post type is 'item'
367
-    if ( $typenow == 'wpi_item') {
368
-        if ( $wpinv_euvat->allow_vat_rules() ) {
369
-            echo wpinv_html_select( array(
370
-                    'options'          => array_merge( array( '' => __( 'All VAT rules', 'invoicing' ) ), $wpinv_euvat->get_rules() ),
367
+    if ($typenow == 'wpi_item') {
368
+        if ($wpinv_euvat->allow_vat_rules()) {
369
+            echo wpinv_html_select(array(
370
+                    'options'          => array_merge(array('' => __('All VAT rules', 'invoicing')), $wpinv_euvat->get_rules()),
371 371
                     'name'             => 'vat_rule',
372 372
                     'id'               => 'vat_rule',
373
-                    'selected'         => ( isset( $_GET['vat_rule'] ) ? $_GET['vat_rule'] : '' ),
373
+                    'selected'         => (isset($_GET['vat_rule']) ? $_GET['vat_rule'] : ''),
374 374
                     'show_option_all'  => false,
375 375
                     'show_option_none' => false,
376 376
                     'class'            => 'gdmbx2-text-medium',
377
-                ) );
377
+                ));
378 378
         }
379 379
         
380
-        if ( $wpinv_euvat->allow_vat_classes() ) {
381
-            echo wpinv_html_select( array(
382
-                    'options'          => array_merge( array( '' => __( 'All VAT classes', 'invoicing' ) ), $wpinv_euvat->get_all_classes() ),
380
+        if ($wpinv_euvat->allow_vat_classes()) {
381
+            echo wpinv_html_select(array(
382
+                    'options'          => array_merge(array('' => __('All VAT classes', 'invoicing')), $wpinv_euvat->get_all_classes()),
383 383
                     'name'             => 'vat_class',
384 384
                     'id'               => 'vat_class',
385
-                    'selected'         => ( isset( $_GET['vat_class'] ) ? $_GET['vat_class'] : '' ),
385
+                    'selected'         => (isset($_GET['vat_class']) ? $_GET['vat_class'] : ''),
386 386
                     'show_option_all'  => false,
387 387
                     'show_option_none' => false,
388 388
                     'class'            => 'gdmbx2-text-medium',
389
-                ) );
389
+                ));
390 390
         }
391 391
             
392
-        echo wpinv_html_select( array(
393
-                'options'          => array_merge( array( '' => __( 'All item types', 'invoicing' ) ), wpinv_get_item_types() ),
392
+        echo wpinv_html_select(array(
393
+                'options'          => array_merge(array('' => __('All item types', 'invoicing')), wpinv_get_item_types()),
394 394
                 'name'             => 'type',
395 395
                 'id'               => 'type',
396
-                'selected'         => ( isset( $_GET['type'] ) ? $_GET['type'] : '' ),
396
+                'selected'         => (isset($_GET['type']) ? $_GET['type'] : ''),
397 397
                 'show_option_all'  => false,
398 398
                 'show_option_none' => false,
399 399
                 'class'            => 'gdmbx2-text-medium',
400
-            ) );
400
+            ));
401 401
 
402
-        if ( isset( $_REQUEST['all_posts'] ) && '1' === $_REQUEST['all_posts'] ) {
402
+        if (isset($_REQUEST['all_posts']) && '1' === $_REQUEST['all_posts']) {
403 403
             echo '<input type="hidden" name="all_posts" value="1" />';
404 404
         }
405 405
     }
406 406
 }
407
-add_action( 'restrict_manage_posts', 'wpinv_add_items_filters', 100 );
407
+add_action('restrict_manage_posts', 'wpinv_add_items_filters', 100);
408 408
 
409
-function wpinv_send_invoice_after_save( $post_id ) {
409
+function wpinv_send_invoice_after_save($post_id) {
410 410
     // If this is just a revision, don't send the email.
411
-    if ( wp_is_post_revision( $post_id ) ) {
411
+    if (wp_is_post_revision($post_id)) {
412 412
         return;
413 413
     }
414 414
     
415
-    if ( !current_user_can( 'manage_options' ) || !(get_post_type( $post_id ) == 'wpi_invoice' || get_post_type( $post_id ) == 'wpi_quote')  ) {
415
+    if (!current_user_can('manage_options') || !(get_post_type($post_id) == 'wpi_invoice' || get_post_type($post_id) == 'wpi_quote')) {
416 416
         return;
417 417
     }
418 418
     
419
-    if ( !empty( $_POST['wpi_save_send'] ) ) {
420
-        wpinv_user_invoice_notification( $post_id );
419
+    if (!empty($_POST['wpi_save_send'])) {
420
+        wpinv_user_invoice_notification($post_id);
421 421
     }
422 422
 }
423
-add_action( 'save_post_wpi_invoice', 'wpinv_send_invoice_after_save', 100, 1 );
423
+add_action('save_post_wpi_invoice', 'wpinv_send_invoice_after_save', 100, 1);
424 424
 
425
-function wpinv_send_register_new_user( $data, $postarr ) {
426
-    if ( current_user_can( 'manage_options' ) && !empty( $data['post_type'] ) && $data['post_type'] == 'wpi_invoice' ) {
427
-        $is_new_user = !empty( $postarr['wpinv_new_user'] ) ? true : false;
428
-        $email = !empty( $postarr['wpinv_email'] ) && $postarr['wpinv_email'] && is_email( $postarr['wpinv_email'] ) ? $postarr['wpinv_email'] : NULL;
425
+function wpinv_send_register_new_user($data, $postarr) {
426
+    if (current_user_can('manage_options') && !empty($data['post_type']) && $data['post_type'] == 'wpi_invoice') {
427
+        $is_new_user = !empty($postarr['wpinv_new_user']) ? true : false;
428
+        $email = !empty($postarr['wpinv_email']) && $postarr['wpinv_email'] && is_email($postarr['wpinv_email']) ? $postarr['wpinv_email'] : NULL;
429 429
         
430
-        if ( $is_new_user && $email && !email_exists( $email ) ) {
431
-            $first_name = !empty( $postarr['wpinv_first_name'] ) ? sanitize_text_field( $postarr['wpinv_first_name'] ) : '';
432
-            $last_name = !empty( $postarr['wpinv_last_name'] ) ? sanitize_text_field( $postarr['wpinv_last_name'] ) : '';
433
-            $display_name = $first_name || $last_name ? trim( $first_name . ' ' . $last_name ) : '';
434
-            $user_nicename = $display_name ? trim( $display_name ) : $email;
435
-            $user_company = !empty( $postarr['wpinv_company'] ) ? sanitize_text_field( $postarr['wpinv_company'] ) : '';
430
+        if ($is_new_user && $email && !email_exists($email)) {
431
+            $first_name = !empty($postarr['wpinv_first_name']) ? sanitize_text_field($postarr['wpinv_first_name']) : '';
432
+            $last_name = !empty($postarr['wpinv_last_name']) ? sanitize_text_field($postarr['wpinv_last_name']) : '';
433
+            $display_name = $first_name || $last_name ? trim($first_name . ' ' . $last_name) : '';
434
+            $user_nicename = $display_name ? trim($display_name) : $email;
435
+            $user_company = !empty($postarr['wpinv_company']) ? sanitize_text_field($postarr['wpinv_company']) : '';
436 436
             
437
-            $user_login = sanitize_user( str_replace( ' ', '', $display_name ), true );
438
-            if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
439
-                $user_login = sanitize_user( str_replace( ' ', '', $user_company ), true );
437
+            $user_login = sanitize_user(str_replace(' ', '', $display_name), true);
438
+            if (!(validate_username($user_login) && !username_exists($user_login))) {
439
+                $user_login = sanitize_user(str_replace(' ', '', $user_company), true);
440 440
                 
441
-                if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
441
+                if (!(validate_username($user_login) && !username_exists($user_login))) {
442 442
                     $user_login = $email;
443 443
                 }
444 444
             }
445 445
             
446 446
             $userdata = array(
447 447
                 'user_login' => $user_login,
448
-                'user_pass' => wp_generate_password( 12, false ),
449
-                'user_email' => sanitize_text_field( $email ),
448
+                'user_pass' => wp_generate_password(12, false),
449
+                'user_email' => sanitize_text_field($email),
450 450
                 'first_name' => $first_name,
451 451
                 'last_name' => $last_name,
452
-                'user_nicename' => wpinv_utf8_substr( $user_nicename, 0, 50 ),
452
+                'user_nicename' => wpinv_utf8_substr($user_nicename, 0, 50),
453 453
                 'nickname' => $display_name,
454 454
                 'display_name' => $display_name,
455 455
             );
456 456
 
457
-            $userdata = apply_filters( 'wpinv_register_new_user_data', $userdata );
457
+            $userdata = apply_filters('wpinv_register_new_user_data', $userdata);
458 458
             
459
-            $new_user_id = wp_insert_user( $userdata );
459
+            $new_user_id = wp_insert_user($userdata);
460 460
             
461
-            if ( !is_wp_error( $new_user_id ) ) {
461
+            if (!is_wp_error($new_user_id)) {
462 462
                 $data['post_author'] = $new_user_id;
463 463
                 $_POST['post_author'] = $new_user_id;
464 464
                 $_POST['post_author_override'] = $new_user_id;
@@ -479,27 +479,27 @@  discard block
 block discarded – undo
479 479
                 
480 480
                 $meta = array();
481 481
                 ///$meta['_wpinv_user_id'] = $new_user_id;
482
-                foreach ( $meta_fields as $field ) {
483
-                    $meta['_wpinv_' . $field] = isset( $postarr['wpinv_' . $field] ) ? sanitize_text_field( $postarr['wpinv_' . $field] ) : '';
482
+                foreach ($meta_fields as $field) {
483
+                    $meta['_wpinv_' . $field] = isset($postarr['wpinv_' . $field]) ? sanitize_text_field($postarr['wpinv_' . $field]) : '';
484 484
                 }
485 485
                 
486
-                $meta = apply_filters( 'wpinv_register_new_user_meta', $meta, $new_user_id );
486
+                $meta = apply_filters('wpinv_register_new_user_meta', $meta, $new_user_id);
487 487
 
488 488
                 // Update user meta.
489
-                foreach ( $meta as $key => $value ) {
490
-                    update_user_meta( $new_user_id, $key, $value );
489
+                foreach ($meta as $key => $value) {
490
+                    update_user_meta($new_user_id, $key, $value);
491 491
                 }
492 492
                 
493
-                if ( function_exists( 'wp_send_new_user_notifications' ) ) {
493
+                if (function_exists('wp_send_new_user_notifications')) {
494 494
                     // Send email notifications related to the creation of new user.
495
-                    wp_send_new_user_notifications( $new_user_id, 'user' );
495
+                    wp_send_new_user_notifications($new_user_id, 'user');
496 496
                 }
497 497
             } else {
498
-                wpinv_error_log( $new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__ );
498
+                wpinv_error_log($new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__);
499 499
             }
500 500
         }
501 501
     }
502 502
     
503 503
     return $data;
504 504
 }
505
-add_filter( 'wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2 );
506 505
\ No newline at end of file
506
+add_filter('wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2);
507 507
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/wpinv-upgrade-functions.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -11,37 +11,37 @@
 block discarded – undo
11 11
  * @since 1.0.0
12 12
 */
13 13
 function wpinv_automatic_upgrade() {
14
-    $wpi_version = get_option( 'wpinv_version' );
14
+    $wpi_version = get_option('wpinv_version');
15 15
     
16
-    if ( $wpi_version == WPINV_VERSION ) {
16
+    if ($wpi_version == WPINV_VERSION) {
17 17
         return;
18 18
     }
19 19
     
20
-    if ( version_compare( $wpi_version, '0.0.5', '<' ) ) {
20
+    if (version_compare($wpi_version, '0.0.5', '<')) {
21 21
         wpinv_v005_upgrades();
22 22
     }
23 23
     
24
-    update_option( 'wpinv_version', WPINV_VERSION );
24
+    update_option('wpinv_version', WPINV_VERSION);
25 25
 }
26
-add_action( 'admin_init', 'wpinv_automatic_upgrade' );
26
+add_action('admin_init', 'wpinv_automatic_upgrade');
27 27
 
28 28
 function wpinv_v005_upgrades() {
29 29
     global $wpdb;
30 30
     
31 31
     // Invoices status
32
-    $wpdb->query( "UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
32
+    $wpdb->query("UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
33 33
     
34 34
     // Item meta key changes
35 35
     $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
36
-    $results = $wpdb->get_results( $query );
36
+    $results = $wpdb->get_results($query);
37 37
     
38
-    if ( !empty( $results ) ) {
39
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
40
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
41
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
38
+    if (!empty($results)) {
39
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )");
40
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'");
41
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'");
42 42
         
43
-        foreach ( $results as $row ) {
44
-            clean_post_cache( $row->post_id );
43
+        foreach ($results as $row) {
44
+            clean_post_cache($row->post_id);
45 45
         }
46 46
     }
47 47
 }
48 48
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-mb-invoice-items.php 1 patch
Spacing   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -1,22 +1,22 @@  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_Items {
8
-    public static function output( $post ) {        
8
+    public static function output($post) {        
9 9
         global $wpinv_euvat, $ajax_cart_details;
10 10
         
11
-        $post_id            = !empty( $post->ID ) ? $post->ID : 0;
12
-        $invoice            = new WPInv_Invoice( $post_id );
11
+        $post_id            = !empty($post->ID) ? $post->ID : 0;
12
+        $invoice            = new WPInv_Invoice($post_id);
13 13
         $ajax_cart_details  = $invoice->get_cart_details();
14
-        $subtotal           = $invoice->get_subtotal( true );
14
+        $subtotal           = $invoice->get_subtotal(true);
15 15
         $discount_raw       = $invoice->get_discount();
16
-        $discount           = wpinv_price( $discount_raw, $invoice->get_currency() );
16
+        $discount           = wpinv_price($discount_raw, $invoice->get_currency());
17 17
         $discounts          = $discount_raw > 0 ? $invoice->get_discounts() : '';
18
-        $tax                = $invoice->get_tax( true );
19
-        $total              = $invoice->get_total( true );
18
+        $tax                = $invoice->get_tax(true);
19
+        $total              = $invoice->get_total(true);
20 20
         $item_quantities    = wpinv_item_quantities_enabled();
21 21
         $use_taxes          = wpinv_use_taxes();
22 22
         $item_types         = wpinv_get_item_types();
@@ -29,17 +29,17 @@  discard block
 block discarded – undo
29 29
         }
30 30
         
31 31
         $cols = 5;
32
-        if ( $item_quantities ) {
32
+        if ($item_quantities) {
33 33
             $cols++;
34 34
         }
35
-        if ( $use_taxes ) {
35
+        if ($use_taxes) {
36 36
             $cols++;
37 37
         }
38 38
         $class = '';
39
-        if ( $invoice->is_paid() ) {
39
+        if ($invoice->is_paid()) {
40 40
             $class .= ' wpinv-paid';
41 41
         }
42
-        if ( $is_recurring ) {
42
+        if ($is_recurring) {
43 43
             $class .= ' wpi-recurring';
44 44
         }
45 45
         ?>
@@ -47,21 +47,21 @@  discard block
 block discarded – undo
47 47
             <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0">
48 48
                 <thead>
49 49
                     <tr>
50
-                        <th class="id"><?php _e( 'ID', 'invoicing' );?></th>
51
-                        <th class="title"><?php _e( 'Item', 'invoicing' );?></th>
52
-                        <th class="price"><?php _e( 'Price', 'invoicing' );?></th>
53
-                        <?php if ( $item_quantities ) { ?>
54
-                        <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th>
50
+                        <th class="id"><?php _e('ID', 'invoicing'); ?></th>
51
+                        <th class="title"><?php _e('Item', 'invoicing'); ?></th>
52
+                        <th class="price"><?php _e('Price', 'invoicing'); ?></th>
53
+                        <?php if ($item_quantities) { ?>
54
+                        <th class="qty"><?php _e('Qty', 'invoicing'); ?></th>
55 55
                         <?php } ?>
56
-                        <th class="total"><?php _e( 'Total', 'invoicing' );?></th>
57
-                        <?php if ( $use_taxes ) { ?>
58
-                        <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th>
56
+                        <th class="total"><?php _e('Total', 'invoicing'); ?></th>
57
+                        <?php if ($use_taxes) { ?>
58
+                        <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th>
59 59
                         <?php } ?>
60 60
                         <th class="action"></th>
61 61
                     </tr>
62 62
                 </thead>
63 63
                 <tbody class="wpinv-line-items">
64
-                    <?php echo wpinv_admin_get_line_items( $invoice ); ?>
64
+                    <?php echo wpinv_admin_get_line_items($invoice); ?>
65 65
                 </tbody>
66 66
                 <tfoot class="wpinv-totals">
67 67
                     <tr>
@@ -73,44 +73,44 @@  discard block
 block discarded – undo
73 73
                                         </td>
74 74
                                         <td class="title">
75 75
                                             <input type="text" class="regular-text" placeholder="Item name" value="" name="_wpinv_quick[name]">
76
-                                            <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?>
76
+                                            <?php if ($wpinv_euvat->allow_vat_rules()) { ?>
77 77
                                             <div class="wp-clearfix">
78 78
                                                 <label class="wpi-vat-rule">
79
-                                                    <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span>
79
+                                                    <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span>
80 80
                                                     <span class="input-text-wrap">
81
-                                                        <?php echo wpinv_html_select( array(
81
+                                                        <?php echo wpinv_html_select(array(
82 82
                                                             'options'          => $wpinv_euvat->get_rules(),
83 83
                                                             'name'             => '_wpinv_quick[vat_rule]',
84 84
                                                             'id'               => '_wpinv_quick_vat_rule',
85 85
                                                             'show_option_all'  => false,
86 86
                                                             'show_option_none' => false,
87 87
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-rule',
88
-                                                        ) ); ?>
88
+                                                        )); ?>
89 89
                                                     </span>
90 90
                                                 </label>
91 91
                                             </div>
92
-                                            <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?>
92
+                                            <?php } if ($wpinv_euvat->allow_vat_classes()) { ?>
93 93
                                             <div class="wp-clearfix">
94 94
                                                 <label class="wpi-vat-class">
95
-                                                    <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span>
95
+                                                    <span class="title"><?php _e('VAT class', 'invoicing'); ?></span>
96 96
                                                     <span class="input-text-wrap">
97
-                                                        <?php echo wpinv_html_select( array(
97
+                                                        <?php echo wpinv_html_select(array(
98 98
                                                             'options'          => $wpinv_euvat->get_all_classes(),
99 99
                                                             'name'             => '_wpinv_quick[vat_class]',
100 100
                                                             'id'               => '_wpinv_quick_vat_class',
101 101
                                                             'show_option_all'  => false,
102 102
                                                             'show_option_none' => false,
103 103
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-class',
104
-                                                        ) ); ?>
104
+                                                        )); ?>
105 105
                                                     </span>
106 106
                                                 </label>
107 107
                                             </div>
108 108
                                             <?php } ?>
109 109
                                             <div class="wp-clearfix">
110 110
                                                 <label class="wpi-item-type">
111
-                                                    <span class="title"><?php _e( 'Item type', 'invoicing' );?></span>
111
+                                                    <span class="title"><?php _e('Item type', 'invoicing'); ?></span>
112 112
                                                     <span class="input-text-wrap">
113
-                                                        <?php echo wpinv_html_select( array(
113
+                                                        <?php echo wpinv_html_select(array(
114 114
                                                             'options'          => $item_types,
115 115
                                                             'name'             => '_wpinv_quick[type]',
116 116
                                                             'id'               => '_wpinv_quick_type',
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
                                                             'show_option_all'  => false,
119 119
                                                             'show_option_none' => false,
120 120
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-type',
121
-                                                        ) ); ?>
121
+                                                        )); ?>
122 122
                                                     </span>
123 123
                                                 </label>
124 124
                                             </div>
@@ -131,11 +131,11 @@  discard block
 block discarded – undo
131 131
                                             </div>
132 132
                                         </td>
133 133
                                         <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td>
134
-                                        <?php if ( $item_quantities ) { ?>
134
+                                        <?php if ($item_quantities) { ?>
135 135
                                         <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td>
136 136
                                         <?php } ?>
137 137
                                         <td class="total"></td>
138
-                                        <?php if ( $use_taxes ) { ?>
138
+                                        <?php if ($use_taxes) { ?>
139 139
                                         <td class="tax"></td>
140 140
                                         <?php } ?>
141 141
                                         <td class="action"></td>
@@ -148,29 +148,29 @@  discard block
 block discarded – undo
148 148
                         <td colspan="<?php echo $cols; ?>"></td>
149 149
                     </tr>
150 150
                     <tr class="totals">
151
-                        <td colspan="<?php echo ( $cols - 4 ); ?>"></td>
151
+                        <td colspan="<?php echo ($cols - 4); ?>"></td>
152 152
                         <td colspan="4">
153 153
                             <table cellspacing="0" cellpadding="0">
154 154
                                 <tr class="subtotal">
155
-                                    <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td>
156
-                                    <td class="total"><?php echo $subtotal;?></td>
155
+                                    <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td>
156
+                                    <td class="total"><?php echo $subtotal; ?></td>
157 157
                                     <td class="action"></td>
158 158
                                 </tr>
159 159
                                 <tr class="discount">
160
-                                    <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td>
161
-                                    <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td>
160
+                                    <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td>
161
+                                    <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td>
162 162
                                     <td class="action"></td>
163 163
                                 </tr>
164
-                                <?php if ( $use_taxes ) { ?>
164
+                                <?php if ($use_taxes) { ?>
165 165
                                 <tr class="tax">
166
-                                    <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td>
167
-                                    <td class="total"><?php echo $tax;?></td>
166
+                                    <td class="name"><?php _e('Tax:', 'invoicing'); ?></td>
167
+                                    <td class="total"><?php echo $tax; ?></td>
168 168
                                     <td class="action"></td>
169 169
                                 </tr>
170 170
                                 <?php } ?>
171 171
                                 <tr class="total">
172
-                                    <td class="name"><?php _e( 'Invoice Total:', 'invoicing' );?></td>
173
-                                    <td class="total"><?php echo $total;?></td>
172
+                                    <td class="name"><?php _e('Invoice Total:', 'invoicing'); ?></td>
173
+                                    <td class="total"><?php echo $total; ?></td>
174 174
                                     <td class="action"></td>
175 175
                                 </tr>
176 176
                             </table>
@@ -180,89 +180,89 @@  discard block
 block discarded – undo
180 180
             </table>
181 181
             <div class="wpinv-actions">
182 182
                 <?php
183
-                    if ( !$invoice->is_paid() ) {
184
-                    if ( !$invoice->is_recurring() ) {
185
-                    echo wpinv_item_dropdown( array(
183
+                    if (!$invoice->is_paid()) {
184
+                    if (!$invoice->is_recurring()) {
185
+                    echo wpinv_item_dropdown(array(
186 186
                         'name'             => 'wpinv_invoice_item',
187 187
                         'id'               => 'wpinv_invoice_item',
188 188
                         'with_packages'    => false,
189 189
                         'show_recurring'   => true,
190
-                    ) );
190
+                    ));
191 191
                     ?>
192
-                <input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
192
+                <input type="button" value="<?php echo sprintf(esc_attr__('Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e('Create new item', 'invoicing'); ?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e('Recalculate Totals', 'invoicing'); ?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
193 193
                     <?php } ?>
194
-                <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?>
194
+                <?php do_action('wpinv_invoice_items_actions', $invoice); ?>
195 195
             </div>
196 196
         </div>
197 197
         <?php
198 198
     }
199 199
     
200
-    public static function prices( $post ) {        
200
+    public static function prices($post) {        
201 201
         $symbol         = wpinv_currency_symbol();
202 202
         $position       = wpinv_currency_position();
203
-        $item           = new WPInv_Item( $post->ID );
203
+        $item           = new WPInv_Item($post->ID);
204 204
         
205 205
         $price          = $item->get_price();
206 206
         $is_recurring   = $item->is_recurring();
207 207
         $period         = $item->get_recurring_period();
208
-        $interval       = absint( $item->get_recurring_interval() );
209
-        $times          = absint( $item->get_recurring_limit() );
208
+        $interval       = absint($item->get_recurring_interval());
209
+        $times          = absint($item->get_recurring_limit());
210 210
         $free_trial     = $item->has_free_trial();
211 211
         $trial_interval = $item->get_trial_interval();
212 212
         $trial_period   = $item->get_trial_period();
213 213
         
214 214
         $intervals      = array();
215
-        for ( $i = 1; $i <= 90; $i++ ) {
215
+        for ($i = 1; $i <= 90; $i++) {
216 216
             $intervals[$i] = $i;
217 217
         }
218 218
         
219
-        $interval       = $interval > 0 ? $interval : 1;
219
+        $interval = $interval > 0 ? $interval : 1;
220 220
         
221 221
         $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n';
222 222
         ?>
223
-        <p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . '&nbsp;' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled( $item->is_package(), true ); ?> /><?php echo ( $position == 'right' ? '&nbsp;' . $symbol : '' );?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce( 'wpinv_item_meta_box_save' ) ;?>" />
224
-        <?php if ( $item->is_package() ) { ?>
225
-        <span class="description"><?php _e( 'GD package item price can be edited only from GD payment manager.', 'invoicing' ); ?></span>
223
+        <p class="wpinv-row-prices"><?php echo ($position != 'right' ? $symbol . '&nbsp;' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled($item->is_package(), true); ?> /><?php echo ($position == 'right' ? '&nbsp;' . $symbol : ''); ?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce('wpinv_item_meta_box_save'); ?>" />
224
+        <?php if ($item->is_package()) { ?>
225
+        <span class="description"><?php _e('GD package item price can be edited only from GD payment manager.', 'invoicing'); ?></span>
226 226
         <?php } ?>
227 227
         </p>
228 228
         <p class="wpinv-row-is-recurring">
229 229
             <label for="wpinv_is_recurring">
230
-                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> />
231
-                <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?>
230
+                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> />
231
+                <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?>
232 232
             </label>
233 233
         </p>
234
-        <p class="wpinv-row-recurring-fields <?php echo $class;?>">
235
-                <label class="wpinv-period" for="wpinv_recurring_period"><?php _e( 'Recurring', 'invoicing' );?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e( 'day(s)', 'invoicing' ); ?>" <?php selected( 'D', $period );?>><?php _e( 'Daily', 'invoicing' ); ?></option><option value="W" data-text="<?php esc_attr_e( 'week(s)', 'invoicing' ); ?>" <?php selected( 'W', $period );?>><?php _e( 'Weekly', 'invoicing' ); ?></option><option value="M" data-text="<?php esc_attr_e( 'month(s)', 'invoicing' ); ?>" <?php selected( 'M', $period );?>><?php _e( 'Monthly', 'invoicing' ); ?></option><option value="Y" data-text="<?php esc_attr_e( 'year(s)', 'invoicing' ); ?>" <?php selected( 'Y', $period );?>><?php _e( 'Yearly', 'invoicing' ); ?></option></select></label>
236
-                <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array(
234
+        <p class="wpinv-row-recurring-fields <?php echo $class; ?>">
235
+                <label class="wpinv-period" for="wpinv_recurring_period"><?php _e('Recurring', 'invoicing'); ?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e('day(s)', 'invoicing'); ?>" <?php selected('D', $period); ?>><?php _e('Daily', 'invoicing'); ?></option><option value="W" data-text="<?php esc_attr_e('week(s)', 'invoicing'); ?>" <?php selected('W', $period); ?>><?php _e('Weekly', 'invoicing'); ?></option><option value="M" data-text="<?php esc_attr_e('month(s)', 'invoicing'); ?>" <?php selected('M', $period); ?>><?php _e('Monthly', 'invoicing'); ?></option><option value="Y" data-text="<?php esc_attr_e('year(s)', 'invoicing'); ?>" <?php selected('Y', $period); ?>><?php _e('Yearly', 'invoicing'); ?></option></select></label>
236
+                <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array(
237 237
                     'options'          => $intervals,
238 238
                     'name'             => 'wpinv_recurring_interval',
239 239
                     'id'               => 'wpinv_recurring_interval',
240 240
                     'selected'         => $interval,
241 241
                     'show_option_all'  => false,
242 242
                     'show_option_none' => false
243
-                ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label>
244
-                <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e( 'for', 'invoicing' );?> <input class="small-text" type="number" value="<?php echo $times;?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e( 'time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing' );?></label>
243
+                )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label>
244
+                <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e('for', 'invoicing'); ?> <input class="small-text" type="number" value="<?php echo $times; ?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e('time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing'); ?></label>
245 245
                 <span class="clear wpi-trial-clr"></span>
246 246
                 <label class="wpinv-free-trial" for="wpinv_free_trial">
247
-                    <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> 
248
-                    <?php echo __( 'Offer free trial for', 'invoicing' ); ?>
247
+                    <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool)$free_trial); ?> /> 
248
+                    <?php echo __('Offer free trial for', 'invoicing'); ?>
249 249
                 </label>
250 250
                 <label class="wpinv-trial-interval" for="wpinv_trial_interval">
251
-                    <input class="small-text" type="number" value="<?php echo $trial_interval;?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected( 'D', $trial_period );?>><?php _e( 'day(s)', 'invoicing' ); ?></option><option value="W" <?php selected( 'W', $trial_period );?>><?php _e( 'week(s)', 'invoicing' ); ?></option><option value="M" <?php selected( 'M', $trial_period );?>><?php _e( 'month(s)', 'invoicing' ); ?></option><option value="Y" <?php selected( 'Y', $trial_period );?>><?php _e( 'year(s)', 'invoicing' ); ?></option></select>
251
+                    <input class="small-text" type="number" value="<?php echo $trial_interval; ?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected('D', $trial_period); ?>><?php _e('day(s)', 'invoicing'); ?></option><option value="W" <?php selected('W', $trial_period); ?>><?php _e('week(s)', 'invoicing'); ?></option><option value="M" <?php selected('M', $trial_period); ?>><?php _e('month(s)', 'invoicing'); ?></option><option value="Y" <?php selected('Y', $trial_period); ?>><?php _e('year(s)', 'invoicing'); ?></option></select>
252 252
                 </label>
253 253
         </p>
254
-        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" />
255
-        <?php do_action( 'wpinv_item_price_field', $post->ID ); ?>
254
+        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" />
255
+        <?php do_action('wpinv_item_price_field', $post->ID); ?>
256 256
         <?php
257 257
     }
258 258
     
259
-    public static function vat_rules( $post ) {
259
+    public static function vat_rules($post) {
260 260
         global $wpinv_euvat;
261 261
         
262
-        $rule_type = $wpinv_euvat->get_item_rule( $post->ID );
262
+        $rule_type = $wpinv_euvat->get_item_rule($post->ID);
263 263
         ?>
264
-        <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
265
-        <?php echo wpinv_html_select( array(
264
+        <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
265
+        <?php echo wpinv_html_select(array(
266 266
                     'options'          => $wpinv_euvat->get_rules(),
267 267
                     'name'             => 'wpinv_vat_rules',
268 268
                     'id'               => 'wpinv_vat_rules',
@@ -270,19 +270,19 @@  discard block
 block discarded – undo
270 270
                     'show_option_all'  => false,
271 271
                     'show_option_none' => false,
272 272
                     'class'            => 'gdmbx2-text-medium wpinv-vat-rules',
273
-                ) ); ?>
273
+                )); ?>
274 274
         </p>
275
-        <p class="wpi-m0"><?php _e( 'When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing' ); ?></p>
276
-        <p class="wpi-m0"><?php _e( 'If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing' ); ?></p>
275
+        <p class="wpi-m0"><?php _e('When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing'); ?></p>
276
+        <p class="wpi-m0"><?php _e('If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing'); ?></p>
277 277
         <?php
278 278
     }
279 279
     
280
-    public static function vat_classes( $post ) {
280
+    public static function vat_classes($post) {
281 281
         global $wpinv_euvat;
282 282
         
283
-        $vat_class = $wpinv_euvat->get_item_class( $post->ID );
283
+        $vat_class = $wpinv_euvat->get_item_class($post->ID);
284 284
         ?>
285
-        <p><?php echo wpinv_html_select( array(
285
+        <p><?php echo wpinv_html_select(array(
286 286
                     'options'          => $wpinv_euvat->get_all_classes(),
287 287
                     'name'             => 'wpinv_vat_class',
288 288
                     'id'               => 'wpinv_vat_class',
@@ -290,18 +290,18 @@  discard block
 block discarded – undo
290 290
                     'show_option_all'  => false,
291 291
                     'show_option_none' => false,
292 292
                     'class'            => 'gdmbx2-text-medium wpinv-vat-class',
293
-                ) ); ?>
293
+                )); ?>
294 294
         </p>
295
-        <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p>
295
+        <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p>
296 296
         <?php
297 297
     }
298 298
     
299
-    public static function item_info( $post ) {
300
-        $item_type = wpinv_get_item_type( $post->ID );
301
-        do_action( 'wpinv_item_info_metabox_before', $post );
299
+    public static function item_info($post) {
300
+        $item_type = wpinv_get_item_type($post->ID);
301
+        do_action('wpinv_item_info_metabox_before', $post);
302 302
         ?>
303
-        <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
304
-        <?php echo wpinv_html_select( array(
303
+        <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
304
+        <?php echo wpinv_html_select(array(
305 305
                     'options'          => wpinv_get_item_types(),
306 306
                     'name'             => 'wpinv_item_type',
307 307
                     'id'               => 'wpinv_item_type',
@@ -310,114 +310,114 @@  discard block
 block discarded – undo
310 310
                     'show_option_none' => false,
311 311
                     'class'            => 'gdmbx2-text-medium wpinv-item-type',
312 312
                     //'disabled'         => $item_type == 'package' ? true : false,
313
-                ) ); ?>
313
+                )); ?>
314 314
         </p>
315
-        <p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( 'Standard: standard item type', 'invoicing' );?><br><?php _e( 'Fee: like Registration Fee, Signup Fee etc.', 'invoicing' );?></p>
315
+        <p class="wpi-m0"><?php _e('Select item type.', 'invoicing'); ?><br><?php _e('Standard: standard item type', 'invoicing'); ?><br><?php _e('Fee: like Registration Fee, Signup Fee etc.', 'invoicing'); ?></p>
316 316
         <?php
317
-        do_action( 'wpinv_item_info_metabox_after', $post );
317
+        do_action('wpinv_item_info_metabox_after', $post);
318 318
     }
319 319
     
320
-    public static function meta_values( $post ) {
321
-        $meta_keys = apply_filters( 'wpinv_show_meta_values_for_keys', array(
320
+    public static function meta_values($post) {
321
+        $meta_keys = apply_filters('wpinv_show_meta_values_for_keys', array(
322 322
             'type',
323 323
             'custom_id'
324
-        ) );
324
+        ));
325 325
         
326
-        if ( empty( $meta_keys ) ) {
326
+        if (empty($meta_keys)) {
327 327
             return;
328 328
         }
329 329
         
330
-        do_action( 'wpinv_meta_values_metabox_before', $post );
330
+        do_action('wpinv_meta_values_metabox_before', $post);
331 331
         
332
-        foreach ( $meta_keys as $meta_key ) {
332
+        foreach ($meta_keys as $meta_key) {
333 333
             ?>
334
-            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta( $post->ID, '_wpinv_' . $meta_key, true ); ?></label></p>
334
+            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta($post->ID, '_wpinv_' . $meta_key, true); ?></label></p>
335 335
             <?php 
336 336
         }
337 337
         
338
-        do_action( 'wpinv_meta_values_metabox_after', $post );
338
+        do_action('wpinv_meta_values_metabox_after', $post);
339 339
     }
340 340
     
341
-    public static function save( $post_id, $data, $post ) {
342
-        $invoice        = new WPInv_Invoice( $post_id );
341
+    public static function save($post_id, $data, $post) {
342
+        $invoice        = new WPInv_Invoice($post_id);
343 343
         
344 344
         // Billing
345
-        $first_name     = sanitize_text_field( $data['wpinv_first_name'] );
346
-        $last_name      = sanitize_text_field( $data['wpinv_last_name'] );
347
-        $company        = sanitize_text_field( $data['wpinv_company'] );
348
-        $vat_number     = sanitize_text_field( $data['wpinv_vat_number'] );
349
-        $phone          = sanitize_text_field( $data['wpinv_phone'] );
350
-        $address        = sanitize_text_field( $data['wpinv_address'] );
351
-        $city           = sanitize_text_field( $data['wpinv_city'] );
352
-        $zip            = sanitize_text_field( $data['wpinv_zip'] );
353
-        $country        = sanitize_text_field( $data['wpinv_country'] );
354
-        $state          = sanitize_text_field( $data['wpinv_state'] );
345
+        $first_name     = sanitize_text_field($data['wpinv_first_name']);
346
+        $last_name      = sanitize_text_field($data['wpinv_last_name']);
347
+        $company        = sanitize_text_field($data['wpinv_company']);
348
+        $vat_number     = sanitize_text_field($data['wpinv_vat_number']);
349
+        $phone          = sanitize_text_field($data['wpinv_phone']);
350
+        $address        = sanitize_text_field($data['wpinv_address']);
351
+        $city           = sanitize_text_field($data['wpinv_city']);
352
+        $zip            = sanitize_text_field($data['wpinv_zip']);
353
+        $country        = sanitize_text_field($data['wpinv_country']);
354
+        $state          = sanitize_text_field($data['wpinv_state']);
355 355
         
356 356
         // Details
357
-        $status         = sanitize_text_field( $data['wpinv_status'] );
358
-        $old_status     = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status;
359
-        $number         = sanitize_text_field( $data['wpinv_number'] );
360
-        $due_date       = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : '';
357
+        $status         = sanitize_text_field($data['wpinv_status']);
358
+        $old_status     = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status;
359
+        $number         = sanitize_text_field($data['wpinv_number']);
360
+        $due_date       = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : '';
361 361
         //$discounts      = sanitize_text_field( $data['wpinv_discounts'] );
362 362
         //$discount       = sanitize_text_field( $data['wpinv_discount'] );
363 363
         
364
-        $ip             = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
364
+        $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
365 365
         
366
-        $invoice->set( 'due_date', $due_date );
367
-        $invoice->set( 'first_name', $first_name );
368
-        $invoice->set( 'last_name', $last_name );
369
-        $invoice->set( 'company', $company );
370
-        $invoice->set( 'vat_number', $vat_number );
371
-        $invoice->set( 'phone', $phone );
372
-        $invoice->set( 'address', $address );
373
-        $invoice->set( 'city', $city );
374
-        $invoice->set( 'zip', $zip );
375
-        $invoice->set( 'country', $country );
376
-        $invoice->set( 'state', $state );
377
-        $invoice->set( 'status', $status );
378
-        $invoice->set( 'number', $number );
366
+        $invoice->set('due_date', $due_date);
367
+        $invoice->set('first_name', $first_name);
368
+        $invoice->set('last_name', $last_name);
369
+        $invoice->set('company', $company);
370
+        $invoice->set('vat_number', $vat_number);
371
+        $invoice->set('phone', $phone);
372
+        $invoice->set('address', $address);
373
+        $invoice->set('city', $city);
374
+        $invoice->set('zip', $zip);
375
+        $invoice->set('country', $country);
376
+        $invoice->set('state', $state);
377
+        $invoice->set('status', $status);
378
+        $invoice->set('number', $number);
379 379
         //$invoice->set( 'discounts', $discounts );
380 380
         //$invoice->set( 'discount', $discount );
381
-        $invoice->set( 'ip', $ip );
381
+        $invoice->set('ip', $ip);
382 382
         $invoice->old_status = $_POST['original_post_status'];
383 383
         $invoice->currency = wpinv_get_currency();
384
-        if ( !empty( $data['wpinv_gateway'] ) ) {
385
-            $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) );
384
+        if (!empty($data['wpinv_gateway'])) {
385
+            $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway']));
386 386
         }
387 387
         $saved = $invoice->save();
388 388
         
389 389
         // Check for payment notes
390
-        if ( !empty( $data['invoice_note'] ) ) {
391
-            $note               = wp_kses( $data['invoice_note'], array() );
392
-            $note_type          = sanitize_text_field( $data['invoice_note_type'] );
390
+        if (!empty($data['invoice_note'])) {
391
+            $note               = wp_kses($data['invoice_note'], array());
392
+            $note_type          = sanitize_text_field($data['invoice_note_type']);
393 393
             $is_customer_note   = $note_type == 'customer' ? 1 : 0;
394 394
         
395
-            wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note );
395
+            wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note);
396 396
         }
397 397
         
398 398
         // Update user address if empty.
399
-        if ( $saved && !empty( $invoice ) ) {
400
-            if ( $user_id = $invoice->get_user_id() ) {
401
-                $user_address = wpinv_get_user_address( $user_id, false );
399
+        if ($saved && !empty($invoice)) {
400
+            if ($user_id = $invoice->get_user_id()) {
401
+                $user_address = wpinv_get_user_address($user_id, false);
402 402
                 
403 403
                 if (empty($user_address['first_name'])) {
404
-                    update_user_meta( $user_id, '_wpinv_first_name', $first_name );
405
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
404
+                    update_user_meta($user_id, '_wpinv_first_name', $first_name);
405
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
406 406
                 } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) {
407
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
407
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
408 408
                 }
409 409
                 
410 410
                 if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) {
411
-                    update_user_meta( $user_id, '_wpinv_address', $address );
412
-                    update_user_meta( $user_id, '_wpinv_city', $city );
413
-                    update_user_meta( $user_id, '_wpinv_state', $state );
414
-                    update_user_meta( $user_id, '_wpinv_country', $country );
415
-                    update_user_meta( $user_id, '_wpinv_zip', $zip );
416
-                    update_user_meta( $user_id, '_wpinv_phone', $phone );
411
+                    update_user_meta($user_id, '_wpinv_address', $address);
412
+                    update_user_meta($user_id, '_wpinv_city', $city);
413
+                    update_user_meta($user_id, '_wpinv_state', $state);
414
+                    update_user_meta($user_id, '_wpinv_country', $country);
415
+                    update_user_meta($user_id, '_wpinv_zip', $zip);
416
+                    update_user_meta($user_id, '_wpinv_phone', $phone);
417 417
                 }
418 418
             }
419 419
             
420
-            do_action( 'wpinv_invoice_metabox_saved', $invoice );
420
+            do_action('wpinv_invoice_metabox_saved', $invoice);
421 421
         }
422 422
         
423 423
         return $saved;
Please login to merge, or discard this patch.
includes/admin/class-wpinv-recurring-admin.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit; // Exit if accessed directly
4 4
 }
5 5
 
@@ -20,13 +20,13 @@  discard block
 block discarded – undo
20 20
      * @return void
21 21
      */
22 22
     private function actions() {
23
-        add_action( 'admin_menu', array( $this, 'add_submenu' ), 11 );
23
+        add_action('admin_menu', array($this, 'add_submenu'), 11);
24 24
 
25 25
         // Register styles
26
-        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
26
+        add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
27 27
 
28 28
         // Register scripts
29
-        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
29
+        add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
30 30
     }
31 31
 
32 32
     /**
@@ -43,11 +43,11 @@  discard block
 block discarded – undo
43 43
         
44 44
         $wpi_subscriptions_page = add_submenu_page( 
45 45
             'wpinv', 
46
-            __( 'Subscriptions', 'invoicing' ), 
47
-            __( 'Subscriptions', 'invoicing' ), 
46
+            __('Subscriptions', 'invoicing'), 
47
+            __('Subscriptions', 'invoicing'), 
48 48
             'manage_options', 
49 49
             'wpinv-subscriptions', 
50
-            array( $this, 'subscriptions_page' ) 
50
+            array($this, 'subscriptions_page') 
51 51
         );
52 52
     }
53 53
     
Please login to merge, or discard this patch.
includes/admin/subscriptions.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -10,8 +10,8 @@
 block discarded – undo
10 10
     ?>
11 11
     <div class="wrap">
12 12
         <h1>
13
-            <?php _e( 'Subscriptions', 'invoicing' ); ?>
14
-            <a href="<?php echo esc_url( add_query_arg( array( 'wpi_action' => 'add_subscription' ) ) ); ?>" class="add-new-h2"><?php _e( 'Add New', 'invoicing' ); ?></a>
13
+            <?php _e('Subscriptions', 'invoicing'); ?>
14
+            <a href="<?php echo esc_url(add_query_arg(array('wpi_action' => 'add_subscription'))); ?>" class="add-new-h2"><?php _e('Add New', 'invoicing'); ?></a>
15 15
         </h1>
16 16
         <?php
17 17
         //$subscribers_table = new EDD_Subscription_Reports_Table();
Please login to merge, or discard this patch.
includes/admin/admin-meta-boxes.php 1 patch
Spacing   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -1,65 +1,65 @@  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
-function wpinv_add_meta_boxes( $post_type, $post ) {
7
+function wpinv_add_meta_boxes($post_type, $post) {
8 8
     global $wpi_mb_invoice;
9
-    if ( $post_type == 'wpi_invoice' && !empty( $post->ID ) ) {
10
-        $wpi_mb_invoice = wpinv_get_invoice( $post->ID );
9
+    if ($post_type == 'wpi_invoice' && !empty($post->ID)) {
10
+        $wpi_mb_invoice = wpinv_get_invoice($post->ID);
11 11
     }
12 12
     
13
-    if ( !empty( $wpi_mb_invoice ) && !$wpi_mb_invoice->has_status( array( 'draft', 'auto-draft' ) ) ) {
14
-        add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high' );
13
+    if (!empty($wpi_mb_invoice) && !$wpi_mb_invoice->has_status(array('draft', 'auto-draft'))) {
14
+        add_meta_box('wpinv-mb-resend-invoice', __('Resend Invoice', 'invoicing'), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high');
15 15
     }
16 16
     
17
-    if ( !empty( $wpi_mb_invoice ) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent() ) {
18
-        add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscriptions', 'invoicing' ), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high' );
17
+    if (!empty($wpi_mb_invoice) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent()) {
18
+        add_meta_box('wpinv-mb-subscriptions', __('Subscriptions', 'invoicing'), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high');
19 19
     }
20 20
     
21
-    if ( wpinv_is_subscription_payment( $wpi_mb_invoice ) ) {
22
-        add_meta_box( 'wpinv-mb-renewals', __( 'Renewal Payment', 'invoicing' ), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high' );
21
+    if (wpinv_is_subscription_payment($wpi_mb_invoice)) {
22
+        add_meta_box('wpinv-mb-renewals', __('Renewal Payment', 'invoicing'), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high');
23 23
     }
24 24
     
25
-    add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default' );
26
-    add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default' );
25
+    add_meta_box('wpinv-details', __('Invoice Details', 'invoicing'), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default');
26
+    add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default');
27 27
    
28
-    add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high' );
29
-    add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high' );
30
-    add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' );
28
+    add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high');
29
+    add_meta_box('wpinv-items', __('Invoice Items', 'invoicing'), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high');
30
+    add_meta_box('wpinv-notes', __('Invoice Notes', 'invoicing'), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high');
31 31
 }
32
-add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 );
32
+add_action('add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2);
33 33
 
34
-function wpinv_save_meta_boxes( $post_id, $post, $update = false ) {
35
-    remove_action( 'save_post', __FUNCTION__ );
34
+function wpinv_save_meta_boxes($post_id, $post, $update = false) {
35
+    remove_action('save_post', __FUNCTION__);
36 36
     
37 37
     // $post_id and $post are required
38
-    if ( empty( $post_id ) || empty( $post ) ) {
38
+    if (empty($post_id) || empty($post)) {
39 39
         return;
40 40
     }
41 41
         
42
-    if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) {
42
+    if (!current_user_can('edit_post', $post_id) || empty($post->post_type)) {
43 43
         return;
44 44
     }
45 45
     
46 46
     // Dont' save meta boxes for revisions or autosaves
47
-    if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
47
+    if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
48 48
         return;
49 49
     }
50 50
         
51
-    if ( $post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote' ) {
52
-        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
51
+    if ($post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote') {
52
+        if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
53 53
             return;
54 54
         }
55 55
     
56
-        if ( isset( $_POST['wpinv_save_invoice'] ) && wp_verify_nonce( $_POST['wpinv_save_invoice'], 'wpinv_save_invoice' ) ) {
57
-            WPInv_Meta_Box_Items::save( $post_id, $_POST, $post );
56
+        if (isset($_POST['wpinv_save_invoice']) && wp_verify_nonce($_POST['wpinv_save_invoice'], 'wpinv_save_invoice')) {
57
+            WPInv_Meta_Box_Items::save($post_id, $_POST, $post);
58 58
         }
59
-    } else if ( $post->post_type == 'wpi_item' ) {
59
+    } else if ($post->post_type == 'wpi_item') {
60 60
         // verify nonce
61
-        if ( isset( $_POST['wpinv_vat_meta_box_nonce'] ) && wp_verify_nonce( $_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save' ) ) {
62
-            $fields                                 = array();
61
+        if (isset($_POST['wpinv_vat_meta_box_nonce']) && wp_verify_nonce($_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save')) {
62
+            $fields = array();
63 63
             $fields['_wpinv_price']              = 'wpinv_item_price';
64 64
             $fields['_wpinv_vat_class']          = 'wpinv_vat_class';
65 65
             $fields['_wpinv_vat_rule']           = 'wpinv_vat_rules';
@@ -72,296 +72,296 @@  discard block
 block discarded – undo
72 72
             $fields['_wpinv_trial_period']       = 'wpinv_trial_period';
73 73
             $fields['_wpinv_trial_interval']     = 'wpinv_trial_interval';
74 74
             
75
-            if ( !isset( $_POST['wpinv_is_recurring'] ) ) {
75
+            if (!isset($_POST['wpinv_is_recurring'])) {
76 76
                 $_POST['wpinv_is_recurring'] = 0;
77 77
             }
78 78
             
79
-            if ( !isset( $_POST['wpinv_free_trial'] ) || empty( $_POST['wpinv_is_recurring'] ) ) {
79
+            if (!isset($_POST['wpinv_free_trial']) || empty($_POST['wpinv_is_recurring'])) {
80 80
                 $_POST['wpinv_free_trial'] = 0;
81 81
             }
82 82
             
83
-            foreach ( $fields as $field => $name ) {
84
-                if ( isset( $_POST[ $name ] ) ) {
85
-                    if ( $field == '_wpinv_price' ) {
86
-                        if ( get_post_meta( $post_id, '_wpinv_type', true ) === 'package' ) {
87
-                            $value = wpinv_sanitize_amount( get_post_meta( $post_id, '_wpinv_price', true ) ); // Don't allow edit GD package item price.
83
+            foreach ($fields as $field => $name) {
84
+                if (isset($_POST[$name])) {
85
+                    if ($field == '_wpinv_price') {
86
+                        if (get_post_meta($post_id, '_wpinv_type', true) === 'package') {
87
+                            $value = wpinv_sanitize_amount(get_post_meta($post_id, '_wpinv_price', true)); // Don't allow edit GD package item price.
88 88
                         } else {
89
-                            $value = wpinv_sanitize_amount( $_POST[ $name ] );
89
+                            $value = wpinv_sanitize_amount($_POST[$name]);
90 90
                         }
91 91
                     } else {
92
-                        $value = is_string( $_POST[ $name ] ) ? sanitize_text_field( $_POST[ $name ] ) : $_POST[ $name ];
92
+                        $value = is_string($_POST[$name]) ? sanitize_text_field($_POST[$name]) : $_POST[$name];
93 93
                     }
94 94
                     
95
-                    $value = apply_filters( 'wpinv_item_metabox_save_' . $field, $value, $name );
96
-                    update_post_meta( $post_id, $field, $value );
95
+                    $value = apply_filters('wpinv_item_metabox_save_' . $field, $value, $name);
96
+                    update_post_meta($post_id, $field, $value);
97 97
                 }
98 98
             }
99 99
             
100
-            if ( !get_post_meta( $post_id, '_wpinv_custom_id', true ) ) {
101
-                update_post_meta( $post_id, '_wpinv_custom_id', $post_id );
100
+            if (!get_post_meta($post_id, '_wpinv_custom_id', true)) {
101
+                update_post_meta($post_id, '_wpinv_custom_id', $post_id);
102 102
             }
103 103
         }
104 104
     }
105 105
 }
106
-add_action( 'save_post', 'wpinv_save_meta_boxes', 10, 3 );
106
+add_action('save_post', 'wpinv_save_meta_boxes', 10, 3);
107 107
 
108
-function wpinv_bulk_and_quick_edit_save( $post_id, $post, $update = false ) {
109
-    if ( !( !empty( $_POST['action'] ) && $_POST['action'] == 'inline-save' ) ) {
108
+function wpinv_bulk_and_quick_edit_save($post_id, $post, $update = false) {
109
+    if (!(!empty($_POST['action']) && $_POST['action'] == 'inline-save')) {
110 110
         return;
111 111
     }
112 112
     
113 113
     // $post_id and $post are required
114
-    if ( empty( $post_id ) || empty( $post ) ) {
114
+    if (empty($post_id) || empty($post)) {
115 115
         return;
116 116
     }
117 117
         
118
-    if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) {
118
+    if (!current_user_can('edit_post', $post_id) || empty($post->post_type)) {
119 119
         return;
120 120
     }
121 121
     
122 122
     // Dont' save meta boxes for revisions or autosaves
123
-    if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
123
+    if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
124 124
         return;
125 125
     }
126 126
 
127
-    if ( $post->post_type == 'wpi_item' ) {
127
+    if ($post->post_type == 'wpi_item') {
128 128
         // verify nonce
129
-        if ( isset( $_POST['_wpinv_item_price'] ) && get_post_meta( $post->ID, '_wpinv_type', true ) !== 'package' ) {
130
-            update_post_meta( $post_id, '_wpinv_price', wpinv_sanitize_amount( $_POST['_wpinv_item_price'] ) );
129
+        if (isset($_POST['_wpinv_item_price']) && get_post_meta($post->ID, '_wpinv_type', true) !== 'package') {
130
+            update_post_meta($post_id, '_wpinv_price', wpinv_sanitize_amount($_POST['_wpinv_item_price']));
131 131
         }
132 132
         
133
-        if ( isset( $_POST['_wpinv_vat_class'] ) ) {
134
-            update_post_meta( $post_id, '_wpinv_vat_class', sanitize_text_field( $_POST['_wpinv_vat_class'] ) );
133
+        if (isset($_POST['_wpinv_vat_class'])) {
134
+            update_post_meta($post_id, '_wpinv_vat_class', sanitize_text_field($_POST['_wpinv_vat_class']));
135 135
         }
136 136
 
137
-        if ( isset( $_POST['_wpinv_vat_rules'] ) ) {
138
-            update_post_meta( $post_id, '_wpinv_vat_rule', sanitize_text_field( $_POST['_wpinv_vat_rules'] ) );
137
+        if (isset($_POST['_wpinv_vat_rules'])) {
138
+            update_post_meta($post_id, '_wpinv_vat_rule', sanitize_text_field($_POST['_wpinv_vat_rules']));
139 139
         }
140 140
         
141
-        if ( isset( $_POST['_wpinv_item_type'] ) ) {
142
-            update_post_meta( $post_id, '_wpinv_type', sanitize_text_field( $_POST['_wpinv_item_type'] ) );
141
+        if (isset($_POST['_wpinv_item_type'])) {
142
+            update_post_meta($post_id, '_wpinv_type', sanitize_text_field($_POST['_wpinv_item_type']));
143 143
         }
144 144
     }
145 145
 }
146
-add_action( 'save_post', 'wpinv_bulk_and_quick_edit_save', 10, 3 );
146
+add_action('save_post', 'wpinv_bulk_and_quick_edit_save', 10, 3);
147 147
 
148 148
 function wpinv_register_item_meta_boxes() {    
149 149
     global $wpinv_euvat;
150 150
     
151
-    add_meta_box( 'wpinv_field_prices', __( 'Item Price', 'invoicing' ), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high' );
151
+    add_meta_box('wpinv_field_prices', __('Item Price', 'invoicing'), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high');
152 152
 
153
-    if ( $wpinv_euvat->allow_vat_rules() ) {
154
-        add_meta_box( 'wpinv_field_vat_rules', __( 'VAT rules type to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high' );
153
+    if ($wpinv_euvat->allow_vat_rules()) {
154
+        add_meta_box('wpinv_field_vat_rules', __('VAT rules type to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high');
155 155
     }
156 156
     
157
-    if ( $wpinv_euvat->allow_vat_classes() ) {
158
-        add_meta_box( 'wpinv_field_vat_classes', __( 'VAT rates class to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high' );
157
+    if ($wpinv_euvat->allow_vat_classes()) {
158
+        add_meta_box('wpinv_field_vat_classes', __('VAT rates class to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high');
159 159
     }
160 160
     
161
-    add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core' );
162
-    add_meta_box( 'wpinv_field_meta_values', __( 'Item Meta Values', 'invoicing' ), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core' );
161
+    add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core');
162
+    add_meta_box('wpinv_field_meta_values', __('Item Meta Values', 'invoicing'), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core');
163 163
 }
164 164
 
165 165
 function wpinv_register_discount_meta_boxes() {
166
-    add_meta_box( 'wpinv_discount_fields', __( 'Discount Details', 'invoicing' ), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high' );
166
+    add_meta_box('wpinv_discount_fields', __('Discount Details', 'invoicing'), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high');
167 167
 }
168 168
 
169
-function wpinv_discount_metabox_details( $post ) {
169
+function wpinv_discount_metabox_details($post) {
170 170
     $discount_id    = $post->ID;
171
-    $discount       = wpinv_get_discount( $discount_id );
171
+    $discount       = wpinv_get_discount($discount_id);
172 172
     
173
-    $type           = wpinv_get_discount_type( $discount_id );
174
-    $item_reqs      = wpinv_get_discount_item_reqs( $discount_id );
175
-    $excluded_items = wpinv_get_discount_excluded_items( $discount_id );
176
-    $min_total      = wpinv_get_discount_min_total( $discount_id );
177
-    $max_total      = wpinv_get_discount_max_total( $discount_id );
178
-    $max_uses       = wpinv_get_discount_max_uses( $discount_id );
179
-    $single_use     = wpinv_discount_is_single_use( $discount_id );
180
-    $recurring      = (bool)wpinv_discount_is_recurring( $discount_id );
173
+    $type           = wpinv_get_discount_type($discount_id);
174
+    $item_reqs      = wpinv_get_discount_item_reqs($discount_id);
175
+    $excluded_items = wpinv_get_discount_excluded_items($discount_id);
176
+    $min_total      = wpinv_get_discount_min_total($discount_id);
177
+    $max_total      = wpinv_get_discount_max_total($discount_id);
178
+    $max_uses       = wpinv_get_discount_max_uses($discount_id);
179
+    $single_use     = wpinv_discount_is_single_use($discount_id);
180
+    $recurring      = (bool)wpinv_discount_is_recurring($discount_id);
181 181
     
182 182
     $min_total      = $min_total > 0 ? $min_total : '';
183 183
     $max_total      = $max_total > 0 ? $max_total : '';
184 184
     $max_uses       = $max_uses > 0 ? $max_uses : '';
185 185
 ?>
186
-<?php do_action( 'wpinv_discount_form_top', $post ); ?>
187
-<?php wp_nonce_field( 'wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce' ); ;?>
186
+<?php do_action('wpinv_discount_form_top', $post); ?>
187
+<?php wp_nonce_field('wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce'); ;?>
188 188
 <table class="form-table wpi-form-table">
189 189
     <tbody>
190
-        <?php do_action( 'wpinv_discount_form_first', $post ); ?>
191
-        <?php do_action( 'wpinv_discount_form_before_code', $post ); ?>
190
+        <?php do_action('wpinv_discount_form_first', $post); ?>
191
+        <?php do_action('wpinv_discount_form_before_code', $post); ?>
192 192
         <tr>
193 193
             <th valign="top" scope="row">
194
-                <label for="wpinv_discount_code"><?php _e( 'Discount Code', 'invoicing' ); ?></label>
194
+                <label for="wpinv_discount_code"><?php _e('Discount Code', 'invoicing'); ?></label>
195 195
             </th>
196 196
             <td>
197
-                <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr( wpinv_get_discount_code( $discount_id ) ); ?>" required>
198
-                <p class="description"><?php _e( 'Enter a code for this discount, such as 10OFF', 'invoicing' ); ?></p>
197
+                <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr(wpinv_get_discount_code($discount_id)); ?>" required>
198
+                <p class="description"><?php _e('Enter a code for this discount, such as 10OFF', 'invoicing'); ?></p>
199 199
             </td>
200 200
         </tr>
201
-        <?php do_action( 'wpinv_discount_form_before_type', $post ); ?>
201
+        <?php do_action('wpinv_discount_form_before_type', $post); ?>
202 202
         <tr>
203 203
             <th valign="top" scope="row">
204
-                <label for="wpinv_discount_type"><?php _e( 'Discount Type', 'invoicing' ); ?></label>
204
+                <label for="wpinv_discount_type"><?php _e('Discount Type', 'invoicing'); ?></label>
205 205
             </th>
206 206
             <td>
207 207
                 <select id="wpinv_discount_type" name="type" class="medium-text">
208
-                    <?php foreach ( wpinv_get_discount_types() as $value => $label ) { ?>
209
-                    <option value="<?php echo $value ;?>" <?php selected( $type, $value ); ?>><?php echo $label; ?></option>
208
+                    <?php foreach (wpinv_get_discount_types() as $value => $label) { ?>
209
+                    <option value="<?php echo $value; ?>" <?php selected($type, $value); ?>><?php echo $label; ?></option>
210 210
                     <?php } ?>
211 211
                 </select>
212
-                <p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'invoicing' ); ?></p>
212
+                <p class="description"><?php _e('The kind of discount to apply for this discount.', 'invoicing'); ?></p>
213 213
             </td>
214 214
         </tr>
215
-        <?php do_action( 'wpinv_discount_form_before_amount', $post ); ?>
215
+        <?php do_action('wpinv_discount_form_before_amount', $post); ?>
216 216
         <tr>
217 217
             <th valign="top" scope="row">
218
-                <label for="wpinv_discount_amount"><?php _e( 'Amount', 'invoicing' ); ?></label>
218
+                <label for="wpinv_discount_amount"><?php _e('Amount', 'invoicing'); ?></label>
219 219
             </th>
220 220
             <td>
221
-                <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr( wpinv_get_discount_amount( $discount_id ) ); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol() ;?></font>
222
-                <p style="display:none;" class="description"><?php _e( 'Enter the discount amount in USD', 'invoicing' ); ?></p>
223
-                <p class="description"><?php _e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?></p>
221
+                <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr(wpinv_get_discount_amount($discount_id)); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol(); ?></font>
222
+                <p style="display:none;" class="description"><?php _e('Enter the discount amount in USD', 'invoicing'); ?></p>
223
+                <p class="description"><?php _e('Enter the discount value. Ex: 10', 'invoicing'); ?></p>
224 224
             </td>
225 225
         </tr>
226
-        <?php do_action( 'wpinv_discount_form_before_items', $post ); ?>
226
+        <?php do_action('wpinv_discount_form_before_items', $post); ?>
227 227
         <tr>
228 228
             <th valign="top" scope="row">
229
-                <label for="wpinv_discount_items"><?php _e( 'Items', 'invoicing' ); ?></label>
229
+                <label for="wpinv_discount_items"><?php _e('Items', 'invoicing'); ?></label>
230 230
             </th>
231 231
             <td>
232
-                <p><?php echo wpinv_item_dropdown( array(
232
+                <p><?php echo wpinv_item_dropdown(array(
233 233
                         'name'              => 'items[]',
234 234
                         'id'                => 'items',
235 235
                         'selected'          => $item_reqs,
236 236
                         'multiple'          => true,
237 237
                         'chosen'            => true,
238 238
                         'class'             => 'medium-text',
239
-                        'placeholder'       => __( 'Select one or more Items', 'invoicing' ),
239
+                        'placeholder'       => __('Select one or more Items', 'invoicing'),
240 240
                         'show_recurring'    => true,
241
-                    ) ); ?>
241
+                    )); ?>
242 242
                 </p>
243
-                <p class="description"><?php _e( 'Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing' ); ?></p>
243
+                <p class="description"><?php _e('Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing'); ?></p>
244 244
             </td>
245 245
         </tr>
246
-        <?php do_action( 'wpinv_discount_form_before_excluded_items', $post ); ?>
246
+        <?php do_action('wpinv_discount_form_before_excluded_items', $post); ?>
247 247
         <tr>
248 248
             <th valign="top" scope="row">
249
-                <label for="wpinv_discount_excluded_items"><?php _e( 'Excluded Items', 'invoicing' ); ?></label>
249
+                <label for="wpinv_discount_excluded_items"><?php _e('Excluded Items', 'invoicing'); ?></label>
250 250
             </th>
251 251
             <td>
252
-                <p><?php echo wpinv_item_dropdown( array(
252
+                <p><?php echo wpinv_item_dropdown(array(
253 253
                         'name'              => 'excluded_items[]',
254 254
                         'id'                => 'excluded_items',
255 255
                         'selected'          => $excluded_items,
256 256
                         'multiple'          => true,
257 257
                         'chosen'            => true,
258 258
                         'class'             => 'medium-text',
259
-                        'placeholder'       => __( 'Select one or more Items', 'invoicing' ),
259
+                        'placeholder'       => __('Select one or more Items', 'invoicing'),
260 260
                         'show_recurring'    => true,
261
-                    ) ); ?>
261
+                    )); ?>
262 262
                 </p>
263
-                <p class="description"><?php _e( 'Items which are NOT allowed to use this discount.', 'invoicing' ); ?></p>
263
+                <p class="description"><?php _e('Items which are NOT allowed to use this discount.', 'invoicing'); ?></p>
264 264
             </td>
265 265
         </tr>
266
-        <?php do_action( 'wpinv_discount_form_before_start', $post ); ?>
266
+        <?php do_action('wpinv_discount_form_before_start', $post); ?>
267 267
         <tr>
268 268
             <th valign="top" scope="row">
269
-                <label for="wpinv_discount_start"><?php _e( 'Start date', 'invoicing' ); ?></label>
269
+                <label for="wpinv_discount_start"><?php _e('Start date', 'invoicing'); ?></label>
270 270
             </th>
271 271
             <td>
272
-                <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr( wpinv_get_discount_start_date( $discount_id ) ); ?>">
273
-                <p class="description"><?php _e( 'Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?></p>
272
+                <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr(wpinv_get_discount_start_date($discount_id)); ?>">
273
+                <p class="description"><?php _e('Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing'); ?></p>
274 274
             </td>
275 275
         </tr>
276
-        <?php do_action( 'wpinv_discount_form_before_expiration', $post ); ?>
276
+        <?php do_action('wpinv_discount_form_before_expiration', $post); ?>
277 277
         <tr>
278 278
             <th valign="top" scope="row">
279
-                <label for="wpinv_discount_expiration"><?php _e( 'Expiration date', 'invoicing' ); ?></label>
279
+                <label for="wpinv_discount_expiration"><?php _e('Expiration date', 'invoicing'); ?></label>
280 280
             </th>
281 281
             <td>
282
-                <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr( wpinv_get_discount_expiration( $discount_id ) ); ?>">
283
-                <p class="description"><?php _e( 'Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing' ); ?></p>
282
+                <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr(wpinv_get_discount_expiration($discount_id)); ?>">
283
+                <p class="description"><?php _e('Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing'); ?></p>
284 284
             </td>
285 285
         </tr>
286
-        <?php do_action( 'wpinv_discount_form_before_min_total', $post ); ?>
286
+        <?php do_action('wpinv_discount_form_before_min_total', $post); ?>
287 287
         <tr>
288 288
             <th valign="top" scope="row">
289
-                <label for="wpinv_discount_min_total"><?php _e( 'Minimum Amount', 'invoicing' ); ?></label>
289
+                <label for="wpinv_discount_min_total"><?php _e('Minimum Amount', 'invoicing'); ?></label>
290 290
             </th>
291 291
             <td>
292 292
                 <input type="text" name="min_total" id="wpinv_discount_min_total" class="wpi-field-price wpi-price" value="<?php echo $min_total; ?>">
293
-                <p class="description"><?php _e( 'This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p>
293
+                <p class="description"><?php _e('This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p>
294 294
             </td>
295 295
         </tr>
296
-        <?php do_action( 'wpinv_discount_form_before_max_total', $post ); ?>
296
+        <?php do_action('wpinv_discount_form_before_max_total', $post); ?>
297 297
         <tr>
298 298
             <th valign="top" scope="row">
299
-                <label for="wpinv_discount_max_total"><?php _e( 'Maximum Amount', 'invoicing' ); ?></label>
299
+                <label for="wpinv_discount_max_total"><?php _e('Maximum Amount', 'invoicing'); ?></label>
300 300
             </th>
301 301
             <td>
302 302
                 <input type="text" name="max_total" id="wpinv_discount_max_total" class="wpi-field-price wpi-price" value="<?php echo $max_total; ?>">
303
-                <p class="description"><?php _e( 'This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p>
303
+                <p class="description"><?php _e('This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p>
304 304
             </td>
305 305
         </tr>
306
-        <?php do_action( 'wpinv_discount_form_before_recurring', $post ); ?>
306
+        <?php do_action('wpinv_discount_form_before_recurring', $post); ?>
307 307
         <tr>
308 308
             <th valign="top" scope="row">
309
-                <label for="wpinv_discount_recurring"><?php _e( 'For recurring apply to', 'invoicing' ); ?></label>
309
+                <label for="wpinv_discount_recurring"><?php _e('For recurring apply to', 'invoicing'); ?></label>
310 310
             </th>
311 311
             <td>
312 312
                 <select id="wpinv_discount_recurring" name="recurring" class="medium-text">
313
-                    <option value="0" <?php selected( false, $recurring ); ?>><?php _e( 'All payments', 'invoicing' ); ?></option>
314
-                    <option value="1" <?php selected( true, $recurring ); ?>><?php _e( 'First payment only', 'invoicing' ); ?></option>
313
+                    <option value="0" <?php selected(false, $recurring); ?>><?php _e('All payments', 'invoicing'); ?></option>
314
+                    <option value="1" <?php selected(true, $recurring); ?>><?php _e('First payment only', 'invoicing'); ?></option>
315 315
                 </select>
316
-                <p class="description"><?php _e( '<b>All payments:</b> apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> apply this discount to only first payment of the recurring invoice.', 'invoicing' ); ?></p>
316
+                <p class="description"><?php _e('<b>All payments:</b> apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> apply this discount to only first payment of the recurring invoice.', 'invoicing'); ?></p>
317 317
             </td>
318 318
         </tr>
319
-        <?php do_action( 'wpinv_discount_form_before_max_uses', $post ); ?>
319
+        <?php do_action('wpinv_discount_form_before_max_uses', $post); ?>
320 320
         <tr>
321 321
             <th valign="top" scope="row">
322
-                <label for="wpinv_discount_max_uses"><?php _e( 'Max Uses', 'invoicing' ); ?></label>
322
+                <label for="wpinv_discount_max_uses"><?php _e('Max Uses', 'invoicing'); ?></label>
323 323
             </th>
324 324
             <td>
325 325
                 <input type="number" min="0" step="1" id="wpinv_discount_max_uses" name="max_uses" class="medium-text" value="<?php echo $max_uses; ?>">
326
-                <p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing' ); ?></p>
326
+                <p class="description"><?php _e('The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing'); ?></p>
327 327
             </td>
328 328
         </tr>
329
-        <?php do_action( 'wpinv_discount_form_before_single_use', $post ); ?>
329
+        <?php do_action('wpinv_discount_form_before_single_use', $post); ?>
330 330
         <tr>
331 331
             <th valign="top" scope="row">
332
-                <label for="wpinv_discount_single_use"><?php _e( 'Use Once Per User', 'invoicing' ); ?></label>
332
+                <label for="wpinv_discount_single_use"><?php _e('Use Once Per User', 'invoicing'); ?></label>
333 333
             </th>
334 334
             <td>
335
-                <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked( true, $single_use ); ?>>
336
-                <span class="description"><?php _e( 'Limit this discount to a single use per user?', 'invoicing' ); ?></span>
335
+                <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked(true, $single_use); ?>>
336
+                <span class="description"><?php _e('Limit this discount to a single use per user?', 'invoicing'); ?></span>
337 337
             </td>
338 338
         </tr>
339
-        <?php do_action( 'wpinv_discount_form_last', $post ); ?>
339
+        <?php do_action('wpinv_discount_form_last', $post); ?>
340 340
     </tbody>
341 341
 </table>
342
-<?php do_action( 'wpinv_discount_form_bottom', $post ); ?>
342
+<?php do_action('wpinv_discount_form_bottom', $post); ?>
343 343
     <?php
344 344
 }
345 345
 
346
-function wpinv_discount_metabox_save( $post_id, $post, $update = false ) {
347
-    $post_type = !empty( $post ) ? $post->post_type : '';
346
+function wpinv_discount_metabox_save($post_id, $post, $update = false) {
347
+    $post_type = !empty($post) ? $post->post_type : '';
348 348
     
349
-    if ( $post_type != 'wpi_discount' ) {
349
+    if ($post_type != 'wpi_discount') {
350 350
         return;
351 351
     }
352 352
     
353
-    if ( !isset( $_POST['wpinv_discount_metabox_nonce'] ) || ( isset( $_POST['wpinv_discount_metabox_nonce'] ) && !wp_verify_nonce( $_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce' ) ) ) {
353
+    if (!isset($_POST['wpinv_discount_metabox_nonce']) || (isset($_POST['wpinv_discount_metabox_nonce']) && !wp_verify_nonce($_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce'))) {
354 354
         return;
355 355
     }
356 356
     
357
-    if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
357
+    if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
358 358
         return;
359 359
     }
360 360
     
361
-    if ( !current_user_can( 'manage_options', $post_id ) ) {
361
+    if (!current_user_can('manage_options', $post_id)) {
362 362
         return;
363 363
     }
364 364
     
365
-    return wpinv_store_discount( $post_id, $_POST, $post, $update );
365
+    return wpinv_store_discount($post_id, $_POST, $post, $update);
366 366
 }
367
-add_action( 'save_post', 'wpinv_discount_metabox_save', 10, 3 );
368 367
\ No newline at end of file
368
+add_action('save_post', 'wpinv_discount_metabox_save', 10, 3);
369 369
\ No newline at end of file
Please login to merge, or discard this patch.