Passed
Push — master ( 944635...26bb6c )
by Stiofan
03:44
created
includes/wpinv-helper-functions.php 1 patch
Spacing   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -7,89 +7,89 @@  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, $decimals = NULL ) {
44
+function wpinv_sanitize_amount($amount, $decimals = NULL) {
45 45
     $is_negative   = false;
46 46
     $thousands_sep = wpinv_thousands_separator();
47 47
     $decimal_sep   = wpinv_decimal_separator();
48
-    if ( $decimals === NULL ) {
48
+    if ($decimals === NULL) {
49 49
         $decimals = wpinv_decimals();
50 50
     }
51 51
 
52 52
     // Sanitize the amount
53
-    if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) {
54
-        if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
55
-            $amount = str_replace( $thousands_sep, '', $amount );
56
-        } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) {
57
-            $amount = str_replace( '.', '', $amount );
53
+    if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) {
54
+        if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) {
55
+            $amount = str_replace($thousands_sep, '', $amount);
56
+        } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) {
57
+            $amount = str_replace('.', '', $amount);
58 58
         }
59 59
 
60
-        $amount = str_replace( $decimal_sep, '.', $amount );
61
-    } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
62
-        $amount = str_replace( $thousands_sep, '', $amount );
60
+        $amount = str_replace($decimal_sep, '.', $amount);
61
+    } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
62
+        $amount = str_replace($thousands_sep, '', $amount);
63 63
     }
64 64
 
65
-    if( $amount < 0 ) {
65
+    if ($amount < 0) {
66 66
         $is_negative = true;
67 67
     }
68 68
 
69
-    $amount   = preg_replace( '/[^0-9\.]/', '', $amount );
69
+    $amount   = preg_replace('/[^0-9\.]/', '', $amount);
70 70
 
71
-    $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', absint( $decimals ), $amount );
72
-    $amount   = number_format( (double) $amount, absint( $decimals ), '.', '' );
71
+    $decimals = apply_filters('wpinv_sanitize_amount_decimals', absint($decimals), $amount);
72
+    $amount   = number_format((double)$amount, absint($decimals), '.', '');
73 73
 
74
-    if( $is_negative ) {
74
+    if ($is_negative) {
75 75
         $amount *= -1;
76 76
     }
77 77
 
78
-    return apply_filters( 'wpinv_sanitize_amount', $amount, $decimals );
78
+    return apply_filters('wpinv_sanitize_amount', $amount, $decimals);
79 79
 }
80
-add_filter( 'wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
80
+add_filter('wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1);
81 81
 
82
-function wpinv_round_amount( $amount, $decimals = NULL ) {
83
-    if ( $decimals === NULL ) {
82
+function wpinv_round_amount($amount, $decimals = NULL) {
83
+    if ($decimals === NULL) {
84 84
         $decimals = wpinv_decimals();
85 85
     }
86 86
     
87
-    $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) );
87
+    $amount = round((double)$amount, wpinv_currency_decimal_filter(absint($decimals)));
88 88
 
89
-    return apply_filters( 'wpinv_round_amount', $amount, $decimals );
89
+    return apply_filters('wpinv_round_amount', $amount, $decimals);
90 90
 }
91 91
 
92
-function wpinv_get_invoice_statuses( $trashed = false ) {
92
+function wpinv_get_invoice_statuses($trashed = false) {
93 93
     global $post;
94 94
     $invoice_statuses = array();
95 95
     $invoice_statuses = array(
@@ -103,32 +103,32 @@  discard block
 block discarded – undo
103 103
         'wpi-renewal' => __('Renewal Payment', 'invoicing')
104 104
     );
105 105
     
106
-    if ( $trashed ) {
107
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
106
+    if ($trashed) {
107
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
108 108
     }
109 109
 
110
-    return apply_filters( 'wpinv_statuses', $invoice_statuses );
110
+    return apply_filters('wpinv_statuses', $invoice_statuses);
111 111
 }
112 112
 
113
-function wpinv_status_nicename( $status ) {
113
+function wpinv_status_nicename($status) {
114 114
     $statuses = wpinv_get_invoice_statuses();
115
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' );
115
+    $status   = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing');
116 116
 
117 117
     return $status;
118 118
 }
119 119
 
120 120
 function wpinv_get_currency() {
121
-    $currency = wpinv_get_option( 'currency', 'USD' );
121
+    $currency = wpinv_get_option('currency', 'USD');
122 122
     
123
-    return apply_filters( 'wpinv_currency', $currency );
123
+    return apply_filters('wpinv_currency', $currency);
124 124
 }
125 125
 
126
-function wpinv_currency_symbol( $currency = '' ) {
127
-    if ( empty( $currency ) ) {
126
+function wpinv_currency_symbol($currency = '') {
127
+    if (empty($currency)) {
128 128
         $currency = wpinv_get_currency();
129 129
     }
130 130
     
131
-    $symbols = apply_filters( 'wpinv_currency_symbols', array(
131
+    $symbols = apply_filters('wpinv_currency_symbols', array(
132 132
         'AED' => 'د.إ',
133 133
         'ARS' => '&#36;',
134 134
         'AUD' => '&#36;',
@@ -180,78 +180,78 @@  discard block
 block discarded – undo
180 180
         'USD' => '&#36;',
181 181
         'VND' => '&#8363;',
182 182
         'ZAR' => '&#82;',
183
-    ) );
183
+    ));
184 184
 
185
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : '&#36;';
185
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : '&#36;';
186 186
 
187
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
187
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
188 188
 }
189 189
 
190 190
 function wpinv_currency_position() {
191
-    $position = wpinv_get_option( 'currency_position', 'left' );
191
+    $position = wpinv_get_option('currency_position', 'left');
192 192
     
193
-    return apply_filters( 'wpinv_currency_position', $position );
193
+    return apply_filters('wpinv_currency_position', $position);
194 194
 }
195 195
 
196 196
 function wpinv_thousands_separator() {
197
-    $thousand_sep = wpinv_get_option( 'thousands_separator', ',' );
197
+    $thousand_sep = wpinv_get_option('thousands_separator', ',');
198 198
     
199
-    return apply_filters( 'wpinv_thousands_separator', $thousand_sep );
199
+    return apply_filters('wpinv_thousands_separator', $thousand_sep);
200 200
 }
201 201
 
202 202
 function wpinv_decimal_separator() {
203
-    $decimal_sep = wpinv_get_option( 'decimal_separator', '.' );
203
+    $decimal_sep = wpinv_get_option('decimal_separator', '.');
204 204
     
205
-    return apply_filters( 'wpinv_decimal_separator', $decimal_sep );
205
+    return apply_filters('wpinv_decimal_separator', $decimal_sep);
206 206
 }
207 207
 
208 208
 function wpinv_decimals() {
209
-    $decimals = apply_filters( 'wpinv_decimals', wpinv_get_option( 'decimals', 2 ) );
209
+    $decimals = apply_filters('wpinv_decimals', wpinv_get_option('decimals', 2));
210 210
     
211
-    return absint( $decimals );
211
+    return absint($decimals);
212 212
 }
213 213
 
214 214
 function wpinv_get_currencies() {
215 215
     $currencies = array(
216
-        'USD'  => __( 'US Dollars (&#36;)', 'invoicing' ),
217
-        'EUR'  => __( 'Euros (&euro;)', 'invoicing' ),
218
-        'GBP'  => __( 'Pounds Sterling (&pound;)', 'invoicing' ),
219
-        'AUD'  => __( 'Australian Dollars (&#36;)', 'invoicing' ),
220
-        'BRL'  => __( 'Brazilian Real (R&#36;)', 'invoicing' ),
221
-        'CAD'  => __( 'Canadian Dollars (&#36;)', 'invoicing' ),
222
-        'CLP'  => __( 'Chilean Peso (&#36;)', 'invoicing' ),
223
-        'CNY'  => __( 'Chinese Yuan (&yen;)', 'invoicing' ),
224
-        'CZK'  => __( 'Czech Koruna (&#75;&#269;)', 'invoicing' ),
225
-        'DKK'  => __( 'Danish Krone (DKK)', 'invoicing' ),
226
-        'HKD'  => __( 'Hong Kong Dollar (&#36;)', 'invoicing' ),
227
-        'HUF'  => __( 'Hungarian Forint (&#70;&#116;)', 'invoicing' ),
228
-        'INR'  => __( 'Indian Rupee (&#8377;)', 'invoicing' ),
229
-        'ILS'  => __( 'Israeli Shekel (&#8362;)', 'invoicing' ),
230
-        'JPY'  => __( 'Japanese Yen (&yen;)', 'invoicing' ),
231
-        'MYR'  => __( 'Malaysian Ringgit (&#82;&#77;)', 'invoicing' ),
232
-        'MXN'  => __( 'Mexican Peso (&#36;)', 'invoicing' ),
233
-        'NZD'  => __( 'New Zealand Dollar (&#36;)', 'invoicing' ),
234
-        'NOK'  => __( 'Norwegian Krone (&#107;&#114;)', 'invoicing' ),
235
-        'PHP'  => __( 'Philippine Peso (&#8369;)', 'invoicing' ),
236
-        'PLN'  => __( 'Polish Zloty (&#122;&#322;)', 'invoicing' ),
237
-        'SGD'  => __( 'Singapore Dollar (&#36;)', 'invoicing' ),
238
-        'SEK'  => __( 'Swedish Krona (&#107;&#114;)', 'invoicing' ),
239
-        'CHF'  => __( 'Swiss Franc (&#67;&#72;&#70;)', 'invoicing' ),
240
-        'TWD'  => __( 'Taiwan New Dollar (&#78;&#84;&#36;)', 'invoicing' ),
241
-        'THB'  => __( 'Thai Baht (&#3647;)', 'invoicing' ),
242
-        'TRY'  => __( 'Turkish Lira (&#8378;)', 'invoicing' ),
243
-        'RIAL' => __( 'Iranian Rial (&#65020;)', 'invoicing' ),
244
-        'RUB'  => __( 'Russian Ruble (&#8381;)', 'invoicing' ),
245
-        'ZAR'  => __( 'South African Rand (&#82;)', 'invoicing' )
216
+        'USD'  => __('US Dollars (&#36;)', 'invoicing'),
217
+        'EUR'  => __('Euros (&euro;)', 'invoicing'),
218
+        'GBP'  => __('Pounds Sterling (&pound;)', 'invoicing'),
219
+        'AUD'  => __('Australian Dollars (&#36;)', 'invoicing'),
220
+        'BRL'  => __('Brazilian Real (R&#36;)', 'invoicing'),
221
+        'CAD'  => __('Canadian Dollars (&#36;)', 'invoicing'),
222
+        'CLP'  => __('Chilean Peso (&#36;)', 'invoicing'),
223
+        'CNY'  => __('Chinese Yuan (&yen;)', 'invoicing'),
224
+        'CZK'  => __('Czech Koruna (&#75;&#269;)', 'invoicing'),
225
+        'DKK'  => __('Danish Krone (DKK)', 'invoicing'),
226
+        'HKD'  => __('Hong Kong Dollar (&#36;)', 'invoicing'),
227
+        'HUF'  => __('Hungarian Forint (&#70;&#116;)', 'invoicing'),
228
+        'INR'  => __('Indian Rupee (&#8377;)', 'invoicing'),
229
+        'ILS'  => __('Israeli Shekel (&#8362;)', 'invoicing'),
230
+        'JPY'  => __('Japanese Yen (&yen;)', 'invoicing'),
231
+        'MYR'  => __('Malaysian Ringgit (&#82;&#77;)', 'invoicing'),
232
+        'MXN'  => __('Mexican Peso (&#36;)', 'invoicing'),
233
+        'NZD'  => __('New Zealand Dollar (&#36;)', 'invoicing'),
234
+        'NOK'  => __('Norwegian Krone (&#107;&#114;)', 'invoicing'),
235
+        'PHP'  => __('Philippine Peso (&#8369;)', 'invoicing'),
236
+        'PLN'  => __('Polish Zloty (&#122;&#322;)', 'invoicing'),
237
+        'SGD'  => __('Singapore Dollar (&#36;)', 'invoicing'),
238
+        'SEK'  => __('Swedish Krona (&#107;&#114;)', 'invoicing'),
239
+        'CHF'  => __('Swiss Franc (&#67;&#72;&#70;)', 'invoicing'),
240
+        'TWD'  => __('Taiwan New Dollar (&#78;&#84;&#36;)', 'invoicing'),
241
+        'THB'  => __('Thai Baht (&#3647;)', 'invoicing'),
242
+        'TRY'  => __('Turkish Lira (&#8378;)', 'invoicing'),
243
+        'RIAL' => __('Iranian Rial (&#65020;)', 'invoicing'),
244
+        'RUB'  => __('Russian Ruble (&#8381;)', 'invoicing'),
245
+        'ZAR'  => __('South African Rand (&#82;)', 'invoicing')
246 246
     );
247 247
     
248
-    asort( $currencies );
248
+    asort($currencies);
249 249
 
250
-    return apply_filters( 'wpinv_currencies', $currencies );
250
+    return apply_filters('wpinv_currencies', $currencies);
251 251
 }
252 252
 
253
-function wpinv_price( $amount = '', $currency = '' ) {
254
-    if( empty( $currency ) ) {
253
+function wpinv_price($amount = '', $currency = '') {
254
+    if (empty($currency)) {
255 255
         $currency = wpinv_get_currency();
256 256
     }
257 257
 
@@ -259,14 +259,14 @@  discard block
 block discarded – undo
259 259
 
260 260
     $negative = $amount < 0;
261 261
 
262
-    if ( $negative ) {
263
-        $amount = substr( $amount, 1 );
262
+    if ($negative) {
263
+        $amount = substr($amount, 1);
264 264
     }
265 265
 
266
-    $symbol = wpinv_currency_symbol( $currency );
266
+    $symbol = wpinv_currency_symbol($currency);
267 267
 
268
-    if ( $position == 'left' || $position == 'left_space' ) {
269
-        switch ( $currency ) {
268
+    if ($position == 'left' || $position == 'left_space') {
269
+        switch ($currency) {
270 270
             case "GBP" :
271 271
             case "BRL" :
272 272
             case "EUR" :
@@ -278,15 +278,15 @@  discard block
 block discarded – undo
278 278
             case "NZD" :
279 279
             case "SGD" :
280 280
             case "JPY" :
281
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
281
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
282 282
                 break;
283 283
             default :
284 284
                 //$price = $currency . ' ' . $amount;
285
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
285
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
286 286
                 break;
287 287
         }
288 288
     } else {
289
-        switch ( $currency ) {
289
+        switch ($currency) {
290 290
             case "GBP" :
291 291
             case "BRL" :
292 292
             case "EUR" :
@@ -297,83 +297,83 @@  discard block
 block discarded – undo
297 297
             case "MXN" :
298 298
             case "SGD" :
299 299
             case "JPY" :
300
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
300
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
301 301
                 break;
302 302
             default :
303 303
                 //$price = $amount . ' ' . $currency;
304
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
304
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
305 305
                 break;
306 306
         }
307 307
     }
308 308
     
309
-    if ( $negative ) {
309
+    if ($negative) {
310 310
         $price = '-' . $price;
311 311
     }
312 312
     
313
-    $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount );
313
+    $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount);
314 314
 
315 315
     return $price;
316 316
 }
317 317
 
318
-function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) {
318
+function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) {
319 319
     $thousands_sep = wpinv_thousands_separator();
320 320
     $decimal_sep   = wpinv_decimal_separator();
321 321
 
322
-    if ( $decimals === NULL ) {
322
+    if ($decimals === NULL) {
323 323
         $decimals = wpinv_decimals();
324 324
     }
325 325
 
326
-    if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) {
327
-        $whole = substr( $amount, 0, $sep_found );
328
-        $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) );
326
+    if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) {
327
+        $whole = substr($amount, 0, $sep_found);
328
+        $part = substr($amount, $sep_found + 1, (strlen($amount) - 1));
329 329
         $amount = $whole . '.' . $part;
330 330
     }
331 331
 
332
-    if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
333
-        $amount = str_replace( ',', '', $amount );
332
+    if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
333
+        $amount = str_replace(',', '', $amount);
334 334
     }
335 335
 
336
-    if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
337
-        $amount = str_replace( ' ', '', $amount );
336
+    if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) {
337
+        $amount = str_replace(' ', '', $amount);
338 338
     }
339 339
 
340
-    if ( empty( $amount ) ) {
340
+    if (empty($amount)) {
341 341
         $amount = 0;
342 342
     }
343 343
     
344
-    $decimals  = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate );
345
-    $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep );
344
+    $decimals  = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate);
345
+    $formatted = number_format((float)$amount, $decimals, $decimal_sep, $thousands_sep);
346 346
     
347
-    if ( $calculate ) {
348
-        if ( $thousands_sep === "," ) {
349
-            $formatted = str_replace( ",", "", $formatted );
347
+    if ($calculate) {
348
+        if ($thousands_sep === ",") {
349
+            $formatted = str_replace(",", "", $formatted);
350 350
         }
351 351
         
352
-        if ( $decimal_sep === "," ) {
353
-            $formatted = str_replace( ",", ".", $formatted );
352
+        if ($decimal_sep === ",") {
353
+            $formatted = str_replace(",", ".", $formatted);
354 354
         }
355 355
     }
356 356
 
357
-    return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate );
357
+    return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate);
358 358
 }
359
-add_filter( 'wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
359
+add_filter('wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1);
360 360
 
361
-function wpinv_sanitize_key( $key ) {
361
+function wpinv_sanitize_key($key) {
362 362
     $raw_key = $key;
363
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
363
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
364 364
 
365
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
365
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
366 366
 }
367 367
 
368
-function wpinv_get_file_extension( $str ) {
369
-    $parts = explode( '.', $str );
370
-    return end( $parts );
368
+function wpinv_get_file_extension($str) {
369
+    $parts = explode('.', $str);
370
+    return end($parts);
371 371
 }
372 372
 
373
-function wpinv_string_is_image_url( $str ) {
374
-    $ext = wpinv_get_file_extension( $str );
373
+function wpinv_string_is_image_url($str) {
374
+    $ext = wpinv_get_file_extension($str);
375 375
 
376
-    switch ( strtolower( $ext ) ) {
376
+    switch (strtolower($ext)) {
377 377
         case 'jpeg';
378 378
         case 'jpg';
379 379
             $return = true;
@@ -389,32 +389,32 @@  discard block
 block discarded – undo
389 389
             break;
390 390
     }
391 391
 
392
-    return (bool)apply_filters( 'wpinv_string_is_image', $return, $str );
392
+    return (bool)apply_filters('wpinv_string_is_image', $return, $str);
393 393
 }
394 394
 
395
-function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) {
396
-    $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG );
395
+function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) {
396
+    $should_log = apply_filters('wpinv_log_errors', WP_DEBUG);
397 397
     
398
-    if ( true === $should_log ) {
398
+    if (true === $should_log) {
399 399
         $label = '';
400
-        if ( $file && $file !== '' ) {
401
-            $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' );
400
+        if ($file && $file !== '') {
401
+            $label .= basename($file) . ($line ? '(' . $line . ')' : '');
402 402
         }
403 403
         
404
-        if ( $title && $title !== '' ) {
404
+        if ($title && $title !== '') {
405 405
             $label = $label !== '' ? $label . ' ' : '';
406 406
             $label .= $title . ' ';
407 407
         }
408 408
         
409
-        $label = $label !== '' ? trim( $label ) . ' : ' : '';
409
+        $label = $label !== '' ? trim($label) . ' : ' : '';
410 410
         
411
-        if ( is_array( $log ) || is_object( $log ) ) {
412
-            error_log( $label . print_r( $log, true ) );
411
+        if (is_array($log) || is_object($log)) {
412
+            error_log($label . print_r($log, true));
413 413
         } else {
414
-            error_log( $label . $log );
414
+            error_log($label . $log);
415 415
         }
416 416
         
417
-        if ( $exit ) {
417
+        if ($exit) {
418 418
             exit;
419 419
         }
420 420
     }
@@ -422,65 +422,65 @@  discard block
 block discarded – undo
422 422
 
423 423
 function wpinv_is_ajax_disabled() {
424 424
     $retval = false;
425
-    return apply_filters( 'wpinv_is_ajax_disabled', $retval );
425
+    return apply_filters('wpinv_is_ajax_disabled', $retval);
426 426
 }
427 427
 
428
-function wpinv_get_current_page_url( $nocache = false ) {
428
+function wpinv_get_current_page_url($nocache = false) {
429 429
     global $wp;
430 430
 
431
-    if ( get_option( 'permalink_structure' ) ) {
432
-        $base = trailingslashit( home_url( $wp->request ) );
431
+    if (get_option('permalink_structure')) {
432
+        $base = trailingslashit(home_url($wp->request));
433 433
     } else {
434
-        $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) );
435
-        $base = remove_query_arg( array( 'post_type', 'name' ), $base );
434
+        $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request)));
435
+        $base = remove_query_arg(array('post_type', 'name'), $base);
436 436
     }
437 437
 
438 438
     $scheme = is_ssl() ? 'https' : 'http';
439
-    $uri    = set_url_scheme( $base, $scheme );
439
+    $uri    = set_url_scheme($base, $scheme);
440 440
 
441
-    if ( is_front_page() ) {
442
-        $uri = home_url( '/' );
443
-    } elseif ( wpinv_is_checkout( array(), false ) ) {
441
+    if (is_front_page()) {
442
+        $uri = home_url('/');
443
+    } elseif (wpinv_is_checkout(array(), false)) {
444 444
         $uri = wpinv_get_checkout_uri();
445 445
     }
446 446
 
447
-    $uri = apply_filters( 'wpinv_get_current_page_url', $uri );
447
+    $uri = apply_filters('wpinv_get_current_page_url', $uri);
448 448
 
449
-    if ( $nocache ) {
450
-        $uri = wpinv_add_cache_busting( $uri );
449
+    if ($nocache) {
450
+        $uri = wpinv_add_cache_busting($uri);
451 451
     }
452 452
 
453 453
     return $uri;
454 454
 }
455 455
 
456 456
 function wpinv_get_php_arg_separator_output() {
457
-	return ini_get( 'arg_separator.output' );
457
+	return ini_get('arg_separator.output');
458 458
 }
459 459
 
460
-function wpinv_rgb_from_hex( $color ) {
461
-    $color = str_replace( '#', '', $color );
460
+function wpinv_rgb_from_hex($color) {
461
+    $color = str_replace('#', '', $color);
462 462
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
463
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
463
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
464 464
 
465 465
     $rgb      = array();
466
-    $rgb['R'] = hexdec( $color{0}.$color{1} );
467
-    $rgb['G'] = hexdec( $color{2}.$color{3} );
468
-    $rgb['B'] = hexdec( $color{4}.$color{5} );
466
+    $rgb['R'] = hexdec($color{0} . $color{1} );
467
+    $rgb['G'] = hexdec($color{2} . $color{3} );
468
+    $rgb['B'] = hexdec($color{4} . $color{5} );
469 469
 
470 470
     return $rgb;
471 471
 }
472 472
 
473
-function wpinv_hex_darker( $color, $factor = 30 ) {
474
-    $base  = wpinv_rgb_from_hex( $color );
473
+function wpinv_hex_darker($color, $factor = 30) {
474
+    $base  = wpinv_rgb_from_hex($color);
475 475
     $color = '#';
476 476
 
477
-    foreach ( $base as $k => $v ) {
477
+    foreach ($base as $k => $v) {
478 478
         $amount      = $v / 100;
479
-        $amount      = round( $amount * $factor );
479
+        $amount      = round($amount * $factor);
480 480
         $new_decimal = $v - $amount;
481 481
 
482
-        $new_hex_component = dechex( $new_decimal );
483
-        if ( strlen( $new_hex_component ) < 2 ) {
482
+        $new_hex_component = dechex($new_decimal);
483
+        if (strlen($new_hex_component) < 2) {
484 484
             $new_hex_component = "0" . $new_hex_component;
485 485
         }
486 486
         $color .= $new_hex_component;
@@ -489,18 +489,18 @@  discard block
 block discarded – undo
489 489
     return $color;
490 490
 }
491 491
 
492
-function wpinv_hex_lighter( $color, $factor = 30 ) {
493
-    $base  = wpinv_rgb_from_hex( $color );
492
+function wpinv_hex_lighter($color, $factor = 30) {
493
+    $base  = wpinv_rgb_from_hex($color);
494 494
     $color = '#';
495 495
 
496
-    foreach ( $base as $k => $v ) {
496
+    foreach ($base as $k => $v) {
497 497
         $amount      = 255 - $v;
498 498
         $amount      = $amount / 100;
499
-        $amount      = round( $amount * $factor );
499
+        $amount      = round($amount * $factor);
500 500
         $new_decimal = $v + $amount;
501 501
 
502
-        $new_hex_component = dechex( $new_decimal );
503
-        if ( strlen( $new_hex_component ) < 2 ) {
502
+        $new_hex_component = dechex($new_decimal);
503
+        if (strlen($new_hex_component) < 2) {
504 504
             $new_hex_component = "0" . $new_hex_component;
505 505
         }
506 506
         $color .= $new_hex_component;
@@ -509,22 +509,22 @@  discard block
 block discarded – undo
509 509
     return $color;
510 510
 }
511 511
 
512
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
513
-    $hex = str_replace( '#', '', $color );
512
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
513
+    $hex = str_replace('#', '', $color);
514 514
 
515
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
516
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
517
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
515
+    $c_r = hexdec(substr($hex, 0, 2));
516
+    $c_g = hexdec(substr($hex, 2, 2));
517
+    $c_b = hexdec(substr($hex, 4, 2));
518 518
 
519
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
519
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
520 520
 
521 521
     return $brightness > 155 ? $dark : $light;
522 522
 }
523 523
 
524
-function wpinv_format_hex( $hex ) {
525
-    $hex = trim( str_replace( '#', '', $hex ) );
524
+function wpinv_format_hex($hex) {
525
+    $hex = trim(str_replace('#', '', $hex));
526 526
 
527
-    if ( strlen( $hex ) == 3 ) {
527
+    if (strlen($hex) == 3) {
528 528
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
529 529
     }
530 530
 
@@ -544,12 +544,12 @@  discard block
 block discarded – undo
544 544
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
545 545
  * @return string
546 546
  */
547
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
548
-    if ( function_exists( 'mb_strimwidth' ) ) {
549
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
547
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
548
+    if (function_exists('mb_strimwidth')) {
549
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
550 550
     }
551 551
     
552
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
552
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
553 553
 }
554 554
 
555 555
 /**
@@ -561,28 +561,28 @@  discard block
 block discarded – undo
561 561
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
562 562
  * @return int Returns the number of characters in string.
563 563
  */
564
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
565
-    if ( function_exists( 'mb_strlen' ) ) {
566
-        return mb_strlen( $str, $encoding );
564
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
565
+    if (function_exists('mb_strlen')) {
566
+        return mb_strlen($str, $encoding);
567 567
     }
568 568
         
569
-    return strlen( $str );
569
+    return strlen($str);
570 570
 }
571 571
 
572
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
573
-    if ( function_exists( 'mb_strtolower' ) ) {
574
-        return mb_strtolower( $str, $encoding );
572
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
573
+    if (function_exists('mb_strtolower')) {
574
+        return mb_strtolower($str, $encoding);
575 575
     }
576 576
     
577
-    return strtolower( $str );
577
+    return strtolower($str);
578 578
 }
579 579
 
580
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
581
-    if ( function_exists( 'mb_strtoupper' ) ) {
582
-        return mb_strtoupper( $str, $encoding );
580
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
581
+    if (function_exists('mb_strtoupper')) {
582
+        return mb_strtoupper($str, $encoding);
583 583
     }
584 584
     
585
-    return strtoupper( $str );
585
+    return strtoupper($str);
586 586
 }
587 587
 
588 588
 /**
@@ -596,12 +596,12 @@  discard block
 block discarded – undo
596 596
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
597 597
  * @return int Returns the position of the first occurrence of search in the string.
598 598
  */
599
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
600
-    if ( function_exists( 'mb_strpos' ) ) {
601
-        return mb_strpos( $str, $find, $offset, $encoding );
599
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
600
+    if (function_exists('mb_strpos')) {
601
+        return mb_strpos($str, $find, $offset, $encoding);
602 602
     }
603 603
         
604
-    return strpos( $str, $find, $offset );
604
+    return strpos($str, $find, $offset);
605 605
 }
606 606
 
607 607
 /**
@@ -615,12 +615,12 @@  discard block
 block discarded – undo
615 615
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
616 616
  * @return int Returns the position of the last occurrence of search.
617 617
  */
618
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
619
-    if ( function_exists( 'mb_strrpos' ) ) {
620
-        return mb_strrpos( $str, $find, $offset, $encoding );
618
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
619
+    if (function_exists('mb_strrpos')) {
620
+        return mb_strrpos($str, $find, $offset, $encoding);
621 621
     }
622 622
         
623
-    return strrpos( $str, $find, $offset );
623
+    return strrpos($str, $find, $offset);
624 624
 }
625 625
 
626 626
 /**
@@ -635,16 +635,16 @@  discard block
 block discarded – undo
635 635
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
636 636
  * @return string
637 637
  */
638
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
639
-    if ( function_exists( 'mb_substr' ) ) {
640
-        if ( $length === null ) {
641
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
638
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
639
+    if (function_exists('mb_substr')) {
640
+        if ($length === null) {
641
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
642 642
         } else {
643
-            return mb_substr( $str, $start, $length, $encoding );
643
+            return mb_substr($str, $start, $length, $encoding);
644 644
         }
645 645
     }
646 646
         
647
-    return substr( $str, $start, $length );
647
+    return substr($str, $start, $length);
648 648
 }
649 649
 
650 650
 /**
@@ -656,48 +656,48 @@  discard block
 block discarded – undo
656 656
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
657 657
  * @return string The width of string.
658 658
  */
659
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
660
-    if ( function_exists( 'mb_strwidth' ) ) {
661
-        return mb_strwidth( $str, $encoding );
659
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
660
+    if (function_exists('mb_strwidth')) {
661
+        return mb_strwidth($str, $encoding);
662 662
     }
663 663
     
664
-    return wpinv_utf8_strlen( $str, $encoding );
664
+    return wpinv_utf8_strlen($str, $encoding);
665 665
 }
666 666
 
667
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
668
-    if ( function_exists( 'mb_strlen' ) ) {
669
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
667
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
668
+    if (function_exists('mb_strlen')) {
669
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
670 670
         $str_end = "";
671 671
         
672
-        if ( $lower_str_end ) {
673
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
672
+        if ($lower_str_end) {
673
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
674 674
         } else {
675
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
675
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
676 676
         }
677 677
 
678 678
         return $first_letter . $str_end;
679 679
     }
680 680
     
681
-    return ucfirst( $str );
681
+    return ucfirst($str);
682 682
 }
683 683
 
684
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
685
-    if ( function_exists( 'mb_convert_case' ) ) {
686
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
684
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
685
+    if (function_exists('mb_convert_case')) {
686
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
687 687
     }
688 688
     
689
-    return ucwords( $str );
689
+    return ucwords($str);
690 690
 }
691 691
 
692
-function wpinv_period_in_days( $period, $unit ) {
693
-    $period = absint( $period );
692
+function wpinv_period_in_days($period, $unit) {
693
+    $period = absint($period);
694 694
     
695
-    if ( $period > 0 ) {
696
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
695
+    if ($period > 0) {
696
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
697 697
             $period = $period * 7;
698
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
698
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
699 699
             $period = $period * 30;
700
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
700
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
701 701
             $period = $period * 365;
702 702
         }
703 703
     }
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Spacing   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 class WPInv_Plugin {
15 15
     private static $instance;
16 16
     
17 17
     public static function run() {
18
-        if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) {
18
+        if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) {
19 19
             self::$instance = new WPInv_Plugin;
20 20
             self::$instance->includes();
21 21
             self::$instance->actions();
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
             self::$instance->reports    = new WPInv_Reports();
24 24
         }
25 25
         
26
-        do_action( 'wpinv_loaded' );
26
+        do_action('wpinv_loaded');
27 27
         
28 28
         return self::$instance;
29 29
     }
@@ -33,31 +33,31 @@  discard block
 block discarded – undo
33 33
     }
34 34
     
35 35
     public function define_constants() {
36
-        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
37
-        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
36
+        define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
37
+        define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
38 38
     }
39 39
     
40 40
     private function actions() {
41 41
         /* Internationalize the text strings used. */
42
-        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
42
+        add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
43 43
         
44 44
         /* Perform actions on admin initialization. */
45
-        add_action( 'admin_init', array( &$this, 'admin_init') );
46
-        add_action( 'init', array( &$this, 'init' ), 3 );
47
-        add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) );
48
-        add_action( 'init', array( &$this, 'wpinv_actions' ) );
45
+        add_action('admin_init', array(&$this, 'admin_init'));
46
+        add_action('init', array(&$this, 'init'), 3);
47
+        add_action('init', array('WPInv_Shortcodes', 'init'));
48
+        add_action('init', array(&$this, 'wpinv_actions'));
49 49
         
50
-        if ( class_exists( 'BuddyPress' ) ) {
51
-            add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
50
+        if (class_exists('BuddyPress')) {
51
+            add_action('bp_include', array(&$this, 'bp_invoicing_init'));
52 52
         }
53 53
 
54
-        add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
54
+        add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts'));
55 55
         
56
-        if ( is_admin() ) {
57
-            add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
58
-            add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) );
56
+        if (is_admin()) {
57
+            add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
58
+            add_action('admin_body_class', array(&$this, 'admin_body_class'));
59 59
         } else {
60
-            add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
60
+            add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
61 61
         }
62 62
         
63 63
         /**
@@ -67,9 +67,9 @@  discard block
 block discarded – undo
67 67
          *
68 68
          * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference.
69 69
          */
70
-        do_action_ref_array( 'wpinv_actions', array( &$this ) );
70
+        do_action_ref_array('wpinv_actions', array(&$this));
71 71
 
72
-        add_action( 'admin_init', array( &$this, 'activation_redirect') );
72
+        add_action('admin_init', array(&$this, 'activation_redirect'));
73 73
     }
74 74
     
75 75
     public function plugins_loaded() {
@@ -83,193 +83,193 @@  discard block
 block discarded – undo
83 83
      * @since 1.0
84 84
      */
85 85
     public function load_textdomain() {
86
-        $locale = apply_filters( 'plugin_locale', get_locale(), 'invoicing' );
86
+        $locale = apply_filters('plugin_locale', get_locale(), 'invoicing');
87 87
         
88
-        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
89
-        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
88
+        load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo');
89
+        load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages');
90 90
         
91 91
         /**
92 92
          * Define language constants.
93 93
          */
94
-        require_once( WPINV_PLUGIN_DIR . 'language.php' );
94
+        require_once(WPINV_PLUGIN_DIR . 'language.php');
95 95
     }
96 96
         
97 97
     public function includes() {
98 98
         global $wpinv_options;
99 99
         
100
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
100
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php');
101 101
         $wpinv_options = wpinv_get_settings();
102 102
         
103
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' );
104
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
105
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
106
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
107
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
108
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
109
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
110
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' );
111
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
112
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
113
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
114
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
115
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
116
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php' );
117
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' );
103
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php');
104
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php');
105
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php');
106
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php');
107
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php');
108
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php');
109
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php');
110
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php');
111
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php');
112
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php');
113
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php');
114
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php');
115
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php');
116
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php');
117
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php');
118 118
         //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
119 119
         //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
120
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' );
120
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php');
121 121
         //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscription.php' );
122
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' );
123
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' );
124
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' );
125
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
126
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
127
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
128
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' );
129
-        if ( !class_exists( 'Geodir_EUVat' ) ) {
130
-            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
122
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php');
123
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php');
124
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php');
125
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php');
126
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php');
127
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php');
128
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php');
129
+        if (!class_exists('Geodir_EUVat')) {
130
+            require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php');
131 131
         }
132 132
         
133
-        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
134
-        if ( !empty( $gateways ) ) {
135
-            foreach ( $gateways as $gateway ) {
136
-                if ( $gateway == 'manual' ) {
133
+        $gateways = array_keys(wpinv_get_enabled_payment_gateways());
134
+        if (!empty($gateways)) {
135
+            foreach ($gateways as $gateway) {
136
+                if ($gateway == 'manual') {
137 137
                     continue;
138 138
                 }
139 139
                 
140 140
                 $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
141 141
                 
142
-                if ( file_exists( $gateway_file ) ) {
143
-                    require_once( $gateway_file );
142
+                if (file_exists($gateway_file)) {
143
+                    require_once($gateway_file);
144 144
                 }
145 145
             }
146 146
         }
147
-        require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' );
147
+        require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php');
148 148
         
149
-        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
150
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
151
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
152
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' );
149
+        if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
150
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php');
151
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php');
152
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php');
153 153
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' );
154
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' );
155
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' );
156
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
157
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' );
158
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
154
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php');
155
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php');
156
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php');
157
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php');
158
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php');
159 159
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
160 160
         }
161 161
         
162 162
         // include css inliner
163
-        if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
164
-            include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
163
+        if (!class_exists('Emogrifier') && class_exists('DOMDocument')) {
164
+            include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php');
165 165
         }
166 166
         
167
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
167
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php');
168 168
     }
169 169
     
170 170
     public function init() {
171 171
     }
172 172
     
173 173
     public function admin_init() {
174
-        if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
174
+        if (!(defined('DOING_AJAX') && DOING_AJAX)) {
175 175
         }
176 176
         
177
-        add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) );
177
+        add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php'));
178 178
     }
179 179
 
180 180
     public function activation_redirect() {
181 181
         // Bail if no activation redirect
182
-        if ( !get_transient( '_wpinv_activation_redirect' ) ) {
182
+        if (!get_transient('_wpinv_activation_redirect')) {
183 183
             return;
184 184
         }
185 185
 
186 186
         // Delete the redirect transient
187
-        delete_transient( '_wpinv_activation_redirect' );
187
+        delete_transient('_wpinv_activation_redirect');
188 188
 
189 189
         // Bail if activating from network, or bulk
190
-        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
190
+        if (is_network_admin() || isset($_GET['activate-multi'])) {
191 191
             return;
192 192
         }
193 193
 
194
-        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
194
+        wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
195 195
         exit;
196 196
     }
197 197
     
198 198
     public function enqueue_scripts() {
199
-        $suffix       = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
199
+        $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
200 200
         
201
-        wp_deregister_style( 'font-awesome' );
202
-        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
203
-        wp_enqueue_style( 'font-awesome' );
201
+        wp_deregister_style('font-awesome');
202
+        wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0');
203
+        wp_enqueue_style('font-awesome');
204 204
         
205
-        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION );
206
-        wp_enqueue_style( 'wpinv_front_style' );
205
+        wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION);
206
+        wp_enqueue_style('wpinv_front_style');
207 207
                
208 208
         // Register scripts
209
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
210
-        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array( 'jquery', 'wpinv-vat-script' ),  WPINV_VERSION );
209
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
210
+        wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array('jquery', 'wpinv-vat-script'), WPINV_VERSION);
211 211
         
212 212
         $localize                         = array();
213
-        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
214
-        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
213
+        $localize['ajax_url']             = admin_url('admin-ajax.php');
214
+        $localize['nonce']                = wp_create_nonce('wpinv-nonce');
215 215
         $localize['currency_symbol']      = wpinv_currency_symbol();
216 216
         $localize['currency_pos']         = wpinv_currency_position();
217 217
         $localize['thousand_sep']         = wpinv_thousands_separator();
218 218
         $localize['decimal_sep']          = wpinv_decimal_separator();
219 219
         $localize['decimals']             = wpinv_decimals();
220 220
         
221
-        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
221
+        $localize = apply_filters('wpinv_front_js_localize', $localize);
222 222
         
223
-        wp_enqueue_script( 'jquery-blockui' );
224
-        wp_enqueue_script( 'wpinv-front-script' );
225
-        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
223
+        wp_enqueue_script('jquery-blockui');
224
+        wp_enqueue_script('wpinv-front-script');
225
+        wp_localize_script('wpinv-front-script', 'WPInv', $localize);
226 226
     }
227 227
     
228 228
     public function admin_enqueue_scripts() {
229 229
         global $post, $pagenow;
230 230
         
231 231
         $post_type  = wpinv_admin_post_type();
232
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
232
+        $suffix     = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
233 233
         
234
-        wp_deregister_style( 'font-awesome' );
235
-        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
236
-        wp_enqueue_style( 'font-awesome' );
234
+        wp_deregister_style('font-awesome');
235
+        wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0');
236
+        wp_enqueue_style('font-awesome');
237 237
         
238
-        wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
239
-        wp_enqueue_style( 'jquery-ui-css' );
238
+        wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16');
239
+        wp_enqueue_style('jquery-ui-css');
240 240
         
241
-        wp_register_style( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2' );
242
-        wp_enqueue_style( 'jquery-chosen' );
241
+        wp_register_style('jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2');
242
+        wp_enqueue_style('jquery-chosen');
243 243
 
244
-        wp_register_script( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.6.2' );
245
-        wp_enqueue_script( 'jquery-chosen' );
244
+        wp_register_script('jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array('jquery'), '1.6.2');
245
+        wp_enqueue_script('jquery-chosen');
246 246
         
247
-        wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
248
-        wp_enqueue_style( 'wpinv_meta_box_style' );
247
+        wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
248
+        wp_enqueue_style('wpinv_meta_box_style');
249 249
         
250
-        wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION );
251
-        wp_enqueue_style( 'wpinv_admin_style' );
250
+        wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION);
251
+        wp_enqueue_style('wpinv_admin_style');
252 252
         
253
-        if ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
254
-            wp_enqueue_script( 'jquery-ui-datepicker' );
253
+        if ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
254
+            wp_enqueue_script('jquery-ui-datepicker');
255 255
         }
256 256
 
257
-        wp_enqueue_style( 'wp-color-picker' );
258
-        wp_enqueue_script( 'wp-color-picker' );
257
+        wp_enqueue_style('wp-color-picker');
258
+        wp_enqueue_script('wp-color-picker');
259 259
         
260
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
260
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
261 261
         
262
-        wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui' ),  WPINV_VERSION );
263
-        wp_enqueue_script( 'wpinv-admin-script' );
262
+        wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui'), WPINV_VERSION);
263
+        wp_enqueue_script('wpinv-admin-script');
264 264
         
265 265
         $localize                               = array();
266
-        $localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
267
-        $localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
268
-        $localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
269
-        $localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
270
-        $localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
271
-        $localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
272
-        $localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
266
+        $localize['ajax_url']                   = admin_url('admin-ajax.php');
267
+        $localize['post_ID']                    = isset($post->ID) ? $post->ID : '';
268
+        $localize['wpinv_nonce']                = wp_create_nonce('wpinv-nonce');
269
+        $localize['add_invoice_note_nonce']     = wp_create_nonce('add-invoice-note');
270
+        $localize['delete_invoice_note_nonce']  = wp_create_nonce('delete-invoice-note');
271
+        $localize['invoice_item_nonce']         = wp_create_nonce('invoice-item');
272
+        $localize['billing_details_nonce']      = wp_create_nonce('get-billing-details');
273 273
         $localize['tax']                        = wpinv_tax_amount();
274 274
         $localize['discount']                   = wpinv_discount_amount();
275 275
         $localize['currency_symbol']            = wpinv_currency_symbol();
@@ -277,55 +277,55 @@  discard block
 block discarded – undo
277 277
         $localize['thousand_sep']               = wpinv_thousands_separator();
278 278
         $localize['decimal_sep']                = wpinv_decimal_separator();
279 279
         $localize['decimals']                   = wpinv_decimals();
280
-        $localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
281
-        $localize['status_publish']             = wpinv_status_nicename( 'publish' );
282
-        $localize['status_pending']             = wpinv_status_nicename( 'pending' );
283
-        $localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
284
-        $localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
285
-        $localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
286
-        $localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
287
-        $localize['confirmCalcTotals']          = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' );
288
-        $localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
289
-        $localize['hasGD']                      = wpinv_gd_active();;
280
+        $localize['save_invoice']               = __('Save Invoice', 'invoicing');
281
+        $localize['status_publish']             = wpinv_status_nicename('publish');
282
+        $localize['status_pending']             = wpinv_status_nicename('pending');
283
+        $localize['delete_tax_rate']            = __('Are you sure you wish to delete this tax rate?', 'invoicing');
284
+        $localize['OneItemMin']                 = __('Invoice must contain at least one item', 'invoicing');
285
+        $localize['DeleteInvoiceItem']          = __('Are you sure you wish to delete this item?', 'invoicing');
286
+        $localize['FillBillingDetails']         = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing');
287
+        $localize['confirmCalcTotals']          = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing');
288
+        $localize['AreYouSure']                 = __('Are you sure?', 'invoicing');
289
+        $localize['hasGD']                      = wpinv_gd_active(); ;
290 290
         $localize['hasPM']                      = wpinv_pm_active();
291
-        $localize['emptyInvoice']               = __( 'Add atleast one item to save invoice!', 'invoicing' );
292
-        $localize['deletePackage']              = __( 'GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing' );
293
-        $localize['deletePackages']             = __( 'GD package items should be deleted from GD payment manager only', 'invoicing' );
294
-        $localize['deleteInvoiceFirst']         = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
291
+        $localize['emptyInvoice']               = __('Add atleast one item to save invoice!', 'invoicing');
292
+        $localize['deletePackage']              = __('GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing');
293
+        $localize['deletePackages']             = __('GD package items should be deleted from GD payment manager only', 'invoicing');
294
+        $localize['deleteInvoiceFirst']         = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing');
295 295
         
296
-        wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
296
+        wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize);
297 297
     }
298 298
     
299
-    public function admin_body_class( $classes ) {
299
+    public function admin_body_class($classes) {
300 300
         global $pagenow;
301 301
         
302
-        $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
302
+        $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
303 303
 
304 304
         $add_class = false;
305
-        if ( $pagenow == 'admin.php' && $page ) {
306
-            $add_class = strpos( $page, 'wpinv-' );
305
+        if ($pagenow == 'admin.php' && $page) {
306
+            $add_class = strpos($page, 'wpinv-');
307 307
         }
308 308
         
309 309
         $settings_class = array();
310
-        if ( $page == 'wpinv-settings' ) {
311
-            if ( !empty( $_REQUEST['tab'] ) ) {
312
-                $settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
310
+        if ($page == 'wpinv-settings') {
311
+            if (!empty($_REQUEST['tab'])) {
312
+                $settings_class[] = sanitize_text_field($_REQUEST['tab']);
313 313
             }
314 314
             
315
-            if ( !empty( $_REQUEST['section'] ) ) {
316
-                $settings_class[] = sanitize_text_field( $_REQUEST['section'] );
315
+            if (!empty($_REQUEST['section'])) {
316
+                $settings_class[] = sanitize_text_field($_REQUEST['section']);
317 317
             }
318 318
             
319
-            $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
319
+            $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main';
320 320
         }
321 321
         
322
-        if ( !empty( $settings_class ) ) {
323
-            $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
322
+        if (!empty($settings_class)) {
323
+            $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-'));
324 324
         }
325 325
         
326 326
         $post_type = wpinv_admin_post_type();
327 327
         
328
-        if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
328
+        if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) {
329 329
             return $classes .= ' wpinv';
330 330
         } else {
331 331
             return $classes;
@@ -337,26 +337,26 @@  discard block
 block discarded – undo
337 337
     public function admin_print_scripts_edit_php() {
338 338
         $post_type = wpinv_admin_post_type();
339 339
         
340
-        if ( $post_type == 'wpi_item' ) {
341
-            wp_enqueue_script( 'wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array( 'jquery', 'inline-edit-post' ), '', true );
340
+        if ($post_type == 'wpi_item') {
341
+            wp_enqueue_script('wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array('jquery', 'inline-edit-post'), '', true);
342 342
         }
343 343
     }
344 344
     
345 345
     public function wpinv_actions() {
346
-        if ( isset( $_REQUEST['wpi_action'] ) ) {
347
-            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
346
+        if (isset($_REQUEST['wpi_action'])) {
347
+            do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
348 348
         }
349 349
     }
350 350
     
351
-    public function pre_get_posts( $wp_query ) {
352
-        if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
353
-            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
351
+    public function pre_get_posts($wp_query) {
352
+        if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) {
353
+            $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses());
354 354
         }
355 355
         
356 356
         return $wp_query;
357 357
     }
358 358
     
359 359
     public function bp_invoicing_init() {
360
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
360
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php');
361 361
     }
362 362
 }
363 363
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/register-settings.php 1 patch
Spacing   +484 added lines, -484 removed lines patch added patch discarded remove patch
@@ -1,66 +1,66 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7
-function wpinv_get_option( $key = '', $default = false ) {
7
+function wpinv_get_option($key = '', $default = false) {
8 8
     global $wpinv_options;
9 9
 
10
-    $value = isset( $wpinv_options[ $key ] ) ? $wpinv_options[ $key ] : $default;
11
-    $value = apply_filters( 'wpinv_get_option', $value, $key, $default );
10
+    $value = isset($wpinv_options[$key]) ? $wpinv_options[$key] : $default;
11
+    $value = apply_filters('wpinv_get_option', $value, $key, $default);
12 12
 
13
-    return apply_filters( 'wpinv_get_option_' . $key, $value, $key, $default );
13
+    return apply_filters('wpinv_get_option_' . $key, $value, $key, $default);
14 14
 }
15 15
 
16
-function wpinv_update_option( $key = '', $value = false ) {
16
+function wpinv_update_option($key = '', $value = false) {
17 17
     // If no key, exit
18
-    if ( empty( $key ) ) {
18
+    if (empty($key)) {
19 19
         return false;
20 20
     }
21 21
 
22
-    if ( empty( $value ) ) {
23
-        $remove_option = wpinv_delete_option( $key );
22
+    if (empty($value)) {
23
+        $remove_option = wpinv_delete_option($key);
24 24
         return $remove_option;
25 25
     }
26 26
 
27 27
     // First let's grab the current settings
28
-    $options = get_option( 'wpinv_settings' );
28
+    $options = get_option('wpinv_settings');
29 29
 
30 30
     // Let's let devs alter that value coming in
31
-    $value = apply_filters( 'wpinv_update_option', $value, $key );
31
+    $value = apply_filters('wpinv_update_option', $value, $key);
32 32
 
33 33
     // Next let's try to update the value
34
-    $options[ $key ] = $value;
35
-    $did_update = update_option( 'wpinv_settings', $options );
34
+    $options[$key] = $value;
35
+    $did_update = update_option('wpinv_settings', $options);
36 36
 
37 37
     // If it updated, let's update the global variable
38
-    if ( $did_update ) {
38
+    if ($did_update) {
39 39
         global $wpinv_options;
40
-        $wpinv_options[ $key ] = $value;
40
+        $wpinv_options[$key] = $value;
41 41
     }
42 42
 
43 43
     return $did_update;
44 44
 }
45 45
 
46
-function wpinv_delete_option( $key = '' ) {
46
+function wpinv_delete_option($key = '') {
47 47
     // If no key, exit
48
-    if ( empty( $key ) ) {
48
+    if (empty($key)) {
49 49
         return false;
50 50
     }
51 51
 
52 52
     // First let's grab the current settings
53
-    $options = get_option( 'wpinv_settings' );
53
+    $options = get_option('wpinv_settings');
54 54
 
55 55
     // Next let's try to update the value
56
-    if( isset( $options[ $key ] ) ) {
57
-        unset( $options[ $key ] );
56
+    if (isset($options[$key])) {
57
+        unset($options[$key]);
58 58
     }
59 59
 
60
-    $did_update = update_option( 'wpinv_settings', $options );
60
+    $did_update = update_option('wpinv_settings', $options);
61 61
 
62 62
     // If it updated, let's update the global variable
63
-    if ( $did_update ){
63
+    if ($did_update) {
64 64
         global $wpinv_options;
65 65
         $wpinv_options = $options;
66 66
     }
@@ -69,37 +69,37 @@  discard block
 block discarded – undo
69 69
 }
70 70
 
71 71
 function wpinv_get_settings() {
72
-    $settings = get_option( 'wpinv_settings' );
72
+    $settings = get_option('wpinv_settings');
73 73
 
74
-    if ( empty( $settings ) ) {
74
+    if (empty($settings)) {
75 75
         // Update old settings with new single option
76
-        $general_settings   = is_array( get_option( 'wpinv_settings_general' ) )    ? get_option( 'wpinv_settings_general' )    : array();
77
-        $gateways_settings  = is_array( get_option( 'wpinv_settings_gateways' ) )   ? get_option( 'wpinv_settings_gateways' )   : array();
78
-        $email_settings     = is_array( get_option( 'wpinv_settings_emails' ) )     ? get_option( 'wpinv_settings_emails' )     : array();
79
-        $tax_settings       = is_array( get_option( 'wpinv_settings_taxes' ) )      ? get_option( 'wpinv_settings_taxes' )      : array();
80
-        $misc_settings      = is_array( get_option( 'wpinv_settings_misc' ) )       ? get_option( 'wpinv_settings_misc' )       : array();
81
-        $tool_settings      = is_array( get_option( 'wpinv_settings_tools' ) )      ? get_option( 'wpinv_settings_tools' )      : array();
76
+        $general_settings   = is_array(get_option('wpinv_settings_general')) ? get_option('wpinv_settings_general') : array();
77
+        $gateways_settings  = is_array(get_option('wpinv_settings_gateways')) ? get_option('wpinv_settings_gateways') : array();
78
+        $email_settings     = is_array(get_option('wpinv_settings_emails')) ? get_option('wpinv_settings_emails') : array();
79
+        $tax_settings       = is_array(get_option('wpinv_settings_taxes')) ? get_option('wpinv_settings_taxes') : array();
80
+        $misc_settings      = is_array(get_option('wpinv_settings_misc')) ? get_option('wpinv_settings_misc') : array();
81
+        $tool_settings      = is_array(get_option('wpinv_settings_tools')) ? get_option('wpinv_settings_tools') : array();
82 82
 
83
-        $settings = array_merge( $general_settings, $gateways_settings, $tax_settings, $tool_settings );
83
+        $settings = array_merge($general_settings, $gateways_settings, $tax_settings, $tool_settings);
84 84
 
85
-        update_option( 'wpinv_settings', $settings );
85
+        update_option('wpinv_settings', $settings);
86 86
 
87 87
     }
88
-    return apply_filters( 'wpinv_get_settings', $settings );
88
+    return apply_filters('wpinv_get_settings', $settings);
89 89
 }
90 90
 
91 91
 function wpinv_register_settings() {
92
-    if ( false == get_option( 'wpinv_settings' ) ) {
93
-        add_option( 'wpinv_settings' );
92
+    if (false == get_option('wpinv_settings')) {
93
+        add_option('wpinv_settings');
94 94
     }
95 95
     
96 96
     $register_settings = wpinv_get_registered_settings();
97 97
     
98
-    foreach ( $register_settings as $tab => $sections ) {
99
-        foreach ( $sections as $section => $settings) {
98
+    foreach ($register_settings as $tab => $sections) {
99
+        foreach ($sections as $section => $settings) {
100 100
             // Check for backwards compatibility
101
-            $section_tabs = wpinv_get_settings_tab_sections( $tab );
102
-            if ( ! is_array( $section_tabs ) || ! array_key_exists( $section, $section_tabs ) ) {
101
+            $section_tabs = wpinv_get_settings_tab_sections($tab);
102
+            if (!is_array($section_tabs) || !array_key_exists($section, $section_tabs)) {
103 103
                 $section = 'main';
104 104
                 $settings = $sections;
105 105
             }
@@ -111,42 +111,42 @@  discard block
 block discarded – undo
111 111
                 'wpinv_settings_' . $tab . '_' . $section
112 112
             );
113 113
 
114
-            foreach ( $settings as $option ) {
114
+            foreach ($settings as $option) {
115 115
                 // For backwards compatibility
116
-                if ( empty( $option['id'] ) ) {
116
+                if (empty($option['id'])) {
117 117
                     continue;
118 118
                 }
119 119
 
120
-                $name = isset( $option['name'] ) ? $option['name'] : '';
120
+                $name = isset($option['name']) ? $option['name'] : '';
121 121
 
122 122
                 add_settings_field(
123 123
                     'wpinv_settings[' . $option['id'] . ']',
124 124
                     $name,
125
-                    function_exists( 'wpinv_' . $option['type'] . '_callback' ) ? 'wpinv_' . $option['type'] . '_callback' : 'wpinv_missing_callback',
125
+                    function_exists('wpinv_' . $option['type'] . '_callback') ? 'wpinv_' . $option['type'] . '_callback' : 'wpinv_missing_callback',
126 126
                     'wpinv_settings_' . $tab . '_' . $section,
127 127
                     'wpinv_settings_' . $tab . '_' . $section,
128 128
                     array(
129 129
                         'section'     => $section,
130
-                        'id'          => isset( $option['id'] )          ? $option['id']          : null,
131
-                        'desc'        => ! empty( $option['desc'] )      ? $option['desc']        : '',
132
-                        'name'        => isset( $option['name'] )        ? $option['name']        : null,
133
-                        'size'        => isset( $option['size'] )        ? $option['size']        : null,
134
-                        'options'     => isset( $option['options'] )     ? $option['options']     : '',
135
-                        'selected'    => isset( $option['selected'] )    ? $option['selected']    : null,
136
-                        'std'         => isset( $option['std'] )         ? $option['std']         : '',
137
-                        'min'         => isset( $option['min'] )         ? $option['min']         : null,
138
-                        'max'         => isset( $option['max'] )         ? $option['max']         : null,
139
-                        'step'        => isset( $option['step'] )        ? $option['step']        : null,
140
-                        'chosen'      => isset( $option['chosen'] )      ? $option['chosen']      : null,
141
-                        'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : null,
142
-                        'allow_blank' => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true,
143
-                        'readonly'    => isset( $option['readonly'] )    ? $option['readonly']    : false,
144
-                        'faux'        => isset( $option['faux'] )        ? $option['faux']        : false,
145
-                        'onchange'    => !empty( $option['onchange'] )   ? $option['onchange']    : '',
146
-                        'custom'      => !empty( $option['custom'] )     ? $option['custom']      : '',
147
-                        'class'       =>  !empty( $option['class'] )     ? $option['class']      : '',
148
-                        'cols'        => !empty( $option['cols'] ) && (int)$option['cols'] > 0 ? (int)$option['cols'] : 50,
149
-                        'rows'        => !empty( $option['rows'] ) && (int)$option['rows'] > 0 ? (int)$option['rows'] : 5,
130
+                        'id'          => isset($option['id']) ? $option['id'] : null,
131
+                        'desc'        => !empty($option['desc']) ? $option['desc'] : '',
132
+                        'name'        => isset($option['name']) ? $option['name'] : null,
133
+                        'size'        => isset($option['size']) ? $option['size'] : null,
134
+                        'options'     => isset($option['options']) ? $option['options'] : '',
135
+                        'selected'    => isset($option['selected']) ? $option['selected'] : null,
136
+                        'std'         => isset($option['std']) ? $option['std'] : '',
137
+                        'min'         => isset($option['min']) ? $option['min'] : null,
138
+                        'max'         => isset($option['max']) ? $option['max'] : null,
139
+                        'step'        => isset($option['step']) ? $option['step'] : null,
140
+                        'chosen'      => isset($option['chosen']) ? $option['chosen'] : null,
141
+                        'placeholder' => isset($option['placeholder']) ? $option['placeholder'] : null,
142
+                        'allow_blank' => isset($option['allow_blank']) ? $option['allow_blank'] : true,
143
+                        'readonly'    => isset($option['readonly']) ? $option['readonly'] : false,
144
+                        'faux'        => isset($option['faux']) ? $option['faux'] : false,
145
+                        'onchange'    => !empty($option['onchange']) ? $option['onchange'] : '',
146
+                        'custom'      => !empty($option['custom']) ? $option['custom'] : '',
147
+                        'class'       =>  !empty($option['class']) ? $option['class'] : '',
148
+                        'cols'        => !empty($option['cols']) && (int)$option['cols'] > 0 ? (int)$option['cols'] : 50,
149
+                        'rows'        => !empty($option['rows']) && (int)$option['rows'] > 0 ? (int)$option['rows'] : 5,
150 150
                     )
151 151
                 );
152 152
             }
@@ -154,21 +154,21 @@  discard block
 block discarded – undo
154 154
     }
155 155
 
156 156
     // Creates our settings in the options table
157
-    register_setting( 'wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize' );
157
+    register_setting('wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize');
158 158
 }
159
-add_action( 'admin_init', 'wpinv_register_settings' );
159
+add_action('admin_init', 'wpinv_register_settings');
160 160
 
161 161
 function wpinv_get_registered_settings() {
162
-    $pages = wpinv_get_pages( true );
162
+    $pages = wpinv_get_pages(true);
163 163
     
164 164
     $due_payment_options       = array();
165
-    $due_payment_options[0]    = __( 'Now', 'invoicing' );
166
-    for ( $i = 1; $i <= 30; $i++ ) {
165
+    $due_payment_options[0]    = __('Now', 'invoicing');
166
+    for ($i = 1; $i <= 30; $i++) {
167 167
         $due_payment_options[$i] = $i;
168 168
     }
169 169
     
170 170
     $invoice_number_padd_options = array();
171
-    for ( $i = 0; $i <= 20; $i++ ) {
171
+    for ($i = 0; $i <= 20; $i++) {
172 172
         $invoice_number_padd_options[$i] = $i;
173 173
     }
174 174
     
@@ -177,141 +177,141 @@  discard block
 block discarded – undo
177 177
     $alert_wrapper_start = '<p style="color: #F00">';
178 178
     $alert_wrapper_close = '</p>';
179 179
     $wpinv_settings = array(
180
-        'general' => apply_filters( 'wpinv_settings_general',
180
+        'general' => apply_filters('wpinv_settings_general',
181 181
             array(
182 182
                 'main' => array(
183 183
                     'location_settings' => array(
184 184
                         'id'   => 'location_settings',
185
-                        'name' => '<h3>' . __( 'Default Location', 'invoicing' ) . '</h3>',
185
+                        'name' => '<h3>' . __('Default Location', 'invoicing') . '</h3>',
186 186
                         'desc' => '',
187 187
                         'type' => 'header',
188 188
                     ),
189 189
                     'default_country' => array(
190 190
                         'id'      => 'default_country',
191
-                        'name'    => __( 'Default Country', 'invoicing' ),
192
-                        'desc'    => __( 'Where does your store operate from?', 'invoicing' ),
191
+                        'name'    => __('Default Country', 'invoicing'),
192
+                        'desc'    => __('Where does your store operate from?', 'invoicing'),
193 193
                         'type'    => 'select',
194 194
                         'options' => wpinv_get_country_list(),
195 195
                         'std'     => 'GB',
196 196
                         'chosen'  => true,
197
-                        'placeholder' => __( 'Select a country', 'invoicing' ),
197
+                        'placeholder' => __('Select a country', 'invoicing'),
198 198
                     ),
199 199
                     'default_state' => array(
200 200
                         'id'      => 'default_state',
201
-                        'name'    => __( 'Default State / Province', 'invoicing' ),
202
-                        'desc'    => __( 'What state / province does your store operate from?', 'invoicing' ),
201
+                        'name'    => __('Default State / Province', 'invoicing'),
202
+                        'desc'    => __('What state / province does your store operate from?', 'invoicing'),
203 203
                         'type'    => 'country_states',
204
-                        'placeholder' => __( 'Select a state', 'invoicing' ),
204
+                        'placeholder' => __('Select a state', 'invoicing'),
205 205
                     ),
206 206
                     'store_name' => array(
207 207
                         'id'   => 'store_name',
208
-                        'name' => __( 'Store Name', 'invoicing' ),
209
-                        'desc' => __( 'Store name to print on invoices.', 'invoicing' ),
208
+                        'name' => __('Store Name', 'invoicing'),
209
+                        'desc' => __('Store name to print on invoices.', 'invoicing'),
210 210
                         'std'     => get_option('blogname'),
211 211
                         'type' => 'text',
212 212
                     ),
213 213
                     'logo' => array(
214 214
                         'id'   => 'logo',
215
-                        'name' => __( 'Logo URL', 'invoicing' ),
216
-                        'desc' => __( 'Store logo to print on invoices.', 'invoicing' ),
215
+                        'name' => __('Logo URL', 'invoicing'),
216
+                        'desc' => __('Store logo to print on invoices.', 'invoicing'),
217 217
                         'type' => 'text',
218 218
                     ),
219 219
                     'store_address' => array(
220 220
                         'id'   => 'store_address',
221
-                        'name' => __( 'Store Address', 'invoicing' ),
222
-                        'desc' => __( 'Enter the store address to display on invoice', 'invoicing' ),
221
+                        'name' => __('Store Address', 'invoicing'),
222
+                        'desc' => __('Enter the store address to display on invoice', 'invoicing'),
223 223
                         'type' => 'textarea',
224 224
                     ),
225 225
                     'page_settings' => array(
226 226
                         'id'   => 'page_settings',
227
-                        'name' => '<h3>' . __( 'Page Settings', 'invoicing' ) . '</h3>',
227
+                        'name' => '<h3>' . __('Page Settings', 'invoicing') . '</h3>',
228 228
                         'desc' => '',
229 229
                         'type' => 'header',
230 230
                     ),
231 231
                     'checkout_page' => array(
232 232
                         'id'          => 'checkout_page',
233
-                        'name'        => __( 'Checkout Page', 'invoicing' ),
234
-                        'desc'        => __( 'This is the checkout page where buyers will complete their payments. The <b>[wpinv_checkout]</b> short code must be on this page.', 'invoicing' ),
233
+                        'name'        => __('Checkout Page', 'invoicing'),
234
+                        'desc'        => __('This is the checkout page where buyers will complete their payments. The <b>[wpinv_checkout]</b> short code must be on this page.', 'invoicing'),
235 235
                         'type'        => 'select',
236 236
                         'options'     => $pages,
237 237
                         'chosen'      => true,
238
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
238
+                        'placeholder' => __('Select a page', 'invoicing'),
239 239
                     ),
240 240
                     'success_page' => array(
241 241
                         'id'          => 'success_page',
242
-                        'name'        => __( 'Success Page', 'invoicing' ),
243
-                        'desc'        => __( 'This is the page buyers are sent to after completing their payments. The <b>[wpinv_receipt]</b> short code should be on this page.', 'invoicing' ),
242
+                        'name'        => __('Success Page', 'invoicing'),
243
+                        'desc'        => __('This is the page buyers are sent to after completing their payments. The <b>[wpinv_receipt]</b> short code should be on this page.', 'invoicing'),
244 244
                         'type'        => 'select',
245 245
                         'options'     => $pages,
246 246
                         'chosen'      => true,
247
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
247
+                        'placeholder' => __('Select a page', 'invoicing'),
248 248
                     ),
249 249
                     'failure_page' => array(
250 250
                         'id'          => 'failure_page',
251
-                        'name'        => __( 'Failed Transaction Page', 'invoicing' ),
252
-                        'desc'        => __( 'This is the page buyers are sent to if their transaction is cancelled or fails', 'invoicing' ),
251
+                        'name'        => __('Failed Transaction Page', 'invoicing'),
252
+                        'desc'        => __('This is the page buyers are sent to if their transaction is cancelled or fails', 'invoicing'),
253 253
                         'type'        => 'select',
254 254
                         'options'     => $pages,
255 255
                         'chosen'      => true,
256
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
256
+                        'placeholder' => __('Select a page', 'invoicing'),
257 257
                     ),
258 258
                     'invoice_history_page' => array(
259 259
                         'id'          => 'invoice_history_page',
260
-                        'name'        => __( 'Invoice History Page', 'invoicing' ),
261
-                        'desc'        => __( 'This page shows a invoice history for the current user', 'invoicing' ),
260
+                        'name'        => __('Invoice History Page', 'invoicing'),
261
+                        'desc'        => __('This page shows a invoice history for the current user', 'invoicing'),
262 262
                         'type'        => 'select',
263 263
                         'options'     => $pages,
264 264
                         'chosen'      => true,
265
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
265
+                        'placeholder' => __('Select a page', 'invoicing'),
266 266
                     )
267 267
                 ),
268 268
                 'currency_section' => array(
269 269
                     'currency_settings' => array(
270 270
                         'id'   => 'currency_settings',
271
-                        'name' => '<h3>' . __( 'Currency Settings', 'invoicing' ) . '</h3>',
271
+                        'name' => '<h3>' . __('Currency Settings', 'invoicing') . '</h3>',
272 272
                         'desc' => '',
273 273
                         'type' => 'header',
274 274
                     ),
275 275
                     'currency' => array(
276 276
                         'id'      => 'currency',
277
-                        'name'    => __( 'Currency', 'invoicing' ),
278
-                        'desc'    => __( 'Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing' ),
277
+                        'name'    => __('Currency', 'invoicing'),
278
+                        'desc'    => __('Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing'),
279 279
                         'type'    => 'select',
280 280
                         'options' => wpinv_get_currencies(),
281 281
                         'chosen'  => true,
282 282
                     ),
283 283
                     'currency_position' => array(
284 284
                         'id'      => 'currency_position',
285
-                        'name'    => __( 'Currency Position', 'invoicing' ),
286
-                        'desc'    => __( 'Choose the location of the currency sign.', 'invoicing' ),
285
+                        'name'    => __('Currency Position', 'invoicing'),
286
+                        'desc'    => __('Choose the location of the currency sign.', 'invoicing'),
287 287
                         'type'    => 'select',
288 288
                         'options'  => array(
289
-                            'left'        => __( 'Left', 'invoicing' ) . ' (' . $currency_symbol . wpinv_format_amount( '99.99' ) . ')',
290
-                            'right'       => __( 'Right', 'invoicing' ) . ' ('. wpinv_format_amount( '99.99' ) . $currency_symbol . ')',
291
-                            'left_space'  => __( 'Left with space', 'invoicing' ) . ' (' . $currency_symbol . ' ' . wpinv_format_amount( '99.99' ) . ')',
292
-                            'right_space' => __( 'Right with space', 'invoicing' ) . ' (' . wpinv_format_amount( '99.99' ) . ' ' . $currency_symbol . ')'
289
+                            'left'        => __('Left', 'invoicing') . ' (' . $currency_symbol . wpinv_format_amount('99.99') . ')',
290
+                            'right'       => __('Right', 'invoicing') . ' (' . wpinv_format_amount('99.99') . $currency_symbol . ')',
291
+                            'left_space'  => __('Left with space', 'invoicing') . ' (' . $currency_symbol . ' ' . wpinv_format_amount('99.99') . ')',
292
+                            'right_space' => __('Right with space', 'invoicing') . ' (' . wpinv_format_amount('99.99') . ' ' . $currency_symbol . ')'
293 293
                         )
294 294
                     ),
295 295
                     'thousands_separator' => array(
296 296
                         'id'   => 'thousands_separator',
297
-                        'name' => __( 'Thousands Separator', 'invoicing' ),
298
-                        'desc' => __( 'The symbol (usually , or .) to separate thousands', 'invoicing' ),
297
+                        'name' => __('Thousands Separator', 'invoicing'),
298
+                        'desc' => __('The symbol (usually , or .) to separate thousands', 'invoicing'),
299 299
                         'type' => 'text',
300 300
                         'size' => 'small',
301 301
                         'std'  => ',',
302 302
                     ),
303 303
                     'decimal_separator' => array(
304 304
                         'id'   => 'decimal_separator',
305
-                        'name' => __( 'Decimal Separator', 'invoicing' ),
306
-                        'desc' => __( 'The symbol (usually , or .) to separate decimal points', 'invoicing' ),
305
+                        'name' => __('Decimal Separator', 'invoicing'),
306
+                        'desc' => __('The symbol (usually , or .) to separate decimal points', 'invoicing'),
307 307
                         'type' => 'text',
308 308
                         'size' => 'small',
309 309
                         'std'  => '.',
310 310
                     ),
311 311
                     'decimals' => array(
312 312
                         'id'   => 'decimals',
313
-                        'name' => __( 'Number of Decimals', 'invoicing' ),
314
-                        'desc' => __( 'This sets the number of decimal points shown in displayed prices.', 'invoicing' ),
313
+                        'name' => __('Number of Decimals', 'invoicing'),
314
+                        'desc' => __('This sets the number of decimal points shown in displayed prices.', 'invoicing'),
315 315
                         'type' => 'number',
316 316
                         'size' => 'small',
317 317
                         'std'  => '2',
@@ -323,29 +323,29 @@  discard block
 block discarded – undo
323 323
                 'labels' => array(
324 324
                     'labels' => array(
325 325
                         'id'   => 'labels_settings',
326
-                        'name' => '<h3>' . __( 'Invoice Labels', 'invoicing' ) . '</h3>',
326
+                        'name' => '<h3>' . __('Invoice Labels', 'invoicing') . '</h3>',
327 327
                         'desc' => '',
328 328
                         'type' => 'header',
329 329
                     ),
330 330
                     'vat_name' => array(
331 331
                         'id' => 'vat_name',
332
-                        'name' => __( 'VAT Name', 'invoicing' ),
333
-                        'desc' => __( 'Enter the VAT name', 'invoicing' ),
332
+                        'name' => __('VAT Name', 'invoicing'),
333
+                        'desc' => __('Enter the VAT name', 'invoicing'),
334 334
                         'type' => 'text',
335 335
                         'size' => 'regular',
336 336
                         'std' => 'VAT'
337 337
                     ),
338 338
                     'vat_invoice_notice_label' => array(
339 339
                         'id' => 'vat_invoice_notice_label',
340
-                        'name' => __( 'Invoice notice label', 'invoicing' ),
341
-                        'desc' => __( 'Use this to add a invoice notice section (label) to your invoices', 'invoicing' ),
340
+                        'name' => __('Invoice notice label', 'invoicing'),
341
+                        'desc' => __('Use this to add a invoice notice section (label) to your invoices', 'invoicing'),
342 342
                         'type' => 'text',
343 343
                         'size' => 'regular',
344 344
                     ),
345 345
                     'vat_invoice_notice' => array(
346 346
                         'id' => 'vat_invoice_notice',
347
-                        'name' => __( 'Invoice notice', 'invoicing' ),
348
-                        'desc' =>   __( 'Use this to add a invoice notice section (description) to your invoices', 'invoicing' ),
347
+                        'name' => __('Invoice notice', 'invoicing'),
348
+                        'desc' =>   __('Use this to add a invoice notice section (description) to your invoices', 'invoicing'),
349 349
                         'type' => 'text',
350 350
                         'size' => 'regular',
351 351
                     )
@@ -357,22 +357,22 @@  discard block
 block discarded – undo
357 357
                 'main' => array(
358 358
                     'gateway_settings' => array(
359 359
                         'id'   => 'api_header',
360
-                        'name' => '<h3>' . __( 'Gateway Settings', 'invoicing' ) . '</h3>',
360
+                        'name' => '<h3>' . __('Gateway Settings', 'invoicing') . '</h3>',
361 361
                         'desc' => '',
362 362
                         'type' => 'header',
363 363
                     ),
364 364
                     'gateways' => array(
365 365
                         'id'      => 'gateways',
366
-                        'name'    => __( 'Payment Gateways', 'invoicing' ),
367
-                        'desc'    => __( 'Choose the payment gateways you want to enable.', 'invoicing' ),
366
+                        'name'    => __('Payment Gateways', 'invoicing'),
367
+                        'desc'    => __('Choose the payment gateways you want to enable.', 'invoicing'),
368 368
                         'type'    => 'gateways',
369 369
                         'std'     => array('manual'=>1),
370 370
                         'options' => wpinv_get_payment_gateways(),
371 371
                     ),
372 372
                     'default_gateway' => array(
373 373
                         'id'      => 'default_gateway',
374
-                        'name'    => __( 'Default Gateway', 'invoicing' ),
375
-                        'desc'    => __( 'This gateway will be loaded automatically with the checkout page.', 'invoicing' ),
374
+                        'name'    => __('Default Gateway', 'invoicing'),
375
+                        'desc'    => __('This gateway will be loaded automatically with the checkout page.', 'invoicing'),
376 376
                         'type'    => 'gateway_select',
377 377
                         'std'     => 'manual',
378 378
                         'options' => wpinv_get_payment_gateways(),
@@ -386,19 +386,19 @@  discard block
 block discarded – undo
386 386
                 'main' => array(
387 387
                     'tax_settings' => array(
388 388
                         'id'   => 'tax_settings',
389
-                        'name' => '<h3>' . __( 'Tax Settings', 'invoicing' ) . '</h3>',
389
+                        'name' => '<h3>' . __('Tax Settings', 'invoicing') . '</h3>',
390 390
                         'type' => 'header',
391 391
                     ),
392 392
                     'enable_taxes' => array(
393 393
                         'id'   => 'enable_taxes',
394
-                        'name' => __( 'Enable Taxes', 'invoicing' ),
395
-                        'desc' => __( 'Check this to enable taxes on invoices.', 'invoicing' ),
394
+                        'name' => __('Enable Taxes', 'invoicing'),
395
+                        'desc' => __('Check this to enable taxes on invoices.', 'invoicing'),
396 396
                         'type' => 'checkbox',
397 397
                     ),
398 398
                     'tax_rate' => array(
399 399
                         'id'   => 'tax_rate',
400
-                        'name' => __( 'Fallback Tax Rate', 'invoicing' ),
401
-                        'desc' => __( 'Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing' ),
400
+                        'name' => __('Fallback Tax Rate', 'invoicing'),
401
+                        'desc' => __('Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing'),
402 402
                         'type' => 'number',
403 403
                         'size' => 'small',
404 404
                         'min'  => '0',
@@ -410,8 +410,8 @@  discard block
 block discarded – undo
410 410
                 'rates' => array(
411 411
                     'tax_rates' => array(
412 412
                         'id'   => 'tax_rates',
413
-                        'name' => '<h3>' . __( 'Tax Rates', 'invoicing' ) . '</h3>',
414
-                        'desc' => __( 'Enter tax rates for specific regions.', 'invoicing' ),
413
+                        'name' => '<h3>' . __('Tax Rates', 'invoicing') . '</h3>',
414
+                        'desc' => __('Enter tax rates for specific regions.', 'invoicing'),
415 415
                         'type' => 'tax_rates',
416 416
                     ),
417 417
                 )
@@ -423,62 +423,62 @@  discard block
 block discarded – undo
423 423
                 'main' => array(
424 424
                     'email_settings_header' => array(
425 425
                         'id'   => 'email_settings_header',
426
-                        'name' => '<h3>' . __( 'Email Sender Options', 'invoicing' ) . '</h3>',
426
+                        'name' => '<h3>' . __('Email Sender Options', 'invoicing') . '</h3>',
427 427
                         'type' => 'header',
428 428
                     ),
429 429
                     'email_from_name' => array(
430 430
                         'id'   => 'email_from_name',
431
-                        'name' => __( 'From Name', 'invoicing' ),
432
-                        'desc' => __( 'Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing' ),
433
-                        'std' => esc_attr( get_bloginfo( 'name', 'display' ) ),
431
+                        'name' => __('From Name', 'invoicing'),
432
+                        'desc' => __('Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing'),
433
+                        'std' => esc_attr(get_bloginfo('name', 'display')),
434 434
                         'type' => 'text',
435 435
                     ),
436 436
                     'email_from' => array(
437 437
                         'id'   => 'email_from',
438
-                        'name' => __( 'From Email', 'invoicing' ),
439
-                        'desc' => sprintf (__( 'Email address to send invoice emails from. This will act as the "from" and "reply-to" address. %s If emails are not being sent it may be that your hosting prevents emails being sent if the email domains do not match.%s', 'invoicing' ), $alert_wrapper_start, $alert_wrapper_close),
440
-                        'std' => get_option( 'admin_email' ),
438
+                        'name' => __('From Email', 'invoicing'),
439
+                        'desc' => sprintf(__('Email address to send invoice emails from. This will act as the "from" and "reply-to" address. %s If emails are not being sent it may be that your hosting prevents emails being sent if the email domains do not match.%s', 'invoicing'), $alert_wrapper_start, $alert_wrapper_close),
440
+                        'std' => get_option('admin_email'),
441 441
                         'type' => 'text',
442 442
                     ),
443 443
                     'overdue_settings_header' => array(
444 444
                         'id'   => 'overdue_settings_header',
445
-                        'name' => '<h3>' . __( 'Due Date Settings', 'invoicing' ) . '</h3>',
445
+                        'name' => '<h3>' . __('Due Date Settings', 'invoicing') . '</h3>',
446 446
                         'type' => 'header',
447 447
                     ),
448 448
                     'overdue_active' => array(
449 449
                         'id'   => 'overdue_active',
450
-                        'name' => __( 'Enable Due Date', 'invoicing' ),
451
-                        'desc' => __( 'Check this to enable due date option for invoices.', 'invoicing' ),
450
+                        'name' => __('Enable Due Date', 'invoicing'),
451
+                        'desc' => __('Check this to enable due date option for invoices.', 'invoicing'),
452 452
                         'type' => 'checkbox',
453 453
                         'std'  => false,
454 454
                     ),
455 455
                     'overdue_days' => array(
456 456
                         'id'          => 'overdue_days',
457
-                        'name'        => __( 'Default Due Date', 'invoicing' ),
458
-                        'desc'        => __( 'Number of days each Invoice is due after the created date. This will automatically set the date in the "Due Date" field. Can be overridden on individual Invoices.', 'invoicing' ),
457
+                        'name'        => __('Default Due Date', 'invoicing'),
458
+                        'desc'        => __('Number of days each Invoice is due after the created date. This will automatically set the date in the "Due Date" field. Can be overridden on individual Invoices.', 'invoicing'),
459 459
                         'type'        => 'select',
460 460
                         'options'     => $due_payment_options,
461 461
                         'chosen'      => true,
462 462
                         'std'         => 0,
463
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
463
+                        'placeholder' => __('Select a page', 'invoicing'),
464 464
                     ),
465 465
                     'email_template_header' => array(
466 466
                         'id'   => 'email_template_header',
467
-                        'name' => '<h3>' . __( 'Email Template', 'invoicing' ) . '</h3>',
467
+                        'name' => '<h3>' . __('Email Template', 'invoicing') . '</h3>',
468 468
                         'type' => 'header',
469 469
                     ),
470 470
                     'email_header_image' => array(
471 471
                         'id'   => 'email_header_image',
472
-                        'name' => __( 'Header Image', 'invoicing' ),
473
-                        'desc' => __( 'URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing' ),
472
+                        'name' => __('Header Image', 'invoicing'),
473
+                        'desc' => __('URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing'),
474 474
                         'std' => '',
475 475
                         'type' => 'text',
476 476
                     ),
477 477
                     'email_footer_text' => array(
478 478
                         'id'   => 'email_footer_text',
479
-                        'name' => __( 'Footer Text', 'invoicing' ),
480
-                        'desc' => __( 'The text to appear in the footer of all invoice emails.', 'invoicing' ),
481
-                        'std' => get_bloginfo( 'name', 'display' ) . ' - ' . __( 'Powered by GeoDirectory', 'invoicing' ),
479
+                        'name' => __('Footer Text', 'invoicing'),
480
+                        'desc' => __('The text to appear in the footer of all invoice emails.', 'invoicing'),
481
+                        'std' => get_bloginfo('name', 'display') . ' - ' . __('Powered by GeoDirectory', 'invoicing'),
482 482
                         'type' => 'textarea',
483 483
                         'class' => 'regular-text',
484 484
                         'rows' => 2,
@@ -486,29 +486,29 @@  discard block
 block discarded – undo
486 486
                     ),
487 487
                     'email_base_color' => array(
488 488
                         'id'   => 'email_base_color',
489
-                        'name' => __( 'Base Color', 'invoicing' ),
490
-                        'desc' => __( 'The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing' ),
489
+                        'name' => __('Base Color', 'invoicing'),
490
+                        'desc' => __('The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing'),
491 491
                         'std' => '#557da2',
492 492
                         'type' => 'color',
493 493
                     ),
494 494
                     'email_background_color' => array(
495 495
                         'id'   => 'email_background_color',
496
-                        'name' => __( 'Background Color', 'invoicing' ),
497
-                        'desc' => __( 'The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing' ),
496
+                        'name' => __('Background Color', 'invoicing'),
497
+                        'desc' => __('The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing'),
498 498
                         'std' => '#f5f5f5',
499 499
                         'type' => 'color',
500 500
                     ),
501 501
                     'email_body_background_color' => array(
502 502
                         'id'   => 'email_body_background_color',
503
-                        'name' => __( 'Body Background Color', 'invoicing' ),
504
-                        'desc' => __( 'The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing' ),
503
+                        'name' => __('Body Background Color', 'invoicing'),
504
+                        'desc' => __('The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing'),
505 505
                         'std' => '#fdfdfd',
506 506
                         'type' => 'color',
507 507
                     ),
508 508
                     'email_text_color' => array(
509 509
                         'id'   => 'email_text_color',
510
-                        'name' => __( 'Body Text Color', 'invoicing' ),
511
-                        'desc' => __( 'The main body text color. Default <code>#505050</code>.', 'invoicing' ),
510
+                        'name' => __('Body Text Color', 'invoicing'),
511
+                        'desc' => __('The main body text color. Default <code>#505050</code>.', 'invoicing'),
512 512
                         'std' => '#505050',
513 513
                         'type' => 'color',
514 514
                     ),
@@ -527,67 +527,67 @@  discard block
 block discarded – undo
527 527
                 'main' => array(
528 528
                     'fields_settings' => array(
529 529
                         'id'   => 'fields_settings',
530
-                        'name' => '<h3>' . __( 'Fields Settings', 'invoicing' ) . '</h3>',
531
-                        'desc' => __( 'Tick fields which are mandatory in invoice address fields.', 'invoicing' ),
530
+                        'name' => '<h3>' . __('Fields Settings', 'invoicing') . '</h3>',
531
+                        'desc' => __('Tick fields which are mandatory in invoice address fields.', 'invoicing'),
532 532
                         'type' => 'header',
533 533
                     ),
534 534
                     'fname_mandatory' => array(
535 535
                         'id'   => 'fname_mandatory',
536
-                        'name' => __( 'First Name Mandatory?', 'invoicing' ),
536
+                        'name' => __('First Name Mandatory?', 'invoicing'),
537 537
                         'type' => 'checkbox',
538 538
                         'std'  => true,
539 539
                     ),
540 540
                     'lname_mandatory' => array(
541 541
                         'id'   => 'lname_mandatory',
542
-                        'name' => __( 'Last Name Mandatory?', 'invoicing' ),
542
+                        'name' => __('Last Name Mandatory?', 'invoicing'),
543 543
                         'type' => 'checkbox',
544 544
                         'std'  => true,
545 545
                     ),
546 546
                     'address_mandatory' => array(
547 547
                         'id'   => 'address_mandatory',
548
-                        'name' => __( 'Address Mandatory?', 'invoicing' ),
548
+                        'name' => __('Address Mandatory?', 'invoicing'),
549 549
                         'type' => 'checkbox',
550 550
                         'std'  => true,
551 551
                     ),
552 552
                     'city_mandatory' => array(
553 553
                         'id'   => 'city_mandatory',
554
-                        'name' => __( 'City Mandatory?', 'invoicing' ),
554
+                        'name' => __('City Mandatory?', 'invoicing'),
555 555
                         'type' => 'checkbox',
556 556
                         'std'  => true,
557 557
                     ),
558 558
                     'country_mandatory' => array(
559 559
                         'id'   => 'country_mandatory',
560
-                        'name' => __( 'Country Mandatory?', 'invoicing' ),
560
+                        'name' => __('Country Mandatory?', 'invoicing'),
561 561
                         'type' => 'checkbox',
562 562
                         'std'  => true,
563 563
                     ),
564 564
                     'state_mandatory' => array(
565 565
                         'id'   => 'state_mandatory',
566
-                        'name' => __( 'State / Province Mandatory?', 'invoicing' ),
566
+                        'name' => __('State / Province Mandatory?', 'invoicing'),
567 567
                         'type' => 'checkbox',
568 568
                         'std'  => true,
569 569
                     ),
570 570
                     'zip_mandatory' => array(
571 571
                         'id'   => 'zip_mandatory',
572
-                        'name' => __( 'ZIP / Postcode Mandatory?', 'invoicing' ),
572
+                        'name' => __('ZIP / Postcode Mandatory?', 'invoicing'),
573 573
                         'type' => 'checkbox',
574 574
                         'std'  => true,
575 575
                     ),
576 576
                     'phone_mandatory' => array(
577 577
                         'id'   => 'phone_mandatory',
578
-                        'name' => __( 'Phone No. Mandatory?', 'invoicing' ),
578
+                        'name' => __('Phone No. Mandatory?', 'invoicing'),
579 579
                         'type' => 'checkbox',
580 580
                         'std'  => true,
581 581
                     ),
582 582
                     'invoice_number_format_settings' => array(
583 583
                         'id'   => 'invoice_number_format_settings',
584
-                        'name' => '<h3>' . __( 'Invoice Number', 'invoicing' ) . '</h3>',
584
+                        'name' => '<h3>' . __('Invoice Number', 'invoicing') . '</h3>',
585 585
                         'type' => 'header',
586 586
                     ),
587 587
                     'invoice_number_padd' => array(
588 588
                         'id'      => 'invoice_number_padd',
589
-                        'name'    => __( 'Minimum digits', 'invoicing' ),
590
-                        'desc'    => __( 'If the invoice number has less digits than this number, it is left padded with 0s. Ex: invoice number 108 will padded to 00108 if digits set to 5. The default 0 means no padding.', 'invoicing' ),
589
+                        'name'    => __('Minimum digits', 'invoicing'),
590
+                        'desc'    => __('If the invoice number has less digits than this number, it is left padded with 0s. Ex: invoice number 108 will padded to 00108 if digits set to 5. The default 0 means no padding.', 'invoicing'),
591 591
                         'type'    => 'select',
592 592
                         'options' => $invoice_number_padd_options,
593 593
                         'std'     => 5,
@@ -595,8 +595,8 @@  discard block
 block discarded – undo
595 595
                     ),
596 596
                     'invoice_number_prefix' => array(
597 597
                         'id' => 'invoice_number_prefix',
598
-                        'name' => __( 'Invoice Number prefix', 'invoicing' ),
599
-                        'desc' => __( 'A prefix to prepend to all invoice numbers. Ex: WPINV-', 'invoicing' ),
598
+                        'name' => __('Invoice Number prefix', 'invoicing'),
599
+                        'desc' => __('A prefix to prepend to all invoice numbers. Ex: WPINV-', 'invoicing'),
600 600
                         'type' => 'text',
601 601
                         'size' => 'regular',
602 602
                         'std' => 'WPINV-',
@@ -604,25 +604,25 @@  discard block
 block discarded – undo
604 604
                     ),
605 605
                     'invoice_number_postfix' => array(
606 606
                         'id' => 'invoice_number_postfix',
607
-                        'name' => __( 'Invoice Number postfix', 'invoicing' ),
608
-                        'desc' => __( 'A postfix to append to all invoice numbers.', 'invoicing' ),
607
+                        'name' => __('Invoice Number postfix', 'invoicing'),
608
+                        'desc' => __('A postfix to append to all invoice numbers.', 'invoicing'),
609 609
                         'type' => 'text',
610 610
                         'size' => 'regular',
611 611
                         'std' => ''
612 612
                     ),
613 613
                     'guest_checkout_settings' => array(
614 614
                         'id'   => 'guest_checkout_settings',
615
-                        'name' => '<h3>' . __( 'Pay via Invoice Link', 'invoicing' ) . '</h3>',
615
+                        'name' => '<h3>' . __('Pay via Invoice Link', 'invoicing') . '</h3>',
616 616
                         'type' => 'header',
617 617
                     ),
618 618
                     'guest_checkout' => array(
619 619
                         'type'    => 'radio',
620 620
                         'id'      => 'guest_checkout',
621
-                        'name'    => __( 'Pay via Invoice Link for non logged in user', 'invoicing' ),
622
-                        'desc'    => __( 'Select how invoice should be paid when non logged in user clicks on the invoice link that sent to them via for pay for invoice.', 'invoicing' ),
621
+                        'name'    => __('Pay via Invoice Link for non logged in user', 'invoicing'),
622
+                        'desc'    => __('Select how invoice should be paid when non logged in user clicks on the invoice link that sent to them via for pay for invoice.', 'invoicing'),
623 623
                         'options' => array(
624
-                            0 => __( 'Ask them to log-in and redirect back to invoice checkout to pay.', 'invoicing' ),
625
-                            1 => __( 'Auto log-in the user via invoice link and take them to invoice checkout to pay.', 'invoicing' ),
624
+                            0 => __('Ask them to log-in and redirect back to invoice checkout to pay.', 'invoicing'),
625
+                            1 => __('Auto log-in the user via invoice link and take them to invoice checkout to pay.', 'invoicing'),
626 626
                         ),
627 627
                         'std'     => 0,
628 628
                     ),
@@ -635,8 +635,8 @@  discard block
 block discarded – undo
635 635
                 'main' => array(
636 636
                     'tool_settings' => array(
637 637
                         'id'   => 'tool_settings',
638
-                        'name' => '<h3>' . __( 'Diagnostic Tools', 'invoicing' ) . '</h3>',
639
-                        'desc' => __( 'Invoicing diagnostic tools', 'invoicing' ),
638
+                        'name' => '<h3>' . __('Diagnostic Tools', 'invoicing') . '</h3>',
639
+                        'desc' => __('Invoicing diagnostic tools', 'invoicing'),
640 640
                         'type' => 'tools',
641 641
                     ),
642 642
                 ),
@@ -644,135 +644,135 @@  discard block
 block discarded – undo
644 644
         )
645 645
     );
646 646
 
647
-    return apply_filters( 'wpinv_registered_settings', $wpinv_settings );
647
+    return apply_filters('wpinv_registered_settings', $wpinv_settings);
648 648
 }
649 649
 
650
-function wpinv_settings_sanitize( $input = array() ) {
650
+function wpinv_settings_sanitize($input = array()) {
651 651
     global $wpinv_options;
652 652
 
653
-    if ( empty( $_POST['_wp_http_referer'] ) ) {
653
+    if (empty($_POST['_wp_http_referer'])) {
654 654
         return $input;
655 655
     }
656 656
 
657
-    parse_str( $_POST['_wp_http_referer'], $referrer );
657
+    parse_str($_POST['_wp_http_referer'], $referrer);
658 658
 
659 659
     $settings = wpinv_get_registered_settings();
660
-    $tab      = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general';
661
-    $section  = isset( $referrer['section'] ) ? $referrer['section'] : 'main';
660
+    $tab      = isset($referrer['tab']) ? $referrer['tab'] : 'general';
661
+    $section  = isset($referrer['section']) ? $referrer['section'] : 'main';
662 662
 
663 663
     $input = $input ? $input : array();
664
-    $input = apply_filters( 'wpinv_settings_tab_' . $tab . '_sanitize', $input );
665
-    $input = apply_filters( 'wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input );
664
+    $input = apply_filters('wpinv_settings_tab_' . $tab . '_sanitize', $input);
665
+    $input = apply_filters('wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input);
666 666
 
667 667
     // Loop through each setting being saved and pass it through a sanitization filter
668
-    foreach ( $input as $key => $value ) {
668
+    foreach ($input as $key => $value) {
669 669
         // Get the setting type (checkbox, select, etc)
670
-        $type = isset( $settings[ $tab ][ $key ]['type'] ) ? $settings[ $tab ][ $key ]['type'] : false;
670
+        $type = isset($settings[$tab][$key]['type']) ? $settings[$tab][$key]['type'] : false;
671 671
 
672
-        if ( $type ) {
672
+        if ($type) {
673 673
             // Field type specific filter
674
-            $input[$key] = apply_filters( 'wpinv_settings_sanitize_' . $type, $value, $key );
674
+            $input[$key] = apply_filters('wpinv_settings_sanitize_' . $type, $value, $key);
675 675
         }
676 676
 
677 677
         // General filter
678
-        $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
678
+        $input[$key] = apply_filters('wpinv_settings_sanitize', $input[$key], $key);
679 679
     }
680 680
 
681 681
     // Loop through the whitelist and unset any that are empty for the tab being saved
682
-    $main_settings    = $section == 'main' ? $settings[ $tab ] : array(); // Check for extensions that aren't using new sections
683
-    $section_settings = ! empty( $settings[ $tab ][ $section ] ) ? $settings[ $tab ][ $section ] : array();
682
+    $main_settings    = $section == 'main' ? $settings[$tab] : array(); // Check for extensions that aren't using new sections
683
+    $section_settings = !empty($settings[$tab][$section]) ? $settings[$tab][$section] : array();
684 684
 
685
-    $found_settings = array_merge( $main_settings, $section_settings );
685
+    $found_settings = array_merge($main_settings, $section_settings);
686 686
 
687
-    if ( ! empty( $found_settings ) ) {
688
-        foreach ( $found_settings as $key => $value ) {
687
+    if (!empty($found_settings)) {
688
+        foreach ($found_settings as $key => $value) {
689 689
 
690 690
             // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work
691
-            if ( is_numeric( $key ) ) {
691
+            if (is_numeric($key)) {
692 692
                 $key = $value['id'];
693 693
             }
694 694
 
695
-            if ( empty( $input[ $key ] ) ) {
696
-                unset( $wpinv_options[ $key ] );
695
+            if (empty($input[$key])) {
696
+                unset($wpinv_options[$key]);
697 697
             }
698 698
         }
699 699
     }
700 700
 
701 701
     // Merge our new settings with the existing
702
-    $output = array_merge( $wpinv_options, $input );
702
+    $output = array_merge($wpinv_options, $input);
703 703
 
704
-    add_settings_error( 'wpinv-notices', '', __( 'Settings updated.', 'invoicing' ), 'updated' );
704
+    add_settings_error('wpinv-notices', '', __('Settings updated.', 'invoicing'), 'updated');
705 705
 
706 706
     return $output;
707 707
 }
708 708
 
709
-function wpinv_settings_sanitize_misc_accounting( $input ) {
709
+function wpinv_settings_sanitize_misc_accounting($input) {
710 710
     global $wpinv_options, $wpi_session;
711 711
 
712
-    if ( !current_user_can( 'manage_options' ) ) {
712
+    if (!current_user_can('manage_options')) {
713 713
         return $input;
714 714
     }
715 715
 
716
-    if( ! empty( $input['enable_sequential'] ) && !wpinv_get_option( 'enable_sequential' ) ) {
716
+    if (!empty($input['enable_sequential']) && !wpinv_get_option('enable_sequential')) {
717 717
         // Shows an admin notice about upgrading previous order numbers
718
-        $wpi_session->set( 'upgrade_sequential', '1' );
718
+        $wpi_session->set('upgrade_sequential', '1');
719 719
     }
720 720
 
721 721
     return $input;
722 722
 }
723
-add_filter( 'wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting' );
723
+add_filter('wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting');
724 724
 
725
-function wpinv_settings_sanitize_tax_rates( $input ) {
726
-    if( !current_user_can( 'manage_options' ) ) {
725
+function wpinv_settings_sanitize_tax_rates($input) {
726
+    if (!current_user_can('manage_options')) {
727 727
         return $input;
728 728
     }
729 729
 
730
-    $new_rates = !empty( $_POST['tax_rates'] ) ? array_values( $_POST['tax_rates'] ) : array();
730
+    $new_rates = !empty($_POST['tax_rates']) ? array_values($_POST['tax_rates']) : array();
731 731
 
732 732
     $tax_rates = array();
733 733
 
734
-    if ( !empty( $new_rates ) ) {
735
-        foreach ( $new_rates as $rate ) {
736
-            if ( isset( $rate['country'] ) && empty( $rate['country'] ) && empty( $rate['state'] ) ) {
734
+    if (!empty($new_rates)) {
735
+        foreach ($new_rates as $rate) {
736
+            if (isset($rate['country']) && empty($rate['country']) && empty($rate['state'])) {
737 737
                 continue;
738 738
             }
739 739
             
740
-            $rate['rate'] = wpinv_sanitize_amount( $rate['rate'], 4 );
740
+            $rate['rate'] = wpinv_sanitize_amount($rate['rate'], 4);
741 741
             
742 742
             $tax_rates[] = $rate;
743 743
         }
744 744
     }
745 745
 
746
-    update_option( 'wpinv_tax_rates', $tax_rates );
746
+    update_option('wpinv_tax_rates', $tax_rates);
747 747
 
748 748
     return $input;
749 749
 }
750
-add_filter( 'wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates' );
750
+add_filter('wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates');
751 751
 
752
-function wpinv_sanitize_text_field( $input ) {
753
-    return trim( $input );
752
+function wpinv_sanitize_text_field($input) {
753
+    return trim($input);
754 754
 }
755
-add_filter( 'wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field' );
755
+add_filter('wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field');
756 756
 
757 757
 function wpinv_get_settings_tabs() {
758 758
     $tabs             = array();
759
-    $tabs['general']  = __( 'General', 'invoicing' );
760
-    $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' );
761
-    $tabs['taxes']    = __( 'Taxes', 'invoicing' );
762
-    $tabs['emails']   = __( 'Emails', 'invoicing' );
763
-    $tabs['misc']     = __( 'Misc', 'invoicing' );
764
-    $tabs['tools']    = __( 'Tools', 'invoicing' );
765
-
766
-    return apply_filters( 'wpinv_settings_tabs', $tabs );
759
+    $tabs['general']  = __('General', 'invoicing');
760
+    $tabs['gateways'] = __('Payment Gateways', 'invoicing');
761
+    $tabs['taxes']    = __('Taxes', 'invoicing');
762
+    $tabs['emails']   = __('Emails', 'invoicing');
763
+    $tabs['misc']     = __('Misc', 'invoicing');
764
+    $tabs['tools']    = __('Tools', 'invoicing');
765
+
766
+    return apply_filters('wpinv_settings_tabs', $tabs);
767 767
 }
768 768
 
769
-function wpinv_get_settings_tab_sections( $tab = false ) {
769
+function wpinv_get_settings_tab_sections($tab = false) {
770 770
     $tabs     = false;
771 771
     $sections = wpinv_get_registered_settings_sections();
772 772
 
773
-    if( $tab && ! empty( $sections[ $tab ] ) ) {
774
-        $tabs = $sections[ $tab ];
775
-    } else if ( $tab ) {
773
+    if ($tab && !empty($sections[$tab])) {
774
+        $tabs = $sections[$tab];
775
+    } else if ($tab) {
776 776
         $tabs = false;
777 777
     }
778 778
 
@@ -782,135 +782,135 @@  discard block
 block discarded – undo
782 782
 function wpinv_get_registered_settings_sections() {
783 783
     static $sections = false;
784 784
 
785
-    if ( false !== $sections ) {
785
+    if (false !== $sections) {
786 786
         return $sections;
787 787
     }
788 788
 
789 789
     $sections = array(
790
-        'general' => apply_filters( 'wpinv_settings_sections_general', array(
791
-            'main' => __( 'General Settings', 'invoicing' ),
792
-            'currency_section' => __( 'Currency Settings', 'invoicing' ),
793
-            'labels' => __( 'Label Texts', 'invoicing' ),
794
-        ) ),
795
-        'gateways' => apply_filters( 'wpinv_settings_sections_gateways', array(
796
-            'main' => __( 'Gateway Settings', 'invoicing' ),
797
-        ) ),
798
-        'taxes' => apply_filters( 'wpinv_settings_sections_taxes', array(
799
-            'main' => __( 'Tax Settings', 'invoicing' ),
800
-            'rates' => __( 'Tax Rates', 'invoicing' ),
801
-        ) ),
802
-        'emails' => apply_filters( 'wpinv_settings_sections_emails', array(
803
-            'main' => __( 'Email Settings', 'invoicing' ),
804
-        ) ),
805
-        'misc' => apply_filters( 'wpinv_settings_sections_misc', array(
806
-            'main' => __( 'Misc Settings', 'invoicing' ),
807
-        ) ),
808
-        'tools' => apply_filters( 'wpinv_settings_sections_tools', array(
809
-            'main' => __( 'Diagnostic Tools', 'invoicing' ),
810
-        ) ),
790
+        'general' => apply_filters('wpinv_settings_sections_general', array(
791
+            'main' => __('General Settings', 'invoicing'),
792
+            'currency_section' => __('Currency Settings', 'invoicing'),
793
+            'labels' => __('Label Texts', 'invoicing'),
794
+        )),
795
+        'gateways' => apply_filters('wpinv_settings_sections_gateways', array(
796
+            'main' => __('Gateway Settings', 'invoicing'),
797
+        )),
798
+        'taxes' => apply_filters('wpinv_settings_sections_taxes', array(
799
+            'main' => __('Tax Settings', 'invoicing'),
800
+            'rates' => __('Tax Rates', 'invoicing'),
801
+        )),
802
+        'emails' => apply_filters('wpinv_settings_sections_emails', array(
803
+            'main' => __('Email Settings', 'invoicing'),
804
+        )),
805
+        'misc' => apply_filters('wpinv_settings_sections_misc', array(
806
+            'main' => __('Misc Settings', 'invoicing'),
807
+        )),
808
+        'tools' => apply_filters('wpinv_settings_sections_tools', array(
809
+            'main' => __('Diagnostic Tools', 'invoicing'),
810
+        )),
811 811
     );
812 812
 
813
-    $sections = apply_filters( 'wpinv_settings_sections', $sections );
813
+    $sections = apply_filters('wpinv_settings_sections', $sections);
814 814
 
815 815
     return $sections;
816 816
 }
817 817
 
818
-function wpinv_get_pages( $with_slug = false, $default_label = NULL ) {
818
+function wpinv_get_pages($with_slug = false, $default_label = NULL) {
819 819
 	$pages_options = array();
820 820
 
821
-	if( $default_label !== NULL && $default_label !== false ) {
822
-		$pages_options = array( '' => $default_label ); // Blank option
821
+	if ($default_label !== NULL && $default_label !== false) {
822
+		$pages_options = array('' => $default_label); // Blank option
823 823
 	}
824 824
 
825 825
 	$pages = get_pages();
826
-	if ( $pages ) {
827
-		foreach ( $pages as $page ) {
826
+	if ($pages) {
827
+		foreach ($pages as $page) {
828 828
 			$title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
829
-            $pages_options[ $page->ID ] = $title;
829
+            $pages_options[$page->ID] = $title;
830 830
 		}
831 831
 	}
832 832
 
833 833
 	return $pages_options;
834 834
 }
835 835
 
836
-function wpinv_header_callback( $args ) {
837
-	if ( !empty( $args['desc'] ) ) {
836
+function wpinv_header_callback($args) {
837
+	if (!empty($args['desc'])) {
838 838
         echo $args['desc'];
839 839
     }
840 840
 }
841 841
 
842
-function wpinv_hidden_callback( $args ) {
842
+function wpinv_hidden_callback($args) {
843 843
 	global $wpinv_options;
844 844
 
845
-	if ( isset( $args['set_value'] ) ) {
845
+	if (isset($args['set_value'])) {
846 846
 		$value = $args['set_value'];
847
-	} elseif ( isset( $wpinv_options[ $args['id'] ] ) ) {
848
-		$value = $wpinv_options[ $args['id'] ];
847
+	} elseif (isset($wpinv_options[$args['id']])) {
848
+		$value = $wpinv_options[$args['id']];
849 849
 	} else {
850
-		$value = isset( $args['std'] ) ? $args['std'] : '';
850
+		$value = isset($args['std']) ? $args['std'] : '';
851 851
 	}
852 852
 
853
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
853
+	if (isset($args['faux']) && true === $args['faux']) {
854 854
 		$args['readonly'] = true;
855
-		$value = isset( $args['std'] ) ? $args['std'] : '';
855
+		$value = isset($args['std']) ? $args['std'] : '';
856 856
 		$name  = '';
857 857
 	} else {
858
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
858
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
859 859
 	}
860 860
 
861
-	$html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
861
+	$html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key($args['id']) . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '" />';
862 862
     
863 863
 	echo $html;
864 864
 }
865 865
 
866
-function wpinv_checkbox_callback( $args ) {
866
+function wpinv_checkbox_callback($args) {
867 867
 	global $wpinv_options;
868 868
     
869
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
869
+    $sanitize_id = wpinv_sanitize_key($args['id']);
870 870
 
871
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
871
+	if (isset($args['faux']) && true === $args['faux']) {
872 872
 		$name = '';
873 873
 	} else {
874 874
 		$name = 'name="wpinv_settings[' . $sanitize_id . ']"';
875 875
 	}
876 876
 
877
-	$checked = isset( $wpinv_options[ $args['id'] ] ) ? checked( 1, $wpinv_options[ $args['id'] ], false ) : '';
877
+	$checked = isset($wpinv_options[$args['id']]) ? checked(1, $wpinv_options[$args['id']], false) : '';
878 878
 	$html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>';
879
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
879
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
880 880
 
881 881
 	echo $html;
882 882
 }
883 883
 
884
-function wpinv_multicheck_callback( $args ) {
884
+function wpinv_multicheck_callback($args) {
885 885
 	global $wpinv_options;
886 886
 	
887
-	$sanitize_id = wpinv_sanitize_key( $args['id'] );
887
+	$sanitize_id = wpinv_sanitize_key($args['id']);
888 888
 	
889
-	if ( ! empty( $args['options'] ) ) {
890
-		foreach( $args['options'] as $key => $option ):
891
-			$sanitize_key = wpinv_sanitize_key( $key );
892
-			if ( isset( $wpinv_options[$args['id']][$sanitize_key] ) ) { 
889
+	if (!empty($args['options'])) {
890
+		foreach ($args['options'] as $key => $option):
891
+			$sanitize_key = wpinv_sanitize_key($key);
892
+			if (isset($wpinv_options[$args['id']][$sanitize_key])) { 
893 893
 				$enabled = $sanitize_key;
894 894
 			} else { 
895 895
 				$enabled = NULL; 
896 896
 			}
897
-			echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
898
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label><br/>';
897
+			echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($sanitize_key) . '" ' . checked($sanitize_key, $enabled, false) . '/>&nbsp;';
898
+			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post($option) . '</label><br/>';
899 899
 		endforeach;
900 900
 		echo '<p class="description">' . $args['desc'] . '</p>';
901 901
 	}
902 902
 }
903 903
 
904
-function wpinv_payment_icons_callback( $args ) {
904
+function wpinv_payment_icons_callback($args) {
905 905
 	global $wpinv_options;
906 906
     
907
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
907
+    $sanitize_id = wpinv_sanitize_key($args['id']);
908 908
 
909
-	if ( ! empty( $args['options'] ) ) {
910
-		foreach( $args['options'] as $key => $option ) {
911
-            $sanitize_key = wpinv_sanitize_key( $key );
909
+	if (!empty($args['options'])) {
910
+		foreach ($args['options'] as $key => $option) {
911
+            $sanitize_key = wpinv_sanitize_key($key);
912 912
             
913
-			if( isset( $wpinv_options[$args['id']][$key] ) ) {
913
+			if (isset($wpinv_options[$args['id']][$key])) {
914 914
 				$enabled = $option;
915 915
 			} else {
916 916
 				$enabled = NULL;
@@ -918,194 +918,194 @@  discard block
 block discarded – undo
918 918
 
919 919
 			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
920 920
 
921
-				echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
921
+				echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($option) . '" ' . checked($option, $enabled, false) . '/>&nbsp;';
922 922
 
923
-				if ( wpinv_string_is_image_url( $key ) ) {
924
-					echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
923
+				if (wpinv_string_is_image_url($key)) {
924
+					echo '<img class="payment-icon" src="' . esc_url($key) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
925 925
 				} else {
926
-					$card = strtolower( str_replace( ' ', '', $option ) );
926
+					$card = strtolower(str_replace(' ', '', $option));
927 927
 
928
-					if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
929
-						$image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
928
+					if (has_filter('wpinv_accepted_payment_' . $card . '_image')) {
929
+						$image = apply_filters('wpinv_accepted_payment_' . $card . '_image', '');
930 930
 					} else {
931
-						$image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
931
+						$image       = wpinv_locate_template('images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false);
932 932
 						$content_dir = WP_CONTENT_DIR;
933 933
 
934
-						if ( function_exists( 'wp_normalize_path' ) ) {
934
+						if (function_exists('wp_normalize_path')) {
935 935
 							// Replaces backslashes with forward slashes for Windows systems
936
-							$image = wp_normalize_path( $image );
937
-							$content_dir = wp_normalize_path( $content_dir );
936
+							$image = wp_normalize_path($image);
937
+							$content_dir = wp_normalize_path($content_dir);
938 938
 						}
939 939
 
940
-						$image = str_replace( $content_dir, content_url(), $image );
940
+						$image = str_replace($content_dir, content_url(), $image);
941 941
 					}
942 942
 
943
-					echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
943
+					echo '<img class="payment-icon" src="' . esc_url($image) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
944 944
 				}
945 945
 			echo $option . '</label>';
946 946
 		}
947
-		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
947
+		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post($args['desc']) . '</p>';
948 948
 	}
949 949
 }
950 950
 
951
-function wpinv_radio_callback( $args ) {
951
+function wpinv_radio_callback($args) {
952 952
 	global $wpinv_options;
953 953
     
954
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
954
+    $sanitize_id = wpinv_sanitize_key($args['id']);
955 955
     
956
-    foreach ( $args['options'] as $key => $option ) :
957
-		$sanitize_key = wpinv_sanitize_key( $key );
956
+    foreach ($args['options'] as $key => $option) :
957
+		$sanitize_key = wpinv_sanitize_key($key);
958 958
         
959 959
         $checked = false;
960 960
 
961
-		if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key )
961
+		if (isset($wpinv_options[$args['id']]) && $wpinv_options[$args['id']] == $key)
962 962
 			$checked = true;
963
-		elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) )
963
+		elseif (isset($args['std']) && $args['std'] == $key && !isset($wpinv_options[$args['id']]))
964 964
 			$checked = true;
965 965
 
966 966
 		echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/>&nbsp;';
967
-		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>';
967
+		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option) . '</label><br/>';
968 968
 	endforeach;
969 969
 
970
-	echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
970
+	echo '<p class="description">' . wp_kses_post($args['desc']) . '</p>';
971 971
 }
972 972
 
973
-function wpinv_gateways_callback( $args ) {
973
+function wpinv_gateways_callback($args) {
974 974
 	global $wpinv_options;
975 975
     
976
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
976
+    $sanitize_id = wpinv_sanitize_key($args['id']);
977 977
 
978
-	foreach ( $args['options'] as $key => $option ) :
979
-		$sanitize_key = wpinv_sanitize_key( $key );
978
+	foreach ($args['options'] as $key => $option) :
979
+		$sanitize_key = wpinv_sanitize_key($key);
980 980
         
981
-        if ( isset( $wpinv_options['gateways'][ $key ] ) )
981
+        if (isset($wpinv_options['gateways'][$key]))
982 982
 			$enabled = '1';
983 983
 		else
984 984
 			$enabled = null;
985 985
 
986
-		echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/>&nbsp;';
987
-		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>';
986
+		echo '<input name="wpinv_settings[' . esc_attr($args['id']) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/>&nbsp;';
987
+		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option['admin_label']) . '</label><br/>';
988 988
 	endforeach;
989 989
 }
990 990
 
991 991
 function wpinv_gateway_select_callback($args) {
992 992
 	global $wpinv_options;
993 993
     
994
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
994
+    $sanitize_id = wpinv_sanitize_key($args['id']);
995 995
 
996 996
 	echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']">';
997 997
 
998
-	foreach ( $args['options'] as $key => $option ) :
999
-		if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
1000
-            $selected = selected( $key, $args['selected'], false );
998
+	foreach ($args['options'] as $key => $option) :
999
+		if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) {
1000
+            $selected = selected($key, $args['selected'], false);
1001 1001
         } else {
1002
-            $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : '';
1002
+            $selected = isset($wpinv_options[$args['id']]) ? selected($key, $wpinv_options[$args['id']], false) : '';
1003 1003
         }
1004
-		echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
1004
+		echo '<option value="' . wpinv_sanitize_key($key) . '"' . $selected . '>' . esc_html($option['admin_label']) . '</option>';
1005 1005
 	endforeach;
1006 1006
 
1007 1007
 	echo '</select>';
1008
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1008
+	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1009 1009
 }
1010 1010
 
1011
-function wpinv_text_callback( $args ) {
1011
+function wpinv_text_callback($args) {
1012 1012
 	global $wpinv_options;
1013 1013
     
1014
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1014
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1015 1015
 
1016
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1017
-		$value = $wpinv_options[ $args['id'] ];
1016
+	if (isset($wpinv_options[$args['id']])) {
1017
+		$value = $wpinv_options[$args['id']];
1018 1018
 	} else {
1019
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1019
+		$value = isset($args['std']) ? $args['std'] : '';
1020 1020
 	}
1021 1021
 
1022
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
1022
+	if (isset($args['faux']) && true === $args['faux']) {
1023 1023
 		$args['readonly'] = true;
1024
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1024
+		$value = isset($args['std']) ? $args['std'] : '';
1025 1025
 		$name  = '';
1026 1026
 	} else {
1027
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
1027
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
1028 1028
 	}
1029 1029
 
1030 1030
 	$readonly = $args['readonly'] === true ? ' readonly="readonly"' : '';
1031
-	$size     = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1032
-	$html     = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>';
1033
-	$html    .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1031
+	$size     = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1032
+	$html     = '<input type="text" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"' . $readonly . '/>';
1033
+	$html    .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1034 1034
 
1035 1035
 	echo $html;
1036 1036
 }
1037 1037
 
1038
-function wpinv_number_callback( $args ) {
1038
+function wpinv_number_callback($args) {
1039 1039
 	global $wpinv_options;
1040 1040
     
1041
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1041
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1042 1042
 
1043
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1044
-		$value = $wpinv_options[ $args['id'] ];
1043
+	if (isset($wpinv_options[$args['id']])) {
1044
+		$value = $wpinv_options[$args['id']];
1045 1045
 	} else {
1046
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1046
+		$value = isset($args['std']) ? $args['std'] : '';
1047 1047
 	}
1048 1048
 
1049
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
1049
+	if (isset($args['faux']) && true === $args['faux']) {
1050 1050
 		$args['readonly'] = true;
1051
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1051
+		$value = isset($args['std']) ? $args['std'] : '';
1052 1052
 		$name  = '';
1053 1053
 	} else {
1054
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
1054
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
1055 1055
 	}
1056 1056
 
1057
-	$max  = isset( $args['max'] ) ? $args['max'] : 999999;
1058
-	$min  = isset( $args['min'] ) ? $args['min'] : 0;
1059
-	$step = isset( $args['step'] ) ? $args['step'] : 1;
1057
+	$max  = isset($args['max']) ? $args['max'] : 999999;
1058
+	$min  = isset($args['min']) ? $args['min'] : 0;
1059
+	$step = isset($args['step']) ? $args['step'] : 1;
1060 1060
 
1061
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1062
-	$html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>';
1063
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1061
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1062
+	$html = '<input type="number" step="' . esc_attr($step) . '" max="' . esc_attr($max) . '" min="' . esc_attr($min) . '" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"/>';
1063
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1064 1064
 
1065 1065
 	echo $html;
1066 1066
 }
1067 1067
 
1068
-function wpinv_textarea_callback( $args ) {
1068
+function wpinv_textarea_callback($args) {
1069 1069
 	global $wpinv_options;
1070 1070
     
1071
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1071
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1072 1072
 
1073
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1074
-		$value = $wpinv_options[ $args['id'] ];
1073
+	if (isset($wpinv_options[$args['id']])) {
1074
+		$value = $wpinv_options[$args['id']];
1075 1075
 	} else {
1076
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1076
+		$value = isset($args['std']) ? $args['std'] : '';
1077 1077
 	}
1078 1078
     
1079
-    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1080
-    $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text';
1079
+    $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1080
+    $class = (isset($args['class']) && !is_null($args['class'])) ? $args['class'] : 'large-text';
1081 1081
 
1082
-	$html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
1083
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1082
+	$html = '<textarea class="' . sanitize_html_class($class) . ' txtarea-' . sanitize_html_class($size) . ' wpi-' . esc_attr(sanitize_html_class($sanitize_id)) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']">' . esc_textarea(stripslashes($value)) . '</textarea>';
1083
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1084 1084
 
1085 1085
 	echo $html;
1086 1086
 }
1087 1087
 
1088
-function wpinv_password_callback( $args ) {
1088
+function wpinv_password_callback($args) {
1089 1089
 	global $wpinv_options;
1090 1090
     
1091
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1091
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1092 1092
 
1093
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1094
-		$value = $wpinv_options[ $args['id'] ];
1093
+	if (isset($wpinv_options[$args['id']])) {
1094
+		$value = $wpinv_options[$args['id']];
1095 1095
 	} else {
1096
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1096
+		$value = isset($args['std']) ? $args['std'] : '';
1097 1097
 	}
1098 1098
 
1099
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1100
-	$html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
1101
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1099
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1100
+	$html = '<input type="password" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '"/>';
1101
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1102 1102
 
1103 1103
 	echo $html;
1104 1104
 }
1105 1105
 
1106 1106
 function wpinv_missing_callback($args) {
1107 1107
 	printf(
1108
-		__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
1108
+		__('The callback function used for the %s setting is missing.', 'invoicing'),
1109 1109
 		'<strong>' . $args['id'] . '</strong>'
1110 1110
 	);
1111 1111
 }
@@ -1113,137 +1113,137 @@  discard block
 block discarded – undo
1113 1113
 function wpinv_select_callback($args) {
1114 1114
 	global $wpinv_options;
1115 1115
     
1116
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1116
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1117 1117
 
1118
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1119
-		$value = $wpinv_options[ $args['id'] ];
1118
+	if (isset($wpinv_options[$args['id']])) {
1119
+		$value = $wpinv_options[$args['id']];
1120 1120
 	} else {
1121
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1121
+		$value = isset($args['std']) ? $args['std'] : '';
1122 1122
 	}
1123 1123
     
1124
-    if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
1124
+    if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) {
1125 1125
         $value = $args['selected'];
1126 1126
     }
1127 1127
 
1128
-	if ( isset( $args['placeholder'] ) ) {
1128
+	if (isset($args['placeholder'])) {
1129 1129
 		$placeholder = $args['placeholder'];
1130 1130
 	} else {
1131 1131
 		$placeholder = '';
1132 1132
 	}
1133 1133
 
1134
-	if ( isset( $args['chosen'] ) ) {
1134
+	if (isset($args['chosen'])) {
1135 1135
 		$chosen = 'class="wpinv-chosen"';
1136 1136
 	} else {
1137 1137
 		$chosen = '';
1138 1138
 	}
1139 1139
     
1140
-    if( !empty( $args['onchange'] ) ) {
1141
-        $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"';
1140
+    if (!empty($args['onchange'])) {
1141
+        $onchange = ' onchange="' . esc_attr($args['onchange']) . '"';
1142 1142
     } else {
1143 1143
         $onchange = '';
1144 1144
     }
1145 1145
 
1146
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" ' . $chosen . 'data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />';
1146
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" ' . $chosen . 'data-placeholder="' . esc_html($placeholder) . '"' . $onchange . ' />';
1147 1147
 
1148
-	foreach ( $args['options'] as $option => $name ) {
1149
-		$selected = selected( $option, $value, false );
1150
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
1148
+	foreach ($args['options'] as $option => $name) {
1149
+		$selected = selected($option, $value, false);
1150
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>';
1151 1151
 	}
1152 1152
 
1153 1153
 	$html .= '</select>';
1154
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1154
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1155 1155
 
1156 1156
 	echo $html;
1157 1157
 }
1158 1158
 
1159
-function wpinv_color_select_callback( $args ) {
1159
+function wpinv_color_select_callback($args) {
1160 1160
 	global $wpinv_options;
1161 1161
     
1162
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1162
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1163 1163
 
1164
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1165
-		$value = $wpinv_options[ $args['id'] ];
1164
+	if (isset($wpinv_options[$args['id']])) {
1165
+		$value = $wpinv_options[$args['id']];
1166 1166
 	} else {
1167
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1167
+		$value = isset($args['std']) ? $args['std'] : '';
1168 1168
 	}
1169 1169
 
1170
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
1170
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"/>';
1171 1171
 
1172
-	foreach ( $args['options'] as $option => $color ) {
1173
-		$selected = selected( $option, $value, false );
1174
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>';
1172
+	foreach ($args['options'] as $option => $color) {
1173
+		$selected = selected($option, $value, false);
1174
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($color['label']) . '</option>';
1175 1175
 	}
1176 1176
 
1177 1177
 	$html .= '</select>';
1178
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1178
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1179 1179
 
1180 1180
 	echo $html;
1181 1181
 }
1182 1182
 
1183
-function wpinv_rich_editor_callback( $args ) {
1183
+function wpinv_rich_editor_callback($args) {
1184 1184
 	global $wpinv_options, $wp_version;
1185 1185
     
1186
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1186
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1187 1187
 
1188
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1189
-		$value = $wpinv_options[ $args['id'] ];
1188
+	if (isset($wpinv_options[$args['id']])) {
1189
+		$value = $wpinv_options[$args['id']];
1190 1190
 
1191
-		if( empty( $args['allow_blank'] ) && empty( $value ) ) {
1192
-			$value = isset( $args['std'] ) ? $args['std'] : '';
1191
+		if (empty($args['allow_blank']) && empty($value)) {
1192
+			$value = isset($args['std']) ? $args['std'] : '';
1193 1193
 		}
1194 1194
 	} else {
1195
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1195
+		$value = isset($args['std']) ? $args['std'] : '';
1196 1196
 	}
1197 1197
 
1198
-	$rows = isset( $args['size'] ) ? $args['size'] : 20;
1198
+	$rows = isset($args['size']) ? $args['size'] : 20;
1199 1199
 
1200
-	if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
1200
+	if ($wp_version >= 3.3 && function_exists('wp_editor')) {
1201 1201
 		ob_start();
1202
-		wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ) ) );
1202
+		wp_editor(stripslashes($value), 'wpinv_settings_' . esc_attr($args['id']), array('textarea_name' => 'wpinv_settings[' . esc_attr($args['id']) . ']', 'textarea_rows' => absint($rows)));
1203 1203
 		$html = ob_get_clean();
1204 1204
 	} else {
1205
-		$html = '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
1205
+		$html = '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" class="wpi-' . esc_attr(sanitize_html_class($args['id'])) . '">' . esc_textarea(stripslashes($value)) . '</textarea>';
1206 1206
 	}
1207 1207
 
1208
-	$html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1208
+	$html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1209 1209
 
1210 1210
 	echo $html;
1211 1211
 }
1212 1212
 
1213
-function wpinv_upload_callback( $args ) {
1213
+function wpinv_upload_callback($args) {
1214 1214
 	global $wpinv_options;
1215 1215
     
1216
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1216
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1217 1217
 
1218
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1218
+	if (isset($wpinv_options[$args['id']])) {
1219 1219
 		$value = $wpinv_options[$args['id']];
1220 1220
 	} else {
1221 1221
 		$value = isset($args['std']) ? $args['std'] : '';
1222 1222
 	}
1223 1223
 
1224
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1225
-	$html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
1226
-	$html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
1227
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1224
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1225
+	$html = '<input type="text" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr(stripslashes($value)) . '"/>';
1226
+	$html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __('Upload File', 'invoicing') . '"/></span>';
1227
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1228 1228
 
1229 1229
 	echo $html;
1230 1230
 }
1231 1231
 
1232
-function wpinv_color_callback( $args ) {
1232
+function wpinv_color_callback($args) {
1233 1233
 	global $wpinv_options;
1234 1234
     
1235
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1235
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1236 1236
 
1237
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1238
-		$value = $wpinv_options[ $args['id'] ];
1237
+	if (isset($wpinv_options[$args['id']])) {
1238
+		$value = $wpinv_options[$args['id']];
1239 1239
 	} else {
1240
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1240
+		$value = isset($args['std']) ? $args['std'] : '';
1241 1241
 	}
1242 1242
 
1243
-	$default = isset( $args['std'] ) ? $args['std'] : '';
1243
+	$default = isset($args['std']) ? $args['std'] : '';
1244 1244
 
1245
-	$html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />';
1246
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1245
+	$html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '" data-default-color="' . esc_attr($default) . '" />';
1246
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1247 1247
 
1248 1248
 	echo $html;
1249 1249
 }
@@ -1251,9 +1251,9 @@  discard block
 block discarded – undo
1251 1251
 function wpinv_country_states_callback($args) {
1252 1252
 	global $wpinv_options;
1253 1253
     
1254
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1254
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1255 1255
 
1256
-	if ( isset( $args['placeholder'] ) ) {
1256
+	if (isset($args['placeholder'])) {
1257 1257
 		$placeholder = $args['placeholder'];
1258 1258
 	} else {
1259 1259
 		$placeholder = '';
@@ -1261,17 +1261,17 @@  discard block
 block discarded – undo
1261 1261
 
1262 1262
 	$states = wpinv_get_country_states();
1263 1263
 
1264
-	$chosen = ( $args['chosen'] ? ' wpinv-chosen' : '' );
1265
-	$class = empty( $states ) ? ' class="wpinv-no-states' . $chosen . '"' : 'class="' . $chosen . '"';
1266
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
1264
+	$chosen = ($args['chosen'] ? ' wpinv-chosen' : '');
1265
+	$class = empty($states) ? ' class="wpinv-no-states' . $chosen . '"' : 'class="' . $chosen . '"';
1266
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"' . $class . 'data-placeholder="' . esc_html($placeholder) . '"/>';
1267 1267
 
1268
-	foreach ( $states as $option => $name ) {
1269
-		$selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : '';
1270
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
1268
+	foreach ($states as $option => $name) {
1269
+		$selected = isset($wpinv_options[$args['id']]) ? selected($option, $wpinv_options[$args['id']], false) : '';
1270
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>';
1271 1271
 	}
1272 1272
 
1273 1273
 	$html .= '</select>';
1274
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1274
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1275 1275
 
1276 1276
 	echo $html;
1277 1277
 }
@@ -1286,25 +1286,25 @@  discard block
 block discarded – undo
1286 1286
 	<table id="wpinv_tax_rates" class="wp-list-table widefat fixed posts">
1287 1287
 		<thead>
1288 1288
 			<tr>
1289
-				<th scope="col" class="wpinv_tax_country"><?php _e( 'Country', 'invoicing' ); ?></th>
1290
-				<th scope="col" class="wpinv_tax_state"><?php _e( 'State / Province', 'invoicing' ); ?></th>
1291
-                <th scope="col" class="wpinv_tax_global" title="<?php esc_attr_e( 'Apply rate to whole country, regardless of state / province', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th>
1292
-                <th scope="col" class="wpinv_tax_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> 
1293
-                <th scope="col" class="wpinv_tax_name"><?php _e( 'Tax Name', 'invoicing' ); ?></th>
1294
-				<th scope="col" class="wpinv_tax_action"><?php _e( 'Remove', 'invoicing' ); ?></th>
1289
+				<th scope="col" class="wpinv_tax_country"><?php _e('Country', 'invoicing'); ?></th>
1290
+				<th scope="col" class="wpinv_tax_state"><?php _e('State / Province', 'invoicing'); ?></th>
1291
+                <th scope="col" class="wpinv_tax_global" title="<?php esc_attr_e('Apply rate to whole country, regardless of state / province', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th>
1292
+                <th scope="col" class="wpinv_tax_rate"><?php _e('Rate %', 'invoicing'); ?></th> 
1293
+                <th scope="col" class="wpinv_tax_name"><?php _e('Tax Name', 'invoicing'); ?></th>
1294
+				<th scope="col" class="wpinv_tax_action"><?php _e('Remove', 'invoicing'); ?></th>
1295 1295
 			</tr>
1296 1296
 		</thead>
1297 1297
         <tbody>
1298
-		<?php if( !empty( $rates ) ) : ?>
1299
-			<?php foreach( $rates as $key => $rate ) : ?>
1298
+		<?php if (!empty($rates)) : ?>
1299
+			<?php foreach ($rates as $key => $rate) : ?>
1300 1300
             <?php 
1301
-            $sanitized_key = wpinv_sanitize_key( $key );
1301
+            $sanitized_key = wpinv_sanitize_key($key);
1302 1302
             ?>
1303 1303
 			<tr>
1304 1304
 				<td class="wpinv_tax_country">
1305 1305
 					<?php
1306
-					echo wpinv_html_select( array(
1307
-						'options'          => wpinv_get_country_list( true ),
1306
+					echo wpinv_html_select(array(
1307
+						'options'          => wpinv_get_country_list(true),
1308 1308
 						'name'             => 'tax_rates[' . $sanitized_key . '][country]',
1309 1309
                         'id'               => 'tax_rates[' . $sanitized_key . '][country]',
1310 1310
 						'selected'         => $rate['country'],
@@ -1312,72 +1312,72 @@  discard block
 block discarded – undo
1312 1312
 						'show_option_none' => false,
1313 1313
 						'class'            => 'wpinv-tax-country',
1314 1314
 						'chosen'           => false,
1315
-						'placeholder'      => __( 'Choose a country', 'invoicing' )
1316
-					) );
1315
+						'placeholder'      => __('Choose a country', 'invoicing')
1316
+					));
1317 1317
 					?>
1318 1318
 				</td>
1319 1319
 				<td class="wpinv_tax_state">
1320 1320
 					<?php
1321
-					$states = wpinv_get_country_states( $rate['country'] );
1322
-					if( !empty( $states ) ) {
1323
-						echo wpinv_html_select( array(
1324
-							'options'          => array_merge( array( '' => '' ), $states ),
1321
+					$states = wpinv_get_country_states($rate['country']);
1322
+					if (!empty($states)) {
1323
+						echo wpinv_html_select(array(
1324
+							'options'          => array_merge(array('' => ''), $states),
1325 1325
 							'name'             => 'tax_rates[' . $sanitized_key . '][state]',
1326 1326
                             'id'               => 'tax_rates[' . $sanitized_key . '][state]',
1327 1327
 							'selected'         => $rate['state'],
1328 1328
 							'show_option_all'  => false,
1329 1329
 							'show_option_none' => false,
1330 1330
 							'chosen'           => false,
1331
-							'placeholder'      => __( 'Choose a state', 'invoicing' )
1332
-						) );
1331
+							'placeholder'      => __('Choose a state', 'invoicing')
1332
+						));
1333 1333
 					} else {
1334
-						echo wpinv_html_text( array(
1334
+						echo wpinv_html_text(array(
1335 1335
 							'name'  => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'],
1336
-							'value' => ! empty( $rate['state'] ) ? $rate['state'] : '',
1336
+							'value' => !empty($rate['state']) ? $rate['state'] : '',
1337 1337
                             'id'    => 'tax_rates[' . $sanitized_key . '][state]',
1338
-						) );
1338
+						));
1339 1339
 					}
1340 1340
 					?>
1341 1341
 				</td>
1342 1342
 				<td class="wpinv_tax_global">
1343
-					<input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked( true, ! empty( $rate['global'] ) ); ?>/>
1344
-					<label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label>
1343
+					<input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked(true, !empty($rate['global'])); ?>/>
1344
+					<label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label>
1345 1345
 				</td>
1346
-				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[<?php echo $sanitized_key; ?>][rate]" value="<?php echo esc_html( $rate['rate'] ); ?>"/></td>
1347
-                <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[<?php echo $sanitized_key; ?>][name]" value="<?php echo esc_html( $rate['name'] ); ?>"/></td>
1348
-				<td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td>
1346
+				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[<?php echo $sanitized_key; ?>][rate]" value="<?php echo esc_html($rate['rate']); ?>"/></td>
1347
+                <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[<?php echo $sanitized_key; ?>][name]" value="<?php echo esc_html($rate['name']); ?>"/></td>
1348
+				<td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td>
1349 1349
 			</tr>
1350 1350
 			<?php endforeach; ?>
1351 1351
 		<?php else : ?>
1352 1352
 			<tr>
1353 1353
 				<td class="wpinv_tax_country">
1354 1354
 					<?php
1355
-					echo wpinv_html_select( array(
1356
-						'options'          => wpinv_get_country_list( true ),
1355
+					echo wpinv_html_select(array(
1356
+						'options'          => wpinv_get_country_list(true),
1357 1357
 						'name'             => 'tax_rates[0][country]',
1358 1358
 						'show_option_all'  => false,
1359 1359
 						'show_option_none' => false,
1360 1360
 						'class'            => 'wpinv-tax-country',
1361 1361
 						'chosen'           => false,
1362
-						'placeholder'      => __( 'Choose a country', 'invoicing' )
1363
-					) ); ?>
1362
+						'placeholder'      => __('Choose a country', 'invoicing')
1363
+					)); ?>
1364 1364
 				</td>
1365 1365
 				<td class="wpinv_tax_state">
1366
-					<?php echo wpinv_html_text( array(
1366
+					<?php echo wpinv_html_text(array(
1367 1367
 						'name' => 'tax_rates[0][state]'
1368
-					) ); ?>
1368
+					)); ?>
1369 1369
 				</td>
1370 1370
 				<td class="wpinv_tax_global">
1371 1371
 					<input type="checkbox" name="tax_rates[0][global]" id="tax_rates[0][global]" value="1"/>
1372
-					<label for="tax_rates[0][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label>
1372
+					<label for="tax_rates[0][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label>
1373 1373
 				</td>
1374
-				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[0][rate]" placeholder="<?php echo (float)wpinv_get_option( 'tax_rate', 0 ) ;?>" value="<?php echo (float)wpinv_get_option( 'tax_rate', 0 ) ;?>"/></td>
1374
+				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[0][rate]" placeholder="<?php echo (float)wpinv_get_option('tax_rate', 0); ?>" value="<?php echo (float)wpinv_get_option('tax_rate', 0); ?>"/></td>
1375 1375
                 <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[0][name]" /></td>
1376
-				<td><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td>
1376
+				<td><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td>
1377 1377
 			</tr>
1378 1378
 		<?php endif; ?>
1379 1379
         </tbody>
1380
-        <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e( 'Add Tax Rate', 'invoicing' ); ?></span></td></tr></tfoot>
1380
+        <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e('Add Tax Rate', 'invoicing'); ?></span></td></tr></tfoot>
1381 1381
 	</table>
1382 1382
 	<?php
1383 1383
 	echo ob_get_clean();
@@ -1388,44 +1388,44 @@  discard block
 block discarded – undo
1388 1388
     ob_start(); ?>
1389 1389
     </td><tr>
1390 1390
     <td colspan="2" class="wpinv_tools_tdbox">
1391
-    <?php if ( $args['desc'] ) { ?><p><?php echo $args['desc']; ?></p><?php } ?>
1392
-    <?php do_action( 'wpinv_tools_before' ); ?>
1391
+    <?php if ($args['desc']) { ?><p><?php echo $args['desc']; ?></p><?php } ?>
1392
+    <?php do_action('wpinv_tools_before'); ?>
1393 1393
     <table id="wpinv_tools_table" class="wp-list-table widefat fixed posts">
1394 1394
         <thead>
1395 1395
             <tr>
1396
-                <th scope="col" class="wpinv-th-tool"><?php _e( 'Tool', 'invoicing' ); ?></th>
1397
-                <th scope="col" class="wpinv-th-desc"><?php _e( 'Description', 'invoicing' ); ?></th>
1398
-                <th scope="col" class="wpinv-th-action"><?php _e( 'Action', 'invoicing' ); ?></th>
1396
+                <th scope="col" class="wpinv-th-tool"><?php _e('Tool', 'invoicing'); ?></th>
1397
+                <th scope="col" class="wpinv-th-desc"><?php _e('Description', 'invoicing'); ?></th>
1398
+                <th scope="col" class="wpinv-th-action"><?php _e('Action', 'invoicing'); ?></th>
1399 1399
             </tr>
1400 1400
         </thead>
1401
-            <?php do_action( 'wpinv_tools_row' ); ?>
1401
+            <?php do_action('wpinv_tools_row'); ?>
1402 1402
         <tbody>
1403 1403
         </tbody>
1404 1404
     </table>
1405
-    <?php do_action( 'wpinv_tools_after' ); ?>
1405
+    <?php do_action('wpinv_tools_after'); ?>
1406 1406
     <?php
1407 1407
     echo ob_get_clean();
1408 1408
 }
1409 1409
 
1410
-function wpinv_descriptive_text_callback( $args ) {
1411
-	echo wp_kses_post( $args['desc'] );
1410
+function wpinv_descriptive_text_callback($args) {
1411
+	echo wp_kses_post($args['desc']);
1412 1412
 }
1413 1413
 
1414
-function wpinv_hook_callback( $args ) {
1415
-	do_action( 'wpinv_' . $args['id'], $args );
1414
+function wpinv_hook_callback($args) {
1415
+	do_action('wpinv_' . $args['id'], $args);
1416 1416
 }
1417 1417
 
1418 1418
 function wpinv_set_settings_cap() {
1419 1419
 	return 'manage_options';
1420 1420
 }
1421
-add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' );
1421
+add_filter('option_page_capability_wpinv_settings', 'wpinv_set_settings_cap');
1422 1422
 
1423
-function wpinv_settings_sanitize_input( $value, $key ) {
1424
-    if ( $key == 'tax_rate' || $key == 'eu_fallback_rate' ) {
1425
-        $value = wpinv_sanitize_amount( $value, 4 );
1423
+function wpinv_settings_sanitize_input($value, $key) {
1424
+    if ($key == 'tax_rate' || $key == 'eu_fallback_rate') {
1425
+        $value = wpinv_sanitize_amount($value, 4);
1426 1426
         $value = $value >= 100 ? 99 : $value;
1427 1427
     }
1428 1428
         
1429 1429
     return $value;
1430 1430
 }
1431
-add_filter( 'wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2 );
1432 1431
\ No newline at end of file
1432
+add_filter('wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2);
1433 1433
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/wpinv-admin-functions.php 1 patch
Spacing   +200 added lines, -200 removed lines patch added patch discarded remove patch
@@ -7,228 +7,228 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14
-function wpinv_columns( $columns ) {
14
+function wpinv_columns($columns) {
15 15
     $columns = array(
16 16
         'cb'                => $columns['cb'],
17
-        'ID'                => __( 'ID', 'invoicing' ),
18
-        'details'           => __( 'Details', 'invoicing' ),
17
+        'ID'                => __('ID', 'invoicing'),
18
+        'details'           => __('Details', 'invoicing'),
19 19
         //'email'             => __( 'Email', 'invoicing' ),
20
-        'customer'          => __( 'Customer', 'invoicing' ),
21
-        'amount'            => __( 'Amount', 'invoicing' ),
22
-        'invoice_date'      => __( 'Date', 'invoicing' ),
23
-        'status'            => __( 'Status', 'invoicing' ),
24
-        'wpi_actions'       => __( 'Actions', 'invoicing' ),
20
+        'customer'          => __('Customer', 'invoicing'),
21
+        'amount'            => __('Amount', 'invoicing'),
22
+        'invoice_date'      => __('Date', 'invoicing'),
23
+        'status'            => __('Status', 'invoicing'),
24
+        'wpi_actions'       => __('Actions', 'invoicing'),
25 25
     );
26 26
 
27
-    return apply_filters( 'wpi_invoice_table_columns', $columns );
27
+    return apply_filters('wpi_invoice_table_columns', $columns);
28 28
 }
29
-add_filter( 'manage_wpi_invoice_posts_columns', 'wpinv_columns' );
29
+add_filter('manage_wpi_invoice_posts_columns', 'wpinv_columns');
30 30
 
31
-function wpinv_bulk_actions( $actions ) {
32
-    if ( isset( $actions['edit'] ) ) {
33
-        unset( $actions['edit'] );
31
+function wpinv_bulk_actions($actions) {
32
+    if (isset($actions['edit'])) {
33
+        unset($actions['edit']);
34 34
     }
35 35
 
36 36
     return $actions;
37 37
 }
38
-add_filter( 'bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions' );
38
+add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions');
39 39
 
40
-function wpinv_sortable_columns( $columns ) {
40
+function wpinv_sortable_columns($columns) {
41 41
     $columns = array(
42
-        'ID'     => array( 'ID', true ),
43
-        'amount' => array( 'amount', false ),
44
-        'invoice_date'   => array( 'date', false ),
45
-        'customer'   => array( 'customer', false ),
42
+        'ID'     => array('ID', true),
43
+        'amount' => array('amount', false),
44
+        'invoice_date'   => array('date', false),
45
+        'customer'   => array('customer', false),
46 46
         ///'email'   => array( 'email', false ),
47
-        'status'   => array( 'status', false ),
47
+        'status'   => array('status', false),
48 48
     );
49 49
     
50
-    return apply_filters( 'wpi_invoice_table_sortable_columns', $columns );
50
+    return apply_filters('wpi_invoice_table_sortable_columns', $columns);
51 51
 }
52
-add_filter( 'manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns' );
52
+add_filter('manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns');
53 53
 
54
-add_action( 'manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
55
-function wpinv_posts_custom_column( $column_name, $post_id = 0 ) {
54
+add_action('manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
55
+function wpinv_posts_custom_column($column_name, $post_id = 0) {
56 56
     global $post, $wpi_invoice;
57 57
     
58
-    if ( empty( $wpi_invoice ) || ( !empty( $wpi_invoice ) && $post->ID != $wpi_invoice->ID ) ) {
59
-        $wpi_invoice = new WPInv_Invoice( $post->ID );
58
+    if (empty($wpi_invoice) || (!empty($wpi_invoice) && $post->ID != $wpi_invoice->ID)) {
59
+        $wpi_invoice = new WPInv_Invoice($post->ID);
60 60
     }
61 61
 
62 62
     $value = NULL;
63 63
     
64
-    switch ( $column_name ) {
64
+    switch ($column_name) {
65 65
         case 'email' :
66
-            $value   = $wpi_invoice->get_email();
66
+            $value = $wpi_invoice->get_email();
67 67
             break;
68 68
         case 'customer' :
69 69
             $customer_name = $wpi_invoice->get_user_full_name();
70
-            $customer_name = $customer_name != '' ? $customer_name : __( 'Customer', 'invoicing' );
71
-            $value = '<a href="' . esc_url( get_edit_user_link( $wpi_invoice->get_user_id() ) ) . '">' . $customer_name . '</a>';
72
-            if ( $email = $wpi_invoice->get_email() ) {
70
+            $customer_name = $customer_name != '' ? $customer_name : __('Customer', 'invoicing');
71
+            $value = '<a href="' . esc_url(get_edit_user_link($wpi_invoice->get_user_id())) . '">' . $customer_name . '</a>';
72
+            if ($email = $wpi_invoice->get_email()) {
73 73
                 $value .= '<br><a class="email" href="mailto:' . $email . '">' . $email . '</a>';
74 74
             }
75 75
             break;
76 76
         case 'amount' :
77
-            echo $wpi_invoice->get_total( true );
77
+            echo $wpi_invoice->get_total(true);
78 78
             break;
79 79
         case 'invoice_date' :
80
-            $date_format = get_option( 'date_format' );
81
-            $time_format = get_option( 'time_format' );
82
-            $date_time_format = $date_format . ' '. $time_format;
80
+            $date_format = get_option('date_format');
81
+            $time_format = get_option('time_format');
82
+            $date_time_format = $date_format . ' ' . $time_format;
83 83
             
84
-            $t_time = get_the_time( $date_time_format );
84
+            $t_time = get_the_time($date_time_format);
85 85
             $m_time = $post->post_date;
86
-            $h_time = mysql2date( $date_format, $m_time );
86
+            $h_time = mysql2date($date_format, $m_time);
87 87
             
88 88
             $value   = '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';
89 89
             break;
90 90
         case 'status' :
91
-            $value   = $wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' );
91
+            $value   = $wpi_invoice->get_status(true) . ($wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '');
92 92
             break;
93 93
         case 'details' :
94
-            $edit_link = get_edit_post_link( $post->ID );
95
-            $value = '<a href="' . esc_url( $edit_link ) . '">' . __( 'View Invoice Details', 'invoicing' ) . '</a>';
94
+            $edit_link = get_edit_post_link($post->ID);
95
+            $value = '<a href="' . esc_url($edit_link) . '">' . __('View Invoice Details', 'invoicing') . '</a>';
96 96
             break;
97 97
         case 'wpi_actions' :
98 98
             $value = '';
99
-            if ( !empty( $post->post_name ) ) {
100
-                $value .= '<a title="' . esc_attr__( 'Print invoice', 'invoicing' ) . '" href="' . esc_url( get_permalink( $post->ID ) ) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
99
+            if (!empty($post->post_name)) {
100
+                $value .= '<a title="' . esc_attr__('Print invoice', 'invoicing') . '" href="' . esc_url(get_permalink($post->ID)) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
101 101
             }
102 102
             
103
-            if ( $email = $wpi_invoice->get_email() ) {
104
-                $value .= '<a title="' . esc_attr__( 'Send invoice to customer', 'invoicing' ) . '" href="' . esc_url( add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) ) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
103
+            if ($email = $wpi_invoice->get_email()) {
104
+                $value .= '<a title="' . esc_attr__('Send invoice to customer', 'invoicing') . '" href="' . esc_url(add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID))) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
105 105
             }
106 106
             
107 107
             break;
108 108
         default:
109
-            $value = isset( $post->$column_name ) ? $post->$column_name : '';
109
+            $value = isset($post->$column_name) ? $post->$column_name : '';
110 110
             break;
111 111
 
112 112
     }
113
-    $value = apply_filters( 'wpinv_payments_table_column', $value, $post->ID, $column_name );
113
+    $value = apply_filters('wpinv_payments_table_column', $value, $post->ID, $column_name);
114 114
     
115
-    if ( $value !== NULL ) {
115
+    if ($value !== NULL) {
116 116
         echo $value;
117 117
     }
118 118
 }
119 119
 
120
-function wpinv_admin_post_id( $id = 0 ) {
120
+function wpinv_admin_post_id($id = 0) {
121 121
     global $post;
122 122
 
123
-    if ( isset( $id ) && ! empty( $id ) ) {
123
+    if (isset($id) && !empty($id)) {
124 124
         return (int)$id;
125
-    } else if ( get_the_ID() ) {
126
-        return (int) get_the_ID();
127
-    } else if ( isset( $post->ID ) && !empty( $post->ID ) ) {
128
-        return (int) $post->ID;
129
-    } else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) {
130
-        return (int) $_GET['post'];
131
-    } else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) {
132
-        return (int) $_GET['id'];
133
-    } else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) {
134
-        return (int) $_POST['id'];
125
+    } else if (get_the_ID()) {
126
+        return (int)get_the_ID();
127
+    } else if (isset($post->ID) && !empty($post->ID)) {
128
+        return (int)$post->ID;
129
+    } else if (isset($_GET['post']) && !empty($_GET['post'])) {
130
+        return (int)$_GET['post'];
131
+    } else if (isset($_GET['id']) && !empty($_GET['id'])) {
132
+        return (int)$_GET['id'];
133
+    } else if (isset($_POST['id']) && !empty($_POST['id'])) {
134
+        return (int)$_POST['id'];
135 135
     } 
136 136
 
137 137
     return null;
138 138
 }
139 139
     
140
-function wpinv_admin_post_type( $id = 0 ) {
141
-    if ( !$id ) {
140
+function wpinv_admin_post_type($id = 0) {
141
+    if (!$id) {
142 142
         $id = wpinv_admin_post_id();
143 143
     }
144 144
     
145
-    $type = get_post_type( $id );
145
+    $type = get_post_type($id);
146 146
     
147
-    if ( !$type ) {
148
-        $type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null;
147
+    if (!$type) {
148
+        $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? $_GET['post_type'] : null;
149 149
     }
150 150
     
151
-    return apply_filters( 'wpinv_admin_post_type', $type, $id );
151
+    return apply_filters('wpinv_admin_post_type', $type, $id);
152 152
 }
153 153
 
154 154
 function wpinv_admin_messages() {
155 155
 	global $wpinv_options;
156 156
 
157
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
158
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' );
157
+	if (isset($_GET['wpinv-message']) && 'discount_added' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
158
+		 add_settings_error('wpinv-notices', 'wpinv-discount-added', __('Discount code added.', 'invoicing'), 'updated');
159 159
 	}
160 160
 
161
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
162
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' );
161
+	if (isset($_GET['wpinv-message']) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
162
+		add_settings_error('wpinv-notices', 'wpinv-discount-add-fail', __('There was a problem adding your discount code, please try again.', 'invoicing'), 'error');
163 163
 	}
164 164
 
165
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
166
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' );
165
+	if (isset($_GET['wpinv-message']) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
166
+		add_settings_error('wpinv-notices', 'wpinv-discount-exists', __('A discount with that code already exists, please use a different code.', 'invoicing'), 'error');
167 167
 	}
168 168
 
169
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
170
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' );
169
+	if (isset($_GET['wpinv-message']) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
170
+		 add_settings_error('wpinv-notices', 'wpinv-discount-updated', __('Discount code updated.', 'invoicing'), 'updated');
171 171
 	}
172 172
 
173
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
174
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' );
173
+	if (isset($_GET['wpinv-message']) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
174
+		add_settings_error('wpinv-notices', 'wpinv-discount-updated-fail', __('There was a problem updating your discount code, please try again.', 'invoicing'), 'error');
175 175
 	}
176 176
 
177
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
178
-		add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' );
177
+	if (isset($_GET['wpinv-message']) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
178
+		add_settings_error('wpinv-notices', 'wpinv-deleted', __('The invoice has been deleted.', 'invoicing'), 'updated');
179 179
 	}
180 180
 
181
-	if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
182
-		add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' );
181
+	if (isset($_GET['wpinv-message']) && 'email_sent' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
182
+		add_settings_error('wpinv-notices', 'wpinv-sent', __('The email has been sent to customer.', 'invoicing'), 'updated');
183 183
     }
184 184
     
185
-    if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
186
-		add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' );
185
+    if (isset($_GET['wpinv-message']) && 'email_fail' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
186
+		add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Fail to send email to the customer.', 'invoicing'), 'error');
187 187
     }
188 188
 
189
-    if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
190
-        add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' );
189
+    if (isset($_GET['wpinv-message']) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
190
+        add_settings_error('wpinv-notices', 'wpinv-note-deleted', __('The invoice note has been deleted.', 'invoicing'), 'updated');
191 191
     }
192 192
 
193
-	if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
194
-		add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' );
193
+	if (isset($_GET['wpinv-message']) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
194
+		add_settings_error('wpinv-notices', 'wpinv-settings-imported', __('The settings have been imported.', 'invoicing'), 'updated');
195 195
 	}
196 196
 
197
-	if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
198
-		add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' );
197
+	if (isset($_GET['wpinv-message']) && 'note-added' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
198
+		add_settings_error('wpinv-notices', 'wpinv-note-added', __('The invoice note has been added successfully.', 'invoicing'), 'updated');
199 199
 	}
200 200
 
201
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
202
-		add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' );
201
+	if (isset($_GET['wpinv-message']) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
202
+		add_settings_error('wpinv-notices', 'wpinv-updated', __('The invoice has been successfully updated.', 'invoicing'), 'updated');
203 203
 	}
204 204
 
205
-	settings_errors( 'wpinv-notices' );
205
+	settings_errors('wpinv-notices');
206 206
 }
207
-add_action( 'admin_notices', 'wpinv_admin_messages' );
207
+add_action('admin_notices', 'wpinv_admin_messages');
208 208
 
209
-function wpinv_items_columns( $existing_columns ) {
209
+function wpinv_items_columns($existing_columns) {
210 210
     global $wpinv_euvat;
211 211
     
212 212
     $columns                = array();
213 213
     $columns['cb']          = $existing_columns['cb'];
214
-    $columns['title']       = __( 'Title', 'invoicing' );
215
-    $columns['price']       = __( 'Price', 'invoicing' );
216
-    if ( $wpinv_euvat->allow_vat_rules() ) {
217
-        $columns['vat_rule']    = __( 'VAT rule type', 'invoicing' );
214
+    $columns['title']       = __('Title', 'invoicing');
215
+    $columns['price']       = __('Price', 'invoicing');
216
+    if ($wpinv_euvat->allow_vat_rules()) {
217
+        $columns['vat_rule']    = __('VAT rule type', 'invoicing');
218 218
     }
219
-    if ( $wpinv_euvat->allow_vat_classes() ) {
220
-        $columns['vat_class']   = __( 'VAT class', 'invoicing' );
219
+    if ($wpinv_euvat->allow_vat_classes()) {
220
+        $columns['vat_class']   = __('VAT class', 'invoicing');
221 221
     }
222
-    $columns['type']        = __( 'Type', 'invoicing' );
223
-    $columns['recurring']   = __( 'Recurring', 'invoicing' );
224
-    $columns['date']        = __( 'Date', 'invoicing' );
225
-    $columns['id']          = __( 'ID', 'invoicing' );
222
+    $columns['type']        = __('Type', 'invoicing');
223
+    $columns['recurring']   = __('Recurring', 'invoicing');
224
+    $columns['date']        = __('Date', 'invoicing');
225
+    $columns['id']          = __('ID', 'invoicing');
226 226
 
227
-    return apply_filters( 'wpinv_items_columns', $columns );
227
+    return apply_filters('wpinv_items_columns', $columns);
228 228
 }
229
-add_filter( 'manage_wpi_item_posts_columns', 'wpinv_items_columns' );
229
+add_filter('manage_wpi_item_posts_columns', 'wpinv_items_columns');
230 230
 
231
-function wpinv_items_sortable_columns( $columns ) {
231
+function wpinv_items_sortable_columns($columns) {
232 232
     $columns['price']       = 'price';
233 233
     $columns['vat_rule']    = 'vat_rule';
234 234
     $columns['vat_class']   = 'vat_class';
@@ -238,10 +238,10 @@  discard block
 block discarded – undo
238 238
 
239 239
     return $columns;
240 240
 }
241
-add_filter( 'manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns' );
241
+add_filter('manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns');
242 242
 
243
-function wpinv_item_quick_edit( $column_name, $post_type ) {
244
-    if ( !( $post_type == 'wpi_item' && $column_name == 'price' ) ) {
243
+function wpinv_item_quick_edit($column_name, $post_type) {
244
+    if (!($post_type == 'wpi_item' && $column_name == 'price')) {
245 245
         return;
246 246
     }
247 247
     global $wpinv_euvat, $post;
@@ -249,23 +249,23 @@  discard block
 block discarded – undo
249 249
     $symbol    = wpinv_currency_symbol();
250 250
     $position  = wpinv_currency_position();
251 251
 
252
-    $price     = wpinv_get_item_price( $post->ID );
253
-    $item_type = wpinv_get_item_type( $post->ID );
252
+    $price     = wpinv_get_item_price($post->ID);
253
+    $item_type = wpinv_get_item_type($post->ID);
254 254
     ?>
255 255
     <fieldset class="inline-edit-col-right wpi-inline-item-col">
256 256
         <div class="inline-edit-col">
257 257
             <div class="inline-edit-group wp-clearfix">
258 258
                 <label class="inline-edit-wpinv-price">
259
-                    <span class="title"><?php _e( 'Item price', 'invoicing' );?></span>
260
-                    <span class="input-text-wrap"><?php echo ( $position != 'right' ? $symbol . '&nbsp;' : '' );?><input type="text" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" name="_wpinv_item_price" class="wpi-field-price wpi-price" id="wpinv_item_price-<?php echo $post->ID;?>"><?php echo ( $position == 'right' ? $symbol . '&nbsp;' : '' );?></span>
259
+                    <span class="title"><?php _e('Item price', 'invoicing'); ?></span>
260
+                    <span class="input-text-wrap"><?php echo ($position != 'right' ? $symbol . '&nbsp;' : ''); ?><input type="text" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" name="_wpinv_item_price" class="wpi-field-price wpi-price" id="wpinv_item_price-<?php echo $post->ID; ?>"><?php echo ($position == 'right' ? $symbol . '&nbsp;' : ''); ?></span>
261 261
                 </label>
262 262
             </div>
263
-            <?php if ( $wpinv_euvat->allow_vat_rules() ) { $rule_type = $wpinv_euvat->get_item_rule( $post->ID ); ?>
263
+            <?php if ($wpinv_euvat->allow_vat_rules()) { $rule_type = $wpinv_euvat->get_item_rule($post->ID); ?>
264 264
             <div class="inline-edit-group wp-clearfix">
265 265
                 <label class="inline-edit-wpinv-vat-rate">
266
-                    <span class="title"><?php _e( 'VAT rule type to use', 'invoicing' );?></span>
266
+                    <span class="title"><?php _e('VAT rule type to use', 'invoicing'); ?></span>
267 267
                     <span class="input-text-wrap">
268
-                        <?php echo wpinv_html_select( array(
268
+                        <?php echo wpinv_html_select(array(
269 269
                             'options'          => $wpinv_euvat->get_rules(),
270 270
                             'name'             => '_wpinv_vat_rules',
271 271
                             'id'               => 'wpinv_vat_rules-' . $post->ID,
@@ -273,16 +273,16 @@  discard block
 block discarded – undo
273 273
                             'show_option_all'  => false,
274 274
                             'show_option_none' => false,
275 275
                             'class'            => 'gdmbx2-text-medium wpinv-vat-rules',
276
-                        ) ); ?>
276
+                        )); ?>
277 277
                     </span>
278 278
                 </label>
279 279
             </div>
280
-            <?php } if ( $wpinv_euvat->allow_vat_classes() ) { $vat_class = $wpinv_euvat->get_item_class( $post->ID ); ?>
280
+            <?php } if ($wpinv_euvat->allow_vat_classes()) { $vat_class = $wpinv_euvat->get_item_class($post->ID); ?>
281 281
             <div class="inline-edit-group wp-clearfix">
282 282
                 <label class="inline-edit-wpinv-vat-class">
283
-                    <span class="title"><?php _e( 'VAT class to use', 'invoicing' );?></span>
283
+                    <span class="title"><?php _e('VAT class to use', 'invoicing'); ?></span>
284 284
                     <span class="input-text-wrap">
285
-                        <?php echo wpinv_html_select( array(
285
+                        <?php echo wpinv_html_select(array(
286 286
                             'options'          => $wpinv_euvat->get_all_classes(),
287 287
                             'name'             => '_wpinv_vat_class',
288 288
                             'id'               => 'wpinv_vat_class-' . $post->ID,
@@ -290,16 +290,16 @@  discard block
 block discarded – undo
290 290
                             'show_option_all'  => false,
291 291
                             'show_option_none' => false,
292 292
                             'class'            => 'gdmbx2-text-medium wpinv-vat-class',
293
-                        ) ); ?>
293
+                        )); ?>
294 294
                     </span>
295 295
                 </label>
296 296
             </div>
297 297
             <?php } ?>
298 298
             <div class="inline-edit-group wp-clearfix">
299 299
                 <label class="inline-edit-wpinv-type">
300
-                    <span class="title"><?php _e( 'Item type', 'invoicing' );?></span>
300
+                    <span class="title"><?php _e('Item type', 'invoicing'); ?></span>
301 301
                     <span class="input-text-wrap">
302
-                        <?php echo wpinv_html_select( array(
302
+                        <?php echo wpinv_html_select(array(
303 303
                             'options'          => wpinv_get_item_types(),
304 304
                             'name'             => '_wpinv_item_type',
305 305
                             'id'               => 'wpinv_item_type-' . $post->ID,
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
                             'show_option_all'  => false,
308 308
                             'show_option_none' => false,
309 309
                             'class'            => 'gdmbx2-text-medium wpinv-item-type',
310
-                        ) ); ?>
310
+                        )); ?>
311 311
                     </span>
312 312
                 </label>
313 313
             </div>
@@ -315,157 +315,157 @@  discard block
 block discarded – undo
315 315
     </fieldset>
316 316
     <?php
317 317
 }
318
-add_action( 'quick_edit_custom_box', 'wpinv_item_quick_edit', 10, 2 );
319
-add_action( 'bulk_edit_custom_box', 'wpinv_item_quick_edit', 10, 2 );
318
+add_action('quick_edit_custom_box', 'wpinv_item_quick_edit', 10, 2);
319
+add_action('bulk_edit_custom_box', 'wpinv_item_quick_edit', 10, 2);
320 320
 
321
-function wpinv_items_table_custom_column( $column ) {
321
+function wpinv_items_table_custom_column($column) {
322 322
     global $wpinv_euvat, $post, $wpi_item;
323 323
     
324
-    if ( empty( $wpi_item ) || ( !empty( $wpi_item ) && $post->ID != $wpi_item->ID ) ) {
325
-        $wpi_item = new WPInv_Item( $post->ID );
324
+    if (empty($wpi_item) || (!empty($wpi_item) && $post->ID != $wpi_item->ID)) {
325
+        $wpi_item = new WPInv_Item($post->ID);
326 326
     }
327 327
 
328
-    switch ( $column ) {
328
+    switch ($column) {
329 329
         case 'price' :
330
-            echo wpinv_item_price( $post->ID );
330
+            echo wpinv_item_price($post->ID);
331 331
         break;
332 332
         case 'vat_rule' :
333
-            echo $wpinv_euvat->item_rule_label( $post->ID );
333
+            echo $wpinv_euvat->item_rule_label($post->ID);
334 334
         break;
335 335
         case 'vat_class' :
336
-            echo $wpinv_euvat->item_class_label( $post->ID );
336
+            echo $wpinv_euvat->item_class_label($post->ID);
337 337
         break;
338 338
         case 'type' :
339
-            echo wpinv_item_type( $post->ID ) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>';
339
+            echo wpinv_item_type($post->ID) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>';
340 340
         break;
341 341
         case 'recurring' :
342
-            echo ( wpinv_is_recurring_item( $post->ID ) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>' );
342
+            echo (wpinv_is_recurring_item($post->ID) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>');
343 343
         break;
344 344
         case 'id' :
345 345
            echo $post->ID;
346 346
            echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '">
347
-                    <div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>';
348
-                    if ( $wpinv_euvat->allow_vat_rules() ) {
349
-                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</div>';
347
+                    <div class="price">' . wpinv_get_item_price($post->ID) . '</div>';
348
+                    if ($wpinv_euvat->allow_vat_rules()) {
349
+                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule($post->ID) . '</div>';
350 350
                     }
351
-                    if ( $wpinv_euvat->allow_vat_classes() ) {
352
-                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class( $post->ID ) . '</div>';
351
+                    if ($wpinv_euvat->allow_vat_classes()) {
352
+                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class($post->ID) . '</div>';
353 353
                     }
354
-                    echo '<div class="type">' . wpinv_get_item_type( $post->ID ) . '</div>
354
+                    echo '<div class="type">' . wpinv_get_item_type($post->ID) . '</div>
355 355
                 </div>';
356 356
         break;
357 357
     }
358 358
     
359
-    do_action( 'wpinv_items_table_column_item_' . $column, $wpi_item, $post );
359
+    do_action('wpinv_items_table_column_item_' . $column, $wpi_item, $post);
360 360
 }
361
-add_action( 'manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column' );
361
+add_action('manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column');
362 362
 
363 363
 function wpinv_add_items_filters() {
364 364
     global $wpinv_euvat, $typenow;
365 365
 
366 366
     // Checks if the current post type is 'item'
367
-    if ( $typenow == 'wpi_item') {
368
-        if ( $wpinv_euvat->allow_vat_rules() ) {
369
-            echo wpinv_html_select( array(
370
-                    'options'          => array_merge( array( '' => __( 'All VAT rules', 'invoicing' ) ), $wpinv_euvat->get_rules() ),
367
+    if ($typenow == 'wpi_item') {
368
+        if ($wpinv_euvat->allow_vat_rules()) {
369
+            echo wpinv_html_select(array(
370
+                    'options'          => array_merge(array('' => __('All VAT rules', 'invoicing')), $wpinv_euvat->get_rules()),
371 371
                     'name'             => 'vat_rule',
372 372
                     'id'               => 'vat_rule',
373
-                    'selected'         => ( isset( $_GET['vat_rule'] ) ? $_GET['vat_rule'] : '' ),
373
+                    'selected'         => (isset($_GET['vat_rule']) ? $_GET['vat_rule'] : ''),
374 374
                     'show_option_all'  => false,
375 375
                     'show_option_none' => false,
376 376
                     'class'            => 'gdmbx2-text-medium',
377
-                ) );
377
+                ));
378 378
         }
379 379
         
380
-        if ( $wpinv_euvat->allow_vat_classes() ) {
381
-            echo wpinv_html_select( array(
382
-                    'options'          => array_merge( array( '' => __( 'All VAT classes', 'invoicing' ) ), $wpinv_euvat->get_all_classes() ),
380
+        if ($wpinv_euvat->allow_vat_classes()) {
381
+            echo wpinv_html_select(array(
382
+                    'options'          => array_merge(array('' => __('All VAT classes', 'invoicing')), $wpinv_euvat->get_all_classes()),
383 383
                     'name'             => 'vat_class',
384 384
                     'id'               => 'vat_class',
385
-                    'selected'         => ( isset( $_GET['vat_class'] ) ? $_GET['vat_class'] : '' ),
385
+                    'selected'         => (isset($_GET['vat_class']) ? $_GET['vat_class'] : ''),
386 386
                     'show_option_all'  => false,
387 387
                     'show_option_none' => false,
388 388
                     'class'            => 'gdmbx2-text-medium',
389
-                ) );
389
+                ));
390 390
         }
391 391
             
392
-        echo wpinv_html_select( array(
393
-                'options'          => array_merge( array( '' => __( 'All item types', 'invoicing' ) ), wpinv_get_item_types() ),
392
+        echo wpinv_html_select(array(
393
+                'options'          => array_merge(array('' => __('All item types', 'invoicing')), wpinv_get_item_types()),
394 394
                 'name'             => 'type',
395 395
                 'id'               => 'type',
396
-                'selected'         => ( isset( $_GET['type'] ) ? $_GET['type'] : '' ),
396
+                'selected'         => (isset($_GET['type']) ? $_GET['type'] : ''),
397 397
                 'show_option_all'  => false,
398 398
                 'show_option_none' => false,
399 399
                 'class'            => 'gdmbx2-text-medium',
400
-            ) );
400
+            ));
401 401
 
402
-        if ( isset( $_REQUEST['all_posts'] ) && '1' === $_REQUEST['all_posts'] ) {
402
+        if (isset($_REQUEST['all_posts']) && '1' === $_REQUEST['all_posts']) {
403 403
             echo '<input type="hidden" name="all_posts" value="1" />';
404 404
         }
405 405
     }
406 406
 }
407
-add_action( 'restrict_manage_posts', 'wpinv_add_items_filters', 100 );
407
+add_action('restrict_manage_posts', 'wpinv_add_items_filters', 100);
408 408
 
409
-function wpinv_send_invoice_after_save( $post_id ) {
409
+function wpinv_send_invoice_after_save($post_id) {
410 410
     // If this is just a revision, don't send the email.
411
-    if ( wp_is_post_revision( $post_id ) ) {
411
+    if (wp_is_post_revision($post_id)) {
412 412
         return;
413 413
     }
414 414
     
415
-    if ( !current_user_can( 'manage_options' ) || !(get_post_type( $post_id ) == 'wpi_invoice')  ) {
415
+    if (!current_user_can('manage_options') || !(get_post_type($post_id) == 'wpi_invoice')) {
416 416
         return;
417 417
     }
418 418
     
419
-    if ( !empty( $_POST['wpi_save_send'] ) ) {
420
-        wpinv_user_invoice_notification( $post_id );
419
+    if (!empty($_POST['wpi_save_send'])) {
420
+        wpinv_user_invoice_notification($post_id);
421 421
     }
422 422
 }
423
-add_action( 'save_post_wpi_invoice', 'wpinv_send_invoice_after_save', 100, 1 );
423
+add_action('save_post_wpi_invoice', 'wpinv_send_invoice_after_save', 100, 1);
424 424
 
425
-function wpinv_send_register_new_user( $data, $postarr ) {
426
-    if ( current_user_can( 'manage_options' ) && !empty( $data['post_type'] ) && ($data['post_type'] == 'wpi_invoice' || $data['post_type'] == 'wpi_quote') ) {
427
-        $is_new_user = !empty( $postarr['wpinv_new_user'] ) ? true : false;
428
-        $email = !empty( $postarr['wpinv_email'] ) && $postarr['wpinv_email'] && is_email( $postarr['wpinv_email'] ) ? $postarr['wpinv_email'] : NULL;
425
+function wpinv_send_register_new_user($data, $postarr) {
426
+    if (current_user_can('manage_options') && !empty($data['post_type']) && ($data['post_type'] == 'wpi_invoice' || $data['post_type'] == 'wpi_quote')) {
427
+        $is_new_user = !empty($postarr['wpinv_new_user']) ? true : false;
428
+        $email = !empty($postarr['wpinv_email']) && $postarr['wpinv_email'] && is_email($postarr['wpinv_email']) ? $postarr['wpinv_email'] : NULL;
429 429
         
430
-        if ( $is_new_user && $email && !email_exists( $email ) ) {
431
-            $first_name = !empty( $postarr['wpinv_first_name'] ) ? sanitize_text_field( $postarr['wpinv_first_name'] ) : '';
432
-            $last_name = !empty( $postarr['wpinv_last_name'] ) ? sanitize_text_field( $postarr['wpinv_last_name'] ) : '';
433
-            $display_name = $first_name || $last_name ? trim( $first_name . ' ' . $last_name ) : '';
434
-            $user_nicename = $display_name ? trim( $display_name ) : $email;
435
-            $user_company = !empty( $postarr['wpinv_company'] ) ? sanitize_text_field( $postarr['wpinv_company'] ) : '';
430
+        if ($is_new_user && $email && !email_exists($email)) {
431
+            $first_name = !empty($postarr['wpinv_first_name']) ? sanitize_text_field($postarr['wpinv_first_name']) : '';
432
+            $last_name = !empty($postarr['wpinv_last_name']) ? sanitize_text_field($postarr['wpinv_last_name']) : '';
433
+            $display_name = $first_name || $last_name ? trim($first_name . ' ' . $last_name) : '';
434
+            $user_nicename = $display_name ? trim($display_name) : $email;
435
+            $user_company = !empty($postarr['wpinv_company']) ? sanitize_text_field($postarr['wpinv_company']) : '';
436 436
             
437
-            $user_login = sanitize_user( str_replace( ' ', '', $display_name ), true );
438
-            if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
437
+            $user_login = sanitize_user(str_replace(' ', '', $display_name), true);
438
+            if (!(validate_username($user_login) && !username_exists($user_login))) {
439 439
                 $new_user_login = strstr($email, '@', true);
440
-                if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
441
-                    $user_login = sanitize_user($new_user_login, true );
440
+                if (validate_username($user_login) && username_exists($user_login)) {
441
+                    $user_login = sanitize_user($new_user_login, true);
442 442
                 }
443
-                if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
444
-                    $user_append_text = rand(10,1000);
445
-                    $user_login = sanitize_user($new_user_login.$user_append_text, true );
443
+                if (validate_username($user_login) && username_exists($user_login)) {
444
+                    $user_append_text = rand(10, 1000);
445
+                    $user_login = sanitize_user($new_user_login . $user_append_text, true);
446 446
                 }
447 447
                 
448
-                if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
448
+                if (!(validate_username($user_login) && !username_exists($user_login))) {
449 449
                     $user_login = $email;
450 450
                 }
451 451
             }
452 452
             
453 453
             $userdata = array(
454 454
                 'user_login' => $user_login,
455
-                'user_pass' => wp_generate_password( 12, false ),
456
-                'user_email' => sanitize_text_field( $email ),
455
+                'user_pass' => wp_generate_password(12, false),
456
+                'user_email' => sanitize_text_field($email),
457 457
                 'first_name' => $first_name,
458 458
                 'last_name' => $last_name,
459
-                'user_nicename' => wpinv_utf8_substr( $user_nicename, 0, 50 ),
459
+                'user_nicename' => wpinv_utf8_substr($user_nicename, 0, 50),
460 460
                 'nickname' => $display_name,
461 461
                 'display_name' => $display_name,
462 462
             );
463 463
 
464
-            $userdata = apply_filters( 'wpinv_register_new_user_data', $userdata );
464
+            $userdata = apply_filters('wpinv_register_new_user_data', $userdata);
465 465
             
466
-            $new_user_id = wp_insert_user( $userdata );
466
+            $new_user_id = wp_insert_user($userdata);
467 467
             
468
-            if ( !is_wp_error( $new_user_id ) ) {
468
+            if (!is_wp_error($new_user_id)) {
469 469
                 $data['post_author'] = $new_user_id;
470 470
                 $_POST['post_author'] = $new_user_id;
471 471
                 $_POST['post_author_override'] = $new_user_id;
@@ -486,27 +486,27 @@  discard block
 block discarded – undo
486 486
                 
487 487
                 $meta = array();
488 488
                 ///$meta['_wpinv_user_id'] = $new_user_id;
489
-                foreach ( $meta_fields as $field ) {
490
-                    $meta['_wpinv_' . $field] = isset( $postarr['wpinv_' . $field] ) ? sanitize_text_field( $postarr['wpinv_' . $field] ) : '';
489
+                foreach ($meta_fields as $field) {
490
+                    $meta['_wpinv_' . $field] = isset($postarr['wpinv_' . $field]) ? sanitize_text_field($postarr['wpinv_' . $field]) : '';
491 491
                 }
492 492
                 
493
-                $meta = apply_filters( 'wpinv_register_new_user_meta', $meta, $new_user_id );
493
+                $meta = apply_filters('wpinv_register_new_user_meta', $meta, $new_user_id);
494 494
 
495 495
                 // Update user meta.
496
-                foreach ( $meta as $key => $value ) {
497
-                    update_user_meta( $new_user_id, $key, $value );
496
+                foreach ($meta as $key => $value) {
497
+                    update_user_meta($new_user_id, $key, $value);
498 498
                 }
499 499
                 
500
-                if ( function_exists( 'wp_send_new_user_notifications' ) ) {
500
+                if (function_exists('wp_send_new_user_notifications')) {
501 501
                     // Send email notifications related to the creation of new user.
502
-                    wp_send_new_user_notifications( $new_user_id, 'user' );
502
+                    wp_send_new_user_notifications($new_user_id, 'user');
503 503
                 }
504 504
             } else {
505
-                wpinv_error_log( $new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__ );
505
+                wpinv_error_log($new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__);
506 506
             }
507 507
         }
508 508
     }
509 509
     
510 510
     return $data;
511 511
 }
512
-add_filter( 'wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2 );
513 512
\ No newline at end of file
513
+add_filter('wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2);
514 514
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 1 patch
Spacing   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -7,28 +7,28 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 class WPInv_Ajax {
15 15
     public static function init() {
16
-        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
17
-        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
16
+        add_action('init', array(__CLASS__, 'define_ajax'), 0);
17
+        add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
18 18
         self::add_ajax_events();
19 19
     }
20 20
 
21 21
     public static function define_ajax() {
22
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
23
-            if ( ! defined( 'DOING_AJAX' ) ) {
24
-                define( 'DOING_AJAX', true );
22
+        if (!empty($_GET['wpinv-ajax'])) {
23
+            if (!defined('DOING_AJAX')) {
24
+                define('DOING_AJAX', true);
25 25
             }
26
-            if ( ! defined( 'WC_DOING_AJAX' ) ) {
27
-                define( 'WC_DOING_AJAX', true );
26
+            if (!defined('WC_DOING_AJAX')) {
27
+                define('WC_DOING_AJAX', true);
28 28
             }
29 29
             // Turn off display_errors during AJAX events to prevent malformed JSON
30
-            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
31
-                @ini_set( 'display_errors', 0 );
30
+            if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
31
+                @ini_set('display_errors', 0);
32 32
             }
33 33
             $GLOBALS['wpdb']->hide_errors();
34 34
         }
@@ -37,24 +37,24 @@  discard block
 block discarded – undo
37 37
     public static function do_wpinv_ajax() {
38 38
         global $wp_query;
39 39
 
40
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
41
-            $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) );
40
+        if (!empty($_GET['wpinv-ajax'])) {
41
+            $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax']));
42 42
         }
43 43
 
44
-        if ( $action = $wp_query->get( 'wpinv-ajax' ) ) {
44
+        if ($action = $wp_query->get('wpinv-ajax')) {
45 45
             self::wpinv_ajax_headers();
46
-            do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) );
46
+            do_action('wpinv_ajax_' . sanitize_text_field($action));
47 47
             die();
48 48
         }
49 49
     }
50 50
     
51 51
     private static function wpinv_ajax_headers() {
52 52
         send_origin_headers();
53
-        @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
54
-        @header( 'X-Robots-Tag: noindex' );
53
+        @header('Content-Type: text/html; charset=' . get_option('blog_charset'));
54
+        @header('X-Robots-Tag: noindex');
55 55
         send_nosniff_header();
56 56
         nocache_headers();
57
-        status_header( 200 );
57
+        status_header(200);
58 58
     }
59 59
     
60 60
     public static function add_ajax_events() {
@@ -76,39 +76,39 @@  discard block
 block discarded – undo
76 76
             'remove_discount' => false,
77 77
         );
78 78
 
79
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
80
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
79
+        foreach ($ajax_events as $ajax_event => $nopriv) {
80
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
81 81
             
82
-            if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) {
83
-                define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 );
82
+            if (!defined('WPI_AJAX_' . strtoupper($nopriv))) {
83
+                define('WPI_AJAX_' . strtoupper($nopriv), 1);
84 84
             }
85 85
 
86
-            if ( $nopriv ) {
87
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
86
+            if ($nopriv) {
87
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
88 88
 
89
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
89
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
90 90
             }
91 91
         }
92 92
     }
93 93
     
94 94
     public static function add_note() {
95
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
95
+        check_ajax_referer('add-invoice-note', '_nonce');
96 96
 
97
-        if ( !current_user_can( 'manage_options' ) ) {
97
+        if (!current_user_can('manage_options')) {
98 98
             die(-1);
99 99
         }
100 100
 
101
-        $post_id   = absint( $_POST['post_id'] );
102
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
103
-        $note_type = sanitize_text_field( $_POST['note_type'] );
101
+        $post_id   = absint($_POST['post_id']);
102
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
103
+        $note_type = sanitize_text_field($_POST['note_type']);
104 104
 
105 105
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
106 106
 
107
-        if ( $post_id > 0 ) {
108
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
107
+        if ($post_id > 0) {
108
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
109 109
 
110
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
111
-                wpinv_get_invoice_note_line_item( $note_id );
110
+            if ($note_id > 0 && !is_wp_error($note_id)) {
111
+                wpinv_get_invoice_note_line_item($note_id);
112 112
             }
113 113
         }
114 114
 
@@ -116,16 +116,16 @@  discard block
 block discarded – undo
116 116
     }
117 117
 
118 118
     public static function delete_note() {
119
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
119
+        check_ajax_referer('delete-invoice-note', '_nonce');
120 120
 
121
-        if ( !current_user_can( 'manage_options' ) ) {
121
+        if (!current_user_can('manage_options')) {
122 122
             die(-1);
123 123
         }
124 124
 
125 125
         $note_id = (int)$_POST['note_id'];
126 126
 
127
-        if ( $note_id > 0 ) {
128
-            wp_delete_comment( $note_id, true );
127
+        if ($note_id > 0) {
128
+            wp_delete_comment($note_id, true);
129 129
         }
130 130
 
131 131
         die();
@@ -138,8 +138,8 @@  discard block
 block discarded – undo
138 138
     }
139 139
     
140 140
     public static function checkout() {
141
-        if ( ! defined( 'WPINV_CHECKOUT' ) ) {
142
-            define( 'WPINV_CHECKOUT', true );
141
+        if (!defined('WPINV_CHECKOUT')) {
142
+            define('WPINV_CHECKOUT', true);
143 143
         }
144 144
 
145 145
         wpinv_process_checkout();
@@ -148,53 +148,53 @@  discard block
 block discarded – undo
148 148
     
149 149
     public static function add_invoice_item() {
150 150
         global $wpi_userID, $wpinv_ip_address_country;
151
-        check_ajax_referer( 'invoice-item', '_nonce' );
152
-        if ( !current_user_can( 'manage_options' ) ) {
151
+        check_ajax_referer('invoice-item', '_nonce');
152
+        if (!current_user_can('manage_options')) {
153 153
             die(-1);
154 154
         }
155 155
         
156
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
157
-        $invoice_id = absint( $_POST['invoice_id'] );
156
+        $item_id    = sanitize_text_field($_POST['item_id']);
157
+        $invoice_id = absint($_POST['invoice_id']);
158 158
         
159
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
159
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
160 160
             die();
161 161
         }
162 162
         
163
-        $invoice    = wpinv_get_invoice( $invoice_id );
164
-        if ( empty( $invoice ) ) {
163
+        $invoice = wpinv_get_invoice($invoice_id);
164
+        if (empty($invoice)) {
165 165
             die();
166 166
         }
167 167
         
168
-        if ( $invoice->is_paid() ) {
168
+        if ($invoice->is_paid()) {
169 169
             die(); // Don't allow modify items for paid invoice.
170 170
         }
171 171
         
172
-        if ( !empty( $_POST['user_id'] ) ) {
173
-            $wpi_userID = absint( $_POST['user_id'] ); 
172
+        if (!empty($_POST['user_id'])) {
173
+            $wpi_userID = absint($_POST['user_id']); 
174 174
         }
175 175
 
176
-        $item = new WPInv_Item( $item_id );
177
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
176
+        $item = new WPInv_Item($item_id);
177
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
178 178
             die();
179 179
         }
180 180
         
181 181
         // Validate item before adding to invoice because recurring item must be paid individually.
182
-        if ( !empty( $invoice->cart_details ) ) {
182
+        if (!empty($invoice->cart_details)) {
183 183
             $valid = true;
184 184
             
185
-            if ( $recurring_item = $invoice->get_recurring() ) {
186
-                if ( $recurring_item != $item_id ) {
185
+            if ($recurring_item = $invoice->get_recurring()) {
186
+                if ($recurring_item != $item_id) {
187 187
                     $valid = false;
188 188
                 }
189
-            } else if ( wpinv_is_recurring_item( $item_id ) ) {
189
+            } else if (wpinv_is_recurring_item($item_id)) {
190 190
                 $valid = false;
191 191
             }
192 192
             
193
-            if ( !$valid ) {
193
+            if (!$valid) {
194 194
                 $response               = array();
195 195
                 $response['success']    = false;
196
-                $response['msg']        = __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' );
197
-                wp_send_json( $response );
196
+                $response['msg']        = __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing');
197
+                wp_send_json($response);
198 198
             }
199 199
         }
200 200
         
@@ -202,9 +202,9 @@  discard block
 block discarded – undo
202 202
         
203 203
         $data                   = array();
204 204
         $data['invoice_id']     = $invoice_id;
205
-        $data['cart_discounts'] = $invoice->get_discounts( true );
205
+        $data['cart_discounts'] = $invoice->get_discounts(true);
206 206
         
207
-        wpinv_set_checkout_session( $data );
207
+        wpinv_set_checkout_session($data);
208 208
         
209 209
         $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1;
210 210
 
@@ -219,21 +219,21 @@  discard block
 block discarded – undo
219 219
             'fees'          => array()
220 220
         );
221 221
 
222
-        $invoice->add_item( $item_id, $args );
222
+        $invoice->add_item($item_id, $args);
223 223
         $invoice->save();
224 224
         
225
-        if ( empty( $_POST['country'] ) ) {
225
+        if (empty($_POST['country'])) {
226 226
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
227 227
         }
228
-        if ( empty( $_POST['state'] ) ) {
228
+        if (empty($_POST['state'])) {
229 229
             $_POST['state'] = $invoice->state;
230 230
         }
231 231
          
232
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
233
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
232
+        $invoice->country   = sanitize_text_field($_POST['country']);
233
+        $invoice->state     = sanitize_text_field($_POST['state']);
234 234
         
235
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
236
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
235
+        $invoice->set('country', sanitize_text_field($_POST['country']));
236
+        $invoice->set('state', sanitize_text_field($_POST['state']));
237 237
         
238 238
         $wpinv_ip_address_country = $invoice->country;
239 239
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
         
242 242
         $response                       = array();
243 243
         $response['success']            = true;
244
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
244
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
245 245
         $response['data']['subtotal']   = $invoice->get_subtotal();
246 246
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
247 247
         $response['data']['tax']        = $invoice->get_tax();
@@ -253,40 +253,40 @@  discard block
 block discarded – undo
253 253
         
254 254
         wpinv_set_checkout_session($checkout_session);
255 255
         
256
-        wp_send_json( $response );
256
+        wp_send_json($response);
257 257
     }
258 258
     
259 259
     public static function remove_invoice_item() {
260 260
         global $wpi_userID, $wpinv_ip_address_country;
261 261
         
262
-        check_ajax_referer( 'invoice-item', '_nonce' );
263
-        if ( !current_user_can( 'manage_options' ) ) {
262
+        check_ajax_referer('invoice-item', '_nonce');
263
+        if (!current_user_can('manage_options')) {
264 264
             die(-1);
265 265
         }
266 266
         
267
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
268
-        $invoice_id = absint( $_POST['invoice_id'] );
269
-        $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false;
267
+        $item_id    = sanitize_text_field($_POST['item_id']);
268
+        $invoice_id = absint($_POST['invoice_id']);
269
+        $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false;
270 270
         
271
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
271
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
272 272
             die();
273 273
         }
274 274
 
275
-        $invoice    = wpinv_get_invoice( $invoice_id );
276
-        if ( empty( $invoice ) ) {
275
+        $invoice = wpinv_get_invoice($invoice_id);
276
+        if (empty($invoice)) {
277 277
             die();
278 278
         }
279 279
         
280
-        if ( $invoice->is_paid() ) {
280
+        if ($invoice->is_paid()) {
281 281
             die(); // Don't allow modify items for paid invoice.
282 282
         }
283 283
         
284
-        if ( !empty( $_POST['user_id'] ) ) {
285
-            $wpi_userID = absint( $_POST['user_id'] ); 
284
+        if (!empty($_POST['user_id'])) {
285
+            $wpi_userID = absint($_POST['user_id']); 
286 286
         }
287 287
 
288
-        $item       = new WPInv_Item( $item_id );
289
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
288
+        $item = new WPInv_Item($item_id);
289
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
290 290
             die();
291 291
         }
292 292
         
@@ -294,9 +294,9 @@  discard block
 block discarded – undo
294 294
         
295 295
         $data                   = array();
296 296
         $data['invoice_id']     = $invoice_id;
297
-        $data['cart_discounts'] = $invoice->get_discounts( true );
297
+        $data['cart_discounts'] = $invoice->get_discounts(true);
298 298
         
299
-        wpinv_set_checkout_session( $data );
299
+        wpinv_set_checkout_session($data);
300 300
 
301 301
         $args = array(
302 302
             'id'         => $item_id,
@@ -304,21 +304,21 @@  discard block
 block discarded – undo
304 304
             'cart_index' => $cart_index
305 305
         );
306 306
 
307
-        $invoice->remove_item( $item_id, $args );
307
+        $invoice->remove_item($item_id, $args);
308 308
         $invoice->save();
309 309
         
310
-        if ( empty( $_POST['country'] ) ) {
310
+        if (empty($_POST['country'])) {
311 311
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
312 312
         }
313
-        if ( empty( $_POST['state'] ) ) {
313
+        if (empty($_POST['state'])) {
314 314
             $_POST['state'] = $invoice->state;
315 315
         }
316 316
          
317
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
318
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
317
+        $invoice->country   = sanitize_text_field($_POST['country']);
318
+        $invoice->state     = sanitize_text_field($_POST['state']);
319 319
         
320
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
321
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
320
+        $invoice->set('country', sanitize_text_field($_POST['country']));
321
+        $invoice->set('state', sanitize_text_field($_POST['state']));
322 322
         
323 323
         $wpinv_ip_address_country = $invoice->country;
324 324
         
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
         
327 327
         $response                       = array();
328 328
         $response['success']            = true;
329
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
329
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
330 330
         $response['data']['subtotal']   = $invoice->get_subtotal();
331 331
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
332 332
         $response['data']['tax']        = $invoice->get_tax();
@@ -338,40 +338,40 @@  discard block
 block discarded – undo
338 338
         
339 339
         wpinv_set_checkout_session($checkout_session);
340 340
         
341
-        wp_send_json( $response );
341
+        wp_send_json($response);
342 342
     }
343 343
     
344 344
     public static function create_invoice_item() {
345
-        check_ajax_referer( 'invoice-item', '_nonce' );
346
-        if ( !current_user_can( 'manage_options' ) ) {
345
+        check_ajax_referer('invoice-item', '_nonce');
346
+        if (!current_user_can('manage_options')) {
347 347
             die(-1);
348 348
         }
349 349
         
350
-        $invoice_id = absint( $_POST['invoice_id'] );
350
+        $invoice_id = absint($_POST['invoice_id']);
351 351
 
352 352
         // Find the item
353
-        if ( !is_numeric( $invoice_id ) ) {
353
+        if (!is_numeric($invoice_id)) {
354 354
             die();
355 355
         }        
356 356
         
357
-        $invoice     = wpinv_get_invoice( $invoice_id );
358
-        if ( empty( $invoice ) ) {
357
+        $invoice = wpinv_get_invoice($invoice_id);
358
+        if (empty($invoice)) {
359 359
             die();
360 360
         }
361 361
         
362 362
         // Validate item before adding to invoice because recurring item must be paid individually.
363
-        if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) {
363
+        if (!empty($invoice->cart_details) && $invoice->get_recurring()) {
364 364
             $response               = array();
365 365
             $response['success']    = false;
366
-            $response['msg']        = __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' );
367
-            wp_send_json( $response );
366
+            $response['msg']        = __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing');
367
+            wp_send_json($response);
368 368
         }        
369 369
         
370 370
         $save_item = $_POST['_wpinv_quick'];
371 371
         
372 372
         $meta               = array();
373 373
         $meta['type']       = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom';
374
-        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0;
374
+        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0;
375 375
         $meta['vat_rule']   = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital';
376 376
         $meta['vat_class']  = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard';
377 377
         
@@ -381,9 +381,9 @@  discard block
 block discarded – undo
381 381
         $data['meta']           = $meta;
382 382
         
383 383
         $item = new WPInv_Item();
384
-        $item->create( $data );
384
+        $item->create($data);
385 385
         
386
-        if ( !empty( $item ) ) {
386
+        if (!empty($item)) {
387 387
             $_POST['item_id']   = $item->ID;
388 388
             $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1;
389 389
             
@@ -393,15 +393,15 @@  discard block
 block discarded – undo
393 393
     }
394 394
     
395 395
     public static function get_billing_details() {
396
-        check_ajax_referer( 'get-billing-details', '_nonce' );
396
+        check_ajax_referer('get-billing-details', '_nonce');
397 397
         
398
-        if ( !current_user_can( 'manage_options' ) ) {
398
+        if (!current_user_can('manage_options')) {
399 399
             die(-1);
400 400
         }
401 401
 
402 402
         $user_id            = (int)$_POST['user_id'];
403 403
         $billing_details    = wpinv_get_user_address($user_id);
404
-        $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
404
+        $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
405 405
         
406 406
         if (isset($billing_details['user_id'])) {
407 407
             unset($billing_details['user_id']);
@@ -415,20 +415,20 @@  discard block
 block discarded – undo
415 415
         $response['success']                    = true;
416 416
         $response['data']['billing_details']    = $billing_details;
417 417
         
418
-        wp_send_json( $response );
418
+        wp_send_json($response);
419 419
     }
420 420
     
421 421
     public static function admin_recalculate_totals() {
422 422
         global $wpi_userID, $wpinv_ip_address_country;
423 423
         
424
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
425
-        if ( !current_user_can( 'manage_options' ) ) {
424
+        check_ajax_referer('wpinv-nonce', '_nonce');
425
+        if (!current_user_can('manage_options')) {
426 426
             die(-1);
427 427
         }
428 428
         
429
-        $invoice_id = absint( $_POST['invoice_id'] );        
430
-        $invoice    = wpinv_get_invoice( $invoice_id );
431
-        if ( empty( $invoice ) ) {
429
+        $invoice_id = absint($_POST['invoice_id']);        
430
+        $invoice    = wpinv_get_invoice($invoice_id);
431
+        if (empty($invoice)) {
432 432
             die();
433 433
         }
434 434
         
@@ -436,23 +436,23 @@  discard block
 block discarded – undo
436 436
         
437 437
         $data                   = array();
438 438
         $data['invoice_id']     = $invoice_id;
439
-        $data['cart_discounts'] = $invoice->get_discounts( true );
439
+        $data['cart_discounts'] = $invoice->get_discounts(true);
440 440
         
441
-        wpinv_set_checkout_session( $data );
441
+        wpinv_set_checkout_session($data);
442 442
         
443
-        if ( !empty( $_POST['user_id'] ) ) {
444
-            $wpi_userID = absint( $_POST['user_id'] ); 
443
+        if (!empty($_POST['user_id'])) {
444
+            $wpi_userID = absint($_POST['user_id']); 
445 445
         }
446 446
         
447
-        if ( empty( $_POST['country'] ) ) {
447
+        if (empty($_POST['country'])) {
448 448
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
449 449
         }
450 450
             
451
-        $invoice->country = sanitize_text_field( $_POST['country'] );
452
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
453
-        if ( isset( $_POST['state'] ) ) {
454
-            $invoice->state = sanitize_text_field( $_POST['state'] );
455
-            $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
451
+        $invoice->country = sanitize_text_field($_POST['country']);
452
+        $invoice->set('country', sanitize_text_field($_POST['country']));
453
+        if (isset($_POST['state'])) {
454
+            $invoice->state = sanitize_text_field($_POST['state']);
455
+            $invoice->set('state', sanitize_text_field($_POST['state']));
456 456
         }
457 457
         
458 458
         $wpinv_ip_address_country = $invoice->country;
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
         
462 462
         $response                       = array();
463 463
         $response['success']            = true;
464
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
464
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
465 465
         $response['data']['subtotal']   = $invoice->get_subtotal();
466 466
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
467 467
         $response['data']['tax']        = $invoice->get_tax();
@@ -473,25 +473,25 @@  discard block
 block discarded – undo
473 473
         
474 474
         wpinv_set_checkout_session($checkout_session);
475 475
         
476
-        wp_send_json( $response );
476
+        wp_send_json($response);
477 477
     }
478 478
     
479 479
     public static function admin_apply_discount() {
480 480
         global $wpi_userID;
481 481
         
482
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
483
-        if ( !current_user_can( 'manage_options' ) ) {
482
+        check_ajax_referer('wpinv-nonce', '_nonce');
483
+        if (!current_user_can('manage_options')) {
484 484
             die(-1);
485 485
         }
486 486
         
487
-        $invoice_id = absint( $_POST['invoice_id'] );
488
-        $discount_code = sanitize_text_field( $_POST['code'] );
489
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
487
+        $invoice_id = absint($_POST['invoice_id']);
488
+        $discount_code = sanitize_text_field($_POST['code']);
489
+        if (empty($invoice_id) || empty($discount_code)) {
490 490
             die();
491 491
         }
492 492
         
493
-        $invoice = wpinv_get_invoice( $invoice_id );
494
-        if ( empty( $invoice ) || ( !empty( $invoice ) && $invoice->is_paid() ) ) {
493
+        $invoice = wpinv_get_invoice($invoice_id);
494
+        if (empty($invoice) || (!empty($invoice) && $invoice->is_paid())) {
495 495
             die();
496 496
         }
497 497
         
@@ -499,49 +499,49 @@  discard block
 block discarded – undo
499 499
         
500 500
         $data                   = array();
501 501
         $data['invoice_id']     = $invoice_id;
502
-        $data['cart_discounts'] = $invoice->get_discounts( true );
502
+        $data['cart_discounts'] = $invoice->get_discounts(true);
503 503
         
504
-        wpinv_set_checkout_session( $data );
504
+        wpinv_set_checkout_session($data);
505 505
         
506 506
         $response               = array();
507 507
         $response['success']    = false;
508
-        $response['msg']        = __( 'This discount is invalid.', 'invoicing' );
508
+        $response['msg']        = __('This discount is invalid.', 'invoicing');
509 509
         $response['data']['code'] = $discount_code;
510 510
         
511
-        if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) {
512
-            $discounts = wpinv_set_cart_discount( $discount_code );
511
+        if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) {
512
+            $discounts = wpinv_set_cart_discount($discount_code);
513 513
             
514 514
             $response['success'] = true;
515
-            $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' );
516
-        }  else {
515
+            $response['msg'] = __('Discount has been applied successfully.', 'invoicing');
516
+        } else {
517 517
             $errors = wpinv_get_errors();
518
-            if ( !empty( $errors['wpinv-discount-error'] ) ) {
518
+            if (!empty($errors['wpinv-discount-error'])) {
519 519
                 $response['msg'] = $errors['wpinv-discount-error'];
520 520
             }
521
-            wpinv_unset_error( 'wpinv-discount-error' );
521
+            wpinv_unset_error('wpinv-discount-error');
522 522
         }
523 523
         
524 524
         wpinv_set_checkout_session($checkout_session);
525 525
         
526
-        wp_send_json( $response );
526
+        wp_send_json($response);
527 527
     }
528 528
     
529 529
     public static function admin_remove_discount() {
530 530
         global $wpi_userID;
531 531
         
532
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
533
-        if ( !current_user_can( 'manage_options' ) ) {
532
+        check_ajax_referer('wpinv-nonce', '_nonce');
533
+        if (!current_user_can('manage_options')) {
534 534
             die(-1);
535 535
         }
536 536
         
537
-        $invoice_id = absint( $_POST['invoice_id'] );
538
-        $discount_code = sanitize_text_field( $_POST['code'] );
539
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
537
+        $invoice_id = absint($_POST['invoice_id']);
538
+        $discount_code = sanitize_text_field($_POST['code']);
539
+        if (empty($invoice_id) || empty($discount_code)) {
540 540
             die();
541 541
         }
542 542
         
543
-        $invoice = wpinv_get_invoice( $invoice_id );
544
-        if ( empty( $invoice ) || ( !empty( $invoice ) && $invoice->is_paid() ) ) {
543
+        $invoice = wpinv_get_invoice($invoice_id);
544
+        if (empty($invoice) || (!empty($invoice) && $invoice->is_paid())) {
545 545
             die();
546 546
         }
547 547
         
@@ -549,38 +549,38 @@  discard block
 block discarded – undo
549 549
         
550 550
         $data                   = array();
551 551
         $data['invoice_id']     = $invoice_id;
552
-        $data['cart_discounts'] = $invoice->get_discounts( true );
552
+        $data['cart_discounts'] = $invoice->get_discounts(true);
553 553
         
554
-        wpinv_set_checkout_session( $data );
554
+        wpinv_set_checkout_session($data);
555 555
         
556 556
         $response               = array();
557 557
         $response['success']    = false;
558 558
         $response['msg']        = NULL;
559 559
         
560
-        $discounts  = wpinv_unset_cart_discount( $discount_code );
560
+        $discounts = wpinv_unset_cart_discount($discount_code);
561 561
         $response['success'] = true;
562
-        $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' );
562
+        $response['msg'] = __('Discount has been removed successfully.', 'invoicing');
563 563
         
564 564
         wpinv_set_checkout_session($checkout_session);
565 565
         
566
-        wp_send_json( $response );
566
+        wp_send_json($response);
567 567
     }
568 568
     
569 569
     public static function check_email() {
570
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
571
-        if ( !current_user_can( 'manage_options' ) ) {
570
+        check_ajax_referer('wpinv-nonce', '_nonce');
571
+        if (!current_user_can('manage_options')) {
572 572
             die(-1);
573 573
         }
574 574
         
575
-        $email = sanitize_text_field( $_POST['email'] );
575
+        $email = sanitize_text_field($_POST['email']);
576 576
         
577 577
         $response = array();
578
-        if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) {
578
+        if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) {
579 579
             $user_id            = $user_data->ID;
580 580
             $user_login         = $user_data->user_login;
581 581
             $display_name       = $user_data->display_name ? $user_data->display_name : $user_login;
582 582
             $billing_details    = wpinv_get_user_address($user_id);
583
-            $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
583
+            $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
584 584
             
585 585
             if (isset($billing_details['user_id'])) {
586 586
                 unset($billing_details['user_id']);
@@ -596,31 +596,31 @@  discard block
 block discarded – undo
596 596
             $response['data']['billing_details']    = $billing_details;
597 597
         }
598 598
         
599
-        wp_send_json( $response );
599
+        wp_send_json($response);
600 600
     }
601 601
     
602 602
     public static function run_tool() {
603
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
604
-        if ( !current_user_can( 'manage_options' ) ) {
603
+        check_ajax_referer('wpinv-nonce', '_nonce');
604
+        if (!current_user_can('manage_options')) {
605 605
             die(-1);
606 606
         }
607 607
         
608
-        $tool = sanitize_text_field( $_POST['tool'] );
608
+        $tool = sanitize_text_field($_POST['tool']);
609 609
         
610
-        do_action( 'wpinv_run_tool' );
610
+        do_action('wpinv_run_tool');
611 611
         
612
-        if ( !empty( $tool ) ) {
613
-            do_action( 'wpinv_tool_' . $tool );
612
+        if (!empty($tool)) {
613
+            do_action('wpinv_tool_' . $tool);
614 614
         }
615 615
     }
616 616
     
617 617
     public static function apply_discount() {
618
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
618
+        check_ajax_referer('wpinv-nonce', '_nonce');
619 619
         
620 620
         $response = array();
621 621
         
622
-        if ( isset( $_POST['code'] ) ) {
623
-            $discount_code = sanitize_text_field( $_POST['code'] );
622
+        if (isset($_POST['code'])) {
623
+            $discount_code = sanitize_text_field($_POST['code']);
624 624
 
625 625
             $response['success']        = false;
626 626
             $response['msg']            = '';
@@ -628,14 +628,14 @@  discard block
 block discarded – undo
628 628
             
629 629
             $user = is_user_logged_in() ? get_current_user_id() : '';
630 630
 
631
-            if ( wpinv_is_discount_valid( $discount_code, $user ) ) {
632
-                $discount       = wpinv_get_discount_by_code( $discount_code );
633
-                $discounts      = wpinv_set_cart_discount( $discount_code );
634
-                $amount         = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
635
-                $total          = wpinv_get_cart_total( null, $discounts );
636
-                $cart_totals    = wpinv_recalculate_tax( true );
631
+            if (wpinv_is_discount_valid($discount_code, $user)) {
632
+                $discount       = wpinv_get_discount_by_code($discount_code);
633
+                $discounts      = wpinv_set_cart_discount($discount_code);
634
+                $amount         = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
635
+                $total          = wpinv_get_cart_total(null, $discounts);
636
+                $cart_totals    = wpinv_recalculate_tax(true);
637 637
             
638
-                if ( !empty( $cart_totals ) ) {
638
+                if (!empty($cart_totals)) {
639 639
                     $response['success']        = true;
640 640
                     $response['data']           = $cart_totals;
641 641
                     $response['data']['code']   = $discount_code;
@@ -644,29 +644,29 @@  discard block
 block discarded – undo
644 644
                 }
645 645
             } else {
646 646
                 $errors = wpinv_get_errors();
647
-                $response['msg']  = $errors['wpinv-discount-error'];
648
-                wpinv_unset_error( 'wpinv-discount-error' );
647
+                $response['msg'] = $errors['wpinv-discount-error'];
648
+                wpinv_unset_error('wpinv-discount-error');
649 649
             }
650 650
 
651 651
             // Allow for custom discount code handling
652
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
652
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
653 653
         }
654 654
         
655
-        wp_send_json( $response );
655
+        wp_send_json($response);
656 656
     }
657 657
     
658 658
     public static function remove_discount() {
659
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
659
+        check_ajax_referer('wpinv-nonce', '_nonce');
660 660
         
661 661
         $response = array();
662 662
         
663
-        if ( isset( $_POST['code'] ) ) {
664
-            $discount_code  = sanitize_text_field( $_POST['code'] );
665
-            $discounts      = wpinv_unset_cart_discount( $discount_code );
666
-            $total          = wpinv_get_cart_total( null, $discounts );
667
-            $cart_totals    = wpinv_recalculate_tax( true );
663
+        if (isset($_POST['code'])) {
664
+            $discount_code  = sanitize_text_field($_POST['code']);
665
+            $discounts      = wpinv_unset_cart_discount($discount_code);
666
+            $total          = wpinv_get_cart_total(null, $discounts);
667
+            $cart_totals    = wpinv_recalculate_tax(true);
668 668
             
669
-            if ( !empty( $cart_totals ) ) {
669
+            if (!empty($cart_totals)) {
670 670
                 $response['success']        = true;
671 671
                 $response['data']           = $cart_totals;
672 672
                 $response['data']['code']   = $discount_code;
@@ -675,10 +675,10 @@  discard block
 block discarded – undo
675 675
             }
676 676
             
677 677
             // Allow for custom discount code handling
678
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
678
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
679 679
         }
680 680
         
681
-        wp_send_json( $response );
681
+        wp_send_json($response);
682 682
     }
683 683
 }
684 684
 
Please login to merge, or discard this patch.
templates/wpinv-invoice-history.php 1 patch
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -1,80 +1,80 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
6
-if ( !( $user_id = get_current_user_id() ) ) {
6
+if (!($user_id = get_current_user_id())) {
7 7
     ?>
8
-    <div class="wpinv-empty alert alert-error"><?php _e( 'You are not allowed to access this section', 'invoicing' ) ;?></div>
8
+    <div class="wpinv-empty alert alert-error"><?php _e('You are not allowed to access this section', 'invoicing'); ?></div>
9 9
     <?php
10 10
     return;
11 11
 }
12 12
 
13 13
 global $current_page;
14
-$current_page   = empty( $current_page ) ? 1 : absint( $current_page );
15
-$query          = apply_filters( 'wpinv_user_invoices_query', array( 'user' => $user_id, 'page' => $current_page, 'paginate' => true ) );
16
-$user_invoices  = wpinv_get_invoices( $query );
14
+$current_page   = empty($current_page) ? 1 : absint($current_page);
15
+$query          = apply_filters('wpinv_user_invoices_query', array('user' => $user_id, 'page' => $current_page, 'paginate' => true));
16
+$user_invoices  = wpinv_get_invoices($query);
17 17
 $has_invoices   = 0 < $user_invoices->total;
18 18
     
19
-do_action( 'wpinv_before_user_invoices', $has_invoices ); ?>
19
+do_action('wpinv_before_user_invoices', $has_invoices); ?>
20 20
 
21
-<?php if ( $has_invoices ) { ?>
21
+<?php if ($has_invoices) { ?>
22 22
 	<table class="table table-bordered table-hover wpi-user-invoices">
23 23
 		<thead>
24 24
 			<tr>
25
-				<?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
26
-					<th class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>"><span class="nobr"><?php echo esc_html( $column_name['title'] ); ?></span></th>
25
+				<?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?>
26
+					<th class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>"><span class="nobr"><?php echo esc_html($column_name['title']); ?></span></th>
27 27
 				<?php endforeach; ?>
28 28
 			</tr>
29 29
 		</thead>
30 30
 
31 31
 		<tbody>
32
-			<?php foreach ( $user_invoices->invoices as $invoice ) {
32
+			<?php foreach ($user_invoices->invoices as $invoice) {
33 33
 				?>
34 34
 				<tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>">
35
-					<?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
36
-						<td class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>" data-title="<?php echo esc_attr( $column_name['title'] ); ?>">
37
-							<?php if ( has_action( 'wpinv_user_invoices_column_' . $column_id ) ) : ?>
38
-								<?php do_action( 'wpinv_user_invoices_column_' . $column_id, $invoice ); ?>
39
-
40
-							<?php elseif ( 'invoice-number' === $column_id ) : ?>
41
-								<a href="<?php echo esc_url( $invoice->get_view_url() ); ?>">
42
-									<?php echo _x( '#', 'hash before invoice number', 'invoicing' ) . $invoice->get_number(); ?>
35
+					<?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?>
36
+						<td class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>" data-title="<?php echo esc_attr($column_name['title']); ?>">
37
+							<?php if (has_action('wpinv_user_invoices_column_' . $column_id)) : ?>
38
+								<?php do_action('wpinv_user_invoices_column_' . $column_id, $invoice); ?>
39
+
40
+							<?php elseif ('invoice-number' === $column_id) : ?>
41
+								<a href="<?php echo esc_url($invoice->get_view_url()); ?>">
42
+									<?php echo _x('#', 'hash before invoice number', 'invoicing') . $invoice->get_number(); ?>
43 43
 								</a>
44 44
 
45
-							<?php elseif ( 'invoice-date' === $column_id ) : $date = wpinv_get_invoice_date( $invoice->ID ); $dateYMD = wpinv_get_invoice_date( $invoice->ID, 'Y-m-d H:i:s' ); ?>
46
-								<time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
45
+							<?php elseif ('invoice-date' === $column_id) : $date = wpinv_get_invoice_date($invoice->ID); $dateYMD = wpinv_get_invoice_date($invoice->ID, 'Y-m-d H:i:s'); ?>
46
+								<time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
47 47
 
48
-							<?php elseif ( 'invoice-status' === $column_id ) : ?>
49
-								<?php echo wpinv_invoice_status_label( $invoice_status, $invoice->get_status( true ) ) ; ?>
48
+							<?php elseif ('invoice-status' === $column_id) : ?>
49
+								<?php echo wpinv_invoice_status_label($invoice_status, $invoice->get_status(true)); ?>
50 50
 
51
-							<?php elseif ( 'invoice-total' === $column_id ) : ?>
52
-								<?php echo $invoice->get_total( true ); ?>
51
+							<?php elseif ('invoice-total' === $column_id) : ?>
52
+								<?php echo $invoice->get_total(true); ?>
53 53
 
54
-							<?php elseif ( 'invoice-actions' === $column_id ) : ?>
54
+							<?php elseif ('invoice-actions' === $column_id) : ?>
55 55
 								<?php
56 56
 									$actions = array(
57 57
 										'pay'    => array(
58 58
 											'url'  => $invoice->get_checkout_payment_url(),
59
-											'name' => __( 'Pay Now', 'invoicing' ),
59
+											'name' => __('Pay Now', 'invoicing'),
60 60
                                             'class' => 'btn-success'
61 61
 										),
62 62
                                         'print'   => array(
63 63
 											'url'  => $invoice->get_view_url(),
64
-											'name' => __( 'Print', 'invoicing' ),
64
+											'name' => __('Print', 'invoicing'),
65 65
                                             'class' => 'btn-primary',
66 66
                                             'attrs' => 'target="_blank"'
67 67
 										)
68 68
 									);
69 69
 
70
-									if ( ! $invoice->needs_payment() ) {
71
-										unset( $actions['pay'] );
70
+									if (!$invoice->needs_payment()) {
71
+										unset($actions['pay']);
72 72
 									}
73 73
 
74
-									if ( $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ) ) {
75
-										foreach ( $actions as $key => $action ) {
74
+									if ($actions = apply_filters('wpinv_user_invoices_actions', $actions, $invoice)) {
75
+										foreach ($actions as $key => $action) {
76 76
 											$class = !empty($action['class']) ? sanitize_html_class($action['class']) : '';
77
-                                            echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>';
77
+                                            echo '<a href="' . esc_url($action['url']) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class($key) . '" ' . (!empty($action['attrs']) ? $action['attrs'] : '') . '>' . $action['name'] . '</a>';
78 78
 										}
79 79
 									}
80 80
 								?>
@@ -86,9 +86,9 @@  discard block
 block discarded – undo
86 86
 		</tbody>
87 87
 	</table>
88 88
 
89
-	<?php do_action( 'wpinv_before_user_invoices_pagination' ); ?>
89
+	<?php do_action('wpinv_before_user_invoices_pagination'); ?>
90 90
 
91
-	<?php if ( 1 < $user_invoices->max_num_pages ) : ?>
91
+	<?php if (1 < $user_invoices->max_num_pages) : ?>
92 92
 		<div class="invoicing-Pagination">
93 93
 			<?php
94 94
 			$big = 999999;
@@ -101,23 +101,23 @@  discard block
 block discarded – undo
101 101
 			else
102 102
 				$current_page = 1;
103 103
 
104
-			echo paginate_links( array(
105
-				'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
104
+			echo paginate_links(array(
105
+				'base'    => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
106 106
 				'format'  => '?paged=%#%',
107
-				'current' => max( 1, $current_page ),
107
+				'current' => max(1, $current_page),
108 108
 				'total'   => $user_invoices->max_num_pages,
109 109
 				'add_args' => array(
110 110
 					'wpinv-cpt' => 'wpi_invoice',
111 111
 				)
112
-			) );
112
+			));
113 113
 			?>
114 114
 		</div>
115 115
 	<?php endif; ?>
116 116
 
117 117
 <?php } else { ?>
118 118
 	<div class="wpinv-empty alert-info">
119
-		<?php _e( 'No invoice has been made yet.', 'invoicing' ); ?>
119
+		<?php _e('No invoice has been made yet.', 'invoicing'); ?>
120 120
 	</div>
121 121
 <?php } ?>
122 122
 
123
-<?php do_action( 'wpinv_after_user_invoices', $has_invoices ); ?>
123
+<?php do_action('wpinv_after_user_invoices', $has_invoices); ?>
Please login to merge, or discard this patch.
includes/class-wpinv-invoice.php 1 patch
Spacing   +797 added lines, -797 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 final class WPInv_Invoice {
15
-    public $ID  = 0;
15
+    public $ID = 0;
16 16
     public $title;
17 17
     public $post_type;
18 18
     
@@ -65,17 +65,17 @@  discard block
 block discarded – undo
65 65
     public $full_name = '';
66 66
     public $parent_invoice = 0;
67 67
     
68
-    public function __construct( $invoice_id = false ) {
69
-        if( empty( $invoice_id ) ) {
68
+    public function __construct($invoice_id = false) {
69
+        if (empty($invoice_id)) {
70 70
             return false;
71 71
         }
72 72
 
73
-        $this->setup_invoice( $invoice_id );
73
+        $this->setup_invoice($invoice_id);
74 74
     }
75 75
 
76
-    public function get( $key ) {
77
-        if ( method_exists( $this, 'get_' . $key ) ) {
78
-            $value = call_user_func( array( $this, 'get_' . $key ) );
76
+    public function get($key) {
77
+        if (method_exists($this, 'get_' . $key)) {
78
+            $value = call_user_func(array($this, 'get_' . $key));
79 79
         } else {
80 80
             $value = $this->$key;
81 81
         }
@@ -83,51 +83,51 @@  discard block
 block discarded – undo
83 83
         return $value;
84 84
     }
85 85
 
86
-    public function set( $key, $value ) {
87
-        $ignore = array( 'items', 'cart_details', 'fees', '_ID' );
86
+    public function set($key, $value) {
87
+        $ignore = array('items', 'cart_details', 'fees', '_ID');
88 88
 
89
-        if ( $key === 'status' ) {
89
+        if ($key === 'status') {
90 90
             $this->old_status = $this->status;
91 91
         }
92 92
 
93
-        if ( ! in_array( $key, $ignore ) ) {
94
-            $this->pending[ $key ] = $value;
93
+        if (!in_array($key, $ignore)) {
94
+            $this->pending[$key] = $value;
95 95
         }
96 96
 
97
-        if( '_ID' !== $key ) {
97
+        if ('_ID' !== $key) {
98 98
             $this->$key = $value;
99 99
         }
100 100
     }
101 101
 
102
-    public function _isset( $name ) {
103
-        if ( property_exists( $this, $name) ) {
104
-            return false === empty( $this->$name );
102
+    public function _isset($name) {
103
+        if (property_exists($this, $name)) {
104
+            return false === empty($this->$name);
105 105
         } else {
106 106
             return null;
107 107
         }
108 108
     }
109 109
 
110
-    private function setup_invoice( $invoice_id ) {
110
+    private function setup_invoice($invoice_id) {
111 111
         $this->pending = array();
112 112
 
113
-        if ( empty( $invoice_id ) ) {
113
+        if (empty($invoice_id)) {
114 114
             return false;
115 115
         }
116 116
 
117
-        $invoice = get_post( $invoice_id );
117
+        $invoice = get_post($invoice_id);
118 118
 
119
-        if( !$invoice || is_wp_error( $invoice ) ) {
119
+        if (!$invoice || is_wp_error($invoice)) {
120 120
             return false;
121 121
         }
122 122
 
123
-        if( !('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type) ) {
123
+        if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) {
124 124
             return false;
125 125
         }
126 126
 
127
-        do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id );
127
+        do_action('wpinv_pre_setup_invoice', $this, $invoice_id);
128 128
         
129 129
         // Primary Identifier
130
-        $this->ID              = absint( $invoice_id );
130
+        $this->ID              = absint($invoice_id);
131 131
         $this->post_type       = $invoice->post_type;
132 132
         
133 133
         // We have a payment, get the generic payment_meta item to reduce calls to it
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
         $this->post_status     = $this->status;
140 140
         $this->mode            = $this->setup_mode();
141 141
         $this->parent_invoice  = $invoice->post_parent;
142
-        $this->post_name       = $this->setup_post_name( $invoice );
142
+        $this->post_name       = $this->setup_post_name($invoice);
143 143
         $this->status_nicename = $this->setup_status_nicename($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,113 +1343,113 @@  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
-            if ( !empty( $ajax_cart_details ) && count( $ajax_cart_details ) == count( $this->items ) ) {
1390
+            if (!empty($ajax_cart_details) && count($ajax_cart_details) == count($this->items)) {
1391 1391
                 $cart_items = $ajax_cart_details;
1392 1392
             } else {
1393 1393
                 $cart_items = $this->items;
1394 1394
             }
1395 1395
 
1396
-            $this->discount = wpinv_get_cart_items_discount_amount( $cart_items , $this->discounts );
1396
+            $this->discount = wpinv_get_cart_items_discount_amount($cart_items, $this->discounts);
1397 1397
         }
1398
-        $discount   = wpinv_round_amount( $this->discount );
1398
+        $discount   = wpinv_round_amount($this->discount);
1399 1399
         $dash       = $dash && $discount > 0 ? '&ndash;' : '';
1400 1400
         
1401
-        if ( $currency ) {
1402
-            $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() );
1401
+        if ($currency) {
1402
+            $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency());
1403 1403
         }
1404 1404
         
1405
-        $discount   = $dash . $discount;
1405
+        $discount = $dash . $discount;
1406 1406
         
1407
-        return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash );
1407
+        return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash);
1408 1408
     }
1409 1409
     
1410 1410
     public function get_discount_code() {
1411 1411
         return $this->discount_code;
1412 1412
     }
1413 1413
     
1414
-    public function get_tax( $currency = false ) {
1415
-        $tax = wpinv_round_amount( $this->tax );
1414
+    public function get_tax($currency = false) {
1415
+        $tax = wpinv_round_amount($this->tax);
1416 1416
         
1417
-        if ( $currency ) {
1418
-            $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() );
1417
+        if ($currency) {
1418
+            $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency());
1419 1419
         }
1420 1420
         
1421
-        return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency );
1421
+        return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency);
1422 1422
     }
1423 1423
     
1424
-    public function get_fees( $type = 'all' ) {
1425
-        $fees    = array();
1424
+    public function get_fees($type = 'all') {
1425
+        $fees = array();
1426 1426
 
1427
-        if ( ! empty( $this->fees ) && is_array( $this->fees ) ) {
1428
-            foreach ( $this->fees as $fee ) {
1429
-                if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) {
1427
+        if (!empty($this->fees) && is_array($this->fees)) {
1428
+            foreach ($this->fees as $fee) {
1429
+                if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) {
1430 1430
                     continue;
1431 1431
                 }
1432 1432
 
1433
-                $fee['label'] = stripslashes( $fee['label'] );
1434
-                $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() );
1435
-                $fees[]    = $fee;
1433
+                $fee['label'] = stripslashes($fee['label']);
1434
+                $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency());
1435
+                $fees[] = $fee;
1436 1436
             }
1437 1437
         }
1438 1438
 
1439
-        return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this );
1439
+        return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this);
1440 1440
     }
1441 1441
     
1442
-    public function get_fees_total( $type = 'all' ) {
1443
-        $fees_total = (float) 0.00;
1442
+    public function get_fees_total($type = 'all') {
1443
+        $fees_total = (float)0.00;
1444 1444
 
1445
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
1446
-        if ( ! empty( $payment_fees ) ) {
1447
-            foreach ( $payment_fees as $fee ) {
1448
-                $fees_total += (float) $fee['amount'];
1445
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
1446
+        if (!empty($payment_fees)) {
1447
+            foreach ($payment_fees as $fee) {
1448
+                $fees_total += (float)$fee['amount'];
1449 1449
             }
1450 1450
         }
1451 1451
 
1452
-        return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this );
1452
+        return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this);
1453 1453
         /*
1454 1454
         $fees = $this->get_fees( $type );
1455 1455
 
@@ -1469,116 +1469,116 @@  discard block
 block discarded – undo
1469 1469
     }
1470 1470
 
1471 1471
     public function get_user_id() {
1472
-        return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this );
1472
+        return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this);
1473 1473
     }
1474 1474
     
1475 1475
     public function get_first_name() {
1476
-        return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this );
1476
+        return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this);
1477 1477
     }
1478 1478
     
1479 1479
     public function get_last_name() {
1480
-        return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this );
1480
+        return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this);
1481 1481
     }
1482 1482
     
1483 1483
     public function get_user_full_name() {
1484
-        return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this );
1484
+        return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this);
1485 1485
     }
1486 1486
     
1487 1487
     public function get_user_info() {
1488
-        return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this );
1488
+        return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this);
1489 1489
     }
1490 1490
     
1491 1491
     public function get_email() {
1492
-        return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this );
1492
+        return apply_filters('wpinv_user_email', $this->email, $this->ID, $this);
1493 1493
     }
1494 1494
     
1495 1495
     public function get_address() {
1496
-        return apply_filters( 'wpinv_address', $this->address, $this->ID, $this );
1496
+        return apply_filters('wpinv_address', $this->address, $this->ID, $this);
1497 1497
     }
1498 1498
     
1499 1499
     public function get_phone() {
1500
-        return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this );
1500
+        return apply_filters('wpinv_phone', $this->phone, $this->ID, $this);
1501 1501
     }
1502 1502
     
1503 1503
     public function get_number() {
1504
-        return apply_filters( 'wpinv_number', $this->number, $this->ID, $this );
1504
+        return apply_filters('wpinv_number', $this->number, $this->ID, $this);
1505 1505
     }
1506 1506
     
1507 1507
     public function get_items() {
1508
-        return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this );
1508
+        return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this);
1509 1509
     }
1510 1510
     
1511 1511
     public function get_key() {
1512
-        return apply_filters( 'wpinv_key', $this->key, $this->ID, $this );
1512
+        return apply_filters('wpinv_key', $this->key, $this->ID, $this);
1513 1513
     }
1514 1514
     
1515 1515
     public function get_transaction_id() {
1516
-        return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this );
1516
+        return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this);
1517 1517
     }
1518 1518
     
1519 1519
     public function get_gateway() {
1520
-        return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this );
1520
+        return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this);
1521 1521
     }
1522 1522
     
1523 1523
     public function get_gateway_title() {
1524
-        $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway );
1524
+        $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway);
1525 1525
         
1526
-        return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this );
1526
+        return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this);
1527 1527
     }
1528 1528
     
1529 1529
     public function get_currency() {
1530
-        return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this );
1530
+        return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this);
1531 1531
     }
1532 1532
     
1533 1533
     public function get_created_date() {
1534
-        return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this );
1534
+        return apply_filters('wpinv_created_date', $this->date, $this->ID, $this);
1535 1535
     }
1536 1536
     
1537
-    public function get_due_date( $display = false ) {
1538
-        $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this );
1537
+    public function get_due_date($display = false) {
1538
+        $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this);
1539 1539
         
1540
-        if ( !$display || empty( $due_date ) ) {
1540
+        if (!$display || empty($due_date)) {
1541 1541
             return $due_date;
1542 1542
         }
1543 1543
         
1544
-        return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) );
1544
+        return date_i18n(get_option('date_format'), strtotime($due_date));
1545 1545
     }
1546 1546
     
1547 1547
     public function get_completed_date() {
1548
-        return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this );
1548
+        return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this);
1549 1549
     }
1550 1550
     
1551
-    public function get_invoice_date( $formatted = true ) {
1551
+    public function get_invoice_date($formatted = true) {
1552 1552
         $date_completed = $this->completed_date;
1553 1553
         $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
1554 1554
         
1555
-        if ( $invoice_date == '' ) {
1555
+        if ($invoice_date == '') {
1556 1556
             $date_created   = $this->date;
1557 1557
             $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : '';
1558 1558
         }
1559 1559
         
1560
-        if ( $formatted && $invoice_date ) {
1561
-            $invoice_date   = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );
1560
+        if ($formatted && $invoice_date) {
1561
+            $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date));
1562 1562
         }
1563 1563
 
1564
-        return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this );
1564
+        return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this);
1565 1565
     }
1566 1566
     
1567 1567
     public function get_ip() {
1568
-        return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this );
1568
+        return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this);
1569 1569
     }
1570 1570
         
1571
-    public function has_status( $status ) {
1572
-        return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status );
1571
+    public function has_status($status) {
1572
+        return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status);
1573 1573
     }
1574 1574
     
1575
-    public function add_item( $item_id = 0, $args = array() ) {
1575
+    public function add_item($item_id = 0, $args = array()) {
1576 1576
         global $wpi_current_id, $wpi_item_id;
1577 1577
         
1578
-        $item = new WPInv_Item( $item_id );
1578
+        $item = new WPInv_Item($item_id);
1579 1579
 
1580 1580
         // Bail if this post isn't a item
1581
-        if( !$item || $item->post_type !== 'wpi_item' ) {
1581
+        if (!$item || $item->post_type !== 'wpi_item') {
1582 1582
             return false;
1583 1583
         }
1584 1584
         
@@ -1597,8 +1597,8 @@  discard block
 block discarded – undo
1597 1597
             'fees'          => array()
1598 1598
         );
1599 1599
 
1600
-        $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults );
1601
-        $args['quantity']   = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1;
1600
+        $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults);
1601
+        $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1;
1602 1602
 
1603 1603
         $wpi_current_id         = $this->ID;
1604 1604
         $wpi_item_id            = $item->ID;
@@ -1610,19 +1610,19 @@  discard block
 block discarded – undo
1610 1610
         $found_cart_key         = false;
1611 1611
         
1612 1612
         if ($has_quantities) {
1613
-            $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1613
+            $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1614 1614
             
1615
-            foreach ( $this->items as $key => $cart_item ) {
1616
-                if ( (int)$item_id !== (int)$cart_item['id'] ) {
1615
+            foreach ($this->items as $key => $cart_item) {
1616
+                if ((int)$item_id !== (int)$cart_item['id']) {
1617 1617
                     continue;
1618 1618
                 }
1619 1619
 
1620
-                $this->items[ $key ]['quantity'] += $args['quantity'];
1620
+                $this->items[$key]['quantity'] += $args['quantity'];
1621 1621
                 break;
1622 1622
             }
1623 1623
             
1624
-            foreach ( $this->cart_details as $cart_key => $cart_item ) {
1625
-                if ( $item_id != $cart_item['id'] ) {
1624
+            foreach ($this->cart_details as $cart_key => $cart_item) {
1625
+                if ($item_id != $cart_item['id']) {
1626 1626
                     continue;
1627 1627
                 }
1628 1628
 
@@ -1634,29 +1634,29 @@  discard block
 block discarded – undo
1634 1634
         if ($has_quantities && $found_cart_key !== false) {
1635 1635
             $cart_item          = $this->cart_details[$found_cart_key];
1636 1636
             $item_price         = $cart_item['item_price'];
1637
-            $quantity           = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1638
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1637
+            $quantity           = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1638
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1639 1639
             
1640 1640
             $new_quantity       = $quantity + $args['quantity'];
1641 1641
             $subtotal           = $item_price * $new_quantity;
1642 1642
             
1643 1643
             $args['quantity']   = $new_quantity;
1644
-            $discount           = !empty( $args['discount'] ) ? $args['discount'] : 0;
1645
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1644
+            $discount           = !empty($args['discount']) ? $args['discount'] : 0;
1645
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1646 1646
             
1647 1647
             $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0;
1648 1648
             $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0;
1649 1649
             // The total increase equals the number removed * the item_price
1650
-            $total_increased    = wpinv_round_amount( $item_price );
1650
+            $total_increased    = wpinv_round_amount($item_price);
1651 1651
             
1652
-            if ( wpinv_prices_include_tax() ) {
1653
-                $subtotal -= wpinv_round_amount( $tax );
1652
+            if (wpinv_prices_include_tax()) {
1653
+                $subtotal -= wpinv_round_amount($tax);
1654 1654
             }
1655 1655
 
1656
-            $total              = $subtotal - $discount + $tax;
1656
+            $total = $subtotal - $discount + $tax;
1657 1657
 
1658 1658
             // Do not allow totals to go negative
1659
-            if( $total < 0 ) {
1659
+            if ($total < 0) {
1660 1660
                 $total = 0;
1661 1661
             }
1662 1662
             
@@ -1672,25 +1672,25 @@  discard block
 block discarded – undo
1672 1672
             $this->cart_details[$found_cart_key] = $cart_item;
1673 1673
         } else {
1674 1674
             // Set custom price.
1675
-            if ( $args['custom_price'] !== '' ) {
1675
+            if ($args['custom_price'] !== '') {
1676 1676
                 $item_price = $args['custom_price'];
1677 1677
             } else {
1678 1678
                 // Allow overriding the price
1679
-                if ( false !== $args['item_price'] ) {
1679
+                if (false !== $args['item_price']) {
1680 1680
                     $item_price = $args['item_price'];
1681 1681
                 } else {
1682
-                    $item_price = wpinv_get_item_price( $item->ID );
1682
+                    $item_price = wpinv_get_item_price($item->ID);
1683 1683
                 }
1684 1684
             }
1685 1685
 
1686 1686
             // Sanitizing the price here so we don't have a dozen calls later
1687
-            $item_price = wpinv_sanitize_amount( $item_price );
1688
-            $subtotal   = wpinv_round_amount( $item_price * $args['quantity'] );
1687
+            $item_price = wpinv_sanitize_amount($item_price);
1688
+            $subtotal   = wpinv_round_amount($item_price * $args['quantity']);
1689 1689
         
1690
-            $discount   = !empty( $args['discount'] ) ? $args['discount'] : 0;
1691
-            $tax_class  = !empty( $args['vat_class'] ) ? $args['vat_class'] : '';
1692
-            $tax_rate   = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0;
1693
-            $tax        = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1690
+            $discount   = !empty($args['discount']) ? $args['discount'] : 0;
1691
+            $tax_class  = !empty($args['vat_class']) ? $args['vat_class'] : '';
1692
+            $tax_rate   = !empty($args['vat_rate']) ? $args['vat_rate'] : 0;
1693
+            $tax        = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1694 1694
 
1695 1695
             // Setup the items meta item
1696 1696
             $new_item = array(
@@ -1698,29 +1698,29 @@  discard block
 block discarded – undo
1698 1698
                 'quantity' => $args['quantity'],
1699 1699
             );
1700 1700
 
1701
-            $this->items[]  = $new_item;
1701
+            $this->items[] = $new_item;
1702 1702
 
1703
-            if ( wpinv_prices_include_tax() ) {
1704
-                $subtotal -= wpinv_round_amount( $tax );
1703
+            if (wpinv_prices_include_tax()) {
1704
+                $subtotal -= wpinv_round_amount($tax);
1705 1705
             }
1706 1706
 
1707
-            $total      = $subtotal - $discount + $tax;
1707
+            $total = $subtotal - $discount + $tax;
1708 1708
 
1709 1709
             // Do not allow totals to go negative
1710
-            if( $total < 0 ) {
1710
+            if ($total < 0) {
1711 1711
                 $total = 0;
1712 1712
             }
1713 1713
         
1714 1714
             $this->cart_details[] = array(
1715 1715
                 'name'          => !empty($args['name']) ? $args['name'] : $item->get_name(),
1716 1716
                 'id'            => $item->ID,
1717
-                'item_price'    => wpinv_round_amount( $item_price ),
1718
-                'custom_price'  => ( $args['custom_price'] !== '' ? wpinv_round_amount( $args['custom_price'] ) : '' ),
1717
+                'item_price'    => wpinv_round_amount($item_price),
1718
+                'custom_price'  => ($args['custom_price'] !== '' ? wpinv_round_amount($args['custom_price']) : ''),
1719 1719
                 'quantity'      => $args['quantity'],
1720 1720
                 'discount'      => $discount,
1721
-                'subtotal'      => wpinv_round_amount( $subtotal ),
1722
-                'tax'           => wpinv_round_amount( $tax ),
1723
-                'price'         => wpinv_round_amount( $total ),
1721
+                'subtotal'      => wpinv_round_amount($subtotal),
1722
+                'tax'           => wpinv_round_amount($tax),
1723
+                'price'         => wpinv_round_amount($total),
1724 1724
                 'vat_rate'      => $tax_rate,
1725 1725
                 'vat_class'     => $tax_class,
1726 1726
                 'meta'          => $args['meta'],
@@ -1730,18 +1730,18 @@  discard block
 block discarded – undo
1730 1730
             $subtotal = $subtotal - $discount;
1731 1731
         }
1732 1732
         
1733
-        $added_item = end( $this->cart_details );
1734
-        $added_item['action']  = 'add';
1733
+        $added_item = end($this->cart_details);
1734
+        $added_item['action'] = 'add';
1735 1735
         
1736 1736
         $this->pending['items'][] = $added_item;
1737 1737
         
1738
-        $this->increase_subtotal( $subtotal );
1739
-        $this->increase_tax( $tax );
1738
+        $this->increase_subtotal($subtotal);
1739
+        $this->increase_tax($tax);
1740 1740
 
1741 1741
         return true;
1742 1742
     }
1743 1743
     
1744
-    public function remove_item( $item_id, $args = array() ) {
1744
+    public function remove_item($item_id, $args = array()) {
1745 1745
         // Set some defaults
1746 1746
         $defaults = array(
1747 1747
             'quantity'      => 1,
@@ -1749,51 +1749,51 @@  discard block
 block discarded – undo
1749 1749
             'custom_price'  => '',
1750 1750
             'cart_index'    => false,
1751 1751
         );
1752
-        $args = wp_parse_args( $args, $defaults );
1752
+        $args = wp_parse_args($args, $defaults);
1753 1753
 
1754 1754
         // Bail if this post isn't a item
1755
-        if ( get_post_type( $item_id ) !== 'wpi_item' ) {
1755
+        if (get_post_type($item_id) !== 'wpi_item') {
1756 1756
             return false;
1757 1757
         }
1758 1758
         
1759
-        $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1759
+        $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1760 1760
 
1761
-        foreach ( $this->items as $key => $item ) {
1762
-            if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) {
1761
+        foreach ($this->items as $key => $item) {
1762
+            if (!empty($item['id']) && (int)$item_id !== (int)$item['id']) {
1763 1763
                 continue;
1764 1764
             }
1765 1765
 
1766
-            if ( false !== $args['cart_index'] ) {
1767
-                $cart_index = absint( $args['cart_index'] );
1768
-                $cart_item  = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false;
1766
+            if (false !== $args['cart_index']) {
1767
+                $cart_index = absint($args['cart_index']);
1768
+                $cart_item  = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false;
1769 1769
 
1770
-                if ( ! empty( $cart_item ) ) {
1770
+                if (!empty($cart_item)) {
1771 1771
                     // If the cart index item isn't the same item ID, don't remove it
1772
-                    if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) {
1772
+                    if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) {
1773 1773
                         continue;
1774 1774
                     }
1775 1775
                 }
1776 1776
             }
1777 1777
 
1778
-            $item_quantity = $this->items[ $key ]['quantity'];
1779
-            if ( $item_quantity > $args['quantity'] ) {
1780
-                $this->items[ $key ]['quantity'] -= $args['quantity'];
1778
+            $item_quantity = $this->items[$key]['quantity'];
1779
+            if ($item_quantity > $args['quantity']) {
1780
+                $this->items[$key]['quantity'] -= $args['quantity'];
1781 1781
                 break;
1782 1782
             } else {
1783
-                unset( $this->items[ $key ] );
1783
+                unset($this->items[$key]);
1784 1784
                 break;
1785 1785
             }
1786 1786
         }
1787 1787
 
1788 1788
         $found_cart_key = false;
1789
-        if ( false === $args['cart_index'] ) {
1790
-            foreach ( $this->cart_details as $cart_key => $item ) {
1791
-                if ( $item_id != $item['id'] ) {
1789
+        if (false === $args['cart_index']) {
1790
+            foreach ($this->cart_details as $cart_key => $item) {
1791
+                if ($item_id != $item['id']) {
1792 1792
                     continue;
1793 1793
                 }
1794 1794
 
1795
-                if ( false !== $args['item_price'] ) {
1796
-                    if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) {
1795
+                if (false !== $args['item_price']) {
1796
+                    if (isset($item['item_price']) && (float)$args['item_price'] != (float)$item['item_price']) {
1797 1797
                         continue;
1798 1798
                     }
1799 1799
                 }
@@ -1802,13 +1802,13 @@  discard block
 block discarded – undo
1802 1802
                 break;
1803 1803
             }
1804 1804
         } else {
1805
-            $cart_index = absint( $args['cart_index'] );
1805
+            $cart_index = absint($args['cart_index']);
1806 1806
 
1807
-            if ( ! array_key_exists( $cart_index, $this->cart_details ) ) {
1807
+            if (!array_key_exists($cart_index, $this->cart_details)) {
1808 1808
                 return false; // Invalid cart index passed.
1809 1809
             }
1810 1810
 
1811
-            if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) {
1811
+            if ((int)$this->cart_details[$cart_index]['id'] > 0 && (int)$this->cart_details[$cart_index]['id'] !== (int)$item_id) {
1812 1812
                 return false; // We still need the proper Item ID to be sure.
1813 1813
             }
1814 1814
 
@@ -1816,41 +1816,41 @@  discard block
 block discarded – undo
1816 1816
         }
1817 1817
         
1818 1818
         $cart_item  = $this->cart_details[$found_cart_key];
1819
-        $quantity   = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1819
+        $quantity   = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1820 1820
         
1821
-        if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) {
1821
+        if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) {
1822 1822
             return false; // Invoice must contain at least one item.
1823 1823
         }
1824 1824
         
1825
-        $discounts  = $this->get_discounts();
1825
+        $discounts = $this->get_discounts();
1826 1826
         
1827
-        if ( $quantity > $args['quantity'] ) {
1827
+        if ($quantity > $args['quantity']) {
1828 1828
             $item_price         = $cart_item['item_price'];
1829
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1829
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1830 1830
             
1831
-            $new_quantity       = max( $quantity - $args['quantity'], 1);
1831
+            $new_quantity       = max($quantity - $args['quantity'], 1);
1832 1832
             $subtotal           = $item_price * $new_quantity;
1833 1833
             
1834 1834
             $args['quantity']   = $new_quantity;
1835
-            $discount           = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1836
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1835
+            $discount           = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1836
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1837 1837
             
1838
-            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0;
1838
+            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float)$cart_item['discount'] / $quantity)) : 0;
1839 1839
             $discount_decrease  = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; 
1840
-            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0;
1840
+            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float)$cart_item['tax'] / $quantity)) : 0;
1841 1841
             $tax_decrease       = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease;
1842 1842
             
1843 1843
             // The total increase equals the number removed * the item_price
1844
-            $total_decrease     = wpinv_round_amount( $item_price );
1844
+            $total_decrease     = wpinv_round_amount($item_price);
1845 1845
             
1846
-            if ( wpinv_prices_include_tax() ) {
1847
-                $subtotal -= wpinv_round_amount( $tax );
1846
+            if (wpinv_prices_include_tax()) {
1847
+                $subtotal -= wpinv_round_amount($tax);
1848 1848
             }
1849 1849
 
1850
-            $total              = $subtotal - $discount + $tax;
1850
+            $total = $subtotal - $discount + $tax;
1851 1851
 
1852 1852
             // Do not allow totals to go negative
1853
-            if( $total < 0 ) {
1853
+            if ($total < 0) {
1854 1854
                 $total = 0;
1855 1855
             }
1856 1856
             
@@ -1869,16 +1869,16 @@  discard block
 block discarded – undo
1869 1869
             
1870 1870
             $this->cart_details[$found_cart_key] = $cart_item;
1871 1871
             
1872
-            $remove_item = end( $this->cart_details );
1872
+            $remove_item = end($this->cart_details);
1873 1873
         } else {
1874 1874
             $item_price     = $cart_item['item_price'];
1875
-            $discount       = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1876
-            $tax            = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0;
1875
+            $discount       = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1876
+            $tax            = !empty($cart_item['tax']) ? $cart_item['tax'] : 0;
1877 1877
         
1878
-            $subtotal_decrease  = ( $item_price * $quantity ) - $discount;
1878
+            $subtotal_decrease  = ($item_price * $quantity) - $discount;
1879 1879
             $tax_decrease       = $tax;
1880 1880
 
1881
-            unset( $this->cart_details[$found_cart_key] );
1881
+            unset($this->cart_details[$found_cart_key]);
1882 1882
             
1883 1883
             $remove_item             = $args;
1884 1884
             $remove_item['id']       = $item_id;
@@ -1889,8 +1889,8 @@  discard block
 block discarded – undo
1889 1889
         $remove_item['action']      = 'remove';
1890 1890
         $this->pending['items'][]   = $remove_item;
1891 1891
                
1892
-        $this->decrease_subtotal( $subtotal_decrease );
1893
-        $this->decrease_tax( $tax_decrease );
1892
+        $this->decrease_subtotal($subtotal_decrease);
1893
+        $this->decrease_tax($tax_decrease);
1894 1894
         
1895 1895
         return true;
1896 1896
     }
@@ -1898,7 +1898,7 @@  discard block
 block discarded – undo
1898 1898
     public function update_items($temp = false) {
1899 1899
         global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave;
1900 1900
         
1901
-        if ( !empty( $this->cart_details ) ) {
1901
+        if (!empty($this->cart_details)) {
1902 1902
             $wpi_nosave             = $temp;
1903 1903
             $cart_subtotal          = 0;
1904 1904
             $cart_discount          = 0;
@@ -1908,42 +1908,42 @@  discard block
 block discarded – undo
1908 1908
             $_POST['wpinv_country'] = $this->country;
1909 1909
             $_POST['wpinv_state']   = $this->state;
1910 1910
             
1911
-            foreach ( $this->cart_details as $key => $item ) {
1911
+            foreach ($this->cart_details as $key => $item) {
1912 1912
                 $item_price = $item['item_price'];
1913
-                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1914
-                $amount     = wpinv_round_amount( $item_price * $quantity );
1913
+                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1914
+                $amount     = wpinv_round_amount($item_price * $quantity);
1915 1915
                 $subtotal   = $item_price * $quantity;
1916 1916
                 
1917 1917
                 $wpi_current_id         = $this->ID;
1918 1918
                 $wpi_item_id            = $item['id'];
1919 1919
                 
1920
-                $discount   = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() );
1920
+                $discount   = wpinv_get_cart_item_discount_amount($item, $this->get_discounts());
1921 1921
                 
1922
-                $tax_rate   = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id );
1923
-                $tax_class  = $wpinv_euvat->get_item_class( $wpi_item_id );
1924
-                $tax        = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1922
+                $tax_rate   = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id);
1923
+                $tax_class  = $wpinv_euvat->get_item_class($wpi_item_id);
1924
+                $tax        = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1925 1925
 
1926
-                if ( wpinv_prices_include_tax() ) {
1927
-                    $subtotal -= wpinv_round_amount( $tax );
1926
+                if (wpinv_prices_include_tax()) {
1927
+                    $subtotal -= wpinv_round_amount($tax);
1928 1928
                 }
1929 1929
 
1930
-                $total      = $subtotal - $discount + $tax;
1930
+                $total = $subtotal - $discount + $tax;
1931 1931
 
1932 1932
                 // Do not allow totals to go negative
1933
-                if( $total < 0 ) {
1933
+                if ($total < 0) {
1934 1934
                     $total = 0;
1935 1935
                 }
1936 1936
 
1937 1937
                 $cart_details[] = array(
1938 1938
                     'id'          => $item['id'],
1939 1939
                     'name'        => $item['name'],
1940
-                    'item_price'  => wpinv_round_amount( $item_price ),
1941
-                    'custom_price'=> ( isset( $item['custom_price'] ) ? $item['custom_price'] : '' ),
1940
+                    'item_price'  => wpinv_round_amount($item_price),
1941
+                    'custom_price'=> (isset($item['custom_price']) ? $item['custom_price'] : ''),
1942 1942
                     'quantity'    => $quantity,
1943 1943
                     'discount'    => $discount,
1944
-                    'subtotal'    => wpinv_round_amount( $subtotal ),
1945
-                    'tax'         => wpinv_round_amount( $tax ),
1946
-                    'price'       => wpinv_round_amount( $total ),
1944
+                    'subtotal'    => wpinv_round_amount($subtotal),
1945
+                    'tax'         => wpinv_round_amount($tax),
1946
+                    'price'       => wpinv_round_amount($total),
1947 1947
                     'vat_rate'    => $tax_rate,
1948 1948
                     'vat_class'   => $tax_class,
1949 1949
                     'meta'        => isset($item['meta']) ? $item['meta'] : array(),
@@ -1954,9 +1954,9 @@  discard block
 block discarded – undo
1954 1954
                 $cart_discount  += (float)($discount);
1955 1955
                 $cart_tax       += (float)($tax);
1956 1956
             }
1957
-            $this->subtotal = wpinv_round_amount( $cart_subtotal );
1958
-            $this->tax      = wpinv_round_amount( $cart_tax );
1959
-            $this->discount = wpinv_round_amount( $cart_discount );
1957
+            $this->subtotal = wpinv_round_amount($cart_subtotal);
1958
+            $this->tax      = wpinv_round_amount($cart_tax);
1959
+            $this->discount = wpinv_round_amount($cart_discount);
1960 1960
             
1961 1961
             $this->recalculate_total();
1962 1962
             
@@ -1968,221 +1968,221 @@  discard block
 block discarded – undo
1968 1968
     
1969 1969
     public function recalculate_totals($temp = false) {        
1970 1970
         $this->update_items($temp);
1971
-        $this->save( true );
1971
+        $this->save(true);
1972 1972
         
1973 1973
         return $this;
1974 1974
     }
1975 1975
     
1976 1976
     public function needs_payment() {
1977
-        $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'pending' ), $this );
1977
+        $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('pending'), $this);
1978 1978
 
1979
-        if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() ) ) {
1979
+        if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free())) {
1980 1980
             $needs_payment = true;
1981 1981
         } else {
1982 1982
             $needs_payment = false;
1983 1983
         }
1984 1984
 
1985
-        return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses );
1985
+        return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses);
1986 1986
     }
1987 1987
     
1988
-    public function get_checkout_payment_url( $on_checkout = false, $secret = false ) {
1988
+    public function get_checkout_payment_url($on_checkout = false, $secret = false) {
1989 1989
         $pay_url = wpinv_get_checkout_uri();
1990 1990
 
1991
-        if ( is_ssl() ) {
1992
-            $pay_url = str_replace( 'http:', 'https:', $pay_url );
1991
+        if (is_ssl()) {
1992
+            $pay_url = str_replace('http:', 'https:', $pay_url);
1993 1993
         }
1994 1994
         
1995 1995
         $key = $this->get_key();
1996 1996
 
1997
-        if ( $on_checkout ) {
1998
-            $pay_url = add_query_arg( 'invoice_key', $key, $pay_url );
1997
+        if ($on_checkout) {
1998
+            $pay_url = add_query_arg('invoice_key', $key, $pay_url);
1999 1999
         } else {
2000
-            $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url );
2000
+            $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url);
2001 2001
         }
2002 2002
         
2003
-        if ( $secret ) {
2004
-            $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url );
2003
+        if ($secret) {
2004
+            $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url);
2005 2005
         }
2006 2006
 
2007
-        return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this );
2007
+        return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this);
2008 2008
     }
2009 2009
     
2010
-    public function get_view_url( $secret = false ) {
2011
-        $print_url = get_permalink( $this->ID );
2010
+    public function get_view_url($secret = false) {
2011
+        $print_url = get_permalink($this->ID);
2012 2012
         
2013
-        if ( $secret ) {
2014
-            $print_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $print_url );
2013
+        if ($secret) {
2014
+            $print_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key())), $print_url);
2015 2015
         }
2016 2016
 
2017
-        return apply_filters( 'wpinv_get_view_url', $print_url, $this );
2017
+        return apply_filters('wpinv_get_view_url', $print_url, $this);
2018 2018
     }
2019 2019
     
2020
-    public function generate_key( $string = '' ) {
2021
-        $auth_key  = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
2022
-        return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) );  // Unique key
2020
+    public function generate_key($string = '') {
2021
+        $auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
2022
+        return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key
2023 2023
     }
2024 2024
     
2025 2025
     public function is_recurring() {
2026
-        if ( empty( $this->cart_details ) ) {
2026
+        if (empty($this->cart_details)) {
2027 2027
             return false;
2028 2028
         }
2029 2029
         
2030 2030
         $has_subscription = false;
2031
-        foreach( $this->cart_details as $cart_item ) {
2032
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2031
+        foreach ($this->cart_details as $cart_item) {
2032
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2033 2033
                 $has_subscription = true;
2034 2034
                 break;
2035 2035
             }
2036 2036
         }
2037 2037
         
2038
-        if ( count( $this->cart_details ) > 1 ) {
2038
+        if (count($this->cart_details) > 1) {
2039 2039
             $has_subscription = false;
2040 2040
         }
2041 2041
 
2042
-        return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details );
2042
+        return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details);
2043 2043
     }
2044 2044
     
2045 2045
     public function is_free_trial() {
2046 2046
         $is_free_trial = false;
2047 2047
         
2048
-        if ( $this->is_parent() && $item = $this->get_recurring( true ) ) {
2049
-            if ( !empty( $item ) && $item->has_free_trial() ) {
2048
+        if ($this->is_parent() && $item = $this->get_recurring(true)) {
2049
+            if (!empty($item) && $item->has_free_trial()) {
2050 2050
                 $is_free_trial = true;
2051 2051
             }
2052 2052
         }
2053 2053
 
2054
-        return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details );
2054
+        return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details);
2055 2055
     }
2056 2056
     
2057
-    public function get_recurring( $object = false ) {
2057
+    public function get_recurring($object = false) {
2058 2058
         $item = NULL;
2059 2059
         
2060
-        if ( empty( $this->cart_details ) ) {
2060
+        if (empty($this->cart_details)) {
2061 2061
             return $item;
2062 2062
         }
2063 2063
         
2064
-        foreach( $this->cart_details as $cart_item ) {
2065
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2064
+        foreach ($this->cart_details as $cart_item) {
2065
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2066 2066
                 $item = $cart_item['id'];
2067 2067
                 break;
2068 2068
             }
2069 2069
         }
2070 2070
         
2071
-        if ( $object ) {
2072
-            $item = $item ? new WPInv_Item( $item ) : NULL;
2071
+        if ($object) {
2072
+            $item = $item ? new WPInv_Item($item) : NULL;
2073 2073
             
2074
-            apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this );
2074
+            apply_filters('wpinv_invoice_get_recurring_item', $item, $this);
2075 2075
         }
2076 2076
 
2077
-        return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this );
2077
+        return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this);
2078 2078
     }
2079 2079
     
2080 2080
     public function get_subscription_name() {
2081
-        $item = $this->get_recurring( true );
2081
+        $item = $this->get_recurring(true);
2082 2082
         
2083
-        if ( empty( $item ) ) {
2083
+        if (empty($item)) {
2084 2084
             return NULL;
2085 2085
         }
2086 2086
         
2087
-        if ( !($name = $item->get_name()) ) {
2087
+        if (!($name = $item->get_name())) {
2088 2088
             $name = $item->post_name;
2089 2089
         }
2090 2090
 
2091
-        return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this );
2091
+        return apply_filters('wpinv_invoice_get_subscription_name', $name, $this);
2092 2092
     }
2093 2093
         
2094 2094
     public function get_expiration() {
2095
-        $expiration = $this->get_meta( '_wpinv_subscr_expiration', true );
2095
+        $expiration = $this->get_meta('_wpinv_subscr_expiration', true);
2096 2096
         return $expiration;
2097 2097
     }
2098 2098
     
2099
-    public function get_cancelled_date( $formatted = true ) {
2100
-        $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta( '_wpinv_subscr_cancelled_on', true ) : '';
2099
+    public function get_cancelled_date($formatted = true) {
2100
+        $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta('_wpinv_subscr_cancelled_on', true) : '';
2101 2101
         
2102
-        if ( $formatted && $cancelled_date ) {
2103
-            $cancelled_date = date_i18n( get_option( 'date_format' ), strtotime( $cancelled_date ) );
2102
+        if ($formatted && $cancelled_date) {
2103
+            $cancelled_date = date_i18n(get_option('date_format'), strtotime($cancelled_date));
2104 2104
         }
2105 2105
         
2106 2106
         return $cancelled_date;
2107 2107
     }
2108 2108
     
2109
-    public function get_trial_end_date( $formatted = true ) {
2110
-        if ( !$this->is_free_trial() || !$this->is_paid() ) {
2109
+    public function get_trial_end_date($formatted = true) {
2110
+        if (!$this->is_free_trial() || !$this->is_paid()) {
2111 2111
             return NULL;
2112 2112
         }
2113 2113
         
2114
-        $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta( '_wpinv_subscr_trial_end', true ) : '';
2114
+        $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta('_wpinv_subscr_trial_end', true) : '';
2115 2115
         
2116
-        if ( empty( $trial_end_date ) ) {
2117
-            $trial_start_time = strtotime( $this->get_subscription_start() );
2118
-            $trial_start_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;
2116
+        if (empty($trial_end_date)) {
2117
+            $trial_start_time = strtotime($this->get_subscription_start());
2118
+            $trial_start_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);
2119 2119
             
2120
-            $trial_end_date = date_i18n( 'Y-m-d H:i:s', $trial_start_time );
2120
+            $trial_end_date = date_i18n('Y-m-d H:i:s', $trial_start_time);
2121 2121
         }
2122 2122
         
2123
-        if ( $formatted && $trial_end_date ) {
2124
-            $trial_end_date = date_i18n( get_option( 'date_format' ), strtotime( $trial_end_date ) );
2123
+        if ($formatted && $trial_end_date) {
2124
+            $trial_end_date = date_i18n(get_option('date_format'), strtotime($trial_end_date));
2125 2125
         }
2126 2126
         
2127 2127
         return $trial_end_date;
2128 2128
     }
2129 2129
     
2130
-    public function get_subscription_created( $default = true ) {
2131
-        $created = $this->get_meta( '_wpinv_subscr_created', true );
2130
+    public function get_subscription_created($default = true) {
2131
+        $created = $this->get_meta('_wpinv_subscr_created', true);
2132 2132
         
2133
-        if ( empty( $created ) && $default ) {
2133
+        if (empty($created) && $default) {
2134 2134
             $created = $this->date;
2135 2135
         }
2136 2136
         return $created;
2137 2137
     }
2138 2138
     
2139
-    public function get_subscription_start( $formatted = true ) {
2140
-        if ( !$this->is_paid() ) {
2139
+    public function get_subscription_start($formatted = true) {
2140
+        if (!$this->is_paid()) {
2141 2141
             return '-';
2142 2142
         }
2143
-        $start   = $this->get_subscription_created();
2143
+        $start = $this->get_subscription_created();
2144 2144
         
2145
-        if ( $formatted ) {
2146
-            $date = date_i18n( get_option( 'date_format' ), strtotime( $start ) );
2145
+        if ($formatted) {
2146
+            $date = date_i18n(get_option('date_format'), strtotime($start));
2147 2147
         } else {
2148
-            $date = date_i18n( 'Y-m-d H:i:s', strtotime( $start ) );
2148
+            $date = date_i18n('Y-m-d H:i:s', strtotime($start));
2149 2149
         }
2150 2150
 
2151 2151
         return $date;
2152 2152
     }
2153 2153
     
2154
-    public function get_subscription_end( $formatted = true ) {
2155
-        if ( !$this->is_paid() ) {
2154
+    public function get_subscription_end($formatted = true) {
2155
+        if (!$this->is_paid()) {
2156 2156
             return '-';
2157 2157
         }
2158 2158
         $start          = $this->get_subscription_created();
2159 2159
         $interval       = $this->get_subscription_interval();
2160
-        $period         = $this->get_subscription_period( true );
2160
+        $period         = $this->get_subscription_period(true);
2161 2161
         $bill_times     = (int)$this->get_bill_times();
2162 2162
         
2163
-        if ( $bill_times == 0 ) {
2164
-            return $formatted ? __( 'Until cancelled', 'invoicing' ) : $bill_times;
2163
+        if ($bill_times == 0) {
2164
+            return $formatted ? __('Until cancelled', 'invoicing') : $bill_times;
2165 2165
         }
2166 2166
         
2167
-        $total_period = $start . '+' . ( $interval * $bill_times ) . ' ' . $period;
2167
+        $total_period = $start . '+' . ($interval * $bill_times) . ' ' . $period;
2168 2168
         
2169
-        $end_time = strtotime( $start . '+' . ( $interval * $bill_times ) . ' ' . $period );
2169
+        $end_time = strtotime($start . '+' . ($interval * $bill_times) . ' ' . $period);
2170 2170
         
2171
-        if ( $this->is_free_trial() ) {
2172
-            $end_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;
2171
+        if ($this->is_free_trial()) {
2172
+            $end_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);
2173 2173
         }
2174 2174
         
2175
-        if ( $formatted ) {
2176
-            $date = date_i18n( get_option( 'date_format' ), $end_time );
2175
+        if ($formatted) {
2176
+            $date = date_i18n(get_option('date_format'), $end_time);
2177 2177
         } else {
2178
-            $date = date_i18n( 'Y-m-d H:i:s', $end_time );
2178
+            $date = date_i18n('Y-m-d H:i:s', $end_time);
2179 2179
         }
2180 2180
 
2181 2181
         return $date;
2182 2182
     }
2183 2183
     
2184 2184
     public function get_expiration_time() {
2185
-        return strtotime( $this->get_expiration(), current_time( 'timestamp' ) );
2185
+        return strtotime($this->get_expiration(), current_time('timestamp'));
2186 2186
     }
2187 2187
     
2188 2188
     public function get_original_invoice_id() {        
@@ -2194,125 +2194,125 @@  discard block
 block discarded – undo
2194 2194
         return $subscription_data['bill_times'];
2195 2195
     }
2196 2196
 
2197
-    public function get_child_payments( $self = false ) {
2198
-        $invoices = get_posts( array(
2197
+    public function get_child_payments($self = false) {
2198
+        $invoices = get_posts(array(
2199 2199
             'post_type'         => $this->post_type,
2200 2200
             'post_parent'       => (int)$this->ID,
2201 2201
             'posts_per_page'    => '999',
2202
-            'post_status'       => array( 'publish', 'wpi-processing', 'wpi-renewal' ),
2202
+            'post_status'       => array('publish', 'wpi-processing', 'wpi-renewal'),
2203 2203
             'orderby'           => 'ID',
2204 2204
             'order'             => 'DESC',
2205 2205
             'fields'            => 'ids'
2206
-        ) );
2206
+        ));
2207 2207
         
2208
-        if ( $this->is_free_trial() ) {
2208
+        if ($this->is_free_trial()) {
2209 2209
             $self = false;
2210 2210
         }
2211 2211
         
2212
-        if ( $self && $this->is_paid() ) {
2213
-            if ( !empty( $invoices ) ) {
2212
+        if ($self && $this->is_paid()) {
2213
+            if (!empty($invoices)) {
2214 2214
                 $invoices[] = (int)$this->ID;
2215 2215
             } else {
2216
-                $invoices = array( $this->ID );
2216
+                $invoices = array($this->ID);
2217 2217
             }
2218 2218
             
2219
-            $invoices = array_unique( $invoices );
2219
+            $invoices = array_unique($invoices);
2220 2220
         }
2221 2221
 
2222 2222
         return $invoices;
2223 2223
     }
2224 2224
 
2225
-    public function get_total_payments( $self = true ) {
2226
-        return count( $this->get_child_payments( $self ) );
2225
+    public function get_total_payments($self = true) {
2226
+        return count($this->get_child_payments($self));
2227 2227
     }
2228 2228
     
2229
-    public function get_subscriptions( $limit = -1 ) {
2230
-        $subscriptions = wpinv_get_subscriptions( array( 'parent_invoice_id' => $this->ID, 'numberposts' => $limit ) );
2229
+    public function get_subscriptions($limit = -1) {
2230
+        $subscriptions = wpinv_get_subscriptions(array('parent_invoice_id' => $this->ID, 'numberposts' => $limit));
2231 2231
 
2232 2232
         return $subscriptions;
2233 2233
     }
2234 2234
     
2235 2235
     public function get_subscription_id() {
2236
-        $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true );
2236
+        $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true);
2237 2237
         
2238
-        if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) {
2239
-            $parent_invoice = wpinv_get_invoice( $this->parent_invoice );
2238
+        if (empty($subscription_id) && !empty($this->parent_invoice)) {
2239
+            $parent_invoice = wpinv_get_invoice($this->parent_invoice);
2240 2240
             
2241
-            $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true );
2241
+            $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true);
2242 2242
         }
2243 2243
         
2244 2244
         return $subscription_id;
2245 2245
     }
2246 2246
     
2247 2247
     public function get_subscription_status() {
2248
-        $subscription_status = $this->get_meta( '_wpinv_subscr_status', true );
2248
+        $subscription_status = $this->get_meta('_wpinv_subscr_status', true);
2249 2249
 
2250
-        if ( empty( $subscription_status ) ) {
2250
+        if (empty($subscription_status)) {
2251 2251
             $status = 'pending';
2252 2252
             
2253
-            if ( $this->is_paid() ) {        
2253
+            if ($this->is_paid()) {        
2254 2254
                 $bill_times   = (int)$this->get_bill_times();
2255 2255
                 $times_billed = (int)$this->get_total_payments();
2256
-                $expiration = $this->get_subscription_end( false );
2257
-                $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;
2256
+                $expiration = $this->get_subscription_end(false);
2257
+                $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;
2258 2258
                 
2259
-                if ( (int)$bill_times == 0 ) {
2259
+                if ((int)$bill_times == 0) {
2260 2260
                     $status = $expired ? 'expired' : 'active';
2261
-                } else if ( $bill_times > 0 && $times_billed >= $bill_times ) {
2261
+                } else if ($bill_times > 0 && $times_billed >= $bill_times) {
2262 2262
                     $status = 'completed';
2263
-                } else if ( $expired ) {
2263
+                } else if ($expired) {
2264 2264
                     $status = 'expired';
2265
-                } else if ( $bill_times > 0 ) {
2265
+                } else if ($bill_times > 0) {
2266 2266
                     $status = 'active';
2267 2267
                 } else {
2268 2268
                     $status = 'pending';
2269 2269
                 }
2270 2270
             }
2271 2271
             
2272
-            if ( $status && $status != $subscription_status ) {
2272
+            if ($status && $status != $subscription_status) {
2273 2273
                 $subscription_status = $status;
2274 2274
                 
2275
-                $this->update_meta( '_wpinv_subscr_status', $status );
2275
+                $this->update_meta('_wpinv_subscr_status', $status);
2276 2276
             }
2277 2277
         }
2278 2278
         
2279 2279
         return $subscription_status;
2280 2280
     }
2281 2281
     
2282
-    public function get_subscription_status_label( $status = '' ) {
2283
-        $status = !empty( $status ) ? $status : $this->get_subscription_status();
2282
+    public function get_subscription_status_label($status = '') {
2283
+        $status = !empty($status) ? $status : $this->get_subscription_status();
2284 2284
 
2285
-        switch( $status ) {
2285
+        switch ($status) {
2286 2286
             case 'active' :
2287
-                $status_label = __( 'Active', 'invoicing' );
2287
+                $status_label = __('Active', 'invoicing');
2288 2288
                 break;
2289 2289
 
2290 2290
             case 'cancelled' :
2291
-                $status_label = __( 'Cancelled', 'invoicing' );
2291
+                $status_label = __('Cancelled', 'invoicing');
2292 2292
                 break;
2293 2293
                 
2294 2294
             case 'completed' :
2295
-                $status_label = __( 'Completed', 'invoicing' );
2295
+                $status_label = __('Completed', 'invoicing');
2296 2296
                 break;
2297 2297
 
2298 2298
             case 'expired' :
2299
-                $status_label = __( 'Expired', 'invoicing' );
2299
+                $status_label = __('Expired', 'invoicing');
2300 2300
                 break;
2301 2301
 
2302 2302
             case 'pending' :
2303
-                $status_label = __( 'Pending', 'invoicing' );
2303
+                $status_label = __('Pending', 'invoicing');
2304 2304
                 break;
2305 2305
 
2306 2306
             case 'failing' :
2307
-                $status_label = __( 'Failing', 'invoicing' );
2307
+                $status_label = __('Failing', 'invoicing');
2308 2308
                 break;
2309 2309
                 
2310 2310
             case 'stopped' :
2311
-                $status_label = __( 'Stopped', 'invoicing' );
2311
+                $status_label = __('Stopped', 'invoicing');
2312 2312
                 break;
2313 2313
                 
2314 2314
             case 'trialing' :
2315
-                $status_label = __( 'Trialing', 'invoicing' );
2315
+                $status_label = __('Trialing', 'invoicing');
2316 2316
                 break;
2317 2317
 
2318 2318
             default:
@@ -2323,26 +2323,26 @@  discard block
 block discarded – undo
2323 2323
         return $status_label;
2324 2324
     }
2325 2325
     
2326
-    public function get_subscription_period( $full = false ) {
2327
-        $period = $this->get_meta( '_wpinv_subscr_period', true );
2326
+    public function get_subscription_period($full = false) {
2327
+        $period = $this->get_meta('_wpinv_subscr_period', true);
2328 2328
         
2329 2329
         // Fix period for old invoices
2330
-        if ( $period == 'day' ) {
2330
+        if ($period == 'day') {
2331 2331
             $period = 'D';
2332
-        } else if ( $period == 'week' ) {
2332
+        } else if ($period == 'week') {
2333 2333
             $period = 'W';
2334
-        } else if ( $period == 'month' ) {
2334
+        } else if ($period == 'month') {
2335 2335
             $period = 'M';
2336
-        } else if ( $period == 'year' ) {
2336
+        } else if ($period == 'year') {
2337 2337
             $period = 'Y';
2338 2338
         }
2339 2339
         
2340
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2340
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
2341 2341
             $period = 'D';
2342 2342
         }
2343 2343
         
2344
-        if ( $full ) {
2345
-            switch( $period ) {
2344
+        if ($full) {
2345
+            switch ($period) {
2346 2346
                 case 'D':
2347 2347
                     $period = 'day';
2348 2348
                 break;
@@ -2362,39 +2362,39 @@  discard block
 block discarded – undo
2362 2362
     }
2363 2363
     
2364 2364
     public function get_subscription_interval() {
2365
-        $interval = (int)$this->get_meta( '_wpinv_subscr_interval', true );
2365
+        $interval = (int)$this->get_meta('_wpinv_subscr_interval', true);
2366 2366
         
2367
-        if ( !$interval > 0 ) {
2367
+        if (!$interval > 0) {
2368 2368
             $interval = 1;
2369 2369
         }
2370 2370
         
2371 2371
         return $interval;
2372 2372
     }
2373 2373
     
2374
-    public function get_subscription_trial_period( $full = false ) {
2375
-        if ( !$this->is_free_trial() ) {
2374
+    public function get_subscription_trial_period($full = false) {
2375
+        if (!$this->is_free_trial()) {
2376 2376
             return '';
2377 2377
         }
2378 2378
         
2379
-        $period = $this->get_meta( '_wpinv_subscr_trial_period', true );
2379
+        $period = $this->get_meta('_wpinv_subscr_trial_period', true);
2380 2380
         
2381 2381
         // Fix period for old invoices
2382
-        if ( $period == 'day' ) {
2382
+        if ($period == 'day') {
2383 2383
             $period = 'D';
2384
-        } else if ( $period == 'week' ) {
2384
+        } else if ($period == 'week') {
2385 2385
             $period = 'W';
2386
-        } else if ( $period == 'month' ) {
2386
+        } else if ($period == 'month') {
2387 2387
             $period = 'M';
2388
-        } else if ( $period == 'year' ) {
2388
+        } else if ($period == 'year') {
2389 2389
             $period = 'Y';
2390 2390
         }
2391 2391
         
2392
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2392
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
2393 2393
             $period = 'D';
2394 2394
         }
2395 2395
         
2396
-        if ( $full ) {
2397
-            switch( $period ) {
2396
+        if ($full) {
2397
+            switch ($period) {
2398 2398
                 case 'D':
2399 2399
                     $period = 'day';
2400 2400
                 break;
@@ -2414,13 +2414,13 @@  discard block
 block discarded – undo
2414 2414
     }
2415 2415
     
2416 2416
     public function get_subscription_trial_interval() {
2417
-        if ( !$this->is_free_trial() ) {
2417
+        if (!$this->is_free_trial()) {
2418 2418
             return 0;
2419 2419
         }
2420 2420
         
2421
-        $interval = (int)$this->get_meta( '_wpinv_subscr_trial_interval', true );
2421
+        $interval = (int)$this->get_meta('_wpinv_subscr_trial_interval', true);
2422 2422
         
2423
-        if ( !$interval > 0 ) {
2423
+        if (!$interval > 0) {
2424 2424
             $interval = 1;
2425 2425
         }
2426 2426
         
@@ -2432,8 +2432,8 @@  discard block
 block discarded – undo
2432 2432
             'status' => 'failing'
2433 2433
         );
2434 2434
 
2435
-        if ( $this->update_subscription( $args ) ) {
2436
-            do_action( 'wpinv_subscription_failing', $this->ID, $this );
2435
+        if ($this->update_subscription($args)) {
2436
+            do_action('wpinv_subscription_failing', $this->ID, $this);
2437 2437
             return true;
2438 2438
         }
2439 2439
 
@@ -2445,8 +2445,8 @@  discard block
 block discarded – undo
2445 2445
             'status' => 'stopped'
2446 2446
         );
2447 2447
 
2448
-        if ( $this->update_subscription( $args ) ) {
2449
-            do_action( 'wpinv_subscription_stopped', $this->ID, $this );
2448
+        if ($this->update_subscription($args)) {
2449
+            do_action('wpinv_subscription_stopped', $this->ID, $this);
2450 2450
             return true;
2451 2451
         }
2452 2452
 
@@ -2458,8 +2458,8 @@  discard block
 block discarded – undo
2458 2458
             'status' => 'active'
2459 2459
         );
2460 2460
 
2461
-        if ( $this->update_subscription( $args ) ) {
2462
-            do_action( 'wpinv_subscription_restarted', $this->ID, $this );
2461
+        if ($this->update_subscription($args)) {
2462
+            do_action('wpinv_subscription_restarted', $this->ID, $this);
2463 2463
             return true;
2464 2464
         }
2465 2465
 
@@ -2471,23 +2471,23 @@  discard block
 block discarded – undo
2471 2471
             'status' => 'cancelled'
2472 2472
         );
2473 2473
 
2474
-        if ( $this->update_subscription( $args ) ) {
2475
-            if ( is_user_logged_in() ) {
2476
-                $userdata = get_userdata( get_current_user_id() );
2474
+        if ($this->update_subscription($args)) {
2475
+            if (is_user_logged_in()) {
2476
+                $userdata = get_userdata(get_current_user_id());
2477 2477
                 $user     = $userdata->user_login;
2478 2478
             } else {
2479
-                $user = __( 'gateway', 'invoicing' );
2479
+                $user = __('gateway', 'invoicing');
2480 2480
             }
2481 2481
             
2482 2482
             $subscription_id = $this->get_subscription_id();
2483
-            if ( !$subscription_id ) {
2483
+            if (!$subscription_id) {
2484 2484
                 $subscription_id = $this->ID;
2485 2485
             }
2486 2486
 
2487
-            $note = sprintf( __( 'Subscription %s has been cancelled by %s', 'invoicing' ), $subscription_id, $user );
2488
-            $this->add_note( $note );
2487
+            $note = sprintf(__('Subscription %s has been cancelled by %s', 'invoicing'), $subscription_id, $user);
2488
+            $this->add_note($note);
2489 2489
 
2490
-            do_action( 'wpinv_subscription_cancelled', $this->ID, $this );
2490
+            do_action('wpinv_subscription_cancelled', $this->ID, $this);
2491 2491
             return true;
2492 2492
         }
2493 2493
 
@@ -2495,11 +2495,11 @@  discard block
 block discarded – undo
2495 2495
     }
2496 2496
 
2497 2497
     public function can_cancel() {
2498
-        return apply_filters( 'wpinv_subscription_can_cancel', false, $this );
2498
+        return apply_filters('wpinv_subscription_can_cancel', false, $this);
2499 2499
     }
2500 2500
     
2501
-    public function add_subscription( $data = array() ) {
2502
-        if ( empty( $this->ID ) ) {
2501
+    public function add_subscription($data = array()) {
2502
+        if (empty($this->ID)) {
2503 2503
             return false;
2504 2504
         }
2505 2505
 
@@ -2518,85 +2518,85 @@  discard block
 block discarded – undo
2518 2518
             'profile_id'        => '',
2519 2519
         );
2520 2520
 
2521
-        $args = wp_parse_args( $data, $defaults );
2521
+        $args = wp_parse_args($data, $defaults);
2522 2522
 
2523
-        if ( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
2524
-            if ( 'active' == $args['status'] || $args['status'] == 'trialing' ) {
2523
+        if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
2524
+            if ('active' == $args['status'] || $args['status'] == 'trialing') {
2525 2525
                 $args['status'] = 'expired';
2526 2526
             }
2527 2527
         }
2528 2528
 
2529
-        do_action( 'wpinv_subscription_pre_create', $args, $data, $this );
2529
+        do_action('wpinv_subscription_pre_create', $args, $data, $this);
2530 2530
         
2531
-        if ( !empty( $args ) ) {
2532
-            foreach ( $args as $key => $value ) {
2533
-                $this->update_meta( '_wpinv_subscr_' . $key, $value );
2531
+        if (!empty($args)) {
2532
+            foreach ($args as $key => $value) {
2533
+                $this->update_meta('_wpinv_subscr_' . $key, $value);
2534 2534
             }
2535 2535
         }
2536 2536
 
2537
-        do_action( 'wpinv_subscription_post_create', $args, $data, $this );
2537
+        do_action('wpinv_subscription_post_create', $args, $data, $this);
2538 2538
 
2539 2539
         return true;
2540 2540
     }
2541 2541
     
2542
-    public function update_subscription( $args = array() ) {
2543
-        if ( empty( $this->ID ) ) {
2542
+    public function update_subscription($args = array()) {
2543
+        if (empty($this->ID)) {
2544 2544
             return false;
2545 2545
         }
2546 2546
 
2547
-        if ( !empty( $args['expiration'] ) && $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
2548
-            if ( !isset( $args['status'] ) || ( isset( $args['status'] ) && ( 'active' == $args['status'] || $args['status'] == 'trialing' ) ) ) {
2547
+        if (!empty($args['expiration']) && $args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
2548
+            if (!isset($args['status']) || (isset($args['status']) && ('active' == $args['status'] || $args['status'] == 'trialing'))) {
2549 2549
                 $args['status'] = 'expired';
2550 2550
             }
2551 2551
         }
2552 2552
 
2553
-        if ( isset( $args['status'] ) && $args['status'] == 'cancelled' && empty( $args['cancelled_on'] ) ) {
2554
-            $args['cancelled_on'] = date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) );
2553
+        if (isset($args['status']) && $args['status'] == 'cancelled' && empty($args['cancelled_on'])) {
2554
+            $args['cancelled_on'] = date_i18n('Y-m-d H:i:s', current_time('timestamp'));
2555 2555
         }
2556 2556
 
2557
-        do_action( 'wpinv_subscription_pre_update', $args, $this );
2557
+        do_action('wpinv_subscription_pre_update', $args, $this);
2558 2558
         
2559
-        if ( !empty( $args ) ) {
2560
-            foreach ( $args as $key => $value ) {
2561
-                $this->update_meta( '_wpinv_subscr_' . $key, $value );
2559
+        if (!empty($args)) {
2560
+            foreach ($args as $key => $value) {
2561
+                $this->update_meta('_wpinv_subscr_' . $key, $value);
2562 2562
             }
2563 2563
         }
2564 2564
 
2565
-        do_action( 'wpinv_subscription_post_update', $args, $this );
2565
+        do_action('wpinv_subscription_post_update', $args, $this);
2566 2566
 
2567 2567
         return true;
2568 2568
     }
2569 2569
     
2570 2570
     public function renew_subscription() {
2571 2571
         $parent_invoice = $this->get_parent_payment();
2572
-        $parent_invoice = empty( $parent_invoice ) ? $this : $parent_invoice;
2572
+        $parent_invoice = empty($parent_invoice) ? $this : $parent_invoice;
2573 2573
         
2574
-        $current_time   = current_time( 'timestamp' );
2574
+        $current_time   = current_time('timestamp');
2575 2575
         $start          = $this->get_subscription_created();
2576
-        $start          = $start ? strtotime( $start ) : $current_time;
2576
+        $start          = $start ? strtotime($start) : $current_time;
2577 2577
         $expires        = $this->get_expiration_time();
2578 2578
         
2579
-        if ( !$expires ) {
2580
-            $expires    = strtotime( '+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period( true ), $start );
2579
+        if (!$expires) {
2580
+            $expires    = strtotime('+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period(true), $start);
2581 2581
         }
2582 2582
         
2583
-        $expiration     = date_i18n( 'Y-m-d 23:59:59', $expires );
2584
-        $expiration     = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this );
2583
+        $expiration     = date_i18n('Y-m-d 23:59:59', $expires);
2584
+        $expiration     = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this);
2585 2585
         $bill_times     = $parent_invoice->get_bill_times();
2586 2586
         $times_billed   = $parent_invoice->get_total_payments();
2587 2587
         
2588
-        if ( $parent_invoice->get_subscription_status() == 'trialing' && ( $times_billed > 0 || strtotime( date_i18n( 'Y-m-d' ) ) < strtotime( $parent_invoice->get_trial_end_date( false ) ) ) ) {
2588
+        if ($parent_invoice->get_subscription_status() == 'trialing' && ($times_billed > 0 || strtotime(date_i18n('Y-m-d')) < strtotime($parent_invoice->get_trial_end_date(false)))) {
2589 2589
             $args = array(
2590 2590
                 'status'     => 'active',
2591 2591
             );
2592 2592
 
2593
-            $parent_invoice->update_subscription( $args );
2593
+            $parent_invoice->update_subscription($args);
2594 2594
         }
2595 2595
         
2596
-        do_action( 'wpinv_subscription_pre_renew', $this->ID, $expiration, $this );
2596
+        do_action('wpinv_subscription_pre_renew', $this->ID, $expiration, $this);
2597 2597
 
2598
-        $status       = 'active';
2599
-        if ( $bill_times > 0 && $times_billed >= $bill_times ) {
2598
+        $status = 'active';
2599
+        if ($bill_times > 0 && $times_billed >= $bill_times) {
2600 2600
             $this->complete_subscription();
2601 2601
             $status = 'completed';
2602 2602
         }
@@ -2606,10 +2606,10 @@  discard block
 block discarded – undo
2606 2606
             'status'     => $status,
2607 2607
         );
2608 2608
 
2609
-        $this->update_subscription( $args );
2609
+        $this->update_subscription($args);
2610 2610
 
2611
-        do_action( 'wpinv_subscription_post_renew', $this->ID, $expiration, $this );
2612
-        do_action( 'wpinv_recurring_set_subscription_status', $this->ID, $status, $this );
2611
+        do_action('wpinv_subscription_post_renew', $this->ID, $expiration, $this);
2612
+        do_action('wpinv_recurring_set_subscription_status', $this->ID, $status, $this);
2613 2613
     }
2614 2614
     
2615 2615
     public function complete_subscription() {
@@ -2617,8 +2617,8 @@  discard block
 block discarded – undo
2617 2617
             'status' => 'completed'
2618 2618
         );
2619 2619
 
2620
-        if ( $this->update_subscription( $args ) ) {
2621
-            do_action( 'wpinv_subscription_completed', $this->ID, $this );
2620
+        if ($this->update_subscription($args)) {
2621
+            do_action('wpinv_subscription_completed', $this->ID, $this);
2622 2622
         }
2623 2623
     }
2624 2624
     
@@ -2627,44 +2627,44 @@  discard block
 block discarded – undo
2627 2627
             'status' => 'expired'
2628 2628
         );
2629 2629
 
2630
-        if ( $this->update_subscription( $args ) ) {
2631
-            do_action( 'wpinv_subscription_expired', $this->ID, $this );
2630
+        if ($this->update_subscription($args)) {
2631
+            do_action('wpinv_subscription_expired', $this->ID, $this);
2632 2632
         }
2633 2633
     }
2634 2634
 
2635 2635
     public function get_cancel_url() {
2636
-        $url = wp_nonce_url( add_query_arg( array( 'wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID ) ), 'wpinv-recurring-cancel' );
2636
+        $url = wp_nonce_url(add_query_arg(array('wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID)), 'wpinv-recurring-cancel');
2637 2637
 
2638
-        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
2638
+        return apply_filters('wpinv_subscription_cancel_url', $url, $this);
2639 2639
     }
2640 2640
 
2641 2641
     public function can_update() {
2642
-        return apply_filters( 'wpinv_subscription_can_update', false, $this );
2642
+        return apply_filters('wpinv_subscription_can_update', false, $this);
2643 2643
     }
2644 2644
 
2645 2645
     public function get_update_url() {
2646
-        $url = add_query_arg( array( 'action' => 'update', 'sub_id' => $this->ID ) );
2646
+        $url = add_query_arg(array('action' => 'update', 'sub_id' => $this->ID));
2647 2647
 
2648
-        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
2648
+        return apply_filters('wpinv_subscription_update_url', $url, $this);
2649 2649
     }
2650 2650
 
2651 2651
     public function is_parent() {
2652
-        $is_parent = empty( $this->parent_invoice ) ? true : false;
2652
+        $is_parent = empty($this->parent_invoice) ? true : false;
2653 2653
 
2654
-        return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this );
2654
+        return apply_filters('wpinv_invoice_is_parent', $is_parent, $this);
2655 2655
     }
2656 2656
     
2657 2657
     public function is_renewal() {
2658 2658
         $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false;
2659 2659
 
2660
-        return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this );
2660
+        return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this);
2661 2661
     }
2662 2662
     
2663 2663
     public function get_parent_payment() {
2664 2664
         $parent_payment = NULL;
2665 2665
         
2666
-        if ( $this->is_renewal() ) {
2667
-            $parent_payment = wpinv_get_invoice( $this->parent_invoice );
2666
+        if ($this->is_renewal()) {
2667
+            $parent_payment = wpinv_get_invoice($this->parent_invoice);
2668 2668
         }
2669 2669
         
2670 2670
         return $parent_payment;
@@ -2675,100 +2675,100 @@  discard block
 block discarded – undo
2675 2675
         
2676 2676
         $subscription_status = $this->get_subscription_status();
2677 2677
 
2678
-        if( ! $this->is_subscription_expired() && ( $subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing' ) ) {
2678
+        if (!$this->is_subscription_expired() && ($subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing')) {
2679 2679
             $ret = true;
2680 2680
         }
2681 2681
 
2682
-        return apply_filters( 'wpinv_subscription_is_active', $ret, $this->ID, $this );
2682
+        return apply_filters('wpinv_subscription_is_active', $ret, $this->ID, $this);
2683 2683
     }
2684 2684
 
2685 2685
     public function is_subscription_expired() {
2686 2686
         $ret = false;
2687 2687
         $subscription_status = $this->get_subscription_status();
2688 2688
 
2689
-        if ( $subscription_status == 'expired' ) {
2689
+        if ($subscription_status == 'expired') {
2690 2690
             $ret = true;
2691
-        } else if ( 'active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status ) {
2691
+        } else if ('active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status) {
2692 2692
             $ret        = false;
2693 2693
             $expiration = $this->get_expiration_time();
2694 2694
 
2695
-            if ( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) {
2695
+            if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) {
2696 2696
                 $ret = true;
2697 2697
 
2698
-                if ( 'active' === $subscription_status || 'trialing' === $subscription_status ) {
2698
+                if ('active' === $subscription_status || 'trialing' === $subscription_status) {
2699 2699
                     $this->expire_subscription();
2700 2700
                 }
2701 2701
             }
2702 2702
         }
2703 2703
 
2704
-        return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->ID, $this );
2704
+        return apply_filters('wpinv_subscription_is_expired', $ret, $this->ID, $this);
2705 2705
     }
2706 2706
     
2707
-    public function get_new_expiration( $item_id = 0, $trial = true ) {
2708
-        $item   = new WPInv_Item( $item_id );
2707
+    public function get_new_expiration($item_id = 0, $trial = true) {
2708
+        $item   = new WPInv_Item($item_id);
2709 2709
         $interval = $item->get_recurring_interval();
2710
-        $period = $item->get_recurring_period( true );
2710
+        $period = $item->get_recurring_period(true);
2711 2711
         
2712
-        $expiration_time = strtotime( '+' . $interval . ' ' . $period );
2712
+        $expiration_time = strtotime('+' . $interval . ' ' . $period);
2713 2713
         
2714
-        if ( $trial && $this->is_free_trial() && $item->has_free_trial() ) {
2715
-            $expiration_time += ( wpinv_period_in_days( $item->get_trial_interval(), $item->get_trial_period() ) * DAY_IN_SECONDS ) ;
2714
+        if ($trial && $this->is_free_trial() && $item->has_free_trial()) {
2715
+            $expiration_time += (wpinv_period_in_days($item->get_trial_interval(), $item->get_trial_period()) * DAY_IN_SECONDS);
2716 2716
         }
2717 2717
 
2718
-        return date_i18n( 'Y-m-d 23:59:59', $expiration_time );
2718
+        return date_i18n('Y-m-d 23:59:59', $expiration_time);
2719 2719
     }
2720 2720
     
2721
-    public function get_subscription_data( $filed = '' ) {
2722
-        $fields = array( 'item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on' );
2721
+    public function get_subscription_data($filed = '') {
2722
+        $fields = array('item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on');
2723 2723
         
2724 2724
         $subscription_meta = array();
2725
-        foreach ( $fields as $field ) {
2726
-            $subscription_meta[ $field ] = $this->get_meta( '_wpinv_subscr_' . $field );
2725
+        foreach ($fields as $field) {
2726
+            $subscription_meta[$field] = $this->get_meta('_wpinv_subscr_' . $field);
2727 2727
         }
2728 2728
         
2729
-        $item = $this->get_recurring( true );
2729
+        $item = $this->get_recurring(true);
2730 2730
         
2731
-        if ( !empty( $item ) ) {
2732
-            if ( empty( $subscription_meta['item_id'] ) ) {
2731
+        if (!empty($item)) {
2732
+            if (empty($subscription_meta['item_id'])) {
2733 2733
                 $subscription_meta['item_id'] = $item->ID;
2734 2734
             }
2735
-            if ( empty( $subscription_meta['period'] ) ) {
2735
+            if (empty($subscription_meta['period'])) {
2736 2736
                 $subscription_meta['period'] = $item->get_recurring_period();
2737 2737
             }
2738
-            if ( empty( $subscription_meta['interval'] ) ) {
2738
+            if (empty($subscription_meta['interval'])) {
2739 2739
                 $subscription_meta['interval'] = $item->get_recurring_interval();
2740 2740
             }
2741
-            if ( $item->has_free_trial() ) {
2742
-                if ( empty( $subscription_meta['trial_period'] ) ) {
2741
+            if ($item->has_free_trial()) {
2742
+                if (empty($subscription_meta['trial_period'])) {
2743 2743
                     $subscription_meta['trial_period'] = $item->get_trial_period();
2744 2744
                 }
2745
-                if ( empty( $subscription_meta['trial_interval'] ) ) {
2745
+                if (empty($subscription_meta['trial_interval'])) {
2746 2746
                     $subscription_meta['trial_interval'] = $item->get_trial_interval();
2747 2747
                 }
2748 2748
             } else {
2749 2749
                 $subscription_meta['trial_period']      = '';
2750 2750
                 $subscription_meta['trial_interval']    = 0;
2751 2751
             }
2752
-            if ( !$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0 ) {
2752
+            if (!$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0) {
2753 2753
                 $subscription_meta['bill_times'] = $item->get_recurring_limit();
2754 2754
             }
2755
-            if ( $subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '' ) {
2756
-                $subscription_meta['initial_amount']    = wpinv_round_amount( $this->get_total() );
2757
-                $subscription_meta['recurring_amount']  = wpinv_round_amount( $this->get_recurring_details( 'total' ) );
2755
+            if ($subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '') {
2756
+                $subscription_meta['initial_amount']    = wpinv_round_amount($this->get_total());
2757
+                $subscription_meta['recurring_amount']  = wpinv_round_amount($this->get_recurring_details('total'));
2758 2758
             }
2759 2759
         }
2760 2760
         
2761
-        if ( $filed === '' ) {
2762
-            return apply_filters( 'wpinv_get_invoice_subscription_data', $subscription_meta, $this );
2761
+        if ($filed === '') {
2762
+            return apply_filters('wpinv_get_invoice_subscription_data', $subscription_meta, $this);
2763 2763
         }
2764 2764
         
2765
-        $value = isset( $subscription_meta[$filed] ) ? $subscription_meta[$filed] : '';
2765
+        $value = isset($subscription_meta[$filed]) ? $subscription_meta[$filed] : '';
2766 2766
         
2767
-        return apply_filters( 'wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this );
2767
+        return apply_filters('wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this);
2768 2768
     }
2769 2769
     
2770 2770
     public function is_paid() {
2771
-        if ( $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
2771
+        if ($this->has_status(array('publish', 'wpi-processing', 'wpi-renewal'))) {
2772 2772
             return true;
2773 2773
         }
2774 2774
         
@@ -2778,15 +2778,15 @@  discard block
 block discarded – undo
2778 2778
     public function is_free() {
2779 2779
         $is_free = false;
2780 2780
         
2781
-        if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) {
2782
-            if ( $this->is_parent() && $this->is_recurring() ) {
2783
-                $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true;
2781
+        if (!((float)wpinv_round_amount($this->get_total()) > 0)) {
2782
+            if ($this->is_parent() && $this->is_recurring()) {
2783
+                $is_free = (float)wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true;
2784 2784
             } else {
2785 2785
                 $is_free = true;
2786 2786
             }
2787 2787
         }
2788 2788
         
2789
-        return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2789
+        return apply_filters('wpinv_invoice_is_free', $is_free, $this);
2790 2790
     }
2791 2791
     
2792 2792
     public function has_vat() {
@@ -2794,41 +2794,41 @@  discard block
 block discarded – undo
2794 2794
         
2795 2795
         $requires_vat = false;
2796 2796
         
2797
-        if ( $this->country ) {
2797
+        if ($this->country) {
2798 2798
             $wpi_country        = $this->country;
2799 2799
             
2800
-            $requires_vat       = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) );
2800
+            $requires_vat       = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this));
2801 2801
         }
2802 2802
         
2803
-        return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2803
+        return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this);
2804 2804
     }
2805 2805
     
2806 2806
     public function refresh_item_ids() {
2807 2807
         $item_ids = array();
2808 2808
         
2809
-        if ( !empty( $this->cart_details ) ) {
2810
-            foreach ( $this->cart_details as $key => $item ) {
2811
-                if ( !empty( $item['id'] ) ) {
2809
+        if (!empty($this->cart_details)) {
2810
+            foreach ($this->cart_details as $key => $item) {
2811
+                if (!empty($item['id'])) {
2812 2812
                     $item_ids[] = $item['id'];
2813 2813
                 }
2814 2814
             }
2815 2815
         }
2816 2816
         
2817
-        $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : '';
2817
+        $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : '';
2818 2818
         
2819
-        update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids );
2819
+        update_post_meta($this->ID, '_wpinv_item_ids', $item_ids);
2820 2820
     }
2821 2821
     
2822
-    public function get_invoice_quote_type( $post_id ) {
2823
-        if ( empty( $post_id ) ) {
2822
+    public function get_invoice_quote_type($post_id) {
2823
+        if (empty($post_id)) {
2824 2824
             return '';
2825 2825
         }
2826 2826
 
2827
-        $type = get_post_type( $post_id );
2827
+        $type = get_post_type($post_id);
2828 2828
 
2829
-        if ( 'wpi_invoice' === $type ) {
2829
+        if ('wpi_invoice' === $type) {
2830 2830
             $post_type = __('Invoice', 'invoicing');
2831
-        } else{
2831
+        } else {
2832 2832
             $post_type = __('Quote', 'invoicing');
2833 2833
         }
2834 2834
 
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 1 patch
Spacing   +682 added lines, -682 removed lines patch added patch discarded remove patch
@@ -7,109 +7,109 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14
-if ( !is_admin() ) {
15
-    add_filter( 'template_include', 'wpinv_template', 10, 1 );
16
-    add_action( 'wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar' );
17
-    add_action( 'wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions' );
18
-    add_action( 'wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions' );
14
+if (!is_admin()) {
15
+    add_filter('template_include', 'wpinv_template', 10, 1);
16
+    add_action('wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar');
17
+    add_action('wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions');
18
+    add_action('wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions');
19 19
 }
20 20
 
21 21
 function wpinv_template_path() {
22
-    return apply_filters( 'wpinv_template_path', 'invoicing/' );
22
+    return apply_filters('wpinv_template_path', 'invoicing/');
23 23
 }
24 24
 
25
-function wpinv_post_class( $classes, $class, $post_id ) {
25
+function wpinv_post_class($classes, $class, $post_id) {
26 26
     global $pagenow, $typenow;
27 27
 
28
-    if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' ) {
28
+    if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow && get_post_meta($post_id, '_wpinv_type', true) == 'package') {
29 29
         $classes[] = 'wpi-gd-package';
30 30
     }
31 31
     return $classes;
32 32
 }
33
-add_filter( 'post_class', 'wpinv_post_class', 10, 3 );
33
+add_filter('post_class', 'wpinv_post_class', 10, 3);
34 34
 
35
-function wpinv_display_invoice_top_bar( $invoice ) {
36
-    if ( empty( $invoice ) ) {
35
+function wpinv_display_invoice_top_bar($invoice) {
36
+    if (empty($invoice)) {
37 37
         return;
38 38
     }
39 39
     ?>
40 40
     <div class="row wpinv-top-bar no-print">
41 41
         <div class="container">
42 42
             <div class="col-xs-6">
43
-                <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?>
43
+                <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?>
44 44
             </div>
45 45
             <div class="col-xs-6 text-right">
46
-                <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?>
46
+                <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?>
47 47
             </div>
48 48
         </div>
49 49
     </div>
50 50
     <?php
51 51
 }
52 52
 
53
-function wpinv_invoice_display_left_actions( $invoice ) {
54
-    if ( empty( $invoice ) ) {
53
+function wpinv_invoice_display_left_actions($invoice) {
54
+    if (empty($invoice)) {
55 55
         return;
56 56
     }
57 57
     
58
-    if($invoice->post_type == 'wpi_invoice'){
58
+    if ($invoice->post_type == 'wpi_invoice') {
59 59
     
60 60
         $user_id = (int)$invoice->get_user_id();
61 61
         $current_user_id = (int)get_current_user_id();
62 62
 
63
-        if ( $user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment() ) {
63
+        if ($user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment()) {
64 64
             ?> 
65
-            <a class="btn btn-success btn-sm" title="<?php esc_attr_e( 'Pay This Invoice', 'invoicing' ); ?>" href="<?php echo esc_url( $invoice->get_checkout_payment_url() ); ?>"><?php _e( 'Pay For Invoice', 'invoicing' ); ?></a>
65
+            <a class="btn btn-success btn-sm" title="<?php esc_attr_e('Pay This Invoice', 'invoicing'); ?>" href="<?php echo esc_url($invoice->get_checkout_payment_url()); ?>"><?php _e('Pay For Invoice', 'invoicing'); ?></a>
66 66
             <?php
67 67
         }
68 68
     }
69 69
     do_action('wpinv_invoice_display_left_actions', $invoice);
70 70
 }
71 71
 
72
-function wpinv_invoice_display_right_actions( $invoice ) {
73
-    if ( empty( $invoice ) ) return; //Exit if invoice is not set.
72
+function wpinv_invoice_display_right_actions($invoice) {
73
+    if (empty($invoice)) return; //Exit if invoice is not set.
74 74
     
75
-    if($invoice->post_type == 'wpi_invoice'){
75
+    if ($invoice->post_type == 'wpi_invoice') {
76 76
         $user_id = (int)$invoice->get_user_id();
77 77
         $current_user_id = (int)get_current_user_id();
78 78
 
79
-        if ( $user_id > 0 && $user_id == $current_user_id ) {
79
+        if ($user_id > 0 && $user_id == $current_user_id) {
80 80
         ?>
81
-            <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a> &nbsp;
82
-            <a class="btn btn-warning btn-sm" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a>
81
+            <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a> &nbsp;
82
+            <a class="btn btn-warning btn-sm" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a>
83 83
         <?php } 
84 84
     }
85 85
     do_action('wpinv_invoice_display_right_actions', $invoice);
86 86
 }
87 87
 
88
-function wpinv_before_invoice_content( $content ) {
88
+function wpinv_before_invoice_content($content) {
89 89
     global $post;
90 90
 
91
-    if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
91
+    if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
92 92
         ob_start();
93
-        do_action( 'wpinv_before_invoice_content', $post->ID );
93
+        do_action('wpinv_before_invoice_content', $post->ID);
94 94
         $content = ob_get_clean() . $content;
95 95
     }
96 96
 
97 97
     return $content;
98 98
 }
99
-add_filter( 'the_content', 'wpinv_before_invoice_content' );
99
+add_filter('the_content', 'wpinv_before_invoice_content');
100 100
 
101
-function wpinv_after_invoice_content( $content ) {
101
+function wpinv_after_invoice_content($content) {
102 102
     global $post;
103 103
 
104
-    if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
104
+    if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
105 105
         ob_start();
106
-        do_action( 'wpinv_after_invoice_content', $post->ID );
106
+        do_action('wpinv_after_invoice_content', $post->ID);
107 107
         $content .= ob_get_clean();
108 108
     }
109 109
 
110 110
     return $content;
111 111
 }
112
-add_filter( 'the_content', 'wpinv_after_invoice_content' );
112
+add_filter('the_content', 'wpinv_after_invoice_content');
113 113
 
114 114
 function wpinv_get_templates_dir() {
115 115
     return WPINV_PLUGIN_DIR . 'templates';
@@ -119,105 +119,105 @@  discard block
 block discarded – undo
119 119
     return WPINV_PLUGIN_URL . 'templates';
120 120
 }
121 121
 
122
-function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
123
-    if ( ! empty( $args ) && is_array( $args ) ) {
124
-		extract( $args );
122
+function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
123
+    if (!empty($args) && is_array($args)) {
124
+		extract($args);
125 125
 	}
126 126
 
127
-	$located = wpinv_locate_template( $template_name, $template_path, $default_path );
127
+	$located = wpinv_locate_template($template_name, $template_path, $default_path);
128 128
 	// Allow 3rd party plugin filter template file from their plugin.
129
-	$located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path );
129
+	$located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path);
130 130
 
131
-	if ( ! file_exists( $located ) ) {
132
-        _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
131
+	if (!file_exists($located)) {
132
+        _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1');
133 133
 		return;
134 134
 	}
135 135
 
136
-	do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args );
136
+	do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args);
137 137
 
138
-	include( $located );
138
+	include($located);
139 139
 
140
-	do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args );
140
+	do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args);
141 141
 }
142 142
 
143
-function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
143
+function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') {
144 144
 	ob_start();
145
-	wpinv_get_template( $template_name, $args, $template_path, $default_path );
145
+	wpinv_get_template($template_name, $args, $template_path, $default_path);
146 146
 	return ob_get_clean();
147 147
 }
148 148
 
149
-function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
150
-    if ( ! $template_path ) {
149
+function wpinv_locate_template($template_name, $template_path = '', $default_path = '') {
150
+    if (!$template_path) {
151 151
         $template_path = wpinv_template_path();
152 152
     }
153 153
 
154
-    if ( ! $default_path ) {
154
+    if (!$default_path) {
155 155
         $default_path = WPINV_PLUGIN_DIR . 'templates/';
156 156
     }
157 157
 
158 158
     // Look within passed path within the theme - this is priority.
159 159
     $template = locate_template(
160 160
         array(
161
-            trailingslashit( $template_path ) . $template_name,
161
+            trailingslashit($template_path) . $template_name,
162 162
             $template_name
163 163
         )
164 164
     );
165 165
 
166 166
     // Get default templates/
167
-    if ( !$template && $default_path ) {
168
-        $template = trailingslashit( $default_path ) . $template_name;
167
+    if (!$template && $default_path) {
168
+        $template = trailingslashit($default_path) . $template_name;
169 169
     }
170 170
 
171 171
     // Return what we found.
172
-    return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path );
172
+    return apply_filters('wpinv_locate_template', $template, $template_name, $template_path);
173 173
 }
174 174
 
175
-function wpinv_get_template_part( $slug, $name = null, $load = true ) {
176
-	do_action( 'get_template_part_' . $slug, $slug, $name );
175
+function wpinv_get_template_part($slug, $name = null, $load = true) {
176
+	do_action('get_template_part_' . $slug, $slug, $name);
177 177
 
178 178
 	// Setup possible parts
179 179
 	$templates = array();
180
-	if ( isset( $name ) )
180
+	if (isset($name))
181 181
 		$templates[] = $slug . '-' . $name . '.php';
182 182
 	$templates[] = $slug . '.php';
183 183
 
184 184
 	// Allow template parts to be filtered
185
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
185
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
186 186
 
187 187
 	// Return the part that is found
188
-	return wpinv_locate_tmpl( $templates, $load, false );
188
+	return wpinv_locate_tmpl($templates, $load, false);
189 189
 }
190 190
 
191
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
191
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
192 192
 	// No file found yet
193 193
 	$located = false;
194 194
 
195 195
 	// Try to find a template file
196
-	foreach ( (array)$template_names as $template_name ) {
196
+	foreach ((array)$template_names as $template_name) {
197 197
 
198 198
 		// Continue if template is empty
199
-		if ( empty( $template_name ) )
199
+		if (empty($template_name))
200 200
 			continue;
201 201
 
202 202
 		// Trim off any slashes from the template name
203
-		$template_name = ltrim( $template_name, '/' );
203
+		$template_name = ltrim($template_name, '/');
204 204
 
205 205
 		// try locating this template file by looping through the template paths
206
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
206
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
207 207
 
208
-			if( file_exists( $template_path . $template_name ) ) {
208
+			if (file_exists($template_path . $template_name)) {
209 209
 				$located = $template_path . $template_name;
210 210
 				break;
211 211
 			}
212 212
 		}
213 213
 
214
-		if( !empty( $located ) ) {
214
+		if (!empty($located)) {
215 215
 			break;
216 216
 		}
217 217
 	}
218 218
 
219
-	if ( ( true == $load ) && ! empty( $located ) )
220
-		load_template( $located, $require_once );
219
+	if ((true == $load) && !empty($located))
220
+		load_template($located, $require_once);
221 221
 
222 222
 	return $located;
223 223
 }
@@ -226,143 +226,143 @@  discard block
 block discarded – undo
226 226
 	$template_dir = wpinv_get_theme_template_dir_name();
227 227
 
228 228
 	$file_paths = array(
229
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
230
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
229
+		1 => trailingslashit(get_stylesheet_directory()) . $template_dir,
230
+		10 => trailingslashit(get_template_directory()) . $template_dir,
231 231
 		100 => wpinv_get_templates_dir()
232 232
 	);
233 233
 
234
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
234
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
235 235
 
236 236
 	// sort the file paths based on priority
237
-	ksort( $file_paths, SORT_NUMERIC );
237
+	ksort($file_paths, SORT_NUMERIC);
238 238
 
239
-	return array_map( 'trailingslashit', $file_paths );
239
+	return array_map('trailingslashit', $file_paths);
240 240
 }
241 241
 
242 242
 function wpinv_get_theme_template_dir_name() {
243
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'wpinv_templates' ) );
243
+	return trailingslashit(apply_filters('wpinv_templates_dir', 'wpinv_templates'));
244 244
 }
245 245
 
246 246
 function wpinv_checkout_meta_tags() {
247 247
 
248 248
 	$pages   = array();
249
-	$pages[] = wpinv_get_option( 'success_page' );
250
-	$pages[] = wpinv_get_option( 'failure_page' );
251
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
249
+	$pages[] = wpinv_get_option('success_page');
250
+	$pages[] = wpinv_get_option('failure_page');
251
+	$pages[] = wpinv_get_option('invoice_history_page');
252 252
 
253
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
253
+	if (!wpinv_is_checkout() && !is_page($pages)) {
254 254
 		return;
255 255
 	}
256 256
 
257 257
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
258 258
 }
259
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
259
+add_action('wp_head', 'wpinv_checkout_meta_tags');
260 260
 
261
-function wpinv_add_body_classes( $class ) {
261
+function wpinv_add_body_classes($class) {
262 262
 	$classes = (array)$class;
263 263
 
264
-	if( wpinv_is_checkout() ) {
264
+	if (wpinv_is_checkout()) {
265 265
 		$classes[] = 'wpinv-checkout';
266 266
 		$classes[] = 'wpinv-page';
267 267
 	}
268 268
 
269
-	if( wpinv_is_success_page() ) {
269
+	if (wpinv_is_success_page()) {
270 270
 		$classes[] = 'wpinv-success';
271 271
 		$classes[] = 'wpinv-page';
272 272
 	}
273 273
 
274
-	if( wpinv_is_failed_transaction_page() ) {
274
+	if (wpinv_is_failed_transaction_page()) {
275 275
 		$classes[] = 'wpinv-failed-transaction';
276 276
 		$classes[] = 'wpinv-page';
277 277
 	}
278 278
 
279
-	if( wpinv_is_invoice_history_page() ) {
279
+	if (wpinv_is_invoice_history_page()) {
280 280
 		$classes[] = 'wpinv-history';
281 281
 		$classes[] = 'wpinv-page';
282 282
 	}
283 283
 
284
-	if( wpinv_is_test_mode() ) {
284
+	if (wpinv_is_test_mode()) {
285 285
 		$classes[] = 'wpinv-test-mode';
286 286
 		$classes[] = 'wpinv-page';
287 287
 	}
288 288
 
289
-	return array_unique( $classes );
289
+	return array_unique($classes);
290 290
 }
291
-add_filter( 'body_class', 'wpinv_add_body_classes' );
291
+add_filter('body_class', 'wpinv_add_body_classes');
292 292
 
293
-function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) {
294
-    $args = array( 'nopaging' => true );
293
+function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') {
294
+    $args = array('nopaging' => true);
295 295
 
296
-    if ( ! empty( $status ) )
296
+    if (!empty($status))
297 297
         $args['post_status'] = $status;
298 298
 
299
-    $discounts = wpinv_get_discounts( $args );
299
+    $discounts = wpinv_get_discounts($args);
300 300
     $options   = array();
301 301
 
302
-    if ( $discounts ) {
303
-        foreach ( $discounts as $discount ) {
304
-            $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) );
302
+    if ($discounts) {
303
+        foreach ($discounts as $discount) {
304
+            $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID));
305 305
         }
306 306
     } else {
307
-        $options[0] = __( 'No discounts found', 'invoicing' );
307
+        $options[0] = __('No discounts found', 'invoicing');
308 308
     }
309 309
 
310
-    $output = wpinv_html_select( array(
310
+    $output = wpinv_html_select(array(
311 311
         'name'             => $name,
312 312
         'selected'         => $selected,
313 313
         'options'          => $options,
314 314
         'show_option_all'  => false,
315 315
         'show_option_none' => false,
316
-    ) );
316
+    ));
317 317
 
318 318
     return $output;
319 319
 }
320 320
 
321
-function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
322
-    $current     = date( 'Y' );
323
-    $start_year  = $current - absint( $years_before );
324
-    $end_year    = $current + absint( $years_after );
325
-    $selected    = empty( $selected ) ? date( 'Y' ) : $selected;
321
+function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
322
+    $current     = date('Y');
323
+    $start_year  = $current - absint($years_before);
324
+    $end_year    = $current + absint($years_after);
325
+    $selected    = empty($selected) ? date('Y') : $selected;
326 326
     $options     = array();
327 327
 
328
-    while ( $start_year <= $end_year ) {
329
-        $options[ absint( $start_year ) ] = $start_year;
328
+    while ($start_year <= $end_year) {
329
+        $options[absint($start_year)] = $start_year;
330 330
         $start_year++;
331 331
     }
332 332
 
333
-    $output = wpinv_html_select( array(
333
+    $output = wpinv_html_select(array(
334 334
         'name'             => $name,
335 335
         'selected'         => $selected,
336 336
         'options'          => $options,
337 337
         'show_option_all'  => false,
338 338
         'show_option_none' => false
339
-    ) );
339
+    ));
340 340
 
341 341
     return $output;
342 342
 }
343 343
 
344
-function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) {
344
+function wpinv_html_month_dropdown($name = 'month', $selected = 0) {
345 345
     $month   = 1;
346 346
     $options = array();
347
-    $selected = empty( $selected ) ? date( 'n' ) : $selected;
347
+    $selected = empty($selected) ? date('n') : $selected;
348 348
 
349
-    while ( $month <= 12 ) {
350
-        $options[ absint( $month ) ] = wpinv_month_num_to_name( $month );
349
+    while ($month <= 12) {
350
+        $options[absint($month)] = wpinv_month_num_to_name($month);
351 351
         $month++;
352 352
     }
353 353
 
354
-    $output = wpinv_html_select( array(
354
+    $output = wpinv_html_select(array(
355 355
         'name'             => $name,
356 356
         'selected'         => $selected,
357 357
         'options'          => $options,
358 358
         'show_option_all'  => false,
359 359
         'show_option_none' => false
360
-    ) );
360
+    ));
361 361
 
362 362
     return $output;
363 363
 }
364 364
 
365
-function wpinv_html_select( $args = array() ) {
365
+function wpinv_html_select($args = array()) {
366 366
     $defaults = array(
367 367
         'options'          => array(),
368 368
         'name'             => null,
@@ -372,8 +372,8 @@  discard block
 block discarded – undo
372 372
         'chosen'           => false,
373 373
         'placeholder'      => null,
374 374
         'multiple'         => false,
375
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
376
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
375
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
376
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
377 377
         'data'             => array(),
378 378
         'onchange'         => null,
379 379
         'required'         => false,
@@ -381,78 +381,78 @@  discard block
 block discarded – undo
381 381
         'readonly'         => false,
382 382
     );
383 383
 
384
-    $args = wp_parse_args( $args, $defaults );
384
+    $args = wp_parse_args($args, $defaults);
385 385
 
386 386
     $data_elements = '';
387
-    foreach ( $args['data'] as $key => $value ) {
388
-        $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
387
+    foreach ($args['data'] as $key => $value) {
388
+        $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
389 389
     }
390 390
 
391
-    if( $args['multiple'] ) {
391
+    if ($args['multiple']) {
392 392
         $multiple = ' MULTIPLE';
393 393
     } else {
394 394
         $multiple = '';
395 395
     }
396 396
 
397
-    if( $args['chosen'] ) {
397
+    if ($args['chosen']) {
398 398
         $args['class'] .= ' wpinv-select-chosen';
399 399
     }
400 400
 
401
-    if( $args['placeholder'] ) {
401
+    if ($args['placeholder']) {
402 402
         $placeholder = $args['placeholder'];
403 403
     } else {
404 404
         $placeholder = '';
405 405
     }
406 406
     
407 407
     $options = '';
408
-    if( !empty( $args['onchange'] ) ) {
409
-        $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"';
408
+    if (!empty($args['onchange'])) {
409
+        $options .= ' onchange="' . esc_attr($args['onchange']) . '"';
410 410
     }
411 411
     
412
-    if( !empty( $args['required'] ) ) {
412
+    if (!empty($args['required'])) {
413 413
         $options .= ' required="required"';
414 414
     }
415 415
     
416
-    if( !empty( $args['disabled'] ) ) {
416
+    if (!empty($args['disabled'])) {
417 417
         $options .= ' disabled';
418 418
     }
419 419
     
420
-    if( !empty( $args['readonly'] ) ) {
420
+    if (!empty($args['readonly'])) {
421 421
         $options .= ' readonly';
422 422
     }
423 423
 
424
-    $class  = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
425
-    $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>';
424
+    $class  = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
425
+    $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>';
426 426
 
427
-    if ( $args['show_option_all'] ) {
428
-        if( $args['multiple'] ) {
429
-            $selected = selected( true, in_array( 0, $args['selected'] ), false );
427
+    if ($args['show_option_all']) {
428
+        if ($args['multiple']) {
429
+            $selected = selected(true, in_array(0, $args['selected']), false);
430 430
         } else {
431
-            $selected = selected( $args['selected'], 0, false );
431
+            $selected = selected($args['selected'], 0, false);
432 432
         }
433
-        $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
433
+        $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>';
434 434
     }
435 435
 
436
-    if ( !empty( $args['options'] ) ) {
436
+    if (!empty($args['options'])) {
437 437
 
438
-        if ( $args['show_option_none'] ) {
439
-            if( $args['multiple'] ) {
440
-                $selected = selected( true, in_array( "", $args['selected'] ), false );
438
+        if ($args['show_option_none']) {
439
+            if ($args['multiple']) {
440
+                $selected = selected(true, in_array("", $args['selected']), false);
441 441
             } else {
442
-                $selected = selected( $args['selected'] === "", true, false );
442
+                $selected = selected($args['selected'] === "", true, false);
443 443
             }
444
-            $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
444
+            $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>';
445 445
         }
446 446
 
447
-        foreach( $args['options'] as $key => $option ) {
447
+        foreach ($args['options'] as $key => $option) {
448 448
 
449
-            if( $args['multiple'] && is_array( $args['selected'] ) ) {
450
-                $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false );
449
+            if ($args['multiple'] && is_array($args['selected'])) {
450
+                $selected = selected(true, (bool)in_array($key, $args['selected']), false);
451 451
             } else {
452
-                $selected = selected( $args['selected'], $key, false );
452
+                $selected = selected($args['selected'], $key, false);
453 453
             }
454 454
 
455
-            $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
455
+            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>';
456 456
         }
457 457
     }
458 458
 
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
     return $output;
462 462
 }
463 463
 
464
-function wpinv_item_dropdown( $args = array() ) {
464
+function wpinv_item_dropdown($args = array()) {
465 465
     $defaults = array(
466 466
         'name'              => 'wpi_item',
467 467
         'id'                => 'wpi_item',
@@ -470,15 +470,15 @@  discard block
 block discarded – undo
470 470
         'selected'          => 0,
471 471
         'chosen'            => false,
472 472
         'number'            => 100,
473
-        'placeholder'       => __( 'Choose a item', 'invoicing' ),
474
-        'data'              => array( 'search-type' => 'item' ),
473
+        'placeholder'       => __('Choose a item', 'invoicing'),
474
+        'data'              => array('search-type' => 'item'),
475 475
         'show_option_all'   => false,
476 476
         'show_option_none'  => false,
477 477
         'with_packages'     => true,
478 478
         'show_recurring'    => false,
479 479
     );
480 480
 
481
-    $args = wp_parse_args( $args, $defaults );
481
+    $args = wp_parse_args($args, $defaults);
482 482
 
483 483
     $item_args = array(
484 484
         'post_type'      => 'wpi_item',
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
         'posts_per_page' => $args['number']
488 488
     );
489 489
     
490
-    if ( !$args['with_packages'] ) {
490
+    if (!$args['with_packages']) {
491 491
         $item_args['meta_query'] = array(
492 492
             array(
493 493
                 'key'       => '_wpinv_type',
@@ -497,42 +497,42 @@  discard block
 block discarded – undo
497 497
         );
498 498
     }
499 499
 
500
-    $items      = get_posts( $item_args );
500
+    $items      = get_posts($item_args);
501 501
     $options    = array();
502
-    if ( $items ) {
503
-        foreach ( $items as $item ) {
504
-            $title = esc_html( $item->post_title );
502
+    if ($items) {
503
+        foreach ($items as $item) {
504
+            $title = esc_html($item->post_title);
505 505
             
506
-            if ( !empty( $args['show_recurring'] ) ) {
507
-                $title .= wpinv_get_item_suffix( $item->ID, false );
506
+            if (!empty($args['show_recurring'])) {
507
+                $title .= wpinv_get_item_suffix($item->ID, false);
508 508
             }
509 509
             
510
-            $options[ absint( $item->ID ) ] = $title;
510
+            $options[absint($item->ID)] = $title;
511 511
         }
512 512
     }
513 513
 
514 514
     // This ensures that any selected items are included in the drop down
515
-    if( is_array( $args['selected'] ) ) {
516
-        foreach( $args['selected'] as $item ) {
517
-            if( ! in_array( $item, $options ) ) {
518
-                $title = get_the_title( $item );
519
-                if ( !empty( $args['show_recurring'] ) ) {
520
-                    $title .= wpinv_get_item_suffix( $item, false );
515
+    if (is_array($args['selected'])) {
516
+        foreach ($args['selected'] as $item) {
517
+            if (!in_array($item, $options)) {
518
+                $title = get_the_title($item);
519
+                if (!empty($args['show_recurring'])) {
520
+                    $title .= wpinv_get_item_suffix($item, false);
521 521
                 }
522 522
                 $options[$item] = $title;
523 523
             }
524 524
         }
525
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
526
-        if ( ! in_array( $args['selected'], $options ) ) {
527
-            $title = get_the_title( $args['selected'] );
528
-            if ( !empty( $args['show_recurring'] ) ) {
529
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
525
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
526
+        if (!in_array($args['selected'], $options)) {
527
+            $title = get_the_title($args['selected']);
528
+            if (!empty($args['show_recurring'])) {
529
+                $title .= wpinv_get_item_suffix($args['selected'], false);
530 530
             }
531
-            $options[$args['selected']] = get_the_title( $args['selected'] );
531
+            $options[$args['selected']] = get_the_title($args['selected']);
532 532
         }
533 533
     }
534 534
 
535
-    $output = wpinv_html_select( array(
535
+    $output = wpinv_html_select(array(
536 536
         'name'             => $args['name'],
537 537
         'selected'         => $args['selected'],
538 538
         'id'               => $args['id'],
@@ -544,12 +544,12 @@  discard block
 block discarded – undo
544 544
         'show_option_all'  => $args['show_option_all'],
545 545
         'show_option_none' => $args['show_option_none'],
546 546
         'data'             => $args['data'],
547
-    ) );
547
+    ));
548 548
 
549 549
     return $output;
550 550
 }
551 551
 
552
-function wpinv_html_checkbox( $args = array() ) {
552
+function wpinv_html_checkbox($args = array()) {
553 553
     $defaults = array(
554 554
         'name'     => null,
555 555
         'current'  => null,
@@ -560,38 +560,38 @@  discard block
 block discarded – undo
560 560
         )
561 561
     );
562 562
 
563
-    $args = wp_parse_args( $args, $defaults );
563
+    $args = wp_parse_args($args, $defaults);
564 564
 
565
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
565
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
566 566
     $options = '';
567
-    if ( ! empty( $args['options']['disabled'] ) ) {
567
+    if (!empty($args['options']['disabled'])) {
568 568
         $options .= ' disabled="disabled"';
569
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
569
+    } elseif (!empty($args['options']['readonly'])) {
570 570
         $options .= ' readonly';
571 571
     }
572 572
 
573
-    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />';
573
+    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />';
574 574
 
575 575
     return $output;
576 576
 }
577 577
 
578
-function wpinv_html_text( $args = array() ) {
578
+function wpinv_html_text($args = array()) {
579 579
     // Backwards compatibility
580
-    if ( func_num_args() > 1 ) {
580
+    if (func_num_args() > 1) {
581 581
         $args = func_get_args();
582 582
 
583 583
         $name  = $args[0];
584
-        $value = isset( $args[1] ) ? $args[1] : '';
585
-        $label = isset( $args[2] ) ? $args[2] : '';
586
-        $desc  = isset( $args[3] ) ? $args[3] : '';
584
+        $value = isset($args[1]) ? $args[1] : '';
585
+        $label = isset($args[2]) ? $args[2] : '';
586
+        $desc  = isset($args[3]) ? $args[3] : '';
587 587
     }
588 588
 
589 589
     $defaults = array(
590 590
         'id'           => '',
591
-        'name'         => isset( $name )  ? $name  : 'text',
592
-        'value'        => isset( $value ) ? $value : null,
593
-        'label'        => isset( $label ) ? $label : null,
594
-        'desc'         => isset( $desc )  ? $desc  : null,
591
+        'name'         => isset($name) ? $name : 'text',
592
+        'value'        => isset($value) ? $value : null,
593
+        'label'        => isset($label) ? $label : null,
594
+        'desc'         => isset($desc) ? $desc : null,
595 595
         'placeholder'  => '',
596 596
         'class'        => 'regular-text',
597 597
         'disabled'     => false,
@@ -601,51 +601,51 @@  discard block
 block discarded – undo
601 601
         'data'         => false
602 602
     );
603 603
 
604
-    $args = wp_parse_args( $args, $defaults );
604
+    $args = wp_parse_args($args, $defaults);
605 605
 
606
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
606
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
607 607
     $options = '';
608
-    if( $args['required'] ) {
608
+    if ($args['required']) {
609 609
         $options .= ' required="required"';
610 610
     }
611
-    if( $args['readonly'] ) {
611
+    if ($args['readonly']) {
612 612
         $options .= ' readonly';
613 613
     }
614
-    if( $args['readonly'] ) {
614
+    if ($args['readonly']) {
615 615
         $options .= ' readonly';
616 616
     }
617 617
 
618 618
     $data = '';
619
-    if ( !empty( $args['data'] ) ) {
620
-        foreach ( $args['data'] as $key => $value ) {
621
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
619
+    if (!empty($args['data'])) {
620
+        foreach ($args['data'] as $key => $value) {
621
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
622 622
         }
623 623
     }
624 624
 
625
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
626
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
627
-    if ( ! empty( $args['desc'] ) ) {
628
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
625
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
626
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
627
+    if (!empty($args['desc'])) {
628
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
629 629
     }
630 630
 
631
-    $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] )  . '" autocomplete="' . esc_attr( $args['autocomplete'] )  . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>';
631
+    $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>';
632 632
 
633 633
     $output .= '</span>';
634 634
 
635 635
     return $output;
636 636
 }
637 637
 
638
-function wpinv_html_date_field( $args = array() ) {
639
-    if( empty( $args['class'] ) ) {
638
+function wpinv_html_date_field($args = array()) {
639
+    if (empty($args['class'])) {
640 640
         $args['class'] = 'wpiDatepicker';
641
-    } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) {
641
+    } elseif (!strpos($args['class'], 'wpiDatepicker')) {
642 642
         $args['class'] .= ' wpiDatepicker';
643 643
     }
644 644
 
645
-    return wpinv_html_text( $args );
645
+    return wpinv_html_text($args);
646 646
 }
647 647
 
648
-function wpinv_html_textarea( $args = array() ) {
648
+function wpinv_html_textarea($args = array()) {
649 649
     $defaults = array(
650 650
         'name'        => 'textarea',
651 651
         'value'       => null,
@@ -655,31 +655,31 @@  discard block
 block discarded – undo
655 655
         'disabled'    => false
656 656
     );
657 657
 
658
-    $args = wp_parse_args( $args, $defaults );
658
+    $args = wp_parse_args($args, $defaults);
659 659
 
660
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
660
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
661 661
     $disabled = '';
662
-    if( $args['disabled'] ) {
662
+    if ($args['disabled']) {
663 663
         $disabled = ' disabled="disabled"';
664 664
     }
665 665
 
666
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
667
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
668
-    $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
666
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
667
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
668
+    $output .= '<textarea name="' . esc_attr($args['name']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>';
669 669
 
670
-    if ( ! empty( $args['desc'] ) ) {
671
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
670
+    if (!empty($args['desc'])) {
671
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
672 672
     }
673 673
     $output .= '</span>';
674 674
 
675 675
     return $output;
676 676
 }
677 677
 
678
-function wpinv_html_ajax_user_search( $args = array() ) {
678
+function wpinv_html_ajax_user_search($args = array()) {
679 679
     $defaults = array(
680 680
         'name'        => 'user_id',
681 681
         'value'       => null,
682
-        'placeholder' => __( 'Enter username', 'invoicing' ),
682
+        'placeholder' => __('Enter username', 'invoicing'),
683 683
         'label'       => null,
684 684
         'desc'        => null,
685 685
         'class'       => '',
@@ -688,13 +688,13 @@  discard block
 block discarded – undo
688 688
         'data'        => false
689 689
     );
690 690
 
691
-    $args = wp_parse_args( $args, $defaults );
691
+    $args = wp_parse_args($args, $defaults);
692 692
 
693 693
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
694 694
 
695 695
     $output  = '<span class="wpinv_user_search_wrap">';
696
-        $output .= wpinv_html_text( $args );
697
-        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>';
696
+        $output .= wpinv_html_text($args);
697
+        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>';
698 698
     $output .= '</span>';
699 699
 
700 700
     return $output;
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
 function wpinv_ip_geolocation() {
704 704
     global $wpinv_euvat;
705 705
     
706
-    $ip         = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : '';    
706
+    $ip         = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : '';    
707 707
     $content    = '';
708 708
     $iso        = '';
709 709
     $country    = '';
@@ -714,69 +714,69 @@  discard block
 block discarded – undo
714 714
     $credit     = '';
715 715
     $address    = '';
716 716
     
717
-    if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) {
717
+    if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) {
718 718
         try {
719 719
             $iso        = $geoip2_city->country->isoCode;
720 720
             $country    = $geoip2_city->country->name;
721
-            $region     = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : '';
721
+            $region     = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : '';
722 722
             $city       = $geoip2_city->city->name;
723 723
             $longitude  = $geoip2_city->location->longitude;
724 724
             $latitude   = $geoip2_city->location->latitude;
725
-            $credit     = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' );
726
-        } catch( Exception $e ) { }
725
+            $credit     = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing');
726
+        } catch (Exception $e) { }
727 727
     }
728 728
     
729
-    if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) {
729
+    if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) {
730 730
         try {
731
-            $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
731
+            $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
732 732
             
733
-            if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) {
733
+            if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) {
734 734
                 $iso        = $load_xml->geoplugin_countryCode;
735 735
                 $country    = $load_xml->geoplugin_countryName;
736
-                $region     = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : '';
737
-                $city       = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : '';
736
+                $region     = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : '';
737
+                $city       = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : '';
738 738
                 $longitude  = $load_xml->geoplugin_longitude;
739 739
                 $latitude   = $load_xml->geoplugin_latitude;
740 740
                 $credit     = $load_xml->geoplugin_credit;
741
-                $credit     = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit;
741
+                $credit     = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit;
742 742
             }
743
-        } catch( Exception $e ) { }
743
+        } catch (Exception $e) { }
744 744
     }
745 745
     
746
-    if ( $iso && $longitude && $latitude ) {
747
-        if ( $city ) {
746
+    if ($iso && $longitude && $latitude) {
747
+        if ($city) {
748 748
             $address .= $city . ', ';
749 749
         }
750 750
         
751
-        if ( $region ) {
751
+        if ($region) {
752 752
             $address .= $region . ', ';
753 753
         }
754 754
         
755 755
         $address .= $country . ' (' . $iso . ')';
756
-        $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>';
757
-        $content .= '<p>'. $credit . '</p>';
756
+        $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>';
757
+        $content .= '<p>' . $credit . '</p>';
758 758
     } else {
759
-        $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>';
759
+        $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>';
760 760
     }
761 761
     ?>
762 762
 <!DOCTYPE html>
763
-<html><head><title><?php echo sprintf( __( 'IP: %s', 'invoicing' ), $ip );?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
763
+<html><head><title><?php echo sprintf(__('IP: %s', 'invoicing'), $ip); ?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
764 764
 <body>
765
-    <?php if ( $latitude && $latitude ) { ?>
765
+    <?php if ($latitude && $latitude) { ?>
766 766
     <div id="map"></div>
767 767
         <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script>
768 768
         <script type="text/javascript">
769 769
         var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
770 770
             osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
771 771
             osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}),
772
-            latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>);
772
+            latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>);
773 773
 
774 774
         var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]});
775 775
 
776 776
         var marker = new L.Marker(latlng);
777 777
         map.addLayer(marker);
778 778
 
779
-        marker.bindPopup("<p><?php esc_attr_e( $address );?></p>");
779
+        marker.bindPopup("<p><?php esc_attr_e($address); ?></p>");
780 780
     </script>
781 781
     <?php } ?>
782 782
     <div style="height:100px"><?php echo $content; ?></div>
@@ -784,31 +784,31 @@  discard block
 block discarded – undo
784 784
 <?php
785 785
     exit;
786 786
 }
787
-add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
788
-add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
787
+add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
788
+add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
789 789
 
790 790
 // Set up the template for the invoice.
791
-function wpinv_template( $template ) {
791
+function wpinv_template($template) {
792 792
     global $post, $wp_query;
793 793
     
794
-    if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) {
795
-        if ( wpinv_user_can_print_invoice( $post->ID ) ) {
796
-            $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false );
794
+    if ((is_single() || is_404()) && !empty($post->ID) && (get_post_type($post->ID) == 'wpi_invoice' or get_post_type($post->ID) == 'wpi_quote')) {
795
+        if (wpinv_user_can_print_invoice($post->ID)) {
796
+            $template = wpinv_get_template_part('wpinv-invoice-print', false, false);
797 797
         } else {
798
-            if ( !is_user_logged_in() && !empty( $_REQUEST['_wpipay'] ) && $invoice = wpinv_get_invoice( $post->ID ) ) {
798
+            if (!is_user_logged_in() && !empty($_REQUEST['_wpipay']) && $invoice = wpinv_get_invoice($post->ID)) {
799 799
                 $user_id = $invoice->get_user_id();
800
-                $secret = sanitize_text_field( $_GET['_wpipay'] );
800
+                $secret = sanitize_text_field($_GET['_wpipay']);
801 801
 
802
-                if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key() ) ) { // valid invoice link
803
-                    $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
802
+                if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key())) { // valid invoice link
803
+                    $redirect_to = remove_query_arg('_wpipay', get_permalink());
804 804
 
805
-                    wpinv_guest_redirect( $redirect_to, $user_id );
805
+                    wpinv_guest_redirect($redirect_to, $user_id);
806 806
                     wpinv_die();
807 807
                 }
808 808
             }
809
-            $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
809
+            $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
810 810
 
811
-            wp_redirect( $redirect_to );
811
+            wp_redirect($redirect_to);
812 812
             wpinv_die();
813 813
         }
814 814
     }
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
 
819 819
 function wpinv_get_business_address() {
820 820
     $business_address   = wpinv_store_address();
821
-    $business_address   = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
821
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
822 822
     
823 823
     /*
824 824
     $default_country    = wpinv_get_default_country();
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
     
843 843
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
844 844
     
845
-    return apply_filters( 'wpinv_get_business_address', $business_address );
845
+    return apply_filters('wpinv_get_business_address', $business_address);
846 846
 }
847 847
 
848 848
 function wpinv_display_from_address() {
@@ -852,185 +852,185 @@  discard block
 block discarded – undo
852 852
     if (empty($from_name)) {
853 853
         $from_name = wpinv_get_business_name();
854 854
     }
855
-    ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div>
855
+    ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div>
856 856
     <div class="wrapper col-xs-10">
857
-        <div class="name"><?php echo esc_html( $from_name ); ?></div>
858
-        <?php if ( $address = wpinv_get_business_address() ) { ?>
859
-        <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div>
857
+        <div class="name"><?php echo esc_html($from_name); ?></div>
858
+        <?php if ($address = wpinv_get_business_address()) { ?>
859
+        <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div>
860 860
         <?php } ?>
861
-        <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?>
862
-        <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s' ), $email_from );?></div>
861
+        <?php if ($email_from = wpinv_mail_get_from_address()) { ?>
862
+        <div class="email_from"><?php echo wp_sprintf(__('Email: %s'), $email_from); ?></div>
863 863
         <?php } ?>
864 864
     </div>
865 865
     <?php
866 866
 }
867 867
 
868
-function wpinv_watermark( $id = 0 ) {
869
-    $output = wpinv_get_watermark( $id );
868
+function wpinv_watermark($id = 0) {
869
+    $output = wpinv_get_watermark($id);
870 870
     
871
-    return apply_filters( 'wpinv_get_watermark', $output, $id );
871
+    return apply_filters('wpinv_get_watermark', $output, $id);
872 872
 }
873 873
 
874
-function wpinv_get_watermark( $id ) {
875
-    if ( !$id > 0 ) {
874
+function wpinv_get_watermark($id) {
875
+    if (!$id > 0) {
876 876
         return NULL;
877 877
     }
878
-    $invoice = wpinv_get_invoice( $id );
878
+    $invoice = wpinv_get_invoice($id);
879 879
     
880
-    if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) {
881
-        if ( $invoice->is_paid() ) {
882
-            return __( 'Paid', 'invoicing' );
880
+    if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) {
881
+        if ($invoice->is_paid()) {
882
+            return __('Paid', 'invoicing');
883 883
         }
884
-        if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) {
885
-            return __( 'Cancelled', 'invoicing' );
884
+        if ($invoice->has_status(array('wpi-cancelled'))) {
885
+            return __('Cancelled', 'invoicing');
886 886
         }
887 887
     }
888 888
     
889 889
     return NULL;
890 890
 }
891 891
 
892
-function wpinv_display_invoice_details( $invoice ) {
892
+function wpinv_display_invoice_details($invoice) {
893 893
     global $wpinv_euvat;
894 894
     
895 895
     $invoice_id = $invoice->ID;
896 896
     $vat_name   = $wpinv_euvat->get_vat_name();
897 897
     $use_taxes  = wpinv_use_taxes();
898 898
     
899
-    $invoice_status = wpinv_get_invoice_status( $invoice_id );
899
+    $invoice_status = wpinv_get_invoice_status($invoice_id);
900 900
     
901
-    if($invoice->post_type == 'wpi_invoice') $type = 'Invoice';
902
-    elseif($invoice->post_type == 'wpi_quote') $type = 'Quote';
901
+    if ($invoice->post_type == 'wpi_invoice') $type = 'Invoice';
902
+    elseif ($invoice->post_type == 'wpi_quote') $type = 'Quote';
903 903
     ?>
904 904
     <table class="table table-bordered table-sm">
905
-        <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?>
905
+        <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?>
906 906
             <tr class="wpi-row-number">
907
-                <th><?php echo sprintf(__( '%s Number', 'invoicing' ), $type); ?></th>
908
-                <td><?php echo esc_html( $invoice_number ); ?></td>
907
+                <th><?php echo sprintf(__('%s Number', 'invoicing'), $type); ?></th>
908
+                <td><?php echo esc_html($invoice_number); ?></td>
909 909
             </tr>
910 910
         <?php } ?>
911 911
         <tr class="wpi-row-status">
912
-            <th><?php echo wp_sprintf(__( '%s Status', 'invoicing' ), $type); ?></th>
913
-            <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td>
912
+            <th><?php echo wp_sprintf(__('%s Status', 'invoicing'), $type); ?></th>
913
+            <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td>
914 914
         </tr>
915
-        <?php if ( $invoice->is_renewal() ) { ?>
915
+        <?php if ($invoice->is_renewal()) { ?>
916 916
         <tr class="wpi-row-parent">
917
-            <th><?php echo wp_sprintf(__( 'Parent %s', 'invoicing' ), $type); ?></th>
918
-            <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td>
917
+            <th><?php echo wp_sprintf(__('Parent %s', 'invoicing'), $type); ?></th>
918
+            <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td>
919 919
         </tr>
920 920
         <?php } ?>
921 921
         <tr class="wpi-row-gateway">
922
-            <th><?php _e( 'Payment Method', 'invoicing' ); ?></th>
923
-            <td><?php echo wpinv_get_payment_gateway_name( $invoice_id ); ?></td>
922
+            <th><?php _e('Payment Method', 'invoicing'); ?></th>
923
+            <td><?php echo wpinv_get_payment_gateway_name($invoice_id); ?></td>
924 924
         </tr>
925
-        <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?>
925
+        <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?>
926 926
             <tr class="wpi-row-date">
927
-                <th><?php echo wp_sprintf(__( '%s Date', 'invoicing' ), $type); ?></th>
927
+                <th><?php echo wp_sprintf(__('%s Date', 'invoicing'), $type); ?></th>
928 928
                 <td><?php echo $invoice_date; ?></td>
929 929
             </tr>
930 930
         <?php } ?>
931
-        <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?>
931
+        <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?>
932 932
             <tr class="wpi-row-date">
933
-                <th><?php _e( 'Due Date', 'invoicing' ); ?></th>
933
+                <th><?php _e('Due Date', 'invoicing'); ?></th>
934 934
                 <td><?php echo $due_date; ?></td>
935 935
             </tr>
936 936
         <?php } ?>
937
-        <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?>
937
+        <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?>
938 938
             <tr class="wpi-row-ovatno">
939
-                <th><?php echo wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ); ?></th>
939
+                <th><?php echo wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name); ?></th>
940 940
                 <td><?php echo $owner_vat_number; ?></td>
941 941
             </tr>
942 942
         <?php } ?>
943
-        <?php if ( $use_taxes && $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) { ?>
943
+        <?php if ($use_taxes && $user_vat_number = wpinv_get_invoice_vat_number($invoice_id)) { ?>
944 944
             <tr class="wpi-row-uvatno">
945
-                <th><?php echo wp_sprintf( __( 'Your %s Number', 'invoicing' ), $vat_name ); ?></th>
945
+                <th><?php echo wp_sprintf(__('Your %s Number', 'invoicing'), $vat_name); ?></th>
946 946
                 <td><?php echo $user_vat_number; ?></td>
947 947
             </tr>
948 948
         <?php } ?>
949 949
         <tr class="table-active tr-total wpi-row-total">
950
-            <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th>
951
-            <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td>
950
+            <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th>
951
+            <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td>
952 952
         </tr>
953 953
     </table>
954 954
 <?php
955 955
 }
956 956
 
957
-function wpinv_display_to_address( $invoice_id = 0 ) {
958
-    $invoice = wpinv_get_invoice( $invoice_id );
957
+function wpinv_display_to_address($invoice_id = 0) {
958
+    $invoice = wpinv_get_invoice($invoice_id);
959 959
     
960
-    if ( empty( $invoice ) ) {
960
+    if (empty($invoice)) {
961 961
         return NULL;
962 962
     }
963 963
     
964 964
     $billing_details = $invoice->get_user_info();
965
-    $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>';
965
+    $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>';
966 966
     $output .= '<div class="wrapper col-xs-10">';
967 967
     
968 968
     ob_start();
969
-    do_action( 'wpinv_display_to_address_top', $invoice );
969
+    do_action('wpinv_display_to_address_top', $invoice);
970 970
     $output .= ob_get_clean();
971 971
     
972
-    $output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>';
973
-    if ( $company = $billing_details['company'] ) {
974
-        $output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>';
972
+    $output .= '<div class="name">' . esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])) . '</div>';
973
+    if ($company = $billing_details['company']) {
974
+        $output .= '<div class="company">' . wpautop(wp_kses_post($company)) . '</div>';
975 975
     }
976 976
     $address_row = '';
977
-    if ( $address = $billing_details['address'] ) {
978
-        $address_row .= wpautop( wp_kses_post( $address ) );
977
+    if ($address = $billing_details['address']) {
978
+        $address_row .= wpautop(wp_kses_post($address));
979 979
     }
980 980
     
981 981
     $address_fields = array();
982
-    if ( !empty( $billing_details['city'] ) ) {
982
+    if (!empty($billing_details['city'])) {
983 983
         $address_fields[] = $billing_details['city'];
984 984
     }
985 985
     
986
-    $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : '';
987
-    if ( !empty( $billing_details['state'] ) ) {
988
-        $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country );
986
+    $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : '';
987
+    if (!empty($billing_details['state'])) {
988
+        $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country);
989 989
     }
990 990
     
991
-    if ( !empty( $billing_country ) ) {
992
-        $address_fields[] = wpinv_country_name( $billing_country );
991
+    if (!empty($billing_country)) {
992
+        $address_fields[] = wpinv_country_name($billing_country);
993 993
     }
994 994
     
995
-    if ( !empty( $address_fields ) ) {
996
-        $address_fields = implode( ", ", $address_fields );
995
+    if (!empty($address_fields)) {
996
+        $address_fields = implode(", ", $address_fields);
997 997
         
998
-        if ( !empty( $billing_details['zip'] ) ) {
998
+        if (!empty($billing_details['zip'])) {
999 999
             $address_fields .= ' ' . $billing_details['zip'];
1000 1000
         }
1001 1001
         
1002
-        $address_row .= wpautop( wp_kses_post( $address_fields ) );
1002
+        $address_row .= wpautop(wp_kses_post($address_fields));
1003 1003
     }
1004 1004
     
1005
-    if ( $address_row ) {
1005
+    if ($address_row) {
1006 1006
         $output .= '<div class="address">' . $address_row . '</div>';
1007 1007
     }
1008 1008
     
1009
-    if ( $phone = $invoice->get_phone() ) {
1010
-        $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s' ), esc_html( $phone ) ) . '</div>';
1009
+    if ($phone = $invoice->get_phone()) {
1010
+        $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s'), esc_html($phone)) . '</div>';
1011 1011
     }
1012
-    if ( $email = $invoice->get_email() ) {
1013
-        $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' ), esc_html( $email ) ) . '</div>';
1012
+    if ($email = $invoice->get_email()) {
1013
+        $output .= '<div class="email">' . wp_sprintf(__('Email: %s'), esc_html($email)) . '</div>';
1014 1014
     }
1015 1015
     
1016 1016
     ob_start();
1017
-    do_action( 'wpinv_display_to_address_bottom', $invoice );
1017
+    do_action('wpinv_display_to_address_bottom', $invoice);
1018 1018
     $output .= ob_get_clean();
1019 1019
     
1020 1020
     $output .= '</div>';
1021
-    $output = apply_filters( 'wpinv_display_to_address', $output, $invoice );
1021
+    $output = apply_filters('wpinv_display_to_address', $output, $invoice);
1022 1022
 
1023 1023
     echo $output;
1024 1024
 }
1025 1025
 
1026
-function wpinv_display_line_items( $invoice_id = 0 ) {
1026
+function wpinv_display_line_items($invoice_id = 0) {
1027 1027
     global $wpinv_euvat, $ajax_cart_details;
1028
-    $invoice            = wpinv_get_invoice( $invoice_id );
1028
+    $invoice            = wpinv_get_invoice($invoice_id);
1029 1029
     $quantities_enabled = wpinv_item_quantities_enabled();
1030 1030
     $use_taxes          = wpinv_use_taxes();
1031 1031
     $zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
1032
-    $tax_label           = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' );
1033
-    $tax_title          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
1032
+    $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing');
1033
+    $tax_title          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
1034 1034
     
1035 1035
     $cart_details       = $invoice->get_cart_details();
1036 1036
     $ajax_cart_details  = $cart_details;
@@ -1039,68 +1039,68 @@  discard block
 block discarded – undo
1039 1039
     <table class="table table-sm table-bordered table-responsive">
1040 1040
         <thead>
1041 1041
             <tr>
1042
-                <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th>
1043
-                <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th>
1042
+                <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th>
1043
+                <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th>
1044 1044
                 <?php if ($quantities_enabled) { ?>
1045
-                    <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th>
1045
+                    <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th>
1046 1046
                 <?php } ?>
1047 1047
                 <?php if ($use_taxes && !$zero_tax) { ?>
1048 1048
                     <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th>
1049 1049
                 <?php } ?>
1050
-                <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th>
1050
+                <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th>
1051 1051
             </tr>
1052 1052
         </thead>
1053 1053
         <tbody>
1054 1054
         <?php 
1055
-            if ( !empty( $cart_details ) ) {
1056
-                do_action( 'wpinv_display_line_items_start', $invoice );
1055
+            if (!empty($cart_details)) {
1056
+                do_action('wpinv_display_line_items_start', $invoice);
1057 1057
                 
1058 1058
                 $count = 0;
1059 1059
                 $cols  = 3;
1060
-                foreach ( $cart_details as $key => $cart_item ) {
1061
-                    $item_id    = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : '';
1062
-                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount( $cart_item["item_price"] ) : 0;
1063
-                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount( $cart_item["subtotal"] ) : 0;
1064
-                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1;
1060
+                foreach ($cart_details as $key => $cart_item) {
1061
+                    $item_id    = !empty($cart_item['id']) ? absint($cart_item['id']) : '';
1062
+                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount($cart_item["item_price"]) : 0;
1063
+                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount($cart_item["subtotal"]) : 0;
1064
+                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1;
1065 1065
                     
1066
-                    $item       = $item_id ? new WPInv_Item( $item_id ) : NULL;
1066
+                    $item       = $item_id ? new WPInv_Item($item_id) : NULL;
1067 1067
                     $summary    = '';
1068 1068
                     $cols       = 3;
1069
-                    if ( !empty($item) ) {
1069
+                    if (!empty($item)) {
1070 1070
                         $item_name  = $item->get_name();
1071 1071
                         $summary    = $item->get_summary();
1072 1072
                     }
1073
-                    $item_name  = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1073
+                    $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1074 1074
                     
1075 1075
                     if (!empty($item) && $item->is_package() && !empty($cart_item['meta']['post_id'])) {
1076
-                        $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>';
1077
-                        $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $item->get_custom_singular_name(), $post_link );
1076
+                        $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>';
1077
+                        $summary = wp_sprintf(__('%s: %s', 'invoicing'), $item->get_custom_singular_name(), $post_link);
1078 1078
                     }
1079
-                    $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice );
1079
+                    $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice);
1080 1080
                     
1081 1081
                     $item_tax       = '';
1082 1082
                     $tax_rate       = '';
1083
-                    if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1084
-                        $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) );
1085
-                        $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1086
-                        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1083
+                    if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1084
+                        $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']));
1085
+                        $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1086
+                        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
1087 1087
                         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : '';
1088 1088
                     }
1089 1089
                     
1090 1090
                     $line_item_tax = $item_tax . $tax_rate;
1091 1091
                     
1092
-                    if ( $line_item_tax === '' ) {
1092
+                    if ($line_item_tax === '') {
1093 1093
                         $line_item_tax = 0; // Zero tax
1094 1094
                     }
1095 1095
                     
1096
-                    $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">';
1097
-                        $line_item .= '<td class="name">' . esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item );
1098
-                        if ( $summary !== '' ) {
1099
-                            $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>';
1096
+                    $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">';
1097
+                        $line_item .= '<td class="name">' . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item);
1098
+                        if ($summary !== '') {
1099
+                            $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>';
1100 1100
                         }
1101 1101
                         $line_item .= '</td>';
1102 1102
                         
1103
-                        $line_item .= '<td class="rate">' . esc_html__( wpinv_price( wpinv_format_amount( $item_price ), $invoice->get_currency() ) ) . '</td>';
1103
+                        $line_item .= '<td class="rate">' . esc_html__(wpinv_price(wpinv_format_amount($item_price), $invoice->get_currency())) . '</td>';
1104 1104
                         if ($quantities_enabled) {
1105 1105
                             $cols++;
1106 1106
                             $line_item .= '<td class="qty">' . $quantity . '</td>';
@@ -1109,55 +1109,55 @@  discard block
 block discarded – undo
1109 1109
                             $cols++;
1110 1110
                             $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1111 1111
                         }
1112
-                        $line_item .= '<td class="total">' . esc_html__( wpinv_price( wpinv_format_amount( $line_total ), $invoice->get_currency() ) ) . '</td>';
1112
+                        $line_item .= '<td class="total">' . esc_html__(wpinv_price(wpinv_format_amount($line_total), $invoice->get_currency())) . '</td>';
1113 1113
                     $line_item .= '</tr>';
1114 1114
                     
1115
-                    echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols );
1115
+                    echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols);
1116 1116
 
1117 1117
                     $count++;
1118 1118
                 }
1119 1119
                 
1120
-                do_action( 'wpinv_display_before_subtotal', $invoice, $cols );
1120
+                do_action('wpinv_display_before_subtotal', $invoice, $cols);
1121 1121
                 ?>
1122 1122
                 <tr class="row-sub-total row_odd">
1123
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1124
-                    <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1123
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1124
+                    <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1125 1125
                 </tr>
1126 1126
                 <?php
1127
-                do_action( 'wpinv_display_after_subtotal', $invoice, $cols );
1127
+                do_action('wpinv_display_after_subtotal', $invoice, $cols);
1128 1128
                 
1129
-                if ( wpinv_discount( $invoice_id, false ) > 0 ) {
1130
-                    do_action( 'wpinv_display_before_discount', $invoice, $cols );
1129
+                if (wpinv_discount($invoice_id, false) > 0) {
1130
+                    do_action('wpinv_display_before_discount', $invoice, $cols);
1131 1131
                     ?>
1132 1132
                         <tr class="row-discount">
1133
-                            <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td>
1134
-                            <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1133
+                            <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td>
1134
+                            <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1135 1135
                         </tr>
1136 1136
                     <?php
1137
-                    do_action( 'wpinv_display_after_discount', $invoice, $cols );
1137
+                    do_action('wpinv_display_after_discount', $invoice, $cols);
1138 1138
                 }
1139 1139
                 
1140
-                if ( $use_taxes ) {
1141
-                    do_action( 'wpinv_display_before_tax', $invoice, $cols );
1140
+                if ($use_taxes) {
1141
+                    do_action('wpinv_display_before_tax', $invoice, $cols);
1142 1142
                     ?>
1143 1143
                     <tr class="row-tax">
1144
-                        <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td>
1145
-                        <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1144
+                        <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td>
1145
+                        <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1146 1146
                     </tr>
1147 1147
                     <?php
1148
-                    do_action( 'wpinv_display_after_tax', $invoice, $cols );
1148
+                    do_action('wpinv_display_after_tax', $invoice, $cols);
1149 1149
                 }
1150 1150
                 
1151
-                do_action( 'wpinv_display_before_total', $invoice, $cols );
1151
+                do_action('wpinv_display_before_total', $invoice, $cols);
1152 1152
                 ?>
1153 1153
                 <tr class="table-active row-total">
1154
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1155
-                    <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1154
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1155
+                    <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1156 1156
                 </tr>
1157 1157
                 <?php
1158
-                do_action( 'wpinv_display_after_total', $invoice, $cols );
1158
+                do_action('wpinv_display_after_total', $invoice, $cols);
1159 1159
                 
1160
-                do_action( 'wpinv_display_line_end', $invoice, $cols );
1160
+                do_action('wpinv_display_line_end', $invoice, $cols);
1161 1161
             }
1162 1162
         ?>
1163 1163
         </tbody>
@@ -1166,35 +1166,35 @@  discard block
 block discarded – undo
1166 1166
     echo ob_get_clean();
1167 1167
 }
1168 1168
 
1169
-function wpinv_display_invoice_totals( $invoice_id = 0 ) {    
1169
+function wpinv_display_invoice_totals($invoice_id = 0) {    
1170 1170
     $use_taxes = wpinv_use_taxes();
1171 1171
     
1172
-    do_action( 'wpinv_before_display_totals_table', $invoice_id ); 
1172
+    do_action('wpinv_before_display_totals_table', $invoice_id); 
1173 1173
     ?>
1174 1174
     <table class="table table-sm table-bordered table-responsive">
1175 1175
         <tbody>
1176
-            <?php do_action( 'wpinv_before_display_totals' ); ?>
1176
+            <?php do_action('wpinv_before_display_totals'); ?>
1177 1177
             <tr class="row-sub-total">
1178
-                <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td>
1179
-                <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1178
+                <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td>
1179
+                <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1180 1180
             </tr>
1181
-            <?php do_action( 'wpinv_after_display_totals' ); ?>
1182
-            <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?>
1181
+            <?php do_action('wpinv_after_display_totals'); ?>
1182
+            <?php if (wpinv_discount($invoice_id, false) > 0) { ?>
1183 1183
                 <tr class="row-discount">
1184
-                    <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td>
1185
-                    <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1184
+                    <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td>
1185
+                    <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1186 1186
                 </tr>
1187
-            <?php do_action( 'wpinv_after_display_discount' ); ?>
1187
+            <?php do_action('wpinv_after_display_discount'); ?>
1188 1188
             <?php } ?>
1189
-            <?php if ( $use_taxes ) { ?>
1189
+            <?php if ($use_taxes) { ?>
1190 1190
             <tr class="row-tax">
1191
-                <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td>
1192
-                <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1191
+                <td class="rate"><?php _e('Tax', 'invoicing'); ?></td>
1192
+                <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1193 1193
             </tr>
1194
-            <?php do_action( 'wpinv_after_display_tax' ); ?>
1194
+            <?php do_action('wpinv_after_display_tax'); ?>
1195 1195
             <?php } ?>
1196
-            <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?>
1197
-                <?php foreach ( $fees as $fee ) { ?>
1196
+            <?php if ($fees = wpinv_get_fees($invoice_id)) { ?>
1197
+                <?php foreach ($fees as $fee) { ?>
1198 1198
                     <tr class="row-fee">
1199 1199
                         <td class="rate"><?php echo $fee['label']; ?></td>
1200 1200
                         <td class="total"><?php echo $fee['amount_display']; ?></td>
@@ -1202,72 +1202,72 @@  discard block
 block discarded – undo
1202 1202
                 <?php } ?>
1203 1203
             <?php } ?>
1204 1204
             <tr class="table-active row-total">
1205
-                <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td>
1206
-                <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1205
+                <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td>
1206
+                <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1207 1207
             </tr>
1208
-            <?php do_action( 'wpinv_after_totals' ); ?>
1208
+            <?php do_action('wpinv_after_totals'); ?>
1209 1209
         </tbody>
1210 1210
 
1211 1211
     </table>
1212 1212
 
1213
-    <?php do_action( 'wpinv_after_totals_table' );
1213
+    <?php do_action('wpinv_after_totals_table');
1214 1214
 }
1215 1215
 
1216
-function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) {
1217
-    $invoice = wpinv_get_invoice( $invoice_id );
1216
+function wpinv_display_payments_info($invoice_id = 0, $echo = true) {
1217
+    $invoice = wpinv_get_invoice($invoice_id);
1218 1218
     
1219 1219
     ob_start();
1220
-    do_action( 'wpinv_before_display_payments_info', $invoice_id );
1221
-    if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() ) {
1220
+    do_action('wpinv_before_display_payments_info', $invoice_id);
1221
+    if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid()) {
1222 1222
         ?>
1223 1223
         <div class="wpi-payment-info">
1224
-            <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p>
1225
-            <?php if ( $gateway_title ) { ?>
1226
-            <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p>
1224
+            <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p>
1225
+            <?php if ($gateway_title) { ?>
1226
+            <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p>
1227 1227
             <?php } ?>
1228 1228
         </div>
1229 1229
         <?php
1230 1230
     }
1231
-    do_action( 'wpinv_after_display_payments_info', $invoice_id );
1231
+    do_action('wpinv_after_display_payments_info', $invoice_id);
1232 1232
     $outout = ob_get_clean();
1233 1233
     
1234
-    if ( $echo ) {
1234
+    if ($echo) {
1235 1235
         echo $outout;
1236 1236
     } else {
1237 1237
         return $outout;
1238 1238
     }
1239 1239
 }
1240 1240
 
1241
-function wpinv_display_style( $invoice ) {
1242
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION );
1241
+function wpinv_display_style($invoice) {
1242
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION);
1243 1243
     
1244
-    wp_print_styles( 'open-sans' );
1245
-    wp_print_styles( 'wpinv-single-style' );
1244
+    wp_print_styles('open-sans');
1245
+    wp_print_styles('wpinv-single-style');
1246 1246
 }
1247
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
1247
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
1248 1248
 
1249 1249
 function wpinv_checkout_billing_details() {  
1250 1250
     $invoice_id = (int)wpinv_get_invoice_cart_id();
1251 1251
     if (empty($invoice_id)) {
1252
-        wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ );
1252
+        wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__);
1253 1253
         return null;
1254 1254
     }
1255 1255
     
1256
-    $invoice = wpinv_get_invoice_cart( $invoice_id );
1256
+    $invoice = wpinv_get_invoice_cart($invoice_id);
1257 1257
     if (empty($invoice)) {
1258
-        wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ );
1258
+        wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__);
1259 1259
         return null;
1260 1260
     }
1261 1261
     $user_id        = $invoice->get_user_id();
1262 1262
     $user_info      = $invoice->get_user_info();
1263
-    $address_info   = wpinv_get_user_address( $user_id );
1263
+    $address_info   = wpinv_get_user_address($user_id);
1264 1264
     
1265
-    if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) {
1265
+    if (empty($user_info['first_name']) && !empty($user_info['first_name'])) {
1266 1266
         $user_info['first_name'] = $user_info['first_name'];
1267 1267
         $user_info['last_name'] = $user_info['last_name'];
1268 1268
     }
1269 1269
     
1270
-    if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) {
1270
+    if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) {
1271 1271
         $user_info['country']   = $address_info['country'];
1272 1272
         $user_info['state']     = $address_info['state'];
1273 1273
         $user_info['city']      = $address_info['city'];
@@ -1283,103 +1283,103 @@  discard block
 block discarded – undo
1283 1283
         'address'
1284 1284
     );
1285 1285
     
1286
-    foreach ( $address_fields as $field ) {
1287
-        if ( empty( $user_info[$field] ) ) {
1286
+    foreach ($address_fields as $field) {
1287
+        if (empty($user_info[$field])) {
1288 1288
             $user_info[$field] = $address_info[$field];
1289 1289
         }
1290 1290
     }
1291 1291
     
1292
-    return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice );
1292
+    return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice);
1293 1293
 }
1294 1294
 
1295 1295
 function wpinv_admin_get_line_items($invoice = array()) {
1296 1296
     $item_quantities    = wpinv_item_quantities_enabled();
1297 1297
     $use_taxes          = wpinv_use_taxes();
1298 1298
     
1299
-    if ( empty( $invoice ) ) {
1299
+    if (empty($invoice)) {
1300 1300
         return NULL;
1301 1301
     }
1302 1302
     
1303 1303
     $cart_items = $invoice->get_cart_details();
1304
-    if ( empty( $cart_items ) ) {
1304
+    if (empty($cart_items)) {
1305 1305
         return NULL;
1306 1306
     }
1307 1307
     ob_start();
1308 1308
     
1309
-    do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice );
1309
+    do_action('wpinv_admin_before_line_items', $cart_items, $invoice);
1310 1310
     
1311 1311
     $count = 0;
1312
-    foreach ( $cart_items as $key => $cart_item ) {
1312
+    foreach ($cart_items as $key => $cart_item) {
1313 1313
         $item_id    = $cart_item['id'];
1314
-        $wpi_item   = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL;
1314
+        $wpi_item   = $item_id > 0 ? new WPInv_Item($item_id) : NULL;
1315 1315
         
1316 1316
         if (empty($wpi_item)) {
1317 1317
             continue;
1318 1318
         }
1319 1319
         
1320
-        $item_price     = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ) );
1321
-        $quantity       = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1322
-        $item_subtotal  = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ) );
1320
+        $item_price     = wpinv_price(wpinv_format_amount($cart_item['item_price']));
1321
+        $quantity       = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1322
+        $item_subtotal  = wpinv_price(wpinv_format_amount($cart_item['subtotal']));
1323 1323
         $can_remove     = true;
1324 1324
         
1325 1325
         $summary = '';
1326 1326
         if ($wpi_item->is_package() && !empty($cart_item['meta']['post_id'])) {
1327
-            $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>';
1328
-            $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_custom_singular_name(), $post_link );
1327
+            $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>';
1328
+            $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_custom_singular_name(), $post_link);
1329 1329
         }
1330
-        $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice );
1330
+        $summary = apply_filters('wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice);
1331 1331
         
1332 1332
         $item_tax       = '';
1333 1333
         $tax_rate       = '';
1334
-        if ( $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1335
-            $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) );
1336
-            $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1337
-            $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1334
+        if ($cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1335
+            $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']));
1336
+            $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1337
+            $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
1338 1338
             $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : '';
1339 1339
         }
1340 1340
         $line_item_tax = $item_tax . $tax_rate;
1341 1341
         
1342
-        if ( $line_item_tax === '' ) {
1342
+        if ($line_item_tax === '') {
1343 1343
             $line_item_tax = 0; // Zero tax
1344 1344
         }
1345 1345
 
1346
-        $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">';
1346
+        $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">';
1347 1347
             $line_item .= '<td class="id">' . $item_id . '</td>';
1348
-            $line_item .= '<td class="title"><a href="' . get_edit_post_link( $item_id ) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix( $wpi_item );
1349
-            if ( $summary !== '' ) {
1350
-                $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>';
1348
+            $line_item .= '<td class="title"><a href="' . get_edit_post_link($item_id) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix($wpi_item);
1349
+            if ($summary !== '') {
1350
+                $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>';
1351 1351
             }
1352 1352
             $line_item .= '</td>';
1353 1353
             $line_item .= '<td class="price">' . $item_price . '</td>';
1354 1354
             
1355
-            if ( $item_quantities ) {
1356
-                if ( count( $cart_items ) == 1 && $quantity <= 1 ) {
1355
+            if ($item_quantities) {
1356
+                if (count($cart_items) == 1 && $quantity <= 1) {
1357 1357
                     $can_remove = false;
1358 1358
                 }
1359 1359
                 $line_item .= '<td class="qty" data-quantity="' . $quantity . '">&nbsp;&times;&nbsp;' . $quantity . '</td>';
1360 1360
             } else {
1361
-                if ( count( $cart_items ) == 1 ) {
1361
+                if (count($cart_items) == 1) {
1362 1362
                     $can_remove = false;
1363 1363
                 }
1364 1364
             }
1365 1365
             $line_item .= '<td class="total">' . $item_subtotal . '</td>';
1366 1366
             
1367
-            if ( $use_taxes ) {
1367
+            if ($use_taxes) {
1368 1368
                 $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1369 1369
             }
1370 1370
             $line_item .= '<td class="action">';
1371
-            if ( !$invoice->is_paid() && $can_remove ) {
1371
+            if (!$invoice->is_paid() && $can_remove) {
1372 1372
                 $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>';
1373 1373
             }
1374 1374
             $line_item .= '</td>';
1375 1375
         $line_item .= '</tr>';
1376 1376
         
1377
-        echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice );
1377
+        echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice);
1378 1378
         
1379 1379
         $count++;
1380 1380
     } 
1381 1381
     
1382
-    do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice );
1382
+    do_action('wpinv_admin_after_line_items', $cart_items, $invoice);
1383 1383
     
1384 1384
     return ob_get_clean();
1385 1385
 }
@@ -1390,35 +1390,35 @@  discard block
 block discarded – undo
1390 1390
     // Set current invoice id.
1391 1391
     $wpi_checkout_id = wpinv_get_invoice_cart_id();
1392 1392
     
1393
-    $form_action  = esc_url( wpinv_get_checkout_uri() );
1393
+    $form_action = esc_url(wpinv_get_checkout_uri());
1394 1394
 
1395 1395
     ob_start();
1396 1396
         echo '<div id="wpinv_checkout_wrap">';
1397 1397
         
1398
-        if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) {
1398
+        if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) {
1399 1399
             ?>
1400 1400
             <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive">
1401
-                <?php do_action( 'wpinv_before_checkout_form' ); ?>
1401
+                <?php do_action('wpinv_before_checkout_form'); ?>
1402 1402
                 <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST">
1403 1403
                     <?php
1404
-                    do_action( 'wpinv_checkout_form_top' );
1405
-                    do_action( 'wpinv_checkout_billing_info' );
1406
-                    do_action( 'wpinv_checkout_cart' );
1407
-                    do_action( 'wpinv_payment_mode_select'  );
1408
-                    do_action( 'wpinv_checkout_form_bottom' )
1404
+                    do_action('wpinv_checkout_form_top');
1405
+                    do_action('wpinv_checkout_billing_info');
1406
+                    do_action('wpinv_checkout_cart');
1407
+                    do_action('wpinv_payment_mode_select');
1408
+                    do_action('wpinv_checkout_form_bottom')
1409 1409
                     ?>
1410 1410
                 </form>
1411
-                <?php do_action( 'wpinv_after_purchase_form' ); ?>
1411
+                <?php do_action('wpinv_after_purchase_form'); ?>
1412 1412
             </div><!--end #wpinv_checkout_form_wrap-->
1413 1413
         <?php
1414 1414
         } else {
1415
-            do_action( 'wpinv_cart_empty' );
1415
+            do_action('wpinv_cart_empty');
1416 1416
         }
1417 1417
         echo '</div><!--end #wpinv_checkout_wrap-->';
1418 1418
     return ob_get_clean();
1419 1419
 }
1420 1420
 
1421
-function wpinv_checkout_cart( $cart_details = array(), $echo = true ) {
1421
+function wpinv_checkout_cart($cart_details = array(), $echo = true) {
1422 1422
     global $ajax_cart_details;
1423 1423
     $ajax_cart_details = $cart_details;
1424 1424
     /*
@@ -1433,25 +1433,25 @@  discard block
 block discarded – undo
1433 1433
     }
1434 1434
     */
1435 1435
     ob_start();
1436
-    do_action( 'wpinv_before_checkout_cart' );
1436
+    do_action('wpinv_before_checkout_cart');
1437 1437
     echo '<div id="wpinv_checkout_cart_form" method="post">';
1438 1438
         echo '<div id="wpinv_checkout_cart_wrap">';
1439
-            wpinv_get_template_part( 'wpinv-checkout-cart' );
1439
+            wpinv_get_template_part('wpinv-checkout-cart');
1440 1440
         echo '</div>';
1441 1441
     echo '</div>';
1442
-    do_action( 'wpinv_after_checkout_cart' );
1442
+    do_action('wpinv_after_checkout_cart');
1443 1443
     $content = ob_get_clean();
1444 1444
     
1445
-    if ( $echo ) {
1445
+    if ($echo) {
1446 1446
         echo $content;
1447 1447
     } else {
1448 1448
         return $content;
1449 1449
     }
1450 1450
 }
1451
-add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 );
1451
+add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10);
1452 1452
 
1453 1453
 function wpinv_empty_cart_message() {
1454
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1454
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1455 1455
 }
1456 1456
 
1457 1457
 /**
@@ -1463,91 +1463,91 @@  discard block
 block discarded – undo
1463 1463
 function wpinv_empty_checkout_cart() {
1464 1464
 	echo wpinv_empty_cart_message();
1465 1465
 }
1466
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1466
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1467 1467
 
1468 1468
 function wpinv_save_cart_button() {
1469
-    if ( wpinv_is_cart_saving_disabled() )
1469
+    if (wpinv_is_cart_saving_disabled())
1470 1470
         return;
1471 1471
 ?>
1472
-    <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url( add_query_arg( 'wpi_action', 'save_cart' ) ); ?>"><?php _e( 'Save Cart', 'invoicing' ); ?></a>
1472
+    <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url(add_query_arg('wpi_action', 'save_cart')); ?>"><?php _e('Save Cart', 'invoicing'); ?></a>
1473 1473
 <?php
1474 1474
 }
1475 1475
 
1476 1476
 function wpinv_update_cart_button() {
1477
-    if ( !wpinv_item_quantities_enabled() )
1477
+    if (!wpinv_item_quantities_enabled())
1478 1478
         return;
1479 1479
 ?>
1480
-    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/>
1480
+    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/>
1481 1481
     <input type="hidden" name="wpi_action" value="update_cart"/>
1482 1482
 <?php
1483 1483
 }
1484 1484
 
1485 1485
 function wpinv_checkout_cart_columns() {
1486 1486
     $default = 3;
1487
-    if ( wpinv_item_quantities_enabled() ) {
1487
+    if (wpinv_item_quantities_enabled()) {
1488 1488
         $default++;
1489 1489
     }
1490 1490
     
1491
-    if ( wpinv_use_taxes() ) {
1491
+    if (wpinv_use_taxes()) {
1492 1492
         $default++;
1493 1493
     }
1494 1494
 
1495
-    return apply_filters( 'wpinv_checkout_cart_columns', $default );
1495
+    return apply_filters('wpinv_checkout_cart_columns', $default);
1496 1496
 }
1497 1497
 
1498 1498
 function wpinv_display_cart_messages() {
1499 1499
     global $wpi_session;
1500 1500
 
1501
-    $messages = $wpi_session->get( 'wpinv_cart_messages' );
1501
+    $messages = $wpi_session->get('wpinv_cart_messages');
1502 1502
 
1503
-    if ( $messages ) {
1504
-        foreach ( $messages as $message_id => $message ) {
1503
+    if ($messages) {
1504
+        foreach ($messages as $message_id => $message) {
1505 1505
             // Try and detect what type of message this is
1506
-            if ( strpos( strtolower( $message ), 'error' ) ) {
1506
+            if (strpos(strtolower($message), 'error')) {
1507 1507
                 $type = 'error';
1508
-            } elseif ( strpos( strtolower( $message ), 'success' ) ) {
1508
+            } elseif (strpos(strtolower($message), 'success')) {
1509 1509
                 $type = 'success';
1510 1510
             } else {
1511 1511
                 $type = 'info';
1512 1512
             }
1513 1513
 
1514
-            $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) );
1514
+            $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type));
1515 1515
 
1516
-            echo '<div class="' . implode( ' ', $classes ) . '">';
1516
+            echo '<div class="' . implode(' ', $classes) . '">';
1517 1517
                 // Loop message codes and display messages
1518 1518
                     echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>';
1519 1519
             echo '</div>';
1520 1520
         }
1521 1521
 
1522 1522
         // Remove all of the cart saving messages
1523
-        $wpi_session->set( 'wpinv_cart_messages', null );
1523
+        $wpi_session->set('wpinv_cart_messages', null);
1524 1524
     }
1525 1525
 }
1526
-add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' );
1526
+add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages');
1527 1527
 
1528 1528
 function wpinv_discount_field() {
1529
-    if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) {
1529
+    if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) {
1530 1530
         return; // Only show before a payment method has been selected if ajax is disabled
1531 1531
     }
1532 1532
 
1533
-    if ( !wpinv_is_checkout() ) {
1533
+    if (!wpinv_is_checkout()) {
1534 1534
         return;
1535 1535
     }
1536 1536
 
1537
-    if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) {
1537
+    if (wpinv_has_active_discounts() && wpinv_get_cart_total()) {
1538 1538
     ?>
1539 1539
     <div id="wpinv-discount-field" class="panel panel-default">
1540 1540
         <div class="panel-body">
1541 1541
             <p>
1542
-                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label>
1543
-                <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span>
1542
+                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label>
1543
+                <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span>
1544 1544
             </p>
1545 1545
             <div class="form-group row">
1546 1546
                 <div class="col-sm-4">
1547
-                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/>
1547
+                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/>
1548 1548
                 </div>
1549 1549
                 <div class="col-sm-3">
1550
-                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button>
1550
+                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button>
1551 1551
                 </div>
1552 1552
                 <div style="clear:both"></div>
1553 1553
                 <div class="col-sm-12 wpinv-discount-msg">
@@ -1560,10 +1560,10 @@  discard block
 block discarded – undo
1560 1560
 <?php
1561 1561
     }
1562 1562
 }
1563
-add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 );
1563
+add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10);
1564 1564
 
1565 1565
 function wpinv_agree_to_terms_js() {
1566
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
1566
+    if (wpinv_get_option('show_agree_to_terms', false)) {
1567 1567
 ?>
1568 1568
 <script type="text/javascript">
1569 1569
     jQuery(document).ready(function($){
@@ -1578,126 +1578,126 @@  discard block
 block discarded – undo
1578 1578
 <?php
1579 1579
     }
1580 1580
 }
1581
-add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' );
1581
+add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js');
1582 1582
 
1583 1583
 function wpinv_payment_mode_select() {
1584
-    $gateways = wpinv_get_enabled_payment_gateways( true );
1585
-    $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways );
1584
+    $gateways = wpinv_get_enabled_payment_gateways(true);
1585
+    $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways);
1586 1586
     $page_URL = wpinv_get_current_page_url();
1587
-    $invoice = wpinv_get_invoice( 0, true );
1587
+    $invoice = wpinv_get_invoice(0, true);
1588 1588
     
1589 1589
     do_action('wpinv_payment_mode_top');
1590 1590
     $invoice_id = (int)$invoice->ID;
1591
-    $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id );
1591
+    $chosen_gateway = wpinv_get_chosen_gateway($invoice_id);
1592 1592
     ?>
1593
-    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ( $invoice->is_free() ? 'style="display:none;"' : '' ); ?>>
1594
-            <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?>
1593
+    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ($invoice->is_free() ? 'style="display:none;"' : ''); ?>>
1594
+            <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?>
1595 1595
             <div id="wpinv-payment-mode-wrap" class="panel panel-default">
1596
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div>
1596
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div>
1597 1597
                 <div class="panel-body list-group wpi-payment_methods">
1598 1598
                     <?php
1599
-                    do_action( 'wpinv_payment_mode_before_gateways' );
1599
+                    do_action('wpinv_payment_mode_before_gateways');
1600 1600
                     
1601
-                    if(!empty($gateways)){
1602
-	                    foreach ( $gateways as $gateway_id => $gateway ) {
1603
-		                    $checked = checked( $gateway_id, $chosen_gateway, false );
1604
-		                    $button_label = wpinv_get_gateway_button_label( $gateway_id );
1605
-		                    $description = wpinv_get_gateway_description( $gateway_id );
1601
+                    if (!empty($gateways)) {
1602
+	                    foreach ($gateways as $gateway_id => $gateway) {
1603
+		                    $checked = checked($gateway_id, $chosen_gateway, false);
1604
+		                    $button_label = wpinv_get_gateway_button_label($gateway_id);
1605
+		                    $description = wpinv_get_gateway_description($gateway_id);
1606 1606
 		                    ?>
1607 1607
 		                    <div class="list-group-item">
1608 1608
 			                    <div class="radio">
1609
-				                    <label><input type="radio" data-button-text="<?php echo esc_attr( $button_label );?>" value="<?php echo esc_attr( $gateway_id ) ;?>" <?php echo $checked ;?> id="wpi_gateway_<?php echo esc_attr( $gateway_id );?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html( $gateway['checkout_label'] ); ?></label>
1609
+				                    <label><input type="radio" data-button-text="<?php echo esc_attr($button_label); ?>" value="<?php echo esc_attr($gateway_id); ?>" <?php echo $checked; ?> id="wpi_gateway_<?php echo esc_attr($gateway_id); ?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html($gateway['checkout_label']); ?></label>
1610 1610
 			                    </div>
1611
-			                    <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert">
1612
-				                    <?php if ( !empty( $description ) ) { ?>
1613
-					                    <div class="wpi-gateway-desc alert alert-info"><?php echo $description;?></div>
1611
+			                    <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert">
1612
+				                    <?php if (!empty($description)) { ?>
1613
+					                    <div class="wpi-gateway-desc alert alert-info"><?php echo $description; ?></div>
1614 1614
 				                    <?php } ?>
1615
-				                    <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?>
1615
+				                    <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?>
1616 1616
 			                    </div>
1617 1617
 		                    </div>
1618 1618
 		                    <?php
1619 1619
 	                    }
1620
-                    }else{
1621
-	                    echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>';
1620
+                    } else {
1621
+	                    echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>';
1622 1622
                     }
1623 1623
 
1624
-                    do_action( 'wpinv_payment_mode_after_gateways' );
1624
+                    do_action('wpinv_payment_mode_after_gateways');
1625 1625
                     ?>
1626 1626
                 </div>
1627 1627
             </div>
1628
-            <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?>
1628
+            <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?>
1629 1629
     </div>
1630 1630
     <?php
1631 1631
     do_action('wpinv_payment_mode_bottom');
1632 1632
 }
1633
-add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' );
1633
+add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select');
1634 1634
 
1635 1635
 function wpinv_checkout_billing_info() {    
1636
-    if ( wpinv_is_checkout() ) {
1636
+    if (wpinv_is_checkout()) {
1637 1637
         $logged_in          = is_user_logged_in();
1638 1638
         $billing_details    = wpinv_checkout_billing_details();
1639
-        $selected_country   = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country();
1639
+        $selected_country   = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country();
1640 1640
         ?>
1641 1641
         <div id="wpinv-fields" class="clearfix">
1642 1642
             <div id="wpi-billing" class="wpi-billing clearfix panel panel-default">
1643
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div>
1643
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div>
1644 1644
                 <div id="wpinv-fields-box" class="panel-body">
1645
-                    <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?>
1645
+                    <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?>
1646 1646
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1647
-                        <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><?php if ( wpinv_get_option( 'fname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1647
+                        <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><?php if (wpinv_get_option('fname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1648 1648
                         <?php
1649
-                        echo wpinv_html_text( array(
1649
+                        echo wpinv_html_text(array(
1650 1650
                                 'id'            => 'wpinv_first_name',
1651 1651
                                 'name'          => 'wpinv_first_name',
1652 1652
                                 'value'         => $billing_details['first_name'],
1653 1653
                                 'class'         => 'wpi-input form-control required',
1654
-                                'placeholder'   => __( 'First name', 'invoicing' ),
1655
-                                'required'      => (bool)wpinv_get_option( 'fname_mandatory' ),
1656
-                            ) );
1654
+                                'placeholder'   => __('First name', 'invoicing'),
1655
+                                'required'      => (bool)wpinv_get_option('fname_mandatory'),
1656
+                            ));
1657 1657
                         ?>
1658 1658
                     </p>
1659 1659
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1660
-                        <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?><?php if ( wpinv_get_option( 'lname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1660
+                        <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?><?php if (wpinv_get_option('lname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1661 1661
                         <?php
1662
-                        echo wpinv_html_text( array(
1662
+                        echo wpinv_html_text(array(
1663 1663
                                 'id'            => 'wpinv_last_name',
1664 1664
                                 'name'          => 'wpinv_last_name',
1665 1665
                                 'value'         => $billing_details['last_name'],
1666 1666
                                 'class'         => 'wpi-input form-control',
1667
-                                'placeholder'   => __( 'Last name', 'invoicing' ),
1668
-                                'required'      => (bool)wpinv_get_option( 'lname_mandatory' ),
1669
-                            ) );
1667
+                                'placeholder'   => __('Last name', 'invoicing'),
1668
+                                'required'      => (bool)wpinv_get_option('lname_mandatory'),
1669
+                            ));
1670 1670
                         ?>
1671 1671
                     </p>
1672 1672
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1673
-                        <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><?php if ( wpinv_get_option( 'address_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1673
+                        <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><?php if (wpinv_get_option('address_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1674 1674
                         <?php
1675
-                        echo wpinv_html_text( array(
1675
+                        echo wpinv_html_text(array(
1676 1676
                                 'id'            => 'wpinv_address',
1677 1677
                                 'name'          => 'wpinv_address',
1678 1678
                                 'value'         => $billing_details['address'],
1679 1679
                                 'class'         => 'wpi-input form-control required',
1680
-                                'placeholder'   => __( 'Address', 'invoicing' ),
1681
-                                'required'      => (bool)wpinv_get_option( 'address_mandatory' ),
1682
-                            ) );
1680
+                                'placeholder'   => __('Address', 'invoicing'),
1681
+                                'required'      => (bool)wpinv_get_option('address_mandatory'),
1682
+                            ));
1683 1683
                         ?>
1684 1684
                     </p>
1685 1685
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1686
-                        <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><?php if ( wpinv_get_option( 'city_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1686
+                        <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><?php if (wpinv_get_option('city_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1687 1687
                         <?php
1688
-                        echo wpinv_html_text( array(
1688
+                        echo wpinv_html_text(array(
1689 1689
                                 'id'            => 'wpinv_city',
1690 1690
                                 'name'          => 'wpinv_city',
1691 1691
                                 'value'         => $billing_details['city'],
1692 1692
                                 'class'         => 'wpi-input form-control required',
1693
-                                'placeholder'   => __( 'City', 'invoicing' ),
1694
-                                'required'      => (bool)wpinv_get_option( 'city_mandatory' ),
1695
-                            ) );
1693
+                                'placeholder'   => __('City', 'invoicing'),
1694
+                                'required'      => (bool)wpinv_get_option('city_mandatory'),
1695
+                            ));
1696 1696
                         ?>
1697 1697
                     </p>
1698 1698
                     <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf">
1699
-                        <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><?php if ( wpinv_get_option( 'country_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1700
-                        <?php echo wpinv_html_select( array(
1699
+                        <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><?php if (wpinv_get_option('country_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1700
+                        <?php echo wpinv_html_select(array(
1701 1701
                             'options'          => wpinv_get_country_list(),
1702 1702
                             'name'             => 'wpinv_country',
1703 1703
                             'id'               => 'wpinv_country',
@@ -1705,16 +1705,16 @@  discard block
 block discarded – undo
1705 1705
                             'show_option_all'  => false,
1706 1706
                             'show_option_none' => false,
1707 1707
                             'class'            => 'wpi-input form-control required',
1708
-                            'placeholder'      => __( 'Choose a country', 'invoicing' ),
1709
-                            'required'         => (bool)wpinv_get_option( 'country_mandatory' ),
1710
-                        ) ); ?>
1708
+                            'placeholder'      => __('Choose a country', 'invoicing'),
1709
+                            'required'         => (bool)wpinv_get_option('country_mandatory'),
1710
+                        )); ?>
1711 1711
                     </p>
1712 1712
                     <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll">
1713
-                        <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><?php if ( wpinv_get_option( 'state_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1713
+                        <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><?php if (wpinv_get_option('state_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1714 1714
                         <?php
1715
-                        $states = wpinv_get_country_states( $selected_country );
1716
-                        if( !empty( $states ) ) {
1717
-                            echo wpinv_html_select( array(
1715
+                        $states = wpinv_get_country_states($selected_country);
1716
+                        if (!empty($states)) {
1717
+                            echo wpinv_html_select(array(
1718 1718
                                 'options'          => $states,
1719 1719
                                 'name'             => 'wpinv_state',
1720 1720
                                 'id'               => 'wpinv_state',
@@ -1722,61 +1722,61 @@  discard block
 block discarded – undo
1722 1722
                                 'show_option_all'  => false,
1723 1723
                                 'show_option_none' => false,
1724 1724
                                 'class'            => 'wpi-input form-control required',
1725
-                                'placeholder'      => __( 'Choose a state', 'invoicing' ),
1726
-                                'required'         => (bool)wpinv_get_option( 'state_mandatory' ),
1727
-                            ) );
1725
+                                'placeholder'      => __('Choose a state', 'invoicing'),
1726
+                                'required'         => (bool)wpinv_get_option('state_mandatory'),
1727
+                            ));
1728 1728
                         } else {
1729
-                            echo wpinv_html_text( array(
1729
+                            echo wpinv_html_text(array(
1730 1730
                                 'name'          => 'wpinv_state',
1731 1731
                                 'value'         => $billing_details['state'],
1732 1732
                                 'id'            => 'wpinv_state',
1733 1733
                                 'class'         => 'wpi-input form-control required',
1734
-                                'placeholder'   => __( 'State / Province', 'invoicing' ),
1735
-                                'required'      => (bool)wpinv_get_option( 'state_mandatory' ),
1736
-                            ) );
1734
+                                'placeholder'   => __('State / Province', 'invoicing'),
1735
+                                'required'      => (bool)wpinv_get_option('state_mandatory'),
1736
+                            ));
1737 1737
                         }
1738 1738
                         ?>
1739 1739
                     </p>
1740 1740
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1741
-                        <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?><?php if ( wpinv_get_option( 'zip_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1741
+                        <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?><?php if (wpinv_get_option('zip_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1742 1742
                         <?php
1743
-                        echo wpinv_html_text( array(
1743
+                        echo wpinv_html_text(array(
1744 1744
                                 'name'          => 'wpinv_zip',
1745 1745
                                 'value'         => $billing_details['zip'],
1746 1746
                                 'id'            => 'wpinv_zip',
1747 1747
                                 'class'         => 'wpi-input form-control',
1748
-                                'placeholder'   => __( 'ZIP / Postcode', 'invoicing' ),
1749
-                                'required'      => (bool)wpinv_get_option( 'zip_mandatory' ),
1750
-                            ) );
1748
+                                'placeholder'   => __('ZIP / Postcode', 'invoicing'),
1749
+                                'required'      => (bool)wpinv_get_option('zip_mandatory'),
1750
+                            ));
1751 1751
                         ?>
1752 1752
                     </p>
1753 1753
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1754
-                        <label for="wpinv_phone" class="wpi-label"><?php _e( 'Phone', 'invoicing' );?><?php if ( wpinv_get_option( 'phone_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1754
+                        <label for="wpinv_phone" class="wpi-label"><?php _e('Phone', 'invoicing'); ?><?php if (wpinv_get_option('phone_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1755 1755
                         <?php
1756
-                        echo wpinv_html_text( array(
1756
+                        echo wpinv_html_text(array(
1757 1757
                                 'id'            => 'wpinv_phone',
1758 1758
                                 'name'          => 'wpinv_phone',
1759 1759
                                 'value'         => $billing_details['phone'],
1760 1760
                                 'class'         => 'wpi-input form-control',
1761
-                                'placeholder'   => __( 'Phone', 'invoicing' ),
1762
-                                'required'      => (bool)wpinv_get_option( 'phone_mandatory' ),
1763
-                            ) );
1761
+                                'placeholder'   => __('Phone', 'invoicing'),
1762
+                                'required'      => (bool)wpinv_get_option('phone_mandatory'),
1763
+                            ));
1764 1764
                         ?>
1765 1765
                     </p>
1766
-                    <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?>
1766
+                    <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?>
1767 1767
                     <div class="clearfix"></div>
1768 1768
                 </div>
1769 1769
             </div>
1770
-            <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?>
1770
+            <?php do_action('wpinv_after_billing_fields', $billing_details); ?>
1771 1771
         </div>
1772 1772
         <?php
1773 1773
     }
1774 1774
 }
1775
-add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' );
1775
+add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info');
1776 1776
 
1777 1777
 function wpinv_checkout_hidden_fields() {
1778 1778
 ?>
1779
-    <?php if ( is_user_logged_in() ) { ?>
1779
+    <?php if (is_user_logged_in()) { ?>
1780 1780
     <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/>
1781 1781
     <?php } ?>
1782 1782
     <input type="hidden" name="wpi_action" value="payment" />
@@ -1786,9 +1786,9 @@  discard block
 block discarded – undo
1786 1786
 function wpinv_checkout_button_purchase() {
1787 1787
     ob_start();
1788 1788
 ?>
1789
-    <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>" name="wpinv_payment" value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>"/>
1789
+    <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>" name="wpinv_payment" value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>"/>
1790 1790
 <?php
1791
-    return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() );
1791
+    return apply_filters('wpinv_checkout_button_purchase', ob_get_clean());
1792 1792
 }
1793 1793
 
1794 1794
 function wpinv_checkout_total() {
@@ -1797,96 +1797,96 @@  discard block
 block discarded – undo
1797 1797
 <div id="wpinv_checkout_total" class="panel panel-info">
1798 1798
     <div class="panel-body">
1799 1799
     <?php
1800
-    do_action( 'wpinv_purchase_form_before_checkout_total' );
1800
+    do_action('wpinv_purchase_form_before_checkout_total');
1801 1801
     ?>
1802
-    <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span>
1802
+    <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span>
1803 1803
     <?php
1804
-    do_action( 'wpinv_purchase_form_after_checkout_total' );
1804
+    do_action('wpinv_purchase_form_after_checkout_total');
1805 1805
     ?>
1806 1806
     </div>
1807 1807
 </div>
1808 1808
 <?php
1809 1809
 }
1810
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 );
1810
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998);
1811 1811
 
1812 1812
 function wpinv_checkout_submit() {
1813 1813
 ?>
1814 1814
 <div id="wpinv_purchase_submit" class="panel panel-success">
1815 1815
     <div class="panel-body text-center">
1816 1816
     <?php
1817
-    do_action( 'wpinv_purchase_form_before_submit' );
1817
+    do_action('wpinv_purchase_form_before_submit');
1818 1818
     wpinv_checkout_hidden_fields();
1819 1819
     echo wpinv_checkout_button_purchase();
1820
-    do_action( 'wpinv_purchase_form_after_submit' );
1820
+    do_action('wpinv_purchase_form_after_submit');
1821 1821
     ?>
1822 1822
     </div>
1823 1823
 </div>
1824 1824
 <?php
1825 1825
 }
1826
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 );
1826
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999);
1827 1827
 
1828
-function wpinv_receipt_billing_address( $invoice_id = 0 ) {
1829
-    $invoice = wpinv_get_invoice( $invoice_id );
1828
+function wpinv_receipt_billing_address($invoice_id = 0) {
1829
+    $invoice = wpinv_get_invoice($invoice_id);
1830 1830
     
1831
-    if ( empty( $invoice ) ) {
1831
+    if (empty($invoice)) {
1832 1832
         return NULL;
1833 1833
     }
1834 1834
     
1835 1835
     $billing_details = $invoice->get_user_info();
1836 1836
     $address_row = '';
1837
-    if ( $address = $billing_details['address'] ) {
1838
-        $address_row .= wpautop( wp_kses_post( $address ) );
1837
+    if ($address = $billing_details['address']) {
1838
+        $address_row .= wpautop(wp_kses_post($address));
1839 1839
     }
1840 1840
     
1841 1841
     $address_fields = array();
1842
-    if ( !empty( $billing_details['city'] ) ) {
1842
+    if (!empty($billing_details['city'])) {
1843 1843
         $address_fields[] = $billing_details['city'];
1844 1844
     }
1845 1845
     
1846
-    $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : '';
1847
-    if ( !empty( $billing_details['state'] ) ) {
1848
-        $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country );
1846
+    $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : '';
1847
+    if (!empty($billing_details['state'])) {
1848
+        $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country);
1849 1849
     }
1850 1850
     
1851
-    if ( !empty( $billing_country ) ) {
1852
-        $address_fields[] = wpinv_country_name( $billing_country );
1851
+    if (!empty($billing_country)) {
1852
+        $address_fields[] = wpinv_country_name($billing_country);
1853 1853
     }
1854 1854
     
1855
-    if ( !empty( $address_fields ) ) {
1856
-        $address_fields = implode( ", ", $address_fields );
1855
+    if (!empty($address_fields)) {
1856
+        $address_fields = implode(", ", $address_fields);
1857 1857
         
1858
-        if ( !empty( $billing_details['zip'] ) ) {
1858
+        if (!empty($billing_details['zip'])) {
1859 1859
             $address_fields .= ' ' . $billing_details['zip'];
1860 1860
         }
1861 1861
         
1862
-        $address_row .= wpautop( wp_kses_post( $address_fields ) );
1862
+        $address_row .= wpautop(wp_kses_post($address_fields));
1863 1863
     }
1864 1864
     ob_start();
1865 1865
     ?>
1866 1866
     <table class="table table-bordered table-sm wpi-billing-details">
1867 1867
         <tbody>
1868 1868
             <tr class="wpi-receipt-name">
1869
-                <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th>
1870
-                <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td>
1869
+                <th class="text-left"><?php _e('Name', 'invoicing'); ?></th>
1870
+                <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td>
1871 1871
             </tr>
1872 1872
             <tr class="wpi-receipt-email">
1873
-                <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th>
1874
-                <td><?php echo $billing_details['email'] ;?></td>
1873
+                <th class="text-left"><?php _e('Email', 'invoicing'); ?></th>
1874
+                <td><?php echo $billing_details['email']; ?></td>
1875 1875
             </tr>
1876
-            <?php if ( $billing_details['company'] ) { ?>
1876
+            <?php if ($billing_details['company']) { ?>
1877 1877
             <tr class="wpi-receipt-company">
1878
-                <th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th>
1879
-                <td><?php echo esc_html( $billing_details['company'] ) ;?></td>
1878
+                <th class="text-left"><?php _e('Company', 'invoicing'); ?></th>
1879
+                <td><?php echo esc_html($billing_details['company']); ?></td>
1880 1880
             </tr>
1881 1881
             <?php } ?>
1882 1882
             <tr class="wpi-receipt-address">
1883
-                <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th>
1884
-                <td><?php echo $address_row ;?></td>
1883
+                <th class="text-left"><?php _e('Address', 'invoicing'); ?></th>
1884
+                <td><?php echo $address_row; ?></td>
1885 1885
             </tr>
1886
-            <?php if ( $billing_details['phone'] ) { ?>
1886
+            <?php if ($billing_details['phone']) { ?>
1887 1887
             <tr class="wpi-receipt-phone">
1888
-                <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th>
1889
-                <td><?php echo esc_html( $billing_details['phone'] ) ;?></td>
1888
+                <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th>
1889
+                <td><?php echo esc_html($billing_details['phone']); ?></td>
1890 1890
             </tr>
1891 1891
             <?php } ?>
1892 1892
         </tbody>
@@ -1894,98 +1894,98 @@  discard block
 block discarded – undo
1894 1894
     <?php
1895 1895
     $output = ob_get_clean();
1896 1896
     
1897
-    $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id );
1897
+    $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id);
1898 1898
 
1899 1899
     echo $output;
1900 1900
 }
1901 1901
 
1902
-function wpinv_filter_success_page_content( $content ) {
1903
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1904
-        if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) {
1905
-            $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content );
1902
+function wpinv_filter_success_page_content($content) {
1903
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1904
+        if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) {
1905
+            $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content);
1906 1906
         }
1907 1907
     }
1908 1908
 
1909 1909
     return $content;
1910 1910
 }
1911
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1911
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1912 1912
 
1913
-function wpinv_receipt_actions( $invoice ) {
1914
-    if ( !empty( $invoice ) ) {
1913
+function wpinv_receipt_actions($invoice) {
1914
+    if (!empty($invoice)) {
1915 1915
         $actions = array(
1916 1916
             'print'   => array(
1917 1917
                 'url'  => $invoice->get_view_url(),
1918
-                'name' => __( 'Print Invoice', 'invoicing' ),
1918
+                'name' => __('Print Invoice', 'invoicing'),
1919 1919
                 'class' => 'btn-primary',
1920 1920
             ),
1921 1921
             'history'   => array(
1922 1922
                 'url'  => wpinv_get_history_page_uri(),
1923
-                'name' => __( 'Invoice History', 'invoicing' ),
1923
+                'name' => __('Invoice History', 'invoicing'),
1924 1924
                 'class' => 'btn-warning',
1925 1925
             )
1926 1926
         );
1927 1927
 
1928
-        $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice );
1928
+        $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice);
1929 1929
         
1930
-        if ( !empty( $actions ) ) {
1930
+        if (!empty($actions)) {
1931 1931
         ?>
1932 1932
         <div class="wpinv-receipt-actions text-right">
1933
-            <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?>
1934
-            <a href="<?php echo esc_url( $action['url'] );?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class( $key );?>" <?php echo ( !empty($action['attrs']) ? $action['attrs'] : '' ) ;?>><?php echo esc_html( $action['name'] );?></a>
1933
+            <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?>
1934
+            <a href="<?php echo esc_url($action['url']); ?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class($key); ?>" <?php echo (!empty($action['attrs']) ? $action['attrs'] : ''); ?>><?php echo esc_html($action['name']); ?></a>
1935 1935
             <?php } ?>
1936 1936
         </div>
1937 1937
         <?php
1938 1938
         }
1939 1939
     }
1940 1940
 }
1941
-add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 );
1941
+add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1);
1942 1942
 
1943
-function wpinv_invoice_link( $invoice_id ) {
1944
-    $invoice = wpinv_get_invoice( $invoice_id );
1943
+function wpinv_invoice_link($invoice_id) {
1944
+    $invoice = wpinv_get_invoice($invoice_id);
1945 1945
     
1946
-    if ( empty( $invoice ) ) {
1946
+    if (empty($invoice)) {
1947 1947
         return NULL;
1948 1948
     }
1949 1949
     
1950
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1950
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1951 1951
     
1952
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1952
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1953 1953
 }
1954 1954
 
1955
-function wpinv_invoice_subscription_details( $invoice ) {
1956
-    if ( !empty( $invoice ) && $invoice->is_recurring() && !wpinv_is_subscription_payment( $invoice ) ) {
1955
+function wpinv_invoice_subscription_details($invoice) {
1956
+    if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) {
1957 1957
         $total_payments = (int)$invoice->get_total_payments();
1958 1958
         $payments       = $invoice->get_child_payments();
1959 1959
         
1960 1960
         $subscription   = $invoice->get_subscription_data();
1961 1961
         
1962
-        if ( !( !empty( $subscription ) && !empty( $subscription['item_id'] ) ) ) {
1962
+        if (!(!empty($subscription) && !empty($subscription['item_id']))) {
1963 1963
             return;
1964 1964
         }
1965 1965
         
1966
-        $billing_cycle  = wpinv_get_billing_cycle( $subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency() );
1967
-        $times_billed   = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] );
1966
+        $billing_cycle  = wpinv_get_billing_cycle($subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency());
1967
+        $times_billed   = $total_payments . ' / ' . (((int)$subscription['bill_times'] == 0) ? __('Until cancelled', 'invoicing') : $subscription['bill_times']);
1968 1968
         
1969 1969
         $subscription_status = $invoice->get_subscription_status();
1970 1970
         
1971 1971
         $status_desc = '';
1972
-        if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) {
1973
-            $status_desc = wp_sprintf( __( 'Until: %s', 'invoicing' ), $trial_end_date );
1974
-        } else if ( $subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date() ) {
1975
-            $status_desc = wp_sprintf( __( 'On: %s', 'invoicing' ), $cancelled_date );
1972
+        if ($subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date()) {
1973
+            $status_desc = wp_sprintf(__('Until: %s', 'invoicing'), $trial_end_date);
1974
+        } else if ($subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date()) {
1975
+            $status_desc = wp_sprintf(__('On: %s', 'invoicing'), $cancelled_date);
1976 1976
         }
1977 1977
         $status_desc = $status_desc != '' ? '<span class="meta">' . $status_desc . '</span>' : '';
1978 1978
         ?>
1979 1979
         <div class="wpinv-subscriptions-details">
1980
-            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3>
1980
+            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3>
1981 1981
             <table class="table">
1982 1982
                 <thead>
1983 1983
                     <tr>
1984
-                        <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th>
1985
-                        <th><?php _e( 'Start Date', 'invoicing' ) ;?></th>
1986
-                        <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th>
1987
-                        <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th>
1988
-                        <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th>
1984
+                        <th><?php _e('Billing Cycle', 'invoicing'); ?></th>
1985
+                        <th><?php _e('Start Date', 'invoicing'); ?></th>
1986
+                        <th><?php _e('Expiration Date', 'invoicing'); ?></th>
1987
+                        <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th>
1988
+                        <th class="text-center"><?php _e('Status', 'invoicing'); ?></th>
1989 1989
                     </tr>
1990 1990
                 </thead>
1991 1991
                 <tbody>
@@ -1994,32 +1994,32 @@  discard block
 block discarded – undo
1994 1994
                         <td><?php echo $invoice->get_subscription_start(); ?></td>
1995 1995
                         <td><?php echo $invoice->get_subscription_end(); ?></td>
1996 1996
                         <td class="text-center"><?php echo $times_billed; ?></td>
1997
-                        <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label() ;?>
1997
+                        <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label(); ?>
1998 1998
                         <?php echo $status_desc; ?>
1999 1999
                         </td>
2000 2000
                     </tr>
2001 2001
                 </tbody>
2002 2002
             </table>
2003 2003
         </div>
2004
-        <?php if ( !empty( $payments ) ) { ?>
2004
+        <?php if (!empty($payments)) { ?>
2005 2005
         <div class="wpinv-renewal-payments">
2006
-            <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3>
2006
+            <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3>
2007 2007
             <table class="table">
2008 2008
                 <thead>
2009 2009
                     <tr>
2010 2010
                         <th>#</th>
2011
-                        <th><?php _e( 'Invoice', 'invoicing' ) ;?></th>
2012
-                        <th><?php _e( 'Date', 'invoicing' ) ;?></th>
2013
-                        <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th>
2011
+                        <th><?php _e('Invoice', 'invoicing'); ?></th>
2012
+                        <th><?php _e('Date', 'invoicing'); ?></th>
2013
+                        <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th>
2014 2014
                     </tr>
2015 2015
                 </thead>
2016 2016
                 <tbody>
2017
-                    <?php foreach ( $payments as $key => $invoice_id ) { ?>
2017
+                    <?php foreach ($payments as $key => $invoice_id) { ?>
2018 2018
                     <tr>
2019
-                        <th scope="row"><?php echo ( $key + 1 );?></th>
2020
-                        <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td>
2021
-                        <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td>
2022
-                        <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td>
2019
+                        <th scope="row"><?php echo ($key + 1); ?></th>
2020
+                        <td><?php echo wpinv_invoice_link($invoice_id); ?></td>
2021
+                        <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td>
2022
+                        <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td>
2023 2023
                     </tr>
2024 2024
                     <?php } ?>
2025 2025
                     <tr><td colspan="4" style="padding:0"></td></tr>
@@ -2031,52 +2031,52 @@  discard block
 block discarded – undo
2031 2031
     }
2032 2032
 }
2033 2033
 
2034
-function wpinv_cart_total_label( $label, $invoice ) {
2035
-    if ( empty( $invoice ) ) {
2034
+function wpinv_cart_total_label($label, $invoice) {
2035
+    if (empty($invoice)) {
2036 2036
         return $label;
2037 2037
     }
2038 2038
     
2039 2039
     $prefix_label = '';
2040
-    if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) {        
2041
-        $prefix_label   = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice );
2042
-    } else if ( $invoice->is_renewal() ) {
2043
-        $prefix_label   = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> ';        
2040
+    if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) {        
2041
+        $prefix_label   = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice);
2042
+    } else if ($invoice->is_renewal()) {
2043
+        $prefix_label   = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> ';        
2044 2044
     }
2045 2045
     
2046
-    if ( $prefix_label != '' ) {
2047
-        $label  = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2046
+    if ($prefix_label != '') {
2047
+        $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2048 2048
     }
2049 2049
     
2050 2050
     return $label;
2051 2051
 }
2052
-add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2053
-add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2054
-add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2052
+add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2053
+add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2054
+add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2055 2055
 
2056
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 );
2056
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1);
2057 2057
 
2058
-function wpinv_invoice_print_description( $invoice ) {
2059
-    if ( empty( $invoice ) ) {
2058
+function wpinv_invoice_print_description($invoice) {
2059
+    if (empty($invoice)) {
2060 2060
         return NULL;
2061 2061
     }
2062
-    if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) {
2062
+    if ($description = wpinv_get_invoice_description($invoice->ID)) {
2063 2063
         ?>
2064 2064
         <div class="row wpinv-lower">
2065 2065
             <div class="col-sm-12 wpinv-description">
2066
-                <?php echo wpautop( $description ); ?>
2066
+                <?php echo wpautop($description); ?>
2067 2067
             </div>
2068 2068
         </div>
2069 2069
         <?php
2070 2070
     }
2071 2071
 }
2072
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 );
2072
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1);
2073 2073
 
2074
-function wpinv_invoice_print_payment_info( $invoice ) {
2075
-    if ( empty( $invoice ) ) {
2074
+function wpinv_invoice_print_payment_info($invoice) {
2075
+    if (empty($invoice)) {
2076 2076
         return NULL;
2077 2077
     }
2078 2078
     
2079
-    if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) {
2079
+    if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) {
2080 2080
         ?>
2081 2081
         <div class="row wpinv-payments">
2082 2082
             <div class="col-sm-12">
@@ -2088,43 +2088,43 @@  discard block
 block discarded – undo
2088 2088
 }
2089 2089
 // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 );
2090 2090
 
2091
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
2092
-    if ( empty( $note ) ) {
2091
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
2092
+    if (empty($note)) {
2093 2093
         return NULL;
2094 2094
     }
2095 2095
     
2096
-    if ( is_int( $note ) ) {
2097
-        $note = get_comment( $note );
2096
+    if (is_int($note)) {
2097
+        $note = get_comment($note);
2098 2098
     }
2099 2099
     
2100
-    if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
2100
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
2101 2101
         return NULL;
2102 2102
     }
2103 2103
     
2104
-    $note_classes   = array( 'note' );
2105
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
2106
-    $note_classes[] = $note->comment_author === __( 'System', 'invoicing' ) ? 'system-note' : '';
2107
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
2108
-    $note_classes   = !empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
2104
+    $note_classes   = array('note');
2105
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
2106
+    $note_classes[] = $note->comment_author === __('System', 'invoicing') ? 'system-note' : '';
2107
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
2108
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
2109 2109
     
2110 2110
     ob_start();
2111 2111
     ?>
2112
-    <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>">
2112
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>">
2113 2113
         <div class="note_content">
2114
-            <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
2114
+            <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?>
2115 2115
         </div>
2116 2116
         <p class="meta">
2117
-            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr>&nbsp;&nbsp;
2118
-            <?php if($note->comment_author !== 'System') {?>
2119
-                <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a>
2117
+            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr>&nbsp;&nbsp;
2118
+            <?php if ($note->comment_author !== 'System') {?>
2119
+                <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
2120 2120
             <?php } ?>
2121 2121
         </p>
2122 2122
     </li>
2123 2123
     <?php
2124 2124
     $note_content = ob_get_clean();
2125
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
2125
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
2126 2126
     
2127
-    if ( $echo ) {
2127
+    if ($echo) {
2128 2128
         echo $note_content;
2129 2129
     } else {
2130 2130
         return $note_content;
Please login to merge, or discard this patch.
includes/wpinv-gd-functions.php 1 patch
Spacing   +266 added lines, -266 removed lines patch added patch discarded remove patch
@@ -1,23 +1,23 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 function wpinv_gd_active() {
8
-    return (bool)defined( 'GEODIRECTORY_VERSION' );
8
+    return (bool)defined('GEODIRECTORY_VERSION');
9 9
 }
10 10
 
11 11
 function wpinv_pm_active() {
12
-    return (bool)wpinv_gd_active() && (bool)defined( 'GEODIRPAYMENT_VERSION' );
12
+    return (bool)wpinv_gd_active() && (bool)defined('GEODIRPAYMENT_VERSION');
13 13
 }
14 14
 
15
-function wpinv_is_gd_post_type( $post_type ) {
15
+function wpinv_is_gd_post_type($post_type) {
16 16
     global $gd_posttypes;
17 17
     
18
-    $gd_posttypes = !empty( $gd_posttypes ) && is_array( $gd_posttypes ) ? $gd_posttypes : geodir_get_posttypes();
18
+    $gd_posttypes = !empty($gd_posttypes) && is_array($gd_posttypes) ? $gd_posttypes : geodir_get_posttypes();
19 19
     
20
-    if ( !empty( $post_type ) && !empty( $gd_posttypes ) && in_array( $post_type, $gd_posttypes ) ) {
20
+    if (!empty($post_type) && !empty($gd_posttypes) && in_array($post_type, $gd_posttypes)) {
21 21
         return true;
22 22
     }
23 23
     
@@ -29,10 +29,10 @@  discard block
 block discarded – undo
29 29
         return;
30 30
     }
31 31
     
32
-    if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
32
+    if (!(defined('DOING_AJAX') && DOING_AJAX)) {
33 33
         // Add  fields for force upgrade
34
-        if ( defined('INVOICE_TABLE') && !get_option('wpinv_gdp_column') ) {
35
-            geodir_add_column_if_not_exist( INVOICE_TABLE, 'invoice_id', 'INT( 11 ) NOT NULL DEFAULT 0' );
34
+        if (defined('INVOICE_TABLE') && !get_option('wpinv_gdp_column')) {
35
+            geodir_add_column_if_not_exist(INVOICE_TABLE, 'invoice_id', 'INT( 11 ) NOT NULL DEFAULT 0');
36 36
             
37 37
             update_option('wpinv_gdp_column', '1');
38 38
         }
@@ -40,39 +40,39 @@  discard block
 block discarded – undo
40 40
         wpinv_merge_gd_packages_to_items();
41 41
     }
42 42
 }
43
-add_action( 'admin_init', 'wpinv_geodir_integration' );
43
+add_action('admin_init', 'wpinv_geodir_integration');
44 44
 
45
-function wpinv_get_gdp_package_type( $item_types ) {
46
-    if ( wpinv_pm_active() ) {
47
-        $item_types['package'] = __( 'Package', 'invoicing' );
45
+function wpinv_get_gdp_package_type($item_types) {
46
+    if (wpinv_pm_active()) {
47
+        $item_types['package'] = __('Package', 'invoicing');
48 48
     }
49 49
         
50 50
     return $item_types;
51 51
 }
52
-add_filter( 'wpinv_get_item_types', 'wpinv_get_gdp_package_type', 10, 1 );
52
+add_filter('wpinv_get_item_types', 'wpinv_get_gdp_package_type', 10, 1);
53 53
 
54 54
 function wpinv_update_package_item($package_id) {
55 55
     return wpinv_merge_gd_package_to_item($package_id, true);
56 56
 }
57 57
 add_action('geodir_after_save_package', 'wpinv_update_package_item', 10, 1);
58 58
 
59
-function wpinv_merge_gd_packages_to_items( $force = false ) {    
60
-    if ( $merged = get_option( 'wpinv_merge_gd_packages' ) && !$force ) {
59
+function wpinv_merge_gd_packages_to_items($force = false) {    
60
+    if ($merged = get_option('wpinv_merge_gd_packages') && !$force) {
61 61
         return true;
62 62
     }
63 63
 
64
-    if(!function_exists('geodir_package_list_info')){
64
+    if (!function_exists('geodir_package_list_info')) {
65 65
         return false;
66 66
     }
67 67
     
68 68
     $packages = geodir_package_list_info();
69 69
     
70
-    foreach ( $packages as $key => $package ) {
71
-        wpinv_merge_gd_package_to_item( $package->pid, $force, $package );
70
+    foreach ($packages as $key => $package) {
71
+        wpinv_merge_gd_package_to_item($package->pid, $force, $package);
72 72
     }
73 73
     
74
-    if ( !$merged ) {
75
-        update_option( 'wpinv_merge_gd_packages', 1 );
74
+    if (!$merged) {
75
+        update_option('wpinv_merge_gd_packages', 1);
76 76
     }
77 77
     
78 78
     return true;
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 
102 102
     $package = empty($package) ? geodir_get_package_info_by_id($package_id, '') : $package;
103 103
 
104
-    if ( empty($package) || !wpinv_is_gd_post_type( $package->post_type ) ) {
104
+    if (empty($package) || !wpinv_is_gd_post_type($package->post_type)) {
105 105
         return false;
106 106
     }
107 107
         
@@ -110,17 +110,17 @@  discard block
 block discarded – undo
110 110
     $meta['custom_id']              = $package_id;
111 111
     $meta['custom_singular_name']   = get_post_type_singular_label($package->post_type);
112 112
     $meta['custom_name']            = get_post_type_plural_label($package->post_type);
113
-    $meta['price']                  = wpinv_round_amount( $package->amount );
113
+    $meta['price']                  = wpinv_round_amount($package->amount);
114 114
     $meta['vat_rule']               = 'digital';
115 115
     $meta['vat_class']              = '_standard';
116 116
     
117
-    if ( !empty( $package->sub_active ) ) {
118
-        $sub_num_trial_days = absint( $package->sub_num_trial_days );
117
+    if (!empty($package->sub_active)) {
118
+        $sub_num_trial_days = absint($package->sub_num_trial_days);
119 119
         
120 120
         $meta['is_recurring']       = 1;
121 121
         $meta['recurring_period']   = $package->sub_units;
122
-        $meta['recurring_interval'] = absint( $package->sub_units_num );
123
-        $meta['recurring_limit']    = absint( $package->sub_units_num_times );
122
+        $meta['recurring_interval'] = absint($package->sub_units_num);
123
+        $meta['recurring_limit']    = absint($package->sub_units_num_times);
124 124
         $meta['free_trial']         = $sub_num_trial_days > 0 ? 1 : 0;
125 125
         $meta['trial_period']       = $package->sub_num_trial_units;
126 126
         $meta['trial_interval']     = $sub_num_trial_days;
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
         $meta['trial_interval']     = '';
135 135
     }
136 136
     
137
-    $data  = array( 
137
+    $data = array( 
138 138
         'post_title'    => $package->title,
139 139
         'post_excerpt'  => $package->title_desc,
140 140
         'post_status'   => $package->status == 1 ? 'publish' : 'pending',
@@ -151,48 +151,48 @@  discard block
 block discarded – undo
151 151
     return $item;
152 152
 }
153 153
 
154
-function wpinv_gdp_to_wpi_gateway( $payment_method ) {
155
-    switch( $payment_method ) {
154
+function wpinv_gdp_to_wpi_gateway($payment_method) {
155
+    switch ($payment_method) {
156 156
         case 'prebanktransfer':
157 157
             $gateway = 'bank_transfer';
158 158
         break;
159 159
         default:
160
-            $gateway = empty( $payment_method ) ? 'manual' : $payment_method;
160
+            $gateway = empty($payment_method) ? 'manual' : $payment_method;
161 161
         break;
162 162
     }
163 163
     
164
-    return apply_filters( 'wpinv_gdp_to_wpi_gateway', $gateway, $payment_method );
164
+    return apply_filters('wpinv_gdp_to_wpi_gateway', $gateway, $payment_method);
165 165
 }
166 166
 
167
-function wpinv_gdp_to_wpi_gateway_title( $payment_method ) {
168
-    $gateway = wpinv_gdp_to_wpi_gateway( $payment_method );
167
+function wpinv_gdp_to_wpi_gateway_title($payment_method) {
168
+    $gateway = wpinv_gdp_to_wpi_gateway($payment_method);
169 169
     
170
-    $gateway_title = wpinv_get_gateway_checkout_label( $gateway );
170
+    $gateway_title = wpinv_get_gateway_checkout_label($gateway);
171 171
     
172
-    if ( $gateway == $gateway_title ) {
173
-        $gateway_title = geodir_payment_method_title( $gateway );
172
+    if ($gateway == $gateway_title) {
173
+        $gateway_title = geodir_payment_method_title($gateway);
174 174
     }
175 175
     
176
-    return apply_filters( 'wpinv_gdp_to_wpi_gateway_title', $gateway_title, $payment_method );
176
+    return apply_filters('wpinv_gdp_to_wpi_gateway_title', $gateway_title, $payment_method);
177 177
 }
178 178
 
179 179
 function wpinv_print_checkout_errors() {
180 180
     global $wpi_session;
181 181
     wpinv_print_errors();
182 182
 }
183
-add_action( 'geodir_checkout_page_content', 'wpinv_print_checkout_errors', -10 );
183
+add_action('geodir_checkout_page_content', 'wpinv_print_checkout_errors', -10);
184 184
 
185
-function wpinv_cpt_save( $invoice_id, $update = false, $pre_status = NULL ) {
185
+function wpinv_cpt_save($invoice_id, $update = false, $pre_status = NULL) {
186 186
     global $wpi_nosave, $wpi_zero_tax, $wpi_gdp_inv_merge;
187 187
     
188
-    $invoice_info = geodir_get_invoice( $invoice_id );
188
+    $invoice_info = geodir_get_invoice($invoice_id);
189 189
     
190
-    $wpi_invoice_id  = !empty( $invoice_info->invoice_id ) ? $invoice_info->invoice_id : 0;
190
+    $wpi_invoice_id  = !empty($invoice_info->invoice_id) ? $invoice_info->invoice_id : 0;
191 191
     
192 192
     if (!empty($invoice_info)) {
193
-        $wpi_invoice = $wpi_invoice_id > 0 ? wpinv_get_invoice( $wpi_invoice_id ) : NULL;
193
+        $wpi_invoice = $wpi_invoice_id > 0 ? wpinv_get_invoice($wpi_invoice_id) : NULL;
194 194
         
195
-        if ( !empty( $wpi_invoice ) ) { // update invoice
195
+        if (!empty($wpi_invoice)) { // update invoice
196 196
             $save = false;
197 197
             if ($invoice_info->coupon_code !== $wpi_invoice->discount_code || (float)$invoice_info->discount < (float)$wpi_invoice->discount || (float)$invoice_info->discount > (float)$wpi_invoice->discount) {
198 198
                 $save = true;
@@ -202,16 +202,16 @@  discard block
 block discarded – undo
202 202
             
203 203
             if ($invoice_info->paymentmethod !== $wpi_invoice->gateway) {
204 204
                 $save = true;
205
-                $gateway = !empty( $invoice_info->paymentmethod ) ? $invoice_info->paymentmethod : '';
206
-                $gateway = wpinv_gdp_to_wpi_gateway( $gateway );
207
-                $gateway_title = wpinv_gdp_to_wpi_gateway_title( $gateway );
208
-                $wpi_invoice->set('gateway', $gateway );
209
-                $wpi_invoice->set('gateway_title', $gateway_title );
205
+                $gateway = !empty($invoice_info->paymentmethod) ? $invoice_info->paymentmethod : '';
206
+                $gateway = wpinv_gdp_to_wpi_gateway($gateway);
207
+                $gateway_title = wpinv_gdp_to_wpi_gateway_title($gateway);
208
+                $wpi_invoice->set('gateway', $gateway);
209
+                $wpi_invoice->set('gateway_title', $gateway_title);
210 210
             }
211 211
             
212
-            if ( ( $status = wpinv_gdp_to_wpi_status( $invoice_info->status ) ) !== $wpi_invoice->status ) {
212
+            if (($status = wpinv_gdp_to_wpi_status($invoice_info->status)) !== $wpi_invoice->status) {
213 213
                 $save = true;
214
-                $wpi_invoice->set( 'status', $status );
214
+                $wpi_invoice->set('status', $status);
215 215
             }
216 216
             
217 217
             if ($save) {
@@ -222,16 +222,16 @@  discard block
 block discarded – undo
222 222
             
223 223
             return $wpi_invoice;
224 224
         } else { // create invoice
225
-            $user_info = get_userdata( $invoice_info->user_id );
225
+            $user_info = get_userdata($invoice_info->user_id);
226 226
             
227
-            if ( !empty( $pre_status ) ) {
227
+            if (!empty($pre_status)) {
228 228
                 $invoice_info->status = $pre_status;
229 229
             }
230
-            $status = wpinv_gdp_to_wpi_status( $invoice_info->status );
230
+            $status = wpinv_gdp_to_wpi_status($invoice_info->status);
231 231
             
232 232
             $wpi_zero_tax = false;
233 233
             
234
-            if ( $wpi_gdp_inv_merge && in_array( $status, array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
234
+            if ($wpi_gdp_inv_merge && in_array($status, array('publish', 'wpi-processing', 'wpi-renewal'))) {
235 235
                 $wpi_zero_tax = true;
236 236
             }
237 237
             
@@ -241,13 +241,13 @@  discard block
 block discarded – undo
241 241
             $invoice_data['user_id']        = $invoice_info->user_id;
242 242
             $invoice_data['created_via']    = 'API';
243 243
             
244
-            if ( !empty( $invoice_info->date ) ) {
245
-                $invoice_data['created_date']   = $invoice_info->date;
244
+            if (!empty($invoice_info->date)) {
245
+                $invoice_data['created_date'] = $invoice_info->date;
246 246
             }
247 247
             
248
-            $paymentmethod = !empty( $invoice_info->paymentmethod ) ? $invoice_info->paymentmethod : '';
249
-            $paymentmethod = wpinv_gdp_to_wpi_gateway( $paymentmethod );
250
-            $payment_method_title = wpinv_gdp_to_wpi_gateway_title( $paymentmethod );
248
+            $paymentmethod = !empty($invoice_info->paymentmethod) ? $invoice_info->paymentmethod : '';
249
+            $paymentmethod = wpinv_gdp_to_wpi_gateway($paymentmethod);
250
+            $payment_method_title = wpinv_gdp_to_wpi_gateway_title($paymentmethod);
251 251
             
252 252
             $invoice_data['payment_details'] = array( 
253 253
                 'gateway'           => $paymentmethod, 
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
                 'currency'          => geodir_get_currency_type(),
256 256
             );
257 257
             
258
-            $user_address = wpinv_get_user_address( $invoice_info->user_id, false );
258
+            $user_address = wpinv_get_user_address($invoice_info->user_id, false);
259 259
             
260 260
             $invoice_data['user_info'] = array( 
261 261
                 'user_id'       => $invoice_info->user_id, 
@@ -278,14 +278,14 @@  discard block
 block discarded – undo
278 278
             
279 279
             $post_item = wpinv_get_gd_package_item($invoice_info->package_id);
280 280
 
281
-            if ( $invoice_info->invoice_type == 'add_franchise' ) {
281
+            if ($invoice_info->invoice_type == 'add_franchise') {
282 282
                 $custom_price = $invoice_info->amount;
283 283
             } else {
284 284
                 $custom_price = '';
285 285
             }
286 286
 
287
-            if ( !empty( $post_item ) ) {
288
-                $cart_details  = array();
287
+            if (!empty($post_item)) {
288
+                $cart_details = array();
289 289
                 $cart_details[] = array(
290 290
                     'id'            => $post_item->ID,
291 291
                     'name'          => $post_item->get_name(),
@@ -299,19 +299,19 @@  discard block
 block discarded – undo
299 299
                     ),
300 300
                 );
301 301
                 
302
-                $invoice_data['cart_details']  = $cart_details;
302
+                $invoice_data['cart_details'] = $cart_details;
303 303
             }
304 304
 
305
-            $data = array( 'invoice' => $invoice_data );
305
+            $data = array('invoice' => $invoice_data);
306 306
 
307 307
             $wpinv_api = new WPInv_API();
308
-            $data = $wpinv_api->insert_invoice( $data );
308
+            $data = $wpinv_api->insert_invoice($data);
309 309
             
310
-            if ( is_wp_error( $data ) ) {
311
-                wpinv_error_log( 'WPInv_Invoice: ' . $data->get_error_message() );
310
+            if (is_wp_error($data)) {
311
+                wpinv_error_log('WPInv_Invoice: ' . $data->get_error_message());
312 312
             } else {
313
-                if ( !empty( $data ) ) {
314
-                    update_post_meta( $data->ID, '_wpinv_gdp_id', $invoice_id );
313
+                if (!empty($data)) {
314
+                    update_post_meta($data->ID, '_wpinv_gdp_id', $invoice_id);
315 315
                     
316 316
                     $update_data = array();
317 317
                     $update_data['tax_amount'] = $data->get_tax();
@@ -319,14 +319,14 @@  discard block
 block discarded – undo
319 319
                     $update_data['invoice_id'] = $data->ID;
320 320
                     
321 321
                     global $wpdb;
322
-                    $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $invoice_id ) );
322
+                    $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $invoice_id));
323 323
                     
324 324
                     return $data;
325 325
                 } else {
326
-                    if ( $update ) {
327
-                        wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to update invoice.', 'invoicing' ) );
326
+                    if ($update) {
327
+                        wpinv_error_log('WPInv_Invoice: ' . __('Fail to update invoice.', 'invoicing'));
328 328
                     } else {
329
-                        wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to create invoice.', 'invoicing' ) );
329
+                        wpinv_error_log('WPInv_Invoice: ' . __('Fail to create invoice.', 'invoicing'));
330 330
                     }
331 331
                 }
332 332
             }
@@ -337,59 +337,59 @@  discard block
 block discarded – undo
337 337
 }
338 338
 add_action('geodir_payment_invoice_created', 'wpinv_cpt_save', 11, 3);
339 339
 
340
-function wpinv_cpt_update( $invoice_id ) {
341
-    return wpinv_cpt_save( $invoice_id, true );
340
+function wpinv_cpt_update($invoice_id) {
341
+    return wpinv_cpt_save($invoice_id, true);
342 342
 }
343 343
 add_action('geodir_payment_invoice_updated', 'wpinv_cpt_update', 11, 1);
344 344
 
345
-function wpinv_payment_status_changed( $invoice_id, $new_status, $old_status = 'pending', $subscription = false ) {
346
-    $invoice_info = geodir_get_invoice( $invoice_id );
347
-    if ( empty( $invoice_info ) ) {
345
+function wpinv_payment_status_changed($invoice_id, $new_status, $old_status = 'pending', $subscription = false) {
346
+    $invoice_info = geodir_get_invoice($invoice_id);
347
+    if (empty($invoice_info)) {
348 348
         return false;
349 349
     }
350 350
 
351
-    $invoice = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL;
352
-    if ( !empty( $invoice ) ) {
351
+    $invoice = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL;
352
+    if (!empty($invoice)) {
353 353
         $new_status = wpinv_gdp_to_wpi_status($new_status);
354
-        $invoice    = wpinv_update_payment_status( $invoice->ID, $new_status );
354
+        $invoice    = wpinv_update_payment_status($invoice->ID, $new_status);
355 355
     } else {
356
-        $invoice = wpinv_cpt_save( $invoice_id );
356
+        $invoice = wpinv_cpt_save($invoice_id);
357 357
     }
358 358
     
359 359
     return $invoice;
360 360
 }
361
-add_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 );
361
+add_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4);
362 362
 
363
-function wpinv_transaction_details_note( $invoice_id, $html ) {
364
-    $invoice_info = geodir_get_invoice( $invoice_id );
365
-    if ( empty( $invoice_info ) ) {
363
+function wpinv_transaction_details_note($invoice_id, $html) {
364
+    $invoice_info = geodir_get_invoice($invoice_id);
365
+    if (empty($invoice_info)) {
366 366
         return false;
367 367
     }
368 368
 
369
-    $wpi_invoice_id = !empty( $invoice_info->invoice_id ) ? $invoice_info->invoice_id : NULL;
369
+    $wpi_invoice_id = !empty($invoice_info->invoice_id) ? $invoice_info->invoice_id : NULL;
370 370
     
371
-    if ( !$wpi_invoice_id ) {
372
-        $invoice = wpinv_cpt_save( $invoice_id, false, $old_status );
371
+    if (!$wpi_invoice_id) {
372
+        $invoice = wpinv_cpt_save($invoice_id, false, $old_status);
373 373
         
374
-        if ( !empty( $invoice ) ) {
374
+        if (!empty($invoice)) {
375 375
             $wpi_invoice_id = $invoice->ID;
376 376
         }
377 377
     }
378 378
 
379
-    $invoice = wpinv_get_invoice( $wpi_invoice_id );
379
+    $invoice = wpinv_get_invoice($wpi_invoice_id);
380 380
     
381
-    if ( empty( $invoice ) ) {
381
+    if (empty($invoice)) {
382 382
         return false;
383 383
     }
384 384
     
385
-    return $invoice->add_note( $html, true );
385
+    return $invoice->add_note($html, true);
386 386
 }
387
-add_action( 'geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2 );
387
+add_action('geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2);
388 388
 
389
-function wpinv_gdp_to_wpi_status( $status ) {
389
+function wpinv_gdp_to_wpi_status($status) {
390 390
     $inv_status = $status ? $status : 'pending';
391 391
     
392
-    switch ( $status ) {
392
+    switch ($status) {
393 393
         case 'confirmed':
394 394
             $inv_status = 'publish';
395 395
         break;
@@ -409,10 +409,10 @@  discard block
 block discarded – undo
409 409
     return $inv_status;
410 410
 }
411 411
 
412
-function wpinv_wpi_to_gdp_status( $status ) {
412
+function wpinv_wpi_to_gdp_status($status) {
413 413
     $inv_status = $status ? $status : 'pending';
414 414
     
415
-    switch ( $status ) {
415
+    switch ($status) {
416 416
         case 'publish':
417 417
         case 'wpi-processing':
418 418
         case 'wpi-renewal':
@@ -435,72 +435,72 @@  discard block
 block discarded – undo
435 435
     return $inv_status;
436 436
 }
437 437
 
438
-function wpinv_wpi_to_gdp_id( $invoice_id ) {
438
+function wpinv_wpi_to_gdp_id($invoice_id) {
439 439
     global $wpdb;
440 440
     
441
-    return $wpdb->get_var( $wpdb->prepare( "SELECT `id` FROM `" . INVOICE_TABLE . "` WHERE `invoice_id` = %d AND `invoice_id` > 0 ORDER BY id DESC LIMIT 1", array( (int)$invoice_id ) ) );
441
+    return $wpdb->get_var($wpdb->prepare("SELECT `id` FROM `" . INVOICE_TABLE . "` WHERE `invoice_id` = %d AND `invoice_id` > 0 ORDER BY id DESC LIMIT 1", array((int)$invoice_id)));
442 442
 }
443 443
 
444
-function wpinv_gdp_to_wpi_id( $invoice_id ) {
445
-    $invoice = geodir_get_invoice( $invoice_id );    
446
-    return ( empty( $invoice->invoice_id ) ? $invoice->invoice_id : false);
444
+function wpinv_gdp_to_wpi_id($invoice_id) {
445
+    $invoice = geodir_get_invoice($invoice_id);    
446
+    return (empty($invoice->invoice_id) ? $invoice->invoice_id : false);
447 447
 }
448 448
 
449
-function wpinv_to_gdp_recalculate_total( $invoice, $wpi_nosave ) {
449
+function wpinv_to_gdp_recalculate_total($invoice, $wpi_nosave) {
450 450
     global $wpdb;
451 451
     
452
-    if ( !empty( $wpi_nosave ) ) {
452
+    if (!empty($wpi_nosave)) {
453 453
         return;
454 454
     }
455 455
     
456
-    $gdp_invoice_id = wpinv_wpi_to_gdp_id( $invoice->ID );
456
+    $gdp_invoice_id = wpinv_wpi_to_gdp_id($invoice->ID);
457 457
     
458
-    if ( $gdp_invoice_id > 0 ) {
458
+    if ($gdp_invoice_id > 0) {
459 459
         $update_data = array();
460 460
         $update_data['tax_amount']      = $invoice->tax;
461 461
         $update_data['paied_amount']    = $invoice->total;
462 462
         $update_data['discount']        = $invoice->discount;
463 463
         $update_data['coupon_code']     = $invoice->discount_code;
464 464
         
465
-        $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $gdp_invoice_id ) );
465
+        $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $gdp_invoice_id));
466 466
     }
467 467
     
468 468
     return;
469 469
 }
470 470
 //add_action( 'wpinv_invoice_recalculate_total', 'wpinv_to_gdp_recalculate_total', 10, 2 );
471 471
 
472
-function wpinv_gdp_to_wpi_invoice( $invoice_id ) {
473
-    $invoice = geodir_get_invoice( $invoice_id );
474
-    if ( empty( $invoice->invoice_id ) ) {
472
+function wpinv_gdp_to_wpi_invoice($invoice_id) {
473
+    $invoice = geodir_get_invoice($invoice_id);
474
+    if (empty($invoice->invoice_id)) {
475 475
         return false;
476 476
     }
477 477
     
478
-    return wpinv_get_invoice( $invoice->invoice_id );
478
+    return wpinv_get_invoice($invoice->invoice_id);
479 479
 }
480 480
 
481
-function wpinv_payment_set_coupon_code( $status, $invoice_id, $coupon_code ) {
482
-    $invoice = wpinv_gdp_to_wpi_invoice( $invoice_id );
483
-    if ( empty( $invoice ) ) {
481
+function wpinv_payment_set_coupon_code($status, $invoice_id, $coupon_code) {
482
+    $invoice = wpinv_gdp_to_wpi_invoice($invoice_id);
483
+    if (empty($invoice)) {
484 484
         return $status;
485 485
     }
486 486
 
487
-    if ( $status === 1 || $status === 0 ) {
488
-        if ( $status === 1 ) {
489
-            $discount = geodir_get_discount_amount( $coupon_code, $invoice->get_subtotal() );
487
+    if ($status === 1 || $status === 0) {
488
+        if ($status === 1) {
489
+            $discount = geodir_get_discount_amount($coupon_code, $invoice->get_subtotal());
490 490
         } else {
491 491
             $discount = '';
492 492
             $coupon_code = '';
493 493
         }
494 494
         
495
-        $invoice->set( 'discount', $discount );
496
-        $invoice->set( 'discount_code', $coupon_code );
495
+        $invoice->set('discount', $discount);
496
+        $invoice->set('discount_code', $coupon_code);
497 497
         $invoice->save();
498 498
         $invoice->recalculate_total();
499 499
     }
500 500
     
501 501
     return $status;
502 502
 }
503
-add_filter( 'geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3 );
503
+add_filter('geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3);
504 504
 
505 505
 function wpinv_merge_gd_invoices() {
506 506
     if (!defined('GEODIRPAYMENT_VERSION')) {
@@ -508,157 +508,157 @@  discard block
 block discarded – undo
508 508
     }
509 509
     ?>
510 510
     <tr>
511
-        <td><?php _e( 'Merge Price Packages', 'invoicing' ); ?></td>
512
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing' ); ?></p></td>
513
-        <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
511
+        <td><?php _e('Merge Price Packages', 'invoicing'); ?></td>
512
+        <td><p><?php _e('Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing'); ?></p></td>
513
+        <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
514 514
     </tr>
515 515
     <tr>
516
-        <td><?php _e( 'Merge Invoices', 'invoicing' ); ?></td>
517
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing' ); ?></p></td>
518
-        <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
516
+        <td><?php _e('Merge Invoices', 'invoicing'); ?></td>
517
+        <td><p><?php _e('Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing'); ?></p></td>
518
+        <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
519 519
     </tr>
520 520
 	<tr>
521
-        <td><?php _e( 'Fix Taxes for Merged Invoices', 'invoicing' ); ?></td>
522
-        <td><p><?php _e( 'Fix taxes for NON-PAID invoices which are merged before, from GeoDirectory Payment Manager invoices to Invoicing. This will recalculate taxes for non-paid merged invoices.', 'invoicing' ); ?></p></td>
523
-        <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
521
+        <td><?php _e('Fix Taxes for Merged Invoices', 'invoicing'); ?></td>
522
+        <td><p><?php _e('Fix taxes for NON-PAID invoices which are merged before, from GeoDirectory Payment Manager invoices to Invoicing. This will recalculate taxes for non-paid merged invoices.', 'invoicing'); ?></p></td>
523
+        <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
524 524
     </tr>
525 525
     <tr>
526
-        <td><?php _e( 'Merge Coupons', 'invoicing' ); ?></td>
527
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing' ); ?></p></td>
528
-        <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
526
+        <td><?php _e('Merge Coupons', 'invoicing'); ?></td>
527
+        <td><p><?php _e('Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing'); ?></p></td>
528
+        <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
529 529
     </tr>
530 530
     <?php
531 531
 }
532
-add_action( 'wpinv_tools_row', 'wpinv_merge_gd_invoices', 10 );
532
+add_action('wpinv_tools_row', 'wpinv_merge_gd_invoices', 10);
533 533
 
534 534
 function wpinv_tool_merge_packages() {
535 535
     $packages = geodir_package_list_info();
536 536
     
537 537
     $count = 0;
538 538
     
539
-    if ( !empty( $packages ) ) {
539
+    if (!empty($packages)) {
540 540
         $success = true;
541 541
         
542
-        foreach ( $packages as $key => $package ) {
542
+        foreach ($packages as $key => $package) {
543 543
             $item = wpinv_get_item_by('custom_id', $package->pid, 'package');
544
-            if ( !empty( $item ) ) {
544
+            if (!empty($item)) {
545 545
                 continue;
546 546
             }
547 547
             
548
-            $merged = wpinv_merge_gd_package_to_item( $package->pid, false, $package );
548
+            $merged = wpinv_merge_gd_package_to_item($package->pid, false, $package);
549 549
             
550
-            if ( !empty( $merged ) ) {
551
-                wpinv_error_log( 'Package merge S : ' . $package->pid );
550
+            if (!empty($merged)) {
551
+                wpinv_error_log('Package merge S : ' . $package->pid);
552 552
                 $count++;
553 553
             } else {
554
-                wpinv_error_log( 'Package merge F : ' . $package->pid );
554
+                wpinv_error_log('Package merge F : ' . $package->pid);
555 555
             }
556 556
         }
557 557
         
558
-        if ( $count > 0 ) {
559
-            $message = sprintf( _n( 'Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing' ), $count );
558
+        if ($count > 0) {
559
+            $message = sprintf(_n('Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing'), $count);
560 560
         } else {
561
-            $message = __( 'No price packages merged.', 'invoicing' );
561
+            $message = __('No price packages merged.', 'invoicing');
562 562
         }
563 563
     } else {
564 564
         $success = false;
565
-        $message = __( 'No price packages found to merge!', 'invoicing' );
565
+        $message = __('No price packages found to merge!', 'invoicing');
566 566
     }
567 567
     
568 568
     $response = array();
569 569
     $response['success'] = $success;
570 570
     $response['data']['message'] = $message;
571
-    wp_send_json( $response );
571
+    wp_send_json($response);
572 572
 }
573
-add_action( 'wpinv_tool_merge_packages', 'wpinv_tool_merge_packages' );
573
+add_action('wpinv_tool_merge_packages', 'wpinv_tool_merge_packages');
574 574
 
575 575
 function wpinv_tool_merge_invoices() {
576 576
     global $wpdb, $wpi_gdp_inv_merge, $wpi_tax_rates;
577 577
     
578 578
     $sql = "SELECT `gdi`.`id`, `gdi`.`date`, `gdi`.`date_updated` FROM `" . INVOICE_TABLE . "` AS gdi LEFT JOIN `" . $wpdb->posts . "` AS p ON `p`.`ID` = `gdi`.`invoice_id` AND `p`.`post_type` = 'wpi_invoice' WHERE `p`.`ID` IS NULL ORDER BY `gdi`.`id` ASC";
579 579
 
580
-    $items = $wpdb->get_results( $sql );
580
+    $items = $wpdb->get_results($sql);
581 581
     
582 582
     $count = 0;
583 583
     
584
-    if ( !empty( $items ) ) {
584
+    if (!empty($items)) {
585 585
         $success = true;
586 586
         $wpi_gdp_inv_merge = true;
587 587
         
588
-        foreach ( $items as $item ) {
588
+        foreach ($items as $item) {
589 589
             $wpi_tax_rates = NULL;
590 590
             
591
-            $wpdb->query( "UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'" );
591
+            $wpdb->query("UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'");
592 592
             
593
-            $merged = wpinv_cpt_save( $item->id );
593
+            $merged = wpinv_cpt_save($item->id);
594 594
             
595
-            if ( !empty( $merged ) && !empty( $merged->ID ) ) {
595
+            if (!empty($merged) && !empty($merged->ID)) {
596 596
                 $count++;
597 597
                 
598
-                $post_date = !empty( $item->date ) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time( 'mysql' );
599
-                $post_date_gmt = get_gmt_from_date( $post_date );
600
-                $post_modified = !empty( $item->date_updated ) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date;
601
-                $post_modified_gmt = get_gmt_from_date( $post_modified );
598
+                $post_date = !empty($item->date) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time('mysql');
599
+                $post_date_gmt = get_gmt_from_date($post_date);
600
+                $post_modified = !empty($item->date_updated) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date;
601
+                $post_modified_gmt = get_gmt_from_date($post_modified);
602 602
                 
603
-                $wpdb->update( $wpdb->posts, array( 'post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified_gmt ), array( 'ID' => $merged->ID ) );
603
+                $wpdb->update($wpdb->posts, array('post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified_gmt), array('ID' => $merged->ID));
604 604
                 
605
-                if ( $merged->is_paid() ) {
606
-                    update_post_meta( $merged->ID, '_wpinv_completed_date', $post_modified );
605
+                if ($merged->is_paid()) {
606
+                    update_post_meta($merged->ID, '_wpinv_completed_date', $post_modified);
607 607
                 }
608 608
                 
609
-                clean_post_cache( $merged->ID );
609
+                clean_post_cache($merged->ID);
610 610
                 
611
-                wpinv_error_log( 'Invoice merge S : ' . $item->id . ' => ' . $merged->ID );
611
+                wpinv_error_log('Invoice merge S : ' . $item->id . ' => ' . $merged->ID);
612 612
             } else {
613
-                wpinv_error_log( 'Invoice merge F : ' . $item->id );
613
+                wpinv_error_log('Invoice merge F : ' . $item->id);
614 614
             }
615 615
         }
616 616
         
617 617
         $wpi_gdp_inv_merge = false;
618 618
         
619
-        if ( $count > 0 ) {
620
-            $message = sprintf( _n( 'Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing' ), $count );
619
+        if ($count > 0) {
620
+            $message = sprintf(_n('Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing'), $count);
621 621
         } else {
622
-            $message = __( 'No invoices merged.', 'invoicing' );
622
+            $message = __('No invoices merged.', 'invoicing');
623 623
         }
624 624
     } else {
625 625
         $success = false;
626
-        $message = __( 'No invoices found to merge!', 'invoicing' );
626
+        $message = __('No invoices found to merge!', 'invoicing');
627 627
     }
628 628
     
629 629
     $response = array();
630 630
     $response['success'] = $success;
631 631
     $response['data']['message'] = $message;
632
-    wp_send_json( $response );
632
+    wp_send_json($response);
633 633
 }
634
-add_action( 'wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices' );
634
+add_action('wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices');
635 635
 
636 636
 function wpinv_tool_merge_coupons() {
637 637
     global $wpdb;
638 638
     
639 639
     $sql = "SELECT * FROM `" . COUPON_TABLE . "` WHERE `coupon_code` IS NOT NULL AND `coupon_code` != '' ORDER BY `cid` ASC";
640
-    $items = $wpdb->get_results( $sql );
640
+    $items = $wpdb->get_results($sql);
641 641
     $count = 0;
642 642
     
643
-    if ( !empty( $items ) ) {
643
+    if (!empty($items)) {
644 644
         $success = true;
645 645
         
646
-        foreach ( $items as $item ) {
647
-            if ( wpinv_get_discount_by_code( $item->coupon_code ) ) {
646
+        foreach ($items as $item) {
647
+            if (wpinv_get_discount_by_code($item->coupon_code)) {
648 648
                 continue;
649 649
             }
650 650
             
651 651
             $args = array(
652 652
                 'post_type'   => 'wpi_discount',
653 653
                 'post_title'  => $item->coupon_code,
654
-                'post_status' => !empty( $item->status ) ? 'publish' : 'pending'
654
+                'post_status' => !empty($item->status) ? 'publish' : 'pending'
655 655
             );
656 656
 
657
-            $merged = wp_insert_post( $args );
657
+            $merged = wp_insert_post($args);
658 658
             
659 659
             $item_id = $item->cid;
660 660
             
661
-            if ( $merged ) {
661
+            if ($merged) {
662 662
                 $meta = array(
663 663
                     'code'              => $item->coupon_code,
664 664
                     'type'              => $item->discount_type != 'per' ? 'flat' : 'percent',
@@ -666,65 +666,65 @@  discard block
 block discarded – undo
666 666
                     'max_uses'          => (int)$item->usage_limit,
667 667
                     'uses'              => (int)$item->usage_count,
668 668
                 );
669
-                wpinv_store_discount( $merged, $meta, get_post( $merged ) );
669
+                wpinv_store_discount($merged, $meta, get_post($merged));
670 670
                 
671 671
                 $count++;
672 672
                 
673
-                wpinv_error_log( 'Coupon merge S : ' . $item_id . ' => ' . $merged );
673
+                wpinv_error_log('Coupon merge S : ' . $item_id . ' => ' . $merged);
674 674
             } else {
675
-                wpinv_error_log( 'Coupon merge F : ' . $item_id );
675
+                wpinv_error_log('Coupon merge F : ' . $item_id);
676 676
             }
677 677
         }
678 678
         
679
-        if ( $count > 0 ) {
680
-            $message = sprintf( _n( 'Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing' ), $count );
679
+        if ($count > 0) {
680
+            $message = sprintf(_n('Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing'), $count);
681 681
         } else {
682
-            $message = __( 'No coupons merged.', 'invoicing' );
682
+            $message = __('No coupons merged.', 'invoicing');
683 683
         }
684 684
     } else {
685 685
         $success = false;
686
-        $message = __( 'No coupons found to merge!', 'invoicing' );
686
+        $message = __('No coupons found to merge!', 'invoicing');
687 687
     }
688 688
     
689 689
     $response = array();
690 690
     $response['success'] = $success;
691 691
     $response['data']['message'] = $message;
692
-    wp_send_json( $response );
692
+    wp_send_json($response);
693 693
 }
694
-add_action( 'wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons' );
694
+add_action('wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons');
695 695
 
696
-function wpinv_gdp_to_wpi_currency( $value, $option = '' ) {
696
+function wpinv_gdp_to_wpi_currency($value, $option = '') {
697 697
     return wpinv_get_currency();
698 698
 }
699
-add_filter( 'pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2 );
699
+add_filter('pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2);
700 700
 
701
-function wpinv_gdp_to_wpi_currency_sign( $value, $option = '' ) {
701
+function wpinv_gdp_to_wpi_currency_sign($value, $option = '') {
702 702
     return wpinv_currency_symbol();
703 703
 }
704
-add_filter( 'pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2 );
704
+add_filter('pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2);
705 705
 
706
-function wpinv_gdp_to_wpi_display_price( $price, $amount, $display = true , $decimal_sep, $thousand_sep ) {
707
-    if ( !$display ) {
708
-        $price = wpinv_round_amount( $amount );
706
+function wpinv_gdp_to_wpi_display_price($price, $amount, $display = true, $decimal_sep, $thousand_sep) {
707
+    if (!$display) {
708
+        $price = wpinv_round_amount($amount);
709 709
     } else {
710
-        $price = wpinv_price( wpinv_format_amount( $amount ) );
710
+        $price = wpinv_price(wpinv_format_amount($amount));
711 711
     }
712 712
     
713 713
     return $price;
714 714
 }
715
-add_filter( 'geodir_payment_price' , 'wpinv_gdp_to_wpi_display_price', 10000, 5 );
715
+add_filter('geodir_payment_price', 'wpinv_gdp_to_wpi_display_price', 10000, 5);
716 716
 
717
-function wpinv_gdp_to_inv_checkout_redirect( $redirect_url ) {
717
+function wpinv_gdp_to_inv_checkout_redirect($redirect_url) {
718 718
     $invoice_id         = geodir_payment_cart_id();
719
-    $invoice_info       = geodir_get_invoice( $invoice_id );
720
-    $wpi_invoice        = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL;
719
+    $invoice_info       = geodir_get_invoice($invoice_id);
720
+    $wpi_invoice        = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL;
721 721
     
722
-    if ( !( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) ) {
723
-        $wpi_invoice_id = wpinv_cpt_save( $invoice_id );
724
-        $wpi_invoice    = wpinv_get_invoice( $wpi_invoice_id );
722
+    if (!(!empty($wpi_invoice) && !empty($wpi_invoice->ID))) {
723
+        $wpi_invoice_id = wpinv_cpt_save($invoice_id);
724
+        $wpi_invoice    = wpinv_get_invoice($wpi_invoice_id);
725 725
     }
726 726
     
727
-    if ( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) {
727
+    if (!empty($wpi_invoice) && !empty($wpi_invoice->ID)) {
728 728
         
729 729
         // Clear cart
730 730
         geodir_payment_clear_cart();
@@ -734,121 +734,121 @@  discard block
 block discarded – undo
734 734
     
735 735
     return $redirect_url;
736 736
 }
737
-add_filter( 'geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1 );
737
+add_filter('geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1);
738 738
 
739
-function wpinv_gdp_dashboard_invoice_history_link( $dashboard_links ) {    
740
-    if ( get_current_user_id() ) {        
741
-        $dashboard_links .= '<li><i class="fa fa-shopping-cart"></i><a class="gd-invoice-link" href="' . esc_url( wpinv_get_history_page_uri() ) . '">' . __( 'My Invoice History', 'invoicing' ) . '</a></li>';
739
+function wpinv_gdp_dashboard_invoice_history_link($dashboard_links) {    
740
+    if (get_current_user_id()) {        
741
+        $dashboard_links .= '<li><i class="fa fa-shopping-cart"></i><a class="gd-invoice-link" href="' . esc_url(wpinv_get_history_page_uri()) . '">' . __('My Invoice History', 'invoicing') . '</a></li>';
742 742
     }
743 743
 
744 744
     return $dashboard_links;
745 745
 }
746
-add_action( 'geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link' );
747
-remove_action( 'geodir_dashboard_links', 'geodir_payment_invoices_list_page_link' );
746
+add_action('geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link');
747
+remove_action('geodir_dashboard_links', 'geodir_payment_invoices_list_page_link');
748 748
 
749
-function wpinv_wpi_to_gdp_update_status( $invoice_id, $new_status, $old_status ) {
749
+function wpinv_wpi_to_gdp_update_status($invoice_id, $new_status, $old_status) {
750 750
     if (!defined('GEODIRPAYMENT_VERSION')) {
751 751
         return false;
752 752
     }
753 753
     
754
-    $invoice    = wpinv_get_invoice( $invoice_id );
755
-    if ( empty( $invoice ) ) {
754
+    $invoice = wpinv_get_invoice($invoice_id);
755
+    if (empty($invoice)) {
756 756
         return false;
757 757
     }
758 758
     
759
-    remove_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 );
759
+    remove_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4);
760 760
     
761
-    $invoice_id = wpinv_wpi_to_gdp_id( $invoice_id );
762
-    $new_status = wpinv_wpi_to_gdp_status( $new_status );
761
+    $invoice_id = wpinv_wpi_to_gdp_id($invoice_id);
762
+    $new_status = wpinv_wpi_to_gdp_status($new_status);
763 763
     
764
-    geodir_update_invoice_status( $invoice_id, $new_status, $invoice->is_recurring() );
764
+    geodir_update_invoice_status($invoice_id, $new_status, $invoice->is_recurring());
765 765
 }
766
-add_action( 'wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3 );
766
+add_action('wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3);
767 767
 
768
-function wpinv_gdp_to_wpi_delete_package( $gd_package_id ) {
769
-    $item = wpinv_get_item_by( 'custom_id', $gd_package_id, 'package' );
768
+function wpinv_gdp_to_wpi_delete_package($gd_package_id) {
769
+    $item = wpinv_get_item_by('custom_id', $gd_package_id, 'package');
770 770
     
771
-    if ( !empty( $item ) ) {
772
-        wpinv_remove_item( $item, true );
771
+    if (!empty($item)) {
772
+        wpinv_remove_item($item, true);
773 773
     }
774 774
 }
775
-add_action( 'geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1 ) ;
775
+add_action('geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1);
776 776
 
777
-function wpinv_can_delete_package_item( $return, $post_id ) {
778
-    if ( $return && function_exists( 'geodir_get_package_info_by_id' ) && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' && $package_id = get_post_meta( $post_id, '_wpinv_custom_id', true ) ) {
779
-        $gd_package = geodir_get_package_info_by_id( $package_id, '' );
777
+function wpinv_can_delete_package_item($return, $post_id) {
778
+    if ($return && function_exists('geodir_get_package_info_by_id') && get_post_meta($post_id, '_wpinv_type', true) == 'package' && $package_id = get_post_meta($post_id, '_wpinv_custom_id', true)) {
779
+        $gd_package = geodir_get_package_info_by_id($package_id, '');
780 780
         
781
-        if ( !empty( $gd_package ) ) {
781
+        if (!empty($gd_package)) {
782 782
             $return = false;
783 783
         }
784 784
     }
785 785
 
786 786
     return $return;
787 787
 }
788
-add_filter( 'wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2 );
788
+add_filter('wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2);
789 789
 
790
-function wpinv_package_item_classes( $classes, $class, $post_id ) {
790
+function wpinv_package_item_classes($classes, $class, $post_id) {
791 791
     global $typenow;
792 792
 
793
-    if ( $typenow == 'wpi_item' && in_array( 'wpi-gd-package', $classes ) ) {
794
-        if ( wpinv_item_in_use( $post_id ) ) {
793
+    if ($typenow == 'wpi_item' && in_array('wpi-gd-package', $classes)) {
794
+        if (wpinv_item_in_use($post_id)) {
795 795
             $classes[] = 'wpi-inuse-pkg';
796
-        } else if ( !( function_exists( 'geodir_get_package_info_by_id' ) && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' && geodir_get_package_info_by_id( (int)get_post_meta( $post_id, '_wpinv_custom_id', true ), '' ) ) ) {
796
+        } else if (!(function_exists('geodir_get_package_info_by_id') && get_post_meta($post_id, '_wpinv_type', true) == 'package' && geodir_get_package_info_by_id((int)get_post_meta($post_id, '_wpinv_custom_id', true), ''))) {
797 797
             $classes[] = 'wpi-delete-pkg';
798 798
         }
799 799
     }
800 800
 
801 801
     return $classes;
802 802
 }
803
-add_filter( 'post_class', 'wpinv_package_item_classes', 10, 3 );
803
+add_filter('post_class', 'wpinv_package_item_classes', 10, 3);
804 804
 
805
-function wpinv_gdp_package_type_info( $post ) {
806
-    if ( wpinv_pm_active() ) {
807
-        ?><p class="wpi-m0"><?php _e( 'Package: GeoDirectory price packages items.', 'invoicing' );?></p>
805
+function wpinv_gdp_package_type_info($post) {
806
+    if (wpinv_pm_active()) {
807
+        ?><p class="wpi-m0"><?php _e('Package: GeoDirectory price packages items.', 'invoicing'); ?></p>
808 808
         <?php
809 809
     }
810 810
 }
811
-add_action( 'wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1 ) ;
811
+add_action('wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1);
812 812
 
813
-function wpinv_gdp_to_gdi_set_zero_tax( $is_taxable, $item_id, $country , $state ) {
813
+function wpinv_gdp_to_gdi_set_zero_tax($is_taxable, $item_id, $country, $state) {
814 814
     global $wpi_zero_tax;
815 815
 
816
-    if ( $wpi_zero_tax ) {
816
+    if ($wpi_zero_tax) {
817 817
         $is_taxable = false;
818 818
     }
819 819
 
820 820
     return $is_taxable;
821 821
 }
822
-add_action( 'wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4 ) ;
822
+add_action('wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4);
823 823
 
824 824
 function wpinv_tool_merge_fix_taxes() {
825 825
     global $wpdb;
826 826
     
827 827
 	$sql = "SELECT DISTINCT p.ID FROM `" . $wpdb->posts . "` AS p LEFT JOIN " . $wpdb->postmeta . " AS pm ON pm.post_id = p.ID WHERE p.post_type = 'wpi_item' AND pm.meta_key = '_wpinv_type' AND pm.meta_value = 'package'";
828
-	$items = $wpdb->get_results( $sql );
828
+	$items = $wpdb->get_results($sql);
829 829
 	
830
-	if ( !empty( $items ) ) {
831
-		foreach ( $items as $item ) {
832
-			if ( get_post_meta( $item->ID, '_wpinv_vat_class', true ) == '_exempt' ) {
833
-				update_post_meta( $item->ID, '_wpinv_vat_class', '_standard' );
830
+	if (!empty($items)) {
831
+		foreach ($items as $item) {
832
+			if (get_post_meta($item->ID, '_wpinv_vat_class', true) == '_exempt') {
833
+				update_post_meta($item->ID, '_wpinv_vat_class', '_standard');
834 834
 			}
835 835
 		}
836 836
 	}
837 837
 		
838 838
     $sql = "SELECT `p`.`ID`, gdi.id AS gdp_id FROM `" . INVOICE_TABLE . "` AS gdi LEFT JOIN `" . $wpdb->posts . "` AS p ON `p`.`ID` = `gdi`.`invoice_id` AND `p`.`post_type` = 'wpi_invoice' WHERE `p`.`ID` IS NOT NULL AND p.post_status NOT IN( 'publish', 'wpi-processing', 'wpi-renewal' ) ORDER BY `gdi`.`id` ASC";
839
-    $items = $wpdb->get_results( $sql );
839
+    $items = $wpdb->get_results($sql);
840 840
 	
841
-	if ( !empty( $items ) ) {
841
+	if (!empty($items)) {
842 842
 		$success = false;
843
-        $message = __( 'Taxes fixed for non-paid merged GD invoices.', 'invoicing' );
843
+        $message = __('Taxes fixed for non-paid merged GD invoices.', 'invoicing');
844 844
 		
845 845
 		global $wpi_userID, $wpinv_ip_address_country, $wpi_tax_rates;
846 846
 		
847
-		foreach ( $items as $item ) {
847
+		foreach ($items as $item) {
848 848
 			$wpi_tax_rates = NULL;               
849 849
 			$data = wpinv_get_invoice($item->ID);
850 850
 
851
-			if ( empty( $data ) ) {
851
+			if (empty($data)) {
852 852
 				continue;
853 853
 			}
854 854
 			
@@ -856,51 +856,51 @@  discard block
 block discarded – undo
856 856
 			
857 857
 			$data_session                   = array();
858 858
 			$data_session['invoice_id']     = $data->ID;
859
-			$data_session['cart_discounts'] = $data->get_discounts( true );
859
+			$data_session['cart_discounts'] = $data->get_discounts(true);
860 860
 			
861
-			wpinv_set_checkout_session( $data_session );
861
+			wpinv_set_checkout_session($data_session);
862 862
 			
863 863
 			$wpi_userID         = (int)$data->get_user_id();
864 864
 			$_POST['country']   = !empty($data->country) ? $data->country : wpinv_get_default_country();
865 865
 				
866
-			$data->country      = sanitize_text_field( $_POST['country'] );
867
-			$data->set( 'country', sanitize_text_field( $_POST['country'] ) );
866
+			$data->country      = sanitize_text_field($_POST['country']);
867
+			$data->set('country', sanitize_text_field($_POST['country']));
868 868
 			
869 869
 			$wpinv_ip_address_country = $data->country;
870 870
 			
871 871
 			$data->recalculate_totals(true);
872 872
 			
873
-			wpinv_set_checkout_session( $checkout_session );
873
+			wpinv_set_checkout_session($checkout_session);
874 874
 			
875 875
 			$update_data = array();
876 876
 			$update_data['tax_amount'] = $data->get_tax();
877 877
 			$update_data['paied_amount'] = $data->get_total();
878 878
 			$update_data['invoice_id'] = $data->ID;
879 879
 			
880
-			$wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $item->gdp_id ) );
880
+			$wpdb->update(INVOICE_TABLE, $update_data, array('id' => $item->gdp_id));
881 881
 		}
882 882
 	} else {
883 883
         $success = false;
884
-        $message = __( 'No invoices found to fix taxes!', 'invoicing' );
884
+        $message = __('No invoices found to fix taxes!', 'invoicing');
885 885
     }
886 886
 	
887 887
 	$response = array();
888 888
     $response['success'] = $success;
889 889
     $response['data']['message'] = $message;
890
-    wp_send_json( $response );
890
+    wp_send_json($response);
891 891
 }
892
-add_action( 'wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes' );
893
-remove_action( 'geodir_before_detail_fields' , 'geodir_build_coupon', 2 );
892
+add_action('wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes');
893
+remove_action('geodir_before_detail_fields', 'geodir_build_coupon', 2);
894 894
 
895
-function wpinv_wpi_to_gdp_handle_subscription_cancel( $invoice_id, $invoice ) {
896
-    if ( wpinv_pm_active() && !empty( $invoice ) && $invoice->is_recurring() ) {
897
-        if ( $invoice->is_renewal() ) {
895
+function wpinv_wpi_to_gdp_handle_subscription_cancel($invoice_id, $invoice) {
896
+    if (wpinv_pm_active() && !empty($invoice) && $invoice->is_recurring()) {
897
+        if ($invoice->is_renewal()) {
898 898
             $invoice = $invoice->get_parent_payment();
899 899
         }
900 900
         
901
-        if ( !empty( $invoice ) ) {
902
-            wpinv_wpi_to_gdp_update_status( $invoice->ID, 'wpi-cancelled', $invoice->get_status() );
901
+        if (!empty($invoice)) {
902
+            wpinv_wpi_to_gdp_update_status($invoice->ID, 'wpi-cancelled', $invoice->get_status());
903 903
         }
904 904
     }
905 905
 }
906
-add_action( 'wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2 );
907 906
\ No newline at end of file
907
+add_action('wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2);
908 908
\ No newline at end of file
Please login to merge, or discard this patch.