@@ -8,8 +8,8 @@ |
||
| 8 | 8 | |
| 9 | 9 | $dummy_rule = array( |
| 10 | 10 | 'key' => 'TAX_RULE_KEY', |
| 11 | - 'label' => __( 'New Tax Rule', 'invoicing' ), |
|
| 12 | - 'tax_base' => wpinv_get_option( 'tax_base', 'billing' ), |
|
| 11 | + 'label' => __( 'New Tax Rule', 'invoicing' ), |
|
| 12 | + 'tax_base' => wpinv_get_option( 'tax_base', 'billing' ), |
|
| 13 | 13 | 'same_country_rule' => wpinv_get_option( 'vat_same_country_rule', 'vat_too' ), |
| 14 | 14 | ); |
| 15 | 15 | |
@@ -4,40 +4,40 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | $dummy_rule = array( |
| 10 | 10 | 'key' => 'TAX_RULE_KEY', |
| 11 | - 'label' => __( 'New Tax Rule', 'invoicing' ), |
|
| 12 | - 'tax_base' => wpinv_get_option( 'tax_base', 'billing' ), |
|
| 13 | - 'same_country_rule' => wpinv_get_option( 'vat_same_country_rule', 'vat_too' ), |
|
| 11 | + 'label' => __('New Tax Rule', 'invoicing'), |
|
| 12 | + 'tax_base' => wpinv_get_option('tax_base', 'billing'), |
|
| 13 | + 'same_country_rule' => wpinv_get_option('vat_same_country_rule', 'vat_too'), |
|
| 14 | 14 | ); |
| 15 | 15 | |
| 16 | -wp_nonce_field( 'wpinv_tax_rules', 'wpinv_tax_rules_nonce' ); |
|
| 16 | +wp_nonce_field('wpinv_tax_rules', 'wpinv_tax_rules_nonce'); |
|
| 17 | 17 | |
| 18 | 18 | ?> |
| 19 | 19 | <div class="table-responsive"> |
| 20 | 20 | <table id="wpinv-tax-rules" class="widefat fixed table"> |
| 21 | - <caption><?php echo esc_html_e( 'You can use this section to create or edit your tax rules', 'invoicing' ); ?></caption> |
|
| 21 | + <caption><?php echo esc_html_e('You can use this section to create or edit your tax rules', 'invoicing'); ?></caption> |
|
| 22 | 22 | |
| 23 | 23 | <thead> |
| 24 | 24 | <tr class="table-light"> |
| 25 | 25 | |
| 26 | 26 | <th scope="col" class="border-bottom border-top"> |
| 27 | - <?php esc_html_e( 'Unique Key', 'invoicing' ); ?> |
|
| 27 | + <?php esc_html_e('Unique Key', 'invoicing'); ?> |
|
| 28 | 28 | </th> |
| 29 | 29 | |
| 30 | 30 | <th scope="col" class="border-bottom border-top"> |
| 31 | - <?php esc_html_e( 'Label', 'invoicing' ); ?> |
|
| 31 | + <?php esc_html_e('Label', 'invoicing'); ?> |
|
| 32 | 32 | </th> |
| 33 | 33 | |
| 34 | 34 | <th scope="col" class="border-bottom border-top"> |
| 35 | - <?php esc_html_e( 'Calculate tax based on', 'invoicing' ); ?> |
|
| 35 | + <?php esc_html_e('Calculate tax based on', 'invoicing'); ?> |
|
| 36 | 36 | </th> |
| 37 | 37 | |
| 38 | 38 | <!-- <th scope="col" class="border-bottom border-top"> |
| 39 | - <?php esc_html_e( 'Same country rule', 'invoicing' ); ?> |
|
| 40 | - <?php getpaid_get_help_tip( __( 'What should happen if a customer is from the same country as your business?.', 'invoicing' ), 'position-static', true ); ?> |
|
| 39 | + <?php esc_html_e('Same country rule', 'invoicing'); ?> |
|
| 40 | + <?php getpaid_get_help_tip(__('What should happen if a customer is from the same country as your business?.', 'invoicing'), 'position-static', true); ?> |
|
| 41 | 41 | </th> --> |
| 42 | 42 | |
| 43 | 43 | <th scope="col" class="border-bottom border-top" style="width:32px"> </th> |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | </thead> |
| 47 | 47 | |
| 48 | 48 | <tbody> |
| 49 | - <?php foreach ( GetPaid_Tax::get_all_tax_rules() as $tax_rule ) : ?> |
|
| 50 | - <?php include plugin_dir_path( __FILE__ ) . 'html-tax-rule-edit.php'; ?> |
|
| 49 | + <?php foreach (GetPaid_Tax::get_all_tax_rules() as $tax_rule) : ?> |
|
| 50 | + <?php include plugin_dir_path(__FILE__) . 'html-tax-rule-edit.php'; ?> |
|
| 51 | 51 | <?php endforeach; ?> |
| 52 | 52 | </tbody> |
| 53 | 53 | |
@@ -55,8 +55,8 @@ discard block |
||
| 55 | 55 | <tr class="table-light"> |
| 56 | 56 | <td colspan="4" class="border-top"> |
| 57 | 57 | |
| 58 | - <button type="button" class="button button-secondary wpinv_add_tax_rule" aria-label="<?php esc_attr_e( 'Add Tax Rule', 'invoicing' ); ?>"> |
|
| 59 | - <span><?php esc_html_e( 'Add Tax Rule', 'invoicing' ); ?></span> |
|
| 58 | + <button type="button" class="button button-secondary wpinv_add_tax_rule" aria-label="<?php esc_attr_e('Add Tax Rule', 'invoicing'); ?>"> |
|
| 59 | + <span><?php esc_html_e('Add Tax Rule', 'invoicing'); ?></span> |
|
| 60 | 60 | </button> |
| 61 | 61 | |
| 62 | 62 | </td> |
@@ -67,6 +67,6 @@ discard block |
||
| 67 | 67 | |
| 68 | 68 | <script type="text/html" id="tmpl-wpinv-tax-rule-row"> |
| 69 | 69 | <?php $tax_rule = $dummy_rule; ?> |
| 70 | - <?php include plugin_dir_path( __FILE__ ) . 'html-tax-rule-edit.php'; ?> |
|
| 70 | + <?php include plugin_dir_path(__FILE__) . 'html-tax-rule-edit.php'; ?> |
|
| 71 | 71 | </script> |
| 72 | 72 | |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | ?> |
| 10 | 10 | |
@@ -12,24 +12,24 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | <form method="post" class="text-center card-body"> |
| 14 | 14 | <div class="gp-wizard-payments"> |
| 15 | - <h2 class="gd-settings-title h3 "><?php esc_html_e( 'Gateway Setup', 'invoicing' ); ?></h2> |
|
| 16 | - <p><?php esc_html_e( 'Below are a few gateways that can be setup in a few seconds.', 'invoicing' ); ?> |
|
| 15 | + <h2 class="gd-settings-title h3 "><?php esc_html_e('Gateway Setup', 'invoicing'); ?></h2> |
|
| 16 | + <p><?php esc_html_e('Below are a few gateways that can be setup in a few seconds.', 'invoicing'); ?> |
|
| 17 | 17 | <br> |
| 18 | - <?php esc_html_e( 'We have 20+ Gateways that can be setup later.', 'invoicing' ); ?> |
|
| 18 | + <?php esc_html_e('We have 20+ Gateways that can be setup later.', 'invoicing'); ?> |
|
| 19 | 19 | </p> |
| 20 | 20 | |
| 21 | 21 | <ul class="list-group"> |
| 22 | 22 | |
| 23 | 23 | <li class="list-group-item d-flex justify-content-between align-items-center"> |
| 24 | - <span class="mr-auto"><img src="<?php echo esc_url( WPINV_PLUGIN_URL . 'assets/images/stripe-verified.svg' ); ?>" class="ml-n2" alt="Stripe"></span> |
|
| 25 | - <?php if ( false === wpinv_get_option( 'stripe_live_connect_account_id' ) ) : ?> |
|
| 24 | + <span class="mr-auto"><img src="<?php echo esc_url(WPINV_PLUGIN_URL . 'assets/images/stripe-verified.svg'); ?>" class="ml-n2" alt="Stripe"></span> |
|
| 25 | + <?php if (false === wpinv_get_option('stripe_live_connect_account_id')) : ?> |
|
| 26 | 26 | <a href="<?php |
| 27 | - echo esc_url( wp_nonce_url( |
|
| 27 | + echo esc_url(wp_nonce_url( |
|
| 28 | 28 | add_query_arg( |
| 29 | 29 | array( |
| 30 | 30 | 'getpaid-admin-action' => 'connect_gateway', |
| 31 | 31 | 'plugin' => 'stripe', |
| 32 | - 'redirect' => urlencode( add_query_arg( 'step', 'payments' ) ), |
|
| 32 | + 'redirect' => urlencode(add_query_arg('step', 'payments')), |
|
| 33 | 33 | ), |
| 34 | 34 | admin_url() |
| 35 | 35 | ), |
@@ -37,31 +37,31 @@ discard block |
||
| 37 | 37 | 'getpaid-nonce' |
| 38 | 38 | )); |
| 39 | 39 | ?>" |
| 40 | - class="btn btn-sm btn-outline-primary"><?php esc_html_e( 'Connect', 'invoicing' ); ?></a> |
|
| 40 | + class="btn btn-sm btn-outline-primary"><?php esc_html_e('Connect', 'invoicing'); ?></a> |
|
| 41 | 41 | <?php else : ?> |
| 42 | - <span class="btn btn-sm btn-success"><?php esc_html_e( 'Connected', 'invoicing' ); ?></span> |
|
| 42 | + <span class="btn btn-sm btn-success"><?php esc_html_e('Connected', 'invoicing'); ?></span> |
|
| 43 | 43 | <?php endif; ?> |
| 44 | 44 | </li> |
| 45 | 45 | |
| 46 | 46 | <li class="list-group-item"> |
| 47 | 47 | <div class="d-flex justify-content-between align-items-center"> |
| 48 | 48 | <span class="mr-auto"> |
| 49 | - <img src="<?php echo esc_url( WPINV_PLUGIN_URL . 'assets/images/pp-logo-150px.webp' ); ?>" class="" alt="PayPal" height="25"> |
|
| 49 | + <img src="<?php echo esc_url(WPINV_PLUGIN_URL . 'assets/images/pp-logo-150px.webp'); ?>" class="" alt="PayPal" height="25"> |
|
| 50 | 50 | </span> |
| 51 | 51 | <a |
| 52 | 52 | href="#" |
| 53 | 53 | onclick="jQuery('.getpaid-setup-paypal-input').toggleClass('d-none'); return false;" |
| 54 | - class="getpaid-setup-paypal btn btn-sm btn-outline-primary"><?php esc_html_e( 'Set-up', 'invoicing' ); ?></a> |
|
| 54 | + class="getpaid-setup-paypal btn btn-sm btn-outline-primary"><?php esc_html_e('Set-up', 'invoicing'); ?></a> |
|
| 55 | 55 | </div> |
| 56 | 56 | <div class="mt-4 getpaid-setup-paypal-input d-none"> |
| 57 | - <input type="text" placeholder="<?php esc_attr_e( 'PayPal Email', 'invoicing' ); ?>" name="paypal-email" class="form-control" value="<?php echo esc_attr( wpinv_get_option( 'paypal_email' ) ); ?>"> |
|
| 57 | + <input type="text" placeholder="<?php esc_attr_e('PayPal Email', 'invoicing'); ?>" name="paypal-email" class="form-control" value="<?php echo esc_attr(wpinv_get_option('paypal_email')); ?>"> |
|
| 58 | 58 | </div> |
| 59 | 59 | </li> |
| 60 | 60 | |
| 61 | 61 | <li class="list-group-item d-flex justify-content-between align-items-center"> |
| 62 | - <span class="mr-auto"><?php esc_html_e( 'Test Gateway', 'invoicing' ); ?></span> |
|
| 62 | + <span class="mr-auto"><?php esc_html_e('Test Gateway', 'invoicing'); ?></span> |
|
| 63 | 63 | <div class="custom-control custom-switch"> |
| 64 | - <input type="checkbox" name="enable-manual-gateway" class="custom-control-input" id="enable-manual-gateway" <?php checked( wpinv_is_gateway_active( 'manual' ) ); ?>> |
|
| 64 | + <input type="checkbox" name="enable-manual-gateway" class="custom-control-input" id="enable-manual-gateway" <?php checked(wpinv_is_gateway_active('manual')); ?>> |
|
| 65 | 65 | <label class="custom-control-label" for="enable-manual-gateway"></label> |
| 66 | 66 | </div> |
| 67 | 67 | </li> |
@@ -70,10 +70,10 @@ discard block |
||
| 70 | 70 | </div> |
| 71 | 71 | |
| 72 | 72 | <p class="gp-setup-actions step text-center mt-4"> |
| 73 | - <input type="submit" class="btn btn-primary" value="<?php esc_attr_e( 'Continue', 'invoicing' ); ?>" /> |
|
| 73 | + <input type="submit" class="btn btn-primary" value="<?php esc_attr_e('Continue', 'invoicing'); ?>" /> |
|
| 74 | 74 | </p> |
| 75 | 75 | |
| 76 | - <?php getpaid_hidden_field( 'save_step', 1 ); ?> |
|
| 77 | - <?php wp_nonce_field( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); ?> |
|
| 76 | + <?php getpaid_hidden_field('save_step', 1); ?> |
|
| 77 | + <?php wp_nonce_field('getpaid-setup-wizard', 'getpaid-setup-wizard'); ?> |
|
| 78 | 78 | </form> |
| 79 | 79 | </div> |
@@ -38,8 +38,11 @@ |
||
| 38 | 38 | )); |
| 39 | 39 | ?>" |
| 40 | 40 | class="btn btn-sm btn-outline-primary"><?php esc_html_e( 'Connect', 'invoicing' ); ?></a> |
| 41 | - <?php else : ?> |
|
| 42 | - <span class="btn btn-sm btn-success"><?php esc_html_e( 'Connected', 'invoicing' ); ?></span> |
|
| 41 | + <?php else { |
|
| 42 | + : ?> |
|
| 43 | + <span class="btn btn-sm btn-success"><?php esc_html_e( 'Connected', 'invoicing' ); |
|
| 44 | +} |
|
| 45 | +?></span> |
|
| 43 | 46 | <?php endif; ?> |
| 44 | 47 | </li> |
| 45 | 48 | |
@@ -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; |
@@ -220,43 +220,43 @@ discard block |
||
| 220 | 220 | |
| 221 | 221 | foreach ( getpaid_user_address_fields() as $key => $label ) { |
| 222 | 222 | |
| 223 | - // Display the country. |
|
| 224 | - if ( 'country' == $key ) { |
|
| 225 | - |
|
| 226 | - aui()->select( |
|
| 227 | - array( |
|
| 228 | - 'options' => wpinv_get_country_list(), |
|
| 229 | - 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
|
| 230 | - 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
| 231 | - 'value' => sanitize_text_field( getpaid_get_user_address_field( get_current_user_id(), $key ) ), |
|
| 232 | - 'placeholder' => $label, |
|
| 233 | - 'label' => wp_kses_post( $label ), |
|
| 234 | - 'label_type' => 'vertical', |
|
| 235 | - 'class' => 'getpaid-address-field', |
|
| 223 | + // Display the country. |
|
| 224 | + if ( 'country' == $key ) { |
|
| 225 | + |
|
| 226 | + aui()->select( |
|
| 227 | + array( |
|
| 228 | + 'options' => wpinv_get_country_list(), |
|
| 229 | + 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
|
| 230 | + 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
| 231 | + 'value' => sanitize_text_field( getpaid_get_user_address_field( get_current_user_id(), $key ) ), |
|
| 232 | + 'placeholder' => $label, |
|
| 233 | + 'label' => wp_kses_post( $label ), |
|
| 234 | + 'label_type' => 'vertical', |
|
| 235 | + 'class' => 'getpaid-address-field', |
|
| 236 | 236 | ), |
| 237 | 237 | true |
| 238 | - ); |
|
| 239 | - |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - // Display the state. |
|
| 243 | - elseif ( 'state' == $key ) { |
|
| 244 | - |
|
| 245 | - getpaid_get_states_select_markup( |
|
| 246 | - getpaid_get_user_address_field( get_current_user_id(), 'country' ), |
|
| 247 | - getpaid_get_user_address_field( get_current_user_id(), 'state' ), |
|
| 248 | - $label, |
|
| 249 | - $label, |
|
| 250 | - '', |
|
| 251 | - false, |
|
| 252 | - '', |
|
| 253 | - 'getpaid_address[' . esc_attr( $key ) . ']', |
|
| 238 | + ); |
|
| 239 | + |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + // Display the state. |
|
| 243 | + elseif ( 'state' == $key ) { |
|
| 244 | + |
|
| 245 | + getpaid_get_states_select_markup( |
|
| 246 | + getpaid_get_user_address_field( get_current_user_id(), 'country' ), |
|
| 247 | + getpaid_get_user_address_field( get_current_user_id(), 'state' ), |
|
| 248 | + $label, |
|
| 249 | + $label, |
|
| 250 | + '', |
|
| 251 | + false, |
|
| 252 | + '', |
|
| 253 | + 'getpaid_address[' . esc_attr( $key ) . ']', |
|
| 254 | 254 | true |
| 255 | - ); |
|
| 255 | + ); |
|
| 256 | 256 | |
| 257 | 257 | } else { |
| 258 | 258 | |
| 259 | - aui()->input( |
|
| 259 | + aui()->input( |
|
| 260 | 260 | array( |
| 261 | 261 | 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
| 262 | 262 | 'id' => 'wpinv-' . sanitize_html_class( $key ), |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | 'class' => 'getpaid-address-field', |
| 269 | 269 | ), |
| 270 | 270 | true |
| 271 | - ); |
|
| 271 | + ); |
|
| 272 | 272 | |
| 273 | 273 | } |
| 274 | 274 | } |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | function getpaid_allowed_html() { |
| 408 | 408 | $allowed_html = wp_kses_allowed_html( 'post' ); |
| 409 | 409 | |
| 410 | - // form fields |
|
| 410 | + // form fields |
|
| 411 | 411 | $allowed_html['form'] = array( |
| 412 | 412 | 'action' => true, |
| 413 | 413 | 'accept' => true, |
@@ -419,12 +419,12 @@ discard block |
||
| 419 | 419 | ); |
| 420 | 420 | |
| 421 | 421 | // - input |
| 422 | - $allowed_html['input'] = array( |
|
| 423 | - 'class' => array(), |
|
| 424 | - 'id' => array(), |
|
| 425 | - 'name' => array(), |
|
| 426 | - 'value' => array(), |
|
| 427 | - 'type' => array(), |
|
| 422 | + $allowed_html['input'] = array( |
|
| 423 | + 'class' => array(), |
|
| 424 | + 'id' => array(), |
|
| 425 | + 'name' => array(), |
|
| 426 | + 'value' => array(), |
|
| 427 | + 'type' => array(), |
|
| 428 | 428 | 'placeholder' => array(), |
| 429 | 429 | 'autocomplete' => array(), |
| 430 | 430 | 'autofocus' => array(), |
@@ -438,33 +438,33 @@ discard block |
||
| 438 | 438 | 'max' => array(), |
| 439 | 439 | 'step' => array(), |
| 440 | 440 | 'size' => array(), |
| 441 | - ); |
|
| 441 | + ); |
|
| 442 | 442 | |
| 443 | 443 | // - input |
| 444 | - $allowed_html['textarea'] = array( |
|
| 445 | - 'class' => array(), |
|
| 446 | - 'id' => array(), |
|
| 447 | - 'name' => array(), |
|
| 448 | - 'value' => array(), |
|
| 449 | - ); |
|
| 450 | - |
|
| 451 | - // select |
|
| 452 | - $allowed_html['select'] = array( |
|
| 453 | - 'class' => array(), |
|
| 454 | - 'id' => array(), |
|
| 455 | - 'name' => array(), |
|
| 444 | + $allowed_html['textarea'] = array( |
|
| 445 | + 'class' => array(), |
|
| 446 | + 'id' => array(), |
|
| 447 | + 'name' => array(), |
|
| 448 | + 'value' => array(), |
|
| 449 | + ); |
|
| 450 | + |
|
| 451 | + // select |
|
| 452 | + $allowed_html['select'] = array( |
|
| 453 | + 'class' => array(), |
|
| 454 | + 'id' => array(), |
|
| 455 | + 'name' => array(), |
|
| 456 | 456 | 'autocomplete' => array(), |
| 457 | 457 | 'multiple' => array(), |
| 458 | - ); |
|
| 458 | + ); |
|
| 459 | 459 | |
| 460 | - // select options |
|
| 461 | - $allowed_html['option'] = array( |
|
| 462 | - 'selected' => array(), |
|
| 460 | + // select options |
|
| 461 | + $allowed_html['option'] = array( |
|
| 462 | + 'selected' => array(), |
|
| 463 | 463 | 'disabled' => array(), |
| 464 | 464 | 'value' => array(), |
| 465 | - ); |
|
| 465 | + ); |
|
| 466 | 466 | |
| 467 | - return $allowed_html; |
|
| 467 | + return $allowed_html; |
|
| 468 | 468 | |
| 469 | 469 | } |
| 470 | 470 | |
@@ -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,31 +115,31 @@ discard block |
||
| 115 | 115 | $tabs = array( |
| 116 | 116 | |
| 117 | 117 | 'gp-invoices' => array( |
| 118 | - 'label' => __( 'Invoices', 'invoicing' ), // Name of the tab. |
|
| 118 | + 'label' => __('Invoices', 'invoicing'), // Name of the tab. |
|
| 119 | 119 | 'content' => '[wpinv_history]', // Content of the tab. Or specify "callback" to provide a callback instead. |
| 120 | 120 | 'icon' => 'fas fa-file-invoice', // Shown on some profile plugins. |
| 121 | 121 | ), |
| 122 | 122 | |
| 123 | 123 | 'gp-subscriptions' => array( |
| 124 | - 'label' => __( 'Subscriptions', 'invoicing' ), |
|
| 124 | + 'label' => __('Subscriptions', 'invoicing'), |
|
| 125 | 125 | 'content' => '[wpinv_subscriptions]', |
| 126 | 126 | 'icon' => 'fas fa-redo', |
| 127 | 127 | ), |
| 128 | 128 | |
| 129 | 129 | 'gp-edit-address' => array( |
| 130 | - 'label' => __( 'Billing Address', 'invoicing' ), |
|
| 130 | + 'label' => __('Billing Address', 'invoicing'), |
|
| 131 | 131 | 'callback' => 'getpaid_display_address_edit_tab', |
| 132 | 132 | 'icon' => 'fas fa-credit-card', |
| 133 | 133 | ), |
| 134 | 134 | |
| 135 | 135 | ); |
| 136 | 136 | |
| 137 | - $tabs = apply_filters( 'getpaid_user_content_tabs', $tabs ); |
|
| 137 | + $tabs = apply_filters('getpaid_user_content_tabs', $tabs); |
|
| 138 | 138 | |
| 139 | 139 | // Make sure address editing is last on the list. |
| 140 | - if ( isset( $tabs['gp-edit-address'] ) ) { |
|
| 140 | + if (isset($tabs['gp-edit-address'])) { |
|
| 141 | 141 | $address = $tabs['gp-edit-address']; |
| 142 | - unset( $tabs['gp-edit-address'] ); |
|
| 142 | + unset($tabs['gp-edit-address']); |
|
| 143 | 143 | $tabs['gp-edit-address'] = $address; |
| 144 | 144 | } |
| 145 | 145 | |
@@ -153,19 +153,19 @@ discard block |
||
| 153 | 153 | * @param array $tab |
| 154 | 154 | * @return array |
| 155 | 155 | */ |
| 156 | -function getpaid_prepare_user_content_tab( $tab ) { |
|
| 156 | +function getpaid_prepare_user_content_tab($tab) { |
|
| 157 | 157 | |
| 158 | - if ( ! empty( $tab['callback'] ) ) { |
|
| 159 | - return call_user_func( $tab['callback'] ); |
|
| 158 | + if (!empty($tab['callback'])) { |
|
| 159 | + return call_user_func($tab['callback']); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - if ( ! empty( $tab['content'] ) ) { |
|
| 163 | - return convert_smilies( capital_P_dangit( wp_filter_content_tags( do_shortcode( shortcode_unautop( wpautop( wptexturize( do_blocks( $tab['content'] ) ) ) ) ) ) ) ); |
|
| 162 | + if (!empty($tab['content'])) { |
|
| 163 | + return convert_smilies(capital_P_dangit(wp_filter_content_tags(do_shortcode(shortcode_unautop(wpautop(wptexturize(do_blocks($tab['content'])))))))); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | $notice = aui()->alert( |
| 167 | 167 | array( |
| 168 | - 'content' => __( 'This tab has no content or content callback.', 'invoicing' ), |
|
| 168 | + 'content' => __('This tab has no content or content callback.', 'invoicing'), |
|
| 169 | 169 | 'type' => 'error', |
| 170 | 170 | ) |
| 171 | 171 | ); |
@@ -181,14 +181,14 @@ discard block |
||
| 181 | 181 | * @param string $default |
| 182 | 182 | * @return array |
| 183 | 183 | */ |
| 184 | -function getpaid_get_tab_url( $tab, $default ) { |
|
| 184 | +function getpaid_get_tab_url($tab, $default) { |
|
| 185 | 185 | global $getpaid_tab_url; |
| 186 | 186 | |
| 187 | - if ( empty( $getpaid_tab_url ) ) { |
|
| 187 | + if (empty($getpaid_tab_url)) { |
|
| 188 | 188 | return $default; |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - return sprintf( $getpaid_tab_url, $tab ); |
|
| 191 | + return sprintf($getpaid_tab_url, $tab); |
|
| 192 | 192 | |
| 193 | 193 | } |
| 194 | 194 | |
@@ -200,11 +200,11 @@ discard block |
||
| 200 | 200 | */ |
| 201 | 201 | function getpaid_display_address_edit_tab() { |
| 202 | 202 | |
| 203 | - if ( 0 === get_current_user_id() ) { |
|
| 203 | + if (0 === get_current_user_id()) { |
|
| 204 | 204 | return '<div class="bsui">' . aui()->alert( |
| 205 | 205 | array( |
| 206 | 206 | 'type' => 'error', |
| 207 | - 'content' => __( 'Your must be logged in to view this section', 'invoicing' ), |
|
| 207 | + 'content' => __('Your must be logged in to view this section', 'invoicing'), |
|
| 208 | 208 | 'dismissible' => false, |
| 209 | 209 | ) |
| 210 | 210 | ) . '</div>'; |
@@ -218,19 +218,19 @@ discard block |
||
| 218 | 218 | |
| 219 | 219 | <?php |
| 220 | 220 | |
| 221 | - foreach ( getpaid_user_address_fields() as $key => $label ) { |
|
| 221 | + foreach (getpaid_user_address_fields() as $key => $label) { |
|
| 222 | 222 | |
| 223 | 223 | // Display the country. |
| 224 | - if ( 'country' == $key ) { |
|
| 224 | + if ('country' == $key) { |
|
| 225 | 225 | |
| 226 | 226 | aui()->select( |
| 227 | 227 | array( |
| 228 | 228 | 'options' => wpinv_get_country_list(), |
| 229 | - 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
|
| 230 | - 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
| 231 | - 'value' => sanitize_text_field( getpaid_get_user_address_field( get_current_user_id(), $key ) ), |
|
| 229 | + 'name' => 'getpaid_address[' . esc_attr($key) . ']', |
|
| 230 | + 'id' => 'wpinv-' . sanitize_html_class($key), |
|
| 231 | + 'value' => sanitize_text_field(getpaid_get_user_address_field(get_current_user_id(), $key)), |
|
| 232 | 232 | 'placeholder' => $label, |
| 233 | - 'label' => wp_kses_post( $label ), |
|
| 233 | + 'label' => wp_kses_post($label), |
|
| 234 | 234 | 'label_type' => 'vertical', |
| 235 | 235 | 'class' => 'getpaid-address-field', |
| 236 | 236 | ), |
@@ -240,17 +240,17 @@ discard block |
||
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | // Display the state. |
| 243 | - elseif ( 'state' == $key ) { |
|
| 243 | + elseif ('state' == $key) { |
|
| 244 | 244 | |
| 245 | 245 | getpaid_get_states_select_markup( |
| 246 | - getpaid_get_user_address_field( get_current_user_id(), 'country' ), |
|
| 247 | - getpaid_get_user_address_field( get_current_user_id(), 'state' ), |
|
| 246 | + getpaid_get_user_address_field(get_current_user_id(), 'country'), |
|
| 247 | + getpaid_get_user_address_field(get_current_user_id(), 'state'), |
|
| 248 | 248 | $label, |
| 249 | 249 | $label, |
| 250 | 250 | '', |
| 251 | 251 | false, |
| 252 | 252 | '', |
| 253 | - 'getpaid_address[' . esc_attr( $key ) . ']', |
|
| 253 | + 'getpaid_address[' . esc_attr($key) . ']', |
|
| 254 | 254 | true |
| 255 | 255 | ); |
| 256 | 256 | |
@@ -258,13 +258,13 @@ discard block |
||
| 258 | 258 | |
| 259 | 259 | aui()->input( |
| 260 | 260 | array( |
| 261 | - 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
|
| 262 | - 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
| 261 | + 'name' => 'getpaid_address[' . esc_attr($key) . ']', |
|
| 262 | + 'id' => 'wpinv-' . sanitize_html_class($key), |
|
| 263 | 263 | 'placeholder' => $label, |
| 264 | - 'label' => wp_kses_post( $label ), |
|
| 264 | + 'label' => wp_kses_post($label), |
|
| 265 | 265 | 'label_type' => 'vertical', |
| 266 | 266 | 'type' => 'text', |
| 267 | - 'value' => sanitize_text_field( getpaid_get_user_address_field( get_current_user_id(), $key ) ), |
|
| 267 | + 'value' => sanitize_text_field(getpaid_get_user_address_field(get_current_user_id(), $key)), |
|
| 268 | 268 | 'class' => 'getpaid-address-field', |
| 269 | 269 | ), |
| 270 | 270 | true |
@@ -278,32 +278,32 @@ discard block |
||
| 278 | 278 | 'name' => 'getpaid_address[email_cc]', |
| 279 | 279 | 'id' => 'wpinv-email_cc', |
| 280 | 280 | 'placeholder' => '[email protected], [email protected]', |
| 281 | - 'label' => __( 'Other email addresses', 'invoicing' ), |
|
| 281 | + 'label' => __('Other email addresses', 'invoicing'), |
|
| 282 | 282 | 'label_type' => 'vertical', |
| 283 | 283 | 'type' => 'text', |
| 284 | - 'value' => sanitize_text_field( get_user_meta( get_current_user_id(), '_wpinv_email_cc', true ) ), |
|
| 284 | + 'value' => sanitize_text_field(get_user_meta(get_current_user_id(), '_wpinv_email_cc', true)), |
|
| 285 | 285 | 'class' => 'getpaid-address-field', |
| 286 | - 'help_text' => __( 'Optionally provide other email addresses where we should send payment notifications', 'invoicing' ), |
|
| 286 | + 'help_text' => __('Optionally provide other email addresses where we should send payment notifications', 'invoicing'), |
|
| 287 | 287 | ), |
| 288 | 288 | true |
| 289 | 289 | ); |
| 290 | 290 | |
| 291 | - do_action( 'getpaid_display_address_edit_tab' ); |
|
| 291 | + do_action('getpaid_display_address_edit_tab'); |
|
| 292 | 292 | |
| 293 | 293 | aui()->input( |
| 294 | 294 | array( |
| 295 | 295 | 'name' => 'getpaid_profile_edit_submit_button', |
| 296 | 296 | 'id' => 'getpaid_profile_edit_submit_button', |
| 297 | - 'value' => __( 'Save Address', 'invoicing' ), |
|
| 298 | - 'help_text' => __( 'New invoices will use this address as the billing address.', 'invoicing' ), |
|
| 297 | + 'value' => __('Save Address', 'invoicing'), |
|
| 298 | + 'help_text' => __('New invoices will use this address as the billing address.', 'invoicing'), |
|
| 299 | 299 | 'type' => 'submit', |
| 300 | 300 | 'class' => 'btn btn-primary btn-block submit-button', |
| 301 | 301 | ), |
| 302 | 302 | true |
| 303 | 303 | ); |
| 304 | 304 | |
| 305 | - wp_nonce_field( 'getpaid-nonce', 'getpaid-nonce' ); |
|
| 306 | - getpaid_hidden_field( 'getpaid-action', 'edit_billing_details' ); |
|
| 305 | + wp_nonce_field('getpaid-nonce', 'getpaid-nonce'); |
|
| 306 | + getpaid_hidden_field('getpaid-action', 'edit_billing_details'); |
|
| 307 | 307 | ?> |
| 308 | 308 | |
| 309 | 309 | </form> |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | |
| 314 | 314 | return ob_get_clean(); |
| 315 | 315 | } |
| 316 | -add_shortcode( 'getpaid_edit_address', 'getpaid_display_address_edit_tab' ); |
|
| 316 | +add_shortcode('getpaid_edit_address', 'getpaid_display_address_edit_tab'); |
|
| 317 | 317 | |
| 318 | 318 | /** |
| 319 | 319 | * Saves the billing address edit tab. |
@@ -321,30 +321,30 @@ discard block |
||
| 321 | 321 | * @since 2.1.4 |
| 322 | 322 | * @param array $data |
| 323 | 323 | */ |
| 324 | -function getpaid_save_address_edit_tab( $data ) { |
|
| 324 | +function getpaid_save_address_edit_tab($data) { |
|
| 325 | 325 | |
| 326 | - if ( empty( $data['getpaid_address'] ) || ! is_array( $data['getpaid_address'] ) ) { |
|
| 326 | + if (empty($data['getpaid_address']) || !is_array($data['getpaid_address'])) { |
|
| 327 | 327 | return; |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | $data = $data['getpaid_address']; |
| 331 | 331 | $user_id = get_current_user_id(); |
| 332 | 332 | |
| 333 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
| 333 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
| 334 | 334 | |
| 335 | - if ( isset( $data[ $field ] ) ) { |
|
| 336 | - $value = sanitize_text_field( $data[ $field ] ); |
|
| 337 | - update_user_meta( $user_id, '_wpinv_' . $field, $value ); |
|
| 335 | + if (isset($data[$field])) { |
|
| 336 | + $value = sanitize_text_field($data[$field]); |
|
| 337 | + update_user_meta($user_id, '_wpinv_' . $field, $value); |
|
| 338 | 338 | } |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | - if ( isset( $data['email_cc'] ) ) { |
|
| 342 | - update_user_meta( $user_id, '_wpinv_email_cc', sanitize_text_field( $data['email_cc'] ) ); |
|
| 341 | + if (isset($data['email_cc'])) { |
|
| 342 | + update_user_meta($user_id, '_wpinv_email_cc', sanitize_text_field($data['email_cc'])); |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | - wpinv_set_error( 'address_updated' ); |
|
| 345 | + wpinv_set_error('address_updated'); |
|
| 346 | 346 | } |
| 347 | -add_action( 'getpaid_authenticated_action_edit_billing_details', 'getpaid_save_address_edit_tab' ); |
|
| 347 | +add_action('getpaid_authenticated_action_edit_billing_details', 'getpaid_save_address_edit_tab'); |
|
| 348 | 348 | |
| 349 | 349 | |
| 350 | 350 | /* |
@@ -362,27 +362,27 @@ discard block |
||
| 362 | 362 | * @param array $tabs |
| 363 | 363 | * @return array |
| 364 | 364 | */ |
| 365 | -function getpaid_filter_userswp_account_tabs( $tabs ) { |
|
| 365 | +function getpaid_filter_userswp_account_tabs($tabs) { |
|
| 366 | 366 | |
| 367 | 367 | // Abort if the integration is inactive. |
| 368 | - if ( ! getpaid_is_userswp_integration_active() ) { |
|
| 368 | + if (!getpaid_is_userswp_integration_active()) { |
|
| 369 | 369 | return $tabs; |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | - $new_tabs = array(); |
|
| 372 | + $new_tabs = array(); |
|
| 373 | 373 | |
| 374 | - foreach ( getpaid_get_user_content_tabs() as $slug => $tab ) { |
|
| 374 | + foreach (getpaid_get_user_content_tabs() as $slug => $tab) { |
|
| 375 | 375 | |
| 376 | - $new_tabs[ $slug ] = array( |
|
| 376 | + $new_tabs[$slug] = array( |
|
| 377 | 377 | 'title' => $tab['label'], |
| 378 | 378 | 'icon' => $tab['icon'], |
| 379 | 379 | ); |
| 380 | 380 | |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | - return array_merge( $tabs, $new_tabs ); |
|
| 383 | + return array_merge($tabs, $new_tabs); |
|
| 384 | 384 | } |
| 385 | -add_filter( 'uwp_account_available_tabs', 'getpaid_filter_userswp_account_tabs' ); |
|
| 385 | +add_filter('uwp_account_available_tabs', 'getpaid_filter_userswp_account_tabs'); |
|
| 386 | 386 | |
| 387 | 387 | /** |
| 388 | 388 | * Display our UsersWP account tabs. |
@@ -391,21 +391,21 @@ discard block |
||
| 391 | 391 | * @param array $tabs |
| 392 | 392 | * @return array |
| 393 | 393 | */ |
| 394 | -function getpaid_display_userswp_account_tabs( $tab ) { |
|
| 394 | +function getpaid_display_userswp_account_tabs($tab) { |
|
| 395 | 395 | global $getpaid_tab_url; |
| 396 | 396 | |
| 397 | 397 | $our_tabs = getpaid_get_user_content_tabs(); |
| 398 | 398 | |
| 399 | - if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) { |
|
| 400 | - $getpaid_tab_url = add_query_arg( 'type', '%s', uwp_get_account_page_url() ); |
|
| 401 | - echo wp_kses( getpaid_prepare_user_content_tab( $our_tabs[ $tab ] ), getpaid_allowed_html() ); |
|
| 399 | + if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) { |
|
| 400 | + $getpaid_tab_url = add_query_arg('type', '%s', uwp_get_account_page_url()); |
|
| 401 | + echo wp_kses(getpaid_prepare_user_content_tab($our_tabs[$tab]), getpaid_allowed_html()); |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | } |
| 405 | -add_action( 'uwp_account_form_display', 'getpaid_display_userswp_account_tabs' ); |
|
| 405 | +add_action('uwp_account_form_display', 'getpaid_display_userswp_account_tabs'); |
|
| 406 | 406 | |
| 407 | 407 | function getpaid_allowed_html() { |
| 408 | - $allowed_html = wp_kses_allowed_html( 'post' ); |
|
| 408 | + $allowed_html = wp_kses_allowed_html('post'); |
|
| 409 | 409 | |
| 410 | 410 | // form fields |
| 411 | 411 | $allowed_html['form'] = array( |
@@ -476,17 +476,17 @@ discard block |
||
| 476 | 476 | * @param string $tab Current tab. |
| 477 | 477 | * @return string Title. |
| 478 | 478 | */ |
| 479 | -function getpaid_filter_userswp_account_title( $title, $tab ) { |
|
| 479 | +function getpaid_filter_userswp_account_title($title, $tab) { |
|
| 480 | 480 | |
| 481 | - $our_tabs = getpaid_get_user_content_tabs(); |
|
| 481 | + $our_tabs = getpaid_get_user_content_tabs(); |
|
| 482 | 482 | |
| 483 | - if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) { |
|
| 484 | - return $our_tabs[ $tab ]['label']; |
|
| 483 | + if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) { |
|
| 484 | + return $our_tabs[$tab]['label']; |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | return $title; |
| 488 | 488 | } |
| 489 | -add_filter( 'uwp_account_page_title', 'getpaid_filter_userswp_account_title', 10, 2 ); |
|
| 489 | +add_filter('uwp_account_page_title', 'getpaid_filter_userswp_account_title', 10, 2); |
|
| 490 | 490 | |
| 491 | 491 | /** |
| 492 | 492 | * Registers the UsersWP integration settings. |
@@ -495,26 +495,26 @@ discard block |
||
| 495 | 495 | * @param array $settings An array of integration settings. |
| 496 | 496 | * @return array |
| 497 | 497 | */ |
| 498 | -function getpaid_register_userswp_settings( $settings ) { |
|
| 498 | +function getpaid_register_userswp_settings($settings) { |
|
| 499 | 499 | |
| 500 | - if ( defined( 'USERSWP_PLUGIN_FILE' ) ) { |
|
| 500 | + if (defined('USERSWP_PLUGIN_FILE')) { |
|
| 501 | 501 | |
| 502 | 502 | $settings[] = array( |
| 503 | 503 | |
| 504 | 504 | 'id' => 'userswp', |
| 505 | - 'label' => __( 'UsersWP', 'invoicing' ), |
|
| 505 | + 'label' => __('UsersWP', 'invoicing'), |
|
| 506 | 506 | 'settings' => array( |
| 507 | 507 | |
| 508 | 508 | 'userswp_settings' => array( |
| 509 | 509 | 'id' => 'userswp_settings', |
| 510 | - 'name' => '<h3>' . __( 'UsersWP', 'invoicing' ) . '</h3>', |
|
| 510 | + 'name' => '<h3>' . __('UsersWP', 'invoicing') . '</h3>', |
|
| 511 | 511 | 'type' => 'header', |
| 512 | 512 | ), |
| 513 | 513 | |
| 514 | 514 | 'enable_userswp' => array( |
| 515 | 515 | 'id' => 'enable_userswp', |
| 516 | - 'name' => __( 'Enable Integration', 'invoicing' ), |
|
| 517 | - 'desc' => __( 'Display GetPaid items on UsersWP account page.', 'invoicing' ), |
|
| 516 | + 'name' => __('Enable Integration', 'invoicing'), |
|
| 517 | + 'desc' => __('Display GetPaid items on UsersWP account page.', 'invoicing'), |
|
| 518 | 518 | 'type' => 'checkbox', |
| 519 | 519 | 'std' => 1, |
| 520 | 520 | ), |
@@ -527,7 +527,7 @@ discard block |
||
| 527 | 527 | |
| 528 | 528 | return $settings; |
| 529 | 529 | } |
| 530 | -add_filter( 'getpaid_integration_settings', 'getpaid_register_userswp_settings' ); |
|
| 530 | +add_filter('getpaid_integration_settings', 'getpaid_register_userswp_settings'); |
|
| 531 | 531 | |
| 532 | 532 | /** |
| 533 | 533 | * Ovewrites the invoices history page to UsersWP. |
@@ -535,18 +535,18 @@ discard block |
||
| 535 | 535 | * @since 2.3.1 |
| 536 | 536 | * @return bool |
| 537 | 537 | */ |
| 538 | -function getpaid_userswp_overwrite_invoice_history_page( $url, $post_type ) { |
|
| 538 | +function getpaid_userswp_overwrite_invoice_history_page($url, $post_type) { |
|
| 539 | 539 | |
| 540 | 540 | $our_tabs = getpaid_get_user_content_tabs(); |
| 541 | 541 | $tab = "gp-{$post_type}s"; |
| 542 | - if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) { |
|
| 543 | - return add_query_arg( 'type', $tab, uwp_get_account_page_url() ); |
|
| 542 | + if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) { |
|
| 543 | + return add_query_arg('type', $tab, uwp_get_account_page_url()); |
|
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | return $url; |
| 547 | 547 | |
| 548 | 548 | } |
| 549 | -add_filter( 'wpinv_get_history_page_uri', 'getpaid_userswp_overwrite_invoice_history_page', 10, 2 ); |
|
| 549 | +add_filter('wpinv_get_history_page_uri', 'getpaid_userswp_overwrite_invoice_history_page', 10, 2); |
|
| 550 | 550 | |
| 551 | 551 | /** |
| 552 | 552 | * Checks if the integration is enabled. |
@@ -555,8 +555,8 @@ discard block |
||
| 555 | 555 | * @return bool |
| 556 | 556 | */ |
| 557 | 557 | function getpaid_is_userswp_integration_active() { |
| 558 | - $enabled = wpinv_get_option( 'enable_userswp', 1 ); |
|
| 559 | - return defined( 'USERSWP_PLUGIN_FILE' ) && ! empty( $enabled ); |
|
| 558 | + $enabled = wpinv_get_option('enable_userswp', 1); |
|
| 559 | + return defined('USERSWP_PLUGIN_FILE') && !empty($enabled); |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | /* |
@@ -574,26 +574,26 @@ discard block |
||
| 574 | 574 | * @param array $settings An array of integration settings. |
| 575 | 575 | * @return array |
| 576 | 576 | */ |
| 577 | -function getpaid_register_buddypress_settings( $settings ) { |
|
| 577 | +function getpaid_register_buddypress_settings($settings) { |
|
| 578 | 578 | |
| 579 | - if ( class_exists( 'BuddyPress' ) ) { |
|
| 579 | + if (class_exists('BuddyPress')) { |
|
| 580 | 580 | |
| 581 | 581 | $settings[] = array( |
| 582 | 582 | |
| 583 | 583 | 'id' => 'buddypress', |
| 584 | - 'label' => __( 'BuddyPress', 'invoicing' ), |
|
| 584 | + 'label' => __('BuddyPress', 'invoicing'), |
|
| 585 | 585 | 'settings' => array( |
| 586 | 586 | |
| 587 | 587 | 'buddypress_settings' => array( |
| 588 | 588 | 'id' => 'buddypress_settings', |
| 589 | - 'name' => '<h3>' . __( 'BuddyPress', 'invoicing' ) . '</h3>', |
|
| 589 | + 'name' => '<h3>' . __('BuddyPress', 'invoicing') . '</h3>', |
|
| 590 | 590 | 'type' => 'header', |
| 591 | 591 | ), |
| 592 | 592 | |
| 593 | 593 | 'enable_buddypress' => array( |
| 594 | 594 | 'id' => 'enable_buddypress', |
| 595 | - 'name' => __( 'Enable Integration', 'invoicing' ), |
|
| 596 | - 'desc' => __( 'Display GetPaid items on BuddyPress account pages.', 'invoicing' ), |
|
| 595 | + 'name' => __('Enable Integration', 'invoicing'), |
|
| 596 | + 'desc' => __('Display GetPaid items on BuddyPress account pages.', 'invoicing'), |
|
| 597 | 597 | 'type' => 'checkbox', |
| 598 | 598 | 'std' => 1, |
| 599 | 599 | ), |
@@ -606,7 +606,7 @@ discard block |
||
| 606 | 606 | |
| 607 | 607 | return $settings; |
| 608 | 608 | } |
| 609 | -add_filter( 'getpaid_integration_settings', 'getpaid_register_buddypress_settings' ); |
|
| 609 | +add_filter('getpaid_integration_settings', 'getpaid_register_buddypress_settings'); |
|
| 610 | 610 | |
| 611 | 611 | /** |
| 612 | 612 | * Checks if the integration is enabled. |
@@ -615,8 +615,8 @@ discard block |
||
| 615 | 615 | * @return bool |
| 616 | 616 | */ |
| 617 | 617 | function getpaid_is_buddypress_integration_active() { |
| 618 | - $enabled = wpinv_get_option( 'enable_buddypress', 1 ); |
|
| 619 | - return class_exists( 'BuddyPress' ) && ! empty( $enabled ); |
|
| 618 | + $enabled = wpinv_get_option('enable_buddypress', 1); |
|
| 619 | + return class_exists('BuddyPress') && !empty($enabled); |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | /** |
@@ -627,13 +627,13 @@ discard block |
||
| 627 | 627 | */ |
| 628 | 628 | function getpaid_setup_buddypress_integration() { |
| 629 | 629 | |
| 630 | - if ( getpaid_is_buddypress_integration_active() ) { |
|
| 630 | + if (getpaid_is_buddypress_integration_active()) { |
|
| 631 | 631 | require_once WPINV_PLUGIN_DIR . 'includes/class-bp-getpaid-component.php'; |
| 632 | 632 | buddypress()->getpaid = new BP_GetPaid_Component(); |
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | } |
| 636 | -add_action( 'bp_setup_components', 'getpaid_setup_buddypress_integration' ); |
|
| 636 | +add_action('bp_setup_components', 'getpaid_setup_buddypress_integration'); |
|
| 637 | 637 | |
| 638 | 638 | /** |
| 639 | 639 | * Checks if a given user has purchased a given item. |
@@ -641,10 +641,10 @@ discard block |
||
| 641 | 641 | * @since 2.6.17 |
| 642 | 642 | * @param int $user_id The user id. |
| 643 | 643 | */ |
| 644 | -function getpaid_has_user_purchased_item( $user_id, $item_id ) { |
|
| 644 | +function getpaid_has_user_purchased_item($user_id, $item_id) { |
|
| 645 | 645 | global $wpdb; |
| 646 | 646 | |
| 647 | - if ( empty( $user_id ) ) { |
|
| 647 | + if (empty($user_id)) { |
|
| 648 | 648 | return false; |
| 649 | 649 | } |
| 650 | 650 | |
@@ -659,5 +659,5 @@ discard block |
||
| 659 | 659 | ) |
| 660 | 660 | ); |
| 661 | 661 | |
| 662 | - return ! empty( $count ); |
|
| 662 | + return !empty($count); |
|
| 663 | 663 | } |
@@ -1,32 +1,32 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - // Is the request set up correctly? |
|
| 4 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
| 5 | - return aui()->alert( |
|
| 6 | - array( |
|
| 7 | - 'type' => 'warning', |
|
| 8 | - 'content' => __( 'No payment form or item selected', 'invoicing' ), |
|
| 9 | - ) |
|
| 10 | - ); |
|
| 11 | - wp_die( esc_html__( 'No payment form or item selected', 'invoicing' ), 400 ); |
|
| 12 | - } |
|
| 13 | - |
|
| 14 | - // Payment form or button? |
|
| 15 | - if ( ! empty( $_GET['form'] ) ) { |
|
| 16 | - |
|
| 17 | - $shortcode = sprintf( |
|
| 18 | - '[getpaid form=%s]', |
|
| 19 | - (int) $_GET['form'] |
|
| 20 | - ); |
|
| 21 | - |
|
| 22 | - } else { |
|
| 23 | - |
|
| 24 | - $shortcode = sprintf( |
|
| 25 | - '[getpaid item=%s]', |
|
| 26 | - esc_attr( urldecode( $_GET['item'] ) ) |
|
| 27 | - ); |
|
| 28 | - |
|
| 29 | - } |
|
| 3 | + // Is the request set up correctly? |
|
| 4 | + if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
| 5 | + return aui()->alert( |
|
| 6 | + array( |
|
| 7 | + 'type' => 'warning', |
|
| 8 | + 'content' => __( 'No payment form or item selected', 'invoicing' ), |
|
| 9 | + ) |
|
| 10 | + ); |
|
| 11 | + wp_die( esc_html__( 'No payment form or item selected', 'invoicing' ), 400 ); |
|
| 12 | + } |
|
| 13 | + |
|
| 14 | + // Payment form or button? |
|
| 15 | + if ( ! empty( $_GET['form'] ) ) { |
|
| 16 | + |
|
| 17 | + $shortcode = sprintf( |
|
| 18 | + '[getpaid form=%s]', |
|
| 19 | + (int) $_GET['form'] |
|
| 20 | + ); |
|
| 21 | + |
|
| 22 | + } else { |
|
| 23 | + |
|
| 24 | + $shortcode = sprintf( |
|
| 25 | + '[getpaid item=%s]', |
|
| 26 | + esc_attr( urldecode( $_GET['item'] ) ) |
|
| 27 | + ); |
|
| 28 | + |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | 31 | ?> |
| 32 | 32 | |
@@ -44,13 +44,13 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | <title><?php echo esc_html( get_bloginfo( 'name' ) ); ?></title> |
| 46 | 46 | <?php |
| 47 | - wp_enqueue_scripts(); |
|
| 48 | - wp_print_styles(); |
|
| 49 | - wp_print_head_scripts(); |
|
| 50 | - wp_custom_css_cb(); |
|
| 51 | - wpinv_get_template( 'frontend-head.php' ); |
|
| 52 | - wp_site_icon(); |
|
| 53 | - ?> |
|
| 47 | + wp_enqueue_scripts(); |
|
| 48 | + wp_print_styles(); |
|
| 49 | + wp_print_head_scripts(); |
|
| 50 | + wp_custom_css_cb(); |
|
| 51 | + wpinv_get_template( 'frontend-head.php' ); |
|
| 52 | + wp_site_icon(); |
|
| 53 | + ?> |
|
| 54 | 54 | |
| 55 | 55 | <style type="text/css"> |
| 56 | 56 | .body{ |
@@ -84,11 +84,11 @@ discard block |
||
| 84 | 84 | <body class="body page-template-default page"> |
| 85 | 85 | <div id="getpaid-form-embed" class="container my-5 page type-page status-publish hentry post post-content"> |
| 86 | 86 | <?php |
| 87 | - do_action( 'getpaid_payment_form_embed_top' ); |
|
| 88 | - echo do_shortcode( $shortcode ); |
|
| 89 | - do_action( 'getpaid_payment_form_embed_bottom' ); |
|
| 90 | - wpinv_get_template( 'frontend-footer.php' ); |
|
| 91 | - ?> |
|
| 87 | + do_action( 'getpaid_payment_form_embed_top' ); |
|
| 88 | + echo do_shortcode( $shortcode ); |
|
| 89 | + do_action( 'getpaid_payment_form_embed_bottom' ); |
|
| 90 | + wpinv_get_template( 'frontend-footer.php' ); |
|
| 91 | + ?> |
|
| 92 | 92 | </div> |
| 93 | 93 | <?php wp_footer(); ?> |
| 94 | 94 | </body> |
@@ -1,18 +1,18 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | // Is the request set up correctly? |
| 4 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
| 4 | + if (empty($_GET['form']) && empty($_GET['item'])) { |
|
| 5 | 5 | return aui()->alert( |
| 6 | 6 | array( |
| 7 | 7 | 'type' => 'warning', |
| 8 | - 'content' => __( 'No payment form or item selected', 'invoicing' ), |
|
| 8 | + 'content' => __('No payment form or item selected', 'invoicing'), |
|
| 9 | 9 | ) |
| 10 | 10 | ); |
| 11 | - wp_die( esc_html__( 'No payment form or item selected', 'invoicing' ), 400 ); |
|
| 11 | + wp_die(esc_html__('No payment form or item selected', 'invoicing'), 400); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | // Payment form or button? |
| 15 | - if ( ! empty( $_GET['form'] ) ) { |
|
| 15 | + if (!empty($_GET['form'])) { |
|
| 16 | 16 | |
| 17 | 17 | $shortcode = sprintf( |
| 18 | 18 | '[getpaid form=%s]', |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | $shortcode = sprintf( |
| 25 | 25 | '[getpaid item=%s]', |
| 26 | - esc_attr( urldecode( $_GET['item'] ) ) |
|
| 26 | + esc_attr(urldecode($_GET['item'])) |
|
| 27 | 27 | ); |
| 28 | 28 | |
| 29 | 29 | } |
@@ -35,20 +35,20 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | <head> |
| 37 | 37 | |
| 38 | - <meta charset="<?php bloginfo( 'charset' ); ?>"> |
|
| 38 | + <meta charset="<?php bloginfo('charset'); ?>"> |
|
| 39 | 39 | <meta name="viewport" content="width=device-width, initial-scale=1.0" > |
| 40 | 40 | |
| 41 | 41 | <meta name="robots" content="noindex,nofollow"> |
| 42 | 42 | |
| 43 | 43 | <link rel="profile" href="https://gmpg.org/xfn/11"> |
| 44 | 44 | |
| 45 | - <title><?php echo esc_html( get_bloginfo( 'name' ) ); ?></title> |
|
| 45 | + <title><?php echo esc_html(get_bloginfo('name')); ?></title> |
|
| 46 | 46 | <?php |
| 47 | 47 | wp_enqueue_scripts(); |
| 48 | 48 | wp_print_styles(); |
| 49 | 49 | wp_print_head_scripts(); |
| 50 | 50 | wp_custom_css_cb(); |
| 51 | - wpinv_get_template( 'frontend-head.php' ); |
|
| 51 | + wpinv_get_template('frontend-head.php'); |
|
| 52 | 52 | wp_site_icon(); |
| 53 | 53 | ?> |
| 54 | 54 | |
@@ -84,10 +84,10 @@ discard block |
||
| 84 | 84 | <body class="body page-template-default page"> |
| 85 | 85 | <div id="getpaid-form-embed" class="container my-5 page type-page status-publish hentry post post-content"> |
| 86 | 86 | <?php |
| 87 | - do_action( 'getpaid_payment_form_embed_top' ); |
|
| 88 | - echo do_shortcode( $shortcode ); |
|
| 89 | - do_action( 'getpaid_payment_form_embed_bottom' ); |
|
| 90 | - wpinv_get_template( 'frontend-footer.php' ); |
|
| 87 | + do_action('getpaid_payment_form_embed_top'); |
|
| 88 | + echo do_shortcode($shortcode); |
|
| 89 | + do_action('getpaid_payment_form_embed_bottom'); |
|
| 90 | + wpinv_get_template('frontend-footer.php'); |
|
| 91 | 91 | ?> |
| 92 | 92 | </div> |
| 93 | 93 | <?php wp_footer(); ?> |
@@ -13,30 +13,30 @@ discard block |
||
| 13 | 13 | class GetPaid_Manual_Gateway extends GetPaid_Payment_Gateway { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Payment method id. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 16 | + * Payment method id. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | 20 | public $id = 'manual'; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * An array of features that this gateway supports. |
|
| 24 | - * |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 23 | + * An array of features that this gateway supports. |
|
| 24 | + * |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | 27 | protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Payment method order. |
|
| 31 | - * |
|
| 32 | - * @var int |
|
| 33 | - */ |
|
| 34 | - public $order = 11; |
|
| 30 | + * Payment method order. |
|
| 31 | + * |
|
| 32 | + * @var int |
|
| 33 | + */ |
|
| 34 | + public $order = 11; |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | - * Class constructor. |
|
| 38 | - */ |
|
| 39 | - public function __construct() { |
|
| 37 | + * Class constructor. |
|
| 38 | + */ |
|
| 39 | + public function __construct() { |
|
| 40 | 40 | parent::__construct(); |
| 41 | 41 | |
| 42 | 42 | $this->title = __( 'Test Gateway', 'invoicing' ); |
@@ -46,15 +46,15 @@ discard block |
||
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | - * Process Payment. |
|
| 50 | - * |
|
| 51 | - * |
|
| 52 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 53 | - * @param array $submission_data Posted checkout fields. |
|
| 54 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 55 | - * @return array |
|
| 56 | - */ |
|
| 57 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 49 | + * Process Payment. |
|
| 50 | + * |
|
| 51 | + * |
|
| 52 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 53 | + * @param array $submission_data Posted checkout fields. |
|
| 54 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 55 | + * @return array |
|
| 56 | + */ |
|
| 57 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 58 | 58 | |
| 59 | 59 | // Mark it as paid. |
| 60 | 60 | $invoice->mark_paid(); |
@@ -84,12 +84,12 @@ discard block |
||
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
| 87 | - * (Maybe) renews a manual subscription profile. |
|
| 88 | - * |
|
| 89 | - * |
|
| 87 | + * (Maybe) renews a manual subscription profile. |
|
| 88 | + * |
|
| 89 | + * |
|
| 90 | 90 | * @param WPInv_Subscription $subscription |
| 91 | - */ |
|
| 92 | - public function maybe_renew_subscription( $subscription ) { |
|
| 91 | + */ |
|
| 92 | + public function maybe_renew_subscription( $subscription ) { |
|
| 93 | 93 | |
| 94 | 94 | // Ensure its our subscription && it's active. |
| 95 | 95 | if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
@@ -109,13 +109,13 @@ discard block |
||
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
| 112 | - * Processes invoice addons. |
|
| 113 | - * |
|
| 114 | - * @param WPInv_Invoice $invoice |
|
| 115 | - * @param GetPaid_Form_Item[] $items |
|
| 116 | - * @return WPInv_Invoice |
|
| 117 | - */ |
|
| 118 | - public function process_addons( $invoice, $items ) { |
|
| 112 | + * Processes invoice addons. |
|
| 113 | + * |
|
| 114 | + * @param WPInv_Invoice $invoice |
|
| 115 | + * @param GetPaid_Form_Item[] $items |
|
| 116 | + * @return WPInv_Invoice |
|
| 117 | + */ |
|
| 118 | + public function process_addons( $invoice, $items ) { |
|
| 119 | 119 | |
| 120 | 120 | foreach ( $items as $item ) { |
| 121 | 121 | $invoice->add_item( $item ); |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Manual Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @var array |
| 26 | 26 | */ |
| 27 | - protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
| 27 | + protected $supports = array('subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups'); |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Payment method order. |
@@ -39,10 +39,10 @@ discard block |
||
| 39 | 39 | public function __construct() { |
| 40 | 40 | parent::__construct(); |
| 41 | 41 | |
| 42 | - $this->title = __( 'Test Gateway', 'invoicing' ); |
|
| 43 | - $this->method_title = __( 'Test Gateway', 'invoicing' ); |
|
| 42 | + $this->title = __('Test Gateway', 'invoicing'); |
|
| 43 | + $this->method_title = __('Test Gateway', 'invoicing'); |
|
| 44 | 44 | |
| 45 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
| 45 | + add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription')); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -54,32 +54,32 @@ discard block |
||
| 54 | 54 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
| 55 | 55 | * @return array |
| 56 | 56 | */ |
| 57 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 57 | + public function process_payment($invoice, $submission_data, $submission) { |
|
| 58 | 58 | |
| 59 | 59 | // Mark it as paid. |
| 60 | 60 | $invoice->mark_paid(); |
| 61 | 61 | |
| 62 | 62 | // (Maybe) activate subscriptions. |
| 63 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 63 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
| 64 | 64 | |
| 65 | - if ( ! empty( $subscriptions ) ) { |
|
| 66 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
| 65 | + if (!empty($subscriptions)) { |
|
| 66 | + $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
| 67 | 67 | |
| 68 | - foreach ( $subscriptions as $subscription ) { |
|
| 69 | - if ( $subscription->exists() ) { |
|
| 70 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
| 71 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
| 68 | + foreach ($subscriptions as $subscription) { |
|
| 69 | + if ($subscription->exists()) { |
|
| 70 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
| 71 | + $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
| 72 | 72 | |
| 73 | - $subscription->set_next_renewal_date( $expiry ); |
|
| 74 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 75 | - $subscription->set_profile_id( $invoice->generate_key( 'manual_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) ); |
|
| 73 | + $subscription->set_next_renewal_date($expiry); |
|
| 74 | + $subscription->set_date_created(current_time('mysql')); |
|
| 75 | + $subscription->set_profile_id($invoice->generate_key('manual_sub_' . $invoice->get_id() . '_' . $subscription->get_id())); |
|
| 76 | 76 | $subscription->activate(); |
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | // Send to the success page. |
| 82 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 82 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
| 83 | 83 | |
| 84 | 84 | } |
| 85 | 85 | |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | * |
| 90 | 90 | * @param WPInv_Subscription $subscription |
| 91 | 91 | */ |
| 92 | - public function maybe_renew_subscription( $subscription ) { |
|
| 92 | + public function maybe_renew_subscription($subscription) { |
|
| 93 | 93 | |
| 94 | 94 | // Ensure its our subscription && it's active. |
| 95 | - if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
| 95 | + if ($this->id === $subscription->get_gateway() && $subscription->has_status('active trialling')) { |
|
| 96 | 96 | |
| 97 | 97 | // Renew the subscription. |
| 98 | 98 | $subscription->add_payment( |
@@ -115,10 +115,10 @@ discard block |
||
| 115 | 115 | * @param GetPaid_Form_Item[] $items |
| 116 | 116 | * @return WPInv_Invoice |
| 117 | 117 | */ |
| 118 | - public function process_addons( $invoice, $items ) { |
|
| 118 | + public function process_addons($invoice, $items) { |
|
| 119 | 119 | |
| 120 | - foreach ( $items as $item ) { |
|
| 121 | - $invoice->add_item( $item ); |
|
| 120 | + foreach ($items as $item) { |
|
| 121 | + $invoice->add_item($item); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | $invoice->recalculate_total(); |
@@ -13,311 +13,311 @@ |
||
| 13 | 13 | class GetPaid_Subscription_Notification_Emails { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * The array of subscription email actions. |
|
| 17 | - * |
|
| 18 | - * @param array |
|
| 19 | - */ |
|
| 20 | - public $subscription_actions; |
|
| 16 | + * The array of subscription email actions. |
|
| 17 | + * |
|
| 18 | + * @param array |
|
| 19 | + */ |
|
| 20 | + public $subscription_actions; |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * Class constructor |
|
| 23 | + * Class constructor |
|
| 24 | 24 | * |
| 25 | - */ |
|
| 26 | - public function __construct() { |
|
| 27 | - |
|
| 28 | - $this->subscription_actions = apply_filters( |
|
| 29 | - 'getpaid_notification_email_subscription_triggers', |
|
| 30 | - array( |
|
| 31 | - 'getpaid_subscription_trialling' => 'subscription_trial', |
|
| 32 | - 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
| 33 | - 'getpaid_subscription_expired' => 'subscription_expired', |
|
| 34 | - 'getpaid_subscription_completed' => 'subscription_complete', |
|
| 35 | - 'getpaid_daily_maintenance' => 'renewal_reminder', |
|
| 36 | - ) |
|
| 37 | - ); |
|
| 38 | - |
|
| 39 | - $this->init_hooks(); |
|
| 25 | + */ |
|
| 26 | + public function __construct() { |
|
| 27 | + |
|
| 28 | + $this->subscription_actions = apply_filters( |
|
| 29 | + 'getpaid_notification_email_subscription_triggers', |
|
| 30 | + array( |
|
| 31 | + 'getpaid_subscription_trialling' => 'subscription_trial', |
|
| 32 | + 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
| 33 | + 'getpaid_subscription_expired' => 'subscription_expired', |
|
| 34 | + 'getpaid_subscription_completed' => 'subscription_complete', |
|
| 35 | + 'getpaid_daily_maintenance' => 'renewal_reminder', |
|
| 36 | + ) |
|
| 37 | + ); |
|
| 38 | + |
|
| 39 | + $this->init_hooks(); |
|
| 40 | 40 | |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | - * Registers email hooks. |
|
| 45 | - */ |
|
| 46 | - public function init_hooks() { |
|
| 47 | - |
|
| 48 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
| 49 | - foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
| 50 | - |
|
| 51 | - $email = new GetPaid_Notification_Email( $email_type ); |
|
| 52 | - |
|
| 53 | - if ( ! $email->is_active() ) { |
|
| 54 | - continue; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - if ( method_exists( $this, $email_type ) ) { |
|
| 58 | - add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
| 59 | - continue; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
| 63 | - |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Filters subscription merge tags. |
|
| 70 | - * |
|
| 71 | - * @param array $merge_tags |
|
| 72 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
| 73 | - */ |
|
| 74 | - public function subscription_merge_tags( $merge_tags, $object ) { |
|
| 75 | - |
|
| 76 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
| 77 | - $merge_tags = array_merge( |
|
| 78 | - $merge_tags, |
|
| 79 | - $this->get_subscription_merge_tags( $object ) |
|
| 80 | - ); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - return $merge_tags; |
|
| 84 | - |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Generates subscription merge tags. |
|
| 89 | - * |
|
| 90 | - * @param WPInv_Subscription $subscription |
|
| 91 | - * @return array |
|
| 92 | - */ |
|
| 93 | - public function get_subscription_merge_tags( $subscription ) { |
|
| 94 | - |
|
| 95 | - // Abort if it does not exist. |
|
| 96 | - if ( ! $subscription->get_id() ) { |
|
| 97 | - return array(); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - $invoice = $subscription->get_parent_invoice(); |
|
| 101 | - return array( |
|
| 102 | - '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
| 103 | - '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
| 104 | - '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
| 105 | - '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
| 106 | - '{subscription_id}' => absint( $subscription->get_id() ), |
|
| 107 | - '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
| 108 | - '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
| 109 | - '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
| 110 | - '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
| 111 | - '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
| 112 | - ); |
|
| 113 | - |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Checks if we should send a notification for a subscription. |
|
| 118 | - * |
|
| 119 | - * @param WPInv_Invoice $invoice |
|
| 120 | - * @return bool |
|
| 121 | - */ |
|
| 122 | - public function should_send_notification( $invoice ) { |
|
| 123 | - return 0 != $invoice->get_id(); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Returns notification recipients. |
|
| 128 | - * |
|
| 129 | - * @param WPInv_Invoice $invoice |
|
| 130 | - * @return array |
|
| 131 | - */ |
|
| 132 | - public function get_recipients( $invoice ) { |
|
| 133 | - $recipients = array( $invoice->get_email() ); |
|
| 134 | - |
|
| 135 | - $cc = $invoice->get_email_cc(); |
|
| 136 | - |
|
| 137 | - if ( ! empty( $cc ) ) { |
|
| 138 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
| 139 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return $recipients; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Helper function to send an email. |
|
| 147 | - * |
|
| 148 | - * @param WPInv_Subscription $subscription |
|
| 149 | - * @param GetPaid_Notification_Email $email |
|
| 150 | - * @param string $type |
|
| 151 | - * @param array $extra_args Extra template args. |
|
| 152 | - */ |
|
| 153 | - public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
| 154 | - |
|
| 155 | - if ( empty( $subscription ) ) { |
|
| 156 | - return; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - if ( is_array( $subscription ) ) { |
|
| 160 | - $subscription = current( $subscription ); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - if ( ! $subscription instanceof WPInv_Subscription ) { |
|
| 164 | - return; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // Abort in case the parent invoice does not exist. |
|
| 168 | - $invoice = $subscription->get_parent_invoice(); |
|
| 169 | - if ( ! $this->should_send_notification( $invoice ) ) { |
|
| 170 | - return; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
| 174 | - return; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
| 178 | - |
|
| 179 | - $recipients = $this->get_recipients( $invoice ); |
|
| 180 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
| 181 | - $merge_tags = $email->get_merge_tags(); |
|
| 182 | - $content = $email->get_content( $merge_tags, $extra_args ); |
|
| 183 | - $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
| 184 | - $attachments = $email->get_attachments(); |
|
| 185 | - |
|
| 186 | - $result = $mailer->send( |
|
| 187 | - apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
| 188 | - $subject, |
|
| 189 | - $content, |
|
| 190 | - $attachments |
|
| 191 | - ); |
|
| 192 | - |
|
| 193 | - // Maybe send a copy to the admin. |
|
| 194 | - if ( $email->include_admin_bcc() ) { |
|
| 195 | - $mailer->send( |
|
| 196 | - wpinv_get_admin_email(), |
|
| 197 | - $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
| 198 | - $content, |
|
| 199 | - $attachments |
|
| 200 | - ); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - if ( $result ) { |
|
| 204 | - $invoice->add_system_note( |
|
| 205 | - sprintf( |
|
| 206 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
| 207 | - sanitize_key( $type ), |
|
| 208 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
| 209 | - ) |
|
| 210 | - ); |
|
| 211 | - } else { |
|
| 212 | - $invoice->add_system_note( |
|
| 213 | - sprintf( |
|
| 214 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
| 215 | - sanitize_key( $type ), |
|
| 216 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
| 217 | - ) |
|
| 218 | - ); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
| 222 | - |
|
| 223 | - } |
|
| 44 | + * Registers email hooks. |
|
| 45 | + */ |
|
| 46 | + public function init_hooks() { |
|
| 47 | + |
|
| 48 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
| 49 | + foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
| 50 | + |
|
| 51 | + $email = new GetPaid_Notification_Email( $email_type ); |
|
| 52 | + |
|
| 53 | + if ( ! $email->is_active() ) { |
|
| 54 | + continue; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + if ( method_exists( $this, $email_type ) ) { |
|
| 58 | + add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
| 59 | + continue; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
| 63 | + |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + } |
|
| 224 | 67 | |
| 225 | 68 | /** |
| 226 | - * Sends a new trial notification. |
|
| 227 | - * |
|
| 228 | - * @param WPInv_Subscription $subscription |
|
| 229 | - */ |
|
| 230 | - public function subscription_trial( $subscription ) { |
|
| 69 | + * Filters subscription merge tags. |
|
| 70 | + * |
|
| 71 | + * @param array $merge_tags |
|
| 72 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
| 73 | + */ |
|
| 74 | + public function subscription_merge_tags( $merge_tags, $object ) { |
|
| 231 | 75 | |
| 232 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 233 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 76 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
| 77 | + $merge_tags = array_merge( |
|
| 78 | + $merge_tags, |
|
| 79 | + $this->get_subscription_merge_tags( $object ) |
|
| 80 | + ); |
|
| 81 | + } |
|
| 234 | 82 | |
| 235 | - } |
|
| 83 | + return $merge_tags; |
|
| 236 | 84 | |
| 237 | - /** |
|
| 238 | - * Sends a cancelled subscription notification. |
|
| 239 | - * |
|
| 240 | - * @param WPInv_Subscription $subscription |
|
| 241 | - */ |
|
| 242 | - public function subscription_cancelled( $subscription ) { |
|
| 85 | + } |
|
| 243 | 86 | |
| 244 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 245 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 87 | + /** |
|
| 88 | + * Generates subscription merge tags. |
|
| 89 | + * |
|
| 90 | + * @param WPInv_Subscription $subscription |
|
| 91 | + * @return array |
|
| 92 | + */ |
|
| 93 | + public function get_subscription_merge_tags( $subscription ) { |
|
| 94 | + |
|
| 95 | + // Abort if it does not exist. |
|
| 96 | + if ( ! $subscription->get_id() ) { |
|
| 97 | + return array(); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + $invoice = $subscription->get_parent_invoice(); |
|
| 101 | + return array( |
|
| 102 | + '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
| 103 | + '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
| 104 | + '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
| 105 | + '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
| 106 | + '{subscription_id}' => absint( $subscription->get_id() ), |
|
| 107 | + '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
| 108 | + '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
| 109 | + '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
| 110 | + '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
| 111 | + '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
| 112 | + ); |
|
| 246 | 113 | |
| 247 | - } |
|
| 114 | + } |
|
| 248 | 115 | |
| 249 | - /** |
|
| 250 | - * Sends a subscription expired notification. |
|
| 251 | - * |
|
| 252 | - * @param WPInv_Subscription $subscription |
|
| 253 | - */ |
|
| 254 | - public function subscription_expired( $subscription ) { |
|
| 116 | + /** |
|
| 117 | + * Checks if we should send a notification for a subscription. |
|
| 118 | + * |
|
| 119 | + * @param WPInv_Invoice $invoice |
|
| 120 | + * @return bool |
|
| 121 | + */ |
|
| 122 | + public function should_send_notification( $invoice ) { |
|
| 123 | + return 0 != $invoice->get_id(); |
|
| 124 | + } |
|
| 255 | 125 | |
| 256 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 257 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 126 | + /** |
|
| 127 | + * Returns notification recipients. |
|
| 128 | + * |
|
| 129 | + * @param WPInv_Invoice $invoice |
|
| 130 | + * @return array |
|
| 131 | + */ |
|
| 132 | + public function get_recipients( $invoice ) { |
|
| 133 | + $recipients = array( $invoice->get_email() ); |
|
| 258 | 134 | |
| 259 | - } |
|
| 135 | + $cc = $invoice->get_email_cc(); |
|
| 260 | 136 | |
| 261 | - /** |
|
| 262 | - * Sends a completed subscription notification. |
|
| 263 | - * |
|
| 264 | - * @param WPInv_Subscription $subscription |
|
| 265 | - */ |
|
| 266 | - public function subscription_complete( $subscription ) { |
|
| 137 | + if ( ! empty( $cc ) ) { |
|
| 138 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
| 139 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
| 140 | + } |
|
| 267 | 141 | |
| 268 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 269 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 142 | + return $recipients; |
|
| 143 | + } |
|
| 270 | 144 | |
| 271 | - } |
|
| 145 | + /** |
|
| 146 | + * Helper function to send an email. |
|
| 147 | + * |
|
| 148 | + * @param WPInv_Subscription $subscription |
|
| 149 | + * @param GetPaid_Notification_Email $email |
|
| 150 | + * @param string $type |
|
| 151 | + * @param array $extra_args Extra template args. |
|
| 152 | + */ |
|
| 153 | + public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
| 154 | + |
|
| 155 | + if ( empty( $subscription ) ) { |
|
| 156 | + return; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + if ( is_array( $subscription ) ) { |
|
| 160 | + $subscription = current( $subscription ); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + if ( ! $subscription instanceof WPInv_Subscription ) { |
|
| 164 | + return; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // Abort in case the parent invoice does not exist. |
|
| 168 | + $invoice = $subscription->get_parent_invoice(); |
|
| 169 | + if ( ! $this->should_send_notification( $invoice ) ) { |
|
| 170 | + return; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
| 174 | + return; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
| 178 | + |
|
| 179 | + $recipients = $this->get_recipients( $invoice ); |
|
| 180 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
| 181 | + $merge_tags = $email->get_merge_tags(); |
|
| 182 | + $content = $email->get_content( $merge_tags, $extra_args ); |
|
| 183 | + $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
| 184 | + $attachments = $email->get_attachments(); |
|
| 185 | + |
|
| 186 | + $result = $mailer->send( |
|
| 187 | + apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
| 188 | + $subject, |
|
| 189 | + $content, |
|
| 190 | + $attachments |
|
| 191 | + ); |
|
| 192 | + |
|
| 193 | + // Maybe send a copy to the admin. |
|
| 194 | + if ( $email->include_admin_bcc() ) { |
|
| 195 | + $mailer->send( |
|
| 196 | + wpinv_get_admin_email(), |
|
| 197 | + $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
| 198 | + $content, |
|
| 199 | + $attachments |
|
| 200 | + ); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + if ( $result ) { |
|
| 204 | + $invoice->add_system_note( |
|
| 205 | + sprintf( |
|
| 206 | + __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
| 207 | + sanitize_key( $type ), |
|
| 208 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
| 209 | + ) |
|
| 210 | + ); |
|
| 211 | + } else { |
|
| 212 | + $invoice->add_system_note( |
|
| 213 | + sprintf( |
|
| 214 | + __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
| 215 | + sanitize_key( $type ), |
|
| 216 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
| 217 | + ) |
|
| 218 | + ); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
| 272 | 222 | |
| 273 | - /** |
|
| 274 | - * Sends a subscription renewal reminder notification. |
|
| 275 | - * |
|
| 276 | - */ |
|
| 277 | - public function renewal_reminder() { |
|
| 223 | + } |
|
| 278 | 224 | |
| 279 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
| 225 | + /** |
|
| 226 | + * Sends a new trial notification. |
|
| 227 | + * |
|
| 228 | + * @param WPInv_Subscription $subscription |
|
| 229 | + */ |
|
| 230 | + public function subscription_trial( $subscription ) { |
|
| 280 | 231 | |
| 281 | - // Fetch reminder days. |
|
| 282 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
| 232 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 233 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 283 | 234 | |
| 284 | - // Abort if non is set. |
|
| 285 | - if ( empty( $reminder_days ) ) { |
|
| 286 | - return; |
|
| 287 | - } |
|
| 235 | + } |
|
| 288 | 236 | |
| 289 | - // Fetch matching subscriptions. |
|
| 237 | + /** |
|
| 238 | + * Sends a cancelled subscription notification. |
|
| 239 | + * |
|
| 240 | + * @param WPInv_Subscription $subscription |
|
| 241 | + */ |
|
| 242 | + public function subscription_cancelled( $subscription ) { |
|
| 243 | + |
|
| 244 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 245 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 246 | + |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Sends a subscription expired notification. |
|
| 251 | + * |
|
| 252 | + * @param WPInv_Subscription $subscription |
|
| 253 | + */ |
|
| 254 | + public function subscription_expired( $subscription ) { |
|
| 255 | + |
|
| 256 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 257 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 258 | + |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Sends a completed subscription notification. |
|
| 263 | + * |
|
| 264 | + * @param WPInv_Subscription $subscription |
|
| 265 | + */ |
|
| 266 | + public function subscription_complete( $subscription ) { |
|
| 267 | + |
|
| 268 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 269 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 270 | + |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * Sends a subscription renewal reminder notification. |
|
| 275 | + * |
|
| 276 | + */ |
|
| 277 | + public function renewal_reminder() { |
|
| 278 | + |
|
| 279 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
| 280 | + |
|
| 281 | + // Fetch reminder days. |
|
| 282 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
| 283 | + |
|
| 284 | + // Abort if non is set. |
|
| 285 | + if ( empty( $reminder_days ) ) { |
|
| 286 | + return; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + // Fetch matching subscriptions. |
|
| 290 | 290 | $args = array( |
| 291 | 291 | 'number' => -1, |
| 292 | - 'count_total' => false, |
|
| 293 | - 'status' => 'trialling active', |
|
| 292 | + 'count_total' => false, |
|
| 293 | + 'status' => 'trialling active', |
|
| 294 | 294 | 'date_expires_query' => array( |
| 295 | - 'relation' => 'OR', |
|
| 295 | + 'relation' => 'OR', |
|
| 296 | 296 | ), |
| 297 | - ); |
|
| 297 | + ); |
|
| 298 | 298 | |
| 299 | - foreach ( $reminder_days as $days ) { |
|
| 300 | - $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
| 299 | + foreach ( $reminder_days as $days ) { |
|
| 300 | + $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
| 301 | 301 | |
| 302 | - $args['date_expires_query'][] = array( |
|
| 303 | - 'year' => $date['year'], |
|
| 304 | - 'month' => $date['month'], |
|
| 305 | - 'day' => $date['day'], |
|
| 306 | - ); |
|
| 302 | + $args['date_expires_query'][] = array( |
|
| 303 | + 'year' => $date['year'], |
|
| 304 | + 'month' => $date['month'], |
|
| 305 | + 'day' => $date['day'], |
|
| 306 | + ); |
|
| 307 | 307 | |
| 308 | - } |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
| 310 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
| 311 | 311 | |
| 312 | 312 | foreach ( $subscriptions->get_results() as $subscription ) { |
| 313 | 313 | |
| 314 | - // Skip packages. |
|
| 315 | - if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) { |
|
| 316 | - $email->object = $subscription; |
|
| 317 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 318 | - } |
|
| 319 | - } |
|
| 314 | + // Skip packages. |
|
| 315 | + if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) { |
|
| 316 | + $email->object = $subscription; |
|
| 317 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | 320 | |
| 321 | - } |
|
| 321 | + } |
|
| 322 | 322 | |
| 323 | 323 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * This class handles subscription notificaiton emails. |
@@ -45,21 +45,21 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function init_hooks() { |
| 47 | 47 | |
| 48 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
| 49 | - foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
| 48 | + add_filter('getpaid_get_email_merge_tags', array($this, 'subscription_merge_tags'), 10, 2); |
|
| 49 | + foreach ($this->subscription_actions as $hook => $email_type) { |
|
| 50 | 50 | |
| 51 | - $email = new GetPaid_Notification_Email( $email_type ); |
|
| 51 | + $email = new GetPaid_Notification_Email($email_type); |
|
| 52 | 52 | |
| 53 | - if ( ! $email->is_active() ) { |
|
| 53 | + if (!$email->is_active()) { |
|
| 54 | 54 | continue; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if ( method_exists( $this, $email_type ) ) { |
|
| 58 | - add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
| 57 | + if (method_exists($this, $email_type)) { |
|
| 58 | + add_action($hook, array($this, $email_type), 100, 2); |
|
| 59 | 59 | continue; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
| 62 | + do_action('getpaid_subscription_notification_email_register_hook', $email_type, $hook); |
|
| 63 | 63 | |
| 64 | 64 | } |
| 65 | 65 | |
@@ -71,12 +71,12 @@ discard block |
||
| 71 | 71 | * @param array $merge_tags |
| 72 | 72 | * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
| 73 | 73 | */ |
| 74 | - public function subscription_merge_tags( $merge_tags, $object ) { |
|
| 74 | + public function subscription_merge_tags($merge_tags, $object) { |
|
| 75 | 75 | |
| 76 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
| 76 | + if (is_a($object, 'WPInv_Subscription')) { |
|
| 77 | 77 | $merge_tags = array_merge( |
| 78 | 78 | $merge_tags, |
| 79 | - $this->get_subscription_merge_tags( $object ) |
|
| 79 | + $this->get_subscription_merge_tags($object) |
|
| 80 | 80 | ); |
| 81 | 81 | } |
| 82 | 82 | |
@@ -90,25 +90,25 @@ discard block |
||
| 90 | 90 | * @param WPInv_Subscription $subscription |
| 91 | 91 | * @return array |
| 92 | 92 | */ |
| 93 | - public function get_subscription_merge_tags( $subscription ) { |
|
| 93 | + public function get_subscription_merge_tags($subscription) { |
|
| 94 | 94 | |
| 95 | 95 | // Abort if it does not exist. |
| 96 | - if ( ! $subscription->get_id() ) { |
|
| 96 | + if (!$subscription->get_id()) { |
|
| 97 | 97 | return array(); |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - $invoice = $subscription->get_parent_invoice(); |
|
| 100 | + $invoice = $subscription->get_parent_invoice(); |
|
| 101 | 101 | return array( |
| 102 | - '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
| 103 | - '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
| 104 | - '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
| 105 | - '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
| 106 | - '{subscription_id}' => absint( $subscription->get_id() ), |
|
| 107 | - '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
| 108 | - '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
| 109 | - '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
| 102 | + '{subscription_renewal_date}' => getpaid_format_date_value($subscription->get_next_renewal_date(), __('Never', 'invoicing')), |
|
| 103 | + '{subscription_created}' => getpaid_format_date_value($subscription->get_date_created()), |
|
| 104 | + '{subscription_status}' => sanitize_text_field($subscription->get_status_label()), |
|
| 105 | + '{subscription_profile_id}' => sanitize_text_field($subscription->get_profile_id()), |
|
| 106 | + '{subscription_id}' => absint($subscription->get_id()), |
|
| 107 | + '{subscription_recurring_amount}' => sanitize_text_field(wpinv_price($subscription->get_recurring_amount(), $invoice->get_currency())), |
|
| 108 | + '{subscription_initial_amount}' => sanitize_text_field(wpinv_price($subscription->get_initial_amount(), $invoice->get_currency())), |
|
| 109 | + '{subscription_recurring_period}' => getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''), |
|
| 110 | 110 | '{subscription_bill_times}' => $subscription->get_bill_times(), |
| 111 | - '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
| 111 | + '{subscription_url}' => esc_url($subscription->get_view_url()), |
|
| 112 | 112 | ); |
| 113 | 113 | |
| 114 | 114 | } |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * @param WPInv_Invoice $invoice |
| 120 | 120 | * @return bool |
| 121 | 121 | */ |
| 122 | - public function should_send_notification( $invoice ) { |
|
| 122 | + public function should_send_notification($invoice) { |
|
| 123 | 123 | return 0 != $invoice->get_id(); |
| 124 | 124 | } |
| 125 | 125 | |
@@ -129,14 +129,14 @@ discard block |
||
| 129 | 129 | * @param WPInv_Invoice $invoice |
| 130 | 130 | * @return array |
| 131 | 131 | */ |
| 132 | - public function get_recipients( $invoice ) { |
|
| 133 | - $recipients = array( $invoice->get_email() ); |
|
| 132 | + public function get_recipients($invoice) { |
|
| 133 | + $recipients = array($invoice->get_email()); |
|
| 134 | 134 | |
| 135 | 135 | $cc = $invoice->get_email_cc(); |
| 136 | 136 | |
| 137 | - if ( ! empty( $cc ) ) { |
|
| 138 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
| 139 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
| 137 | + if (!empty($cc)) { |
|
| 138 | + $cc = array_map('sanitize_email', wpinv_parse_list($cc)); |
|
| 139 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc))); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | return $recipients; |
@@ -150,75 +150,75 @@ discard block |
||
| 150 | 150 | * @param string $type |
| 151 | 151 | * @param array $extra_args Extra template args. |
| 152 | 152 | */ |
| 153 | - public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
| 153 | + public function send_email($subscription, $email, $type, $extra_args = array()) { |
|
| 154 | 154 | |
| 155 | - if ( empty( $subscription ) ) { |
|
| 155 | + if (empty($subscription)) { |
|
| 156 | 156 | return; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - if ( is_array( $subscription ) ) { |
|
| 160 | - $subscription = current( $subscription ); |
|
| 159 | + if (is_array($subscription)) { |
|
| 160 | + $subscription = current($subscription); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - if ( ! $subscription instanceof WPInv_Subscription ) { |
|
| 163 | + if (!$subscription instanceof WPInv_Subscription) { |
|
| 164 | 164 | return; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | // Abort in case the parent invoice does not exist. |
| 168 | 168 | $invoice = $subscription->get_parent_invoice(); |
| 169 | - if ( ! $this->should_send_notification( $invoice ) ) { |
|
| 169 | + if (!$this->should_send_notification($invoice)) { |
|
| 170 | 170 | return; |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
| 173 | + if (apply_filters('getpaid_skip_subscription_email', false, $type, $subscription)) { |
|
| 174 | 174 | return; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
| 177 | + do_action('getpaid_before_send_subscription_notification', $type, $subscription, $email); |
|
| 178 | 178 | |
| 179 | - $recipients = $this->get_recipients( $invoice ); |
|
| 179 | + $recipients = $this->get_recipients($invoice); |
|
| 180 | 180 | $mailer = new GetPaid_Notification_Email_Sender(); |
| 181 | 181 | $merge_tags = $email->get_merge_tags(); |
| 182 | - $content = $email->get_content( $merge_tags, $extra_args ); |
|
| 183 | - $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
| 182 | + $content = $email->get_content($merge_tags, $extra_args); |
|
| 183 | + $subject = $email->add_merge_tags($email->get_subject(), $merge_tags); |
|
| 184 | 184 | $attachments = $email->get_attachments(); |
| 185 | 185 | |
| 186 | 186 | $result = $mailer->send( |
| 187 | - apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
| 187 | + apply_filters('getpaid_subscription_email_recipients', wpinv_parse_list($recipients), $email), |
|
| 188 | 188 | $subject, |
| 189 | 189 | $content, |
| 190 | 190 | $attachments |
| 191 | 191 | ); |
| 192 | 192 | |
| 193 | 193 | // Maybe send a copy to the admin. |
| 194 | - if ( $email->include_admin_bcc() ) { |
|
| 194 | + if ($email->include_admin_bcc()) { |
|
| 195 | 195 | $mailer->send( |
| 196 | 196 | wpinv_get_admin_email(), |
| 197 | - $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
| 197 | + $subject . __(' - ADMIN BCC COPY', 'invoicing'), |
|
| 198 | 198 | $content, |
| 199 | 199 | $attachments |
| 200 | 200 | ); |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - if ( $result ) { |
|
| 203 | + if ($result) { |
|
| 204 | 204 | $invoice->add_system_note( |
| 205 | 205 | sprintf( |
| 206 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
| 207 | - sanitize_key( $type ), |
|
| 208 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
| 206 | + __('Successfully sent %1$s notification email to %2$s.', 'invoicing'), |
|
| 207 | + sanitize_key($type), |
|
| 208 | + $email->is_admin_email() ? __('admin') : __('the customer') |
|
| 209 | 209 | ) |
| 210 | 210 | ); |
| 211 | 211 | } else { |
| 212 | 212 | $invoice->add_system_note( |
| 213 | 213 | sprintf( |
| 214 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
| 215 | - sanitize_key( $type ), |
|
| 216 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
| 214 | + __('Failed sending %1$s notification email to %2$s.', 'invoicing'), |
|
| 215 | + sanitize_key($type), |
|
| 216 | + $email->is_admin_email() ? __('admin') : __('the customer') |
|
| 217 | 217 | ) |
| 218 | 218 | ); |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
| 221 | + do_action('getpaid_after_send_subscription_notification', $type, $subscription, $email); |
|
| 222 | 222 | |
| 223 | 223 | } |
| 224 | 224 | |
@@ -227,10 +227,10 @@ discard block |
||
| 227 | 227 | * |
| 228 | 228 | * @param WPInv_Subscription $subscription |
| 229 | 229 | */ |
| 230 | - public function subscription_trial( $subscription ) { |
|
| 230 | + public function subscription_trial($subscription) { |
|
| 231 | 231 | |
| 232 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 233 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 232 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
| 233 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
| 234 | 234 | |
| 235 | 235 | } |
| 236 | 236 | |
@@ -239,10 +239,10 @@ discard block |
||
| 239 | 239 | * |
| 240 | 240 | * @param WPInv_Subscription $subscription |
| 241 | 241 | */ |
| 242 | - public function subscription_cancelled( $subscription ) { |
|
| 242 | + public function subscription_cancelled($subscription) { |
|
| 243 | 243 | |
| 244 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 245 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 244 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
| 245 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
| 246 | 246 | |
| 247 | 247 | } |
| 248 | 248 | |
@@ -251,10 +251,10 @@ discard block |
||
| 251 | 251 | * |
| 252 | 252 | * @param WPInv_Subscription $subscription |
| 253 | 253 | */ |
| 254 | - public function subscription_expired( $subscription ) { |
|
| 254 | + public function subscription_expired($subscription) { |
|
| 255 | 255 | |
| 256 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 257 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 256 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
| 257 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
| 258 | 258 | |
| 259 | 259 | } |
| 260 | 260 | |
@@ -263,10 +263,10 @@ discard block |
||
| 263 | 263 | * |
| 264 | 264 | * @param WPInv_Subscription $subscription |
| 265 | 265 | */ |
| 266 | - public function subscription_complete( $subscription ) { |
|
| 266 | + public function subscription_complete($subscription) { |
|
| 267 | 267 | |
| 268 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 269 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 268 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
| 269 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
| 270 | 270 | |
| 271 | 271 | } |
| 272 | 272 | |
@@ -276,18 +276,18 @@ discard block |
||
| 276 | 276 | */ |
| 277 | 277 | public function renewal_reminder() { |
| 278 | 278 | |
| 279 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
| 279 | + $email = new GetPaid_Notification_Email(__FUNCTION__); |
|
| 280 | 280 | |
| 281 | 281 | // Fetch reminder days. |
| 282 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
| 282 | + $reminder_days = array_unique(wp_parse_id_list($email->get_option('days'))); |
|
| 283 | 283 | |
| 284 | 284 | // Abort if non is set. |
| 285 | - if ( empty( $reminder_days ) ) { |
|
| 285 | + if (empty($reminder_days)) { |
|
| 286 | 286 | return; |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | // Fetch matching subscriptions. |
| 290 | - $args = array( |
|
| 290 | + $args = array( |
|
| 291 | 291 | 'number' => -1, |
| 292 | 292 | 'count_total' => false, |
| 293 | 293 | 'status' => 'trialling active', |
@@ -296,8 +296,8 @@ discard block |
||
| 296 | 296 | ), |
| 297 | 297 | ); |
| 298 | 298 | |
| 299 | - foreach ( $reminder_days as $days ) { |
|
| 300 | - $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
| 299 | + foreach ($reminder_days as $days) { |
|
| 300 | + $date = date_parse(date('Y-m-d', strtotime("+$days days", current_time('timestamp')))); |
|
| 301 | 301 | |
| 302 | 302 | $args['date_expires_query'][] = array( |
| 303 | 303 | 'year' => $date['year'], |
@@ -307,14 +307,14 @@ discard block |
||
| 307 | 307 | |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
| 310 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
| 311 | 311 | |
| 312 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
| 312 | + foreach ($subscriptions->get_results() as $subscription) { |
|
| 313 | 313 | |
| 314 | 314 | // Skip packages. |
| 315 | - if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) { |
|
| 315 | + if (apply_filters('getpaid_send_subscription_renewal_reminder_email', true)) { |
|
| 316 | 316 | $email->object = $subscription; |
| 317 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 317 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
| 318 | 318 | } |
| 319 | 319 | } |
| 320 | 320 | |
@@ -7,50 +7,50 @@ |
||
| 7 | 7 | * @version 1.0.19 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | -$class = ! is_singular( 'page' ) ? 'px-1' : ''; |
|
| 12 | +$class = !is_singular('page') ? 'px-1' : ''; |
|
| 13 | 13 | ?> |
| 14 | 14 | |
| 15 | - <?php do_action( 'getpaid_before_invoice_meta', $invoice ); ?> |
|
| 15 | + <?php do_action('getpaid_before_invoice_meta', $invoice); ?> |
|
| 16 | 16 | <div class="getpaid-invoice-meta-data"> |
| 17 | 17 | |
| 18 | - <?php do_action( 'getpaid_before_invoice_meta_table', $invoice ); ?> |
|
| 18 | + <?php do_action('getpaid_before_invoice_meta_table', $invoice); ?> |
|
| 19 | 19 | <table class="table table-bordered"> |
| 20 | 20 | <tbody> |
| 21 | 21 | |
| 22 | - <?php do_action( 'getpaid_before_invoice_meta_rows', $invoice ); ?> |
|
| 23 | - <?php foreach ( $meta as $key => $data ) : ?> |
|
| 22 | + <?php do_action('getpaid_before_invoice_meta_rows', $invoice); ?> |
|
| 23 | + <?php foreach ($meta as $key => $data) : ?> |
|
| 24 | 24 | |
| 25 | - <?php if ( ! empty( $data['value'] ) ) : ?> |
|
| 25 | + <?php if (!empty($data['value'])) : ?> |
|
| 26 | 26 | |
| 27 | - <?php do_action( "getpaid_before_invoice_meta_$key", $invoice, $data ); ?> |
|
| 27 | + <?php do_action("getpaid_before_invoice_meta_$key", $invoice, $data); ?> |
|
| 28 | 28 | |
| 29 | - <tr class="getpaid-invoice-meta-<?php echo esc_attr( $key ); ?>"> |
|
| 29 | + <tr class="getpaid-invoice-meta-<?php echo esc_attr($key); ?>"> |
|
| 30 | 30 | |
| 31 | - <th class="<?php echo esc_attr( $class ); ?> font-weight-bold" style="width: 40%"> |
|
| 32 | - <?php echo esc_html( $data['label'] ); ?> |
|
| 31 | + <th class="<?php echo esc_attr($class); ?> font-weight-bold" style="width: 40%"> |
|
| 32 | + <?php echo esc_html($data['label']); ?> |
|
| 33 | 33 | </th> |
| 34 | 34 | |
| 35 | - <td class="<?php echo esc_attr( $class ); ?> <?php echo 'invoice_total' === $key ? 'font-weight-bold' : 'font-weight-normal'; ?> text-break" style="width: 60%"> |
|
| 36 | - <span class="getpaid-invoice-meta-<?php echo esc_attr( $key ); ?>-value"><?php echo wp_kses_post( $data['value'] ); ?></span> |
|
| 35 | + <td class="<?php echo esc_attr($class); ?> <?php echo 'invoice_total' === $key ? 'font-weight-bold' : 'font-weight-normal'; ?> text-break" style="width: 60%"> |
|
| 36 | + <span class="getpaid-invoice-meta-<?php echo esc_attr($key); ?>-value"><?php echo wp_kses_post($data['value']); ?></span> |
|
| 37 | 37 | </td> |
| 38 | 38 | |
| 39 | 39 | </tr> |
| 40 | 40 | |
| 41 | - <?php do_action( "getpaid_after_invoice_meta_$key", $invoice, $data ); ?> |
|
| 41 | + <?php do_action("getpaid_after_invoice_meta_$key", $invoice, $data); ?> |
|
| 42 | 42 | |
| 43 | 43 | <?php endif; ?> |
| 44 | 44 | |
| 45 | 45 | <?php endforeach; ?> |
| 46 | - <?php do_action( 'getpaid_after_invoice_meta_rows', $invoice ); ?> |
|
| 46 | + <?php do_action('getpaid_after_invoice_meta_rows', $invoice); ?> |
|
| 47 | 47 | |
| 48 | 48 | </tbody> |
| 49 | 49 | </table> |
| 50 | - <?php do_action( 'getpaid_after_invoice_meta_table', $invoice ); ?> |
|
| 50 | + <?php do_action('getpaid_after_invoice_meta_table', $invoice); ?> |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | 53 | </div> |
| 54 | - <?php do_action( 'getpaid_after_invoice_meta', $invoice ); ?> |
|
| 54 | + <?php do_action('getpaid_after_invoice_meta', $invoice); ?> |
|
| 55 | 55 | |
| 56 | 56 | <?php |
@@ -39,40 +39,40 @@ |
||
| 39 | 39 | if ( 'tax' === $key ) { |
| 40 | 40 | wpinv_the_price( $invoice->get_total_tax(), $invoice->get_currency() ); |
| 41 | 41 | |
| 42 | - if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
| 42 | + if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
| 43 | 43 | |
| 44 | - $taxes = $invoice->get_total_tax(); |
|
| 45 | - if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
| 46 | - echo ' <em class="text-muted small">'; |
|
| 47 | - _x( '(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing' ); |
|
| 48 | - echo '</em>'; |
|
| 44 | + $taxes = $invoice->get_total_tax(); |
|
| 45 | + if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
| 46 | + echo ' <em class="text-muted small">'; |
|
| 47 | + _x( '(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing' ); |
|
| 48 | + echo '</em>'; |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | // Total Fee. |
| 54 | 54 | if ( 'fee' === $key ) { |
| 55 | - wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
| 55 | + wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | // Total discount. |
| 59 | 59 | if ( 'discount' === $key ) { |
| 60 | - wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
| 60 | + wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | // Shipping. |
| 64 | 64 | if ( 'shipping' === $key ) { |
| 65 | - wpinv_the_price( $invoice->get_shipping(), $invoice->get_currency() ); |
|
| 65 | + wpinv_the_price( $invoice->get_shipping(), $invoice->get_currency() ); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | // Sub total. |
| 69 | 69 | if ( 'subtotal' === $key ) { |
| 70 | - wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
| 70 | + wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // Total. |
| 74 | 74 | if ( 'total' === $key ) { |
| 75 | - wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
| 75 | + wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | // Fires when printing a cart total. |
@@ -9,26 +9,26 @@ discard block |
||
| 9 | 9 | * @var WPInv_Invoice $invoice |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | // Totals rows. |
| 15 | -$totals = getpaid_invoice_totals_rows( $invoice ); |
|
| 15 | +$totals = getpaid_invoice_totals_rows($invoice); |
|
| 16 | 16 | |
| 17 | -do_action( 'getpaid_before_invoice_line_totals', $invoice, $totals ); |
|
| 17 | +do_action('getpaid_before_invoice_line_totals', $invoice, $totals); |
|
| 18 | 18 | |
| 19 | 19 | ?> |
| 20 | 20 | <div class='getpaid-invoice-line-totals'> |
| 21 | 21 | <div class="row"> |
| 22 | 22 | <div class="col-12 offset-sm-6 col-sm-6 border-sm-left pl-sm-0"> |
| 23 | 23 | |
| 24 | - <?php foreach ( $totals as $key => $label ) : ?> |
|
| 24 | + <?php foreach ($totals as $key => $label) : ?> |
|
| 25 | 25 | |
| 26 | - <div class="getpaid-invoice-line-totals-col <?php echo esc_attr( $key ); ?>"> |
|
| 26 | + <div class="getpaid-invoice-line-totals-col <?php echo esc_attr($key); ?>"> |
|
| 27 | 27 | |
| 28 | 28 | <div class="form-row row"> |
| 29 | 29 | |
| 30 | 30 | <div class="col-8 getpaid-invoice-line-totals-label"> |
| 31 | - <?php echo esc_html( $label ); ?> |
|
| 31 | + <?php echo esc_html($label); ?> |
|
| 32 | 32 | </div> |
| 33 | 33 | |
| 34 | 34 | <div class="col-4 getpaid-invoice-line-totals-value pl-0"> |
@@ -36,47 +36,47 @@ discard block |
||
| 36 | 36 | <?php |
| 37 | 37 | |
| 38 | 38 | // Total tax. |
| 39 | - if ( 'tax' === $key ) { |
|
| 40 | - wpinv_the_price( $invoice->get_total_tax(), $invoice->get_currency() ); |
|
| 39 | + if ('tax' === $key) { |
|
| 40 | + wpinv_the_price($invoice->get_total_tax(), $invoice->get_currency()); |
|
| 41 | 41 | |
| 42 | - if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
| 42 | + if (wpinv_use_taxes() && !$invoice->get_disable_taxes()) { |
|
| 43 | 43 | |
| 44 | 44 | $taxes = $invoice->get_total_tax(); |
| 45 | - if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
| 45 | + if (empty($taxes) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction($invoice->get_country())) { |
|
| 46 | 46 | echo ' <em class="text-muted small">'; |
| 47 | - _x( '(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing' ); |
|
| 47 | + _x('(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing'); |
|
| 48 | 48 | echo '</em>'; |
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | // Total Fee. |
| 54 | - if ( 'fee' === $key ) { |
|
| 55 | - wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
| 54 | + if ('fee' === $key) { |
|
| 55 | + wpinv_the_price($invoice->get_total_fees(), $invoice->get_currency()); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | // Total discount. |
| 59 | - if ( 'discount' === $key ) { |
|
| 60 | - wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
| 59 | + if ('discount' === $key) { |
|
| 60 | + wpinv_the_price($invoice->get_total_discount(), $invoice->get_currency()); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | // Shipping. |
| 64 | - if ( 'shipping' === $key ) { |
|
| 65 | - wpinv_the_price( $invoice->get_shipping(), $invoice->get_currency() ); |
|
| 64 | + if ('shipping' === $key) { |
|
| 65 | + wpinv_the_price($invoice->get_shipping(), $invoice->get_currency()); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | // Sub total. |
| 69 | - if ( 'subtotal' === $key ) { |
|
| 70 | - wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
| 69 | + if ('subtotal' === $key) { |
|
| 70 | + wpinv_the_price($invoice->get_subtotal(), $invoice->get_currency()); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // Total. |
| 74 | - if ( 'total' === $key ) { |
|
| 75 | - wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
| 74 | + if ('total' === $key) { |
|
| 75 | + wpinv_the_price($invoice->get_total(), $invoice->get_currency()); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | // Fires when printing a cart total. |
| 79 | - do_action( "getpaid_invoice_cart_totals_$key", $invoice ); |
|
| 79 | + do_action("getpaid_invoice_cart_totals_$key", $invoice); |
|
| 80 | 80 | |
| 81 | 81 | ?> |
| 82 | 82 | |
@@ -90,4 +90,4 @@ discard block |
||
| 90 | 90 | </div> |
| 91 | 91 | </div> <!-- end .getpaid-invoice-line-totals --> |
| 92 | 92 | |
| 93 | -<?php do_action( 'getpaid_after_invoice_line_totals', $invoice, $totals ); ?> |
|
| 93 | +<?php do_action('getpaid_after_invoice_line_totals', $invoice, $totals); ?> |
|
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | // Load WP_List_Table if not loaded |
| 13 | 13 | if ( ! class_exists( 'WP_List_Table' ) ) { |
| 14 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 14 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -23,375 +23,375 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | class WPInv_Customers_Table extends WP_List_Table { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var int Number of items per page |
|
| 28 | - * @since 1.0.19 |
|
| 29 | - */ |
|
| 30 | - public $per_page = 10; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @var int Number of items |
|
| 34 | - * @since 1.0.19 |
|
| 35 | - */ |
|
| 36 | - public $total = 0; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Get things started |
|
| 40 | - * |
|
| 41 | - * @since 1.0.19 |
|
| 42 | - * @see WP_List_Table::__construct() |
|
| 43 | - */ |
|
| 44 | - public function __construct() { |
|
| 45 | - |
|
| 46 | - // Set parent defaults |
|
| 47 | - parent::__construct( |
|
| 26 | + /** |
|
| 27 | + * @var int Number of items per page |
|
| 28 | + * @since 1.0.19 |
|
| 29 | + */ |
|
| 30 | + public $per_page = 10; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @var int Number of items |
|
| 34 | + * @since 1.0.19 |
|
| 35 | + */ |
|
| 36 | + public $total = 0; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Get things started |
|
| 40 | + * |
|
| 41 | + * @since 1.0.19 |
|
| 42 | + * @see WP_List_Table::__construct() |
|
| 43 | + */ |
|
| 44 | + public function __construct() { |
|
| 45 | + |
|
| 46 | + // Set parent defaults |
|
| 47 | + parent::__construct( |
|
| 48 | 48 | array( |
| 49 | - 'singular' => 'id', |
|
| 50 | - 'plural' => 'ids', |
|
| 51 | - 'ajax' => false, |
|
| 49 | + 'singular' => 'id', |
|
| 50 | + 'plural' => 'ids', |
|
| 51 | + 'ajax' => false, |
|
| 52 | 52 | ) |
| 53 | 53 | ); |
| 54 | 54 | |
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Gets the name of the primary column. |
|
| 59 | - * |
|
| 60 | - * @since 1.0.19 |
|
| 61 | - * @access protected |
|
| 62 | - * |
|
| 63 | - * @return string Name of the primary column. |
|
| 64 | - */ |
|
| 65 | - protected function get_primary_column_name() { |
|
| 66 | - return 'name'; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * This function renders most of the columns in the list table. |
|
| 71 | - * |
|
| 72 | - * @since 1.0.19 |
|
| 73 | - * |
|
| 74 | - * @param WP_User $item |
|
| 75 | - * @param string $column_name The name of the column |
|
| 76 | - * |
|
| 77 | - * @return string Column Name |
|
| 78 | - */ |
|
| 79 | - public function column_default( $item, $column_name ) { |
|
| 80 | - $value = esc_html( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
| 81 | - return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Displays the country column. |
|
| 86 | - * |
|
| 87 | - * @since 1.0.19 |
|
| 88 | - * |
|
| 89 | - * @param WP_User $user |
|
| 90 | - * |
|
| 91 | - * @return string Column Name |
|
| 92 | - */ |
|
| 93 | - public function column_country( $user ) { |
|
| 94 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 95 | - if ( $country ) { |
|
| 96 | - $country = wpinv_country_name( $country ); |
|
| 97 | - } |
|
| 98 | - return esc_html( $country ); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Displays the state column. |
|
| 103 | - * |
|
| 104 | - * @since 1.0.19 |
|
| 105 | - * |
|
| 106 | - * @param WP_User $user |
|
| 107 | - * |
|
| 108 | - * @return string Column Name |
|
| 109 | - */ |
|
| 110 | - public function column_state( $user ) { |
|
| 111 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 112 | - $state = $user->_wpinv_state; |
|
| 113 | - if ( $state ) { |
|
| 114 | - $state = wpinv_state_name( $state, $country ); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return esc_html( $state ); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Displays the signup column. |
|
| 122 | - * |
|
| 123 | - * @since 1.0.19 |
|
| 124 | - * |
|
| 125 | - * @param WP_User $user |
|
| 126 | - * |
|
| 127 | - * @return string Column Name |
|
| 128 | - */ |
|
| 129 | - public function column_signup( $user ) { |
|
| 130 | - return getpaid_format_date_value( $user->user_registered ); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Displays the total spent column. |
|
| 135 | - * |
|
| 136 | - * @since 1.0.19 |
|
| 137 | - * |
|
| 138 | - * @param WP_User $user |
|
| 139 | - * |
|
| 140 | - * @return string Column Name |
|
| 141 | - */ |
|
| 142 | - public function column_total( $user ) { |
|
| 143 | - return wpinv_price( $this->column_total_raw( $user ) ); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Displays the total spent column. |
|
| 148 | - * |
|
| 149 | - * @since 1.0.19 |
|
| 150 | - * |
|
| 151 | - * @param WP_User $user |
|
| 152 | - * |
|
| 153 | - * @return float |
|
| 154 | - */ |
|
| 155 | - public function column_total_raw( $user ) { |
|
| 156 | - |
|
| 157 | - $args = array( |
|
| 158 | - 'data' => array( |
|
| 159 | - |
|
| 160 | - 'total' => array( |
|
| 161 | - 'type' => 'invoice_data', |
|
| 162 | - 'function' => 'SUM', |
|
| 163 | - 'name' => 'total_sales', |
|
| 164 | - ), |
|
| 165 | - |
|
| 166 | - ), |
|
| 167 | - 'where' => array( |
|
| 168 | - |
|
| 169 | - 'author' => array( |
|
| 170 | - 'type' => 'post_data', |
|
| 171 | - 'value' => absint( $user->ID ), |
|
| 172 | - 'key' => 'posts.post_author', |
|
| 173 | - 'operator' => '=', |
|
| 174 | - ), |
|
| 175 | - |
|
| 176 | - ), |
|
| 177 | - 'query_type' => 'get_var', |
|
| 178 | - 'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ), |
|
| 179 | - ); |
|
| 180 | - |
|
| 181 | - return wpinv_round_amount( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 182 | - |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Displays the total spent column. |
|
| 187 | - * |
|
| 188 | - * @since 1.0.19 |
|
| 189 | - * |
|
| 190 | - * @param WP_User $user |
|
| 191 | - * |
|
| 192 | - * @return string Column Name |
|
| 193 | - */ |
|
| 194 | - public function column_invoices( $user ) { |
|
| 195 | - |
|
| 196 | - $args = array( |
|
| 197 | - 'data' => array( |
|
| 198 | - |
|
| 199 | - 'ID' => array( |
|
| 200 | - 'type' => 'post_data', |
|
| 201 | - 'function' => 'COUNT', |
|
| 202 | - 'name' => 'count', |
|
| 203 | - 'distinct' => true, |
|
| 204 | - ), |
|
| 205 | - |
|
| 206 | - ), |
|
| 207 | - 'where' => array( |
|
| 208 | - |
|
| 209 | - 'author' => array( |
|
| 210 | - 'type' => 'post_data', |
|
| 211 | - 'value' => absint( $user->ID ), |
|
| 212 | - 'key' => 'posts.post_author', |
|
| 213 | - 'operator' => '=', |
|
| 214 | - ), |
|
| 215 | - |
|
| 216 | - ), |
|
| 217 | - 'query_type' => 'get_var', |
|
| 218 | - 'invoice_status' => array_keys( wpinv_get_invoice_statuses() ), |
|
| 219 | - ); |
|
| 220 | - |
|
| 221 | - $value = absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 222 | - $url = add_query_arg( array( 'post_type' => 'wpi_invoice', 'author' => $user->ID ), admin_url( 'edit.php' ) ); |
|
| 223 | - return empty( $value ) ? '0' : '<a href="' . esc_url( $url ) . '">' . absint( $value ) . '</a>'; |
|
| 224 | - |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Generates content for a single row of the table |
|
| 229 | - * @since 1.0.19 |
|
| 230 | - * |
|
| 231 | - * @param int $item The user id. |
|
| 232 | - */ |
|
| 233 | - public function single_row( $item ) { |
|
| 234 | - $item = get_user_by( 'id', $item ); |
|
| 235 | - |
|
| 236 | - if ( empty( $item ) ) { |
|
| 237 | - return; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - echo '<tr>'; |
|
| 241 | - $this->single_row_columns( $item ); |
|
| 242 | - echo '</tr>'; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * Displays the customers name |
|
| 247 | - * |
|
| 248 | - * @param WP_User $customer customer. |
|
| 249 | - * @return string |
|
| 250 | - */ |
|
| 251 | - public function column_name( $customer ) { |
|
| 252 | - |
|
| 253 | - // Customer view URL. |
|
| 254 | - $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
| 255 | - $row_actions = $this->row_actions( |
|
| 256 | - array( |
|
| 257 | - 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
| 258 | - ) |
|
| 259 | - ); |
|
| 260 | - |
|
| 261 | - // Get user's address. |
|
| 262 | - $address = wpinv_get_user_address( $customer->ID ); |
|
| 263 | - |
|
| 264 | - // Customer email address. |
|
| 265 | - $email = sanitize_email( $customer->user_email ); |
|
| 266 | - |
|
| 267 | - // Customer's avatar. |
|
| 268 | - $avatar = esc_url( get_avatar_url( $email ) ); |
|
| 269 | - $avatar = "<img src='$avatar' height='32' width='32'/>"; |
|
| 270 | - |
|
| 271 | - // Customer's name. |
|
| 272 | - $name = esc_html( "{$address['first_name']} {$address['last_name']}" ); |
|
| 273 | - |
|
| 274 | - if ( empty( trim( $name ) ) ) { |
|
| 275 | - $name = esc_html( $address['display_name'] ); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - if ( ! empty( $name ) ) { |
|
| 279 | - $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - $email = "<div class='row-title'><a href='$view_url'>$email</a></div>"; |
|
| 283 | - |
|
| 284 | - return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>"; |
|
| 285 | - |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * Retrieve the table columns |
|
| 290 | - * |
|
| 291 | - * @since 1.0.19 |
|
| 292 | - * @return array $columns Array of all the list table columns |
|
| 293 | - */ |
|
| 294 | - public function get_columns() { |
|
| 295 | - |
|
| 296 | - $columns = array( |
|
| 297 | - 'name' => __( 'Name', 'invoicing' ), |
|
| 298 | - 'country' => __( 'Country', 'invoicing' ), |
|
| 299 | - 'state' => __( 'State', 'invoicing' ), |
|
| 300 | - 'city' => __( 'City', 'invoicing' ), |
|
| 301 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
| 302 | - 'address' => __( 'Address', 'invoicing' ), |
|
| 303 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
| 304 | - 'company' => __( 'Company', 'invoicing' ), |
|
| 305 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
| 306 | - 'total' => __( 'Total Spend', 'invoicing' ), |
|
| 307 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
| 308 | - ); |
|
| 309 | - return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
| 310 | - |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * Retrieve the current page number |
|
| 315 | - * |
|
| 316 | - * @since 1.0.19 |
|
| 317 | - * @return int Current page number |
|
| 318 | - */ |
|
| 319 | - public function get_paged() { |
|
| 320 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * Returns bulk actions. |
|
| 325 | - * |
|
| 326 | - * @since 1.0.19 |
|
| 327 | - * @return void |
|
| 328 | - */ |
|
| 329 | - public function bulk_actions( $which = '' ) { |
|
| 330 | - return array(); |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * Prepares the display query |
|
| 335 | - */ |
|
| 336 | - public function prepare_query() { |
|
| 337 | - global $wpdb; |
|
| 338 | - |
|
| 339 | - $post_types = ''; |
|
| 340 | - |
|
| 341 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 342 | - $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - $post_types = rtrim( $post_types, ' OR' ); |
|
| 346 | - |
|
| 347 | - // Maybe search. |
|
| 348 | - if ( ! empty( $_POST['s'] ) ) { |
|
| 349 | - $users = get_users( |
|
| 350 | - array( |
|
| 351 | - 'search' => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*', |
|
| 352 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
| 353 | - 'fields' => 'ID', |
|
| 354 | - ) |
|
| 355 | - ); |
|
| 356 | - |
|
| 357 | - $users = implode( ', ', $users ); |
|
| 358 | - $post_types = "($post_types) AND ( post_author IN ( $users ) )"; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - // Users with invoices. |
|
| 362 | - $customers = $wpdb->get_col( |
|
| 363 | - $wpdb->prepare( |
|
| 364 | - "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d", |
|
| 365 | - $this->get_paged() * 10 - 10, |
|
| 366 | - $this->per_page |
|
| 367 | - ) |
|
| 368 | - ); |
|
| 369 | - |
|
| 370 | - $this->items = $customers; |
|
| 371 | - $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" ); |
|
| 372 | - |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * Setup the final data for the table |
|
| 377 | - * |
|
| 378 | - * @since 1.0.19 |
|
| 379 | - * @return void |
|
| 380 | - */ |
|
| 381 | - public function prepare_items() { |
|
| 382 | - $columns = $this->get_columns(); |
|
| 383 | - $hidden = array(); // No hidden columns |
|
| 384 | - $sortable = $this->get_sortable_columns(); |
|
| 385 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 386 | - $this->prepare_query(); |
|
| 387 | - |
|
| 388 | - $this->set_pagination_args( |
|
| 389 | - array( |
|
| 390 | - 'total_items' => $this->total, |
|
| 391 | - 'per_page' => $this->per_page, |
|
| 392 | - 'total_pages' => ceil( $this->total / $this->per_page ), |
|
| 393 | - ) |
|
| 394 | - ); |
|
| 395 | - |
|
| 396 | - } |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Gets the name of the primary column. |
|
| 59 | + * |
|
| 60 | + * @since 1.0.19 |
|
| 61 | + * @access protected |
|
| 62 | + * |
|
| 63 | + * @return string Name of the primary column. |
|
| 64 | + */ |
|
| 65 | + protected function get_primary_column_name() { |
|
| 66 | + return 'name'; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * This function renders most of the columns in the list table. |
|
| 71 | + * |
|
| 72 | + * @since 1.0.19 |
|
| 73 | + * |
|
| 74 | + * @param WP_User $item |
|
| 75 | + * @param string $column_name The name of the column |
|
| 76 | + * |
|
| 77 | + * @return string Column Name |
|
| 78 | + */ |
|
| 79 | + public function column_default( $item, $column_name ) { |
|
| 80 | + $value = esc_html( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
| 81 | + return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Displays the country column. |
|
| 86 | + * |
|
| 87 | + * @since 1.0.19 |
|
| 88 | + * |
|
| 89 | + * @param WP_User $user |
|
| 90 | + * |
|
| 91 | + * @return string Column Name |
|
| 92 | + */ |
|
| 93 | + public function column_country( $user ) { |
|
| 94 | + $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 95 | + if ( $country ) { |
|
| 96 | + $country = wpinv_country_name( $country ); |
|
| 97 | + } |
|
| 98 | + return esc_html( $country ); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Displays the state column. |
|
| 103 | + * |
|
| 104 | + * @since 1.0.19 |
|
| 105 | + * |
|
| 106 | + * @param WP_User $user |
|
| 107 | + * |
|
| 108 | + * @return string Column Name |
|
| 109 | + */ |
|
| 110 | + public function column_state( $user ) { |
|
| 111 | + $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 112 | + $state = $user->_wpinv_state; |
|
| 113 | + if ( $state ) { |
|
| 114 | + $state = wpinv_state_name( $state, $country ); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return esc_html( $state ); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Displays the signup column. |
|
| 122 | + * |
|
| 123 | + * @since 1.0.19 |
|
| 124 | + * |
|
| 125 | + * @param WP_User $user |
|
| 126 | + * |
|
| 127 | + * @return string Column Name |
|
| 128 | + */ |
|
| 129 | + public function column_signup( $user ) { |
|
| 130 | + return getpaid_format_date_value( $user->user_registered ); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Displays the total spent column. |
|
| 135 | + * |
|
| 136 | + * @since 1.0.19 |
|
| 137 | + * |
|
| 138 | + * @param WP_User $user |
|
| 139 | + * |
|
| 140 | + * @return string Column Name |
|
| 141 | + */ |
|
| 142 | + public function column_total( $user ) { |
|
| 143 | + return wpinv_price( $this->column_total_raw( $user ) ); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Displays the total spent column. |
|
| 148 | + * |
|
| 149 | + * @since 1.0.19 |
|
| 150 | + * |
|
| 151 | + * @param WP_User $user |
|
| 152 | + * |
|
| 153 | + * @return float |
|
| 154 | + */ |
|
| 155 | + public function column_total_raw( $user ) { |
|
| 156 | + |
|
| 157 | + $args = array( |
|
| 158 | + 'data' => array( |
|
| 159 | + |
|
| 160 | + 'total' => array( |
|
| 161 | + 'type' => 'invoice_data', |
|
| 162 | + 'function' => 'SUM', |
|
| 163 | + 'name' => 'total_sales', |
|
| 164 | + ), |
|
| 165 | + |
|
| 166 | + ), |
|
| 167 | + 'where' => array( |
|
| 168 | + |
|
| 169 | + 'author' => array( |
|
| 170 | + 'type' => 'post_data', |
|
| 171 | + 'value' => absint( $user->ID ), |
|
| 172 | + 'key' => 'posts.post_author', |
|
| 173 | + 'operator' => '=', |
|
| 174 | + ), |
|
| 175 | + |
|
| 176 | + ), |
|
| 177 | + 'query_type' => 'get_var', |
|
| 178 | + 'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ), |
|
| 179 | + ); |
|
| 180 | + |
|
| 181 | + return wpinv_round_amount( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 182 | + |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Displays the total spent column. |
|
| 187 | + * |
|
| 188 | + * @since 1.0.19 |
|
| 189 | + * |
|
| 190 | + * @param WP_User $user |
|
| 191 | + * |
|
| 192 | + * @return string Column Name |
|
| 193 | + */ |
|
| 194 | + public function column_invoices( $user ) { |
|
| 195 | + |
|
| 196 | + $args = array( |
|
| 197 | + 'data' => array( |
|
| 198 | + |
|
| 199 | + 'ID' => array( |
|
| 200 | + 'type' => 'post_data', |
|
| 201 | + 'function' => 'COUNT', |
|
| 202 | + 'name' => 'count', |
|
| 203 | + 'distinct' => true, |
|
| 204 | + ), |
|
| 205 | + |
|
| 206 | + ), |
|
| 207 | + 'where' => array( |
|
| 208 | + |
|
| 209 | + 'author' => array( |
|
| 210 | + 'type' => 'post_data', |
|
| 211 | + 'value' => absint( $user->ID ), |
|
| 212 | + 'key' => 'posts.post_author', |
|
| 213 | + 'operator' => '=', |
|
| 214 | + ), |
|
| 215 | + |
|
| 216 | + ), |
|
| 217 | + 'query_type' => 'get_var', |
|
| 218 | + 'invoice_status' => array_keys( wpinv_get_invoice_statuses() ), |
|
| 219 | + ); |
|
| 220 | + |
|
| 221 | + $value = absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 222 | + $url = add_query_arg( array( 'post_type' => 'wpi_invoice', 'author' => $user->ID ), admin_url( 'edit.php' ) ); |
|
| 223 | + return empty( $value ) ? '0' : '<a href="' . esc_url( $url ) . '">' . absint( $value ) . '</a>'; |
|
| 224 | + |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Generates content for a single row of the table |
|
| 229 | + * @since 1.0.19 |
|
| 230 | + * |
|
| 231 | + * @param int $item The user id. |
|
| 232 | + */ |
|
| 233 | + public function single_row( $item ) { |
|
| 234 | + $item = get_user_by( 'id', $item ); |
|
| 235 | + |
|
| 236 | + if ( empty( $item ) ) { |
|
| 237 | + return; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + echo '<tr>'; |
|
| 241 | + $this->single_row_columns( $item ); |
|
| 242 | + echo '</tr>'; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * Displays the customers name |
|
| 247 | + * |
|
| 248 | + * @param WP_User $customer customer. |
|
| 249 | + * @return string |
|
| 250 | + */ |
|
| 251 | + public function column_name( $customer ) { |
|
| 252 | + |
|
| 253 | + // Customer view URL. |
|
| 254 | + $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
| 255 | + $row_actions = $this->row_actions( |
|
| 256 | + array( |
|
| 257 | + 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
| 258 | + ) |
|
| 259 | + ); |
|
| 260 | + |
|
| 261 | + // Get user's address. |
|
| 262 | + $address = wpinv_get_user_address( $customer->ID ); |
|
| 263 | + |
|
| 264 | + // Customer email address. |
|
| 265 | + $email = sanitize_email( $customer->user_email ); |
|
| 266 | + |
|
| 267 | + // Customer's avatar. |
|
| 268 | + $avatar = esc_url( get_avatar_url( $email ) ); |
|
| 269 | + $avatar = "<img src='$avatar' height='32' width='32'/>"; |
|
| 270 | + |
|
| 271 | + // Customer's name. |
|
| 272 | + $name = esc_html( "{$address['first_name']} {$address['last_name']}" ); |
|
| 273 | + |
|
| 274 | + if ( empty( trim( $name ) ) ) { |
|
| 275 | + $name = esc_html( $address['display_name'] ); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + if ( ! empty( $name ) ) { |
|
| 279 | + $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + $email = "<div class='row-title'><a href='$view_url'>$email</a></div>"; |
|
| 283 | + |
|
| 284 | + return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>"; |
|
| 285 | + |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * Retrieve the table columns |
|
| 290 | + * |
|
| 291 | + * @since 1.0.19 |
|
| 292 | + * @return array $columns Array of all the list table columns |
|
| 293 | + */ |
|
| 294 | + public function get_columns() { |
|
| 295 | + |
|
| 296 | + $columns = array( |
|
| 297 | + 'name' => __( 'Name', 'invoicing' ), |
|
| 298 | + 'country' => __( 'Country', 'invoicing' ), |
|
| 299 | + 'state' => __( 'State', 'invoicing' ), |
|
| 300 | + 'city' => __( 'City', 'invoicing' ), |
|
| 301 | + 'zip' => __( 'ZIP', 'invoicing' ), |
|
| 302 | + 'address' => __( 'Address', 'invoicing' ), |
|
| 303 | + 'phone' => __( 'Phone', 'invoicing' ), |
|
| 304 | + 'company' => __( 'Company', 'invoicing' ), |
|
| 305 | + 'invoices' => __( 'Invoices', 'invoicing' ), |
|
| 306 | + 'total' => __( 'Total Spend', 'invoicing' ), |
|
| 307 | + 'signup' => __( 'Date created', 'invoicing' ), |
|
| 308 | + ); |
|
| 309 | + return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
| 310 | + |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * Retrieve the current page number |
|
| 315 | + * |
|
| 316 | + * @since 1.0.19 |
|
| 317 | + * @return int Current page number |
|
| 318 | + */ |
|
| 319 | + public function get_paged() { |
|
| 320 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * Returns bulk actions. |
|
| 325 | + * |
|
| 326 | + * @since 1.0.19 |
|
| 327 | + * @return void |
|
| 328 | + */ |
|
| 329 | + public function bulk_actions( $which = '' ) { |
|
| 330 | + return array(); |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * Prepares the display query |
|
| 335 | + */ |
|
| 336 | + public function prepare_query() { |
|
| 337 | + global $wpdb; |
|
| 338 | + |
|
| 339 | + $post_types = ''; |
|
| 340 | + |
|
| 341 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 342 | + $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + $post_types = rtrim( $post_types, ' OR' ); |
|
| 346 | + |
|
| 347 | + // Maybe search. |
|
| 348 | + if ( ! empty( $_POST['s'] ) ) { |
|
| 349 | + $users = get_users( |
|
| 350 | + array( |
|
| 351 | + 'search' => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*', |
|
| 352 | + 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
| 353 | + 'fields' => 'ID', |
|
| 354 | + ) |
|
| 355 | + ); |
|
| 356 | + |
|
| 357 | + $users = implode( ', ', $users ); |
|
| 358 | + $post_types = "($post_types) AND ( post_author IN ( $users ) )"; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + // Users with invoices. |
|
| 362 | + $customers = $wpdb->get_col( |
|
| 363 | + $wpdb->prepare( |
|
| 364 | + "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d", |
|
| 365 | + $this->get_paged() * 10 - 10, |
|
| 366 | + $this->per_page |
|
| 367 | + ) |
|
| 368 | + ); |
|
| 369 | + |
|
| 370 | + $this->items = $customers; |
|
| 371 | + $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" ); |
|
| 372 | + |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * Setup the final data for the table |
|
| 377 | + * |
|
| 378 | + * @since 1.0.19 |
|
| 379 | + * @return void |
|
| 380 | + */ |
|
| 381 | + public function prepare_items() { |
|
| 382 | + $columns = $this->get_columns(); |
|
| 383 | + $hidden = array(); // No hidden columns |
|
| 384 | + $sortable = $this->get_sortable_columns(); |
|
| 385 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 386 | + $this->prepare_query(); |
|
| 387 | + |
|
| 388 | + $this->set_pagination_args( |
|
| 389 | + array( |
|
| 390 | + 'total_items' => $this->total, |
|
| 391 | + 'per_page' => $this->per_page, |
|
| 392 | + 'total_pages' => ceil( $this->total / $this->per_page ), |
|
| 393 | + ) |
|
| 394 | + ); |
|
| 395 | + |
|
| 396 | + } |
|
| 397 | 397 | } |
@@ -5,12 +5,12 @@ discard block |
||
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | // Exit if accessed directly |
| 8 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 8 | +if (!defined('ABSPATH')) { |
|
| 9 | 9 | exit; |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | // Load WP_List_Table if not loaded |
| 13 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
| 13 | +if (!class_exists('WP_List_Table')) { |
|
| 14 | 14 | require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -76,9 +76,9 @@ discard block |
||
| 76 | 76 | * |
| 77 | 77 | * @return string Column Name |
| 78 | 78 | */ |
| 79 | - public function column_default( $item, $column_name ) { |
|
| 80 | - $value = esc_html( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
| 81 | - return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
| 79 | + public function column_default($item, $column_name) { |
|
| 80 | + $value = esc_html(get_user_meta($item->ID, '_wpinv_' . $column_name, true)); |
|
| 81 | + return apply_filters('wpinv_customers_table_column' . $column_name, $value, $item); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -90,12 +90,12 @@ discard block |
||
| 90 | 90 | * |
| 91 | 91 | * @return string Column Name |
| 92 | 92 | */ |
| 93 | - public function column_country( $user ) { |
|
| 94 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 95 | - if ( $country ) { |
|
| 96 | - $country = wpinv_country_name( $country ); |
|
| 93 | + public function column_country($user) { |
|
| 94 | + $country = wpinv_sanitize_country($user->_wpinv_country); |
|
| 95 | + if ($country) { |
|
| 96 | + $country = wpinv_country_name($country); |
|
| 97 | 97 | } |
| 98 | - return esc_html( $country ); |
|
| 98 | + return esc_html($country); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -107,14 +107,14 @@ discard block |
||
| 107 | 107 | * |
| 108 | 108 | * @return string Column Name |
| 109 | 109 | */ |
| 110 | - public function column_state( $user ) { |
|
| 111 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 110 | + public function column_state($user) { |
|
| 111 | + $country = wpinv_sanitize_country($user->_wpinv_country); |
|
| 112 | 112 | $state = $user->_wpinv_state; |
| 113 | - if ( $state ) { |
|
| 114 | - $state = wpinv_state_name( $state, $country ); |
|
| 113 | + if ($state) { |
|
| 114 | + $state = wpinv_state_name($state, $country); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - return esc_html( $state ); |
|
| 117 | + return esc_html($state); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -126,8 +126,8 @@ discard block |
||
| 126 | 126 | * |
| 127 | 127 | * @return string Column Name |
| 128 | 128 | */ |
| 129 | - public function column_signup( $user ) { |
|
| 130 | - return getpaid_format_date_value( $user->user_registered ); |
|
| 129 | + public function column_signup($user) { |
|
| 130 | + return getpaid_format_date_value($user->user_registered); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -139,8 +139,8 @@ discard block |
||
| 139 | 139 | * |
| 140 | 140 | * @return string Column Name |
| 141 | 141 | */ |
| 142 | - public function column_total( $user ) { |
|
| 143 | - return wpinv_price( $this->column_total_raw( $user ) ); |
|
| 142 | + public function column_total($user) { |
|
| 143 | + return wpinv_price($this->column_total_raw($user)); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | * |
| 153 | 153 | * @return float |
| 154 | 154 | */ |
| 155 | - public function column_total_raw( $user ) { |
|
| 155 | + public function column_total_raw($user) { |
|
| 156 | 156 | |
| 157 | 157 | $args = array( |
| 158 | 158 | 'data' => array( |
@@ -168,17 +168,17 @@ discard block |
||
| 168 | 168 | |
| 169 | 169 | 'author' => array( |
| 170 | 170 | 'type' => 'post_data', |
| 171 | - 'value' => absint( $user->ID ), |
|
| 171 | + 'value' => absint($user->ID), |
|
| 172 | 172 | 'key' => 'posts.post_author', |
| 173 | 173 | 'operator' => '=', |
| 174 | 174 | ), |
| 175 | 175 | |
| 176 | 176 | ), |
| 177 | 177 | 'query_type' => 'get_var', |
| 178 | - 'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ), |
|
| 178 | + 'invoice_status' => array('wpi-renewal', 'wpi-processing', 'publish'), |
|
| 179 | 179 | ); |
| 180 | 180 | |
| 181 | - return wpinv_round_amount( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 181 | + return wpinv_round_amount(GetPaid_Reports_Helper::get_invoice_report_data($args)); |
|
| 182 | 182 | |
| 183 | 183 | } |
| 184 | 184 | |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | * |
| 192 | 192 | * @return string Column Name |
| 193 | 193 | */ |
| 194 | - public function column_invoices( $user ) { |
|
| 194 | + public function column_invoices($user) { |
|
| 195 | 195 | |
| 196 | 196 | $args = array( |
| 197 | 197 | 'data' => array( |
@@ -208,19 +208,19 @@ discard block |
||
| 208 | 208 | |
| 209 | 209 | 'author' => array( |
| 210 | 210 | 'type' => 'post_data', |
| 211 | - 'value' => absint( $user->ID ), |
|
| 211 | + 'value' => absint($user->ID), |
|
| 212 | 212 | 'key' => 'posts.post_author', |
| 213 | 213 | 'operator' => '=', |
| 214 | 214 | ), |
| 215 | 215 | |
| 216 | 216 | ), |
| 217 | 217 | 'query_type' => 'get_var', |
| 218 | - 'invoice_status' => array_keys( wpinv_get_invoice_statuses() ), |
|
| 218 | + 'invoice_status' => array_keys(wpinv_get_invoice_statuses()), |
|
| 219 | 219 | ); |
| 220 | 220 | |
| 221 | - $value = absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 222 | - $url = add_query_arg( array( 'post_type' => 'wpi_invoice', 'author' => $user->ID ), admin_url( 'edit.php' ) ); |
|
| 223 | - return empty( $value ) ? '0' : '<a href="' . esc_url( $url ) . '">' . absint( $value ) . '</a>'; |
|
| 221 | + $value = absint(GetPaid_Reports_Helper::get_invoice_report_data($args)); |
|
| 222 | + $url = add_query_arg(array('post_type' => 'wpi_invoice', 'author' => $user->ID), admin_url('edit.php')); |
|
| 223 | + return empty($value) ? '0' : '<a href="' . esc_url($url) . '">' . absint($value) . '</a>'; |
|
| 224 | 224 | |
| 225 | 225 | } |
| 226 | 226 | |
@@ -230,15 +230,15 @@ discard block |
||
| 230 | 230 | * |
| 231 | 231 | * @param int $item The user id. |
| 232 | 232 | */ |
| 233 | - public function single_row( $item ) { |
|
| 234 | - $item = get_user_by( 'id', $item ); |
|
| 233 | + public function single_row($item) { |
|
| 234 | + $item = get_user_by('id', $item); |
|
| 235 | 235 | |
| 236 | - if ( empty( $item ) ) { |
|
| 236 | + if (empty($item)) { |
|
| 237 | 237 | return; |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | echo '<tr>'; |
| 241 | - $this->single_row_columns( $item ); |
|
| 241 | + $this->single_row_columns($item); |
|
| 242 | 242 | echo '</tr>'; |
| 243 | 243 | } |
| 244 | 244 | |
@@ -248,34 +248,34 @@ discard block |
||
| 248 | 248 | * @param WP_User $customer customer. |
| 249 | 249 | * @return string |
| 250 | 250 | */ |
| 251 | - public function column_name( $customer ) { |
|
| 251 | + public function column_name($customer) { |
|
| 252 | 252 | |
| 253 | 253 | // Customer view URL. |
| 254 | - $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
| 254 | + $view_url = esc_url(add_query_arg('user_id', $customer->ID, admin_url('user-edit.php'))); |
|
| 255 | 255 | $row_actions = $this->row_actions( |
| 256 | 256 | array( |
| 257 | - 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
| 257 | + 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __('Edit Details', 'invoicing') . '</a>', |
|
| 258 | 258 | ) |
| 259 | 259 | ); |
| 260 | 260 | |
| 261 | 261 | // Get user's address. |
| 262 | - $address = wpinv_get_user_address( $customer->ID ); |
|
| 262 | + $address = wpinv_get_user_address($customer->ID); |
|
| 263 | 263 | |
| 264 | 264 | // Customer email address. |
| 265 | - $email = sanitize_email( $customer->user_email ); |
|
| 265 | + $email = sanitize_email($customer->user_email); |
|
| 266 | 266 | |
| 267 | 267 | // Customer's avatar. |
| 268 | - $avatar = esc_url( get_avatar_url( $email ) ); |
|
| 268 | + $avatar = esc_url(get_avatar_url($email)); |
|
| 269 | 269 | $avatar = "<img src='$avatar' height='32' width='32'/>"; |
| 270 | 270 | |
| 271 | 271 | // Customer's name. |
| 272 | - $name = esc_html( "{$address['first_name']} {$address['last_name']}" ); |
|
| 272 | + $name = esc_html("{$address['first_name']} {$address['last_name']}"); |
|
| 273 | 273 | |
| 274 | - if ( empty( trim( $name ) ) ) { |
|
| 275 | - $name = esc_html( $address['display_name'] ); |
|
| 274 | + if (empty(trim($name))) { |
|
| 275 | + $name = esc_html($address['display_name']); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - if ( ! empty( $name ) ) { |
|
| 278 | + if (!empty($name)) { |
|
| 279 | 279 | $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
| 280 | 280 | } |
| 281 | 281 | |
@@ -294,19 +294,19 @@ discard block |
||
| 294 | 294 | public function get_columns() { |
| 295 | 295 | |
| 296 | 296 | $columns = array( |
| 297 | - 'name' => __( 'Name', 'invoicing' ), |
|
| 298 | - 'country' => __( 'Country', 'invoicing' ), |
|
| 299 | - 'state' => __( 'State', 'invoicing' ), |
|
| 300 | - 'city' => __( 'City', 'invoicing' ), |
|
| 301 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
| 302 | - 'address' => __( 'Address', 'invoicing' ), |
|
| 303 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
| 304 | - 'company' => __( 'Company', 'invoicing' ), |
|
| 305 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
| 306 | - 'total' => __( 'Total Spend', 'invoicing' ), |
|
| 307 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
| 297 | + 'name' => __('Name', 'invoicing'), |
|
| 298 | + 'country' => __('Country', 'invoicing'), |
|
| 299 | + 'state' => __('State', 'invoicing'), |
|
| 300 | + 'city' => __('City', 'invoicing'), |
|
| 301 | + 'zip' => __('ZIP', 'invoicing'), |
|
| 302 | + 'address' => __('Address', 'invoicing'), |
|
| 303 | + 'phone' => __('Phone', 'invoicing'), |
|
| 304 | + 'company' => __('Company', 'invoicing'), |
|
| 305 | + 'invoices' => __('Invoices', 'invoicing'), |
|
| 306 | + 'total' => __('Total Spend', 'invoicing'), |
|
| 307 | + 'signup' => __('Date created', 'invoicing'), |
|
| 308 | 308 | ); |
| 309 | - return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
| 309 | + return apply_filters('wpinv_customers_table_columns', $columns); |
|
| 310 | 310 | |
| 311 | 311 | } |
| 312 | 312 | |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | * @return int Current page number |
| 318 | 318 | */ |
| 319 | 319 | public function get_paged() { |
| 320 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 320 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | /** |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | * @since 1.0.19 |
| 327 | 327 | * @return void |
| 328 | 328 | */ |
| 329 | - public function bulk_actions( $which = '' ) { |
|
| 329 | + public function bulk_actions($which = '') { |
|
| 330 | 330 | return array(); |
| 331 | 331 | } |
| 332 | 332 | |
@@ -338,23 +338,23 @@ discard block |
||
| 338 | 338 | |
| 339 | 339 | $post_types = ''; |
| 340 | 340 | |
| 341 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 342 | - $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
| 341 | + foreach (array_keys(getpaid_get_invoice_post_types()) as $post_type) { |
|
| 342 | + $post_types .= $wpdb->prepare('post_type=%s OR ', $post_type); |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | - $post_types = rtrim( $post_types, ' OR' ); |
|
| 345 | + $post_types = rtrim($post_types, ' OR'); |
|
| 346 | 346 | |
| 347 | 347 | // Maybe search. |
| 348 | - if ( ! empty( $_POST['s'] ) ) { |
|
| 348 | + if (!empty($_POST['s'])) { |
|
| 349 | 349 | $users = get_users( |
| 350 | 350 | array( |
| 351 | - 'search' => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*', |
|
| 352 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
| 351 | + 'search' => '*' . sanitize_text_field(urldecode($_POST['s'])) . '*', |
|
| 352 | + 'search_columns' => array('user_login', 'user_email', 'display_name'), |
|
| 353 | 353 | 'fields' => 'ID', |
| 354 | 354 | ) |
| 355 | 355 | ); |
| 356 | 356 | |
| 357 | - $users = implode( ', ', $users ); |
|
| 357 | + $users = implode(', ', $users); |
|
| 358 | 358 | $post_types = "($post_types) AND ( post_author IN ( $users ) )"; |
| 359 | 359 | } |
| 360 | 360 | |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | ); |
| 369 | 369 | |
| 370 | 370 | $this->items = $customers; |
| 371 | - $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" ); |
|
| 371 | + $this->total = (int) $wpdb->get_var("SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types"); |
|
| 372 | 372 | |
| 373 | 373 | } |
| 374 | 374 | |
@@ -382,14 +382,14 @@ discard block |
||
| 382 | 382 | $columns = $this->get_columns(); |
| 383 | 383 | $hidden = array(); // No hidden columns |
| 384 | 384 | $sortable = $this->get_sortable_columns(); |
| 385 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 385 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
| 386 | 386 | $this->prepare_query(); |
| 387 | 387 | |
| 388 | 388 | $this->set_pagination_args( |
| 389 | 389 | array( |
| 390 | 390 | 'total_items' => $this->total, |
| 391 | 391 | 'per_page' => $this->per_page, |
| 392 | - 'total_pages' => ceil( $this->total / $this->per_page ), |
|
| 392 | + 'total_pages' => ceil($this->total / $this->per_page), |
|
| 393 | 393 | ) |
| 394 | 394 | ); |
| 395 | 395 | |