Completed
Push — master ( c72cea...2f3eab )
by Stiofan
18s
created
includes/wpinv-helper-functions.php 2 patches
Doc Comments   +25 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,6 +31,9 @@  discard block
 block discarded – undo
31 31
     return apply_filters( 'wpinv_get_ip', $ip );
32 32
 }
33 33
 
34
+/**
35
+ * @return string
36
+ */
34 37
 function wpinv_get_user_agent() {
35 38
     if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
36 39
         $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
@@ -110,6 +113,9 @@  discard block
 block discarded – undo
110 113
     return $status;
111 114
 }
112 115
 
116
+/**
117
+ * @return string
118
+ */
113 119
 function wpinv_get_currency() {
114 120
     $currency = wpinv_get_option( 'currency', 'USD' );
115 121
     
@@ -180,6 +186,9 @@  discard block
 block discarded – undo
180 186
     return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
181 187
 }
182 188
 
189
+/**
190
+ * @return string
191
+ */
183 192
 function wpinv_currency_position() {
184 193
     $position = wpinv_get_option( 'currency_position', 'left' );
185 194
     
@@ -198,6 +207,9 @@  discard block
 block discarded – undo
198 207
     return apply_filters( 'wpinv_decimal_separator', $decimal_sep );
199 208
 }
200 209
 
210
+/**
211
+ * @return integer
212
+ */
201 213
 function wpinv_decimals() {
202 214
     $decimals = apply_filters( 'wpinv_decimals', wpinv_get_option( 'decimals', 2 ) );
203 215
     
@@ -308,6 +320,9 @@  discard block
 block discarded – undo
308 320
     return $price;
309 321
 }
310 322
 
323
+/**
324
+ * @return string
325
+ */
311 326
 function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) {
312 327
     $thousands_sep = wpinv_thousands_separator();
313 328
     $decimal_sep   = wpinv_decimal_separator();
@@ -357,6 +372,9 @@  discard block
 block discarded – undo
357 372
     return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
358 373
 }
359 374
 
375
+/**
376
+ * @return string
377
+ */
360 378
 function wpinv_get_file_extension( $str ) {
361 379
     $parts = explode( '.', $str );
362 380
     return end( $parts );
@@ -561,6 +579,9 @@  discard block
 block discarded – undo
561 579
     return strlen( $str );
562 580
 }
563 581
 
582
+/**
583
+ * @param string $str
584
+ */
564 585
 function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
565 586
     if ( function_exists( 'mb_strtolower' ) ) {
566 587
         return mb_strtolower( $str, $encoding );
@@ -569,6 +590,9 @@  discard block
 block discarded – undo
569 590
     return strtolower( $str );
570 591
 }
571 592
 
593
+/**
594
+ * @param string $str
595
+ */
572 596
 function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
573 597
     if ( function_exists( 'mb_strtoupper' ) ) {
574 598
         return mb_strtoupper( $str, $encoding );
@@ -646,7 +670,7 @@  discard block
 block discarded – undo
646 670
  *
647 671
  * @param string $str The string being decoded.
648 672
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
649
- * @return string The width of string.
673
+ * @return integer The width of string.
650 674
  */
651 675
 function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
652 676
     if ( function_exists( 'mb_strwidth' ) ) {
Please login to merge, or discard this patch.
Spacing   +239 added lines, -239 removed lines patch added patch discarded remove patch
@@ -7,121 +7,121 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_item_quantities_enabled() {
15
-    $ret = wpinv_get_option( 'item_quantities', true );
15
+    $ret = wpinv_get_option('item_quantities', true);
16 16
     
17
-    return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret );
17
+    return (bool)apply_filters('wpinv_item_quantities_enabled', $ret);
18 18
 }
19 19
 
20 20
 function wpinv_get_ip() {
21 21
     $ip = '127.0.0.1';
22 22
 
23
-    if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
24
-        $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] );
25
-    } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
26
-        $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] );
27
-    } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) {
28
-        $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
23
+    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
24
+        $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']);
25
+    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
26
+        $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']);
27
+    } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
28
+        $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']);
29 29
     }
30 30
     
31
-    return apply_filters( 'wpinv_get_ip', $ip );
31
+    return apply_filters('wpinv_get_ip', $ip);
32 32
 }
33 33
 
34 34
 function wpinv_get_user_agent() {
35
-    if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
36
-        $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
35
+    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
36
+        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
37 37
     } else {
38 38
         $user_agent = '';
39 39
     }
40 40
     
41
-    return apply_filters( 'wpinv_get_user_agent', $user_agent );
41
+    return apply_filters('wpinv_get_user_agent', $user_agent);
42 42
 }
43 43
 
44
-function wpinv_sanitize_amount( $amount ) {
44
+function wpinv_sanitize_amount($amount) {
45 45
     $is_negative   = false;
46 46
     $thousands_sep = wpinv_thousands_separator();
47 47
     $decimal_sep   = wpinv_decimal_separator();
48 48
     $decimals = wpinv_decimals();
49 49
 
50 50
     // Sanitize the amount
51
-    if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) {
52
-        if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
53
-            $amount = str_replace( $thousands_sep, '', $amount );
54
-        } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) {
55
-            $amount = str_replace( '.', '', $amount );
51
+    if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) {
52
+        if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) {
53
+            $amount = str_replace($thousands_sep, '', $amount);
54
+        } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) {
55
+            $amount = str_replace('.', '', $amount);
56 56
         }
57 57
 
58
-        $amount = str_replace( $decimal_sep, '.', $amount );
59
-    } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
60
-        $amount = str_replace( $thousands_sep, '', $amount );
58
+        $amount = str_replace($decimal_sep, '.', $amount);
59
+    } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
60
+        $amount = str_replace($thousands_sep, '', $amount);
61 61
     }
62 62
 
63
-    if( $amount < 0 ) {
63
+    if ($amount < 0) {
64 64
         $is_negative = true;
65 65
     }
66 66
 
67
-    $amount   = preg_replace( '/[^0-9\.]/', '', $amount );
67
+    $amount   = preg_replace('/[^0-9\.]/', '', $amount);
68 68
 
69
-    $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', $decimals, $amount );
70
-    $amount   = number_format( (double) $amount, $decimals, '.', '' );
69
+    $decimals = apply_filters('wpinv_sanitize_amount_decimals', $decimals, $amount);
70
+    $amount   = number_format((double)$amount, $decimals, '.', '');
71 71
 
72
-    if( $is_negative ) {
72
+    if ($is_negative) {
73 73
         $amount *= -1;
74 74
     }
75 75
 
76
-    return apply_filters( 'wpinv_sanitize_amount', $amount );
76
+    return apply_filters('wpinv_sanitize_amount', $amount);
77 77
 }
78 78
 
79
-function wpinv_round_amount( $amount ) {
79
+function wpinv_round_amount($amount) {
80 80
     $decimals = wpinv_decimals();
81 81
     
82
-    $amount = round( (double)$amount, wpinv_currency_decimal_filter( $decimals ) );
82
+    $amount = round((double)$amount, wpinv_currency_decimal_filter($decimals));
83 83
 
84
-    return apply_filters( 'wpinv_round_amount', $amount );
84
+    return apply_filters('wpinv_round_amount', $amount);
85 85
 }
86 86
 
87
-function wpinv_get_invoice_statuses( $trashed = false ) {
87
+function wpinv_get_invoice_statuses($trashed = false) {
88 88
     $invoice_statuses = array(
89
-        'pending'       => __( 'Pending Payment', 'invoicing' ),
90
-        'publish'       => __( 'Paid', 'invoicing' ),
91
-        'wpi-processing'    => __( 'Processing', 'invoicing' ),
92
-        'wpi-onhold'        => __( 'On Hold', 'invoicing' ),
93
-        'wpi-refunded'      => __( 'Refunded', 'invoicing' ),
94
-        'wpi-cancelled'     => __( 'Cancelled', 'invoicing' ),
95
-        'wpi-failed'        => __( 'Failed', 'invoicing' ),
96
-        'wpi-renewal'       => __( 'Renewal Payment', 'invoicing' )
89
+        'pending'       => __('Pending Payment', 'invoicing'),
90
+        'publish'       => __('Paid', 'invoicing'),
91
+        'wpi-processing'    => __('Processing', 'invoicing'),
92
+        'wpi-onhold'        => __('On Hold', 'invoicing'),
93
+        'wpi-refunded'      => __('Refunded', 'invoicing'),
94
+        'wpi-cancelled'     => __('Cancelled', 'invoicing'),
95
+        'wpi-failed'        => __('Failed', 'invoicing'),
96
+        'wpi-renewal'       => __('Renewal Payment', 'invoicing')
97 97
     );
98 98
     
99
-    if ( $trashed ) {
100
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
99
+    if ($trashed) {
100
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
101 101
     }
102 102
 
103
-    return apply_filters( 'wpinv_statuses', $invoice_statuses );
103
+    return apply_filters('wpinv_statuses', $invoice_statuses);
104 104
 }
105 105
 
106
-function wpinv_status_nicename( $status ) {
106
+function wpinv_status_nicename($status) {
107 107
     $statuses = wpinv_get_invoice_statuses();
108
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' );
108
+    $status   = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing');
109 109
 
110 110
     return $status;
111 111
 }
112 112
 
113 113
 function wpinv_get_currency() {
114
-    $currency = wpinv_get_option( 'currency', 'USD' );
114
+    $currency = wpinv_get_option('currency', 'USD');
115 115
     
116
-    return apply_filters( 'wpinv_currency', $currency );
116
+    return apply_filters('wpinv_currency', $currency);
117 117
 }
118 118
 
119
-function wpinv_currency_symbol( $currency = '' ) {
120
-    if ( empty( $currency ) ) {
119
+function wpinv_currency_symbol($currency = '') {
120
+    if (empty($currency)) {
121 121
         $currency = wpinv_get_currency();
122 122
     }
123 123
     
124
-    $symbols = apply_filters( 'wpinv_currency_symbols', array(
124
+    $symbols = apply_filters('wpinv_currency_symbols', array(
125 125
         'AED' => 'د.إ',
126 126
         'ARS' => '&#36;',
127 127
         'AUD' => '&#36;',
@@ -173,78 +173,78 @@  discard block
 block discarded – undo
173 173
         'USD' => '&#36;',
174 174
         'VND' => '&#8363;',
175 175
         'ZAR' => '&#82;',
176
-    ) );
176
+    ));
177 177
 
178
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : '&#36;';
178
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : '&#36;';
179 179
 
180
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
180
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
181 181
 }
182 182
 
183 183
 function wpinv_currency_position() {
184
-    $position = wpinv_get_option( 'currency_position', 'left' );
184
+    $position = wpinv_get_option('currency_position', 'left');
185 185
     
186
-    return apply_filters( 'wpinv_currency_position', $position );
186
+    return apply_filters('wpinv_currency_position', $position);
187 187
 }
188 188
 
189 189
 function wpinv_thousands_separator() {
190
-    $thousand_sep = wpinv_get_option( 'thousands_separator', ',' );
190
+    $thousand_sep = wpinv_get_option('thousands_separator', ',');
191 191
     
192
-    return apply_filters( 'wpinv_thousands_separator', $thousand_sep );
192
+    return apply_filters('wpinv_thousands_separator', $thousand_sep);
193 193
 }
194 194
 
195 195
 function wpinv_decimal_separator() {
196
-    $decimal_sep = wpinv_get_option( 'decimal_separator', '.' );
196
+    $decimal_sep = wpinv_get_option('decimal_separator', '.');
197 197
     
198
-    return apply_filters( 'wpinv_decimal_separator', $decimal_sep );
198
+    return apply_filters('wpinv_decimal_separator', $decimal_sep);
199 199
 }
200 200
 
201 201
 function wpinv_decimals() {
202
-    $decimals = apply_filters( 'wpinv_decimals', wpinv_get_option( 'decimals', 2 ) );
202
+    $decimals = apply_filters('wpinv_decimals', wpinv_get_option('decimals', 2));
203 203
     
204
-    return absint( $decimals );
204
+    return absint($decimals);
205 205
 }
206 206
 
207 207
 function wpinv_get_currencies() {
208 208
     $currencies = array(
209
-        'USD'  => __( 'US Dollars (&#36;)', 'invoicing' ),
210
-        'EUR'  => __( 'Euros (&euro;)', 'invoicing' ),
211
-        'GBP'  => __( 'Pounds Sterling (&pound;)', 'invoicing' ),
212
-        'AUD'  => __( 'Australian Dollars (&#36;)', 'invoicing' ),
213
-        'BRL'  => __( 'Brazilian Real (R&#36;)', 'invoicing' ),
214
-        'CAD'  => __( 'Canadian Dollars (&#36;)', 'invoicing' ),
215
-        'CLP'  => __( 'Chilean Peso (&#36;)', 'invoicing' ),
216
-        'CNY'  => __( 'Chinese Yuan (&yen;)', 'invoicing' ),
217
-        'CZK'  => __( 'Czech Koruna (&#75;&#269;)', 'invoicing' ),
218
-        'DKK'  => __( 'Danish Krone (DKK)', 'invoicing' ),
219
-        'HKD'  => __( 'Hong Kong Dollar (&#36;)', 'invoicing' ),
220
-        'HUF'  => __( 'Hungarian Forint (&#70;&#116;)', 'invoicing' ),
221
-        'INR'  => __( 'Indian Rupee (&#8377;)', 'invoicing' ),
222
-        'ILS'  => __( 'Israeli Shekel (&#8362;)', 'invoicing' ),
223
-        'JPY'  => __( 'Japanese Yen (&yen;)', 'invoicing' ),
224
-        'MYR'  => __( 'Malaysian Ringgit (&#82;&#77;)', 'invoicing' ),
225
-        'MXN'  => __( 'Mexican Peso (&#36;)', 'invoicing' ),
226
-        'NZD'  => __( 'New Zealand Dollar (&#36;)', 'invoicing' ),
227
-        'NOK'  => __( 'Norwegian Krone (&#107;&#114;)', 'invoicing' ),
228
-        'PHP'  => __( 'Philippine Peso (&#8369;)', 'invoicing' ),
229
-        'PLN'  => __( 'Polish Zloty (&#122;&#322;)', 'invoicing' ),
230
-        'SGD'  => __( 'Singapore Dollar (&#36;)', 'invoicing' ),
231
-        'SEK'  => __( 'Swedish Krona (&#107;&#114;)', 'invoicing' ),
232
-        'CHF'  => __( 'Swiss Franc (&#67;&#72;&#70;)', 'invoicing' ),
233
-        'TWD'  => __( 'Taiwan New Dollar (&#78;&#84;&#36;)', 'invoicing' ),
234
-        'THB'  => __( 'Thai Baht (&#3647;)', 'invoicing' ),
235
-        'TRY'  => __( 'Turkish Lira (&#8378;)', 'invoicing' ),
236
-        'RIAL' => __( 'Iranian Rial (&#65020;)', 'invoicing' ),
237
-        'RUB'  => __( 'Russian Ruble (&#8381;)', 'invoicing' ),
238
-        'ZAR'  => __( 'South African Rand (&#82;)', 'invoicing' )
209
+        'USD'  => __('US Dollars (&#36;)', 'invoicing'),
210
+        'EUR'  => __('Euros (&euro;)', 'invoicing'),
211
+        'GBP'  => __('Pounds Sterling (&pound;)', 'invoicing'),
212
+        'AUD'  => __('Australian Dollars (&#36;)', 'invoicing'),
213
+        'BRL'  => __('Brazilian Real (R&#36;)', 'invoicing'),
214
+        'CAD'  => __('Canadian Dollars (&#36;)', 'invoicing'),
215
+        'CLP'  => __('Chilean Peso (&#36;)', 'invoicing'),
216
+        'CNY'  => __('Chinese Yuan (&yen;)', 'invoicing'),
217
+        'CZK'  => __('Czech Koruna (&#75;&#269;)', 'invoicing'),
218
+        'DKK'  => __('Danish Krone (DKK)', 'invoicing'),
219
+        'HKD'  => __('Hong Kong Dollar (&#36;)', 'invoicing'),
220
+        'HUF'  => __('Hungarian Forint (&#70;&#116;)', 'invoicing'),
221
+        'INR'  => __('Indian Rupee (&#8377;)', 'invoicing'),
222
+        'ILS'  => __('Israeli Shekel (&#8362;)', 'invoicing'),
223
+        'JPY'  => __('Japanese Yen (&yen;)', 'invoicing'),
224
+        'MYR'  => __('Malaysian Ringgit (&#82;&#77;)', 'invoicing'),
225
+        'MXN'  => __('Mexican Peso (&#36;)', 'invoicing'),
226
+        'NZD'  => __('New Zealand Dollar (&#36;)', 'invoicing'),
227
+        'NOK'  => __('Norwegian Krone (&#107;&#114;)', 'invoicing'),
228
+        'PHP'  => __('Philippine Peso (&#8369;)', 'invoicing'),
229
+        'PLN'  => __('Polish Zloty (&#122;&#322;)', 'invoicing'),
230
+        'SGD'  => __('Singapore Dollar (&#36;)', 'invoicing'),
231
+        'SEK'  => __('Swedish Krona (&#107;&#114;)', 'invoicing'),
232
+        'CHF'  => __('Swiss Franc (&#67;&#72;&#70;)', 'invoicing'),
233
+        'TWD'  => __('Taiwan New Dollar (&#78;&#84;&#36;)', 'invoicing'),
234
+        'THB'  => __('Thai Baht (&#3647;)', 'invoicing'),
235
+        'TRY'  => __('Turkish Lira (&#8378;)', 'invoicing'),
236
+        'RIAL' => __('Iranian Rial (&#65020;)', 'invoicing'),
237
+        'RUB'  => __('Russian Ruble (&#8381;)', 'invoicing'),
238
+        'ZAR'  => __('South African Rand (&#82;)', 'invoicing')
239 239
     );
240 240
     
241
-    asort( $currencies );
241
+    asort($currencies);
242 242
 
243
-    return apply_filters( 'wpinv_currencies', $currencies );
243
+    return apply_filters('wpinv_currencies', $currencies);
244 244
 }
245 245
 
246
-function wpinv_price( $amount = '', $currency = '' ) {
247
-    if( empty( $currency ) ) {
246
+function wpinv_price($amount = '', $currency = '') {
247
+    if (empty($currency)) {
248 248
         $currency = wpinv_get_currency();
249 249
     }
250 250
 
@@ -252,14 +252,14 @@  discard block
 block discarded – undo
252 252
 
253 253
     $negative = $amount < 0;
254 254
 
255
-    if ( $negative ) {
256
-        $amount = substr( $amount, 1 );
255
+    if ($negative) {
256
+        $amount = substr($amount, 1);
257 257
     }
258 258
 
259
-    $symbol = wpinv_currency_symbol( $currency );
259
+    $symbol = wpinv_currency_symbol($currency);
260 260
 
261
-    if ( $position == 'left' || $position == 'left_space' ) {
262
-        switch ( $currency ) {
261
+    if ($position == 'left' || $position == 'left_space') {
262
+        switch ($currency) {
263 263
             case "GBP" :
264 264
             case "BRL" :
265 265
             case "EUR" :
@@ -271,15 +271,15 @@  discard block
 block discarded – undo
271 271
             case "NZD" :
272 272
             case "SGD" :
273 273
             case "JPY" :
274
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
274
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
275 275
                 break;
276 276
             default :
277 277
                 //$price = $currency . ' ' . $amount;
278
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
278
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
279 279
                 break;
280 280
         }
281 281
     } else {
282
-        switch ( $currency ) {
282
+        switch ($currency) {
283 283
             case "GBP" :
284 284
             case "BRL" :
285 285
             case "EUR" :
@@ -290,82 +290,82 @@  discard block
 block discarded – undo
290 290
             case "MXN" :
291 291
             case "SGD" :
292 292
             case "JPY" :
293
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
293
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
294 294
                 break;
295 295
             default :
296 296
                 //$price = $amount . ' ' . $currency;
297
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
297
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
298 298
                 break;
299 299
         }
300 300
     }
301 301
     
302
-    if ( $negative ) {
302
+    if ($negative) {
303 303
         $price = '-' . $price;
304 304
     }
305 305
     
306
-    $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount );
306
+    $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount);
307 307
 
308 308
     return $price;
309 309
 }
310 310
 
311
-function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) {
311
+function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) {
312 312
     $thousands_sep = wpinv_thousands_separator();
313 313
     $decimal_sep   = wpinv_decimal_separator();
314 314
 
315
-    if ( $decimals === NULL ) {
315
+    if ($decimals === NULL) {
316 316
         $decimals = wpinv_decimals();
317 317
     }
318 318
 
319
-    if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) {
320
-        $whole = substr( $amount, 0, $sep_found );
321
-        $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) );
319
+    if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) {
320
+        $whole = substr($amount, 0, $sep_found);
321
+        $part = substr($amount, $sep_found + 1, (strlen($amount) - 1));
322 322
         $amount = $whole . '.' . $part;
323 323
     }
324 324
 
325
-    if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
326
-        $amount = str_replace( ',', '', $amount );
325
+    if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
326
+        $amount = str_replace(',', '', $amount);
327 327
     }
328 328
 
329
-    if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
330
-        $amount = str_replace( ' ', '', $amount );
329
+    if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) {
330
+        $amount = str_replace(' ', '', $amount);
331 331
     }
332 332
 
333
-    if ( empty( $amount ) ) {
333
+    if (empty($amount)) {
334 334
         $amount = 0;
335 335
     }
336 336
     
337
-    $decimals  = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate );
338
-    $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep );
337
+    $decimals  = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate);
338
+    $formatted = number_format((float)$amount, $decimals, $decimal_sep, $thousands_sep);
339 339
     
340
-    if ( $calculate ) {
341
-        if ( $thousands_sep === "," ) {
342
-            $formatted = str_replace( ",", "", $formatted );
340
+    if ($calculate) {
341
+        if ($thousands_sep === ",") {
342
+            $formatted = str_replace(",", "", $formatted);
343 343
         }
344 344
         
345
-        if ( $decimal_sep === "," ) {
346
-            $formatted = str_replace( ",", ".", $formatted );
345
+        if ($decimal_sep === ",") {
346
+            $formatted = str_replace(",", ".", $formatted);
347 347
         }
348 348
     }
349 349
 
350
-    return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate );
350
+    return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate);
351 351
 }
352 352
 
353
-function wpinv_sanitize_key( $key ) {
353
+function wpinv_sanitize_key($key) {
354 354
     $raw_key = $key;
355
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
355
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
356 356
 
357
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
357
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
358 358
 }
359 359
 
360
-function wpinv_get_file_extension( $str ) {
361
-    $parts = explode( '.', $str );
362
-    return end( $parts );
360
+function wpinv_get_file_extension($str) {
361
+    $parts = explode('.', $str);
362
+    return end($parts);
363 363
 }
364 364
 
365
-function wpinv_string_is_image_url( $str ) {
366
-    $ext = wpinv_get_file_extension( $str );
365
+function wpinv_string_is_image_url($str) {
366
+    $ext = wpinv_get_file_extension($str);
367 367
 
368
-    switch ( strtolower( $ext ) ) {
368
+    switch (strtolower($ext)) {
369 369
         case 'jpeg';
370 370
         case 'jpg';
371 371
             $return = true;
@@ -381,32 +381,32 @@  discard block
 block discarded – undo
381 381
             break;
382 382
     }
383 383
 
384
-    return (bool)apply_filters( 'wpinv_string_is_image', $return, $str );
384
+    return (bool)apply_filters('wpinv_string_is_image', $return, $str);
385 385
 }
386 386
 
387
-function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) {
388
-    $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG );
387
+function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) {
388
+    $should_log = apply_filters('wpinv_log_errors', WP_DEBUG);
389 389
     
390
-    if ( true === $should_log ) {
390
+    if (true === $should_log) {
391 391
         $label = '';
392
-        if ( $file && $file !== '' ) {
393
-            $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' );
392
+        if ($file && $file !== '') {
393
+            $label .= basename($file) . ($line ? '(' . $line . ')' : '');
394 394
         }
395 395
         
396
-        if ( $title && $title !== '' ) {
396
+        if ($title && $title !== '') {
397 397
             $label = $label !== '' ? $label . ' ' : '';
398 398
             $label .= $title . ' ';
399 399
         }
400 400
         
401
-        $label = $label !== '' ? trim( $label ) . ' : ' : '';
401
+        $label = $label !== '' ? trim($label) . ' : ' : '';
402 402
         
403
-        if ( is_array( $log ) || is_object( $log ) ) {
404
-            error_log( $label . print_r( $log, true ) );
403
+        if (is_array($log) || is_object($log)) {
404
+            error_log($label . print_r($log, true));
405 405
         } else {
406
-            error_log( $label . $log );
406
+            error_log($label . $log);
407 407
         }
408 408
         
409
-        if ( $exit ) {
409
+        if ($exit) {
410 410
             exit;
411 411
         }
412 412
     }
@@ -414,65 +414,65 @@  discard block
 block discarded – undo
414 414
 
415 415
 function wpinv_is_ajax_disabled() {
416 416
     $retval = false;
417
-    return apply_filters( 'wpinv_is_ajax_disabled', $retval );
417
+    return apply_filters('wpinv_is_ajax_disabled', $retval);
418 418
 }
419 419
 
420
-function wpinv_get_current_page_url( $nocache = false ) {
420
+function wpinv_get_current_page_url($nocache = false) {
421 421
     global $wp;
422 422
 
423
-    if ( get_option( 'permalink_structure' ) ) {
424
-        $base = trailingslashit( home_url( $wp->request ) );
423
+    if (get_option('permalink_structure')) {
424
+        $base = trailingslashit(home_url($wp->request));
425 425
     } else {
426
-        $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) );
427
-        $base = remove_query_arg( array( 'post_type', 'name' ), $base );
426
+        $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request)));
427
+        $base = remove_query_arg(array('post_type', 'name'), $base);
428 428
     }
429 429
 
430 430
     $scheme = is_ssl() ? 'https' : 'http';
431
-    $uri    = set_url_scheme( $base, $scheme );
431
+    $uri    = set_url_scheme($base, $scheme);
432 432
 
433
-    if ( is_front_page() ) {
434
-        $uri = home_url( '/' );
435
-    } elseif ( wpinv_is_checkout( array(), false ) ) {
433
+    if (is_front_page()) {
434
+        $uri = home_url('/');
435
+    } elseif (wpinv_is_checkout(array(), false)) {
436 436
         $uri = wpinv_get_checkout_uri();
437 437
     }
438 438
 
439
-    $uri = apply_filters( 'wpinv_get_current_page_url', $uri );
439
+    $uri = apply_filters('wpinv_get_current_page_url', $uri);
440 440
 
441
-    if ( $nocache ) {
442
-        $uri = wpinv_add_cache_busting( $uri );
441
+    if ($nocache) {
442
+        $uri = wpinv_add_cache_busting($uri);
443 443
     }
444 444
 
445 445
     return $uri;
446 446
 }
447 447
 
448 448
 function wpinv_get_php_arg_separator_output() {
449
-	return ini_get( 'arg_separator.output' );
449
+	return ini_get('arg_separator.output');
450 450
 }
451 451
 
452
-function wpinv_rgb_from_hex( $color ) {
453
-    $color = str_replace( '#', '', $color );
452
+function wpinv_rgb_from_hex($color) {
453
+    $color = str_replace('#', '', $color);
454 454
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
455
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
455
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
456 456
 
457 457
     $rgb      = array();
458
-    $rgb['R'] = hexdec( $color{0}.$color{1} );
459
-    $rgb['G'] = hexdec( $color{2}.$color{3} );
460
-    $rgb['B'] = hexdec( $color{4}.$color{5} );
458
+    $rgb['R'] = hexdec($color{0} . $color{1} );
459
+    $rgb['G'] = hexdec($color{2} . $color{3} );
460
+    $rgb['B'] = hexdec($color{4} . $color{5} );
461 461
 
462 462
     return $rgb;
463 463
 }
464 464
 
465
-function wpinv_hex_darker( $color, $factor = 30 ) {
466
-    $base  = wpinv_rgb_from_hex( $color );
465
+function wpinv_hex_darker($color, $factor = 30) {
466
+    $base  = wpinv_rgb_from_hex($color);
467 467
     $color = '#';
468 468
 
469
-    foreach ( $base as $k => $v ) {
469
+    foreach ($base as $k => $v) {
470 470
         $amount      = $v / 100;
471
-        $amount      = round( $amount * $factor );
471
+        $amount      = round($amount * $factor);
472 472
         $new_decimal = $v - $amount;
473 473
 
474
-        $new_hex_component = dechex( $new_decimal );
475
-        if ( strlen( $new_hex_component ) < 2 ) {
474
+        $new_hex_component = dechex($new_decimal);
475
+        if (strlen($new_hex_component) < 2) {
476 476
             $new_hex_component = "0" . $new_hex_component;
477 477
         }
478 478
         $color .= $new_hex_component;
@@ -481,18 +481,18 @@  discard block
 block discarded – undo
481 481
     return $color;
482 482
 }
483 483
 
484
-function wpinv_hex_lighter( $color, $factor = 30 ) {
485
-    $base  = wpinv_rgb_from_hex( $color );
484
+function wpinv_hex_lighter($color, $factor = 30) {
485
+    $base  = wpinv_rgb_from_hex($color);
486 486
     $color = '#';
487 487
 
488
-    foreach ( $base as $k => $v ) {
488
+    foreach ($base as $k => $v) {
489 489
         $amount      = 255 - $v;
490 490
         $amount      = $amount / 100;
491
-        $amount      = round( $amount * $factor );
491
+        $amount      = round($amount * $factor);
492 492
         $new_decimal = $v + $amount;
493 493
 
494
-        $new_hex_component = dechex( $new_decimal );
495
-        if ( strlen( $new_hex_component ) < 2 ) {
494
+        $new_hex_component = dechex($new_decimal);
495
+        if (strlen($new_hex_component) < 2) {
496 496
             $new_hex_component = "0" . $new_hex_component;
497 497
         }
498 498
         $color .= $new_hex_component;
@@ -501,22 +501,22 @@  discard block
 block discarded – undo
501 501
     return $color;
502 502
 }
503 503
 
504
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
505
-    $hex = str_replace( '#', '', $color );
504
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
505
+    $hex = str_replace('#', '', $color);
506 506
 
507
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
508
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
509
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
507
+    $c_r = hexdec(substr($hex, 0, 2));
508
+    $c_g = hexdec(substr($hex, 2, 2));
509
+    $c_b = hexdec(substr($hex, 4, 2));
510 510
 
511
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
511
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
512 512
 
513 513
     return $brightness > 155 ? $dark : $light;
514 514
 }
515 515
 
516
-function wpinv_format_hex( $hex ) {
517
-    $hex = trim( str_replace( '#', '', $hex ) );
516
+function wpinv_format_hex($hex) {
517
+    $hex = trim(str_replace('#', '', $hex));
518 518
 
519
-    if ( strlen( $hex ) == 3 ) {
519
+    if (strlen($hex) == 3) {
520 520
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
521 521
     }
522 522
 
@@ -536,12 +536,12 @@  discard block
 block discarded – undo
536 536
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
537 537
  * @return string
538 538
  */
539
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
540
-    if ( function_exists( 'mb_strimwidth' ) ) {
541
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
539
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
540
+    if (function_exists('mb_strimwidth')) {
541
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
542 542
     }
543 543
     
544
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
544
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
545 545
 }
546 546
 
547 547
 /**
@@ -553,28 +553,28 @@  discard block
 block discarded – undo
553 553
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
554 554
  * @return int Returns the number of characters in string.
555 555
  */
556
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
557
-    if ( function_exists( 'mb_strlen' ) ) {
558
-        return mb_strlen( $str, $encoding );
556
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
557
+    if (function_exists('mb_strlen')) {
558
+        return mb_strlen($str, $encoding);
559 559
     }
560 560
         
561
-    return strlen( $str );
561
+    return strlen($str);
562 562
 }
563 563
 
564
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
565
-    if ( function_exists( 'mb_strtolower' ) ) {
566
-        return mb_strtolower( $str, $encoding );
564
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
565
+    if (function_exists('mb_strtolower')) {
566
+        return mb_strtolower($str, $encoding);
567 567
     }
568 568
     
569
-    return strtolower( $str );
569
+    return strtolower($str);
570 570
 }
571 571
 
572
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
573
-    if ( function_exists( 'mb_strtoupper' ) ) {
574
-        return mb_strtoupper( $str, $encoding );
572
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
573
+    if (function_exists('mb_strtoupper')) {
574
+        return mb_strtoupper($str, $encoding);
575 575
     }
576 576
     
577
-    return strtoupper( $str );
577
+    return strtoupper($str);
578 578
 }
579 579
 
580 580
 /**
@@ -588,12 +588,12 @@  discard block
 block discarded – undo
588 588
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
589 589
  * @return int Returns the position of the first occurrence of search in the string.
590 590
  */
591
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
592
-    if ( function_exists( 'mb_strpos' ) ) {
593
-        return mb_strpos( $str, $find, $offset, $encoding );
591
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
592
+    if (function_exists('mb_strpos')) {
593
+        return mb_strpos($str, $find, $offset, $encoding);
594 594
     }
595 595
         
596
-    return strpos( $str, $find, $offset );
596
+    return strpos($str, $find, $offset);
597 597
 }
598 598
 
599 599
 /**
@@ -607,12 +607,12 @@  discard block
 block discarded – undo
607 607
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
608 608
  * @return int Returns the position of the last occurrence of search.
609 609
  */
610
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
611
-    if ( function_exists( 'mb_strrpos' ) ) {
612
-        return mb_strrpos( $str, $find, $offset, $encoding );
610
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
611
+    if (function_exists('mb_strrpos')) {
612
+        return mb_strrpos($str, $find, $offset, $encoding);
613 613
     }
614 614
         
615
-    return strrpos( $str, $find, $offset );
615
+    return strrpos($str, $find, $offset);
616 616
 }
617 617
 
618 618
 /**
@@ -627,16 +627,16 @@  discard block
 block discarded – undo
627 627
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
628 628
  * @return string
629 629
  */
630
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
631
-    if ( function_exists( 'mb_substr' ) ) {
632
-        if ( $length === null ) {
633
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
630
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
631
+    if (function_exists('mb_substr')) {
632
+        if ($length === null) {
633
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
634 634
         } else {
635
-            return mb_substr( $str, $start, $length, $encoding );
635
+            return mb_substr($str, $start, $length, $encoding);
636 636
         }
637 637
     }
638 638
         
639
-    return substr( $str, $start, $length );
639
+    return substr($str, $start, $length);
640 640
 }
641 641
 
642 642
 /**
@@ -648,48 +648,48 @@  discard block
 block discarded – undo
648 648
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
649 649
  * @return string The width of string.
650 650
  */
651
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
652
-    if ( function_exists( 'mb_strwidth' ) ) {
653
-        return mb_strwidth( $str, $encoding );
651
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
652
+    if (function_exists('mb_strwidth')) {
653
+        return mb_strwidth($str, $encoding);
654 654
     }
655 655
     
656
-    return wpinv_utf8_strlen( $str, $encoding );
656
+    return wpinv_utf8_strlen($str, $encoding);
657 657
 }
658 658
 
659
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
660
-    if ( function_exists( 'mb_strlen' ) ) {
661
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
659
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
660
+    if (function_exists('mb_strlen')) {
661
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
662 662
         $str_end = "";
663 663
         
664
-        if ( $lower_str_end ) {
665
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
664
+        if ($lower_str_end) {
665
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
666 666
         } else {
667
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
667
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
668 668
         }
669 669
 
670 670
         return $first_letter . $str_end;
671 671
     }
672 672
     
673
-    return ucfirst( $str );
673
+    return ucfirst($str);
674 674
 }
675 675
 
676
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
677
-    if ( function_exists( 'mb_convert_case' ) ) {
678
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
676
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
677
+    if (function_exists('mb_convert_case')) {
678
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
679 679
     }
680 680
     
681
-    return ucwords( $str );
681
+    return ucwords($str);
682 682
 }
683 683
 
684
-function wpinv_period_in_days( $period, $unit ) {
685
-    $period = absint( $period );
684
+function wpinv_period_in_days($period, $unit) {
685
+    $period = absint($period);
686 686
     
687
-    if ( $period > 0 ) {
688
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
687
+    if ($period > 0) {
688
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
689 689
             $period = $period * 7;
690
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
690
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
691 691
             $period = $period * 30;
692
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
692
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
693 693
             $period = $period * 365;
694 694
         }
695 695
     }
Please login to merge, or discard this patch.
includes/wpinv-payment-functions.php 1 patch
Spacing   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2
-function wpinv_get_subscriptions( $args = array() ) {
3
-    if ( empty( $args['parent_invoice_id'] ) ) {
2
+function wpinv_get_subscriptions($args = array()) {
3
+    if (empty($args['parent_invoice_id'])) {
4 4
         return false;
5 5
     }
6 6
     
@@ -14,18 +14,18 @@  discard block
 block discarded – undo
14 14
     );
15 15
 
16 16
     $args['post_parent']    = $args['parent_invoice_id'];
17
-    $args                   = wp_parse_args( $args, $defaults );
17
+    $args                   = wp_parse_args($args, $defaults);
18 18
 
19
-    if( $args['numberposts'] < 1 ) {
19
+    if ($args['numberposts'] < 1) {
20 20
         $args['numberposts'] = 999999999999;
21 21
     }
22 22
 
23
-    $posts          = get_posts( $args );
23
+    $posts          = get_posts($args);
24 24
     $subscriptions  = array();
25
-    if ( !empty( $posts ) ) {
26
-        foreach ( $posts as $post ) {
27
-            if ( !empty( $post->ID ) ) {
28
-                $subscriptions[] = wpinv_get_invoice( $post->ID );
25
+    if (!empty($posts)) {
26
+        foreach ($posts as $post) {
27
+            if (!empty($post->ID)) {
28
+                $subscriptions[] = wpinv_get_invoice($post->ID);
29 29
             }
30 30
         }
31 31
     }
@@ -33,19 +33,19 @@  discard block
 block discarded – undo
33 33
     
34 34
     return $subscriptions;
35 35
 }
36
-function wpinv_get_subscription( $id = 0, $by_profile_id = false ) {
36
+function wpinv_get_subscription($id = 0, $by_profile_id = false) {
37 37
     global $wpdb;
38 38
 
39
-    if ( empty( $id ) ) {
39
+    if (empty($id)) {
40 40
         return false;
41 41
     }
42 42
 
43
-    $id = esc_sql( $id );
43
+    $id = esc_sql($id);
44 44
 
45
-    $invoice_id = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1" );
45
+    $invoice_id = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1");
46 46
 
47
-    if ( $invoice_id != null ) {
48
-        return wpinv_get_invoice( $invoice_id );
47
+    if ($invoice_id != null) {
48
+        return wpinv_get_invoice($invoice_id);
49 49
     }
50 50
 
51 51
     return false;
@@ -55,49 +55,49 @@  discard block
 block discarded – undo
55 55
  * Records a new payment on the subscription
56 56
  * 
57 57
  */
58
-function wpinv_recurring_add_subscription_payment( $parent_invoice_id, $subscription_args = array() ) {    
59
-    $args = wp_parse_args( $subscription_args, array(
58
+function wpinv_recurring_add_subscription_payment($parent_invoice_id, $subscription_args = array()) {    
59
+    $args = wp_parse_args($subscription_args, array(
60 60
         'amount'         => '',
61 61
         'transaction_id' => '',
62 62
         'gateway'        => ''
63
-    ) );
63
+    ));
64 64
 
65
-    if ( wpinv_payment_exists( $args['transaction_id'] ) ) {
65
+    if (wpinv_payment_exists($args['transaction_id'])) {
66 66
         return false;
67 67
     }
68 68
     
69
-    $parent_invoice = wpinv_get_invoice( $parent_invoice_id );
70
-    if ( empty( $parent_invoice ) ) {
69
+    $parent_invoice = wpinv_get_invoice($parent_invoice_id);
70
+    if (empty($parent_invoice)) {
71 71
         return;
72 72
     }
73 73
 
74 74
     $invoice = new WPInv_Invoice();
75
-    $invoice->set( 'parent_invoice', $parent_invoice_id );
76
-    $invoice->set( 'currency', $parent_invoice->get_currency() );
75
+    $invoice->set('parent_invoice', $parent_invoice_id);
76
+    $invoice->set('currency', $parent_invoice->get_currency());
77 77
     //$invoice->set( 'status', 'publish' );
78
-    $invoice->set( 'transaction_id', $args['transaction_id'] );
79
-    $invoice->set( 'key', $parent_invoice->get_key() );
78
+    $invoice->set('transaction_id', $args['transaction_id']);
79
+    $invoice->set('key', $parent_invoice->get_key());
80 80
     
81
-    $invoice->set( 'ip', $parent_invoice->ip );
82
-    $invoice->set( 'user_id', $parent_invoice->get_user_id() );
83
-    $invoice->set( 'first_name', $parent_invoice->get_first_name() );
84
-    $invoice->set( 'last_name', $parent_invoice->get_last_name() );
81
+    $invoice->set('ip', $parent_invoice->ip);
82
+    $invoice->set('user_id', $parent_invoice->get_user_id());
83
+    $invoice->set('first_name', $parent_invoice->get_first_name());
84
+    $invoice->set('last_name', $parent_invoice->get_last_name());
85 85
     ///$invoice->set( 'email', $parent_invoice->get_email() );
86
-    $invoice->set( 'phone', $parent_invoice->phone );
87
-    $invoice->set( 'address', $parent_invoice->address );
88
-    $invoice->set( 'city', $parent_invoice->city );
89
-    $invoice->set( 'country', $parent_invoice->country );
90
-    $invoice->set( 'state', $parent_invoice->state );
91
-    $invoice->set( 'zip', $parent_invoice->zip );
92
-    $invoice->set( 'company', $parent_invoice->company );
93
-    $invoice->set( 'vat_number', $parent_invoice->vat_number );
94
-    $invoice->set( 'vat_rate', $parent_invoice->vat_rate );
95
-    $invoice->set( 'adddress_confirmed', $parent_invoice->adddress_confirmed );
96
-
97
-    if ( empty( $args['gateway'] ) ) {
98
-        $invoice->set( 'gateway', $parent_invoice->get_gateway() );
86
+    $invoice->set('phone', $parent_invoice->phone);
87
+    $invoice->set('address', $parent_invoice->address);
88
+    $invoice->set('city', $parent_invoice->city);
89
+    $invoice->set('country', $parent_invoice->country);
90
+    $invoice->set('state', $parent_invoice->state);
91
+    $invoice->set('zip', $parent_invoice->zip);
92
+    $invoice->set('company', $parent_invoice->company);
93
+    $invoice->set('vat_number', $parent_invoice->vat_number);
94
+    $invoice->set('vat_rate', $parent_invoice->vat_rate);
95
+    $invoice->set('adddress_confirmed', $parent_invoice->adddress_confirmed);
96
+
97
+    if (empty($args['gateway'])) {
98
+        $invoice->set('gateway', $parent_invoice->get_gateway());
99 99
     } else {
100
-        $invoice->set( 'gateway', $args['gateway'] );
100
+        $invoice->set('gateway', $args['gateway']);
101 101
     }
102 102
     
103 103
     $recurring_details = $parent_invoice->get_recurring_details();
@@ -105,11 +105,11 @@  discard block
 block discarded – undo
105 105
     // increase the earnings for each item in the subscription
106 106
     $items = $recurring_details['cart_details'];
107 107
     
108
-    if ( $items ) {        
108
+    if ($items) {        
109 109
         $add_items      = array();
110 110
         $cart_details   = array();
111 111
         
112
-        foreach ( $items as $item ) {
112
+        foreach ($items as $item) {
113 113
             $add_item             = array();
114 114
             $add_item['id']       = $item['id'];
115 115
             $add_item['quantity'] = $item['quantity'];
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
             break;
120 120
         }
121 121
         
122
-        $invoice->set( 'items', $add_items );
122
+        $invoice->set('items', $add_items);
123 123
         $invoice->cart_details = $cart_details;
124 124
     }
125 125
     
@@ -129,277 +129,277 @@  discard block
 block discarded – undo
129 129
     $tax                = $recurring_details['tax'];
130 130
     $discount           = $recurring_details['discount'];
131 131
     
132
-    if ( $discount > 0 ) {
133
-        $invoice->set( 'discount_code', $parent_invoice->discount_code );
132
+    if ($discount > 0) {
133
+        $invoice->set('discount_code', $parent_invoice->discount_code);
134 134
     }
135 135
     
136
-    $invoice->subtotal = wpinv_round_amount( $subtotal );
137
-    $invoice->tax      = wpinv_round_amount( $tax );
138
-    $invoice->discount = wpinv_round_amount( $discount );
139
-    $invoice->total    = wpinv_round_amount( $total );
136
+    $invoice->subtotal = wpinv_round_amount($subtotal);
137
+    $invoice->tax      = wpinv_round_amount($tax);
138
+    $invoice->discount = wpinv_round_amount($discount);
139
+    $invoice->total    = wpinv_round_amount($total);
140 140
     $invoice->save();
141 141
     
142
-    wpinv_update_payment_status( $invoice->ID, 'publish' );
142
+    wpinv_update_payment_status($invoice->ID, 'publish');
143 143
     sleep(1);
144
-    wpinv_update_payment_status( $invoice->ID, 'wpi-renewal' );
144
+    wpinv_update_payment_status($invoice->ID, 'wpi-renewal');
145 145
     
146
-    $invoice = wpinv_get_invoice( $invoice->ID );
146
+    $invoice = wpinv_get_invoice($invoice->ID);
147 147
     
148
-    $subscription_data                      = wpinv_payment_subscription_data( $parent_invoice );
148
+    $subscription_data                      = wpinv_payment_subscription_data($parent_invoice);
149 149
     $subscription_data['recurring_amount']  = $invoice->get_total();
150
-    $subscription_data['created']           = current_time( 'mysql', 0 );
151
-    $subscription_data['expiration']        = $invoice->get_new_expiration( $subscription_data['item_id'] );
150
+    $subscription_data['created']           = current_time('mysql', 0);
151
+    $subscription_data['expiration']        = $invoice->get_new_expiration($subscription_data['item_id']);
152 152
     
153 153
     // Retrieve pending subscription from database and update it's status to active and set proper profile ID
154
-    $invoice->update_subscription( $subscription_data );
154
+    $invoice->update_subscription($subscription_data);
155 155
 
156
-    do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args );
157
-    do_action( 'wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args );
156
+    do_action('wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args);
157
+    do_action('wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args);
158 158
 
159 159
     return $invoice;
160 160
 }
161 161
 
162
-function wpinv_payment_exists( $txn_id = '' ) {
162
+function wpinv_payment_exists($txn_id = '') {
163 163
     global $wpdb;
164 164
 
165
-    if ( empty( $txn_id ) ) {
165
+    if (empty($txn_id)) {
166 166
         return false;
167 167
     }
168 168
 
169
-    $txn_id = esc_sql( $txn_id );
169
+    $txn_id = esc_sql($txn_id);
170 170
 
171
-    $invoice = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1" );
171
+    $invoice = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1");
172 172
 
173
-    if ( $invoice != null ) {
173
+    if ($invoice != null) {
174 174
         return true;
175 175
     }
176 176
 
177 177
     return false;
178 178
 }
179 179
 
180
-function wpinv_is_subscription_payment( $invoice = '' ) {
181
-    if ( empty( $invoice ) ) {
180
+function wpinv_is_subscription_payment($invoice = '') {
181
+    if (empty($invoice)) {
182 182
         return false;
183 183
     }
184 184
     
185
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
186
-        $invoice = wpinv_get_invoice( $invoice );
185
+    if (!is_object($invoice) && is_scalar($invoice)) {
186
+        $invoice = wpinv_get_invoice($invoice);
187 187
     }
188 188
     
189
-    if ( empty( $invoice ) ) {
189
+    if (empty($invoice)) {
190 190
         return false;
191 191
     }
192 192
         
193
-    if ( $invoice->is_renewal() ) {
193
+    if ($invoice->is_renewal()) {
194 194
         return true;
195 195
     }
196 196
 
197 197
     return false;
198 198
 }
199 199
 
200
-function wpinv_payment_subscription_data( $invoice = '' ) {
201
-    if ( empty( $invoice ) ) {
200
+function wpinv_payment_subscription_data($invoice = '') {
201
+    if (empty($invoice)) {
202 202
         return false;
203 203
     }
204 204
     
205
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
206
-        $invoice = wpinv_get_invoice( $invoice );
205
+    if (!is_object($invoice) && is_scalar($invoice)) {
206
+        $invoice = wpinv_get_invoice($invoice);
207 207
     }
208 208
     
209
-    if ( empty( $invoice ) ) {
209
+    if (empty($invoice)) {
210 210
         return false;
211 211
     }    
212 212
 
213 213
     return $invoice->get_subscription_data();
214 214
 }
215 215
 
216
-function wpinv_payment_link_transaction_id( $invoice = '' ) {
217
-    if ( empty( $invoice ) ) {
216
+function wpinv_payment_link_transaction_id($invoice = '') {
217
+    if (empty($invoice)) {
218 218
         return false;
219 219
     }
220 220
     
221
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
222
-        $invoice = wpinv_get_invoice( $invoice );
221
+    if (!is_object($invoice) && is_scalar($invoice)) {
222
+        $invoice = wpinv_get_invoice($invoice);
223 223
     }
224 224
     
225
-    if ( empty( $invoice ) ) {
225
+    if (empty($invoice)) {
226 226
         return false;
227 227
     }
228 228
 
229
-    return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice );
229
+    return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice);
230 230
 }
231 231
 
232
-function wpinv_get_pretty_subscription_period( $period ) {
232
+function wpinv_get_pretty_subscription_period($period) {
233 233
     $frequency = '';
234 234
     //Format period details
235
-    switch ( $period ) {
235
+    switch ($period) {
236 236
         case 'D' :
237 237
         case 'day' :
238
-            $frequency = __( 'Daily', 'invoicing' );
238
+            $frequency = __('Daily', 'invoicing');
239 239
             break;
240 240
         case 'W' :
241 241
         case 'week' :
242
-            $frequency = __( 'Weekly', 'invoicing' );
242
+            $frequency = __('Weekly', 'invoicing');
243 243
             break;
244 244
         case 'M' :
245 245
         case 'month' :
246
-            $frequency = __( 'Monthly', 'invoicing' );
246
+            $frequency = __('Monthly', 'invoicing');
247 247
             break;
248 248
         case 'Y' :
249 249
         case 'year' :
250
-            $frequency = __( 'Yearly', 'invoicing' );
250
+            $frequency = __('Yearly', 'invoicing');
251 251
             break;
252 252
         default :
253
-            $frequency = apply_filters( 'wpinv_pretty_subscription_period', $frequency, $period );
253
+            $frequency = apply_filters('wpinv_pretty_subscription_period', $frequency, $period);
254 254
             break;
255 255
     }
256 256
 
257 257
     return $frequency;
258 258
 }
259 259
 
260
-function wpinv_get_pretty_subscription_period_name( $period ) {
260
+function wpinv_get_pretty_subscription_period_name($period) {
261 261
     $frequency = '';
262 262
     //Format period details
263
-    switch ( $period ) {
263
+    switch ($period) {
264 264
         case 'D' :
265 265
         case 'day' :
266
-            $frequency = __( 'Day', 'invoicing' );
266
+            $frequency = __('Day', 'invoicing');
267 267
             break;
268 268
         case 'W' :
269 269
         case 'week' :
270
-            $frequency = __( 'Week', 'invoicing' );
270
+            $frequency = __('Week', 'invoicing');
271 271
             break;
272 272
         case 'M' :
273 273
         case 'month' :
274
-            $frequency = __( 'Month', 'invoicing' );
274
+            $frequency = __('Month', 'invoicing');
275 275
             break;
276 276
         case 'Y' :
277 277
         case 'year' :
278
-            $frequency = __( 'Year', 'invoicing' );
278
+            $frequency = __('Year', 'invoicing');
279 279
             break;
280 280
         default :
281
-            $frequency = apply_filters( 'wpinv_pretty_subscription_period_name', $frequency, $period );
281
+            $frequency = apply_filters('wpinv_pretty_subscription_period_name', $frequency, $period);
282 282
             break;
283 283
     }
284 284
 
285 285
     return $frequency;
286 286
 }
287 287
 
288
-function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) {
288
+function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) {
289 289
     $interval   = (int)$interval > 0 ? (int)$interval : 1;
290 290
     
291
-    if ( $trial_interval > 0 && !empty( $trial_period ) ) {
292
-        $amount = __( 'Free', 'invoicing' );
291
+    if ($trial_interval > 0 && !empty($trial_period)) {
292
+        $amount = __('Free', 'invoicing');
293 293
         $interval = $trial_interval;
294 294
         $period = $trial_period;
295 295
     }
296 296
     
297 297
     $description = '';
298
-    switch ( $period ) {
298
+    switch ($period) {
299 299
         case 'D' :
300 300
         case 'day' :
301
-            $description = wp_sprintf( _n( '%s for the first day.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval );
301
+            $description = wp_sprintf(_n('%s for the first day.', '%s for the first %d days.', $interval, 'invoicing'), $amount, $interval);
302 302
             break;
303 303
         case 'W' :
304 304
         case 'week' :
305
-            $description = wp_sprintf( _n( '%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval );
305
+            $description = wp_sprintf(_n('%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing'), $amount, $interval);
306 306
             break;
307 307
         case 'M' :
308 308
         case 'month' :
309
-            $description = wp_sprintf( _n( '%s for the first month.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval );
309
+            $description = wp_sprintf(_n('%s for the first month.', '%s for the first %d months.', $interval, 'invoicing'), $amount, $interval);
310 310
             break;
311 311
         case 'Y' :
312 312
         case 'year' :
313
-            $description = wp_sprintf( _n( '%s for the first year.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval );
313
+            $description = wp_sprintf(_n('%s for the first year.', '%s for the first %d years.', $interval, 'invoicing'), $amount, $interval);
314 314
             break;
315 315
     }
316 316
 
317
-    return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval  );
317
+    return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval);
318 318
 }
319 319
 
320
-function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) {
320
+function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) {
321 321
     $interval   = (int)$interval > 0 ? (int)$interval : 1;
322 322
     $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0;
323 323
     
324 324
     $description = '';
325
-    switch ( $period ) {
325
+    switch ($period) {
326 326
         case 'D' :
327 327
         case 'day' :            
328
-            if ( (int)$bill_times > 0 ) {
329
-                if ( $interval > 1 ) {
330
-                    if ( $bill_times > 1 ) {
331
-                        $description = wp_sprintf( __( '%s for each %d days, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
328
+            if ((int)$bill_times > 0) {
329
+                if ($interval > 1) {
330
+                    if ($bill_times > 1) {
331
+                        $description = wp_sprintf(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
332 332
                     } else {
333
-                        $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval );
333
+                        $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval);
334 334
                     }
335 335
                 } else {
336
-                    $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
336
+                    $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
337 337
                 }
338 338
             } else {
339
-                $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval );
339
+                $description = wp_sprintf(_n('%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval);
340 340
             }
341 341
             break;
342 342
         case 'W' :
343 343
         case 'week' :            
344
-            if ( (int)$bill_times > 0 ) {
345
-                if ( $interval > 1 ) {
346
-                    if ( $bill_times > 1 ) {
347
-                        $description = wp_sprintf( __( '%s for each %d weeks, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
344
+            if ((int)$bill_times > 0) {
345
+                if ($interval > 1) {
346
+                    if ($bill_times > 1) {
347
+                        $description = wp_sprintf(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
348 348
                     } else {
349
-                        $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval );
349
+                        $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval);
350 350
                     }
351 351
                 } else {
352
-                    $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
352
+                    $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
353 353
                 }
354 354
             } else {
355
-                $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval );
355
+                $description = wp_sprintf(_n('%s for each week.', '%s for each %d weeks.', $interval, 'invoicing'), $amount, $interval);
356 356
             }
357 357
             break;
358 358
         case 'M' :
359 359
         case 'month' :            
360
-            if ( (int)$bill_times > 0 ) {
361
-                if ( $interval > 1 ) {
362
-                    if ( $bill_times > 1 ) {
363
-                        $description = wp_sprintf( __( '%s for each %d months, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
360
+            if ((int)$bill_times > 0) {
361
+                if ($interval > 1) {
362
+                    if ($bill_times > 1) {
363
+                        $description = wp_sprintf(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
364 364
                     } else {
365
-                        $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval );
365
+                        $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval);
366 366
                     }
367 367
                 } else {
368
-                    $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
368
+                    $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
369 369
                 }
370 370
             } else {
371
-                $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval );
371
+                $description = wp_sprintf(_n('%s for each month.', '%s for each %d months.', $interval, 'invoicing'), $amount, $interval);
372 372
             }
373 373
             break;
374 374
         case 'Y' :
375 375
         case 'year' :            
376
-            if ( (int)$bill_times > 0 ) {
377
-                if ( $interval > 1 ) {
378
-                    if ( $bill_times > 1 ) {
379
-                        $description = wp_sprintf( __( '%s for each %d years, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
376
+            if ((int)$bill_times > 0) {
377
+                if ($interval > 1) {
378
+                    if ($bill_times > 1) {
379
+                        $description = wp_sprintf(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
380 380
                     } else {
381
-                        $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval );
381
+                        $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval);
382 382
                     }
383 383
                 } else {
384
-                    $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
384
+                    $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
385 385
                 }
386 386
             } else {
387
-                $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval );
387
+                $description = wp_sprintf(_n('%s for each year.', '%s for each %d years.', $interval, 'invoicing'), $amount, $interval);
388 388
             }
389 389
             break;
390 390
     }
391 391
 
392
-    return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
392
+    return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
393 393
 }
394 394
 
395
-function wpinv_subscription_payment_desc( $invoice ) {
396
-    if ( empty( $invoice ) ) {
395
+function wpinv_subscription_payment_desc($invoice) {
396
+    if (empty($invoice)) {
397 397
         return NULL;
398 398
     }
399 399
     
400 400
     $description = '';
401
-    if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) {
402
-        if ( $item->has_free_trial() ) {
401
+    if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) {
402
+        if ($item->has_free_trial()) {
403 403
             $trial_period = $item->get_trial_period();
404 404
             $trial_interval = $item->get_trial_interval();
405 405
         } else {
@@ -407,45 +407,45 @@  discard block
 block discarded – undo
407 407
             $trial_interval = 0;
408 408
         }
409 409
         
410
-        $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() );
410
+        $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency());
411 411
     }
412 412
     
413
-    return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice );
413
+    return apply_filters('wpinv_subscription_payment_desc', $description, $invoice);
414 414
 }
415 415
 
416
-function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) {
417
-    $initial_total      = wpinv_round_amount( $initial );
418
-    $recurring_total    = wpinv_round_amount( $recurring );
416
+function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') {
417
+    $initial_total      = wpinv_round_amount($initial);
418
+    $recurring_total    = wpinv_round_amount($recurring);
419 419
     
420
-    if ( $trial_interval > 0 && !empty( $trial_period ) ) {
420
+    if ($trial_interval > 0 && !empty($trial_period)) {
421 421
         // Free trial
422 422
     } else {
423
-        if ( $bill_times == 1 ) {
423
+        if ($bill_times == 1) {
424 424
             $recurring_total = $initial_total;
425
-        } else if ( $bill_times > 1 && $initial_total != $recurring_total ) {
425
+        } else if ($bill_times > 1 && $initial_total != $recurring_total) {
426 426
             $bill_times--;
427 427
         }
428 428
     }
429 429
     
430
-    $initial_amount     = wpinv_price( wpinv_format_amount( $initial_total ), $currency );
431
-    $recurring_amount   = wpinv_price( wpinv_format_amount( $recurring_total ), $currency );
430
+    $initial_amount     = wpinv_price(wpinv_format_amount($initial_total), $currency);
431
+    $recurring_amount   = wpinv_price(wpinv_format_amount($recurring_total), $currency);
432 432
     
433
-    $recurring          = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
433
+    $recurring          = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
434 434
         
435
-    if ( $initial_total != $recurring_total ) {
436
-        $initial        = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval );
435
+    if ($initial_total != $recurring_total) {
436
+        $initial        = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval);
437 437
         
438
-        $description    = wp_sprintf( __( '%s Then %s', 'invoicing' ), $initial, $recurring );
438
+        $description    = wp_sprintf(__('%s Then %s', 'invoicing'), $initial, $recurring);
439 439
     } else {
440 440
         $description    = $recurring;
441 441
     }
442 442
     
443
-    return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency );
443
+    return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency);
444 444
 }
445 445
 
446
-function wpinv_recurring_send_payment_failed( $invoice ) {
447
-    if ( !empty( $invoice->ID ) ) {
448
-        wpinv_failed_invoice_notification( $invoice->ID );
446
+function wpinv_recurring_send_payment_failed($invoice) {
447
+    if (!empty($invoice->ID)) {
448
+        wpinv_failed_invoice_notification($invoice->ID);
449 449
     }
450 450
 }
451
-add_action( 'wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1 );
452 451
\ No newline at end of file
452
+add_action('wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1);
453 453
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 1 patch
Spacing   +672 added lines, -672 removed lines patch added patch discarded remove patch
@@ -7,109 +7,109 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14
-if ( !is_admin() ) {
15
-    add_filter( 'template_include', 'wpinv_template', 10, 1 );
16
-    add_action( 'wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar' );
17
-    add_action( 'wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions' );
18
-    add_action( 'wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions' );
14
+if (!is_admin()) {
15
+    add_filter('template_include', 'wpinv_template', 10, 1);
16
+    add_action('wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar');
17
+    add_action('wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions');
18
+    add_action('wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions');
19 19
 }
20 20
 
21 21
 function wpinv_template_path() {
22
-    return apply_filters( 'wpinv_template_path', 'invoicing/' );
22
+    return apply_filters('wpinv_template_path', 'invoicing/');
23 23
 }
24 24
 
25
-function wpinv_post_class( $classes, $class, $post_id ) {
25
+function wpinv_post_class($classes, $class, $post_id) {
26 26
     global $pagenow, $typenow;
27 27
 
28
-    if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' ) {
28
+    if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow && get_post_meta($post_id, '_wpinv_type', true) == 'package') {
29 29
         $classes[] = 'wpi-gd-package';
30 30
     }
31 31
     return $classes;
32 32
 }
33
-add_filter( 'post_class', 'wpinv_post_class', 10, 3 );
33
+add_filter('post_class', 'wpinv_post_class', 10, 3);
34 34
 
35
-function wpinv_display_invoice_top_bar( $invoice ) {
36
-    if ( empty( $invoice ) ) {
35
+function wpinv_display_invoice_top_bar($invoice) {
36
+    if (empty($invoice)) {
37 37
         return;
38 38
     }
39 39
     ?>
40 40
     <div class="row wpinv-top-bar no-print">
41 41
         <div class="container">
42 42
             <div class="col-xs-6">
43
-                <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?>
43
+                <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?>
44 44
             </div>
45 45
             <div class="col-xs-6 text-right">
46
-                <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?>
46
+                <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?>
47 47
             </div>
48 48
         </div>
49 49
     </div>
50 50
     <?php
51 51
 }
52 52
 
53
-function wpinv_invoice_display_left_actions( $invoice ) {
54
-    if ( empty( $invoice ) ) {
53
+function wpinv_invoice_display_left_actions($invoice) {
54
+    if (empty($invoice)) {
55 55
         return;
56 56
     }
57 57
     
58
-    if($invoice->post_type == 'wpi_invoice'){
58
+    if ($invoice->post_type == 'wpi_invoice') {
59 59
     
60 60
         $user_id = (int)$invoice->get_user_id();
61 61
         $current_user_id = (int)get_current_user_id();
62 62
 
63
-        if ( $user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment() ) {
63
+        if ($user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment()) {
64 64
             ?> 
65
-            <a class="btn btn-success btn-sm" title="<?php esc_attr_e( 'Pay This Invoice', 'invoicing' ); ?>" href="<?php echo esc_url( $invoice->get_checkout_payment_url() ); ?>"><?php _e( 'Pay For Invoice', 'invoicing' ); ?></a>
65
+            <a class="btn btn-success btn-sm" title="<?php esc_attr_e('Pay This Invoice', 'invoicing'); ?>" href="<?php echo esc_url($invoice->get_checkout_payment_url()); ?>"><?php _e('Pay For Invoice', 'invoicing'); ?></a>
66 66
             <?php
67 67
         }
68 68
     }
69 69
     do_action('wpinv_invoice_display_left_actions', $invoice);
70 70
 }
71 71
 
72
-function wpinv_invoice_display_right_actions( $invoice ) {
73
-    if ( empty( $invoice ) ) return; //Exit if invoice is not set.
72
+function wpinv_invoice_display_right_actions($invoice) {
73
+    if (empty($invoice)) return; //Exit if invoice is not set.
74 74
     
75
-    if($invoice->post_type == 'wpi_invoice'){
75
+    if ($invoice->post_type == 'wpi_invoice') {
76 76
         $user_id = (int)$invoice->get_user_id();
77 77
         $current_user_id = (int)get_current_user_id();
78 78
 
79
-        if ( $user_id > 0 && $user_id == $current_user_id ) {
79
+        if ($user_id > 0 && $user_id == $current_user_id) {
80 80
         ?>
81
-            <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a> &nbsp;
82
-            <a class="btn btn-warning btn-sm" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a>
81
+            <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a> &nbsp;
82
+            <a class="btn btn-warning btn-sm" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a>
83 83
         <?php } 
84 84
     }
85 85
     do_action('wpinv_invoice_display_right_actions', $invoice);
86 86
 }
87 87
 
88
-function wpinv_before_invoice_content( $content ) {
88
+function wpinv_before_invoice_content($content) {
89 89
     global $post;
90 90
 
91
-    if ( $post && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
91
+    if ($post && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
92 92
         ob_start();
93
-        do_action( 'wpinv_before_invoice_content', $post->ID );
93
+        do_action('wpinv_before_invoice_content', $post->ID);
94 94
         $content = ob_get_clean() . $content;
95 95
     }
96 96
 
97 97
     return $content;
98 98
 }
99
-add_filter( 'the_content', 'wpinv_before_invoice_content' );
99
+add_filter('the_content', 'wpinv_before_invoice_content');
100 100
 
101
-function wpinv_after_invoice_content( $content ) {
101
+function wpinv_after_invoice_content($content) {
102 102
     global $post;
103 103
 
104
-    if ( $post && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
104
+    if ($post && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
105 105
         ob_start();
106
-        do_action( 'wpinv_after_invoice_content', $post->ID );
106
+        do_action('wpinv_after_invoice_content', $post->ID);
107 107
         $content .= ob_get_clean();
108 108
     }
109 109
 
110 110
     return $content;
111 111
 }
112
-add_filter( 'the_content', 'wpinv_after_invoice_content' );
112
+add_filter('the_content', 'wpinv_after_invoice_content');
113 113
 
114 114
 function wpinv_get_templates_dir() {
115 115
     return WPINV_PLUGIN_DIR . 'templates';
@@ -119,105 +119,105 @@  discard block
 block discarded – undo
119 119
     return WPINV_PLUGIN_URL . 'templates';
120 120
 }
121 121
 
122
-function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
123
-    if ( ! empty( $args ) && is_array( $args ) ) {
124
-		extract( $args );
122
+function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
123
+    if (!empty($args) && is_array($args)) {
124
+		extract($args);
125 125
 	}
126 126
 
127
-	$located = wpinv_locate_template( $template_name, $template_path, $default_path );
127
+	$located = wpinv_locate_template($template_name, $template_path, $default_path);
128 128
 	// Allow 3rd party plugin filter template file from their plugin.
129
-	$located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path );
129
+	$located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path);
130 130
 
131
-	if ( ! file_exists( $located ) ) {
132
-        _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
131
+	if (!file_exists($located)) {
132
+        _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1');
133 133
 		return;
134 134
 	}
135 135
 
136
-	do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args );
136
+	do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args);
137 137
 
138
-	include( $located );
138
+	include($located);
139 139
 
140
-	do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args );
140
+	do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args);
141 141
 }
142 142
 
143
-function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
143
+function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') {
144 144
 	ob_start();
145
-	wpinv_get_template( $template_name, $args, $template_path, $default_path );
145
+	wpinv_get_template($template_name, $args, $template_path, $default_path);
146 146
 	return ob_get_clean();
147 147
 }
148 148
 
149
-function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
150
-    if ( ! $template_path ) {
149
+function wpinv_locate_template($template_name, $template_path = '', $default_path = '') {
150
+    if (!$template_path) {
151 151
         $template_path = wpinv_template_path();
152 152
     }
153 153
 
154
-    if ( ! $default_path ) {
154
+    if (!$default_path) {
155 155
         $default_path = WPINV_PLUGIN_DIR . 'templates/';
156 156
     }
157 157
 
158 158
     // Look within passed path within the theme - this is priority.
159 159
     $template = locate_template(
160 160
         array(
161
-            trailingslashit( $template_path ) . $template_name,
161
+            trailingslashit($template_path) . $template_name,
162 162
             $template_name
163 163
         )
164 164
     );
165 165
 
166 166
     // Get default templates/
167
-    if ( !$template && $default_path ) {
168
-        $template = trailingslashit( $default_path ) . $template_name;
167
+    if (!$template && $default_path) {
168
+        $template = trailingslashit($default_path) . $template_name;
169 169
     }
170 170
 
171 171
     // Return what we found.
172
-    return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path );
172
+    return apply_filters('wpinv_locate_template', $template, $template_name, $template_path);
173 173
 }
174 174
 
175
-function wpinv_get_template_part( $slug, $name = null, $load = true ) {
176
-	do_action( 'get_template_part_' . $slug, $slug, $name );
175
+function wpinv_get_template_part($slug, $name = null, $load = true) {
176
+	do_action('get_template_part_' . $slug, $slug, $name);
177 177
 
178 178
 	// Setup possible parts
179 179
 	$templates = array();
180
-	if ( isset( $name ) )
180
+	if (isset($name))
181 181
 		$templates[] = $slug . '-' . $name . '.php';
182 182
 	$templates[] = $slug . '.php';
183 183
 
184 184
 	// Allow template parts to be filtered
185
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
185
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
186 186
 
187 187
 	// Return the part that is found
188
-	return wpinv_locate_tmpl( $templates, $load, false );
188
+	return wpinv_locate_tmpl($templates, $load, false);
189 189
 }
190 190
 
191
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
191
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
192 192
 	// No file found yet
193 193
 	$located = false;
194 194
 
195 195
 	// Try to find a template file
196
-	foreach ( (array)$template_names as $template_name ) {
196
+	foreach ((array)$template_names as $template_name) {
197 197
 
198 198
 		// Continue if template is empty
199
-		if ( empty( $template_name ) )
199
+		if (empty($template_name))
200 200
 			continue;
201 201
 
202 202
 		// Trim off any slashes from the template name
203
-		$template_name = ltrim( $template_name, '/' );
203
+		$template_name = ltrim($template_name, '/');
204 204
 
205 205
 		// try locating this template file by looping through the template paths
206
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
206
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
207 207
 
208
-			if( file_exists( $template_path . $template_name ) ) {
208
+			if (file_exists($template_path . $template_name)) {
209 209
 				$located = $template_path . $template_name;
210 210
 				break;
211 211
 			}
212 212
 		}
213 213
 
214
-		if( !empty( $located ) ) {
214
+		if (!empty($located)) {
215 215
 			break;
216 216
 		}
217 217
 	}
218 218
 
219
-	if ( ( true == $load ) && ! empty( $located ) )
220
-		load_template( $located, $require_once );
219
+	if ((true == $load) && !empty($located))
220
+		load_template($located, $require_once);
221 221
 
222 222
 	return $located;
223 223
 }
@@ -226,143 +226,143 @@  discard block
 block discarded – undo
226 226
 	$template_dir = wpinv_get_theme_template_dir_name();
227 227
 
228 228
 	$file_paths = array(
229
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
230
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
229
+		1 => trailingslashit(get_stylesheet_directory()) . $template_dir,
230
+		10 => trailingslashit(get_template_directory()) . $template_dir,
231 231
 		100 => wpinv_get_templates_dir()
232 232
 	);
233 233
 
234
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
234
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
235 235
 
236 236
 	// sort the file paths based on priority
237
-	ksort( $file_paths, SORT_NUMERIC );
237
+	ksort($file_paths, SORT_NUMERIC);
238 238
 
239
-	return array_map( 'trailingslashit', $file_paths );
239
+	return array_map('trailingslashit', $file_paths);
240 240
 }
241 241
 
242 242
 function wpinv_get_theme_template_dir_name() {
243
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'wpinv_templates' ) );
243
+	return trailingslashit(apply_filters('wpinv_templates_dir', 'wpinv_templates'));
244 244
 }
245 245
 
246 246
 function wpinv_checkout_meta_tags() {
247 247
 
248 248
 	$pages   = array();
249
-	$pages[] = wpinv_get_option( 'success_page' );
250
-	$pages[] = wpinv_get_option( 'failure_page' );
251
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
249
+	$pages[] = wpinv_get_option('success_page');
250
+	$pages[] = wpinv_get_option('failure_page');
251
+	$pages[] = wpinv_get_option('invoice_history_page');
252 252
 
253
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
253
+	if (!wpinv_is_checkout() && !is_page($pages)) {
254 254
 		return;
255 255
 	}
256 256
 
257 257
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
258 258
 }
259
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
259
+add_action('wp_head', 'wpinv_checkout_meta_tags');
260 260
 
261
-function wpinv_add_body_classes( $class ) {
261
+function wpinv_add_body_classes($class) {
262 262
 	$classes = (array)$class;
263 263
 
264
-	if( wpinv_is_checkout() ) {
264
+	if (wpinv_is_checkout()) {
265 265
 		$classes[] = 'wpinv-checkout';
266 266
 		$classes[] = 'wpinv-page';
267 267
 	}
268 268
 
269
-	if( wpinv_is_success_page() ) {
269
+	if (wpinv_is_success_page()) {
270 270
 		$classes[] = 'wpinv-success';
271 271
 		$classes[] = 'wpinv-page';
272 272
 	}
273 273
 
274
-	if( wpinv_is_failed_transaction_page() ) {
274
+	if (wpinv_is_failed_transaction_page()) {
275 275
 		$classes[] = 'wpinv-failed-transaction';
276 276
 		$classes[] = 'wpinv-page';
277 277
 	}
278 278
 
279
-	if( wpinv_is_invoice_history_page() ) {
279
+	if (wpinv_is_invoice_history_page()) {
280 280
 		$classes[] = 'wpinv-history';
281 281
 		$classes[] = 'wpinv-page';
282 282
 	}
283 283
 
284
-	if( wpinv_is_test_mode() ) {
284
+	if (wpinv_is_test_mode()) {
285 285
 		$classes[] = 'wpinv-test-mode';
286 286
 		$classes[] = 'wpinv-page';
287 287
 	}
288 288
 
289
-	return array_unique( $classes );
289
+	return array_unique($classes);
290 290
 }
291
-add_filter( 'body_class', 'wpinv_add_body_classes' );
291
+add_filter('body_class', 'wpinv_add_body_classes');
292 292
 
293
-function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) {
294
-    $args = array( 'nopaging' => true );
293
+function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') {
294
+    $args = array('nopaging' => true);
295 295
 
296
-    if ( ! empty( $status ) )
296
+    if (!empty($status))
297 297
         $args['post_status'] = $status;
298 298
 
299
-    $discounts = wpinv_get_discounts( $args );
299
+    $discounts = wpinv_get_discounts($args);
300 300
     $options   = array();
301 301
 
302
-    if ( $discounts ) {
303
-        foreach ( $discounts as $discount ) {
304
-            $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) );
302
+    if ($discounts) {
303
+        foreach ($discounts as $discount) {
304
+            $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID));
305 305
         }
306 306
     } else {
307
-        $options[0] = __( 'No discounts found', 'invoicing' );
307
+        $options[0] = __('No discounts found', 'invoicing');
308 308
     }
309 309
 
310
-    $output = wpinv_html_select( array(
310
+    $output = wpinv_html_select(array(
311 311
         'name'             => $name,
312 312
         'selected'         => $selected,
313 313
         'options'          => $options,
314 314
         'show_option_all'  => false,
315 315
         'show_option_none' => false,
316
-    ) );
316
+    ));
317 317
 
318 318
     return $output;
319 319
 }
320 320
 
321
-function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
322
-    $current     = date( 'Y' );
323
-    $start_year  = $current - absint( $years_before );
324
-    $end_year    = $current + absint( $years_after );
325
-    $selected    = empty( $selected ) ? date( 'Y' ) : $selected;
321
+function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
322
+    $current     = date('Y');
323
+    $start_year  = $current - absint($years_before);
324
+    $end_year    = $current + absint($years_after);
325
+    $selected    = empty($selected) ? date('Y') : $selected;
326 326
     $options     = array();
327 327
 
328
-    while ( $start_year <= $end_year ) {
329
-        $options[ absint( $start_year ) ] = $start_year;
328
+    while ($start_year <= $end_year) {
329
+        $options[absint($start_year)] = $start_year;
330 330
         $start_year++;
331 331
     }
332 332
 
333
-    $output = wpinv_html_select( array(
333
+    $output = wpinv_html_select(array(
334 334
         'name'             => $name,
335 335
         'selected'         => $selected,
336 336
         'options'          => $options,
337 337
         'show_option_all'  => false,
338 338
         'show_option_none' => false
339
-    ) );
339
+    ));
340 340
 
341 341
     return $output;
342 342
 }
343 343
 
344
-function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) {
344
+function wpinv_html_month_dropdown($name = 'month', $selected = 0) {
345 345
     $month   = 1;
346 346
     $options = array();
347
-    $selected = empty( $selected ) ? date( 'n' ) : $selected;
347
+    $selected = empty($selected) ? date('n') : $selected;
348 348
 
349
-    while ( $month <= 12 ) {
350
-        $options[ absint( $month ) ] = wpinv_month_num_to_name( $month );
349
+    while ($month <= 12) {
350
+        $options[absint($month)] = wpinv_month_num_to_name($month);
351 351
         $month++;
352 352
     }
353 353
 
354
-    $output = wpinv_html_select( array(
354
+    $output = wpinv_html_select(array(
355 355
         'name'             => $name,
356 356
         'selected'         => $selected,
357 357
         'options'          => $options,
358 358
         'show_option_all'  => false,
359 359
         'show_option_none' => false
360
-    ) );
360
+    ));
361 361
 
362 362
     return $output;
363 363
 }
364 364
 
365
-function wpinv_html_select( $args = array() ) {
365
+function wpinv_html_select($args = array()) {
366 366
     $defaults = array(
367 367
         'options'          => array(),
368 368
         'name'             => null,
@@ -372,8 +372,8 @@  discard block
 block discarded – undo
372 372
         'chosen'           => false,
373 373
         'placeholder'      => null,
374 374
         'multiple'         => false,
375
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
376
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
375
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
376
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
377 377
         'data'             => array(),
378 378
         'onchange'         => null,
379 379
         'required'         => false,
@@ -381,78 +381,78 @@  discard block
 block discarded – undo
381 381
         'readonly'         => false,
382 382
     );
383 383
 
384
-    $args = wp_parse_args( $args, $defaults );
384
+    $args = wp_parse_args($args, $defaults);
385 385
 
386 386
     $data_elements = '';
387
-    foreach ( $args['data'] as $key => $value ) {
388
-        $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
387
+    foreach ($args['data'] as $key => $value) {
388
+        $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
389 389
     }
390 390
 
391
-    if( $args['multiple'] ) {
391
+    if ($args['multiple']) {
392 392
         $multiple = ' MULTIPLE';
393 393
     } else {
394 394
         $multiple = '';
395 395
     }
396 396
 
397
-    if( $args['chosen'] ) {
397
+    if ($args['chosen']) {
398 398
         $args['class'] .= ' wpinv-select-chosen';
399 399
     }
400 400
 
401
-    if( $args['placeholder'] ) {
401
+    if ($args['placeholder']) {
402 402
         $placeholder = $args['placeholder'];
403 403
     } else {
404 404
         $placeholder = '';
405 405
     }
406 406
     
407 407
     $options = '';
408
-    if( !empty( $args['onchange'] ) ) {
409
-        $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"';
408
+    if (!empty($args['onchange'])) {
409
+        $options .= ' onchange="' . esc_attr($args['onchange']) . '"';
410 410
     }
411 411
     
412
-    if( !empty( $args['required'] ) ) {
412
+    if (!empty($args['required'])) {
413 413
         $options .= ' required="required"';
414 414
     }
415 415
     
416
-    if( !empty( $args['disabled'] ) ) {
416
+    if (!empty($args['disabled'])) {
417 417
         $options .= ' disabled';
418 418
     }
419 419
     
420
-    if( !empty( $args['readonly'] ) ) {
420
+    if (!empty($args['readonly'])) {
421 421
         $options .= ' readonly';
422 422
     }
423 423
 
424
-    $class  = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
425
-    $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>';
424
+    $class  = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
425
+    $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>';
426 426
 
427
-    if ( $args['show_option_all'] ) {
428
-        if( $args['multiple'] ) {
429
-            $selected = selected( true, in_array( 0, $args['selected'] ), false );
427
+    if ($args['show_option_all']) {
428
+        if ($args['multiple']) {
429
+            $selected = selected(true, in_array(0, $args['selected']), false);
430 430
         } else {
431
-            $selected = selected( $args['selected'], 0, false );
431
+            $selected = selected($args['selected'], 0, false);
432 432
         }
433
-        $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
433
+        $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>';
434 434
     }
435 435
 
436
-    if ( !empty( $args['options'] ) ) {
436
+    if (!empty($args['options'])) {
437 437
 
438
-        if ( $args['show_option_none'] ) {
439
-            if( $args['multiple'] ) {
440
-                $selected = selected( true, in_array( "", $args['selected'] ), false );
438
+        if ($args['show_option_none']) {
439
+            if ($args['multiple']) {
440
+                $selected = selected(true, in_array("", $args['selected']), false);
441 441
             } else {
442
-                $selected = selected( $args['selected'] === "", true, false );
442
+                $selected = selected($args['selected'] === "", true, false);
443 443
             }
444
-            $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
444
+            $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>';
445 445
         }
446 446
 
447
-        foreach( $args['options'] as $key => $option ) {
447
+        foreach ($args['options'] as $key => $option) {
448 448
 
449
-            if( $args['multiple'] && is_array( $args['selected'] ) ) {
450
-                $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false );
449
+            if ($args['multiple'] && is_array($args['selected'])) {
450
+                $selected = selected(true, (bool)in_array($key, $args['selected']), false);
451 451
             } else {
452
-                $selected = selected( $args['selected'], $key, false );
452
+                $selected = selected($args['selected'], $key, false);
453 453
             }
454 454
 
455
-            $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
455
+            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>';
456 456
         }
457 457
     }
458 458
 
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
     return $output;
462 462
 }
463 463
 
464
-function wpinv_item_dropdown( $args = array() ) {
464
+function wpinv_item_dropdown($args = array()) {
465 465
     $defaults = array(
466 466
         'name'              => 'wpi_item',
467 467
         'id'                => 'wpi_item',
@@ -470,15 +470,15 @@  discard block
 block discarded – undo
470 470
         'selected'          => 0,
471 471
         'chosen'            => false,
472 472
         'number'            => 100,
473
-        'placeholder'       => __( 'Choose a item', 'invoicing' ),
474
-        'data'              => array( 'search-type' => 'item' ),
473
+        'placeholder'       => __('Choose a item', 'invoicing'),
474
+        'data'              => array('search-type' => 'item'),
475 475
         'show_option_all'   => false,
476 476
         'show_option_none'  => false,
477 477
         'with_packages'     => true,
478 478
         'show_recurring'    => false,
479 479
     );
480 480
 
481
-    $args = wp_parse_args( $args, $defaults );
481
+    $args = wp_parse_args($args, $defaults);
482 482
 
483 483
     $item_args = array(
484 484
         'post_type'      => 'wpi_item',
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
         'posts_per_page' => $args['number']
488 488
     );
489 489
     
490
-    if ( !$args['with_packages'] ) {
490
+    if (!$args['with_packages']) {
491 491
         $item_args['meta_query'] = array(
492 492
             array(
493 493
                 'key'       => '_wpinv_type',
@@ -497,42 +497,42 @@  discard block
 block discarded – undo
497 497
         );
498 498
     }
499 499
 
500
-    $items      = get_posts( $item_args );
500
+    $items      = get_posts($item_args);
501 501
     $options    = array();
502
-    if ( $items ) {
503
-        foreach ( $items as $item ) {
504
-            $title = esc_html( $item->post_title );
502
+    if ($items) {
503
+        foreach ($items as $item) {
504
+            $title = esc_html($item->post_title);
505 505
             
506
-            if ( !empty( $args['show_recurring'] ) ) {
507
-                $title .= wpinv_get_item_suffix( $item->ID, false );
506
+            if (!empty($args['show_recurring'])) {
507
+                $title .= wpinv_get_item_suffix($item->ID, false);
508 508
             }
509 509
             
510
-            $options[ absint( $item->ID ) ] = $title;
510
+            $options[absint($item->ID)] = $title;
511 511
         }
512 512
     }
513 513
 
514 514
     // This ensures that any selected items are included in the drop down
515
-    if( is_array( $args['selected'] ) ) {
516
-        foreach( $args['selected'] as $item ) {
517
-            if( ! in_array( $item, $options ) ) {
518
-                $title = get_the_title( $item );
519
-                if ( !empty( $args['show_recurring'] ) ) {
520
-                    $title .= wpinv_get_item_suffix( $item, false );
515
+    if (is_array($args['selected'])) {
516
+        foreach ($args['selected'] as $item) {
517
+            if (!in_array($item, $options)) {
518
+                $title = get_the_title($item);
519
+                if (!empty($args['show_recurring'])) {
520
+                    $title .= wpinv_get_item_suffix($item, false);
521 521
                 }
522 522
                 $options[$item] = $title;
523 523
             }
524 524
         }
525
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
526
-        if ( ! in_array( $args['selected'], $options ) ) {
527
-            $title = get_the_title( $args['selected'] );
528
-            if ( !empty( $args['show_recurring'] ) ) {
529
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
525
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
526
+        if (!in_array($args['selected'], $options)) {
527
+            $title = get_the_title($args['selected']);
528
+            if (!empty($args['show_recurring'])) {
529
+                $title .= wpinv_get_item_suffix($args['selected'], false);
530 530
             }
531
-            $options[$args['selected']] = get_the_title( $args['selected'] );
531
+            $options[$args['selected']] = get_the_title($args['selected']);
532 532
         }
533 533
     }
534 534
 
535
-    $output = wpinv_html_select( array(
535
+    $output = wpinv_html_select(array(
536 536
         'name'             => $args['name'],
537 537
         'selected'         => $args['selected'],
538 538
         'id'               => $args['id'],
@@ -544,12 +544,12 @@  discard block
 block discarded – undo
544 544
         'show_option_all'  => $args['show_option_all'],
545 545
         'show_option_none' => $args['show_option_none'],
546 546
         'data'             => $args['data'],
547
-    ) );
547
+    ));
548 548
 
549 549
     return $output;
550 550
 }
551 551
 
552
-function wpinv_html_checkbox( $args = array() ) {
552
+function wpinv_html_checkbox($args = array()) {
553 553
     $defaults = array(
554 554
         'name'     => null,
555 555
         'current'  => null,
@@ -560,38 +560,38 @@  discard block
 block discarded – undo
560 560
         )
561 561
     );
562 562
 
563
-    $args = wp_parse_args( $args, $defaults );
563
+    $args = wp_parse_args($args, $defaults);
564 564
 
565
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
565
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
566 566
     $options = '';
567
-    if ( ! empty( $args['options']['disabled'] ) ) {
567
+    if (!empty($args['options']['disabled'])) {
568 568
         $options .= ' disabled="disabled"';
569
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
569
+    } elseif (!empty($args['options']['readonly'])) {
570 570
         $options .= ' readonly';
571 571
     }
572 572
 
573
-    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />';
573
+    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />';
574 574
 
575 575
     return $output;
576 576
 }
577 577
 
578
-function wpinv_html_text( $args = array() ) {
578
+function wpinv_html_text($args = array()) {
579 579
     // Backwards compatibility
580
-    if ( func_num_args() > 1 ) {
580
+    if (func_num_args() > 1) {
581 581
         $args = func_get_args();
582 582
 
583 583
         $name  = $args[0];
584
-        $value = isset( $args[1] ) ? $args[1] : '';
585
-        $label = isset( $args[2] ) ? $args[2] : '';
586
-        $desc  = isset( $args[3] ) ? $args[3] : '';
584
+        $value = isset($args[1]) ? $args[1] : '';
585
+        $label = isset($args[2]) ? $args[2] : '';
586
+        $desc  = isset($args[3]) ? $args[3] : '';
587 587
     }
588 588
 
589 589
     $defaults = array(
590 590
         'id'           => '',
591
-        'name'         => isset( $name )  ? $name  : 'text',
592
-        'value'        => isset( $value ) ? $value : null,
593
-        'label'        => isset( $label ) ? $label : null,
594
-        'desc'         => isset( $desc )  ? $desc  : null,
591
+        'name'         => isset($name) ? $name : 'text',
592
+        'value'        => isset($value) ? $value : null,
593
+        'label'        => isset($label) ? $label : null,
594
+        'desc'         => isset($desc) ? $desc : null,
595 595
         'placeholder'  => '',
596 596
         'class'        => 'regular-text',
597 597
         'disabled'     => false,
@@ -601,51 +601,51 @@  discard block
 block discarded – undo
601 601
         'data'         => false
602 602
     );
603 603
 
604
-    $args = wp_parse_args( $args, $defaults );
604
+    $args = wp_parse_args($args, $defaults);
605 605
 
606
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
606
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
607 607
     $options = '';
608
-    if( $args['required'] ) {
608
+    if ($args['required']) {
609 609
         $options .= ' required="required"';
610 610
     }
611
-    if( $args['readonly'] ) {
611
+    if ($args['readonly']) {
612 612
         $options .= ' readonly';
613 613
     }
614
-    if( $args['readonly'] ) {
614
+    if ($args['readonly']) {
615 615
         $options .= ' readonly';
616 616
     }
617 617
 
618 618
     $data = '';
619
-    if ( !empty( $args['data'] ) ) {
620
-        foreach ( $args['data'] as $key => $value ) {
621
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
619
+    if (!empty($args['data'])) {
620
+        foreach ($args['data'] as $key => $value) {
621
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
622 622
         }
623 623
     }
624 624
 
625
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
626
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
627
-    if ( ! empty( $args['desc'] ) ) {
628
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
625
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
626
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
627
+    if (!empty($args['desc'])) {
628
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
629 629
     }
630 630
 
631
-    $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] )  . '" autocomplete="' . esc_attr( $args['autocomplete'] )  . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>';
631
+    $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>';
632 632
 
633 633
     $output .= '</span>';
634 634
 
635 635
     return $output;
636 636
 }
637 637
 
638
-function wpinv_html_date_field( $args = array() ) {
639
-    if( empty( $args['class'] ) ) {
638
+function wpinv_html_date_field($args = array()) {
639
+    if (empty($args['class'])) {
640 640
         $args['class'] = 'wpiDatepicker';
641
-    } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) {
641
+    } elseif (!strpos($args['class'], 'wpiDatepicker')) {
642 642
         $args['class'] .= ' wpiDatepicker';
643 643
     }
644 644
 
645
-    return wpinv_html_text( $args );
645
+    return wpinv_html_text($args);
646 646
 }
647 647
 
648
-function wpinv_html_textarea( $args = array() ) {
648
+function wpinv_html_textarea($args = array()) {
649 649
     $defaults = array(
650 650
         'name'        => 'textarea',
651 651
         'value'       => null,
@@ -655,31 +655,31 @@  discard block
 block discarded – undo
655 655
         'disabled'    => false
656 656
     );
657 657
 
658
-    $args = wp_parse_args( $args, $defaults );
658
+    $args = wp_parse_args($args, $defaults);
659 659
 
660
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
660
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
661 661
     $disabled = '';
662
-    if( $args['disabled'] ) {
662
+    if ($args['disabled']) {
663 663
         $disabled = ' disabled="disabled"';
664 664
     }
665 665
 
666
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
667
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
668
-    $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
666
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
667
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
668
+    $output .= '<textarea name="' . esc_attr($args['name']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>';
669 669
 
670
-    if ( ! empty( $args['desc'] ) ) {
671
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
670
+    if (!empty($args['desc'])) {
671
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
672 672
     }
673 673
     $output .= '</span>';
674 674
 
675 675
     return $output;
676 676
 }
677 677
 
678
-function wpinv_html_ajax_user_search( $args = array() ) {
678
+function wpinv_html_ajax_user_search($args = array()) {
679 679
     $defaults = array(
680 680
         'name'        => 'user_id',
681 681
         'value'       => null,
682
-        'placeholder' => __( 'Enter username', 'invoicing' ),
682
+        'placeholder' => __('Enter username', 'invoicing'),
683 683
         'label'       => null,
684 684
         'desc'        => null,
685 685
         'class'       => '',
@@ -688,13 +688,13 @@  discard block
 block discarded – undo
688 688
         'data'        => false
689 689
     );
690 690
 
691
-    $args = wp_parse_args( $args, $defaults );
691
+    $args = wp_parse_args($args, $defaults);
692 692
 
693 693
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
694 694
 
695 695
     $output  = '<span class="wpinv_user_search_wrap">';
696
-        $output .= wpinv_html_text( $args );
697
-        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>';
696
+        $output .= wpinv_html_text($args);
697
+        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>';
698 698
     $output .= '</span>';
699 699
 
700 700
     return $output;
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
 function wpinv_ip_geolocation() {
704 704
     global $wpinv_euvat;
705 705
     
706
-    $ip         = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : '';    
706
+    $ip         = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : '';    
707 707
     $content    = '';
708 708
     $iso        = '';
709 709
     $country    = '';
@@ -714,69 +714,69 @@  discard block
 block discarded – undo
714 714
     $credit     = '';
715 715
     $address    = '';
716 716
     
717
-    if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) {
717
+    if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) {
718 718
         try {
719 719
             $iso        = $geoip2_city->country->isoCode;
720 720
             $country    = $geoip2_city->country->name;
721
-            $region     = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : '';
721
+            $region     = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : '';
722 722
             $city       = $geoip2_city->city->name;
723 723
             $longitude  = $geoip2_city->location->longitude;
724 724
             $latitude   = $geoip2_city->location->latitude;
725
-            $credit     = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' );
726
-        } catch( Exception $e ) { }
725
+            $credit     = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing');
726
+        } catch (Exception $e) { }
727 727
     }
728 728
     
729
-    if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) {
729
+    if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) {
730 730
         try {
731
-            $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
731
+            $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
732 732
             
733
-            if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) {
733
+            if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) {
734 734
                 $iso        = $load_xml->geoplugin_countryCode;
735 735
                 $country    = $load_xml->geoplugin_countryName;
736
-                $region     = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : '';
737
-                $city       = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : '';
736
+                $region     = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : '';
737
+                $city       = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : '';
738 738
                 $longitude  = $load_xml->geoplugin_longitude;
739 739
                 $latitude   = $load_xml->geoplugin_latitude;
740 740
                 $credit     = $load_xml->geoplugin_credit;
741
-                $credit     = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit;
741
+                $credit     = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit;
742 742
             }
743
-        } catch( Exception $e ) { }
743
+        } catch (Exception $e) { }
744 744
     }
745 745
     
746
-    if ( $iso && $longitude && $latitude ) {
747
-        if ( $city ) {
746
+    if ($iso && $longitude && $latitude) {
747
+        if ($city) {
748 748
             $address .= $city . ', ';
749 749
         }
750 750
         
751
-        if ( $region ) {
751
+        if ($region) {
752 752
             $address .= $region . ', ';
753 753
         }
754 754
         
755 755
         $address .= $country . ' (' . $iso . ')';
756
-        $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>';
757
-        $content .= '<p>'. $credit . '</p>';
756
+        $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>';
757
+        $content .= '<p>' . $credit . '</p>';
758 758
     } else {
759
-        $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>';
759
+        $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>';
760 760
     }
761 761
     ?>
762 762
 <!DOCTYPE html>
763
-<html><head><title><?php echo sprintf( __( 'IP: %s', 'invoicing' ), $ip );?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
763
+<html><head><title><?php echo sprintf(__('IP: %s', 'invoicing'), $ip); ?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
764 764
 <body>
765
-    <?php if ( $latitude && $latitude ) { ?>
765
+    <?php if ($latitude && $latitude) { ?>
766 766
     <div id="map"></div>
767 767
         <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script>
768 768
         <script type="text/javascript">
769 769
         var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
770 770
             osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
771 771
             osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}),
772
-            latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>);
772
+            latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>);
773 773
 
774 774
         var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]});
775 775
 
776 776
         var marker = new L.Marker(latlng);
777 777
         map.addLayer(marker);
778 778
 
779
-        marker.bindPopup("<p><?php esc_attr_e( $address );?></p>");
779
+        marker.bindPopup("<p><?php esc_attr_e($address); ?></p>");
780 780
     </script>
781 781
     <?php } ?>
782 782
     <div style="height:100px"><?php echo $content; ?></div>
@@ -784,31 +784,31 @@  discard block
 block discarded – undo
784 784
 <?php
785 785
     exit;
786 786
 }
787
-add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
788
-add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
787
+add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
788
+add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
789 789
 
790 790
 // Set up the template for the invoice.
791
-function wpinv_template( $template ) {
791
+function wpinv_template($template) {
792 792
     global $post, $wp_query;
793 793
     
794
-    if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) {
795
-        if ( wpinv_user_can_print_invoice( $post->ID ) ) {
796
-            $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false );
794
+    if ((is_single() || is_404()) && !empty($post->ID) && (get_post_type($post->ID) == 'wpi_invoice' or get_post_type($post->ID) == 'wpi_quote')) {
795
+        if (wpinv_user_can_print_invoice($post->ID)) {
796
+            $template = wpinv_get_template_part('wpinv-invoice-print', false, false);
797 797
         } else {
798
-            if ( !is_user_logged_in() && !empty( $_REQUEST['_wpipay'] ) && $invoice = wpinv_get_invoice( $post->ID ) ) {
798
+            if (!is_user_logged_in() && !empty($_REQUEST['_wpipay']) && $invoice = wpinv_get_invoice($post->ID)) {
799 799
                 $user_id = $invoice->get_user_id();
800
-                $secret = sanitize_text_field( $_GET['_wpipay'] );
800
+                $secret = sanitize_text_field($_GET['_wpipay']);
801 801
 
802
-                if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key() ) ) { // valid invoice link
803
-                    $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
802
+                if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key())) { // valid invoice link
803
+                    $redirect_to = remove_query_arg('_wpipay', get_permalink());
804 804
 
805
-                    wpinv_guest_redirect( $redirect_to, $user_id );
805
+                    wpinv_guest_redirect($redirect_to, $user_id);
806 806
                     wpinv_die();
807 807
                 }
808 808
             }
809
-            $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
809
+            $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
810 810
 
811
-            wp_redirect( $redirect_to );
811
+            wp_redirect($redirect_to);
812 812
             wpinv_die();
813 813
         }
814 814
     }
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
 
819 819
 function wpinv_get_business_address() {
820 820
     $business_address   = wpinv_store_address();
821
-    $business_address   = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
821
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
822 822
     
823 823
     /*
824 824
     $default_country    = wpinv_get_default_country();
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
     
843 843
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
844 844
     
845
-    return apply_filters( 'wpinv_get_business_address', $business_address );
845
+    return apply_filters('wpinv_get_business_address', $business_address);
846 846
 }
847 847
 
848 848
 function wpinv_display_from_address() {
@@ -852,185 +852,185 @@  discard block
 block discarded – undo
852 852
     if (empty($from_name)) {
853 853
         $from_name = wpinv_get_business_name();
854 854
     }
855
-    ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div>
855
+    ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div>
856 856
     <div class="wrapper col-xs-10">
857
-        <div class="name"><?php echo esc_html( $from_name ); ?></div>
858
-        <?php if ( $address = wpinv_get_business_address() ) { ?>
859
-        <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div>
857
+        <div class="name"><?php echo esc_html($from_name); ?></div>
858
+        <?php if ($address = wpinv_get_business_address()) { ?>
859
+        <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div>
860 860
         <?php } ?>
861
-        <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?>
862
-        <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s' ), $email_from );?></div>
861
+        <?php if ($email_from = wpinv_mail_get_from_address()) { ?>
862
+        <div class="email_from"><?php echo wp_sprintf(__('Email: %s'), $email_from); ?></div>
863 863
         <?php } ?>
864 864
     </div>
865 865
     <?php
866 866
 }
867 867
 
868
-function wpinv_watermark( $id = 0 ) {
869
-    $output = wpinv_get_watermark( $id );
868
+function wpinv_watermark($id = 0) {
869
+    $output = wpinv_get_watermark($id);
870 870
     
871
-    return apply_filters( 'wpinv_get_watermark', $output, $id );
871
+    return apply_filters('wpinv_get_watermark', $output, $id);
872 872
 }
873 873
 
874
-function wpinv_get_watermark( $id ) {
875
-    if ( !$id > 0 ) {
874
+function wpinv_get_watermark($id) {
875
+    if (!$id > 0) {
876 876
         return NULL;
877 877
     }
878
-    $invoice = wpinv_get_invoice( $id );
878
+    $invoice = wpinv_get_invoice($id);
879 879
     
880
-    if ( !empty( $invoice ) ) {
881
-        if ( $invoice->is_paid() ) {
882
-            return __( 'Paid', 'invoicing' );
880
+    if (!empty($invoice)) {
881
+        if ($invoice->is_paid()) {
882
+            return __('Paid', 'invoicing');
883 883
         }
884
-        if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) {
885
-            return __( 'Cancelled', 'invoicing' );
884
+        if ($invoice->has_status(array('wpi-cancelled'))) {
885
+            return __('Cancelled', 'invoicing');
886 886
         }
887 887
     }
888 888
     
889 889
     return NULL;
890 890
 }
891 891
 
892
-function wpinv_display_invoice_details( $invoice ) {
892
+function wpinv_display_invoice_details($invoice) {
893 893
     global $wpinv_euvat;
894 894
     
895 895
     $invoice_id = $invoice->ID;
896 896
     $vat_name   = $wpinv_euvat->get_vat_name();
897 897
     $use_taxes  = wpinv_use_taxes();
898 898
     
899
-    $invoice_status = wpinv_get_invoice_status( $invoice_id );
899
+    $invoice_status = wpinv_get_invoice_status($invoice_id);
900 900
     
901
-    if($invoice->post_type == 'wpi_invoice') $type = 'Invoice';
902
-    elseif($invoice->post_type == 'wpi_quote') $type = 'Quote';
901
+    if ($invoice->post_type == 'wpi_invoice') $type = 'Invoice';
902
+    elseif ($invoice->post_type == 'wpi_quote') $type = 'Quote';
903 903
     ?>
904 904
     <table class="table table-bordered table-sm">
905
-        <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?>
905
+        <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?>
906 906
             <tr class="wpi-row-number">
907
-                <th><?php echo sprintf(__( '%s Number', 'invoicing' ), $type); ?></th>
908
-                <td><?php echo esc_html( $invoice_number ); ?></td>
907
+                <th><?php echo sprintf(__('%s Number', 'invoicing'), $type); ?></th>
908
+                <td><?php echo esc_html($invoice_number); ?></td>
909 909
             </tr>
910 910
         <?php } ?>
911 911
         <tr class="wpi-row-status">
912
-            <th><?php echo wp_sprintf(__( '%s Status', 'invoicing' ), $type); ?></th>
913
-            <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td>
912
+            <th><?php echo wp_sprintf(__('%s Status', 'invoicing'), $type); ?></th>
913
+            <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td>
914 914
         </tr>
915
-        <?php if ( $invoice->is_renewal() ) { ?>
915
+        <?php if ($invoice->is_renewal()) { ?>
916 916
         <tr class="wpi-row-parent">
917
-            <th><?php echo wp_sprintf(__( 'Parent %s', 'invoicing' ), $type); ?></th>
918
-            <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td>
917
+            <th><?php echo wp_sprintf(__('Parent %s', 'invoicing'), $type); ?></th>
918
+            <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td>
919 919
         </tr>
920 920
         <?php } ?>
921 921
         <tr class="wpi-row-gateway">
922
-            <th><?php _e( 'Payment Method', 'invoicing' ); ?></th>
923
-            <td><?php echo wpinv_get_payment_gateway_name( $invoice_id ); ?></td>
922
+            <th><?php _e('Payment Method', 'invoicing'); ?></th>
923
+            <td><?php echo wpinv_get_payment_gateway_name($invoice_id); ?></td>
924 924
         </tr>
925
-        <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?>
925
+        <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?>
926 926
             <tr class="wpi-row-date">
927
-                <th><?php echo wp_sprintf(__( '%s Date', 'invoicing' ), $type); ?></th>
927
+                <th><?php echo wp_sprintf(__('%s Date', 'invoicing'), $type); ?></th>
928 928
                 <td><?php echo $invoice_date; ?></td>
929 929
             </tr>
930 930
         <?php } ?>
931
-        <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?>
931
+        <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?>
932 932
             <tr class="wpi-row-date">
933
-                <th><?php _e( 'Due Date', 'invoicing' ); ?></th>
933
+                <th><?php _e('Due Date', 'invoicing'); ?></th>
934 934
                 <td><?php echo $due_date; ?></td>
935 935
             </tr>
936 936
         <?php } ?>
937
-        <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?>
937
+        <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?>
938 938
             <tr class="wpi-row-ovatno">
939
-                <th><?php echo wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ); ?></th>
939
+                <th><?php echo wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name); ?></th>
940 940
                 <td><?php echo $owner_vat_number; ?></td>
941 941
             </tr>
942 942
         <?php } ?>
943
-        <?php if ( $use_taxes && $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) { ?>
943
+        <?php if ($use_taxes && $user_vat_number = wpinv_get_invoice_vat_number($invoice_id)) { ?>
944 944
             <tr class="wpi-row-uvatno">
945
-                <th><?php echo wp_sprintf( __( 'Your %s Number', 'invoicing' ), $vat_name ); ?></th>
945
+                <th><?php echo wp_sprintf(__('Your %s Number', 'invoicing'), $vat_name); ?></th>
946 946
                 <td><?php echo $user_vat_number; ?></td>
947 947
             </tr>
948 948
         <?php } ?>
949 949
         <tr class="table-active tr-total wpi-row-total">
950
-            <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th>
951
-            <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td>
950
+            <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th>
951
+            <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td>
952 952
         </tr>
953 953
     </table>
954 954
 <?php
955 955
 }
956 956
 
957
-function wpinv_display_to_address( $invoice_id = 0 ) {
958
-    $invoice = wpinv_get_invoice( $invoice_id );
957
+function wpinv_display_to_address($invoice_id = 0) {
958
+    $invoice = wpinv_get_invoice($invoice_id);
959 959
     
960
-    if ( empty( $invoice ) ) {
960
+    if (empty($invoice)) {
961 961
         return NULL;
962 962
     }
963 963
     
964 964
     $billing_details = $invoice->get_user_info();
965
-    $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>';
965
+    $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>';
966 966
     $output .= '<div class="wrapper col-xs-10">';
967 967
     
968 968
     ob_start();
969
-    do_action( 'wpinv_display_to_address_top', $invoice );
969
+    do_action('wpinv_display_to_address_top', $invoice);
970 970
     $output .= ob_get_clean();
971 971
     
972
-    $output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>';
973
-    if ( $company = $billing_details['company'] ) {
974
-        $output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>';
972
+    $output .= '<div class="name">' . esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])) . '</div>';
973
+    if ($company = $billing_details['company']) {
974
+        $output .= '<div class="company">' . wpautop(wp_kses_post($company)) . '</div>';
975 975
     }
976 976
     $address_row = '';
977
-    if ( $address = $billing_details['address'] ) {
978
-        $address_row .= wpautop( wp_kses_post( $address ) );
977
+    if ($address = $billing_details['address']) {
978
+        $address_row .= wpautop(wp_kses_post($address));
979 979
     }
980 980
     
981 981
     $address_fields = array();
982
-    if ( !empty( $billing_details['city'] ) ) {
982
+    if (!empty($billing_details['city'])) {
983 983
         $address_fields[] = $billing_details['city'];
984 984
     }
985 985
     
986
-    $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : '';
987
-    if ( !empty( $billing_details['state'] ) ) {
988
-        $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country );
986
+    $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : '';
987
+    if (!empty($billing_details['state'])) {
988
+        $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country);
989 989
     }
990 990
     
991
-    if ( !empty( $billing_country ) ) {
992
-        $address_fields[] = wpinv_country_name( $billing_country );
991
+    if (!empty($billing_country)) {
992
+        $address_fields[] = wpinv_country_name($billing_country);
993 993
     }
994 994
     
995
-    if ( !empty( $address_fields ) ) {
996
-        $address_fields = implode( ", ", $address_fields );
995
+    if (!empty($address_fields)) {
996
+        $address_fields = implode(", ", $address_fields);
997 997
         
998
-        if ( !empty( $billing_details['zip'] ) ) {
998
+        if (!empty($billing_details['zip'])) {
999 999
             $address_fields .= ' ' . $billing_details['zip'];
1000 1000
         }
1001 1001
         
1002
-        $address_row .= wpautop( wp_kses_post( $address_fields ) );
1002
+        $address_row .= wpautop(wp_kses_post($address_fields));
1003 1003
     }
1004 1004
     
1005
-    if ( $address_row ) {
1005
+    if ($address_row) {
1006 1006
         $output .= '<div class="address">' . $address_row . '</div>';
1007 1007
     }
1008 1008
     
1009
-    if ( $phone = $invoice->get_phone() ) {
1010
-        $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s' ), esc_html( $phone ) ) . '</div>';
1009
+    if ($phone = $invoice->get_phone()) {
1010
+        $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s'), esc_html($phone)) . '</div>';
1011 1011
     }
1012
-    if ( $email = $invoice->get_email() ) {
1013
-        $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' ), esc_html( $email ) ) . '</div>';
1012
+    if ($email = $invoice->get_email()) {
1013
+        $output .= '<div class="email">' . wp_sprintf(__('Email: %s'), esc_html($email)) . '</div>';
1014 1014
     }
1015 1015
     
1016 1016
     ob_start();
1017
-    do_action( 'wpinv_display_to_address_bottom', $invoice );
1017
+    do_action('wpinv_display_to_address_bottom', $invoice);
1018 1018
     $output .= ob_get_clean();
1019 1019
     
1020 1020
     $output .= '</div>';
1021
-    $output = apply_filters( 'wpinv_display_to_address', $output, $invoice );
1021
+    $output = apply_filters('wpinv_display_to_address', $output, $invoice);
1022 1022
 
1023 1023
     echo $output;
1024 1024
 }
1025 1025
 
1026
-function wpinv_display_line_items( $invoice_id = 0 ) {
1026
+function wpinv_display_line_items($invoice_id = 0) {
1027 1027
     global $wpinv_euvat, $ajax_cart_details;
1028
-    $invoice            = wpinv_get_invoice( $invoice_id );
1028
+    $invoice            = wpinv_get_invoice($invoice_id);
1029 1029
     $quantities_enabled = wpinv_item_quantities_enabled();
1030 1030
     $use_taxes          = wpinv_use_taxes();
1031 1031
     $zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
1032
-    $tax_label           = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' );
1033
-    $tax_title          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
1032
+    $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing');
1033
+    $tax_title          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
1034 1034
     
1035 1035
     $cart_details       = $invoice->get_cart_details();
1036 1036
     $ajax_cart_details  = $cart_details;
@@ -1039,68 +1039,68 @@  discard block
 block discarded – undo
1039 1039
     <table class="table table-sm table-bordered table-responsive">
1040 1040
         <thead>
1041 1041
             <tr>
1042
-                <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th>
1043
-                <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th>
1042
+                <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th>
1043
+                <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th>
1044 1044
                 <?php if ($quantities_enabled) { ?>
1045
-                    <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th>
1045
+                    <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th>
1046 1046
                 <?php } ?>
1047 1047
                 <?php if ($use_taxes && !$zero_tax) { ?>
1048 1048
                     <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th>
1049 1049
                 <?php } ?>
1050
-                <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th>
1050
+                <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th>
1051 1051
             </tr>
1052 1052
         </thead>
1053 1053
         <tbody>
1054 1054
         <?php 
1055
-            if ( !empty( $cart_details ) ) {
1056
-                do_action( 'wpinv_display_line_items_start', $invoice );
1055
+            if (!empty($cart_details)) {
1056
+                do_action('wpinv_display_line_items_start', $invoice);
1057 1057
                 
1058 1058
                 $count = 0;
1059 1059
                 $cols  = 3;
1060
-                foreach ( $cart_details as $key => $cart_item ) {
1061
-                    $item_id    = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : '';
1062
-                    $item_price = isset($cart_item["item_price"]) ? wpinv_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_cpt_singular_name(), $post_link );
1076
+                        $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>';
1077
+                        $summary = wp_sprintf(__('%s: %s', 'invoicing'), $item->get_cpt_singular_name(), $post_link);
1078 1078
                     }
1079
-                    $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice );
1079
+                    $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice);
1080 1080
                     
1081 1081
                     $item_tax       = '';
1082 1082
                     $tax_rate       = '';
1083
-                    if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1084
-                        $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) );
1085
-                        $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1086
-                        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 2 ) : '';
1083
+                    if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1084
+                        $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']));
1085
+                        $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1086
+                        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 2) : '';
1087 1087
                         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : '';
1088 1088
                     }
1089 1089
                     
1090 1090
                     $line_item_tax = $item_tax . $tax_rate;
1091 1091
                     
1092
-                    if ( $line_item_tax === '' ) {
1092
+                    if ($line_item_tax === '') {
1093 1093
                         $line_item_tax = 0; // Zero tax
1094 1094
                     }
1095 1095
                     
1096
-                    $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">';
1097
-                        $line_item .= '<td class="name">' . esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item );
1098
-                        if ( $summary !== '' ) {
1099
-                            $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>';
1096
+                    $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">';
1097
+                        $line_item .= '<td class="name">' . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item);
1098
+                        if ($summary !== '') {
1099
+                            $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>';
1100 1100
                         }
1101 1101
                         $line_item .= '</td>';
1102 1102
                         
1103
-                        $line_item .= '<td class="rate">' . esc_html__( wpinv_price( 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_cpt_singular_name(), $post_link );
1327
+            $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>';
1328
+            $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_cpt_singular_name(), $post_link);
1329 1329
         }
1330
-        $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice );
1330
+        $summary = apply_filters('wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice);
1331 1331
         
1332 1332
         $item_tax       = '';
1333 1333
         $tax_rate       = '';
1334
-        if ( $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1335
-            $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) );
1336
-            $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1337
-            $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $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) : '';
1338 1338
             $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : '';
1339 1339
         }
1340 1340
         $line_item_tax = $item_tax . $tax_rate;
1341 1341
         
1342
-        if ( $line_item_tax === '' ) {
1342
+        if ($line_item_tax === '') {
1343 1343
             $line_item_tax = 0; // Zero tax
1344 1344
         }
1345 1345
 
1346
-        $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">';
1346
+        $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">';
1347 1347
             $line_item .= '<td class="id">' . $item_id . '</td>';
1348
-            $line_item .= '<td class="title"><a href="' . get_edit_post_link( $item_id ) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix( $wpi_item );
1349
-            if ( $summary !== '' ) {
1350
-                $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>';
1348
+            $line_item .= '<td class="title"><a href="' . get_edit_post_link($item_id) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix($wpi_item);
1349
+            if ($summary !== '') {
1350
+                $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>';
1351 1351
             }
1352 1352
             $line_item .= '</td>';
1353 1353
             $line_item .= '<td class="price">' . $item_price . '</td>';
1354 1354
             
1355
-            if ( $item_quantities ) {
1356
-                if ( count( $cart_items ) == 1 && $quantity <= 1 ) {
1355
+            if ($item_quantities) {
1356
+                if (count($cart_items) == 1 && $quantity <= 1) {
1357 1357
                     $can_remove = false;
1358 1358
                 }
1359 1359
                 $line_item .= '<td class="qty" data-quantity="' . $quantity . '">&nbsp;&times;&nbsp;' . $quantity . '</td>';
1360 1360
             } else {
1361
-                if ( count( $cart_items ) == 1 ) {
1361
+                if (count($cart_items) == 1) {
1362 1362
                     $can_remove = false;
1363 1363
                 }
1364 1364
             }
1365 1365
             $line_item .= '<td class="total">' . $item_subtotal . '</td>';
1366 1366
             
1367
-            if ( $use_taxes ) {
1367
+            if ($use_taxes) {
1368 1368
                 $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1369 1369
             }
1370 1370
             $line_item .= '<td class="action">';
1371
-            if ( !$invoice->is_paid() && $can_remove ) {
1371
+            if (!$invoice->is_paid() && $can_remove) {
1372 1372
                 $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>';
1373 1373
             }
1374 1374
             $line_item .= '</td>';
1375 1375
         $line_item .= '</tr>';
1376 1376
         
1377
-        echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice );
1377
+        echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice);
1378 1378
         
1379 1379
         $count++;
1380 1380
     } 
1381 1381
     
1382
-    do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice );
1382
+    do_action('wpinv_admin_after_line_items', $cart_items, $invoice);
1383 1383
     
1384 1384
     return ob_get_clean();
1385 1385
 }
@@ -1390,35 +1390,35 @@  discard block
 block discarded – undo
1390 1390
     // Set current invoice id.
1391 1391
     $wpi_checkout_id = wpinv_get_invoice_cart_id();
1392 1392
     
1393
-    $form_action  = esc_url( wpinv_get_checkout_uri() );
1393
+    $form_action = esc_url(wpinv_get_checkout_uri());
1394 1394
 
1395 1395
     ob_start();
1396 1396
         echo '<div id="wpinv_checkout_wrap">';
1397 1397
         
1398
-        if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) {
1398
+        if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) {
1399 1399
             ?>
1400 1400
             <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive">
1401
-                <?php do_action( 'wpinv_before_checkout_form' ); ?>
1401
+                <?php do_action('wpinv_before_checkout_form'); ?>
1402 1402
                 <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST">
1403 1403
                     <?php
1404
-                    do_action( 'wpinv_checkout_form_top' );
1405
-                    do_action( 'wpinv_checkout_billing_info' );
1406
-                    do_action( 'wpinv_checkout_cart' );
1407
-                    do_action( 'wpinv_payment_mode_select'  );
1408
-                    do_action( 'wpinv_checkout_form_bottom' )
1404
+                    do_action('wpinv_checkout_form_top');
1405
+                    do_action('wpinv_checkout_billing_info');
1406
+                    do_action('wpinv_checkout_cart');
1407
+                    do_action('wpinv_payment_mode_select');
1408
+                    do_action('wpinv_checkout_form_bottom')
1409 1409
                     ?>
1410 1410
                 </form>
1411
-                <?php do_action( 'wpinv_after_purchase_form' ); ?>
1411
+                <?php do_action('wpinv_after_purchase_form'); ?>
1412 1412
             </div><!--end #wpinv_checkout_form_wrap-->
1413 1413
         <?php
1414 1414
         } else {
1415
-            do_action( 'wpinv_cart_empty' );
1415
+            do_action('wpinv_cart_empty');
1416 1416
         }
1417 1417
         echo '</div><!--end #wpinv_checkout_wrap-->';
1418 1418
     return ob_get_clean();
1419 1419
 }
1420 1420
 
1421
-function wpinv_checkout_cart( $cart_details = array(), $echo = true ) {
1421
+function wpinv_checkout_cart($cart_details = array(), $echo = true) {
1422 1422
     global $ajax_cart_details;
1423 1423
     $ajax_cart_details = $cart_details;
1424 1424
     /*
@@ -1433,25 +1433,25 @@  discard block
 block discarded – undo
1433 1433
     }
1434 1434
     */
1435 1435
     ob_start();
1436
-    do_action( 'wpinv_before_checkout_cart' );
1436
+    do_action('wpinv_before_checkout_cart');
1437 1437
     echo '<div id="wpinv_checkout_cart_form" method="post">';
1438 1438
         echo '<div id="wpinv_checkout_cart_wrap">';
1439
-            wpinv_get_template_part( 'wpinv-checkout-cart' );
1439
+            wpinv_get_template_part('wpinv-checkout-cart');
1440 1440
         echo '</div>';
1441 1441
     echo '</div>';
1442
-    do_action( 'wpinv_after_checkout_cart' );
1442
+    do_action('wpinv_after_checkout_cart');
1443 1443
     $content = ob_get_clean();
1444 1444
     
1445
-    if ( $echo ) {
1445
+    if ($echo) {
1446 1446
         echo $content;
1447 1447
     } else {
1448 1448
         return $content;
1449 1449
     }
1450 1450
 }
1451
-add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 );
1451
+add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10);
1452 1452
 
1453 1453
 function wpinv_empty_cart_message() {
1454
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1454
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1455 1455
 }
1456 1456
 
1457 1457
 /**
@@ -1463,91 +1463,91 @@  discard block
 block discarded – undo
1463 1463
 function wpinv_empty_checkout_cart() {
1464 1464
 	echo wpinv_empty_cart_message();
1465 1465
 }
1466
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1466
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1467 1467
 
1468 1468
 function wpinv_save_cart_button() {
1469
-    if ( wpinv_is_cart_saving_disabled() )
1469
+    if (wpinv_is_cart_saving_disabled())
1470 1470
         return;
1471 1471
 ?>
1472
-    <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url( add_query_arg( 'wpi_action', 'save_cart' ) ); ?>"><?php _e( 'Save Cart', 'invoicing' ); ?></a>
1472
+    <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url(add_query_arg('wpi_action', 'save_cart')); ?>"><?php _e('Save Cart', 'invoicing'); ?></a>
1473 1473
 <?php
1474 1474
 }
1475 1475
 
1476 1476
 function wpinv_update_cart_button() {
1477
-    if ( !wpinv_item_quantities_enabled() )
1477
+    if (!wpinv_item_quantities_enabled())
1478 1478
         return;
1479 1479
 ?>
1480
-    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/>
1480
+    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/>
1481 1481
     <input type="hidden" name="wpi_action" value="update_cart"/>
1482 1482
 <?php
1483 1483
 }
1484 1484
 
1485 1485
 function wpinv_checkout_cart_columns() {
1486 1486
     $default = 3;
1487
-    if ( wpinv_item_quantities_enabled() ) {
1487
+    if (wpinv_item_quantities_enabled()) {
1488 1488
         $default++;
1489 1489
     }
1490 1490
     
1491
-    if ( wpinv_use_taxes() ) {
1491
+    if (wpinv_use_taxes()) {
1492 1492
         $default++;
1493 1493
     }
1494 1494
 
1495
-    return apply_filters( 'wpinv_checkout_cart_columns', $default );
1495
+    return apply_filters('wpinv_checkout_cart_columns', $default);
1496 1496
 }
1497 1497
 
1498 1498
 function wpinv_display_cart_messages() {
1499 1499
     global $wpi_session;
1500 1500
 
1501
-    $messages = $wpi_session->get( 'wpinv_cart_messages' );
1501
+    $messages = $wpi_session->get('wpinv_cart_messages');
1502 1502
 
1503
-    if ( $messages ) {
1504
-        foreach ( $messages as $message_id => $message ) {
1503
+    if ($messages) {
1504
+        foreach ($messages as $message_id => $message) {
1505 1505
             // Try and detect what type of message this is
1506
-            if ( strpos( strtolower( $message ), 'error' ) ) {
1506
+            if (strpos(strtolower($message), 'error')) {
1507 1507
                 $type = 'error';
1508
-            } elseif ( strpos( strtolower( $message ), 'success' ) ) {
1508
+            } elseif (strpos(strtolower($message), 'success')) {
1509 1509
                 $type = 'success';
1510 1510
             } else {
1511 1511
                 $type = 'info';
1512 1512
             }
1513 1513
 
1514
-            $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) );
1514
+            $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type));
1515 1515
 
1516
-            echo '<div class="' . implode( ' ', $classes ) . '">';
1516
+            echo '<div class="' . implode(' ', $classes) . '">';
1517 1517
                 // Loop message codes and display messages
1518 1518
                     echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>';
1519 1519
             echo '</div>';
1520 1520
         }
1521 1521
 
1522 1522
         // Remove all of the cart saving messages
1523
-        $wpi_session->set( 'wpinv_cart_messages', null );
1523
+        $wpi_session->set('wpinv_cart_messages', null);
1524 1524
     }
1525 1525
 }
1526
-add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' );
1526
+add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages');
1527 1527
 
1528 1528
 function wpinv_discount_field() {
1529
-    if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) {
1529
+    if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) {
1530 1530
         return; // Only show before a payment method has been selected if ajax is disabled
1531 1531
     }
1532 1532
 
1533
-    if ( !wpinv_is_checkout() ) {
1533
+    if (!wpinv_is_checkout()) {
1534 1534
         return;
1535 1535
     }
1536 1536
 
1537
-    if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) {
1537
+    if (wpinv_has_active_discounts() && wpinv_get_cart_total()) {
1538 1538
     ?>
1539 1539
     <div id="wpinv-discount-field" class="panel panel-default">
1540 1540
         <div class="panel-body">
1541 1541
             <p>
1542
-                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label>
1543
-                <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span>
1542
+                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label>
1543
+                <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span>
1544 1544
             </p>
1545 1545
             <div class="form-group row">
1546 1546
                 <div class="col-sm-4">
1547
-                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/>
1547
+                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/>
1548 1548
                 </div>
1549 1549
                 <div class="col-sm-3">
1550
-                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button>
1550
+                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button>
1551 1551
                 </div>
1552 1552
                 <div class="col-sm-12 wpinv-discount-msg">
1553 1553
                     <div class="alert alert-success"><i class="fa fa-check-circle"></i><span class="wpi-msg"></span></div>
@@ -1559,10 +1559,10 @@  discard block
 block discarded – undo
1559 1559
 <?php
1560 1560
     }
1561 1561
 }
1562
-add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 );
1562
+add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10);
1563 1563
 
1564 1564
 function wpinv_agree_to_terms_js() {
1565
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
1565
+    if (wpinv_get_option('show_agree_to_terms', false)) {
1566 1566
 ?>
1567 1567
 <script type="text/javascript">
1568 1568
     jQuery(document).ready(function($){
@@ -1577,125 +1577,125 @@  discard block
 block discarded – undo
1577 1577
 <?php
1578 1578
     }
1579 1579
 }
1580
-add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' );
1580
+add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js');
1581 1581
 
1582 1582
 function wpinv_payment_mode_select() {
1583
-    $gateways = wpinv_get_enabled_payment_gateways( true );
1584
-    $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways );
1583
+    $gateways = wpinv_get_enabled_payment_gateways(true);
1584
+    $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways);
1585 1585
     $page_URL = wpinv_get_current_page_url();
1586
-    $invoice = wpinv_get_invoice( 0, true );
1586
+    $invoice = wpinv_get_invoice(0, true);
1587 1587
     
1588 1588
     do_action('wpinv_payment_mode_top');
1589 1589
     $invoice_id = (int)$invoice->ID;
1590
-    $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id );
1590
+    $chosen_gateway = wpinv_get_chosen_gateway($invoice_id);
1591 1591
     ?>
1592
-    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ( $invoice->is_free() ? 'style="display:none;"' : '' ); ?>>
1593
-            <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?>
1592
+    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ($invoice->is_free() ? 'style="display:none;"' : ''); ?>>
1593
+            <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?>
1594 1594
             <div id="wpinv-payment-mode-wrap" class="panel panel-default">
1595
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div>
1595
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div>
1596 1596
                 <div class="panel-body list-group wpi-payment_methods">
1597 1597
                     <?php
1598
-                    do_action( 'wpinv_payment_mode_before_gateways' );
1598
+                    do_action('wpinv_payment_mode_before_gateways');
1599 1599
                     
1600
-                    if(!empty($gateways)){
1601
-	                    foreach ( $gateways as $gateway_id => $gateway ) {
1602
-		                    $checked = checked( $gateway_id, $chosen_gateway, false );
1603
-		                    $button_label = wpinv_get_gateway_button_label( $gateway_id );
1604
-		                    $description = wpinv_get_gateway_description( $gateway_id );
1600
+                    if (!empty($gateways)) {
1601
+	                    foreach ($gateways as $gateway_id => $gateway) {
1602
+		                    $checked = checked($gateway_id, $chosen_gateway, false);
1603
+		                    $button_label = wpinv_get_gateway_button_label($gateway_id);
1604
+		                    $description = wpinv_get_gateway_description($gateway_id);
1605 1605
 		                    ?>
1606 1606
 		                    <div class="list-group-item">
1607 1607
 			                    <div class="radio">
1608
-				                    <label><input type="radio" data-button-text="<?php echo esc_attr( $button_label );?>" value="<?php echo esc_attr( $gateway_id ) ;?>" <?php echo $checked ;?> id="wpi_gateway_<?php echo esc_attr( $gateway_id );?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html( $gateway['checkout_label'] ); ?></label>
1608
+				                    <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 1609
 			                    </div>
1610
-			                    <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert">
1611
-				                    <?php if ( !empty( $description ) ) { ?>
1612
-					                    <div class="wpi-gateway-desc alert alert-info"><?php echo $description;?></div>
1610
+			                    <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert">
1611
+				                    <?php if (!empty($description)) { ?>
1612
+					                    <div class="wpi-gateway-desc alert alert-info"><?php echo $description; ?></div>
1613 1613
 				                    <?php } ?>
1614
-				                    <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?>
1614
+				                    <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?>
1615 1615
 			                    </div>
1616 1616
 		                    </div>
1617 1617
 		                    <?php
1618 1618
 	                    }
1619
-                    }else{
1620
-	                    echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>';
1619
+                    } else {
1620
+	                    echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>';
1621 1621
                     }
1622 1622
 
1623
-                    do_action( 'wpinv_payment_mode_after_gateways' );
1623
+                    do_action('wpinv_payment_mode_after_gateways');
1624 1624
                     ?>
1625 1625
                 </div>
1626 1626
             </div>
1627
-            <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?>
1627
+            <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?>
1628 1628
     </div>
1629 1629
     <?php
1630 1630
     do_action('wpinv_payment_mode_bottom');
1631 1631
 }
1632
-add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' );
1632
+add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select');
1633 1633
 
1634 1634
 function wpinv_checkout_billing_info() {    
1635
-    if ( wpinv_is_checkout() ) {
1635
+    if (wpinv_is_checkout()) {
1636 1636
         $logged_in          = is_user_logged_in();
1637 1637
         $billing_details    = wpinv_checkout_billing_details();
1638
-        $selected_country   = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country();
1638
+        $selected_country   = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country();
1639 1639
         ?>
1640 1640
         <div id="wpinv-fields" class="clearfix">
1641 1641
             <div id="wpi-billing" class="wpi-billing clearfix panel panel-default">
1642
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div>
1642
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div>
1643 1643
                 <div id="wpinv-fields-box" class="panel-body">
1644
-                    <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?>
1644
+                    <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?>
1645 1645
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1646
-                        <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><span class="wpi-required">*</span></label>
1646
+                        <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><span class="wpi-required">*</span></label>
1647 1647
                         <?php
1648
-                        echo wpinv_html_text( array(
1648
+                        echo wpinv_html_text(array(
1649 1649
                                 'id'            => 'wpinv_first_name',
1650 1650
                                 'name'          => 'wpinv_first_name',
1651 1651
                                 'value'         => $billing_details['first_name'],
1652 1652
                                 'class'         => 'wpi-input form-control required',
1653
-                                'placeholder'   => __( 'First name', 'invoicing' ),
1653
+                                'placeholder'   => __('First name', 'invoicing'),
1654 1654
                                 'required'      => true,
1655
-                            ) );
1655
+                            ));
1656 1656
                         ?>
1657 1657
                     </p>
1658 1658
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1659
-                        <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?></label>
1659
+                        <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?></label>
1660 1660
                         <?php
1661
-                        echo wpinv_html_text( array(
1661
+                        echo wpinv_html_text(array(
1662 1662
                                 'id'            => 'wpinv_last_name',
1663 1663
                                 'name'          => 'wpinv_last_name',
1664 1664
                                 'value'         => $billing_details['last_name'],
1665 1665
                                 'class'         => 'wpi-input form-control',
1666
-                                'placeholder'   => __( 'Last name', 'invoicing' ),
1667
-                            ) );
1666
+                                'placeholder'   => __('Last name', 'invoicing'),
1667
+                            ));
1668 1668
                         ?>
1669 1669
                     </p>
1670 1670
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1671
-                        <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><span class="wpi-required">*</span></label>
1671
+                        <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><span class="wpi-required">*</span></label>
1672 1672
                         <?php
1673
-                        echo wpinv_html_text( array(
1673
+                        echo wpinv_html_text(array(
1674 1674
                                 'id'            => 'wpinv_address',
1675 1675
                                 'name'          => 'wpinv_address',
1676 1676
                                 'value'         => $billing_details['address'],
1677 1677
                                 'class'         => 'wpi-input form-control required',
1678
-                                'placeholder'   => __( 'Address', 'invoicing' ),
1678
+                                'placeholder'   => __('Address', 'invoicing'),
1679 1679
                                 'required'      => true,
1680
-                            ) );
1680
+                            ));
1681 1681
                         ?>
1682 1682
                     </p>
1683 1683
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1684
-                        <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><span class="wpi-required">*</span></label>
1684
+                        <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><span class="wpi-required">*</span></label>
1685 1685
                         <?php
1686
-                        echo wpinv_html_text( array(
1686
+                        echo wpinv_html_text(array(
1687 1687
                                 'id'            => 'wpinv_city',
1688 1688
                                 'name'          => 'wpinv_city',
1689 1689
                                 'value'         => $billing_details['city'],
1690 1690
                                 'class'         => 'wpi-input form-control required',
1691
-                                'placeholder'   => __( 'City', 'invoicing' ),
1691
+                                'placeholder'   => __('City', 'invoicing'),
1692 1692
                                 'required'      => true,
1693
-                            ) );
1693
+                            ));
1694 1694
                         ?>
1695 1695
                     </p>
1696 1696
                     <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf">
1697
-                        <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><span class="wpi-required">*</span></label>
1698
-                        <?php echo wpinv_html_select( array(
1697
+                        <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><span class="wpi-required">*</span></label>
1698
+                        <?php echo wpinv_html_select(array(
1699 1699
                             'options'          => wpinv_get_country_list(),
1700 1700
                             'name'             => 'wpinv_country',
1701 1701
                             'id'               => 'wpinv_country',
@@ -1703,16 +1703,16 @@  discard block
 block discarded – undo
1703 1703
                             'show_option_all'  => false,
1704 1704
                             'show_option_none' => false,
1705 1705
                             'class'            => 'wpi-input form-control required',
1706
-                            'placeholder'      => __( 'Choose a country', 'invoicing' ),
1706
+                            'placeholder'      => __('Choose a country', 'invoicing'),
1707 1707
                             'required'          => true,
1708
-                        ) ); ?>
1708
+                        )); ?>
1709 1709
                     </p>
1710 1710
                     <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll">
1711
-                        <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><span class="wpi-required">*</span></label>
1711
+                        <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><span class="wpi-required">*</span></label>
1712 1712
                         <?php
1713
-                        $states = wpinv_get_country_states( $selected_country );
1714
-                        if( !empty( $states ) ) {
1715
-                            echo wpinv_html_select( array(
1713
+                        $states = wpinv_get_country_states($selected_country);
1714
+                        if (!empty($states)) {
1715
+                            echo wpinv_html_select(array(
1716 1716
                                 'options'          => $states,
1717 1717
                                 'name'             => 'wpinv_state',
1718 1718
                                 'id'               => 'wpinv_state',
@@ -1720,60 +1720,60 @@  discard block
 block discarded – undo
1720 1720
                                 'show_option_all'  => false,
1721 1721
                                 'show_option_none' => false,
1722 1722
                                 'class'            => 'wpi-input form-control required',
1723
-                                'placeholder'      => __( 'Choose a state', 'invoicing' ),
1723
+                                'placeholder'      => __('Choose a state', 'invoicing'),
1724 1724
                                 'required'         => true,
1725
-                            ) );
1725
+                            ));
1726 1726
                         } else {
1727
-                            echo wpinv_html_text( array(
1727
+                            echo wpinv_html_text(array(
1728 1728
                                 'name'          => 'wpinv_state',
1729 1729
                                 'value'         => $billing_details['state'],
1730 1730
                                 'id'            => 'wpinv_state',
1731 1731
                                 'class'         => 'wpi-input form-control required',
1732
-                                'placeholder'   => __( 'State / Province', 'invoicing' ),
1732
+                                'placeholder'   => __('State / Province', 'invoicing'),
1733 1733
                                 'required'      => true,
1734
-                            ) );
1734
+                            ));
1735 1735
                         }
1736 1736
                         ?>
1737 1737
                     </p>
1738 1738
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1739
-                        <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?></label>
1739
+                        <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?></label>
1740 1740
                         <?php
1741
-                        echo wpinv_html_text( array(
1741
+                        echo wpinv_html_text(array(
1742 1742
                                 'name'          => 'wpinv_zip',
1743 1743
                                 'value'         => $billing_details['zip'],
1744 1744
                                 'id'            => 'wpinv_zip',
1745 1745
                                 'class'         => 'wpi-input form-control',
1746
-                                'placeholder'   => __( 'ZIP / Postcode', 'invoicing' ),
1747
-                            ) );
1746
+                                'placeholder'   => __('ZIP / Postcode', 'invoicing'),
1747
+                            ));
1748 1748
                         ?>
1749 1749
                     </p>
1750 1750
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1751
-                        <label for="wpinv_phone" class="wpi-label"><?php _e( 'Phone', 'invoicing' );?><?php if ( wpinv_get_option( 'phone_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1751
+                        <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>
1752 1752
                         <?php
1753
-                        echo wpinv_html_text( array(
1753
+                        echo wpinv_html_text(array(
1754 1754
                                 'id'            => 'wpinv_phone',
1755 1755
                                 'name'          => 'wpinv_phone',
1756 1756
                                 'value'         => $billing_details['phone'],
1757 1757
                                 'class'         => 'wpi-input form-control',
1758
-                                'placeholder'   => __( 'Phone', 'invoicing' ),
1759
-                                'required'      => (bool)wpinv_get_option( 'phone_mandatory' ),
1760
-                            ) );
1758
+                                'placeholder'   => __('Phone', 'invoicing'),
1759
+                                'required'      => (bool)wpinv_get_option('phone_mandatory'),
1760
+                            ));
1761 1761
                         ?>
1762 1762
                     </p>
1763
-                    <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?>
1763
+                    <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?>
1764 1764
                     <div class="clearfix"></div>
1765 1765
                 </div>
1766 1766
             </div>
1767
-            <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?>
1767
+            <?php do_action('wpinv_after_billing_fields', $billing_details); ?>
1768 1768
         </div>
1769 1769
         <?php
1770 1770
     }
1771 1771
 }
1772
-add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' );
1772
+add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info');
1773 1773
 
1774 1774
 function wpinv_checkout_hidden_fields() {
1775 1775
 ?>
1776
-    <?php if ( is_user_logged_in() ) { ?>
1776
+    <?php if (is_user_logged_in()) { ?>
1777 1777
     <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/>
1778 1778
     <?php } ?>
1779 1779
     <input type="hidden" name="wpi_action" value="payment" />
@@ -1783,9 +1783,9 @@  discard block
 block discarded – undo
1783 1783
 function wpinv_checkout_button_purchase() {
1784 1784
     ob_start();
1785 1785
 ?>
1786
-    <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>" name="wpinv_payment" value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>"/>
1786
+    <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') ?>"/>
1787 1787
 <?php
1788
-    return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() );
1788
+    return apply_filters('wpinv_checkout_button_purchase', ob_get_clean());
1789 1789
 }
1790 1790
 
1791 1791
 function wpinv_checkout_total() {
@@ -1794,96 +1794,96 @@  discard block
 block discarded – undo
1794 1794
 <div id="wpinv_checkout_total" class="panel panel-info">
1795 1795
     <div class="panel-body">
1796 1796
     <?php
1797
-    do_action( 'wpinv_purchase_form_before_checkout_total' );
1797
+    do_action('wpinv_purchase_form_before_checkout_total');
1798 1798
     ?>
1799
-    <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span>
1799
+    <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span>
1800 1800
     <?php
1801
-    do_action( 'wpinv_purchase_form_after_checkout_total' );
1801
+    do_action('wpinv_purchase_form_after_checkout_total');
1802 1802
     ?>
1803 1803
     </div>
1804 1804
 </div>
1805 1805
 <?php
1806 1806
 }
1807
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 );
1807
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998);
1808 1808
 
1809 1809
 function wpinv_checkout_submit() {
1810 1810
 ?>
1811 1811
 <div id="wpinv_purchase_submit" class="panel panel-success">
1812 1812
     <div class="panel-body text-center">
1813 1813
     <?php
1814
-    do_action( 'wpinv_purchase_form_before_submit' );
1814
+    do_action('wpinv_purchase_form_before_submit');
1815 1815
     wpinv_checkout_hidden_fields();
1816 1816
     echo wpinv_checkout_button_purchase();
1817
-    do_action( 'wpinv_purchase_form_after_submit' );
1817
+    do_action('wpinv_purchase_form_after_submit');
1818 1818
     ?>
1819 1819
     </div>
1820 1820
 </div>
1821 1821
 <?php
1822 1822
 }
1823
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 );
1823
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999);
1824 1824
 
1825
-function wpinv_receipt_billing_address( $invoice_id = 0 ) {
1826
-    $invoice = wpinv_get_invoice( $invoice_id );
1825
+function wpinv_receipt_billing_address($invoice_id = 0) {
1826
+    $invoice = wpinv_get_invoice($invoice_id);
1827 1827
     
1828
-    if ( empty( $invoice ) ) {
1828
+    if (empty($invoice)) {
1829 1829
         return NULL;
1830 1830
     }
1831 1831
     
1832 1832
     $billing_details = $invoice->get_user_info();
1833 1833
     $address_row = '';
1834
-    if ( $address = $billing_details['address'] ) {
1835
-        $address_row .= wpautop( wp_kses_post( $address ) );
1834
+    if ($address = $billing_details['address']) {
1835
+        $address_row .= wpautop(wp_kses_post($address));
1836 1836
     }
1837 1837
     
1838 1838
     $address_fields = array();
1839
-    if ( !empty( $billing_details['city'] ) ) {
1839
+    if (!empty($billing_details['city'])) {
1840 1840
         $address_fields[] = $billing_details['city'];
1841 1841
     }
1842 1842
     
1843
-    $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : '';
1844
-    if ( !empty( $billing_details['state'] ) ) {
1845
-        $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country );
1843
+    $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : '';
1844
+    if (!empty($billing_details['state'])) {
1845
+        $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country);
1846 1846
     }
1847 1847
     
1848
-    if ( !empty( $billing_country ) ) {
1849
-        $address_fields[] = wpinv_country_name( $billing_country );
1848
+    if (!empty($billing_country)) {
1849
+        $address_fields[] = wpinv_country_name($billing_country);
1850 1850
     }
1851 1851
     
1852
-    if ( !empty( $address_fields ) ) {
1853
-        $address_fields = implode( ", ", $address_fields );
1852
+    if (!empty($address_fields)) {
1853
+        $address_fields = implode(", ", $address_fields);
1854 1854
         
1855
-        if ( !empty( $billing_details['zip'] ) ) {
1855
+        if (!empty($billing_details['zip'])) {
1856 1856
             $address_fields .= ' ' . $billing_details['zip'];
1857 1857
         }
1858 1858
         
1859
-        $address_row .= wpautop( wp_kses_post( $address_fields ) );
1859
+        $address_row .= wpautop(wp_kses_post($address_fields));
1860 1860
     }
1861 1861
     ob_start();
1862 1862
     ?>
1863 1863
     <table class="table table-bordered table-sm wpi-billing-details">
1864 1864
         <tbody>
1865 1865
             <tr class="wpi-receipt-name">
1866
-                <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th>
1867
-                <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td>
1866
+                <th class="text-left"><?php _e('Name', 'invoicing'); ?></th>
1867
+                <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td>
1868 1868
             </tr>
1869 1869
             <tr class="wpi-receipt-email">
1870
-                <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th>
1871
-                <td><?php echo $billing_details['email'] ;?></td>
1870
+                <th class="text-left"><?php _e('Email', 'invoicing'); ?></th>
1871
+                <td><?php echo $billing_details['email']; ?></td>
1872 1872
             </tr>
1873
-            <?php if ( $billing_details['company'] ) { ?>
1873
+            <?php if ($billing_details['company']) { ?>
1874 1874
             <tr class="wpi-receipt-company">
1875
-                <th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th>
1876
-                <td><?php echo esc_html( $billing_details['company'] ) ;?></td>
1875
+                <th class="text-left"><?php _e('Company', 'invoicing'); ?></th>
1876
+                <td><?php echo esc_html($billing_details['company']); ?></td>
1877 1877
             </tr>
1878 1878
             <?php } ?>
1879 1879
             <tr class="wpi-receipt-address">
1880
-                <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th>
1881
-                <td><?php echo $address_row ;?></td>
1880
+                <th class="text-left"><?php _e('Address', 'invoicing'); ?></th>
1881
+                <td><?php echo $address_row; ?></td>
1882 1882
             </tr>
1883
-            <?php if ( $billing_details['phone'] ) { ?>
1883
+            <?php if ($billing_details['phone']) { ?>
1884 1884
             <tr class="wpi-receipt-phone">
1885
-                <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th>
1886
-                <td><?php echo esc_html( $billing_details['phone'] ) ;?></td>
1885
+                <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th>
1886
+                <td><?php echo esc_html($billing_details['phone']); ?></td>
1887 1887
             </tr>
1888 1888
             <?php } ?>
1889 1889
         </tbody>
@@ -1891,98 +1891,98 @@  discard block
 block discarded – undo
1891 1891
     <?php
1892 1892
     $output = ob_get_clean();
1893 1893
     
1894
-    $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id );
1894
+    $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id);
1895 1895
 
1896 1896
     echo $output;
1897 1897
 }
1898 1898
 
1899
-function wpinv_filter_success_page_content( $content ) {
1900
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1901
-        if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) {
1902
-            $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content );
1899
+function wpinv_filter_success_page_content($content) {
1900
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1901
+        if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) {
1902
+            $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content);
1903 1903
         }
1904 1904
     }
1905 1905
 
1906 1906
     return $content;
1907 1907
 }
1908
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1908
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1909 1909
 
1910
-function wpinv_receipt_actions( $invoice ) {
1911
-    if ( !empty( $invoice ) ) {
1910
+function wpinv_receipt_actions($invoice) {
1911
+    if (!empty($invoice)) {
1912 1912
         $actions = array(
1913 1913
             'print'   => array(
1914 1914
                 'url'  => $invoice->get_view_url(),
1915
-                'name' => __( 'Print Invoice', 'invoicing' ),
1915
+                'name' => __('Print Invoice', 'invoicing'),
1916 1916
                 'class' => 'btn-primary',
1917 1917
             ),
1918 1918
             'history'   => array(
1919 1919
                 'url'  => wpinv_get_history_page_uri(),
1920
-                'name' => __( 'Invoice History', 'invoicing' ),
1920
+                'name' => __('Invoice History', 'invoicing'),
1921 1921
                 'class' => 'btn-warning',
1922 1922
             )
1923 1923
         );
1924 1924
 
1925
-        $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice );
1925
+        $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice);
1926 1926
         
1927
-        if ( !empty( $actions ) ) {
1927
+        if (!empty($actions)) {
1928 1928
         ?>
1929 1929
         <div class="wpinv-receipt-actions text-right">
1930
-            <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?>
1931
-            <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>
1930
+            <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?>
1931
+            <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>
1932 1932
             <?php } ?>
1933 1933
         </div>
1934 1934
         <?php
1935 1935
         }
1936 1936
     }
1937 1937
 }
1938
-add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 );
1938
+add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1);
1939 1939
 
1940
-function wpinv_invoice_link( $invoice_id ) {
1941
-    $invoice = wpinv_get_invoice( $invoice_id );
1940
+function wpinv_invoice_link($invoice_id) {
1941
+    $invoice = wpinv_get_invoice($invoice_id);
1942 1942
     
1943
-    if ( empty( $invoice ) ) {
1943
+    if (empty($invoice)) {
1944 1944
         return NULL;
1945 1945
     }
1946 1946
     
1947
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1947
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1948 1948
     
1949
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1949
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1950 1950
 }
1951 1951
 
1952
-function wpinv_invoice_subscription_details( $invoice ) {
1953
-    if ( !empty( $invoice ) && $invoice->is_recurring() && !wpinv_is_subscription_payment( $invoice ) ) {
1952
+function wpinv_invoice_subscription_details($invoice) {
1953
+    if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) {
1954 1954
         $total_payments = (int)$invoice->get_total_payments();
1955 1955
         $payments       = $invoice->get_child_payments();
1956 1956
         
1957 1957
         $subscription   = $invoice->get_subscription_data();
1958 1958
         
1959
-        if ( !( !empty( $subscription ) && !empty( $subscription['item_id'] ) ) ) {
1959
+        if (!(!empty($subscription) && !empty($subscription['item_id']))) {
1960 1960
             return;
1961 1961
         }
1962 1962
         
1963
-        $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() );
1964
-        $times_billed   = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] );
1963
+        $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());
1964
+        $times_billed   = $total_payments . ' / ' . (((int)$subscription['bill_times'] == 0) ? __('Until cancelled', 'invoicing') : $subscription['bill_times']);
1965 1965
         
1966 1966
         $subscription_status = $invoice->get_subscription_status();
1967 1967
         
1968 1968
         $status_desc = '';
1969
-        if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) {
1970
-            $status_desc = wp_sprintf( __( 'Until: %s', 'invoicing' ), $trial_end_date );
1971
-        } else if ( $subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date() ) {
1972
-            $status_desc = wp_sprintf( __( 'On: %s', 'invoicing' ), $cancelled_date );
1969
+        if ($subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date()) {
1970
+            $status_desc = wp_sprintf(__('Until: %s', 'invoicing'), $trial_end_date);
1971
+        } else if ($subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date()) {
1972
+            $status_desc = wp_sprintf(__('On: %s', 'invoicing'), $cancelled_date);
1973 1973
         }
1974 1974
         $status_desc = $status_desc != '' ? '<span class="meta">' . $status_desc . '</span>' : '';
1975 1975
         ?>
1976 1976
         <div class="wpinv-subscriptions-details">
1977
-            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3>
1977
+            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3>
1978 1978
             <table class="table">
1979 1979
                 <thead>
1980 1980
                     <tr>
1981
-                        <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th>
1982
-                        <th><?php _e( 'Start Date', 'invoicing' ) ;?></th>
1983
-                        <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th>
1984
-                        <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th>
1985
-                        <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th>
1981
+                        <th><?php _e('Billing Cycle', 'invoicing'); ?></th>
1982
+                        <th><?php _e('Start Date', 'invoicing'); ?></th>
1983
+                        <th><?php _e('Expiration Date', 'invoicing'); ?></th>
1984
+                        <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th>
1985
+                        <th class="text-center"><?php _e('Status', 'invoicing'); ?></th>
1986 1986
                     </tr>
1987 1987
                 </thead>
1988 1988
                 <tbody>
@@ -1991,32 +1991,32 @@  discard block
 block discarded – undo
1991 1991
                         <td><?php echo $invoice->get_subscription_start(); ?></td>
1992 1992
                         <td><?php echo $invoice->get_subscription_end(); ?></td>
1993 1993
                         <td class="text-center"><?php echo $times_billed; ?></td>
1994
-                        <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label() ;?>
1994
+                        <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label(); ?>
1995 1995
                         <?php echo $status_desc; ?>
1996 1996
                         </td>
1997 1997
                     </tr>
1998 1998
                 </tbody>
1999 1999
             </table>
2000 2000
         </div>
2001
-        <?php if ( !empty( $payments ) ) { ?>
2001
+        <?php if (!empty($payments)) { ?>
2002 2002
         <div class="wpinv-renewal-payments">
2003
-            <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3>
2003
+            <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3>
2004 2004
             <table class="table">
2005 2005
                 <thead>
2006 2006
                     <tr>
2007 2007
                         <th>#</th>
2008
-                        <th><?php _e( 'Invoice', 'invoicing' ) ;?></th>
2009
-                        <th><?php _e( 'Date', 'invoicing' ) ;?></th>
2010
-                        <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th>
2008
+                        <th><?php _e('Invoice', 'invoicing'); ?></th>
2009
+                        <th><?php _e('Date', 'invoicing'); ?></th>
2010
+                        <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th>
2011 2011
                     </tr>
2012 2012
                 </thead>
2013 2013
                 <tbody>
2014
-                    <?php foreach ( $payments as $key => $invoice_id ) { ?>
2014
+                    <?php foreach ($payments as $key => $invoice_id) { ?>
2015 2015
                     <tr>
2016
-                        <th scope="row"><?php echo ( $key + 1 );?></th>
2017
-                        <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td>
2018
-                        <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td>
2019
-                        <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td>
2016
+                        <th scope="row"><?php echo ($key + 1); ?></th>
2017
+                        <td><?php echo wpinv_invoice_link($invoice_id); ?></td>
2018
+                        <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td>
2019
+                        <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td>
2020 2020
                     </tr>
2021 2021
                     <?php } ?>
2022 2022
                     <tr><td colspan="4" style="padding:0"></td></tr>
@@ -2028,52 +2028,52 @@  discard block
 block discarded – undo
2028 2028
     }
2029 2029
 }
2030 2030
 
2031
-function wpinv_cart_total_label( $label, $invoice ) {
2032
-    if ( empty( $invoice ) ) {
2031
+function wpinv_cart_total_label($label, $invoice) {
2032
+    if (empty($invoice)) {
2033 2033
         return $label;
2034 2034
     }
2035 2035
     
2036 2036
     $prefix_label = '';
2037
-    if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) {        
2038
-        $prefix_label   = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice );
2039
-    } else if ( $invoice->is_renewal() ) {
2040
-        $prefix_label   = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> ';        
2037
+    if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) {        
2038
+        $prefix_label   = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice);
2039
+    } else if ($invoice->is_renewal()) {
2040
+        $prefix_label   = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> ';        
2041 2041
     }
2042 2042
     
2043
-    if ( $prefix_label != '' ) {
2044
-        $label  = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2043
+    if ($prefix_label != '') {
2044
+        $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2045 2045
     }
2046 2046
     
2047 2047
     return $label;
2048 2048
 }
2049
-add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2050
-add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2051
-add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2049
+add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2050
+add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2051
+add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2052 2052
 
2053
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 );
2053
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1);
2054 2054
 
2055
-function wpinv_invoice_print_description( $invoice ) {
2056
-    if ( empty( $invoice ) ) {
2055
+function wpinv_invoice_print_description($invoice) {
2056
+    if (empty($invoice)) {
2057 2057
         return NULL;
2058 2058
     }
2059
-    if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) {
2059
+    if ($description = wpinv_get_invoice_description($invoice->ID)) {
2060 2060
         ?>
2061 2061
         <div class="row wpinv-lower">
2062 2062
             <div class="col-sm-12 wpinv-description">
2063
-                <?php echo wpautop( $description ); ?>
2063
+                <?php echo wpautop($description); ?>
2064 2064
             </div>
2065 2065
         </div>
2066 2066
         <?php
2067 2067
     }
2068 2068
 }
2069
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 );
2069
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1);
2070 2070
 
2071
-function wpinv_invoice_print_payment_info( $invoice ) {
2072
-    if ( empty( $invoice ) ) {
2071
+function wpinv_invoice_print_payment_info($invoice) {
2072
+    if (empty($invoice)) {
2073 2073
         return NULL;
2074 2074
     }
2075 2075
     
2076
-    if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) {
2076
+    if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) {
2077 2077
         ?>
2078 2078
         <div class="row wpinv-payments">
2079 2079
             <div class="col-sm-12">
@@ -2085,40 +2085,40 @@  discard block
 block discarded – undo
2085 2085
 }
2086 2086
 // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 );
2087 2087
 
2088
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
2089
-    if ( empty( $note ) ) {
2088
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
2089
+    if (empty($note)) {
2090 2090
         return NULL;
2091 2091
     }
2092 2092
     
2093
-    if ( is_int( $note ) ) {
2094
-        $note = get_comment( $note );
2093
+    if (is_int($note)) {
2094
+        $note = get_comment($note);
2095 2095
     }
2096 2096
     
2097
-    if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
2097
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
2098 2098
         return NULL;
2099 2099
     }
2100 2100
     
2101
-    $note_classes   = array( 'note' );
2102
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
2103
-    $note_classes[] = $note->comment_author === __( 'GeoDirectory', 'invoicing' ) ? 'system-note' : '';
2104
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
2105
-    $note_classes   = !empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
2101
+    $note_classes   = array('note');
2102
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
2103
+    $note_classes[] = $note->comment_author === __('GeoDirectory', 'invoicing') ? 'system-note' : '';
2104
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
2105
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
2106 2106
     
2107 2107
     ob_start();
2108 2108
     ?>
2109
-    <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>">
2109
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>">
2110 2110
         <div class="note_content">
2111
-            <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
2111
+            <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?>
2112 2112
         </div>
2113 2113
         <p class="meta">
2114
-            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr>&nbsp;&nbsp;<a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a>
2114
+            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr>&nbsp;&nbsp;<a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
2115 2115
         </p>
2116 2116
     </li>
2117 2117
     <?php
2118 2118
     $note_content = ob_get_clean();
2119
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
2119
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
2120 2120
     
2121
-    if ( $echo ) {
2121
+    if ($echo) {
2122 2122
         echo $note_content;
2123 2123
     } else {
2124 2124
         return $note_content;
Please login to merge, or discard this patch.
includes/wpinv-discount-functions.php 1 patch
Spacing   +469 added lines, -469 removed lines patch added patch discarded remove patch
@@ -7,90 +7,90 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_get_discount_types() {
15 15
     $discount_types = array(
16
-                        'percent'   => __( 'Percentage', 'invoicing' ),
17
-                        'flat'     => __( 'Flat Amount', 'invoicing' ),
16
+                        'percent'   => __('Percentage', 'invoicing'),
17
+                        'flat'     => __('Flat Amount', 'invoicing'),
18 18
                     );
19
-    return (array)apply_filters( 'wpinv_discount_types', $discount_types );
19
+    return (array)apply_filters('wpinv_discount_types', $discount_types);
20 20
 }
21 21
 
22
-function wpinv_get_discount_type_name( $type = '' ) {
22
+function wpinv_get_discount_type_name($type = '') {
23 23
     $types = wpinv_get_discount_types();
24
-    return isset( $types[ $type ] ) ? $types[ $type ] : '';
24
+    return isset($types[$type]) ? $types[$type] : '';
25 25
 }
26 26
 
27
-function wpinv_delete_discount( $data ) {
28
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
29
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
27
+function wpinv_delete_discount($data) {
28
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
29
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
30 30
     }
31 31
 
32
-    if( ! current_user_can( 'manage_options' ) ) {
33
-        wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
32
+    if (!current_user_can('manage_options')) {
33
+        wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
34 34
     }
35 35
 
36 36
     $discount_id = $data['discount'];
37
-    wpinv_remove_discount( $discount_id );
37
+    wpinv_remove_discount($discount_id);
38 38
 }
39
-add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' );
39
+add_action('wpinv_delete_discount', 'wpinv_delete_discount');
40 40
 
41
-function wpinv_activate_discount( $data ) {
42
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
43
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
41
+function wpinv_activate_discount($data) {
42
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
43
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
44 44
     }
45 45
 
46
-    if( ! current_user_can( 'manage_options' ) ) {
47
-        wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
46
+    if (!current_user_can('manage_options')) {
47
+        wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
48 48
     }
49 49
 
50
-    $id = absint( $data['discount'] );
51
-    wpinv_update_discount_status( $id, 'publish' );
50
+    $id = absint($data['discount']);
51
+    wpinv_update_discount_status($id, 'publish');
52 52
 }
53
-add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' );
53
+add_action('wpinv_activate_discount', 'wpinv_activate_discount');
54 54
 
55
-function wpinv_deactivate_discount( $data ) {
56
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
57
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
55
+function wpinv_deactivate_discount($data) {
56
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
57
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
58 58
     }
59 59
 
60
-    if( ! current_user_can( 'manage_options' ) ) {
61
-        wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) );
60
+    if (!current_user_can('manage_options')) {
61
+        wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403));
62 62
     }
63 63
 
64
-    $id = absint( $data['discount'] );
65
-    wpinv_update_discount_status( $id, 'pending' );
64
+    $id = absint($data['discount']);
65
+    wpinv_update_discount_status($id, 'pending');
66 66
 }
67
-add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' );
67
+add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount');
68 68
 
69
-function wpinv_get_discounts( $args = array() ) {
69
+function wpinv_get_discounts($args = array()) {
70 70
     $defaults = array(
71 71
         'post_type'      => 'wpi_discount',
72 72
         'posts_per_page' => 20,
73 73
         'paged'          => null,
74
-        'post_status'    => array( 'publish', 'pending', 'draft', 'expired' )
74
+        'post_status'    => array('publish', 'pending', 'draft', 'expired')
75 75
     );
76 76
 
77
-    $args = wp_parse_args( $args, $defaults );
77
+    $args = wp_parse_args($args, $defaults);
78 78
 
79
-    $discounts = get_posts( $args );
79
+    $discounts = get_posts($args);
80 80
 
81
-    if ( $discounts ) {
81
+    if ($discounts) {
82 82
         return $discounts;
83 83
     }
84 84
 
85
-    if( ! $discounts && ! empty( $args['s'] ) ) {
85
+    if (!$discounts && !empty($args['s'])) {
86 86
         $args['meta_key']     = 'gd_discount_code';
87 87
         $args['meta_value']   = $args['s'];
88 88
         $args['meta_compare'] = 'LIKE';
89
-        unset( $args['s'] );
90
-        $discounts = get_posts( $args );
89
+        unset($args['s']);
90
+        $discounts = get_posts($args);
91 91
     }
92 92
 
93
-    if( $discounts ) {
93
+    if ($discounts) {
94 94
         return $discounts;
95 95
     }
96 96
 
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
 
103 103
     $discounts  = wpinv_get_discounts();
104 104
 
105
-    if ( $discounts) {
106
-        foreach ( $discounts as $discount ) {
107
-            if ( wpinv_is_discount_active( $discount->ID ) ) {
105
+    if ($discounts) {
106
+        foreach ($discounts as $discount) {
107
+            if (wpinv_is_discount_active($discount->ID)) {
108 108
                 $has_active = true;
109 109
                 break;
110 110
             }
@@ -113,38 +113,38 @@  discard block
 block discarded – undo
113 113
     return $has_active;
114 114
 }
115 115
 
116
-function wpinv_get_discount( $discount_id = 0 ) {
117
-    if( empty( $discount_id ) ) {
116
+function wpinv_get_discount($discount_id = 0) {
117
+    if (empty($discount_id)) {
118 118
         return false;
119 119
     }
120 120
     
121
-    if ( get_post_type( $discount_id ) != 'wpi_discount' ) {
121
+    if (get_post_type($discount_id) != 'wpi_discount') {
122 122
         return false;
123 123
     }
124 124
 
125
-    $discount = get_post( $discount_id );
125
+    $discount = get_post($discount_id);
126 126
 
127 127
     return $discount;
128 128
 }
129 129
 
130
-function wpinv_get_discount_by_code( $code = '' ) {
131
-    if( empty( $code ) || ! is_string( $code ) ) {
130
+function wpinv_get_discount_by_code($code = '') {
131
+    if (empty($code) || !is_string($code)) {
132 132
         return false;
133 133
     }
134 134
 
135
-    return wpinv_get_discount_by( 'code', $code );
135
+    return wpinv_get_discount_by('code', $code);
136 136
 }
137 137
 
138
-function wpinv_get_discount_by( $field = '', $value = '' ) {
139
-    if( empty( $field ) || empty( $value ) ) {
138
+function wpinv_get_discount_by($field = '', $value = '') {
139
+    if (empty($field) || empty($value)) {
140 140
         return false;
141 141
     }
142 142
 
143
-    if( ! is_string( $field ) ) {
143
+    if (!is_string($field)) {
144 144
         return false;
145 145
     }
146 146
 
147
-    switch( strtolower( $field ) ) {
147
+    switch (strtolower($field)) {
148 148
 
149 149
         case 'code':
150 150
             $meta_query     = array();
@@ -154,32 +154,32 @@  discard block
 block discarded – undo
154 154
                 'compare' => '='
155 155
             );
156 156
             
157
-            $discount = wpinv_get_discounts( array(
157
+            $discount = wpinv_get_discounts(array(
158 158
                 'posts_per_page' => 1,
159 159
                 'post_status'    => 'any',
160 160
                 'meta_query'     => $meta_query,
161
-            ) );
161
+            ));
162 162
             
163
-            if( $discount ) {
163
+            if ($discount) {
164 164
                 $discount = $discount[0];
165 165
             }
166 166
 
167 167
             break;
168 168
 
169 169
         case 'id':
170
-            $discount = wpinv_get_discount( $value );
170
+            $discount = wpinv_get_discount($value);
171 171
 
172 172
             break;
173 173
 
174 174
         case 'name':
175
-            $discount = get_posts( array(
175
+            $discount = get_posts(array(
176 176
                 'post_type'      => 'wpi_discount',
177 177
                 'name'           => $value,
178 178
                 'posts_per_page' => 1,
179 179
                 'post_status'    => 'any'
180
-            ) );
180
+            ));
181 181
 
182
-            if( $discount ) {
182
+            if ($discount) {
183 183
                 $discount = $discount[0];
184 184
             }
185 185
 
@@ -189,99 +189,99 @@  discard block
 block discarded – undo
189 189
             return false;
190 190
     }
191 191
 
192
-    if( ! empty( $discount ) ) {
192
+    if (!empty($discount)) {
193 193
         return $discount;
194 194
     }
195 195
 
196 196
     return false;
197 197
 }
198 198
 
199
-function wpinv_store_discount( $post_id, $data, $post, $update = false ) {
199
+function wpinv_store_discount($post_id, $data, $post, $update = false) {
200 200
     $meta = array(
201
-        'code'              => isset( $data['code'] )             ? sanitize_text_field( $data['code'] )              : '',
202
-        'type'              => isset( $data['type'] )             ? sanitize_text_field( $data['type'] )              : 'percent',
203
-        'amount'            => isset( $data['amount'] )           ? wpinv_sanitize_amount( $data['amount'] )          : '',
204
-        'start'             => isset( $data['start'] )            ? sanitize_text_field( $data['start'] )             : '',
205
-        'expiration'        => isset( $data['expiration'] )       ? sanitize_text_field( $data['expiration'] )        : '',
206
-        'min_total'         => isset( $data['min_total'] )        ? wpinv_sanitize_amount( $data['min_total'] )       : '',
207
-        'max_total'         => isset( $data['max_total'] )        ? wpinv_sanitize_amount( $data['max_total'] )       : '',
208
-        'max_uses'          => isset( $data['max_uses'] )         ? absint( $data['max_uses'] )                       : '',
209
-        'items'             => isset( $data['items'] )            ? $data['items']                                    : array(),
210
-        'excluded_items'    => isset( $data['excluded_items'] )   ? $data['excluded_items']                           : array(),
211
-        'is_recurring'      => isset( $data['recurring'] )        ? (bool)$data['recurring']                          : false,
212
-        'is_single_use'     => isset( $data['single_use'] )       ? (bool)$data['single_use']                         : false,
213
-        'uses'              => isset( $data['uses'] )             ? (int)$data['uses']                                : false,
201
+        'code'              => isset($data['code']) ? sanitize_text_field($data['code']) : '',
202
+        'type'              => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent',
203
+        'amount'            => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '',
204
+        'start'             => isset($data['start']) ? sanitize_text_field($data['start']) : '',
205
+        'expiration'        => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '',
206
+        'min_total'         => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '',
207
+        'max_total'         => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '',
208
+        'max_uses'          => isset($data['max_uses']) ? absint($data['max_uses']) : '',
209
+        'items'             => isset($data['items']) ? $data['items'] : array(),
210
+        'excluded_items'    => isset($data['excluded_items']) ? $data['excluded_items'] : array(),
211
+        'is_recurring'      => isset($data['recurring']) ? (bool)$data['recurring'] : false,
212
+        'is_single_use'     => isset($data['single_use']) ? (bool)$data['single_use'] : false,
213
+        'uses'              => isset($data['uses']) ? (int)$data['uses'] : false,
214 214
     );
215 215
     
216
-    $start_timestamp        = strtotime( $meta['start'] );
216
+    $start_timestamp        = strtotime($meta['start']);
217 217
 
218
-    if ( !empty( $meta['start'] ) ) {
219
-        $meta['start']      = date( 'Y-m-d H:i:s', $start_timestamp );
218
+    if (!empty($meta['start'])) {
219
+        $meta['start']      = date('Y-m-d H:i:s', $start_timestamp);
220 220
     }
221 221
         
222
-    if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) {
222
+    if ($meta['type'] == 'percent' && (float)$meta['amount'] > 100) {
223 223
         $meta['amount'] = 100;
224 224
     }
225 225
 
226
-    if ( !empty( $meta['expiration'] ) ) {
227
-        $meta['expiration'] = date( 'Y-m-d H:i:s', strtotime( date( 'Y-m-d', strtotime( $meta['expiration'] ) ) . ' 23:59:59' ) );
228
-        $end_timestamp      = strtotime( $meta['expiration'] );
226
+    if (!empty($meta['expiration'])) {
227
+        $meta['expiration'] = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime($meta['expiration'])) . ' 23:59:59'));
228
+        $end_timestamp      = strtotime($meta['expiration']);
229 229
 
230
-        if ( !empty( $meta['start'] ) && $start_timestamp > $end_timestamp ) {
230
+        if (!empty($meta['start']) && $start_timestamp > $end_timestamp) {
231 231
             $meta['expiration'] = $meta['start']; // Set the expiration date to the start date if start is later than expiration date.
232 232
         }
233 233
     }
234 234
     
235
-    if ( $meta['uses'] === false ) {
236
-        unset( $meta['uses'] );
235
+    if ($meta['uses'] === false) {
236
+        unset($meta['uses']);
237 237
     }
238 238
     
239
-    if ( ! empty( $meta['items'] ) ) {
240
-        foreach ( $meta['items'] as $key => $item ) {
241
-            if ( 0 === intval( $item ) ) {
242
-                unset( $meta['items'][ $key ] );
239
+    if (!empty($meta['items'])) {
240
+        foreach ($meta['items'] as $key => $item) {
241
+            if (0 === intval($item)) {
242
+                unset($meta['items'][$key]);
243 243
             }
244 244
         }
245 245
     }
246 246
     
247
-    if ( ! empty( $meta['excluded_items'] ) ) {
248
-        foreach ( $meta['excluded_items'] as $key => $item ) {
249
-            if ( 0 === intval( $item ) ) {
250
-                unset( $meta['excluded_items'][ $key ] );
247
+    if (!empty($meta['excluded_items'])) {
248
+        foreach ($meta['excluded_items'] as $key => $item) {
249
+            if (0 === intval($item)) {
250
+                unset($meta['excluded_items'][$key]);
251 251
             }
252 252
         }
253 253
     }
254 254
     
255
-    $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post );
255
+    $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post);
256 256
     
257
-    do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post );
257
+    do_action('wpinv_pre_update_discount', $meta, $post_id, $post);
258 258
     
259
-    foreach( $meta as $key => $value ) {
260
-        update_post_meta( $post_id, '_wpi_discount_' . $key, $value );
259
+    foreach ($meta as $key => $value) {
260
+        update_post_meta($post_id, '_wpi_discount_' . $key, $value);
261 261
     }
262 262
     
263
-    do_action( 'wpinv_post_update_discount', $meta, $post_id, $post );
263
+    do_action('wpinv_post_update_discount', $meta, $post_id, $post);
264 264
     
265 265
     return $post_id;
266 266
 }
267 267
 
268
-function wpinv_remove_discount( $discount_id = 0 ) {
269
-    do_action( 'wpinv_pre_delete_discount', $discount_id );
268
+function wpinv_remove_discount($discount_id = 0) {
269
+    do_action('wpinv_pre_delete_discount', $discount_id);
270 270
 
271
-    wp_delete_post( $discount_id, true );
271
+    wp_delete_post($discount_id, true);
272 272
 
273
-    do_action( 'wpinv_post_delete_discount', $discount_id );
273
+    do_action('wpinv_post_delete_discount', $discount_id);
274 274
 }
275 275
 
276
-function wpinv_update_discount_status( $code_id = 0, $new_status = 'publish' ) {
277
-    $discount = wpinv_get_discount(  $code_id );
276
+function wpinv_update_discount_status($code_id = 0, $new_status = 'publish') {
277
+    $discount = wpinv_get_discount($code_id);
278 278
 
279
-    if ( $discount ) {
280
-        do_action( 'wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status );
279
+    if ($discount) {
280
+        do_action('wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status);
281 281
 
282
-        wp_update_post( array( 'ID' => $code_id, 'post_status' => $new_status ) );
282
+        wp_update_post(array('ID' => $code_id, 'post_status' => $new_status));
283 283
 
284
-        do_action( 'wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status );
284
+        do_action('wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status);
285 285
 
286 286
         return true;
287 287
     }
@@ -289,173 +289,173 @@  discard block
 block discarded – undo
289 289
     return false;
290 290
 }
291 291
 
292
-function wpinv_discount_exists( $code_id ) {
293
-    if ( wpinv_get_discount(  $code_id ) ) {
292
+function wpinv_discount_exists($code_id) {
293
+    if (wpinv_get_discount($code_id)) {
294 294
         return true;
295 295
     }
296 296
 
297 297
     return false;
298 298
 }
299 299
 
300
-function wpinv_is_discount_active( $code_id = null ) {
301
-    $discount = wpinv_get_discount(  $code_id );
300
+function wpinv_is_discount_active($code_id = null) {
301
+    $discount = wpinv_get_discount($code_id);
302 302
     $return   = false;
303 303
 
304
-    if ( $discount ) {
305
-        if ( wpinv_is_discount_expired( $code_id ) ) {
306
-            if( defined( 'DOING_AJAX' ) ) {
307
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) );
304
+    if ($discount) {
305
+        if (wpinv_is_discount_expired($code_id)) {
306
+            if (defined('DOING_AJAX')) {
307
+                wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing'));
308 308
             }
309
-        } elseif ( $discount->post_status == 'publish' ) {
309
+        } elseif ($discount->post_status == 'publish') {
310 310
             $return = true;
311 311
         } else {
312
-            if( defined( 'DOING_AJAX' ) ) {
313
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) );
312
+            if (defined('DOING_AJAX')) {
313
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing'));
314 314
             }
315 315
         }
316 316
     }
317 317
 
318
-    return apply_filters( 'wpinv_is_discount_active', $return, $code_id );
318
+    return apply_filters('wpinv_is_discount_active', $return, $code_id);
319 319
 }
320 320
 
321
-function wpinv_get_discount_code( $code_id = null ) {
322
-    $code = get_post_meta( $code_id, '_wpi_discount_code', true );
321
+function wpinv_get_discount_code($code_id = null) {
322
+    $code = get_post_meta($code_id, '_wpi_discount_code', true);
323 323
 
324
-    return apply_filters( 'wpinv_get_discount_code', $code, $code_id );
324
+    return apply_filters('wpinv_get_discount_code', $code, $code_id);
325 325
 }
326 326
 
327
-function wpinv_get_discount_start_date( $code_id = null ) {
328
-    $start_date = get_post_meta( $code_id, '_wpi_discount_start', true );
327
+function wpinv_get_discount_start_date($code_id = null) {
328
+    $start_date = get_post_meta($code_id, '_wpi_discount_start', true);
329 329
 
330
-    return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id );
330
+    return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id);
331 331
 }
332 332
 
333
-function wpinv_get_discount_expiration( $code_id = null ) {
334
-    $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true );
333
+function wpinv_get_discount_expiration($code_id = null) {
334
+    $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true);
335 335
 
336
-    return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id );
336
+    return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id);
337 337
 }
338 338
 
339
-function wpinv_get_discount_max_uses( $code_id = null ) {
340
-    $max_uses = get_post_meta( $code_id, '_wpi_discount_max_uses', true );
339
+function wpinv_get_discount_max_uses($code_id = null) {
340
+    $max_uses = get_post_meta($code_id, '_wpi_discount_max_uses', true);
341 341
 
342
-    return (int) apply_filters( 'wpinv_get_discount_max_uses', $max_uses, $code_id );
342
+    return (int)apply_filters('wpinv_get_discount_max_uses', $max_uses, $code_id);
343 343
 }
344 344
 
345
-function wpinv_get_discount_uses( $code_id = null ) {
346
-    $uses = get_post_meta( $code_id, '_wpi_discount_uses', true );
345
+function wpinv_get_discount_uses($code_id = null) {
346
+    $uses = get_post_meta($code_id, '_wpi_discount_uses', true);
347 347
 
348
-    return (int) apply_filters( 'wpinv_get_discount_uses', $uses, $code_id );
348
+    return (int)apply_filters('wpinv_get_discount_uses', $uses, $code_id);
349 349
 }
350 350
 
351
-function wpinv_get_discount_min_total( $code_id = null ) {
352
-    $min_total = get_post_meta( $code_id, '_wpi_discount_min_total', true );
351
+function wpinv_get_discount_min_total($code_id = null) {
352
+    $min_total = get_post_meta($code_id, '_wpi_discount_min_total', true);
353 353
 
354
-    return (float) apply_filters( 'wpinv_get_discount_min_total', $min_total, $code_id );
354
+    return (float)apply_filters('wpinv_get_discount_min_total', $min_total, $code_id);
355 355
 }
356 356
 
357
-function wpinv_get_discount_max_total( $code_id = null ) {
358
-    $max_total = get_post_meta( $code_id, '_wpi_discount_max_total', true );
357
+function wpinv_get_discount_max_total($code_id = null) {
358
+    $max_total = get_post_meta($code_id, '_wpi_discount_max_total', true);
359 359
 
360
-    return (float) apply_filters( 'wpinv_get_discount_max_total', $max_total, $code_id );
360
+    return (float)apply_filters('wpinv_get_discount_max_total', $max_total, $code_id);
361 361
 }
362 362
 
363
-function wpinv_get_discount_amount( $code_id = null ) {
364
-    $amount = get_post_meta( $code_id, '_wpi_discount_amount', true );
363
+function wpinv_get_discount_amount($code_id = null) {
364
+    $amount = get_post_meta($code_id, '_wpi_discount_amount', true);
365 365
 
366
-    return (float) apply_filters( 'wpinv_get_discount_amount', $amount, $code_id );
366
+    return (float)apply_filters('wpinv_get_discount_amount', $amount, $code_id);
367 367
 }
368 368
 
369
-function wpinv_get_discount_type( $code_id = null, $name = false ) {
370
-    $type = strtolower( get_post_meta( $code_id, '_wpi_discount_type', true ) );
369
+function wpinv_get_discount_type($code_id = null, $name = false) {
370
+    $type = strtolower(get_post_meta($code_id, '_wpi_discount_type', true));
371 371
     
372
-    if ( $name ) {
373
-        $name = wpinv_get_discount_type_name( $type );
372
+    if ($name) {
373
+        $name = wpinv_get_discount_type_name($type);
374 374
         
375
-        return apply_filters( 'wpinv_get_discount_type_name', $name, $code_id );
375
+        return apply_filters('wpinv_get_discount_type_name', $name, $code_id);
376 376
     }
377 377
 
378
-    return apply_filters( 'wpinv_get_discount_type', $type, $code_id );
378
+    return apply_filters('wpinv_get_discount_type', $type, $code_id);
379 379
 }
380 380
 
381
-function wpinv_discount_status( $status ) {
382
-    switch( $status ){
381
+function wpinv_discount_status($status) {
382
+    switch ($status) {
383 383
         case 'expired' :
384
-            $name = __( 'Expired', 'invoicing' );
384
+            $name = __('Expired', 'invoicing');
385 385
             break;
386 386
         case 'publish' :
387 387
         case 'active' :
388
-            $name = __( 'Active', 'invoicing' );
388
+            $name = __('Active', 'invoicing');
389 389
             break;
390 390
         default :
391
-            $name = __( 'Inactive', 'invoicing' );
391
+            $name = __('Inactive', 'invoicing');
392 392
             break;
393 393
     }
394 394
     return $name;
395 395
 }
396 396
 
397
-function wpinv_get_discount_excluded_items( $code_id = null ) {
398
-    $excluded_items = get_post_meta( $code_id, '_wpi_discount_excluded_items', true );
397
+function wpinv_get_discount_excluded_items($code_id = null) {
398
+    $excluded_items = get_post_meta($code_id, '_wpi_discount_excluded_items', true);
399 399
 
400
-    if ( empty( $excluded_items ) || ! is_array( $excluded_items ) ) {
400
+    if (empty($excluded_items) || !is_array($excluded_items)) {
401 401
         $excluded_items = array();
402 402
     }
403 403
 
404
-    return (array) apply_filters( 'wpinv_get_discount_excluded_items', $excluded_items, $code_id );
404
+    return (array)apply_filters('wpinv_get_discount_excluded_items', $excluded_items, $code_id);
405 405
 }
406 406
 
407
-function wpinv_get_discount_item_reqs( $code_id = null ) {
408
-    $item_reqs = get_post_meta( $code_id, '_wpi_discount_items', true );
407
+function wpinv_get_discount_item_reqs($code_id = null) {
408
+    $item_reqs = get_post_meta($code_id, '_wpi_discount_items', true);
409 409
 
410
-    if ( empty( $item_reqs ) || ! is_array( $item_reqs ) ) {
410
+    if (empty($item_reqs) || !is_array($item_reqs)) {
411 411
         $item_reqs = array();
412 412
     }
413 413
 
414
-    return (array) apply_filters( 'wpinv_get_discount_item_reqs', $item_reqs, $code_id );
414
+    return (array)apply_filters('wpinv_get_discount_item_reqs', $item_reqs, $code_id);
415 415
 }
416 416
 
417
-function wpinv_get_discount_item_condition( $code_id = 0 ) {
418
-    return get_post_meta( $code_id, '_wpi_discount_item_condition', true );
417
+function wpinv_get_discount_item_condition($code_id = 0) {
418
+    return get_post_meta($code_id, '_wpi_discount_item_condition', true);
419 419
 }
420 420
 
421
-function wpinv_is_discount_not_global( $code_id = 0 ) {
422
-    return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true );
421
+function wpinv_is_discount_not_global($code_id = 0) {
422
+    return (bool)get_post_meta($code_id, '_wpi_discount_is_not_global', true);
423 423
 }
424 424
 
425
-function wpinv_is_discount_expired( $code_id = null ) {
426
-    $discount = wpinv_get_discount(  $code_id );
425
+function wpinv_is_discount_expired($code_id = null) {
426
+    $discount = wpinv_get_discount($code_id);
427 427
     $return   = false;
428 428
 
429
-    if ( $discount ) {
430
-        $expiration = wpinv_get_discount_expiration( $code_id );
431
-        if ( $expiration ) {
432
-            $expiration = strtotime( $expiration );
433
-            if ( $expiration < current_time( 'timestamp' ) ) {
429
+    if ($discount) {
430
+        $expiration = wpinv_get_discount_expiration($code_id);
431
+        if ($expiration) {
432
+            $expiration = strtotime($expiration);
433
+            if ($expiration < current_time('timestamp')) {
434 434
                 // Discount is expired
435
-                wpinv_update_discount_status( $code_id, 'pending' );
435
+                wpinv_update_discount_status($code_id, 'pending');
436 436
                 $return = true;
437 437
             }
438 438
         }
439 439
     }
440 440
 
441
-    return apply_filters( 'wpinv_is_discount_expired', $return, $code_id );
441
+    return apply_filters('wpinv_is_discount_expired', $return, $code_id);
442 442
 }
443 443
 
444
-function wpinv_is_discount_started( $code_id = null ) {
445
-    $discount = wpinv_get_discount(  $code_id );
444
+function wpinv_is_discount_started($code_id = null) {
445
+    $discount = wpinv_get_discount($code_id);
446 446
     $return   = false;
447 447
 
448
-    if ( $discount ) {
449
-        $start_date = wpinv_get_discount_start_date( $code_id );
448
+    if ($discount) {
449
+        $start_date = wpinv_get_discount_start_date($code_id);
450 450
 
451
-        if ( $start_date ) {
452
-            $start_date = strtotime( $start_date );
451
+        if ($start_date) {
452
+            $start_date = strtotime($start_date);
453 453
 
454
-            if ( $start_date < current_time( 'timestamp' ) ) {
454
+            if ($start_date < current_time('timestamp')) {
455 455
                 // Discount has past the start date
456 456
                 $return = true;
457 457
             } else {
458
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
458
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
459 459
             }
460 460
         } else {
461 461
             // No start date for this discount, so has to be true
@@ -463,159 +463,159 @@  discard block
 block discarded – undo
463 463
         }
464 464
     }
465 465
 
466
-    return apply_filters( 'wpinv_is_discount_started', $return, $code_id );
466
+    return apply_filters('wpinv_is_discount_started', $return, $code_id);
467 467
 }
468 468
 
469
-function wpinv_check_discount_dates( $code_id = null ) {
470
-    $discount = wpinv_get_discount(  $code_id );
469
+function wpinv_check_discount_dates($code_id = null) {
470
+    $discount = wpinv_get_discount($code_id);
471 471
     $return   = false;
472 472
 
473
-    if ( $discount ) {
474
-        $start_date = wpinv_get_discount_start_date( $code_id );
473
+    if ($discount) {
474
+        $start_date = wpinv_get_discount_start_date($code_id);
475 475
 
476
-        if ( $start_date ) {
477
-            $start_date = strtotime( $start_date );
476
+        if ($start_date) {
477
+            $start_date = strtotime($start_date);
478 478
 
479
-            if ( $start_date < current_time( 'timestamp' ) ) {
479
+            if ($start_date < current_time('timestamp')) {
480 480
                 // Discount has past the start date
481 481
                 $return = true;
482 482
             } else {
483
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
483
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
484 484
             }
485 485
         } else {
486 486
             // No start date for this discount, so has to be true
487 487
             $return = true;
488 488
         }
489 489
         
490
-        if ( $return ) {
491
-            $expiration = wpinv_get_discount_expiration( $code_id );
490
+        if ($return) {
491
+            $expiration = wpinv_get_discount_expiration($code_id);
492 492
             
493
-            if ( $expiration ) {
494
-                $expiration = strtotime( $expiration );
495
-                if ( $expiration < current_time( 'timestamp' ) ) {
493
+            if ($expiration) {
494
+                $expiration = strtotime($expiration);
495
+                if ($expiration < current_time('timestamp')) {
496 496
                     // Discount is expired
497
-                    wpinv_update_discount_status( $code_id, 'pending' );
497
+                    wpinv_update_discount_status($code_id, 'pending');
498 498
                     $return = true;
499 499
                 }
500 500
             }
501 501
         }
502 502
     }
503 503
     
504
-    return apply_filters( 'wpinv_check_discount_dates', $return, $code_id );
504
+    return apply_filters('wpinv_check_discount_dates', $return, $code_id);
505 505
 }
506 506
 
507
-function wpinv_is_discount_maxed_out( $code_id = null ) {
508
-    $discount = wpinv_get_discount(  $code_id );
507
+function wpinv_is_discount_maxed_out($code_id = null) {
508
+    $discount = wpinv_get_discount($code_id);
509 509
     $return   = false;
510 510
 
511
-    if ( $discount ) {
512
-        $uses = wpinv_get_discount_uses( $code_id );
511
+    if ($discount) {
512
+        $uses = wpinv_get_discount_uses($code_id);
513 513
         // Large number that will never be reached
514
-        $max_uses = wpinv_get_discount_max_uses( $code_id );
514
+        $max_uses = wpinv_get_discount_max_uses($code_id);
515 515
         // Should never be greater than, but just in case
516
-        if ( $uses >= $max_uses && ! empty( $max_uses ) ) {
516
+        if ($uses >= $max_uses && !empty($max_uses)) {
517 517
             // Discount is maxed out
518
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) );
518
+            wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing'));
519 519
             $return = true;
520 520
         }
521 521
     }
522 522
 
523
-    return apply_filters( 'wpinv_is_discount_maxed_out', $return, $code_id );
523
+    return apply_filters('wpinv_is_discount_maxed_out', $return, $code_id);
524 524
 }
525 525
 
526
-function wpinv_discount_is_min_met( $code_id = null ) {
527
-    $discount = wpinv_get_discount( $code_id );
526
+function wpinv_discount_is_min_met($code_id = null) {
527
+    $discount = wpinv_get_discount($code_id);
528 528
     $return   = false;
529 529
 
530
-    if ( $discount ) {
531
-        $min         = (float)wpinv_get_discount_min_total( $code_id );
532
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
530
+    if ($discount) {
531
+        $min         = (float)wpinv_get_discount_min_total($code_id);
532
+        $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id);
533 533
 
534
-        if ( !$min > 0 || $cart_amount >= $min ) {
534
+        if (!$min > 0 || $cart_amount >= $min) {
535 535
             // Minimum has been met
536 536
             $return = true;
537 537
         } else {
538
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) );
538
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($min))));
539 539
         }
540 540
     }
541 541
 
542
-    return apply_filters( 'wpinv_is_discount_min_met', $return, $code_id );
542
+    return apply_filters('wpinv_is_discount_min_met', $return, $code_id);
543 543
 }
544 544
 
545
-function wpinv_discount_is_max_met( $code_id = null ) {
546
-    $discount = wpinv_get_discount( $code_id );
545
+function wpinv_discount_is_max_met($code_id = null) {
546
+    $discount = wpinv_get_discount($code_id);
547 547
     $return   = false;
548 548
 
549
-    if ( $discount ) {
550
-        $max         = (float)wpinv_get_discount_max_total( $code_id );
551
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
549
+    if ($discount) {
550
+        $max         = (float)wpinv_get_discount_max_total($code_id);
551
+        $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id);
552 552
 
553
-        if ( !$max > 0 || $cart_amount <= $max ) {
553
+        if (!$max > 0 || $cart_amount <= $max) {
554 554
             // Minimum has been met
555 555
             $return = true;
556 556
         } else {
557
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) );
557
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($max))));
558 558
         }
559 559
     }
560 560
 
561
-    return apply_filters( 'wpinv_is_discount_max_met', $return, $code_id );
561
+    return apply_filters('wpinv_is_discount_max_met', $return, $code_id);
562 562
 }
563 563
 
564
-function wpinv_discount_is_single_use( $code_id = 0 ) {
565
-    $single_use = get_post_meta( $code_id, '_wpi_discount_is_single_use', true );
566
-    return (bool) apply_filters( 'wpinv_is_discount_single_use', $single_use, $code_id );
564
+function wpinv_discount_is_single_use($code_id = 0) {
565
+    $single_use = get_post_meta($code_id, '_wpi_discount_is_single_use', true);
566
+    return (bool)apply_filters('wpinv_is_discount_single_use', $single_use, $code_id);
567 567
 }
568 568
 
569
-function wpinv_discount_is_recurring( $code_id = 0, $code = false ) {
570
-    if ( $code ) {
571
-        $discount = wpinv_get_discount_by_code( $code_id );
569
+function wpinv_discount_is_recurring($code_id = 0, $code = false) {
570
+    if ($code) {
571
+        $discount = wpinv_get_discount_by_code($code_id);
572 572
         
573
-        if ( !empty( $discount ) ) {
573
+        if (!empty($discount)) {
574 574
             $code_id = $discount->ID;
575 575
         }
576 576
     }
577 577
     
578
-    $recurring = get_post_meta( $code_id, '_wpi_discount_is_recurring', true );
578
+    $recurring = get_post_meta($code_id, '_wpi_discount_is_recurring', true);
579 579
     
580
-    return (bool) apply_filters( 'wpinv_is_discount_recurring', $recurring, $code_id, $code );
580
+    return (bool)apply_filters('wpinv_is_discount_recurring', $recurring, $code_id, $code);
581 581
 }
582 582
 
583
-function wpinv_discount_item_reqs_met( $code_id = null ) {
584
-    $item_reqs    = wpinv_get_discount_item_reqs( $code_id );
585
-    $condition    = wpinv_get_discount_item_condition( $code_id );
586
-    $excluded_ps  = wpinv_get_discount_excluded_items( $code_id );
583
+function wpinv_discount_item_reqs_met($code_id = null) {
584
+    $item_reqs    = wpinv_get_discount_item_reqs($code_id);
585
+    $condition    = wpinv_get_discount_item_condition($code_id);
586
+    $excluded_ps  = wpinv_get_discount_excluded_items($code_id);
587 587
     $cart_items   = wpinv_get_cart_contents();
588
-    $cart_ids     = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null;
588
+    $cart_ids     = $cart_items ? wp_list_pluck($cart_items, 'id') : null;
589 589
     $ret          = false;
590 590
 
591
-    if ( empty( $item_reqs ) && empty( $excluded_ps ) ) {
591
+    if (empty($item_reqs) && empty($excluded_ps)) {
592 592
         $ret = true;
593 593
     }
594 594
 
595 595
     // Normalize our data for item requirements, exclusions and cart data
596 596
     // First absint the items, then sort, and reset the array keys
597
-    $item_reqs = array_map( 'absint', $item_reqs );
598
-    asort( $item_reqs );
599
-    $item_reqs = array_values( $item_reqs );
597
+    $item_reqs = array_map('absint', $item_reqs);
598
+    asort($item_reqs);
599
+    $item_reqs = array_values($item_reqs);
600 600
 
601
-    $excluded_ps  = array_map( 'absint', $excluded_ps );
602
-    asort( $excluded_ps );
603
-    $excluded_ps  = array_values( $excluded_ps );
601
+    $excluded_ps  = array_map('absint', $excluded_ps);
602
+    asort($excluded_ps);
603
+    $excluded_ps  = array_values($excluded_ps);
604 604
 
605
-    $cart_ids     = array_map( 'absint', $cart_ids );
606
-    asort( $cart_ids );
607
-    $cart_ids     = array_values( $cart_ids );
605
+    $cart_ids     = array_map('absint', $cart_ids);
606
+    asort($cart_ids);
607
+    $cart_ids     = array_values($cart_ids);
608 608
 
609 609
     // Ensure we have requirements before proceeding
610
-    if ( !$ret && ! empty( $item_reqs ) ) {
611
-        switch( $condition ) {
610
+    if (!$ret && !empty($item_reqs)) {
611
+        switch ($condition) {
612 612
             case 'all' :
613 613
                 // Default back to true
614 614
                 $ret = true;
615 615
 
616
-                foreach ( $item_reqs as $item_id ) {
617
-                    if ( !wpinv_item_in_cart( $item_id ) ) {
618
-                        wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
616
+                foreach ($item_reqs as $item_id) {
617
+                    if (!wpinv_item_in_cart($item_id)) {
618
+                        wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
619 619
                         $ret = false;
620 620
                         break;
621 621
                     }
@@ -624,15 +624,15 @@  discard block
 block discarded – undo
624 624
                 break;
625 625
 
626 626
             default : // Any
627
-                foreach ( $item_reqs as $item_id ) {
628
-                    if ( wpinv_item_in_cart( $item_id ) ) {
627
+                foreach ($item_reqs as $item_id) {
628
+                    if (wpinv_item_in_cart($item_id)) {
629 629
                         $ret = true;
630 630
                         break;
631 631
                     }
632 632
                 }
633 633
 
634
-                if( ! $ret ) {
635
-                    wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
634
+                if (!$ret) {
635
+                    wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
636 636
                 }
637 637
 
638 638
                 break;
@@ -641,68 +641,68 @@  discard block
 block discarded – undo
641 641
         $ret = true;
642 642
     }
643 643
 
644
-    if( ! empty( $excluded_ps ) ) {
644
+    if (!empty($excluded_ps)) {
645 645
         // Check that there are items other than excluded ones in the cart
646
-        if( $cart_ids == $excluded_ps ) {
647
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) );
646
+        if ($cart_ids == $excluded_ps) {
647
+            wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing'));
648 648
             $ret = false;
649 649
         }
650 650
     }
651 651
 
652
-    return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition );
652
+    return (bool)apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition);
653 653
 }
654 654
 
655
-function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) {
655
+function wpinv_is_discount_used($code = null, $user = '', $code_id = 0) {
656 656
     global $wpi_checkout_id;
657 657
     
658 658
     $return = false;
659 659
 
660
-    if ( empty( $code_id ) ) {
661
-        $code_id = wpinv_get_discount_id_by_code( $code );
660
+    if (empty($code_id)) {
661
+        $code_id = wpinv_get_discount_id_by_code($code);
662 662
         
663
-        if( empty( $code_id ) ) {
663
+        if (empty($code_id)) {
664 664
             return false; // No discount was found
665 665
         }
666 666
     }
667 667
 
668
-    if ( wpinv_discount_is_single_use( $code_id ) ) {
668
+    if (wpinv_discount_is_single_use($code_id)) {
669 669
         $payments = array();
670 670
 
671 671
         $user_id = 0;
672
-        if ( is_int( $user ) ) {
672
+        if (is_int($user)) {
673 673
             $user_id = $user;
674
-        } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) {
674
+        } else if (is_email($user) && $user_data = get_user_by('email', $user)) {
675 675
             $user_id = $user_data->ID;
676
-        } else if ( $user_data = get_user_by( 'login', $user ) ) {
676
+        } else if ($user_data = get_user_by('login', $user)) {
677 677
             $user_id = $user_data->ID;
678 678
         }
679 679
 
680
-        if ( !$user_id ) {
681
-            $query    = array( 'user' => $user_id, 'limit' => false );
682
-            $payments = wpinv_get_invoices( $query ); // Get all payments with matching email
680
+        if (!$user_id) {
681
+            $query    = array('user' => $user_id, 'limit' => false);
682
+            $payments = wpinv_get_invoices($query); // Get all payments with matching email
683 683
         }
684 684
 
685
-        if ( $payments ) {
686
-            foreach ( $payments as $payment ) {
687
-                if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) {
685
+        if ($payments) {
686
+            foreach ($payments as $payment) {
687
+                if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) {
688 688
                     continue;
689 689
                 }
690 690
 
691 691
                 // Don't count discount used for current invoice chekcout.
692
-                if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) {
692
+                if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) {
693 693
                     continue;
694 694
                 }
695 695
 
696
-                $discounts = $payment->get_discounts( true );
697
-                if ( empty( $discounts ) ) {
696
+                $discounts = $payment->get_discounts(true);
697
+                if (empty($discounts)) {
698 698
                     continue;
699 699
                 }
700 700
 
701
-                $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts;
701
+                $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts;
702 702
 
703
-                if ( !empty( $discounts ) && is_array( $discounts ) ) {
704
-                    if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) {
705
-                        wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) );
703
+                if (!empty($discounts) && is_array($discounts)) {
704
+                    if (in_array(strtolower($code), array_map('strtolower', $discounts))) {
705
+                        wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing'));
706 706
                         $return = true;
707 707
                         break;
708 708
                     }
@@ -711,61 +711,61 @@  discard block
 block discarded – undo
711 711
         }
712 712
     }
713 713
 
714
-    return apply_filters( 'wpinv_is_discount_used', $return, $code, $user );
714
+    return apply_filters('wpinv_is_discount_used', $return, $code, $user);
715 715
 }
716 716
 
717
-function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) {
717
+function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) {
718 718
     $return      = false;
719
-    $discount_id = wpinv_get_discount_id_by_code( $code );
720
-    $user        = trim( $user );
719
+    $discount_id = wpinv_get_discount_id_by_code($code);
720
+    $user        = trim($user);
721 721
 
722
-    if ( wpinv_get_cart_contents() ) {
723
-        if ( $discount_id ) {
722
+    if (wpinv_get_cart_contents()) {
723
+        if ($discount_id) {
724 724
             if (
725
-                wpinv_is_discount_active( $discount_id ) &&
726
-                wpinv_check_discount_dates( $discount_id ) &&
727
-                !wpinv_is_discount_maxed_out( $discount_id ) &&
728
-                !wpinv_is_discount_used( $code, $user, $discount_id ) &&
729
-                wpinv_discount_is_min_met( $discount_id ) &&
730
-                wpinv_discount_is_max_met( $discount_id ) &&
731
-                wpinv_discount_item_reqs_met( $discount_id )
725
+                wpinv_is_discount_active($discount_id) &&
726
+                wpinv_check_discount_dates($discount_id) &&
727
+                !wpinv_is_discount_maxed_out($discount_id) &&
728
+                !wpinv_is_discount_used($code, $user, $discount_id) &&
729
+                wpinv_discount_is_min_met($discount_id) &&
730
+                wpinv_discount_is_max_met($discount_id) &&
731
+                wpinv_discount_item_reqs_met($discount_id)
732 732
             ) {
733 733
                 $return = true;
734 734
             }
735
-        } elseif( $set_error ) {
736
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) );
735
+        } elseif ($set_error) {
736
+            wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing'));
737 737
         }
738 738
     }
739 739
 
740
-    return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user );
740
+    return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user);
741 741
 }
742 742
 
743
-function wpinv_get_discount_id_by_code( $code ) {
744
-    $discount = wpinv_get_discount_by_code( $code );
745
-    if( $discount ) {
743
+function wpinv_get_discount_id_by_code($code) {
744
+    $discount = wpinv_get_discount_by_code($code);
745
+    if ($discount) {
746 746
         return $discount->ID;
747 747
     }
748 748
     return false;
749 749
 }
750 750
 
751
-function wpinv_get_discounted_amount( $code, $base_price ) {
751
+function wpinv_get_discounted_amount($code, $base_price) {
752 752
     $amount      = $base_price;
753
-    $discount_id = wpinv_get_discount_id_by_code( $code );
753
+    $discount_id = wpinv_get_discount_id_by_code($code);
754 754
 
755
-    if( $discount_id ) {
756
-        $type        = wpinv_get_discount_type( $discount_id );
757
-        $rate        = wpinv_get_discount_amount( $discount_id );
755
+    if ($discount_id) {
756
+        $type        = wpinv_get_discount_type($discount_id);
757
+        $rate        = wpinv_get_discount_amount($discount_id);
758 758
 
759
-        if ( $type == 'flat' ) {
759
+        if ($type == 'flat') {
760 760
             // Set amount
761 761
             $amount = $base_price - $rate;
762
-            if ( $amount < 0 ) {
762
+            if ($amount < 0) {
763 763
                 $amount = 0;
764 764
             }
765 765
 
766 766
         } else {
767 767
             // Percentage discount
768
-            $amount = $base_price - ( $base_price * ( $rate / 100 ) );
768
+            $amount = $base_price - ($base_price * ($rate / 100));
769 769
         }
770 770
 
771 771
     } else {
@@ -774,108 +774,108 @@  discard block
 block discarded – undo
774 774
 
775 775
     }
776 776
 
777
-    return apply_filters( 'wpinv_discounted_amount', $amount );
777
+    return apply_filters('wpinv_discounted_amount', $amount);
778 778
 }
779 779
 
780
-function wpinv_increase_discount_usage( $code ) {
780
+function wpinv_increase_discount_usage($code) {
781 781
 
782
-    $id   = wpinv_get_discount_id_by_code( $code );
783
-    $uses = wpinv_get_discount_uses( $id );
782
+    $id   = wpinv_get_discount_id_by_code($code);
783
+    $uses = wpinv_get_discount_uses($id);
784 784
 
785
-    if ( $uses ) {
785
+    if ($uses) {
786 786
         $uses++;
787 787
     } else {
788 788
         $uses = 1;
789 789
     }
790 790
 
791
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
791
+    update_post_meta($id, '_wpi_discount_uses', $uses);
792 792
 
793
-    do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code );
793
+    do_action('wpinv_discount_increase_use_count', $uses, $id, $code);
794 794
 
795 795
     return $uses;
796 796
 
797 797
 }
798 798
 
799
-function wpinv_decrease_discount_usage( $code ) {
799
+function wpinv_decrease_discount_usage($code) {
800 800
 
801
-    $id   = wpinv_get_discount_id_by_code( $code );
802
-    $uses = wpinv_get_discount_uses( $id );
801
+    $id   = wpinv_get_discount_id_by_code($code);
802
+    $uses = wpinv_get_discount_uses($id);
803 803
 
804
-    if ( $uses ) {
804
+    if ($uses) {
805 805
         $uses--;
806 806
     }
807 807
 
808
-    if ( $uses < 0 ) {
808
+    if ($uses < 0) {
809 809
         $uses = 0;
810 810
     }
811 811
 
812
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
812
+    update_post_meta($id, '_wpi_discount_uses', $uses);
813 813
 
814
-    do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code );
814
+    do_action('wpinv_discount_decrease_use_count', $uses, $id, $code);
815 815
 
816 816
     return $uses;
817 817
 
818 818
 }
819 819
 
820
-function wpinv_format_discount_rate( $type, $amount ) {
821
-    if ( $type == 'flat' ) {
822
-        return wpinv_price( wpinv_format_amount( $amount ) );
820
+function wpinv_format_discount_rate($type, $amount) {
821
+    if ($type == 'flat') {
822
+        return wpinv_price(wpinv_format_amount($amount));
823 823
     } else {
824 824
         return $amount . '%';
825 825
     }
826 826
 }
827 827
 
828
-function wpinv_set_cart_discount( $code = '' ) {    
829
-    if ( wpinv_multiple_discounts_allowed() ) {
828
+function wpinv_set_cart_discount($code = '') {    
829
+    if (wpinv_multiple_discounts_allowed()) {
830 830
         // Get all active cart discounts
831 831
         $discounts = wpinv_get_cart_discounts();
832 832
     } else {
833 833
         $discounts = false; // Only one discount allowed per purchase, so override any existing
834 834
     }
835 835
 
836
-    if ( $discounts ) {
837
-        $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) );
838
-        if( false !== $key ) {
839
-            unset( $discounts[ $key ] ); // Can't set the same discount more than once
836
+    if ($discounts) {
837
+        $key = array_search(strtolower($code), array_map('strtolower', $discounts));
838
+        if (false !== $key) {
839
+            unset($discounts[$key]); // Can't set the same discount more than once
840 840
         }
841 841
         $discounts[] = $code;
842 842
     } else {
843 843
         $discounts = array();
844 844
         $discounts[] = $code;
845 845
     }
846
-    $discounts = array_values( $discounts );
846
+    $discounts = array_values($discounts);
847 847
     
848 848
     $data = wpinv_get_checkout_session();
849
-    if ( empty( $data ) ) {
849
+    if (empty($data)) {
850 850
         $data = array();
851 851
     } else {
852
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
853
-            $payment_meta['user_info']['discount']  = implode( ',', $discounts );
854
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
852
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
853
+            $payment_meta['user_info']['discount'] = implode(',', $discounts);
854
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
855 855
         }
856 856
     }
857 857
     $data['cart_discounts'] = $discounts;
858 858
     
859
-    wpinv_set_checkout_session( $data );
859
+    wpinv_set_checkout_session($data);
860 860
     
861 861
     return $discounts;
862 862
 }
863 863
 
864
-function wpinv_unset_cart_discount( $code = '' ) {    
864
+function wpinv_unset_cart_discount($code = '') {    
865 865
     $discounts = wpinv_get_cart_discounts();
866 866
 
867
-    if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) {
868
-        $key = array_search( $code, $discounts );
869
-        unset( $discounts[ $key ] );
867
+    if ($code && !empty($discounts) && in_array($code, $discounts)) {
868
+        $key = array_search($code, $discounts);
869
+        unset($discounts[$key]);
870 870
             
871 871
         $data = wpinv_get_checkout_session();
872 872
         $data['cart_discounts'] = $discounts;
873
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
874
-            $payment_meta['user_info']['discount']  = !empty( $discounts ) ? implode( ',', $discounts ) : '';
875
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
873
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
874
+            $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : '';
875
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
876 876
         }
877 877
         
878
-        wpinv_set_checkout_session( $data );
878
+        wpinv_set_checkout_session($data);
879 879
     }
880 880
 
881 881
     return $discounts;
@@ -884,27 +884,27 @@  discard block
 block discarded – undo
884 884
 function wpinv_unset_all_cart_discounts() {
885 885
     $data = wpinv_get_checkout_session();
886 886
     
887
-    if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) {
888
-        unset( $data['cart_discounts'] );
887
+    if (!empty($data) && isset($data['cart_discounts'])) {
888
+        unset($data['cart_discounts']);
889 889
         
890
-         wpinv_set_checkout_session( $data );
890
+         wpinv_set_checkout_session($data);
891 891
          return true;
892 892
     }
893 893
     
894 894
     return false;
895 895
 }
896 896
 
897
-function wpinv_get_cart_discounts( $items = array() ) {
897
+function wpinv_get_cart_discounts($items = array()) {
898 898
     $session = wpinv_get_checkout_session();
899 899
     
900
-    $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false;
900
+    $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false;
901 901
     return $discounts;
902 902
 }
903 903
 
904
-function wpinv_cart_has_discounts( $items = array() ) {
904
+function wpinv_cart_has_discounts($items = array()) {
905 905
     $ret = false;
906 906
 
907
-    if ( wpinv_get_cart_discounts( $items ) ) {
907
+    if (wpinv_get_cart_discounts($items)) {
908 908
         $ret = true;
909 909
     }
910 910
     
@@ -915,131 +915,131 @@  discard block
 block discarded – undo
915 915
     }
916 916
     */
917 917
 
918
-    return apply_filters( 'wpinv_cart_has_discounts', $ret );
918
+    return apply_filters('wpinv_cart_has_discounts', $ret);
919 919
 }
920 920
 
921
-function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) {
921
+function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) {
922 922
     $amount = 0.00;
923
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
923
+    $items  = !empty($items) ? $items : wpinv_get_cart_content_details();
924 924
 
925
-    if ( $items ) {
926
-        $discounts = wp_list_pluck( $items, 'discount' );
925
+    if ($items) {
926
+        $discounts = wp_list_pluck($items, 'discount');
927 927
 
928
-        if ( is_array( $discounts ) ) {
929
-            $discounts = array_map( 'floatval', $discounts );
930
-            $amount    = array_sum( $discounts );
928
+        if (is_array($discounts)) {
929
+            $discounts = array_map('floatval', $discounts);
930
+            $amount    = array_sum($discounts);
931 931
         }
932 932
     }
933 933
 
934
-    return apply_filters( 'wpinv_get_cart_discounted_amount', $amount );
934
+    return apply_filters('wpinv_get_cart_discounted_amount', $amount);
935 935
 }
936 936
 
937
-function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) {
938
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
937
+function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) {
938
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
939 939
     
940
-    if ( empty( $discount ) || empty( $items ) ) {
940
+    if (empty($discount) || empty($items)) {
941 941
         return 0;
942 942
     }
943 943
 
944 944
     $amount = 0;
945 945
     
946
-    foreach ( $items as $item ) {
947
-        $amount += wpinv_get_cart_item_discount_amount( $item, $discount );
946
+    foreach ($items as $item) {
947
+        $amount += wpinv_get_cart_item_discount_amount($item, $discount);
948 948
     }
949 949
     
950
-    $amount = wpinv_round_amount( $amount );
950
+    $amount = wpinv_round_amount($amount);
951 951
 
952 952
     return $amount;
953 953
 }
954 954
 
955
-function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) {
955
+function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) {
956 956
     global $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
957 957
     
958 958
     $amount = 0;
959 959
 
960
-    if ( empty( $item ) || empty( $item['id'] ) ) {
960
+    if (empty($item) || empty($item['id'])) {
961 961
         return $amount;
962 962
     }
963 963
 
964
-    if ( empty( $item['quantity'] ) ) {
964
+    if (empty($item['quantity'])) {
965 965
         return $amount;
966 966
     }
967 967
 
968
-    if ( empty( $item['options'] ) ) {
968
+    if (empty($item['options'])) {
969 969
         $item['options'] = array();
970 970
     }
971 971
 
972
-    $price            = wpinv_get_cart_item_price( $item['id'], $item['options'] );
972
+    $price            = wpinv_get_cart_item_price($item['id'], $item['options']);
973 973
     $discounted_price = $price;
974 974
 
975 975
     $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount;
976
-    if ( empty( $discounts ) ) {
976
+    if (empty($discounts)) {
977 977
         return $amount;
978 978
     }
979 979
 
980
-    if ( $discounts ) {
981
-        if ( is_array( $discounts ) ) {
982
-            $discounts = array_values( $discounts );
980
+    if ($discounts) {
981
+        if (is_array($discounts)) {
982
+            $discounts = array_values($discounts);
983 983
         } else {
984
-            $discounts = explode( ',', $discounts );
984
+            $discounts = explode(',', $discounts);
985 985
         }
986 986
     }
987 987
 
988
-    if( $discounts ) {
989
-        foreach ( $discounts as $discount ) {
990
-            $code_id = wpinv_get_discount_id_by_code( $discount );
988
+    if ($discounts) {
989
+        foreach ($discounts as $discount) {
990
+            $code_id = wpinv_get_discount_id_by_code($discount);
991 991
 
992 992
             // Check discount exists
993
-            if( ! $code_id ) {
993
+            if (!$code_id) {
994 994
                 continue;
995 995
             }
996 996
 
997
-            $reqs           = wpinv_get_discount_item_reqs( $code_id );
998
-            $excluded_items = wpinv_get_discount_excluded_items( $code_id );
997
+            $reqs           = wpinv_get_discount_item_reqs($code_id);
998
+            $excluded_items = wpinv_get_discount_excluded_items($code_id);
999 999
 
1000 1000
             // Make sure requirements are set and that this discount shouldn't apply to the whole cart
1001
-            if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) {
1002
-                foreach ( $reqs as $item_id ) {
1003
-                    if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) {
1004
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1001
+            if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) {
1002
+                foreach ($reqs as $item_id) {
1003
+                    if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) {
1004
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1005 1005
                     }
1006 1006
                 }
1007 1007
             } else {
1008 1008
                 // This is a global cart discount
1009
-                if ( !in_array( $item['id'], $excluded_items ) ) {
1010
-                    if ( 'flat' === wpinv_get_discount_type( $code_id ) ) {
1009
+                if (!in_array($item['id'], $excluded_items)) {
1010
+                    if ('flat' === wpinv_get_discount_type($code_id)) {
1011 1011
                         $items_subtotal    = 0.00;
1012 1012
                         $cart_items        = wpinv_get_cart_contents();
1013 1013
                         
1014
-                        foreach ( $cart_items as $cart_item ) {
1015
-                            if ( ! in_array( $cart_item['id'], $excluded_items ) ) {
1016
-                                $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array();
1017
-                                $item_price      = wpinv_get_cart_item_price( $cart_item['id'], $options );
1014
+                        foreach ($cart_items as $cart_item) {
1015
+                            if (!in_array($cart_item['id'], $excluded_items)) {
1016
+                                $options = !empty($cart_item['options']) ? $cart_item['options'] : array();
1017
+                                $item_price      = wpinv_get_cart_item_price($cart_item['id'], $options);
1018 1018
                                 $items_subtotal += $item_price * $cart_item['quantity'];
1019 1019
                             }
1020 1020
                         }
1021 1021
 
1022
-                        $subtotal_percent  = ( ( $price * $item['quantity'] ) / $items_subtotal );
1023
-                        $code_amount       = wpinv_get_discount_amount( $code_id );
1022
+                        $subtotal_percent  = (($price * $item['quantity']) / $items_subtotal);
1023
+                        $code_amount       = wpinv_get_discount_amount($code_id);
1024 1024
                         $discounted_amount = $code_amount * $subtotal_percent;
1025 1025
                         $discounted_price -= $discounted_amount;
1026 1026
 
1027
-                        $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() );
1027
+                        $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter());
1028 1028
 
1029
-                        if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) {
1029
+                        if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) {
1030 1030
                             $adjustment = $code_amount - $wpinv_flat_discount_total;
1031 1031
                             $discounted_price -= $adjustment;
1032 1032
                         }
1033 1033
                     } else {
1034
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1034
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1035 1035
                     }
1036 1036
                 }
1037 1037
             }
1038 1038
         }
1039 1039
 
1040
-        $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) );
1040
+        $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price));
1041 1041
 
1042
-        if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) {
1042
+        if ('flat' !== wpinv_get_discount_type($code_id)) {
1043 1043
             $amount = $amount * $item['quantity'];
1044 1044
         }
1045 1045
     }
@@ -1047,59 +1047,59 @@  discard block
 block discarded – undo
1047 1047
     return $amount;
1048 1048
 }
1049 1049
 
1050
-function wpinv_cart_discounts_html( $items = array() ) {
1051
-    echo wpinv_get_cart_discounts_html( $items );
1050
+function wpinv_cart_discounts_html($items = array()) {
1051
+    echo wpinv_get_cart_discounts_html($items);
1052 1052
 }
1053 1053
 
1054
-function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) {
1054
+function wpinv_get_cart_discounts_html($items = array(), $discounts = false) {
1055 1055
     global $wpi_cart_columns;
1056 1056
     
1057
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
1057
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
1058 1058
     
1059
-    if ( !$discounts ) {
1060
-        $discounts = wpinv_get_cart_discounts( $items );
1059
+    if (!$discounts) {
1060
+        $discounts = wpinv_get_cart_discounts($items);
1061 1061
     }
1062 1062
 
1063
-    if ( !$discounts ) {
1063
+    if (!$discounts) {
1064 1064
         return;
1065 1065
     }
1066 1066
     
1067
-    $discounts = is_array( $discounts ) ? $discounts : array( $discounts );
1067
+    $discounts = is_array($discounts) ? $discounts : array($discounts);
1068 1068
     
1069 1069
     $html = '';
1070 1070
 
1071
-    foreach ( $discounts as $discount ) {
1072
-        $discount_id    = wpinv_get_discount_id_by_code( $discount );
1073
-        $discount_value = wpinv_get_discount_amount( $discount_id );
1074
-        $rate           = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value );
1075
-        $amount         = wpinv_get_cart_items_discount_amount( $items, $discount );
1076
-        $remove_btn     = '<a title="' . esc_attr__( 'Remove discount', 'invoicing' ) . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> ';
1071
+    foreach ($discounts as $discount) {
1072
+        $discount_id    = wpinv_get_discount_id_by_code($discount);
1073
+        $discount_value = wpinv_get_discount_amount($discount_id);
1074
+        $rate           = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value);
1075
+        $amount         = wpinv_get_cart_items_discount_amount($items, $discount);
1076
+        $remove_btn     = '<a title="' . esc_attr__('Remove discount', 'invoicing') . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> ';
1077 1077
         
1078 1078
         $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">';
1079 1079
         ob_start();
1080
-        do_action( 'wpinv_checkout_table_discount_first', $items );
1080
+        do_action('wpinv_checkout_table_discount_first', $items);
1081 1081
         $html .= ob_get_clean();
1082
-        $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label( $discount, $rate, false ) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">&ndash;' . wpinv_price( wpinv_format_amount( $amount ) ) . '</span></td>';
1082
+        $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label($discount, $rate, false) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">&ndash;' . wpinv_price(wpinv_format_amount($amount)) . '</span></td>';
1083 1083
         ob_start();
1084
-        do_action( 'wpinv_checkout_table_discount_last', $items );
1084
+        do_action('wpinv_checkout_table_discount_last', $items);
1085 1085
         $html .= ob_get_clean();
1086 1086
         $html .= '</tr>';
1087 1087
     }
1088 1088
 
1089
-    return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate );
1089
+    return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate);
1090 1090
 }
1091 1091
 
1092
-function wpinv_display_cart_discount( $formatted = false, $echo = false ) {
1092
+function wpinv_display_cart_discount($formatted = false, $echo = false) {
1093 1093
     $discounts = wpinv_get_cart_discounts();
1094 1094
 
1095
-    if ( empty( $discounts ) ) {
1095
+    if (empty($discounts)) {
1096 1096
         return false;
1097 1097
     }
1098 1098
 
1099
-    $discount_id  = wpinv_get_discount_id_by_code( $discounts[0] );
1100
-    $amount       = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) );
1099
+    $discount_id  = wpinv_get_discount_id_by_code($discounts[0]);
1100
+    $amount       = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id));
1101 1101
 
1102
-    if ( $echo ) {
1102
+    if ($echo) {
1103 1103
         echo $amount;
1104 1104
     }
1105 1105
 
@@ -1107,133 +1107,133 @@  discard block
 block discarded – undo
1107 1107
 }
1108 1108
 
1109 1109
 function wpinv_remove_cart_discount() {
1110
-    if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) {
1110
+    if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) {
1111 1111
         return;
1112 1112
     }
1113 1113
 
1114
-    do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) );
1114
+    do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id']));
1115 1115
 
1116
-    wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) );
1116
+    wpinv_unset_cart_discount(urldecode($_GET['discount_code']));
1117 1117
 
1118
-    do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) );
1118
+    do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id']));
1119 1119
 
1120
-    wp_redirect( wpinv_get_checkout_uri() ); wpinv_die();
1120
+    wp_redirect(wpinv_get_checkout_uri()); wpinv_die();
1121 1121
 }
1122
-add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' );
1122
+add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount');
1123 1123
 
1124
-function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) {
1124
+function wpinv_maybe_remove_cart_discount($cart_key = 0) {
1125 1125
     $discounts = wpinv_get_cart_discounts();
1126 1126
 
1127
-    if ( !$discounts ) {
1127
+    if (!$discounts) {
1128 1128
         return;
1129 1129
     }
1130 1130
 
1131
-    foreach ( $discounts as $discount ) {
1132
-        if ( !wpinv_is_discount_valid( $discount ) ) {
1133
-            wpinv_unset_cart_discount( $discount );
1131
+    foreach ($discounts as $discount) {
1132
+        if (!wpinv_is_discount_valid($discount)) {
1133
+            wpinv_unset_cart_discount($discount);
1134 1134
         }
1135 1135
     }
1136 1136
 }
1137
-add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' );
1137
+add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount');
1138 1138
 
1139 1139
 function wpinv_multiple_discounts_allowed() {
1140
-    $ret = wpinv_get_option( 'allow_multiple_discounts', false );
1141
-    return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret );
1140
+    $ret = wpinv_get_option('allow_multiple_discounts', false);
1141
+    return (bool)apply_filters('wpinv_multiple_discounts_allowed', $ret);
1142 1142
 }
1143 1143
 
1144 1144
 function wpinv_listen_for_cart_discount() {
1145 1145
     global $wpi_session;
1146 1146
     
1147
-    if ( empty( $_REQUEST['discount'] ) || is_array( $_REQUEST['discount'] ) ) {
1147
+    if (empty($_REQUEST['discount']) || is_array($_REQUEST['discount'])) {
1148 1148
         return;
1149 1149
     }
1150 1150
 
1151
-    $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount'] );
1151
+    $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount']);
1152 1152
 
1153
-    $wpi_session->set( 'preset_discount', $code );
1153
+    $wpi_session->set('preset_discount', $code);
1154 1154
 }
1155 1155
 //add_action( 'init', 'wpinv_listen_for_cart_discount', 0 );
1156 1156
 
1157 1157
 function wpinv_apply_preset_discount() {
1158 1158
     global $wpi_session;
1159 1159
     
1160
-    $code = $wpi_session->get( 'preset_discount' );
1160
+    $code = $wpi_session->get('preset_discount');
1161 1161
 
1162
-    if ( !$code ) {
1162
+    if (!$code) {
1163 1163
         return;
1164 1164
     }
1165 1165
 
1166
-    if ( !wpinv_is_discount_valid( $code, '', false ) ) {
1166
+    if (!wpinv_is_discount_valid($code, '', false)) {
1167 1167
         return;
1168 1168
     }
1169 1169
     
1170
-    $code = apply_filters( 'wpinv_apply_preset_discount', $code );
1170
+    $code = apply_filters('wpinv_apply_preset_discount', $code);
1171 1171
 
1172
-    wpinv_set_cart_discount( $code );
1172
+    wpinv_set_cart_discount($code);
1173 1173
 
1174
-    $wpi_session->set( 'preset_discount', null );
1174
+    $wpi_session->set('preset_discount', null);
1175 1175
 }
1176 1176
 //add_action( 'init', 'wpinv_apply_preset_discount', 999 );
1177 1177
 
1178
-function wpinv_get_discount_label( $code, $echo = true ) {
1179
-    $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) );
1180
-    $label = apply_filters( 'wpinv_get_discount_label', $label, $code );
1178
+function wpinv_get_discount_label($code, $echo = true) {
1179
+    $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : ''));
1180
+    $label = apply_filters('wpinv_get_discount_label', $label, $code);
1181 1181
 
1182
-    if ( $echo ) {
1182
+    if ($echo) {
1183 1183
         echo $label;
1184 1184
     } else {
1185 1185
         return $label;
1186 1186
     }
1187 1187
 }
1188 1188
 
1189
-function wpinv_cart_discount_label( $code, $rate, $echo = true ) {
1190
-    $label = wp_sprintf( __( '%1$s Discount: %2$s', 'invoicing' ), $rate, $code );
1191
-    $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate );
1189
+function wpinv_cart_discount_label($code, $rate, $echo = true) {
1190
+    $label = wp_sprintf(__('%1$s Discount: %2$s', 'invoicing'), $rate, $code);
1191
+    $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate);
1192 1192
 
1193
-    if ( $echo ) {
1193
+    if ($echo) {
1194 1194
         echo $label;
1195 1195
     } else {
1196 1196
         return $label;
1197 1197
     }
1198 1198
 }
1199 1199
 
1200
-function wpinv_check_delete_discount( $check, $post, $force_delete ) {
1201
-    if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) {
1200
+function wpinv_check_delete_discount($check, $post, $force_delete) {
1201
+    if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) {
1202 1202
         return true;
1203 1203
     }
1204 1204
     
1205 1205
     return $check;
1206 1206
 }
1207
-add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 );
1207
+add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3);
1208 1208
 
1209 1209
 function wpinv_checkout_form_validate_discounts() {
1210 1210
     $discounts = wpinv_get_cart_discounts();
1211 1211
     
1212
-    if ( !empty( $discounts ) ) {
1212
+    if (!empty($discounts)) {
1213 1213
         $invalid = false;
1214 1214
         
1215
-        foreach ( $discounts as $key => $code ) {
1216
-            if ( !wpinv_is_discount_valid( $code, get_current_user_id() ) ) {
1215
+        foreach ($discounts as $key => $code) {
1216
+            if (!wpinv_is_discount_valid($code, get_current_user_id())) {
1217 1217
                 $invalid = true;
1218 1218
                 
1219
-                wpinv_unset_cart_discount( $code );
1219
+                wpinv_unset_cart_discount($code);
1220 1220
             }
1221 1221
         }
1222 1222
         
1223
-        if ( $invalid ) {
1223
+        if ($invalid) {
1224 1224
             $errors = wpinv_get_errors();
1225
-            $error  = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : '';
1226
-            $error  .= __( 'The discount has been removed from cart.', 'invoicing' );
1227
-            wpinv_set_error( 'wpinv-discount-error', $error );
1225
+            $error  = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : '';
1226
+            $error .= __('The discount has been removed from cart.', 'invoicing');
1227
+            wpinv_set_error('wpinv-discount-error', $error);
1228 1228
             
1229
-            wpinv_recalculate_tax( true );
1229
+            wpinv_recalculate_tax(true);
1230 1230
         }
1231 1231
     }
1232 1232
 }
1233
-add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 );
1233
+add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10);
1234 1234
 
1235 1235
 function wpinv_discount_amount() {
1236 1236
     $output = 0.00;
1237 1237
     
1238
-    return apply_filters( 'wpinv_discount_amount', $output );
1238
+    return apply_filters('wpinv_discount_amount', $output);
1239 1239
 }
1240 1240
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Spacing   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 class WPInv_Plugin {
15 15
     private static $instance;
16 16
     
17 17
     public static function run() {
18
-        if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) {
18
+        if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) {
19 19
             self::$instance = new WPInv_Plugin;
20 20
             self::$instance->includes();
21 21
             self::$instance->actions();
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
             self::$instance->reports    = new WPInv_Reports();
24 24
         }
25 25
         
26
-        do_action( 'wpinv_loaded' );
26
+        do_action('wpinv_loaded');
27 27
         
28 28
         return self::$instance;
29 29
     }
@@ -33,31 +33,31 @@  discard block
 block discarded – undo
33 33
     }
34 34
     
35 35
     public function define_constants() {
36
-        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
37
-        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
36
+        define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
37
+        define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
38 38
     }
39 39
     
40 40
     private function actions() {
41 41
         /* Internationalize the text strings used. */
42
-        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
42
+        add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
43 43
         
44 44
         /* Perform actions on admin initialization. */
45
-        add_action( 'admin_init', array( &$this, 'admin_init') );
46
-        add_action( 'init', array( &$this, 'init' ), 3 );
47
-        add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) );
48
-        add_action( 'init', array( &$this, 'wpinv_actions' ) );
45
+        add_action('admin_init', array(&$this, 'admin_init'));
46
+        add_action('init', array(&$this, 'init'), 3);
47
+        add_action('init', array('WPInv_Shortcodes', 'init'));
48
+        add_action('init', array(&$this, 'wpinv_actions'));
49 49
         
50
-        if ( class_exists( 'BuddyPress' ) ) {
51
-            add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
50
+        if (class_exists('BuddyPress')) {
51
+            add_action('bp_include', array(&$this, 'bp_invoicing_init'));
52 52
         }
53 53
 
54
-        add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
54
+        add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts'));
55 55
         
56
-        if ( is_admin() ) {
57
-            add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
58
-            add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) );
56
+        if (is_admin()) {
57
+            add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
58
+            add_action('admin_body_class', array(&$this, 'admin_body_class'));
59 59
         } else {
60
-            add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
60
+            add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
61 61
         }
62 62
         
63 63
         /**
@@ -67,9 +67,9 @@  discard block
 block discarded – undo
67 67
          *
68 68
          * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference.
69 69
          */
70
-        do_action_ref_array( 'wpinv_actions', array( &$this ) );
70
+        do_action_ref_array('wpinv_actions', array(&$this));
71 71
 
72
-        add_action( 'admin_init', array( &$this, 'activation_redirect') );
72
+        add_action('admin_init', array(&$this, 'activation_redirect'));
73 73
     }
74 74
     
75 75
     public function plugins_loaded() {
@@ -83,189 +83,189 @@  discard block
 block discarded – undo
83 83
      * @since 1.0
84 84
      */
85 85
     public function load_textdomain() {
86
-        $locale = apply_filters( 'plugin_locale', get_locale(), 'invoicing' );
86
+        $locale = apply_filters('plugin_locale', get_locale(), 'invoicing');
87 87
         
88
-        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
89
-        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
88
+        load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo');
89
+        load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages');
90 90
         
91 91
         /**
92 92
          * Define language constants.
93 93
          */
94
-        require_once( WPINV_PLUGIN_DIR . 'language.php' );
94
+        require_once(WPINV_PLUGIN_DIR . 'language.php');
95 95
     }
96 96
         
97 97
     public function includes() {
98 98
         global $wpinv_options;
99 99
         
100
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
100
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php');
101 101
         $wpinv_options = wpinv_get_settings();
102 102
         
103
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' );
104
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
105
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
106
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
107
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
108
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
109
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
110
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' );
111
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
112
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
113
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
114
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
115
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
116
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php' );
117
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' );
118
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' );
119
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' );
120
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' );
121
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' );
122
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
123
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
124
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
125
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' );
126
-        if ( !class_exists( 'Geodir_EUVat' ) ) {
127
-            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
103
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php');
104
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php');
105
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php');
106
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php');
107
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php');
108
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php');
109
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php');
110
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php');
111
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php');
112
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php');
113
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php');
114
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php');
115
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php');
116
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php');
117
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php');
118
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php');
119
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php');
120
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php');
121
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php');
122
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php');
123
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php');
124
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php');
125
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php');
126
+        if (!class_exists('Geodir_EUVat')) {
127
+            require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php');
128 128
         }
129 129
         
130
-        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
131
-        if ( !empty( $gateways ) ) {
132
-            foreach ( $gateways as $gateway ) {
133
-                if ( $gateway == 'manual' ) {
130
+        $gateways = array_keys(wpinv_get_enabled_payment_gateways());
131
+        if (!empty($gateways)) {
132
+            foreach ($gateways as $gateway) {
133
+                if ($gateway == 'manual') {
134 134
                     continue;
135 135
                 }
136 136
                 
137 137
                 $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
138 138
                 
139
-                if ( file_exists( $gateway_file ) ) {
140
-                    require_once( $gateway_file );
139
+                if (file_exists($gateway_file)) {
140
+                    require_once($gateway_file);
141 141
                 }
142 142
             }
143 143
         }
144
-        require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' );
145
-        
146
-        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
147
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
148
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
149
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' );
150
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' );
151
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' );
152
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
153
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' );
154
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
144
+        require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php');
145
+        
146
+        if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
147
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php');
148
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php');
149
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php');
150
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php');
151
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php');
152
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php');
153
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php');
154
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php');
155 155
             
156 156
         }
157 157
         
158 158
         // include css inliner
159
-        if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
160
-            include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
159
+        if (!class_exists('Emogrifier') && class_exists('DOMDocument')) {
160
+            include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php');
161 161
         }
162 162
         
163
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
163
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php');
164 164
     }
165 165
     
166 166
     public function init() {
167 167
     }
168 168
     
169 169
     public function admin_init() {
170
-        if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
170
+        if (!(defined('DOING_AJAX') && DOING_AJAX)) {
171 171
         }
172 172
         
173
-        add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) );
173
+        add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php'));
174 174
     }
175 175
 
176 176
     public function activation_redirect() {
177 177
         // Bail if no activation redirect
178
-        if ( !get_transient( '_wpinv_activation_redirect' ) ) {
178
+        if (!get_transient('_wpinv_activation_redirect')) {
179 179
             return;
180 180
         }
181 181
 
182 182
         // Delete the redirect transient
183
-        delete_transient( '_wpinv_activation_redirect' );
183
+        delete_transient('_wpinv_activation_redirect');
184 184
 
185 185
         // Bail if activating from network, or bulk
186
-        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
186
+        if (is_network_admin() || isset($_GET['activate-multi'])) {
187 187
             return;
188 188
         }
189 189
 
190
-        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
190
+        wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
191 191
         exit;
192 192
     }
193 193
     
194 194
     public function enqueue_scripts() {
195
-        $suffix       = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
195
+        $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
196 196
         
197
-        wp_deregister_style( 'font-awesome' );
198
-        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
199
-        wp_enqueue_style( 'font-awesome' );
197
+        wp_deregister_style('font-awesome');
198
+        wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0');
199
+        wp_enqueue_style('font-awesome');
200 200
         
201
-        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION );
202
-        wp_enqueue_style( 'wpinv_front_style' );
201
+        wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION);
202
+        wp_enqueue_style('wpinv_front_style');
203 203
                
204 204
         // Register scripts
205
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
206
-        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array( 'jquery', 'wpinv-vat-script' ),  WPINV_VERSION );
205
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
206
+        wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array('jquery', 'wpinv-vat-script'), WPINV_VERSION);
207 207
         
208 208
         $localize                         = array();
209
-        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
210
-        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
209
+        $localize['ajax_url']             = admin_url('admin-ajax.php');
210
+        $localize['nonce']                = wp_create_nonce('wpinv-nonce');
211 211
         $localize['currency_symbol']      = wpinv_currency_symbol();
212 212
         $localize['currency_pos']         = wpinv_currency_position();
213 213
         $localize['thousand_sep']         = wpinv_thousands_separator();
214 214
         $localize['decimal_sep']          = wpinv_decimal_separator();
215 215
         $localize['decimals']             = wpinv_decimals();
216 216
         
217
-        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
217
+        $localize = apply_filters('wpinv_front_js_localize', $localize);
218 218
         
219
-        wp_enqueue_script( 'jquery-blockui' );
220
-        wp_enqueue_script( 'wpinv-front-script' );
221
-        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
219
+        wp_enqueue_script('jquery-blockui');
220
+        wp_enqueue_script('wpinv-front-script');
221
+        wp_localize_script('wpinv-front-script', 'WPInv', $localize);
222 222
     }
223 223
     
224 224
     public function admin_enqueue_scripts() {
225 225
         global $post, $pagenow;
226 226
         
227 227
         $post_type  = wpinv_admin_post_type();
228
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
228
+        $suffix     = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
229 229
         
230
-        wp_deregister_style( 'font-awesome' );
231
-        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
232
-        wp_enqueue_style( 'font-awesome' );
230
+        wp_deregister_style('font-awesome');
231
+        wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0');
232
+        wp_enqueue_style('font-awesome');
233 233
         
234
-        wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
235
-        wp_enqueue_style( 'jquery-ui-css' );
234
+        wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16');
235
+        wp_enqueue_style('jquery-ui-css');
236 236
         
237
-        wp_register_style( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2' );
238
-        wp_enqueue_style( 'jquery-chosen' );
237
+        wp_register_style('jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2');
238
+        wp_enqueue_style('jquery-chosen');
239 239
 
240
-        wp_register_script( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.6.2' );
241
-        wp_enqueue_script( 'jquery-chosen' );
240
+        wp_register_script('jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array('jquery'), '1.6.2');
241
+        wp_enqueue_script('jquery-chosen');
242 242
         
243
-        wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
244
-        wp_enqueue_style( 'wpinv_meta_box_style' );
243
+        wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
244
+        wp_enqueue_style('wpinv_meta_box_style');
245 245
         
246
-        wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION );
247
-        wp_enqueue_style( 'wpinv_admin_style' );
246
+        wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION);
247
+        wp_enqueue_style('wpinv_admin_style');
248 248
         
249
-        if ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
250
-            wp_enqueue_script( 'jquery-ui-datepicker' );
249
+        if ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
250
+            wp_enqueue_script('jquery-ui-datepicker');
251 251
         }
252 252
 
253
-        wp_enqueue_style( 'wp-color-picker' );
254
-        wp_enqueue_script( 'wp-color-picker' );
253
+        wp_enqueue_style('wp-color-picker');
254
+        wp_enqueue_script('wp-color-picker');
255 255
         
256
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
256
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
257 257
         
258
-        wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui' ),  WPINV_VERSION );
259
-        wp_enqueue_script( 'wpinv-admin-script' );
258
+        wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui'), WPINV_VERSION);
259
+        wp_enqueue_script('wpinv-admin-script');
260 260
         
261 261
         $localize                               = array();
262
-        $localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
263
-        $localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
264
-        $localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
265
-        $localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
266
-        $localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
267
-        $localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
268
-        $localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
262
+        $localize['ajax_url']                   = admin_url('admin-ajax.php');
263
+        $localize['post_ID']                    = isset($post->ID) ? $post->ID : '';
264
+        $localize['wpinv_nonce']                = wp_create_nonce('wpinv-nonce');
265
+        $localize['add_invoice_note_nonce']     = wp_create_nonce('add-invoice-note');
266
+        $localize['delete_invoice_note_nonce']  = wp_create_nonce('delete-invoice-note');
267
+        $localize['invoice_item_nonce']         = wp_create_nonce('invoice-item');
268
+        $localize['billing_details_nonce']      = wp_create_nonce('get-billing-details');
269 269
         $localize['tax']                        = wpinv_tax_amount();
270 270
         $localize['discount']                   = wpinv_discount_amount();
271 271
         $localize['currency_symbol']            = wpinv_currency_symbol();
@@ -273,55 +273,55 @@  discard block
 block discarded – undo
273 273
         $localize['thousand_sep']               = wpinv_thousands_separator();
274 274
         $localize['decimal_sep']                = wpinv_decimal_separator();
275 275
         $localize['decimals']                   = wpinv_decimals();
276
-        $localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
277
-        $localize['status_publish']             = wpinv_status_nicename( 'publish' );
278
-        $localize['status_pending']             = wpinv_status_nicename( 'pending' );
279
-        $localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
280
-        $localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
281
-        $localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
282
-        $localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
283
-        $localize['confirmCalcTotals']          = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' );
284
-        $localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
285
-        $localize['hasGD']                      = wpinv_gd_active();;
276
+        $localize['save_invoice']               = __('Save Invoice', 'invoicing');
277
+        $localize['status_publish']             = wpinv_status_nicename('publish');
278
+        $localize['status_pending']             = wpinv_status_nicename('pending');
279
+        $localize['delete_tax_rate']            = __('Are you sure you wish to delete this tax rate?', 'invoicing');
280
+        $localize['OneItemMin']                 = __('Invoice must contain at least one item', 'invoicing');
281
+        $localize['DeleteInvoiceItem']          = __('Are you sure you wish to delete this item?', 'invoicing');
282
+        $localize['FillBillingDetails']         = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing');
283
+        $localize['confirmCalcTotals']          = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing');
284
+        $localize['AreYouSure']                 = __('Are you sure?', 'invoicing');
285
+        $localize['hasGD']                      = wpinv_gd_active(); ;
286 286
         $localize['hasPM']                      = wpinv_pm_active();
287
-        $localize['emptyInvoice']               = __( 'Add atleast one item to save invoice!', 'invoicing' );
288
-        $localize['deletePackage']              = __( 'GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing' );
289
-        $localize['deletePackages']             = __( 'GD package items should be deleted from GD payment manager only', 'invoicing' );
290
-        $localize['deleteInvoiceFirst']         = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
287
+        $localize['emptyInvoice']               = __('Add atleast one item to save invoice!', 'invoicing');
288
+        $localize['deletePackage']              = __('GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing');
289
+        $localize['deletePackages']             = __('GD package items should be deleted from GD payment manager only', 'invoicing');
290
+        $localize['deleteInvoiceFirst']         = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing');
291 291
         
292
-        wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
292
+        wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize);
293 293
     }
294 294
     
295
-    public function admin_body_class( $classes ) {
295
+    public function admin_body_class($classes) {
296 296
         global $pagenow;
297 297
         
298
-        $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
298
+        $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
299 299
 
300 300
         $add_class = false;
301
-        if ( $pagenow == 'admin.php' && $page ) {
302
-            $add_class = strpos( $page, 'wpinv-' );
301
+        if ($pagenow == 'admin.php' && $page) {
302
+            $add_class = strpos($page, 'wpinv-');
303 303
         }
304 304
         
305 305
         $settings_class = array();
306
-        if ( $page == 'wpinv-settings' ) {
307
-            if ( !empty( $_REQUEST['tab'] ) ) {
308
-                $settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
306
+        if ($page == 'wpinv-settings') {
307
+            if (!empty($_REQUEST['tab'])) {
308
+                $settings_class[] = sanitize_text_field($_REQUEST['tab']);
309 309
             }
310 310
             
311
-            if ( !empty( $_REQUEST['section'] ) ) {
312
-                $settings_class[] = sanitize_text_field( $_REQUEST['section'] );
311
+            if (!empty($_REQUEST['section'])) {
312
+                $settings_class[] = sanitize_text_field($_REQUEST['section']);
313 313
             }
314 314
             
315
-            $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
315
+            $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main';
316 316
         }
317 317
         
318
-        if ( !empty( $settings_class ) ) {
319
-            $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
318
+        if (!empty($settings_class)) {
319
+            $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-'));
320 320
         }
321 321
         
322 322
         $post_type = wpinv_admin_post_type();
323 323
         
324
-        if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
324
+        if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) {
325 325
             return $classes .= ' wpinv';
326 326
         } else {
327 327
             return $classes;
@@ -333,26 +333,26 @@  discard block
 block discarded – undo
333 333
     public function admin_print_scripts_edit_php() {
334 334
         $post_type = wpinv_admin_post_type();
335 335
         
336
-        if ( $post_type == 'wpi_item' ) {
337
-            wp_enqueue_script( 'wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array( 'jquery', 'inline-edit-post' ), '', true );
336
+        if ($post_type == 'wpi_item') {
337
+            wp_enqueue_script('wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array('jquery', 'inline-edit-post'), '', true);
338 338
         }
339 339
     }
340 340
     
341 341
     public function wpinv_actions() {
342
-        if ( isset( $_REQUEST['wpi_action'] ) ) {
343
-            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
342
+        if (isset($_REQUEST['wpi_action'])) {
343
+            do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
344 344
         }
345 345
     }
346 346
     
347
-    public function pre_get_posts( $wp_query ) {
348
-        if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
349
-            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
347
+    public function pre_get_posts($wp_query) {
348
+        if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) {
349
+            $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses());
350 350
         }
351 351
         
352 352
         return $wp_query;
353 353
     }
354 354
     
355 355
     public function bp_invoicing_init() {
356
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
356
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php');
357 357
     }
358 358
 }
359 359
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-invoice-functions.php 1 patch
Spacing   +470 added lines, -470 removed lines patch added patch discarded remove patch
@@ -7,440 +7,440 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_get_invoice_cart_id() {
15 15
     $wpinv_checkout = wpinv_get_checkout_session();
16 16
     
17
-    if ( !empty( $wpinv_checkout['invoice_id'] ) ) {
17
+    if (!empty($wpinv_checkout['invoice_id'])) {
18 18
         return $wpinv_checkout['invoice_id'];
19 19
     }
20 20
     
21 21
     return NULL;
22 22
 }
23 23
 
24
-function wpinv_get_invoice( $invoice_id = 0, $cart = false ) {
25
-    if ( $cart && empty( $invoice_id ) ) {
24
+function wpinv_get_invoice($invoice_id = 0, $cart = false) {
25
+    if ($cart && empty($invoice_id)) {
26 26
         $invoice_id = (int)wpinv_get_invoice_cart_id();
27 27
     }
28 28
 
29
-    $invoice = new WPInv_Invoice( $invoice_id );
29
+    $invoice = new WPInv_Invoice($invoice_id);
30 30
     return $invoice;
31 31
 }
32 32
 
33
-function wpinv_get_invoice_cart( $invoice_id = 0 ) {
34
-    return wpinv_get_invoice( $invoice_id, true );
33
+function wpinv_get_invoice_cart($invoice_id = 0) {
34
+    return wpinv_get_invoice($invoice_id, true);
35 35
 }
36 36
 
37
-function wpinv_get_invoice_description( $invoice_id = 0 ) {
38
-    $invoice = new WPInv_Invoice( $invoice_id );
37
+function wpinv_get_invoice_description($invoice_id = 0) {
38
+    $invoice = new WPInv_Invoice($invoice_id);
39 39
     return $invoice->get_description();
40 40
 }
41 41
 
42
-function wpinv_get_invoice_currency_code( $invoice_id = 0 ) {
43
-    $invoice = new WPInv_Invoice( $invoice_id );
42
+function wpinv_get_invoice_currency_code($invoice_id = 0) {
43
+    $invoice = new WPInv_Invoice($invoice_id);
44 44
     return $invoice->get_currency();
45 45
 }
46 46
 
47
-function wpinv_get_payment_user_email( $invoice_id ) {
48
-    $invoice = new WPInv_Invoice( $invoice_id );
47
+function wpinv_get_payment_user_email($invoice_id) {
48
+    $invoice = new WPInv_Invoice($invoice_id);
49 49
     return $invoice->get_email();
50 50
 }
51 51
 
52
-function wpinv_get_user_id( $invoice_id ) {
53
-    $invoice = new WPInv_Invoice( $invoice_id );
52
+function wpinv_get_user_id($invoice_id) {
53
+    $invoice = new WPInv_Invoice($invoice_id);
54 54
     return $invoice->get_user_id();
55 55
 }
56 56
 
57
-function wpinv_get_invoice_status( $invoice_id, $return_label = false ) {
58
-    $invoice = new WPInv_Invoice( $invoice_id );
57
+function wpinv_get_invoice_status($invoice_id, $return_label = false) {
58
+    $invoice = new WPInv_Invoice($invoice_id);
59 59
     
60
-    return $invoice->get_status( $return_label );
60
+    return $invoice->get_status($return_label);
61 61
 }
62 62
 
63
-function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) {
64
-    $invoice = new WPInv_Invoice( $invoice_id );
63
+function wpinv_get_payment_gateway($invoice_id, $return_label = false) {
64
+    $invoice = new WPInv_Invoice($invoice_id);
65 65
     
66
-    return $invoice->get_gateway( $return_label );
66
+    return $invoice->get_gateway($return_label);
67 67
 }
68 68
 
69
-function wpinv_get_payment_gateway_name( $invoice_id ) {
70
-    $invoice = new WPInv_Invoice( $invoice_id );
69
+function wpinv_get_payment_gateway_name($invoice_id) {
70
+    $invoice = new WPInv_Invoice($invoice_id);
71 71
     
72 72
     return $invoice->get_gateway_title();
73 73
 }
74 74
 
75
-function wpinv_get_payment_transaction_id( $invoice_id ) {
76
-    $invoice = new WPInv_Invoice( $invoice_id );
75
+function wpinv_get_payment_transaction_id($invoice_id) {
76
+    $invoice = new WPInv_Invoice($invoice_id);
77 77
     
78 78
     return $invoice->get_transaction_id();
79 79
 }
80 80
 
81
-function wpinv_get_id_by_transaction_id( $key ) {
81
+function wpinv_get_id_by_transaction_id($key) {
82 82
     global $wpdb;
83 83
 
84
-    $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) );
84
+    $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key));
85 85
 
86
-    if ( $invoice_id != NULL )
86
+    if ($invoice_id != NULL)
87 87
         return $invoice_id;
88 88
 
89 89
     return 0;
90 90
 }
91 91
 
92
-function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) {
93
-    $invoice = new WPInv_Invoice( $invoice_id );
92
+function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) {
93
+    $invoice = new WPInv_Invoice($invoice_id);
94 94
 
95
-    return $invoice->get_meta( $meta_key, $single );
95
+    return $invoice->get_meta($meta_key, $single);
96 96
 }
97 97
 
98
-function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) {
99
-    $invoice = new WPInv_Invoice( $invoice_id );
98
+function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') {
99
+    $invoice = new WPInv_Invoice($invoice_id);
100 100
     
101
-    return $invoice->update_meta( $meta_key, $meta_value, $prev_value );
101
+    return $invoice->update_meta($meta_key, $meta_value, $prev_value);
102 102
 }
103 103
 
104
-function wpinv_get_items( $invoice_id = 0 ) {
105
-    $invoice            = wpinv_get_invoice( $invoice_id );
104
+function wpinv_get_items($invoice_id = 0) {
105
+    $invoice            = wpinv_get_invoice($invoice_id);
106 106
     
107 107
     $items              = $invoice->get_items();
108 108
     $invoice_currency   = $invoice->get_currency();
109 109
 
110
-    if ( !empty( $items ) && is_array( $items ) ) {
111
-        foreach ( $items as $key => $item ) {
110
+    if (!empty($items) && is_array($items)) {
111
+        foreach ($items as $key => $item) {
112 112
             $items[$key]['currency'] = $invoice_currency;
113 113
 
114
-            if ( !isset( $cart_item['subtotal'] ) ) {
114
+            if (!isset($cart_item['subtotal'])) {
115 115
                 $items[$key]['subtotal'] = $items[$key]['amount'] * 1;
116 116
             }
117 117
         }
118 118
     }
119 119
 
120
-    return apply_filters( 'wpinv_get_items', $items, $invoice_id );
120
+    return apply_filters('wpinv_get_items', $items, $invoice_id);
121 121
 }
122 122
 
123
-function wpinv_get_fees( $invoice_id = 0 ) {
124
-    $invoice           = wpinv_get_invoice( $invoice_id );
123
+function wpinv_get_fees($invoice_id = 0) {
124
+    $invoice           = wpinv_get_invoice($invoice_id);
125 125
     $fees              = $invoice->get_fees();
126 126
 
127
-    return apply_filters( 'wpinv_get_fees', $fees, $invoice_id );
127
+    return apply_filters('wpinv_get_fees', $fees, $invoice_id);
128 128
 }
129 129
 
130
-function wpinv_get_invoice_ip( $invoice_id ) {
131
-    $invoice = new WPInv_Invoice( $invoice_id );
130
+function wpinv_get_invoice_ip($invoice_id) {
131
+    $invoice = new WPInv_Invoice($invoice_id);
132 132
     return $invoice->get_ip();
133 133
 }
134 134
 
135
-function wpinv_get_invoice_user_info( $invoice_id ) {
136
-    $invoice = new WPInv_Invoice( $invoice_id );
135
+function wpinv_get_invoice_user_info($invoice_id) {
136
+    $invoice = new WPInv_Invoice($invoice_id);
137 137
     return $invoice->get_user_info();
138 138
 }
139 139
 
140
-function wpinv_subtotal( $invoice_id = 0, $currency = false ) {
141
-    $invoice = new WPInv_Invoice( $invoice_id );
140
+function wpinv_subtotal($invoice_id = 0, $currency = false) {
141
+    $invoice = new WPInv_Invoice($invoice_id);
142 142
 
143
-    return $invoice->get_subtotal( $currency );
143
+    return $invoice->get_subtotal($currency);
144 144
 }
145 145
 
146
-function wpinv_tax( $invoice_id = 0, $currency = false ) {
147
-    $invoice = new WPInv_Invoice( $invoice_id );
146
+function wpinv_tax($invoice_id = 0, $currency = false) {
147
+    $invoice = new WPInv_Invoice($invoice_id);
148 148
 
149
-    return $invoice->get_tax( $currency );
149
+    return $invoice->get_tax($currency);
150 150
 }
151 151
 
152
-function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) {
153
-    $invoice = wpinv_get_invoice( $invoice_id );
152
+function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) {
153
+    $invoice = wpinv_get_invoice($invoice_id);
154 154
 
155
-    return $invoice->get_discount( $currency, $dash );
155
+    return $invoice->get_discount($currency, $dash);
156 156
 }
157 157
 
158
-function wpinv_discount_code( $invoice_id = 0 ) {
159
-    $invoice = new WPInv_Invoice( $invoice_id );
158
+function wpinv_discount_code($invoice_id = 0) {
159
+    $invoice = new WPInv_Invoice($invoice_id);
160 160
 
161 161
     return $invoice->get_discount_code();
162 162
 }
163 163
 
164
-function wpinv_payment_total( $invoice_id = 0, $currency = false ) {
165
-    $invoice = new WPInv_Invoice( $invoice_id );
164
+function wpinv_payment_total($invoice_id = 0, $currency = false) {
165
+    $invoice = new WPInv_Invoice($invoice_id);
166 166
 
167
-    return $invoice->get_total( $currency );
167
+    return $invoice->get_total($currency);
168 168
 }
169 169
 
170
-function wpinv_get_date_created( $invoice_id = 0 ) {
171
-    $invoice = new WPInv_Invoice( $invoice_id );
170
+function wpinv_get_date_created($invoice_id = 0) {
171
+    $invoice = new WPInv_Invoice($invoice_id);
172 172
     
173 173
     $date_created   = $invoice->get_created_date();
174
-    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ), strtotime( $date_created ) ) : '';
174
+    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format'), strtotime($date_created)) : '';
175 175
 
176 176
     return $date_created;
177 177
 }
178 178
 
179
-function wpinv_get_invoice_date( $invoice_id = 0, $format = '' ) {
180
-    $invoice = new WPInv_Invoice( $invoice_id );
179
+function wpinv_get_invoice_date($invoice_id = 0, $format = '') {
180
+    $invoice = new WPInv_Invoice($invoice_id);
181 181
     
182
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
182
+    $format         = !empty($format) ? $format : get_option('date_format');
183 183
     $date_completed = $invoice->get_completed_date();
184
-    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : '';
185
-    if ( $invoice_date == '' ) {
184
+    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : '';
185
+    if ($invoice_date == '') {
186 186
         $date_created   = $invoice->get_created_date();
187
-        $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : '';
187
+        $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : '';
188 188
     }
189 189
 
190 190
     return $invoice_date;
191 191
 }
192 192
 
193
-function wpinv_get_invoice_vat_number( $invoice_id = 0 ) {
194
-    $invoice = new WPInv_Invoice( $invoice_id );
193
+function wpinv_get_invoice_vat_number($invoice_id = 0) {
194
+    $invoice = new WPInv_Invoice($invoice_id);
195 195
     
196 196
     return $invoice->vat_number;
197 197
 }
198 198
 
199
-function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false ) {
200
-    $invoice = new WPInv_Invoice( $invoice_id );
199
+function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false) {
200
+    $invoice = new WPInv_Invoice($invoice_id);
201 201
 
202
-    return $invoice->add_note( $note, $user_type, $added_by_user );
202
+    return $invoice->add_note($note, $user_type, $added_by_user);
203 203
 }
204 204
 
205
-function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) {
205
+function wpinv_get_invoice_notes($invoice_id = 0, $type = '') {
206 206
     global $invoicing;
207 207
     
208
-    if ( empty( $invoice_id ) ) {
208
+    if (empty($invoice_id)) {
209 209
         return NULL;
210 210
     }
211 211
     
212
-    $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type );
212
+    $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type);
213 213
     
214
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type );
214
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type);
215 215
 }
216 216
 
217
-function wpinv_get_payment_key( $invoice_id = 0 ) {
218
-	$invoice = new WPInv_Invoice( $invoice_id );
217
+function wpinv_get_payment_key($invoice_id = 0) {
218
+	$invoice = new WPInv_Invoice($invoice_id);
219 219
     return $invoice->get_key();
220 220
 }
221 221
 
222
-function wpinv_get_invoice_number( $invoice_id = 0 ) {
223
-    $invoice = new WPInv_Invoice( $invoice_id );
222
+function wpinv_get_invoice_number($invoice_id = 0) {
223
+    $invoice = new WPInv_Invoice($invoice_id);
224 224
     return $invoice->get_number();
225 225
 }
226 226
 
227
-function wpinv_get_cart_discountable_subtotal( $code_id ) {
227
+function wpinv_get_cart_discountable_subtotal($code_id) {
228 228
     $cart_items = wpinv_get_cart_content_details();
229 229
     $items      = array();
230 230
 
231
-    $excluded_items = wpinv_get_discount_excluded_items( $code_id );
231
+    $excluded_items = wpinv_get_discount_excluded_items($code_id);
232 232
 
233
-    if( $cart_items ) {
233
+    if ($cart_items) {
234 234
 
235
-        foreach( $cart_items as $item ) {
235
+        foreach ($cart_items as $item) {
236 236
 
237
-            if( ! in_array( $item['id'], $excluded_items ) ) {
238
-                $items[] =  $item;
237
+            if (!in_array($item['id'], $excluded_items)) {
238
+                $items[] = $item;
239 239
             }
240 240
         }
241 241
     }
242 242
 
243
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
243
+    $subtotal = wpinv_get_cart_items_subtotal($items);
244 244
 
245
-    return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal );
245
+    return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal);
246 246
 }
247 247
 
248
-function wpinv_get_cart_items_subtotal( $items ) {
248
+function wpinv_get_cart_items_subtotal($items) {
249 249
     $subtotal = 0.00;
250 250
 
251
-    if ( is_array( $items ) && ! empty( $items ) ) {
252
-        $prices = wp_list_pluck( $items, 'subtotal' );
251
+    if (is_array($items) && !empty($items)) {
252
+        $prices = wp_list_pluck($items, 'subtotal');
253 253
 
254
-        if( is_array( $prices ) ) {
255
-            $subtotal = array_sum( $prices );
254
+        if (is_array($prices)) {
255
+            $subtotal = array_sum($prices);
256 256
         } else {
257 257
             $subtotal = 0.00;
258 258
         }
259 259
 
260
-        if( $subtotal < 0 ) {
260
+        if ($subtotal < 0) {
261 261
             $subtotal = 0.00;
262 262
         }
263 263
     }
264 264
 
265
-    return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal );
265
+    return apply_filters('wpinv_get_cart_items_subtotal', $subtotal);
266 266
 }
267 267
 
268
-function wpinv_get_cart_subtotal( $items = array() ) {
269
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
270
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
268
+function wpinv_get_cart_subtotal($items = array()) {
269
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
270
+    $subtotal = wpinv_get_cart_items_subtotal($items);
271 271
 
272
-    return apply_filters( 'wpinv_get_cart_subtotal', $subtotal );
272
+    return apply_filters('wpinv_get_cart_subtotal', $subtotal);
273 273
 }
274 274
 
275
-function wpinv_cart_subtotal( $items = array() ) {
276
-    $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ) );
275
+function wpinv_cart_subtotal($items = array()) {
276
+    $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items)));
277 277
 
278 278
     // Todo - Show tax labels here (if needed)
279 279
 
280 280
     return $price;
281 281
 }
282 282
 
283
-function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) {
284
-    $subtotal  = (float)wpinv_get_cart_subtotal( $items );
285
-    $discounts = (float)wpinv_get_cart_discounted_amount( $items );
286
-    $cart_tax  = (float)wpinv_get_cart_tax( $items );
283
+function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) {
284
+    $subtotal  = (float)wpinv_get_cart_subtotal($items);
285
+    $discounts = (float)wpinv_get_cart_discounted_amount($items);
286
+    $cart_tax  = (float)wpinv_get_cart_tax($items);
287 287
     $fees      = (float)wpinv_get_cart_fee_total();
288
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
288
+    if (!empty($invoice) && $invoice->is_free_trial()) {
289 289
         $total = 0;
290 290
     } else {
291
-        $total     = $subtotal - $discounts + $cart_tax + $fees;
291
+        $total = $subtotal - $discounts + $cart_tax + $fees;
292 292
     }
293 293
 
294
-    if ( $total < 0 ) {
294
+    if ($total < 0) {
295 295
         $total = 0.00;
296 296
     }
297 297
     
298
-    $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items );
298
+    $total = (float)apply_filters('wpinv_get_cart_total', $total, $items);
299 299
 
300
-    return wpinv_sanitize_amount( $total );
300
+    return wpinv_sanitize_amount($total);
301 301
 }
302 302
 
303
-function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) {
303
+function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) {
304 304
     global $cart_total;
305
-    $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ) );
306
-    $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice );
305
+    $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice)));
306
+    $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice);
307 307
 
308 308
     // Todo - Show tax labels here (if needed)
309 309
     
310 310
     $cart_total = $total;
311 311
 
312
-    if ( !$echo ) {
312
+    if (!$echo) {
313 313
         return $total;
314 314
     }
315 315
 
316 316
     echo $total;
317 317
 }
318 318
 
319
-function wpinv_get_cart_tax( $items = array() ) {
319
+function wpinv_get_cart_tax($items = array()) {
320 320
     $cart_tax = 0;
321
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
321
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
322 322
 
323
-    if ( $items ) {
324
-        $taxes = wp_list_pluck( $items, 'tax' );
323
+    if ($items) {
324
+        $taxes = wp_list_pluck($items, 'tax');
325 325
 
326
-        if( is_array( $taxes ) ) {
327
-            $cart_tax = array_sum( $taxes );
326
+        if (is_array($taxes)) {
327
+            $cart_tax = array_sum($taxes);
328 328
         }
329 329
     }
330 330
 
331 331
     $cart_tax += wpinv_get_cart_fee_tax();
332 332
 
333
-    return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) );
333
+    return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax));
334 334
 }
335 335
 
336
-function wpinv_cart_tax( $items = array(), $echo = false ) {
337
-    $cart_tax = wpinv_get_cart_tax( $items );
338
-    $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ) );
336
+function wpinv_cart_tax($items = array(), $echo = false) {
337
+    $cart_tax = wpinv_get_cart_tax($items);
338
+    $cart_tax = wpinv_price(wpinv_format_amount($cart_tax));
339 339
 
340
-    $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items );
340
+    $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items);
341 341
 
342
-    if ( !$echo ) {
342
+    if (!$echo) {
343 343
         return $tax;
344 344
     }
345 345
 
346 346
     echo $tax;
347 347
 }
348 348
 
349
-function wpinv_get_cart_discount_code( $items = array() ) {
349
+function wpinv_get_cart_discount_code($items = array()) {
350 350
     $invoice = wpinv_get_invoice_cart();
351
-    $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : '';
351
+    $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : '';
352 352
     
353
-    return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code );
353
+    return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code);
354 354
 }
355 355
 
356
-function wpinv_cart_discount_code( $items = array(), $echo = false ) {
357
-    $cart_discount_code = wpinv_get_cart_discount_code( $items );
356
+function wpinv_cart_discount_code($items = array(), $echo = false) {
357
+    $cart_discount_code = wpinv_get_cart_discount_code($items);
358 358
 
359
-    if ( $cart_discount_code != '' ) {
359
+    if ($cart_discount_code != '') {
360 360
         $cart_discount_code = ' (' . $cart_discount_code . ')';
361 361
     }
362 362
     
363
-    $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items );
363
+    $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items);
364 364
 
365
-    if ( !$echo ) {
365
+    if (!$echo) {
366 366
         return $discount_code;
367 367
     }
368 368
 
369 369
     echo $discount_code;
370 370
 }
371 371
 
372
-function wpinv_get_cart_discount( $items = array() ) {
372
+function wpinv_get_cart_discount($items = array()) {
373 373
     $invoice = wpinv_get_invoice_cart();
374
-    $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0;
374
+    $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0;
375 375
     
376
-    return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items );
376
+    return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items);
377 377
 }
378 378
 
379
-function wpinv_cart_discount( $items = array(), $echo = false ) {
380
-    $cart_discount = wpinv_get_cart_discount( $items );
381
-    $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) );
379
+function wpinv_cart_discount($items = array(), $echo = false) {
380
+    $cart_discount = wpinv_get_cart_discount($items);
381
+    $cart_discount = wpinv_price(wpinv_format_amount($cart_discount));
382 382
 
383
-    $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items );
383
+    $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items);
384 384
 
385
-    if ( !$echo ) {
385
+    if (!$echo) {
386 386
         return $discount;
387 387
     }
388 388
 
389 389
     echo $discount;
390 390
 }
391 391
 
392
-function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) {
393
-    $item = new WPInv_Item( $item_id );
392
+function wpinv_get_cart_fees($type = 'all', $item_id = 0) {
393
+    $item = new WPInv_Item($item_id);
394 394
     
395
-    return $item->get_fees( $type, $item_id );
395
+    return $item->get_fees($type, $item_id);
396 396
 }
397 397
 
398 398
 function wpinv_get_cart_fee_total() {
399
-    $total  = 0;
399
+    $total = 0;
400 400
     $fees = wpinv_get_cart_fees();
401 401
     
402
-    if ( $fees ) {
403
-        foreach ( $fees as $fee_id => $fee ) {
402
+    if ($fees) {
403
+        foreach ($fees as $fee_id => $fee) {
404 404
             $total += $fee['amount'];
405 405
         }
406 406
     }
407 407
 
408
-    return apply_filters( 'wpinv_get_cart_fee_total', $total );
408
+    return apply_filters('wpinv_get_cart_fee_total', $total);
409 409
 }
410 410
 
411 411
 function wpinv_get_cart_fee_tax() {
412 412
     $tax  = 0;
413 413
     $fees = wpinv_get_cart_fees();
414 414
 
415
-    if ( $fees ) {
416
-        foreach ( $fees as $fee_id => $fee ) {
417
-            if( ! empty( $fee['no_tax'] ) ) {
415
+    if ($fees) {
416
+        foreach ($fees as $fee_id => $fee) {
417
+            if (!empty($fee['no_tax'])) {
418 418
                 continue;
419 419
             }
420 420
 
421
-            $tax += wpinv_calculate_tax( $fee['amount'] );
421
+            $tax += wpinv_calculate_tax($fee['amount']);
422 422
         }
423 423
     }
424 424
 
425
-    return apply_filters( 'wpinv_get_cart_fee_tax', $tax );
425
+    return apply_filters('wpinv_get_cart_fee_tax', $tax);
426 426
 }
427 427
 
428 428
 function wpinv_cart_has_recurring_item() {
429 429
     $cart_items = wpinv_get_cart_contents();
430 430
     
431
-    if ( empty( $cart_items ) ) {
431
+    if (empty($cart_items)) {
432 432
         return false;
433 433
     }
434 434
     
435 435
     $has_subscription = false;
436
-    foreach( $cart_items as $cart_item ) {
437
-        if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
436
+    foreach ($cart_items as $cart_item) {
437
+        if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
438 438
             $has_subscription = true;
439 439
             break;
440 440
         }
441 441
     }
442 442
     
443
-    return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items );
443
+    return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items);
444 444
 }
445 445
 
446 446
 function wpinv_cart_has_free_trial() {
@@ -448,85 +448,85 @@  discard block
 block discarded – undo
448 448
     
449 449
     $free_trial = false;
450 450
     
451
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
451
+    if (!empty($invoice) && $invoice->is_free_trial()) {
452 452
         $free_trial = true;
453 453
     }
454 454
     
455
-    return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice );
455
+    return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice);
456 456
 }
457 457
 
458 458
 function wpinv_get_cart_contents() {
459 459
     $cart_details = wpinv_get_cart_details();
460 460
     
461
-    return apply_filters( 'wpinv_get_cart_contents', $cart_details );
461
+    return apply_filters('wpinv_get_cart_contents', $cart_details);
462 462
 }
463 463
 
464 464
 function wpinv_get_cart_content_details() {
465 465
     global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
466 466
     $cart_items = wpinv_get_cart_contents();
467 467
     
468
-    if ( empty( $cart_items ) ) {
468
+    if (empty($cart_items)) {
469 469
         return false;
470 470
     }
471 471
     $invoice = wpinv_get_invoice_cart();
472 472
 
473 473
     $details = array();
474
-    $length  = count( $cart_items ) - 1;
474
+    $length  = count($cart_items) - 1;
475 475
     
476
-    if ( empty( $_POST['country'] ) ) {
476
+    if (empty($_POST['country'])) {
477 477
         $_POST['country'] = $invoice->country;
478 478
     }
479
-    if ( !isset( $_POST['state'] ) ) {
479
+    if (!isset($_POST['state'])) {
480 480
         $_POST['state'] = $invoice->state;
481 481
     }
482 482
 
483
-    foreach( $cart_items as $key => $item ) {
484
-        $item_id            = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '';
485
-        if ( empty( $item_id ) ) {
483
+    foreach ($cart_items as $key => $item) {
484
+        $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : '';
485
+        if (empty($item_id)) {
486 486
             continue;
487 487
         }
488 488
         
489 489
         $wpi_current_id         = $invoice->ID;
490 490
         $wpi_item_id            = $item_id;
491 491
         
492
-        $item_price         = wpinv_get_item_price( $item_id );
493
-        $discount           = wpinv_get_cart_item_discount_amount( $item );
494
-        $discount           = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item );
495
-        $quantity           = wpinv_get_cart_item_quantity( $item );
496
-        $fees               = wpinv_get_cart_fees( 'fee', $item_id );
492
+        $item_price         = wpinv_get_item_price($item_id);
493
+        $discount           = wpinv_get_cart_item_discount_amount($item);
494
+        $discount           = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item);
495
+        $quantity           = wpinv_get_cart_item_quantity($item);
496
+        $fees               = wpinv_get_cart_fees('fee', $item_id);
497 497
         
498 498
         $subtotal           = $item_price * $quantity;
499
-        $tax_rate           = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id );
500
-        $tax_class          = $wpinv_euvat->get_item_class( $item_id );
501
-        $tax                = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount );
499
+        $tax_rate           = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id);
500
+        $tax_class          = $wpinv_euvat->get_item_class($item_id);
501
+        $tax                = wpinv_get_cart_item_tax($item_id, $subtotal - $discount);
502 502
         
503
-        if ( wpinv_prices_include_tax() ) {
504
-            $subtotal -= wpinv_round_amount( $tax );
503
+        if (wpinv_prices_include_tax()) {
504
+            $subtotal -= wpinv_round_amount($tax);
505 505
         }
506 506
         
507
-        $total              = $subtotal - $discount + $tax;
507
+        $total = $subtotal - $discount + $tax;
508 508
         
509 509
         // Do not allow totals to go negatve
510
-        if( $total < 0 ) {
510
+        if ($total < 0) {
511 511
             $total = 0;
512 512
         }
513 513
         
514
-        $details[ $key ]  = array(
514
+        $details[$key] = array(
515 515
             'id'                => $item_id,
516
-            'name'              => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ),
517
-            'item_price'        => wpinv_round_amount( $item_price ),
516
+            'name'              => !empty($item['name']) ? $item['name'] : get_the_title($item_id),
517
+            'item_price'        => wpinv_round_amount($item_price),
518 518
             'quantity'          => $quantity,
519
-            'discount'          => wpinv_round_amount( $discount ),
520
-            'subtotal'          => wpinv_round_amount( $subtotal ),
521
-            'tax'               => wpinv_round_amount( $tax ),
522
-            'price'             => wpinv_round_amount( $total ),
519
+            'discount'          => wpinv_round_amount($discount),
520
+            'subtotal'          => wpinv_round_amount($subtotal),
521
+            'tax'               => wpinv_round_amount($tax),
522
+            'price'             => wpinv_round_amount($total),
523 523
             'vat_rates_class'   => $tax_class,
524
-            'vat_rate'          => wpinv_round_amount( $tax_rate ),
525
-            'meta'              => isset( $item['meta'] ) ? $item['meta'] : array(),
524
+            'vat_rate'          => wpinv_round_amount($tax_rate),
525
+            'meta'              => isset($item['meta']) ? $item['meta'] : array(),
526 526
             'fees'              => $fees,
527 527
         );
528 528
         
529
-        if ( $wpinv_is_last_cart_item ) {
529
+        if ($wpinv_is_last_cart_item) {
530 530
             $wpinv_is_last_cart_item   = false;
531 531
             $wpinv_flat_discount_total = 0.00;
532 532
         }
@@ -535,56 +535,56 @@  discard block
 block discarded – undo
535 535
     return $details;
536 536
 }
537 537
 
538
-function wpinv_get_cart_details( $invoice_id = 0 ) {
538
+function wpinv_get_cart_details($invoice_id = 0) {
539 539
     global $ajax_cart_details;
540 540
 
541
-    $invoice      = wpinv_get_invoice_cart( $invoice_id );
542
-    $cart_details = !empty( $ajax_cart_details ) ? $ajax_cart_details : $invoice->cart_details;
541
+    $invoice      = wpinv_get_invoice_cart($invoice_id);
542
+    $cart_details = !empty($ajax_cart_details) ? $ajax_cart_details : $invoice->cart_details;
543 543
 
544 544
     $invoice_currency = $invoice->currency;
545 545
 
546
-    if ( ! empty( $cart_details ) && is_array( $cart_details ) ) {
547
-        foreach ( $cart_details as $key => $cart_item ) {
548
-            $cart_details[ $key ]['currency'] = $invoice_currency;
546
+    if (!empty($cart_details) && is_array($cart_details)) {
547
+        foreach ($cart_details as $key => $cart_item) {
548
+            $cart_details[$key]['currency'] = $invoice_currency;
549 549
 
550
-            if ( ! isset( $cart_item['subtotal'] ) ) {
551
-                $cart_details[ $key ]['subtotal'] = $cart_item['price'];
550
+            if (!isset($cart_item['subtotal'])) {
551
+                $cart_details[$key]['subtotal'] = $cart_item['price'];
552 552
             }
553 553
         }
554 554
     }
555 555
 
556
-    return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id );
556
+    return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id);
557 557
 }
558 558
 
559
-function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) {
560
-    $invoice    = wpinv_get_invoice( $invoice_id );
559
+function wpinv_record_status_change($invoice_id, $new_status, $old_status) {
560
+    $invoice    = wpinv_get_invoice($invoice_id);
561 561
     
562
-    $old_status = wpinv_status_nicename( $old_status );
563
-    $new_status = wpinv_status_nicename( $new_status );
562
+    $old_status = wpinv_status_nicename($old_status);
563
+    $new_status = wpinv_status_nicename($new_status);
564 564
 
565
-    $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status );
565
+    $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status);
566 566
     
567 567
     // Add note
568
-    return $invoice->add_note( $status_change, 0 );
568
+    return $invoice->add_note($status_change, 0);
569 569
 }
570
-add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 );
570
+add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3);
571 571
 
572
-function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) {
572
+function wpinv_complete_payment($invoice_id, $new_status, $old_status) {
573 573
     global $wpi_has_free_trial;
574 574
     
575 575
     $wpi_has_free_trial = false;
576 576
     
577
-    if ( $old_status == 'publish' ) {
577
+    if ($old_status == 'publish') {
578 578
         return; // Make sure that payments are only paid once
579 579
     }
580 580
 
581 581
     // Make sure the payment completion is only processed when new status is paid
582
-    if ( $new_status != 'publish' ) {
582
+    if ($new_status != 'publish') {
583 583
         return;
584 584
     }
585 585
 
586
-    $invoice = new WPInv_Invoice( $invoice_id );
587
-    if ( empty( $invoice ) ) {
586
+    $invoice = new WPInv_Invoice($invoice_id);
587
+    if (empty($invoice)) {
588 588
         return;
589 589
     }
590 590
 
@@ -592,58 +592,58 @@  discard block
 block discarded – undo
592 592
     $completed_date = $invoice->completed_date;
593 593
     $cart_details   = $invoice->cart_details;
594 594
 
595
-    do_action( 'wpinv_pre_complete_payment', $invoice_id );
595
+    do_action('wpinv_pre_complete_payment', $invoice_id);
596 596
 
597
-    if ( is_array( $cart_details ) ) {
597
+    if (is_array($cart_details)) {
598 598
         // Increase purchase count and earnings
599
-        foreach ( $cart_details as $cart_index => $item ) {
599
+        foreach ($cart_details as $cart_index => $item) {
600 600
             // Ensure these actions only run once, ever
601
-            if ( empty( $completed_date ) ) {
602
-                do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index );
601
+            if (empty($completed_date)) {
602
+                do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index);
603 603
             }
604 604
         }
605 605
     }
606 606
     
607 607
     // Check for discount codes and increment their use counts
608
-    if ( $discounts = $invoice->get_discounts( true ) ) {
609
-        if( ! empty( $discounts ) ) {
610
-            foreach( $discounts as $code ) {
611
-                wpinv_increase_discount_usage( $code );
608
+    if ($discounts = $invoice->get_discounts(true)) {
609
+        if (!empty($discounts)) {
610
+            foreach ($discounts as $code) {
611
+                wpinv_increase_discount_usage($code);
612 612
             }
613 613
         }
614 614
     }
615 615
     
616 616
     // Ensure this action only runs once ever
617
-    if( empty( $completed_date ) ) {
617
+    if (empty($completed_date)) {
618 618
         // Save the completed date
619
-        $invoice->set( 'completed_date', current_time( 'mysql', 0 ) );
619
+        $invoice->set('completed_date', current_time('mysql', 0));
620 620
         $invoice->save();
621 621
 
622
-        do_action( 'wpinv_complete_payment', $invoice_id );
622
+        do_action('wpinv_complete_payment', $invoice_id);
623 623
     }
624 624
 
625 625
     // Empty the shopping cart
626 626
     wpinv_empty_cart();
627 627
 }
628
-add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 );
628
+add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3);
629 629
 
630
-function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) {    
631
-    $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id );
630
+function wpinv_update_payment_status($invoice_id, $new_status = 'publish') {    
631
+    $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int)$invoice_id);
632 632
     
633
-    if ( empty( $invoice ) ) {
633
+    if (empty($invoice)) {
634 634
         return false;
635 635
     }
636 636
     
637
-    return $invoice->update_status( $new_status );
637
+    return $invoice->update_status($new_status);
638 638
 }
639 639
 
640
-function wpinv_cart_has_fees( $type = 'all' ) {
640
+function wpinv_cart_has_fees($type = 'all') {
641 641
     return false;
642 642
 }
643 643
 
644 644
 function wpinv_validate_checkout_fields() {    
645 645
     // Check if there is $_POST
646
-    if ( empty( $_POST ) ) {
646
+    if (empty($_POST)) {
647 647
         return false;
648 648
     }
649 649
     
@@ -655,11 +655,11 @@  discard block
 block discarded – undo
655 655
     );
656 656
     
657 657
     // Validate agree to terms
658
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
658
+    if (wpinv_get_option('show_agree_to_terms', false)) {
659 659
         wpinv_checkout_validate_agree_to_terms();
660 660
     }
661 661
     
662
-    $valid_data['logged_in_user']   = wpinv_checkout_validate_logged_in_user();
662
+    $valid_data['logged_in_user'] = wpinv_checkout_validate_logged_in_user();
663 663
     
664 664
     // Return collected data
665 665
     return $valid_data;
@@ -670,26 +670,26 @@  discard block
 block discarded – undo
670 670
     
671 671
     $invoice = wpinv_get_invoice_cart();
672 672
     $has_subscription = $invoice->is_recurring();
673
-    if ( empty( $invoice ) ) {
674
-        wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) );
673
+    if (empty($invoice)) {
674
+        wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing'));
675 675
         return $gateway;
676 676
     }
677 677
 
678 678
     // Check if a gateway value is present
679
-    if ( !empty( $_REQUEST['wpi-gateway'] ) ) {
680
-        $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] );
679
+    if (!empty($_REQUEST['wpi-gateway'])) {
680
+        $gateway = sanitize_text_field($_REQUEST['wpi-gateway']);
681 681
 
682
-        if ( $invoice->is_free() ) {
682
+        if ($invoice->is_free()) {
683 683
             $gateway = 'manual';
684
-        } elseif ( !wpinv_is_gateway_active( $gateway ) ) {
685
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) );
686
-        } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) {
687
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) );
684
+        } elseif (!wpinv_is_gateway_active($gateway)) {
685
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing'));
686
+        } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) {
687
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing'));
688 688
         }
689 689
     }
690 690
 
691
-    if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) {
692
-        wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) );
691
+    if ($has_subscription && count(wpinv_get_cart_contents()) > 1) {
692
+        wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing'));
693 693
     }
694 694
 
695 695
     return $gateway;
@@ -701,10 +701,10 @@  discard block
 block discarded – undo
701 701
     
702 702
     $error = false;
703 703
     // If we have discounts, loop through them
704
-    if ( ! empty( $discounts ) ) {
705
-        foreach ( $discounts as $discount ) {
704
+    if (!empty($discounts)) {
705
+        foreach ($discounts as $discount) {
706 706
             // Check if valid
707
-            if (  !wpinv_is_discount_valid( $discount, get_current_user_id() ) ) {
707
+            if (!wpinv_is_discount_valid($discount, get_current_user_id())) {
708 708
                 // Discount is not valid
709 709
                 $error = true;
710 710
             }
@@ -714,20 +714,20 @@  discard block
 block discarded – undo
714 714
         return NULL;
715 715
     }
716 716
 
717
-    if ( $error && !wpinv_get_errors() ) {
718
-        wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) );
717
+    if ($error && !wpinv_get_errors()) {
718
+        wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing'));
719 719
     }
720 720
 
721
-    return implode( ',', $discounts );
721
+    return implode(',', $discounts);
722 722
 }
723 723
 
724 724
 function wpinv_checkout_validate_cc() {
725 725
     $card_data = wpinv_checkout_get_cc_info();
726 726
 
727 727
     // Validate the card zip
728
-    if ( !empty( $card_data['wpinv_zip'] ) ) {
729
-        if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) {
730
-            wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) );
728
+    if (!empty($card_data['wpinv_zip'])) {
729
+        if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) {
730
+            wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing'));
731 731
         }
732 732
     }
733 733
 
@@ -737,28 +737,28 @@  discard block
 block discarded – undo
737 737
 
738 738
 function wpinv_checkout_get_cc_info() {
739 739
 	$cc_info = array();
740
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
741
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
742
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
743
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
744
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
745
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
746
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
747
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
748
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
749
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
740
+	$cc_info['card_name']      = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : '';
741
+	$cc_info['card_number']    = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : '';
742
+	$cc_info['card_cvc']       = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : '';
743
+	$cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : '';
744
+	$cc_info['card_exp_year']  = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : '';
745
+	$cc_info['card_address']   = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : '';
746
+	$cc_info['card_city']      = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : '';
747
+	$cc_info['card_state']     = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : '';
748
+	$cc_info['card_country']   = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : '';
749
+	$cc_info['card_zip']       = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : '';
750 750
 
751 751
 	// Return cc info
752 752
 	return $cc_info;
753 753
 }
754 754
 
755
-function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
755
+function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') {
756 756
     $ret = false;
757 757
 
758
-    if ( empty( $zip ) || empty( $country_code ) )
758
+    if (empty($zip) || empty($country_code))
759 759
         return $ret;
760 760
 
761
-    $country_code = strtoupper( $country_code );
761
+    $country_code = strtoupper($country_code);
762 762
 
763 763
     $zip_regex = array(
764 764
         "AD" => "AD\d{3}",
@@ -918,17 +918,17 @@  discard block
 block discarded – undo
918 918
         "ZM" => "\d{5}"
919 919
     );
920 920
 
921
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
921
+    if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip))
922 922
         $ret = true;
923 923
 
924
-    return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
924
+    return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code);
925 925
 }
926 926
 
927 927
 function wpinv_checkout_validate_agree_to_terms() {
928 928
     // Validate agree to terms
929
-    if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) {
929
+    if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) {
930 930
         // User did not agree
931
-        wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) );
931
+        wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing')));
932 932
     }
933 933
 }
934 934
 
@@ -941,36 +941,36 @@  discard block
 block discarded – undo
941 941
     );
942 942
     
943 943
     // Verify there is a user_ID
944
-    if ( $user_ID > 0 ) {
944
+    if ($user_ID > 0) {
945 945
         // Get the logged in user data
946
-        $user_data = get_userdata( $user_ID );
947
-        $required_fields  = wpinv_checkout_required_fields();
946
+        $user_data = get_userdata($user_ID);
947
+        $required_fields = wpinv_checkout_required_fields();
948 948
 
949 949
         // Loop through required fields and show error messages
950
-         if ( !empty( $required_fields ) ) {
951
-            foreach ( $required_fields as $field_name => $value ) {
952
-                if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
953
-                    wpinv_set_error( $value['error_id'], $value['error_message'] );
950
+         if (!empty($required_fields)) {
951
+            foreach ($required_fields as $field_name => $value) {
952
+                if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) {
953
+                    wpinv_set_error($value['error_id'], $value['error_message']);
954 954
                 }
955 955
             }
956 956
         }
957 957
 
958 958
         // Verify data
959
-        if ( $user_data ) {
959
+        if ($user_data) {
960 960
             // Collected logged in user data
961 961
             $valid_user_data = array(
962 962
                 'user_id'     => $user_ID,
963
-                'email'       => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email,
964
-                'first_name'  => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name,
965
-                'last_name'   => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name']  ) ? sanitize_text_field( $_POST['wpinv_last_name']  ) : $user_data->last_name,
963
+                'email'       => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email,
964
+                'first_name'  => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name,
965
+                'last_name'   => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name,
966 966
             );
967 967
 
968
-            if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) {
969
-                wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) );
968
+            if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) {
969
+                wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing'));
970 970
             }
971 971
         } else {
972 972
             // Set invalid user error
973
-            wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) );
973
+            wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing'));
974 974
         }
975 975
     }
976 976
 
@@ -978,21 +978,21 @@  discard block
 block discarded – undo
978 978
     return $valid_user_data;
979 979
 }
980 980
 
981
-function wpinv_checkout_form_get_user( $valid_data = array() ) {
981
+function wpinv_checkout_form_get_user($valid_data = array()) {
982 982
     // Initialize user
983 983
     $user    = false;
984
-    $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
984
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
985 985
 
986 986
     /*if ( $is_ajax ) {
987 987
         // Do not create or login the user during the ajax submission (check for errors only)
988 988
         return true;
989
-    } else */if ( is_user_logged_in() ) {
989
+    } else */if (is_user_logged_in()) {
990 990
         // Set the valid user as the logged in collected data
991 991
         $user = $valid_data['logged_in_user'];
992 992
     }
993 993
 
994 994
     // Verify we have an user
995
-    if ( false === $user || empty( $user ) ) {
995
+    if (false === $user || empty($user)) {
996 996
         // Return false
997 997
         return false;
998 998
     }
@@ -1011,11 +1011,11 @@  discard block
 block discarded – undo
1011 1011
         'zip',
1012 1012
     );
1013 1013
     
1014
-    foreach ( $address_fields as $field ) {
1015
-        $user[$field]  = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false;
1014
+    foreach ($address_fields as $field) {
1015
+        $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false;
1016 1016
         
1017
-        if ( !empty( $user['user_id'] ) ) {
1018
-            update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] );
1017
+        if (!empty($user['user_id'])) {
1018
+            update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]);
1019 1019
         }
1020 1020
     }
1021 1021
 
@@ -1023,28 +1023,28 @@  discard block
 block discarded – undo
1023 1023
     return $user;
1024 1024
 }
1025 1025
 
1026
-function wpinv_set_checkout_session( $invoice_data = array() ) {
1026
+function wpinv_set_checkout_session($invoice_data = array()) {
1027 1027
     global $wpi_session;
1028 1028
     
1029
-    return $wpi_session->set( 'wpinv_checkout', $invoice_data );
1029
+    return $wpi_session->set('wpinv_checkout', $invoice_data);
1030 1030
 }
1031 1031
 
1032 1032
 function wpinv_get_checkout_session() {
1033 1033
 	global $wpi_session;
1034 1034
     
1035
-    return $wpi_session->get( 'wpinv_checkout' );
1035
+    return $wpi_session->get('wpinv_checkout');
1036 1036
 }
1037 1037
 
1038 1038
 function wpinv_empty_cart() {
1039 1039
     global $wpi_session;
1040 1040
 
1041 1041
     // Remove cart contents
1042
-    $wpi_session->set( 'wpinv_checkout', NULL );
1042
+    $wpi_session->set('wpinv_checkout', NULL);
1043 1043
 
1044 1044
     // Remove all cart fees
1045
-    $wpi_session->set( 'wpi_cart_fees', NULL );
1045
+    $wpi_session->set('wpi_cart_fees', NULL);
1046 1046
 
1047
-    do_action( 'wpinv_empty_cart' );
1047
+    do_action('wpinv_empty_cart');
1048 1048
 }
1049 1049
 
1050 1050
 function wpinv_process_checkout() {
@@ -1056,42 +1056,42 @@  discard block
 block discarded – undo
1056 1056
     
1057 1057
     $wpi_checkout_id = $invoice->ID;
1058 1058
     
1059
-    do_action( 'wpinv_pre_process_checkout' );
1059
+    do_action('wpinv_pre_process_checkout');
1060 1060
     
1061
-    if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty
1061
+    if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty
1062 1062
         $valid_data = false;
1063
-        wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) );
1063
+        wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing'));
1064 1064
     } else {
1065 1065
         // Validate the form $_POST data
1066 1066
         $valid_data = wpinv_validate_checkout_fields();
1067 1067
         
1068 1068
         // Allow themes and plugins to hook to errors
1069
-        do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST );
1069
+        do_action('wpinv_checkout_error_checks', $valid_data, $_POST);
1070 1070
     }
1071 1071
     
1072
-    $is_ajax    = defined( 'DOING_AJAX' ) && DOING_AJAX;
1072
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1073 1073
     
1074 1074
     // Validate the user
1075
-    $user = wpinv_checkout_form_get_user( $valid_data );
1075
+    $user = wpinv_checkout_form_get_user($valid_data);
1076 1076
 
1077 1077
     // Let extensions validate fields after user is logged in if user has used login/registration form
1078
-    do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST );
1078
+    do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST);
1079 1079
     
1080
-    if ( false === $valid_data || wpinv_get_errors() || ! $user ) {
1081
-        if ( $is_ajax ) {
1082
-            do_action( 'wpinv_ajax_checkout_errors' );
1080
+    if (false === $valid_data || wpinv_get_errors() || !$user) {
1081
+        if ($is_ajax) {
1082
+            do_action('wpinv_ajax_checkout_errors');
1083 1083
             die();
1084 1084
         } else {
1085 1085
             return false;
1086 1086
         }
1087 1087
     }
1088 1088
 
1089
-    if ( $is_ajax ) {
1089
+    if ($is_ajax) {
1090 1090
         // Save address fields.
1091
-        $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' );
1092
-        foreach ( $address_fields as $field ) {
1093
-            if ( isset( $user[$field] ) ) {
1094
-                $invoice->set( $field, $user[$field] );
1091
+        $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company');
1092
+        foreach ($address_fields as $field) {
1093
+            if (isset($user[$field])) {
1094
+                $invoice->set($field, $user[$field]);
1095 1095
             }
1096 1096
             
1097 1097
             $invoice->save();
@@ -1099,15 +1099,15 @@  discard block
 block discarded – undo
1099 1099
 
1100 1100
         $response['success']            = true;
1101 1101
         $response['data']['subtotal']   = $invoice->get_subtotal();
1102
-        $response['data']['subtotalf']  = $invoice->get_subtotal( true );
1102
+        $response['data']['subtotalf']  = $invoice->get_subtotal(true);
1103 1103
         $response['data']['discount']   = $invoice->get_discount();
1104
-        $response['data']['discountf']  = $invoice->get_discount( true );
1104
+        $response['data']['discountf']  = $invoice->get_discount(true);
1105 1105
         $response['data']['tax']        = $invoice->get_tax();
1106
-        $response['data']['taxf']       = $invoice->get_tax( true );
1106
+        $response['data']['taxf']       = $invoice->get_tax(true);
1107 1107
         $response['data']['total']      = $invoice->get_total();
1108
-        $response['data']['totalf']     = $invoice->get_total( true );
1108
+        $response['data']['totalf']     = $invoice->get_total(true);
1109 1109
         
1110
-        wp_send_json( $response );
1110
+        wp_send_json($response);
1111 1111
     }
1112 1112
     
1113 1113
     $user_info = array(
@@ -1129,42 +1129,42 @@  discard block
 block discarded – undo
1129 1129
     
1130 1130
     // Setup invoice information
1131 1131
     $invoice_data = array(
1132
-        'invoice_id'        => !empty( $invoice ) ? $invoice->ID : 0,
1132
+        'invoice_id'        => !empty($invoice) ? $invoice->ID : 0,
1133 1133
         'items'             => $cart_items,
1134 1134
         'cart_discounts'    => $discounts,
1135
-        'fees'              => wpinv_get_cart_fees(),        // Any arbitrary fees that have been added to the cart
1136
-        'subtotal'          => wpinv_get_cart_subtotal( $cart_items ),    // Amount before taxes and discounts
1137
-        'discount'          => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount
1138
-        'tax'               => wpinv_get_cart_tax( $cart_items ),               // Taxed amount
1139
-        'price'             => wpinv_get_cart_total( $cart_items, $discounts ),    // Amount after taxes
1135
+        'fees'              => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart
1136
+        'subtotal'          => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts
1137
+        'discount'          => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount
1138
+        'tax'               => wpinv_get_cart_tax($cart_items), // Taxed amount
1139
+        'price'             => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes
1140 1140
         'invoice_key'       => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(),
1141 1141
         'user_email'        => $user['email'],
1142
-        'date'              => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
1143
-        'user_info'         => stripslashes_deep( $user_info ),
1142
+        'date'              => date('Y-m-d H:i:s', current_time('timestamp')),
1143
+        'user_info'         => stripslashes_deep($user_info),
1144 1144
         'post_data'         => $_POST,
1145 1145
         'cart_details'      => $cart_items,
1146 1146
         'gateway'           => $valid_data['gateway'],
1147 1147
         'card_info'         => $valid_data['cc_info']
1148 1148
     );
1149 1149
     
1150
-    $vat_info   = $wpinv_euvat->current_vat_data();
1151
-    if ( is_array( $vat_info ) ) {
1150
+    $vat_info = $wpinv_euvat->current_vat_data();
1151
+    if (is_array($vat_info)) {
1152 1152
         $invoice_data['user_info']['vat_number']        = $vat_info['number'];
1153 1153
         $invoice_data['user_info']['vat_rate']          = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']);
1154
-        $invoice_data['user_info']['adddress_confirmed']    = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1154
+        $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1155 1155
 
1156 1156
         // Add the VAT rate to each item in the cart
1157
-        foreach( $invoice_data['cart_details'] as $key => $item_data) {
1157
+        foreach ($invoice_data['cart_details'] as $key => $item_data) {
1158 1158
             $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']);
1159
-            $invoice_data['cart_details'][$key]['vat_rate'] = round( $rate, 3 );
1159
+            $invoice_data['cart_details'][$key]['vat_rate'] = round($rate, 3);
1160 1160
         }
1161 1161
     }
1162 1162
     
1163 1163
     // Save vat fields.
1164
-    $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' );
1165
-    foreach ( $address_fields as $field ) {
1166
-        if ( isset( $invoice_data['user_info'][$field] ) ) {
1167
-            $invoice->set( $field, $invoice_data['user_info'][$field] );
1164
+    $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed');
1165
+    foreach ($address_fields as $field) {
1166
+        if (isset($invoice_data['user_info'][$field])) {
1167
+            $invoice->set($field, $invoice_data['user_info'][$field]);
1168 1168
         }
1169 1169
         
1170 1170
         $invoice->save();
@@ -1174,49 +1174,49 @@  discard block
 block discarded – undo
1174 1174
     $valid_data['user'] = $user;
1175 1175
     
1176 1176
     // Allow themes and plugins to hook before the gateway
1177
-    do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data );
1177
+    do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data);
1178 1178
     
1179 1179
     // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice
1180
-    if ( !$invoice_data['price'] ) {
1180
+    if (!$invoice_data['price']) {
1181 1181
         // Revert to manual
1182 1182
         $invoice_data['gateway'] = 'manual';
1183 1183
         $_POST['wpi-gateway'] = 'manual';
1184 1184
     }
1185 1185
     
1186 1186
     // Allow the invoice data to be modified before it is sent to the gateway
1187
-    $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data );
1187
+    $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data);
1188 1188
     
1189 1189
     // Setup the data we're storing in the purchase session
1190 1190
     $session_data = $invoice_data;
1191 1191
     // Make sure credit card numbers are never stored in sessions
1192
-    if ( !empty( $session_data['card_info']['card_number'] ) ) {
1193
-        unset( $session_data['card_info']['card_number'] );
1192
+    if (!empty($session_data['card_info']['card_number'])) {
1193
+        unset($session_data['card_info']['card_number']);
1194 1194
     }
1195 1195
     
1196 1196
     // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data.
1197
-    wpinv_set_checkout_session( $invoice_data );
1197
+    wpinv_set_checkout_session($invoice_data);
1198 1198
     
1199 1199
     // Set gateway
1200
-    $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] );
1201
-    $invoice->update_meta( '_wpinv_mode', ( wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live' ) );
1202
-    $invoice->update_meta( '_wpinv_checkout', true );
1200
+    $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']);
1201
+    $invoice->update_meta('_wpinv_mode', (wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live'));
1202
+    $invoice->update_meta('_wpinv_checkout', true);
1203 1203
     
1204
-    do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data );
1204
+    do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data);
1205 1205
 
1206 1206
     // Send info to the gateway for payment processing
1207
-    wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data );
1207
+    wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data);
1208 1208
     die();
1209 1209
 }
1210
-add_action( 'wpinv_payment', 'wpinv_process_checkout' );
1210
+add_action('wpinv_payment', 'wpinv_process_checkout');
1211 1211
 
1212
-function wpinv_get_invoices( $args ) {
1213
-    $args = wp_parse_args( $args, array(
1214
-        'status'   => array_keys( wpinv_get_invoice_statuses() ),
1212
+function wpinv_get_invoices($args) {
1213
+    $args = wp_parse_args($args, array(
1214
+        'status'   => array_keys(wpinv_get_invoice_statuses()),
1215 1215
         'type'     => 'wpi_invoice',
1216 1216
         'parent'   => null,
1217 1217
         'user'     => null,
1218 1218
         'email'    => '',
1219
-        'limit'    => get_option( 'posts_per_page' ),
1219
+        'limit'    => get_option('posts_per_page'),
1220 1220
         'offset'   => null,
1221 1221
         'page'     => 1,
1222 1222
         'exclude'  => array(),
@@ -1224,7 +1224,7 @@  discard block
 block discarded – undo
1224 1224
         'order'    => 'DESC',
1225 1225
         'return'   => 'objects',
1226 1226
         'paginate' => false,
1227
-    ) );
1227
+    ));
1228 1228
     
1229 1229
     // Handle some BW compatibility arg names where wp_query args differ in naming.
1230 1230
     $map_legacy = array(
@@ -1237,18 +1237,18 @@  discard block
 block discarded – undo
1237 1237
         'paged'          => 'page',
1238 1238
     );
1239 1239
 
1240
-    foreach ( $map_legacy as $from => $to ) {
1241
-        if ( isset( $args[ $from ] ) ) {
1242
-            $args[ $to ] = $args[ $from ];
1240
+    foreach ($map_legacy as $from => $to) {
1241
+        if (isset($args[$from])) {
1242
+            $args[$to] = $args[$from];
1243 1243
         }
1244 1244
     }
1245 1245
     
1246
-    if ( get_query_var( 'paged' ) )
1246
+    if (get_query_var('paged'))
1247 1247
         $args['page'] = get_query_var('paged');
1248
-    else if ( get_query_var( 'page' ) )
1249
-        $args['page'] = get_query_var( 'page' );
1250
-    else if ( !empty( $args[ 'page' ] ) )
1251
-        $args['page'] = $args[ 'page' ];
1248
+    else if (get_query_var('page'))
1249
+        $args['page'] = get_query_var('page');
1250
+    else if (!empty($args['page']))
1251
+        $args['page'] = $args['page'];
1252 1252
     else
1253 1253
         $args['page'] = 1;
1254 1254
 
@@ -1261,47 +1261,47 @@  discard block
 block discarded – undo
1261 1261
         'post_status'    => $args['status'],
1262 1262
         'posts_per_page' => $args['limit'],
1263 1263
         'meta_query'     => array(),
1264
-        'date_query'     => !empty( $args['date_query'] ) ? $args['date_query'] : array(),
1264
+        'date_query'     => !empty($args['date_query']) ? $args['date_query'] : array(),
1265 1265
         'fields'         => 'ids',
1266 1266
         'orderby'        => $args['orderby'],
1267 1267
         'order'          => $args['order'],
1268 1268
     );
1269 1269
     
1270
-    if ( !empty( $args['user'] ) ) {
1271
-        $wp_query_args['author'] = absint( $args['user'] );
1270
+    if (!empty($args['user'])) {
1271
+        $wp_query_args['author'] = absint($args['user']);
1272 1272
     }
1273 1273
 
1274
-    if ( ! is_null( $args['parent'] ) ) {
1275
-        $wp_query_args['post_parent'] = absint( $args['parent'] );
1274
+    if (!is_null($args['parent'])) {
1275
+        $wp_query_args['post_parent'] = absint($args['parent']);
1276 1276
     }
1277 1277
 
1278
-    if ( ! is_null( $args['offset'] ) ) {
1279
-        $wp_query_args['offset'] = absint( $args['offset'] );
1278
+    if (!is_null($args['offset'])) {
1279
+        $wp_query_args['offset'] = absint($args['offset']);
1280 1280
     } else {
1281
-        $wp_query_args['paged'] = absint( $args['page'] );
1281
+        $wp_query_args['paged'] = absint($args['page']);
1282 1282
     }
1283 1283
 
1284
-    if ( ! empty( $args['exclude'] ) ) {
1285
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
1284
+    if (!empty($args['exclude'])) {
1285
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
1286 1286
     }
1287 1287
 
1288
-    if ( ! $args['paginate' ] ) {
1288
+    if (!$args['paginate']) {
1289 1289
         $wp_query_args['no_found_rows'] = true;
1290 1290
     }
1291 1291
 
1292 1292
     // Get results.
1293
-    $invoices = new WP_Query( $wp_query_args );
1293
+    $invoices = new WP_Query($wp_query_args);
1294 1294
 
1295
-    if ( 'objects' === $args['return'] ) {
1296
-        $return = array_map( 'wpinv_get_invoice', $invoices->posts );
1297
-    } elseif ( 'self' === $args['return'] ) {
1295
+    if ('objects' === $args['return']) {
1296
+        $return = array_map('wpinv_get_invoice', $invoices->posts);
1297
+    } elseif ('self' === $args['return']) {
1298 1298
         return $invoices;
1299 1299
     } else {
1300 1300
         $return = $invoices->posts;
1301 1301
     }
1302 1302
 
1303
-    if ( $args['paginate' ] ) {
1304
-        return (object) array(
1303
+    if ($args['paginate']) {
1304
+        return (object)array(
1305 1305
             'invoices'      => $return,
1306 1306
             'total'         => $invoices->found_posts,
1307 1307
             'max_num_pages' => $invoices->max_num_pages,
@@ -1313,21 +1313,21 @@  discard block
 block discarded – undo
1313 1313
 
1314 1314
 function wpinv_get_user_invoices_columns() {
1315 1315
     $columns = array(
1316
-            'invoice-number'  => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ),
1317
-            'invoice-date'    => array( 'title' => __( 'Date', 'invoicing' ), 'class' => 'text-left' ),
1318
-            'invoice-status'  => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ),
1319
-            'invoice-total'   => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ),
1320
-            'invoice-actions' => array( 'title' => '&nbsp;', 'class' => 'text-center' ),
1316
+            'invoice-number'  => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'),
1317
+            'invoice-date'    => array('title' => __('Date', 'invoicing'), 'class' => 'text-left'),
1318
+            'invoice-status'  => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'),
1319
+            'invoice-total'   => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'),
1320
+            'invoice-actions' => array('title' => '&nbsp;', 'class' => 'text-center'),
1321 1321
         );
1322 1322
 
1323
-    return apply_filters( 'wpinv_user_invoices_columns', $columns );
1323
+    return apply_filters('wpinv_user_invoices_columns', $columns);
1324 1324
 }
1325 1325
 
1326
-function wpinv_payment_receipt( $atts, $content = null ) {
1326
+function wpinv_payment_receipt($atts, $content = null) {
1327 1327
     global $wpinv_receipt_args;
1328 1328
 
1329
-    $wpinv_receipt_args = shortcode_atts( array(
1330
-        'error'           => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ),
1329
+    $wpinv_receipt_args = shortcode_atts(array(
1330
+        'error'           => __('Sorry, trouble retrieving payment receipt.', 'invoicing'),
1331 1331
         'price'           => true,
1332 1332
         'discount'        => true,
1333 1333
         'items'           => true,
@@ -1336,185 +1336,185 @@  discard block
 block discarded – undo
1336 1336
         'invoice_key'     => false,
1337 1337
         'payment_method'  => true,
1338 1338
         'invoice_id'      => true
1339
-    ), $atts, 'wpinv_receipt' );
1339
+    ), $atts, 'wpinv_receipt');
1340 1340
 
1341 1341
     $session = wpinv_get_checkout_session();
1342
-    if ( isset( $_GET['invoice_key'] ) ) {
1343
-        $invoice_key = urldecode( $_GET['invoice_key'] );
1344
-    } else if ( $session && isset( $session['invoice_key'] ) ) {
1342
+    if (isset($_GET['invoice_key'])) {
1343
+        $invoice_key = urldecode($_GET['invoice_key']);
1344
+    } else if ($session && isset($session['invoice_key'])) {
1345 1345
         $invoice_key = $session['invoice_key'];
1346
-    } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) {
1346
+    } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) {
1347 1347
         $invoice_key = $wpinv_receipt_args['invoice_key'];
1348
-    } else if ( isset( $_GET['invoice-id'] ) ) {
1349
-        $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] );
1348
+    } else if (isset($_GET['invoice-id'])) {
1349
+        $invoice_key = wpinv_get_payment_key((int)$_GET['invoice-id']);
1350 1350
     }
1351 1351
 
1352 1352
     // No key found
1353
-    if ( ! isset( $invoice_key ) ) {
1353
+    if (!isset($invoice_key)) {
1354 1354
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1355 1355
     }
1356 1356
 
1357
-    $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1358
-    $user_can_view = wpinv_can_view_receipt( $invoice_key );
1359
-    if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1357
+    $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1358
+    $user_can_view = wpinv_can_view_receipt($invoice_key);
1359
+    if ($user_can_view && isset($_GET['invoice-id'])) {
1360 1360
         $invoice_id     = (int)$_GET['invoice-id'];
1361
-        $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1361
+        $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1362 1362
     }
1363 1363
 
1364 1364
     // Key was provided, but user is logged out. Offer them the ability to login and view the receipt
1365
-    if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) {
1365
+    if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) {
1366 1366
         // login redirect
1367
-        return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>';
1367
+        return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>';
1368 1368
     }
1369 1369
 
1370
-    if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) {
1370
+    if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) {
1371 1371
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1372 1372
     }
1373 1373
 
1374 1374
     ob_start();
1375 1375
 
1376
-    wpinv_get_template_part( 'wpinv-invoice-receipt' );
1376
+    wpinv_get_template_part('wpinv-invoice-receipt');
1377 1377
 
1378 1378
     $display = ob_get_clean();
1379 1379
 
1380 1380
     return $display;
1381 1381
 }
1382 1382
 
1383
-function wpinv_get_invoice_id_by_key( $key ) {
1383
+function wpinv_get_invoice_id_by_key($key) {
1384 1384
 	global $wpdb;
1385 1385
 
1386
-	$invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) );
1386
+	$invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key));
1387 1387
 
1388
-	if ( $invoice_id != NULL )
1388
+	if ($invoice_id != NULL)
1389 1389
 		return $invoice_id;
1390 1390
 
1391 1391
 	return 0;
1392 1392
 }
1393 1393
 
1394
-function wpinv_can_view_receipt( $invoice_key = '' ) {
1394
+function wpinv_can_view_receipt($invoice_key = '') {
1395 1395
 	$return = false;
1396 1396
 
1397
-	if ( empty( $invoice_key ) ) {
1397
+	if (empty($invoice_key)) {
1398 1398
 		return $return;
1399 1399
 	}
1400 1400
 
1401 1401
 	global $wpinv_receipt_args;
1402 1402
 
1403
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1404
-	if ( isset( $_GET['invoice-id'] ) ) {
1405
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1403
+	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key);
1404
+	if (isset($_GET['invoice-id'])) {
1405
+		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? (int)$_GET['invoice-id'] : 0;
1406 1406
 	}
1407 1407
 
1408
-	$user_id = (int) wpinv_get_user_id( $wpinv_receipt_args['id'] );
1409
-    $invoice_meta = wpinv_get_invoice_meta( $wpinv_receipt_args['id'] );
1408
+	$user_id = (int)wpinv_get_user_id($wpinv_receipt_args['id']);
1409
+    $invoice_meta = wpinv_get_invoice_meta($wpinv_receipt_args['id']);
1410 1410
 
1411
-	if ( is_user_logged_in() ) {
1412
-		if ( $user_id === (int) get_current_user_id() ) {
1411
+	if (is_user_logged_in()) {
1412
+		if ($user_id === (int)get_current_user_id()) {
1413 1413
 			$return = true;
1414 1414
 		}
1415 1415
 	}
1416 1416
 
1417 1417
 	$session = wpinv_get_checkout_session();
1418
-	if ( ! empty( $session ) && ! is_user_logged_in() ) {
1419
-		if ( $session['invoice_key'] === $invoice_meta['key'] ) {
1418
+	if (!empty($session) && !is_user_logged_in()) {
1419
+		if ($session['invoice_key'] === $invoice_meta['key']) {
1420 1420
 			$return = true;
1421 1421
 		}
1422 1422
 	}
1423 1423
 
1424
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1424
+	return (bool)apply_filters('wpinv_can_view_receipt', $return, $invoice_key);
1425 1425
 }
1426 1426
 
1427 1427
 function wpinv_pay_for_invoice() {
1428 1428
     global $wpinv_euvat;
1429 1429
     
1430
-    if ( isset( $_GET['invoice_key'] ) ) {
1430
+    if (isset($_GET['invoice_key'])) {
1431 1431
         $checkout_uri   = wpinv_get_checkout_uri();
1432
-        $invoice_key    = sanitize_text_field( $_GET['invoice_key'] );
1432
+        $invoice_key    = sanitize_text_field($_GET['invoice_key']);
1433 1433
         
1434
-        if ( empty( $invoice_key ) ) {
1435
-            wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) );
1436
-            wp_redirect( $checkout_uri );
1434
+        if (empty($invoice_key)) {
1435
+            wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing'));
1436
+            wp_redirect($checkout_uri);
1437 1437
             wpinv_die();
1438 1438
         }
1439 1439
         
1440
-        do_action( 'wpinv_check_pay_for_invoice', $invoice_key );
1440
+        do_action('wpinv_check_pay_for_invoice', $invoice_key);
1441 1441
 
1442
-        $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1443
-        $user_can_view = wpinv_can_view_receipt( $invoice_key );
1444
-        if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1442
+        $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1443
+        $user_can_view = wpinv_can_view_receipt($invoice_key);
1444
+        if ($user_can_view && isset($_GET['invoice-id'])) {
1445 1445
             $invoice_id     = (int)$_GET['invoice-id'];
1446
-            $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1446
+            $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1447 1447
         }
1448 1448
         
1449
-        if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) {
1450
-            if ( $invoice->needs_payment() ) {
1449
+        if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) {
1450
+            if ($invoice->needs_payment()) {
1451 1451
                 $data                   = array();
1452 1452
                 $data['invoice_id']     = $invoice_id;
1453
-                $data['cart_discounts'] = $invoice->get_discounts( true );
1453
+                $data['cart_discounts'] = $invoice->get_discounts(true);
1454 1454
                 
1455
-                wpinv_set_checkout_session( $data );
1455
+                wpinv_set_checkout_session($data);
1456 1456
                 
1457
-                if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1457
+                if (wpinv_get_option('vat_ip_country_default')) {
1458 1458
                     $_POST['country']   = $wpinv_euvat->get_country_by_ip();
1459 1459
                     $_POST['state']     = $_POST['country'] == $invoice->country ? $invoice->state : '';
1460 1460
                     
1461
-                    wpinv_recalculate_tax( true );
1461
+                    wpinv_recalculate_tax(true);
1462 1462
                 }
1463 1463
                 
1464 1464
             } else {
1465 1465
                 $checkout_uri = $invoice->get_view_url();
1466 1466
             }
1467 1467
         } else {
1468
-            wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) );
1468
+            wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing'));
1469 1469
             
1470
-            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
1470
+            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
1471 1471
         }
1472 1472
         
1473
-        wp_redirect( $checkout_uri );
1473
+        wp_redirect($checkout_uri);
1474 1474
         wpinv_die();
1475 1475
     }
1476 1476
 }
1477
-add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' );
1477
+add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice');
1478 1478
 
1479
-function wpinv_handle_pay_via_invoice_link( $invoice_key ) {
1480
-    if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) {
1481
-        if ( $invoice = wpinv_get_invoice( $invoice_id ) ) {
1479
+function wpinv_handle_pay_via_invoice_link($invoice_key) {
1480
+    if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) {
1481
+        if ($invoice = wpinv_get_invoice($invoice_id)) {
1482 1482
             $user_id = $invoice->get_user_id();
1483
-            $secret = sanitize_text_field( $_GET['_wpipay'] );
1483
+            $secret = sanitize_text_field($_GET['_wpipay']);
1484 1484
             
1485
-            if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link
1486
-                $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
1485
+            if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link
1486
+                $redirect_to = remove_query_arg('_wpipay', get_permalink());
1487 1487
                 
1488
-                wpinv_guest_redirect( $redirect_to, $user_id );
1488
+                wpinv_guest_redirect($redirect_to, $user_id);
1489 1489
                 wpinv_die();
1490 1490
             }
1491 1491
         }
1492 1492
     }
1493 1493
 }
1494
-add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' );
1494
+add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link');
1495 1495
 
1496
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
1497
-    $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id;
1496
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
1497
+    $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id;
1498 1498
     
1499
-    if ( empty( $invoice_id ) && $invoice_id > 0 ) {
1499
+    if (empty($invoice_id) && $invoice_id > 0) {
1500 1500
         return false;
1501 1501
     }
1502 1502
     
1503
-    if ( empty( $transaction_id ) ) {
1503
+    if (empty($transaction_id)) {
1504 1504
         $transaction_id = $invoice_id;
1505 1505
     }
1506 1506
 
1507
-    $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id );
1507
+    $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id);
1508 1508
     
1509
-    return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id );
1509
+    return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id);
1510 1510
 }
1511 1511
 
1512
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
1513
-    if ( empty( $status_display ) ) {
1514
-        $status_display = wpinv_status_nicename( $status );
1512
+function wpinv_invoice_status_label($status, $status_display = '') {
1513
+    if (empty($status_display)) {
1514
+        $status_display = wpinv_status_nicename($status);
1515 1515
     }
1516 1516
     
1517
-    switch ( $status ) {
1517
+    switch ($status) {
1518 1518
         case 'publish' :
1519 1519
         case 'wpi-renewal' :
1520 1520
             $class = 'label-success';
@@ -1539,28 +1539,28 @@  discard block
 block discarded – undo
1539 1539
     
1540 1540
     $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>';
1541 1541
     
1542
-    return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display );
1542
+    return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display);
1543 1543
 }
1544 1544
 
1545
-function wpinv_format_invoice_number( $number ) {
1546
-    $padd  = wpinv_get_option( 'invoice_number_padd' );
1545
+function wpinv_format_invoice_number($number) {
1546
+    $padd = wpinv_get_option('invoice_number_padd');
1547 1547
     
1548 1548
     // TODO maintain old invoice numbers if invoice number settings not saved. Should be removed before stable release.
1549
-    if ( $padd === '' || $padd === false || $padd === NULL ) {
1550
-        return wp_sprintf( __( 'WPINV-%d', 'invoicing' ), $number );
1549
+    if ($padd === '' || $padd === false || $padd === NULL) {
1550
+        return wp_sprintf(__('WPINV-%d', 'invoicing'), $number);
1551 1551
     }
1552 1552
     
1553
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
1554
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
1553
+    $prefix  = wpinv_get_option('invoice_number_prefix');
1554
+    $postfix = wpinv_get_option('invoice_number_postfix');
1555 1555
     
1556
-    $padd = absint( $padd );
1557
-    $formatted_number = absint( $number );
1556
+    $padd = absint($padd);
1557
+    $formatted_number = absint($number);
1558 1558
     
1559
-    if ( $padd > 0 ) {
1560
-        $formatted_number = zeroise( $formatted_number, $padd );
1559
+    if ($padd > 0) {
1560
+        $formatted_number = zeroise($formatted_number, $padd);
1561 1561
     }    
1562 1562
 
1563 1563
     $formatted_number = $prefix . $formatted_number . $postfix;
1564 1564
 
1565
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
1565
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
1566 1566
 }
1567 1567
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 1 patch
Spacing   +193 added lines, -193 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
 
@@ -218,21 +218,21 @@  discard block
 block discarded – undo
218 218
             'fees'       => array()
219 219
         );
220 220
 
221
-        $invoice->add_item( $item_id, $args );
221
+        $invoice->add_item($item_id, $args);
222 222
         $invoice->save();
223 223
         
224
-        if ( empty( $_POST['country'] ) ) {
224
+        if (empty($_POST['country'])) {
225 225
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
226 226
         }
227
-        if ( empty( $_POST['state'] ) ) {
227
+        if (empty($_POST['state'])) {
228 228
             $_POST['state'] = $invoice->state;
229 229
         }
230 230
          
231
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
232
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
231
+        $invoice->country   = sanitize_text_field($_POST['country']);
232
+        $invoice->state     = sanitize_text_field($_POST['state']);
233 233
         
234
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
235
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
234
+        $invoice->set('country', sanitize_text_field($_POST['country']));
235
+        $invoice->set('state', sanitize_text_field($_POST['state']));
236 236
         
237 237
         $wpinv_ip_address_country = $invoice->country;
238 238
 
@@ -240,52 +240,52 @@  discard block
 block discarded – undo
240 240
         
241 241
         $response                       = array();
242 242
         $response['success']            = true;
243
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
243
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
244 244
         $response['data']['subtotal']   = $invoice->get_subtotal();
245 245
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
246 246
         $response['data']['tax']        = $invoice->get_tax();
247 247
         $response['data']['taxf']       = $invoice->get_tax(true);
248 248
         $response['data']['discount']   = $invoice->discount;
249
-        $response['data']['discountf']  = wpinv_price( $invoice->discount, $invoice->get_currency() );
249
+        $response['data']['discountf']  = wpinv_price($invoice->discount, $invoice->get_currency());
250 250
         $response['data']['total']      = $invoice->get_total();
251 251
         $response['data']['totalf']     = $invoice->get_total(true);
252 252
         
253 253
         wpinv_set_checkout_session($checkout_session);
254 254
         
255
-        wp_send_json( $response );
255
+        wp_send_json($response);
256 256
     }
257 257
     
258 258
     public static function remove_invoice_item() {
259 259
         global $wpi_userID, $wpinv_ip_address_country;
260 260
         
261
-        check_ajax_referer( 'invoice-item', '_nonce' );
262
-        if ( !current_user_can( 'manage_options' ) ) {
261
+        check_ajax_referer('invoice-item', '_nonce');
262
+        if (!current_user_can('manage_options')) {
263 263
             die(-1);
264 264
         }
265 265
         
266
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
267
-        $invoice_id = absint( $_POST['invoice_id'] );
268
-        $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false;
266
+        $item_id    = sanitize_text_field($_POST['item_id']);
267
+        $invoice_id = absint($_POST['invoice_id']);
268
+        $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false;
269 269
         
270
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
270
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
271 271
             die();
272 272
         }
273 273
 
274
-        $invoice    = wpinv_get_invoice( $invoice_id );
275
-        if ( empty( $invoice ) ) {
274
+        $invoice = wpinv_get_invoice($invoice_id);
275
+        if (empty($invoice)) {
276 276
             die();
277 277
         }
278 278
         
279
-        if ( $invoice->is_paid() ) {
279
+        if ($invoice->is_paid()) {
280 280
             die(); // Don't allow modify items for paid invoice.
281 281
         }
282 282
         
283
-        if ( !empty( $_POST['user_id'] ) ) {
284
-            $wpi_userID = absint( $_POST['user_id'] ); 
283
+        if (!empty($_POST['user_id'])) {
284
+            $wpi_userID = absint($_POST['user_id']); 
285 285
         }
286 286
 
287
-        $item       = new WPInv_Item( $item_id );
288
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
287
+        $item = new WPInv_Item($item_id);
288
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
289 289
             die();
290 290
         }
291 291
         
@@ -293,9 +293,9 @@  discard block
 block discarded – undo
293 293
         
294 294
         $data                   = array();
295 295
         $data['invoice_id']     = $invoice_id;
296
-        $data['cart_discounts'] = $invoice->get_discounts( true );
296
+        $data['cart_discounts'] = $invoice->get_discounts(true);
297 297
         
298
-        wpinv_set_checkout_session( $data );
298
+        wpinv_set_checkout_session($data);
299 299
 
300 300
         $args = array(
301 301
             'id'         => $item_id,
@@ -303,21 +303,21 @@  discard block
 block discarded – undo
303 303
             'cart_index' => $cart_index
304 304
         );
305 305
 
306
-        $invoice->remove_item( $item_id, $args );
306
+        $invoice->remove_item($item_id, $args);
307 307
         $invoice->save();
308 308
         
309
-        if ( empty( $_POST['country'] ) ) {
309
+        if (empty($_POST['country'])) {
310 310
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
311 311
         }
312
-        if ( empty( $_POST['state'] ) ) {
312
+        if (empty($_POST['state'])) {
313 313
             $_POST['state'] = $invoice->state;
314 314
         }
315 315
          
316
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
317
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
316
+        $invoice->country   = sanitize_text_field($_POST['country']);
317
+        $invoice->state     = sanitize_text_field($_POST['state']);
318 318
         
319
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
320
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
319
+        $invoice->set('country', sanitize_text_field($_POST['country']));
320
+        $invoice->set('state', sanitize_text_field($_POST['state']));
321 321
         
322 322
         $wpinv_ip_address_country = $invoice->country;
323 323
         
@@ -325,52 +325,52 @@  discard block
 block discarded – undo
325 325
         
326 326
         $response                       = array();
327 327
         $response['success']            = true;
328
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
328
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
329 329
         $response['data']['subtotal']   = $invoice->get_subtotal();
330 330
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
331 331
         $response['data']['tax']        = $invoice->get_tax();
332 332
         $response['data']['taxf']       = $invoice->get_tax(true);
333 333
         $response['data']['discount']   = $invoice->discount;
334
-        $response['data']['discountf']  = wpinv_price( $invoice->discount, $invoice->get_currency() );
334
+        $response['data']['discountf']  = wpinv_price($invoice->discount, $invoice->get_currency());
335 335
         $response['data']['total']      = $invoice->get_total();
336 336
         $response['data']['totalf']     = $invoice->get_total(true);
337 337
         
338 338
         wpinv_set_checkout_session($checkout_session);
339 339
         
340
-        wp_send_json( $response );
340
+        wp_send_json($response);
341 341
     }
342 342
     
343 343
     public static function create_invoice_item() {
344
-        check_ajax_referer( 'invoice-item', '_nonce' );
345
-        if ( !current_user_can( 'manage_options' ) ) {
344
+        check_ajax_referer('invoice-item', '_nonce');
345
+        if (!current_user_can('manage_options')) {
346 346
             die(-1);
347 347
         }
348 348
         
349
-        $invoice_id = absint( $_POST['invoice_id'] );
349
+        $invoice_id = absint($_POST['invoice_id']);
350 350
 
351 351
         // Find the item
352
-        if ( !is_numeric( $invoice_id ) ) {
352
+        if (!is_numeric($invoice_id)) {
353 353
             die();
354 354
         }        
355 355
         
356
-        $invoice     = wpinv_get_invoice( $invoice_id );
357
-        if ( empty( $invoice ) ) {
356
+        $invoice = wpinv_get_invoice($invoice_id);
357
+        if (empty($invoice)) {
358 358
             die();
359 359
         }
360 360
         
361 361
         // Validate item before adding to invoice because recurring item must be paid individually.
362
-        if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) {
362
+        if (!empty($invoice->cart_details) && $invoice->get_recurring()) {
363 363
             $response               = array();
364 364
             $response['success']    = false;
365
-            $response['msg']        = __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' );
366
-            wp_send_json( $response );
365
+            $response['msg']        = __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing');
366
+            wp_send_json($response);
367 367
         }        
368 368
         
369 369
         $save_item = $_POST['_wpinv_quick'];
370 370
         
371 371
         $meta               = array();
372 372
         $meta['type']       = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom';
373
-        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0;
373
+        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0;
374 374
         $meta['vat_rule']   = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital';
375 375
         $meta['vat_class']  = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard';
376 376
         
@@ -380,9 +380,9 @@  discard block
 block discarded – undo
380 380
         $data['meta']           = $meta;
381 381
         
382 382
         $item = new WPInv_Item();
383
-        $item->create( $data );
383
+        $item->create($data);
384 384
         
385
-        if ( !empty( $item ) ) {
385
+        if (!empty($item)) {
386 386
             $_POST['item_id']   = $item->ID;
387 387
             $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1;
388 388
             
@@ -392,15 +392,15 @@  discard block
 block discarded – undo
392 392
     }
393 393
     
394 394
     public static function get_billing_details() {
395
-        check_ajax_referer( 'get-billing-details', '_nonce' );
395
+        check_ajax_referer('get-billing-details', '_nonce');
396 396
         
397
-        if ( !current_user_can( 'manage_options' ) ) {
397
+        if (!current_user_can('manage_options')) {
398 398
             die(-1);
399 399
         }
400 400
 
401 401
         $user_id            = (int)$_POST['user_id'];
402 402
         $billing_details    = wpinv_get_user_address($user_id);
403
-        $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
403
+        $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
404 404
         
405 405
         if (isset($billing_details['user_id'])) {
406 406
             unset($billing_details['user_id']);
@@ -414,20 +414,20 @@  discard block
 block discarded – undo
414 414
         $response['success']                    = true;
415 415
         $response['data']['billing_details']    = $billing_details;
416 416
         
417
-        wp_send_json( $response );
417
+        wp_send_json($response);
418 418
     }
419 419
     
420 420
     public static function admin_recalculate_totals() {
421 421
         global $wpi_userID, $wpinv_ip_address_country;
422 422
         
423
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
424
-        if ( !current_user_can( 'manage_options' ) ) {
423
+        check_ajax_referer('wpinv-nonce', '_nonce');
424
+        if (!current_user_can('manage_options')) {
425 425
             die(-1);
426 426
         }
427 427
         
428
-        $invoice_id = absint( $_POST['invoice_id'] );        
429
-        $invoice    = wpinv_get_invoice( $invoice_id );
430
-        if ( empty( $invoice ) ) {
428
+        $invoice_id = absint($_POST['invoice_id']);        
429
+        $invoice    = wpinv_get_invoice($invoice_id);
430
+        if (empty($invoice)) {
431 431
             die();
432 432
         }
433 433
         
@@ -435,23 +435,23 @@  discard block
 block discarded – undo
435 435
         
436 436
         $data                   = array();
437 437
         $data['invoice_id']     = $invoice_id;
438
-        $data['cart_discounts'] = $invoice->get_discounts( true );
438
+        $data['cart_discounts'] = $invoice->get_discounts(true);
439 439
         
440
-        wpinv_set_checkout_session( $data );
440
+        wpinv_set_checkout_session($data);
441 441
         
442
-        if ( !empty( $_POST['user_id'] ) ) {
443
-            $wpi_userID = absint( $_POST['user_id'] ); 
442
+        if (!empty($_POST['user_id'])) {
443
+            $wpi_userID = absint($_POST['user_id']); 
444 444
         }
445 445
         
446
-        if ( empty( $_POST['country'] ) ) {
446
+        if (empty($_POST['country'])) {
447 447
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
448 448
         }
449 449
             
450
-        $invoice->country = sanitize_text_field( $_POST['country'] );
451
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
452
-        if ( isset( $_POST['state'] ) ) {
453
-            $invoice->state = sanitize_text_field( $_POST['state'] );
454
-            $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
450
+        $invoice->country = sanitize_text_field($_POST['country']);
451
+        $invoice->set('country', sanitize_text_field($_POST['country']));
452
+        if (isset($_POST['state'])) {
453
+            $invoice->state = sanitize_text_field($_POST['state']);
454
+            $invoice->set('state', sanitize_text_field($_POST['state']));
455 455
         }
456 456
         
457 457
         $wpinv_ip_address_country = $invoice->country;
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
         
461 461
         $response                       = array();
462 462
         $response['success']            = true;
463
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
463
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
464 464
         $response['data']['subtotal']   = $invoice->get_subtotal();
465 465
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
466 466
         $response['data']['tax']        = $invoice->get_tax();
@@ -472,25 +472,25 @@  discard block
 block discarded – undo
472 472
         
473 473
         wpinv_set_checkout_session($checkout_session);
474 474
         
475
-        wp_send_json( $response );
475
+        wp_send_json($response);
476 476
     }
477 477
     
478 478
     public static function admin_apply_discount() {
479 479
         global $wpi_userID;
480 480
         
481
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
482
-        if ( !current_user_can( 'manage_options' ) ) {
481
+        check_ajax_referer('wpinv-nonce', '_nonce');
482
+        if (!current_user_can('manage_options')) {
483 483
             die(-1);
484 484
         }
485 485
         
486
-        $invoice_id = absint( $_POST['invoice_id'] );
487
-        $discount_code = sanitize_text_field( $_POST['code'] );
488
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
486
+        $invoice_id = absint($_POST['invoice_id']);
487
+        $discount_code = sanitize_text_field($_POST['code']);
488
+        if (empty($invoice_id) || empty($discount_code)) {
489 489
             die();
490 490
         }
491 491
         
492
-        $invoice = wpinv_get_invoice( $invoice_id );
493
-        if ( empty( $invoice ) || ( !empty( $invoice ) && $invoice->is_paid() ) ) {
492
+        $invoice = wpinv_get_invoice($invoice_id);
493
+        if (empty($invoice) || (!empty($invoice) && $invoice->is_paid())) {
494 494
             die();
495 495
         }
496 496
         
@@ -498,49 +498,49 @@  discard block
 block discarded – undo
498 498
         
499 499
         $data                   = array();
500 500
         $data['invoice_id']     = $invoice_id;
501
-        $data['cart_discounts'] = $invoice->get_discounts( true );
501
+        $data['cart_discounts'] = $invoice->get_discounts(true);
502 502
         
503
-        wpinv_set_checkout_session( $data );
503
+        wpinv_set_checkout_session($data);
504 504
         
505 505
         $response               = array();
506 506
         $response['success']    = false;
507
-        $response['msg']        = __( 'This discount is invalid.', 'invoicing' );
507
+        $response['msg']        = __('This discount is invalid.', 'invoicing');
508 508
         $response['data']['code'] = $discount_code;
509 509
         
510
-        if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) {
511
-            $discounts = wpinv_set_cart_discount( $discount_code );
510
+        if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) {
511
+            $discounts = wpinv_set_cart_discount($discount_code);
512 512
             
513 513
             $response['success'] = true;
514
-            $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' );
515
-        }  else {
514
+            $response['msg'] = __('Discount has been applied successfully.', 'invoicing');
515
+        } else {
516 516
             $errors = wpinv_get_errors();
517
-            if ( !empty( $errors['wpinv-discount-error'] ) ) {
517
+            if (!empty($errors['wpinv-discount-error'])) {
518 518
                 $response['msg'] = $errors['wpinv-discount-error'];
519 519
             }
520
-            wpinv_unset_error( 'wpinv-discount-error' );
520
+            wpinv_unset_error('wpinv-discount-error');
521 521
         }
522 522
         
523 523
         wpinv_set_checkout_session($checkout_session);
524 524
         
525
-        wp_send_json( $response );
525
+        wp_send_json($response);
526 526
     }
527 527
     
528 528
     public static function admin_remove_discount() {
529 529
         global $wpi_userID;
530 530
         
531
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
532
-        if ( !current_user_can( 'manage_options' ) ) {
531
+        check_ajax_referer('wpinv-nonce', '_nonce');
532
+        if (!current_user_can('manage_options')) {
533 533
             die(-1);
534 534
         }
535 535
         
536
-        $invoice_id = absint( $_POST['invoice_id'] );
537
-        $discount_code = sanitize_text_field( $_POST['code'] );
538
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
536
+        $invoice_id = absint($_POST['invoice_id']);
537
+        $discount_code = sanitize_text_field($_POST['code']);
538
+        if (empty($invoice_id) || empty($discount_code)) {
539 539
             die();
540 540
         }
541 541
         
542
-        $invoice = wpinv_get_invoice( $invoice_id );
543
-        if ( empty( $invoice ) || ( !empty( $invoice ) && $invoice->is_paid() ) ) {
542
+        $invoice = wpinv_get_invoice($invoice_id);
543
+        if (empty($invoice) || (!empty($invoice) && $invoice->is_paid())) {
544 544
             die();
545 545
         }
546 546
         
@@ -548,38 +548,38 @@  discard block
 block discarded – undo
548 548
         
549 549
         $data                   = array();
550 550
         $data['invoice_id']     = $invoice_id;
551
-        $data['cart_discounts'] = $invoice->get_discounts( true );
551
+        $data['cart_discounts'] = $invoice->get_discounts(true);
552 552
         
553
-        wpinv_set_checkout_session( $data );
553
+        wpinv_set_checkout_session($data);
554 554
         
555 555
         $response               = array();
556 556
         $response['success']    = false;
557 557
         $response['msg']        = NULL;
558 558
         
559
-        $discounts  = wpinv_unset_cart_discount( $discount_code );
559
+        $discounts = wpinv_unset_cart_discount($discount_code);
560 560
         $response['success'] = true;
561
-        $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' );
561
+        $response['msg'] = __('Discount has been removed successfully.', 'invoicing');
562 562
         
563 563
         wpinv_set_checkout_session($checkout_session);
564 564
         
565
-        wp_send_json( $response );
565
+        wp_send_json($response);
566 566
     }
567 567
     
568 568
     public static function check_email() {
569
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
570
-        if ( !current_user_can( 'manage_options' ) ) {
569
+        check_ajax_referer('wpinv-nonce', '_nonce');
570
+        if (!current_user_can('manage_options')) {
571 571
             die(-1);
572 572
         }
573 573
         
574
-        $email = sanitize_text_field( $_POST['email'] );
574
+        $email = sanitize_text_field($_POST['email']);
575 575
         
576 576
         $response = array();
577
-        if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) {
577
+        if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) {
578 578
             $user_id            = $user_data->ID;
579 579
             $user_login         = $user_data->user_login;
580 580
             $display_name       = $user_data->display_name ? $user_data->display_name : $user_login;
581 581
             $billing_details    = wpinv_get_user_address($user_id);
582
-            $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
582
+            $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
583 583
             
584 584
             if (isset($billing_details['user_id'])) {
585 585
                 unset($billing_details['user_id']);
@@ -595,31 +595,31 @@  discard block
 block discarded – undo
595 595
             $response['data']['billing_details']    = $billing_details;
596 596
         }
597 597
         
598
-        wp_send_json( $response );
598
+        wp_send_json($response);
599 599
     }
600 600
     
601 601
     public static function run_tool() {
602
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
603
-        if ( !current_user_can( 'manage_options' ) ) {
602
+        check_ajax_referer('wpinv-nonce', '_nonce');
603
+        if (!current_user_can('manage_options')) {
604 604
             die(-1);
605 605
         }
606 606
         
607
-        $tool = sanitize_text_field( $_POST['tool'] );
607
+        $tool = sanitize_text_field($_POST['tool']);
608 608
         
609
-        do_action( 'wpinv_run_tool' );
609
+        do_action('wpinv_run_tool');
610 610
         
611
-        if ( !empty( $tool ) ) {
612
-            do_action( 'wpinv_tool_' . $tool );
611
+        if (!empty($tool)) {
612
+            do_action('wpinv_tool_' . $tool);
613 613
         }
614 614
     }
615 615
     
616 616
     public static function apply_discount() {
617
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
617
+        check_ajax_referer('wpinv-nonce', '_nonce');
618 618
         
619 619
         $response = array();
620 620
         
621
-        if ( isset( $_POST['code'] ) ) {
622
-            $discount_code = sanitize_text_field( $_POST['code'] );
621
+        if (isset($_POST['code'])) {
622
+            $discount_code = sanitize_text_field($_POST['code']);
623 623
 
624 624
             $response['success']        = false;
625 625
             $response['msg']            = '';
@@ -627,14 +627,14 @@  discard block
 block discarded – undo
627 627
             
628 628
             $user = is_user_logged_in() ? get_current_user_id() : '';
629 629
 
630
-            if ( wpinv_is_discount_valid( $discount_code, $user ) ) {
631
-                $discount       = wpinv_get_discount_by_code( $discount_code );
632
-                $discounts      = wpinv_set_cart_discount( $discount_code );
633
-                $amount         = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
634
-                $total          = wpinv_get_cart_total( null, $discounts );
635
-                $cart_totals    = wpinv_recalculate_tax( true );
630
+            if (wpinv_is_discount_valid($discount_code, $user)) {
631
+                $discount       = wpinv_get_discount_by_code($discount_code);
632
+                $discounts      = wpinv_set_cart_discount($discount_code);
633
+                $amount         = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
634
+                $total          = wpinv_get_cart_total(null, $discounts);
635
+                $cart_totals    = wpinv_recalculate_tax(true);
636 636
             
637
-                if ( !empty( $cart_totals ) ) {
637
+                if (!empty($cart_totals)) {
638 638
                     $response['success']        = true;
639 639
                     $response['data']           = $cart_totals;
640 640
                     $response['data']['code']   = $discount_code;
@@ -643,29 +643,29 @@  discard block
 block discarded – undo
643 643
                 }
644 644
             } else {
645 645
                 $errors = wpinv_get_errors();
646
-                $response['msg']  = $errors['wpinv-discount-error'];
647
-                wpinv_unset_error( 'wpinv-discount-error' );
646
+                $response['msg'] = $errors['wpinv-discount-error'];
647
+                wpinv_unset_error('wpinv-discount-error');
648 648
             }
649 649
 
650 650
             // Allow for custom discount code handling
651
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
651
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
652 652
         }
653 653
         
654
-        wp_send_json( $response );
654
+        wp_send_json($response);
655 655
     }
656 656
     
657 657
     public static function remove_discount() {
658
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
658
+        check_ajax_referer('wpinv-nonce', '_nonce');
659 659
         
660 660
         $response = array();
661 661
         
662
-        if ( isset( $_POST['code'] ) ) {
663
-            $discount_code  = sanitize_text_field( $_POST['code'] );
664
-            $discounts      = wpinv_unset_cart_discount( $discount_code );
665
-            $total          = wpinv_get_cart_total( null, $discounts );
666
-            $cart_totals    = wpinv_recalculate_tax( true );
662
+        if (isset($_POST['code'])) {
663
+            $discount_code  = sanitize_text_field($_POST['code']);
664
+            $discounts      = wpinv_unset_cart_discount($discount_code);
665
+            $total          = wpinv_get_cart_total(null, $discounts);
666
+            $cart_totals    = wpinv_recalculate_tax(true);
667 667
             
668
-            if ( !empty( $cart_totals ) ) {
668
+            if (!empty($cart_totals)) {
669 669
                 $response['success']        = true;
670 670
                 $response['data']           = $cart_totals;
671 671
                 $response['data']['code']   = $discount_code;
@@ -674,10 +674,10 @@  discard block
 block discarded – undo
674 674
             }
675 675
             
676 676
             // Allow for custom discount code handling
677
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
677
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
678 678
         }
679 679
         
680
-        wp_send_json( $response );
680
+        wp_send_json($response);
681 681
     }
682 682
 }
683 683
 
Please login to merge, or discard this patch.
includes/admin/wpinv-admin-functions.php 1 patch
Spacing   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -7,228 +7,228 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14
-function wpinv_columns( $columns ) {
14
+function wpinv_columns($columns) {
15 15
     $columns = array(
16 16
         'cb'                => $columns['cb'],
17
-        'ID'                => __( 'ID', 'invoicing' ),
18
-        'details'           => __( 'Details', 'invoicing' ),
17
+        'ID'                => __('ID', 'invoicing'),
18
+        'details'           => __('Details', 'invoicing'),
19 19
         //'email'             => __( 'Email', 'invoicing' ),
20
-        'customer'          => __( 'Customer', 'invoicing' ),
21
-        'amount'            => __( 'Amount', 'invoicing' ),
22
-        'invoice_date'      => __( 'Date', 'invoicing' ),
23
-        'status'            => __( 'Status', 'invoicing' ),
24
-        'wpi_actions'       => __( 'Actions', 'invoicing' ),
20
+        'customer'          => __('Customer', 'invoicing'),
21
+        'amount'            => __('Amount', 'invoicing'),
22
+        'invoice_date'      => __('Date', 'invoicing'),
23
+        'status'            => __('Status', 'invoicing'),
24
+        'wpi_actions'       => __('Actions', 'invoicing'),
25 25
     );
26 26
 
27
-    return apply_filters( 'wpi_invoice_table_columns', $columns );
27
+    return apply_filters('wpi_invoice_table_columns', $columns);
28 28
 }
29
-add_filter( 'manage_wpi_invoice_posts_columns', 'wpinv_columns' );
29
+add_filter('manage_wpi_invoice_posts_columns', 'wpinv_columns');
30 30
 
31
-function wpinv_bulk_actions( $actions ) {
32
-    if ( isset( $actions['edit'] ) ) {
33
-        unset( $actions['edit'] );
31
+function wpinv_bulk_actions($actions) {
32
+    if (isset($actions['edit'])) {
33
+        unset($actions['edit']);
34 34
     }
35 35
 
36 36
     return $actions;
37 37
 }
38
-add_filter( 'bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions' );
38
+add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions');
39 39
 
40
-function wpinv_sortable_columns( $columns ) {
40
+function wpinv_sortable_columns($columns) {
41 41
     $columns = array(
42
-        'ID'     => array( 'ID', true ),
43
-        'amount' => array( 'amount', false ),
44
-        'invoice_date'   => array( 'date', false ),
45
-        'customer'   => array( 'customer', false ),
42
+        'ID'     => array('ID', true),
43
+        'amount' => array('amount', false),
44
+        'invoice_date'   => array('date', false),
45
+        'customer'   => array('customer', false),
46 46
         ///'email'   => array( 'email', false ),
47
-        'status'   => array( 'status', false ),
47
+        'status'   => array('status', false),
48 48
     );
49 49
     
50
-    return apply_filters( 'wpi_invoice_table_sortable_columns', $columns );
50
+    return apply_filters('wpi_invoice_table_sortable_columns', $columns);
51 51
 }
52
-add_filter( 'manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns' );
52
+add_filter('manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns');
53 53
 
54
-add_action( 'manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
55
-function wpinv_posts_custom_column( $column_name, $post_id = 0 ) {
54
+add_action('manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
55
+function wpinv_posts_custom_column($column_name, $post_id = 0) {
56 56
     global $post, $wpi_invoice;
57 57
     
58
-    if ( empty( $wpi_invoice ) || ( !empty( $wpi_invoice ) && $post->ID != $wpi_invoice->ID ) ) {
59
-        $wpi_invoice = new WPInv_Invoice( $post->ID );
58
+    if (empty($wpi_invoice) || (!empty($wpi_invoice) && $post->ID != $wpi_invoice->ID)) {
59
+        $wpi_invoice = new WPInv_Invoice($post->ID);
60 60
     }
61 61
 
62 62
     $value = NULL;
63 63
     
64
-    switch ( $column_name ) {
64
+    switch ($column_name) {
65 65
         case 'email' :
66
-            $value   = $wpi_invoice->get_email();
66
+            $value = $wpi_invoice->get_email();
67 67
             break;
68 68
         case 'customer' :
69 69
             $customer_name = $wpi_invoice->get_user_full_name();
70
-            $customer_name = $customer_name != '' ? $customer_name : __( 'Customer', 'invoicing' );
71
-            $value = '<a href="' . esc_url( get_edit_user_link( $wpi_invoice->get_user_id() ) ) . '">' . $customer_name . '</a>';
72
-            if ( $email = $wpi_invoice->get_email() ) {
70
+            $customer_name = $customer_name != '' ? $customer_name : __('Customer', 'invoicing');
71
+            $value = '<a href="' . esc_url(get_edit_user_link($wpi_invoice->get_user_id())) . '">' . $customer_name . '</a>';
72
+            if ($email = $wpi_invoice->get_email()) {
73 73
                 $value .= '<br><a class="email" href="mailto:' . $email . '">' . $email . '</a>';
74 74
             }
75 75
             break;
76 76
         case 'amount' :
77
-            echo $wpi_invoice->get_total( true );
77
+            echo $wpi_invoice->get_total(true);
78 78
             break;
79 79
         case 'invoice_date' :
80
-            $date_format = get_option( 'date_format' );
81
-            $time_format = get_option( 'time_format' );
82
-            $date_time_format = $date_format . ' '. $time_format;
80
+            $date_format = get_option('date_format');
81
+            $time_format = get_option('time_format');
82
+            $date_time_format = $date_format . ' ' . $time_format;
83 83
             
84
-            $t_time = get_the_time( $date_time_format );
84
+            $t_time = get_the_time($date_time_format);
85 85
             $m_time = $post->post_date;
86
-            $h_time = mysql2date( $date_format, $m_time );
86
+            $h_time = mysql2date($date_format, $m_time);
87 87
             
88 88
             $value   = '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';
89 89
             break;
90 90
         case 'status' :
91
-            $value   = $wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' );
91
+            $value   = $wpi_invoice->get_status(true) . ($wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '');
92 92
             break;
93 93
         case 'details' :
94
-            $edit_link = get_edit_post_link( $post->ID );
95
-            $value = '<a href="' . esc_url( $edit_link ) . '">' . __( 'View Invoice Details', 'invoicing' ) . '</a>';
94
+            $edit_link = get_edit_post_link($post->ID);
95
+            $value = '<a href="' . esc_url($edit_link) . '">' . __('View Invoice Details', 'invoicing') . '</a>';
96 96
             break;
97 97
         case 'wpi_actions' :
98 98
             $value = '';
99
-            if ( !empty( $post->post_name ) ) {
100
-                $value .= '<a title="' . esc_attr__( 'Print invoice', 'invoicing' ) . '" href="' . esc_url( get_permalink( $post->ID ) ) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
99
+            if (!empty($post->post_name)) {
100
+                $value .= '<a title="' . esc_attr__('Print invoice', 'invoicing') . '" href="' . esc_url(get_permalink($post->ID)) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
101 101
             }
102 102
             
103
-            if ( $email = $wpi_invoice->get_email() ) {
104
-                $value .= '<a title="' . esc_attr__( 'Send invoice to customer', 'invoicing' ) . '" href="' . esc_url( add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) ) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
103
+            if ($email = $wpi_invoice->get_email()) {
104
+                $value .= '<a title="' . esc_attr__('Send invoice to customer', 'invoicing') . '" href="' . esc_url(add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID))) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
105 105
             }
106 106
             
107 107
             break;
108 108
         default:
109
-            $value = isset( $post->$column_name ) ? $post->$column_name : '';
109
+            $value = isset($post->$column_name) ? $post->$column_name : '';
110 110
             break;
111 111
 
112 112
     }
113
-    $value = apply_filters( 'wpinv_payments_table_column', $value, $post->ID, $column_name );
113
+    $value = apply_filters('wpinv_payments_table_column', $value, $post->ID, $column_name);
114 114
     
115
-    if ( $value !== NULL ) {
115
+    if ($value !== NULL) {
116 116
         echo $value;
117 117
     }
118 118
 }
119 119
 
120
-function wpinv_admin_post_id( $id = 0 ) {
120
+function wpinv_admin_post_id($id = 0) {
121 121
     global $post;
122 122
 
123
-    if ( isset( $id ) && ! empty( $id ) ) {
123
+    if (isset($id) && !empty($id)) {
124 124
         return (int)$id;
125
-    } else if ( get_the_ID() ) {
126
-        return (int) get_the_ID();
127
-    } else if ( isset( $post->ID ) && !empty( $post->ID ) ) {
128
-        return (int) $post->ID;
129
-    } else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) {
130
-        return (int) $_GET['post'];
131
-    } else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) {
132
-        return (int) $_GET['id'];
133
-    } else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) {
134
-        return (int) $_POST['id'];
125
+    } else if (get_the_ID()) {
126
+        return (int)get_the_ID();
127
+    } else if (isset($post->ID) && !empty($post->ID)) {
128
+        return (int)$post->ID;
129
+    } else if (isset($_GET['post']) && !empty($_GET['post'])) {
130
+        return (int)$_GET['post'];
131
+    } else if (isset($_GET['id']) && !empty($_GET['id'])) {
132
+        return (int)$_GET['id'];
133
+    } else if (isset($_POST['id']) && !empty($_POST['id'])) {
134
+        return (int)$_POST['id'];
135 135
     } 
136 136
 
137 137
     return null;
138 138
 }
139 139
     
140
-function wpinv_admin_post_type( $id = 0 ) {
141
-    if ( !$id ) {
140
+function wpinv_admin_post_type($id = 0) {
141
+    if (!$id) {
142 142
         $id = wpinv_admin_post_id();
143 143
     }
144 144
     
145
-    $type = get_post_type( $id );
145
+    $type = get_post_type($id);
146 146
     
147
-    if ( !$type ) {
148
-        $type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null;
147
+    if (!$type) {
148
+        $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? $_GET['post_type'] : null;
149 149
     }
150 150
     
151
-    return apply_filters( 'wpinv_admin_post_type', $type, $id );
151
+    return apply_filters('wpinv_admin_post_type', $type, $id);
152 152
 }
153 153
 
154 154
 function wpinv_admin_messages() {
155 155
 	global $wpinv_options;
156 156
 
157
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
158
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' );
157
+	if (isset($_GET['wpinv-message']) && 'discount_added' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
158
+		 add_settings_error('wpinv-notices', 'wpinv-discount-added', __('Discount code added.', 'invoicing'), 'updated');
159 159
 	}
160 160
 
161
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
162
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' );
161
+	if (isset($_GET['wpinv-message']) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
162
+		add_settings_error('wpinv-notices', 'wpinv-discount-add-fail', __('There was a problem adding your discount code, please try again.', 'invoicing'), 'error');
163 163
 	}
164 164
 
165
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
166
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' );
165
+	if (isset($_GET['wpinv-message']) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
166
+		add_settings_error('wpinv-notices', 'wpinv-discount-exists', __('A discount with that code already exists, please use a different code.', 'invoicing'), 'error');
167 167
 	}
168 168
 
169
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
170
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' );
169
+	if (isset($_GET['wpinv-message']) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
170
+		 add_settings_error('wpinv-notices', 'wpinv-discount-updated', __('Discount code updated.', 'invoicing'), 'updated');
171 171
 	}
172 172
 
173
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
174
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' );
173
+	if (isset($_GET['wpinv-message']) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
174
+		add_settings_error('wpinv-notices', 'wpinv-discount-updated-fail', __('There was a problem updating your discount code, please try again.', 'invoicing'), 'error');
175 175
 	}
176 176
 
177
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
178
-		add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' );
177
+	if (isset($_GET['wpinv-message']) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
178
+		add_settings_error('wpinv-notices', 'wpinv-deleted', __('The invoice has been deleted.', 'invoicing'), 'updated');
179 179
 	}
180 180
 
181
-	if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
182
-		add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' );
181
+	if (isset($_GET['wpinv-message']) && 'email_sent' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
182
+		add_settings_error('wpinv-notices', 'wpinv-sent', __('The email has been sent to customer.', 'invoicing'), 'updated');
183 183
     }
184 184
     
185
-    if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
186
-		add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' );
185
+    if (isset($_GET['wpinv-message']) && 'email_fail' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
186
+		add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Fail to send email to the customer.', 'invoicing'), 'error');
187 187
     }
188 188
 
189
-    if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
190
-        add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' );
189
+    if (isset($_GET['wpinv-message']) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
190
+        add_settings_error('wpinv-notices', 'wpinv-note-deleted', __('The invoice note has been deleted.', 'invoicing'), 'updated');
191 191
     }
192 192
 
193
-	if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
194
-		add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' );
193
+	if (isset($_GET['wpinv-message']) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
194
+		add_settings_error('wpinv-notices', 'wpinv-settings-imported', __('The settings have been imported.', 'invoicing'), 'updated');
195 195
 	}
196 196
 
197
-	if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
198
-		add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' );
197
+	if (isset($_GET['wpinv-message']) && 'note-added' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
198
+		add_settings_error('wpinv-notices', 'wpinv-note-added', __('The invoice note has been added successfully.', 'invoicing'), 'updated');
199 199
 	}
200 200
 
201
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
202
-		add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' );
201
+	if (isset($_GET['wpinv-message']) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
202
+		add_settings_error('wpinv-notices', 'wpinv-updated', __('The invoice has been successfully updated.', 'invoicing'), 'updated');
203 203
 	}
204 204
 
205
-	settings_errors( 'wpinv-notices' );
205
+	settings_errors('wpinv-notices');
206 206
 }
207
-add_action( 'admin_notices', 'wpinv_admin_messages' );
207
+add_action('admin_notices', 'wpinv_admin_messages');
208 208
 
209
-function wpinv_items_columns( $existing_columns ) {
209
+function wpinv_items_columns($existing_columns) {
210 210
     global $wpinv_euvat;
211 211
     
212 212
     $columns                = array();
213 213
     $columns['cb']          = $existing_columns['cb'];
214
-    $columns['title']       = __( 'Title', 'invoicing' );
215
-    $columns['price']       = __( 'Price', 'invoicing' );
216
-    if ( $wpinv_euvat->allow_vat_rules() ) {
217
-        $columns['vat_rule']    = __( 'VAT rule type', 'invoicing' );
214
+    $columns['title']       = __('Title', 'invoicing');
215
+    $columns['price']       = __('Price', 'invoicing');
216
+    if ($wpinv_euvat->allow_vat_rules()) {
217
+        $columns['vat_rule']    = __('VAT rule type', 'invoicing');
218 218
     }
219
-    if ( $wpinv_euvat->allow_vat_classes() ) {
220
-        $columns['vat_class']   = __( 'VAT class', 'invoicing' );
219
+    if ($wpinv_euvat->allow_vat_classes()) {
220
+        $columns['vat_class']   = __('VAT class', 'invoicing');
221 221
     }
222
-    $columns['type']        = __( 'Type', 'invoicing' );
223
-    $columns['recurring']   = __( 'Recurring', 'invoicing' );
224
-    $columns['date']        = __( 'Date', 'invoicing' );
225
-    $columns['id']          = __( 'ID', 'invoicing' );
222
+    $columns['type']        = __('Type', 'invoicing');
223
+    $columns['recurring']   = __('Recurring', 'invoicing');
224
+    $columns['date']        = __('Date', 'invoicing');
225
+    $columns['id']          = __('ID', 'invoicing');
226 226
 
227
-    return apply_filters( 'wpinv_items_columns', $columns );
227
+    return apply_filters('wpinv_items_columns', $columns);
228 228
 }
229
-add_filter( 'manage_wpi_item_posts_columns', 'wpinv_items_columns' );
229
+add_filter('manage_wpi_item_posts_columns', 'wpinv_items_columns');
230 230
 
231
-function wpinv_items_sortable_columns( $columns ) {
231
+function wpinv_items_sortable_columns($columns) {
232 232
     $columns['price']       = 'price';
233 233
     $columns['vat_rule']    = 'vat_rule';
234 234
     $columns['vat_class']   = 'vat_class';
@@ -238,10 +238,10 @@  discard block
 block discarded – undo
238 238
 
239 239
     return $columns;
240 240
 }
241
-add_filter( 'manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns' );
241
+add_filter('manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns');
242 242
 
243
-function wpinv_item_quick_edit( $column_name, $post_type ) {
244
-    if ( !( $post_type == 'wpi_item' && $column_name == 'price' ) ) {
243
+function wpinv_item_quick_edit($column_name, $post_type) {
244
+    if (!($post_type == 'wpi_item' && $column_name == 'price')) {
245 245
         return;
246 246
     }
247 247
     global $wpinv_euvat, $post;
@@ -249,23 +249,23 @@  discard block
 block discarded – undo
249 249
     $symbol    = wpinv_currency_symbol();
250 250
     $position  = wpinv_currency_position();
251 251
 
252
-    $price     = wpinv_get_item_price( $post->ID );
253
-    $item_type = wpinv_get_item_type( $post->ID );
252
+    $price     = wpinv_get_item_price($post->ID);
253
+    $item_type = wpinv_get_item_type($post->ID);
254 254
     ?>
255 255
     <fieldset class="inline-edit-col-right wpi-inline-item-col">
256 256
         <div class="inline-edit-col">
257 257
             <div class="inline-edit-group wp-clearfix">
258 258
                 <label class="inline-edit-wpinv-price">
259
-                    <span class="title"><?php _e( 'Item price', 'invoicing' );?></span>
260
-                    <span class="input-text-wrap"><?php echo ( $position != 'right' ? $symbol . '&nbsp;' : '' );?><input type="text" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" name="_wpinv_item_price" class="wpi-field-price wpi-price" id="wpinv_item_price-<?php echo $post->ID;?>"><?php echo ( $position == 'right' ? $symbol . '&nbsp;' : '' );?></span>
259
+                    <span class="title"><?php _e('Item price', 'invoicing'); ?></span>
260
+                    <span class="input-text-wrap"><?php echo ($position != 'right' ? $symbol . '&nbsp;' : ''); ?><input type="text" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" name="_wpinv_item_price" class="wpi-field-price wpi-price" id="wpinv_item_price-<?php echo $post->ID; ?>"><?php echo ($position == 'right' ? $symbol . '&nbsp;' : ''); ?></span>
261 261
                 </label>
262 262
             </div>
263
-            <?php if ( $wpinv_euvat->allow_vat_rules() ) { $rule_type = $wpinv_euvat->get_item_rule( $post->ID ); ?>
263
+            <?php if ($wpinv_euvat->allow_vat_rules()) { $rule_type = $wpinv_euvat->get_item_rule($post->ID); ?>
264 264
             <div class="inline-edit-group wp-clearfix">
265 265
                 <label class="inline-edit-wpinv-vat-rate">
266
-                    <span class="title"><?php _e( 'VAT rule type to use', 'invoicing' );?></span>
266
+                    <span class="title"><?php _e('VAT rule type to use', 'invoicing'); ?></span>
267 267
                     <span class="input-text-wrap">
268
-                        <?php echo wpinv_html_select( array(
268
+                        <?php echo wpinv_html_select(array(
269 269
                             'options'          => $wpinv_euvat->get_rules(),
270 270
                             'name'             => '_wpinv_vat_rules',
271 271
                             'id'               => 'wpinv_vat_rules-' . $post->ID,
@@ -273,16 +273,16 @@  discard block
 block discarded – undo
273 273
                             'show_option_all'  => false,
274 274
                             'show_option_none' => false,
275 275
                             'class'            => 'gdmbx2-text-medium wpinv-vat-rules',
276
-                        ) ); ?>
276
+                        )); ?>
277 277
                     </span>
278 278
                 </label>
279 279
             </div>
280
-            <?php } if ( $wpinv_euvat->allow_vat_classes() ) { $vat_class = $wpinv_euvat->get_item_class( $post->ID ); ?>
280
+            <?php } if ($wpinv_euvat->allow_vat_classes()) { $vat_class = $wpinv_euvat->get_item_class($post->ID); ?>
281 281
             <div class="inline-edit-group wp-clearfix">
282 282
                 <label class="inline-edit-wpinv-vat-class">
283
-                    <span class="title"><?php _e( 'VAT class to use', 'invoicing' );?></span>
283
+                    <span class="title"><?php _e('VAT class to use', 'invoicing'); ?></span>
284 284
                     <span class="input-text-wrap">
285
-                        <?php echo wpinv_html_select( array(
285
+                        <?php echo wpinv_html_select(array(
286 286
                             'options'          => $wpinv_euvat->get_all_classes(),
287 287
                             'name'             => '_wpinv_vat_class',
288 288
                             'id'               => 'wpinv_vat_class-' . $post->ID,
@@ -290,16 +290,16 @@  discard block
 block discarded – undo
290 290
                             'show_option_all'  => false,
291 291
                             'show_option_none' => false,
292 292
                             'class'            => 'gdmbx2-text-medium wpinv-vat-class',
293
-                        ) ); ?>
293
+                        )); ?>
294 294
                     </span>
295 295
                 </label>
296 296
             </div>
297 297
             <?php } ?>
298 298
             <div class="inline-edit-group wp-clearfix">
299 299
                 <label class="inline-edit-wpinv-type">
300
-                    <span class="title"><?php _e( 'Item type', 'invoicing' );?></span>
300
+                    <span class="title"><?php _e('Item type', 'invoicing'); ?></span>
301 301
                     <span class="input-text-wrap">
302
-                        <?php echo wpinv_html_select( array(
302
+                        <?php echo wpinv_html_select(array(
303 303
                             'options'          => wpinv_get_item_types(),
304 304
                             'name'             => '_wpinv_item_type',
305 305
                             'id'               => 'wpinv_item_type-' . $post->ID,
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
                             'show_option_all'  => false,
308 308
                             'show_option_none' => false,
309 309
                             'class'            => 'gdmbx2-text-medium wpinv-item-type',
310
-                        ) ); ?>
310
+                        )); ?>
311 311
                     </span>
312 312
                 </label>
313 313
             </div>
@@ -315,150 +315,150 @@  discard block
 block discarded – undo
315 315
     </fieldset>
316 316
     <?php
317 317
 }
318
-add_action( 'quick_edit_custom_box', 'wpinv_item_quick_edit', 10, 2 );
319
-add_action( 'bulk_edit_custom_box', 'wpinv_item_quick_edit', 10, 2 );
318
+add_action('quick_edit_custom_box', 'wpinv_item_quick_edit', 10, 2);
319
+add_action('bulk_edit_custom_box', 'wpinv_item_quick_edit', 10, 2);
320 320
 
321
-function wpinv_items_table_custom_column( $column ) {
321
+function wpinv_items_table_custom_column($column) {
322 322
     global $wpinv_euvat, $post, $wpi_item;
323 323
     
324
-    if ( empty( $wpi_item ) || ( !empty( $wpi_item ) && $post->ID != $wpi_item->ID ) ) {
325
-        $wpi_item = new WPInv_Item( $post->ID );
324
+    if (empty($wpi_item) || (!empty($wpi_item) && $post->ID != $wpi_item->ID)) {
325
+        $wpi_item = new WPInv_Item($post->ID);
326 326
     }
327 327
 
328
-    switch ( $column ) {
328
+    switch ($column) {
329 329
         case 'price' :
330
-            echo wpinv_item_price( $post->ID );
330
+            echo wpinv_item_price($post->ID);
331 331
         break;
332 332
         case 'vat_rule' :
333
-            echo $wpinv_euvat->item_rule_label( $post->ID );
333
+            echo $wpinv_euvat->item_rule_label($post->ID);
334 334
         break;
335 335
         case 'vat_class' :
336
-            echo $wpinv_euvat->item_class_label( $post->ID );
336
+            echo $wpinv_euvat->item_class_label($post->ID);
337 337
         break;
338 338
         case 'type' :
339
-            echo wpinv_item_type( $post->ID ) . '<span class="meta">' . $wpi_item->get_cpt_singular_name() . '</span>';
339
+            echo wpinv_item_type($post->ID) . '<span class="meta">' . $wpi_item->get_cpt_singular_name() . '</span>';
340 340
         break;
341 341
         case 'recurring' :
342
-            echo ( wpinv_is_recurring_item( $post->ID ) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>' );
342
+            echo (wpinv_is_recurring_item($post->ID) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>');
343 343
         break;
344 344
         case 'id' :
345 345
            echo $post->ID;
346 346
            echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '">
347
-                    <div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>';
348
-                    if ( $wpinv_euvat->allow_vat_rules() ) {
349
-                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</div>';
347
+                    <div class="price">' . wpinv_get_item_price($post->ID) . '</div>';
348
+                    if ($wpinv_euvat->allow_vat_rules()) {
349
+                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule($post->ID) . '</div>';
350 350
                     }
351
-                    if ( $wpinv_euvat->allow_vat_classes() ) {
352
-                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class( $post->ID ) . '</div>';
351
+                    if ($wpinv_euvat->allow_vat_classes()) {
352
+                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class($post->ID) . '</div>';
353 353
                     }
354
-                    echo '<div class="type">' . wpinv_get_item_type( $post->ID ) . '</div>
354
+                    echo '<div class="type">' . wpinv_get_item_type($post->ID) . '</div>
355 355
                 </div>';
356 356
         break;
357 357
     }
358 358
     
359
-    do_action( 'wpinv_items_table_column_item_' . $column, $wpi_item, $post );
359
+    do_action('wpinv_items_table_column_item_' . $column, $wpi_item, $post);
360 360
 }
361
-add_action( 'manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column' );
361
+add_action('manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column');
362 362
 
363 363
 function wpinv_add_items_filters() {
364 364
     global $wpinv_euvat, $typenow;
365 365
 
366 366
     // Checks if the current post type is 'item'
367
-    if ( $typenow == 'wpi_item') {
368
-        if ( $wpinv_euvat->allow_vat_rules() ) {
369
-            echo wpinv_html_select( array(
370
-                    'options'          => array_merge( array( '' => __( 'All VAT rules', 'invoicing' ) ), $wpinv_euvat->get_rules() ),
367
+    if ($typenow == 'wpi_item') {
368
+        if ($wpinv_euvat->allow_vat_rules()) {
369
+            echo wpinv_html_select(array(
370
+                    'options'          => array_merge(array('' => __('All VAT rules', 'invoicing')), $wpinv_euvat->get_rules()),
371 371
                     'name'             => 'vat_rule',
372 372
                     'id'               => 'vat_rule',
373
-                    'selected'         => ( isset( $_GET['vat_rule'] ) ? $_GET['vat_rule'] : '' ),
373
+                    'selected'         => (isset($_GET['vat_rule']) ? $_GET['vat_rule'] : ''),
374 374
                     'show_option_all'  => false,
375 375
                     'show_option_none' => false,
376 376
                     'class'            => 'gdmbx2-text-medium',
377
-                ) );
377
+                ));
378 378
         }
379 379
         
380
-        if ( $wpinv_euvat->allow_vat_classes() ) {
381
-            echo wpinv_html_select( array(
382
-                    'options'          => array_merge( array( '' => __( 'All VAT classes', 'invoicing' ) ), $wpinv_euvat->get_all_classes() ),
380
+        if ($wpinv_euvat->allow_vat_classes()) {
381
+            echo wpinv_html_select(array(
382
+                    'options'          => array_merge(array('' => __('All VAT classes', 'invoicing')), $wpinv_euvat->get_all_classes()),
383 383
                     'name'             => 'vat_class',
384 384
                     'id'               => 'vat_class',
385
-                    'selected'         => ( isset( $_GET['vat_class'] ) ? $_GET['vat_class'] : '' ),
385
+                    'selected'         => (isset($_GET['vat_class']) ? $_GET['vat_class'] : ''),
386 386
                     'show_option_all'  => false,
387 387
                     'show_option_none' => false,
388 388
                     'class'            => 'gdmbx2-text-medium',
389
-                ) );
389
+                ));
390 390
         }
391 391
             
392
-        echo wpinv_html_select( array(
393
-                'options'          => array_merge( array( '' => __( 'All item types', 'invoicing' ) ), wpinv_get_item_types() ),
392
+        echo wpinv_html_select(array(
393
+                'options'          => array_merge(array('' => __('All item types', 'invoicing')), wpinv_get_item_types()),
394 394
                 'name'             => 'type',
395 395
                 'id'               => 'type',
396
-                'selected'         => ( isset( $_GET['type'] ) ? $_GET['type'] : '' ),
396
+                'selected'         => (isset($_GET['type']) ? $_GET['type'] : ''),
397 397
                 'show_option_all'  => false,
398 398
                 'show_option_none' => false,
399 399
                 'class'            => 'gdmbx2-text-medium',
400
-            ) );
400
+            ));
401 401
 
402
-        if ( isset( $_REQUEST['all_posts'] ) && '1' === $_REQUEST['all_posts'] ) {
402
+        if (isset($_REQUEST['all_posts']) && '1' === $_REQUEST['all_posts']) {
403 403
             echo '<input type="hidden" name="all_posts" value="1" />';
404 404
         }
405 405
     }
406 406
 }
407
-add_action( 'restrict_manage_posts', 'wpinv_add_items_filters', 100 );
407
+add_action('restrict_manage_posts', 'wpinv_add_items_filters', 100);
408 408
 
409
-function wpinv_send_invoice_after_save( $post_id ) {
409
+function wpinv_send_invoice_after_save($post_id) {
410 410
     // If this is just a revision, don't send the email.
411
-    if ( wp_is_post_revision( $post_id ) ) {
411
+    if (wp_is_post_revision($post_id)) {
412 412
         return;
413 413
     }
414 414
     
415
-    if ( !current_user_can( 'manage_options' ) || !(get_post_type( $post_id ) == 'wpi_invoice' || get_post_type( $post_id ) == 'wpi_quote')  ) {
415
+    if (!current_user_can('manage_options') || !(get_post_type($post_id) == 'wpi_invoice' || get_post_type($post_id) == 'wpi_quote')) {
416 416
         return;
417 417
     }
418 418
     
419
-    if ( !empty( $_POST['wpi_save_send'] ) ) {
420
-        wpinv_user_invoice_notification( $post_id );
419
+    if (!empty($_POST['wpi_save_send'])) {
420
+        wpinv_user_invoice_notification($post_id);
421 421
     }
422 422
 }
423
-add_action( 'save_post_wpi_invoice', 'wpinv_send_invoice_after_save', 100, 1 );
423
+add_action('save_post_wpi_invoice', 'wpinv_send_invoice_after_save', 100, 1);
424 424
 
425
-function wpinv_send_register_new_user( $data, $postarr ) {
426
-    if ( current_user_can( 'manage_options' ) && !empty( $data['post_type'] ) && $data['post_type'] == 'wpi_invoice' ) {
427
-        $is_new_user = !empty( $postarr['wpinv_new_user'] ) ? true : false;
428
-        $email = !empty( $postarr['wpinv_email'] ) && $postarr['wpinv_email'] && is_email( $postarr['wpinv_email'] ) ? $postarr['wpinv_email'] : NULL;
425
+function wpinv_send_register_new_user($data, $postarr) {
426
+    if (current_user_can('manage_options') && !empty($data['post_type']) && $data['post_type'] == 'wpi_invoice') {
427
+        $is_new_user = !empty($postarr['wpinv_new_user']) ? true : false;
428
+        $email = !empty($postarr['wpinv_email']) && $postarr['wpinv_email'] && is_email($postarr['wpinv_email']) ? $postarr['wpinv_email'] : NULL;
429 429
         
430
-        if ( $is_new_user && $email && !email_exists( $email ) ) {
431
-            $first_name = !empty( $postarr['wpinv_first_name'] ) ? sanitize_text_field( $postarr['wpinv_first_name'] ) : '';
432
-            $last_name = !empty( $postarr['wpinv_last_name'] ) ? sanitize_text_field( $postarr['wpinv_last_name'] ) : '';
433
-            $display_name = $first_name || $last_name ? trim( $first_name . ' ' . $last_name ) : '';
434
-            $user_nicename = $display_name ? trim( $display_name ) : $email;
435
-            $user_company = !empty( $postarr['wpinv_company'] ) ? sanitize_text_field( $postarr['wpinv_company'] ) : '';
430
+        if ($is_new_user && $email && !email_exists($email)) {
431
+            $first_name = !empty($postarr['wpinv_first_name']) ? sanitize_text_field($postarr['wpinv_first_name']) : '';
432
+            $last_name = !empty($postarr['wpinv_last_name']) ? sanitize_text_field($postarr['wpinv_last_name']) : '';
433
+            $display_name = $first_name || $last_name ? trim($first_name . ' ' . $last_name) : '';
434
+            $user_nicename = $display_name ? trim($display_name) : $email;
435
+            $user_company = !empty($postarr['wpinv_company']) ? sanitize_text_field($postarr['wpinv_company']) : '';
436 436
             
437
-            $user_login = sanitize_user( str_replace( ' ', '', $display_name ), true );
438
-            if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
439
-                $user_login = sanitize_user( str_replace( ' ', '', $user_company ), true );
437
+            $user_login = sanitize_user(str_replace(' ', '', $display_name), true);
438
+            if (!(validate_username($user_login) && !username_exists($user_login))) {
439
+                $user_login = sanitize_user(str_replace(' ', '', $user_company), true);
440 440
                 
441
-                if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
441
+                if (!(validate_username($user_login) && !username_exists($user_login))) {
442 442
                     $user_login = $email;
443 443
                 }
444 444
             }
445 445
             
446 446
             $userdata = array(
447 447
                 'user_login' => $user_login,
448
-                'user_pass' => wp_generate_password( 12, false ),
449
-                'user_email' => sanitize_text_field( $email ),
448
+                'user_pass' => wp_generate_password(12, false),
449
+                'user_email' => sanitize_text_field($email),
450 450
                 'first_name' => $first_name,
451 451
                 'last_name' => $last_name,
452
-                'user_nicename' => wpinv_utf8_substr( $user_nicename, 0, 50 ),
452
+                'user_nicename' => wpinv_utf8_substr($user_nicename, 0, 50),
453 453
                 'nickname' => $display_name,
454 454
                 'display_name' => $display_name,
455 455
             );
456 456
 
457
-            $userdata = apply_filters( 'wpinv_register_new_user_data', $userdata );
457
+            $userdata = apply_filters('wpinv_register_new_user_data', $userdata);
458 458
             
459
-            $new_user_id = wp_insert_user( $userdata );
459
+            $new_user_id = wp_insert_user($userdata);
460 460
             
461
-            if ( !is_wp_error( $new_user_id ) ) {
461
+            if (!is_wp_error($new_user_id)) {
462 462
                 $data['post_author'] = $new_user_id;
463 463
                 $_POST['post_author'] = $new_user_id;
464 464
                 $_POST['post_author_override'] = $new_user_id;
@@ -479,27 +479,27 @@  discard block
 block discarded – undo
479 479
                 
480 480
                 $meta = array();
481 481
                 ///$meta['_wpinv_user_id'] = $new_user_id;
482
-                foreach ( $meta_fields as $field ) {
483
-                    $meta['_wpinv_' . $field] = isset( $postarr['wpinv_' . $field] ) ? sanitize_text_field( $postarr['wpinv_' . $field] ) : '';
482
+                foreach ($meta_fields as $field) {
483
+                    $meta['_wpinv_' . $field] = isset($postarr['wpinv_' . $field]) ? sanitize_text_field($postarr['wpinv_' . $field]) : '';
484 484
                 }
485 485
                 
486
-                $meta = apply_filters( 'wpinv_register_new_user_meta', $meta, $new_user_id );
486
+                $meta = apply_filters('wpinv_register_new_user_meta', $meta, $new_user_id);
487 487
 
488 488
                 // Update user meta.
489
-                foreach ( $meta as $key => $value ) {
490
-                    update_user_meta( $new_user_id, $key, $value );
489
+                foreach ($meta as $key => $value) {
490
+                    update_user_meta($new_user_id, $key, $value);
491 491
                 }
492 492
                 
493
-                if ( function_exists( 'wp_send_new_user_notifications' ) ) {
493
+                if (function_exists('wp_send_new_user_notifications')) {
494 494
                     // Send email notifications related to the creation of new user.
495
-                    wp_send_new_user_notifications( $new_user_id, 'user' );
495
+                    wp_send_new_user_notifications($new_user_id, 'user');
496 496
                 }
497 497
             } else {
498
-                wpinv_error_log( $new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__ );
498
+                wpinv_error_log($new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__);
499 499
             }
500 500
         }
501 501
     }
502 502
     
503 503
     return $data;
504 504
 }
505
-add_filter( 'wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2 );
506 505
\ No newline at end of file
506
+add_filter('wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2);
507 507
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-mb-invoice-items.php 1 patch
Spacing   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -1,22 +1,22 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 class WPInv_Meta_Box_Items {
8
-    public static function output( $post ) {        
8
+    public static function output($post) {        
9 9
         global $wpinv_euvat, $ajax_cart_details;
10 10
         
11
-        $post_id            = !empty( $post->ID ) ? $post->ID : 0;
12
-        $invoice            = new WPInv_Invoice( $post_id );
11
+        $post_id            = !empty($post->ID) ? $post->ID : 0;
12
+        $invoice            = new WPInv_Invoice($post_id);
13 13
         $ajax_cart_details  = $invoice->get_cart_details();
14
-        $subtotal           = $invoice->get_subtotal( true );
14
+        $subtotal           = $invoice->get_subtotal(true);
15 15
         $discount_raw       = $invoice->get_discount();
16
-        $discount           = wpinv_price( $discount_raw, $invoice->get_currency() );
16
+        $discount           = wpinv_price($discount_raw, $invoice->get_currency());
17 17
         $discounts          = $discount_raw > 0 ? $invoice->get_discounts() : '';
18
-        $tax                = $invoice->get_tax( true );
19
-        $total              = $invoice->get_total( true );
18
+        $tax                = $invoice->get_tax(true);
19
+        $total              = $invoice->get_total(true);
20 20
         $item_quantities    = wpinv_item_quantities_enabled();
21 21
         $use_taxes          = wpinv_use_taxes();
22 22
         $item_types         = wpinv_get_item_types();
@@ -29,17 +29,17 @@  discard block
 block discarded – undo
29 29
         }
30 30
         
31 31
         $cols = 5;
32
-        if ( $item_quantities ) {
32
+        if ($item_quantities) {
33 33
             $cols++;
34 34
         }
35
-        if ( $use_taxes ) {
35
+        if ($use_taxes) {
36 36
             $cols++;
37 37
         }
38 38
         $class = '';
39
-        if ( $invoice->is_paid() ) {
39
+        if ($invoice->is_paid()) {
40 40
             $class .= ' wpinv-paid';
41 41
         }
42
-        if ( $is_recurring ) {
42
+        if ($is_recurring) {
43 43
             $class .= ' wpi-recurring';
44 44
         }
45 45
         ?>
@@ -47,21 +47,21 @@  discard block
 block discarded – undo
47 47
             <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0">
48 48
                 <thead>
49 49
                     <tr>
50
-                        <th class="id"><?php _e( 'ID', 'invoicing' );?></th>
51
-                        <th class="title"><?php _e( 'Item', 'invoicing' );?></th>
52
-                        <th class="price"><?php _e( 'Price', 'invoicing' );?></th>
53
-                        <?php if ( $item_quantities ) { ?>
54
-                        <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th>
50
+                        <th class="id"><?php _e('ID', 'invoicing'); ?></th>
51
+                        <th class="title"><?php _e('Item', 'invoicing'); ?></th>
52
+                        <th class="price"><?php _e('Price', 'invoicing'); ?></th>
53
+                        <?php if ($item_quantities) { ?>
54
+                        <th class="qty"><?php _e('Qty', 'invoicing'); ?></th>
55 55
                         <?php } ?>
56
-                        <th class="total"><?php _e( 'Total', 'invoicing' );?></th>
57
-                        <?php if ( $use_taxes ) { ?>
58
-                        <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th>
56
+                        <th class="total"><?php _e('Total', 'invoicing'); ?></th>
57
+                        <?php if ($use_taxes) { ?>
58
+                        <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th>
59 59
                         <?php } ?>
60 60
                         <th class="action"></th>
61 61
                     </tr>
62 62
                 </thead>
63 63
                 <tbody class="wpinv-line-items">
64
-                    <?php echo wpinv_admin_get_line_items( $invoice ); ?>
64
+                    <?php echo wpinv_admin_get_line_items($invoice); ?>
65 65
                 </tbody>
66 66
                 <tfoot class="wpinv-totals">
67 67
                     <tr>
@@ -73,44 +73,44 @@  discard block
 block discarded – undo
73 73
                                         </td>
74 74
                                         <td class="title">
75 75
                                             <input type="text" class="regular-text" placeholder="Item name" value="" name="_wpinv_quick[name]">
76
-                                            <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?>
76
+                                            <?php if ($wpinv_euvat->allow_vat_rules()) { ?>
77 77
                                             <div class="wp-clearfix">
78 78
                                                 <label class="wpi-vat-rule">
79
-                                                    <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span>
79
+                                                    <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span>
80 80
                                                     <span class="input-text-wrap">
81
-                                                        <?php echo wpinv_html_select( array(
81
+                                                        <?php echo wpinv_html_select(array(
82 82
                                                             'options'          => $wpinv_euvat->get_rules(),
83 83
                                                             'name'             => '_wpinv_quick[vat_rule]',
84 84
                                                             'id'               => '_wpinv_quick_vat_rule',
85 85
                                                             'show_option_all'  => false,
86 86
                                                             'show_option_none' => false,
87 87
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-rule',
88
-                                                        ) ); ?>
88
+                                                        )); ?>
89 89
                                                     </span>
90 90
                                                 </label>
91 91
                                             </div>
92
-                                            <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?>
92
+                                            <?php } if ($wpinv_euvat->allow_vat_classes()) { ?>
93 93
                                             <div class="wp-clearfix">
94 94
                                                 <label class="wpi-vat-class">
95
-                                                    <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span>
95
+                                                    <span class="title"><?php _e('VAT class', 'invoicing'); ?></span>
96 96
                                                     <span class="input-text-wrap">
97
-                                                        <?php echo wpinv_html_select( array(
97
+                                                        <?php echo wpinv_html_select(array(
98 98
                                                             'options'          => $wpinv_euvat->get_all_classes(),
99 99
                                                             'name'             => '_wpinv_quick[vat_class]',
100 100
                                                             'id'               => '_wpinv_quick_vat_class',
101 101
                                                             'show_option_all'  => false,
102 102
                                                             'show_option_none' => false,
103 103
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-class',
104
-                                                        ) ); ?>
104
+                                                        )); ?>
105 105
                                                     </span>
106 106
                                                 </label>
107 107
                                             </div>
108 108
                                             <?php } ?>
109 109
                                             <div class="wp-clearfix">
110 110
                                                 <label class="wpi-item-type">
111
-                                                    <span class="title"><?php _e( 'Item type', 'invoicing' );?></span>
111
+                                                    <span class="title"><?php _e('Item type', 'invoicing'); ?></span>
112 112
                                                     <span class="input-text-wrap">
113
-                                                        <?php echo wpinv_html_select( array(
113
+                                                        <?php echo wpinv_html_select(array(
114 114
                                                             'options'          => $item_types,
115 115
                                                             'name'             => '_wpinv_quick[type]',
116 116
                                                             'id'               => '_wpinv_quick_type',
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
                                                             'show_option_all'  => false,
119 119
                                                             'show_option_none' => false,
120 120
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-type',
121
-                                                        ) ); ?>
121
+                                                        )); ?>
122 122
                                                     </span>
123 123
                                                 </label>
124 124
                                             </div>
@@ -131,11 +131,11 @@  discard block
 block discarded – undo
131 131
                                             </div>
132 132
                                         </td>
133 133
                                         <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td>
134
-                                        <?php if ( $item_quantities ) { ?>
134
+                                        <?php if ($item_quantities) { ?>
135 135
                                         <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td>
136 136
                                         <?php } ?>
137 137
                                         <td class="total"></td>
138
-                                        <?php if ( $use_taxes ) { ?>
138
+                                        <?php if ($use_taxes) { ?>
139 139
                                         <td class="tax"></td>
140 140
                                         <?php } ?>
141 141
                                         <td class="action"></td>
@@ -148,29 +148,29 @@  discard block
 block discarded – undo
148 148
                         <td colspan="<?php echo $cols; ?>"></td>
149 149
                     </tr>
150 150
                     <tr class="totals">
151
-                        <td colspan="<?php echo ( $cols - 4 ); ?>"></td>
151
+                        <td colspan="<?php echo ($cols - 4); ?>"></td>
152 152
                         <td colspan="4">
153 153
                             <table cellspacing="0" cellpadding="0">
154 154
                                 <tr class="subtotal">
155
-                                    <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td>
156
-                                    <td class="total"><?php echo $subtotal;?></td>
155
+                                    <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td>
156
+                                    <td class="total"><?php echo $subtotal; ?></td>
157 157
                                     <td class="action"></td>
158 158
                                 </tr>
159 159
                                 <tr class="discount">
160
-                                    <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td>
161
-                                    <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td>
160
+                                    <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td>
161
+                                    <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td>
162 162
                                     <td class="action"></td>
163 163
                                 </tr>
164
-                                <?php if ( $use_taxes ) { ?>
164
+                                <?php if ($use_taxes) { ?>
165 165
                                 <tr class="tax">
166
-                                    <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td>
167
-                                    <td class="total"><?php echo $tax;?></td>
166
+                                    <td class="name"><?php _e('Tax:', 'invoicing'); ?></td>
167
+                                    <td class="total"><?php echo $tax; ?></td>
168 168
                                     <td class="action"></td>
169 169
                                 </tr>
170 170
                                 <?php } ?>
171 171
                                 <tr class="total">
172
-                                    <td class="name"><?php _e( 'Invoice Total:', 'invoicing' );?></td>
173
-                                    <td class="total"><?php echo $total;?></td>
172
+                                    <td class="name"><?php _e('Invoice Total:', 'invoicing'); ?></td>
173
+                                    <td class="total"><?php echo $total; ?></td>
174 174
                                     <td class="action"></td>
175 175
                                 </tr>
176 176
                             </table>
@@ -180,89 +180,89 @@  discard block
 block discarded – undo
180 180
             </table>
181 181
             <div class="wpinv-actions">
182 182
                 <?php
183
-                    if ( !$invoice->is_paid() ) {
184
-                    if ( !$invoice->is_recurring() ) {
185
-                    echo wpinv_item_dropdown( array(
183
+                    if (!$invoice->is_paid()) {
184
+                    if (!$invoice->is_recurring()) {
185
+                    echo wpinv_item_dropdown(array(
186 186
                         'name'             => 'wpinv_invoice_item',
187 187
                         'id'               => 'wpinv_invoice_item',
188 188
                         'with_packages'    => false,
189 189
                         'show_recurring'   => true,
190
-                    ) );
190
+                    ));
191 191
                     ?>
192
-                <input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
192
+                <input type="button" value="<?php echo sprintf(esc_attr__('Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e('Create new item', 'invoicing'); ?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e('Recalculate Totals', 'invoicing'); ?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
193 193
                     <?php } ?>
194
-                <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?>
194
+                <?php do_action('wpinv_invoice_items_actions', $invoice); ?>
195 195
             </div>
196 196
         </div>
197 197
         <?php
198 198
     }
199 199
     
200
-    public static function prices( $post ) {        
200
+    public static function prices($post) {        
201 201
         $symbol         = wpinv_currency_symbol();
202 202
         $position       = wpinv_currency_position();
203
-        $item           = new WPInv_Item( $post->ID );
203
+        $item           = new WPInv_Item($post->ID);
204 204
         
205 205
         $price          = $item->get_price();
206 206
         $is_recurring   = $item->is_recurring();
207 207
         $period         = $item->get_recurring_period();
208
-        $interval       = absint( $item->get_recurring_interval() );
209
-        $times          = absint( $item->get_recurring_limit() );
208
+        $interval       = absint($item->get_recurring_interval());
209
+        $times          = absint($item->get_recurring_limit());
210 210
         $free_trial     = $item->has_free_trial();
211 211
         $trial_interval = $item->get_trial_interval();
212 212
         $trial_period   = $item->get_trial_period();
213 213
         
214 214
         $intervals      = array();
215
-        for ( $i = 1; $i <= 90; $i++ ) {
215
+        for ($i = 1; $i <= 90; $i++) {
216 216
             $intervals[$i] = $i;
217 217
         }
218 218
         
219
-        $interval       = $interval > 0 ? $interval : 1;
219
+        $interval = $interval > 0 ? $interval : 1;
220 220
         
221 221
         $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n';
222 222
         ?>
223
-        <p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . '&nbsp;' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled( $item->is_package(), true ); ?> /><?php echo ( $position == 'right' ? '&nbsp;' . $symbol : '' );?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce( 'wpinv_item_meta_box_save' ) ;?>" />
224
-        <?php if ( $item->is_package() ) { ?>
225
-        <span class="description"><?php _e( 'GD package item price can be edited only from GD payment manager.', 'invoicing' ); ?></span>
223
+        <p class="wpinv-row-prices"><?php echo ($position != 'right' ? $symbol . '&nbsp;' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled($item->is_package(), true); ?> /><?php echo ($position == 'right' ? '&nbsp;' . $symbol : ''); ?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce('wpinv_item_meta_box_save'); ?>" />
224
+        <?php if ($item->is_package()) { ?>
225
+        <span class="description"><?php _e('GD package item price can be edited only from GD payment manager.', 'invoicing'); ?></span>
226 226
         <?php } ?>
227 227
         </p>
228 228
         <p class="wpinv-row-is-recurring">
229 229
             <label for="wpinv_is_recurring">
230
-                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> />
231
-                <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?>
230
+                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> />
231
+                <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?>
232 232
             </label>
233 233
         </p>
234
-        <p class="wpinv-row-recurring-fields <?php echo $class;?>">
235
-                <label class="wpinv-period" for="wpinv_recurring_period"><?php _e( 'Recurring', 'invoicing' );?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e( 'day(s)', 'invoicing' ); ?>" <?php selected( 'D', $period );?>><?php _e( 'Daily', 'invoicing' ); ?></option><option value="W" data-text="<?php esc_attr_e( 'week(s)', 'invoicing' ); ?>" <?php selected( 'W', $period );?>><?php _e( 'Weekly', 'invoicing' ); ?></option><option value="M" data-text="<?php esc_attr_e( 'month(s)', 'invoicing' ); ?>" <?php selected( 'M', $period );?>><?php _e( 'Monthly', 'invoicing' ); ?></option><option value="Y" data-text="<?php esc_attr_e( 'year(s)', 'invoicing' ); ?>" <?php selected( 'Y', $period );?>><?php _e( 'Yearly', 'invoicing' ); ?></option></select></label>
236
-                <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array(
234
+        <p class="wpinv-row-recurring-fields <?php echo $class; ?>">
235
+                <label class="wpinv-period" for="wpinv_recurring_period"><?php _e('Recurring', 'invoicing'); ?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e('day(s)', 'invoicing'); ?>" <?php selected('D', $period); ?>><?php _e('Daily', 'invoicing'); ?></option><option value="W" data-text="<?php esc_attr_e('week(s)', 'invoicing'); ?>" <?php selected('W', $period); ?>><?php _e('Weekly', 'invoicing'); ?></option><option value="M" data-text="<?php esc_attr_e('month(s)', 'invoicing'); ?>" <?php selected('M', $period); ?>><?php _e('Monthly', 'invoicing'); ?></option><option value="Y" data-text="<?php esc_attr_e('year(s)', 'invoicing'); ?>" <?php selected('Y', $period); ?>><?php _e('Yearly', 'invoicing'); ?></option></select></label>
236
+                <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array(
237 237
                     'options'          => $intervals,
238 238
                     'name'             => 'wpinv_recurring_interval',
239 239
                     'id'               => 'wpinv_recurring_interval',
240 240
                     'selected'         => $interval,
241 241
                     'show_option_all'  => false,
242 242
                     'show_option_none' => false
243
-                ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label>
244
-                <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e( 'for', 'invoicing' );?> <input class="small-text" type="number" value="<?php echo $times;?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e( 'time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing' );?></label>
243
+                )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label>
244
+                <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e('for', 'invoicing'); ?> <input class="small-text" type="number" value="<?php echo $times; ?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e('time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing'); ?></label>
245 245
                 <span class="clear wpi-trial-clr"></span>
246 246
                 <label class="wpinv-free-trial" for="wpinv_free_trial">
247
-                    <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> 
248
-                    <?php echo __( 'Offer free trial for', 'invoicing' ); ?>
247
+                    <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool)$free_trial); ?> /> 
248
+                    <?php echo __('Offer free trial for', 'invoicing'); ?>
249 249
                 </label>
250 250
                 <label class="wpinv-trial-interval" for="wpinv_trial_interval">
251
-                    <input class="small-text" type="number" value="<?php echo $trial_interval;?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected( 'D', $trial_period );?>><?php _e( 'day(s)', 'invoicing' ); ?></option><option value="W" <?php selected( 'W', $trial_period );?>><?php _e( 'week(s)', 'invoicing' ); ?></option><option value="M" <?php selected( 'M', $trial_period );?>><?php _e( 'month(s)', 'invoicing' ); ?></option><option value="Y" <?php selected( 'Y', $trial_period );?>><?php _e( 'year(s)', 'invoicing' ); ?></option></select>
251
+                    <input class="small-text" type="number" value="<?php echo $trial_interval; ?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected('D', $trial_period); ?>><?php _e('day(s)', 'invoicing'); ?></option><option value="W" <?php selected('W', $trial_period); ?>><?php _e('week(s)', 'invoicing'); ?></option><option value="M" <?php selected('M', $trial_period); ?>><?php _e('month(s)', 'invoicing'); ?></option><option value="Y" <?php selected('Y', $trial_period); ?>><?php _e('year(s)', 'invoicing'); ?></option></select>
252 252
                 </label>
253 253
         </p>
254
-        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" />
255
-        <?php do_action( 'wpinv_item_price_field', $post->ID ); ?>
254
+        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" />
255
+        <?php do_action('wpinv_item_price_field', $post->ID); ?>
256 256
         <?php
257 257
     }
258 258
     
259
-    public static function vat_rules( $post ) {
259
+    public static function vat_rules($post) {
260 260
         global $wpinv_euvat;
261 261
         
262
-        $rule_type = $wpinv_euvat->get_item_rule( $post->ID );
262
+        $rule_type = $wpinv_euvat->get_item_rule($post->ID);
263 263
         ?>
264
-        <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
265
-        <?php echo wpinv_html_select( array(
264
+        <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
265
+        <?php echo wpinv_html_select(array(
266 266
                     'options'          => $wpinv_euvat->get_rules(),
267 267
                     'name'             => 'wpinv_vat_rules',
268 268
                     'id'               => 'wpinv_vat_rules',
@@ -270,19 +270,19 @@  discard block
 block discarded – undo
270 270
                     'show_option_all'  => false,
271 271
                     'show_option_none' => false,
272 272
                     'class'            => 'gdmbx2-text-medium wpinv-vat-rules',
273
-                ) ); ?>
273
+                )); ?>
274 274
         </p>
275
-        <p class="wpi-m0"><?php _e( 'When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing' ); ?></p>
276
-        <p class="wpi-m0"><?php _e( 'If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing' ); ?></p>
275
+        <p class="wpi-m0"><?php _e('When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing'); ?></p>
276
+        <p class="wpi-m0"><?php _e('If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing'); ?></p>
277 277
         <?php
278 278
     }
279 279
     
280
-    public static function vat_classes( $post ) {
280
+    public static function vat_classes($post) {
281 281
         global $wpinv_euvat;
282 282
         
283
-        $vat_class = $wpinv_euvat->get_item_class( $post->ID );
283
+        $vat_class = $wpinv_euvat->get_item_class($post->ID);
284 284
         ?>
285
-        <p><?php echo wpinv_html_select( array(
285
+        <p><?php echo wpinv_html_select(array(
286 286
                     'options'          => $wpinv_euvat->get_all_classes(),
287 287
                     'name'             => 'wpinv_vat_class',
288 288
                     'id'               => 'wpinv_vat_class',
@@ -290,18 +290,18 @@  discard block
 block discarded – undo
290 290
                     'show_option_all'  => false,
291 291
                     'show_option_none' => false,
292 292
                     'class'            => 'gdmbx2-text-medium wpinv-vat-class',
293
-                ) ); ?>
293
+                )); ?>
294 294
         </p>
295
-        <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p>
295
+        <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p>
296 296
         <?php
297 297
     }
298 298
     
299
-    public static function item_info( $post ) {
300
-        $item_type = wpinv_get_item_type( $post->ID );
301
-        do_action( 'wpinv_item_info_metabox_before', $post );
299
+    public static function item_info($post) {
300
+        $item_type = wpinv_get_item_type($post->ID);
301
+        do_action('wpinv_item_info_metabox_before', $post);
302 302
         ?>
303
-        <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
304
-        <?php echo wpinv_html_select( array(
303
+        <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
304
+        <?php echo wpinv_html_select(array(
305 305
                     'options'          => wpinv_get_item_types(),
306 306
                     'name'             => 'wpinv_item_type',
307 307
                     'id'               => 'wpinv_item_type',
@@ -310,93 +310,93 @@  discard block
 block discarded – undo
310 310
                     'show_option_none' => false,
311 311
                     'class'            => 'gdmbx2-text-medium wpinv-item-type',
312 312
                     //'disabled'         => $item_type == 'package' ? true : false,
313
-                ) ); ?>
313
+                )); ?>
314 314
         </p>
315
-        <p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( 'Standard: standard item type', 'invoicing' );?><br><?php _e( 'Fee: like Registration Fee, Signup Fee etc.', 'invoicing' );?></p>
315
+        <p class="wpi-m0"><?php _e('Select item type.', 'invoicing'); ?><br><?php _e('Standard: standard item type', 'invoicing'); ?><br><?php _e('Fee: like Registration Fee, Signup Fee etc.', 'invoicing'); ?></p>
316 316
         <?php
317
-        do_action( 'wpinv_item_info_metabox_after', $post );
317
+        do_action('wpinv_item_info_metabox_after', $post);
318 318
     }
319 319
     
320
-    public static function save( $post_id, $data, $post ) {
321
-        $invoice        = new WPInv_Invoice( $post_id );
320
+    public static function save($post_id, $data, $post) {
321
+        $invoice        = new WPInv_Invoice($post_id);
322 322
         
323 323
         // Billing
324
-        $first_name     = sanitize_text_field( $data['wpinv_first_name'] );
325
-        $last_name      = sanitize_text_field( $data['wpinv_last_name'] );
326
-        $company        = sanitize_text_field( $data['wpinv_company'] );
327
-        $vat_number     = sanitize_text_field( $data['wpinv_vat_number'] );
328
-        $phone          = sanitize_text_field( $data['wpinv_phone'] );
329
-        $address        = sanitize_text_field( $data['wpinv_address'] );
330
-        $city           = sanitize_text_field( $data['wpinv_city'] );
331
-        $zip            = sanitize_text_field( $data['wpinv_zip'] );
332
-        $country        = sanitize_text_field( $data['wpinv_country'] );
333
-        $state          = sanitize_text_field( $data['wpinv_state'] );
324
+        $first_name     = sanitize_text_field($data['wpinv_first_name']);
325
+        $last_name      = sanitize_text_field($data['wpinv_last_name']);
326
+        $company        = sanitize_text_field($data['wpinv_company']);
327
+        $vat_number     = sanitize_text_field($data['wpinv_vat_number']);
328
+        $phone          = sanitize_text_field($data['wpinv_phone']);
329
+        $address        = sanitize_text_field($data['wpinv_address']);
330
+        $city           = sanitize_text_field($data['wpinv_city']);
331
+        $zip            = sanitize_text_field($data['wpinv_zip']);
332
+        $country        = sanitize_text_field($data['wpinv_country']);
333
+        $state          = sanitize_text_field($data['wpinv_state']);
334 334
         
335 335
         // Details
336
-        $status         = sanitize_text_field( $data['wpinv_status'] );
337
-        $old_status     = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status;
338
-        $number         = sanitize_text_field( $data['wpinv_number'] );
339
-        $due_date       = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : '';
336
+        $status         = sanitize_text_field($data['wpinv_status']);
337
+        $old_status     = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status;
338
+        $number         = sanitize_text_field($data['wpinv_number']);
339
+        $due_date       = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : '';
340 340
         //$discounts      = sanitize_text_field( $data['wpinv_discounts'] );
341 341
         //$discount       = sanitize_text_field( $data['wpinv_discount'] );
342 342
         
343
-        $ip             = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
343
+        $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
344 344
         
345
-        $invoice->set( 'due_date', $due_date );
346
-        $invoice->set( 'first_name', $first_name );
347
-        $invoice->set( 'last_name', $last_name );
348
-        $invoice->set( 'company', $company );
349
-        $invoice->set( 'vat_number', $vat_number );
350
-        $invoice->set( 'phone', $phone );
351
-        $invoice->set( 'address', $address );
352
-        $invoice->set( 'city', $city );
353
-        $invoice->set( 'zip', $zip );
354
-        $invoice->set( 'country', $country );
355
-        $invoice->set( 'state', $state );
356
-        $invoice->set( 'status', $status );
357
-        $invoice->set( 'number', $number );
345
+        $invoice->set('due_date', $due_date);
346
+        $invoice->set('first_name', $first_name);
347
+        $invoice->set('last_name', $last_name);
348
+        $invoice->set('company', $company);
349
+        $invoice->set('vat_number', $vat_number);
350
+        $invoice->set('phone', $phone);
351
+        $invoice->set('address', $address);
352
+        $invoice->set('city', $city);
353
+        $invoice->set('zip', $zip);
354
+        $invoice->set('country', $country);
355
+        $invoice->set('state', $state);
356
+        $invoice->set('status', $status);
357
+        $invoice->set('number', $number);
358 358
         //$invoice->set( 'discounts', $discounts );
359 359
         //$invoice->set( 'discount', $discount );
360
-        $invoice->set( 'ip', $ip );
360
+        $invoice->set('ip', $ip);
361 361
         $invoice->old_status = $_POST['original_post_status'];
362 362
         $invoice->currency = wpinv_get_currency();
363
-        if ( !empty( $data['wpinv_gateway'] ) ) {
364
-            $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) );
363
+        if (!empty($data['wpinv_gateway'])) {
364
+            $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway']));
365 365
         }
366 366
         $saved = $invoice->save();
367 367
         
368 368
         // Check for payment notes
369
-        if ( !empty( $data['invoice_note'] ) ) {
370
-            $note               = wp_kses( $data['invoice_note'], array() );
371
-            $note_type          = sanitize_text_field( $data['invoice_note_type'] );
369
+        if (!empty($data['invoice_note'])) {
370
+            $note               = wp_kses($data['invoice_note'], array());
371
+            $note_type          = sanitize_text_field($data['invoice_note_type']);
372 372
             $is_customer_note   = $note_type == 'customer' ? 1 : 0;
373 373
         
374
-            wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note );
374
+            wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note);
375 375
         }
376 376
         
377 377
         // Update user address if empty.
378
-        if ( $saved && !empty( $invoice ) ) {
379
-            if ( $user_id = $invoice->get_user_id() ) {
380
-                $user_address = wpinv_get_user_address( $user_id, false );
378
+        if ($saved && !empty($invoice)) {
379
+            if ($user_id = $invoice->get_user_id()) {
380
+                $user_address = wpinv_get_user_address($user_id, false);
381 381
                 
382 382
                 if (empty($user_address['first_name'])) {
383
-                    update_user_meta( $user_id, '_wpinv_first_name', $first_name );
384
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
383
+                    update_user_meta($user_id, '_wpinv_first_name', $first_name);
384
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
385 385
                 } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) {
386
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
386
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
387 387
                 }
388 388
                 
389 389
                 if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) {
390
-                    update_user_meta( $user_id, '_wpinv_address', $address );
391
-                    update_user_meta( $user_id, '_wpinv_city', $city );
392
-                    update_user_meta( $user_id, '_wpinv_state', $state );
393
-                    update_user_meta( $user_id, '_wpinv_country', $country );
394
-                    update_user_meta( $user_id, '_wpinv_zip', $zip );
395
-                    update_user_meta( $user_id, '_wpinv_phone', $phone );
390
+                    update_user_meta($user_id, '_wpinv_address', $address);
391
+                    update_user_meta($user_id, '_wpinv_city', $city);
392
+                    update_user_meta($user_id, '_wpinv_state', $state);
393
+                    update_user_meta($user_id, '_wpinv_country', $country);
394
+                    update_user_meta($user_id, '_wpinv_zip', $zip);
395
+                    update_user_meta($user_id, '_wpinv_phone', $phone);
396 396
                 }
397 397
             }
398 398
             
399
-            do_action( 'wpinv_invoice_metabox_saveed', $invoice );
399
+            do_action('wpinv_invoice_metabox_saveed', $invoice);
400 400
         }
401 401
         
402 402
         return $saved;
Please login to merge, or discard this patch.