@@ -7,15 +7,15 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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,22 +130,22 @@ discard block |
||
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 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
143 | - '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 | + 'company_id' => __('Company ID', 'invoicing'), |
|
143 | + 'vat_number' => __('VAT Number', 'invoicing'), |
|
144 | 144 | ) |
145 | 145 | ); |
146 | 146 | |
147 | - if ( ! wpinv_use_taxes() && isset( $address_fields['vat_number'] ) ) { |
|
148 | - unset( $address_fields['vat_number'] ); |
|
147 | + if (!wpinv_use_taxes() && isset($address_fields['vat_number'])) { |
|
148 | + unset($address_fields['vat_number']); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | return $address_fields; |
@@ -156,8 +156,8 @@ discard block |
||
156 | 156 | * |
157 | 157 | * @return bool |
158 | 158 | */ |
159 | -function getpaid_is_address_field_whitelisted( $key ) { |
|
160 | - return array_key_exists( $key, getpaid_user_address_fields() ); |
|
159 | +function getpaid_is_address_field_whitelisted($key) { |
|
160 | + return array_key_exists($key, getpaid_user_address_fields()); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -167,24 +167,24 @@ discard block |
||
167 | 167 | * |
168 | 168 | * @param WPInv_Invoice $invoice |
169 | 169 | */ |
170 | -function getpaid_save_invoice_user_address( $invoice ) { |
|
170 | +function getpaid_save_invoice_user_address($invoice) { |
|
171 | 171 | |
172 | 172 | // Retrieve the invoice. |
173 | - $invoice = wpinv_get_invoice( $invoice ); |
|
173 | + $invoice = wpinv_get_invoice($invoice); |
|
174 | 174 | |
175 | 175 | // Abort if it does not exist. |
176 | - if ( empty( $invoice ) || $invoice->is_renewal() ) { |
|
176 | + if (empty($invoice) || $invoice->is_renewal()) { |
|
177 | 177 | return; |
178 | 178 | } |
179 | 179 | |
180 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
180 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
181 | 181 | |
182 | - if ( is_callable( array( $invoice, "get_$field" ) ) ) { |
|
183 | - $value = call_user_func( array( $invoice, "get_$field" ) ); |
|
182 | + if (is_callable(array($invoice, "get_$field"))) { |
|
183 | + $value = call_user_func(array($invoice, "get_$field")); |
|
184 | 184 | |
185 | 185 | // Only save if it is not empty. |
186 | - if ( ! empty( $value ) ) { |
|
187 | - update_user_meta( $invoice->get_user_id(), '_wpinv_' . $field, $value ); |
|
186 | + if (!empty($value)) { |
|
187 | + update_user_meta($invoice->get_user_id(), '_wpinv_' . $field, $value); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | } |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | } |
193 | 193 | |
194 | 194 | } |
195 | -add_action( 'getpaid_checkout_invoice_updated', 'getpaid_save_invoice_user_address' ); |
|
195 | +add_action('getpaid_checkout_invoice_updated', 'getpaid_save_invoice_user_address'); |
|
196 | 196 | |
197 | 197 | /** |
198 | 198 | * Retrieves a saved user address. |
@@ -201,14 +201,14 @@ discard block |
||
201 | 201 | * @param bool $with_default Whether or not we should use the default country and state. |
202 | 202 | * @return array |
203 | 203 | */ |
204 | -function wpinv_get_user_address( $user_id = 0, $with_default = true ) { |
|
204 | +function wpinv_get_user_address($user_id = 0, $with_default = true) { |
|
205 | 205 | |
206 | 206 | // Prepare the user id. |
207 | - $user_id = empty( $user_id ) ? get_current_user_id() : $user_id; |
|
208 | - $user_info = get_userdata( $user_id ); |
|
207 | + $user_id = empty($user_id) ? get_current_user_id() : $user_id; |
|
208 | + $user_info = get_userdata($user_id); |
|
209 | 209 | |
210 | 210 | // Abort if non exists. |
211 | - if ( empty( $user_info ) ) { |
|
211 | + if (empty($user_info)) { |
|
212 | 212 | return array(); |
213 | 213 | } |
214 | 214 | |
@@ -218,13 +218,13 @@ discard block |
||
218 | 218 | 'email' => $user_info->user_email, |
219 | 219 | ); |
220 | 220 | |
221 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
222 | - $address[$field] = getpaid_get_user_address_field( $user_id, $field ); |
|
221 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
222 | + $address[$field] = getpaid_get_user_address_field($user_id, $field); |
|
223 | 223 | } |
224 | 224 | |
225 | - $address = array_filter( $address ); |
|
225 | + $address = array_filter($address); |
|
226 | 226 | |
227 | - if ( ! $with_default ) { |
|
227 | + if (!$with_default) { |
|
228 | 228 | return $address; |
229 | 229 | } |
230 | 230 | |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | 'country' => wpinv_get_default_country(), |
236 | 236 | ); |
237 | 237 | |
238 | - return getpaid_array_merge_if_empty( $address, $defaults ); |
|
238 | + return getpaid_array_merge_if_empty($address, $defaults); |
|
239 | 239 | |
240 | 240 | } |
241 | 241 | |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | * @param string $field The field to use. |
247 | 247 | * @return string|null |
248 | 248 | */ |
249 | -function getpaid_get_user_address_field( $user_id, $field ) { |
|
249 | +function getpaid_get_user_address_field($user_id, $field) { |
|
250 | 250 | |
251 | 251 | $prefixes = array( |
252 | 252 | '_wpinv_', |
@@ -254,15 +254,15 @@ discard block |
||
254 | 254 | '' |
255 | 255 | ); |
256 | 256 | |
257 | - foreach ( $prefixes as $prefix ) { |
|
257 | + foreach ($prefixes as $prefix) { |
|
258 | 258 | |
259 | 259 | // Meta table. |
260 | - $value = get_user_meta( $user_id, $prefix . $field, true ); |
|
260 | + $value = get_user_meta($user_id, $prefix . $field, true); |
|
261 | 261 | |
262 | 262 | // UWP table. |
263 | - $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value; |
|
263 | + $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value; |
|
264 | 264 | |
265 | - if ( ! empty( $value ) ) { |
|
265 | + if (!empty($value)) { |
|
266 | 266 | return $value; |
267 | 267 | } |
268 | 268 | |
@@ -279,16 +279,16 @@ discard block |
||
279 | 279 | * @param string $return What to return. |
280 | 280 | * @return array |
281 | 281 | */ |
282 | -function wpinv_get_continents( $return = 'all' ) { |
|
282 | +function wpinv_get_continents($return = 'all') { |
|
283 | 283 | |
284 | - $continents = wpinv_get_data( 'continents' ); |
|
284 | + $continents = wpinv_get_data('continents'); |
|
285 | 285 | |
286 | - switch( $return ) { |
|
286 | + switch ($return) { |
|
287 | 287 | case 'name' : |
288 | - return wp_list_pluck( $continents, 'name' ); |
|
288 | + return wp_list_pluck($continents, 'name'); |
|
289 | 289 | break; |
290 | 290 | case 'countries' : |
291 | - return wp_list_pluck( $continents, 'countries' ); |
|
291 | + return wp_list_pluck($continents, 'countries'); |
|
292 | 292 | break; |
293 | 293 | default : |
294 | 294 | return $continents; |
@@ -304,12 +304,12 @@ discard block |
||
304 | 304 | * @param string $country Country code. If no code is specified, defaults to the default country. |
305 | 305 | * @return string |
306 | 306 | */ |
307 | -function wpinv_get_continent_code_for_country( $country = false ) { |
|
307 | +function wpinv_get_continent_code_for_country($country = false) { |
|
308 | 308 | |
309 | - $country = wpinv_sanitize_country( $country ); |
|
309 | + $country = wpinv_sanitize_country($country); |
|
310 | 310 | |
311 | - foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
312 | - if ( false !== array_search( $country, $countries, true ) ) { |
|
311 | + foreach (wpinv_get_continents('countries') as $continent_code => $countries) { |
|
312 | + if (false !== array_search($country, $countries, true)) { |
|
313 | 313 | return $continent_code; |
314 | 314 | } |
315 | 315 | } |
@@ -325,13 +325,13 @@ discard block |
||
325 | 325 | * @param string $country Country code. If no code is specified, defaults to the default country. |
326 | 326 | * @return array |
327 | 327 | */ |
328 | -function wpinv_get_country_calling_code( $country = null) { |
|
328 | +function wpinv_get_country_calling_code($country = null) { |
|
329 | 329 | |
330 | - $country = wpinv_sanitize_country( $country ); |
|
331 | - $codes = wpinv_get_data( 'phone-codes' ); |
|
332 | - $code = isset( $codes[ $country ] ) ? $codes[ $country ] : ''; |
|
330 | + $country = wpinv_sanitize_country($country); |
|
331 | + $codes = wpinv_get_data('phone-codes'); |
|
332 | + $code = isset($codes[$country]) ? $codes[$country] : ''; |
|
333 | 333 | |
334 | - if ( is_array( $code ) ) { |
|
334 | + if (is_array($code)) { |
|
335 | 335 | return $code[0]; |
336 | 336 | } |
337 | 337 | return $code; |
@@ -344,8 +344,8 @@ discard block |
||
344 | 344 | * @param bool $first_empty Whether or not the first item in the list should be empty |
345 | 345 | * @return array |
346 | 346 | */ |
347 | -function wpinv_get_country_list( $first_empty = false ) { |
|
348 | - return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty ); |
|
347 | +function wpinv_get_country_list($first_empty = false) { |
|
348 | + return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | /** |
@@ -355,22 +355,22 @@ discard block |
||
355 | 355 | * @param bool $first_empty Whether or not the first item in the list should be empty |
356 | 356 | * @return array |
357 | 357 | */ |
358 | -function wpinv_get_country_states( $country = null, $first_empty = false ) { |
|
358 | +function wpinv_get_country_states($country = null, $first_empty = false) { |
|
359 | 359 | |
360 | 360 | // Prepare the country. |
361 | - $country = wpinv_sanitize_country( $country ); |
|
361 | + $country = wpinv_sanitize_country($country); |
|
362 | 362 | |
363 | 363 | // Fetch all states. |
364 | - $all_states = wpinv_get_data( 'states' ); |
|
364 | + $all_states = wpinv_get_data('states'); |
|
365 | 365 | |
366 | 366 | // Fetch the specified country's states. |
367 | - $states = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array() ; |
|
368 | - $states = apply_filters( "wpinv_{$country}_states", $states ); |
|
369 | - $states = apply_filters( 'wpinv_country_states', $states, $country ); |
|
367 | + $states = isset($all_states[$country]) ? $all_states[$country] : array(); |
|
368 | + $states = apply_filters("wpinv_{$country}_states", $states); |
|
369 | + $states = apply_filters('wpinv_country_states', $states, $country); |
|
370 | 370 | |
371 | - asort( $states ); |
|
371 | + asort($states); |
|
372 | 372 | |
373 | - return wpinv_maybe_add_empty_option( $states, $first_empty ); |
|
373 | + return wpinv_maybe_add_empty_option($states, $first_empty); |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | /** |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | * @return array |
381 | 381 | */ |
382 | 382 | function wpinv_get_us_states_list() { |
383 | - return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) ); |
|
383 | + return apply_filters('wpinv_usa_states', wpinv_get_country_states('US')); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | /** |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | * @return array |
391 | 391 | */ |
392 | 392 | function wpinv_get_canada_states_list() { |
393 | - return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) ); |
|
393 | + return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA')); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | /** |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | * @return array |
401 | 401 | */ |
402 | 402 | function wpinv_get_australia_states_list() { |
403 | - return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) ); |
|
403 | + return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU')); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | /** |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | * @return array |
411 | 411 | */ |
412 | 412 | function wpinv_get_bangladesh_states_list() { |
413 | - return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) ); |
|
413 | + return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD')); |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | * @return array |
421 | 421 | */ |
422 | 422 | function wpinv_get_brazil_states_list() { |
423 | - return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) ); |
|
423 | + return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR')); |
|
424 | 424 | } |
425 | 425 | |
426 | 426 | /** |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | * @return array |
431 | 431 | */ |
432 | 432 | function wpinv_get_bulgaria_states_list() { |
433 | - return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) ); |
|
433 | + return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG')); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | /** |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | * @return array |
441 | 441 | */ |
442 | 442 | function wpinv_get_hong_kong_states_list() { |
443 | - return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) ); |
|
443 | + return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK')); |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | /** |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | * @return array |
451 | 451 | */ |
452 | 452 | function wpinv_get_hungary_states_list() { |
453 | - return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) ); |
|
453 | + return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU')); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | /** |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | * @return array |
461 | 461 | */ |
462 | 462 | function wpinv_get_japan_states_list() { |
463 | - return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) ); |
|
463 | + return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP')); |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | /** |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | * @return array |
471 | 471 | */ |
472 | 472 | function wpinv_get_china_states_list() { |
473 | - return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) ); |
|
473 | + return apply_filters('wpinv_china_states', wpinv_get_country_states('CN')); |
|
474 | 474 | } |
475 | 475 | |
476 | 476 | /** |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | * @return array |
481 | 481 | */ |
482 | 482 | function wpinv_get_new_zealand_states_list() { |
483 | - return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) ); |
|
483 | + return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ')); |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | /** |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | * @return array |
491 | 491 | */ |
492 | 492 | function wpinv_get_peru_states_list() { |
493 | - return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) ); |
|
493 | + return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE')); |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | /** |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | * @return array |
501 | 501 | */ |
502 | 502 | function wpinv_get_indonesia_states_list() { |
503 | - return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) ); |
|
503 | + return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID')); |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | /** |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | * @return array |
511 | 511 | */ |
512 | 512 | function wpinv_get_india_states_list() { |
513 | - return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) ); |
|
513 | + return apply_filters('wpinv_india_states', wpinv_get_country_states('IN')); |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | /** |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | * @return array |
521 | 521 | */ |
522 | 522 | function wpinv_get_iran_states_list() { |
523 | - return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) ); |
|
523 | + return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR')); |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | /** |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | * @return array |
531 | 531 | */ |
532 | 532 | function wpinv_get_italy_states_list() { |
533 | - return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) ); |
|
533 | + return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT')); |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | /** |
@@ -540,7 +540,7 @@ discard block |
||
540 | 540 | * @return array |
541 | 541 | */ |
542 | 542 | function wpinv_get_malaysia_states_list() { |
543 | - return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) ); |
|
543 | + return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY')); |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | /** |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | * @return array |
551 | 551 | */ |
552 | 552 | function wpinv_get_mexico_states_list() { |
553 | - return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) ); |
|
553 | + return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX')); |
|
554 | 554 | } |
555 | 555 | |
556 | 556 | /** |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | * @return array |
561 | 561 | */ |
562 | 562 | function wpinv_get_nepal_states_list() { |
563 | - return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) ); |
|
563 | + return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP')); |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | /** |
@@ -570,7 +570,7 @@ discard block |
||
570 | 570 | * @return array |
571 | 571 | */ |
572 | 572 | function wpinv_get_south_africa_states_list() { |
573 | - return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) ); |
|
573 | + return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA')); |
|
574 | 574 | } |
575 | 575 | |
576 | 576 | /** |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | * @return array |
581 | 581 | */ |
582 | 582 | function wpinv_get_thailand_states_list() { |
583 | - return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) ); |
|
583 | + return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH')); |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | /** |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | * @return array |
591 | 591 | */ |
592 | 592 | function wpinv_get_turkey_states_list() { |
593 | - return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) ); |
|
593 | + return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR')); |
|
594 | 594 | } |
595 | 595 | |
596 | 596 | /** |
@@ -600,31 +600,31 @@ discard block |
||
600 | 600 | * @return array |
601 | 601 | */ |
602 | 602 | function wpinv_get_spain_states_list() { |
603 | - return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) ); |
|
603 | + return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES')); |
|
604 | 604 | } |
605 | 605 | |
606 | 606 | function wpinv_get_states_field() { |
607 | - if( empty( $_POST['country'] ) ) { |
|
607 | + if (empty($_POST['country'])) { |
|
608 | 608 | $_POST['country'] = wpinv_get_default_country(); |
609 | 609 | } |
610 | - $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
610 | + $states = wpinv_get_country_states(sanitize_text_field($_POST['country'])); |
|
611 | 611 | |
612 | - if( !empty( $states ) ) { |
|
613 | - $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
612 | + if (!empty($states)) { |
|
613 | + $sanitized_field_name = sanitize_text_field($_POST['field_name']); |
|
614 | 614 | |
615 | - $class = isset( $_POST['class'] ) ? esc_attr( $_POST['class'] ) : ''; |
|
615 | + $class = isset($_POST['class']) ? esc_attr($_POST['class']) : ''; |
|
616 | 616 | $class .= " $sanitized_field_name getpaid_js_field-state custom-select wpinv-select wpi_select2"; |
617 | 617 | |
618 | - $args = array( |
|
618 | + $args = array( |
|
619 | 619 | 'name' => $sanitized_field_name, |
620 | 620 | 'id' => $sanitized_field_name, |
621 | - 'class' => implode( ' ', array_unique( explode( ' ', $class ) ) ), |
|
622 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
621 | + 'class' => implode(' ', array_unique(explode(' ', $class))), |
|
622 | + 'options' => array_merge(array('' => ''), $states), |
|
623 | 623 | 'show_option_all' => false, |
624 | 624 | 'show_option_none' => false |
625 | 625 | ); |
626 | 626 | |
627 | - $response = wpinv_html_select( $args ); |
|
627 | + $response = wpinv_html_select($args); |
|
628 | 628 | |
629 | 629 | } else { |
630 | 630 | $response = 'nostates'; |
@@ -633,10 +633,10 @@ discard block |
||
633 | 633 | return $response; |
634 | 634 | } |
635 | 635 | |
636 | -function wpinv_default_billing_country( $country = '', $user_id = 0 ) { |
|
637 | - $country = !empty( $country ) ? $country : wpinv_get_default_country(); |
|
636 | +function wpinv_default_billing_country($country = '', $user_id = 0) { |
|
637 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
638 | 638 | |
639 | - return apply_filters( 'wpinv_default_billing_country', $country, $user_id ); |
|
639 | + return apply_filters('wpinv_default_billing_country', $country, $user_id); |
|
640 | 640 | } |
641 | 641 | |
642 | 642 | /** |
@@ -648,7 +648,7 @@ discard block |
||
648 | 648 | */ |
649 | 649 | function wpinv_get_address_formats() { |
650 | 650 | |
651 | - return apply_filters( 'wpinv_localisation_address_formats', |
|
651 | + return apply_filters('wpinv_localisation_address_formats', |
|
652 | 652 | array( |
653 | 653 | 'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}", |
654 | 654 | 'AU' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}", |
@@ -697,9 +697,9 @@ discard block |
||
697 | 697 | * @see `wpinv_get_invoice_address_replacements` |
698 | 698 | * @return string |
699 | 699 | */ |
700 | -function wpinv_get_full_address_format( $country = false) { |
|
700 | +function wpinv_get_full_address_format($country = false) { |
|
701 | 701 | |
702 | - if( empty( $country ) ) { |
|
702 | + if (empty($country)) { |
|
703 | 703 | $country = wpinv_get_default_country(); |
704 | 704 | } |
705 | 705 | |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | $formats = wpinv_get_address_formats(); |
708 | 708 | |
709 | 709 | // Get format for the specified country. |
710 | - $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
710 | + $format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default']; |
|
711 | 711 | |
712 | 712 | /** |
713 | 713 | * Filters the address format to use on Invoices. |
@@ -719,7 +719,7 @@ discard block |
||
719 | 719 | * @param string $format The address format to use. |
720 | 720 | * @param string $country The country who's address format is being retrieved. |
721 | 721 | */ |
722 | - return apply_filters( 'wpinv_get_full_address_format', $format, $country ); |
|
722 | + return apply_filters('wpinv_get_full_address_format', $format, $country); |
|
723 | 723 | } |
724 | 724 | |
725 | 725 | /** |
@@ -730,7 +730,7 @@ discard block |
||
730 | 730 | * @param array $billing_details customer's billing details |
731 | 731 | * @return array |
732 | 732 | */ |
733 | -function wpinv_get_invoice_address_replacements( $billing_details ) { |
|
733 | +function wpinv_get_invoice_address_replacements($billing_details) { |
|
734 | 734 | |
735 | 735 | $default_args = array( |
736 | 736 | 'address' => '', |
@@ -743,22 +743,22 @@ discard block |
||
743 | 743 | 'company' => '', |
744 | 744 | ); |
745 | 745 | |
746 | - $args = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' ); |
|
746 | + $args = map_deep(wp_parse_args($billing_details, $default_args), 'trim'); |
|
747 | 747 | $state = $args['state']; |
748 | 748 | $country = $args['country']; |
749 | 749 | |
750 | 750 | // Handle full country name. |
751 | - $full_country = empty( $country ) ? $country : wpinv_country_name( $country ); |
|
751 | + $full_country = empty($country) ? $country : wpinv_country_name($country); |
|
752 | 752 | |
753 | 753 | // Handle full state name. |
754 | - $full_state = ( $country && $state ) ? wpinv_state_name( $state, $country ) : $state; |
|
754 | + $full_state = ($country && $state) ? wpinv_state_name($state, $country) : $state; |
|
755 | 755 | |
756 | 756 | $args['postcode'] = $args['zip']; |
757 | 757 | $args['name'] = $args['first_name'] . ' ' . $args['last_name']; |
758 | 758 | $args['state'] = $full_state; |
759 | 759 | $args['state_code'] = $state; |
760 | 760 | $args['country'] = $full_country; |
761 | - $args['country_code']= $country; |
|
761 | + $args['country_code'] = $country; |
|
762 | 762 | |
763 | 763 | /** |
764 | 764 | * Filters the address format replacements to use on Invoices. |
@@ -769,14 +769,14 @@ discard block |
||
769 | 769 | * @param array $replacements The address replacements to use. |
770 | 770 | * @param array $billing_details The billing details to use. |
771 | 771 | */ |
772 | - $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details ); |
|
772 | + $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details); |
|
773 | 773 | |
774 | 774 | $return = array(); |
775 | 775 | |
776 | - foreach( $replacements as $key => $value ) { |
|
777 | - $value = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : ''; |
|
776 | + foreach ($replacements as $key => $value) { |
|
777 | + $value = is_scalar($value) ? trim(sanitize_text_field($value)) : ''; |
|
778 | 778 | $return['{{' . $key . '}}'] = $value; |
779 | - $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper( $value ); |
|
779 | + $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value); |
|
780 | 780 | } |
781 | 781 | |
782 | 782 | return $return; |
@@ -790,6 +790,6 @@ discard block |
||
790 | 790 | * @since 1.0.14 |
791 | 791 | * @return string |
792 | 792 | */ |
793 | -function wpinv_trim_formatted_address_line( $line ) { |
|
794 | - return trim( $line, ', ' ); |
|
793 | +function wpinv_trim_formatted_address_line($line) { |
|
794 | + return trim($line, ', '); |
|
795 | 795 | } |
796 | 796 | \ No newline at end of file |