Passed
Push — master ( 7383db...683722 )
by Brian
03:43
created
includes/wpinv-address-functions.php 1 patch
Spacing   +146 added lines, -146 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
 
15 15
 function wpinv_get_default_country() {
16
-	$country = wpinv_get_option( 'default_country', 'UK' );
16
+	$country = wpinv_get_option('default_country', 'UK');
17 17
 
18
-	return apply_filters( 'wpinv_default_country', $country );
18
+	return apply_filters('wpinv_default_country', $country);
19 19
 }
20 20
 
21 21
 /**
@@ -23,8 +23,8 @@  discard block
 block discarded – undo
23 23
  *
24 24
  * @return string
25 25
  */
26
-function getpaid_get_ip_country( $ip_address = '' ) {
27
-    $country = GetPaid_Geolocation::geolocate_ip( $ip_address, true );
26
+function getpaid_get_ip_country($ip_address = '') {
27
+    $country = GetPaid_Geolocation::geolocate_ip($ip_address, true);
28 28
     return $country['country'];
29 29
 }
30 30
 
@@ -34,59 +34,59 @@  discard block
 block discarded – undo
34 34
  * @param string $country The country code to sanitize
35 35
  * @return array
36 36
  */
37
-function wpinv_sanitize_country( $country ) {
37
+function wpinv_sanitize_country($country) {
38 38
 
39 39
 	// Enure the country is specified
40
-    if ( empty( $country ) ) {
40
+    if (empty($country)) {
41 41
         $country = wpinv_get_default_country();
42 42
     }
43
-    return trim( wpinv_utf8_strtoupper( $country ) );
43
+    return trim(wpinv_utf8_strtoupper($country));
44 44
 
45 45
 }
46 46
 
47
-function wpinv_is_base_country( $country ) {
47
+function wpinv_is_base_country($country) {
48 48
     $base_country = wpinv_get_default_country();
49 49
     
50
-    if ( $base_country === 'UK' ) {
50
+    if ($base_country === 'UK') {
51 51
         $base_country = 'GB';
52 52
     }
53
-    if ( $country == 'UK' ) {
53
+    if ($country == 'UK') {
54 54
         $country = 'GB';
55 55
     }
56 56
 
57
-    return ( $country && $country === $base_country ) ? true : false;
57
+    return ($country && $country === $base_country) ? true : false;
58 58
 }
59 59
 
60
-function wpinv_country_name( $country_code = '' ) { 
60
+function wpinv_country_name($country_code = '') { 
61 61
     $countries = wpinv_get_country_list();
62 62
     $country_code = $country_code == 'UK' ? 'GB' : $country_code;
63
-    $country = isset( $countries[$country_code] ) ? $countries[$country_code] : $country_code;
63
+    $country = isset($countries[$country_code]) ? $countries[$country_code] : $country_code;
64 64
 
65
-    return apply_filters( 'wpinv_country_name', $country, $country_code );
65
+    return apply_filters('wpinv_country_name', $country, $country_code);
66 66
 }
67 67
 
68 68
 function wpinv_get_default_state() {
69
-	$state = wpinv_get_option( 'default_state', '' );
69
+	$state = wpinv_get_option('default_state', '');
70 70
 
71
-	return apply_filters( 'wpinv_default_state', $state );
71
+	return apply_filters('wpinv_default_state', $state);
72 72
 }
73 73
 
74
-function wpinv_state_name( $state_code = '', $country_code = '' ) {
74
+function wpinv_state_name($state_code = '', $country_code = '') {
75 75
     $state = $state_code;
76 76
     
77
-    if ( !empty( $country_code ) ) {
78
-        $states = wpinv_get_country_states( $country_code );
77
+    if (!empty($country_code)) {
78
+        $states = wpinv_get_country_states($country_code);
79 79
         
80
-        $state = !empty( $states ) && isset( $states[$state_code] ) ? $states[$state_code] : $state;
80
+        $state = !empty($states) && isset($states[$state_code]) ? $states[$state_code] : $state;
81 81
     }
82 82
 
83
-    return apply_filters( 'wpinv_state_name', $state, $state_code, $country_code );
83
+    return apply_filters('wpinv_state_name', $state, $state_code, $country_code);
84 84
 }
85 85
 
86 86
 function wpinv_store_address() {
87
-    $address = wpinv_get_option( 'store_address', '' );
87
+    $address = wpinv_get_option('store_address', '');
88 88
 
89
-    return apply_filters( 'wpinv_store_address', $address );
89
+    return apply_filters('wpinv_store_address', $address);
90 90
 }
91 91
 
92 92
 /**
@@ -94,24 +94,24 @@  discard block
 block discarded – undo
94 94
  *
95 95
  * @param WPInv_Invoice $invoice
96 96
  */
97
-function getpaid_maybe_add_default_address( &$invoice ) {
97
+function getpaid_maybe_add_default_address(&$invoice) {
98 98
 
99 99
     $user_id = $invoice->get_user_id();
100 100
 
101 101
     // Abort if the invoice belongs to no one.
102
-    if ( empty( $user_id ) ) {
102
+    if (empty($user_id)) {
103 103
         return;
104 104
     }
105 105
 
106 106
     // Fill in defaults whenever necessary.
107
-    foreach ( wpinv_get_user_address( $user_id ) as $key => $value ) {
107
+    foreach (wpinv_get_user_address($user_id) as $key => $value) {
108 108
 
109
-        if ( is_callable( $invoice, "get_$key" ) ) {
110
-            $current = call_user_func( array( $invoice, "get_$key" ) );
109
+        if (is_callable($invoice, "get_$key")) {
110
+            $current = call_user_func(array($invoice, "get_$key"));
111 111
 
112
-            if ( empty( $current ) ) {
112
+            if (empty($current)) {
113 113
                 $method = "set_$key";
114
-                $invoice->$method( $value );
114
+                $invoice->$method($value);
115 115
             }
116 116
 
117 117
         }
@@ -130,21 +130,21 @@  discard block
 block discarded – undo
130 130
     $address_fields = apply_filters(
131 131
         'getpaid_user_address_fields',
132 132
         array(
133
-            'first_name' => __( 'First Name', 'invoicing' ),
134
-            'last_name'  => __( 'Last Name', 'invoicing' ),
135
-            'country'    => __( 'Country', 'invoicing' ),
136
-            'state'      => __( 'State', 'invoicing' ),
137
-            'city'       => __( 'City', 'invoicing' ),
138
-            'zip'        => __( 'Zip/Postal Code', 'invoicing' ),
139
-            'address'    => __( 'Address', 'invoicing' ),
140
-            'phone'      => __( 'Phone Number', 'invoicing' ),
141
-            'company'    => __( 'Company', 'invoicing' ),
142
-            'vat_number' => __( 'VAT Number', 'invoicing' ),
133
+            'first_name' => __('First Name', 'invoicing'),
134
+            'last_name'  => __('Last Name', 'invoicing'),
135
+            'country'    => __('Country', 'invoicing'),
136
+            'state'      => __('State', 'invoicing'),
137
+            'city'       => __('City', 'invoicing'),
138
+            'zip'        => __('Zip/Postal Code', 'invoicing'),
139
+            'address'    => __('Address', 'invoicing'),
140
+            'phone'      => __('Phone Number', 'invoicing'),
141
+            'company'    => __('Company', 'invoicing'),
142
+            'vat_number' => __('VAT Number', 'invoicing'),
143 143
         )
144 144
     );
145 145
 
146
-    if ( ! wpinv_use_taxes() && isset( $address_fields['vat_number'] ) ) {
147
-        unset( $address_fields['vat_number'] );
146
+    if (!wpinv_use_taxes() && isset($address_fields['vat_number'])) {
147
+        unset($address_fields['vat_number']);
148 148
     }
149 149
 
150 150
     return $address_fields;
@@ -155,8 +155,8 @@  discard block
 block discarded – undo
155 155
  * 
156 156
  * @return bool
157 157
  */
158
-function getpaid_is_address_field_whitelisted( $key ) {
159
-    return array_key_exists( $key, getpaid_user_address_fields() );
158
+function getpaid_is_address_field_whitelisted($key) {
159
+    return array_key_exists($key, getpaid_user_address_fields());
160 160
 }
161 161
 
162 162
 /**
@@ -166,24 +166,24 @@  discard block
 block discarded – undo
166 166
  *
167 167
  * @param WPInv_Invoice $invoice
168 168
  */
169
-function getpaid_save_invoice_user_address( $invoice ) {
169
+function getpaid_save_invoice_user_address($invoice) {
170 170
 
171 171
     // Retrieve the invoice.
172
-    $invoice = wpinv_get_invoice( $invoice );
172
+    $invoice = wpinv_get_invoice($invoice);
173 173
 
174 174
     // Abort if it does not exist.
175
-    if ( empty( $invoice ) ) {
175
+    if (empty($invoice)) {
176 176
         return;
177 177
     }
178 178
 
179
-    foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
179
+    foreach (array_keys(getpaid_user_address_fields()) as $field) {
180 180
 
181
-        if ( is_callable( array( $invoice, "get_$field" ) ) ) {
182
-            $value = call_user_func( array( $invoice, "get_$field" ) );
181
+        if (is_callable(array($invoice, "get_$field"))) {
182
+            $value = call_user_func(array($invoice, "get_$field"));
183 183
 
184 184
             // Only save if it is not empty.
185
-            if ( ! empty( $value ) ) {
186
-                update_user_meta( $invoice->get_user_id(), '_wpinv_' . $field, $value );
185
+            if (!empty($value)) {
186
+                update_user_meta($invoice->get_user_id(), '_wpinv_' . $field, $value);
187 187
             }
188 188
 
189 189
         }
@@ -194,24 +194,24 @@  discard block
 block discarded – undo
194 194
     $last_name  = $invoice->get_last_name();
195 195
     $update     = array();
196 196
 
197
-    if ( ! empty( $first_name ) ) {
197
+    if (!empty($first_name)) {
198 198
         $update['first_name'] = $first_name;
199 199
     }
200 200
 
201
-    if ( ! empty( $last_name ) ) {
201
+    if (!empty($last_name)) {
202 202
         $update['last_name'] = $last_name;
203 203
     }
204 204
 
205
-    if ( 2 == count( $update ) ) {
206
-        $update['display_name'] = $first_name . ' ' .$last_name;
205
+    if (2 == count($update)) {
206
+        $update['display_name'] = $first_name . ' ' . $last_name;
207 207
     }
208 208
 
209 209
     $update['ID'] = $invoice->get_user_id();
210
-    wp_update_user( $update );
210
+    wp_update_user($update);
211 211
 
212 212
 }
213
-add_action( 'getpaid_new_invoice', 'getpaid_save_invoice_user_address' );
214
-add_action( 'getpaid_update_invoice', 'getpaid_save_invoice_user_address' );
213
+add_action('getpaid_new_invoice', 'getpaid_save_invoice_user_address');
214
+add_action('getpaid_update_invoice', 'getpaid_save_invoice_user_address');
215 215
 
216 216
 /**
217 217
  * Retrieves a saved user address.
@@ -220,14 +220,14 @@  discard block
 block discarded – undo
220 220
  * @param bool $with_default Whether or not we should use the default country and state.
221 221
  * @return array
222 222
  */
223
-function wpinv_get_user_address( $user_id = 0, $with_default = true ) {
223
+function wpinv_get_user_address($user_id = 0, $with_default = true) {
224 224
 
225 225
     // Prepare the user id.
226
-    $user_id   = empty( $user_id ) ? get_current_user_id() : $user_id;
227
-    $user_info = get_userdata( $user_id );
226
+    $user_id   = empty($user_id) ? get_current_user_id() : $user_id;
227
+    $user_info = get_userdata($user_id);
228 228
 
229 229
     // Abort if non exists.
230
-    if ( empty( $user_info ) ) {
230
+    if (empty($user_info)) {
231 231
         return array();
232 232
     }
233 233
 
@@ -237,11 +237,11 @@  discard block
 block discarded – undo
237 237
         'email'   => $user_info->user_email,
238 238
     );
239 239
 
240
-    foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
241
-        $address[$field] = getpaid_get_user_address_field( $user_id, $field );
240
+    foreach (array_keys(getpaid_user_address_fields()) as $field) {
241
+        $address[$field] = getpaid_get_user_address_field($user_id, $field);
242 242
     }
243 243
 
244
-    if ( ! $with_default ) {
244
+    if (!$with_default) {
245 245
         return $address;
246 246
     }
247 247
 
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
         'country'    => wpinv_get_default_country(),
253 253
     );
254 254
 
255
-    return getpaid_array_merge_if_empty( $address, $defaults );
255
+    return getpaid_array_merge_if_empty($address, $defaults);
256 256
 
257 257
 }
258 258
 
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
  * @param string $field The field to use.
264 264
  * @return string|null
265 265
  */
266
-function getpaid_get_user_address_field( $user_id, $field ) {
266
+function getpaid_get_user_address_field($user_id, $field) {
267 267
 
268 268
     $prefixes = array(
269 269
         '_wpinv_',
@@ -271,15 +271,15 @@  discard block
 block discarded – undo
271 271
         ''
272 272
     );
273 273
 
274
-    foreach ( $prefixes as $prefix ) {
274
+    foreach ($prefixes as $prefix) {
275 275
 
276 276
         // Meta table.
277
-        $value = get_user_meta( $user_id, $prefix . $field, true );
277
+        $value = get_user_meta($user_id, $prefix . $field, true);
278 278
         
279 279
         // UWP table.
280
-        $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value;
280
+        $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value;
281 281
 
282
-        if ( ! empty( $value ) ) {
282
+        if (!empty($value)) {
283 283
             return $value;
284 284
         }
285 285
 
@@ -296,16 +296,16 @@  discard block
 block discarded – undo
296 296
  * @param string $return What to return.
297 297
  * @return array
298 298
  */
299
-function wpinv_get_continents( $return = 'all' ) {
299
+function wpinv_get_continents($return = 'all') {
300 300
 
301
-    $continents = wpinv_get_data( 'continents' );
301
+    $continents = wpinv_get_data('continents');
302 302
 
303
-    switch( $return ) {
303
+    switch ($return) {
304 304
         case 'name' :
305
-            return wp_list_pluck( $continents, 'name' );
305
+            return wp_list_pluck($continents, 'name');
306 306
             break;
307 307
         case 'countries' :
308
-            return wp_list_pluck( $continents, 'countries' );
308
+            return wp_list_pluck($continents, 'countries');
309 309
             break;
310 310
         default :
311 311
             return $continents;
@@ -321,12 +321,12 @@  discard block
 block discarded – undo
321 321
  * @param string $country Country code. If no code is specified, defaults to the default country.
322 322
  * @return string
323 323
  */
324
-function wpinv_get_continent_code_for_country( $country = false ) {
324
+function wpinv_get_continent_code_for_country($country = false) {
325 325
 
326
-    $country = wpinv_sanitize_country( $country );
326
+    $country = wpinv_sanitize_country($country);
327 327
     
328
-	foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) {
329
-		if ( false !== array_search( $country, $countries, true ) ) {
328
+	foreach (wpinv_get_continents('countries') as $continent_code => $countries) {
329
+		if (false !== array_search($country, $countries, true)) {
330 330
 			return $continent_code;
331 331
 		}
332 332
 	}
@@ -342,13 +342,13 @@  discard block
 block discarded – undo
342 342
  * @param string $country Country code. If no code is specified, defaults to the default country.
343 343
  * @return array
344 344
  */
345
-function wpinv_get_country_calling_code( $country = null) {
345
+function wpinv_get_country_calling_code($country = null) {
346 346
 
347
-    $country = wpinv_sanitize_country( $country );
348
-    $codes   = wpinv_get_data( 'phone-codes' );
349
-    $code    = isset( $codes[ $country ] ) ? $codes[ $country ] : '';
347
+    $country = wpinv_sanitize_country($country);
348
+    $codes   = wpinv_get_data('phone-codes');
349
+    $code    = isset($codes[$country]) ? $codes[$country] : '';
350 350
 
351
-    if ( is_array( $code ) ) {
351
+    if (is_array($code)) {
352 352
         return $code[0];
353 353
     }
354 354
     return $code;
@@ -361,8 +361,8 @@  discard block
 block discarded – undo
361 361
  * @param bool $first_empty Whether or not the first item in the list should be empty
362 362
  * @return array
363 363
  */
364
-function wpinv_get_country_list( $first_empty = false ) {
365
-    return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty );
364
+function wpinv_get_country_list($first_empty = false) {
365
+    return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty);
366 366
 }
367 367
 
368 368
 /**
@@ -372,22 +372,22 @@  discard block
 block discarded – undo
372 372
  * @param bool $first_empty Whether or not the first item in the list should be empty
373 373
  * @return array
374 374
  */
375
-function wpinv_get_country_states( $country = null, $first_empty = false ) {
375
+function wpinv_get_country_states($country = null, $first_empty = false) {
376 376
     
377 377
     // Prepare the country.
378
-    $country = wpinv_sanitize_country( $country );
378
+    $country = wpinv_sanitize_country($country);
379 379
 
380 380
     // Fetch all states.
381
-    $all_states = wpinv_get_data( 'states' );
381
+    $all_states = wpinv_get_data('states');
382 382
 
383 383
     // Fetch the specified country's states.
384
-    $states     = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array() ;
385
-    $states     = apply_filters( "wpinv_{$country}_states", $states );
386
-    $states     = apply_filters( 'wpinv_country_states', $states, $country );
384
+    $states     = isset($all_states[$country]) ? $all_states[$country] : array();
385
+    $states     = apply_filters("wpinv_{$country}_states", $states);
386
+    $states     = apply_filters('wpinv_country_states', $states, $country);
387 387
 
388
-    asort( $states );
388
+    asort($states);
389 389
      
390
-    return wpinv_maybe_add_empty_option( $states, $first_empty );
390
+    return wpinv_maybe_add_empty_option($states, $first_empty);
391 391
 }
392 392
 
393 393
 /**
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
  * @return array
398 398
  */
399 399
 function wpinv_get_us_states_list() {
400
-    return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) );
400
+    return apply_filters('wpinv_usa_states', wpinv_get_country_states('US'));
401 401
 }
402 402
 
403 403
 /**
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
  * @return array
408 408
  */
409 409
 function wpinv_get_canada_states_list() {
410
-    return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) );
410
+    return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA'));
411 411
 }
412 412
 
413 413
 /**
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
  * @return array
418 418
  */
419 419
 function wpinv_get_australia_states_list() {
420
-    return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) );
420
+    return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU'));
421 421
 }
422 422
 
423 423
 /**
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
  * @return array
428 428
  */
429 429
 function wpinv_get_bangladesh_states_list() {
430
-    return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) );
430
+    return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD'));
431 431
 }
432 432
 
433 433
 /**
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
  * @return array
438 438
  */
439 439
 function wpinv_get_brazil_states_list() {
440
-    return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) );
440
+    return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR'));
441 441
 }
442 442
 
443 443
 /**
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
  * @return array
448 448
  */
449 449
 function wpinv_get_bulgaria_states_list() {
450
-    return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) );
450
+    return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG'));
451 451
 }
452 452
 
453 453
 /**
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
  * @return array
458 458
  */
459 459
 function wpinv_get_hong_kong_states_list() {
460
-    return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) );
460
+    return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK'));
461 461
 }
462 462
 
463 463
 /**
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
  * @return array
468 468
  */
469 469
 function wpinv_get_hungary_states_list() {
470
-    return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) );
470
+    return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU'));
471 471
 }
472 472
 
473 473
 /**
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
  * @return array
478 478
  */
479 479
 function wpinv_get_japan_states_list() {
480
-    return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) );
480
+    return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP'));
481 481
 }
482 482
 
483 483
 /**
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
  * @return array
488 488
  */
489 489
 function wpinv_get_china_states_list() {
490
-    return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) );
490
+    return apply_filters('wpinv_china_states', wpinv_get_country_states('CN'));
491 491
 }
492 492
 
493 493
 /**
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
  * @return array
498 498
  */
499 499
 function wpinv_get_new_zealand_states_list() {
500
-    return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) );
500
+    return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ'));
501 501
 }
502 502
 
503 503
 /**
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
  * @return array
508 508
  */
509 509
 function wpinv_get_peru_states_list() {
510
-    return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) );
510
+    return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE'));
511 511
 }
512 512
 
513 513
 /**
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
  * @return array
518 518
  */
519 519
 function wpinv_get_indonesia_states_list() {
520
-    return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) );
520
+    return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID'));
521 521
 }
522 522
 
523 523
 /**
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
  * @return array
528 528
  */
529 529
 function wpinv_get_india_states_list() {
530
-    return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) );
530
+    return apply_filters('wpinv_india_states', wpinv_get_country_states('IN'));
531 531
 }
532 532
 
533 533
 /**
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
  * @return array
538 538
  */
539 539
 function wpinv_get_iran_states_list() {
540
-    return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) );
540
+    return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR'));
541 541
 }
542 542
 
543 543
 /**
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
  * @return array
548 548
  */
549 549
 function wpinv_get_italy_states_list() {
550
-    return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) );
550
+    return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT'));
551 551
 }
552 552
 
553 553
 /**
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
  * @return array
558 558
  */
559 559
 function wpinv_get_malaysia_states_list() {
560
-    return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) );
560
+    return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY'));
561 561
 }
562 562
 
563 563
 /**
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
  * @return array
568 568
  */
569 569
 function wpinv_get_mexico_states_list() {
570
-    return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) );
570
+    return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX'));
571 571
 }
572 572
 
573 573
 /**
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
  * @return array
578 578
  */
579 579
 function wpinv_get_nepal_states_list() {
580
-    return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) );
580
+    return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP'));
581 581
 }
582 582
 
583 583
 /**
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
  * @return array
588 588
  */
589 589
 function wpinv_get_south_africa_states_list() {
590
-    return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) );
590
+    return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA'));
591 591
 }
592 592
 
593 593
 /**
@@ -597,7 +597,7 @@  discard block
 block discarded – undo
597 597
  * @return array
598 598
  */
599 599
 function wpinv_get_thailand_states_list() {
600
-    return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) );
600
+    return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH'));
601 601
 }
602 602
 
603 603
 /**
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
  * @return array
608 608
  */
609 609
 function wpinv_get_turkey_states_list() {
610
-    return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) );
610
+    return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR'));
611 611
 }
612 612
 
613 613
 /**
@@ -617,28 +617,28 @@  discard block
 block discarded – undo
617 617
  * @return array
618 618
  */
619 619
 function wpinv_get_spain_states_list() {
620
-    return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) );
620
+    return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES'));
621 621
 }
622 622
 
623 623
 function wpinv_get_states_field() {
624
-	if( empty( $_POST['country'] ) ) {
624
+	if (empty($_POST['country'])) {
625 625
 		$_POST['country'] = wpinv_get_default_country();
626 626
 	}
627
-	$states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
627
+	$states = wpinv_get_country_states(sanitize_text_field($_POST['country']));
628 628
 
629
-	if( !empty( $states ) ) {
630
-		$sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
629
+	if (!empty($states)) {
630
+		$sanitized_field_name = sanitize_text_field($_POST['field_name']);
631 631
         
632 632
         $args = array(
633 633
 			'name'    => $sanitized_field_name,
634 634
 			'id'      => $sanitized_field_name,
635 635
 			'class'   => $sanitized_field_name . 'custom-select wpinv-select wpi_select2',
636
-			'options' => array_merge( array( '' => '' ), $states ),
636
+			'options' => array_merge(array('' => ''), $states),
637 637
 			'show_option_all'  => false,
638 638
 			'show_option_none' => false
639 639
 		);
640 640
 
641
-		$response = wpinv_html_select( $args );
641
+		$response = wpinv_html_select($args);
642 642
 
643 643
 	} else {
644 644
 		$response = 'nostates';
@@ -647,10 +647,10 @@  discard block
 block discarded – undo
647 647
 	return $response;
648 648
 }
649 649
 
650
-function wpinv_default_billing_country( $country = '', $user_id = 0 ) {
651
-    $country = !empty( $country ) ? $country : wpinv_get_default_country();
650
+function wpinv_default_billing_country($country = '', $user_id = 0) {
651
+    $country = !empty($country) ? $country : wpinv_get_default_country();
652 652
     
653
-    return apply_filters( 'wpinv_default_billing_country', $country, $user_id );
653
+    return apply_filters('wpinv_default_billing_country', $country, $user_id);
654 654
 }
655 655
 
656 656
 /**
@@ -662,7 +662,7 @@  discard block
 block discarded – undo
662 662
  */
663 663
 function wpinv_get_address_formats() {
664 664
 
665
-		return apply_filters( 'wpinv_localisation_address_formats',
665
+		return apply_filters('wpinv_localisation_address_formats',
666 666
 			array(
667 667
 				'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}",
668 668
 				'AU'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}",
@@ -711,9 +711,9 @@  discard block
 block discarded – undo
711 711
  * @see `wpinv_get_invoice_address_replacements`
712 712
  * @return string
713 713
  */
714
-function wpinv_get_full_address_format( $country = false) {
714
+function wpinv_get_full_address_format($country = false) {
715 715
 
716
-    if( empty( $country ) ) {
716
+    if (empty($country)) {
717 717
         $country = wpinv_get_default_country();
718 718
     }
719 719
 
@@ -721,7 +721,7 @@  discard block
 block discarded – undo
721 721
 	$formats = wpinv_get_address_formats();
722 722
 
723 723
 	// Get format for the specified country.
724
-	$format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
724
+	$format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default'];
725 725
     
726 726
     /**
727 727
 	 * Filters the address format to use on Invoices.
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
 	 * @param string $format  The address format to use.
734 734
      * @param string $country The country who's address format is being retrieved.
735 735
 	 */
736
-    return apply_filters( 'wpinv_get_full_address_format', $format, $country );
736
+    return apply_filters('wpinv_get_full_address_format', $format, $country);
737 737
 }
738 738
 
739 739
 /**
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
  * @param array $billing_details customer's billing details
745 745
  * @return array
746 746
  */
747
-function wpinv_get_invoice_address_replacements( $billing_details ) {
747
+function wpinv_get_invoice_address_replacements($billing_details) {
748 748
 
749 749
     $default_args = array(
750 750
         'address'           => '',
@@ -757,22 +757,22 @@  discard block
 block discarded – undo
757 757
 		'company'           => '',
758 758
     );
759 759
 
760
-    $args    = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' );
760
+    $args    = map_deep(wp_parse_args($billing_details, $default_args), 'trim');
761 761
     $state   = $args['state'];
762 762
     $country = $args['country'];
763 763
 
764 764
     // Handle full country name.
765
-    $full_country = empty( $country ) ? $country : wpinv_country_name( $country );
765
+    $full_country = empty($country) ? $country : wpinv_country_name($country);
766 766
 
767 767
     // Handle full state name.
768
-    $full_state   = ( $country && $state ) ?  wpinv_state_name( $state, $country ) : $state;
768
+    $full_state   = ($country && $state) ?  wpinv_state_name($state, $country) : $state;
769 769
 
770 770
     $args['postcode']    = $args['zip'];
771 771
     $args['name']        = $args['first_name'] . ' ' . $args['last_name'];
772 772
     $args['state']       = $full_state;
773 773
     $args['state_code']  = $state;
774 774
     $args['country']     = $full_country;
775
-    $args['country_code']= $country;
775
+    $args['country_code'] = $country;
776 776
 
777 777
     /**
778 778
 	 * Filters the address format replacements to use on Invoices.
@@ -783,14 +783,14 @@  discard block
 block discarded – undo
783 783
 	 * @param array $replacements  The address replacements to use.
784 784
      * @param array $billing_details  The billing details to use.
785 785
 	 */
786
-    $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details );
786
+    $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details);
787 787
 
788 788
     $return = array();
789 789
 
790
-    foreach( $replacements as $key => $value ) {
791
-        $value  = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : '';
790
+    foreach ($replacements as $key => $value) {
791
+        $value = is_scalar($value) ? trim(sanitize_text_field($value)) : '';
792 792
         $return['{{' . $key . '}}'] = $value;
793
-        $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper( $value );
793
+        $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value);
794 794
     }
795 795
 
796 796
     return $return;
@@ -804,6 +804,6 @@  discard block
 block discarded – undo
804 804
  * @since 1.0.14
805 805
  * @return string
806 806
  */
807
-function wpinv_trim_formatted_address_line( $line ) {
808
-	return trim( $line, ', ' );
807
+function wpinv_trim_formatted_address_line($line) {
808
+	return trim($line, ', ');
809 809
 }
810 810
\ No newline at end of file
Please login to merge, or discard this patch.