Passed
Pull Request — master (#572)
by Brian
05:40
created
includes/wpinv-address-functions.php 1 patch
Spacing   +140 added lines, -140 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
-            'address'    => __( 'Address', 'invoicing' ),
136
-            'city'       => __( 'City', 'invoicing' ),
137
-            'country'    => __( 'Country', 'invoicing' ),
138
-            'state'      => __( 'State', 'invoicing' ),
139
-            'zip'        => __( 'Zip/Postal Code', '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
+            'address'    => __('Address', 'invoicing'),
136
+            'city'       => __('City', 'invoicing'),
137
+            'country'    => __('Country', 'invoicing'),
138
+            'state'      => __('State', 'invoicing'),
139
+            'zip'        => __('Zip/Postal Code', '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 ) || $invoice->is_renewal() ) {
175
+    if (empty($invoice) || $invoice->is_renewal()) {
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
         }
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
     }
192 192
 
193 193
 }
194
-add_action( 'getpaid_checkout_invoice_updated', 'getpaid_save_invoice_user_address' );
194
+add_action('getpaid_checkout_invoice_updated', 'getpaid_save_invoice_user_address');
195 195
 
196 196
 /**
197 197
  * Retrieves a saved user address.
@@ -200,14 +200,14 @@  discard block
 block discarded – undo
200 200
  * @param bool $with_default Whether or not we should use the default country and state.
201 201
  * @return array
202 202
  */
203
-function wpinv_get_user_address( $user_id = 0, $with_default = true ) {
203
+function wpinv_get_user_address($user_id = 0, $with_default = true) {
204 204
 
205 205
     // Prepare the user id.
206
-    $user_id   = empty( $user_id ) ? get_current_user_id() : $user_id;
207
-    $user_info = get_userdata( $user_id );
206
+    $user_id   = empty($user_id) ? get_current_user_id() : $user_id;
207
+    $user_info = get_userdata($user_id);
208 208
 
209 209
     // Abort if non exists.
210
-    if ( empty( $user_info ) ) {
210
+    if (empty($user_info)) {
211 211
         return array();
212 212
     }
213 213
 
@@ -217,11 +217,11 @@  discard block
 block discarded – undo
217 217
         'email'   => $user_info->user_email,
218 218
     );
219 219
 
220
-    foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
221
-        $address[$field] = getpaid_get_user_address_field( $user_id, $field );
220
+    foreach (array_keys(getpaid_user_address_fields()) as $field) {
221
+        $address[$field] = getpaid_get_user_address_field($user_id, $field);
222 222
     }
223 223
 
224
-    if ( ! $with_default ) {
224
+    if (!$with_default) {
225 225
         return $address;
226 226
     }
227 227
 
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
         'country'    => wpinv_get_default_country(),
233 233
     );
234 234
 
235
-    return getpaid_array_merge_if_empty( $address, $defaults );
235
+    return getpaid_array_merge_if_empty($address, $defaults);
236 236
 
237 237
 }
238 238
 
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
  * @param string $field The field to use.
244 244
  * @return string|null
245 245
  */
246
-function getpaid_get_user_address_field( $user_id, $field ) {
246
+function getpaid_get_user_address_field($user_id, $field) {
247 247
 
248 248
     $prefixes = array(
249 249
         '_wpinv_',
@@ -251,15 +251,15 @@  discard block
 block discarded – undo
251 251
         ''
252 252
     );
253 253
 
254
-    foreach ( $prefixes as $prefix ) {
254
+    foreach ($prefixes as $prefix) {
255 255
 
256 256
         // Meta table.
257
-        $value = get_user_meta( $user_id, $prefix . $field, true );
257
+        $value = get_user_meta($user_id, $prefix . $field, true);
258 258
         
259 259
         // UWP table.
260
-        $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value;
260
+        $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value;
261 261
 
262
-        if ( ! empty( $value ) ) {
262
+        if (!empty($value)) {
263 263
             return $value;
264 264
         }
265 265
 
@@ -276,16 +276,16 @@  discard block
 block discarded – undo
276 276
  * @param string $return What to return.
277 277
  * @return array
278 278
  */
279
-function wpinv_get_continents( $return = 'all' ) {
279
+function wpinv_get_continents($return = 'all') {
280 280
 
281
-    $continents = wpinv_get_data( 'continents' );
281
+    $continents = wpinv_get_data('continents');
282 282
 
283
-    switch( $return ) {
283
+    switch ($return) {
284 284
         case 'name' :
285
-            return wp_list_pluck( $continents, 'name' );
285
+            return wp_list_pluck($continents, 'name');
286 286
             break;
287 287
         case 'countries' :
288
-            return wp_list_pluck( $continents, 'countries' );
288
+            return wp_list_pluck($continents, 'countries');
289 289
             break;
290 290
         default :
291 291
             return $continents;
@@ -301,12 +301,12 @@  discard block
 block discarded – undo
301 301
  * @param string $country Country code. If no code is specified, defaults to the default country.
302 302
  * @return string
303 303
  */
304
-function wpinv_get_continent_code_for_country( $country = false ) {
304
+function wpinv_get_continent_code_for_country($country = false) {
305 305
 
306
-    $country = wpinv_sanitize_country( $country );
306
+    $country = wpinv_sanitize_country($country);
307 307
     
308
-	foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) {
309
-		if ( false !== array_search( $country, $countries, true ) ) {
308
+	foreach (wpinv_get_continents('countries') as $continent_code => $countries) {
309
+		if (false !== array_search($country, $countries, true)) {
310 310
 			return $continent_code;
311 311
 		}
312 312
 	}
@@ -322,13 +322,13 @@  discard block
 block discarded – undo
322 322
  * @param string $country Country code. If no code is specified, defaults to the default country.
323 323
  * @return array
324 324
  */
325
-function wpinv_get_country_calling_code( $country = null) {
325
+function wpinv_get_country_calling_code($country = null) {
326 326
 
327
-    $country = wpinv_sanitize_country( $country );
328
-    $codes   = wpinv_get_data( 'phone-codes' );
329
-    $code    = isset( $codes[ $country ] ) ? $codes[ $country ] : '';
327
+    $country = wpinv_sanitize_country($country);
328
+    $codes   = wpinv_get_data('phone-codes');
329
+    $code    = isset($codes[$country]) ? $codes[$country] : '';
330 330
 
331
-    if ( is_array( $code ) ) {
331
+    if (is_array($code)) {
332 332
         return $code[0];
333 333
     }
334 334
     return $code;
@@ -341,8 +341,8 @@  discard block
 block discarded – undo
341 341
  * @param bool $first_empty Whether or not the first item in the list should be empty
342 342
  * @return array
343 343
  */
344
-function wpinv_get_country_list( $first_empty = false ) {
345
-    return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty );
344
+function wpinv_get_country_list($first_empty = false) {
345
+    return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty);
346 346
 }
347 347
 
348 348
 /**
@@ -352,22 +352,22 @@  discard block
 block discarded – undo
352 352
  * @param bool $first_empty Whether or not the first item in the list should be empty
353 353
  * @return array
354 354
  */
355
-function wpinv_get_country_states( $country = null, $first_empty = false ) {
355
+function wpinv_get_country_states($country = null, $first_empty = false) {
356 356
     
357 357
     // Prepare the country.
358
-    $country = wpinv_sanitize_country( $country );
358
+    $country = wpinv_sanitize_country($country);
359 359
 
360 360
     // Fetch all states.
361
-    $all_states = wpinv_get_data( 'states' );
361
+    $all_states = wpinv_get_data('states');
362 362
 
363 363
     // Fetch the specified country's states.
364
-    $states     = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array() ;
365
-    $states     = apply_filters( "wpinv_{$country}_states", $states );
366
-    $states     = apply_filters( 'wpinv_country_states', $states, $country );
364
+    $states     = isset($all_states[$country]) ? $all_states[$country] : array();
365
+    $states     = apply_filters("wpinv_{$country}_states", $states);
366
+    $states     = apply_filters('wpinv_country_states', $states, $country);
367 367
 
368
-    asort( $states );
368
+    asort($states);
369 369
      
370
-    return wpinv_maybe_add_empty_option( $states, $first_empty );
370
+    return wpinv_maybe_add_empty_option($states, $first_empty);
371 371
 }
372 372
 
373 373
 /**
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
  * @return array
378 378
  */
379 379
 function wpinv_get_us_states_list() {
380
-    return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) );
380
+    return apply_filters('wpinv_usa_states', wpinv_get_country_states('US'));
381 381
 }
382 382
 
383 383
 /**
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
  * @return array
388 388
  */
389 389
 function wpinv_get_canada_states_list() {
390
-    return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) );
390
+    return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA'));
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_australia_states_list() {
400
-    return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) );
400
+    return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU'));
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_bangladesh_states_list() {
410
-    return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) );
410
+    return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD'));
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_brazil_states_list() {
420
-    return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) );
420
+    return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR'));
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_bulgaria_states_list() {
430
-    return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) );
430
+    return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG'));
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_hong_kong_states_list() {
440
-    return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) );
440
+    return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK'));
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_hungary_states_list() {
450
-    return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) );
450
+    return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU'));
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_japan_states_list() {
460
-    return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) );
460
+    return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP'));
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_china_states_list() {
470
-    return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) );
470
+    return apply_filters('wpinv_china_states', wpinv_get_country_states('CN'));
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_new_zealand_states_list() {
480
-    return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) );
480
+    return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ'));
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_peru_states_list() {
490
-    return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) );
490
+    return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE'));
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_indonesia_states_list() {
500
-    return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) );
500
+    return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID'));
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_india_states_list() {
510
-    return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) );
510
+    return apply_filters('wpinv_india_states', wpinv_get_country_states('IN'));
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_iran_states_list() {
520
-    return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) );
520
+    return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR'));
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_italy_states_list() {
530
-    return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) );
530
+    return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT'));
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_malaysia_states_list() {
540
-    return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) );
540
+    return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY'));
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_mexico_states_list() {
550
-    return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) );
550
+    return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX'));
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_nepal_states_list() {
560
-    return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) );
560
+    return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP'));
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_south_africa_states_list() {
570
-    return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) );
570
+    return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA'));
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_thailand_states_list() {
580
-    return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) );
580
+    return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH'));
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_turkey_states_list() {
590
-    return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) );
590
+    return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR'));
591 591
 }
592 592
 
593 593
 /**
@@ -597,28 +597,28 @@  discard block
 block discarded – undo
597 597
  * @return array
598 598
  */
599 599
 function wpinv_get_spain_states_list() {
600
-    return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) );
600
+    return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES'));
601 601
 }
602 602
 
603 603
 function wpinv_get_states_field() {
604
-	if( empty( $_POST['country'] ) ) {
604
+	if (empty($_POST['country'])) {
605 605
 		$_POST['country'] = wpinv_get_default_country();
606 606
 	}
607
-	$states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
607
+	$states = wpinv_get_country_states(sanitize_text_field($_POST['country']));
608 608
 
609
-	if( !empty( $states ) ) {
610
-		$sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
609
+	if (!empty($states)) {
610
+		$sanitized_field_name = sanitize_text_field($_POST['field_name']);
611 611
         
612 612
         $args = array(
613 613
 			'name'    => $sanitized_field_name,
614 614
 			'id'      => $sanitized_field_name,
615 615
 			'class'   => $sanitized_field_name . 'custom-select wpinv-select wpi_select2',
616
-			'options' => array_merge( array( '' => '' ), $states ),
616
+			'options' => array_merge(array('' => ''), $states),
617 617
 			'show_option_all'  => false,
618 618
 			'show_option_none' => false
619 619
 		);
620 620
 
621
-		$response = wpinv_html_select( $args );
621
+		$response = wpinv_html_select($args);
622 622
 
623 623
 	} else {
624 624
 		$response = 'nostates';
@@ -627,10 +627,10 @@  discard block
 block discarded – undo
627 627
 	return $response;
628 628
 }
629 629
 
630
-function wpinv_default_billing_country( $country = '', $user_id = 0 ) {
631
-    $country = !empty( $country ) ? $country : wpinv_get_default_country();
630
+function wpinv_default_billing_country($country = '', $user_id = 0) {
631
+    $country = !empty($country) ? $country : wpinv_get_default_country();
632 632
     
633
-    return apply_filters( 'wpinv_default_billing_country', $country, $user_id );
633
+    return apply_filters('wpinv_default_billing_country', $country, $user_id);
634 634
 }
635 635
 
636 636
 /**
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
  */
643 643
 function wpinv_get_address_formats() {
644 644
 
645
-		return apply_filters( 'wpinv_localisation_address_formats',
645
+		return apply_filters('wpinv_localisation_address_formats',
646 646
 			array(
647 647
 				'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}",
648 648
 				'AU'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}",
@@ -691,9 +691,9 @@  discard block
 block discarded – undo
691 691
  * @see `wpinv_get_invoice_address_replacements`
692 692
  * @return string
693 693
  */
694
-function wpinv_get_full_address_format( $country = false) {
694
+function wpinv_get_full_address_format($country = false) {
695 695
 
696
-    if( empty( $country ) ) {
696
+    if (empty($country)) {
697 697
         $country = wpinv_get_default_country();
698 698
     }
699 699
 
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
 	$formats = wpinv_get_address_formats();
702 702
 
703 703
 	// Get format for the specified country.
704
-	$format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
704
+	$format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default'];
705 705
     
706 706
     /**
707 707
 	 * Filters the address format to use on Invoices.
@@ -713,7 +713,7 @@  discard block
 block discarded – undo
713 713
 	 * @param string $format  The address format to use.
714 714
      * @param string $country The country who's address format is being retrieved.
715 715
 	 */
716
-    return apply_filters( 'wpinv_get_full_address_format', $format, $country );
716
+    return apply_filters('wpinv_get_full_address_format', $format, $country);
717 717
 }
718 718
 
719 719
 /**
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
  * @param array $billing_details customer's billing details
725 725
  * @return array
726 726
  */
727
-function wpinv_get_invoice_address_replacements( $billing_details ) {
727
+function wpinv_get_invoice_address_replacements($billing_details) {
728 728
 
729 729
     $default_args = array(
730 730
         'address'           => '',
@@ -737,22 +737,22 @@  discard block
 block discarded – undo
737 737
 		'company'           => '',
738 738
     );
739 739
 
740
-    $args    = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' );
740
+    $args    = map_deep(wp_parse_args($billing_details, $default_args), 'trim');
741 741
     $state   = $args['state'];
742 742
     $country = $args['country'];
743 743
 
744 744
     // Handle full country name.
745
-    $full_country = empty( $country ) ? $country : wpinv_country_name( $country );
745
+    $full_country = empty($country) ? $country : wpinv_country_name($country);
746 746
 
747 747
     // Handle full state name.
748
-    $full_state   = ( $country && $state ) ?  wpinv_state_name( $state, $country ) : $state;
748
+    $full_state   = ($country && $state) ?  wpinv_state_name($state, $country) : $state;
749 749
 
750 750
     $args['postcode']    = $args['zip'];
751 751
     $args['name']        = $args['first_name'] . ' ' . $args['last_name'];
752 752
     $args['state']       = $full_state;
753 753
     $args['state_code']  = $state;
754 754
     $args['country']     = $full_country;
755
-    $args['country_code']= $country;
755
+    $args['country_code'] = $country;
756 756
 
757 757
     /**
758 758
 	 * Filters the address format replacements to use on Invoices.
@@ -763,14 +763,14 @@  discard block
 block discarded – undo
763 763
 	 * @param array $replacements  The address replacements to use.
764 764
      * @param array $billing_details  The billing details to use.
765 765
 	 */
766
-    $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details );
766
+    $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details);
767 767
 
768 768
     $return = array();
769 769
 
770
-    foreach( $replacements as $key => $value ) {
771
-        $value  = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : '';
770
+    foreach ($replacements as $key => $value) {
771
+        $value = is_scalar($value) ? trim(sanitize_text_field($value)) : '';
772 772
         $return['{{' . $key . '}}'] = $value;
773
-        $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper( $value );
773
+        $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value);
774 774
     }
775 775
 
776 776
     return $return;
@@ -784,6 +784,6 @@  discard block
 block discarded – undo
784 784
  * @since 1.0.14
785 785
  * @return string
786 786
  */
787
-function wpinv_trim_formatted_address_line( $line ) {
788
-	return trim( $line, ', ' );
787
+function wpinv_trim_formatted_address_line($line) {
788
+	return trim($line, ', ');
789 789
 }
790 790
\ No newline at end of file
Please login to merge, or discard this patch.