Passed
Push — master ( 61f4f6...8a324c )
by Stiofan
03:54
created
includes/wpinv-helper-functions.php 1 patch
Spacing   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -7,89 +7,89 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_item_quantities_enabled() {
15
-    $ret = wpinv_get_option( 'item_quantities', true );
15
+    $ret = wpinv_get_option('item_quantities', true);
16 16
     
17
-    return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret );
17
+    return (bool)apply_filters('wpinv_item_quantities_enabled', $ret);
18 18
 }
19 19
 
20 20
 function wpinv_get_ip() {
21 21
     $ip = '127.0.0.1';
22 22
 
23
-    if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
24
-        $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] );
25
-    } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
26
-        $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] );
27
-    } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) {
28
-        $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
23
+    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
24
+        $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']);
25
+    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
26
+        $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']);
27
+    } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
28
+        $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']);
29 29
     }
30 30
     
31
-    return apply_filters( 'wpinv_get_ip', $ip );
31
+    return apply_filters('wpinv_get_ip', $ip);
32 32
 }
33 33
 
34 34
 function wpinv_get_user_agent() {
35
-    if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
36
-        $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
35
+    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
36
+        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
37 37
     } else {
38 38
         $user_agent = '';
39 39
     }
40 40
     
41
-    return apply_filters( 'wpinv_get_user_agent', $user_agent );
41
+    return apply_filters('wpinv_get_user_agent', $user_agent);
42 42
 }
43 43
 
44
-function wpinv_sanitize_amount( $amount, $decimals = NULL ) {
44
+function wpinv_sanitize_amount($amount, $decimals = NULL) {
45 45
     $is_negative   = false;
46 46
     $thousands_sep = wpinv_thousands_separator();
47 47
     $decimal_sep   = wpinv_decimal_separator();
48
-    if ( $decimals === NULL ) {
48
+    if ($decimals === NULL) {
49 49
         $decimals = wpinv_decimals();
50 50
     }
51 51
 
52 52
     // Sanitize the amount
53
-    if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) {
54
-        if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
55
-            $amount = str_replace( $thousands_sep, '', $amount );
56
-        } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) {
57
-            $amount = str_replace( '.', '', $amount );
53
+    if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) {
54
+        if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) {
55
+            $amount = str_replace($thousands_sep, '', $amount);
56
+        } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) {
57
+            $amount = str_replace('.', '', $amount);
58 58
         }
59 59
 
60
-        $amount = str_replace( $decimal_sep, '.', $amount );
61
-    } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
62
-        $amount = str_replace( $thousands_sep, '', $amount );
60
+        $amount = str_replace($decimal_sep, '.', $amount);
61
+    } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
62
+        $amount = str_replace($thousands_sep, '', $amount);
63 63
     }
64 64
 
65
-    if( $amount < 0 ) {
65
+    if ($amount < 0) {
66 66
         $is_negative = true;
67 67
     }
68 68
 
69
-    $amount   = preg_replace( '/[^0-9\.]/', '', $amount );
69
+    $amount   = preg_replace('/[^0-9\.]/', '', $amount);
70 70
 
71
-    $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', absint( $decimals ), $amount );
72
-    $amount   = number_format( (double) $amount, absint( $decimals ), '.', '' );
71
+    $decimals = apply_filters('wpinv_sanitize_amount_decimals', absint($decimals), $amount);
72
+    $amount   = number_format((double)$amount, absint($decimals), '.', '');
73 73
 
74
-    if( $is_negative ) {
74
+    if ($is_negative) {
75 75
         $amount *= -1;
76 76
     }
77 77
 
78
-    return apply_filters( 'wpinv_sanitize_amount', $amount, $decimals );
78
+    return apply_filters('wpinv_sanitize_amount', $amount, $decimals);
79 79
 }
80
-add_filter( 'wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
80
+add_filter('wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1);
81 81
 
82
-function wpinv_round_amount( $amount, $decimals = NULL ) {
83
-    if ( $decimals === NULL ) {
82
+function wpinv_round_amount($amount, $decimals = NULL) {
83
+    if ($decimals === NULL) {
84 84
         $decimals = wpinv_decimals();
85 85
     }
86 86
     
87
-    $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) );
87
+    $amount = round((double)$amount, wpinv_currency_decimal_filter(absint($decimals)));
88 88
 
89
-    return apply_filters( 'wpinv_round_amount', $amount, $decimals );
89
+    return apply_filters('wpinv_round_amount', $amount, $decimals);
90 90
 }
91 91
 
92
-function wpinv_get_invoice_statuses( $trashed = false ) {
92
+function wpinv_get_invoice_statuses($trashed = false) {
93 93
     global $post;
94 94
     $invoice_statuses = array();
95 95
     $invoice_statuses = array(
@@ -103,32 +103,32 @@  discard block
 block discarded – undo
103 103
         'wpi-renewal' => __('Renewal Payment', 'invoicing')
104 104
     );
105 105
     
106
-    if ( $trashed ) {
107
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
106
+    if ($trashed) {
107
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
108 108
     }
109 109
 
110
-    return apply_filters( 'wpinv_statuses', $invoice_statuses );
110
+    return apply_filters('wpinv_statuses', $invoice_statuses);
111 111
 }
112 112
 
113
-function wpinv_status_nicename( $status ) {
113
+function wpinv_status_nicename($status) {
114 114
     $statuses = wpinv_get_invoice_statuses();
115
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' );
115
+    $status   = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing');
116 116
 
117 117
     return $status;
118 118
 }
119 119
 
120 120
 function wpinv_get_currency() {
121
-    $currency = wpinv_get_option( 'currency', 'USD' );
121
+    $currency = wpinv_get_option('currency', 'USD');
122 122
     
123
-    return apply_filters( 'wpinv_currency', $currency );
123
+    return apply_filters('wpinv_currency', $currency);
124 124
 }
125 125
 
126
-function wpinv_currency_symbol( $currency = '' ) {
127
-    if ( empty( $currency ) ) {
126
+function wpinv_currency_symbol($currency = '') {
127
+    if (empty($currency)) {
128 128
         $currency = wpinv_get_currency();
129 129
     }
130 130
     
131
-    $symbols = apply_filters( 'wpinv_currency_symbols', array(
131
+    $symbols = apply_filters('wpinv_currency_symbols', array(
132 132
         'AED' => 'د.إ',
133 133
         'ARS' => '&#36;',
134 134
         'AUD' => '&#36;',
@@ -180,79 +180,79 @@  discard block
 block discarded – undo
180 180
         'USD' => '&#36;',
181 181
         'VND' => '&#8363;',
182 182
         'ZAR' => '&#82;',
183
-    ) );
183
+    ));
184 184
 
185
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : '&#36;';
185
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : '&#36;';
186 186
 
187
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
187
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
188 188
 }
189 189
 
190 190
 function wpinv_currency_position() {
191
-    $position = wpinv_get_option( 'currency_position', 'left' );
191
+    $position = wpinv_get_option('currency_position', 'left');
192 192
     
193
-    return apply_filters( 'wpinv_currency_position', $position );
193
+    return apply_filters('wpinv_currency_position', $position);
194 194
 }
195 195
 
196 196
 function wpinv_thousands_separator() {
197
-    $thousand_sep = wpinv_get_option( 'thousands_separator', ',' );
197
+    $thousand_sep = wpinv_get_option('thousands_separator', ',');
198 198
     
199
-    return apply_filters( 'wpinv_thousands_separator', $thousand_sep );
199
+    return apply_filters('wpinv_thousands_separator', $thousand_sep);
200 200
 }
201 201
 
202 202
 function wpinv_decimal_separator() {
203
-    $decimal_sep = wpinv_get_option( 'decimal_separator', '.' );
203
+    $decimal_sep = wpinv_get_option('decimal_separator', '.');
204 204
     
205
-    return apply_filters( 'wpinv_decimal_separator', $decimal_sep );
205
+    return apply_filters('wpinv_decimal_separator', $decimal_sep);
206 206
 }
207 207
 
208 208
 function wpinv_decimals() {
209
-    $decimals = apply_filters( 'wpinv_decimals', wpinv_get_option( 'decimals', 2 ) );
209
+    $decimals = apply_filters('wpinv_decimals', wpinv_get_option('decimals', 2));
210 210
     
211
-    return absint( $decimals );
211
+    return absint($decimals);
212 212
 }
213 213
 
214 214
 function wpinv_get_currencies() {
215 215
     $currencies = array(
216
-        'USD'  => __( 'US Dollars (&#36;)', 'invoicing' ),
217
-        'EUR'  => __( 'Euros (&euro;)', 'invoicing' ),
218
-        'GBP'  => __( 'Pounds Sterling (&pound;)', 'invoicing' ),
219
-        'AUD'  => __( 'Australian Dollars (&#36;)', 'invoicing' ),
220
-        'BRL'  => __( 'Brazilian Real (R&#36;)', 'invoicing' ),
221
-        'CAD'  => __( 'Canadian Dollars (&#36;)', 'invoicing' ),
222
-        'CLP'  => __( 'Chilean Peso (&#36;)', 'invoicing' ),
223
-        'CNY'  => __( 'Chinese Yuan (&yen;)', 'invoicing' ),
224
-        'CZK'  => __( 'Czech Koruna (&#75;&#269;)', 'invoicing' ),
225
-        'DKK'  => __( 'Danish Krone (DKK)', 'invoicing' ),
226
-        'HKD'  => __( 'Hong Kong Dollar (&#36;)', 'invoicing' ),
227
-        'HUF'  => __( 'Hungarian Forint (&#70;&#116;)', 'invoicing' ),
228
-        'INR'  => __( 'Indian Rupee (&#8377;)', 'invoicing' ),
229
-        'ILS'  => __( 'Israeli Shekel (&#8362;)', 'invoicing' ),
230
-        'JPY'  => __( 'Japanese Yen (&yen;)', 'invoicing' ),
231
-        'MYR'  => __( 'Malaysian Ringgit (&#82;&#77;)', 'invoicing' ),
232
-        'MXN'  => __( 'Mexican Peso (&#36;)', 'invoicing' ),
233
-        'NZD'  => __( 'New Zealand Dollar (&#36;)', 'invoicing' ),
234
-        'NOK'  => __( 'Norwegian Krone (&#107;&#114;)', 'invoicing' ),
235
-        'PKR'  => __( 'Pakistani rupee (&#8360;)', 'invoicing' ),
236
-        'PHP'  => __( 'Philippine Peso (&#8369;)', 'invoicing' ),
237
-        'PLN'  => __( 'Polish Zloty (&#122;&#322;)', 'invoicing' ),
238
-        'SGD'  => __( 'Singapore Dollar (&#36;)', 'invoicing' ),
239
-        'SEK'  => __( 'Swedish Krona (&#107;&#114;)', 'invoicing' ),
240
-        'CHF'  => __( 'Swiss Franc (&#67;&#72;&#70;)', 'invoicing' ),
241
-        'TWD'  => __( 'Taiwan New Dollar (&#78;&#84;&#36;)', 'invoicing' ),
242
-        'THB'  => __( 'Thai Baht (&#3647;)', 'invoicing' ),
243
-        'TRY'  => __( 'Turkish Lira (&#8378;)', 'invoicing' ),
244
-        'RIAL' => __( 'Iranian Rial (&#65020;)', 'invoicing' ),
245
-        'RUB'  => __( 'Russian Ruble (&#8381;)', 'invoicing' ),
246
-        'ZAR'  => __( 'South African Rand (&#82;)', 'invoicing' )
216
+        'USD'  => __('US Dollars (&#36;)', 'invoicing'),
217
+        'EUR'  => __('Euros (&euro;)', 'invoicing'),
218
+        'GBP'  => __('Pounds Sterling (&pound;)', 'invoicing'),
219
+        'AUD'  => __('Australian Dollars (&#36;)', 'invoicing'),
220
+        'BRL'  => __('Brazilian Real (R&#36;)', 'invoicing'),
221
+        'CAD'  => __('Canadian Dollars (&#36;)', 'invoicing'),
222
+        'CLP'  => __('Chilean Peso (&#36;)', 'invoicing'),
223
+        'CNY'  => __('Chinese Yuan (&yen;)', 'invoicing'),
224
+        'CZK'  => __('Czech Koruna (&#75;&#269;)', 'invoicing'),
225
+        'DKK'  => __('Danish Krone (DKK)', 'invoicing'),
226
+        'HKD'  => __('Hong Kong Dollar (&#36;)', 'invoicing'),
227
+        'HUF'  => __('Hungarian Forint (&#70;&#116;)', 'invoicing'),
228
+        'INR'  => __('Indian Rupee (&#8377;)', 'invoicing'),
229
+        'ILS'  => __('Israeli Shekel (&#8362;)', 'invoicing'),
230
+        'JPY'  => __('Japanese Yen (&yen;)', 'invoicing'),
231
+        'MYR'  => __('Malaysian Ringgit (&#82;&#77;)', 'invoicing'),
232
+        'MXN'  => __('Mexican Peso (&#36;)', 'invoicing'),
233
+        'NZD'  => __('New Zealand Dollar (&#36;)', 'invoicing'),
234
+        'NOK'  => __('Norwegian Krone (&#107;&#114;)', 'invoicing'),
235
+        'PKR'  => __('Pakistani rupee (&#8360;)', 'invoicing'),
236
+        'PHP'  => __('Philippine Peso (&#8369;)', 'invoicing'),
237
+        'PLN'  => __('Polish Zloty (&#122;&#322;)', 'invoicing'),
238
+        'SGD'  => __('Singapore Dollar (&#36;)', 'invoicing'),
239
+        'SEK'  => __('Swedish Krona (&#107;&#114;)', 'invoicing'),
240
+        'CHF'  => __('Swiss Franc (&#67;&#72;&#70;)', 'invoicing'),
241
+        'TWD'  => __('Taiwan New Dollar (&#78;&#84;&#36;)', 'invoicing'),
242
+        'THB'  => __('Thai Baht (&#3647;)', 'invoicing'),
243
+        'TRY'  => __('Turkish Lira (&#8378;)', 'invoicing'),
244
+        'RIAL' => __('Iranian Rial (&#65020;)', 'invoicing'),
245
+        'RUB'  => __('Russian Ruble (&#8381;)', 'invoicing'),
246
+        'ZAR'  => __('South African Rand (&#82;)', 'invoicing')
247 247
     );
248 248
     
249 249
     //asort( $currencies ); // this
250 250
 
251
-    return apply_filters( 'wpinv_currencies', $currencies );
251
+    return apply_filters('wpinv_currencies', $currencies);
252 252
 }
253 253
 
254
-function wpinv_price( $amount = '', $currency = '' ) {
255
-    if( empty( $currency ) ) {
254
+function wpinv_price($amount = '', $currency = '') {
255
+    if (empty($currency)) {
256 256
         $currency = wpinv_get_currency();
257 257
     }
258 258
 
@@ -260,14 +260,14 @@  discard block
 block discarded – undo
260 260
 
261 261
     $negative = $amount < 0;
262 262
 
263
-    if ( $negative ) {
264
-        $amount = substr( $amount, 1 );
263
+    if ($negative) {
264
+        $amount = substr($amount, 1);
265 265
     }
266 266
 
267
-    $symbol = wpinv_currency_symbol( $currency );
267
+    $symbol = wpinv_currency_symbol($currency);
268 268
 
269
-    if ( $position == 'left' || $position == 'left_space' ) {
270
-        switch ( $currency ) {
269
+    if ($position == 'left' || $position == 'left_space') {
270
+        switch ($currency) {
271 271
             case "GBP" :
272 272
             case "BRL" :
273 273
             case "EUR" :
@@ -279,15 +279,15 @@  discard block
 block discarded – undo
279 279
             case "NZD" :
280 280
             case "SGD" :
281 281
             case "JPY" :
282
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
282
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
283 283
                 break;
284 284
             default :
285 285
                 //$price = $currency . ' ' . $amount;
286
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
286
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
287 287
                 break;
288 288
         }
289 289
     } else {
290
-        switch ( $currency ) {
290
+        switch ($currency) {
291 291
             case "GBP" :
292 292
             case "BRL" :
293 293
             case "EUR" :
@@ -298,83 +298,83 @@  discard block
 block discarded – undo
298 298
             case "MXN" :
299 299
             case "SGD" :
300 300
             case "JPY" :
301
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
301
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
302 302
                 break;
303 303
             default :
304 304
                 //$price = $amount . ' ' . $currency;
305
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
305
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
306 306
                 break;
307 307
         }
308 308
     }
309 309
     
310
-    if ( $negative ) {
310
+    if ($negative) {
311 311
         $price = '-' . $price;
312 312
     }
313 313
     
314
-    $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount );
314
+    $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount);
315 315
 
316 316
     return $price;
317 317
 }
318 318
 
319
-function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) {
319
+function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) {
320 320
     $thousands_sep = wpinv_thousands_separator();
321 321
     $decimal_sep   = wpinv_decimal_separator();
322 322
 
323
-    if ( $decimals === NULL ) {
323
+    if ($decimals === NULL) {
324 324
         $decimals = wpinv_decimals();
325 325
     }
326 326
 
327
-    if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) {
328
-        $whole = substr( $amount, 0, $sep_found );
329
-        $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) );
327
+    if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) {
328
+        $whole = substr($amount, 0, $sep_found);
329
+        $part = substr($amount, $sep_found + 1, (strlen($amount) - 1));
330 330
         $amount = $whole . '.' . $part;
331 331
     }
332 332
 
333
-    if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
334
-        $amount = str_replace( ',', '', $amount );
333
+    if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
334
+        $amount = str_replace(',', '', $amount);
335 335
     }
336 336
 
337
-    if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
338
-        $amount = str_replace( ' ', '', $amount );
337
+    if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) {
338
+        $amount = str_replace(' ', '', $amount);
339 339
     }
340 340
 
341
-    if ( empty( $amount ) ) {
341
+    if (empty($amount)) {
342 342
         $amount = 0;
343 343
     }
344 344
     
345
-    $decimals  = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate );
346
-    $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep );
345
+    $decimals  = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate);
346
+    $formatted = number_format((float)$amount, $decimals, $decimal_sep, $thousands_sep);
347 347
     
348
-    if ( $calculate ) {
349
-        if ( $thousands_sep === "," ) {
350
-            $formatted = str_replace( ",", "", $formatted );
348
+    if ($calculate) {
349
+        if ($thousands_sep === ",") {
350
+            $formatted = str_replace(",", "", $formatted);
351 351
         }
352 352
         
353
-        if ( $decimal_sep === "," ) {
354
-            $formatted = str_replace( ",", ".", $formatted );
353
+        if ($decimal_sep === ",") {
354
+            $formatted = str_replace(",", ".", $formatted);
355 355
         }
356 356
     }
357 357
 
358
-    return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate );
358
+    return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate);
359 359
 }
360
-add_filter( 'wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
360
+add_filter('wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1);
361 361
 
362
-function wpinv_sanitize_key( $key ) {
362
+function wpinv_sanitize_key($key) {
363 363
     $raw_key = $key;
364
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
364
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
365 365
 
366
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
366
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
367 367
 }
368 368
 
369
-function wpinv_get_file_extension( $str ) {
370
-    $parts = explode( '.', $str );
371
-    return end( $parts );
369
+function wpinv_get_file_extension($str) {
370
+    $parts = explode('.', $str);
371
+    return end($parts);
372 372
 }
373 373
 
374
-function wpinv_string_is_image_url( $str ) {
375
-    $ext = wpinv_get_file_extension( $str );
374
+function wpinv_string_is_image_url($str) {
375
+    $ext = wpinv_get_file_extension($str);
376 376
 
377
-    switch ( strtolower( $ext ) ) {
377
+    switch (strtolower($ext)) {
378 378
         case 'jpeg';
379 379
         case 'jpg';
380 380
             $return = true;
@@ -390,32 +390,32 @@  discard block
 block discarded – undo
390 390
             break;
391 391
     }
392 392
 
393
-    return (bool)apply_filters( 'wpinv_string_is_image', $return, $str );
393
+    return (bool)apply_filters('wpinv_string_is_image', $return, $str);
394 394
 }
395 395
 
396
-function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) {
397
-    $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG );
396
+function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) {
397
+    $should_log = apply_filters('wpinv_log_errors', WP_DEBUG);
398 398
     
399
-    if ( true === $should_log ) {
399
+    if (true === $should_log) {
400 400
         $label = '';
401
-        if ( $file && $file !== '' ) {
402
-            $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' );
401
+        if ($file && $file !== '') {
402
+            $label .= basename($file) . ($line ? '(' . $line . ')' : '');
403 403
         }
404 404
         
405
-        if ( $title && $title !== '' ) {
405
+        if ($title && $title !== '') {
406 406
             $label = $label !== '' ? $label . ' ' : '';
407 407
             $label .= $title . ' ';
408 408
         }
409 409
         
410
-        $label = $label !== '' ? trim( $label ) . ' : ' : '';
410
+        $label = $label !== '' ? trim($label) . ' : ' : '';
411 411
         
412
-        if ( is_array( $log ) || is_object( $log ) ) {
413
-            error_log( $label . print_r( $log, true ) );
412
+        if (is_array($log) || is_object($log)) {
413
+            error_log($label . print_r($log, true));
414 414
         } else {
415
-            error_log( $label . $log );
415
+            error_log($label . $log);
416 416
         }
417 417
         
418
-        if ( $exit ) {
418
+        if ($exit) {
419 419
             exit;
420 420
         }
421 421
     }
@@ -423,65 +423,65 @@  discard block
 block discarded – undo
423 423
 
424 424
 function wpinv_is_ajax_disabled() {
425 425
     $retval = false;
426
-    return apply_filters( 'wpinv_is_ajax_disabled', $retval );
426
+    return apply_filters('wpinv_is_ajax_disabled', $retval);
427 427
 }
428 428
 
429
-function wpinv_get_current_page_url( $nocache = false ) {
429
+function wpinv_get_current_page_url($nocache = false) {
430 430
     global $wp;
431 431
 
432
-    if ( get_option( 'permalink_structure' ) ) {
433
-        $base = trailingslashit( home_url( $wp->request ) );
432
+    if (get_option('permalink_structure')) {
433
+        $base = trailingslashit(home_url($wp->request));
434 434
     } else {
435
-        $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) );
436
-        $base = remove_query_arg( array( 'post_type', 'name' ), $base );
435
+        $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request)));
436
+        $base = remove_query_arg(array('post_type', 'name'), $base);
437 437
     }
438 438
 
439 439
     $scheme = is_ssl() ? 'https' : 'http';
440
-    $uri    = set_url_scheme( $base, $scheme );
440
+    $uri    = set_url_scheme($base, $scheme);
441 441
 
442
-    if ( is_front_page() ) {
443
-        $uri = home_url( '/' );
444
-    } elseif ( wpinv_is_checkout( array(), false ) ) {
442
+    if (is_front_page()) {
443
+        $uri = home_url('/');
444
+    } elseif (wpinv_is_checkout(array(), false)) {
445 445
         $uri = wpinv_get_checkout_uri();
446 446
     }
447 447
 
448
-    $uri = apply_filters( 'wpinv_get_current_page_url', $uri );
448
+    $uri = apply_filters('wpinv_get_current_page_url', $uri);
449 449
 
450
-    if ( $nocache ) {
451
-        $uri = wpinv_add_cache_busting( $uri );
450
+    if ($nocache) {
451
+        $uri = wpinv_add_cache_busting($uri);
452 452
     }
453 453
 
454 454
     return $uri;
455 455
 }
456 456
 
457 457
 function wpinv_get_php_arg_separator_output() {
458
-	return ini_get( 'arg_separator.output' );
458
+	return ini_get('arg_separator.output');
459 459
 }
460 460
 
461
-function wpinv_rgb_from_hex( $color ) {
462
-    $color = str_replace( '#', '', $color );
461
+function wpinv_rgb_from_hex($color) {
462
+    $color = str_replace('#', '', $color);
463 463
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
464
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
464
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
465 465
 
466 466
     $rgb      = array();
467
-    $rgb['R'] = hexdec( $color{0}.$color{1} );
468
-    $rgb['G'] = hexdec( $color{2}.$color{3} );
469
-    $rgb['B'] = hexdec( $color{4}.$color{5} );
467
+    $rgb['R'] = hexdec($color{0} . $color{1} );
468
+    $rgb['G'] = hexdec($color{2} . $color{3} );
469
+    $rgb['B'] = hexdec($color{4} . $color{5} );
470 470
 
471 471
     return $rgb;
472 472
 }
473 473
 
474
-function wpinv_hex_darker( $color, $factor = 30 ) {
475
-    $base  = wpinv_rgb_from_hex( $color );
474
+function wpinv_hex_darker($color, $factor = 30) {
475
+    $base  = wpinv_rgb_from_hex($color);
476 476
     $color = '#';
477 477
 
478
-    foreach ( $base as $k => $v ) {
478
+    foreach ($base as $k => $v) {
479 479
         $amount      = $v / 100;
480
-        $amount      = round( $amount * $factor );
480
+        $amount      = round($amount * $factor);
481 481
         $new_decimal = $v - $amount;
482 482
 
483
-        $new_hex_component = dechex( $new_decimal );
484
-        if ( strlen( $new_hex_component ) < 2 ) {
483
+        $new_hex_component = dechex($new_decimal);
484
+        if (strlen($new_hex_component) < 2) {
485 485
             $new_hex_component = "0" . $new_hex_component;
486 486
         }
487 487
         $color .= $new_hex_component;
@@ -490,18 +490,18 @@  discard block
 block discarded – undo
490 490
     return $color;
491 491
 }
492 492
 
493
-function wpinv_hex_lighter( $color, $factor = 30 ) {
494
-    $base  = wpinv_rgb_from_hex( $color );
493
+function wpinv_hex_lighter($color, $factor = 30) {
494
+    $base  = wpinv_rgb_from_hex($color);
495 495
     $color = '#';
496 496
 
497
-    foreach ( $base as $k => $v ) {
497
+    foreach ($base as $k => $v) {
498 498
         $amount      = 255 - $v;
499 499
         $amount      = $amount / 100;
500
-        $amount      = round( $amount * $factor );
500
+        $amount      = round($amount * $factor);
501 501
         $new_decimal = $v + $amount;
502 502
 
503
-        $new_hex_component = dechex( $new_decimal );
504
-        if ( strlen( $new_hex_component ) < 2 ) {
503
+        $new_hex_component = dechex($new_decimal);
504
+        if (strlen($new_hex_component) < 2) {
505 505
             $new_hex_component = "0" . $new_hex_component;
506 506
         }
507 507
         $color .= $new_hex_component;
@@ -510,22 +510,22 @@  discard block
 block discarded – undo
510 510
     return $color;
511 511
 }
512 512
 
513
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
514
-    $hex = str_replace( '#', '', $color );
513
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
514
+    $hex = str_replace('#', '', $color);
515 515
 
516
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
517
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
518
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
516
+    $c_r = hexdec(substr($hex, 0, 2));
517
+    $c_g = hexdec(substr($hex, 2, 2));
518
+    $c_b = hexdec(substr($hex, 4, 2));
519 519
 
520
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
520
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
521 521
 
522 522
     return $brightness > 155 ? $dark : $light;
523 523
 }
524 524
 
525
-function wpinv_format_hex( $hex ) {
526
-    $hex = trim( str_replace( '#', '', $hex ) );
525
+function wpinv_format_hex($hex) {
526
+    $hex = trim(str_replace('#', '', $hex));
527 527
 
528
-    if ( strlen( $hex ) == 3 ) {
528
+    if (strlen($hex) == 3) {
529 529
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
530 530
     }
531 531
 
@@ -545,12 +545,12 @@  discard block
 block discarded – undo
545 545
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
546 546
  * @return string
547 547
  */
548
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
549
-    if ( function_exists( 'mb_strimwidth' ) ) {
550
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
548
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
549
+    if (function_exists('mb_strimwidth')) {
550
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
551 551
     }
552 552
     
553
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
553
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
554 554
 }
555 555
 
556 556
 /**
@@ -562,28 +562,28 @@  discard block
 block discarded – undo
562 562
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
563 563
  * @return int Returns the number of characters in string.
564 564
  */
565
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
566
-    if ( function_exists( 'mb_strlen' ) ) {
567
-        return mb_strlen( $str, $encoding );
565
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
566
+    if (function_exists('mb_strlen')) {
567
+        return mb_strlen($str, $encoding);
568 568
     }
569 569
         
570
-    return strlen( $str );
570
+    return strlen($str);
571 571
 }
572 572
 
573
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
574
-    if ( function_exists( 'mb_strtolower' ) ) {
575
-        return mb_strtolower( $str, $encoding );
573
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
574
+    if (function_exists('mb_strtolower')) {
575
+        return mb_strtolower($str, $encoding);
576 576
     }
577 577
     
578
-    return strtolower( $str );
578
+    return strtolower($str);
579 579
 }
580 580
 
581
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
582
-    if ( function_exists( 'mb_strtoupper' ) ) {
583
-        return mb_strtoupper( $str, $encoding );
581
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
582
+    if (function_exists('mb_strtoupper')) {
583
+        return mb_strtoupper($str, $encoding);
584 584
     }
585 585
     
586
-    return strtoupper( $str );
586
+    return strtoupper($str);
587 587
 }
588 588
 
589 589
 /**
@@ -597,12 +597,12 @@  discard block
 block discarded – undo
597 597
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
598 598
  * @return int Returns the position of the first occurrence of search in the string.
599 599
  */
600
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
601
-    if ( function_exists( 'mb_strpos' ) ) {
602
-        return mb_strpos( $str, $find, $offset, $encoding );
600
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
601
+    if (function_exists('mb_strpos')) {
602
+        return mb_strpos($str, $find, $offset, $encoding);
603 603
     }
604 604
         
605
-    return strpos( $str, $find, $offset );
605
+    return strpos($str, $find, $offset);
606 606
 }
607 607
 
608 608
 /**
@@ -616,12 +616,12 @@  discard block
 block discarded – undo
616 616
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
617 617
  * @return int Returns the position of the last occurrence of search.
618 618
  */
619
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
620
-    if ( function_exists( 'mb_strrpos' ) ) {
621
-        return mb_strrpos( $str, $find, $offset, $encoding );
619
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
620
+    if (function_exists('mb_strrpos')) {
621
+        return mb_strrpos($str, $find, $offset, $encoding);
622 622
     }
623 623
         
624
-    return strrpos( $str, $find, $offset );
624
+    return strrpos($str, $find, $offset);
625 625
 }
626 626
 
627 627
 /**
@@ -636,16 +636,16 @@  discard block
 block discarded – undo
636 636
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
637 637
  * @return string
638 638
  */
639
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
640
-    if ( function_exists( 'mb_substr' ) ) {
641
-        if ( $length === null ) {
642
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
639
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
640
+    if (function_exists('mb_substr')) {
641
+        if ($length === null) {
642
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
643 643
         } else {
644
-            return mb_substr( $str, $start, $length, $encoding );
644
+            return mb_substr($str, $start, $length, $encoding);
645 645
         }
646 646
     }
647 647
         
648
-    return substr( $str, $start, $length );
648
+    return substr($str, $start, $length);
649 649
 }
650 650
 
651 651
 /**
@@ -657,48 +657,48 @@  discard block
 block discarded – undo
657 657
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
658 658
  * @return string The width of string.
659 659
  */
660
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
661
-    if ( function_exists( 'mb_strwidth' ) ) {
662
-        return mb_strwidth( $str, $encoding );
660
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
661
+    if (function_exists('mb_strwidth')) {
662
+        return mb_strwidth($str, $encoding);
663 663
     }
664 664
     
665
-    return wpinv_utf8_strlen( $str, $encoding );
665
+    return wpinv_utf8_strlen($str, $encoding);
666 666
 }
667 667
 
668
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
669
-    if ( function_exists( 'mb_strlen' ) ) {
670
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
668
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
669
+    if (function_exists('mb_strlen')) {
670
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
671 671
         $str_end = "";
672 672
         
673
-        if ( $lower_str_end ) {
674
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
673
+        if ($lower_str_end) {
674
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
675 675
         } else {
676
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
676
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
677 677
         }
678 678
 
679 679
         return $first_letter . $str_end;
680 680
     }
681 681
     
682
-    return ucfirst( $str );
682
+    return ucfirst($str);
683 683
 }
684 684
 
685
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
686
-    if ( function_exists( 'mb_convert_case' ) ) {
687
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
685
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
686
+    if (function_exists('mb_convert_case')) {
687
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
688 688
     }
689 689
     
690
-    return ucwords( $str );
690
+    return ucwords($str);
691 691
 }
692 692
 
693
-function wpinv_period_in_days( $period, $unit ) {
694
-    $period = absint( $period );
693
+function wpinv_period_in_days($period, $unit) {
694
+    $period = absint($period);
695 695
     
696
-    if ( $period > 0 ) {
697
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
696
+    if ($period > 0) {
697
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
698 698
             $period = $period * 7;
699
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
699
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
700 700
             $period = $period * 30;
701
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
701
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
702 702
             $period = $period * 365;
703 703
         }
704 704
     }
Please login to merge, or discard this patch.