Passed
Pull Request — master (#48)
by
unknown
03:55
created
includes/class-wpinv-invoice.php 1 patch
Spacing   +792 added lines, -792 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 final class WPInv_Invoice {
15
-    public $ID  = 0;
15
+    public $ID = 0;
16 16
     public $title;
17 17
     public $post_type;
18 18
     
@@ -65,17 +65,17 @@  discard block
 block discarded – undo
65 65
     public $full_name = '';
66 66
     public $parent_invoice = 0;
67 67
     
68
-    public function __construct( $invoice_id = false ) {
69
-        if( empty( $invoice_id ) ) {
68
+    public function __construct($invoice_id = false) {
69
+        if (empty($invoice_id)) {
70 70
             return false;
71 71
         }
72 72
 
73
-        $this->setup_invoice( $invoice_id );
73
+        $this->setup_invoice($invoice_id);
74 74
     }
75 75
 
76
-    public function get( $key ) {
77
-        if ( method_exists( $this, 'get_' . $key ) ) {
78
-            $value = call_user_func( array( $this, 'get_' . $key ) );
76
+    public function get($key) {
77
+        if (method_exists($this, 'get_' . $key)) {
78
+            $value = call_user_func(array($this, 'get_' . $key));
79 79
         } else {
80 80
             $value = $this->$key;
81 81
         }
@@ -83,52 +83,52 @@  discard block
 block discarded – undo
83 83
         return $value;
84 84
     }
85 85
 
86
-    public function set( $key, $value ) {
87
-        $ignore = array( 'items', 'cart_details', 'fees', '_ID' );
86
+    public function set($key, $value) {
87
+        $ignore = array('items', 'cart_details', 'fees', '_ID');
88 88
 
89
-        if ( $key === 'status' ) {
89
+        if ($key === 'status') {
90 90
             $this->old_status = $this->status;
91 91
         }
92 92
 
93
-        if ( ! in_array( $key, $ignore ) ) {
94
-            $this->pending[ $key ] = $value;
93
+        if (!in_array($key, $ignore)) {
94
+            $this->pending[$key] = $value;
95 95
         }
96 96
 
97
-        if( '_ID' !== $key ) {
97
+        if ('_ID' !== $key) {
98 98
             $this->$key = $value;
99 99
         }
100 100
     }
101 101
 
102
-    public function _isset( $name ) {
103
-        if ( property_exists( $this, $name) ) {
104
-            return false === empty( $this->$name );
102
+    public function _isset($name) {
103
+        if (property_exists($this, $name)) {
104
+            return false === empty($this->$name);
105 105
         } else {
106 106
             return null;
107 107
         }
108 108
     }
109 109
 
110
-    private function setup_invoice( $invoice_id ) {
110
+    private function setup_invoice($invoice_id) {
111 111
         $this->pending = array();
112 112
 
113
-        if ( empty( $invoice_id ) ) {
113
+        if (empty($invoice_id)) {
114 114
             return false;
115 115
         }
116 116
 
117
-        $invoice = get_post( $invoice_id );
117
+        $invoice = get_post($invoice_id);
118 118
 
119
-        if( !$invoice || is_wp_error( $invoice ) ) {
119
+        if (!$invoice || is_wp_error($invoice)) {
120 120
             return false;
121 121
         }
122 122
 
123
-        if( !('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type) ) {
123
+        if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) {
124 124
             return false;
125 125
         }
126 126
 
127
-        do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id );
127
+        do_action('wpinv_pre_setup_invoice', $this, $invoice_id);
128 128
         
129 129
         // Primary Identifier
130
-        $this->ID              = absint( $invoice_id );
131
-        $this->post_type            = $invoice->post_type;
130
+        $this->ID = absint($invoice_id);
131
+        $this->post_type = $invoice->post_type;
132 132
         
133 133
         // We have a payment, get the generic payment_meta item to reduce calls to it
134 134
         $this->payment_meta    = $this->get_meta();
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
         $this->post_status     = $this->status;
140 140
         $this->mode            = $this->setup_mode();
141 141
         $this->parent_invoice  = $invoice->post_parent;
142
-        $this->post_name       = $this->setup_post_name( $invoice );
142
+        $this->post_name       = $this->setup_post_name($invoice);
143 143
         $this->status_nicename = $this->setup_status_nicename($invoice->post_status);
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,47 +186,47 @@  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($status) {
200
-        $all_invoice_statuses  = wpinv_get_invoice_statuses();
201
-        $status   = isset( $all_invoice_statuses[$status] ) ? $all_invoice_statuses[$status] : __( $status, 'invoicing' );
200
+        $all_invoice_statuses = wpinv_get_invoice_statuses();
201
+        $status = isset($all_invoice_statuses[$status]) ? $all_invoice_statuses[$status] : __($status, 'invoicing');
202 202
 
203
-        return apply_filters( 'setup_status_nicename', $status );
203
+        return apply_filters('setup_status_nicename', $status);
204 204
     }
205 205
     
206
-    private function setup_post_name( $post = NULL ) {
206
+    private function setup_post_name($post = NULL) {
207 207
         $post_name = '';
208 208
         
209
-        if ( !empty( $post ) ) {
210
-            if( !empty( $post->post_name ) ) {
209
+        if (!empty($post)) {
210
+            if (!empty($post->post_name)) {
211 211
                 $post_name = $post->post_name;
212
-            } else if ( !empty( $post->ID ) && !empty( $post->post_title ) ) {
213
-                $post_name = sanitize_title( $post->post_title );
212
+            } else if (!empty($post->ID) && !empty($post->post_title)) {
213
+                $post_name = sanitize_title($post->post_title);
214 214
                 
215 215
                 global $wpdb;
216
-                $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) );
216
+                $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID));
217 217
             }
218 218
         }
219 219
 
220
-        $this->post_name   = $post_name;
220
+        $this->post_name = $post_name;
221 221
     }
222 222
     
223 223
     private function setup_due_date() {
224
-        $due_date = $this->get_meta( '_wpinv_due_date' );
224
+        $due_date = $this->get_meta('_wpinv_due_date');
225 225
         
226
-        if ( empty( $due_date ) ) {
227
-            $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) );
228
-            $due_date = date_i18n( 'Y-m-d', $overdue_time );
229
-        } else if ( $due_date == 'none' ) {
226
+        if (empty($due_date)) {
227
+            $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days')));
228
+            $due_date = date_i18n('Y-m-d', $overdue_time);
229
+        } else if ($due_date == 'none') {
230 230
             $due_date = '';
231 231
         }
232 232
 
@@ -234,63 +234,63 @@  discard block
 block discarded – undo
234 234
     }
235 235
     
236 236
     private function setup_completed_date() {
237
-        $invoice = get_post( $this->ID );
237
+        $invoice = get_post($this->ID);
238 238
 
239
-        if ( 'pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) {
239
+        if ('pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) {
240 240
             return false; // This invoice was never paid
241 241
         }
242 242
 
243
-        $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date;
243
+        $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date;
244 244
 
245 245
         return $date;
246 246
     }
247 247
     
248 248
     private function setup_cart_details() {
249
-        $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array();
249
+        $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array();
250 250
         return $cart_details;
251 251
     }
252 252
     
253 253
     public function array_convert() {
254
-        return get_object_vars( $this );
254
+        return get_object_vars($this);
255 255
     }
256 256
     
257 257
     private function setup_items() {
258
-        $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array();
258
+        $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array();
259 259
         return $items;
260 260
     }
261 261
     
262 262
     private function setup_fees() {
263
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
263
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
264 264
         return $payment_fees;
265 265
     }
266 266
         
267 267
     private function setup_currency() {
268
-        $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this );
268
+        $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this);
269 269
         return $currency;
270 270
     }
271 271
     
272 272
     private function setup_discount() {
273 273
         //$discount = $this->get_meta( '_wpinv_discount', true );
274
-        $discount = (float)$this->subtotal - ( (float)$this->total - (float)$this->tax - (float)$this->fees_total );
275
-        if ( $discount < 0 ) {
274
+        $discount = (float)$this->subtotal - ((float)$this->total - (float)$this->tax - (float)$this->fees_total);
275
+        if ($discount < 0) {
276 276
             $discount = 0;
277 277
         }
278
-        $discount = wpinv_round_amount( $discount );
278
+        $discount = wpinv_round_amount($discount);
279 279
         
280 280
         return $discount;
281 281
     }
282 282
     
283 283
     private function setup_discount_code() {
284
-        $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true );
284
+        $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true);
285 285
         return $discount_code;
286 286
     }
287 287
     
288 288
     private function setup_tax() {
289
-        $tax = $this->get_meta( '_wpinv_tax', true );
289
+        $tax = $this->get_meta('_wpinv_tax', true);
290 290
 
291 291
         // We don't have tax as it's own meta and no meta was passed
292
-        if ( '' === $tax ) {            
293
-            $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0;
292
+        if ('' === $tax) {            
293
+            $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0;
294 294
         }
295 295
 
296 296
         return $tax;
@@ -300,9 +300,9 @@  discard block
 block discarded – undo
300 300
         $subtotal     = 0;
301 301
         $cart_details = $this->cart_details;
302 302
 
303
-        if ( is_array( $cart_details ) ) {
304
-            foreach ( $cart_details as $item ) {
305
-                if ( isset( $item['subtotal'] ) ) {
303
+        if (is_array($cart_details)) {
304
+            foreach ($cart_details as $item) {
305
+                if (isset($item['subtotal'])) {
306 306
                     $subtotal += $item['subtotal'];
307 307
                 }
308 308
             }
@@ -316,18 +316,18 @@  discard block
 block discarded – undo
316 316
     }
317 317
     
318 318
     private function setup_discounts() {
319
-        $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array();
319
+        $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array();
320 320
         return $discounts;
321 321
     }
322 322
     
323 323
     private function setup_total() {
324
-        $amount = $this->get_meta( '_wpinv_total', true );
324
+        $amount = $this->get_meta('_wpinv_total', true);
325 325
 
326
-        if ( empty( $amount ) && '0.00' != $amount ) {
327
-            $meta   = $this->get_meta( '_wpinv_payment_meta', true );
328
-            $meta   = maybe_unserialize( $meta );
326
+        if (empty($amount) && '0.00' != $amount) {
327
+            $meta   = $this->get_meta('_wpinv_payment_meta', true);
328
+            $meta   = maybe_unserialize($meta);
329 329
 
330
-            if ( isset( $meta['amount'] ) ) {
330
+            if (isset($meta['amount'])) {
331 331
                 $amount = $meta['amount'];
332 332
             }
333 333
         }
@@ -336,13 +336,13 @@  discard block
 block discarded – undo
336 336
     }
337 337
     
338 338
     private function setup_mode() {
339
-        return $this->get_meta( '_wpinv_mode' );
339
+        return $this->get_meta('_wpinv_mode');
340 340
     }
341 341
 
342 342
     private function setup_gateway() {
343
-        $gateway = $this->get_meta( '_wpinv_gateway' );
343
+        $gateway = $this->get_meta('_wpinv_gateway');
344 344
         
345
-        if ( empty( $gateway ) && 'publish' === $this->status ) {
345
+        if (empty($gateway) && 'publish' === $this->status) {
346 346
             $gateway = 'manual';
347 347
         }
348 348
         
@@ -350,23 +350,23 @@  discard block
 block discarded – undo
350 350
     }
351 351
     
352 352
     private function setup_gateway_title() {
353
-        $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway );
353
+        $gateway_title = wpinv_get_gateway_checkout_label($this->gateway);
354 354
         return $gateway_title;
355 355
     }
356 356
 
357 357
     private function setup_transaction_id() {
358
-        $transaction_id = $this->get_meta( '_wpinv_transaction_id' );
358
+        $transaction_id = $this->get_meta('_wpinv_transaction_id');
359 359
 
360
-        if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) {
360
+        if (empty($transaction_id) || (int)$transaction_id === (int)$this->ID) {
361 361
             $gateway        = $this->gateway;
362
-            $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID );
362
+            $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID);
363 363
         }
364 364
 
365 365
         return $transaction_id;
366 366
     }
367 367
 
368 368
     private function setup_ip() {
369
-        $ip = $this->get_meta( '_wpinv_user_ip' );
369
+        $ip = $this->get_meta('_wpinv_user_ip');
370 370
         return $ip;
371 371
     }
372 372
 
@@ -376,62 +376,62 @@  discard block
 block discarded – undo
376 376
     ///}
377 377
         
378 378
     private function setup_first_name() {
379
-        $first_name = $this->get_meta( '_wpinv_first_name' );
379
+        $first_name = $this->get_meta('_wpinv_first_name');
380 380
         return $first_name;
381 381
     }
382 382
     
383 383
     private function setup_last_name() {
384
-        $last_name = $this->get_meta( '_wpinv_last_name' );
384
+        $last_name = $this->get_meta('_wpinv_last_name');
385 385
         return $last_name;
386 386
     }
387 387
     
388 388
     private function setup_company() {
389
-        $company = $this->get_meta( '_wpinv_company' );
389
+        $company = $this->get_meta('_wpinv_company');
390 390
         return $company;
391 391
     }
392 392
     
393 393
     private function setup_vat_number() {
394
-        $vat_number = $this->get_meta( '_wpinv_vat_number' );
394
+        $vat_number = $this->get_meta('_wpinv_vat_number');
395 395
         return $vat_number;
396 396
     }
397 397
     
398 398
     private function setup_vat_rate() {
399
-        $vat_rate = $this->get_meta( '_wpinv_vat_rate' );
399
+        $vat_rate = $this->get_meta('_wpinv_vat_rate');
400 400
         return $vat_rate;
401 401
     }
402 402
     
403 403
     private function setup_adddress_confirmed() {
404
-        $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' );
404
+        $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed');
405 405
         return $adddress_confirmed;
406 406
     }
407 407
     
408 408
     private function setup_phone() {
409
-        $phone = $this->get_meta( '_wpinv_phone' );
409
+        $phone = $this->get_meta('_wpinv_phone');
410 410
         return $phone;
411 411
     }
412 412
     
413 413
     private function setup_address() {
414
-        $address = $this->get_meta( '_wpinv_address', true );
414
+        $address = $this->get_meta('_wpinv_address', true);
415 415
         return $address;
416 416
     }
417 417
     
418 418
     private function setup_city() {
419
-        $city = $this->get_meta( '_wpinv_city', true );
419
+        $city = $this->get_meta('_wpinv_city', true);
420 420
         return $city;
421 421
     }
422 422
     
423 423
     private function setup_country() {
424
-        $country = $this->get_meta( '_wpinv_country', true );
424
+        $country = $this->get_meta('_wpinv_country', true);
425 425
         return $country;
426 426
     }
427 427
     
428 428
     private function setup_state() {
429
-        $state = $this->get_meta( '_wpinv_state', true );
429
+        $state = $this->get_meta('_wpinv_state', true);
430 430
         return $state;
431 431
     }
432 432
     
433 433
     private function setup_zip() {
434
-        $zip = $this->get_meta( '_wpinv_zip', true );
434
+        $zip = $this->get_meta('_wpinv_zip', true);
435 435
         return $zip;
436 436
     }
437 437
 
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
             'user_id'        => $this->user_id,
441 441
             'first_name'     => $this->first_name,
442 442
             'last_name'      => $this->last_name,
443
-            'email'          => get_the_author_meta( 'email', $this->user_id ),
443
+            'email'          => get_the_author_meta('email', $this->user_id),
444 444
             'phone'          => $this->phone,
445 445
             'address'        => $this->address,
446 446
             'city'           => $this->city,
@@ -455,12 +455,12 @@  discard block
 block discarded – undo
455 455
         );
456 456
         
457 457
         $user_info = array();
458
-        if ( isset( $this->payment_meta['user_info'] ) ) {
459
-            $user_info = maybe_unserialize( $this->payment_meta['user_info'] );
458
+        if (isset($this->payment_meta['user_info'])) {
459
+            $user_info = maybe_unserialize($this->payment_meta['user_info']);
460 460
             
461
-            if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) {
461
+            if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) {
462 462
                 $this->user_id = $post->post_author;
463
-                $this->email = get_the_author_meta( 'email', $this->user_id );
463
+                $this->email = get_the_author_meta('email', $this->user_id);
464 464
                 
465 465
                 $user_info['user_id'] = $this->user_id;
466 466
                 $user_info['email'] = $this->email;
@@ -469,13 +469,13 @@  discard block
 block discarded – undo
469 469
             }
470 470
         }
471 471
         
472
-        $user_info    = wp_parse_args( $user_info, $defaults );
472
+        $user_info = wp_parse_args($user_info, $defaults);
473 473
         
474 474
         // Get the user, but only if it's been created
475
-        $user = get_userdata( $this->user_id );
475
+        $user = get_userdata($this->user_id);
476 476
         
477
-        if ( !empty( $user ) && $user->ID > 0 ) {
478
-            if ( empty( $user_info ) ) {
477
+        if (!empty($user) && $user->ID > 0) {
478
+            if (empty($user_info)) {
479 479
                 $user_info = array(
480 480
                     'user_id'    => $user->ID,
481 481
                     'first_name' => $user->first_name,
@@ -484,23 +484,23 @@  discard block
 block discarded – undo
484 484
                     'discount'   => '',
485 485
                 );
486 486
             } else {
487
-                foreach ( $user_info as $key => $value ) {
488
-                    if ( ! empty( $value ) ) {
487
+                foreach ($user_info as $key => $value) {
488
+                    if (!empty($value)) {
489 489
                         continue;
490 490
                     }
491 491
 
492
-                    switch( $key ) {
492
+                    switch ($key) {
493 493
                         case 'user_id':
494
-                            $user_info[ $key ] = $user->ID;
494
+                            $user_info[$key] = $user->ID;
495 495
                             break;
496 496
                         case 'first_name':
497
-                            $user_info[ $key ] = $user->first_name;
497
+                            $user_info[$key] = $user->first_name;
498 498
                             break;
499 499
                         case 'last_name':
500
-                            $user_info[ $key ] = $user->last_name;
500
+                            $user_info[$key] = $user->last_name;
501 501
                             break;
502 502
                         case 'email':
503
-                            $user_info[ $key ] = $user->user_email;
503
+                            $user_info[$key] = $user->user_email;
504 504
                             break;
505 505
                     }
506 506
                 }
@@ -511,16 +511,16 @@  discard block
 block discarded – undo
511 511
     }
512 512
 
513 513
     private function setup_invoice_key() {
514
-        $key = $this->get_meta( '_wpinv_key', true );
514
+        $key = $this->get_meta('_wpinv_key', true);
515 515
         
516 516
         return $key;
517 517
     }
518 518
 
519 519
     private function setup_invoice_number() {
520
-        $number = $this->get_meta( '_wpinv_number', true );
520
+        $number = $this->get_meta('_wpinv_number', true);
521 521
 
522
-        if ( !$number ) {
523
-            $number = wpinv_format_invoice_number( $this->ID );
522
+        if (!$number) {
523
+            $number = wpinv_format_invoice_number($this->ID);
524 524
         }
525 525
 
526 526
         return $number;
@@ -531,18 +531,18 @@  discard block
 block discarded – undo
531 531
 
532 532
         if ($number = $this->get_number()) {
533 533
             $invoice_title = $number;
534
-        } else if ( ! empty( $this->ID ) ) {
535
-            $invoice_title = wpinv_format_invoice_number( $this->ID );
534
+        } else if (!empty($this->ID)) {
535
+            $invoice_title = wpinv_format_invoice_number($this->ID);
536 536
         } else {
537
-            $invoice_title = wpinv_format_invoice_number( 0 );
537
+            $invoice_title = wpinv_format_invoice_number(0);
538 538
         }
539 539
 
540
-        if ( empty( $this->key ) ) {
540
+        if (empty($this->key)) {
541 541
             $this->key = self::generate_key();
542 542
             $this->pending['key'] = $this->key;
543 543
         }
544 544
 
545
-        if ( empty( $this->ip ) ) {
545
+        if (empty($this->ip)) {
546 546
             $this->ip = wpinv_get_ip();
547 547
             $this->pending['ip'] = $this->ip;
548 548
         }
@@ -574,75 +574,75 @@  discard block
 block discarded – undo
574 574
             'fees'         => $this->fees,
575 575
         );
576 576
         
577
-        $post_name      = sanitize_title( $invoice_title );
577
+        $post_name = sanitize_title($invoice_title);
578 578
 
579 579
         $post_data = array(
580 580
                         'post_title'    => $invoice_title,
581 581
                         'post_status'   => $this->status,
582 582
                         'post_author'   => $this->user_id,
583 583
                         'post_type'     => $this->post_type,
584
-                        'post_date'     => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ),
585
-                        'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ),
584
+                        'post_date'     => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'),
585
+                        'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1),
586 586
                         'post_parent'   => $this->parent_invoice,
587 587
                     );
588
-        $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this );
588
+        $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this);
589 589
 
590 590
         // Create a blank invoice
591
-        if ( !empty( $this->ID ) ) {
591
+        if (!empty($this->ID)) {
592 592
             $args['ID']         = $this->ID;
593 593
             $args['post_name']  = $post_name;
594 594
             
595
-            $invoice_id = wp_update_post( $args );
595
+            $invoice_id = wp_update_post($args);
596 596
         } else {
597
-            $invoice_id = wp_insert_post( $args );
597
+            $invoice_id = wp_insert_post($args);
598 598
             
599
-            $post_title = wpinv_format_invoice_number( $invoice_id );
599
+            $post_title = wpinv_format_invoice_number($invoice_id);
600 600
             global $wpdb;
601
-            $wpdb->update( $wpdb->posts, array( 'post_title' => $post_title, 'post_name' => sanitize_title( $post_title ) ), array( 'ID' => $invoice_id ) );
602
-            clean_post_cache( $invoice_id );
601
+            $wpdb->update($wpdb->posts, array('post_title' => $post_title, 'post_name' => sanitize_title($post_title)), array('ID' => $invoice_id));
602
+            clean_post_cache($invoice_id);
603 603
         }
604 604
 
605
-        if ( !empty( $invoice_id ) ) {             
605
+        if (!empty($invoice_id)) {             
606 606
             $this->ID  = $invoice_id;
607 607
             $this->_ID = $invoice_id;
608 608
             
609 609
             ///$this->pending['user_id'] = $this->user_id;
610
-            if ( isset( $this->pending['number'] ) ) {
610
+            if (isset($this->pending['number'])) {
611 611
                 $this->pending['number'] = $post_name;
612 612
             }
613 613
             
614
-            $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data );
615
-            if ( ! empty( $this->payment_meta['fees'] ) ) {
616
-                $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] );
617
-                foreach( $this->fees as $fee ) {
618
-                    $this->increase_fees( $fee['amount'] );
614
+            $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data);
615
+            if (!empty($this->payment_meta['fees'])) {
616
+                $this->fees = array_merge($this->fees, $this->payment_meta['fees']);
617
+                foreach ($this->fees as $fee) {
618
+                    $this->increase_fees($fee['amount']);
619 619
                 }
620 620
             }
621 621
 
622
-            $this->update_meta( '_wpinv_payment_meta', $this->payment_meta );            
622
+            $this->update_meta('_wpinv_payment_meta', $this->payment_meta);            
623 623
             $this->new = true;
624 624
         }
625 625
 
626 626
         return $this->ID;
627 627
     }
628 628
 
629
-    public function save( $setup = false ) {
629
+    public function save($setup = false) {
630 630
         global $wpi_session;
631 631
         
632 632
         $saved = false;
633
-        if ( empty( $this->items ) ) {
633
+        if (empty($this->items)) {
634 634
             return $saved; // Don't save empty invoice.
635 635
         }
636 636
         
637
-        if ( empty( $this->key ) ) {
637
+        if (empty($this->key)) {
638 638
             $this->key = self::generate_key();
639 639
             $this->pending['key'] = $this->key;
640 640
         }
641 641
         
642
-        if ( empty( $this->ID ) ) {
642
+        if (empty($this->ID)) {
643 643
             $invoice_id = $this->insert_invoice();
644 644
 
645
-            if ( false === $invoice_id ) {
645
+            if (false === $invoice_id) {
646 646
                 $saved = false;
647 647
             } else {
648 648
                 $this->ID = $invoice_id;
@@ -650,27 +650,27 @@  discard block
 block discarded – undo
650 650
         }        
651 651
 
652 652
         // If we have something pending, let's save it
653
-        if ( !empty( $this->pending ) ) {
653
+        if (!empty($this->pending)) {
654 654
             $total_increase = 0;
655 655
             $total_decrease = 0;
656 656
 
657
-            foreach ( $this->pending as $key => $value ) {
658
-                switch( $key ) {
657
+            foreach ($this->pending as $key => $value) {
658
+                switch ($key) {
659 659
                     case 'items':
660 660
                         // Update totals for pending items
661
-                        foreach ( $this->pending[ $key ] as $item ) {
662
-                            switch( $item['action'] ) {
661
+                        foreach ($this->pending[$key] as $item) {
662
+                            switch ($item['action']) {
663 663
                                 case 'add':
664 664
                                     $price = $item['price'];
665 665
                                     $taxes = $item['tax'];
666 666
 
667
-                                    if ( 'publish' === $this->status ) {
667
+                                    if ('publish' === $this->status) {
668 668
                                         $total_increase += $price;
669 669
                                     }
670 670
                                     break;
671 671
 
672 672
                                 case 'remove':
673
-                                    if ( 'publish' === $this->status ) {
673
+                                    if ('publish' === $this->status) {
674 674
                                         $total_decrease += $item['price'];
675 675
                                     }
676 676
                                     break;
@@ -678,16 +678,16 @@  discard block
 block discarded – undo
678 678
                         }
679 679
                         break;
680 680
                     case 'fees':
681
-                        if ( 'publish' !== $this->status ) {
681
+                        if ('publish' !== $this->status) {
682 682
                             break;
683 683
                         }
684 684
 
685
-                        if ( empty( $this->pending[ $key ] ) ) {
685
+                        if (empty($this->pending[$key])) {
686 686
                             break;
687 687
                         }
688 688
 
689
-                        foreach ( $this->pending[ $key ] as $fee ) {
690
-                            switch( $fee['action'] ) {
689
+                        foreach ($this->pending[$key] as $fee) {
690
+                            switch ($fee['action']) {
691 691
                                 case 'add':
692 692
                                     $total_increase += $fee['amount'];
693 693
                                     break;
@@ -699,86 +699,86 @@  discard block
 block discarded – undo
699 699
                         }
700 700
                         break;
701 701
                     case 'status':
702
-                        $this->update_status( $this->status );
702
+                        $this->update_status($this->status);
703 703
                         break;
704 704
                     case 'gateway':
705
-                        $this->update_meta( '_wpinv_gateway', $this->gateway );
705
+                        $this->update_meta('_wpinv_gateway', $this->gateway);
706 706
                         break;
707 707
                     case 'mode':
708
-                        $this->update_meta( '_wpinv_mode', $this->mode );
708
+                        $this->update_meta('_wpinv_mode', $this->mode);
709 709
                         break;
710 710
                     case 'transaction_id':
711
-                        $this->update_meta( '_wpinv_transaction_id', $this->transaction_id );
711
+                        $this->update_meta('_wpinv_transaction_id', $this->transaction_id);
712 712
                         break;
713 713
                     case 'ip':
714
-                        $this->update_meta( '_wpinv_user_ip', $this->ip );
714
+                        $this->update_meta('_wpinv_user_ip', $this->ip);
715 715
                         break;
716 716
                     ///case 'user_id':
717 717
                         ///$this->update_meta( '_wpinv_user_id', $this->user_id );
718 718
                         ///$this->user_info['user_id'] = $this->user_id;
719 719
                         ///break;
720 720
                     case 'first_name':
721
-                        $this->update_meta( '_wpinv_first_name', $this->first_name );
721
+                        $this->update_meta('_wpinv_first_name', $this->first_name);
722 722
                         $this->user_info['first_name'] = $this->first_name;
723 723
                         break;
724 724
                     case 'last_name':
725
-                        $this->update_meta( '_wpinv_last_name', $this->last_name );
725
+                        $this->update_meta('_wpinv_last_name', $this->last_name);
726 726
                         $this->user_info['last_name'] = $this->last_name;
727 727
                         break;
728 728
                     case 'phone':
729
-                        $this->update_meta( '_wpinv_phone', $this->phone );
729
+                        $this->update_meta('_wpinv_phone', $this->phone);
730 730
                         $this->user_info['phone'] = $this->phone;
731 731
                         break;
732 732
                     case 'address':
733
-                        $this->update_meta( '_wpinv_address', $this->address );
733
+                        $this->update_meta('_wpinv_address', $this->address);
734 734
                         $this->user_info['address'] = $this->address;
735 735
                         break;
736 736
                     case 'city':
737
-                        $this->update_meta( '_wpinv_city', $this->city );
737
+                        $this->update_meta('_wpinv_city', $this->city);
738 738
                         $this->user_info['city'] = $this->city;
739 739
                         break;
740 740
                     case 'country':
741
-                        $this->update_meta( '_wpinv_country', $this->country );
741
+                        $this->update_meta('_wpinv_country', $this->country);
742 742
                         $this->user_info['country'] = $this->country;
743 743
                         break;
744 744
                     case 'state':
745
-                        $this->update_meta( '_wpinv_state', $this->state );
745
+                        $this->update_meta('_wpinv_state', $this->state);
746 746
                         $this->user_info['state'] = $this->state;
747 747
                         break;
748 748
                     case 'zip':
749
-                        $this->update_meta( '_wpinv_zip', $this->zip );
749
+                        $this->update_meta('_wpinv_zip', $this->zip);
750 750
                         $this->user_info['zip'] = $this->zip;
751 751
                         break;
752 752
                     case 'company':
753
-                        $this->update_meta( '_wpinv_company', $this->company );
753
+                        $this->update_meta('_wpinv_company', $this->company);
754 754
                         $this->user_info['company'] = $this->company;
755 755
                         break;
756 756
                     case 'vat_number':
757
-                        $this->update_meta( '_wpinv_vat_number', $this->vat_number );
757
+                        $this->update_meta('_wpinv_vat_number', $this->vat_number);
758 758
                         $this->user_info['vat_number'] = $this->vat_number;
759 759
                         
760
-                        $vat_info = $wpi_session->get( 'user_vat_data' );
761
-                        if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) {
762
-                            $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false;
763
-                            $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed );
760
+                        $vat_info = $wpi_session->get('user_vat_data');
761
+                        if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) {
762
+                            $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
763
+                            $this->update_meta('_wpinv_adddress_confirmed', (bool)$adddress_confirmed);
764 764
                             $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed;
765 765
                         }
766 766
     
767 767
                         break;
768 768
                     case 'vat_rate':
769
-                        $this->update_meta( '_wpinv_vat_rate', $this->vat_rate );
769
+                        $this->update_meta('_wpinv_vat_rate', $this->vat_rate);
770 770
                         $this->user_info['vat_rate'] = $this->vat_rate;
771 771
                         break;
772 772
                     case 'adddress_confirmed':
773
-                        $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed );
773
+                        $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed);
774 774
                         $this->user_info['adddress_confirmed'] = $this->adddress_confirmed;
775 775
                         break;
776 776
                     
777 777
                     case 'key':
778
-                        $this->update_meta( '_wpinv_key', $this->key );
778
+                        $this->update_meta('_wpinv_key', $this->key);
779 779
                         break;
780 780
                     case 'number':
781
-                        $this->update_meta( '_wpinv_number', $this->number );
781
+                        $this->update_meta('_wpinv_number', $this->number);
782 782
                         break;
783 783
                     case 'date':
784 784
                         $args = array(
@@ -787,34 +787,34 @@  discard block
 block discarded – undo
787 787
                             'edit_date' => true,
788 788
                         );
789 789
 
790
-                        wp_update_post( $args );
790
+                        wp_update_post($args);
791 791
                         break;
792 792
                     case 'due_date':
793
-                        if ( empty( $this->due_date ) ) {
793
+                        if (empty($this->due_date)) {
794 794
                             $this->due_date = 'none';
795 795
                         }
796 796
                         
797
-                        $this->update_meta( '_wpinv_due_date', $this->due_date );
797
+                        $this->update_meta('_wpinv_due_date', $this->due_date);
798 798
                         break;
799 799
                     case 'completed_date':
800
-                        $this->update_meta( '_wpinv_completed_date', $this->completed_date );
800
+                        $this->update_meta('_wpinv_completed_date', $this->completed_date);
801 801
                         break;
802 802
                     case 'discounts':
803
-                        if ( ! is_array( $this->discounts ) ) {
804
-                            $this->discounts = explode( ',', $this->discounts );
803
+                        if (!is_array($this->discounts)) {
804
+                            $this->discounts = explode(',', $this->discounts);
805 805
                         }
806 806
 
807
-                        $this->user_info['discount'] = implode( ',', $this->discounts );
807
+                        $this->user_info['discount'] = implode(',', $this->discounts);
808 808
                         break;
809 809
                         
810 810
                     //case 'tax':
811 811
                         //$this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
812 812
                         //break;
813 813
                     case 'discount':
814
-                        $this->update_meta( '_wpinv_discount', wpinv_round_amount( $this->discount ) );
814
+                        $this->update_meta('_wpinv_discount', wpinv_round_amount($this->discount));
815 815
                         break;
816 816
                     case 'discount_code':
817
-                        $this->update_meta( '_wpinv_discount_code', $this->discount_code );
817
+                        $this->update_meta('_wpinv_discount_code', $this->discount_code);
818 818
                         break;
819 819
                     //case 'fees':
820 820
                         //$this->update_meta( '_wpinv_fees', $this->fees );
@@ -824,19 +824,19 @@  discard block
 block discarded – undo
824 824
                             'ID'          => $this->ID,
825 825
                             'post_parent' => $this->parent_invoice,
826 826
                         );
827
-                        wp_update_post( $args );
827
+                        wp_update_post($args);
828 828
                         break;
829 829
                     default:
830
-                        do_action( 'wpinv_save', $this, $key );
830
+                        do_action('wpinv_save', $this, $key);
831 831
                         break;
832 832
                 }
833 833
             }       
834 834
 
835
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
836
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
837
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
835
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
836
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
837
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
838 838
             
839
-            $this->items    = array_values( $this->items );
839
+            $this->items = array_values($this->items);
840 840
             
841 841
             $new_meta = array(
842 842
                 'items'         => $this->items,
@@ -847,12 +847,12 @@  discard block
 block discarded – undo
847 847
             );
848 848
             
849 849
             $meta        = $this->get_meta();
850
-            $merged_meta = array_merge( $meta, $new_meta );
850
+            $merged_meta = array_merge($meta, $new_meta);
851 851
 
852 852
             // Only save the payment meta if it's changed
853
-            if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) {
854
-                $updated     = $this->update_meta( '_wpinv_payment_meta', $merged_meta );
855
-                if ( false !== $updated ) {
853
+            if (md5(serialize($meta)) !== md5(serialize($merged_meta))) {
854
+                $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta);
855
+                if (false !== $updated) {
856 856
                     $saved = true;
857 857
                 }
858 858
             }
@@ -860,15 +860,15 @@  discard block
 block discarded – undo
860 860
             $this->pending = array();
861 861
             $saved         = true;
862 862
         } else {
863
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
864
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
865
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
863
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
864
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
865
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
866 866
         }
867 867
         
868
-        do_action( 'wpinv_invoice_save', $this, $saved );
868
+        do_action('wpinv_invoice_save', $this, $saved);
869 869
 
870
-        if ( true === $saved || $setup ) {
871
-            $this->setup_invoice( $this->ID );
870
+        if (true === $saved || $setup) {
871
+            $this->setup_invoice($this->ID);
872 872
         }
873 873
         
874 874
         $this->refresh_item_ids();
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
         return $saved;
877 877
     }
878 878
     
879
-    public function add_fee( $args, $global = true ) {
879
+    public function add_fee($args, $global = true) {
880 880
         $default_args = array(
881 881
             'label'       => '',
882 882
             'amount'      => 0,
@@ -886,75 +886,75 @@  discard block
 block discarded – undo
886 886
             'item_id'     => 0,
887 887
         );
888 888
 
889
-        $fee = wp_parse_args( $args, $default_args );
889
+        $fee = wp_parse_args($args, $default_args);
890 890
         
891
-        if ( !empty( $fee['label'] ) ) {
891
+        if (!empty($fee['label'])) {
892 892
             return false;
893 893
         }
894 894
         
895
-        $fee['id']  = sanitize_title( $fee['label'] );
895
+        $fee['id'] = sanitize_title($fee['label']);
896 896
         
897
-        $this->fees[]               = $fee;
897
+        $this->fees[] = $fee;
898 898
         
899 899
         $added_fee               = $fee;
900 900
         $added_fee['action']     = 'add';
901 901
         $this->pending['fees'][] = $added_fee;
902
-        reset( $this->fees );
902
+        reset($this->fees);
903 903
 
904
-        $this->increase_fees( $fee['amount'] );
904
+        $this->increase_fees($fee['amount']);
905 905
         return true;
906 906
     }
907 907
 
908
-    public function remove_fee( $key ) {
908
+    public function remove_fee($key) {
909 909
         $removed = false;
910 910
 
911
-        if ( is_numeric( $key ) ) {
912
-            $removed = $this->remove_fee_by( 'index', $key );
911
+        if (is_numeric($key)) {
912
+            $removed = $this->remove_fee_by('index', $key);
913 913
         }
914 914
 
915 915
         return $removed;
916 916
     }
917 917
 
918
-    public function remove_fee_by( $key, $value, $global = false ) {
919
-        $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array(
918
+    public function remove_fee_by($key, $value, $global = false) {
919
+        $allowed_fee_keys = apply_filters('wpinv_fee_keys', array(
920 920
             'index', 'label', 'amount', 'type',
921
-        ) );
921
+        ));
922 922
 
923
-        if ( ! in_array( $key, $allowed_fee_keys ) ) {
923
+        if (!in_array($key, $allowed_fee_keys)) {
924 924
             return false;
925 925
         }
926 926
 
927 927
         $removed = false;
928
-        if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) {
929
-            $removed_fee             = $this->fees[ $value ];
928
+        if ('index' === $key && array_key_exists($value, $this->fees)) {
929
+            $removed_fee             = $this->fees[$value];
930 930
             $removed_fee['action']   = 'remove';
931 931
             $this->pending['fees'][] = $removed_fee;
932 932
 
933
-            $this->decrease_fees( $removed_fee['amount'] );
933
+            $this->decrease_fees($removed_fee['amount']);
934 934
 
935
-            unset( $this->fees[ $value ] );
935
+            unset($this->fees[$value]);
936 936
             $removed = true;
937
-        } else if ( 'index' !== $key ) {
938
-            foreach ( $this->fees as $index => $fee ) {
939
-                if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) {
937
+        } else if ('index' !== $key) {
938
+            foreach ($this->fees as $index => $fee) {
939
+                if (isset($fee[$key]) && $fee[$key] == $value) {
940 940
                     $removed_fee             = $fee;
941 941
                     $removed_fee['action']   = 'remove';
942 942
                     $this->pending['fees'][] = $removed_fee;
943 943
 
944
-                    $this->decrease_fees( $removed_fee['amount'] );
944
+                    $this->decrease_fees($removed_fee['amount']);
945 945
 
946
-                    unset( $this->fees[ $index ] );
946
+                    unset($this->fees[$index]);
947 947
                     $removed = true;
948 948
 
949
-                    if ( false === $global ) {
949
+                    if (false === $global) {
950 950
                         break;
951 951
                     }
952 952
                 }
953 953
             }
954 954
         }
955 955
 
956
-        if ( true === $removed ) {
957
-            $this->fees = array_values( $this->fees );
956
+        if (true === $removed) {
957
+            $this->fees = array_values($this->fees);
958 958
         }
959 959
 
960 960
         return $removed;
@@ -962,35 +962,35 @@  discard block
 block discarded – undo
962 962
 
963 963
     
964 964
 
965
-    public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
965
+    public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) {
966 966
         // Bail if no note specified
967
-        if( !$note ) {
967
+        if (!$note) {
968 968
             return false;
969 969
         }
970 970
 
971
-        if ( empty( $this->ID ) )
971
+        if (empty($this->ID))
972 972
             return false;
973 973
         
974
-        if ( ( ( is_user_logged_in() && current_user_can( 'manage_options' ) ) || $added_by_user ) && !$system ) {
975
-            $user                 = get_user_by( 'id', get_current_user_id() );
974
+        if (((is_user_logged_in() && current_user_can('manage_options')) || $added_by_user) && !$system) {
975
+            $user                 = get_user_by('id', get_current_user_id());
976 976
             $comment_author       = $user->display_name;
977 977
             $comment_author_email = $user->user_email;
978 978
         } else {
979
-            $comment_author       = __( 'System', 'invoicing' );
980
-            $comment_author_email = strtolower( __( 'System', 'invoicing' ) ) . '@';
981
-            $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com';
982
-            $comment_author_email = sanitize_email( $comment_author_email );
979
+            $comment_author       = __('System', 'invoicing');
980
+            $comment_author_email = strtolower(__('System', 'invoicing')) . '@';
981
+            $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com';
982
+            $comment_author_email = sanitize_email($comment_author_email);
983 983
         }
984 984
 
985
-        do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type );
985
+        do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type);
986 986
 
987
-        $note_id = wp_insert_comment( wp_filter_comment( array(
987
+        $note_id = wp_insert_comment(wp_filter_comment(array(
988 988
             'comment_post_ID'      => $this->ID,
989 989
             'comment_content'      => $note,
990 990
             'comment_agent'        => 'GeoDirectory',
991 991
             'user_id'              => is_admin() ? get_current_user_id() : 0,
992
-            'comment_date'         => current_time( 'mysql' ),
993
-            'comment_date_gmt'     => current_time( 'mysql', 1 ),
992
+            'comment_date'         => current_time('mysql'),
993
+            'comment_date_gmt'     => current_time('mysql', 1),
994 994
             'comment_approved'     => 1,
995 995
             'comment_parent'       => 0,
996 996
             'comment_author'       => $comment_author,
@@ -998,53 +998,53 @@  discard block
 block discarded – undo
998 998
             'comment_author_url'   => '',
999 999
             'comment_author_email' => $comment_author_email,
1000 1000
             'comment_type'         => 'wpinv_note'
1001
-        ) ) );
1001
+        )));
1002 1002
 
1003
-        do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note );
1003
+        do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note);
1004 1004
         
1005
-        if ( $customer_type ) {
1006
-            add_comment_meta( $note_id, '_wpi_customer_note', 1 );
1005
+        if ($customer_type) {
1006
+            add_comment_meta($note_id, '_wpi_customer_note', 1);
1007 1007
 
1008
-            do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) );
1008
+            do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note));
1009 1009
         }
1010 1010
 
1011 1011
         return $note_id;
1012 1012
     }
1013 1013
 
1014
-    private function increase_subtotal( $amount = 0.00 ) {
1015
-        $amount          = (float) $amount;
1014
+    private function increase_subtotal($amount = 0.00) {
1015
+        $amount          = (float)$amount;
1016 1016
         $this->subtotal += $amount;
1017
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1017
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1018 1018
 
1019 1019
         $this->recalculate_total();
1020 1020
     }
1021 1021
 
1022
-    private function decrease_subtotal( $amount = 0.00 ) {
1023
-        $amount          = (float) $amount;
1022
+    private function decrease_subtotal($amount = 0.00) {
1023
+        $amount          = (float)$amount;
1024 1024
         $this->subtotal -= $amount;
1025
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1025
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1026 1026
 
1027
-        if ( $this->subtotal < 0 ) {
1027
+        if ($this->subtotal < 0) {
1028 1028
             $this->subtotal = 0;
1029 1029
         }
1030 1030
 
1031 1031
         $this->recalculate_total();
1032 1032
     }
1033 1033
 
1034
-    private function increase_fees( $amount = 0.00 ) {
1034
+    private function increase_fees($amount = 0.00) {
1035 1035
         $amount            = (float)$amount;
1036 1036
         $this->fees_total += $amount;
1037
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1037
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1038 1038
 
1039 1039
         $this->recalculate_total();
1040 1040
     }
1041 1041
 
1042
-    private function decrease_fees( $amount = 0.00 ) {
1043
-        $amount            = (float) $amount;
1042
+    private function decrease_fees($amount = 0.00) {
1043
+        $amount            = (float)$amount;
1044 1044
         $this->fees_total -= $amount;
1045
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1045
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1046 1046
 
1047
-        if ( $this->fees_total < 0 ) {
1047
+        if ($this->fees_total < 0) {
1048 1048
             $this->fees_total = 0;
1049 1049
         }
1050 1050
 
@@ -1055,54 +1055,54 @@  discard block
 block discarded – undo
1055 1055
         global $wpi_nosave;
1056 1056
         
1057 1057
         $this->total = $this->subtotal + $this->tax + $this->fees_total;
1058
-        $this->total = wpinv_round_amount( $this->total );
1058
+        $this->total = wpinv_round_amount($this->total);
1059 1059
         
1060
-        do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave );
1060
+        do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave);
1061 1061
     }
1062 1062
     
1063
-    public function increase_tax( $amount = 0.00 ) {
1064
-        $amount       = (float) $amount;
1063
+    public function increase_tax($amount = 0.00) {
1064
+        $amount       = (float)$amount;
1065 1065
         $this->tax   += $amount;
1066 1066
 
1067 1067
         $this->recalculate_total();
1068 1068
     }
1069 1069
 
1070
-    public function decrease_tax( $amount = 0.00 ) {
1071
-        $amount     = (float) $amount;
1070
+    public function decrease_tax($amount = 0.00) {
1071
+        $amount     = (float)$amount;
1072 1072
         $this->tax -= $amount;
1073 1073
 
1074
-        if ( $this->tax < 0 ) {
1074
+        if ($this->tax < 0) {
1075 1075
             $this->tax = 0;
1076 1076
         }
1077 1077
 
1078 1078
         $this->recalculate_total();
1079 1079
     }
1080 1080
 
1081
-    public function update_status( $new_status = false, $note = '', $manual = false ) {
1082
-        $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID );
1081
+    public function update_status($new_status = false, $note = '', $manual = false) {
1082
+        $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID);
1083 1083
         
1084
-        if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses() ) ) ) {
1084
+        if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses()))) {
1085 1085
             return false; // Don't permit status changes that aren't changes
1086 1086
         }
1087 1087
 
1088
-        $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status );
1088
+        $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status);
1089 1089
         $updated = false;
1090 1090
 
1091
-        if ( $do_change ) {
1092
-            do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status );
1091
+        if ($do_change) {
1092
+            do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status);
1093 1093
 
1094 1094
             $update_post_data                   = array();
1095 1095
             $update_post_data['ID']             = $this->ID;
1096 1096
             $update_post_data['post_status']    = $new_status;
1097
-            $update_post_data['edit_date']      = current_time( 'mysql', 0 );
1098
-            $update_post_data['edit_date_gmt']  = current_time( 'mysql', 1 );
1097
+            $update_post_data['edit_date']      = current_time('mysql', 0);
1098
+            $update_post_data['edit_date_gmt']  = current_time('mysql', 1);
1099 1099
             
1100
-            $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID );
1100
+            $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID);
1101 1101
 
1102
-            $updated = wp_update_post( $update_post_data );     
1102
+            $updated = wp_update_post($update_post_data);     
1103 1103
            
1104 1104
             // Process any specific status functions
1105
-            switch( $new_status ) {
1105
+            switch ($new_status) {
1106 1106
                 case 'wpi-refunded':
1107 1107
                     $this->process_refund();
1108 1108
                     break;
@@ -1115,9 +1115,9 @@  discard block
 block discarded – undo
1115 1115
             }
1116 1116
             
1117 1117
             // Status was changed.
1118
-            do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status );
1119
-            do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status );
1120
-            do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status );
1118
+            do_action('wpinv_status_' . $new_status, $this->ID, $old_status);
1119
+            do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status);
1120
+            do_action('wpinv_update_status', $this->ID, $new_status, $old_status);
1121 1121
         }
1122 1122
 
1123 1123
         return $updated;
@@ -1131,72 +1131,72 @@  discard block
 block discarded – undo
1131 1131
         $this->save();
1132 1132
     }
1133 1133
 
1134
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
1135
-        if ( empty( $meta_key ) ) {
1134
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
1135
+        if (empty($meta_key)) {
1136 1136
             return false;
1137 1137
         }
1138 1138
 
1139
-        if ( $meta_key == 'key' || $meta_key == 'date' ) {
1139
+        if ($meta_key == 'key' || $meta_key == 'date') {
1140 1140
             $current_meta = $this->get_meta();
1141
-            $current_meta[ $meta_key ] = $meta_value;
1141
+            $current_meta[$meta_key] = $meta_value;
1142 1142
 
1143 1143
             $meta_key     = '_wpinv_payment_meta';
1144 1144
             $meta_value   = $current_meta;
1145 1145
         }
1146 1146
 
1147
-        $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID );
1147
+        $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID);
1148 1148
         
1149
-        if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) {
1149
+        if ($meta_key == '_wpinv_completed_date' && !empty($meta_value)) {
1150 1150
             $args = array(
1151 1151
                 'ID'                => $this->ID,
1152 1152
                 'post_date'         => $meta_value,
1153 1153
                 'edit_date'         => true,
1154
-                'post_date_gmt'     => get_gmt_from_date( $meta_value ),
1154
+                'post_date_gmt'     => get_gmt_from_date($meta_value),
1155 1155
                 'post_modified'     => $meta_value,
1156
-                'post_modified_gmt' => get_gmt_from_date( $meta_value )
1156
+                'post_modified_gmt' => get_gmt_from_date($meta_value)
1157 1157
             );
1158
-            wp_update_post( $args );
1158
+            wp_update_post($args);
1159 1159
         }
1160 1160
         
1161
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
1161
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
1162 1162
     }
1163 1163
 
1164 1164
     private function process_refund() {
1165 1165
         $process_refund = true;
1166 1166
 
1167 1167
         // If the payment was not in publish, don't decrement stats as they were never incremented
1168
-        if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) {
1168
+        if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) {
1169 1169
             $process_refund = false;
1170 1170
         }
1171 1171
 
1172 1172
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1173
-        $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this );
1173
+        $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this);
1174 1174
 
1175
-        if ( false === $process_refund ) {
1175
+        if (false === $process_refund) {
1176 1176
             return;
1177 1177
         }
1178 1178
 
1179
-        do_action( 'wpinv_pre_refund_invoice', $this );
1179
+        do_action('wpinv_pre_refund_invoice', $this);
1180 1180
         
1181
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this );
1182
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this );
1183
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this );
1181
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this);
1182
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this);
1183
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this);
1184 1184
         
1185
-        do_action( 'wpinv_post_refund_invoice', $this );
1185
+        do_action('wpinv_post_refund_invoice', $this);
1186 1186
     }
1187 1187
 
1188 1188
     private function process_failure() {
1189 1189
         $discounts = $this->discounts;
1190
-        if ( empty( $discounts ) ) {
1190
+        if (empty($discounts)) {
1191 1191
             return;
1192 1192
         }
1193 1193
 
1194
-        if ( ! is_array( $discounts ) ) {
1195
-            $discounts = array_map( 'trim', explode( ',', $discounts ) );
1194
+        if (!is_array($discounts)) {
1195
+            $discounts = array_map('trim', explode(',', $discounts));
1196 1196
         }
1197 1197
 
1198
-        foreach ( $discounts as $discount ) {
1199
-            wpinv_decrease_discount_usage( $discount );
1198
+        foreach ($discounts as $discount) {
1199
+            wpinv_decrease_discount_usage($discount);
1200 1200
         }
1201 1201
     }
1202 1202
     
@@ -1204,92 +1204,92 @@  discard block
 block discarded – undo
1204 1204
         $process_pending = true;
1205 1205
 
1206 1206
         // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented
1207
-        if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'pending' != $this->status ) {
1207
+        if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'pending' != $this->status) {
1208 1208
             $process_pending = false;
1209 1209
         }
1210 1210
 
1211 1211
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1212
-        $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this );
1212
+        $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this);
1213 1213
 
1214
-        if ( false === $process_pending ) {
1214
+        if (false === $process_pending) {
1215 1215
             return;
1216 1216
         }
1217 1217
 
1218
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this );
1219
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this );
1220
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this );
1218
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this);
1219
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this);
1220
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this);
1221 1221
 
1222 1222
         $this->completed_date = '';
1223
-        $this->update_meta( '_wpinv_completed_date', '' );
1223
+        $this->update_meta('_wpinv_completed_date', '');
1224 1224
     }
1225 1225
     
1226 1226
     // get data
1227
-    public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) {
1228
-        $meta = get_post_meta( $this->ID, $meta_key, $single );
1227
+    public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) {
1228
+        $meta = get_post_meta($this->ID, $meta_key, $single);
1229 1229
 
1230
-        if ( $meta_key === '_wpinv_payment_meta' ) {
1230
+        if ($meta_key === '_wpinv_payment_meta') {
1231 1231
 
1232
-            if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is.
1232
+            if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is.
1233 1233
 
1234
-            if ( empty( $meta['key'] ) ) {
1234
+            if (empty($meta['key'])) {
1235 1235
                 $meta['key'] = $this->setup_invoice_key();
1236 1236
             }
1237 1237
 
1238
-            if ( empty( $meta['date'] ) ) {
1239
-                $meta['date'] = get_post_field( 'post_date', $this->ID );
1238
+            if (empty($meta['date'])) {
1239
+                $meta['date'] = get_post_field('post_date', $this->ID);
1240 1240
             }
1241 1241
         }
1242 1242
 
1243
-        $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID );
1243
+        $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID);
1244 1244
 
1245
-        return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key );
1245
+        return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key);
1246 1246
     }
1247 1247
     
1248 1248
     public function get_description() {
1249
-        $post = get_post( $this->ID );
1249
+        $post = get_post($this->ID);
1250 1250
         
1251
-        $description = !empty( $post ) ? $post->post_content : '';
1252
-        return apply_filters( 'wpinv_get_description', $description, $this->ID, $this );
1251
+        $description = !empty($post) ? $post->post_content : '';
1252
+        return apply_filters('wpinv_get_description', $description, $this->ID, $this);
1253 1253
     }
1254 1254
     
1255
-    public function get_status( $nicename = false ) {
1256
-        if ( !$nicename ) {
1255
+    public function get_status($nicename = false) {
1256
+        if (!$nicename) {
1257 1257
             $status = $this->status;
1258 1258
         } else {
1259 1259
             $status = $this->status_nicename;
1260 1260
         }
1261 1261
         
1262
-        return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this );
1262
+        return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this);
1263 1263
     }
1264 1264
     
1265 1265
     public function get_cart_details() {
1266
-        return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this );
1266
+        return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this);
1267 1267
     }
1268 1268
     
1269
-    public function get_subtotal( $currency = false ) {
1270
-        $subtotal = wpinv_round_amount( $this->subtotal );
1269
+    public function get_subtotal($currency = false) {
1270
+        $subtotal = wpinv_round_amount($this->subtotal);
1271 1271
         
1272
-        if ( $currency ) {
1273
-            $subtotal = wpinv_price( wpinv_format_amount( $subtotal, NULL, !$currency ), $this->get_currency() );
1272
+        if ($currency) {
1273
+            $subtotal = wpinv_price(wpinv_format_amount($subtotal, NULL, !$currency), $this->get_currency());
1274 1274
         }
1275 1275
         
1276
-        return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency );
1276
+        return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency);
1277 1277
     }
1278 1278
     
1279
-    public function get_total( $currency = false ) {        
1280
-        if ( $this->is_free_trial() ) {
1281
-            $total = wpinv_round_amount( 0 );
1279
+    public function get_total($currency = false) {        
1280
+        if ($this->is_free_trial()) {
1281
+            $total = wpinv_round_amount(0);
1282 1282
         } else {
1283
-            $total = wpinv_round_amount( $this->total );
1283
+            $total = wpinv_round_amount($this->total);
1284 1284
         }
1285
-        if ( $currency ) {
1286
-            $total = wpinv_price( wpinv_format_amount( $total, NULL, !$currency ), $this->get_currency() );
1285
+        if ($currency) {
1286
+            $total = wpinv_price(wpinv_format_amount($total, NULL, !$currency), $this->get_currency());
1287 1287
         }
1288 1288
         
1289
-        return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency );
1289
+        return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency);
1290 1290
     }
1291 1291
     
1292
-    public function get_recurring_details( $field = '', $currency = false ) {        
1292
+    public function get_recurring_details($field = '', $currency = false) {        
1293 1293
         $data                 = array();
1294 1294
         $data['cart_details'] = $this->cart_details;
1295 1295
         $data['subtotal']     = $this->get_subtotal();
@@ -1297,45 +1297,45 @@  discard block
 block discarded – undo
1297 1297
         $data['tax']          = $this->get_tax();
1298 1298
         $data['total']        = $this->get_total();
1299 1299
     
1300
-        if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) {
1300
+        if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) {
1301 1301
             $is_free_trial = $this->is_free_trial();
1302
-            $discounts = $this->get_discounts( true );
1302
+            $discounts = $this->get_discounts(true);
1303 1303
             
1304
-            if ( $is_free_trial || !empty( $discounts ) ) {
1304
+            if ($is_free_trial || !empty($discounts)) {
1305 1305
                 $first_use_only = false;
1306 1306
                 
1307
-                if ( !empty( $discounts ) ) {
1308
-                    foreach ( $discounts as $key => $code ) {
1309
-                        if ( wpinv_discount_is_recurring( $code, true ) ) {
1307
+                if (!empty($discounts)) {
1308
+                    foreach ($discounts as $key => $code) {
1309
+                        if (wpinv_discount_is_recurring($code, true)) {
1310 1310
                             $first_use_only = true;
1311 1311
                             break;
1312 1312
                         }
1313 1313
                     }
1314 1314
                 }
1315 1315
                     
1316
-                if ( !$first_use_only ) {
1317
-                    $data['subtotal'] = wpinv_round_amount( $this->subtotal );
1318
-                    $data['discount'] = wpinv_round_amount( $this->discount );
1319
-                    $data['tax']      = wpinv_round_amount( $this->tax );
1320
-                    $data['total']    = wpinv_round_amount( $this->total );
1316
+                if (!$first_use_only) {
1317
+                    $data['subtotal'] = wpinv_round_amount($this->subtotal);
1318
+                    $data['discount'] = wpinv_round_amount($this->discount);
1319
+                    $data['tax']      = wpinv_round_amount($this->tax);
1320
+                    $data['total']    = wpinv_round_amount($this->total);
1321 1321
                 } else {
1322 1322
                     $cart_subtotal   = 0;
1323 1323
                     $cart_discount   = 0;
1324 1324
                     $cart_tax        = 0;
1325 1325
 
1326
-                    foreach ( $this->cart_details as $key => $item ) {
1327
-                        $item_quantity  = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1328
-                        $item_subtotal  = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1326
+                    foreach ($this->cart_details as $key => $item) {
1327
+                        $item_quantity  = $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1328
+                        $item_subtotal  = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1329 1329
                         $item_discount  = 0;
1330
-                        $item_tax       = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0;
1330
+                        $item_tax       = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float)$item['vat_rate']) : 0;
1331 1331
                         
1332
-                        if ( wpinv_prices_include_tax() ) {
1333
-                            $item_subtotal -= wpinv_round_amount( $item_tax );
1332
+                        if (wpinv_prices_include_tax()) {
1333
+                            $item_subtotal -= wpinv_round_amount($item_tax);
1334 1334
                         }
1335 1335
                         
1336 1336
                         $item_total     = $item_subtotal - $item_discount + $item_tax;
1337 1337
                         // Do not allow totals to go negative
1338
-                        if ( $item_total < 0 ) {
1338
+                        if ($item_total < 0) {
1339 1339
                             $item_total = 0;
1340 1340
                         }
1341 1341
                         
@@ -1343,107 +1343,107 @@  discard block
 block discarded – undo
1343 1343
                         $cart_discount  += (float)($item_discount);
1344 1344
                         $cart_tax       += (float)($item_tax);
1345 1345
                         
1346
-                        $data['cart_details'][$key]['discount']   = wpinv_round_amount( $item_discount );
1347
-                        $data['cart_details'][$key]['tax']        = wpinv_round_amount( $item_tax );
1348
-                        $data['cart_details'][$key]['price']      = wpinv_round_amount( $item_total );
1346
+                        $data['cart_details'][$key]['discount']   = wpinv_round_amount($item_discount);
1347
+                        $data['cart_details'][$key]['tax']        = wpinv_round_amount($item_tax);
1348
+                        $data['cart_details'][$key]['price']      = wpinv_round_amount($item_total);
1349 1349
                     }
1350 1350
                     
1351
-                    $data['subtotal'] = wpinv_round_amount( $cart_subtotal );
1352
-                    $data['discount'] = wpinv_round_amount( $cart_discount );
1353
-                    $data['tax']      = wpinv_round_amount( $cart_tax );
1354
-                    $data['total']    = wpinv_round_amount( $data['subtotal'] + $data['tax'] );
1351
+                    $data['subtotal'] = wpinv_round_amount($cart_subtotal);
1352
+                    $data['discount'] = wpinv_round_amount($cart_discount);
1353
+                    $data['tax']      = wpinv_round_amount($cart_tax);
1354
+                    $data['total']    = wpinv_round_amount($data['subtotal'] + $data['tax']);
1355 1355
                 }
1356 1356
             }
1357 1357
         }
1358 1358
         
1359
-        $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency );
1359
+        $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency);
1360 1360
 
1361
-        if ( isset( $data[$field] ) ) {
1362
-            return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
1361
+        if (isset($data[$field])) {
1362
+            return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]);
1363 1363
         }
1364 1364
         
1365 1365
         return $data;
1366 1366
     }
1367 1367
     
1368
-    public function get_final_tax( $currency = false ) {        
1369
-        $final_total = wpinv_round_amount( $this->tax );
1370
-        if ( $currency ) {
1371
-            $final_total = wpinv_price( wpinv_format_amount( $final_total, NULL, !$currency ), $this->get_currency() );
1368
+    public function get_final_tax($currency = false) {        
1369
+        $final_total = wpinv_round_amount($this->tax);
1370
+        if ($currency) {
1371
+            $final_total = wpinv_price(wpinv_format_amount($final_total, NULL, !$currency), $this->get_currency());
1372 1372
         }
1373 1373
         
1374
-        return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency );
1374
+        return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency);
1375 1375
     }
1376 1376
     
1377
-    public function get_discounts( $array = false ) {
1377
+    public function get_discounts($array = false) {
1378 1378
         $discounts = $this->discounts;
1379
-        if ( $array && $discounts ) {
1380
-            $discounts = explode( ',', $discounts );
1379
+        if ($array && $discounts) {
1380
+            $discounts = explode(',', $discounts);
1381 1381
         }
1382
-        return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array );
1382
+        return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array);
1383 1383
     }
1384 1384
     
1385
-    public function get_discount( $currency = false, $dash = false ) {
1386
-        if ( !empty( $this->discounts ) ) {
1385
+    public function get_discount($currency = false, $dash = false) {
1386
+        if (!empty($this->discounts)) {
1387 1387
             global $ajax_cart_details;
1388 1388
             $ajax_cart_details = $this->get_cart_details();
1389 1389
 
1390
-            $this->discount = wpinv_get_cart_items_discount_amount( $this->items , $this->discounts );
1390
+            $this->discount = wpinv_get_cart_items_discount_amount($this->items, $this->discounts);
1391 1391
         }
1392
-        $discount   = wpinv_round_amount( $this->discount );
1392
+        $discount   = wpinv_round_amount($this->discount);
1393 1393
         $dash       = $dash && $discount > 0 ? '&ndash;' : '';
1394 1394
         
1395
-        if ( $currency ) {
1396
-            $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() );
1395
+        if ($currency) {
1396
+            $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency());
1397 1397
         }
1398 1398
         
1399
-        $discount   = $dash . $discount;
1399
+        $discount = $dash . $discount;
1400 1400
         
1401
-        return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash );
1401
+        return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash);
1402 1402
     }
1403 1403
     
1404 1404
     public function get_discount_code() {
1405 1405
         return $this->discount_code;
1406 1406
     }
1407 1407
     
1408
-    public function get_tax( $currency = false ) {
1409
-        $tax = wpinv_round_amount( $this->tax );
1408
+    public function get_tax($currency = false) {
1409
+        $tax = wpinv_round_amount($this->tax);
1410 1410
         
1411
-        if ( $currency ) {
1412
-            $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() );
1411
+        if ($currency) {
1412
+            $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency());
1413 1413
         }
1414 1414
         
1415
-        return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency );
1415
+        return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency);
1416 1416
     }
1417 1417
     
1418
-    public function get_fees( $type = 'all' ) {
1419
-        $fees    = array();
1418
+    public function get_fees($type = 'all') {
1419
+        $fees = array();
1420 1420
 
1421
-        if ( ! empty( $this->fees ) && is_array( $this->fees ) ) {
1422
-            foreach ( $this->fees as $fee ) {
1423
-                if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) {
1421
+        if (!empty($this->fees) && is_array($this->fees)) {
1422
+            foreach ($this->fees as $fee) {
1423
+                if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) {
1424 1424
                     continue;
1425 1425
                 }
1426 1426
 
1427
-                $fee['label'] = stripslashes( $fee['label'] );
1428
-                $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() );
1429
-                $fees[]    = $fee;
1427
+                $fee['label'] = stripslashes($fee['label']);
1428
+                $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency());
1429
+                $fees[] = $fee;
1430 1430
             }
1431 1431
         }
1432 1432
 
1433
-        return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this );
1433
+        return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this);
1434 1434
     }
1435 1435
     
1436
-    public function get_fees_total( $type = 'all' ) {
1437
-        $fees_total = (float) 0.00;
1436
+    public function get_fees_total($type = 'all') {
1437
+        $fees_total = (float)0.00;
1438 1438
 
1439
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
1440
-        if ( ! empty( $payment_fees ) ) {
1441
-            foreach ( $payment_fees as $fee ) {
1442
-                $fees_total += (float) $fee['amount'];
1439
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
1440
+        if (!empty($payment_fees)) {
1441
+            foreach ($payment_fees as $fee) {
1442
+                $fees_total += (float)$fee['amount'];
1443 1443
             }
1444 1444
         }
1445 1445
 
1446
-        return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this );
1446
+        return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this);
1447 1447
         /*
1448 1448
         $fees = $this->get_fees( $type );
1449 1449
 
@@ -1463,116 +1463,116 @@  discard block
 block discarded – undo
1463 1463
     }
1464 1464
 
1465 1465
     public function get_user_id() {
1466
-        return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this );
1466
+        return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this);
1467 1467
     }
1468 1468
     
1469 1469
     public function get_first_name() {
1470
-        return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this );
1470
+        return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this);
1471 1471
     }
1472 1472
     
1473 1473
     public function get_last_name() {
1474
-        return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this );
1474
+        return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this);
1475 1475
     }
1476 1476
     
1477 1477
     public function get_user_full_name() {
1478
-        return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this );
1478
+        return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this);
1479 1479
     }
1480 1480
     
1481 1481
     public function get_user_info() {
1482
-        return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this );
1482
+        return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this);
1483 1483
     }
1484 1484
     
1485 1485
     public function get_email() {
1486
-        return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this );
1486
+        return apply_filters('wpinv_user_email', $this->email, $this->ID, $this);
1487 1487
     }
1488 1488
     
1489 1489
     public function get_address() {
1490
-        return apply_filters( 'wpinv_address', $this->address, $this->ID, $this );
1490
+        return apply_filters('wpinv_address', $this->address, $this->ID, $this);
1491 1491
     }
1492 1492
     
1493 1493
     public function get_phone() {
1494
-        return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this );
1494
+        return apply_filters('wpinv_phone', $this->phone, $this->ID, $this);
1495 1495
     }
1496 1496
     
1497 1497
     public function get_number() {
1498
-        return apply_filters( 'wpinv_number', $this->number, $this->ID, $this );
1498
+        return apply_filters('wpinv_number', $this->number, $this->ID, $this);
1499 1499
     }
1500 1500
     
1501 1501
     public function get_items() {
1502
-        return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this );
1502
+        return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this);
1503 1503
     }
1504 1504
     
1505 1505
     public function get_key() {
1506
-        return apply_filters( 'wpinv_key', $this->key, $this->ID, $this );
1506
+        return apply_filters('wpinv_key', $this->key, $this->ID, $this);
1507 1507
     }
1508 1508
     
1509 1509
     public function get_transaction_id() {
1510
-        return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this );
1510
+        return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this);
1511 1511
     }
1512 1512
     
1513 1513
     public function get_gateway() {
1514
-        return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this );
1514
+        return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this);
1515 1515
     }
1516 1516
     
1517 1517
     public function get_gateway_title() {
1518
-        $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway );
1518
+        $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway);
1519 1519
         
1520
-        return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this );
1520
+        return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this);
1521 1521
     }
1522 1522
     
1523 1523
     public function get_currency() {
1524
-        return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this );
1524
+        return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this);
1525 1525
     }
1526 1526
     
1527 1527
     public function get_created_date() {
1528
-        return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this );
1528
+        return apply_filters('wpinv_created_date', $this->date, $this->ID, $this);
1529 1529
     }
1530 1530
     
1531
-    public function get_due_date( $display = false ) {
1532
-        $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this );
1531
+    public function get_due_date($display = false) {
1532
+        $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this);
1533 1533
         
1534
-        if ( !$display || empty( $due_date ) ) {
1534
+        if (!$display || empty($due_date)) {
1535 1535
             return $due_date;
1536 1536
         }
1537 1537
         
1538
-        return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) );
1538
+        return date_i18n(get_option('date_format'), strtotime($due_date));
1539 1539
     }
1540 1540
     
1541 1541
     public function get_completed_date() {
1542
-        return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this );
1542
+        return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this);
1543 1543
     }
1544 1544
     
1545
-    public function get_invoice_date( $formatted = true ) {
1545
+    public function get_invoice_date($formatted = true) {
1546 1546
         $date_completed = $this->completed_date;
1547 1547
         $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
1548 1548
         
1549
-        if ( $invoice_date == '' ) {
1549
+        if ($invoice_date == '') {
1550 1550
             $date_created   = $this->date;
1551 1551
             $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : '';
1552 1552
         }
1553 1553
         
1554
-        if ( $formatted && $invoice_date ) {
1555
-            $invoice_date   = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );
1554
+        if ($formatted && $invoice_date) {
1555
+            $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date));
1556 1556
         }
1557 1557
 
1558
-        return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this );
1558
+        return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this);
1559 1559
     }
1560 1560
     
1561 1561
     public function get_ip() {
1562
-        return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this );
1562
+        return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this);
1563 1563
     }
1564 1564
         
1565
-    public function has_status( $status ) {
1566
-        return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status );
1565
+    public function has_status($status) {
1566
+        return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status);
1567 1567
     }
1568 1568
     
1569
-    public function add_item( $item_id = 0, $args = array() ) {
1569
+    public function add_item($item_id = 0, $args = array()) {
1570 1570
         global $wpi_current_id, $wpi_item_id;
1571 1571
         
1572
-        $item = new WPInv_Item( $item_id );
1572
+        $item = new WPInv_Item($item_id);
1573 1573
 
1574 1574
         // Bail if this post isn't a item
1575
-        if( !$item || $item->post_type !== 'wpi_item' ) {
1575
+        if (!$item || $item->post_type !== 'wpi_item') {
1576 1576
             return false;
1577 1577
         }
1578 1578
         
@@ -1590,8 +1590,8 @@  discard block
 block discarded – undo
1590 1590
             'fees'      => array()
1591 1591
         );
1592 1592
 
1593
-        $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults );
1594
-        $args['quantity']   = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1;
1593
+        $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults);
1594
+        $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1;
1595 1595
 
1596 1596
         $wpi_current_id         = $this->ID;
1597 1597
         $wpi_item_id            = $item->ID;
@@ -1603,19 +1603,19 @@  discard block
 block discarded – undo
1603 1603
         $found_cart_key         = false;
1604 1604
         
1605 1605
         if ($has_quantities) {
1606
-            $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1606
+            $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1607 1607
             
1608
-            foreach ( $this->items as $key => $cart_item ) {
1609
-                if ( (int)$item_id !== (int)$cart_item['id'] ) {
1608
+            foreach ($this->items as $key => $cart_item) {
1609
+                if ((int)$item_id !== (int)$cart_item['id']) {
1610 1610
                     continue;
1611 1611
                 }
1612 1612
 
1613
-                $this->items[ $key ]['quantity'] += $args['quantity'];
1613
+                $this->items[$key]['quantity'] += $args['quantity'];
1614 1614
                 break;
1615 1615
             }
1616 1616
             
1617
-            foreach ( $this->cart_details as $cart_key => $cart_item ) {
1618
-                if ( $item_id != $cart_item['id'] ) {
1617
+            foreach ($this->cart_details as $cart_key => $cart_item) {
1618
+                if ($item_id != $cart_item['id']) {
1619 1619
                     continue;
1620 1620
                 }
1621 1621
 
@@ -1627,29 +1627,29 @@  discard block
 block discarded – undo
1627 1627
         if ($has_quantities && $found_cart_key !== false) {
1628 1628
             $cart_item          = $this->cart_details[$found_cart_key];
1629 1629
             $item_price         = $cart_item['item_price'];
1630
-            $quantity           = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1631
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1630
+            $quantity           = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1631
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1632 1632
             
1633 1633
             $new_quantity       = $quantity + $args['quantity'];
1634 1634
             $subtotal           = $item_price * $new_quantity;
1635 1635
             
1636 1636
             $args['quantity']   = $new_quantity;
1637
-            $discount           = !empty( $args['discount'] ) ? $args['discount'] : 0;
1638
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1637
+            $discount           = !empty($args['discount']) ? $args['discount'] : 0;
1638
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1639 1639
             
1640 1640
             $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0;
1641 1641
             $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0;
1642 1642
             // The total increase equals the number removed * the item_price
1643
-            $total_increased    = wpinv_round_amount( $item_price );
1643
+            $total_increased    = wpinv_round_amount($item_price);
1644 1644
             
1645
-            if ( wpinv_prices_include_tax() ) {
1646
-                $subtotal -= wpinv_round_amount( $tax );
1645
+            if (wpinv_prices_include_tax()) {
1646
+                $subtotal -= wpinv_round_amount($tax);
1647 1647
             }
1648 1648
 
1649
-            $total              = $subtotal - $discount + $tax;
1649
+            $total = $subtotal - $discount + $tax;
1650 1650
 
1651 1651
             // Do not allow totals to go negative
1652
-            if( $total < 0 ) {
1652
+            if ($total < 0) {
1653 1653
                 $total = 0;
1654 1654
             }
1655 1655
             
@@ -1665,20 +1665,20 @@  discard block
 block discarded – undo
1665 1665
             $this->cart_details[$found_cart_key] = $cart_item;
1666 1666
         } else {
1667 1667
             // Allow overriding the price
1668
-            if( false !== $args['item_price'] ) {
1668
+            if (false !== $args['item_price']) {
1669 1669
                 $item_price = $args['item_price'];
1670 1670
             } else {
1671
-                $item_price = wpinv_get_item_price( $item->ID );
1671
+                $item_price = wpinv_get_item_price($item->ID);
1672 1672
             }
1673 1673
 
1674 1674
             // Sanitizing the price here so we don't have a dozen calls later
1675
-            $item_price = wpinv_sanitize_amount( $item_price );
1676
-            $subtotal   = wpinv_round_amount( $item_price * $args['quantity'] );
1675
+            $item_price = wpinv_sanitize_amount($item_price);
1676
+            $subtotal   = wpinv_round_amount($item_price * $args['quantity']);
1677 1677
         
1678
-            $discount   = !empty( $args['discount'] ) ? $args['discount'] : 0;
1679
-            $tax_class  = !empty( $args['vat_class'] ) ? $args['vat_class'] : '';
1680
-            $tax_rate   = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0;
1681
-            $tax        = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1678
+            $discount   = !empty($args['discount']) ? $args['discount'] : 0;
1679
+            $tax_class  = !empty($args['vat_class']) ? $args['vat_class'] : '';
1680
+            $tax_rate   = !empty($args['vat_rate']) ? $args['vat_rate'] : 0;
1681
+            $tax        = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1682 1682
 
1683 1683
             // Setup the items meta item
1684 1684
             $new_item = array(
@@ -1686,28 +1686,28 @@  discard block
 block discarded – undo
1686 1686
                 'quantity' => $args['quantity'],
1687 1687
             );
1688 1688
 
1689
-            $this->items[]  = $new_item;
1689
+            $this->items[] = $new_item;
1690 1690
 
1691
-            if ( wpinv_prices_include_tax() ) {
1692
-                $subtotal -= wpinv_round_amount( $tax );
1691
+            if (wpinv_prices_include_tax()) {
1692
+                $subtotal -= wpinv_round_amount($tax);
1693 1693
             }
1694 1694
 
1695
-            $total      = $subtotal - $discount + $tax;
1695
+            $total = $subtotal - $discount + $tax;
1696 1696
 
1697 1697
             // Do not allow totals to go negative
1698
-            if( $total < 0 ) {
1698
+            if ($total < 0) {
1699 1699
                 $total = 0;
1700 1700
             }
1701 1701
         
1702 1702
             $this->cart_details[] = array(
1703 1703
                 'name'        => !empty($args['name']) ? $args['name'] : $item->get_name(),
1704 1704
                 'id'          => $item->ID,
1705
-                'item_price'  => wpinv_round_amount( $item_price ),
1705
+                'item_price'  => wpinv_round_amount($item_price),
1706 1706
                 'quantity'    => $args['quantity'],
1707 1707
                 'discount'    => $discount,
1708
-                'subtotal'    => wpinv_round_amount( $subtotal ),
1709
-                'tax'         => wpinv_round_amount( $tax ),
1710
-                'price'       => wpinv_round_amount( $total ),
1708
+                'subtotal'    => wpinv_round_amount($subtotal),
1709
+                'tax'         => wpinv_round_amount($tax),
1710
+                'price'       => wpinv_round_amount($total),
1711 1711
                 'vat_rate'    => $tax_rate,
1712 1712
                 'vat_class'   => $tax_class,
1713 1713
                 'meta'        => $args['meta'],
@@ -1717,69 +1717,69 @@  discard block
 block discarded – undo
1717 1717
             $subtotal = $subtotal - $discount;
1718 1718
         }
1719 1719
         
1720
-        $added_item = end( $this->cart_details );
1721
-        $added_item['action']  = 'add';
1720
+        $added_item = end($this->cart_details);
1721
+        $added_item['action'] = 'add';
1722 1722
         
1723 1723
         $this->pending['items'][] = $added_item;
1724 1724
         
1725
-        $this->increase_subtotal( $subtotal );
1726
-        $this->increase_tax( $tax );
1725
+        $this->increase_subtotal($subtotal);
1726
+        $this->increase_tax($tax);
1727 1727
 
1728 1728
         return true;
1729 1729
     }
1730 1730
     
1731
-    public function remove_item( $item_id, $args = array() ) {
1731
+    public function remove_item($item_id, $args = array()) {
1732 1732
         // Set some defaults
1733 1733
         $defaults = array(
1734 1734
             'quantity'   => 1,
1735 1735
             'item_price' => false,
1736 1736
             'cart_index' => false,
1737 1737
         );
1738
-        $args = wp_parse_args( $args, $defaults );
1738
+        $args = wp_parse_args($args, $defaults);
1739 1739
 
1740 1740
         // Bail if this post isn't a item
1741
-        if ( get_post_type( $item_id ) !== 'wpi_item' ) {
1741
+        if (get_post_type($item_id) !== 'wpi_item') {
1742 1742
             return false;
1743 1743
         }
1744 1744
         
1745
-        $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1745
+        $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1746 1746
 
1747
-        foreach ( $this->items as $key => $item ) {
1748
-            if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) {
1747
+        foreach ($this->items as $key => $item) {
1748
+            if (!empty($item['id']) && (int)$item_id !== (int)$item['id']) {
1749 1749
                 continue;
1750 1750
             }
1751 1751
 
1752
-            if ( false !== $args['cart_index'] ) {
1753
-                $cart_index = absint( $args['cart_index'] );
1754
-                $cart_item  = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false;
1752
+            if (false !== $args['cart_index']) {
1753
+                $cart_index = absint($args['cart_index']);
1754
+                $cart_item  = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false;
1755 1755
 
1756
-                if ( ! empty( $cart_item ) ) {
1756
+                if (!empty($cart_item)) {
1757 1757
                     // If the cart index item isn't the same item ID, don't remove it
1758
-                    if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) {
1758
+                    if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) {
1759 1759
                         continue;
1760 1760
                     }
1761 1761
                 }
1762 1762
             }
1763 1763
 
1764
-            $item_quantity = $this->items[ $key ]['quantity'];
1765
-            if ( $item_quantity > $args['quantity'] ) {
1766
-                $this->items[ $key ]['quantity'] -= $args['quantity'];
1764
+            $item_quantity = $this->items[$key]['quantity'];
1765
+            if ($item_quantity > $args['quantity']) {
1766
+                $this->items[$key]['quantity'] -= $args['quantity'];
1767 1767
                 break;
1768 1768
             } else {
1769
-                unset( $this->items[ $key ] );
1769
+                unset($this->items[$key]);
1770 1770
                 break;
1771 1771
             }
1772 1772
         }
1773 1773
 
1774 1774
         $found_cart_key = false;
1775
-        if ( false === $args['cart_index'] ) {
1776
-            foreach ( $this->cart_details as $cart_key => $item ) {
1777
-                if ( $item_id != $item['id'] ) {
1775
+        if (false === $args['cart_index']) {
1776
+            foreach ($this->cart_details as $cart_key => $item) {
1777
+                if ($item_id != $item['id']) {
1778 1778
                     continue;
1779 1779
                 }
1780 1780
 
1781
-                if ( false !== $args['item_price'] ) {
1782
-                    if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) {
1781
+                if (false !== $args['item_price']) {
1782
+                    if (isset($item['item_price']) && (float)$args['item_price'] != (float)$item['item_price']) {
1783 1783
                         continue;
1784 1784
                     }
1785 1785
                 }
@@ -1788,13 +1788,13 @@  discard block
 block discarded – undo
1788 1788
                 break;
1789 1789
             }
1790 1790
         } else {
1791
-            $cart_index = absint( $args['cart_index'] );
1791
+            $cart_index = absint($args['cart_index']);
1792 1792
 
1793
-            if ( ! array_key_exists( $cart_index, $this->cart_details ) ) {
1793
+            if (!array_key_exists($cart_index, $this->cart_details)) {
1794 1794
                 return false; // Invalid cart index passed.
1795 1795
             }
1796 1796
 
1797
-            if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) {
1797
+            if ((int)$this->cart_details[$cart_index]['id'] > 0 && (int)$this->cart_details[$cart_index]['id'] !== (int)$item_id) {
1798 1798
                 return false; // We still need the proper Item ID to be sure.
1799 1799
             }
1800 1800
 
@@ -1802,41 +1802,41 @@  discard block
 block discarded – undo
1802 1802
         }
1803 1803
         
1804 1804
         $cart_item  = $this->cart_details[$found_cart_key];
1805
-        $quantity   = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1805
+        $quantity   = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1806 1806
         
1807
-        if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) {
1807
+        if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) {
1808 1808
             return false; // Invoice must contain at least one item.
1809 1809
         }
1810 1810
         
1811
-        $discounts  = $this->get_discounts();
1811
+        $discounts = $this->get_discounts();
1812 1812
         
1813
-        if ( $quantity > $args['quantity'] ) {
1813
+        if ($quantity > $args['quantity']) {
1814 1814
             $item_price         = $cart_item['item_price'];
1815
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1815
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1816 1816
             
1817
-            $new_quantity       = max( $quantity - $args['quantity'], 1);
1817
+            $new_quantity       = max($quantity - $args['quantity'], 1);
1818 1818
             $subtotal           = $item_price * $new_quantity;
1819 1819
             
1820 1820
             $args['quantity']   = $new_quantity;
1821
-            $discount           = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1822
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1821
+            $discount           = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1822
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1823 1823
             
1824
-            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0;
1824
+            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float)$cart_item['discount'] / $quantity)) : 0;
1825 1825
             $discount_decrease  = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; 
1826
-            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0;
1826
+            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float)$cart_item['tax'] / $quantity)) : 0;
1827 1827
             $tax_decrease       = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease;
1828 1828
             
1829 1829
             // The total increase equals the number removed * the item_price
1830
-            $total_decrease     = wpinv_round_amount( $item_price );
1830
+            $total_decrease     = wpinv_round_amount($item_price);
1831 1831
             
1832
-            if ( wpinv_prices_include_tax() ) {
1833
-                $subtotal -= wpinv_round_amount( $tax );
1832
+            if (wpinv_prices_include_tax()) {
1833
+                $subtotal -= wpinv_round_amount($tax);
1834 1834
             }
1835 1835
 
1836
-            $total              = $subtotal - $discount + $tax;
1836
+            $total = $subtotal - $discount + $tax;
1837 1837
 
1838 1838
             // Do not allow totals to go negative
1839
-            if( $total < 0 ) {
1839
+            if ($total < 0) {
1840 1840
                 $total = 0;
1841 1841
             }
1842 1842
             
@@ -1855,16 +1855,16 @@  discard block
 block discarded – undo
1855 1855
             
1856 1856
             $this->cart_details[$found_cart_key] = $cart_item;
1857 1857
             
1858
-            $remove_item = end( $this->cart_details );
1858
+            $remove_item = end($this->cart_details);
1859 1859
         } else {
1860 1860
             $item_price     = $cart_item['item_price'];
1861
-            $discount       = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1862
-            $tax            = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0;
1861
+            $discount       = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1862
+            $tax            = !empty($cart_item['tax']) ? $cart_item['tax'] : 0;
1863 1863
         
1864
-            $subtotal_decrease  = ( $item_price * $quantity ) - $discount;
1864
+            $subtotal_decrease  = ($item_price * $quantity) - $discount;
1865 1865
             $tax_decrease       = $tax;
1866 1866
 
1867
-            unset( $this->cart_details[$found_cart_key] );
1867
+            unset($this->cart_details[$found_cart_key]);
1868 1868
             
1869 1869
             $remove_item             = $args;
1870 1870
             $remove_item['id']       = $item_id;
@@ -1875,8 +1875,8 @@  discard block
 block discarded – undo
1875 1875
         $remove_item['action']      = 'remove';
1876 1876
         $this->pending['items'][]   = $remove_item;
1877 1877
                
1878
-        $this->decrease_subtotal( $subtotal_decrease );
1879
-        $this->decrease_tax( $tax_decrease );
1878
+        $this->decrease_subtotal($subtotal_decrease);
1879
+        $this->decrease_tax($tax_decrease);
1880 1880
         
1881 1881
         return true;
1882 1882
     }
@@ -1884,7 +1884,7 @@  discard block
 block discarded – undo
1884 1884
     public function update_items($temp = false) {
1885 1885
         global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave;
1886 1886
         
1887
-        if ( !empty( $this->cart_details ) ) {
1887
+        if (!empty($this->cart_details)) {
1888 1888
             $wpi_nosave             = $temp;
1889 1889
             $cart_subtotal          = 0;
1890 1890
             $cart_discount          = 0;
@@ -1894,41 +1894,41 @@  discard block
 block discarded – undo
1894 1894
             $_POST['wpinv_country'] = $this->country;
1895 1895
             $_POST['wpinv_state']   = $this->state;
1896 1896
             
1897
-            foreach ( $this->cart_details as $key => $item ) {
1897
+            foreach ($this->cart_details as $key => $item) {
1898 1898
                 $item_price = $item['item_price'];
1899
-                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1900
-                $amount     = wpinv_round_amount( $item_price * $quantity );
1899
+                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1900
+                $amount     = wpinv_round_amount($item_price * $quantity);
1901 1901
                 $subtotal   = $item_price * $quantity;
1902 1902
                 
1903 1903
                 $wpi_current_id         = $this->ID;
1904 1904
                 $wpi_item_id            = $item['id'];
1905 1905
                 
1906
-                $discount   = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() );
1906
+                $discount   = wpinv_get_cart_item_discount_amount($item, $this->get_discounts());
1907 1907
                 
1908
-                $tax_rate   = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id );
1909
-                $tax_class  = $wpinv_euvat->get_item_class( $wpi_item_id );
1910
-                $tax        = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1908
+                $tax_rate   = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id);
1909
+                $tax_class  = $wpinv_euvat->get_item_class($wpi_item_id);
1910
+                $tax        = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1911 1911
 
1912
-                if ( wpinv_prices_include_tax() ) {
1913
-                    $subtotal -= wpinv_round_amount( $tax );
1912
+                if (wpinv_prices_include_tax()) {
1913
+                    $subtotal -= wpinv_round_amount($tax);
1914 1914
                 }
1915 1915
 
1916
-                $total      = $subtotal - $discount + $tax;
1916
+                $total = $subtotal - $discount + $tax;
1917 1917
 
1918 1918
                 // Do not allow totals to go negative
1919
-                if( $total < 0 ) {
1919
+                if ($total < 0) {
1920 1920
                     $total = 0;
1921 1921
                 }
1922 1922
 
1923 1923
                 $cart_details[] = array(
1924 1924
                     'id'          => $item['id'],
1925 1925
                     'name'        => $item['name'],
1926
-                    'item_price'  => wpinv_round_amount( $item_price ),
1926
+                    'item_price'  => wpinv_round_amount($item_price),
1927 1927
                     'quantity'    => $quantity,
1928 1928
                     'discount'    => $discount,
1929
-                    'subtotal'    => wpinv_round_amount( $subtotal ),
1930
-                    'tax'         => wpinv_round_amount( $tax ),
1931
-                    'price'       => wpinv_round_amount( $total ),
1929
+                    'subtotal'    => wpinv_round_amount($subtotal),
1930
+                    'tax'         => wpinv_round_amount($tax),
1931
+                    'price'       => wpinv_round_amount($total),
1932 1932
                     'vat_rate'    => $tax_rate,
1933 1933
                     'vat_class'   => $tax_class,
1934 1934
                     'meta'        => isset($item['meta']) ? $item['meta'] : array(),
@@ -1939,9 +1939,9 @@  discard block
 block discarded – undo
1939 1939
                 $cart_discount  += (float)($discount);
1940 1940
                 $cart_tax       += (float)($tax);
1941 1941
             }
1942
-            $this->subtotal = wpinv_round_amount( $cart_subtotal );
1943
-            $this->tax      = wpinv_round_amount( $cart_tax );
1944
-            $this->discount = wpinv_round_amount( $cart_discount );
1942
+            $this->subtotal = wpinv_round_amount($cart_subtotal);
1943
+            $this->tax      = wpinv_round_amount($cart_tax);
1944
+            $this->discount = wpinv_round_amount($cart_discount);
1945 1945
             
1946 1946
             $this->recalculate_total();
1947 1947
             
@@ -1953,221 +1953,221 @@  discard block
 block discarded – undo
1953 1953
     
1954 1954
     public function recalculate_totals($temp = false) {        
1955 1955
         $this->update_items($temp);
1956
-        $this->save( true );
1956
+        $this->save(true);
1957 1957
         
1958 1958
         return $this;
1959 1959
     }
1960 1960
     
1961 1961
     public function needs_payment() {
1962
-        $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'pending' ), $this );
1962
+        $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('pending'), $this);
1963 1963
 
1964
-        if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() ) ) {
1964
+        if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free())) {
1965 1965
             $needs_payment = true;
1966 1966
         } else {
1967 1967
             $needs_payment = false;
1968 1968
         }
1969 1969
 
1970
-        return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses );
1970
+        return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses);
1971 1971
     }
1972 1972
     
1973
-    public function get_checkout_payment_url( $on_checkout = false, $secret = false ) {
1973
+    public function get_checkout_payment_url($on_checkout = false, $secret = false) {
1974 1974
         $pay_url = wpinv_get_checkout_uri();
1975 1975
 
1976
-        if ( is_ssl() ) {
1977
-            $pay_url = str_replace( 'http:', 'https:', $pay_url );
1976
+        if (is_ssl()) {
1977
+            $pay_url = str_replace('http:', 'https:', $pay_url);
1978 1978
         }
1979 1979
         
1980 1980
         $key = $this->get_key();
1981 1981
 
1982
-        if ( $on_checkout ) {
1983
-            $pay_url = add_query_arg( 'invoice_key', $key, $pay_url );
1982
+        if ($on_checkout) {
1983
+            $pay_url = add_query_arg('invoice_key', $key, $pay_url);
1984 1984
         } else {
1985
-            $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url );
1985
+            $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url);
1986 1986
         }
1987 1987
         
1988
-        if ( $secret ) {
1989
-            $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url );
1988
+        if ($secret) {
1989
+            $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url);
1990 1990
         }
1991 1991
 
1992
-        return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this );
1992
+        return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this);
1993 1993
     }
1994 1994
     
1995
-    public function get_view_url( $secret = false ) {
1996
-        $print_url = get_permalink( $this->ID );
1995
+    public function get_view_url($secret = false) {
1996
+        $print_url = get_permalink($this->ID);
1997 1997
         
1998
-        if ( $secret ) {
1999
-            $print_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $print_url );
1998
+        if ($secret) {
1999
+            $print_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key())), $print_url);
2000 2000
         }
2001 2001
 
2002
-        return apply_filters( 'wpinv_get_view_url', $print_url, $this );
2002
+        return apply_filters('wpinv_get_view_url', $print_url, $this);
2003 2003
     }
2004 2004
     
2005
-    public function generate_key( $string = '' ) {
2006
-        $auth_key  = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
2007
-        return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) );  // Unique key
2005
+    public function generate_key($string = '') {
2006
+        $auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
2007
+        return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key
2008 2008
     }
2009 2009
     
2010 2010
     public function is_recurring() {
2011
-        if ( empty( $this->cart_details ) ) {
2011
+        if (empty($this->cart_details)) {
2012 2012
             return false;
2013 2013
         }
2014 2014
         
2015 2015
         $has_subscription = false;
2016
-        foreach( $this->cart_details as $cart_item ) {
2017
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2016
+        foreach ($this->cart_details as $cart_item) {
2017
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2018 2018
                 $has_subscription = true;
2019 2019
                 break;
2020 2020
             }
2021 2021
         }
2022 2022
         
2023
-        if ( count( $this->cart_details ) > 1 ) {
2023
+        if (count($this->cart_details) > 1) {
2024 2024
             $has_subscription = false;
2025 2025
         }
2026 2026
 
2027
-        return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details );
2027
+        return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details);
2028 2028
     }
2029 2029
     
2030 2030
     public function is_free_trial() {
2031 2031
         $is_free_trial = false;
2032 2032
         
2033
-        if ( $this->is_parent() && $item = $this->get_recurring( true ) ) {
2034
-            if ( !empty( $item ) && $item->has_free_trial() ) {
2033
+        if ($this->is_parent() && $item = $this->get_recurring(true)) {
2034
+            if (!empty($item) && $item->has_free_trial()) {
2035 2035
                 $is_free_trial = true;
2036 2036
             }
2037 2037
         }
2038 2038
 
2039
-        return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details );
2039
+        return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details);
2040 2040
     }
2041 2041
     
2042
-    public function get_recurring( $object = false ) {
2042
+    public function get_recurring($object = false) {
2043 2043
         $item = NULL;
2044 2044
         
2045
-        if ( empty( $this->cart_details ) ) {
2045
+        if (empty($this->cart_details)) {
2046 2046
             return $item;
2047 2047
         }
2048 2048
         
2049
-        foreach( $this->cart_details as $cart_item ) {
2050
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2049
+        foreach ($this->cart_details as $cart_item) {
2050
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2051 2051
                 $item = $cart_item['id'];
2052 2052
                 break;
2053 2053
             }
2054 2054
         }
2055 2055
         
2056
-        if ( $object ) {
2057
-            $item = $item ? new WPInv_Item( $item ) : NULL;
2056
+        if ($object) {
2057
+            $item = $item ? new WPInv_Item($item) : NULL;
2058 2058
             
2059
-            apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this );
2059
+            apply_filters('wpinv_invoice_get_recurring_item', $item, $this);
2060 2060
         }
2061 2061
 
2062
-        return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this );
2062
+        return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this);
2063 2063
     }
2064 2064
     
2065 2065
     public function get_subscription_name() {
2066
-        $item = $this->get_recurring( true );
2066
+        $item = $this->get_recurring(true);
2067 2067
         
2068
-        if ( empty( $item ) ) {
2068
+        if (empty($item)) {
2069 2069
             return NULL;
2070 2070
         }
2071 2071
         
2072
-        if ( !($name = $item->get_name()) ) {
2072
+        if (!($name = $item->get_name())) {
2073 2073
             $name = $item->post_name;
2074 2074
         }
2075 2075
 
2076
-        return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this );
2076
+        return apply_filters('wpinv_invoice_get_subscription_name', $name, $this);
2077 2077
     }
2078 2078
         
2079 2079
     public function get_expiration() {
2080
-        $expiration = $this->get_meta( '_wpinv_subscr_expiration', true );
2080
+        $expiration = $this->get_meta('_wpinv_subscr_expiration', true);
2081 2081
         return $expiration;
2082 2082
     }
2083 2083
     
2084
-    public function get_cancelled_date( $formatted = true ) {
2085
-        $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta( '_wpinv_subscr_cancelled_on', true ) : '';
2084
+    public function get_cancelled_date($formatted = true) {
2085
+        $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta('_wpinv_subscr_cancelled_on', true) : '';
2086 2086
         
2087
-        if ( $formatted && $cancelled_date ) {
2088
-            $cancelled_date = date_i18n( get_option( 'date_format' ), strtotime( $cancelled_date ) );
2087
+        if ($formatted && $cancelled_date) {
2088
+            $cancelled_date = date_i18n(get_option('date_format'), strtotime($cancelled_date));
2089 2089
         }
2090 2090
         
2091 2091
         return $cancelled_date;
2092 2092
     }
2093 2093
     
2094
-    public function get_trial_end_date( $formatted = true ) {
2095
-        if ( !$this->is_free_trial() || !$this->is_paid() ) {
2094
+    public function get_trial_end_date($formatted = true) {
2095
+        if (!$this->is_free_trial() || !$this->is_paid()) {
2096 2096
             return NULL;
2097 2097
         }
2098 2098
         
2099
-        $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta( '_wpinv_subscr_trial_end', true ) : '';
2099
+        $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta('_wpinv_subscr_trial_end', true) : '';
2100 2100
         
2101
-        if ( empty( $trial_end_date ) ) {
2102
-            $trial_start_time = strtotime( $this->get_subscription_start() );
2103
-            $trial_start_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;
2101
+        if (empty($trial_end_date)) {
2102
+            $trial_start_time = strtotime($this->get_subscription_start());
2103
+            $trial_start_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);
2104 2104
             
2105
-            $trial_end_date = date_i18n( 'Y-m-d H:i:s', $trial_start_time );
2105
+            $trial_end_date = date_i18n('Y-m-d H:i:s', $trial_start_time);
2106 2106
         }
2107 2107
         
2108
-        if ( $formatted && $trial_end_date ) {
2109
-            $trial_end_date = date_i18n( get_option( 'date_format' ), strtotime( $trial_end_date ) );
2108
+        if ($formatted && $trial_end_date) {
2109
+            $trial_end_date = date_i18n(get_option('date_format'), strtotime($trial_end_date));
2110 2110
         }
2111 2111
         
2112 2112
         return $trial_end_date;
2113 2113
     }
2114 2114
     
2115
-    public function get_subscription_created( $default = true ) {
2116
-        $created = $this->get_meta( '_wpinv_subscr_created', true );
2115
+    public function get_subscription_created($default = true) {
2116
+        $created = $this->get_meta('_wpinv_subscr_created', true);
2117 2117
         
2118
-        if ( empty( $created ) && $default ) {
2118
+        if (empty($created) && $default) {
2119 2119
             $created = $this->date;
2120 2120
         }
2121 2121
         return $created;
2122 2122
     }
2123 2123
     
2124
-    public function get_subscription_start( $formatted = true ) {
2125
-        if ( !$this->is_paid() ) {
2124
+    public function get_subscription_start($formatted = true) {
2125
+        if (!$this->is_paid()) {
2126 2126
             return '-';
2127 2127
         }
2128
-        $start   = $this->get_subscription_created();
2128
+        $start = $this->get_subscription_created();
2129 2129
         
2130
-        if ( $formatted ) {
2131
-            $date = date_i18n( get_option( 'date_format' ), strtotime( $start ) );
2130
+        if ($formatted) {
2131
+            $date = date_i18n(get_option('date_format'), strtotime($start));
2132 2132
         } else {
2133
-            $date = date_i18n( 'Y-m-d H:i:s', strtotime( $start ) );
2133
+            $date = date_i18n('Y-m-d H:i:s', strtotime($start));
2134 2134
         }
2135 2135
 
2136 2136
         return $date;
2137 2137
     }
2138 2138
     
2139
-    public function get_subscription_end( $formatted = true ) {
2140
-        if ( !$this->is_paid() ) {
2139
+    public function get_subscription_end($formatted = true) {
2140
+        if (!$this->is_paid()) {
2141 2141
             return '-';
2142 2142
         }
2143 2143
         $start          = $this->get_subscription_created();
2144 2144
         $interval       = $this->get_subscription_interval();
2145
-        $period         = $this->get_subscription_period( true );
2145
+        $period         = $this->get_subscription_period(true);
2146 2146
         $bill_times     = (int)$this->get_bill_times();
2147 2147
         
2148
-        if ( $bill_times == 0 ) {
2149
-            return $formatted ? __( 'Until cancelled', 'invoicing' ) : $bill_times;
2148
+        if ($bill_times == 0) {
2149
+            return $formatted ? __('Until cancelled', 'invoicing') : $bill_times;
2150 2150
         }
2151 2151
         
2152
-        $total_period = $start . '+' . ( $interval * $bill_times ) . ' ' . $period;
2152
+        $total_period = $start . '+' . ($interval * $bill_times) . ' ' . $period;
2153 2153
         
2154
-        $end_time = strtotime( $start . '+' . ( $interval * $bill_times ) . ' ' . $period );
2154
+        $end_time = strtotime($start . '+' . ($interval * $bill_times) . ' ' . $period);
2155 2155
         
2156
-        if ( $this->is_free_trial() ) {
2157
-            $end_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;
2156
+        if ($this->is_free_trial()) {
2157
+            $end_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);
2158 2158
         }
2159 2159
         
2160
-        if ( $formatted ) {
2161
-            $date = date_i18n( get_option( 'date_format' ), $end_time );
2160
+        if ($formatted) {
2161
+            $date = date_i18n(get_option('date_format'), $end_time);
2162 2162
         } else {
2163
-            $date = date_i18n( 'Y-m-d H:i:s', $end_time );
2163
+            $date = date_i18n('Y-m-d H:i:s', $end_time);
2164 2164
         }
2165 2165
 
2166 2166
         return $date;
2167 2167
     }
2168 2168
     
2169 2169
     public function get_expiration_time() {
2170
-        return strtotime( $this->get_expiration(), current_time( 'timestamp' ) );
2170
+        return strtotime($this->get_expiration(), current_time('timestamp'));
2171 2171
     }
2172 2172
     
2173 2173
     public function get_original_invoice_id() {        
@@ -2179,125 +2179,125 @@  discard block
 block discarded – undo
2179 2179
         return $subscription_data['bill_times'];
2180 2180
     }
2181 2181
 
2182
-    public function get_child_payments( $self = false ) {
2183
-        $invoices = get_posts( array(
2182
+    public function get_child_payments($self = false) {
2183
+        $invoices = get_posts(array(
2184 2184
             'post_type'         => $this->post_type,
2185 2185
             'post_parent'       => (int)$this->ID,
2186 2186
             'posts_per_page'    => '999',
2187
-            'post_status'       => array( 'publish', 'wpi-processing', 'wpi-renewal' ),
2187
+            'post_status'       => array('publish', 'wpi-processing', 'wpi-renewal'),
2188 2188
             'orderby'           => 'ID',
2189 2189
             'order'             => 'DESC',
2190 2190
             'fields'            => 'ids'
2191
-        ) );
2191
+        ));
2192 2192
         
2193
-        if ( $this->is_free_trial() ) {
2193
+        if ($this->is_free_trial()) {
2194 2194
             $self = false;
2195 2195
         }
2196 2196
         
2197
-        if ( $self && $this->is_paid() ) {
2198
-            if ( !empty( $invoices ) ) {
2197
+        if ($self && $this->is_paid()) {
2198
+            if (!empty($invoices)) {
2199 2199
                 $invoices[] = (int)$this->ID;
2200 2200
             } else {
2201
-                $invoices = array( $this->ID );
2201
+                $invoices = array($this->ID);
2202 2202
             }
2203 2203
             
2204
-            $invoices = array_unique( $invoices );
2204
+            $invoices = array_unique($invoices);
2205 2205
         }
2206 2206
 
2207 2207
         return $invoices;
2208 2208
     }
2209 2209
 
2210
-    public function get_total_payments( $self = true ) {
2211
-        return count( $this->get_child_payments( $self ) );
2210
+    public function get_total_payments($self = true) {
2211
+        return count($this->get_child_payments($self));
2212 2212
     }
2213 2213
     
2214
-    public function get_subscriptions( $limit = -1 ) {
2215
-        $subscriptions = wpinv_get_subscriptions( array( 'parent_invoice_id' => $this->ID, 'numberposts' => $limit ) );
2214
+    public function get_subscriptions($limit = -1) {
2215
+        $subscriptions = wpinv_get_subscriptions(array('parent_invoice_id' => $this->ID, 'numberposts' => $limit));
2216 2216
 
2217 2217
         return $subscriptions;
2218 2218
     }
2219 2219
     
2220 2220
     public function get_subscription_id() {
2221
-        $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true );
2221
+        $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true);
2222 2222
         
2223
-        if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) {
2224
-            $parent_invoice = wpinv_get_invoice( $this->parent_invoice );
2223
+        if (empty($subscription_id) && !empty($this->parent_invoice)) {
2224
+            $parent_invoice = wpinv_get_invoice($this->parent_invoice);
2225 2225
             
2226
-            $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true );
2226
+            $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true);
2227 2227
         }
2228 2228
         
2229 2229
         return $subscription_id;
2230 2230
     }
2231 2231
     
2232 2232
     public function get_subscription_status() {
2233
-        $subscription_status = $this->get_meta( '_wpinv_subscr_status', true );
2233
+        $subscription_status = $this->get_meta('_wpinv_subscr_status', true);
2234 2234
 
2235
-        if ( empty( $subscription_status ) ) {
2235
+        if (empty($subscription_status)) {
2236 2236
             $status = 'pending';
2237 2237
             
2238
-            if ( $this->is_paid() ) {        
2238
+            if ($this->is_paid()) {        
2239 2239
                 $bill_times   = (int)$this->get_bill_times();
2240 2240
                 $times_billed = (int)$this->get_total_payments();
2241
-                $expiration = $this->get_subscription_end( false );
2242
-                $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;
2241
+                $expiration = $this->get_subscription_end(false);
2242
+                $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;
2243 2243
                 
2244
-                if ( (int)$bill_times == 0 ) {
2244
+                if ((int)$bill_times == 0) {
2245 2245
                     $status = $expired ? 'expired' : 'active';
2246
-                } else if ( $bill_times > 0 && $times_billed >= $bill_times ) {
2246
+                } else if ($bill_times > 0 && $times_billed >= $bill_times) {
2247 2247
                     $status = 'completed';
2248
-                } else if ( $expired ) {
2248
+                } else if ($expired) {
2249 2249
                     $status = 'expired';
2250
-                } else if ( $bill_times > 0 ) {
2250
+                } else if ($bill_times > 0) {
2251 2251
                     $status = 'active';
2252 2252
                 } else {
2253 2253
                     $status = 'pending';
2254 2254
                 }
2255 2255
             }
2256 2256
             
2257
-            if ( $status && $status != $subscription_status ) {
2257
+            if ($status && $status != $subscription_status) {
2258 2258
                 $subscription_status = $status;
2259 2259
                 
2260
-                $this->update_meta( '_wpinv_subscr_status', $status );
2260
+                $this->update_meta('_wpinv_subscr_status', $status);
2261 2261
             }
2262 2262
         }
2263 2263
         
2264 2264
         return $subscription_status;
2265 2265
     }
2266 2266
     
2267
-    public function get_subscription_status_label( $status = '' ) {
2268
-        $status = !empty( $status ) ? $status : $this->get_subscription_status();
2267
+    public function get_subscription_status_label($status = '') {
2268
+        $status = !empty($status) ? $status : $this->get_subscription_status();
2269 2269
 
2270
-        switch( $status ) {
2270
+        switch ($status) {
2271 2271
             case 'active' :
2272
-                $status_label = __( 'Active', 'invoicing' );
2272
+                $status_label = __('Active', 'invoicing');
2273 2273
                 break;
2274 2274
 
2275 2275
             case 'cancelled' :
2276
-                $status_label = __( 'Cancelled', 'invoicing' );
2276
+                $status_label = __('Cancelled', 'invoicing');
2277 2277
                 break;
2278 2278
                 
2279 2279
             case 'completed' :
2280
-                $status_label = __( 'Completed', 'invoicing' );
2280
+                $status_label = __('Completed', 'invoicing');
2281 2281
                 break;
2282 2282
 
2283 2283
             case 'expired' :
2284
-                $status_label = __( 'Expired', 'invoicing' );
2284
+                $status_label = __('Expired', 'invoicing');
2285 2285
                 break;
2286 2286
 
2287 2287
             case 'pending' :
2288
-                $status_label = __( 'Pending', 'invoicing' );
2288
+                $status_label = __('Pending', 'invoicing');
2289 2289
                 break;
2290 2290
 
2291 2291
             case 'failing' :
2292
-                $status_label = __( 'Failing', 'invoicing' );
2292
+                $status_label = __('Failing', 'invoicing');
2293 2293
                 break;
2294 2294
                 
2295 2295
             case 'stopped' :
2296
-                $status_label = __( 'Stopped', 'invoicing' );
2296
+                $status_label = __('Stopped', 'invoicing');
2297 2297
                 break;
2298 2298
                 
2299 2299
             case 'trialing' :
2300
-                $status_label = __( 'Trialing', 'invoicing' );
2300
+                $status_label = __('Trialing', 'invoicing');
2301 2301
                 break;
2302 2302
 
2303 2303
             default:
@@ -2308,26 +2308,26 @@  discard block
 block discarded – undo
2308 2308
         return $status_label;
2309 2309
     }
2310 2310
     
2311
-    public function get_subscription_period( $full = false ) {
2312
-        $period = $this->get_meta( '_wpinv_subscr_period', true );
2311
+    public function get_subscription_period($full = false) {
2312
+        $period = $this->get_meta('_wpinv_subscr_period', true);
2313 2313
         
2314 2314
         // Fix period for old invoices
2315
-        if ( $period == 'day' ) {
2315
+        if ($period == 'day') {
2316 2316
             $period = 'D';
2317
-        } else if ( $period == 'week' ) {
2317
+        } else if ($period == 'week') {
2318 2318
             $period = 'W';
2319
-        } else if ( $period == 'month' ) {
2319
+        } else if ($period == 'month') {
2320 2320
             $period = 'M';
2321
-        } else if ( $period == 'year' ) {
2321
+        } else if ($period == 'year') {
2322 2322
             $period = 'Y';
2323 2323
         }
2324 2324
         
2325
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2325
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
2326 2326
             $period = 'D';
2327 2327
         }
2328 2328
         
2329
-        if ( $full ) {
2330
-            switch( $period ) {
2329
+        if ($full) {
2330
+            switch ($period) {
2331 2331
                 case 'D':
2332 2332
                     $period = 'day';
2333 2333
                 break;
@@ -2347,39 +2347,39 @@  discard block
 block discarded – undo
2347 2347
     }
2348 2348
     
2349 2349
     public function get_subscription_interval() {
2350
-        $interval = (int)$this->get_meta( '_wpinv_subscr_interval', true );
2350
+        $interval = (int)$this->get_meta('_wpinv_subscr_interval', true);
2351 2351
         
2352
-        if ( !$interval > 0 ) {
2352
+        if (!$interval > 0) {
2353 2353
             $interval = 1;
2354 2354
         }
2355 2355
         
2356 2356
         return $interval;
2357 2357
     }
2358 2358
     
2359
-    public function get_subscription_trial_period( $full = false ) {
2360
-        if ( !$this->is_free_trial() ) {
2359
+    public function get_subscription_trial_period($full = false) {
2360
+        if (!$this->is_free_trial()) {
2361 2361
             return '';
2362 2362
         }
2363 2363
         
2364
-        $period = $this->get_meta( '_wpinv_subscr_trial_period', true );
2364
+        $period = $this->get_meta('_wpinv_subscr_trial_period', true);
2365 2365
         
2366 2366
         // Fix period for old invoices
2367
-        if ( $period == 'day' ) {
2367
+        if ($period == 'day') {
2368 2368
             $period = 'D';
2369
-        } else if ( $period == 'week' ) {
2369
+        } else if ($period == 'week') {
2370 2370
             $period = 'W';
2371
-        } else if ( $period == 'month' ) {
2371
+        } else if ($period == 'month') {
2372 2372
             $period = 'M';
2373
-        } else if ( $period == 'year' ) {
2373
+        } else if ($period == 'year') {
2374 2374
             $period = 'Y';
2375 2375
         }
2376 2376
         
2377
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2377
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
2378 2378
             $period = 'D';
2379 2379
         }
2380 2380
         
2381
-        if ( $full ) {
2382
-            switch( $period ) {
2381
+        if ($full) {
2382
+            switch ($period) {
2383 2383
                 case 'D':
2384 2384
                     $period = 'day';
2385 2385
                 break;
@@ -2399,13 +2399,13 @@  discard block
 block discarded – undo
2399 2399
     }
2400 2400
     
2401 2401
     public function get_subscription_trial_interval() {
2402
-        if ( !$this->is_free_trial() ) {
2402
+        if (!$this->is_free_trial()) {
2403 2403
             return 0;
2404 2404
         }
2405 2405
         
2406
-        $interval = (int)$this->get_meta( '_wpinv_subscr_trial_interval', true );
2406
+        $interval = (int)$this->get_meta('_wpinv_subscr_trial_interval', true);
2407 2407
         
2408
-        if ( !$interval > 0 ) {
2408
+        if (!$interval > 0) {
2409 2409
             $interval = 1;
2410 2410
         }
2411 2411
         
@@ -2417,8 +2417,8 @@  discard block
 block discarded – undo
2417 2417
             'status' => 'failing'
2418 2418
         );
2419 2419
 
2420
-        if ( $this->update_subscription( $args ) ) {
2421
-            do_action( 'wpinv_subscription_failing', $this->ID, $this );
2420
+        if ($this->update_subscription($args)) {
2421
+            do_action('wpinv_subscription_failing', $this->ID, $this);
2422 2422
             return true;
2423 2423
         }
2424 2424
 
@@ -2430,8 +2430,8 @@  discard block
 block discarded – undo
2430 2430
             'status' => 'stopped'
2431 2431
         );
2432 2432
 
2433
-        if ( $this->update_subscription( $args ) ) {
2434
-            do_action( 'wpinv_subscription_stopped', $this->ID, $this );
2433
+        if ($this->update_subscription($args)) {
2434
+            do_action('wpinv_subscription_stopped', $this->ID, $this);
2435 2435
             return true;
2436 2436
         }
2437 2437
 
@@ -2443,8 +2443,8 @@  discard block
 block discarded – undo
2443 2443
             'status' => 'active'
2444 2444
         );
2445 2445
 
2446
-        if ( $this->update_subscription( $args ) ) {
2447
-            do_action( 'wpinv_subscription_restarted', $this->ID, $this );
2446
+        if ($this->update_subscription($args)) {
2447
+            do_action('wpinv_subscription_restarted', $this->ID, $this);
2448 2448
             return true;
2449 2449
         }
2450 2450
 
@@ -2456,23 +2456,23 @@  discard block
 block discarded – undo
2456 2456
             'status' => 'cancelled'
2457 2457
         );
2458 2458
 
2459
-        if ( $this->update_subscription( $args ) ) {
2460
-            if ( is_user_logged_in() ) {
2461
-                $userdata = get_userdata( get_current_user_id() );
2459
+        if ($this->update_subscription($args)) {
2460
+            if (is_user_logged_in()) {
2461
+                $userdata = get_userdata(get_current_user_id());
2462 2462
                 $user     = $userdata->user_login;
2463 2463
             } else {
2464
-                $user = __( 'gateway', 'invoicing' );
2464
+                $user = __('gateway', 'invoicing');
2465 2465
             }
2466 2466
             
2467 2467
             $subscription_id = $this->get_subscription_id();
2468
-            if ( !$subscription_id ) {
2468
+            if (!$subscription_id) {
2469 2469
                 $subscription_id = $this->ID;
2470 2470
             }
2471 2471
 
2472
-            $note = sprintf( __( 'Subscription %s has been cancelled by %s', 'invoicing' ), $subscription_id, $user );
2473
-            $this->add_note( $note );
2472
+            $note = sprintf(__('Subscription %s has been cancelled by %s', 'invoicing'), $subscription_id, $user);
2473
+            $this->add_note($note);
2474 2474
 
2475
-            do_action( 'wpinv_subscription_cancelled', $this->ID, $this );
2475
+            do_action('wpinv_subscription_cancelled', $this->ID, $this);
2476 2476
             return true;
2477 2477
         }
2478 2478
 
@@ -2480,11 +2480,11 @@  discard block
 block discarded – undo
2480 2480
     }
2481 2481
 
2482 2482
     public function can_cancel() {
2483
-        return apply_filters( 'wpinv_subscription_can_cancel', false, $this );
2483
+        return apply_filters('wpinv_subscription_can_cancel', false, $this);
2484 2484
     }
2485 2485
     
2486
-    public function add_subscription( $data = array() ) {
2487
-        if ( empty( $this->ID ) ) {
2486
+    public function add_subscription($data = array()) {
2487
+        if (empty($this->ID)) {
2488 2488
             return false;
2489 2489
         }
2490 2490
 
@@ -2503,85 +2503,85 @@  discard block
 block discarded – undo
2503 2503
             'profile_id'        => '',
2504 2504
         );
2505 2505
 
2506
-        $args = wp_parse_args( $data, $defaults );
2506
+        $args = wp_parse_args($data, $defaults);
2507 2507
 
2508
-        if ( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
2509
-            if ( 'active' == $args['status'] || $args['status'] == 'trialing' ) {
2508
+        if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
2509
+            if ('active' == $args['status'] || $args['status'] == 'trialing') {
2510 2510
                 $args['status'] = 'expired';
2511 2511
             }
2512 2512
         }
2513 2513
 
2514
-        do_action( 'wpinv_subscription_pre_create', $args, $data, $this );
2514
+        do_action('wpinv_subscription_pre_create', $args, $data, $this);
2515 2515
         
2516
-        if ( !empty( $args ) ) {
2517
-            foreach ( $args as $key => $value ) {
2518
-                $this->update_meta( '_wpinv_subscr_' . $key, $value );
2516
+        if (!empty($args)) {
2517
+            foreach ($args as $key => $value) {
2518
+                $this->update_meta('_wpinv_subscr_' . $key, $value);
2519 2519
             }
2520 2520
         }
2521 2521
 
2522
-        do_action( 'wpinv_subscription_post_create', $args, $data, $this );
2522
+        do_action('wpinv_subscription_post_create', $args, $data, $this);
2523 2523
 
2524 2524
         return true;
2525 2525
     }
2526 2526
     
2527
-    public function update_subscription( $args = array() ) {
2528
-        if ( empty( $this->ID ) ) {
2527
+    public function update_subscription($args = array()) {
2528
+        if (empty($this->ID)) {
2529 2529
             return false;
2530 2530
         }
2531 2531
 
2532
-        if ( !empty( $args['expiration'] ) && $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
2533
-            if ( !isset( $args['status'] ) || ( isset( $args['status'] ) && ( 'active' == $args['status'] || $args['status'] == 'trialing' ) ) ) {
2532
+        if (!empty($args['expiration']) && $args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
2533
+            if (!isset($args['status']) || (isset($args['status']) && ('active' == $args['status'] || $args['status'] == 'trialing'))) {
2534 2534
                 $args['status'] = 'expired';
2535 2535
             }
2536 2536
         }
2537 2537
 
2538
-        if ( isset( $args['status'] ) && $args['status'] == 'cancelled' && empty( $args['cancelled_on'] ) ) {
2539
-            $args['cancelled_on'] = date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) );
2538
+        if (isset($args['status']) && $args['status'] == 'cancelled' && empty($args['cancelled_on'])) {
2539
+            $args['cancelled_on'] = date_i18n('Y-m-d H:i:s', current_time('timestamp'));
2540 2540
         }
2541 2541
 
2542
-        do_action( 'wpinv_subscription_pre_update', $args, $this );
2542
+        do_action('wpinv_subscription_pre_update', $args, $this);
2543 2543
         
2544
-        if ( !empty( $args ) ) {
2545
-            foreach ( $args as $key => $value ) {
2546
-                $this->update_meta( '_wpinv_subscr_' . $key, $value );
2544
+        if (!empty($args)) {
2545
+            foreach ($args as $key => $value) {
2546
+                $this->update_meta('_wpinv_subscr_' . $key, $value);
2547 2547
             }
2548 2548
         }
2549 2549
 
2550
-        do_action( 'wpinv_subscription_post_update', $args, $this );
2550
+        do_action('wpinv_subscription_post_update', $args, $this);
2551 2551
 
2552 2552
         return true;
2553 2553
     }
2554 2554
     
2555 2555
     public function renew_subscription() {
2556 2556
         $parent_invoice = $this->get_parent_payment();
2557
-        $parent_invoice = empty( $parent_invoice ) ? $this : $parent_invoice;
2557
+        $parent_invoice = empty($parent_invoice) ? $this : $parent_invoice;
2558 2558
         
2559
-        $current_time   = current_time( 'timestamp' );
2559
+        $current_time   = current_time('timestamp');
2560 2560
         $start          = $this->get_subscription_created();
2561
-        $start          = $start ? strtotime( $start ) : $current_time;
2561
+        $start          = $start ? strtotime($start) : $current_time;
2562 2562
         $expires        = $this->get_expiration_time();
2563 2563
         
2564
-        if ( !$expires ) {
2565
-            $expires    = strtotime( '+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period( true ), $start );
2564
+        if (!$expires) {
2565
+            $expires    = strtotime('+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period(true), $start);
2566 2566
         }
2567 2567
         
2568
-        $expiration     = date_i18n( 'Y-m-d 23:59:59', $expires );
2569
-        $expiration     = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this );
2568
+        $expiration     = date_i18n('Y-m-d 23:59:59', $expires);
2569
+        $expiration     = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this);
2570 2570
         $bill_times     = $parent_invoice->get_bill_times();
2571 2571
         $times_billed   = $parent_invoice->get_total_payments();
2572 2572
         
2573
-        if ( $parent_invoice->get_subscription_status() == 'trialing' && ( $times_billed > 0 || strtotime( date_i18n( 'Y-m-d' ) ) < strtotime( $parent_invoice->get_trial_end_date( false ) ) ) ) {
2573
+        if ($parent_invoice->get_subscription_status() == 'trialing' && ($times_billed > 0 || strtotime(date_i18n('Y-m-d')) < strtotime($parent_invoice->get_trial_end_date(false)))) {
2574 2574
             $args = array(
2575 2575
                 'status'     => 'active',
2576 2576
             );
2577 2577
 
2578
-            $parent_invoice->update_subscription( $args );
2578
+            $parent_invoice->update_subscription($args);
2579 2579
         }
2580 2580
         
2581
-        do_action( 'wpinv_subscription_pre_renew', $this->ID, $expiration, $this );
2581
+        do_action('wpinv_subscription_pre_renew', $this->ID, $expiration, $this);
2582 2582
 
2583
-        $status       = 'active';
2584
-        if ( $bill_times > 0 && $times_billed >= $bill_times ) {
2583
+        $status = 'active';
2584
+        if ($bill_times > 0 && $times_billed >= $bill_times) {
2585 2585
             $this->complete_subscription();
2586 2586
             $status = 'completed';
2587 2587
         }
@@ -2591,10 +2591,10 @@  discard block
 block discarded – undo
2591 2591
             'status'     => $status,
2592 2592
         );
2593 2593
 
2594
-        $this->update_subscription( $args );
2594
+        $this->update_subscription($args);
2595 2595
 
2596
-        do_action( 'wpinv_subscription_post_renew', $this->ID, $expiration, $this );
2597
-        do_action( 'wpinv_recurring_set_subscription_status', $this->ID, $status, $this );
2596
+        do_action('wpinv_subscription_post_renew', $this->ID, $expiration, $this);
2597
+        do_action('wpinv_recurring_set_subscription_status', $this->ID, $status, $this);
2598 2598
     }
2599 2599
     
2600 2600
     public function complete_subscription() {
@@ -2602,8 +2602,8 @@  discard block
 block discarded – undo
2602 2602
             'status' => 'completed'
2603 2603
         );
2604 2604
 
2605
-        if ( $this->update_subscription( $args ) ) {
2606
-            do_action( 'wpinv_subscription_completed', $this->ID, $this );
2605
+        if ($this->update_subscription($args)) {
2606
+            do_action('wpinv_subscription_completed', $this->ID, $this);
2607 2607
         }
2608 2608
     }
2609 2609
     
@@ -2612,44 +2612,44 @@  discard block
 block discarded – undo
2612 2612
             'status' => 'expired'
2613 2613
         );
2614 2614
 
2615
-        if ( $this->update_subscription( $args ) ) {
2616
-            do_action( 'wpinv_subscription_expired', $this->ID, $this );
2615
+        if ($this->update_subscription($args)) {
2616
+            do_action('wpinv_subscription_expired', $this->ID, $this);
2617 2617
         }
2618 2618
     }
2619 2619
 
2620 2620
     public function get_cancel_url() {
2621
-        $url = wp_nonce_url( add_query_arg( array( 'wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID ) ), 'wpinv-recurring-cancel' );
2621
+        $url = wp_nonce_url(add_query_arg(array('wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID)), 'wpinv-recurring-cancel');
2622 2622
 
2623
-        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
2623
+        return apply_filters('wpinv_subscription_cancel_url', $url, $this);
2624 2624
     }
2625 2625
 
2626 2626
     public function can_update() {
2627
-        return apply_filters( 'wpinv_subscription_can_update', false, $this );
2627
+        return apply_filters('wpinv_subscription_can_update', false, $this);
2628 2628
     }
2629 2629
 
2630 2630
     public function get_update_url() {
2631
-        $url = add_query_arg( array( 'action' => 'update', 'sub_id' => $this->ID ) );
2631
+        $url = add_query_arg(array('action' => 'update', 'sub_id' => $this->ID));
2632 2632
 
2633
-        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
2633
+        return apply_filters('wpinv_subscription_update_url', $url, $this);
2634 2634
     }
2635 2635
 
2636 2636
     public function is_parent() {
2637
-        $is_parent = empty( $this->parent_invoice ) ? true : false;
2637
+        $is_parent = empty($this->parent_invoice) ? true : false;
2638 2638
 
2639
-        return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this );
2639
+        return apply_filters('wpinv_invoice_is_parent', $is_parent, $this);
2640 2640
     }
2641 2641
     
2642 2642
     public function is_renewal() {
2643 2643
         $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false;
2644 2644
 
2645
-        return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this );
2645
+        return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this);
2646 2646
     }
2647 2647
     
2648 2648
     public function get_parent_payment() {
2649 2649
         $parent_payment = NULL;
2650 2650
         
2651
-        if ( $this->is_renewal() ) {
2652
-            $parent_payment = wpinv_get_invoice( $this->parent_invoice );
2651
+        if ($this->is_renewal()) {
2652
+            $parent_payment = wpinv_get_invoice($this->parent_invoice);
2653 2653
         }
2654 2654
         
2655 2655
         return $parent_payment;
@@ -2660,100 +2660,100 @@  discard block
 block discarded – undo
2660 2660
         
2661 2661
         $subscription_status = $this->get_subscription_status();
2662 2662
 
2663
-        if( ! $this->is_subscription_expired() && ( $subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing' ) ) {
2663
+        if (!$this->is_subscription_expired() && ($subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing')) {
2664 2664
             $ret = true;
2665 2665
         }
2666 2666
 
2667
-        return apply_filters( 'wpinv_subscription_is_active', $ret, $this->ID, $this );
2667
+        return apply_filters('wpinv_subscription_is_active', $ret, $this->ID, $this);
2668 2668
     }
2669 2669
 
2670 2670
     public function is_subscription_expired() {
2671 2671
         $ret = false;
2672 2672
         $subscription_status = $this->get_subscription_status();
2673 2673
 
2674
-        if ( $subscription_status == 'expired' ) {
2674
+        if ($subscription_status == 'expired') {
2675 2675
             $ret = true;
2676
-        } else if ( 'active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status ) {
2676
+        } else if ('active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status) {
2677 2677
             $ret        = false;
2678 2678
             $expiration = $this->get_expiration_time();
2679 2679
 
2680
-            if ( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) {
2680
+            if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) {
2681 2681
                 $ret = true;
2682 2682
 
2683
-                if ( 'active' === $subscription_status || 'trialing' === $subscription_status ) {
2683
+                if ('active' === $subscription_status || 'trialing' === $subscription_status) {
2684 2684
                     $this->expire_subscription();
2685 2685
                 }
2686 2686
             }
2687 2687
         }
2688 2688
 
2689
-        return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->ID, $this );
2689
+        return apply_filters('wpinv_subscription_is_expired', $ret, $this->ID, $this);
2690 2690
     }
2691 2691
     
2692
-    public function get_new_expiration( $item_id = 0, $trial = true ) {
2693
-        $item   = new WPInv_Item( $item_id );
2692
+    public function get_new_expiration($item_id = 0, $trial = true) {
2693
+        $item   = new WPInv_Item($item_id);
2694 2694
         $interval = $item->get_recurring_interval();
2695
-        $period = $item->get_recurring_period( true );
2695
+        $period = $item->get_recurring_period(true);
2696 2696
         
2697
-        $expiration_time = strtotime( '+' . $interval . ' ' . $period );
2697
+        $expiration_time = strtotime('+' . $interval . ' ' . $period);
2698 2698
         
2699
-        if ( $trial && $this->is_free_trial() && $item->has_free_trial() ) {
2700
-            $expiration_time += ( wpinv_period_in_days( $item->get_trial_interval(), $item->get_trial_period() ) * DAY_IN_SECONDS ) ;
2699
+        if ($trial && $this->is_free_trial() && $item->has_free_trial()) {
2700
+            $expiration_time += (wpinv_period_in_days($item->get_trial_interval(), $item->get_trial_period()) * DAY_IN_SECONDS);
2701 2701
         }
2702 2702
 
2703
-        return date_i18n( 'Y-m-d 23:59:59', $expiration_time );
2703
+        return date_i18n('Y-m-d 23:59:59', $expiration_time);
2704 2704
     }
2705 2705
     
2706
-    public function get_subscription_data( $filed = '' ) {
2707
-        $fields = array( 'item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on' );
2706
+    public function get_subscription_data($filed = '') {
2707
+        $fields = array('item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on');
2708 2708
         
2709 2709
         $subscription_meta = array();
2710
-        foreach ( $fields as $field ) {
2711
-            $subscription_meta[ $field ] = $this->get_meta( '_wpinv_subscr_' . $field );
2710
+        foreach ($fields as $field) {
2711
+            $subscription_meta[$field] = $this->get_meta('_wpinv_subscr_' . $field);
2712 2712
         }
2713 2713
         
2714
-        $item = $this->get_recurring( true );
2714
+        $item = $this->get_recurring(true);
2715 2715
         
2716
-        if ( !empty( $item ) ) {
2717
-            if ( empty( $subscription_meta['item_id'] ) ) {
2716
+        if (!empty($item)) {
2717
+            if (empty($subscription_meta['item_id'])) {
2718 2718
                 $subscription_meta['item_id'] = $item->ID;
2719 2719
             }
2720
-            if ( empty( $subscription_meta['period'] ) ) {
2720
+            if (empty($subscription_meta['period'])) {
2721 2721
                 $subscription_meta['period'] = $item->get_recurring_period();
2722 2722
             }
2723
-            if ( empty( $subscription_meta['interval'] ) ) {
2723
+            if (empty($subscription_meta['interval'])) {
2724 2724
                 $subscription_meta['interval'] = $item->get_recurring_interval();
2725 2725
             }
2726
-            if ( $item->has_free_trial() ) {
2727
-                if ( empty( $subscription_meta['trial_period'] ) ) {
2726
+            if ($item->has_free_trial()) {
2727
+                if (empty($subscription_meta['trial_period'])) {
2728 2728
                     $subscription_meta['trial_period'] = $item->get_trial_period();
2729 2729
                 }
2730
-                if ( empty( $subscription_meta['trial_interval'] ) ) {
2730
+                if (empty($subscription_meta['trial_interval'])) {
2731 2731
                     $subscription_meta['trial_interval'] = $item->get_trial_interval();
2732 2732
                 }
2733 2733
             } else {
2734 2734
                 $subscription_meta['trial_period']      = '';
2735 2735
                 $subscription_meta['trial_interval']    = 0;
2736 2736
             }
2737
-            if ( !$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0 ) {
2737
+            if (!$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0) {
2738 2738
                 $subscription_meta['bill_times'] = $item->get_recurring_limit();
2739 2739
             }
2740
-            if ( $subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '' ) {
2741
-                $subscription_meta['initial_amount']    = wpinv_round_amount( $this->get_total() );
2742
-                $subscription_meta['recurring_amount']  = wpinv_round_amount( $this->get_recurring_details( 'total' ) );
2740
+            if ($subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '') {
2741
+                $subscription_meta['initial_amount']    = wpinv_round_amount($this->get_total());
2742
+                $subscription_meta['recurring_amount']  = wpinv_round_amount($this->get_recurring_details('total'));
2743 2743
             }
2744 2744
         }
2745 2745
         
2746
-        if ( $filed === '' ) {
2747
-            return apply_filters( 'wpinv_get_invoice_subscription_data', $subscription_meta, $this );
2746
+        if ($filed === '') {
2747
+            return apply_filters('wpinv_get_invoice_subscription_data', $subscription_meta, $this);
2748 2748
         }
2749 2749
         
2750
-        $value = isset( $subscription_meta[$filed] ) ? $subscription_meta[$filed] : '';
2750
+        $value = isset($subscription_meta[$filed]) ? $subscription_meta[$filed] : '';
2751 2751
         
2752
-        return apply_filters( 'wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this );
2752
+        return apply_filters('wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this);
2753 2753
     }
2754 2754
     
2755 2755
     public function is_paid() {
2756
-        if ( $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
2756
+        if ($this->has_status(array('publish', 'wpi-processing', 'wpi-renewal'))) {
2757 2757
             return true;
2758 2758
         }
2759 2759
         
@@ -2763,15 +2763,15 @@  discard block
 block discarded – undo
2763 2763
     public function is_free() {
2764 2764
         $is_free = false;
2765 2765
         
2766
-        if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) {
2767
-            if ( $this->is_parent() && $this->is_recurring() ) {
2768
-                $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true;
2766
+        if (!((float)wpinv_round_amount($this->get_total()) > 0)) {
2767
+            if ($this->is_parent() && $this->is_recurring()) {
2768
+                $is_free = (float)wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true;
2769 2769
             } else {
2770 2770
                 $is_free = true;
2771 2771
             }
2772 2772
         }
2773 2773
         
2774
-        return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2774
+        return apply_filters('wpinv_invoice_is_free', $is_free, $this);
2775 2775
     }
2776 2776
     
2777 2777
     public function has_vat() {
@@ -2779,40 +2779,40 @@  discard block
 block discarded – undo
2779 2779
         
2780 2780
         $requires_vat = false;
2781 2781
         
2782
-        if ( $this->country ) {
2782
+        if ($this->country) {
2783 2783
             $wpi_country        = $this->country;
2784 2784
             
2785
-            $requires_vat       = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) );
2785
+            $requires_vat       = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this));
2786 2786
         }
2787 2787
         
2788
-        return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2788
+        return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this);
2789 2789
     }
2790 2790
     
2791 2791
     public function refresh_item_ids() {
2792 2792
         $item_ids = array();
2793 2793
         
2794
-        if ( !empty( $this->cart_details ) ) {
2795
-            foreach ( $this->cart_details as $key => $item ) {
2796
-                if ( !empty( $item['id'] ) ) {
2794
+        if (!empty($this->cart_details)) {
2795
+            foreach ($this->cart_details as $key => $item) {
2796
+                if (!empty($item['id'])) {
2797 2797
                     $item_ids[] = $item['id'];
2798 2798
                 }
2799 2799
             }
2800 2800
         }
2801 2801
         
2802
-        $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : '';
2802
+        $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : '';
2803 2803
         
2804
-        update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids );
2804
+        update_post_meta($this->ID, '_wpinv_item_ids', $item_ids);
2805 2805
     }
2806 2806
 
2807 2807
     public function get_invoice_quote_type($post_id) {
2808
-        if ( empty( $post_id ) ) {
2808
+        if (empty($post_id)) {
2809 2809
             return '';
2810 2810
         }
2811 2811
         $post_type = '';
2812 2812
         $type = get_post_type($post_id);
2813
-        if("wpi_invoice" === $type){
2813
+        if ("wpi_invoice" === $type) {
2814 2814
             $post_type = __('Invoice', 'invoicing');
2815
-        } else{
2815
+        } else {
2816 2816
             $post_type = __('Quote', 'invoicing');
2817 2817
         }
2818 2818
 
Please login to merge, or discard this patch.
includes/wpinv-helper-functions.php 1 patch
Spacing   +231 added lines, -231 removed lines patch added patch discarded remove patch
@@ -7,84 +7,84 @@  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_item_quantities_enabled() {
15
-    $ret = wpinv_get_option( 'item_quantities', true );
15
+    $ret = wpinv_get_option('item_quantities', true);
16 16
     
17
-    return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret );
17
+    return (bool)apply_filters('wpinv_item_quantities_enabled', $ret);
18 18
 }
19 19
 
20 20
 function wpinv_get_ip() {
21 21
     $ip = '127.0.0.1';
22 22
 
23
-    if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
24
-        $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] );
25
-    } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
26
-        $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] );
27
-    } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) {
28
-        $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
23
+    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
24
+        $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']);
25
+    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
26
+        $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']);
27
+    } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
28
+        $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']);
29 29
     }
30 30
     
31
-    return apply_filters( 'wpinv_get_ip', $ip );
31
+    return apply_filters('wpinv_get_ip', $ip);
32 32
 }
33 33
 
34 34
 function wpinv_get_user_agent() {
35
-    if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
36
-        $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
35
+    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
36
+        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
37 37
     } else {
38 38
         $user_agent = '';
39 39
     }
40 40
     
41
-    return apply_filters( 'wpinv_get_user_agent', $user_agent );
41
+    return apply_filters('wpinv_get_user_agent', $user_agent);
42 42
 }
43 43
 
44
-function wpinv_sanitize_amount( $amount ) {
44
+function wpinv_sanitize_amount($amount) {
45 45
     $is_negative   = false;
46 46
     $thousands_sep = wpinv_thousands_separator();
47 47
     $decimal_sep   = wpinv_decimal_separator();
48 48
     $decimals = wpinv_decimals();
49 49
 
50 50
     // Sanitize the amount
51
-    if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) {
52
-        if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
53
-            $amount = str_replace( $thousands_sep, '', $amount );
54
-        } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) {
55
-            $amount = str_replace( '.', '', $amount );
51
+    if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) {
52
+        if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) {
53
+            $amount = str_replace($thousands_sep, '', $amount);
54
+        } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) {
55
+            $amount = str_replace('.', '', $amount);
56 56
         }
57 57
 
58
-        $amount = str_replace( $decimal_sep, '.', $amount );
59
-    } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
60
-        $amount = str_replace( $thousands_sep, '', $amount );
58
+        $amount = str_replace($decimal_sep, '.', $amount);
59
+    } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
60
+        $amount = str_replace($thousands_sep, '', $amount);
61 61
     }
62 62
 
63
-    if( $amount < 0 ) {
63
+    if ($amount < 0) {
64 64
         $is_negative = true;
65 65
     }
66 66
 
67
-    $amount   = preg_replace( '/[^0-9\.]/', '', $amount );
67
+    $amount   = preg_replace('/[^0-9\.]/', '', $amount);
68 68
 
69
-    $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', $decimals, $amount );
70
-    $amount   = number_format( (double) $amount, $decimals, '.', '' );
69
+    $decimals = apply_filters('wpinv_sanitize_amount_decimals', $decimals, $amount);
70
+    $amount   = number_format((double)$amount, $decimals, '.', '');
71 71
 
72
-    if( $is_negative ) {
72
+    if ($is_negative) {
73 73
         $amount *= -1;
74 74
     }
75 75
 
76
-    return apply_filters( 'wpinv_sanitize_amount', $amount );
76
+    return apply_filters('wpinv_sanitize_amount', $amount);
77 77
 }
78 78
 
79
-function wpinv_round_amount( $amount ) {
79
+function wpinv_round_amount($amount) {
80 80
     $decimals = wpinv_decimals();
81 81
     
82
-    $amount = round( (double)$amount, wpinv_currency_decimal_filter( $decimals ) );
82
+    $amount = round((double)$amount, wpinv_currency_decimal_filter($decimals));
83 83
 
84
-    return apply_filters( 'wpinv_round_amount', $amount );
84
+    return apply_filters('wpinv_round_amount', $amount);
85 85
 }
86 86
 
87
-function wpinv_get_invoice_statuses( $trashed = false ) {
87
+function wpinv_get_invoice_statuses($trashed = false) {
88 88
     global $post;
89 89
     $invoice_statuses = array();
90 90
     $invoice_statuses = array(
@@ -98,32 +98,32 @@  discard block
 block discarded – undo
98 98
         'wpi-renewal' => __('Renewal Payment', 'invoicing')
99 99
     );
100 100
     
101
-    if ( $trashed ) {
102
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
101
+    if ($trashed) {
102
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
103 103
     }
104 104
 
105
-    return apply_filters( 'wpinv_statuses', $invoice_statuses );
105
+    return apply_filters('wpinv_statuses', $invoice_statuses);
106 106
 }
107 107
 
108
-function wpinv_status_nicename( $status ) {
108
+function wpinv_status_nicename($status) {
109 109
     $statuses = wpinv_get_invoice_statuses();
110
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' );
110
+    $status   = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing');
111 111
 
112 112
     return $status;
113 113
 }
114 114
 
115 115
 function wpinv_get_currency() {
116
-    $currency = wpinv_get_option( 'currency', 'USD' );
116
+    $currency = wpinv_get_option('currency', 'USD');
117 117
     
118
-    return apply_filters( 'wpinv_currency', $currency );
118
+    return apply_filters('wpinv_currency', $currency);
119 119
 }
120 120
 
121
-function wpinv_currency_symbol( $currency = '' ) {
122
-    if ( empty( $currency ) ) {
121
+function wpinv_currency_symbol($currency = '') {
122
+    if (empty($currency)) {
123 123
         $currency = wpinv_get_currency();
124 124
     }
125 125
     
126
-    $symbols = apply_filters( 'wpinv_currency_symbols', array(
126
+    $symbols = apply_filters('wpinv_currency_symbols', array(
127 127
         'AED' => 'د.إ',
128 128
         'ARS' => '&#36;',
129 129
         'AUD' => '&#36;',
@@ -175,78 +175,78 @@  discard block
 block discarded – undo
175 175
         'USD' => '&#36;',
176 176
         'VND' => '&#8363;',
177 177
         'ZAR' => '&#82;',
178
-    ) );
178
+    ));
179 179
 
180
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : '&#36;';
180
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : '&#36;';
181 181
 
182
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
182
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
183 183
 }
184 184
 
185 185
 function wpinv_currency_position() {
186
-    $position = wpinv_get_option( 'currency_position', 'left' );
186
+    $position = wpinv_get_option('currency_position', 'left');
187 187
     
188
-    return apply_filters( 'wpinv_currency_position', $position );
188
+    return apply_filters('wpinv_currency_position', $position);
189 189
 }
190 190
 
191 191
 function wpinv_thousands_separator() {
192
-    $thousand_sep = wpinv_get_option( 'thousands_separator', ',' );
192
+    $thousand_sep = wpinv_get_option('thousands_separator', ',');
193 193
     
194
-    return apply_filters( 'wpinv_thousands_separator', $thousand_sep );
194
+    return apply_filters('wpinv_thousands_separator', $thousand_sep);
195 195
 }
196 196
 
197 197
 function wpinv_decimal_separator() {
198
-    $decimal_sep = wpinv_get_option( 'decimal_separator', '.' );
198
+    $decimal_sep = wpinv_get_option('decimal_separator', '.');
199 199
     
200
-    return apply_filters( 'wpinv_decimal_separator', $decimal_sep );
200
+    return apply_filters('wpinv_decimal_separator', $decimal_sep);
201 201
 }
202 202
 
203 203
 function wpinv_decimals() {
204
-    $decimals = apply_filters( 'wpinv_decimals', wpinv_get_option( 'decimals', 2 ) );
204
+    $decimals = apply_filters('wpinv_decimals', wpinv_get_option('decimals', 2));
205 205
     
206
-    return absint( $decimals );
206
+    return absint($decimals);
207 207
 }
208 208
 
209 209
 function wpinv_get_currencies() {
210 210
     $currencies = array(
211
-        'USD'  => __( 'US Dollars (&#36;)', 'invoicing' ),
212
-        'EUR'  => __( 'Euros (&euro;)', 'invoicing' ),
213
-        'GBP'  => __( 'Pounds Sterling (&pound;)', 'invoicing' ),
214
-        'AUD'  => __( 'Australian Dollars (&#36;)', 'invoicing' ),
215
-        'BRL'  => __( 'Brazilian Real (R&#36;)', 'invoicing' ),
216
-        'CAD'  => __( 'Canadian Dollars (&#36;)', 'invoicing' ),
217
-        'CLP'  => __( 'Chilean Peso (&#36;)', 'invoicing' ),
218
-        'CNY'  => __( 'Chinese Yuan (&yen;)', 'invoicing' ),
219
-        'CZK'  => __( 'Czech Koruna (&#75;&#269;)', 'invoicing' ),
220
-        'DKK'  => __( 'Danish Krone (DKK)', 'invoicing' ),
221
-        'HKD'  => __( 'Hong Kong Dollar (&#36;)', 'invoicing' ),
222
-        'HUF'  => __( 'Hungarian Forint (&#70;&#116;)', 'invoicing' ),
223
-        'INR'  => __( 'Indian Rupee (&#8377;)', 'invoicing' ),
224
-        'ILS'  => __( 'Israeli Shekel (&#8362;)', 'invoicing' ),
225
-        'JPY'  => __( 'Japanese Yen (&yen;)', 'invoicing' ),
226
-        'MYR'  => __( 'Malaysian Ringgit (&#82;&#77;)', 'invoicing' ),
227
-        'MXN'  => __( 'Mexican Peso (&#36;)', 'invoicing' ),
228
-        'NZD'  => __( 'New Zealand Dollar (&#36;)', 'invoicing' ),
229
-        'NOK'  => __( 'Norwegian Krone (&#107;&#114;)', 'invoicing' ),
230
-        'PHP'  => __( 'Philippine Peso (&#8369;)', 'invoicing' ),
231
-        'PLN'  => __( 'Polish Zloty (&#122;&#322;)', 'invoicing' ),
232
-        'SGD'  => __( 'Singapore Dollar (&#36;)', 'invoicing' ),
233
-        'SEK'  => __( 'Swedish Krona (&#107;&#114;)', 'invoicing' ),
234
-        'CHF'  => __( 'Swiss Franc (&#67;&#72;&#70;)', 'invoicing' ),
235
-        'TWD'  => __( 'Taiwan New Dollar (&#78;&#84;&#36;)', 'invoicing' ),
236
-        'THB'  => __( 'Thai Baht (&#3647;)', 'invoicing' ),
237
-        'TRY'  => __( 'Turkish Lira (&#8378;)', 'invoicing' ),
238
-        'RIAL' => __( 'Iranian Rial (&#65020;)', 'invoicing' ),
239
-        'RUB'  => __( 'Russian Ruble (&#8381;)', 'invoicing' ),
240
-        'ZAR'  => __( 'South African Rand (&#82;)', 'invoicing' )
211
+        'USD'  => __('US Dollars (&#36;)', 'invoicing'),
212
+        'EUR'  => __('Euros (&euro;)', 'invoicing'),
213
+        'GBP'  => __('Pounds Sterling (&pound;)', 'invoicing'),
214
+        'AUD'  => __('Australian Dollars (&#36;)', 'invoicing'),
215
+        'BRL'  => __('Brazilian Real (R&#36;)', 'invoicing'),
216
+        'CAD'  => __('Canadian Dollars (&#36;)', 'invoicing'),
217
+        'CLP'  => __('Chilean Peso (&#36;)', 'invoicing'),
218
+        'CNY'  => __('Chinese Yuan (&yen;)', 'invoicing'),
219
+        'CZK'  => __('Czech Koruna (&#75;&#269;)', 'invoicing'),
220
+        'DKK'  => __('Danish Krone (DKK)', 'invoicing'),
221
+        'HKD'  => __('Hong Kong Dollar (&#36;)', 'invoicing'),
222
+        'HUF'  => __('Hungarian Forint (&#70;&#116;)', 'invoicing'),
223
+        'INR'  => __('Indian Rupee (&#8377;)', 'invoicing'),
224
+        'ILS'  => __('Israeli Shekel (&#8362;)', 'invoicing'),
225
+        'JPY'  => __('Japanese Yen (&yen;)', 'invoicing'),
226
+        'MYR'  => __('Malaysian Ringgit (&#82;&#77;)', 'invoicing'),
227
+        'MXN'  => __('Mexican Peso (&#36;)', 'invoicing'),
228
+        'NZD'  => __('New Zealand Dollar (&#36;)', 'invoicing'),
229
+        'NOK'  => __('Norwegian Krone (&#107;&#114;)', 'invoicing'),
230
+        'PHP'  => __('Philippine Peso (&#8369;)', 'invoicing'),
231
+        'PLN'  => __('Polish Zloty (&#122;&#322;)', 'invoicing'),
232
+        'SGD'  => __('Singapore Dollar (&#36;)', 'invoicing'),
233
+        'SEK'  => __('Swedish Krona (&#107;&#114;)', 'invoicing'),
234
+        'CHF'  => __('Swiss Franc (&#67;&#72;&#70;)', 'invoicing'),
235
+        'TWD'  => __('Taiwan New Dollar (&#78;&#84;&#36;)', 'invoicing'),
236
+        'THB'  => __('Thai Baht (&#3647;)', 'invoicing'),
237
+        'TRY'  => __('Turkish Lira (&#8378;)', 'invoicing'),
238
+        'RIAL' => __('Iranian Rial (&#65020;)', 'invoicing'),
239
+        'RUB'  => __('Russian Ruble (&#8381;)', 'invoicing'),
240
+        'ZAR'  => __('South African Rand (&#82;)', 'invoicing')
241 241
     );
242 242
     
243
-    asort( $currencies );
243
+    asort($currencies);
244 244
 
245
-    return apply_filters( 'wpinv_currencies', $currencies );
245
+    return apply_filters('wpinv_currencies', $currencies);
246 246
 }
247 247
 
248
-function wpinv_price( $amount = '', $currency = '' ) {
249
-    if( empty( $currency ) ) {
248
+function wpinv_price($amount = '', $currency = '') {
249
+    if (empty($currency)) {
250 250
         $currency = wpinv_get_currency();
251 251
     }
252 252
 
@@ -254,14 +254,14 @@  discard block
 block discarded – undo
254 254
 
255 255
     $negative = $amount < 0;
256 256
 
257
-    if ( $negative ) {
258
-        $amount = substr( $amount, 1 );
257
+    if ($negative) {
258
+        $amount = substr($amount, 1);
259 259
     }
260 260
 
261
-    $symbol = wpinv_currency_symbol( $currency );
261
+    $symbol = wpinv_currency_symbol($currency);
262 262
 
263
-    if ( $position == 'left' || $position == 'left_space' ) {
264
-        switch ( $currency ) {
263
+    if ($position == 'left' || $position == 'left_space') {
264
+        switch ($currency) {
265 265
             case "GBP" :
266 266
             case "BRL" :
267 267
             case "EUR" :
@@ -273,15 +273,15 @@  discard block
 block discarded – undo
273 273
             case "NZD" :
274 274
             case "SGD" :
275 275
             case "JPY" :
276
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
276
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
277 277
                 break;
278 278
             default :
279 279
                 //$price = $currency . ' ' . $amount;
280
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
280
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
281 281
                 break;
282 282
         }
283 283
     } else {
284
-        switch ( $currency ) {
284
+        switch ($currency) {
285 285
             case "GBP" :
286 286
             case "BRL" :
287 287
             case "EUR" :
@@ -292,82 +292,82 @@  discard block
 block discarded – undo
292 292
             case "MXN" :
293 293
             case "SGD" :
294 294
             case "JPY" :
295
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
295
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
296 296
                 break;
297 297
             default :
298 298
                 //$price = $amount . ' ' . $currency;
299
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
299
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
300 300
                 break;
301 301
         }
302 302
     }
303 303
     
304
-    if ( $negative ) {
304
+    if ($negative) {
305 305
         $price = '-' . $price;
306 306
     }
307 307
     
308
-    $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount );
308
+    $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount);
309 309
 
310 310
     return $price;
311 311
 }
312 312
 
313
-function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) {
313
+function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) {
314 314
     $thousands_sep = wpinv_thousands_separator();
315 315
     $decimal_sep   = wpinv_decimal_separator();
316 316
 
317
-    if ( $decimals === NULL ) {
317
+    if ($decimals === NULL) {
318 318
         $decimals = wpinv_decimals();
319 319
     }
320 320
 
321
-    if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) {
322
-        $whole = substr( $amount, 0, $sep_found );
323
-        $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) );
321
+    if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) {
322
+        $whole = substr($amount, 0, $sep_found);
323
+        $part = substr($amount, $sep_found + 1, (strlen($amount) - 1));
324 324
         $amount = $whole . '.' . $part;
325 325
     }
326 326
 
327
-    if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
328
-        $amount = str_replace( ',', '', $amount );
327
+    if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
328
+        $amount = str_replace(',', '', $amount);
329 329
     }
330 330
 
331
-    if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
332
-        $amount = str_replace( ' ', '', $amount );
331
+    if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) {
332
+        $amount = str_replace(' ', '', $amount);
333 333
     }
334 334
 
335
-    if ( empty( $amount ) ) {
335
+    if (empty($amount)) {
336 336
         $amount = 0;
337 337
     }
338 338
     
339
-    $decimals  = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate );
340
-    $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep );
339
+    $decimals  = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate);
340
+    $formatted = number_format((float)$amount, $decimals, $decimal_sep, $thousands_sep);
341 341
     
342
-    if ( $calculate ) {
343
-        if ( $thousands_sep === "," ) {
344
-            $formatted = str_replace( ",", "", $formatted );
342
+    if ($calculate) {
343
+        if ($thousands_sep === ",") {
344
+            $formatted = str_replace(",", "", $formatted);
345 345
         }
346 346
         
347
-        if ( $decimal_sep === "," ) {
348
-            $formatted = str_replace( ",", ".", $formatted );
347
+        if ($decimal_sep === ",") {
348
+            $formatted = str_replace(",", ".", $formatted);
349 349
         }
350 350
     }
351 351
 
352
-    return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate );
352
+    return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate);
353 353
 }
354 354
 
355
-function wpinv_sanitize_key( $key ) {
355
+function wpinv_sanitize_key($key) {
356 356
     $raw_key = $key;
357
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
357
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
358 358
 
359
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
359
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
360 360
 }
361 361
 
362
-function wpinv_get_file_extension( $str ) {
363
-    $parts = explode( '.', $str );
364
-    return end( $parts );
362
+function wpinv_get_file_extension($str) {
363
+    $parts = explode('.', $str);
364
+    return end($parts);
365 365
 }
366 366
 
367
-function wpinv_string_is_image_url( $str ) {
368
-    $ext = wpinv_get_file_extension( $str );
367
+function wpinv_string_is_image_url($str) {
368
+    $ext = wpinv_get_file_extension($str);
369 369
 
370
-    switch ( strtolower( $ext ) ) {
370
+    switch (strtolower($ext)) {
371 371
         case 'jpeg';
372 372
         case 'jpg';
373 373
             $return = true;
@@ -383,32 +383,32 @@  discard block
 block discarded – undo
383 383
             break;
384 384
     }
385 385
 
386
-    return (bool)apply_filters( 'wpinv_string_is_image', $return, $str );
386
+    return (bool)apply_filters('wpinv_string_is_image', $return, $str);
387 387
 }
388 388
 
389
-function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) {
390
-    $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG );
389
+function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) {
390
+    $should_log = apply_filters('wpinv_log_errors', WP_DEBUG);
391 391
     
392
-    if ( true === $should_log ) {
392
+    if (true === $should_log) {
393 393
         $label = '';
394
-        if ( $file && $file !== '' ) {
395
-            $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' );
394
+        if ($file && $file !== '') {
395
+            $label .= basename($file) . ($line ? '(' . $line . ')' : '');
396 396
         }
397 397
         
398
-        if ( $title && $title !== '' ) {
398
+        if ($title && $title !== '') {
399 399
             $label = $label !== '' ? $label . ' ' : '';
400 400
             $label .= $title . ' ';
401 401
         }
402 402
         
403
-        $label = $label !== '' ? trim( $label ) . ' : ' : '';
403
+        $label = $label !== '' ? trim($label) . ' : ' : '';
404 404
         
405
-        if ( is_array( $log ) || is_object( $log ) ) {
406
-            error_log( $label . print_r( $log, true ) );
405
+        if (is_array($log) || is_object($log)) {
406
+            error_log($label . print_r($log, true));
407 407
         } else {
408
-            error_log( $label . $log );
408
+            error_log($label . $log);
409 409
         }
410 410
         
411
-        if ( $exit ) {
411
+        if ($exit) {
412 412
             exit;
413 413
         }
414 414
     }
@@ -416,65 +416,65 @@  discard block
 block discarded – undo
416 416
 
417 417
 function wpinv_is_ajax_disabled() {
418 418
     $retval = false;
419
-    return apply_filters( 'wpinv_is_ajax_disabled', $retval );
419
+    return apply_filters('wpinv_is_ajax_disabled', $retval);
420 420
 }
421 421
 
422
-function wpinv_get_current_page_url( $nocache = false ) {
422
+function wpinv_get_current_page_url($nocache = false) {
423 423
     global $wp;
424 424
 
425
-    if ( get_option( 'permalink_structure' ) ) {
426
-        $base = trailingslashit( home_url( $wp->request ) );
425
+    if (get_option('permalink_structure')) {
426
+        $base = trailingslashit(home_url($wp->request));
427 427
     } else {
428
-        $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) );
429
-        $base = remove_query_arg( array( 'post_type', 'name' ), $base );
428
+        $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request)));
429
+        $base = remove_query_arg(array('post_type', 'name'), $base);
430 430
     }
431 431
 
432 432
     $scheme = is_ssl() ? 'https' : 'http';
433
-    $uri    = set_url_scheme( $base, $scheme );
433
+    $uri    = set_url_scheme($base, $scheme);
434 434
 
435
-    if ( is_front_page() ) {
436
-        $uri = home_url( '/' );
437
-    } elseif ( wpinv_is_checkout( array(), false ) ) {
435
+    if (is_front_page()) {
436
+        $uri = home_url('/');
437
+    } elseif (wpinv_is_checkout(array(), false)) {
438 438
         $uri = wpinv_get_checkout_uri();
439 439
     }
440 440
 
441
-    $uri = apply_filters( 'wpinv_get_current_page_url', $uri );
441
+    $uri = apply_filters('wpinv_get_current_page_url', $uri);
442 442
 
443
-    if ( $nocache ) {
444
-        $uri = wpinv_add_cache_busting( $uri );
443
+    if ($nocache) {
444
+        $uri = wpinv_add_cache_busting($uri);
445 445
     }
446 446
 
447 447
     return $uri;
448 448
 }
449 449
 
450 450
 function wpinv_get_php_arg_separator_output() {
451
-	return ini_get( 'arg_separator.output' );
451
+	return ini_get('arg_separator.output');
452 452
 }
453 453
 
454
-function wpinv_rgb_from_hex( $color ) {
455
-    $color = str_replace( '#', '', $color );
454
+function wpinv_rgb_from_hex($color) {
455
+    $color = str_replace('#', '', $color);
456 456
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
457
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
457
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
458 458
 
459 459
     $rgb      = array();
460
-    $rgb['R'] = hexdec( $color{0}.$color{1} );
461
-    $rgb['G'] = hexdec( $color{2}.$color{3} );
462
-    $rgb['B'] = hexdec( $color{4}.$color{5} );
460
+    $rgb['R'] = hexdec($color{0} . $color{1} );
461
+    $rgb['G'] = hexdec($color{2} . $color{3} );
462
+    $rgb['B'] = hexdec($color{4} . $color{5} );
463 463
 
464 464
     return $rgb;
465 465
 }
466 466
 
467
-function wpinv_hex_darker( $color, $factor = 30 ) {
468
-    $base  = wpinv_rgb_from_hex( $color );
467
+function wpinv_hex_darker($color, $factor = 30) {
468
+    $base  = wpinv_rgb_from_hex($color);
469 469
     $color = '#';
470 470
 
471
-    foreach ( $base as $k => $v ) {
471
+    foreach ($base as $k => $v) {
472 472
         $amount      = $v / 100;
473
-        $amount      = round( $amount * $factor );
473
+        $amount      = round($amount * $factor);
474 474
         $new_decimal = $v - $amount;
475 475
 
476
-        $new_hex_component = dechex( $new_decimal );
477
-        if ( strlen( $new_hex_component ) < 2 ) {
476
+        $new_hex_component = dechex($new_decimal);
477
+        if (strlen($new_hex_component) < 2) {
478 478
             $new_hex_component = "0" . $new_hex_component;
479 479
         }
480 480
         $color .= $new_hex_component;
@@ -483,18 +483,18 @@  discard block
 block discarded – undo
483 483
     return $color;
484 484
 }
485 485
 
486
-function wpinv_hex_lighter( $color, $factor = 30 ) {
487
-    $base  = wpinv_rgb_from_hex( $color );
486
+function wpinv_hex_lighter($color, $factor = 30) {
487
+    $base  = wpinv_rgb_from_hex($color);
488 488
     $color = '#';
489 489
 
490
-    foreach ( $base as $k => $v ) {
490
+    foreach ($base as $k => $v) {
491 491
         $amount      = 255 - $v;
492 492
         $amount      = $amount / 100;
493
-        $amount      = round( $amount * $factor );
493
+        $amount      = round($amount * $factor);
494 494
         $new_decimal = $v + $amount;
495 495
 
496
-        $new_hex_component = dechex( $new_decimal );
497
-        if ( strlen( $new_hex_component ) < 2 ) {
496
+        $new_hex_component = dechex($new_decimal);
497
+        if (strlen($new_hex_component) < 2) {
498 498
             $new_hex_component = "0" . $new_hex_component;
499 499
         }
500 500
         $color .= $new_hex_component;
@@ -503,22 +503,22 @@  discard block
 block discarded – undo
503 503
     return $color;
504 504
 }
505 505
 
506
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
507
-    $hex = str_replace( '#', '', $color );
506
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
507
+    $hex = str_replace('#', '', $color);
508 508
 
509
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
510
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
511
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
509
+    $c_r = hexdec(substr($hex, 0, 2));
510
+    $c_g = hexdec(substr($hex, 2, 2));
511
+    $c_b = hexdec(substr($hex, 4, 2));
512 512
 
513
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
513
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
514 514
 
515 515
     return $brightness > 155 ? $dark : $light;
516 516
 }
517 517
 
518
-function wpinv_format_hex( $hex ) {
519
-    $hex = trim( str_replace( '#', '', $hex ) );
518
+function wpinv_format_hex($hex) {
519
+    $hex = trim(str_replace('#', '', $hex));
520 520
 
521
-    if ( strlen( $hex ) == 3 ) {
521
+    if (strlen($hex) == 3) {
522 522
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
523 523
     }
524 524
 
@@ -538,12 +538,12 @@  discard block
 block discarded – undo
538 538
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
539 539
  * @return string
540 540
  */
541
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
542
-    if ( function_exists( 'mb_strimwidth' ) ) {
543
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
541
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
542
+    if (function_exists('mb_strimwidth')) {
543
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
544 544
     }
545 545
     
546
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
546
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
547 547
 }
548 548
 
549 549
 /**
@@ -555,28 +555,28 @@  discard block
 block discarded – undo
555 555
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
556 556
  * @return int Returns the number of characters in string.
557 557
  */
558
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
559
-    if ( function_exists( 'mb_strlen' ) ) {
560
-        return mb_strlen( $str, $encoding );
558
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
559
+    if (function_exists('mb_strlen')) {
560
+        return mb_strlen($str, $encoding);
561 561
     }
562 562
         
563
-    return strlen( $str );
563
+    return strlen($str);
564 564
 }
565 565
 
566
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
567
-    if ( function_exists( 'mb_strtolower' ) ) {
568
-        return mb_strtolower( $str, $encoding );
566
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
567
+    if (function_exists('mb_strtolower')) {
568
+        return mb_strtolower($str, $encoding);
569 569
     }
570 570
     
571
-    return strtolower( $str );
571
+    return strtolower($str);
572 572
 }
573 573
 
574
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
575
-    if ( function_exists( 'mb_strtoupper' ) ) {
576
-        return mb_strtoupper( $str, $encoding );
574
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
575
+    if (function_exists('mb_strtoupper')) {
576
+        return mb_strtoupper($str, $encoding);
577 577
     }
578 578
     
579
-    return strtoupper( $str );
579
+    return strtoupper($str);
580 580
 }
581 581
 
582 582
 /**
@@ -590,12 +590,12 @@  discard block
 block discarded – undo
590 590
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
591 591
  * @return int Returns the position of the first occurrence of search in the string.
592 592
  */
593
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
594
-    if ( function_exists( 'mb_strpos' ) ) {
595
-        return mb_strpos( $str, $find, $offset, $encoding );
593
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
594
+    if (function_exists('mb_strpos')) {
595
+        return mb_strpos($str, $find, $offset, $encoding);
596 596
     }
597 597
         
598
-    return strpos( $str, $find, $offset );
598
+    return strpos($str, $find, $offset);
599 599
 }
600 600
 
601 601
 /**
@@ -609,12 +609,12 @@  discard block
 block discarded – undo
609 609
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
610 610
  * @return int Returns the position of the last occurrence of search.
611 611
  */
612
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
613
-    if ( function_exists( 'mb_strrpos' ) ) {
614
-        return mb_strrpos( $str, $find, $offset, $encoding );
612
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
613
+    if (function_exists('mb_strrpos')) {
614
+        return mb_strrpos($str, $find, $offset, $encoding);
615 615
     }
616 616
         
617
-    return strrpos( $str, $find, $offset );
617
+    return strrpos($str, $find, $offset);
618 618
 }
619 619
 
620 620
 /**
@@ -629,16 +629,16 @@  discard block
 block discarded – undo
629 629
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
630 630
  * @return string
631 631
  */
632
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
633
-    if ( function_exists( 'mb_substr' ) ) {
634
-        if ( $length === null ) {
635
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
632
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
633
+    if (function_exists('mb_substr')) {
634
+        if ($length === null) {
635
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
636 636
         } else {
637
-            return mb_substr( $str, $start, $length, $encoding );
637
+            return mb_substr($str, $start, $length, $encoding);
638 638
         }
639 639
     }
640 640
         
641
-    return substr( $str, $start, $length );
641
+    return substr($str, $start, $length);
642 642
 }
643 643
 
644 644
 /**
@@ -650,48 +650,48 @@  discard block
 block discarded – undo
650 650
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
651 651
  * @return string The width of string.
652 652
  */
653
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
654
-    if ( function_exists( 'mb_strwidth' ) ) {
655
-        return mb_strwidth( $str, $encoding );
653
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
654
+    if (function_exists('mb_strwidth')) {
655
+        return mb_strwidth($str, $encoding);
656 656
     }
657 657
     
658
-    return wpinv_utf8_strlen( $str, $encoding );
658
+    return wpinv_utf8_strlen($str, $encoding);
659 659
 }
660 660
 
661
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
662
-    if ( function_exists( 'mb_strlen' ) ) {
663
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
661
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
662
+    if (function_exists('mb_strlen')) {
663
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
664 664
         $str_end = "";
665 665
         
666
-        if ( $lower_str_end ) {
667
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
666
+        if ($lower_str_end) {
667
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
668 668
         } else {
669
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
669
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
670 670
         }
671 671
 
672 672
         return $first_letter . $str_end;
673 673
     }
674 674
     
675
-    return ucfirst( $str );
675
+    return ucfirst($str);
676 676
 }
677 677
 
678
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
679
-    if ( function_exists( 'mb_convert_case' ) ) {
680
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
678
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
679
+    if (function_exists('mb_convert_case')) {
680
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
681 681
     }
682 682
     
683
-    return ucwords( $str );
683
+    return ucwords($str);
684 684
 }
685 685
 
686
-function wpinv_period_in_days( $period, $unit ) {
687
-    $period = absint( $period );
686
+function wpinv_period_in_days($period, $unit) {
687
+    $period = absint($period);
688 688
     
689
-    if ( $period > 0 ) {
690
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
689
+    if ($period > 0) {
690
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
691 691
             $period = $period * 7;
692
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
692
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
693 693
             $period = $period * 30;
694
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
694
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
695 695
             $period = $period * 365;
696 696
         }
697 697
     }
Please login to merge, or discard this patch.
includes/wpinv-email-functions.php 1 patch
Spacing   +507 added lines, -507 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
 function wpinv_init_transactional_emails() {
15
-    $email_actions = apply_filters( 'wpinv_email_actions', array(
15
+    $email_actions = apply_filters('wpinv_email_actions', array(
16 16
         'wpinv_status_pending_to_processing',
17 17
         'wpinv_status_pending_to_publish',
18 18
         'wpinv_status_pending_to_cancelled',
@@ -28,79 +28,79 @@  discard block
 block discarded – undo
28 28
         'wpinv_fully_refunded',
29 29
         'wpinv_partially_refunded',
30 30
         'wpinv_new_invoice_note'
31
-    ) );
31
+    ));
32 32
 
33
-    foreach ( $email_actions as $action ) {
34
-        add_action( $action, 'wpinv_send_transactional_email', 10, 10 );
33
+    foreach ($email_actions as $action) {
34
+        add_action($action, 'wpinv_send_transactional_email', 10, 10);
35 35
     }
36 36
 }
37
-add_action( 'init', 'wpinv_init_transactional_emails' );
37
+add_action('init', 'wpinv_init_transactional_emails');
38 38
 
39 39
 // New invoice email
40
-add_action( 'wpinv_status_pending_to_processing_notification', 'wpinv_new_invoice_notification' );
41
-add_action( 'wpinv_status_pending_to_publish_notification', 'wpinv_new_invoice_notification' );
42
-add_action( 'wpinv_status_pending_to_onhold_notification', 'wpinv_new_invoice_notification' );
43
-add_action( 'wpinv_status_failed_to_processing_notification', 'wpinv_new_invoice_notification' );
44
-add_action( 'wpinv_status_failed_to_publish_notification', 'wpinv_new_invoice_notification' );
45
-add_action( 'wpinv_status_failed_to_onhold_notification', 'wpinv_new_invoice_notification' );
40
+add_action('wpinv_status_pending_to_processing_notification', 'wpinv_new_invoice_notification');
41
+add_action('wpinv_status_pending_to_publish_notification', 'wpinv_new_invoice_notification');
42
+add_action('wpinv_status_pending_to_onhold_notification', 'wpinv_new_invoice_notification');
43
+add_action('wpinv_status_failed_to_processing_notification', 'wpinv_new_invoice_notification');
44
+add_action('wpinv_status_failed_to_publish_notification', 'wpinv_new_invoice_notification');
45
+add_action('wpinv_status_failed_to_onhold_notification', 'wpinv_new_invoice_notification');
46 46
 
47 47
 // Cancelled invoice email
48
-add_action( 'wpinv_status_pending_to_cancelled_notification', 'wpinv_cancelled_invoice_notification' );
49
-add_action( 'wpinv_status_onhold_to_cancelled_notification', 'wpinv_cancelled_invoice_notification' );
48
+add_action('wpinv_status_pending_to_cancelled_notification', 'wpinv_cancelled_invoice_notification');
49
+add_action('wpinv_status_onhold_to_cancelled_notification', 'wpinv_cancelled_invoice_notification');
50 50
 
51 51
 // Failed invoice email
52
-add_action( 'wpinv_status_pending_to_failed_notification', 'wpinv_failed_invoice_notification' );
53
-add_action( 'wpinv_status_onhold_to_failed_notification', 'wpinv_failed_invoice_notification' );
52
+add_action('wpinv_status_pending_to_failed_notification', 'wpinv_failed_invoice_notification');
53
+add_action('wpinv_status_onhold_to_failed_notification', 'wpinv_failed_invoice_notification');
54 54
 
55 55
 // On hold invoice email
56
-add_action( 'wpinv_status_pending_to_onhold_notification', 'wpinv_onhold_invoice_notification' );
57
-add_action( 'wpinv_status_failed_to_onhold_notification', 'wpinv_onhold_invoice_notification' );
56
+add_action('wpinv_status_pending_to_onhold_notification', 'wpinv_onhold_invoice_notification');
57
+add_action('wpinv_status_failed_to_onhold_notification', 'wpinv_onhold_invoice_notification');
58 58
 
59 59
 // Processing invoice email
60
-add_action( 'wpinv_status_pending_to_processing_notification', 'wpinv_processing_invoice_notification' );
60
+add_action('wpinv_status_pending_to_processing_notification', 'wpinv_processing_invoice_notification');
61 61
 
62 62
 // Paid invoice email
63
-add_action( 'wpinv_status_publish_notification', 'wpinv_completed_invoice_notification' );
63
+add_action('wpinv_status_publish_notification', 'wpinv_completed_invoice_notification');
64 64
 
65 65
 // Refunded invoice email
66
-add_action( 'wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification' );
67
-add_action( 'wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification' );
66
+add_action('wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification');
67
+add_action('wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification');
68 68
 
69 69
 // Invoice note
70
-add_action( 'wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification' );
70
+add_action('wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification');
71 71
 
72
-add_action( 'wpinv_email_header', 'wpinv_email_header' );
73
-add_action( 'wpinv_email_footer', 'wpinv_email_footer' );
74
-add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 );
75
-add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 );
76
-add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 );
77
-add_action( 'wpinv_email_before_note_details', 'wpinv_email_before_note_details', 10, 4 );
72
+add_action('wpinv_email_header', 'wpinv_email_header');
73
+add_action('wpinv_email_footer', 'wpinv_email_footer');
74
+add_action('wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3);
75
+add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3);
76
+add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3);
77
+add_action('wpinv_email_before_note_details', 'wpinv_email_before_note_details', 10, 4);
78 78
 
79 79
 function wpinv_send_transactional_email() {
80 80
     $args       = func_get_args();
81 81
     $function   = current_filter() . '_notification';
82
-    do_action_ref_array( $function, $args );
82
+    do_action_ref_array($function, $args);
83 83
 }
84 84
     
85
-function wpinv_new_invoice_notification( $invoice_id, $new_status = '' ) {
85
+function wpinv_new_invoice_notification($invoice_id, $new_status = '') {
86 86
     global $wpinv_email_search, $wpinv_email_replace;
87 87
     
88 88
     $email_type = 'new_invoice';
89
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
89
+    if (!wpinv_email_is_enabled($email_type)) {
90 90
         return false;
91 91
     }
92 92
     
93
-    $invoice = wpinv_get_invoice( $invoice_id );
94
-    if ( empty( $invoice ) ) {
93
+    $invoice = wpinv_get_invoice($invoice_id);
94
+    if (empty($invoice)) {
95 95
         return false;
96 96
     }
97 97
 
98
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
98
+    if (!("wpi_invoice" === $invoice->post_type)) {
99 99
         return false;
100 100
     }
101 101
     
102
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
103
-    if ( !is_email( $recipient ) ) {
102
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
103
+    if (!is_email($recipient)) {
104 104
         return false;
105 105
     }
106 106
         
@@ -117,41 +117,41 @@  discard block
 block discarded – undo
117 117
     $wpinv_email_search     = $search;
118 118
     $wpinv_email_replace    = $replace;
119 119
     
120
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
121
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
122
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
123
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
120
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
121
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
122
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
123
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
124 124
     
125
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
125
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
126 126
             'invoice'       => $invoice,
127 127
             'email_type'    => $email_type,
128 128
             'email_heading' => $email_heading,
129 129
             'sent_to_admin' => true,
130 130
             'plain_text'    => false,
131
-        ) );
131
+        ));
132 132
     
133
-    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
133
+    return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
134 134
 }
135 135
 
136
-function wpinv_cancelled_invoice_notification( $invoice_id, $new_status = '' ) {
136
+function wpinv_cancelled_invoice_notification($invoice_id, $new_status = '') {
137 137
     global $wpinv_email_search, $wpinv_email_replace;
138 138
     
139 139
     $email_type = 'cancelled_invoice';
140
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
140
+    if (!wpinv_email_is_enabled($email_type)) {
141 141
         return false;
142 142
     }
143 143
     
144
-    $invoice = wpinv_get_invoice( $invoice_id );
145
-    if ( empty( $invoice ) ) {
144
+    $invoice = wpinv_get_invoice($invoice_id);
145
+    if (empty($invoice)) {
146 146
         return false;
147 147
     }
148 148
 
149
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
149
+    if (!("wpi_invoice" === $invoice->post_type)) {
150 150
         return false;
151 151
     }
152 152
     
153
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
154
-    if ( !is_email( $recipient ) ) {
153
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
154
+    if (!is_email($recipient)) {
155 155
         return false;
156 156
     }
157 157
         
@@ -168,41 +168,41 @@  discard block
 block discarded – undo
168 168
     $wpinv_email_search     = $search;
169 169
     $wpinv_email_replace    = $replace;
170 170
     
171
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
172
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
173
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
174
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
171
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
172
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
173
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
174
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
175 175
     
176
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
176
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
177 177
             'invoice'       => $invoice,
178 178
             'email_type'    => $email_type,
179 179
             'email_heading' => $email_heading,
180 180
             'sent_to_admin' => true,
181 181
             'plain_text'    => false,
182
-        ) );
182
+        ));
183 183
     
184
-    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
184
+    return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
185 185
 }
186 186
 
187
-function wpinv_failed_invoice_notification( $invoice_id, $new_status = '' ) {
187
+function wpinv_failed_invoice_notification($invoice_id, $new_status = '') {
188 188
     global $wpinv_email_search, $wpinv_email_replace;
189 189
     
190 190
     $email_type = 'failed_invoice';
191
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
191
+    if (!wpinv_email_is_enabled($email_type)) {
192 192
         return false;
193 193
     }
194 194
     
195
-    $invoice = wpinv_get_invoice( $invoice_id );
196
-    if ( empty( $invoice ) ) {
195
+    $invoice = wpinv_get_invoice($invoice_id);
196
+    if (empty($invoice)) {
197 197
         return false;
198 198
     }
199 199
 
200
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
200
+    if (!("wpi_invoice" === $invoice->post_type)) {
201 201
         return false;
202 202
     }
203 203
     
204
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
205
-    if ( !is_email( $recipient ) ) {
204
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
205
+    if (!is_email($recipient)) {
206 206
         return false;
207 207
     }
208 208
         
@@ -219,41 +219,41 @@  discard block
 block discarded – undo
219 219
     $wpinv_email_search     = $search;
220 220
     $wpinv_email_replace    = $replace;
221 221
     
222
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
223
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
224
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
225
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
222
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
223
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
224
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
225
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
226 226
     
227
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
227
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
228 228
             'invoice'       => $invoice,
229 229
             'email_type'    => $email_type,
230 230
             'email_heading' => $email_heading,
231 231
             'sent_to_admin' => true,
232 232
             'plain_text'    => false,
233
-        ) );
233
+        ));
234 234
     
235
-    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
235
+    return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
236 236
 }
237 237
 
238
-function wpinv_onhold_invoice_notification( $invoice_id, $new_status = '' ) {
238
+function wpinv_onhold_invoice_notification($invoice_id, $new_status = '') {
239 239
     global $wpinv_email_search, $wpinv_email_replace;
240 240
     
241 241
     $email_type = 'onhold_invoice';
242
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
242
+    if (!wpinv_email_is_enabled($email_type)) {
243 243
         return false;
244 244
     }
245 245
     
246
-    $invoice = wpinv_get_invoice( $invoice_id );
247
-    if ( empty( $invoice ) ) {
246
+    $invoice = wpinv_get_invoice($invoice_id);
247
+    if (empty($invoice)) {
248 248
         return false;
249 249
     }
250 250
 
251
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
251
+    if (!("wpi_invoice" === $invoice->post_type)) {
252 252
         return false;
253 253
     }
254 254
     
255
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
256
-    if ( !is_email( $recipient ) ) {
255
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
256
+    if (!is_email($recipient)) {
257 257
         return false;
258 258
     }
259 259
         
@@ -270,49 +270,49 @@  discard block
 block discarded – undo
270 270
     $wpinv_email_search     = $search;
271 271
     $wpinv_email_replace    = $replace;
272 272
     
273
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
274
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
275
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
276
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
273
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
274
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
275
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
276
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
277 277
     
278
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
278
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
279 279
             'invoice'       => $invoice,
280 280
             'email_type'    => $email_type,
281 281
             'email_heading' => $email_heading,
282 282
             'sent_to_admin' => false,
283 283
             'plain_text'    => false,
284
-        ) );
284
+        ));
285 285
     
286
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
286
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
287 287
     
288
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
289
-        $recipient  = wpinv_get_admin_email();
290
-        $subject    .= ' - ADMIN BCC COPY';
291
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
288
+    if (wpinv_mail_admin_bcc_active($email_type)) {
289
+        $recipient = wpinv_get_admin_email();
290
+        $subject .= ' - ADMIN BCC COPY';
291
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
292 292
     }
293 293
     
294 294
     return $sent;
295 295
 }
296 296
 
297
-function wpinv_processing_invoice_notification( $invoice_id, $new_status = '' ) {
297
+function wpinv_processing_invoice_notification($invoice_id, $new_status = '') {
298 298
     global $wpinv_email_search, $wpinv_email_replace;
299 299
     
300 300
     $email_type = 'processing_invoice';
301
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
301
+    if (!wpinv_email_is_enabled($email_type)) {
302 302
         return false;
303 303
     }
304 304
     
305
-    $invoice = wpinv_get_invoice( $invoice_id );
306
-    if ( empty( $invoice ) ) {
305
+    $invoice = wpinv_get_invoice($invoice_id);
306
+    if (empty($invoice)) {
307 307
         return false;
308 308
     }
309 309
 
310
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
310
+    if (!("wpi_invoice" === $invoice->post_type)) {
311 311
         return false;
312 312
     }
313 313
     
314
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
315
-    if ( !is_email( $recipient ) ) {
314
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
315
+    if (!is_email($recipient)) {
316 316
         return false;
317 317
     }
318 318
         
@@ -329,49 +329,49 @@  discard block
 block discarded – undo
329 329
     $wpinv_email_search     = $search;
330 330
     $wpinv_email_replace    = $replace;
331 331
     
332
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
333
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
334
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
335
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
332
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
333
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
334
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
335
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
336 336
     
337
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
337
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
338 338
             'invoice'       => $invoice,
339 339
             'email_type'    => $email_type,
340 340
             'email_heading' => $email_heading,
341 341
             'sent_to_admin' => false,
342 342
             'plain_text'    => false,
343
-        ) );
343
+        ));
344 344
     
345
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
345
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
346 346
     
347
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
348
-        $recipient  = wpinv_get_admin_email();
349
-        $subject    .= ' - ADMIN BCC COPY';
350
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
347
+    if (wpinv_mail_admin_bcc_active($email_type)) {
348
+        $recipient = wpinv_get_admin_email();
349
+        $subject .= ' - ADMIN BCC COPY';
350
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
351 351
     }
352 352
     
353 353
     return $sent;
354 354
 }
355 355
 
356
-function wpinv_completed_invoice_notification( $invoice_id, $new_status = '' ) {
356
+function wpinv_completed_invoice_notification($invoice_id, $new_status = '') {
357 357
     global $wpinv_email_search, $wpinv_email_replace;
358 358
     
359 359
     $email_type = 'completed_invoice';
360
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
360
+    if (!wpinv_email_is_enabled($email_type)) {
361 361
         return false;
362 362
     }
363 363
     
364
-    $invoice = wpinv_get_invoice( $invoice_id );
365
-    if ( empty( $invoice ) ) {
364
+    $invoice = wpinv_get_invoice($invoice_id);
365
+    if (empty($invoice)) {
366 366
         return false;
367 367
     }
368 368
 
369
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
369
+    if (!("wpi_invoice" === $invoice->post_type)) {
370 370
         return false;
371 371
     }
372 372
     
373
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
374
-    if ( !is_email( $recipient ) ) {
373
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
374
+    if (!is_email($recipient)) {
375 375
         return false;
376 376
     }
377 377
         
@@ -388,49 +388,49 @@  discard block
 block discarded – undo
388 388
     $wpinv_email_search     = $search;
389 389
     $wpinv_email_replace    = $replace;
390 390
     
391
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
392
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
393
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
394
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
391
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
392
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
393
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
394
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
395 395
     
396
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
396
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
397 397
             'invoice'       => $invoice,
398 398
             'email_type'    => $email_type,
399 399
             'email_heading' => $email_heading,
400 400
             'sent_to_admin' => false,
401 401
             'plain_text'    => false,
402
-        ) );
402
+        ));
403 403
     
404
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
404
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
405 405
     
406
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
407
-        $recipient  = wpinv_get_admin_email();
408
-        $subject    .= ' - ADMIN BCC COPY';
409
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
406
+    if (wpinv_mail_admin_bcc_active($email_type)) {
407
+        $recipient = wpinv_get_admin_email();
408
+        $subject .= ' - ADMIN BCC COPY';
409
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
410 410
     }
411 411
     
412 412
     return $sent;
413 413
 }
414 414
 
415
-function wpinv_fully_refunded_notification( $invoice_id, $new_status = '' ) {
415
+function wpinv_fully_refunded_notification($invoice_id, $new_status = '') {
416 416
     global $wpinv_email_search, $wpinv_email_replace;
417 417
     
418 418
     $email_type = 'refunded_invoice';
419
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
419
+    if (!wpinv_email_is_enabled($email_type)) {
420 420
         return false;
421 421
     }
422 422
     
423
-    $invoice = wpinv_get_invoice( $invoice_id );
424
-    if ( empty( $invoice ) ) {
423
+    $invoice = wpinv_get_invoice($invoice_id);
424
+    if (empty($invoice)) {
425 425
         return false;
426 426
     }
427 427
 
428
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
428
+    if (!("wpi_invoice" === $invoice->post_type)) {
429 429
         return false;
430 430
     }
431 431
     
432
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
433
-    if ( !is_email( $recipient ) ) {
432
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
433
+    if (!is_email($recipient)) {
434 434
         return false;
435 435
     }
436 436
         
@@ -447,50 +447,50 @@  discard block
 block discarded – undo
447 447
     $wpinv_email_search     = $search;
448 448
     $wpinv_email_replace    = $replace;
449 449
     
450
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
451
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
452
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
453
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
450
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
451
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
452
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
453
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
454 454
     
455
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
455
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
456 456
             'invoice'           => $invoice,
457 457
             'email_type'        => $email_type,
458 458
             'email_heading'     => $email_heading,
459 459
             'sent_to_admin'     => false,
460 460
             'plain_text'        => false,
461 461
             'partial_refund'    => false
462
-        ) );
462
+        ));
463 463
     
464
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
464
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
465 465
     
466
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
467
-        $recipient  = wpinv_get_admin_email();
468
-        $subject    .= ' - ADMIN BCC COPY';
469
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
466
+    if (wpinv_mail_admin_bcc_active($email_type)) {
467
+        $recipient = wpinv_get_admin_email();
468
+        $subject .= ' - ADMIN BCC COPY';
469
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
470 470
     }
471 471
     
472 472
     return $sent;
473 473
 }
474 474
 
475
-function wpinv_partially_refunded_notification( $invoice_id, $new_status = '' ) {
475
+function wpinv_partially_refunded_notification($invoice_id, $new_status = '') {
476 476
     global $wpinv_email_search, $wpinv_email_replace;
477 477
     
478 478
     $email_type = 'refunded_invoice';
479
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
479
+    if (!wpinv_email_is_enabled($email_type)) {
480 480
         return false;
481 481
     }
482 482
     
483
-    $invoice = wpinv_get_invoice( $invoice_id );
484
-    if ( empty( $invoice ) ) {
483
+    $invoice = wpinv_get_invoice($invoice_id);
484
+    if (empty($invoice)) {
485 485
         return false;
486 486
     }
487 487
 
488
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
488
+    if (!("wpi_invoice" === $invoice->post_type)) {
489 489
         return false;
490 490
     }
491 491
     
492
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
493
-    if ( !is_email( $recipient ) ) {
492
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
493
+    if (!is_email($recipient)) {
494 494
         return false;
495 495
     }
496 496
         
@@ -507,53 +507,53 @@  discard block
 block discarded – undo
507 507
     $wpinv_email_search     = $search;
508 508
     $wpinv_email_replace    = $replace;
509 509
     
510
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
511
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
512
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
513
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
510
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
511
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
512
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
513
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
514 514
     
515
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
515
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
516 516
             'invoice'           => $invoice,
517 517
             'email_type'        => $email_type,
518 518
             'email_heading'     => $email_heading,
519 519
             'sent_to_admin'     => false,
520 520
             'plain_text'        => false,
521 521
             'partial_refund'    => true
522
-        ) );
522
+        ));
523 523
     
524
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
524
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
525 525
     
526
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
527
-        $recipient  = wpinv_get_admin_email();
528
-        $subject    .= ' - ADMIN BCC COPY';
529
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
526
+    if (wpinv_mail_admin_bcc_active($email_type)) {
527
+        $recipient = wpinv_get_admin_email();
528
+        $subject .= ' - ADMIN BCC COPY';
529
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
530 530
     }
531 531
     
532 532
     return $sent;
533 533
 }
534 534
 
535
-function wpinv_new_invoice_note_notification( $invoice_id, $new_status = '' ) {
535
+function wpinv_new_invoice_note_notification($invoice_id, $new_status = '') {
536 536
 }
537 537
 
538
-function wpinv_user_invoice_notification( $invoice_id ) {
538
+function wpinv_user_invoice_notification($invoice_id) {
539 539
     global $wpinv_email_search, $wpinv_email_replace;
540 540
     
541 541
     $email_type = 'user_invoice';
542
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
542
+    if (!wpinv_email_is_enabled($email_type)) {
543 543
         return false;
544 544
     }
545 545
     
546
-    $invoice = wpinv_get_invoice( $invoice_id );
547
-    if ( empty( $invoice ) ) {
546
+    $invoice = wpinv_get_invoice($invoice_id);
547
+    if (empty($invoice)) {
548 548
         return false;
549 549
     }
550 550
 
551
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
551
+    if (!("wpi_invoice" === $invoice->post_type)) {
552 552
         return false;
553 553
     }
554 554
     
555
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
556
-    if ( !is_email( $recipient ) ) {
555
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
556
+    if (!is_email($recipient)) {
557 557
         return false;
558 558
     }
559 559
         
@@ -570,52 +570,52 @@  discard block
 block discarded – undo
570 570
     $wpinv_email_search     = $search;
571 571
     $wpinv_email_replace    = $replace;
572 572
     
573
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
574
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
575
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
576
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
573
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
574
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
575
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
576
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
577 577
     
578
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
578
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
579 579
             'invoice'       => $invoice,
580 580
             'email_type'    => $email_type,
581 581
             'email_heading' => $email_heading,
582 582
             'sent_to_admin' => false,
583 583
             'plain_text'    => false,
584
-        ) );
584
+        ));
585 585
     
586
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
586
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
587 587
     
588
-    if ( $sent ) {
589
-        $note = __( 'Invoice has been emailed to the user.', 'invoicing' );
588
+    if ($sent) {
589
+        $note = __('Invoice has been emailed to the user.', 'invoicing');
590 590
     } else {
591
-        $note = __( 'Fail to send invoice to the user!', 'invoicing' );
591
+        $note = __('Fail to send invoice to the user!', 'invoicing');
592 592
     }
593
-    $invoice->add_note( $note ); // Add private note.
593
+    $invoice->add_note($note); // Add private note.
594 594
     
595
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
596
-        $recipient  = wpinv_get_admin_email();
597
-        $subject    .= ' - ADMIN BCC COPY';
598
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
595
+    if (wpinv_mail_admin_bcc_active($email_type)) {
596
+        $recipient = wpinv_get_admin_email();
597
+        $subject .= ' - ADMIN BCC COPY';
598
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
599 599
     }
600 600
     
601 601
     return $sent;
602 602
 }
603 603
 
604
-function wpinv_user_note_notification( $invoice_id, $args = array() ) {
604
+function wpinv_user_note_notification($invoice_id, $args = array()) {
605 605
     global $wpinv_email_search, $wpinv_email_replace;
606 606
     
607 607
     $email_type = 'user_note';
608
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
608
+    if (!wpinv_email_is_enabled($email_type)) {
609 609
         return false;
610 610
     }
611 611
     
612
-    $invoice = wpinv_get_invoice( $invoice_id );
613
-    if ( empty( $invoice ) ) {
612
+    $invoice = wpinv_get_invoice($invoice_id);
613
+    if (empty($invoice)) {
614 614
         return false;
615 615
     }
616 616
     
617
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
618
-    if ( !is_email( $recipient ) ) {
617
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
618
+    if (!is_email($recipient)) {
619 619
         return false;
620 620
     }
621 621
     
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
         'user_note' => ''
624 624
     );
625 625
 
626
-    $args = wp_parse_args( $args, $defaults );
626
+    $args = wp_parse_args($args, $defaults);
627 627
         
628 628
     $search                     = array();
629 629
     $search['invoice_number']   = '{invoice_number}';
@@ -642,46 +642,46 @@  discard block
 block discarded – undo
642 642
     $wpinv_email_search     = $search;
643 643
     $wpinv_email_replace    = $replace;
644 644
     
645
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
646
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
647
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
648
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
645
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
646
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
647
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
648
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
649 649
     
650
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
650
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
651 651
             'invoice'       => $invoice,
652 652
             'email_type'    => $email_type,
653 653
             'email_heading' => $email_heading,
654 654
             'sent_to_admin' => false,
655 655
             'plain_text'    => false,
656 656
             'customer_note' => $args['user_note']
657
-        ) );
657
+        ));
658 658
         
659
-    $content        = wpinv_email_format_text( $content );
659
+    $content = wpinv_email_format_text($content);
660 660
     
661
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
661
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
662 662
         
663 663
     return $sent;
664 664
 }
665 665
 
666 666
 function wpinv_mail_get_from_address() {
667
-    $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) );
668
-    return sanitize_email( $from_address );
667
+    $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from'));
668
+    return sanitize_email($from_address);
669 669
 }
670 670
 
671 671
 function wpinv_mail_get_from_name() {
672
-    $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name' ) );
673
-    return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES );
672
+    $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name'));
673
+    return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES);
674 674
 }
675 675
 
676
-function wpinv_mail_admin_bcc_active( $mail_type = '' ) {
677
-    $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) );
678
-    return ( $active ? true : false );
676
+function wpinv_mail_admin_bcc_active($mail_type = '') {
677
+    $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc'));
678
+    return ($active ? true : false);
679 679
 }
680 680
     
681
-function wpinv_mail_get_content_type(  $content_type = 'text/html', $email_type = 'html' ) {
682
-    $email_type = apply_filters( 'wpinv_mail_content_type', $email_type );
681
+function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') {
682
+    $email_type = apply_filters('wpinv_mail_content_type', $email_type);
683 683
     
684
-    switch ( $email_type ) {
684
+    switch ($email_type) {
685 685
         case 'html' :
686 686
             $content_type = 'text/html';
687 687
             break;
@@ -696,35 +696,35 @@  discard block
 block discarded – undo
696 696
     return $content_type;
697 697
 }
698 698
     
699
-function wpinv_mail_send( $to, $subject, $message, $headers, $attachments ) {
700
-    add_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
701
-    add_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
702
-    add_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
699
+function wpinv_mail_send($to, $subject, $message, $headers, $attachments) {
700
+    add_filter('wp_mail_from', 'wpinv_mail_get_from_address');
701
+    add_filter('wp_mail_from_name', 'wpinv_mail_get_from_name');
702
+    add_filter('wp_mail_content_type', 'wpinv_mail_get_content_type');
703 703
 
704
-    $message = wpinv_email_style_body( $message );
705
-    $message = apply_filters( 'wpinv_mail_content', $message );
704
+    $message = wpinv_email_style_body($message);
705
+    $message = apply_filters('wpinv_mail_content', $message);
706 706
     
707
-    $sent  = wp_mail( $to, $subject, $message, $headers, $attachments );
707
+    $sent = wp_mail($to, $subject, $message, $headers, $attachments);
708 708
     
709
-    if ( !$sent ) {
710
-        $log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), ( is_array( $to ) ? implode( ', ', $to ) : $to ), $subject );
711
-        wpinv_error_log( $log_message, __( "Email from Invoicing plugin failed to send", 'invoicing' ), __FILE__, __LINE__ );
709
+    if (!$sent) {
710
+        $log_message = wp_sprintf(__("\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing'), date_i18n('F j Y H:i:s', current_time('timestamp')), (is_array($to) ? implode(', ', $to) : $to), $subject);
711
+        wpinv_error_log($log_message, __("Email from Invoicing plugin failed to send", 'invoicing'), __FILE__, __LINE__);
712 712
     }
713 713
 
714
-    remove_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
715
-    remove_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
716
-    remove_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
714
+    remove_filter('wp_mail_from', 'wpinv_mail_get_from_address');
715
+    remove_filter('wp_mail_from_name', 'wpinv_mail_get_from_name');
716
+    remove_filter('wp_mail_content_type', 'wpinv_mail_get_content_type');
717 717
 
718 718
     return $sent;
719 719
 }
720 720
     
721 721
 function wpinv_get_emails() {
722 722
     $overdue_days_options       = array();
723
-    $overdue_days_options[0]    = __( 'On the Due Date', 'invoicing' );
724
-    $overdue_days_options[1]    = __( '1 day after Due Date', 'invoicing' );
723
+    $overdue_days_options[0]    = __('On the Due Date', 'invoicing');
724
+    $overdue_days_options[1]    = __('1 day after Due Date', 'invoicing');
725 725
     
726
-    for ( $i = 2; $i <= 10; $i++ ) {
727
-        $overdue_days_options[$i]   = wp_sprintf( __( '%d days after Due Date', 'invoicing' ), $i );
726
+    for ($i = 2; $i <= 10; $i++) {
727
+        $overdue_days_options[$i] = wp_sprintf(__('%d days after Due Date', 'invoicing'), $i);
728 728
     }
729 729
 
730 730
 	// Default, built-in gateways
@@ -732,130 +732,130 @@  discard block
 block discarded – undo
732 732
             'new_invoice' => array(
733 733
             'email_new_invoice_header' => array(
734 734
                 'id'   => 'email_new_invoice_header',
735
-                'name' => '<h3>' . __( 'New Invoice', 'invoicing' ) . '</h3>',
736
-                'desc' => __( 'New invoice emails are sent to admin when a new invoice is received.', 'invoicing' ),
735
+                'name' => '<h3>' . __('New Invoice', 'invoicing') . '</h3>',
736
+                'desc' => __('New invoice emails are sent to admin when a new invoice is received.', 'invoicing'),
737 737
                 'type' => 'header',
738 738
             ),
739 739
             'email_new_invoice_active' => array(
740 740
                 'id'   => 'email_new_invoice_active',
741
-                'name' => __( 'Enable/Disable', 'invoicing' ),
742
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
741
+                'name' => __('Enable/Disable', 'invoicing'),
742
+                'desc' => __('Enable this email notification', 'invoicing'),
743 743
                 'type' => 'checkbox',
744 744
                 'std'  => 1
745 745
             ),
746 746
             'email_new_invoice_subject' => array(
747 747
                 'id'   => 'email_new_invoice_subject',
748
-                'name' => __( 'Subject', 'invoicing' ),
749
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
748
+                'name' => __('Subject', 'invoicing'),
749
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
750 750
                 'type' => 'text',
751
-                'std'  => __( '[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing' ),
751
+                'std'  => __('[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing'),
752 752
                 'size' => 'large'
753 753
             ),
754 754
             'email_new_invoice_heading' => array(
755 755
                 'id'   => 'email_new_invoice_heading',
756
-                'name' => __( 'Email Heading', 'invoicing' ),
757
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
756
+                'name' => __('Email Heading', 'invoicing'),
757
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
758 758
                 'type' => 'text',
759
-                'std'  => __( 'New payment invoice', 'invoicing' ),
759
+                'std'  => __('New payment invoice', 'invoicing'),
760 760
                 'size' => 'large'
761 761
             ),
762 762
         ),
763 763
         'cancelled_invoice' => array(
764 764
             'email_cancelled_invoice_header' => array(
765 765
                 'id'   => 'email_cancelled_invoice_header',
766
-                'name' => '<h3>' . __( 'Cancelled Invoice', 'invoicing' ) . '</h3>',
767
-                'desc' => __( 'Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing' ),
766
+                'name' => '<h3>' . __('Cancelled Invoice', 'invoicing') . '</h3>',
767
+                'desc' => __('Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing'),
768 768
                 'type' => 'header',
769 769
             ),
770 770
             'email_cancelled_invoice_active' => array(
771 771
                 'id'   => 'email_cancelled_invoice_active',
772
-                'name' => __( 'Enable/Disable', 'invoicing' ),
773
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
772
+                'name' => __('Enable/Disable', 'invoicing'),
773
+                'desc' => __('Enable this email notification', 'invoicing'),
774 774
                 'type' => 'checkbox',
775 775
                 'std'  => 1
776 776
             ),
777 777
             'email_cancelled_invoice_subject' => array(
778 778
                 'id'   => 'email_cancelled_invoice_subject',
779
-                'name' => __( 'Subject', 'invoicing' ),
780
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
779
+                'name' => __('Subject', 'invoicing'),
780
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
781 781
                 'type' => 'text',
782
-                'std'  => __( '[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing' ),
782
+                'std'  => __('[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing'),
783 783
                 'size' => 'large'
784 784
             ),
785 785
             'email_cancelled_invoice_heading' => array(
786 786
                 'id'   => 'email_cancelled_invoice_heading',
787
-                'name' => __( 'Email Heading', 'invoicing' ),
788
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
787
+                'name' => __('Email Heading', 'invoicing'),
788
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
789 789
                 'type' => 'text',
790
-                'std'  => __( 'Cancelled invoice', 'invoicing' ),
790
+                'std'  => __('Cancelled invoice', 'invoicing'),
791 791
                 'size' => 'large'
792 792
             ),
793 793
         ),
794 794
         'failed_invoice' => array(
795 795
             'email_failed_invoice_header' => array(
796 796
                 'id'   => 'email_failed_invoice_header',
797
-                'name' => '<h3>' . __( 'Failed Invoice', 'invoicing' ) . '</h3>',
798
-                'desc' => __( 'Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing' ),
797
+                'name' => '<h3>' . __('Failed Invoice', 'invoicing') . '</h3>',
798
+                'desc' => __('Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing'),
799 799
                 'type' => 'header',
800 800
             ),
801 801
             'email_failed_invoice_active' => array(
802 802
                 'id'   => 'email_failed_invoice_active',
803
-                'name' => __( 'Enable/Disable', 'invoicing' ),
804
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
803
+                'name' => __('Enable/Disable', 'invoicing'),
804
+                'desc' => __('Enable this email notification', 'invoicing'),
805 805
                 'type' => 'checkbox',
806 806
                 'std'  => 1
807 807
             ),
808 808
             'email_failed_invoice_subject' => array(
809 809
                 'id'   => 'email_failed_invoice_subject',
810
-                'name' => __( 'Subject', 'invoicing' ),
811
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
810
+                'name' => __('Subject', 'invoicing'),
811
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
812 812
                 'type' => 'text',
813
-                'std'  => __( '[{site_title}] Failed invoice ({invoice_number})', 'invoicing' ),
813
+                'std'  => __('[{site_title}] Failed invoice ({invoice_number})', 'invoicing'),
814 814
                 'size' => 'large'
815 815
             ),
816 816
             'email_failed_invoice_heading' => array(
817 817
                 'id'   => 'email_failed_invoice_heading',
818
-                'name' => __( 'Email Heading', 'invoicing' ),
819
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
818
+                'name' => __('Email Heading', 'invoicing'),
819
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
820 820
                 'type' => 'text',
821
-                'std'  => __( 'Failed invoice', 'invoicing' ),
821
+                'std'  => __('Failed invoice', 'invoicing'),
822 822
                 'size' => 'large'
823 823
             )
824 824
         ),
825 825
         'onhold_invoice' => array(
826 826
             'email_onhold_invoice_header' => array(
827 827
                 'id'   => 'email_onhold_invoice_header',
828
-                'name' => '<h3>' . __( 'On Hold Invoice', 'invoicing' ) . '</h3>',
829
-                'desc' => __( 'This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing' ),
828
+                'name' => '<h3>' . __('On Hold Invoice', 'invoicing') . '</h3>',
829
+                'desc' => __('This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing'),
830 830
                 'type' => 'header',
831 831
             ),
832 832
             'email_onhold_invoice_active' => array(
833 833
                 'id'   => 'email_onhold_invoice_active',
834
-                'name' => __( 'Enable/Disable', 'invoicing' ),
835
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
834
+                'name' => __('Enable/Disable', 'invoicing'),
835
+                'desc' => __('Enable this email notification', 'invoicing'),
836 836
                 'type' => 'checkbox',
837 837
                 'std'  => 1
838 838
             ),
839 839
             'email_onhold_invoice_subject' => array(
840 840
                 'id'   => 'email_onhold_invoice_subject',
841
-                'name' => __( 'Subject', 'invoicing' ),
842
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
841
+                'name' => __('Subject', 'invoicing'),
842
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
843 843
                 'type' => 'text',
844
-                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
844
+                'std'  => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'),
845 845
                 'size' => 'large'
846 846
             ),
847 847
             'email_onhold_invoice_heading' => array(
848 848
                 'id'   => 'email_onhold_invoice_heading',
849
-                'name' => __( 'Email Heading', 'invoicing' ),
850
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
849
+                'name' => __('Email Heading', 'invoicing'),
850
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
851 851
                 'type' => 'text',
852
-                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
852
+                'std'  => __('Thank you for your invoice', 'invoicing'),
853 853
                 'size' => 'large'
854 854
             ),
855 855
             'email_onhold_invoice_admin_bcc' => array(
856 856
                 'id'   => 'email_onhold_invoice_admin_bcc',
857
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
858
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
857
+                'name' => __('Enable Admin BCC', 'invoicing'),
858
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
859 859
                 'type' => 'checkbox',
860 860
                 'std'  => 1
861 861
             ),
@@ -863,37 +863,37 @@  discard block
 block discarded – undo
863 863
         'processing_invoice' => array(
864 864
             'email_processing_invoice_header' => array(
865 865
                 'id'   => 'email_processing_invoice_header',
866
-                'name' => '<h3>' . __( 'Processing Invoice', 'invoicing' ) . '</h3>',
867
-                'desc' => __( 'This is an invoice notification sent to users containing invoice details after payment.', 'invoicing' ),
866
+                'name' => '<h3>' . __('Processing Invoice', 'invoicing') . '</h3>',
867
+                'desc' => __('This is an invoice notification sent to users containing invoice details after payment.', 'invoicing'),
868 868
                 'type' => 'header',
869 869
             ),
870 870
             'email_processing_invoice_active' => array(
871 871
                 'id'   => 'email_processing_invoice_active',
872
-                'name' => __( 'Enable/Disable', 'invoicing' ),
873
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
872
+                'name' => __('Enable/Disable', 'invoicing'),
873
+                'desc' => __('Enable this email notification', 'invoicing'),
874 874
                 'type' => 'checkbox',
875 875
                 'std'  => 1
876 876
             ),
877 877
             'email_processing_invoice_subject' => array(
878 878
                 'id'   => 'email_processing_invoice_subject',
879
-                'name' => __( 'Subject', 'invoicing' ),
880
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
879
+                'name' => __('Subject', 'invoicing'),
880
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
881 881
                 'type' => 'text',
882
-                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
882
+                'std'  => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'),
883 883
                 'size' => 'large'
884 884
             ),
885 885
             'email_processing_invoice_heading' => array(
886 886
                 'id'   => 'email_processing_invoice_heading',
887
-                'name' => __( 'Email Heading', 'invoicing' ),
888
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
887
+                'name' => __('Email Heading', 'invoicing'),
888
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
889 889
                 'type' => 'text',
890
-                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
890
+                'std'  => __('Thank you for your invoice', 'invoicing'),
891 891
                 'size' => 'large'
892 892
             ),
893 893
             'email_processing_invoice_admin_bcc' => array(
894 894
                 'id'   => 'email_processing_invoice_admin_bcc',
895
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
896
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
895
+                'name' => __('Enable Admin BCC', 'invoicing'),
896
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
897 897
                 'type' => 'checkbox',
898 898
                 'std'  => 1
899 899
             ),
@@ -901,37 +901,37 @@  discard block
 block discarded – undo
901 901
         'completed_invoice' => array(
902 902
             'email_completed_invoice_header' => array(
903 903
                 'id'   => 'email_completed_invoice_header',
904
-                'name' => '<h3>' . __( 'Paid Invoice', 'invoicing' ) . '</h3>',
905
-                'desc' => __( 'Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing' ),
904
+                'name' => '<h3>' . __('Paid Invoice', 'invoicing') . '</h3>',
905
+                'desc' => __('Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing'),
906 906
                 'type' => 'header',
907 907
             ),
908 908
             'email_completed_invoice_active' => array(
909 909
                 'id'   => 'email_completed_invoice_active',
910
-                'name' => __( 'Enable/Disable', 'invoicing' ),
911
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
910
+                'name' => __('Enable/Disable', 'invoicing'),
911
+                'desc' => __('Enable this email notification', 'invoicing'),
912 912
                 'type' => 'checkbox',
913 913
                 'std'  => 1
914 914
             ),
915 915
             'email_completed_invoice_subject' => array(
916 916
                 'id'   => 'email_completed_invoice_subject',
917
-                'name' => __( 'Subject', 'invoicing' ),
918
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
917
+                'name' => __('Subject', 'invoicing'),
918
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
919 919
                 'type' => 'text',
920
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing' ),
920
+                'std'  => __('[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing'),
921 921
                 'size' => 'large'
922 922
             ),
923 923
             'email_completed_invoice_heading' => array(
924 924
                 'id'   => 'email_completed_invoice_heading',
925
-                'name' => __( 'Email Heading', 'invoicing' ),
926
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
925
+                'name' => __('Email Heading', 'invoicing'),
926
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
927 927
                 'type' => 'text',
928
-                'std'  => __( 'Your invoice has been paid', 'invoicing' ),
928
+                'std'  => __('Your invoice has been paid', 'invoicing'),
929 929
                 'size' => 'large'
930 930
             ),
931 931
             'email_completed_invoice_admin_bcc' => array(
932 932
                 'id'   => 'email_completed_invoice_admin_bcc',
933
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
934
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
933
+                'name' => __('Enable Admin BCC', 'invoicing'),
934
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
935 935
                 'type' => 'checkbox',
936 936
             ),
937 937
             'std'  => 1
@@ -939,37 +939,37 @@  discard block
 block discarded – undo
939 939
         'refunded_invoice' => array(
940 940
             'email_refunded_invoice_header' => array(
941 941
                 'id'   => 'email_refunded_invoice_header',
942
-                'name' => '<h3>' . __( 'Refunded Invoice', 'invoicing' ) . '</h3>',
943
-                'desc' => __( 'Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing' ),
942
+                'name' => '<h3>' . __('Refunded Invoice', 'invoicing') . '</h3>',
943
+                'desc' => __('Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing'),
944 944
                 'type' => 'header',
945 945
             ),
946 946
             'email_refunded_invoice_active' => array(
947 947
                 'id'   => 'email_refunded_invoice_active',
948
-                'name' => __( 'Enable/Disable', 'invoicing' ),
949
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
948
+                'name' => __('Enable/Disable', 'invoicing'),
949
+                'desc' => __('Enable this email notification', 'invoicing'),
950 950
                 'type' => 'checkbox',
951 951
                 'std'  => 1
952 952
             ),
953 953
             'email_refunded_invoice_subject' => array(
954 954
                 'id'   => 'email_refunded_invoice_subject',
955
-                'name' => __( 'Subject', 'invoicing' ),
956
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
955
+                'name' => __('Subject', 'invoicing'),
956
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
957 957
                 'type' => 'text',
958
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing' ),
958
+                'std'  => __('[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing'),
959 959
                 'size' => 'large'
960 960
             ),
961 961
             'email_refunded_invoice_heading' => array(
962 962
                 'id'   => 'email_refunded_invoice_heading',
963
-                'name' => __( 'Email Heading', 'invoicing' ),
964
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
963
+                'name' => __('Email Heading', 'invoicing'),
964
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
965 965
                 'type' => 'text',
966
-                'std'  => __( 'Your invoice has been refunded', 'invoicing' ),
966
+                'std'  => __('Your invoice has been refunded', 'invoicing'),
967 967
                 'size' => 'large'
968 968
             ),
969 969
             'email_refunded_invoice_admin_bcc' => array(
970 970
                 'id'   => 'email_refunded_invoice_admin_bcc',
971
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
972
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
971
+                'name' => __('Enable Admin BCC', 'invoicing'),
972
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
973 973
                 'type' => 'checkbox',
974 974
                 'std'  => 1
975 975
             ),
@@ -977,37 +977,37 @@  discard block
 block discarded – undo
977 977
         'user_invoice' => array(
978 978
             'email_user_invoice_header' => array(
979 979
                 'id'   => 'email_user_invoice_header',
980
-                'name' => '<h3>' . __( 'Customer Invoice', 'invoicing' ) . '</h3>',
981
-                'desc' => __( 'Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing' ),
980
+                'name' => '<h3>' . __('Customer Invoice', 'invoicing') . '</h3>',
981
+                'desc' => __('Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing'),
982 982
                 'type' => 'header',
983 983
             ),
984 984
             'email_user_invoice_active' => array(
985 985
                 'id'   => 'email_user_invoice_active',
986
-                'name' => __( 'Enable/Disable', 'invoicing' ),
987
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
986
+                'name' => __('Enable/Disable', 'invoicing'),
987
+                'desc' => __('Enable this email notification', 'invoicing'),
988 988
                 'type' => 'checkbox',
989 989
                 'std'  => 1
990 990
             ),
991 991
             'email_user_invoice_subject' => array(
992 992
                 'id'   => 'email_user_invoice_subject',
993
-                'name' => __( 'Subject', 'invoicing' ),
994
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
993
+                'name' => __('Subject', 'invoicing'),
994
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
995 995
                 'type' => 'text',
996
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date}', 'invoicing' ),
996
+                'std'  => __('[{site_title}] Your invoice from {invoice_date}', 'invoicing'),
997 997
                 'size' => 'large'
998 998
             ),
999 999
             'email_user_invoice_heading' => array(
1000 1000
                 'id'   => 'email_user_invoice_heading',
1001
-                'name' => __( 'Email Heading', 'invoicing' ),
1002
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
1001
+                'name' => __('Email Heading', 'invoicing'),
1002
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
1003 1003
                 'type' => 'text',
1004
-                'std'  => __( 'Your invoice {invoice_number} details', 'invoicing' ),
1004
+                'std'  => __('Your invoice {invoice_number} details', 'invoicing'),
1005 1005
                 'size' => 'large'
1006 1006
             ),
1007 1007
             'email_user_invoice_admin_bcc' => array(
1008 1008
                 'id'   => 'email_user_invoice_admin_bcc',
1009
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
1010
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
1009
+                'name' => __('Enable Admin BCC', 'invoicing'),
1010
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
1011 1011
                 'type' => 'checkbox',
1012 1012
                 'std'  => 1
1013 1013
             ),
@@ -1015,177 +1015,177 @@  discard block
 block discarded – undo
1015 1015
         'user_note' => array(
1016 1016
             'email_user_note_header' => array(
1017 1017
                 'id'   => 'email_user_note_header',
1018
-                'name' => '<h3>' . __( 'Customer Note', 'invoicing' ) . '</h3>',
1019
-                'desc' => __( 'Customer note emails are sent when you add a note to an invoice.', 'invoicing' ),
1018
+                'name' => '<h3>' . __('Customer Note', 'invoicing') . '</h3>',
1019
+                'desc' => __('Customer note emails are sent when you add a note to an invoice.', 'invoicing'),
1020 1020
                 'type' => 'header',
1021 1021
             ),
1022 1022
             'email_user_note_active' => array(
1023 1023
                 'id'   => 'email_user_note_active',
1024
-                'name' => __( 'Enable/Disable', 'invoicing' ),
1025
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
1024
+                'name' => __('Enable/Disable', 'invoicing'),
1025
+                'desc' => __('Enable this email notification', 'invoicing'),
1026 1026
                 'type' => 'checkbox',
1027 1027
                 'std'  => 1
1028 1028
             ),
1029 1029
             'email_user_note_subject' => array(
1030 1030
                 'id'   => 'email_user_note_subject',
1031
-                'name' => __( 'Subject', 'invoicing' ),
1032
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
1031
+                'name' => __('Subject', 'invoicing'),
1032
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
1033 1033
                 'type' => 'text',
1034
-                'std'  => __( '[{site_title}] Note added to your invoice #{invoice_number} from {invoice_date}', 'invoicing' ),
1034
+                'std'  => __('[{site_title}] Note added to your invoice #{invoice_number} from {invoice_date}', 'invoicing'),
1035 1035
                 'size' => 'large'
1036 1036
             ),
1037 1037
             'email_user_note_heading' => array(
1038 1038
                 'id'   => 'email_user_note_heading',
1039
-                'name' => __( 'Email Heading', 'invoicing' ),
1040
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
1039
+                'name' => __('Email Heading', 'invoicing'),
1040
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
1041 1041
                 'type' => 'text',
1042
-                'std'  => __( 'A note has been added to your invoice', 'invoicing' ),
1042
+                'std'  => __('A note has been added to your invoice', 'invoicing'),
1043 1043
                 'size' => 'large'
1044 1044
             ),
1045 1045
         ),
1046 1046
         'overdue' => array(
1047 1047
             'email_overdue_header' => array(
1048 1048
                 'id'   => 'email_overdue_header',
1049
-                'name' => '<h3>' . __( 'Payment Reminder', 'invoicing' ) . '</h3>',
1050
-                'desc' => __( 'Payment reminder emails are sent to user automatically.', 'invoicing' ),
1049
+                'name' => '<h3>' . __('Payment Reminder', 'invoicing') . '</h3>',
1050
+                'desc' => __('Payment reminder emails are sent to user automatically.', 'invoicing'),
1051 1051
                 'type' => 'header',
1052 1052
             ),
1053 1053
             'email_overdue_active' => array(
1054 1054
                 'id'   => 'email_overdue_active',
1055
-                'name' => __( 'Enable/Disable', 'invoicing' ),
1056
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
1055
+                'name' => __('Enable/Disable', 'invoicing'),
1056
+                'desc' => __('Enable this email notification', 'invoicing'),
1057 1057
                 'type' => 'checkbox',
1058 1058
                 'std'  => 1
1059 1059
             ),
1060 1060
             'email_due_reminder_days' => array(
1061 1061
                 'id'        => 'email_due_reminder_days',
1062
-                'name'      => __( 'When to Send', 'sliced-invoices' ),
1063
-                'desc'      => __( 'Check when you would like payment reminders sent out.', 'invoicing' ),
1062
+                'name'      => __('When to Send', 'sliced-invoices'),
1063
+                'desc'      => __('Check when you would like payment reminders sent out.', 'invoicing'),
1064 1064
                 'default'   => '',
1065 1065
                 'type'      => 'multicheck',
1066 1066
                 'options'   => $overdue_days_options,
1067 1067
             ),
1068 1068
             'email_overdue_subject' => array(
1069 1069
                 'id'   => 'email_overdue_subject',
1070
-                'name' => __( 'Subject', 'invoicing' ),
1071
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
1070
+                'name' => __('Subject', 'invoicing'),
1071
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
1072 1072
                 'type' => 'text',
1073
-                'std'  => __( '[{site_title}] Payment Reminder', 'invoicing' ),
1073
+                'std'  => __('[{site_title}] Payment Reminder', 'invoicing'),
1074 1074
                 'size' => 'large'
1075 1075
             ),
1076 1076
             'email_overdue_heading' => array(
1077 1077
                 'id'   => 'email_overdue_heading',
1078
-                'name' => __( 'Email Heading', 'invoicing' ),
1079
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
1078
+                'name' => __('Email Heading', 'invoicing'),
1079
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
1080 1080
                 'type' => 'text',
1081
-                'std'  => __( 'Payment reminder for your invoice', 'invoicing' ),
1081
+                'std'  => __('Payment reminder for your invoice', 'invoicing'),
1082 1082
                 'size' => 'large'
1083 1083
             ),
1084 1084
             'email_overdue_body' => array(
1085 1085
                 'id'   => 'email_overdue_body',
1086
-                'name' => __( 'Email Content', 'invoicing' ),
1087
-                'desc' => __( 'The content of the email.', 'invoicing' ),
1086
+                'name' => __('Email Content', 'invoicing'),
1087
+                'desc' => __('The content of the email.', 'invoicing'),
1088 1088
                 'type' => 'rich_editor',
1089
-                'std'  => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To pay now for this invoice please use the following link: <a href="{invoice_pay_link}">Pay Now</a></p>', 'invoicing' ),
1089
+                'std'  => __('<p>Hi {full_name},</p><p>This is just a friendly reminder your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To pay now for this invoice please use the following link: <a href="{invoice_pay_link}">Pay Now</a></p>', 'invoicing'),
1090 1090
                 'class' => 'large',
1091 1091
                 'size'  => 10,
1092 1092
             ),
1093 1093
         ),
1094 1094
     );
1095 1095
 
1096
-    return apply_filters( 'wpinv_get_emails', $emails );
1096
+    return apply_filters('wpinv_get_emails', $emails);
1097 1097
 }
1098 1098
 
1099
-function wpinv_settings_emails( $settings = array() ) {
1099
+function wpinv_settings_emails($settings = array()) {
1100 1100
     $emails = wpinv_get_emails();
1101 1101
     
1102
-    if ( !empty( $emails ) ) {
1103
-        foreach ( $emails as $key => $email ) {
1102
+    if (!empty($emails)) {
1103
+        foreach ($emails as $key => $email) {
1104 1104
             $settings[$key] = $email;
1105 1105
         }
1106 1106
     }
1107 1107
     
1108
-    return apply_filters( 'wpinv_settings_get_emails', $settings );
1108
+    return apply_filters('wpinv_settings_get_emails', $settings);
1109 1109
 }
1110
-add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 );
1110
+add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1);
1111 1111
 
1112
-function wpinv_settings_sections_emails( $settings ) {
1112
+function wpinv_settings_sections_emails($settings) {
1113 1113
     $emails = wpinv_get_emails();
1114 1114
     
1115 1115
     if (!empty($emails)) {
1116
-        foreach  ($emails as $key => $email) {
1117
-            $settings[$key] = !empty( $email['email_' . $key . '_header']['name'] ) ? strip_tags( $email['email_' . $key . '_header']['name'] ) : $key;
1116
+        foreach ($emails as $key => $email) {
1117
+            $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : $key;
1118 1118
         }
1119 1119
     }
1120 1120
     
1121 1121
     return $settings;    
1122 1122
 }
1123
-add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 );
1123
+add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1);
1124 1124
 
1125
-function wpinv_email_is_enabled( $email_type ) {
1125
+function wpinv_email_is_enabled($email_type) {
1126 1126
     $emails = wpinv_get_emails();
1127
-    $enabled = isset( $emails[$email_type] ) && wpinv_get_option( $email_type . '_active', 1 ) ? true : false;
1127
+    $enabled = isset($emails[$email_type]) && wpinv_get_option($email_type . '_active', 1) ? true : false;
1128 1128
 
1129
-    return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type );
1129
+    return apply_filters('wpinv_email_is_enabled', $enabled, $email_type);
1130 1130
 }
1131 1131
 
1132
-function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1133
-    switch ( $email_type ) {
1132
+function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) {
1133
+    switch ($email_type) {
1134 1134
         case 'new_invoice':
1135 1135
         case 'cancelled_invoice':
1136 1136
         case 'failed_invoice':
1137 1137
             $recipient  = wpinv_get_admin_email();
1138 1138
         break;
1139 1139
         default:
1140
-            $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1141
-            $recipient  = !empty( $invoice ) ? $invoice->get_email() : '';
1140
+            $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
1141
+            $recipient  = !empty($invoice) ? $invoice->get_email() : '';
1142 1142
         break;
1143 1143
     }
1144 1144
     
1145
-    return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice );
1145
+    return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice);
1146 1146
 }
1147 1147
 
1148
-function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1149
-    $subject    = wpinv_get_option( 'email_' . $email_type . '_subject' );
1148
+function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) {
1149
+    $subject    = wpinv_get_option('email_' . $email_type . '_subject');
1150 1150
     
1151
-    $subject    = wpinv_email_format_text( $subject );
1151
+    $subject    = wpinv_email_format_text($subject);
1152 1152
     
1153
-    return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice );
1153
+    return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice);
1154 1154
 }
1155 1155
 
1156
-function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1157
-    $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' );
1156
+function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) {
1157
+    $email_heading = wpinv_get_option('email_' . $email_type . '_heading');
1158 1158
     
1159
-    $email_heading = wpinv_email_format_text( $email_heading );
1159
+    $email_heading = wpinv_email_format_text($email_heading);
1160 1160
     
1161
-    return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice );
1161
+    return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice);
1162 1162
 }
1163 1163
 
1164
-function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1165
-    $content    = wpinv_get_option( 'email_' . $email_type . '_body' );
1164
+function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) {
1165
+    $content    = wpinv_get_option('email_' . $email_type . '_body');
1166 1166
     
1167
-    $content    = wpinv_email_format_text( $content );
1167
+    $content    = wpinv_email_format_text($content);
1168 1168
     
1169
-    return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice );
1169
+    return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice);
1170 1170
 }
1171 1171
 
1172
-function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1172
+function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) {
1173 1173
     $from_name = wpinv_mail_get_from_address();
1174 1174
     $from_email = wpinv_mail_get_from_address();
1175 1175
     
1176
-    $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1176
+    $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
1177 1177
     
1178
-    $headers    = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n";
1179
-    $headers    .= "Reply-To: ". $from_email . "\r\n";
1178
+    $headers    = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n";
1179
+    $headers    .= "Reply-To: " . $from_email . "\r\n";
1180 1180
     $headers    .= "Content-Type: " . wpinv_mail_get_content_type() . "\r\n";
1181 1181
     
1182
-    return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice );
1182
+    return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice);
1183 1183
 }
1184 1184
 
1185
-function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1185
+function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) {
1186 1186
     $attachments = array();
1187 1187
     
1188
-    return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice );
1188
+    return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice);
1189 1189
 }
1190 1190
 
1191 1191
 function wpinv_email_global_vars() {
@@ -1202,73 +1202,73 @@  discard block
 block discarded – undo
1202 1202
     $replace['sitename']    = $blogname;
1203 1203
     $replace['site-title']  = $blogname;
1204 1204
     
1205
-    return apply_filters( 'wpinv_email_global_vars', array( $search, $replace ) );
1205
+    return apply_filters('wpinv_email_global_vars', array($search, $replace));
1206 1206
 }
1207 1207
 
1208
-function wpinv_email_format_text( $content ) {
1208
+function wpinv_email_format_text($content) {
1209 1209
     global $wpinv_email_search, $wpinv_email_replace;
1210 1210
     
1211
-    if ( empty( $wpinv_email_search ) ) {
1211
+    if (empty($wpinv_email_search)) {
1212 1212
         $wpinv_email_search = array();
1213 1213
     }
1214 1214
     
1215
-    if ( empty( $wpinv_email_replace ) ) {
1215
+    if (empty($wpinv_email_replace)) {
1216 1216
         $wpinv_email_replace = array();
1217 1217
     }
1218 1218
     
1219
-    $wpinv_email_search     = (array)apply_filters( 'wpinv_email_format_text_search', $wpinv_email_search );
1220
-    $wpinv_email_replace    = (array)apply_filters( 'wpinv_email_format_text_replace', $wpinv_email_replace );
1219
+    $wpinv_email_search     = (array)apply_filters('wpinv_email_format_text_search', $wpinv_email_search);
1220
+    $wpinv_email_replace    = (array)apply_filters('wpinv_email_format_text_replace', $wpinv_email_replace);
1221 1221
     
1222 1222
     $global_vars    = wpinv_email_global_vars();
1223 1223
     
1224
-    $search         = array_merge( $global_vars[0], $wpinv_email_search );
1225
-    $replace        = array_merge( $global_vars[1], $wpinv_email_replace );
1224
+    $search         = array_merge($global_vars[0], $wpinv_email_search);
1225
+    $replace        = array_merge($global_vars[1], $wpinv_email_replace);
1226 1226
     
1227
-    if ( empty( $search ) || empty( $replace ) || !is_array( $search ) || !is_array( $replace ) ) {
1227
+    if (empty($search) || empty($replace) || !is_array($search) || !is_array($replace)) {
1228 1228
         return  $content;
1229 1229
     }
1230 1230
         
1231
-    return str_replace( $search, $replace, $content );
1231
+    return str_replace($search, $replace, $content);
1232 1232
 }
1233 1233
 
1234
-function wpinv_email_style_body( $content ) {
1234
+function wpinv_email_style_body($content) {
1235 1235
     // make sure we only inline CSS for html emails
1236
-    if ( in_array( wpinv_mail_get_content_type(), array( 'text/html', 'multipart/alternative' ) ) && class_exists( 'DOMDocument' ) ) {
1236
+    if (in_array(wpinv_mail_get_content_type(), array('text/html', 'multipart/alternative')) && class_exists('DOMDocument')) {
1237 1237
         ob_start();
1238
-        wpinv_get_template( 'emails/wpinv-email-styles.php' );
1239
-        $css = apply_filters( 'wpinv_email_styles', ob_get_clean() );
1238
+        wpinv_get_template('emails/wpinv-email-styles.php');
1239
+        $css = apply_filters('wpinv_email_styles', ob_get_clean());
1240 1240
         
1241 1241
         // apply CSS styles inline for picky email clients
1242 1242
         try {
1243
-            $emogrifier = new Emogrifier( $content, $css );
1243
+            $emogrifier = new Emogrifier($content, $css);
1244 1244
             $content    = $emogrifier->emogrify();
1245
-        } catch ( Exception $e ) {
1246
-            wpinv_error_log( $e->getMessage(), 'emogrifier' );
1245
+        } catch (Exception $e) {
1246
+            wpinv_error_log($e->getMessage(), 'emogrifier');
1247 1247
         }
1248 1248
     }
1249 1249
     return $content;
1250 1250
 }
1251 1251
 
1252
-function wpinv_email_header( $email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1253
-    wpinv_get_template( 'emails/wpinv-email-header.php', array( 'email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1252
+function wpinv_email_header($email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false) {
1253
+    wpinv_get_template('emails/wpinv-email-header.php', array('email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1254 1254
 }
1255 1255
 
1256 1256
 /**
1257 1257
  * Get the email footer.
1258 1258
  */
1259
-function wpinv_email_footer( $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1260
-    wpinv_get_template( 'emails/wpinv-email-footer.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1259
+function wpinv_email_footer($invoice = array(), $email_type = '', $sent_to_admin = false) {
1260
+    wpinv_get_template('emails/wpinv-email-footer.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1261 1261
 }
1262 1262
 
1263
-function wpinv_email_wrap_message( $message ) {
1263
+function wpinv_email_wrap_message($message) {
1264 1264
     // Buffer
1265 1265
     ob_start();
1266 1266
 
1267
-    do_action( 'wpinv_email_header' );
1267
+    do_action('wpinv_email_header');
1268 1268
 
1269
-    echo wpautop( wptexturize( $message ) );
1269
+    echo wpautop(wptexturize($message));
1270 1270
 
1271
-    do_action( 'wpinv_email_footer' );
1271
+    do_action('wpinv_email_footer');
1272 1272
 
1273 1273
     // Get contents
1274 1274
     $message = ob_get_clean();
@@ -1276,86 +1276,86 @@  discard block
 block discarded – undo
1276 1276
     return $message;
1277 1277
 }
1278 1278
 
1279
-function wpinv_email_invoice_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1280
-    wpinv_get_template( 'emails/wpinv-email-invoice-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1279
+function wpinv_email_invoice_details($invoice, $email_type = '', $sent_to_admin = false) {
1280
+    wpinv_get_template('emails/wpinv-email-invoice-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1281 1281
 }
1282 1282
 
1283
-function wpinv_email_invoice_items( $invoice, $email_type = '', $sent_to_admin = false ) {
1284
-    wpinv_get_template( 'emails/wpinv-email-invoice-items.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1283
+function wpinv_email_invoice_items($invoice, $email_type = '', $sent_to_admin = false) {
1284
+    wpinv_get_template('emails/wpinv-email-invoice-items.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1285 1285
 }
1286 1286
 
1287
-function wpinv_email_billing_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1288
-    wpinv_get_template( 'emails/wpinv-email-billing-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1287
+function wpinv_email_billing_details($invoice, $email_type = '', $sent_to_admin = false) {
1288
+    wpinv_get_template('emails/wpinv-email-billing-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1289 1289
 }
1290 1290
 
1291
-function wpinv_send_customer_invoice( $data = array() ) {
1292
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1291
+function wpinv_send_customer_invoice($data = array()) {
1292
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1293 1293
     
1294
-    if ( empty( $invoice_id ) ) {
1294
+    if (empty($invoice_id)) {
1295 1295
         return;
1296 1296
     }
1297 1297
 
1298
-    if ( !current_user_can( 'manage_options' ) ) {
1299
-        wp_die( __( 'You do not have permission to send invoice notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1298
+    if (!current_user_can('manage_options')) {
1299
+        wp_die(__('You do not have permission to send invoice notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
1300 1300
     }
1301 1301
     
1302
-    $sent = wpinv_user_invoice_notification( $invoice_id );
1302
+    $sent = wpinv_user_invoice_notification($invoice_id);
1303 1303
     
1304 1304
     $status = $sent ? 'email_sent' : 'email_fail';
1305 1305
     
1306
-    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1307
-    wp_redirect( $redirect );
1306
+    $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false));
1307
+    wp_redirect($redirect);
1308 1308
     exit;
1309 1309
 }
1310
-add_action( 'wpinv_send_invoice', 'wpinv_send_customer_invoice' );
1310
+add_action('wpinv_send_invoice', 'wpinv_send_customer_invoice');
1311 1311
 
1312
-function wpinv_send_overdue_reminder( $data = array() ) {
1313
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1312
+function wpinv_send_overdue_reminder($data = array()) {
1313
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1314 1314
     
1315
-    if ( empty( $invoice_id ) ) {
1315
+    if (empty($invoice_id)) {
1316 1316
         return;
1317 1317
     }
1318 1318
 
1319
-    if ( !current_user_can( 'manage_options' ) ) {
1320
-        wp_die( __( 'You do not have permission to send reminder notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1319
+    if (!current_user_can('manage_options')) {
1320
+        wp_die(__('You do not have permission to send reminder notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
1321 1321
     }
1322 1322
     
1323
-    $sent = wpinv_send_payment_reminder_notification( $invoice_id );
1323
+    $sent = wpinv_send_payment_reminder_notification($invoice_id);
1324 1324
     
1325 1325
     $status = $sent ? 'email_sent' : 'email_fail';
1326 1326
     
1327
-    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1328
-    wp_redirect( $redirect );
1327
+    $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false));
1328
+    wp_redirect($redirect);
1329 1329
     exit;
1330 1330
 }
1331
-add_action( 'wpinv_send_reminder', 'wpinv_send_overdue_reminder' );
1331
+add_action('wpinv_send_reminder', 'wpinv_send_overdue_reminder');
1332 1332
 
1333
-function wpinv_send_customer_note_email( $data ) {
1334
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1333
+function wpinv_send_customer_note_email($data) {
1334
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1335 1335
     
1336
-    if ( empty( $invoice_id ) ) {
1336
+    if (empty($invoice_id)) {
1337 1337
         return;
1338 1338
     }
1339 1339
     
1340
-    $sent = wpinv_user_note_notification( $invoice_id, $data );
1340
+    $sent = wpinv_user_note_notification($invoice_id, $data);
1341 1341
 }
1342
-add_action( 'wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1 );
1342
+add_action('wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1);
1343 1343
 
1344
-function wpinv_add_notes_to_invoice_email( $invoice, $email_type, $sent_to_admin ) {
1345
-    if ( !empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->ID, true ) ) {
1346
-        $date_format = get_option( 'date_format' );
1347
-        $time_format = get_option( 'time_format' );
1344
+function wpinv_add_notes_to_invoice_email($invoice, $email_type, $sent_to_admin) {
1345
+    if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->ID, true)) {
1346
+        $date_format = get_option('date_format');
1347
+        $time_format = get_option('time_format');
1348 1348
         ?>
1349 1349
         <div id="wpinv-email-notes">
1350
-            <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3>
1350
+            <h3 class="wpinv-notes-t"><?php echo apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing')); ?></h3>
1351 1351
             <ol class="wpinv-notes-lists">
1352 1352
         <?php
1353
-        foreach ( $invoice_notes as $note ) {
1354
-            $note_time = strtotime( $note->comment_date );
1353
+        foreach ($invoice_notes as $note) {
1354
+            $note_time = strtotime($note->comment_date);
1355 1355
             ?>
1356 1356
             <li class="comment wpinv-note">
1357
-            <p class="wpinv-note-date meta"><?php printf( __( '%2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( $date_format, $note_time ), date_i18n( $time_format, $note_time ), $note_time ); ?></p>
1358
-            <div class="wpinv-note-desc description"><?php echo wpautop( wptexturize( $note->comment_content ) ); ?></div>
1357
+            <p class="wpinv-note-date meta"><?php printf(__('%2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n($date_format, $note_time), date_i18n($time_format, $note_time), $note_time); ?></p>
1358
+            <div class="wpinv-note-desc description"><?php echo wpautop(wptexturize($note->comment_content)); ?></div>
1359 1359
             </li>
1360 1360
             <?php
1361 1361
         }
@@ -1364,21 +1364,21 @@  discard block
 block discarded – undo
1364 1364
         <?php
1365 1365
     }
1366 1366
 }
1367
-add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 );
1367
+add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3);
1368 1368
 
1369 1369
 function wpinv_email_payment_reminders() {    
1370 1370
     global $wpi_auto_reminder;
1371
-    if ( !wpinv_get_option( 'email_overdue_active' ) ) {
1371
+    if (!wpinv_get_option('email_overdue_active')) {
1372 1372
         return;
1373 1373
     }
1374 1374
     
1375
-    if ( $reminder_days = wpinv_get_option( 'email_due_reminder_days' ) ) {
1376
-        $reminder_days  = is_array( $reminder_days ) ? array_values( $reminder_days ) : '';
1375
+    if ($reminder_days = wpinv_get_option('email_due_reminder_days')) {
1376
+        $reminder_days  = is_array($reminder_days) ? array_values($reminder_days) : '';
1377 1377
         
1378
-        if ( empty( $reminder_days ) ) {
1378
+        if (empty($reminder_days)) {
1379 1379
             return;
1380 1380
         }
1381
-        $reminder_days  = array_unique( array_map( 'absint', $reminder_days ) );
1381
+        $reminder_days = array_unique(array_map('absint', $reminder_days));
1382 1382
         
1383 1383
         $args = array(
1384 1384
             'post_type'     => 'wpi_invoice',
@@ -1388,7 +1388,7 @@  discard block
 block discarded – undo
1388 1388
             'meta_query'    => array(
1389 1389
                 array(
1390 1390
                     'key'       =>  '_wpinv_due_date',
1391
-                    'value'     =>  array( '', 'none' ),
1391
+                    'value'     =>  array('', 'none'),
1392 1392
                     'compare'   =>  'NOT IN',
1393 1393
                 )
1394 1394
             ),
@@ -1397,64 +1397,64 @@  discard block
 block discarded – undo
1397 1397
             'order'         => 'ASC',
1398 1398
         );
1399 1399
         
1400
-        $invoices = get_posts( $args );
1400
+        $invoices = get_posts($args);
1401 1401
         
1402
-        if ( empty( $invoices ) ) {
1402
+        if (empty($invoices)) {
1403 1403
             return;
1404 1404
         }
1405 1405
         
1406
-        $date_to_send   = array();
1406
+        $date_to_send = array();
1407 1407
         
1408
-        foreach ( $invoices as $id ) {
1409
-            $due_date = get_post_meta( $id, '_wpinv_due_date', true );
1408
+        foreach ($invoices as $id) {
1409
+            $due_date = get_post_meta($id, '_wpinv_due_date', true);
1410 1410
             
1411
-            foreach ( $reminder_days as $key => $days ) {
1412
-                if ( $days !== '' ) {
1413
-                    $date_to_send[$id][] = date_i18n( 'Y-m-d', strtotime( $due_date ) + ( $days * DAY_IN_SECONDS ) );
1411
+            foreach ($reminder_days as $key => $days) {
1412
+                if ($days !== '') {
1413
+                    $date_to_send[$id][] = date_i18n('Y-m-d', strtotime($due_date) + ($days * DAY_IN_SECONDS));
1414 1414
                 }
1415 1415
             }
1416 1416
         }
1417 1417
 
1418
-        $today              = date_i18n( 'Y-m-d' );
1418
+        $today              = date_i18n('Y-m-d');
1419 1419
         $wpi_auto_reminder  = true;
1420 1420
 
1421
-        foreach ( $date_to_send as $id => $values ) {
1422
-            if ( in_array( $today, $values ) ) {
1423
-                $sent = get_post_meta( $id, '_wpinv_reminder_sent', true );
1421
+        foreach ($date_to_send as $id => $values) {
1422
+            if (in_array($today, $values)) {
1423
+                $sent = get_post_meta($id, '_wpinv_reminder_sent', true);
1424 1424
 
1425
-                if ( isset( $sent ) && !empty( $sent ) ) {
1426
-                    if ( !in_array( $today, $sent ) ) {
1427
-                        do_action( 'wpinv_send_payment_reminder_notification', $id );
1425
+                if (isset($sent) && !empty($sent)) {
1426
+                    if (!in_array($today, $sent)) {
1427
+                        do_action('wpinv_send_payment_reminder_notification', $id);
1428 1428
                     }
1429 1429
                 } else {
1430
-                    do_action( 'wpinv_send_payment_reminder_notification', $id );
1430
+                    do_action('wpinv_send_payment_reminder_notification', $id);
1431 1431
                 }
1432 1432
             }
1433 1433
         }
1434 1434
         
1435
-        $wpi_auto_reminder  = false;
1435
+        $wpi_auto_reminder = false;
1436 1436
     }
1437 1437
 }
1438 1438
 
1439
-function wpinv_send_payment_reminder_notification( $invoice_id ) {
1439
+function wpinv_send_payment_reminder_notification($invoice_id) {
1440 1440
     global $wpinv_email_search, $wpinv_email_replace;
1441 1441
     
1442 1442
     $email_type = 'overdue';
1443
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
1443
+    if (!wpinv_email_is_enabled($email_type)) {
1444 1444
         return false;
1445 1445
     }
1446 1446
     
1447
-    $invoice    = wpinv_get_invoice( $invoice_id );
1448
-    if ( empty( $invoice ) ) {
1447
+    $invoice = wpinv_get_invoice($invoice_id);
1448
+    if (empty($invoice)) {
1449 1449
         return false;
1450 1450
     }
1451 1451
     
1452
-    if ( !$invoice->needs_payment() ) {
1452
+    if (!$invoice->needs_payment()) {
1453 1453
         return false;
1454 1454
     }
1455 1455
     
1456
-    $recipient  = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
1457
-    if ( !is_email( $recipient ) ) {
1456
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
1457
+    if (!is_email($recipient)) {
1458 1458
         return false;
1459 1459
     }
1460 1460
         
@@ -1470,70 +1470,70 @@  discard block
 block discarded – undo
1470 1470
     $replace                    = array();
1471 1471
     $replace['full_name']       = $invoice->get_user_full_name();
1472 1472
     $replace['invoice_number']  = $invoice->get_number();
1473
-    $replace['invoice_due_date']= $invoice->get_due_date( true );
1474
-    $replace['invoice_total']   = $invoice->get_total( true );
1475
-    $replace['invoice_link']    = $invoice->get_view_url( true );
1476
-    $replace['invoice_pay_link']= $invoice->get_checkout_payment_url( false, true );
1477
-    $replace['is_was']          = strtotime( $invoice->get_due_date() ) < strtotime( date_i18n( 'Y-m-d' ) ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' );
1473
+    $replace['invoice_due_date'] = $invoice->get_due_date(true);
1474
+    $replace['invoice_total']   = $invoice->get_total(true);
1475
+    $replace['invoice_link']    = $invoice->get_view_url(true);
1476
+    $replace['invoice_pay_link'] = $invoice->get_checkout_payment_url(false, true);
1477
+    $replace['is_was']          = strtotime($invoice->get_due_date()) < strtotime(date_i18n('Y-m-d')) ? __('was', 'invoicing') : __('is', 'invoicing');
1478 1478
 
1479 1479
     $wpinv_email_search         = $search;
1480 1480
     $wpinv_email_replace        = $replace;
1481 1481
     
1482
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
1483
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
1484
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
1485
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
1482
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
1483
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
1484
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
1485
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
1486 1486
     
1487
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
1487
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
1488 1488
     
1489
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
1489
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
1490 1490
             'invoice'       => $invoice,
1491 1491
             'email_type'    => $email_type,
1492 1492
             'email_heading' => $email_heading,
1493 1493
             'sent_to_admin' => false,
1494 1494
             'plain_text'    => false,
1495 1495
             'message_body'  => $message_body
1496
-        ) );
1496
+        ));
1497 1497
         
1498
-    $content        = wpinv_email_format_text( $content );
1498
+    $content = wpinv_email_format_text($content);
1499 1499
 
1500
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
1501
-    if ( $sent ) {
1502
-        do_action( 'wpinv_payment_reminder_sent', $invoice_id, $invoice );
1500
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
1501
+    if ($sent) {
1502
+        do_action('wpinv_payment_reminder_sent', $invoice_id, $invoice);
1503 1503
     }
1504 1504
         
1505 1505
     return $sent;
1506 1506
 }
1507
-add_action( 'wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1 );
1507
+add_action('wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1);
1508 1508
 
1509
-function wpinv_payment_reminder_sent( $invoice_id, $invoice ) {
1509
+function wpinv_payment_reminder_sent($invoice_id, $invoice) {
1510 1510
     global $wpi_auto_reminder;
1511 1511
     
1512
-    $sent = get_post_meta( $invoice_id, '_wpinv_reminder_sent', true );
1512
+    $sent = get_post_meta($invoice_id, '_wpinv_reminder_sent', true);
1513 1513
     
1514
-    if ( empty( $sent ) ) {
1514
+    if (empty($sent)) {
1515 1515
         $sent = array();
1516 1516
     }
1517
-    $sent[] = date_i18n( 'Y-m-d' );
1517
+    $sent[] = date_i18n('Y-m-d');
1518 1518
     
1519
-    update_post_meta( $invoice_id, '_wpinv_reminder_sent', $sent );
1519
+    update_post_meta($invoice_id, '_wpinv_reminder_sent', $sent);
1520 1520
     
1521
-    if ( $wpi_auto_reminder ) { // Auto reminder note.
1522
-        $note = __( 'Manual reminder sent to the user.', 'invoicing' );
1523
-        $invoice->add_note( $note, false, false, true );
1521
+    if ($wpi_auto_reminder) { // Auto reminder note.
1522
+        $note = __('Manual reminder sent to the user.', 'invoicing');
1523
+        $invoice->add_note($note, false, false, true);
1524 1524
     } else { // Menual reminder note.
1525
-        $note = __( 'Manual reminder sent to the user.', 'invoicing' );
1526
-        $invoice->add_note( $note );
1525
+        $note = __('Manual reminder sent to the user.', 'invoicing');
1526
+        $invoice->add_note($note);
1527 1527
     }
1528 1528
 }
1529
-add_action( 'wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2 );
1529
+add_action('wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2);
1530 1530
 
1531
-function wpinv_email_before_note_details( $invoice, $email_type, $sent_to_admin, $customer_note ) {
1532
-    if("wpi_invoice" === $invoice->post_type && !empty($customer_note)){
1531
+function wpinv_email_before_note_details($invoice, $email_type, $sent_to_admin, $customer_note) {
1532
+    if ("wpi_invoice" === $invoice->post_type && !empty($customer_note)) {
1533 1533
         $before_note = '';
1534
-        $before_note .= __( 'Hello, a note has just been added to your invoice:', 'invoicing' );
1535
-        $before_note .= '<blockquote class="wpinv-note">'.wpautop( wptexturize( $customer_note ) ).'</blockquote>';
1536
-        $before_note .= __( 'For your reference, your invoice details are shown below.', 'invoicing' );
1534
+        $before_note .= __('Hello, a note has just been added to your invoice:', 'invoicing');
1535
+        $before_note .= '<blockquote class="wpinv-note">' . wpautop(wptexturize($customer_note)) . '</blockquote>';
1536
+        $before_note .= __('For your reference, your invoice details are shown below.', 'invoicing');
1537 1537
         echo $before_note;
1538 1538
     }
1539 1539
 }
1540 1540
\ No newline at end of file
Please login to merge, or discard this patch.