@@ -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,21 +130,21 @@ 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 | - '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 |
||
| 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 |
||
| 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 | } |
@@ -191,8 +191,8 @@ discard block |
||
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | } |
| 194 | -add_action( 'getpaid_new_invoice', 'getpaid_save_invoice_user_address' ); |
|
| 195 | -add_action( 'getpaid_update_invoice', 'getpaid_save_invoice_user_address' ); |
|
| 194 | +add_action('getpaid_new_invoice', 'getpaid_save_invoice_user_address'); |
|
| 195 | +add_action('getpaid_update_invoice', '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,11 +218,11 @@ 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 | - if ( ! $with_default ) { |
|
| 225 | + if (!$with_default) { |
|
| 226 | 226 | return $address; |
| 227 | 227 | } |
| 228 | 228 | |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | 'country' => wpinv_get_default_country(), |
| 234 | 234 | ); |
| 235 | 235 | |
| 236 | - return getpaid_array_merge_if_empty( $address, $defaults ); |
|
| 236 | + return getpaid_array_merge_if_empty($address, $defaults); |
|
| 237 | 237 | |
| 238 | 238 | } |
| 239 | 239 | |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | * @param string $field The field to use. |
| 245 | 245 | * @return string|null |
| 246 | 246 | */ |
| 247 | -function getpaid_get_user_address_field( $user_id, $field ) { |
|
| 247 | +function getpaid_get_user_address_field($user_id, $field) { |
|
| 248 | 248 | |
| 249 | 249 | $prefixes = array( |
| 250 | 250 | '_wpinv_', |
@@ -252,15 +252,15 @@ discard block |
||
| 252 | 252 | '' |
| 253 | 253 | ); |
| 254 | 254 | |
| 255 | - foreach ( $prefixes as $prefix ) { |
|
| 255 | + foreach ($prefixes as $prefix) { |
|
| 256 | 256 | |
| 257 | 257 | // Meta table. |
| 258 | - $value = get_user_meta( $user_id, $prefix . $field, true ); |
|
| 258 | + $value = get_user_meta($user_id, $prefix . $field, true); |
|
| 259 | 259 | |
| 260 | 260 | // UWP table. |
| 261 | - $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value; |
|
| 261 | + $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value; |
|
| 262 | 262 | |
| 263 | - if ( ! empty( $value ) ) { |
|
| 263 | + if (!empty($value)) { |
|
| 264 | 264 | return $value; |
| 265 | 265 | } |
| 266 | 266 | |
@@ -277,16 +277,16 @@ discard block |
||
| 277 | 277 | * @param string $return What to return. |
| 278 | 278 | * @return array |
| 279 | 279 | */ |
| 280 | -function wpinv_get_continents( $return = 'all' ) { |
|
| 280 | +function wpinv_get_continents($return = 'all') { |
|
| 281 | 281 | |
| 282 | - $continents = wpinv_get_data( 'continents' ); |
|
| 282 | + $continents = wpinv_get_data('continents'); |
|
| 283 | 283 | |
| 284 | - switch( $return ) { |
|
| 284 | + switch ($return) { |
|
| 285 | 285 | case 'name' : |
| 286 | - return wp_list_pluck( $continents, 'name' ); |
|
| 286 | + return wp_list_pluck($continents, 'name'); |
|
| 287 | 287 | break; |
| 288 | 288 | case 'countries' : |
| 289 | - return wp_list_pluck( $continents, 'countries' ); |
|
| 289 | + return wp_list_pluck($continents, 'countries'); |
|
| 290 | 290 | break; |
| 291 | 291 | default : |
| 292 | 292 | return $continents; |
@@ -302,12 +302,12 @@ discard block |
||
| 302 | 302 | * @param string $country Country code. If no code is specified, defaults to the default country. |
| 303 | 303 | * @return string |
| 304 | 304 | */ |
| 305 | -function wpinv_get_continent_code_for_country( $country = false ) { |
|
| 305 | +function wpinv_get_continent_code_for_country($country = false) { |
|
| 306 | 306 | |
| 307 | - $country = wpinv_sanitize_country( $country ); |
|
| 307 | + $country = wpinv_sanitize_country($country); |
|
| 308 | 308 | |
| 309 | - foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
| 310 | - if ( false !== array_search( $country, $countries, true ) ) { |
|
| 309 | + foreach (wpinv_get_continents('countries') as $continent_code => $countries) { |
|
| 310 | + if (false !== array_search($country, $countries, true)) { |
|
| 311 | 311 | return $continent_code; |
| 312 | 312 | } |
| 313 | 313 | } |
@@ -323,13 +323,13 @@ discard block |
||
| 323 | 323 | * @param string $country Country code. If no code is specified, defaults to the default country. |
| 324 | 324 | * @return array |
| 325 | 325 | */ |
| 326 | -function wpinv_get_country_calling_code( $country = null) { |
|
| 326 | +function wpinv_get_country_calling_code($country = null) { |
|
| 327 | 327 | |
| 328 | - $country = wpinv_sanitize_country( $country ); |
|
| 329 | - $codes = wpinv_get_data( 'phone-codes' ); |
|
| 330 | - $code = isset( $codes[ $country ] ) ? $codes[ $country ] : ''; |
|
| 328 | + $country = wpinv_sanitize_country($country); |
|
| 329 | + $codes = wpinv_get_data('phone-codes'); |
|
| 330 | + $code = isset($codes[$country]) ? $codes[$country] : ''; |
|
| 331 | 331 | |
| 332 | - if ( is_array( $code ) ) { |
|
| 332 | + if (is_array($code)) { |
|
| 333 | 333 | return $code[0]; |
| 334 | 334 | } |
| 335 | 335 | return $code; |
@@ -342,8 +342,8 @@ discard block |
||
| 342 | 342 | * @param bool $first_empty Whether or not the first item in the list should be empty |
| 343 | 343 | * @return array |
| 344 | 344 | */ |
| 345 | -function wpinv_get_country_list( $first_empty = false ) { |
|
| 346 | - return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty ); |
|
| 345 | +function wpinv_get_country_list($first_empty = false) { |
|
| 346 | + return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty); |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /** |
@@ -353,22 +353,22 @@ discard block |
||
| 353 | 353 | * @param bool $first_empty Whether or not the first item in the list should be empty |
| 354 | 354 | * @return array |
| 355 | 355 | */ |
| 356 | -function wpinv_get_country_states( $country = null, $first_empty = false ) { |
|
| 356 | +function wpinv_get_country_states($country = null, $first_empty = false) { |
|
| 357 | 357 | |
| 358 | 358 | // Prepare the country. |
| 359 | - $country = wpinv_sanitize_country( $country ); |
|
| 359 | + $country = wpinv_sanitize_country($country); |
|
| 360 | 360 | |
| 361 | 361 | // Fetch all states. |
| 362 | - $all_states = wpinv_get_data( 'states' ); |
|
| 362 | + $all_states = wpinv_get_data('states'); |
|
| 363 | 363 | |
| 364 | 364 | // Fetch the specified country's states. |
| 365 | - $states = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array() ; |
|
| 366 | - $states = apply_filters( "wpinv_{$country}_states", $states ); |
|
| 367 | - $states = apply_filters( 'wpinv_country_states', $states, $country ); |
|
| 365 | + $states = isset($all_states[$country]) ? $all_states[$country] : array(); |
|
| 366 | + $states = apply_filters("wpinv_{$country}_states", $states); |
|
| 367 | + $states = apply_filters('wpinv_country_states', $states, $country); |
|
| 368 | 368 | |
| 369 | - asort( $states ); |
|
| 369 | + asort($states); |
|
| 370 | 370 | |
| 371 | - return wpinv_maybe_add_empty_option( $states, $first_empty ); |
|
| 371 | + return wpinv_maybe_add_empty_option($states, $first_empty); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | /** |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | * @return array |
| 379 | 379 | */ |
| 380 | 380 | function wpinv_get_us_states_list() { |
| 381 | - return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) ); |
|
| 381 | + return apply_filters('wpinv_usa_states', wpinv_get_country_states('US')); |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | /** |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | * @return array |
| 389 | 389 | */ |
| 390 | 390 | function wpinv_get_canada_states_list() { |
| 391 | - return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) ); |
|
| 391 | + return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA')); |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | /** |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | * @return array |
| 399 | 399 | */ |
| 400 | 400 | function wpinv_get_australia_states_list() { |
| 401 | - return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) ); |
|
| 401 | + return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU')); |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | /** |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | * @return array |
| 409 | 409 | */ |
| 410 | 410 | function wpinv_get_bangladesh_states_list() { |
| 411 | - return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) ); |
|
| 411 | + return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD')); |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | /** |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | * @return array |
| 419 | 419 | */ |
| 420 | 420 | function wpinv_get_brazil_states_list() { |
| 421 | - return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) ); |
|
| 421 | + return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR')); |
|
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | /** |
@@ -428,7 +428,7 @@ discard block |
||
| 428 | 428 | * @return array |
| 429 | 429 | */ |
| 430 | 430 | function wpinv_get_bulgaria_states_list() { |
| 431 | - return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) ); |
|
| 431 | + return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG')); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | /** |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | * @return array |
| 439 | 439 | */ |
| 440 | 440 | function wpinv_get_hong_kong_states_list() { |
| 441 | - return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) ); |
|
| 441 | + return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK')); |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | /** |
@@ -448,7 +448,7 @@ discard block |
||
| 448 | 448 | * @return array |
| 449 | 449 | */ |
| 450 | 450 | function wpinv_get_hungary_states_list() { |
| 451 | - return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) ); |
|
| 451 | + return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU')); |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | /** |
@@ -458,7 +458,7 @@ discard block |
||
| 458 | 458 | * @return array |
| 459 | 459 | */ |
| 460 | 460 | function wpinv_get_japan_states_list() { |
| 461 | - return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) ); |
|
| 461 | + return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP')); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | /** |
@@ -468,7 +468,7 @@ discard block |
||
| 468 | 468 | * @return array |
| 469 | 469 | */ |
| 470 | 470 | function wpinv_get_china_states_list() { |
| 471 | - return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) ); |
|
| 471 | + return apply_filters('wpinv_china_states', wpinv_get_country_states('CN')); |
|
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | /** |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | * @return array |
| 479 | 479 | */ |
| 480 | 480 | function wpinv_get_new_zealand_states_list() { |
| 481 | - return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) ); |
|
| 481 | + return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ')); |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | /** |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | * @return array |
| 489 | 489 | */ |
| 490 | 490 | function wpinv_get_peru_states_list() { |
| 491 | - return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) ); |
|
| 491 | + return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE')); |
|
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | /** |
@@ -498,7 +498,7 @@ discard block |
||
| 498 | 498 | * @return array |
| 499 | 499 | */ |
| 500 | 500 | function wpinv_get_indonesia_states_list() { |
| 501 | - return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) ); |
|
| 501 | + return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID')); |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | /** |
@@ -508,7 +508,7 @@ discard block |
||
| 508 | 508 | * @return array |
| 509 | 509 | */ |
| 510 | 510 | function wpinv_get_india_states_list() { |
| 511 | - return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) ); |
|
| 511 | + return apply_filters('wpinv_india_states', wpinv_get_country_states('IN')); |
|
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | /** |
@@ -518,7 +518,7 @@ discard block |
||
| 518 | 518 | * @return array |
| 519 | 519 | */ |
| 520 | 520 | function wpinv_get_iran_states_list() { |
| 521 | - return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) ); |
|
| 521 | + return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR')); |
|
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | /** |
@@ -528,7 +528,7 @@ discard block |
||
| 528 | 528 | * @return array |
| 529 | 529 | */ |
| 530 | 530 | function wpinv_get_italy_states_list() { |
| 531 | - return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) ); |
|
| 531 | + return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT')); |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | /** |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | * @return array |
| 539 | 539 | */ |
| 540 | 540 | function wpinv_get_malaysia_states_list() { |
| 541 | - return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) ); |
|
| 541 | + return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY')); |
|
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | /** |
@@ -548,7 +548,7 @@ discard block |
||
| 548 | 548 | * @return array |
| 549 | 549 | */ |
| 550 | 550 | function wpinv_get_mexico_states_list() { |
| 551 | - return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) ); |
|
| 551 | + return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX')); |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | /** |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | * @return array |
| 559 | 559 | */ |
| 560 | 560 | function wpinv_get_nepal_states_list() { |
| 561 | - return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) ); |
|
| 561 | + return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP')); |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | /** |
@@ -568,7 +568,7 @@ discard block |
||
| 568 | 568 | * @return array |
| 569 | 569 | */ |
| 570 | 570 | function wpinv_get_south_africa_states_list() { |
| 571 | - return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) ); |
|
| 571 | + return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA')); |
|
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | /** |
@@ -578,7 +578,7 @@ discard block |
||
| 578 | 578 | * @return array |
| 579 | 579 | */ |
| 580 | 580 | function wpinv_get_thailand_states_list() { |
| 581 | - return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) ); |
|
| 581 | + return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH')); |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | /** |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | * @return array |
| 589 | 589 | */ |
| 590 | 590 | function wpinv_get_turkey_states_list() { |
| 591 | - return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) ); |
|
| 591 | + return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR')); |
|
| 592 | 592 | } |
| 593 | 593 | |
| 594 | 594 | /** |
@@ -598,28 +598,28 @@ discard block |
||
| 598 | 598 | * @return array |
| 599 | 599 | */ |
| 600 | 600 | function wpinv_get_spain_states_list() { |
| 601 | - return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) ); |
|
| 601 | + return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES')); |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | function wpinv_get_states_field() { |
| 605 | - if( empty( $_POST['country'] ) ) { |
|
| 605 | + if (empty($_POST['country'])) { |
|
| 606 | 606 | $_POST['country'] = wpinv_get_default_country(); |
| 607 | 607 | } |
| 608 | - $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
| 608 | + $states = wpinv_get_country_states(sanitize_text_field($_POST['country'])); |
|
| 609 | 609 | |
| 610 | - if( !empty( $states ) ) { |
|
| 611 | - $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
| 610 | + if (!empty($states)) { |
|
| 611 | + $sanitized_field_name = sanitize_text_field($_POST['field_name']); |
|
| 612 | 612 | |
| 613 | 613 | $args = array( |
| 614 | 614 | 'name' => $sanitized_field_name, |
| 615 | 615 | 'id' => $sanitized_field_name, |
| 616 | 616 | 'class' => $sanitized_field_name . 'custom-select wpinv-select wpi_select2', |
| 617 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
| 617 | + 'options' => array_merge(array('' => ''), $states), |
|
| 618 | 618 | 'show_option_all' => false, |
| 619 | 619 | 'show_option_none' => false |
| 620 | 620 | ); |
| 621 | 621 | |
| 622 | - $response = wpinv_html_select( $args ); |
|
| 622 | + $response = wpinv_html_select($args); |
|
| 623 | 623 | |
| 624 | 624 | } else { |
| 625 | 625 | $response = 'nostates'; |
@@ -628,10 +628,10 @@ discard block |
||
| 628 | 628 | return $response; |
| 629 | 629 | } |
| 630 | 630 | |
| 631 | -function wpinv_default_billing_country( $country = '', $user_id = 0 ) { |
|
| 632 | - $country = !empty( $country ) ? $country : wpinv_get_default_country(); |
|
| 631 | +function wpinv_default_billing_country($country = '', $user_id = 0) { |
|
| 632 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
| 633 | 633 | |
| 634 | - return apply_filters( 'wpinv_default_billing_country', $country, $user_id ); |
|
| 634 | + return apply_filters('wpinv_default_billing_country', $country, $user_id); |
|
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | /** |
@@ -643,7 +643,7 @@ discard block |
||
| 643 | 643 | */ |
| 644 | 644 | function wpinv_get_address_formats() { |
| 645 | 645 | |
| 646 | - return apply_filters( 'wpinv_localisation_address_formats', |
|
| 646 | + return apply_filters('wpinv_localisation_address_formats', |
|
| 647 | 647 | array( |
| 648 | 648 | 'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}", |
| 649 | 649 | 'AU' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}", |
@@ -692,9 +692,9 @@ discard block |
||
| 692 | 692 | * @see `wpinv_get_invoice_address_replacements` |
| 693 | 693 | * @return string |
| 694 | 694 | */ |
| 695 | -function wpinv_get_full_address_format( $country = false) { |
|
| 695 | +function wpinv_get_full_address_format($country = false) { |
|
| 696 | 696 | |
| 697 | - if( empty( $country ) ) { |
|
| 697 | + if (empty($country)) { |
|
| 698 | 698 | $country = wpinv_get_default_country(); |
| 699 | 699 | } |
| 700 | 700 | |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | $formats = wpinv_get_address_formats(); |
| 703 | 703 | |
| 704 | 704 | // Get format for the specified country. |
| 705 | - $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
| 705 | + $format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default']; |
|
| 706 | 706 | |
| 707 | 707 | /** |
| 708 | 708 | * Filters the address format to use on Invoices. |
@@ -714,7 +714,7 @@ discard block |
||
| 714 | 714 | * @param string $format The address format to use. |
| 715 | 715 | * @param string $country The country who's address format is being retrieved. |
| 716 | 716 | */ |
| 717 | - return apply_filters( 'wpinv_get_full_address_format', $format, $country ); |
|
| 717 | + return apply_filters('wpinv_get_full_address_format', $format, $country); |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | /** |
@@ -725,7 +725,7 @@ discard block |
||
| 725 | 725 | * @param array $billing_details customer's billing details |
| 726 | 726 | * @return array |
| 727 | 727 | */ |
| 728 | -function wpinv_get_invoice_address_replacements( $billing_details ) { |
|
| 728 | +function wpinv_get_invoice_address_replacements($billing_details) { |
|
| 729 | 729 | |
| 730 | 730 | $default_args = array( |
| 731 | 731 | 'address' => '', |
@@ -738,22 +738,22 @@ discard block |
||
| 738 | 738 | 'company' => '', |
| 739 | 739 | ); |
| 740 | 740 | |
| 741 | - $args = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' ); |
|
| 741 | + $args = map_deep(wp_parse_args($billing_details, $default_args), 'trim'); |
|
| 742 | 742 | $state = $args['state']; |
| 743 | 743 | $country = $args['country']; |
| 744 | 744 | |
| 745 | 745 | // Handle full country name. |
| 746 | - $full_country = empty( $country ) ? $country : wpinv_country_name( $country ); |
|
| 746 | + $full_country = empty($country) ? $country : wpinv_country_name($country); |
|
| 747 | 747 | |
| 748 | 748 | // Handle full state name. |
| 749 | - $full_state = ( $country && $state ) ? wpinv_state_name( $state, $country ) : $state; |
|
| 749 | + $full_state = ($country && $state) ? wpinv_state_name($state, $country) : $state; |
|
| 750 | 750 | |
| 751 | 751 | $args['postcode'] = $args['zip']; |
| 752 | 752 | $args['name'] = $args['first_name'] . ' ' . $args['last_name']; |
| 753 | 753 | $args['state'] = $full_state; |
| 754 | 754 | $args['state_code'] = $state; |
| 755 | 755 | $args['country'] = $full_country; |
| 756 | - $args['country_code']= $country; |
|
| 756 | + $args['country_code'] = $country; |
|
| 757 | 757 | |
| 758 | 758 | /** |
| 759 | 759 | * Filters the address format replacements to use on Invoices. |
@@ -764,14 +764,14 @@ discard block |
||
| 764 | 764 | * @param array $replacements The address replacements to use. |
| 765 | 765 | * @param array $billing_details The billing details to use. |
| 766 | 766 | */ |
| 767 | - $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details ); |
|
| 767 | + $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details); |
|
| 768 | 768 | |
| 769 | 769 | $return = array(); |
| 770 | 770 | |
| 771 | - foreach( $replacements as $key => $value ) { |
|
| 772 | - $value = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : ''; |
|
| 771 | + foreach ($replacements as $key => $value) { |
|
| 772 | + $value = is_scalar($value) ? trim(sanitize_text_field($value)) : ''; |
|
| 773 | 773 | $return['{{' . $key . '}}'] = $value; |
| 774 | - $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper( $value ); |
|
| 774 | + $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value); |
|
| 775 | 775 | } |
| 776 | 776 | |
| 777 | 777 | return $return; |
@@ -785,6 +785,6 @@ discard block |
||
| 785 | 785 | * @since 1.0.14 |
| 786 | 786 | * @return string |
| 787 | 787 | */ |
| 788 | -function wpinv_trim_formatted_address_line( $line ) { |
|
| 789 | - return trim( $line, ', ' ); |
|
| 788 | +function wpinv_trim_formatted_address_line($line) { |
|
| 789 | + return trim($line, ', '); |
|
| 790 | 790 | } |
| 791 | 791 | \ No newline at end of file |