@@ -34,11 +34,11 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) { |
| 36 | 36 | |
| 37 | - if ( current_user_can( 'manage_options' ) ) { |
|
| 38 | - return 'manage_options'; |
|
| 39 | - }; |
|
| 37 | + if ( current_user_can( 'manage_options' ) ) { |
|
| 38 | + return 'manage_options'; |
|
| 39 | + }; |
|
| 40 | 40 | |
| 41 | - return $capalibilty; |
|
| 41 | + return $capalibilty; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -62,10 +62,10 @@ discard block |
||
| 62 | 62 | // Prepare user values. |
| 63 | 63 | $prefix = preg_replace( '/\s+/', '', $prefix ); |
| 64 | 64 | $prefix = empty( $prefix ) ? $email : $prefix; |
| 65 | - $args = array( |
|
| 66 | - 'user_login' => wpinv_generate_user_name( $prefix ), |
|
| 67 | - 'user_pass' => wp_generate_password(), |
|
| 68 | - 'user_email' => $email, |
|
| 65 | + $args = array( |
|
| 66 | + 'user_login' => wpinv_generate_user_name( $prefix ), |
|
| 67 | + 'user_pass' => wp_generate_password(), |
|
| 68 | + 'user_email' => $email, |
|
| 69 | 69 | 'role' => 'subscriber', |
| 70 | 70 | ); |
| 71 | 71 | |
@@ -82,16 +82,16 @@ discard block |
||
| 82 | 82 | function wpinv_generate_user_name( $prefix = '' ) { |
| 83 | 83 | |
| 84 | 84 | // If prefix is an email, retrieve the part before the email. |
| 85 | - $prefix = strtok( $prefix, '@' ); |
|
| 85 | + $prefix = strtok( $prefix, '@' ); |
|
| 86 | 86 | $prefix = trim( $prefix, '.' ); |
| 87 | 87 | |
| 88 | - // Sanitize the username. |
|
| 89 | - $prefix = sanitize_user( $prefix, true ); |
|
| 88 | + // Sanitize the username. |
|
| 89 | + $prefix = sanitize_user( $prefix, true ); |
|
| 90 | 90 | |
| 91 | - $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
| 92 | - if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
| 93 | - $prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
| 94 | - } |
|
| 91 | + $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
| 92 | + if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
| 93 | + $prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | 96 | $username = $prefix; |
| 97 | 97 | $postfix = 2; |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @package GetPaid |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Generates a users select dropdown. |
@@ -16,13 +16,13 @@ discard block |
||
| 16 | 16 | * @param array $args |
| 17 | 17 | * @see wp_dropdown_users |
| 18 | 18 | */ |
| 19 | -function wpinv_dropdown_users( $args = '' ) { |
|
| 19 | +function wpinv_dropdown_users($args = '') { |
|
| 20 | 20 | |
| 21 | - if ( is_array( $args ) && ! empty( $args['show'] ) && 'display_name_with_email' == $args['show'] ) { |
|
| 21 | + if (is_array($args) && !empty($args['show']) && 'display_name_with_email' == $args['show']) { |
|
| 22 | 22 | $args['show'] = 'display_name_with_login'; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - return wp_dropdown_users( $args ); |
|
| 25 | + return wp_dropdown_users($args); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -32,9 +32,9 @@ discard block |
||
| 32 | 32 | * @return string capability to check against |
| 33 | 33 | * @param string $capalibilty Optional. The alternative capability to check against. |
| 34 | 34 | */ |
| 35 | -function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) { |
|
| 35 | +function wpinv_get_capability($capalibilty = 'manage_invoicing') { |
|
| 36 | 36 | |
| 37 | - if ( current_user_can( 'manage_options' ) ) { |
|
| 37 | + if (current_user_can('manage_options')) { |
|
| 38 | 38 | return 'manage_options'; |
| 39 | 39 | }; |
| 40 | 40 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * @return bool |
| 49 | 49 | */ |
| 50 | 50 | function wpinv_current_user_can_manage_invoicing() { |
| 51 | - return current_user_can( wpinv_get_capability() ); |
|
| 51 | + return current_user_can(wpinv_get_capability()); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
@@ -57,19 +57,19 @@ discard block |
||
| 57 | 57 | * @since 1.0.19 |
| 58 | 58 | * @return int|WP_Error |
| 59 | 59 | */ |
| 60 | -function wpinv_create_user( $email, $prefix = '' ) { |
|
| 60 | +function wpinv_create_user($email, $prefix = '') { |
|
| 61 | 61 | |
| 62 | 62 | // Prepare user values. |
| 63 | - $prefix = preg_replace( '/\s+/', '', $prefix ); |
|
| 64 | - $prefix = empty( $prefix ) ? $email : $prefix; |
|
| 65 | - $args = array( |
|
| 66 | - 'user_login' => wpinv_generate_user_name( $prefix ), |
|
| 63 | + $prefix = preg_replace('/\s+/', '', $prefix); |
|
| 64 | + $prefix = empty($prefix) ? $email : $prefix; |
|
| 65 | + $args = array( |
|
| 66 | + 'user_login' => wpinv_generate_user_name($prefix), |
|
| 67 | 67 | 'user_pass' => wp_generate_password(), |
| 68 | 68 | 'user_email' => $email, |
| 69 | 69 | 'role' => 'subscriber', |
| 70 | 70 | ); |
| 71 | 71 | |
| 72 | - return wp_insert_user( $args ); |
|
| 72 | + return wp_insert_user($args); |
|
| 73 | 73 | |
| 74 | 74 | } |
| 75 | 75 | |
@@ -79,26 +79,26 @@ discard block |
||
| 79 | 79 | * @since 1.0.19 |
| 80 | 80 | * @return bool|WP_User |
| 81 | 81 | */ |
| 82 | -function wpinv_generate_user_name( $prefix = '' ) { |
|
| 82 | +function wpinv_generate_user_name($prefix = '') { |
|
| 83 | 83 | |
| 84 | 84 | // If prefix is an email, retrieve the part before the email. |
| 85 | - $prefix = strtok( $prefix, '@' ); |
|
| 86 | - $prefix = trim( $prefix, '.' ); |
|
| 85 | + $prefix = strtok($prefix, '@'); |
|
| 86 | + $prefix = trim($prefix, '.'); |
|
| 87 | 87 | |
| 88 | 88 | // Sanitize the username. |
| 89 | - $prefix = sanitize_user( $prefix, true ); |
|
| 89 | + $prefix = sanitize_user($prefix, true); |
|
| 90 | 90 | |
| 91 | - $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
| 92 | - if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
| 93 | - $prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
| 91 | + $illegal_logins = (array) apply_filters('illegal_user_logins', array()); |
|
| 92 | + if (empty($prefix) || in_array(strtolower($prefix), array_map('strtolower', $illegal_logins), true)) { |
|
| 93 | + $prefix = 'gtp_' . zeroise(wp_rand(0, 9999), 4); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | $username = $prefix; |
| 97 | 97 | $postfix = 2; |
| 98 | 98 | |
| 99 | - while ( username_exists( $username ) ) { |
|
| 99 | + while (username_exists($username)) { |
|
| 100 | 100 | $username = $prefix + $postfix; |
| 101 | - $postfix ++; |
|
| 101 | + $postfix++; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | return $username; |
@@ -115,26 +115,26 @@ discard block |
||
| 115 | 115 | $tabs = array( |
| 116 | 116 | |
| 117 | 117 | 'gp-edit-address' => array( |
| 118 | - 'label' => __( 'Billing Address', 'invoicing' ), |
|
| 118 | + 'label' => __('Billing Address', 'invoicing'), |
|
| 119 | 119 | 'callback' => 'getpaid_display_address_edit_tab', |
| 120 | 120 | 'icon' => 'fas fa-credit-card', |
| 121 | 121 | ), |
| 122 | 122 | |
| 123 | 123 | 'gp-invoices' => array( |
| 124 | - 'label' => __( 'Invoices', 'invoicing' ), // Name of the tab. |
|
| 124 | + 'label' => __('Invoices', 'invoicing'), // Name of the tab. |
|
| 125 | 125 | 'content' => '[wpinv_history]', // Content of the tab. Or specify "callback" to provide a callback instead. |
| 126 | 126 | 'icon' => 'fas fa-file-invoice', // Shown on some profile plugins. |
| 127 | 127 | ), |
| 128 | 128 | |
| 129 | 129 | 'gp-subscriptions' => array( |
| 130 | - 'label' => __( 'Subscriptions', 'invoicing' ), |
|
| 130 | + 'label' => __('Subscriptions', 'invoicing'), |
|
| 131 | 131 | 'content' => '[wpinv_subscriptions]', |
| 132 | 132 | 'icon' => 'fas fa-redo', |
| 133 | 133 | ), |
| 134 | 134 | |
| 135 | 135 | ); |
| 136 | 136 | |
| 137 | - return apply_filters( 'getpaid_user_content_tabs', $tabs ); |
|
| 137 | + return apply_filters('getpaid_user_content_tabs', $tabs); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -144,19 +144,19 @@ discard block |
||
| 144 | 144 | * @param array $tab |
| 145 | 145 | * @return array |
| 146 | 146 | */ |
| 147 | -function getpaid_prepare_user_content_tab( $tab ) { |
|
| 147 | +function getpaid_prepare_user_content_tab($tab) { |
|
| 148 | 148 | |
| 149 | - if ( ! empty( $tab['callback'] ) ) { |
|
| 150 | - return call_user_func( $tab['callback'] ); |
|
| 149 | + if (!empty($tab['callback'])) { |
|
| 150 | + return call_user_func($tab['callback']); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - if ( ! empty( $tab['content'] ) ) { |
|
| 154 | - return convert_smilies( capital_P_dangit( wp_filter_content_tags( do_shortcode( shortcode_unautop( wpautop( wptexturize( do_blocks( $tab['content'] ) ) ) ) ) ) ) ); |
|
| 153 | + if (!empty($tab['content'])) { |
|
| 154 | + return convert_smilies(capital_P_dangit(wp_filter_content_tags(do_shortcode(shortcode_unautop(wpautop(wptexturize(do_blocks($tab['content'])))))))); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | $notice = aui()->alert( |
| 158 | 158 | array( |
| 159 | - 'content' => __( 'This tab has no content or content callback.', 'invoicing' ), |
|
| 159 | + 'content' => __('This tab has no content or content callback.', 'invoicing'), |
|
| 160 | 160 | 'type' => 'error', |
| 161 | 161 | ) |
| 162 | 162 | ); |
@@ -172,14 +172,14 @@ discard block |
||
| 172 | 172 | * @param string $default |
| 173 | 173 | * @return array |
| 174 | 174 | */ |
| 175 | -function getpaid_get_tab_url( $tab, $default ) { |
|
| 175 | +function getpaid_get_tab_url($tab, $default) { |
|
| 176 | 176 | global $getpaid_tab_url; |
| 177 | 177 | |
| 178 | - if ( empty( $getpaid_tab_url ) ) { |
|
| 178 | + if (empty($getpaid_tab_url)) { |
|
| 179 | 179 | return $default; |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - return sprintf( $getpaid_tab_url, $tab ); |
|
| 182 | + return sprintf($getpaid_tab_url, $tab); |
|
| 183 | 183 | |
| 184 | 184 | } |
| 185 | 185 | |
@@ -199,19 +199,19 @@ discard block |
||
| 199 | 199 | |
| 200 | 200 | <?php |
| 201 | 201 | |
| 202 | - foreach ( getpaid_user_address_fields() as $key => $label ) { |
|
| 202 | + foreach (getpaid_user_address_fields() as $key => $label) { |
|
| 203 | 203 | |
| 204 | 204 | // Display the country. |
| 205 | - if ( 'country' == $key ) { |
|
| 205 | + if ('country' == $key) { |
|
| 206 | 206 | |
| 207 | 207 | echo aui()->select( |
| 208 | 208 | array( |
| 209 | 209 | 'options' => wpinv_get_country_list(), |
| 210 | - 'name' => esc_attr( $key ), |
|
| 211 | - 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
| 212 | - 'value' => sanitize_text_field( getpaid_get_user_address_field( get_current_user_id(), $key ) ), |
|
| 210 | + 'name' => esc_attr($key), |
|
| 211 | + 'id' => 'wpinv-' . sanitize_html_class($key), |
|
| 212 | + 'value' => sanitize_text_field(getpaid_get_user_address_field(get_current_user_id(), $key)), |
|
| 213 | 213 | 'placeholder' => $label, |
| 214 | - 'label' => wp_kses_post( $label ), |
|
| 214 | + 'label' => wp_kses_post($label), |
|
| 215 | 215 | 'label_type' => 'vertical', |
| 216 | 216 | 'class' => 'getpaid-address-field', |
| 217 | 217 | ) |
@@ -220,11 +220,11 @@ discard block |
||
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | // Display the state. |
| 223 | - else if ( 'state' == $key ) { |
|
| 223 | + else if ('state' == $key) { |
|
| 224 | 224 | |
| 225 | - echo getpaid_get_states_select_markup ( |
|
| 226 | - getpaid_get_user_address_field( get_current_user_id(), 'country' ), |
|
| 227 | - getpaid_get_user_address_field( get_current_user_id(), 'state' ), |
|
| 225 | + echo getpaid_get_states_select_markup( |
|
| 226 | + getpaid_get_user_address_field(get_current_user_id(), 'country'), |
|
| 227 | + getpaid_get_user_address_field(get_current_user_id(), 'state'), |
|
| 228 | 228 | $label, |
| 229 | 229 | $label, |
| 230 | 230 | '', |
@@ -237,13 +237,13 @@ discard block |
||
| 237 | 237 | |
| 238 | 238 | echo aui()->input( |
| 239 | 239 | array( |
| 240 | - 'name' => esc_attr( $key ), |
|
| 241 | - 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
| 240 | + 'name' => esc_attr($key), |
|
| 241 | + 'id' => 'wpinv-' . sanitize_html_class($key), |
|
| 242 | 242 | 'placeholder' => $label, |
| 243 | - 'label' => wp_kses_post( $label ), |
|
| 243 | + 'label' => wp_kses_post($label), |
|
| 244 | 244 | 'label_type' => 'vertical', |
| 245 | 245 | 'type' => 'text', |
| 246 | - 'value' => sanitize_text_field( getpaid_get_user_address_field( get_current_user_id(), $key ) ), |
|
| 246 | + 'value' => sanitize_text_field(getpaid_get_user_address_field(get_current_user_id(), $key)), |
|
| 247 | 247 | 'class' => 'getpaid-address-field', |
| 248 | 248 | ) |
| 249 | 249 | ); |
@@ -252,21 +252,21 @@ discard block |
||
| 252 | 252 | |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - do_action( 'getpaid_display_address_edit_tab' ); |
|
| 255 | + do_action('getpaid_display_address_edit_tab'); |
|
| 256 | 256 | |
| 257 | 257 | echo aui()->input( |
| 258 | 258 | array( |
| 259 | 259 | 'name' => 'getpaid_profile_edit_submit_button', |
| 260 | 260 | 'id' => 'getpaid_profile_edit_submit_button', |
| 261 | - 'value' => __( 'Save Address', 'invoicing' ), |
|
| 262 | - 'help_text' => __( 'New invoices will use this address as the billing address.', 'invoicing' ), |
|
| 261 | + 'value' => __('Save Address', 'invoicing'), |
|
| 262 | + 'help_text' => __('New invoices will use this address as the billing address.', 'invoicing'), |
|
| 263 | 263 | 'type' => 'submit', |
| 264 | 264 | 'class' => 'btn btn-primary btn-block submit-button', |
| 265 | 265 | ) |
| 266 | 266 | ); |
| 267 | 267 | |
| 268 | - wp_nonce_field( 'getpaid-nonce', 'getpaid-nonce' ); |
|
| 269 | - getpaid_hidden_field( 'getpaid-action', 'edit_billing_details' ); |
|
| 268 | + wp_nonce_field('getpaid-nonce', 'getpaid-nonce'); |
|
| 269 | + getpaid_hidden_field('getpaid-action', 'edit_billing_details'); |
|
| 270 | 270 | ?> |
| 271 | 271 | |
| 272 | 272 | </form> |
@@ -283,20 +283,20 @@ discard block |
||
| 283 | 283 | * @since 2.1.4 |
| 284 | 284 | * @param array $data |
| 285 | 285 | */ |
| 286 | -function getpaid_save_address_edit_tab( $data ) { |
|
| 286 | +function getpaid_save_address_edit_tab($data) { |
|
| 287 | 287 | |
| 288 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
| 288 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
| 289 | 289 | |
| 290 | - if ( isset( $data[ $field ] ) ) { |
|
| 291 | - $value = sanitize_text_field( $data[ $field ] ); |
|
| 292 | - update_user_meta( get_current_user_id(), '_wpinv_' . $field, $value ); |
|
| 290 | + if (isset($data[$field])) { |
|
| 291 | + $value = sanitize_text_field($data[$field]); |
|
| 292 | + update_user_meta(get_current_user_id(), '_wpinv_' . $field, $value); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - wpinv_set_error( 'address_updated', __( 'You billing address has been updated', 'invoicing' ), 'success'); |
|
| 295 | + wpinv_set_error('address_updated', __('You billing address has been updated', 'invoicing'), 'success'); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | } |
| 299 | -add_action( 'getpaid_authenticated_action_edit_billing_details', 'getpaid_save_address_edit_tab' ); |
|
| 299 | +add_action('getpaid_authenticated_action_edit_billing_details', 'getpaid_save_address_edit_tab'); |
|
| 300 | 300 | |
| 301 | 301 | |
| 302 | 302 | /* |
@@ -314,27 +314,27 @@ discard block |
||
| 314 | 314 | * @param array $tabs |
| 315 | 315 | * @return array |
| 316 | 316 | */ |
| 317 | -function getpaid_filter_userswp_account_tabs( $tabs ) { |
|
| 317 | +function getpaid_filter_userswp_account_tabs($tabs) { |
|
| 318 | 318 | |
| 319 | 319 | // Abort if the integration is inactive. |
| 320 | - if ( ! getpaid_is_userswp_integration_active() ) { |
|
| 320 | + if (!getpaid_is_userswp_integration_active()) { |
|
| 321 | 321 | return $tabs; |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | - $new_tabs = array(); |
|
| 324 | + $new_tabs = array(); |
|
| 325 | 325 | |
| 326 | - foreach ( getpaid_get_user_content_tabs() as $slug => $tab ) { |
|
| 326 | + foreach (getpaid_get_user_content_tabs() as $slug => $tab) { |
|
| 327 | 327 | |
| 328 | - $new_tabs[ $slug ] = array( |
|
| 329 | - 'title' => $tab[ 'label'], |
|
| 330 | - 'icon' => $tab[ 'icon'], |
|
| 328 | + $new_tabs[$slug] = array( |
|
| 329 | + 'title' => $tab['label'], |
|
| 330 | + 'icon' => $tab['icon'], |
|
| 331 | 331 | ); |
| 332 | 332 | |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | - return array_merge( $tabs, $new_tabs ); |
|
| 335 | + return array_merge($tabs, $new_tabs); |
|
| 336 | 336 | } |
| 337 | -add_filter( 'uwp_account_available_tabs', 'getpaid_filter_userswp_account_tabs' ); |
|
| 337 | +add_filter('uwp_account_available_tabs', 'getpaid_filter_userswp_account_tabs'); |
|
| 338 | 338 | |
| 339 | 339 | /** |
| 340 | 340 | * Display our UsersWP account tabs. |
@@ -343,18 +343,18 @@ discard block |
||
| 343 | 343 | * @param array $tabs |
| 344 | 344 | * @return array |
| 345 | 345 | */ |
| 346 | -function getpaid_display_userswp_account_tabs( $tab ) { |
|
| 346 | +function getpaid_display_userswp_account_tabs($tab) { |
|
| 347 | 347 | global $getpaid_tab_url; |
| 348 | 348 | |
| 349 | 349 | $our_tabs = getpaid_get_user_content_tabs(); |
| 350 | 350 | |
| 351 | - if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) { |
|
| 352 | - $getpaid_tab_url = add_query_arg( 'type', '%s', uwp_get_account_page_url() ); |
|
| 353 | - echo getpaid_prepare_user_content_tab( $our_tabs[ $tab ] ); |
|
| 351 | + if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) { |
|
| 352 | + $getpaid_tab_url = add_query_arg('type', '%s', uwp_get_account_page_url()); |
|
| 353 | + echo getpaid_prepare_user_content_tab($our_tabs[$tab]); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | } |
| 357 | -add_action( 'uwp_account_form_display', 'getpaid_display_userswp_account_tabs' ); |
|
| 357 | +add_action('uwp_account_form_display', 'getpaid_display_userswp_account_tabs'); |
|
| 358 | 358 | |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -365,17 +365,17 @@ discard block |
||
| 365 | 365 | * @param string $tab Current tab. |
| 366 | 366 | * @return string Title. |
| 367 | 367 | */ |
| 368 | -function getpaid_filter_userswp_account_title( $title, $tab ) { |
|
| 368 | +function getpaid_filter_userswp_account_title($title, $tab) { |
|
| 369 | 369 | |
| 370 | - $our_tabs = getpaid_get_user_content_tabs(); |
|
| 370 | + $our_tabs = getpaid_get_user_content_tabs(); |
|
| 371 | 371 | |
| 372 | - if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) { |
|
| 373 | - return $our_tabs[ $tab ]['label']; |
|
| 372 | + if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) { |
|
| 373 | + return $our_tabs[$tab]['label']; |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | return $title; |
| 377 | 377 | } |
| 378 | -add_filter( 'uwp_account_page_title', 'getpaid_filter_userswp_account_title', 10, 2 ); |
|
| 378 | +add_filter('uwp_account_page_title', 'getpaid_filter_userswp_account_title', 10, 2); |
|
| 379 | 379 | |
| 380 | 380 | /** |
| 381 | 381 | * Registers the UsersWP integration settings. |
@@ -384,26 +384,26 @@ discard block |
||
| 384 | 384 | * @param array $settings An array of integration settings. |
| 385 | 385 | * @return array |
| 386 | 386 | */ |
| 387 | -function getpaid_register_userswp_settings( $settings ) { |
|
| 387 | +function getpaid_register_userswp_settings($settings) { |
|
| 388 | 388 | |
| 389 | - if ( defined( 'USERSWP_PLUGIN_FILE' ) ) { |
|
| 389 | + if (defined('USERSWP_PLUGIN_FILE')) { |
|
| 390 | 390 | |
| 391 | 391 | $settings[] = array( |
| 392 | 392 | |
| 393 | 393 | 'id' => 'userswp', |
| 394 | - 'label' => __( 'UsersWP', 'invoicing' ), |
|
| 394 | + 'label' => __('UsersWP', 'invoicing'), |
|
| 395 | 395 | 'settings' => array( |
| 396 | 396 | |
| 397 | 397 | 'userswp_settings' => array( |
| 398 | 398 | 'id' => 'userswp_settings', |
| 399 | - 'name' => '<h3>' . __( 'UsersWP', 'invoicing' ) . '</h3>', |
|
| 399 | + 'name' => '<h3>' . __('UsersWP', 'invoicing') . '</h3>', |
|
| 400 | 400 | 'type' => 'header', |
| 401 | 401 | ), |
| 402 | 402 | |
| 403 | 403 | 'enable_userswp' => array( |
| 404 | 404 | 'id' => 'enable_userswp', |
| 405 | - 'name' => __( 'Enable Integration', 'invoicing' ), |
|
| 406 | - 'desc' => __( 'Display GetPaid items on UsersWP account page.', 'invoicing' ), |
|
| 405 | + 'name' => __('Enable Integration', 'invoicing'), |
|
| 406 | + 'desc' => __('Display GetPaid items on UsersWP account page.', 'invoicing'), |
|
| 407 | 407 | 'type' => 'checkbox', |
| 408 | 408 | 'std' => 1, |
| 409 | 409 | ) |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | |
| 417 | 417 | return $settings; |
| 418 | 418 | } |
| 419 | -add_filter( 'getpaid_integration_settings', 'getpaid_register_userswp_settings' ); |
|
| 419 | +add_filter('getpaid_integration_settings', 'getpaid_register_userswp_settings'); |
|
| 420 | 420 | |
| 421 | 421 | /** |
| 422 | 422 | * Checks if the integration is enabled. |
@@ -425,6 +425,6 @@ discard block |
||
| 425 | 425 | * @return bool |
| 426 | 426 | */ |
| 427 | 427 | function getpaid_is_userswp_integration_active() { |
| 428 | - $enabled = wpinv_get_option( 'enable_userswp', 1 ); |
|
| 429 | - return defined( 'USERSWP_PLUGIN_FILE' ) && ! empty( $enabled ); |
|
| 428 | + $enabled = wpinv_get_option('enable_userswp', 1); |
|
| 429 | + return defined('USERSWP_PLUGIN_FILE') && !empty($enabled); |
|
| 430 | 430 | } |
@@ -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,16 +130,16 @@ discard block |
||
| 130 | 130 | return apply_filters( |
| 131 | 131 | 'getpaid_user_address_fields', |
| 132 | 132 | array( |
| 133 | - 'first_name' => __( 'First Name', 'invoicing' ), |
|
| 134 | - 'last_name' => __( 'Last Name', 'invoicing' ), |
|
| 135 | - 'country' => __( 'Country', 'invoicing' ), |
|
| 136 | - 'state' => __( 'State', 'invoicing' ), |
|
| 137 | - 'city' => __( 'City', 'invoicing' ), |
|
| 138 | - 'zip' => __( 'Zip/Postal Code', 'invoicing' ), |
|
| 139 | - 'address' => __( 'Address', 'invoicing' ), |
|
| 140 | - 'phone' => __( 'Phone Number', 'invoicing' ), |
|
| 141 | - 'company' => __( 'Company', 'invoicing' ), |
|
| 142 | - 'vat_number' => __( 'VAT Number', 'invoicing' ), |
|
| 133 | + 'first_name' => __('First Name', 'invoicing'), |
|
| 134 | + 'last_name' => __('Last Name', 'invoicing'), |
|
| 135 | + 'country' => __('Country', 'invoicing'), |
|
| 136 | + 'state' => __('State', 'invoicing'), |
|
| 137 | + 'city' => __('City', 'invoicing'), |
|
| 138 | + 'zip' => __('Zip/Postal Code', 'invoicing'), |
|
| 139 | + 'address' => __('Address', 'invoicing'), |
|
| 140 | + 'phone' => __('Phone Number', 'invoicing'), |
|
| 141 | + 'company' => __('Company', 'invoicing'), |
|
| 142 | + 'vat_number' => __('VAT Number', 'invoicing'), |
|
| 143 | 143 | ) |
| 144 | 144 | ); |
| 145 | 145 | |
@@ -150,8 +150,8 @@ discard block |
||
| 150 | 150 | * |
| 151 | 151 | * @return bool |
| 152 | 152 | */ |
| 153 | -function getpaid_is_address_field_whitelisted( $key ) { |
|
| 154 | - return array_key_exists( $key, getpaid_user_address_fields() ); |
|
| 153 | +function getpaid_is_address_field_whitelisted($key) { |
|
| 154 | + return array_key_exists($key, getpaid_user_address_fields()); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -161,24 +161,24 @@ discard block |
||
| 161 | 161 | * |
| 162 | 162 | * @param WPInv_Invoice $invoice |
| 163 | 163 | */ |
| 164 | -function getpaid_save_invoice_user_address( $invoice ) { |
|
| 164 | +function getpaid_save_invoice_user_address($invoice) { |
|
| 165 | 165 | |
| 166 | 166 | // Retrieve the invoice. |
| 167 | - $invoice = wpinv_get_invoice( $invoice ); |
|
| 167 | + $invoice = wpinv_get_invoice($invoice); |
|
| 168 | 168 | |
| 169 | 169 | // Abort if it does not exist. |
| 170 | - if ( empty( $invoice ) ) { |
|
| 170 | + if (empty($invoice)) { |
|
| 171 | 171 | return; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
| 174 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
| 175 | 175 | |
| 176 | - if ( is_callable( array( $invoice, "get_$field" ) ) ) { |
|
| 177 | - $value = call_user_func( array( $invoice, "get_$field" ) ); |
|
| 176 | + if (is_callable(array($invoice, "get_$field"))) { |
|
| 177 | + $value = call_user_func(array($invoice, "get_$field")); |
|
| 178 | 178 | |
| 179 | 179 | // Only save if it is not empty. |
| 180 | - if ( ! empty( $value ) ) { |
|
| 181 | - update_user_meta( $invoice->get_user_id(), '_wpinv_' . $field, $value ); |
|
| 180 | + if (!empty($value)) { |
|
| 181 | + update_user_meta($invoice->get_user_id(), '_wpinv_' . $field, $value); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | } |
@@ -189,24 +189,24 @@ discard block |
||
| 189 | 189 | $last_name = $invoice->get_last_name(); |
| 190 | 190 | $update = array(); |
| 191 | 191 | |
| 192 | - if ( ! empty( $first_name ) ) { |
|
| 192 | + if (!empty($first_name)) { |
|
| 193 | 193 | $update['first_name'] = $first_name; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - if ( ! empty( $last_name ) ) { |
|
| 196 | + if (!empty($last_name)) { |
|
| 197 | 197 | $update['last_name'] = $last_name; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - if ( 2 == count( $update ) ) { |
|
| 201 | - $update['display_name'] = $first_name . ' ' .$last_name; |
|
| 200 | + if (2 == count($update)) { |
|
| 201 | + $update['display_name'] = $first_name . ' ' . $last_name; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | $update['ID'] = $invoice->get_user_id(); |
| 205 | - wp_update_user( $update ); |
|
| 205 | + wp_update_user($update); |
|
| 206 | 206 | |
| 207 | 207 | } |
| 208 | -add_action( 'getpaid_new_invoice', 'getpaid_save_invoice_user_address' ); |
|
| 209 | -add_action( 'getpaid_update_invoice', 'getpaid_save_invoice_user_address' ); |
|
| 208 | +add_action('getpaid_new_invoice', 'getpaid_save_invoice_user_address'); |
|
| 209 | +add_action('getpaid_update_invoice', 'getpaid_save_invoice_user_address'); |
|
| 210 | 210 | |
| 211 | 211 | /** |
| 212 | 212 | * Retrieves a saved user address. |
@@ -215,14 +215,14 @@ discard block |
||
| 215 | 215 | * @param bool $with_default Whether or not we should use the default country and state. |
| 216 | 216 | * @return array |
| 217 | 217 | */ |
| 218 | -function wpinv_get_user_address( $user_id = 0, $with_default = true ) { |
|
| 218 | +function wpinv_get_user_address($user_id = 0, $with_default = true) { |
|
| 219 | 219 | |
| 220 | 220 | // Prepare the user id. |
| 221 | - $user_id = empty( $user_id ) ? get_current_user_id() : $user_id; |
|
| 222 | - $user_info = get_userdata( $user_id ); |
|
| 221 | + $user_id = empty($user_id) ? get_current_user_id() : $user_id; |
|
| 222 | + $user_info = get_userdata($user_id); |
|
| 223 | 223 | |
| 224 | 224 | // Abort if non exists. |
| 225 | - if ( empty( $user_info ) ) { |
|
| 225 | + if (empty($user_info)) { |
|
| 226 | 226 | return array(); |
| 227 | 227 | } |
| 228 | 228 | |
@@ -232,11 +232,11 @@ discard block |
||
| 232 | 232 | 'email' => $user_info->user_email, |
| 233 | 233 | ); |
| 234 | 234 | |
| 235 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
| 236 | - $address[$field] = getpaid_get_user_address_field( $user_id, $field ); |
|
| 235 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
| 236 | + $address[$field] = getpaid_get_user_address_field($user_id, $field); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - if ( ! $with_default ) { |
|
| 239 | + if (!$with_default) { |
|
| 240 | 240 | return $address; |
| 241 | 241 | } |
| 242 | 242 | |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | 'state' => wpinv_get_default_country(), |
| 248 | 248 | ); |
| 249 | 249 | |
| 250 | - return getpaid_array_merge_if_empty( $address, $defaults ); |
|
| 250 | + return getpaid_array_merge_if_empty($address, $defaults); |
|
| 251 | 251 | |
| 252 | 252 | } |
| 253 | 253 | |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | * @param string $field The field to use. |
| 259 | 259 | * @return string|null |
| 260 | 260 | */ |
| 261 | -function getpaid_get_user_address_field( $user_id, $field ) { |
|
| 261 | +function getpaid_get_user_address_field($user_id, $field) { |
|
| 262 | 262 | |
| 263 | 263 | $prefixes = array( |
| 264 | 264 | '_wpinv_', |
@@ -266,15 +266,15 @@ discard block |
||
| 266 | 266 | '' |
| 267 | 267 | ); |
| 268 | 268 | |
| 269 | - foreach ( $prefixes as $prefix ) { |
|
| 269 | + foreach ($prefixes as $prefix) { |
|
| 270 | 270 | |
| 271 | 271 | // Meta table. |
| 272 | - $value = get_user_meta( $user_id, $prefix . $field, true ); |
|
| 272 | + $value = get_user_meta($user_id, $prefix . $field, true); |
|
| 273 | 273 | |
| 274 | 274 | // UWP table. |
| 275 | - $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value; |
|
| 275 | + $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value; |
|
| 276 | 276 | |
| 277 | - if ( ! empty( $value ) ) { |
|
| 277 | + if (!empty($value)) { |
|
| 278 | 278 | return $value; |
| 279 | 279 | } |
| 280 | 280 | |
@@ -291,16 +291,16 @@ discard block |
||
| 291 | 291 | * @param string $return What to return. |
| 292 | 292 | * @return array |
| 293 | 293 | */ |
| 294 | -function wpinv_get_continents( $return = 'all' ) { |
|
| 294 | +function wpinv_get_continents($return = 'all') { |
|
| 295 | 295 | |
| 296 | - $continents = wpinv_get_data( 'continents' ); |
|
| 296 | + $continents = wpinv_get_data('continents'); |
|
| 297 | 297 | |
| 298 | - switch( $return ) { |
|
| 298 | + switch ($return) { |
|
| 299 | 299 | case 'name' : |
| 300 | - return wp_list_pluck( $continents, 'name' ); |
|
| 300 | + return wp_list_pluck($continents, 'name'); |
|
| 301 | 301 | break; |
| 302 | 302 | case 'countries' : |
| 303 | - return wp_list_pluck( $continents, 'countries' ); |
|
| 303 | + return wp_list_pluck($continents, 'countries'); |
|
| 304 | 304 | break; |
| 305 | 305 | default : |
| 306 | 306 | return $continents; |
@@ -316,12 +316,12 @@ discard block |
||
| 316 | 316 | * @param string $country Country code. If no code is specified, defaults to the default country. |
| 317 | 317 | * @return string |
| 318 | 318 | */ |
| 319 | -function wpinv_get_continent_code_for_country( $country = false ) { |
|
| 319 | +function wpinv_get_continent_code_for_country($country = false) { |
|
| 320 | 320 | |
| 321 | - $country = wpinv_sanitize_country( $country ); |
|
| 321 | + $country = wpinv_sanitize_country($country); |
|
| 322 | 322 | |
| 323 | - foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
| 324 | - if ( false !== array_search( $country, $countries, true ) ) { |
|
| 323 | + foreach (wpinv_get_continents('countries') as $continent_code => $countries) { |
|
| 324 | + if (false !== array_search($country, $countries, true)) { |
|
| 325 | 325 | return $continent_code; |
| 326 | 326 | } |
| 327 | 327 | } |
@@ -337,13 +337,13 @@ discard block |
||
| 337 | 337 | * @param string $country Country code. If no code is specified, defaults to the default country. |
| 338 | 338 | * @return array |
| 339 | 339 | */ |
| 340 | -function wpinv_get_country_calling_code( $country = null) { |
|
| 340 | +function wpinv_get_country_calling_code($country = null) { |
|
| 341 | 341 | |
| 342 | - $country = wpinv_sanitize_country( $country ); |
|
| 343 | - $codes = wpinv_get_data( 'phone-codes' ); |
|
| 344 | - $code = isset( $codes[ $country ] ) ? $codes[ $country ] : ''; |
|
| 342 | + $country = wpinv_sanitize_country($country); |
|
| 343 | + $codes = wpinv_get_data('phone-codes'); |
|
| 344 | + $code = isset($codes[$country]) ? $codes[$country] : ''; |
|
| 345 | 345 | |
| 346 | - if ( is_array( $code ) ) { |
|
| 346 | + if (is_array($code)) { |
|
| 347 | 347 | return $code[0]; |
| 348 | 348 | } |
| 349 | 349 | return $code; |
@@ -356,8 +356,8 @@ discard block |
||
| 356 | 356 | * @param bool $first_empty Whether or not the first item in the list should be empty |
| 357 | 357 | * @return array |
| 358 | 358 | */ |
| 359 | -function wpinv_get_country_list( $first_empty = false ) { |
|
| 360 | - return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty ); |
|
| 359 | +function wpinv_get_country_list($first_empty = false) { |
|
| 360 | + return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | /** |
@@ -367,22 +367,22 @@ discard block |
||
| 367 | 367 | * @param bool $first_empty Whether or not the first item in the list should be empty |
| 368 | 368 | * @return array |
| 369 | 369 | */ |
| 370 | -function wpinv_get_country_states( $country = null, $first_empty = false ) { |
|
| 370 | +function wpinv_get_country_states($country = null, $first_empty = false) { |
|
| 371 | 371 | |
| 372 | 372 | // Prepare the country. |
| 373 | - $country = wpinv_sanitize_country( $country ); |
|
| 373 | + $country = wpinv_sanitize_country($country); |
|
| 374 | 374 | |
| 375 | 375 | // Fetch all states. |
| 376 | - $all_states = wpinv_get_data( 'states' ); |
|
| 376 | + $all_states = wpinv_get_data('states'); |
|
| 377 | 377 | |
| 378 | 378 | // Fetch the specified country's states. |
| 379 | - $states = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array() ; |
|
| 380 | - $states = apply_filters( "wpinv_{$country}_states", $states ); |
|
| 381 | - $states = apply_filters( 'wpinv_country_states', $states, $country ); |
|
| 379 | + $states = isset($all_states[$country]) ? $all_states[$country] : array(); |
|
| 380 | + $states = apply_filters("wpinv_{$country}_states", $states); |
|
| 381 | + $states = apply_filters('wpinv_country_states', $states, $country); |
|
| 382 | 382 | |
| 383 | - asort( $states ); |
|
| 383 | + asort($states); |
|
| 384 | 384 | |
| 385 | - return wpinv_maybe_add_empty_option( $states, $first_empty ); |
|
| 385 | + return wpinv_maybe_add_empty_option($states, $first_empty); |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | /** |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | * @return array |
| 393 | 393 | */ |
| 394 | 394 | function wpinv_get_us_states_list() { |
| 395 | - return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) ); |
|
| 395 | + return apply_filters('wpinv_usa_states', wpinv_get_country_states('US')); |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | /** |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | * @return array |
| 403 | 403 | */ |
| 404 | 404 | function wpinv_get_canada_states_list() { |
| 405 | - return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) ); |
|
| 405 | + return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA')); |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | /** |
@@ -412,7 +412,7 @@ discard block |
||
| 412 | 412 | * @return array |
| 413 | 413 | */ |
| 414 | 414 | function wpinv_get_australia_states_list() { |
| 415 | - return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) ); |
|
| 415 | + return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU')); |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | /** |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | * @return array |
| 423 | 423 | */ |
| 424 | 424 | function wpinv_get_bangladesh_states_list() { |
| 425 | - return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) ); |
|
| 425 | + return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD')); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | /** |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | * @return array |
| 433 | 433 | */ |
| 434 | 434 | function wpinv_get_brazil_states_list() { |
| 435 | - return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) ); |
|
| 435 | + return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR')); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | /** |
@@ -442,7 +442,7 @@ discard block |
||
| 442 | 442 | * @return array |
| 443 | 443 | */ |
| 444 | 444 | function wpinv_get_bulgaria_states_list() { |
| 445 | - return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) ); |
|
| 445 | + return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG')); |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | /** |
@@ -452,7 +452,7 @@ discard block |
||
| 452 | 452 | * @return array |
| 453 | 453 | */ |
| 454 | 454 | function wpinv_get_hong_kong_states_list() { |
| 455 | - return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) ); |
|
| 455 | + return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK')); |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | /** |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | * @return array |
| 463 | 463 | */ |
| 464 | 464 | function wpinv_get_hungary_states_list() { |
| 465 | - return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) ); |
|
| 465 | + return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU')); |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | /** |
@@ -472,7 +472,7 @@ discard block |
||
| 472 | 472 | * @return array |
| 473 | 473 | */ |
| 474 | 474 | function wpinv_get_japan_states_list() { |
| 475 | - return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) ); |
|
| 475 | + return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP')); |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | /** |
@@ -482,7 +482,7 @@ discard block |
||
| 482 | 482 | * @return array |
| 483 | 483 | */ |
| 484 | 484 | function wpinv_get_china_states_list() { |
| 485 | - return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) ); |
|
| 485 | + return apply_filters('wpinv_china_states', wpinv_get_country_states('CN')); |
|
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | /** |
@@ -492,7 +492,7 @@ discard block |
||
| 492 | 492 | * @return array |
| 493 | 493 | */ |
| 494 | 494 | function wpinv_get_new_zealand_states_list() { |
| 495 | - return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) ); |
|
| 495 | + return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ')); |
|
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | /** |
@@ -502,7 +502,7 @@ discard block |
||
| 502 | 502 | * @return array |
| 503 | 503 | */ |
| 504 | 504 | function wpinv_get_peru_states_list() { |
| 505 | - return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) ); |
|
| 505 | + return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE')); |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | /** |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | * @return array |
| 513 | 513 | */ |
| 514 | 514 | function wpinv_get_indonesia_states_list() { |
| 515 | - return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) ); |
|
| 515 | + return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID')); |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | /** |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | * @return array |
| 523 | 523 | */ |
| 524 | 524 | function wpinv_get_india_states_list() { |
| 525 | - return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) ); |
|
| 525 | + return apply_filters('wpinv_india_states', wpinv_get_country_states('IN')); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | /** |
@@ -532,7 +532,7 @@ discard block |
||
| 532 | 532 | * @return array |
| 533 | 533 | */ |
| 534 | 534 | function wpinv_get_iran_states_list() { |
| 535 | - return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) ); |
|
| 535 | + return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR')); |
|
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | /** |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | * @return array |
| 543 | 543 | */ |
| 544 | 544 | function wpinv_get_italy_states_list() { |
| 545 | - return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) ); |
|
| 545 | + return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT')); |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | /** |
@@ -552,7 +552,7 @@ discard block |
||
| 552 | 552 | * @return array |
| 553 | 553 | */ |
| 554 | 554 | function wpinv_get_malaysia_states_list() { |
| 555 | - return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) ); |
|
| 555 | + return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY')); |
|
| 556 | 556 | } |
| 557 | 557 | |
| 558 | 558 | /** |
@@ -562,7 +562,7 @@ discard block |
||
| 562 | 562 | * @return array |
| 563 | 563 | */ |
| 564 | 564 | function wpinv_get_mexico_states_list() { |
| 565 | - return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) ); |
|
| 565 | + return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX')); |
|
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | /** |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | * @return array |
| 573 | 573 | */ |
| 574 | 574 | function wpinv_get_nepal_states_list() { |
| 575 | - return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) ); |
|
| 575 | + return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP')); |
|
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | /** |
@@ -582,7 +582,7 @@ discard block |
||
| 582 | 582 | * @return array |
| 583 | 583 | */ |
| 584 | 584 | function wpinv_get_south_africa_states_list() { |
| 585 | - return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) ); |
|
| 585 | + return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA')); |
|
| 586 | 586 | } |
| 587 | 587 | |
| 588 | 588 | /** |
@@ -592,7 +592,7 @@ discard block |
||
| 592 | 592 | * @return array |
| 593 | 593 | */ |
| 594 | 594 | function wpinv_get_thailand_states_list() { |
| 595 | - return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) ); |
|
| 595 | + return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH')); |
|
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | /** |
@@ -602,7 +602,7 @@ discard block |
||
| 602 | 602 | * @return array |
| 603 | 603 | */ |
| 604 | 604 | function wpinv_get_turkey_states_list() { |
| 605 | - return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) ); |
|
| 605 | + return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR')); |
|
| 606 | 606 | } |
| 607 | 607 | |
| 608 | 608 | /** |
@@ -612,28 +612,28 @@ discard block |
||
| 612 | 612 | * @return array |
| 613 | 613 | */ |
| 614 | 614 | function wpinv_get_spain_states_list() { |
| 615 | - return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) ); |
|
| 615 | + return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES')); |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | function wpinv_get_states_field() { |
| 619 | - if( empty( $_POST['country'] ) ) { |
|
| 619 | + if (empty($_POST['country'])) { |
|
| 620 | 620 | $_POST['country'] = wpinv_get_default_country(); |
| 621 | 621 | } |
| 622 | - $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
| 622 | + $states = wpinv_get_country_states(sanitize_text_field($_POST['country'])); |
|
| 623 | 623 | |
| 624 | - if( !empty( $states ) ) { |
|
| 625 | - $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
| 624 | + if (!empty($states)) { |
|
| 625 | + $sanitized_field_name = sanitize_text_field($_POST['field_name']); |
|
| 626 | 626 | |
| 627 | 627 | $args = array( |
| 628 | 628 | 'name' => $sanitized_field_name, |
| 629 | 629 | 'id' => $sanitized_field_name, |
| 630 | 630 | 'class' => $sanitized_field_name . 'custom-select wpinv-select wpi_select2', |
| 631 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
| 631 | + 'options' => array_merge(array('' => ''), $states), |
|
| 632 | 632 | 'show_option_all' => false, |
| 633 | 633 | 'show_option_none' => false |
| 634 | 634 | ); |
| 635 | 635 | |
| 636 | - $response = wpinv_html_select( $args ); |
|
| 636 | + $response = wpinv_html_select($args); |
|
| 637 | 637 | |
| 638 | 638 | } else { |
| 639 | 639 | $response = 'nostates'; |
@@ -642,10 +642,10 @@ discard block |
||
| 642 | 642 | return $response; |
| 643 | 643 | } |
| 644 | 644 | |
| 645 | -function wpinv_default_billing_country( $country = '', $user_id = 0 ) { |
|
| 646 | - $country = !empty( $country ) ? $country : wpinv_get_default_country(); |
|
| 645 | +function wpinv_default_billing_country($country = '', $user_id = 0) { |
|
| 646 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
| 647 | 647 | |
| 648 | - return apply_filters( 'wpinv_default_billing_country', $country, $user_id ); |
|
| 648 | + return apply_filters('wpinv_default_billing_country', $country, $user_id); |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | /** |
@@ -657,7 +657,7 @@ discard block |
||
| 657 | 657 | */ |
| 658 | 658 | function wpinv_get_address_formats() { |
| 659 | 659 | |
| 660 | - return apply_filters( 'wpinv_localisation_address_formats', |
|
| 660 | + return apply_filters('wpinv_localisation_address_formats', |
|
| 661 | 661 | array( |
| 662 | 662 | 'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}", |
| 663 | 663 | 'AU' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}", |
@@ -706,9 +706,9 @@ discard block |
||
| 706 | 706 | * @see `wpinv_get_invoice_address_replacements` |
| 707 | 707 | * @return string |
| 708 | 708 | */ |
| 709 | -function wpinv_get_full_address_format( $country = false) { |
|
| 709 | +function wpinv_get_full_address_format($country = false) { |
|
| 710 | 710 | |
| 711 | - if( empty( $country ) ) { |
|
| 711 | + if (empty($country)) { |
|
| 712 | 712 | $country = wpinv_get_default_country(); |
| 713 | 713 | } |
| 714 | 714 | |
@@ -716,7 +716,7 @@ discard block |
||
| 716 | 716 | $formats = wpinv_get_address_formats(); |
| 717 | 717 | |
| 718 | 718 | // Get format for the specified country. |
| 719 | - $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
| 719 | + $format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default']; |
|
| 720 | 720 | |
| 721 | 721 | /** |
| 722 | 722 | * Filters the address format to use on Invoices. |
@@ -728,7 +728,7 @@ discard block |
||
| 728 | 728 | * @param string $format The address format to use. |
| 729 | 729 | * @param string $country The country who's address format is being retrieved. |
| 730 | 730 | */ |
| 731 | - return apply_filters( 'wpinv_get_full_address_format', $format, $country ); |
|
| 731 | + return apply_filters('wpinv_get_full_address_format', $format, $country); |
|
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | /** |
@@ -739,7 +739,7 @@ discard block |
||
| 739 | 739 | * @param array $billing_details customer's billing details |
| 740 | 740 | * @return array |
| 741 | 741 | */ |
| 742 | -function wpinv_get_invoice_address_replacements( $billing_details ) { |
|
| 742 | +function wpinv_get_invoice_address_replacements($billing_details) { |
|
| 743 | 743 | |
| 744 | 744 | $default_args = array( |
| 745 | 745 | 'address' => '', |
@@ -752,22 +752,22 @@ discard block |
||
| 752 | 752 | 'company' => '', |
| 753 | 753 | ); |
| 754 | 754 | |
| 755 | - $args = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' ); |
|
| 755 | + $args = map_deep(wp_parse_args($billing_details, $default_args), 'trim'); |
|
| 756 | 756 | $state = $args['state']; |
| 757 | 757 | $country = $args['country']; |
| 758 | 758 | |
| 759 | 759 | // Handle full country name. |
| 760 | - $full_country = empty( $country ) ? $country : wpinv_country_name( $country ); |
|
| 760 | + $full_country = empty($country) ? $country : wpinv_country_name($country); |
|
| 761 | 761 | |
| 762 | 762 | // Handle full state name. |
| 763 | - $full_state = ( $country && $state ) ? wpinv_state_name( $state, $country ) : $state; |
|
| 763 | + $full_state = ($country && $state) ? wpinv_state_name($state, $country) : $state; |
|
| 764 | 764 | |
| 765 | 765 | $args['postcode'] = $args['zip']; |
| 766 | 766 | $args['name'] = $args['first_name'] . ' ' . $args['last_name']; |
| 767 | 767 | $args['state'] = $full_state; |
| 768 | 768 | $args['state_code'] = $state; |
| 769 | 769 | $args['country'] = $full_country; |
| 770 | - $args['country_code']= $country; |
|
| 770 | + $args['country_code'] = $country; |
|
| 771 | 771 | |
| 772 | 772 | /** |
| 773 | 773 | * Filters the address format replacements to use on Invoices. |
@@ -778,14 +778,14 @@ discard block |
||
| 778 | 778 | * @param array $replacements The address replacements to use. |
| 779 | 779 | * @param array $billing_details The billing details to use. |
| 780 | 780 | */ |
| 781 | - $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details ); |
|
| 781 | + $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details); |
|
| 782 | 782 | |
| 783 | 783 | $return = array(); |
| 784 | 784 | |
| 785 | - foreach( $replacements as $key => $value ) { |
|
| 786 | - $value = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : ''; |
|
| 785 | + foreach ($replacements as $key => $value) { |
|
| 786 | + $value = is_scalar($value) ? trim(sanitize_text_field($value)) : ''; |
|
| 787 | 787 | $return['{{' . $key . '}}'] = $value; |
| 788 | - $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper( $value ); |
|
| 788 | + $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value); |
|
| 789 | 789 | } |
| 790 | 790 | |
| 791 | 791 | return $return; |
@@ -799,6 +799,6 @@ discard block |
||
| 799 | 799 | * @since 1.0.14 |
| 800 | 800 | * @return string |
| 801 | 801 | */ |
| 802 | -function wpinv_trim_formatted_address_line( $line ) { |
|
| 803 | - return trim( $line, ', ' ); |
|
| 802 | +function wpinv_trim_formatted_address_line($line) { |
|
| 803 | + return trim($line, ', '); |
|
| 804 | 804 | } |
| 805 | 805 | \ No newline at end of file |