@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | $tax_rates = GetPaid_Tax::get_all_tax_rates(); |
10 | 10 | $dummy_rate = array( |
@@ -13,12 +13,12 @@ discard block |
||
13 | 13 | 'global' => true, |
14 | 14 | 'rate' => wpinv_get_default_tax_rate(), |
15 | 15 | 'reduced_rate' => 5, |
16 | - 'name' => __( 'VAT', 'invoicing' ), |
|
16 | + 'name' => __('VAT', 'invoicing'), |
|
17 | 17 | ); |
18 | 18 | |
19 | 19 | $reset_url = esc_url( |
20 | 20 | wp_nonce_url( |
21 | - add_query_arg( 'getpaid-admin-action', 'reset_tax_rates' ), |
|
21 | + add_query_arg('getpaid-admin-action', 'reset_tax_rates'), |
|
22 | 22 | 'getpaid-nonce', |
23 | 23 | 'getpaid-nonce' |
24 | 24 | ) |
@@ -27,34 +27,34 @@ discard block |
||
27 | 27 | ?> |
28 | 28 | <div class="table-responsive"> |
29 | 29 | <table id="wpinv_tax_rates" class="widefat fixed table"> |
30 | - <caption><?php echo esc_html_e( 'Enter tax rates for specific regions.', 'invoicing' ); ?></caption> |
|
30 | + <caption><?php echo esc_html_e('Enter tax rates for specific regions.', 'invoicing'); ?></caption> |
|
31 | 31 | |
32 | 32 | <thead> |
33 | 33 | <tr class="table-light"> |
34 | 34 | |
35 | 35 | <th scope="col" class="border-bottom border-top"> |
36 | - <?php _e( 'Country', 'invoicing' ); ?> |
|
37 | - <?php echo getpaid_get_help_tip( __( 'Optionally limit this tax rate to a specific country.', 'invoicing' ), 'position-static' ); ?> |
|
36 | + <?php _e('Country', 'invoicing'); ?> |
|
37 | + <?php echo getpaid_get_help_tip(__('Optionally limit this tax rate to a specific country.', 'invoicing'), 'position-static'); ?> |
|
38 | 38 | </th> |
39 | 39 | |
40 | 40 | <th scope="col" class="border-bottom border-top"> |
41 | - <?php _e( 'State', 'invoicing' ); ?> |
|
42 | - <?php echo getpaid_get_help_tip( __( 'Separate state codes using a comma or leave blank to apply country wide.', 'invoicing' ), 'position-static' ); ?> |
|
41 | + <?php _e('State', 'invoicing'); ?> |
|
42 | + <?php echo getpaid_get_help_tip(__('Separate state codes using a comma or leave blank to apply country wide.', 'invoicing'), 'position-static'); ?> |
|
43 | 43 | </th> |
44 | 44 | |
45 | 45 | <th scope="col" class="border-bottom border-top"> |
46 | - <?php _e( 'Standard Rate %', 'invoicing' ); ?> |
|
47 | - <?php echo getpaid_get_help_tip( __( 'The tax rate (percentage) to charge on items that use the "Standard rate" tax class.', 'invoicing' ), 'position-static' ); ?> |
|
46 | + <?php _e('Standard Rate %', 'invoicing'); ?> |
|
47 | + <?php echo getpaid_get_help_tip(__('The tax rate (percentage) to charge on items that use the "Standard rate" tax class.', 'invoicing'), 'position-static'); ?> |
|
48 | 48 | </th> |
49 | 49 | |
50 | 50 | <th scope="col" class="border-bottom border-top"> |
51 | - <?php _e( 'Reduced Rate %', 'invoicing' ); ?> |
|
52 | - <?php echo getpaid_get_help_tip( __( 'The tax rate (percentage) to charge on items that use the "Reduced rate" tax class.', 'invoicing' ), 'position-static' ); ?> |
|
51 | + <?php _e('Reduced Rate %', 'invoicing'); ?> |
|
52 | + <?php echo getpaid_get_help_tip(__('The tax rate (percentage) to charge on items that use the "Reduced rate" tax class.', 'invoicing'), 'position-static'); ?> |
|
53 | 53 | </th> |
54 | 54 | |
55 | 55 | <th scope="col" class="border-bottom border-top"> |
56 | - <?php _e( 'Tax Name', 'invoicing' ); ?> |
|
57 | - <?php echo getpaid_get_help_tip( __( 'The name of this tax, e.g VAT.', 'invoicing' ), 'position-static' ); ?> |
|
56 | + <?php _e('Tax Name', 'invoicing'); ?> |
|
57 | + <?php echo getpaid_get_help_tip(__('The name of this tax, e.g VAT.', 'invoicing'), 'position-static'); ?> |
|
58 | 58 | </th> |
59 | 59 | |
60 | 60 | <th scope="col" class="border-bottom border-top" style="width:32px"> </th> |
@@ -63,19 +63,19 @@ discard block |
||
63 | 63 | </thead> |
64 | 64 | |
65 | 65 | <tbody> |
66 | - <?php array_walk( $tax_rates, 'wpinv_tax_rate_callback' ); ?> |
|
66 | + <?php array_walk($tax_rates, 'wpinv_tax_rate_callback'); ?> |
|
67 | 67 | </tbody> |
68 | 68 | |
69 | 69 | <tfoot> |
70 | 70 | <tr class="table-light"> |
71 | 71 | <td colspan="6" class="border-top"> |
72 | 72 | |
73 | - <button type="button" class="button button-secondary wpinv_add_tax_rate" aria-label="<?php esc_attr_e( 'Add Tax Rate', 'invoicing' ); ?>"> |
|
74 | - <span><?php _e( 'Add Tax Rate', 'invoicing' ); ?></span> |
|
73 | + <button type="button" class="button button-secondary wpinv_add_tax_rate" aria-label="<?php esc_attr_e('Add Tax Rate', 'invoicing'); ?>"> |
|
74 | + <span><?php _e('Add Tax Rate', 'invoicing'); ?></span> |
|
75 | 75 | </button> |
76 | 76 | |
77 | - <a href="<?php echo $reset_url; ?>" class="button button-secondary wpinv_reset_tax_rates" aria-label="<?php esc_attr_e( 'Reset Tax Rates', 'invoicing' ); ?>"> |
|
78 | - <span><?php _e( 'Reset Tax Rates', 'invoicing' ); ?></span> |
|
77 | + <a href="<?php echo $reset_url; ?>" class="button button-secondary wpinv_reset_tax_rates" aria-label="<?php esc_attr_e('Reset Tax Rates', 'invoicing'); ?>"> |
|
78 | + <span><?php _e('Reset Tax Rates', 'invoicing'); ?></span> |
|
79 | 79 | </a> |
80 | 80 | </td> |
81 | 81 | </tr> |
@@ -84,6 +84,6 @@ discard block |
||
84 | 84 | </div> |
85 | 85 | |
86 | 86 | <script type="text/html" id="tmpl-wpinv-tax-rate-row"> |
87 | - <?php echo wpinv_tax_rate_callback( $dummy_rate, 0, false ); ?> |
|
87 | + <?php echo wpinv_tax_rate_callback($dummy_rate, 0, false); ?> |
|
88 | 88 | </script> |
89 | 89 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @var array $tax_rate |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | ?> |
12 | 12 | |
@@ -18,54 +18,54 @@ discard block |
||
18 | 18 | $country = aui()->select( |
19 | 19 | array( |
20 | 20 | 'options' => array_merge( |
21 | - array( '' => __( 'All Countries', 'invoicing' ) ), |
|
21 | + array('' => __('All Countries', 'invoicing')), |
|
22 | 22 | wpinv_get_country_list() |
23 | 23 | ), |
24 | 24 | 'name' => "tax_rates[$key][country]", |
25 | - 'id' => uniqid( 'tax_rate_country' ), |
|
26 | - 'value' => sanitize_text_field( $tax_rate['country'] ), |
|
27 | - 'label' => __( 'Country', 'invoicing' ), |
|
25 | + 'id' => uniqid('tax_rate_country'), |
|
26 | + 'value' => sanitize_text_field($tax_rate['country']), |
|
27 | + 'label' => __('Country', 'invoicing'), |
|
28 | 28 | 'class' => 'wpinv_country', |
29 | 29 | 'no_wrap' => true, |
30 | 30 | ) |
31 | 31 | ); |
32 | 32 | |
33 | - echo str_replace( 'custom-select', '', $country ); |
|
33 | + echo str_replace('custom-select', '', $country); |
|
34 | 34 | ?> |
35 | 35 | </td> |
36 | 36 | |
37 | 37 | <td class="wpinv_tax_state"> |
38 | 38 | |
39 | 39 | <label class="w-100"> |
40 | - <span class="screen-reader-text"><?php _e( 'States', 'invoicing' ); ?></span> |
|
41 | - <input type="text" placeholder="<?php esc_attr_e( 'Apply to whole country', 'invoicing' ); ?>" name="tax_rates[<?php echo $key ?>][state]" value="<?php echo empty( $tax_rate['global'] ) ? sanitize_text_field( $tax_rate['state'] ) : ''; ?>"/> |
|
40 | + <span class="screen-reader-text"><?php _e('States', 'invoicing'); ?></span> |
|
41 | + <input type="text" placeholder="<?php esc_attr_e('Apply to whole country', 'invoicing'); ?>" name="tax_rates[<?php echo $key ?>][state]" value="<?php echo empty($tax_rate['global']) ? sanitize_text_field($tax_rate['state']) : ''; ?>"/> |
|
42 | 42 | </label> |
43 | 43 | |
44 | 44 | </td> |
45 | 45 | |
46 | 46 | <td class="wpinv_standard_rate"> |
47 | 47 | <label class="w-100"> |
48 | - <span class="screen-reader-text"><?php _e( 'Standard Rate', 'invoicing' ); ?></span> |
|
49 | - <input type="number" step="any" min="0" max="99" name="tax_rates[<?php echo $key ?>][rate]" value="<?php echo wpinv_sanitize_amount( $tax_rate['rate'] ); ?>"/> |
|
48 | + <span class="screen-reader-text"><?php _e('Standard Rate', 'invoicing'); ?></span> |
|
49 | + <input type="number" step="any" min="0" max="99" name="tax_rates[<?php echo $key ?>][rate]" value="<?php echo wpinv_sanitize_amount($tax_rate['rate']); ?>"/> |
|
50 | 50 | </label> |
51 | 51 | </td> |
52 | 52 | |
53 | 53 | <td class="wpinv_reduced_rate"> |
54 | 54 | <label class="w-100"> |
55 | - <span class="screen-reader-text"><?php _e( 'Reduced Rate', 'invoicing' ); ?></span> |
|
56 | - <input type="number" step="any" min="0" max="99" name="tax_rates[<?php echo $key ?>][reduced_rate]" value="<?php echo wpinv_sanitize_amount( $tax_rate['reduced_rate'] ); ?>"/> |
|
55 | + <span class="screen-reader-text"><?php _e('Reduced Rate', 'invoicing'); ?></span> |
|
56 | + <input type="number" step="any" min="0" max="99" name="tax_rates[<?php echo $key ?>][reduced_rate]" value="<?php echo wpinv_sanitize_amount($tax_rate['reduced_rate']); ?>"/> |
|
57 | 57 | </label> |
58 | 58 | </td> |
59 | 59 | |
60 | 60 | <td class="wpinv_tax_name"> |
61 | 61 | <label class="w-100"> |
62 | - <span class="screen-reader-text"><?php _e( 'Tax Name', 'invoicing' ); ?></span> |
|
63 | - <input type="text" name="tax_rates[<?php echo $key ?>][name]" value="<?php echo sanitize_text_field( $tax_rate['name'] ); ?>"/> |
|
62 | + <span class="screen-reader-text"><?php _e('Tax Name', 'invoicing'); ?></span> |
|
63 | + <input type="text" name="tax_rates[<?php echo $key ?>][name]" value="<?php echo sanitize_text_field($tax_rate['name']); ?>"/> |
|
64 | 64 | </label> |
65 | 65 | </td> |
66 | 66 | |
67 | 67 | <td class="wpinv_tax_remove"> |
68 | - <button type="button" class="close wpinv_remove_tax_rate" aria-label="<?php esc_attr_e( 'Delete', 'invoicing' ); ?>" title="<?php esc_attr_e( 'Delete', 'invoicing' ); ?>"> |
|
68 | + <button type="button" class="close wpinv_remove_tax_rate" aria-label="<?php esc_attr_e('Delete', 'invoicing'); ?>" title="<?php esc_attr_e('Delete', 'invoicing'); ?>"> |
|
69 | 69 | <span aria-hidden="true">×</span> |
70 | 70 | </button> |
71 | 71 | </td> |
@@ -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 | * The main admin class. |
@@ -37,13 +37,13 @@ discard block |
||
37 | 37 | /** |
38 | 38 | * Class constructor. |
39 | 39 | */ |
40 | - public function __construct(){ |
|
40 | + public function __construct() { |
|
41 | 41 | |
42 | - $this->admin_path = plugin_dir_path( __FILE__ ); |
|
43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
42 | + $this->admin_path = plugin_dir_path(__FILE__); |
|
43 | + $this->admin_url = plugins_url('/', __FILE__); |
|
44 | 44 | $this->reports = new GetPaid_Reports(); |
45 | 45 | |
46 | - if ( is_admin() ) { |
|
46 | + if (is_admin()) { |
|
47 | 47 | $this->init_admin_hooks(); |
48 | 48 | } |
49 | 49 | |
@@ -54,16 +54,16 @@ discard block |
||
54 | 54 | * |
55 | 55 | */ |
56 | 56 | private function init_admin_hooks() { |
57 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) ); |
|
58 | - add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
|
59 | - add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
|
60 | - add_action( 'admin_init', array( $this, 'activation_redirect') ); |
|
61 | - add_action( 'admin_init', array( $this, 'maybe_do_admin_action') ); |
|
62 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
64 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
65 | - add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
|
66 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
57 | + add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts')); |
|
58 | + add_filter('admin_body_class', array($this, 'admin_body_class')); |
|
59 | + add_action('admin_init', array($this, 'init_ayecode_connect_helper')); |
|
60 | + add_action('admin_init', array($this, 'activation_redirect')); |
|
61 | + add_action('admin_init', array($this, 'maybe_do_admin_action')); |
|
62 | + add_action('admin_notices', array($this, 'show_notices')); |
|
63 | + add_action('getpaid_authenticated_admin_action_send_invoice', array($this, 'send_customer_invoice')); |
|
64 | + add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder')); |
|
65 | + add_action('getpaid_authenticated_admin_action_reset_tax_rates', array($this, 'admin_reset_tax_rates')); |
|
66 | + do_action('getpaid_init_admin_hooks', $this); |
|
67 | 67 | |
68 | 68 | } |
69 | 69 | |
@@ -74,45 +74,45 @@ discard block |
||
74 | 74 | public function enqeue_scripts() { |
75 | 75 | global $current_screen, $pagenow; |
76 | 76 | |
77 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
77 | + $page = isset($_GET['page']) ? $_GET['page'] : ''; |
|
78 | 78 | $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
79 | 79 | |
80 | - if ( ! empty( $current_screen->post_type ) ) { |
|
80 | + if (!empty($current_screen->post_type)) { |
|
81 | 81 | $page = $current_screen->post_type; |
82 | 82 | } |
83 | 83 | |
84 | 84 | // General styles. |
85 | - if ( false !== stripos( $page, 'wpi' ) ) { |
|
85 | + if (false !== stripos($page, 'wpi')) { |
|
86 | 86 | |
87 | 87 | // Styles. |
88 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' ); |
|
89 | - wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version ); |
|
90 | - wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' ); |
|
91 | - wp_enqueue_style( 'wp_enqueue_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
92 | - wp_enqueue_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16' ); |
|
88 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css'); |
|
89 | + wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version); |
|
90 | + wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all'); |
|
91 | + wp_enqueue_style('wp_enqueue_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
92 | + wp_enqueue_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16'); |
|
93 | 93 | |
94 | 94 | // Scripts. |
95 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '4.0.13', true ); |
|
96 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION ); |
|
95 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '4.0.13', true); |
|
96 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION); |
|
97 | 97 | |
98 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' ); |
|
99 | - wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip', 'wp-color-picker', 'jquery-ui-datepicker' ), $version ); |
|
100 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) ); |
|
98 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js'); |
|
99 | + wp_enqueue_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip', 'wp-color-picker', 'jquery-ui-datepicker'), $version); |
|
100 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18())); |
|
101 | 101 | |
102 | 102 | } |
103 | 103 | |
104 | 104 | // Payment form scripts. |
105 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
105 | + if ('wpi_payment_form' == $page && $editing) { |
|
106 | 106 | $this->load_payment_form_scripts(); |
107 | 107 | } |
108 | 108 | |
109 | - if ( $page == 'wpinv-subscriptions' ) { |
|
110 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
111 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
109 | + if ($page == 'wpinv-subscriptions') { |
|
110 | + wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION); |
|
111 | + wp_enqueue_script('wpinv-sub-admin-script'); |
|
112 | 112 | } |
113 | 113 | |
114 | - if ( $page == 'wpinv-subscriptions' ) { |
|
115 | - wp_enqueue_script( 'postbox' ); |
|
114 | + if ($page == 'wpinv-subscriptions') { |
|
115 | + wp_enqueue_script('postbox'); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | } |
@@ -125,13 +125,13 @@ discard block |
||
125 | 125 | global $post; |
126 | 126 | |
127 | 127 | $i18n = array( |
128 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
129 | - 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
|
130 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
131 | - 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
|
132 | - 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
|
133 | - 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
|
134 | - 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
|
128 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
129 | + 'post_ID' => isset($post->ID) ? $post->ID : '', |
|
130 | + 'wpinv_nonce' => wp_create_nonce('wpinv-nonce'), |
|
131 | + 'add_invoice_note_nonce' => wp_create_nonce('add-invoice-note'), |
|
132 | + 'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'), |
|
133 | + 'invoice_item_nonce' => wp_create_nonce('invoice-item'), |
|
134 | + 'billing_details_nonce' => wp_create_nonce('get-billing-details'), |
|
135 | 135 | 'tax' => wpinv_tax_amount(), |
136 | 136 | 'discount' => 0, |
137 | 137 | 'currency_symbol' => wpinv_currency_symbol(), |
@@ -139,35 +139,35 @@ discard block |
||
139 | 139 | 'thousand_sep' => wpinv_thousands_separator(), |
140 | 140 | 'decimal_sep' => wpinv_decimal_separator(), |
141 | 141 | 'decimals' => wpinv_decimals(), |
142 | - 'save_invoice' => __( 'Save Invoice', 'invoicing' ), |
|
143 | - 'status_publish' => wpinv_status_nicename( 'publish' ), |
|
144 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
145 | - 'delete_tax_rate' => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ), |
|
146 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
147 | - 'FillBillingDetails' => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ), |
|
148 | - 'confirmCalcTotals' => __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ), |
|
149 | - 'AreYouSure' => __( 'Are you sure?', 'invoicing' ), |
|
150 | - 'errDeleteItem' => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ), |
|
151 | - 'delete_subscription' => __( 'Are you sure you want to delete this subscription?', 'invoicing' ), |
|
152 | - 'action_edit' => __( 'Edit', 'invoicing' ), |
|
153 | - 'action_cancel' => __( 'Cancel', 'invoicing' ), |
|
154 | - 'item_description' => __( 'Item Description', 'invoicing' ), |
|
155 | - 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
|
156 | - 'discount_description' => __( 'Discount Description', 'invoicing' ), |
|
157 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
142 | + 'save_invoice' => __('Save Invoice', 'invoicing'), |
|
143 | + 'status_publish' => wpinv_status_nicename('publish'), |
|
144 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
145 | + 'delete_tax_rate' => __('Are you sure you wish to delete this tax rate?', 'invoicing'), |
|
146 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
147 | + 'FillBillingDetails' => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'), |
|
148 | + 'confirmCalcTotals' => __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'), |
|
149 | + 'AreYouSure' => __('Are you sure?', 'invoicing'), |
|
150 | + 'errDeleteItem' => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'), |
|
151 | + 'delete_subscription' => __('Are you sure you want to delete this subscription?', 'invoicing'), |
|
152 | + 'action_edit' => __('Edit', 'invoicing'), |
|
153 | + 'action_cancel' => __('Cancel', 'invoicing'), |
|
154 | + 'item_description' => __('Item Description', 'invoicing'), |
|
155 | + 'invoice_description' => __('Invoice Description', 'invoicing'), |
|
156 | + 'discount_description' => __('Discount Description', 'invoicing'), |
|
157 | + 'searching' => __('Searching', 'invoicing'), |
|
158 | 158 | ); |
159 | 159 | |
160 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
160 | + if (!empty($post) && getpaid_is_invoice_post_type($post->post_type)) { |
|
161 | 161 | |
162 | - $invoice = new WPInv_Invoice( $post ); |
|
162 | + $invoice = new WPInv_Invoice($post); |
|
163 | 163 | $i18n['save_invoice'] = sprintf( |
164 | - __( 'Save %s', 'invoicing' ), |
|
165 | - ucfirst( $invoice->get_type() ) |
|
164 | + __('Save %s', 'invoicing'), |
|
165 | + ucfirst($invoice->get_type()) |
|
166 | 166 | ); |
167 | 167 | |
168 | 168 | $i18n['invoice_description'] = sprintf( |
169 | - __( '%s Description', 'invoicing' ), |
|
170 | - ucfirst( $invoice->get_type() ) |
|
169 | + __('%s Description', 'invoicing'), |
|
170 | + ucfirst($invoice->get_type()) |
|
171 | 171 | ); |
172 | 172 | |
173 | 173 | } |
@@ -181,30 +181,30 @@ discard block |
||
181 | 181 | protected function load_payment_form_scripts() { |
182 | 182 | global $post; |
183 | 183 | |
184 | - wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
|
185 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
186 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
184 | + wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION); |
|
185 | + wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION); |
|
186 | + wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION); |
|
187 | 187 | |
188 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
189 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
188 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js'); |
|
189 | + wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version); |
|
190 | 190 | |
191 | 191 | wp_localize_script( |
192 | 192 | 'wpinv-admin-payment-form-script', |
193 | 193 | 'wpinvPaymentFormAdmin', |
194 | 194 | array( |
195 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
196 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
195 | + 'elements' => wpinv_get_data('payment-form-elements'), |
|
196 | + 'form_elements' => getpaid_get_payment_form_elements($post->ID), |
|
197 | 197 | 'currency' => wpinv_currency_symbol(), |
198 | 198 | 'position' => wpinv_currency_position(), |
199 | 199 | 'decimals' => (int) wpinv_decimals(), |
200 | 200 | 'thousands_sep' => wpinv_thousands_separator(), |
201 | 201 | 'decimals_sep' => wpinv_decimal_separator(), |
202 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
202 | + 'form_items' => gepaid_get_form_items($post->ID), |
|
203 | 203 | 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
204 | 204 | ) |
205 | 205 | ); |
206 | 206 | |
207 | - wp_enqueue_script( 'wpinv-admin-payment-form-script' ); |
|
207 | + wp_enqueue_script('wpinv-admin-payment-form-script'); |
|
208 | 208 | |
209 | 209 | } |
210 | 210 | |
@@ -215,25 +215,25 @@ discard block |
||
215 | 215 | * @return string |
216 | 216 | * |
217 | 217 | */ |
218 | - public function admin_body_class( $classes ) { |
|
218 | + public function admin_body_class($classes) { |
|
219 | 219 | global $pagenow, $post, $current_screen; |
220 | 220 | |
221 | 221 | |
222 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
222 | + $page = isset($_GET['page']) ? $_GET['page'] : ''; |
|
223 | 223 | |
224 | - if ( ! empty( $current_screen->post_type ) ) { |
|
224 | + if (!empty($current_screen->post_type)) { |
|
225 | 225 | $page = $current_screen->post_type; |
226 | 226 | } |
227 | 227 | |
228 | - if ( false !== stripos( $page, 'wpi' ) ) { |
|
229 | - $classes .= ' wpi-' . sanitize_key( $page ); |
|
228 | + if (false !== stripos($page, 'wpi')) { |
|
229 | + $classes .= ' wpi-' . sanitize_key($page); |
|
230 | 230 | } |
231 | 231 | |
232 | - if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
|
232 | + if (in_array($page, wpinv_parse_list('wpi_invoice wpi_payment_form wpi_quote'))) { |
|
233 | 233 | $classes .= ' wpinv-cpt wpinv'; |
234 | 234 | } |
235 | 235 | |
236 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
236 | + if (getpaid_is_invoice_post_type($page)) { |
|
237 | 237 | $classes .= ' getpaid-is-invoice-cpt'; |
238 | 238 | } |
239 | 239 | |
@@ -243,19 +243,19 @@ discard block |
||
243 | 243 | /** |
244 | 244 | * Maybe show the AyeCode Connect Notice. |
245 | 245 | */ |
246 | - public function init_ayecode_connect_helper(){ |
|
246 | + public function init_ayecode_connect_helper() { |
|
247 | 247 | |
248 | 248 | new AyeCode_Connect_Helper( |
249 | 249 | array( |
250 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
251 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
252 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
253 | - 'connect_button' => __("Connect Site","invoicing"), |
|
254 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
255 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
256 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
250 | + 'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"), |
|
251 | + 'connect_external' => __("Please confirm you wish to connect your site?", "invoicing"), |
|
252 | + 'connect' => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"), |
|
253 | + 'connect_button' => __("Connect Site", "invoicing"), |
|
254 | + 'connecting_button' => __("Connecting...", "invoicing"), |
|
255 | + 'error_localhost' => __("This service will only work with a live domain, not a localhost.", "invoicing"), |
|
256 | + 'error' => __("Something went wrong, please refresh and try again.", "invoicing"), |
|
257 | 257 | ), |
258 | - array( 'wpi-addons' ) |
|
258 | + array('wpi-addons') |
|
259 | 259 | ); |
260 | 260 | |
261 | 261 | } |
@@ -266,19 +266,19 @@ discard block |
||
266 | 266 | public function activation_redirect() { |
267 | 267 | |
268 | 268 | // Bail if no activation redirect. |
269 | - if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) { |
|
269 | + if (!get_transient('_wpinv_activation_redirect') || wp_doing_ajax()) { |
|
270 | 270 | return; |
271 | 271 | } |
272 | 272 | |
273 | 273 | // Delete the redirect transient. |
274 | - delete_transient( '_wpinv_activation_redirect' ); |
|
274 | + delete_transient('_wpinv_activation_redirect'); |
|
275 | 275 | |
276 | 276 | // Bail if activating from network, or bulk |
277 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
277 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
278 | 278 | return; |
279 | 279 | } |
280 | 280 | |
281 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
281 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
282 | 282 | exit; |
283 | 283 | } |
284 | 284 | |
@@ -287,9 +287,9 @@ discard block |
||
287 | 287 | */ |
288 | 288 | public function maybe_do_admin_action() { |
289 | 289 | |
290 | - if ( wpinv_current_user_can_manage_invoicing() && isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
291 | - $key = sanitize_key( $_REQUEST['getpaid-admin-action'] ); |
|
292 | - do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST ); |
|
290 | + if (wpinv_current_user_can_manage_invoicing() && isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
291 | + $key = sanitize_key($_REQUEST['getpaid-admin-action']); |
|
292 | + do_action("getpaid_authenticated_admin_action_$key", $_REQUEST); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | } |
@@ -299,16 +299,16 @@ discard block |
||
299 | 299 | * |
300 | 300 | * @param array $args |
301 | 301 | */ |
302 | - public function send_customer_invoice( $args ) { |
|
303 | - $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
302 | + public function send_customer_invoice($args) { |
|
303 | + $sent = getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id'])); |
|
304 | 304 | |
305 | - if ( $sent ) { |
|
306 | - $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
305 | + if ($sent) { |
|
306 | + $this->show_success(__('Invoice was successfully sent to the customer', 'invoicing')); |
|
307 | 307 | } else { |
308 | - $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
308 | + $this->show_error(__('Could not sent the invoice to the customer', 'invoicing')); |
|
309 | 309 | } |
310 | 310 | |
311 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
311 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
312 | 312 | exit; |
313 | 313 | } |
314 | 314 | |
@@ -317,16 +317,16 @@ discard block |
||
317 | 317 | * |
318 | 318 | * @param array $args |
319 | 319 | */ |
320 | - public function send_customer_payment_reminder( $args ) { |
|
321 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
320 | + public function send_customer_payment_reminder($args) { |
|
321 | + $sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id'])); |
|
322 | 322 | |
323 | - if ( $sent ) { |
|
324 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
323 | + if ($sent) { |
|
324 | + $this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing')); |
|
325 | 325 | } else { |
326 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
326 | + $this->show_error(__('Could not sent payment reminder to the customer', 'invoicing')); |
|
327 | 327 | } |
328 | 328 | |
329 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
329 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
330 | 330 | exit; |
331 | 331 | } |
332 | 332 | |
@@ -336,8 +336,8 @@ discard block |
||
336 | 336 | */ |
337 | 337 | public function admin_reset_tax_rates() { |
338 | 338 | |
339 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
340 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
339 | + update_option('wpinv_tax_rates', wpinv_get_data('tax-rates')); |
|
340 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
341 | 341 | exit; |
342 | 342 | |
343 | 343 | } |
@@ -349,8 +349,8 @@ discard block |
||
349 | 349 | * @return array |
350 | 350 | */ |
351 | 351 | public function get_notices() { |
352 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
353 | - return is_array( $notices ) ? $notices : array(); |
|
352 | + $notices = get_option('wpinv_admin_notices'); |
|
353 | + return is_array($notices) ? $notices : array(); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | /** |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | * @since 1.0.19 |
361 | 361 | */ |
362 | 362 | public function clear_notices() { |
363 | - delete_option( 'wpinv_admin_notices' ); |
|
363 | + delete_option('wpinv_admin_notices'); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | /** |
@@ -369,16 +369,16 @@ discard block |
||
369 | 369 | * @access public |
370 | 370 | * @since 1.0.19 |
371 | 371 | */ |
372 | - public function save_notice( $type, $message ) { |
|
372 | + public function save_notice($type, $message) { |
|
373 | 373 | $notices = $this->get_notices(); |
374 | 374 | |
375 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
376 | - $notices[ $type ] = array(); |
|
375 | + if (empty($notices[$type]) || !is_array($notices[$type])) { |
|
376 | + $notices[$type] = array(); |
|
377 | 377 | } |
378 | 378 | |
379 | - $notices[ $type ][] = $message; |
|
379 | + $notices[$type][] = $message; |
|
380 | 380 | |
381 | - update_option( 'wpinv_admin_notices', $notices ); |
|
381 | + update_option('wpinv_admin_notices', $notices); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | /** |
@@ -388,8 +388,8 @@ discard block |
||
388 | 388 | * @access public |
389 | 389 | * @since 1.0.19 |
390 | 390 | */ |
391 | - public function show_success( $msg ) { |
|
392 | - $this->save_notice( 'success', $msg ); |
|
391 | + public function show_success($msg) { |
|
392 | + $this->save_notice('success', $msg); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | /** |
@@ -399,8 +399,8 @@ discard block |
||
399 | 399 | * @param string $msg The message to qeue. |
400 | 400 | * @since 1.0.19 |
401 | 401 | */ |
402 | - public function show_error( $msg ) { |
|
403 | - $this->save_notice( 'error', $msg ); |
|
402 | + public function show_error($msg) { |
|
403 | + $this->save_notice('error', $msg); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | /** |
@@ -410,8 +410,8 @@ discard block |
||
410 | 410 | * @param string $msg The message to qeue. |
411 | 411 | * @since 1.0.19 |
412 | 412 | */ |
413 | - public function show_warning( $msg ) { |
|
414 | - $this->save_notice( 'warning', $msg ); |
|
413 | + public function show_warning($msg) { |
|
414 | + $this->save_notice('warning', $msg); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | /** |
@@ -421,8 +421,8 @@ discard block |
||
421 | 421 | * @param string $msg The message to qeue. |
422 | 422 | * @since 1.0.19 |
423 | 423 | */ |
424 | - public function show_info( $msg ) { |
|
425 | - $this->save_notice( 'info', $msg ); |
|
424 | + public function show_info($msg) { |
|
425 | + $this->save_notice('info', $msg); |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | /** |
@@ -436,15 +436,15 @@ discard block |
||
436 | 436 | $notices = $this->get_notices(); |
437 | 437 | $this->clear_notices(); |
438 | 438 | |
439 | - foreach ( $notices as $type => $messages ) { |
|
439 | + foreach ($notices as $type => $messages) { |
|
440 | 440 | |
441 | - if ( ! is_array( $messages ) ) { |
|
441 | + if (!is_array($messages)) { |
|
442 | 442 | continue; |
443 | 443 | } |
444 | 444 | |
445 | - $type = sanitize_key( $type ); |
|
446 | - foreach ( $messages as $message ) { |
|
447 | - $message = wp_kses_post( $message ); |
|
445 | + $type = sanitize_key($type); |
|
446 | + foreach ($messages as $message) { |
|
447 | + $message = wp_kses_post($message); |
|
448 | 448 | echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
449 | 449 | } |
450 | 450 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 1.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Retrieves all default settings. |
@@ -16,13 +16,13 @@ discard block |
||
16 | 16 | function wpinv_get_settings() { |
17 | 17 | $defaults = array(); |
18 | 18 | |
19 | - foreach ( array_values( wpinv_get_registered_settings() ) as $tab_settings ) { |
|
19 | + foreach (array_values(wpinv_get_registered_settings()) as $tab_settings) { |
|
20 | 20 | |
21 | - foreach ( array_values( $tab_settings ) as $section_settings ) { |
|
21 | + foreach (array_values($tab_settings) as $section_settings) { |
|
22 | 22 | |
23 | - foreach ( $section_settings as $key => $setting ) { |
|
24 | - if ( isset( $setting['std'] ) ) { |
|
25 | - $defaults[ $key ] = $setting['std']; |
|
23 | + foreach ($section_settings as $key => $setting) { |
|
24 | + if (isset($setting['std'])) { |
|
25 | + $defaults[$key] = $setting['std']; |
|
26 | 26 | } |
27 | 27 | } |
28 | 28 | |
@@ -43,12 +43,12 @@ discard block |
||
43 | 43 | global $wpinv_options; |
44 | 44 | |
45 | 45 | // Try fetching the saved options. |
46 | - if ( ! is_array( $wpinv_options ) ) { |
|
47 | - $wpinv_options = get_option( 'wpinv_settings' ); |
|
46 | + if (!is_array($wpinv_options)) { |
|
47 | + $wpinv_options = get_option('wpinv_settings'); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | // If that fails, don't fetch the default settings to prevent a loop. |
51 | - if ( ! is_array( $wpinv_options ) ) { |
|
51 | + if (!is_array($wpinv_options)) { |
|
52 | 52 | $wpinv_options = array(); |
53 | 53 | } |
54 | 54 | |
@@ -62,13 +62,13 @@ discard block |
||
62 | 62 | * @param mixed $default The default value to use if the setting has not been set. |
63 | 63 | * @return mixed |
64 | 64 | */ |
65 | -function wpinv_get_option( $key = '', $default = false ) { |
|
65 | +function wpinv_get_option($key = '', $default = false) { |
|
66 | 66 | |
67 | 67 | $options = wpinv_get_options(); |
68 | - $value = isset( $options[ $key ] ) ? $options[ $key ] : $default; |
|
69 | - $value = apply_filters( 'wpinv_get_option', $value, $key, $default ); |
|
68 | + $value = isset($options[$key]) ? $options[$key] : $default; |
|
69 | + $value = apply_filters('wpinv_get_option', $value, $key, $default); |
|
70 | 70 | |
71 | - return apply_filters( 'wpinv_get_option_' . $key, $value, $key, $default ); |
|
71 | + return apply_filters('wpinv_get_option_' . $key, $value, $key, $default); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -77,11 +77,11 @@ discard block |
||
77 | 77 | * @param array $options the new options. |
78 | 78 | * @return bool |
79 | 79 | */ |
80 | -function wpinv_update_options( $options ) { |
|
80 | +function wpinv_update_options($options) { |
|
81 | 81 | global $wpinv_options; |
82 | 82 | |
83 | 83 | // update the option. |
84 | - if ( is_array( $options ) && update_option( 'wpinv_settings', $options ) ) { |
|
84 | + if (is_array($options) && update_option('wpinv_settings', $options)) { |
|
85 | 85 | $wpinv_options = $options; |
86 | 86 | return true; |
87 | 87 | } |
@@ -96,24 +96,24 @@ discard block |
||
96 | 96 | * @param mixed $value The setting value. |
97 | 97 | * @return bool |
98 | 98 | */ |
99 | -function wpinv_update_option( $key = '', $value = false ) { |
|
99 | +function wpinv_update_option($key = '', $value = false) { |
|
100 | 100 | |
101 | 101 | // If no key, exit. |
102 | - if ( empty( $key ) ) { |
|
102 | + if (empty($key)) { |
|
103 | 103 | return false; |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Maybe delete the option instead. |
107 | - if ( is_null( $value ) ) { |
|
108 | - return wpinv_delete_option( $key ); |
|
107 | + if (is_null($value)) { |
|
108 | + return wpinv_delete_option($key); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | // Prepare the new options. |
112 | 112 | $options = wpinv_get_options(); |
113 | - $options[ $key ] = apply_filters( 'wpinv_update_option', $value, $key ); |
|
113 | + $options[$key] = apply_filters('wpinv_update_option', $value, $key); |
|
114 | 114 | |
115 | 115 | // Save the new options. |
116 | - return wpinv_update_options( $options ); |
|
116 | + return wpinv_update_options($options); |
|
117 | 117 | |
118 | 118 | } |
119 | 119 | |
@@ -123,18 +123,18 @@ discard block |
||
123 | 123 | * @param string $key the setting key. |
124 | 124 | * @return bool |
125 | 125 | */ |
126 | -function wpinv_delete_option( $key = '' ) { |
|
126 | +function wpinv_delete_option($key = '') { |
|
127 | 127 | |
128 | 128 | // If no key, exit |
129 | - if ( empty( $key ) ) { |
|
129 | + if (empty($key)) { |
|
130 | 130 | return false; |
131 | 131 | } |
132 | 132 | |
133 | 133 | $options = wpinv_get_options(); |
134 | 134 | |
135 | - if ( isset( $options[ $key ] ) ) { |
|
136 | - unset( $options[ $key ] ); |
|
137 | - return wpinv_update_options( $options ); |
|
135 | + if (isset($options[$key])) { |
|
136 | + unset($options[$key]); |
|
137 | + return wpinv_update_options($options); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | return true; |
@@ -148,14 +148,14 @@ discard block |
||
148 | 148 | function wpinv_register_settings() { |
149 | 149 | |
150 | 150 | // Loop through all tabs. |
151 | - foreach ( wpinv_get_registered_settings() as $tab => $sections ) { |
|
151 | + foreach (wpinv_get_registered_settings() as $tab => $sections) { |
|
152 | 152 | |
153 | 153 | // In each tab, loop through sections. |
154 | - foreach ( $sections as $section => $settings ) { |
|
154 | + foreach ($sections as $section => $settings) { |
|
155 | 155 | |
156 | 156 | // Check for backwards compatibility |
157 | - $section_tabs = wpinv_get_settings_tab_sections( $tab ); |
|
158 | - if ( ! is_array( $section_tabs ) || ! array_key_exists( $section, $section_tabs ) ) { |
|
157 | + $section_tabs = wpinv_get_settings_tab_sections($tab); |
|
158 | + if (!is_array($section_tabs) || !array_key_exists($section, $section_tabs)) { |
|
159 | 159 | $section = 'main'; |
160 | 160 | $settings = $sections; |
161 | 161 | } |
@@ -168,9 +168,9 @@ discard block |
||
168 | 168 | 'wpinv_settings_' . $tab . '_' . $section |
169 | 169 | ); |
170 | 170 | |
171 | - foreach ( $settings as $option ) { |
|
172 | - if ( ! empty( $option['id'] ) ) { |
|
173 | - wpinv_register_settings_option( $tab, $section, $option ); |
|
171 | + foreach ($settings as $option) { |
|
172 | + if (!empty($option['id'])) { |
|
173 | + wpinv_register_settings_option($tab, $section, $option); |
|
174 | 174 | } |
175 | 175 | } |
176 | 176 | |
@@ -178,9 +178,9 @@ discard block |
||
178 | 178 | } |
179 | 179 | |
180 | 180 | // Creates our settings in the options table. |
181 | - register_setting( 'wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize' ); |
|
181 | + register_setting('wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize'); |
|
182 | 182 | } |
183 | -add_action( 'admin_init', 'wpinv_register_settings' ); |
|
183 | +add_action('admin_init', 'wpinv_register_settings'); |
|
184 | 184 | |
185 | 185 | /** |
186 | 186 | * Register a single settings option. |
@@ -190,46 +190,46 @@ discard block |
||
190 | 190 | * @param string $option |
191 | 191 | * |
192 | 192 | */ |
193 | -function wpinv_register_settings_option( $tab, $section, $option ) { |
|
193 | +function wpinv_register_settings_option($tab, $section, $option) { |
|
194 | 194 | |
195 | - $name = isset( $option['name'] ) ? $option['name'] : ''; |
|
195 | + $name = isset($option['name']) ? $option['name'] : ''; |
|
196 | 196 | $cb = "wpinv_{$option['type']}_callback"; |
197 | 197 | $section = "wpinv_settings_{$tab}_$section"; |
198 | 198 | |
199 | - if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) { |
|
200 | - $tip = esc_attr( $option['desc'] ); |
|
199 | + if (isset($option['desc']) && !empty($option['help-tip'])) { |
|
200 | + $tip = esc_attr($option['desc']); |
|
201 | 201 | $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
202 | - unset( $option['desc'] ); |
|
202 | + unset($option['desc']); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | // Loop through all tabs. |
206 | 206 | add_settings_field( |
207 | 207 | 'wpinv_settings[' . $option['id'] . ']', |
208 | 208 | $name, |
209 | - function_exists( $cb ) ? $cb : 'wpinv_missing_callback', |
|
209 | + function_exists($cb) ? $cb : 'wpinv_missing_callback', |
|
210 | 210 | $section, |
211 | 211 | $section, |
212 | 212 | array( |
213 | 213 | 'section' => $section, |
214 | - 'id' => isset( $option['id'] ) ? $option['id'] : null, |
|
215 | - 'desc' => isset( $option['desc'] ) ? $option['desc'] : '', |
|
214 | + 'id' => isset($option['id']) ? $option['id'] : null, |
|
215 | + 'desc' => isset($option['desc']) ? $option['desc'] : '', |
|
216 | 216 | 'name' => $name, |
217 | - 'size' => isset( $option['size'] ) ? $option['size'] : null, |
|
218 | - 'options' => isset( $option['options'] ) ? $option['options'] : '', |
|
219 | - 'selected' => isset( $option['selected'] ) ? $option['selected'] : null, |
|
220 | - 'std' => isset( $option['std'] ) ? $option['std'] : '', |
|
221 | - 'min' => isset( $option['min'] ) ? $option['min'] : null, |
|
222 | - 'max' => isset( $option['max'] ) ? $option['max'] : null, |
|
223 | - 'step' => isset( $option['step'] ) ? $option['step'] : null, |
|
224 | - 'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : null, |
|
225 | - 'allow_blank' => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true, |
|
226 | - 'readonly' => isset( $option['readonly'] ) ? $option['readonly'] : false, |
|
227 | - 'faux' => isset( $option['faux'] ) ? $option['faux'] : false, |
|
228 | - 'onchange' => isset( $option['onchange'] ) ? $option['onchange'] : '', |
|
229 | - 'custom' => isset( $option['custom'] ) ? $option['custom'] : '', |
|
230 | - 'class' => isset( $option['class'] ) ? $option['class'] : '', |
|
231 | - 'cols' => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50, |
|
232 | - 'rows' => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5, |
|
217 | + 'size' => isset($option['size']) ? $option['size'] : null, |
|
218 | + 'options' => isset($option['options']) ? $option['options'] : '', |
|
219 | + 'selected' => isset($option['selected']) ? $option['selected'] : null, |
|
220 | + 'std' => isset($option['std']) ? $option['std'] : '', |
|
221 | + 'min' => isset($option['min']) ? $option['min'] : null, |
|
222 | + 'max' => isset($option['max']) ? $option['max'] : null, |
|
223 | + 'step' => isset($option['step']) ? $option['step'] : null, |
|
224 | + 'placeholder' => isset($option['placeholder']) ? $option['placeholder'] : null, |
|
225 | + 'allow_blank' => isset($option['allow_blank']) ? $option['allow_blank'] : true, |
|
226 | + 'readonly' => isset($option['readonly']) ? $option['readonly'] : false, |
|
227 | + 'faux' => isset($option['faux']) ? $option['faux'] : false, |
|
228 | + 'onchange' => isset($option['onchange']) ? $option['onchange'] : '', |
|
229 | + 'custom' => isset($option['custom']) ? $option['custom'] : '', |
|
230 | + 'class' => isset($option['class']) ? $option['class'] : '', |
|
231 | + 'cols' => isset($option['cols']) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50, |
|
232 | + 'rows' => isset($option['rows']) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5, |
|
233 | 233 | ) |
234 | 234 | ); |
235 | 235 | |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @return array |
242 | 242 | */ |
243 | 243 | function wpinv_get_registered_settings() { |
244 | - return apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ); |
|
244 | + return apply_filters('wpinv_registered_settings', wpinv_get_data('admin-settings')); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -249,135 +249,135 @@ discard block |
||
249 | 249 | * |
250 | 250 | * @return array |
251 | 251 | */ |
252 | -function wpinv_settings_sanitize( $input = array() ) { |
|
252 | +function wpinv_settings_sanitize($input = array()) { |
|
253 | 253 | |
254 | 254 | $wpinv_options = wpinv_get_options(); |
255 | 255 | |
256 | - if ( empty( wp_get_raw_referer() ) ) { |
|
256 | + if (empty(wp_get_raw_referer())) { |
|
257 | 257 | return $input; |
258 | 258 | } |
259 | 259 | |
260 | - wp_parse_str( wp_get_raw_referer(), $referrer ); |
|
260 | + wp_parse_str(wp_get_raw_referer(), $referrer); |
|
261 | 261 | |
262 | 262 | $settings = wpinv_get_registered_settings(); |
263 | - $tab = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general'; |
|
264 | - $section = isset( $referrer['section'] ) ? $referrer['section'] : 'main'; |
|
263 | + $tab = isset($referrer['tab']) ? $referrer['tab'] : 'general'; |
|
264 | + $section = isset($referrer['section']) ? $referrer['section'] : 'main'; |
|
265 | 265 | |
266 | 266 | $input = $input ? $input : array(); |
267 | - $input = apply_filters( 'wpinv_settings_tab_' . $tab . '_sanitize', $input ); |
|
268 | - $input = apply_filters( 'wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input ); |
|
267 | + $input = apply_filters('wpinv_settings_tab_' . $tab . '_sanitize', $input); |
|
268 | + $input = apply_filters('wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input); |
|
269 | 269 | |
270 | 270 | // Loop through each setting being saved and pass it through a sanitization filter |
271 | - foreach ( $input as $key => $value ) { |
|
271 | + foreach ($input as $key => $value) { |
|
272 | 272 | |
273 | 273 | // Get the setting type (checkbox, select, etc) |
274 | - $type = isset( $settings[ $tab ][$section][ $key ]['type'] ) ? $settings[ $tab ][$section][ $key ]['type'] : false; |
|
274 | + $type = isset($settings[$tab][$section][$key]['type']) ? $settings[$tab][$section][$key]['type'] : false; |
|
275 | 275 | |
276 | - if ( $type ) { |
|
276 | + if ($type) { |
|
277 | 277 | // Field type specific filter |
278 | - $input[$key] = apply_filters( 'wpinv_settings_sanitize_' . $type, $value, $key ); |
|
278 | + $input[$key] = apply_filters('wpinv_settings_sanitize_' . $type, $value, $key); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | // General filter |
282 | - $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
282 | + $input[$key] = apply_filters('wpinv_settings_sanitize', $input[$key], $key); |
|
283 | 283 | |
284 | 284 | // Key specific filter. |
285 | - $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] ); |
|
285 | + $input[$key] = apply_filters("wpinv_settings_sanitize_$key", $input[$key]); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | // Loop through the whitelist and unset any that are empty for the tab being saved |
289 | - $main_settings = $section == 'main' ? $settings[ $tab ] : array(); // Check for extensions that aren't using new sections |
|
290 | - $section_settings = ! empty( $settings[ $tab ][ $section ] ) ? $settings[ $tab ][ $section ] : array(); |
|
289 | + $main_settings = $section == 'main' ? $settings[$tab] : array(); // Check for extensions that aren't using new sections |
|
290 | + $section_settings = !empty($settings[$tab][$section]) ? $settings[$tab][$section] : array(); |
|
291 | 291 | |
292 | - $found_settings = array_merge( $main_settings, $section_settings ); |
|
292 | + $found_settings = array_merge($main_settings, $section_settings); |
|
293 | 293 | |
294 | - if ( ! empty( $found_settings ) ) { |
|
295 | - foreach ( $found_settings as $key => $value ) { |
|
294 | + if (!empty($found_settings)) { |
|
295 | + foreach ($found_settings as $key => $value) { |
|
296 | 296 | |
297 | 297 | // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work |
298 | - if ( is_numeric( $key ) ) { |
|
298 | + if (is_numeric($key)) { |
|
299 | 299 | $key = $value['id']; |
300 | 300 | } |
301 | 301 | |
302 | - if ( ! isset( $input[ $key ] ) && isset( $wpinv_options[ $key ] ) ) { |
|
303 | - unset( $wpinv_options[ $key ] ); |
|
302 | + if (!isset($input[$key]) && isset($wpinv_options[$key])) { |
|
303 | + unset($wpinv_options[$key]); |
|
304 | 304 | } |
305 | 305 | } |
306 | 306 | } |
307 | 307 | |
308 | 308 | // Merge our new settings with the existing |
309 | - $output = array_merge( $wpinv_options, $input ); |
|
309 | + $output = array_merge($wpinv_options, $input); |
|
310 | 310 | |
311 | - add_settings_error( 'wpinv-notices', '', __( 'Settings updated.', 'invoicing' ), 'updated' ); |
|
311 | + add_settings_error('wpinv-notices', '', __('Settings updated.', 'invoicing'), 'updated'); |
|
312 | 312 | |
313 | 313 | return $output; |
314 | 314 | } |
315 | 315 | |
316 | -function wpinv_settings_sanitize_misc_accounting( $input ) { |
|
316 | +function wpinv_settings_sanitize_misc_accounting($input) { |
|
317 | 317 | |
318 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
318 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
319 | 319 | return $input; |
320 | 320 | } |
321 | 321 | |
322 | - if( ! empty( $input['enable_sequential'] ) && !wpinv_get_option( 'enable_sequential' ) ) { |
|
322 | + if (!empty($input['enable_sequential']) && !wpinv_get_option('enable_sequential')) { |
|
323 | 323 | // Shows an admin notice about upgrading previous order numbers |
324 | - getpaid_session()->set( 'upgrade_sequential', '1' ); |
|
324 | + getpaid_session()->set('upgrade_sequential', '1'); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | return $input; |
328 | 328 | } |
329 | -add_filter( 'wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting' ); |
|
329 | +add_filter('wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting'); |
|
330 | 330 | |
331 | -function wpinv_settings_sanitize_tax_rates( $input ) { |
|
332 | - if( ! wpinv_current_user_can_manage_invoicing() ) { |
|
331 | +function wpinv_settings_sanitize_tax_rates($input) { |
|
332 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
333 | 333 | return $input; |
334 | 334 | } |
335 | 335 | |
336 | - $new_rates = ! empty( $_POST['tax_rates'] ) ? array_values( $_POST['tax_rates'] ) : array(); |
|
336 | + $new_rates = !empty($_POST['tax_rates']) ? array_values($_POST['tax_rates']) : array(); |
|
337 | 337 | $tax_rates = array(); |
338 | 338 | |
339 | - foreach ( $new_rates as $rate ) { |
|
339 | + foreach ($new_rates as $rate) { |
|
340 | 340 | |
341 | - $rate['rate'] = wpinv_sanitize_amount( $rate['rate'] ); |
|
342 | - $rate['name'] = sanitize_text_field( $rate['name'] ); |
|
343 | - $rate['state'] = sanitize_text_field( $rate['state'] ); |
|
344 | - $rate['country'] = sanitize_text_field( $rate['country'] ); |
|
345 | - $rate['global'] = empty( $rate['state'] ); |
|
341 | + $rate['rate'] = wpinv_sanitize_amount($rate['rate']); |
|
342 | + $rate['name'] = sanitize_text_field($rate['name']); |
|
343 | + $rate['state'] = sanitize_text_field($rate['state']); |
|
344 | + $rate['country'] = sanitize_text_field($rate['country']); |
|
345 | + $rate['global'] = empty($rate['state']); |
|
346 | 346 | $tax_rates[] = $rate; |
347 | 347 | |
348 | 348 | } |
349 | 349 | |
350 | - update_option( 'wpinv_tax_rates', $tax_rates ); |
|
350 | + update_option('wpinv_tax_rates', $tax_rates); |
|
351 | 351 | |
352 | 352 | return $input; |
353 | 353 | } |
354 | -add_filter( 'wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates' ); |
|
354 | +add_filter('wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates'); |
|
355 | 355 | |
356 | -function wpinv_sanitize_text_field( $input ) { |
|
357 | - return trim( $input ); |
|
356 | +function wpinv_sanitize_text_field($input) { |
|
357 | + return trim($input); |
|
358 | 358 | } |
359 | -add_filter( 'wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field' ); |
|
359 | +add_filter('wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field'); |
|
360 | 360 | |
361 | 361 | function wpinv_get_settings_tabs() { |
362 | 362 | $tabs = array(); |
363 | - $tabs['general'] = __( 'General', 'invoicing' ); |
|
364 | - $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' ); |
|
365 | - $tabs['taxes'] = __( 'Taxes', 'invoicing' ); |
|
366 | - $tabs['emails'] = __( 'Emails', 'invoicing' ); |
|
367 | - $tabs['privacy'] = __( 'Privacy', 'invoicing' ); |
|
368 | - $tabs['misc'] = __( 'Misc', 'invoicing' ); |
|
369 | - $tabs['tools'] = __( 'Tools', 'invoicing' ); |
|
370 | - |
|
371 | - return apply_filters( 'wpinv_settings_tabs', $tabs ); |
|
363 | + $tabs['general'] = __('General', 'invoicing'); |
|
364 | + $tabs['gateways'] = __('Payment Gateways', 'invoicing'); |
|
365 | + $tabs['taxes'] = __('Taxes', 'invoicing'); |
|
366 | + $tabs['emails'] = __('Emails', 'invoicing'); |
|
367 | + $tabs['privacy'] = __('Privacy', 'invoicing'); |
|
368 | + $tabs['misc'] = __('Misc', 'invoicing'); |
|
369 | + $tabs['tools'] = __('Tools', 'invoicing'); |
|
370 | + |
|
371 | + return apply_filters('wpinv_settings_tabs', $tabs); |
|
372 | 372 | } |
373 | 373 | |
374 | -function wpinv_get_settings_tab_sections( $tab = false ) { |
|
374 | +function wpinv_get_settings_tab_sections($tab = false) { |
|
375 | 375 | $tabs = false; |
376 | 376 | $sections = wpinv_get_registered_settings_sections(); |
377 | 377 | |
378 | - if( $tab && ! empty( $sections[ $tab ] ) ) { |
|
379 | - $tabs = $sections[ $tab ]; |
|
380 | - } else if ( $tab ) { |
|
378 | + if ($tab && !empty($sections[$tab])) { |
|
379 | + $tabs = $sections[$tab]; |
|
380 | + } else if ($tab) { |
|
381 | 381 | $tabs = false; |
382 | 382 | } |
383 | 383 | |
@@ -387,87 +387,87 @@ discard block |
||
387 | 387 | function wpinv_get_registered_settings_sections() { |
388 | 388 | static $sections = false; |
389 | 389 | |
390 | - if ( false !== $sections ) { |
|
390 | + if (false !== $sections) { |
|
391 | 391 | return $sections; |
392 | 392 | } |
393 | 393 | |
394 | 394 | $sections = array( |
395 | - 'general' => apply_filters( 'wpinv_settings_sections_general', array( |
|
396 | - 'main' => __( 'General Settings', 'invoicing' ), |
|
397 | - 'currency_section' => __( 'Currency Settings', 'invoicing' ), |
|
398 | - 'labels' => __( 'Label Texts', 'invoicing' ), |
|
399 | - ) ), |
|
400 | - 'gateways' => apply_filters( 'wpinv_settings_sections_gateways', array( |
|
401 | - 'main' => __( 'Gateway Settings', 'invoicing' ), |
|
402 | - ) ), |
|
403 | - 'taxes' => apply_filters( 'wpinv_settings_sections_taxes', array( |
|
404 | - 'main' => __( 'Tax Settings', 'invoicing' ), |
|
405 | - 'rates' => __( 'Tax Rates', 'invoicing' ), |
|
406 | - ) ), |
|
407 | - 'emails' => apply_filters( 'wpinv_settings_sections_emails', array( |
|
408 | - 'main' => __( 'Email Settings', 'invoicing' ), |
|
409 | - ) ), |
|
410 | - 'privacy' => apply_filters( 'wpinv_settings_sections_privacy', array( |
|
411 | - 'main' => __( 'Privacy policy', 'invoicing' ), |
|
412 | - ) ), |
|
413 | - 'misc' => apply_filters( 'wpinv_settings_sections_misc', array( |
|
414 | - 'main' => __( 'Miscellaneous', 'invoicing' ), |
|
415 | - 'custom-css' => __( 'Custom CSS', 'invoicing' ), |
|
416 | - ) ), |
|
417 | - 'tools' => apply_filters( 'wpinv_settings_sections_tools', array( |
|
418 | - 'main' => __( 'Diagnostic Tools', 'invoicing' ), |
|
419 | - ) ), |
|
395 | + 'general' => apply_filters('wpinv_settings_sections_general', array( |
|
396 | + 'main' => __('General Settings', 'invoicing'), |
|
397 | + 'currency_section' => __('Currency Settings', 'invoicing'), |
|
398 | + 'labels' => __('Label Texts', 'invoicing'), |
|
399 | + )), |
|
400 | + 'gateways' => apply_filters('wpinv_settings_sections_gateways', array( |
|
401 | + 'main' => __('Gateway Settings', 'invoicing'), |
|
402 | + )), |
|
403 | + 'taxes' => apply_filters('wpinv_settings_sections_taxes', array( |
|
404 | + 'main' => __('Tax Settings', 'invoicing'), |
|
405 | + 'rates' => __('Tax Rates', 'invoicing'), |
|
406 | + )), |
|
407 | + 'emails' => apply_filters('wpinv_settings_sections_emails', array( |
|
408 | + 'main' => __('Email Settings', 'invoicing'), |
|
409 | + )), |
|
410 | + 'privacy' => apply_filters('wpinv_settings_sections_privacy', array( |
|
411 | + 'main' => __('Privacy policy', 'invoicing'), |
|
412 | + )), |
|
413 | + 'misc' => apply_filters('wpinv_settings_sections_misc', array( |
|
414 | + 'main' => __('Miscellaneous', 'invoicing'), |
|
415 | + 'custom-css' => __('Custom CSS', 'invoicing'), |
|
416 | + )), |
|
417 | + 'tools' => apply_filters('wpinv_settings_sections_tools', array( |
|
418 | + 'main' => __('Diagnostic Tools', 'invoicing'), |
|
419 | + )), |
|
420 | 420 | ); |
421 | 421 | |
422 | - $sections = apply_filters( 'wpinv_settings_sections', $sections ); |
|
422 | + $sections = apply_filters('wpinv_settings_sections', $sections); |
|
423 | 423 | |
424 | 424 | return $sections; |
425 | 425 | } |
426 | 426 | |
427 | -function wpinv_get_pages( $with_slug = false, $default_label = NULL ) { |
|
427 | +function wpinv_get_pages($with_slug = false, $default_label = NULL) { |
|
428 | 428 | $pages_options = array(); |
429 | 429 | |
430 | - if( $default_label !== NULL && $default_label !== false ) { |
|
431 | - $pages_options = array( '' => $default_label ); // Blank option |
|
430 | + if ($default_label !== NULL && $default_label !== false) { |
|
431 | + $pages_options = array('' => $default_label); // Blank option |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | $pages = get_pages(); |
435 | - if ( $pages ) { |
|
436 | - foreach ( $pages as $page ) { |
|
435 | + if ($pages) { |
|
436 | + foreach ($pages as $page) { |
|
437 | 437 | $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
438 | - $pages_options[ $page->ID ] = $title; |
|
438 | + $pages_options[$page->ID] = $title; |
|
439 | 439 | } |
440 | 440 | } |
441 | 441 | |
442 | 442 | return $pages_options; |
443 | 443 | } |
444 | 444 | |
445 | -function wpinv_header_callback( $args ) { |
|
446 | - if ( !empty( $args['desc'] ) ) { |
|
445 | +function wpinv_header_callback($args) { |
|
446 | + if (!empty($args['desc'])) { |
|
447 | 447 | echo $args['desc']; |
448 | 448 | } |
449 | 449 | } |
450 | 450 | |
451 | -function wpinv_hidden_callback( $args ) { |
|
451 | +function wpinv_hidden_callback($args) { |
|
452 | 452 | global $wpinv_options; |
453 | 453 | |
454 | - if ( isset( $args['set_value'] ) ) { |
|
454 | + if (isset($args['set_value'])) { |
|
455 | 455 | $value = $args['set_value']; |
456 | - } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
457 | - $value = $wpinv_options[ $args['id'] ]; |
|
456 | + } elseif (isset($wpinv_options[$args['id']])) { |
|
457 | + $value = $wpinv_options[$args['id']]; |
|
458 | 458 | } else { |
459 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
459 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
460 | 460 | } |
461 | 461 | |
462 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
462 | + if (isset($args['faux']) && true === $args['faux']) { |
|
463 | 463 | $args['readonly'] = true; |
464 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
464 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
465 | 465 | $name = ''; |
466 | 466 | } else { |
467 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
467 | + $name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"'; |
|
468 | 468 | } |
469 | 469 | |
470 | - $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
470 | + $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key($args['id']) . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '" />'; |
|
471 | 471 | |
472 | 472 | echo $html; |
473 | 473 | } |
@@ -475,61 +475,61 @@ discard block |
||
475 | 475 | /** |
476 | 476 | * Displays a checkbox settings callback. |
477 | 477 | */ |
478 | -function wpinv_checkbox_callback( $args ) { |
|
478 | +function wpinv_checkbox_callback($args) { |
|
479 | 479 | |
480 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
481 | - $std = wpinv_get_option( $args['id'], $std ); |
|
482 | - $id = esc_attr( $args['id'] ); |
|
480 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
481 | + $std = wpinv_get_option($args['id'], $std); |
|
482 | + $id = esc_attr($args['id']); |
|
483 | 483 | |
484 | - getpaid_hidden_field( "wpinv_settings[$id]", '0' ); |
|
484 | + getpaid_hidden_field("wpinv_settings[$id]", '0'); |
|
485 | 485 | ?> |
486 | 486 | <fieldset> |
487 | 487 | <label> |
488 | - <input id="wpinv-settings-<?php echo $id; ?>" name="wpinv_settings[<?php echo $id; ?>]" <?php checked( empty( $std ), false ); ?> value="1" type="checkbox"> |
|
489 | - <?php echo wp_kses_post( $args['desc'] ); ?> |
|
488 | + <input id="wpinv-settings-<?php echo $id; ?>" name="wpinv_settings[<?php echo $id; ?>]" <?php checked(empty($std), false); ?> value="1" type="checkbox"> |
|
489 | + <?php echo wp_kses_post($args['desc']); ?> |
|
490 | 490 | </label> |
491 | 491 | </fieldset> |
492 | 492 | <?php |
493 | 493 | } |
494 | 494 | |
495 | -function wpinv_multicheck_callback( $args ) { |
|
495 | +function wpinv_multicheck_callback($args) { |
|
496 | 496 | |
497 | 497 | global $wpinv_options; |
498 | 498 | |
499 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
500 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
499 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
500 | + $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : ''; |
|
501 | 501 | |
502 | - if ( ! empty( $args['options'] ) ) { |
|
502 | + if (!empty($args['options'])) { |
|
503 | 503 | |
504 | - $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
505 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
504 | + $std = isset($args['std']) ? $args['std'] : array(); |
|
505 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : $std; |
|
506 | 506 | |
507 | 507 | echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">'; |
508 | - foreach( $args['options'] as $key => $option ): |
|
509 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
510 | - if ( in_array( $sanitize_key, $value ) ) { |
|
508 | + foreach ($args['options'] as $key => $option): |
|
509 | + $sanitize_key = wpinv_sanitize_key($key); |
|
510 | + if (in_array($sanitize_key, $value)) { |
|
511 | 511 | $enabled = $sanitize_key; |
512 | 512 | } else { |
513 | 513 | $enabled = NULL; |
514 | 514 | } |
515 | - echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
516 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
515 | + echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($sanitize_key) . '" ' . checked($sanitize_key, $enabled, false) . '/> '; |
|
516 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post($option) . '</label></div>'; |
|
517 | 517 | endforeach; |
518 | 518 | echo '</div>'; |
519 | 519 | echo '<p class="description">' . $args['desc'] . '</p>'; |
520 | 520 | } |
521 | 521 | } |
522 | 522 | |
523 | -function wpinv_payment_icons_callback( $args ) { |
|
523 | +function wpinv_payment_icons_callback($args) { |
|
524 | 524 | global $wpinv_options; |
525 | 525 | |
526 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
526 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
527 | 527 | |
528 | - if ( ! empty( $args['options'] ) ) { |
|
529 | - foreach( $args['options'] as $key => $option ) { |
|
530 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
528 | + if (!empty($args['options'])) { |
|
529 | + foreach ($args['options'] as $key => $option) { |
|
530 | + $sanitize_key = wpinv_sanitize_key($key); |
|
531 | 531 | |
532 | - if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
532 | + if (isset($wpinv_options[$args['id']][$key])) { |
|
533 | 533 | $enabled = $option; |
534 | 534 | } else { |
535 | 535 | $enabled = NULL; |
@@ -537,211 +537,211 @@ discard block |
||
537 | 537 | |
538 | 538 | echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
539 | 539 | |
540 | - echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
540 | + echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($option) . '" ' . checked($option, $enabled, false) . '/> '; |
|
541 | 541 | |
542 | - if ( wpinv_string_is_image_url( $key ) ) { |
|
543 | - echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
542 | + if (wpinv_string_is_image_url($key)) { |
|
543 | + echo '<img class="payment-icon" src="' . esc_url($key) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
544 | 544 | } else { |
545 | - $card = strtolower( str_replace( ' ', '', $option ) ); |
|
545 | + $card = strtolower(str_replace(' ', '', $option)); |
|
546 | 546 | |
547 | - if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
548 | - $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
547 | + if (has_filter('wpinv_accepted_payment_' . $card . '_image')) { |
|
548 | + $image = apply_filters('wpinv_accepted_payment_' . $card . '_image', ''); |
|
549 | 549 | } else { |
550 | - $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
550 | + $image = wpinv_locate_template('images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false); |
|
551 | 551 | $content_dir = WP_CONTENT_DIR; |
552 | 552 | |
553 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
553 | + if (function_exists('wp_normalize_path')) { |
|
554 | 554 | // Replaces backslashes with forward slashes for Windows systems |
555 | - $image = wp_normalize_path( $image ); |
|
556 | - $content_dir = wp_normalize_path( $content_dir ); |
|
555 | + $image = wp_normalize_path($image); |
|
556 | + $content_dir = wp_normalize_path($content_dir); |
|
557 | 557 | } |
558 | 558 | |
559 | - $image = str_replace( $content_dir, content_url(), $image ); |
|
559 | + $image = str_replace($content_dir, content_url(), $image); |
|
560 | 560 | } |
561 | 561 | |
562 | - echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
562 | + echo '<img class="payment-icon" src="' . esc_url($image) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
563 | 563 | } |
564 | 564 | echo $option . '</label>'; |
565 | 565 | } |
566 | - echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
566 | + echo '<p class="description" style="margin-top:16px;">' . wp_kses_post($args['desc']) . '</p>'; |
|
567 | 567 | } |
568 | 568 | } |
569 | 569 | |
570 | 570 | /** |
571 | 571 | * Displays a radio settings field. |
572 | 572 | */ |
573 | -function wpinv_radio_callback( $args ) { |
|
573 | +function wpinv_radio_callback($args) { |
|
574 | 574 | |
575 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
576 | - $std = wpinv_get_option( $args['id'], $std ); |
|
575 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
576 | + $std = wpinv_get_option($args['id'], $std); |
|
577 | 577 | ?> |
578 | 578 | <fieldset> |
579 | - <ul id="wpinv-settings-<?php echo esc_attr( $args['id'] ); ?>" style="margin-top: 0;"> |
|
580 | - <?php foreach( $args['options'] as $key => $option ) : ?> |
|
579 | + <ul id="wpinv-settings-<?php echo esc_attr($args['id']); ?>" style="margin-top: 0;"> |
|
580 | + <?php foreach ($args['options'] as $key => $option) : ?> |
|
581 | 581 | <li> |
582 | 582 | <label> |
583 | - <input name="wpinv_settings[<?php echo esc_attr( $args['id'] ); ?>]" <?php checked( $std, $key ); ?> value="<?php echo esc_attr( $key ); ?>" type="radio"> |
|
584 | - <?php echo wp_kses_post( $option ); ?> |
|
583 | + <input name="wpinv_settings[<?php echo esc_attr($args['id']); ?>]" <?php checked($std, $key); ?> value="<?php echo esc_attr($key); ?>" type="radio"> |
|
584 | + <?php echo wp_kses_post($option); ?> |
|
585 | 585 | </label> |
586 | 586 | </li> |
587 | 587 | <?php endforeach; ?> |
588 | 588 | </ul> |
589 | 589 | </fieldset> |
590 | 590 | <?php |
591 | - getpaid_settings_description_callback( $args ); |
|
591 | + getpaid_settings_description_callback($args); |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | /** |
595 | 595 | * Displays a description if available. |
596 | 596 | */ |
597 | -function getpaid_settings_description_callback( $args ) { |
|
597 | +function getpaid_settings_description_callback($args) { |
|
598 | 598 | |
599 | - if ( ! empty( $args['desc'] ) ) { |
|
600 | - $description = wp_kses_post( $args['desc'] ); |
|
599 | + if (!empty($args['desc'])) { |
|
600 | + $description = wp_kses_post($args['desc']); |
|
601 | 601 | echo "<p class='description'>$description</p>"; |
602 | 602 | } |
603 | 603 | |
604 | 604 | } |
605 | 605 | |
606 | -function wpinv_gateways_callback( $args ) { |
|
606 | +function wpinv_gateways_callback($args) { |
|
607 | 607 | global $wpinv_options; |
608 | 608 | |
609 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
609 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
610 | 610 | |
611 | - foreach ( $args['options'] as $key => $option ) : |
|
612 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
611 | + foreach ($args['options'] as $key => $option) : |
|
612 | + $sanitize_key = wpinv_sanitize_key($key); |
|
613 | 613 | |
614 | - if ( isset( $wpinv_options['gateways'][ $key ] ) ) |
|
614 | + if (isset($wpinv_options['gateways'][$key])) |
|
615 | 615 | $enabled = '1'; |
616 | 616 | else |
617 | 617 | $enabled = null; |
618 | 618 | |
619 | - echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
620 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
619 | + echo '<input name="wpinv_settings[' . esc_attr($args['id']) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
620 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option['admin_label']) . '</label><br/>'; |
|
621 | 621 | endforeach; |
622 | 622 | } |
623 | 623 | |
624 | 624 | function wpinv_gateway_select_callback($args) { |
625 | 625 | global $wpinv_options; |
626 | 626 | |
627 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
628 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
627 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
628 | + $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : ''; |
|
629 | 629 | |
630 | - echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >'; |
|
630 | + echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="' . $class . '" >'; |
|
631 | 631 | |
632 | - foreach ( $args['options'] as $key => $option ) : |
|
633 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
634 | - $selected = selected( $key, $args['selected'], false ); |
|
632 | + foreach ($args['options'] as $key => $option) : |
|
633 | + if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) { |
|
634 | + $selected = selected($key, $args['selected'], false); |
|
635 | 635 | } else { |
636 | - $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : ''; |
|
636 | + $selected = isset($wpinv_options[$args['id']]) ? selected($key, $wpinv_options[$args['id']], false) : ''; |
|
637 | 637 | } |
638 | - echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
638 | + echo '<option value="' . wpinv_sanitize_key($key) . '"' . $selected . '>' . esc_html($option['admin_label']) . '</option>'; |
|
639 | 639 | endforeach; |
640 | 640 | |
641 | 641 | echo '</select>'; |
642 | - echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
642 | + echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
643 | 643 | } |
644 | 644 | |
645 | -function wpinv_text_callback( $args ) { |
|
645 | +function wpinv_text_callback($args) { |
|
646 | 646 | global $wpinv_options; |
647 | 647 | |
648 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
648 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
649 | 649 | |
650 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
651 | - $value = $wpinv_options[ $args['id'] ]; |
|
650 | + if (isset($wpinv_options[$args['id']])) { |
|
651 | + $value = $wpinv_options[$args['id']]; |
|
652 | 652 | } else { |
653 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
653 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
654 | 654 | } |
655 | 655 | |
656 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
656 | + if (isset($args['faux']) && true === $args['faux']) { |
|
657 | 657 | $args['readonly'] = true; |
658 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
658 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
659 | 659 | $name = ''; |
660 | 660 | } else { |
661 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
661 | + $name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"'; |
|
662 | 662 | } |
663 | - $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
663 | + $class = !empty($args['class']) ? sanitize_html_class($args['class']) : ''; |
|
664 | 664 | |
665 | 665 | $readonly = $args['readonly'] === true ? ' readonly="readonly"' : ''; |
666 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
667 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>'; |
|
668 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
666 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
667 | + $html = '<input type="text" class="' . sanitize_html_class($size) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"' . $readonly . '/>'; |
|
668 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
669 | 669 | |
670 | 670 | echo $html; |
671 | 671 | } |
672 | 672 | |
673 | -function wpinv_number_callback( $args ) { |
|
673 | +function wpinv_number_callback($args) { |
|
674 | 674 | global $wpinv_options; |
675 | 675 | |
676 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
676 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
677 | 677 | |
678 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
679 | - $value = $wpinv_options[ $args['id'] ]; |
|
678 | + if (isset($wpinv_options[$args['id']])) { |
|
679 | + $value = $wpinv_options[$args['id']]; |
|
680 | 680 | } else { |
681 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
681 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
682 | 682 | } |
683 | 683 | |
684 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
684 | + if (isset($args['faux']) && true === $args['faux']) { |
|
685 | 685 | $args['readonly'] = true; |
686 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
686 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
687 | 687 | $name = ''; |
688 | 688 | } else { |
689 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
689 | + $name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"'; |
|
690 | 690 | } |
691 | 691 | |
692 | - $max = isset( $args['max'] ) ? $args['max'] : 999999; |
|
693 | - $min = isset( $args['min'] ) ? $args['min'] : 0; |
|
694 | - $step = isset( $args['step'] ) ? $args['step'] : 1; |
|
695 | - $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
692 | + $max = isset($args['max']) ? $args['max'] : 999999; |
|
693 | + $min = isset($args['min']) ? $args['min'] : 0; |
|
694 | + $step = isset($args['step']) ? $args['step'] : 1; |
|
695 | + $class = !empty($args['class']) ? sanitize_html_class($args['class']) : ''; |
|
696 | 696 | |
697 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
698 | - $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
699 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
697 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
698 | + $html = '<input type="number" step="' . esc_attr($step) . '" max="' . esc_attr($max) . '" min="' . esc_attr($min) . '" class="' . sanitize_html_class($size) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"/>'; |
|
699 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
700 | 700 | |
701 | 701 | echo $html; |
702 | 702 | } |
703 | 703 | |
704 | -function wpinv_textarea_callback( $args ) { |
|
704 | +function wpinv_textarea_callback($args) { |
|
705 | 705 | global $wpinv_options; |
706 | 706 | |
707 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
707 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
708 | 708 | |
709 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
710 | - $value = $wpinv_options[ $args['id'] ]; |
|
709 | + if (isset($wpinv_options[$args['id']])) { |
|
710 | + $value = $wpinv_options[$args['id']]; |
|
711 | 711 | } else { |
712 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
712 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
713 | 713 | } |
714 | 714 | |
715 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
716 | - $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text'; |
|
715 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
716 | + $class = (isset($args['class']) && !is_null($args['class'])) ? $args['class'] : 'large-text'; |
|
717 | 717 | |
718 | - $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
719 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
718 | + $html = '<textarea class="' . sanitize_html_class($class) . ' txtarea-' . sanitize_html_class($size) . ' wpi-' . esc_attr(sanitize_html_class($sanitize_id)) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']">' . esc_textarea(stripslashes($value)) . '</textarea>'; |
|
719 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
720 | 720 | |
721 | 721 | echo $html; |
722 | 722 | } |
723 | 723 | |
724 | -function wpinv_password_callback( $args ) { |
|
724 | +function wpinv_password_callback($args) { |
|
725 | 725 | global $wpinv_options; |
726 | 726 | |
727 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
727 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
728 | 728 | |
729 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
730 | - $value = $wpinv_options[ $args['id'] ]; |
|
729 | + if (isset($wpinv_options[$args['id']])) { |
|
730 | + $value = $wpinv_options[$args['id']]; |
|
731 | 731 | } else { |
732 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
732 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
733 | 733 | } |
734 | 734 | |
735 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
736 | - $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
737 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
735 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
736 | + $html = '<input type="password" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '"/>'; |
|
737 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
738 | 738 | |
739 | 739 | echo $html; |
740 | 740 | } |
741 | 741 | |
742 | 742 | function wpinv_missing_callback($args) { |
743 | 743 | printf( |
744 | - __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
744 | + __('The callback function used for the %s setting is missing.', 'invoicing'), |
|
745 | 745 | '<strong>' . $args['id'] . '</strong>' |
746 | 746 | ); |
747 | 747 | } |
@@ -749,134 +749,134 @@ discard block |
||
749 | 749 | function wpinv_select_callback($args) { |
750 | 750 | global $wpinv_options; |
751 | 751 | |
752 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
752 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
753 | 753 | |
754 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
755 | - $value = $wpinv_options[ $args['id'] ]; |
|
754 | + if (isset($wpinv_options[$args['id']])) { |
|
755 | + $value = $wpinv_options[$args['id']]; |
|
756 | 756 | } else { |
757 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
757 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
758 | 758 | } |
759 | 759 | |
760 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
760 | + if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) { |
|
761 | 761 | $value = $args['selected']; |
762 | 762 | } |
763 | 763 | |
764 | - if ( isset( $args['placeholder'] ) ) { |
|
764 | + if (isset($args['placeholder'])) { |
|
765 | 765 | $placeholder = $args['placeholder']; |
766 | 766 | } else { |
767 | 767 | $placeholder = ''; |
768 | 768 | } |
769 | 769 | |
770 | - if( !empty( $args['onchange'] ) ) { |
|
771 | - $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
770 | + if (!empty($args['onchange'])) { |
|
771 | + $onchange = ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
772 | 772 | } else { |
773 | 773 | $onchange = ''; |
774 | 774 | } |
775 | 775 | |
776 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
776 | + $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : ''; |
|
777 | 777 | |
778 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />'; |
|
778 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="' . $class . '" name="wpinv_settings[' . esc_attr($args['id']) . ']" data-placeholder="' . esc_html($placeholder) . '"' . $onchange . ' />'; |
|
779 | 779 | |
780 | - foreach ( $args['options'] as $option => $name ) { |
|
781 | - $selected = selected( $option, $value, false ); |
|
782 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
780 | + foreach ($args['options'] as $option => $name) { |
|
781 | + $selected = selected($option, $value, false); |
|
782 | + $html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>'; |
|
783 | 783 | } |
784 | 784 | |
785 | 785 | $html .= '</select>'; |
786 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
786 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
787 | 787 | |
788 | 788 | echo $html; |
789 | 789 | } |
790 | 790 | |
791 | -function wpinv_color_select_callback( $args ) { |
|
791 | +function wpinv_color_select_callback($args) { |
|
792 | 792 | global $wpinv_options; |
793 | 793 | |
794 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
794 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
795 | 795 | |
796 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
797 | - $value = $wpinv_options[ $args['id'] ]; |
|
796 | + if (isset($wpinv_options[$args['id']])) { |
|
797 | + $value = $wpinv_options[$args['id']]; |
|
798 | 798 | } else { |
799 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
799 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
800 | 800 | } |
801 | 801 | |
802 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
802 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"/>'; |
|
803 | 803 | |
804 | - foreach ( $args['options'] as $option => $color ) { |
|
805 | - $selected = selected( $option, $value, false ); |
|
806 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
804 | + foreach ($args['options'] as $option => $color) { |
|
805 | + $selected = selected($option, $value, false); |
|
806 | + $html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($color['label']) . '</option>'; |
|
807 | 807 | } |
808 | 808 | |
809 | 809 | $html .= '</select>'; |
810 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
810 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
811 | 811 | |
812 | 812 | echo $html; |
813 | 813 | } |
814 | 814 | |
815 | -function wpinv_rich_editor_callback( $args ) { |
|
815 | +function wpinv_rich_editor_callback($args) { |
|
816 | 816 | global $wpinv_options, $wp_version; |
817 | 817 | |
818 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
818 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
819 | 819 | |
820 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
821 | - $value = $wpinv_options[ $args['id'] ]; |
|
820 | + if (isset($wpinv_options[$args['id']])) { |
|
821 | + $value = $wpinv_options[$args['id']]; |
|
822 | 822 | |
823 | - if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
824 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
823 | + if (empty($args['allow_blank']) && empty($value)) { |
|
824 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
825 | 825 | } |
826 | 826 | } else { |
827 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
827 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
828 | 828 | } |
829 | 829 | |
830 | - $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
830 | + $rows = isset($args['size']) ? $args['size'] : 20; |
|
831 | 831 | |
832 | 832 | $html = '<div class="getpaid-settings-editor-input">'; |
833 | - if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
833 | + if ($wp_version >= 3.3 && function_exists('wp_editor')) { |
|
834 | 834 | ob_start(); |
835 | - wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
835 | + wp_editor(stripslashes($value), 'wpinv_settings_' . esc_attr($args['id']), array('textarea_name' => 'wpinv_settings[' . esc_attr($args['id']) . ']', 'textarea_rows' => absint($rows), 'media_buttons' => false)); |
|
836 | 836 | $html .= ob_get_clean(); |
837 | 837 | } else { |
838 | - $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
838 | + $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" class="wpi-' . esc_attr(sanitize_html_class($args['id'])) . '">' . esc_textarea(stripslashes($value)) . '</textarea>'; |
|
839 | 839 | } |
840 | 840 | |
841 | - $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
841 | + $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
842 | 842 | |
843 | 843 | echo $html; |
844 | 844 | } |
845 | 845 | |
846 | -function wpinv_upload_callback( $args ) { |
|
846 | +function wpinv_upload_callback($args) { |
|
847 | 847 | global $wpinv_options; |
848 | 848 | |
849 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
849 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
850 | 850 | |
851 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
851 | + if (isset($wpinv_options[$args['id']])) { |
|
852 | 852 | $value = $wpinv_options[$args['id']]; |
853 | 853 | } else { |
854 | 854 | $value = isset($args['std']) ? $args['std'] : ''; |
855 | 855 | } |
856 | 856 | |
857 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
858 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
859 | - $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
860 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
857 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
858 | + $html = '<input type="text" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr(stripslashes($value)) . '"/>'; |
|
859 | + $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __('Upload File', 'invoicing') . '"/></span>'; |
|
860 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
861 | 861 | |
862 | 862 | echo $html; |
863 | 863 | } |
864 | 864 | |
865 | -function wpinv_color_callback( $args ) { |
|
865 | +function wpinv_color_callback($args) { |
|
866 | 866 | global $wpinv_options; |
867 | 867 | |
868 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
868 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
869 | 869 | |
870 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
871 | - $value = $wpinv_options[ $args['id'] ]; |
|
870 | + if (isset($wpinv_options[$args['id']])) { |
|
871 | + $value = $wpinv_options[$args['id']]; |
|
872 | 872 | } else { |
873 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
873 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
874 | 874 | } |
875 | 875 | |
876 | - $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
876 | + $default = isset($args['std']) ? $args['std'] : ''; |
|
877 | 877 | |
878 | - $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
879 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
878 | + $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '" data-default-color="' . esc_attr($default) . '" />'; |
|
879 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
880 | 880 | |
881 | 881 | echo $html; |
882 | 882 | } |
@@ -884,9 +884,9 @@ discard block |
||
884 | 884 | function wpinv_country_states_callback($args) { |
885 | 885 | global $wpinv_options; |
886 | 886 | |
887 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
887 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
888 | 888 | |
889 | - if ( isset( $args['placeholder'] ) ) { |
|
889 | + if (isset($args['placeholder'])) { |
|
890 | 890 | $placeholder = $args['placeholder']; |
891 | 891 | } else { |
892 | 892 | $placeholder = ''; |
@@ -894,16 +894,16 @@ discard block |
||
894 | 894 | |
895 | 895 | $states = wpinv_get_country_states(); |
896 | 896 | |
897 | - $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
898 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
897 | + $class = empty($states) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
898 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"' . $class . 'data-placeholder="' . esc_html($placeholder) . '"/>'; |
|
899 | 899 | |
900 | - foreach ( $states as $option => $name ) { |
|
901 | - $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
902 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
900 | + foreach ($states as $option => $name) { |
|
901 | + $selected = isset($wpinv_options[$args['id']]) ? selected($option, $wpinv_options[$args['id']], false) : ''; |
|
902 | + $html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>'; |
|
903 | 903 | } |
904 | 904 | |
905 | 905 | $html .= '</select>'; |
906 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
906 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
907 | 907 | |
908 | 908 | echo $html; |
909 | 909 | } |
@@ -918,7 +918,7 @@ discard block |
||
918 | 918 | </tr> |
919 | 919 | <tr class="bsui"> |
920 | 920 | <td colspan="2" class="p-0"> |
921 | - <?php include plugin_dir_path( __FILE__ ) . 'views/html-tax-rates-edit.php'; ?> |
|
921 | + <?php include plugin_dir_path(__FILE__) . 'views/html-tax-rates-edit.php'; ?> |
|
922 | 922 | |
923 | 923 | <?php |
924 | 924 | |
@@ -927,17 +927,17 @@ discard block |
||
927 | 927 | /** |
928 | 928 | * Displays a tax rate' edit row. |
929 | 929 | */ |
930 | -function wpinv_tax_rate_callback( $tax_rate, $key, $echo = true ) { |
|
930 | +function wpinv_tax_rate_callback($tax_rate, $key, $echo = true) { |
|
931 | 931 | ob_start(); |
932 | 932 | |
933 | - $key = sanitize_key( $key ); |
|
934 | - $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate']; |
|
935 | - include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php'; |
|
933 | + $key = sanitize_key($key); |
|
934 | + $tax_rate['reduced_rate'] = empty($tax_rate['reduced_rate']) ? 0 : $tax_rate['reduced_rate']; |
|
935 | + include plugin_dir_path(__FILE__) . 'views/html-tax-rate-edit.php'; |
|
936 | 936 | |
937 | - if ( $echo ) { |
|
938 | - echo ob_get_clean( $echo ); |
|
937 | + if ($echo) { |
|
938 | + echo ob_get_clean($echo); |
|
939 | 939 | } else { |
940 | - return ob_get_clean( $echo ); |
|
940 | + return ob_get_clean($echo); |
|
941 | 941 | } |
942 | 942 | |
943 | 943 | } |
@@ -946,77 +946,77 @@ discard block |
||
946 | 946 | ob_start(); ?> |
947 | 947 | </td><tr> |
948 | 948 | <td colspan="2" class="wpinv_tools_tdbox"> |
949 | - <?php if ( $args['desc'] ) { ?><p><?php echo $args['desc']; ?></p><?php } ?> |
|
950 | - <?php do_action( 'wpinv_tools_before' ); ?> |
|
949 | + <?php if ($args['desc']) { ?><p><?php echo $args['desc']; ?></p><?php } ?> |
|
950 | + <?php do_action('wpinv_tools_before'); ?> |
|
951 | 951 | <table id="wpinv_tools_table" class="wp-list-table widefat fixed posts"> |
952 | 952 | <thead> |
953 | 953 | <tr> |
954 | - <th scope="col" class="wpinv-th-tool"><?php _e( 'Tool', 'invoicing' ); ?></th> |
|
955 | - <th scope="col" class="wpinv-th-desc"><?php _e( 'Description', 'invoicing' ); ?></th> |
|
956 | - <th scope="col" class="wpinv-th-action"><?php _e( 'Action', 'invoicing' ); ?></th> |
|
954 | + <th scope="col" class="wpinv-th-tool"><?php _e('Tool', 'invoicing'); ?></th> |
|
955 | + <th scope="col" class="wpinv-th-desc"><?php _e('Description', 'invoicing'); ?></th> |
|
956 | + <th scope="col" class="wpinv-th-action"><?php _e('Action', 'invoicing'); ?></th> |
|
957 | 957 | </tr> |
958 | 958 | </thead> |
959 | - <?php do_action( 'wpinv_tools_row' ); ?> |
|
959 | + <?php do_action('wpinv_tools_row'); ?> |
|
960 | 960 | <tbody> |
961 | 961 | </tbody> |
962 | 962 | </table> |
963 | - <?php do_action( 'wpinv_tools_after' ); ?> |
|
963 | + <?php do_action('wpinv_tools_after'); ?> |
|
964 | 964 | <?php |
965 | 965 | echo ob_get_clean(); |
966 | 966 | } |
967 | 967 | |
968 | -function wpinv_descriptive_text_callback( $args ) { |
|
969 | - echo wp_kses_post( $args['desc'] ); |
|
968 | +function wpinv_descriptive_text_callback($args) { |
|
969 | + echo wp_kses_post($args['desc']); |
|
970 | 970 | } |
971 | 971 | |
972 | -function wpinv_hook_callback( $args ) { |
|
973 | - do_action( 'wpinv_' . $args['id'], $args ); |
|
972 | +function wpinv_hook_callback($args) { |
|
973 | + do_action('wpinv_' . $args['id'], $args); |
|
974 | 974 | } |
975 | 975 | |
976 | 976 | function wpinv_set_settings_cap() { |
977 | 977 | return wpinv_get_capability(); |
978 | 978 | } |
979 | -add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' ); |
|
979 | +add_filter('option_page_capability_wpinv_settings', 'wpinv_set_settings_cap'); |
|
980 | 980 | |
981 | -function wpinv_settings_sanitize_input( $value, $key ) { |
|
981 | +function wpinv_settings_sanitize_input($value, $key) { |
|
982 | 982 | |
983 | - if ( $key == 'tax_rate' ) { |
|
984 | - $value = wpinv_sanitize_amount( $value ); |
|
983 | + if ($key == 'tax_rate') { |
|
984 | + $value = wpinv_sanitize_amount($value); |
|
985 | 985 | $value = $value >= 100 ? 99 : $value; |
986 | 986 | } |
987 | 987 | |
988 | 988 | return $value; |
989 | 989 | } |
990 | -add_filter( 'wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2 ); |
|
990 | +add_filter('wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2); |
|
991 | 991 | |
992 | -function wpinv_on_update_settings( $old_value, $value, $option ) { |
|
993 | - $old = !empty( $old_value['remove_data_on_unistall'] ) ? 1 : ''; |
|
994 | - $new = !empty( $value['remove_data_on_unistall'] ) ? 1 : ''; |
|
992 | +function wpinv_on_update_settings($old_value, $value, $option) { |
|
993 | + $old = !empty($old_value['remove_data_on_unistall']) ? 1 : ''; |
|
994 | + $new = !empty($value['remove_data_on_unistall']) ? 1 : ''; |
|
995 | 995 | |
996 | - if ( $old != $new ) { |
|
997 | - update_option( 'wpinv_remove_data_on_invoice_unistall', $new ); |
|
996 | + if ($old != $new) { |
|
997 | + update_option('wpinv_remove_data_on_invoice_unistall', $new); |
|
998 | 998 | } |
999 | 999 | } |
1000 | -add_action( 'update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3 ); |
|
1001 | -add_action( 'wpinv_settings_tab_bottom_emails_new_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1002 | -add_action( 'wpinv_settings_tab_bottom_emails_cancelled_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1003 | -add_action( 'wpinv_settings_tab_bottom_emails_failed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1004 | -add_action( 'wpinv_settings_tab_bottom_emails_onhold_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1005 | -add_action( 'wpinv_settings_tab_bottom_emails_processing_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1006 | -add_action( 'wpinv_settings_tab_bottom_emails_completed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1007 | -add_action( 'wpinv_settings_tab_bottom_emails_refunded_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1008 | -add_action( 'wpinv_settings_tab_bottom_emails_user_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1009 | -add_action( 'wpinv_settings_tab_bottom_emails_user_note', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1010 | -add_action( 'wpinv_settings_tab_bottom_emails_overdue', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1011 | - |
|
1012 | -function wpinv_settings_tab_bottom_emails( $active_tab, $section ) { |
|
1000 | +add_action('update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3); |
|
1001 | +add_action('wpinv_settings_tab_bottom_emails_new_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1002 | +add_action('wpinv_settings_tab_bottom_emails_cancelled_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1003 | +add_action('wpinv_settings_tab_bottom_emails_failed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1004 | +add_action('wpinv_settings_tab_bottom_emails_onhold_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1005 | +add_action('wpinv_settings_tab_bottom_emails_processing_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1006 | +add_action('wpinv_settings_tab_bottom_emails_completed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1007 | +add_action('wpinv_settings_tab_bottom_emails_refunded_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1008 | +add_action('wpinv_settings_tab_bottom_emails_user_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1009 | +add_action('wpinv_settings_tab_bottom_emails_user_note', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1010 | +add_action('wpinv_settings_tab_bottom_emails_overdue', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1011 | + |
|
1012 | +function wpinv_settings_tab_bottom_emails($active_tab, $section) { |
|
1013 | 1013 | ?> |
1014 | 1014 | <div class="wpinv-email-wc-row "> |
1015 | 1015 | <div class="wpinv-email-wc-td"> |
1016 | - <h3 class="wpinv-email-wc-title"><?php echo apply_filters( 'wpinv_settings_email_wildcards_title', __( 'Wildcards For Emails', 'invoicing' ) ); ?></h3> |
|
1016 | + <h3 class="wpinv-email-wc-title"><?php echo apply_filters('wpinv_settings_email_wildcards_title', __('Wildcards For Emails', 'invoicing')); ?></h3> |
|
1017 | 1017 | <p class="wpinv-email-wc-description"> |
1018 | 1018 | <?php |
1019 | - $description = __( 'The following wildcards can be used in email subjects, heading and content:<br> |
|
1019 | + $description = __('The following wildcards can be used in email subjects, heading and content:<br> |
|
1020 | 1020 | <strong>{site_title} :</strong> Site Title<br> |
1021 | 1021 | <strong>{name} :</strong> Customer\'s full name<br> |
1022 | 1022 | <strong>{first_name} :</strong> Customer\'s first name<br> |
@@ -1030,7 +1030,7 @@ discard block |
||
1030 | 1030 | <strong>{invoice_due_date} :</strong> The date the invoice is due<br> |
1031 | 1031 | <strong>{date} :</strong> Today\'s date.<br> |
1032 | 1032 | <strong>{is_was} :</strong> If due date of invoice is past, displays "was" otherwise displays "is"<br> |
1033 | - <strong>{invoice_label} :</strong> Invoices/quotes singular name. Ex: Invoice/Quote<br>', 'invoicing' ); |
|
1033 | + <strong>{invoice_label} :</strong> Invoices/quotes singular name. Ex: Invoice/Quote<br>', 'invoicing'); |
|
1034 | 1034 | echo apply_filters('wpinv_settings_email_wildcards_description', $description, $active_tab, $section); |
1035 | 1035 | ?> |
1036 | 1036 | </p> |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | class WPInv_EUVat { |
10 | 10 | |
@@ -24,115 +24,115 @@ discard block |
||
24 | 24 | public function init() { |
25 | 25 | |
26 | 26 | // If this is an admin page... |
27 | - if ( is_admin() ) { |
|
27 | + if (is_admin()) { |
|
28 | 28 | |
29 | 29 | // Register our scripts. |
30 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); |
|
31 | - add_action( 'wpinv_settings_sections_taxes', array( $this, 'section_vat_settings' ) ); |
|
32 | - add_action( 'wpinv_settings_taxes', array( $this, 'vat_settings' ) ); |
|
33 | - add_filter( 'wpinv_settings_taxes-vat_sanitize', array( $this, 'sanitize_vat_settings' ) ); |
|
30 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts')); |
|
31 | + add_action('wpinv_settings_sections_taxes', array($this, 'section_vat_settings')); |
|
32 | + add_action('wpinv_settings_taxes', array($this, 'vat_settings')); |
|
33 | + add_filter('wpinv_settings_taxes-vat_sanitize', array($this, 'sanitize_vat_settings')); |
|
34 | 34 | } |
35 | 35 | |
36 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_vat_scripts' ) ); |
|
37 | - add_filter( 'wpinv_default_billing_country', array( $this, 'get_user_country' ), 10 ); |
|
38 | - add_filter( 'wpinv_get_user_country', array( $this, 'set_user_country' ), 10 ); |
|
39 | - add_action( 'wp_ajax_wpinv_vat_validate', array( $this, 'ajax_vat_validate' ) ); |
|
40 | - add_action( 'wp_ajax_nopriv_wpinv_vat_validate', array( $this, 'ajax_vat_validate' ) ); |
|
36 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_vat_scripts')); |
|
37 | + add_filter('wpinv_default_billing_country', array($this, 'get_user_country'), 10); |
|
38 | + add_filter('wpinv_get_user_country', array($this, 'set_user_country'), 10); |
|
39 | + add_action('wp_ajax_wpinv_vat_validate', array($this, 'ajax_vat_validate')); |
|
40 | + add_action('wp_ajax_nopriv_wpinv_vat_validate', array($this, 'ajax_vat_validate')); |
|
41 | 41 | |
42 | 42 | } |
43 | 43 | |
44 | - public static function get_eu_states( $sort = true ) { |
|
45 | - $eu_states = array( 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE' ); |
|
46 | - if ( $sort ) { |
|
47 | - $sort = sort( $eu_states ); |
|
44 | + public static function get_eu_states($sort = true) { |
|
45 | + $eu_states = array('AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE'); |
|
46 | + if ($sort) { |
|
47 | + $sort = sort($eu_states); |
|
48 | 48 | } |
49 | 49 | |
50 | - return apply_filters( 'wpinv_get_eu_states', $eu_states, $sort ); |
|
50 | + return apply_filters('wpinv_get_eu_states', $eu_states, $sort); |
|
51 | 51 | } |
52 | 52 | |
53 | - public static function get_gst_countries( $sort = true ) { |
|
54 | - $gst_countries = array( 'AU', 'NZ', 'CA', 'CN' ); |
|
53 | + public static function get_gst_countries($sort = true) { |
|
54 | + $gst_countries = array('AU', 'NZ', 'CA', 'CN'); |
|
55 | 55 | |
56 | - if ( $sort ) { |
|
57 | - $sort = sort( $gst_countries ); |
|
56 | + if ($sort) { |
|
57 | + $sort = sort($gst_countries); |
|
58 | 58 | } |
59 | 59 | |
60 | - return apply_filters( 'wpinv_get_gst_countries', $gst_countries, $sort ); |
|
60 | + return apply_filters('wpinv_get_gst_countries', $gst_countries, $sort); |
|
61 | 61 | } |
62 | 62 | |
63 | - public static function is_eu_state( $country_code ) { |
|
64 | - $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_eu_states() ) ? true : false; |
|
63 | + public static function is_eu_state($country_code) { |
|
64 | + $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_eu_states()) ? true : false; |
|
65 | 65 | |
66 | - return apply_filters( 'wpinv_is_eu_state', $return, $country_code ); |
|
66 | + return apply_filters('wpinv_is_eu_state', $return, $country_code); |
|
67 | 67 | } |
68 | 68 | |
69 | - public static function is_gst_country( $country_code ) { |
|
70 | - $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_gst_countries() ) ? true : false; |
|
69 | + public static function is_gst_country($country_code) { |
|
70 | + $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_gst_countries()) ? true : false; |
|
71 | 71 | |
72 | - return apply_filters( 'wpinv_is_gst_country', $return, $country_code ); |
|
72 | + return apply_filters('wpinv_is_gst_country', $return, $country_code); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | public function enqueue_vat_scripts() { |
76 | - if( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ) { |
|
76 | + if (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules')) { |
|
77 | 77 | $this->load_vat_scripts(); |
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
81 | - public function load_vat_scripts(){ |
|
82 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
81 | + public function load_vat_scripts() { |
|
82 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
83 | 83 | |
84 | - wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
85 | - wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
84 | + wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
85 | + wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
86 | 86 | |
87 | - $vat_name = $this->get_vat_name(); |
|
87 | + $vat_name = $this->get_vat_name(); |
|
88 | 88 | |
89 | 89 | $vars = array(); |
90 | 90 | $vars['UseTaxes'] = wpinv_use_taxes(); |
91 | 91 | $vars['EUStates'] = self::get_eu_states(); |
92 | - $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' ); |
|
93 | - $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' ); |
|
94 | - $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name ); |
|
95 | - $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name ); |
|
96 | - $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name ); |
|
97 | - $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name ); |
|
98 | - $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name ); |
|
99 | - $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' ); |
|
92 | + $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing'); |
|
93 | + $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing'); |
|
94 | + $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name); |
|
95 | + $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name); |
|
96 | + $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name); |
|
97 | + $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name); |
|
98 | + $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name); |
|
99 | + $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing'); |
|
100 | 100 | $vars['ApplyVATRules'] = $vars['UseTaxes'] ? self::allow_vat_rules() : false; |
101 | - $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' ); |
|
102 | - $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' ); |
|
103 | - $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' ); |
|
104 | - $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' ); |
|
105 | - $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' ); |
|
106 | - $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' ); |
|
107 | - $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' ); |
|
108 | - $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' ); |
|
109 | - $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name ); |
|
110 | - $vars['VatReseting'] = __( 'Reseting...', 'invoicing' ); |
|
111 | - $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
112 | - $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
113 | - $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' ); |
|
101 | + $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing'); |
|
102 | + $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing'); |
|
103 | + $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing'); |
|
104 | + $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing'); |
|
105 | + $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing'); |
|
106 | + $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing'); |
|
107 | + $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing'); |
|
108 | + $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing'); |
|
109 | + $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name); |
|
110 | + $vars['VatReseting'] = __('Reseting...', 'invoicing'); |
|
111 | + $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
112 | + $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
113 | + $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing'); |
|
114 | 114 | $vars['isFront'] = is_admin() ? false : true; |
115 | 115 | $vars['baseCountry'] = wpinv_get_default_country(); |
116 | - $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false ); |
|
117 | - $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false; |
|
116 | + $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false); |
|
117 | + $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false; |
|
118 | 118 | |
119 | - wp_enqueue_script( 'wpinv-vat-validation-script' ); |
|
120 | - wp_enqueue_script( 'wpinv-vat-script' ); |
|
121 | - wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars ); |
|
119 | + wp_enqueue_script('wpinv-vat-validation-script'); |
|
120 | + wp_enqueue_script('wpinv-vat-script'); |
|
121 | + wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | public static function enqueue_admin_scripts() { |
125 | - if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) { |
|
125 | + if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) { |
|
126 | 126 | self::load_vat_scripts(); |
127 | 127 | } |
128 | 128 | } |
129 | 129 | |
130 | - public static function section_vat_settings( $sections ) { |
|
131 | - if ( !empty( $sections ) ) { |
|
132 | - $sections['vat'] = __( 'EU VAT Settings', 'invoicing' ); |
|
130 | + public static function section_vat_settings($sections) { |
|
131 | + if (!empty($sections)) { |
|
132 | + $sections['vat'] = __('EU VAT Settings', 'invoicing'); |
|
133 | 133 | |
134 | - if ( self::allow_vat_classes() ) { |
|
135 | - $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' ); |
|
134 | + if (self::allow_vat_classes()) { |
|
135 | + $sections['vat_rates'] = __('EU VAT Rates', 'invoicing'); |
|
136 | 136 | } |
137 | 137 | } |
138 | 138 | return $sections; |
@@ -143,12 +143,12 @@ discard block |
||
143 | 143 | */ |
144 | 144 | public static function vat_rates_settings() {} |
145 | 145 | |
146 | - public static function vat_settings( $settings ) { |
|
147 | - if ( !empty( $settings ) ) { |
|
146 | + public static function vat_settings($settings) { |
|
147 | + if (!empty($settings)) { |
|
148 | 148 | $vat_settings = array(); |
149 | 149 | $vat_settings['vat_company_title'] = array( |
150 | 150 | 'id' => 'vat_company_title', |
151 | - 'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>', |
|
151 | + 'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>', |
|
152 | 152 | 'desc' => '', |
153 | 153 | 'type' => 'header', |
154 | 154 | 'size' => 'regular' |
@@ -156,22 +156,22 @@ discard block |
||
156 | 156 | |
157 | 157 | $vat_settings['vat_company_name'] = array( |
158 | 158 | 'id' => 'vat_company_name', |
159 | - 'name' => __( 'Your Company Name', 'invoicing' ), |
|
160 | - 'desc' => wp_sprintf(__( 'Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
159 | + 'name' => __('Your Company Name', 'invoicing'), |
|
160 | + 'desc' => wp_sprintf(__('Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
161 | 161 | 'type' => 'text', |
162 | 162 | 'size' => 'regular', |
163 | 163 | ); |
164 | 164 | |
165 | 165 | $vat_settings['vat_number'] = array( |
166 | 166 | 'id' => 'vat_number', |
167 | - 'name' => __( 'Your VAT Number', 'invoicing' ), |
|
167 | + 'name' => __('Your VAT Number', 'invoicing'), |
|
168 | 168 | 'type' => 'vat_number', |
169 | 169 | 'size' => 'regular', |
170 | 170 | ); |
171 | 171 | |
172 | 172 | $vat_settings['vat_settings_title'] = array( |
173 | 173 | 'id' => 'vat_settings_title', |
174 | - 'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>', |
|
174 | + 'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>', |
|
175 | 175 | 'desc' => '', |
176 | 176 | 'type' => 'header', |
177 | 177 | 'size' => 'regular' |
@@ -179,37 +179,37 @@ discard block |
||
179 | 179 | |
180 | 180 | $vat_settings['apply_vat_rules'] = array( |
181 | 181 | 'id' => 'apply_vat_rules', |
182 | - 'name' => __( 'Enable VAT Rules', 'invoicing' ), |
|
183 | - 'desc' => __( 'Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable unless you know what you are doing.', 'invoicing' ) . '</font>', |
|
182 | + 'name' => __('Enable VAT Rules', 'invoicing'), |
|
183 | + 'desc' => __('Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable unless you know what you are doing.', 'invoicing') . '</font>', |
|
184 | 184 | 'type' => 'checkbox', |
185 | 185 | 'std' => '1' |
186 | 186 | ); |
187 | 187 | |
188 | 188 | $vat_settings['vat_prevent_b2c_purchase'] = array( |
189 | 189 | 'id' => 'vat_prevent_b2c_purchase', |
190 | - 'name' => __( 'Prevent EU B2C Sales', 'invoicing' ), |
|
191 | - 'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ), |
|
190 | + 'name' => __('Prevent EU B2C Sales', 'invoicing'), |
|
191 | + 'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'), |
|
192 | 192 | 'type' => 'checkbox' |
193 | 193 | ); |
194 | 194 | |
195 | 195 | $vat_settings['vat_same_country_rule'] = array( |
196 | 196 | 'id' => 'vat_same_country_rule', |
197 | - 'name' => __( 'Same Country Rule', 'invoicing' ), |
|
198 | - 'desc' => __( 'Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing' ), |
|
197 | + 'name' => __('Same Country Rule', 'invoicing'), |
|
198 | + 'desc' => __('Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing'), |
|
199 | 199 | 'type' => 'select', |
200 | 200 | 'options' => array( |
201 | - '' => __( 'Normal', 'invoicing' ), |
|
202 | - 'no' => __( 'No VAT', 'invoicing' ), |
|
203 | - 'always' => __( 'Always apply VAT', 'invoicing' ), |
|
201 | + '' => __('Normal', 'invoicing'), |
|
202 | + 'no' => __('No VAT', 'invoicing'), |
|
203 | + 'always' => __('Always apply VAT', 'invoicing'), |
|
204 | 204 | ), |
205 | - 'placeholder' => __( 'Select an option', 'invoicing' ), |
|
205 | + 'placeholder' => __('Select an option', 'invoicing'), |
|
206 | 206 | 'std' => '', |
207 | 207 | 'class' => 'wpi_select2', |
208 | 208 | ); |
209 | 209 | |
210 | 210 | $vat_settings['vat_checkout_title'] = array( |
211 | 211 | 'id' => 'vat_checkout_title', |
212 | - 'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>', |
|
212 | + 'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>', |
|
213 | 213 | 'desc' => '', |
214 | 214 | 'type' => 'header', |
215 | 215 | 'size' => 'regular' |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | |
218 | 218 | $vat_settings['vies_validation_title'] = array( |
219 | 219 | 'id' => 'vies_validation_title', |
220 | - 'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>', |
|
220 | + 'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>', |
|
221 | 221 | 'desc' => '', |
222 | 222 | 'type' => 'header', |
223 | 223 | 'size' => 'regular' |
@@ -225,22 +225,22 @@ discard block |
||
225 | 225 | |
226 | 226 | $vat_settings['vat_vies_check'] = array( |
227 | 227 | 'id' => 'vat_vies_check', |
228 | - 'name' => __( 'Disable VIES VAT ID Check', 'invoicing' ), |
|
229 | - 'desc' => wp_sprintf( __( 'Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
228 | + 'name' => __('Disable VIES VAT ID Check', 'invoicing'), |
|
229 | + 'desc' => wp_sprintf(__('Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
230 | 230 | 'type' => 'checkbox' |
231 | 231 | ); |
232 | 232 | |
233 | 233 | $vat_settings['vat_disable_company_name_check'] = array( |
234 | 234 | 'id' => 'vat_disable_company_name_check', |
235 | - 'name' => __( 'Disable VIES Name Check', 'invoicing' ), |
|
236 | - 'desc' => wp_sprintf( __( 'Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
235 | + 'name' => __('Disable VIES Name Check', 'invoicing'), |
|
236 | + 'desc' => wp_sprintf(__('Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
237 | 237 | 'type' => 'checkbox' |
238 | 238 | ); |
239 | 239 | |
240 | 240 | $vat_settings['vat_offline_check'] = array( |
241 | 241 | 'id' => 'vat_offline_check', |
242 | - 'name' => __( 'Disable Basic Checks', 'invoicing' ), |
|
243 | - 'desc' => __( 'Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing' ), |
|
242 | + 'name' => __('Disable Basic Checks', 'invoicing'), |
|
243 | + 'desc' => __('Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing'), |
|
244 | 244 | 'type' => 'checkbox' |
245 | 245 | ); |
246 | 246 | |
@@ -333,34 +333,34 @@ discard block |
||
333 | 333 | return getpaid_get_ip_country(); |
334 | 334 | } |
335 | 335 | |
336 | - public static function sanitize_vat_settings( $input ) { |
|
336 | + public static function sanitize_vat_settings($input) { |
|
337 | 337 | global $wpinv_options; |
338 | 338 | |
339 | 339 | $valid = false; |
340 | 340 | $message = ''; |
341 | 341 | |
342 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
343 | - if ( empty( $wpinv_options['vat_offline_check'] ) ) { |
|
344 | - $valid = self::offline_check( $input['vat_number'] ); |
|
342 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
343 | + if (empty($wpinv_options['vat_offline_check'])) { |
|
344 | + $valid = self::offline_check($input['vat_number']); |
|
345 | 345 | } else { |
346 | 346 | $valid = true; |
347 | 347 | } |
348 | 348 | |
349 | - $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' ); |
|
349 | + $message = $valid ? '' : __('VAT number not validated', 'invoicing'); |
|
350 | 350 | } else { |
351 | - $result = self::check_vat( $input['vat_number'] ); |
|
351 | + $result = self::check_vat($input['vat_number']); |
|
352 | 352 | |
353 | - if ( empty( $result['valid'] ) ) { |
|
353 | + if (empty($result['valid'])) { |
|
354 | 354 | $valid = false; |
355 | 355 | $message = $result['message']; |
356 | 356 | } else { |
357 | - $valid = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] ); |
|
358 | - $message = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' ); |
|
357 | + $valid = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']); |
|
358 | + $message = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing'); |
|
359 | 359 | } |
360 | 360 | } |
361 | 361 | |
362 | - if ( $message && self::is_vat_validated() != $valid ) { |
|
363 | - add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) ); |
|
362 | + if ($message && self::is_vat_validated() != $valid) { |
|
363 | + add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error')); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | $input['vat_valid'] = $valid; |
@@ -393,46 +393,46 @@ discard block |
||
393 | 393 | public static function hide_vat_fields() {} |
394 | 394 | |
395 | 395 | public static function same_country_rule() { |
396 | - $same_country_rule = wpinv_get_option( 'vat_same_country_rule' ); |
|
396 | + $same_country_rule = wpinv_get_option('vat_same_country_rule'); |
|
397 | 397 | |
398 | - return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule ); |
|
398 | + return apply_filters('wpinv_vat_same_country_rule', $same_country_rule); |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | /** |
402 | 402 | * Retrieves the vat name. |
403 | 403 | */ |
404 | 404 | public function get_vat_name() { |
405 | - $vat_name = wpinv_get_option( 'vat_name' ); |
|
406 | - return empty( $vat_name ) ? __( 'VAT', 'invoicing' ) : sanitize_text_field( $vat_name ); |
|
405 | + $vat_name = wpinv_get_option('vat_name'); |
|
406 | + return empty($vat_name) ? __('VAT', 'invoicing') : sanitize_text_field($vat_name); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | public static function get_company_name() { |
410 | - $company_name = wpinv_get_option( 'vat_company_name' ); |
|
410 | + $company_name = wpinv_get_option('vat_company_name'); |
|
411 | 411 | |
412 | - return apply_filters( 'wpinv_get_owner_company_name', $company_name ); |
|
412 | + return apply_filters('wpinv_get_owner_company_name', $company_name); |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | public static function get_vat_number() { |
416 | - $vat_number = wpinv_get_option( 'vat_number' ); |
|
416 | + $vat_number = wpinv_get_option('vat_number'); |
|
417 | 417 | |
418 | - return apply_filters( 'wpinv_get_owner_vat_number', $vat_number ); |
|
418 | + return apply_filters('wpinv_get_owner_vat_number', $vat_number); |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | public static function is_vat_validated() { |
422 | - $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' ); |
|
422 | + $validated = self::get_vat_number() && wpinv_get_option('vat_valid'); |
|
423 | 423 | |
424 | - return apply_filters( 'wpinv_is_owner_vat_validated', $validated ); |
|
424 | + return apply_filters('wpinv_is_owner_vat_validated', $validated); |
|
425 | 425 | } |
426 | 426 | |
427 | - public static function sanitize_vat( $vat_number, $country_code = '' ) { |
|
428 | - $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) ); |
|
427 | + public static function sanitize_vat($vat_number, $country_code = '') { |
|
428 | + $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number))); |
|
429 | 429 | |
430 | - if ( empty( $country_code ) ) { |
|
431 | - $country_code = substr( $vat_number, 0, 2 ); |
|
430 | + if (empty($country_code)) { |
|
431 | + $country_code = substr($vat_number, 0, 2); |
|
432 | 432 | } |
433 | 433 | |
434 | - if ( strpos( $vat_number , $country_code ) === 0 ) { |
|
435 | - $vat = str_replace( $country_code, '', $vat_number ); |
|
434 | + if (strpos($vat_number, $country_code) === 0) { |
|
435 | + $vat = str_replace($country_code, '', $vat_number); |
|
436 | 436 | } else { |
437 | 437 | $vat = $country_code . $vat_number; |
438 | 438 | } |
@@ -445,140 +445,140 @@ discard block |
||
445 | 445 | return $return; |
446 | 446 | } |
447 | 447 | |
448 | - public static function offline_check( $vat_number, $country_code = '', $formatted = false ) { |
|
449 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
448 | + public static function offline_check($vat_number, $country_code = '', $formatted = false) { |
|
449 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
450 | 450 | $vat_number = $vat['vat_number']; |
451 | 451 | $country_code = $vat['iso']; |
452 | 452 | $regex = array(); |
453 | 453 | |
454 | - switch ( $country_code ) { |
|
454 | + switch ($country_code) { |
|
455 | 455 | case 'AT': |
456 | - $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
456 | + $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
457 | 457 | break; |
458 | 458 | case 'BE': |
459 | - $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
459 | + $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
460 | 460 | break; |
461 | 461 | case 'BG': |
462 | - $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
462 | + $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
463 | 463 | break; |
464 | 464 | case 'CH': |
465 | 465 | case 'CHE': |
466 | - $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
466 | + $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
467 | 467 | break; |
468 | 468 | case 'CY': |
469 | - $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
469 | + $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
470 | 470 | break; |
471 | 471 | case 'CZ': |
472 | - $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
472 | + $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
473 | 473 | break; |
474 | 474 | case 'DE': |
475 | - $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
475 | + $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
476 | 476 | break; |
477 | 477 | case 'DK': |
478 | - $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
478 | + $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
479 | 479 | break; |
480 | 480 | case 'EE': |
481 | - $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
481 | + $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
482 | 482 | break; |
483 | 483 | case 'EL': |
484 | - $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
484 | + $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
485 | 485 | break; |
486 | 486 | case 'ES': |
487 | - $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
488 | - $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
489 | - $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
490 | - $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
487 | + $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
488 | + $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
489 | + $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
490 | + $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
491 | 491 | break; |
492 | 492 | case 'EU': |
493 | - $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
493 | + $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
494 | 494 | break; |
495 | 495 | case 'FI': |
496 | - $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
496 | + $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
497 | 497 | break; |
498 | 498 | case 'FR': |
499 | - $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
500 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
501 | - $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
502 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
499 | + $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
500 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
501 | + $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
502 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
503 | 503 | break; |
504 | 504 | case 'GB': |
505 | - $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
506 | - $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
507 | - $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
508 | - $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
505 | + $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
506 | + $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
507 | + $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
508 | + $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
509 | 509 | break; |
510 | 510 | case 'GR': |
511 | - $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
511 | + $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
512 | 512 | break; |
513 | 513 | case 'HR': |
514 | - $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
514 | + $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
515 | 515 | break; |
516 | 516 | case 'HU': |
517 | - $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
517 | + $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
518 | 518 | break; |
519 | 519 | case 'IE': |
520 | - $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
521 | - $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
522 | - $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
520 | + $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
521 | + $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
522 | + $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
523 | 523 | break; |
524 | 524 | case 'IT': |
525 | - $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
525 | + $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
526 | 526 | break; |
527 | 527 | case 'LV': |
528 | - $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
528 | + $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
529 | 529 | break; |
530 | 530 | case 'LT': |
531 | - $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
531 | + $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
532 | 532 | break; |
533 | 533 | case 'LU': |
534 | - $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
534 | + $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
535 | 535 | break; |
536 | 536 | case 'MT': |
537 | - $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
537 | + $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
538 | 538 | break; |
539 | 539 | case 'NL': |
540 | - $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
540 | + $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
541 | 541 | break; |
542 | 542 | case 'NO': |
543 | - $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
543 | + $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
544 | 544 | break; |
545 | 545 | case 'PL': |
546 | - $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
546 | + $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
547 | 547 | break; |
548 | 548 | case 'PT': |
549 | - $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
549 | + $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
550 | 550 | break; |
551 | 551 | case 'RO': |
552 | - $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
552 | + $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
553 | 553 | break; |
554 | 554 | case 'RS': |
555 | - $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
555 | + $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
556 | 556 | break; |
557 | 557 | case 'SI': |
558 | - $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
558 | + $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
559 | 559 | break; |
560 | 560 | case 'SK': |
561 | - $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
561 | + $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
562 | 562 | break; |
563 | 563 | case 'SE': |
564 | - $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
564 | + $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
565 | 565 | break; |
566 | 566 | default: |
567 | 567 | $regex = array(); |
568 | 568 | break; |
569 | 569 | } |
570 | 570 | |
571 | - if ( empty( $regex ) ) { |
|
571 | + if (empty($regex)) { |
|
572 | 572 | return false; |
573 | 573 | } |
574 | 574 | |
575 | - foreach ( $regex as $pattern ) { |
|
575 | + foreach ($regex as $pattern) { |
|
576 | 576 | $matches = null; |
577 | - preg_match_all( $pattern, $vat_number, $matches ); |
|
577 | + preg_match_all($pattern, $vat_number, $matches); |
|
578 | 578 | |
579 | - if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) { |
|
580 | - if ( $formatted ) { |
|
581 | - return array( 'code' => $matches[1][0], 'number' => $matches[2][0] ); |
|
579 | + if (!empty($matches[1][0]) && !empty($matches[2][0])) { |
|
580 | + if ($formatted) { |
|
581 | + return array('code' => $matches[1][0], 'number' => $matches[2][0]); |
|
582 | 582 | } else { |
583 | 583 | return true; |
584 | 584 | } |
@@ -588,76 +588,76 @@ discard block |
||
588 | 588 | return false; |
589 | 589 | } |
590 | 590 | |
591 | - public static function vies_check( $vat_number, $country_code = '', $result = false ) { |
|
592 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
591 | + public static function vies_check($vat_number, $country_code = '', $result = false) { |
|
592 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
593 | 593 | $vat_number = $vat['vat']; |
594 | 594 | $iso = $vat['iso']; |
595 | 595 | $response = false; |
596 | 596 | |
597 | - $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number ); |
|
597 | + $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number); |
|
598 | 598 | |
599 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
600 | - $response = file_get_contents( $url ); |
|
601 | - } else if ( function_exists( 'curl_init' ) ) { |
|
599 | + if (ini_get('allow_url_fopen')) { |
|
600 | + $response = file_get_contents($url); |
|
601 | + } else if (function_exists('curl_init')) { |
|
602 | 602 | $ch = curl_init(); |
603 | 603 | |
604 | - curl_setopt( $ch, CURLOPT_URL, $url ); |
|
605 | - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 ); |
|
606 | - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); |
|
607 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); |
|
608 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); |
|
604 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
605 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); |
|
606 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
607 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
|
608 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
609 | 609 | |
610 | - $response = curl_exec( $ch ); |
|
610 | + $response = curl_exec($ch); |
|
611 | 611 | |
612 | - if ( curl_errno( $ch ) ) { |
|
613 | - wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' ); |
|
612 | + if (curl_errno($ch)) { |
|
613 | + wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR'); |
|
614 | 614 | $response = ''; |
615 | 615 | } |
616 | 616 | |
617 | - curl_close( $ch ); |
|
617 | + curl_close($ch); |
|
618 | 618 | } else { |
619 | - wpinv_error_log( 'To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR' ); |
|
619 | + wpinv_error_log('To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR'); |
|
620 | 620 | } |
621 | 621 | |
622 | - if ( empty( $response ) ) { |
|
622 | + if (empty($response)) { |
|
623 | 623 | return $result; |
624 | 624 | } |
625 | 625 | |
626 | - if ( preg_match( '/invalid VAT number/i', $response ) ) { |
|
626 | + if (preg_match('/invalid VAT number/i', $response)) { |
|
627 | 627 | return false; |
628 | - } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) { |
|
629 | - $content = explode( "valid VAT number", htmlentities( $response ) ); |
|
628 | + } else if (preg_match('/valid VAT number/i', $response, $matches)) { |
|
629 | + $content = explode("valid VAT number", htmlentities($response)); |
|
630 | 630 | |
631 | - if ( !empty( $content[1] ) ) { |
|
632 | - preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches ); |
|
631 | + if (!empty($content[1])) { |
|
632 | + preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches); |
|
633 | 633 | |
634 | - if ( !empty( $matches[2] ) && $matches[3] ) { |
|
634 | + if (!empty($matches[2]) && $matches[3]) { |
|
635 | 635 | $return = array(); |
636 | 636 | |
637 | - foreach ( $matches[2] as $key => $label ) { |
|
638 | - $label = trim( $label ); |
|
637 | + foreach ($matches[2] as $key => $label) { |
|
638 | + $label = trim($label); |
|
639 | 639 | |
640 | - switch ( strtolower( $label ) ) { |
|
640 | + switch (strtolower($label)) { |
|
641 | 641 | case 'member state': |
642 | - $return['state'] = trim( strip_tags( $matches[3][$key] ) ); |
|
642 | + $return['state'] = trim(strip_tags($matches[3][$key])); |
|
643 | 643 | break; |
644 | 644 | case 'vat number': |
645 | - $return['number'] = trim( strip_tags( $matches[3][$key] ) ); |
|
645 | + $return['number'] = trim(strip_tags($matches[3][$key])); |
|
646 | 646 | break; |
647 | 647 | case 'name': |
648 | - $return['company'] = trim( strip_tags( $matches[3][$key] ) ); |
|
648 | + $return['company'] = trim(strip_tags($matches[3][$key])); |
|
649 | 649 | break; |
650 | 650 | case 'address': |
651 | - $address = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) ); |
|
652 | - $return['address'] = trim( strip_tags( $address, '<br>' ) ); |
|
651 | + $address = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key]))); |
|
652 | + $return['address'] = trim(strip_tags($address, '<br>')); |
|
653 | 653 | break; |
654 | 654 | case 'consultation number': |
655 | - $return['consultation'] = trim( strip_tags( $matches[3][$key] ) ); |
|
655 | + $return['consultation'] = trim(strip_tags($matches[3][$key])); |
|
656 | 656 | break; |
657 | 657 | } |
658 | 658 | } |
659 | 659 | |
660 | - if ( !empty( $return ) ) { |
|
660 | + if (!empty($return)) { |
|
661 | 661 | return $return; |
662 | 662 | } |
663 | 663 | } |
@@ -669,30 +669,30 @@ discard block |
||
669 | 669 | } |
670 | 670 | } |
671 | 671 | |
672 | - public static function check_vat( $vat_number, $country_code = '' ) { |
|
672 | + public static function check_vat($vat_number, $country_code = '') { |
|
673 | 673 | $vat_name = getpaid_vat_name(); |
674 | 674 | |
675 | 675 | $return = array(); |
676 | 676 | $return['valid'] = false; |
677 | - $return['message'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
677 | + $return['message'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
678 | 678 | |
679 | - if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) { |
|
679 | + if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) { |
|
680 | 680 | return $return; |
681 | 681 | } |
682 | 682 | |
683 | - $response = self::vies_check( $vat_number, $country_code ); |
|
683 | + $response = self::vies_check($vat_number, $country_code); |
|
684 | 684 | |
685 | - if ( $response ) { |
|
686 | - $return['valid'] = true; |
|
685 | + if ($response) { |
|
686 | + $return['valid'] = true; |
|
687 | 687 | |
688 | - if ( is_array( $response ) ) { |
|
689 | - $return['company'] = isset( $response['company'] ) ? $response['company'] : ''; |
|
690 | - $return['address'] = isset( $response['address'] ) ? $response['address'] : ''; |
|
688 | + if (is_array($response)) { |
|
689 | + $return['company'] = isset($response['company']) ? $response['company'] : ''; |
|
690 | + $return['address'] = isset($response['address']) ? $response['address'] : ''; |
|
691 | 691 | $return['message'] = $return['company'] . '<br/>' . $return['address']; |
692 | 692 | } |
693 | 693 | } else { |
694 | 694 | $return['valid'] = false; |
695 | - $return['message'] = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name ); |
|
695 | + $return['message'] = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name); |
|
696 | 696 | } |
697 | 697 | |
698 | 698 | return $return; |
@@ -705,67 +705,67 @@ discard block |
||
705 | 705 | return array(); |
706 | 706 | } |
707 | 707 | |
708 | - public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) { |
|
708 | + public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) { |
|
709 | 709 | global $wpi_item_id, $wpi_country; |
710 | 710 | |
711 | - if ( !empty( $_POST['wpinv_country'] ) ) { |
|
712 | - $country_code = trim( $_POST['wpinv_country'] ); |
|
713 | - } else if ( !empty( $_POST['country'] ) ) { |
|
714 | - $country_code = trim( $_POST['country'] ); |
|
715 | - } else if ( !empty( $wpi_country ) ) { |
|
711 | + if (!empty($_POST['wpinv_country'])) { |
|
712 | + $country_code = trim($_POST['wpinv_country']); |
|
713 | + } else if (!empty($_POST['country'])) { |
|
714 | + $country_code = trim($_POST['country']); |
|
715 | + } else if (!empty($wpi_country)) { |
|
716 | 716 | $country_code = $wpi_country; |
717 | 717 | } else { |
718 | - $country_code = self::get_user_country( '', $user_id ); |
|
718 | + $country_code = self::get_user_country('', $user_id); |
|
719 | 719 | } |
720 | 720 | |
721 | - if ( $is_digital === null && $wpi_item_id ) { |
|
722 | - $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules(); |
|
721 | + if ($is_digital === null && $wpi_item_id) { |
|
722 | + $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules(); |
|
723 | 723 | } |
724 | 724 | |
725 | - if ( !empty( $country_code ) ) { |
|
726 | - $requires_vat = ( self::is_eu_state( $country_code ) && ( self::is_eu_state( wpinv_get_default_country() ) || $is_digital ) ) || ( self::is_gst_country( $country_code ) && self::is_gst_country( wpinv_get_default_country() ) ); |
|
725 | + if (!empty($country_code)) { |
|
726 | + $requires_vat = (self::is_eu_state($country_code) && (self::is_eu_state(wpinv_get_default_country()) || $is_digital)) || (self::is_gst_country($country_code) && self::is_gst_country(wpinv_get_default_country())); |
|
727 | 727 | } |
728 | 728 | |
729 | - return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id ); |
|
729 | + return apply_filters('wpinv_requires_vat', $requires_vat, $user_id); |
|
730 | 730 | } |
731 | 731 | |
732 | - public static function tax_label( $label = '' ) { |
|
732 | + public static function tax_label($label = '') { |
|
733 | 733 | global $wpi_requires_vat; |
734 | 734 | |
735 | - if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) { |
|
736 | - $wpi_requires_vat = self::requires_vat( 0, false ); |
|
735 | + if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) { |
|
736 | + $wpi_requires_vat = self::requires_vat(0, false); |
|
737 | 737 | } |
738 | 738 | |
739 | - return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) ); |
|
739 | + return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing')); |
|
740 | 740 | } |
741 | 741 | |
742 | 742 | public static function standard_rates_label() { |
743 | - return __( 'Standard Rates', 'invoicing' ); |
|
743 | + return __('Standard Rates', 'invoicing'); |
|
744 | 744 | } |
745 | 745 | |
746 | - public static function get_rate_classes( $with_desc = false ) { |
|
747 | - $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true ); |
|
748 | - $classes = maybe_unserialize( $rate_classes_option ); |
|
746 | + public static function get_rate_classes($with_desc = false) { |
|
747 | + $rate_classes_option = get_option('_wpinv_vat_rate_classes', true); |
|
748 | + $classes = maybe_unserialize($rate_classes_option); |
|
749 | 749 | |
750 | - if ( empty( $classes ) || !is_array( $classes ) ) { |
|
750 | + if (empty($classes) || !is_array($classes)) { |
|
751 | 751 | $classes = array(); |
752 | 752 | } |
753 | 753 | |
754 | 754 | $rate_classes = array(); |
755 | - if ( !array_key_exists( '_standard', $classes ) ) { |
|
756 | - if ( $with_desc ) { |
|
757 | - $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) ); |
|
755 | + if (!array_key_exists('_standard', $classes)) { |
|
756 | + if ($with_desc) { |
|
757 | + $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing')); |
|
758 | 758 | } else { |
759 | 759 | $rate_classes['_standard'] = self::standard_rates_label(); |
760 | 760 | } |
761 | 761 | } |
762 | 762 | |
763 | - foreach ( $classes as $key => $class ) { |
|
764 | - $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key; |
|
765 | - $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : ''; |
|
763 | + foreach ($classes as $key => $class) { |
|
764 | + $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key; |
|
765 | + $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : ''; |
|
766 | 766 | |
767 | - if ( $with_desc ) { |
|
768 | - $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc ); |
|
767 | + if ($with_desc) { |
|
768 | + $rate_classes[$key] = array('name' => $name, 'desc' => $desc); |
|
769 | 769 | } else { |
770 | 770 | $rate_classes[$key] = $name; |
771 | 771 | } |
@@ -776,15 +776,15 @@ discard block |
||
776 | 776 | |
777 | 777 | public static function get_all_classes() { |
778 | 778 | $classes = self::get_rate_classes(); |
779 | - $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' ); |
|
779 | + $classes['_exempt'] = __('Exempt (0%)', 'invoicing'); |
|
780 | 780 | |
781 | - return apply_filters( 'wpinv_vat_get_all_classes', $classes ); |
|
781 | + return apply_filters('wpinv_vat_get_all_classes', $classes); |
|
782 | 782 | } |
783 | 783 | |
784 | - public static function get_class_desc( $rate_class ) { |
|
785 | - $rate_classes = self::get_rate_classes( true ); |
|
784 | + public static function get_class_desc($rate_class) { |
|
785 | + $rate_classes = self::get_rate_classes(true); |
|
786 | 786 | |
787 | - if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) { |
|
787 | + if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) { |
|
788 | 788 | return $rate_classes[$rate_class]['desc']; |
789 | 789 | } |
790 | 790 | |
@@ -800,107 +800,107 @@ discard block |
||
800 | 800 | 'increased' => 'Increased' |
801 | 801 | ); |
802 | 802 | |
803 | - return apply_filters( 'wpinv_get_vat_groups', $vat_groups ); |
|
803 | + return apply_filters('wpinv_get_vat_groups', $vat_groups); |
|
804 | 804 | } |
805 | 805 | |
806 | 806 | public static function get_rules() { |
807 | 807 | $vat_rules = array( |
808 | - 'digital' => __( 'Digital Product', 'invoicing' ), |
|
809 | - 'physical' => __( 'Physical Product', 'invoicing' ), |
|
810 | - '_exempt' => __( 'Tax-Free Product', 'invoicing' ), |
|
808 | + 'digital' => __('Digital Product', 'invoicing'), |
|
809 | + 'physical' => __('Physical Product', 'invoicing'), |
|
810 | + '_exempt' => __('Tax-Free Product', 'invoicing'), |
|
811 | 811 | ); |
812 | - return apply_filters( 'wpinv_get_vat_rules', $vat_rules ); |
|
812 | + return apply_filters('wpinv_get_vat_rules', $vat_rules); |
|
813 | 813 | } |
814 | 814 | |
815 | - public static function get_vat_rates( $class ) { |
|
816 | - if ( $class === '_standard' ) { |
|
815 | + public static function get_vat_rates($class) { |
|
816 | + if ($class === '_standard') { |
|
817 | 817 | return GetPaid_Tax::get_all_tax_rates(); |
818 | 818 | } |
819 | 819 | |
820 | 820 | $rates = self::get_non_standard_rates(); |
821 | 821 | |
822 | - return array_key_exists( $class, $rates ) ? $rates[$class] : array(); |
|
822 | + return array_key_exists($class, $rates) ? $rates[$class] : array(); |
|
823 | 823 | } |
824 | 824 | |
825 | 825 | public static function get_non_standard_rates() { |
826 | - $option = get_option( 'wpinv_vat_rates', array()); |
|
827 | - return is_array( $option ) ? $option : array(); |
|
826 | + $option = get_option('wpinv_vat_rates', array()); |
|
827 | + return is_array($option) ? $option : array(); |
|
828 | 828 | } |
829 | 829 | |
830 | 830 | public static function allow_vat_rules() { |
831 | - return ( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ? true : false ); |
|
831 | + return (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules') ? true : false); |
|
832 | 832 | } |
833 | 833 | |
834 | 834 | public static function allow_vat_classes() { |
835 | 835 | return false; // TODO |
836 | - return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false ); |
|
836 | + return (wpinv_get_option('vat_allow_classes') ? true : false); |
|
837 | 837 | } |
838 | 838 | |
839 | - public static function get_item_class( $postID ) { |
|
840 | - $class = get_post_meta( $postID, '_wpinv_vat_class', true ); |
|
839 | + public static function get_item_class($postID) { |
|
840 | + $class = get_post_meta($postID, '_wpinv_vat_class', true); |
|
841 | 841 | |
842 | - if ( empty( $class ) ) { |
|
842 | + if (empty($class)) { |
|
843 | 843 | $class = '_standard'; |
844 | 844 | } |
845 | 845 | |
846 | - return apply_filters( 'wpinv_get_item_vat_class', $class, $postID ); |
|
846 | + return apply_filters('wpinv_get_item_vat_class', $class, $postID); |
|
847 | 847 | } |
848 | 848 | |
849 | - public static function item_class_label( $postID ) { |
|
849 | + public static function item_class_label($postID) { |
|
850 | 850 | $vat_classes = self::get_all_classes(); |
851 | 851 | |
852 | - $class = self::get_item_class( $postID ); |
|
853 | - $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' ); |
|
852 | + $class = self::get_item_class($postID); |
|
853 | + $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing'); |
|
854 | 854 | |
855 | - return apply_filters( 'wpinv_item_class_label', $class, $postID ); |
|
855 | + return apply_filters('wpinv_item_class_label', $class, $postID); |
|
856 | 856 | } |
857 | 857 | |
858 | - public static function get_item_rule( $postID ) { |
|
859 | - $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true ); |
|
858 | + public static function get_item_rule($postID) { |
|
859 | + $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true); |
|
860 | 860 | |
861 | - if ( empty( $rule_type ) ) { |
|
861 | + if (empty($rule_type)) { |
|
862 | 862 | $rule_type = self::allow_vat_rules() ? 'digital' : 'physical'; |
863 | 863 | } |
864 | 864 | |
865 | - return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID ); |
|
865 | + return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID); |
|
866 | 866 | } |
867 | 867 | |
868 | - public static function item_rule_label( $postID ) { |
|
868 | + public static function item_rule_label($postID) { |
|
869 | 869 | $vat_rules = self::get_rules(); |
870 | - $vat_rule = self::get_item_rule( $postID ); |
|
871 | - $vat_rule = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule; |
|
870 | + $vat_rule = self::get_item_rule($postID); |
|
871 | + $vat_rule = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule; |
|
872 | 872 | |
873 | - return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID ); |
|
873 | + return apply_filters('wpinv_item_rule_label', $vat_rule, $postID); |
|
874 | 874 | } |
875 | 875 | |
876 | - public static function item_has_digital_rule( $item_id = 0 ) { |
|
877 | - return self::get_item_rule( $item_id ) == 'digital' ? true : false; |
|
876 | + public static function item_has_digital_rule($item_id = 0) { |
|
877 | + return self::get_item_rule($item_id) == 'digital' ? true : false; |
|
878 | 878 | } |
879 | 879 | |
880 | - public static function invoice_has_digital_rule( $invoice = 0 ) { |
|
881 | - if ( !self::allow_vat_rules() ) { |
|
880 | + public static function invoice_has_digital_rule($invoice = 0) { |
|
881 | + if (!self::allow_vat_rules()) { |
|
882 | 882 | return false; |
883 | 883 | } |
884 | 884 | |
885 | - if ( empty( $invoice ) ) { |
|
885 | + if (empty($invoice)) { |
|
886 | 886 | return true; |
887 | 887 | } |
888 | 888 | |
889 | - if ( is_int( $invoice ) ) { |
|
890 | - $invoice = new WPInv_Invoice( $invoice ); |
|
889 | + if (is_int($invoice)) { |
|
890 | + $invoice = new WPInv_Invoice($invoice); |
|
891 | 891 | } |
892 | 892 | |
893 | - if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) { |
|
893 | + if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) { |
|
894 | 894 | return true; |
895 | 895 | } |
896 | 896 | |
897 | - $cart_items = $invoice->get_cart_details(); |
|
897 | + $cart_items = $invoice->get_cart_details(); |
|
898 | 898 | |
899 | - if ( !empty( $cart_items ) ) { |
|
899 | + if (!empty($cart_items)) { |
|
900 | 900 | $has_digital_rule = false; |
901 | 901 | |
902 | - foreach ( $cart_items as $key => $item ) { |
|
903 | - if ( self::item_has_digital_rule( $item['id'] ) ) { |
|
902 | + foreach ($cart_items as $key => $item) { |
|
903 | + if (self::item_has_digital_rule($item['id'])) { |
|
904 | 904 | $has_digital_rule = true; |
905 | 905 | break; |
906 | 906 | } |
@@ -912,71 +912,71 @@ discard block |
||
912 | 912 | return $has_digital_rule; |
913 | 913 | } |
914 | 914 | |
915 | - public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) { |
|
916 | - if ( !wpinv_use_taxes() ) { |
|
915 | + public static function item_is_taxable($item_id = 0, $country = false, $state = false) { |
|
916 | + if (!wpinv_use_taxes()) { |
|
917 | 917 | return false; |
918 | 918 | } |
919 | 919 | |
920 | 920 | $is_taxable = true; |
921 | 921 | |
922 | - if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) { |
|
922 | + if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') { |
|
923 | 923 | $is_taxable = false; |
924 | 924 | } |
925 | 925 | |
926 | - if ( !empty( $item_id ) && self::get_item_rule( $item_id ) == '_exempt' ) { |
|
926 | + if (!empty($item_id) && self::get_item_rule($item_id) == '_exempt') { |
|
927 | 927 | $is_taxable = false; |
928 | 928 | } |
929 | 929 | |
930 | - return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state ); |
|
930 | + return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state); |
|
931 | 931 | } |
932 | 932 | |
933 | - public static function find_rate( $country, $state, $rate, $class ) { |
|
933 | + public static function find_rate($country, $state, $rate, $class) { |
|
934 | 934 | global $wpi_zero_tax; |
935 | 935 | |
936 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
936 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
937 | 937 | return 0; |
938 | 938 | } |
939 | 939 | |
940 | - $tax_rates = GetPaid_Tax::get_all_tax_rates(); |
|
940 | + $tax_rates = GetPaid_Tax::get_all_tax_rates(); |
|
941 | 941 | |
942 | - if ( $class !== '_standard' ) { |
|
943 | - $class_rates = self::get_vat_rates( $class ); |
|
942 | + if ($class !== '_standard') { |
|
943 | + $class_rates = self::get_vat_rates($class); |
|
944 | 944 | |
945 | - if ( is_array( $class_rates ) ) { |
|
945 | + if (is_array($class_rates)) { |
|
946 | 946 | $indexed_class_rates = array(); |
947 | 947 | |
948 | - foreach ( $class_rates as $key => $cr ) { |
|
948 | + foreach ($class_rates as $key => $cr) { |
|
949 | 949 | $indexed_class_rates[$cr['country']] = $cr; |
950 | 950 | } |
951 | 951 | |
952 | - $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) { |
|
952 | + $tax_rates = array_map(function($tr) use($indexed_class_rates) { |
|
953 | 953 | $tr_country = $tr['country']; |
954 | - if ( !isset( $indexed_class_rates[$tr_country] ) ) { |
|
954 | + if (!isset($indexed_class_rates[$tr_country])) { |
|
955 | 955 | return $tr; |
956 | 956 | } |
957 | 957 | $icr = $indexed_class_rates[$tr_country]; |
958 | - return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr; |
|
958 | + return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr; |
|
959 | 959 | |
960 | - }, $tax_rates, $class_rates ); |
|
960 | + }, $tax_rates, $class_rates); |
|
961 | 961 | } |
962 | 962 | } |
963 | 963 | |
964 | - if ( !empty( $tax_rates ) ) { |
|
965 | - foreach ( $tax_rates as $key => $tax_rate ) { |
|
966 | - if ( $country != $tax_rate['country'] ) |
|
964 | + if (!empty($tax_rates)) { |
|
965 | + foreach ($tax_rates as $key => $tax_rate) { |
|
966 | + if ($country != $tax_rate['country']) |
|
967 | 967 | continue; |
968 | 968 | |
969 | - if ( !empty( $tax_rate['global'] ) ) { |
|
970 | - if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) { |
|
971 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
969 | + if (!empty($tax_rate['global'])) { |
|
970 | + if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) { |
|
971 | + $rate = number_format($tax_rate['rate'], 4); |
|
972 | 972 | } |
973 | 973 | } else { |
974 | - if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
974 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
975 | 975 | continue; |
976 | 976 | |
977 | 977 | $state_rate = $tax_rate['rate']; |
978 | - if ( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
979 | - $rate = number_format( $state_rate, 4 ); |
|
978 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
979 | + $rate = number_format($state_rate, 4); |
|
980 | 980 | } |
981 | 981 | } |
982 | 982 | } |
@@ -985,84 +985,84 @@ discard block |
||
985 | 985 | return $rate; |
986 | 986 | } |
987 | 987 | |
988 | - public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) { |
|
988 | + public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) { |
|
989 | 989 | global $wpinv_options, $wpi_item_id, $wpi_zero_tax; |
990 | 990 | |
991 | 991 | $item_id = $item_id > 0 ? $item_id : $wpi_item_id; |
992 | 992 | $allow_vat_classes = self::allow_vat_classes(); |
993 | - $class = $item_id ? self::get_item_class( $item_id ) : '_standard'; |
|
993 | + $class = $item_id ? self::get_item_class($item_id) : '_standard'; |
|
994 | 994 | |
995 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
995 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
996 | 996 | return 0; |
997 | - } else if ( !$allow_vat_classes ) { |
|
997 | + } else if (!$allow_vat_classes) { |
|
998 | 998 | $class = '_standard'; |
999 | 999 | } |
1000 | 1000 | |
1001 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
1001 | + if (!empty($_POST['wpinv_country'])) { |
|
1002 | 1002 | $post_country = $_POST['wpinv_country']; |
1003 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
1003 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
1004 | 1004 | $post_country = $_POST['wpinv_country']; |
1005 | - } elseif( !empty( $_POST['country'] ) ) { |
|
1005 | + } elseif (!empty($_POST['country'])) { |
|
1006 | 1006 | $post_country = $_POST['country']; |
1007 | 1007 | } else { |
1008 | 1008 | $post_country = ''; |
1009 | 1009 | } |
1010 | 1010 | |
1011 | - $country = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country ); |
|
1012 | - $base_country = wpinv_is_base_country( $country ); |
|
1011 | + $country = !empty($post_country) ? $post_country : wpinv_default_billing_country($country); |
|
1012 | + $base_country = wpinv_is_base_country($country); |
|
1013 | 1013 | |
1014 | - $requires_vat = self::requires_vat( 0, false ); |
|
1015 | - $is_digital = self::get_item_rule( $item_id ) == 'digital' ; |
|
1016 | - $rate = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
1014 | + $requires_vat = self::requires_vat(0, false); |
|
1015 | + $is_digital = self::get_item_rule($item_id) == 'digital'; |
|
1016 | + $rate = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
1017 | 1017 | |
1018 | - if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country |
|
1018 | + if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country |
|
1019 | 1019 | $rate = 0; |
1020 | - } else if ( $requires_vat ) { |
|
1021 | - $vat_number = self::get_user_vat_number( '', 0, true ); |
|
1020 | + } else if ($requires_vat) { |
|
1021 | + $vat_number = self::get_user_vat_number('', 0, true); |
|
1022 | 1022 | $vat_info = self::current_vat_data(); |
1023 | 1023 | |
1024 | - if ( is_array( $vat_info ) ) { |
|
1025 | - $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : ""; |
|
1024 | + if (is_array($vat_info)) { |
|
1025 | + $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : ""; |
|
1026 | 1026 | } |
1027 | 1027 | |
1028 | - if ( $country == 'UK' ) { |
|
1028 | + if ($country == 'UK') { |
|
1029 | 1029 | $country = 'GB'; |
1030 | 1030 | } |
1031 | 1031 | |
1032 | - if ( !empty( $vat_number ) ) { |
|
1032 | + if (!empty($vat_number)) { |
|
1033 | 1033 | $rate = 0; |
1034 | 1034 | } else { |
1035 | - $rate = self::find_rate( $country, $state, $rate, $class ); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate |
|
1035 | + $rate = self::find_rate($country, $state, $rate, $class); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate |
|
1036 | 1036 | } |
1037 | 1037 | |
1038 | - if ( empty( $vat_number ) && !$is_digital ) { |
|
1039 | - if ( $base_country ) { |
|
1040 | - $rate = self::find_rate( $country, null, $rate, $class ); |
|
1038 | + if (empty($vat_number) && !$is_digital) { |
|
1039 | + if ($base_country) { |
|
1040 | + $rate = self::find_rate($country, null, $rate, $class); |
|
1041 | 1041 | } else { |
1042 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
1042 | + if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) { |
|
1043 | 1043 | $rate = $wpinv_options['eu_fallback_rate']; |
1044 | - } else if( !empty( $country ) ) { |
|
1045 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1044 | + } else if (!empty($country)) { |
|
1045 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1046 | 1046 | } |
1047 | 1047 | } |
1048 | - } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) { |
|
1049 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
1048 | + } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) { |
|
1049 | + if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) { |
|
1050 | 1050 | $rate = $wpinv_options['eu_fallback_rate']; |
1051 | - } else if( !empty( $country ) ) { |
|
1052 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1051 | + } else if (!empty($country)) { |
|
1052 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1053 | 1053 | } |
1054 | 1054 | } |
1055 | 1055 | } else { |
1056 | - if ( $is_digital ) { |
|
1056 | + if ($is_digital) { |
|
1057 | 1057 | $ip_country_code = getpaid_get_ip_country(); |
1058 | 1058 | |
1059 | - if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) { |
|
1060 | - $rate = self::find_rate( $ip_country_code, '', 0, $class ); |
|
1059 | + if ($ip_country_code && self::is_eu_state($ip_country_code)) { |
|
1060 | + $rate = self::find_rate($ip_country_code, '', 0, $class); |
|
1061 | 1061 | } else { |
1062 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1062 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1063 | 1063 | } |
1064 | 1064 | } else { |
1065 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1065 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1066 | 1066 | } |
1067 | 1067 | } |
1068 | 1068 | |
@@ -1070,44 +1070,44 @@ discard block |
||
1070 | 1070 | } |
1071 | 1071 | |
1072 | 1072 | public static function current_vat_data() { |
1073 | - return getpaid_session()->get( 'user_vat_data' ); |
|
1073 | + return getpaid_session()->get('user_vat_data'); |
|
1074 | 1074 | } |
1075 | 1075 | |
1076 | - public static function get_user_country( $country = '', $user_id = 0 ) { |
|
1077 | - $user_address = wpinv_get_user_address( $user_id, false ); |
|
1076 | + public static function get_user_country($country = '', $user_id = 0) { |
|
1077 | + $user_address = wpinv_get_user_address($user_id, false); |
|
1078 | 1078 | |
1079 | - $country = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country']; |
|
1080 | - $result = apply_filters( 'wpinv_get_user_country', $country, $user_id ); |
|
1079 | + $country = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country']; |
|
1080 | + $result = apply_filters('wpinv_get_user_country', $country, $user_id); |
|
1081 | 1081 | |
1082 | - if ( empty( $result ) ) { |
|
1082 | + if (empty($result)) { |
|
1083 | 1083 | $result = getpaid_get_ip_country(); |
1084 | 1084 | } |
1085 | 1085 | |
1086 | 1086 | return $result; |
1087 | 1087 | } |
1088 | 1088 | |
1089 | - public static function set_user_country( $country = '', $user_id = 0 ) { |
|
1089 | + public static function set_user_country($country = '', $user_id = 0) { |
|
1090 | 1090 | global $wpi_userID; |
1091 | 1091 | |
1092 | - if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) { |
|
1092 | + if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) { |
|
1093 | 1093 | $country = wpinv_get_default_country(); |
1094 | 1094 | } |
1095 | 1095 | |
1096 | 1096 | return $country; |
1097 | 1097 | } |
1098 | 1098 | |
1099 | - public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) { |
|
1099 | + public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) { |
|
1100 | 1100 | global $wpi_current_id, $wpi_userID; |
1101 | 1101 | |
1102 | - if ( !empty( $_POST['new_user'] ) ) { |
|
1102 | + if (!empty($_POST['new_user'])) { |
|
1103 | 1103 | return ''; |
1104 | 1104 | } |
1105 | 1105 | |
1106 | - if ( empty( $user_id ) ) { |
|
1107 | - $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() ); |
|
1106 | + if (empty($user_id)) { |
|
1107 | + $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id()); |
|
1108 | 1108 | } |
1109 | 1109 | |
1110 | - $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true ); |
|
1110 | + $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true); |
|
1111 | 1111 | |
1112 | 1112 | /* TODO |
1113 | 1113 | if ( $is_valid && $vat_number ) { |
@@ -1118,38 +1118,38 @@ discard block |
||
1118 | 1118 | } |
1119 | 1119 | */ |
1120 | 1120 | |
1121 | - return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid ); |
|
1121 | + return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid); |
|
1122 | 1122 | } |
1123 | 1123 | |
1124 | - public static function get_user_company( $company = '', $user_id = 0 ) { |
|
1124 | + public static function get_user_company($company = '', $user_id = 0) { |
|
1125 | 1125 | global $wpi_current_id, $wpi_userID; |
1126 | 1126 | |
1127 | - if ( empty( $user_id ) ) { |
|
1128 | - $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() ); |
|
1127 | + if (empty($user_id)) { |
|
1128 | + $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id()); |
|
1129 | 1129 | } |
1130 | 1130 | |
1131 | - $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true ); |
|
1131 | + $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true); |
|
1132 | 1132 | |
1133 | - return apply_filters( 'wpinv_user_company', $company, $user_id ); |
|
1133 | + return apply_filters('wpinv_user_company', $company, $user_id); |
|
1134 | 1134 | } |
1135 | 1135 | |
1136 | - public static function save_user_vat_details( $company = '', $vat_number = '' ) { |
|
1137 | - $save = apply_filters( 'wpinv_allow_save_user_vat_details', true ); |
|
1136 | + public static function save_user_vat_details($company = '', $vat_number = '') { |
|
1137 | + $save = apply_filters('wpinv_allow_save_user_vat_details', true); |
|
1138 | 1138 | |
1139 | - if ( is_user_logged_in() && $save ) { |
|
1139 | + if (is_user_logged_in() && $save) { |
|
1140 | 1140 | $user_id = get_current_user_id(); |
1141 | 1141 | |
1142 | - if ( !empty( $vat_number ) ) { |
|
1143 | - update_user_meta( $user_id, '_wpinv_vat_number', $vat_number ); |
|
1142 | + if (!empty($vat_number)) { |
|
1143 | + update_user_meta($user_id, '_wpinv_vat_number', $vat_number); |
|
1144 | 1144 | } else { |
1145 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
1145 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
1146 | 1146 | } |
1147 | 1147 | |
1148 | - if ( !empty( $company ) ) { |
|
1149 | - update_user_meta( $user_id, '_wpinv_company', $company ); |
|
1148 | + if (!empty($company)) { |
|
1149 | + update_user_meta($user_id, '_wpinv_company', $company); |
|
1150 | 1150 | } else { |
1151 | - delete_user_meta( $user_id, '_wpinv_company'); |
|
1152 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
1151 | + delete_user_meta($user_id, '_wpinv_company'); |
|
1152 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
1153 | 1153 | } |
1154 | 1154 | } |
1155 | 1155 | |
@@ -1162,74 +1162,74 @@ discard block |
||
1162 | 1162 | $response = array(); |
1163 | 1163 | $response['success'] = false; |
1164 | 1164 | |
1165 | - if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) { |
|
1166 | - $response['error'] = __( 'Invalid security nonce', 'invoicing' ); |
|
1167 | - wp_send_json( $response ); |
|
1165 | + if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) { |
|
1166 | + $response['error'] = __('Invalid security nonce', 'invoicing'); |
|
1167 | + wp_send_json($response); |
|
1168 | 1168 | } |
1169 | 1169 | |
1170 | 1170 | $vat_name = self::get_vat_name(); |
1171 | 1171 | |
1172 | - $company = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : ''; |
|
1173 | - $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : ''; |
|
1172 | + $company = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : ''; |
|
1173 | + $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : ''; |
|
1174 | 1174 | |
1175 | - $vat_info = getpaid_session()->get( 'user_vat_data' ); |
|
1176 | - if ( !is_array( $vat_info ) || empty( $vat_info ) ) { |
|
1177 | - $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true ); |
|
1175 | + $vat_info = getpaid_session()->get('user_vat_data'); |
|
1176 | + if (!is_array($vat_info) || empty($vat_info)) { |
|
1177 | + $vat_info = array('company'=> $company, 'number' => '', 'valid' => true); |
|
1178 | 1178 | } |
1179 | 1179 | |
1180 | - if ( empty( $vat_number ) ) { |
|
1181 | - $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name ); |
|
1180 | + if (empty($vat_number)) { |
|
1181 | + $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name); |
|
1182 | 1182 | $vat_info['valid'] = false; |
1183 | - getpaid_session()->set( 'user_vat_data', $vat_info ); |
|
1184 | - wp_send_json( $response ); |
|
1183 | + getpaid_session()->set('user_vat_data', $vat_info); |
|
1184 | + wp_send_json($response); |
|
1185 | 1185 | } |
1186 | 1186 | |
1187 | - if ( empty( $company ) ) { |
|
1187 | + if (empty($company)) { |
|
1188 | 1188 | $vat_info['valid'] = false; |
1189 | - getpaid_session()->set( 'user_vat_data', $vat_info ); |
|
1189 | + getpaid_session()->set('user_vat_data', $vat_info); |
|
1190 | 1190 | |
1191 | - $response['error'] = __( 'Please enter your registered company name!', 'invoicing' ); |
|
1192 | - wp_send_json( $response ); |
|
1191 | + $response['error'] = __('Please enter your registered company name!', 'invoicing'); |
|
1192 | + wp_send_json($response); |
|
1193 | 1193 | } |
1194 | 1194 | |
1195 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
1196 | - if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) { |
|
1195 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
1196 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) { |
|
1197 | 1197 | $vat_info['valid'] = false; |
1198 | - getpaid_session()->set( 'user_vat_data', $vat_info ); |
|
1198 | + getpaid_session()->set('user_vat_data', $vat_info); |
|
1199 | 1199 | |
1200 | - $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
1201 | - wp_send_json( $response ); |
|
1200 | + $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
1201 | + wp_send_json($response); |
|
1202 | 1202 | } |
1203 | 1203 | |
1204 | 1204 | $response['success'] = true; |
1205 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
1205 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
1206 | 1206 | } else { |
1207 | - $result = self::check_vat( $vat_number ); |
|
1207 | + $result = self::check_vat($vat_number); |
|
1208 | 1208 | |
1209 | - if ( empty( $result['valid'] ) ) { |
|
1209 | + if (empty($result['valid'])) { |
|
1210 | 1210 | $response['error'] = $result['message']; |
1211 | - wp_send_json( $response ); |
|
1211 | + wp_send_json($response); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | - $vies_company = !empty( $result['company'] ) ? $result['company'] : ''; |
|
1215 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
1214 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
1215 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
1216 | 1216 | |
1217 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
1217 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
1218 | 1218 | |
1219 | - if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) { |
|
1219 | + if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) { |
|
1220 | 1220 | $response['success'] = true; |
1221 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
1221 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
1222 | 1222 | } else { |
1223 | 1223 | $vat_info['valid'] = false; |
1224 | - getpaid_session()->set( 'user_vat_data', $vat_info ); |
|
1224 | + getpaid_session()->set('user_vat_data', $vat_info); |
|
1225 | 1225 | |
1226 | 1226 | $response['success'] = false; |
1227 | - $response['message'] = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name ); |
|
1228 | - wp_send_json( $response ); |
|
1227 | + $response['message'] = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name); |
|
1228 | + wp_send_json($response); |
|
1229 | 1229 | } |
1230 | 1230 | } |
1231 | 1231 | |
1232 | - wp_send_json( $response ); |
|
1232 | + wp_send_json($response); |
|
1233 | 1233 | } |
1234 | 1234 | |
1235 | 1235 | /** |
@@ -1237,16 +1237,16 @@ discard block |
||
1237 | 1237 | * |
1238 | 1238 | * @return string |
1239 | 1239 | */ |
1240 | - public static function validate_vat_number( $vat_number, $company, $country ) { |
|
1240 | + public static function validate_vat_number($vat_number, $company, $country) { |
|
1241 | 1241 | global $wpinv_options; |
1242 | 1242 | |
1243 | 1243 | // If we are not checking the vat number via view... |
1244 | - if ( ! empty( $wpinv_options['vat_vies_check'] ) ) { |
|
1244 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
1245 | 1245 | |
1246 | 1246 | // Try validating via regex. |
1247 | - if ( empty( $wpinv_options['vat_offline_check'] ) && ! self::offline_check( $vat_number, $country ) ) { |
|
1247 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number, $country)) { |
|
1248 | 1248 | return wp_sprintf( |
1249 | - __( 'Your %s number is invalid', 'invoicing' ), |
|
1249 | + __('Your %s number is invalid', 'invoicing'), |
|
1250 | 1250 | getpaid_vat_name() |
1251 | 1251 | ); |
1252 | 1252 | } |
@@ -1255,23 +1255,23 @@ discard block |
||
1255 | 1255 | } |
1256 | 1256 | |
1257 | 1257 | // Validate the vat number. |
1258 | - $result = self::check_vat( $vat_number, $country ); |
|
1258 | + $result = self::check_vat($vat_number, $country); |
|
1259 | 1259 | |
1260 | - if ( empty( $result['valid'] ) ) { |
|
1260 | + if (empty($result['valid'])) { |
|
1261 | 1261 | return wp_sprintf( |
1262 | - __( 'Failed to validate the %s number via EU Commission VAT server (VIES).', 'invoicing' ), |
|
1262 | + __('Failed to validate the %s number via EU Commission VAT server (VIES).', 'invoicing'), |
|
1263 | 1263 | getpaid_vat_name() |
1264 | 1264 | ); |
1265 | 1265 | } |
1266 | 1266 | |
1267 | 1267 | // Validate the company. |
1268 | - $vies_company = ! empty( $result['company'] ) ? $result['company'] : ''; |
|
1269 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
1270 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
1268 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
1269 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
1270 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
1271 | 1271 | |
1272 | - if ( ! $valid_company && ! empty( $wpinv_options['vat_disable_company_name_check'] ) ) { |
|
1272 | + if (!$valid_company && !empty($wpinv_options['vat_disable_company_name_check'])) { |
|
1273 | 1273 | return wp_sprintf( |
1274 | - __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), |
|
1274 | + __('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), |
|
1275 | 1275 | getpaid_vat_name() |
1276 | 1276 | ); |
1277 | 1277 | } |
@@ -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 | * Returns the tax class objet. |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @return bool |
22 | 22 | */ |
23 | -function getpaid_is_eu_state( $country ) { |
|
24 | - return WPInv_EUVat::is_eu_state( $country ); |
|
23 | +function getpaid_is_eu_state($country) { |
|
24 | + return WPInv_EUVat::is_eu_state($country); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @return bool |
31 | 31 | */ |
32 | -function getpaid_is_gst_country( $country ) { |
|
33 | - return WPInv_EUVat::is_gst_country( $country ); |
|
32 | +function getpaid_is_gst_country($country) { |
|
33 | + return WPInv_EUVat::is_gst_country($country); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | */ |
50 | 50 | function wpinv_use_taxes() { |
51 | 51 | |
52 | - $ret = wpinv_get_option( 'enable_taxes', false ); |
|
53 | - return (bool) apply_filters( 'wpinv_use_taxes', ! empty( $ret ) ); |
|
52 | + $ret = wpinv_get_option('enable_taxes', false); |
|
53 | + return (bool) apply_filters('wpinv_use_taxes', !empty($ret)); |
|
54 | 54 | |
55 | 55 | } |
56 | 56 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @param WPInv_Invoice $invoice |
61 | 61 | * @return bool |
62 | 62 | */ |
63 | -function wpinv_is_invoice_taxable( $invoice ) { |
|
63 | +function wpinv_is_invoice_taxable($invoice) { |
|
64 | 64 | return $invoice->is_taxable(); |
65 | 65 | } |
66 | 66 | |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * @param WPInv_Item|GetPaid_Form_Item $item |
71 | 71 | * @return bool |
72 | 72 | */ |
73 | -function wpinv_is_item_taxable( $item ) { |
|
73 | +function wpinv_is_item_taxable($item) { |
|
74 | 74 | return '_exempt' != $item->get_vat_rule(); |
75 | 75 | } |
76 | 76 | |
@@ -80,8 +80,8 @@ discard block |
||
80 | 80 | * @return bool |
81 | 81 | */ |
82 | 82 | function wpinv_use_store_address_as_tax_base() { |
83 | - $use_base = wpinv_get_option( 'tax_base', 'billing' ) == 'base'; |
|
84 | - return (bool) apply_filters( 'wpinv_use_store_address_as_tax_base', $use_base ); |
|
83 | + $use_base = wpinv_get_option('tax_base', 'billing') == 'base'; |
|
84 | + return (bool) apply_filters('wpinv_use_store_address_as_tax_base', $use_base); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -90,8 +90,8 @@ discard block |
||
90 | 90 | * @return bool |
91 | 91 | */ |
92 | 92 | function wpinv_prices_include_tax() { |
93 | - $is_inclusive = wpinv_get_option( 'prices_include_tax', 'no' ) == 'yes'; |
|
94 | - return (bool) apply_filters( 'wpinv_prices_include_tax', $is_inclusive ); |
|
93 | + $is_inclusive = wpinv_get_option('prices_include_tax', 'no') == 'yes'; |
|
94 | + return (bool) apply_filters('wpinv_prices_include_tax', $is_inclusive); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | * @return bool |
101 | 101 | */ |
102 | 102 | function wpinv_round_tax_per_tax_rate() { |
103 | - $subtotal_rounding = wpinv_get_option( 'tax_subtotal_rounding', 1 ); |
|
104 | - return (bool) apply_filters( 'wpinv_round_tax_per_tax_rate', empty( $subtotal_rounding ) ); |
|
103 | + $subtotal_rounding = wpinv_get_option('tax_subtotal_rounding', 1); |
|
104 | + return (bool) apply_filters('wpinv_round_tax_per_tax_rate', empty($subtotal_rounding)); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | * @return bool |
111 | 111 | */ |
112 | 112 | function wpinv_display_individual_tax_rates() { |
113 | - $individual = wpinv_get_option( 'tax_display_totals', 'single' ) == 'individual'; |
|
114 | - return (bool) apply_filters( 'wpinv_display_individual_tax_rates', $individual ); |
|
113 | + $individual = wpinv_get_option('tax_display_totals', 'single') == 'individual'; |
|
114 | + return (bool) apply_filters('wpinv_display_individual_tax_rates', $individual); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * @return float |
121 | 121 | */ |
122 | 122 | function wpinv_get_default_tax_rate() { |
123 | - $rate = wpinv_get_option( 'tax_rate', false ); |
|
124 | - return (float) apply_filters( 'wpinv_get_default_tax_rate', floatval( $rate ) ); |
|
123 | + $rate = wpinv_get_option('tax_rate', false); |
|
124 | + return (float) apply_filters('wpinv_get_default_tax_rate', floatval($rate)); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -141,28 +141,28 @@ discard block |
||
141 | 141 | * @param string $state |
142 | 142 | * @return array |
143 | 143 | */ |
144 | -function getpaid_get_item_tax_rates( $item, $country = '', $state = '' ) { |
|
144 | +function getpaid_get_item_tax_rates($item, $country = '', $state = '') { |
|
145 | 145 | |
146 | 146 | // Abort if the item is not taxable. |
147 | - if ( ! wpinv_is_item_taxable( $item ) ) { |
|
147 | + if (!wpinv_is_item_taxable($item)) { |
|
148 | 148 | return array(); |
149 | 149 | } |
150 | 150 | |
151 | 151 | // Maybe use the store address. |
152 | - if ( wpinv_use_store_address_as_tax_base() ) { |
|
152 | + if (wpinv_use_store_address_as_tax_base()) { |
|
153 | 153 | $country = wpinv_get_default_country(); |
154 | 154 | $state = wpinv_get_default_state(); |
155 | 155 | } |
156 | 156 | |
157 | 157 | // Retrieve tax rates. |
158 | - $tax_rates = GetPaid_Tax::get_address_tax_rates( $country, $state ); |
|
158 | + $tax_rates = GetPaid_Tax::get_address_tax_rates($country, $state); |
|
159 | 159 | |
160 | 160 | // Fallback to the default tax rates if non were found. |
161 | - if ( empty( $tax_rates ) ) { |
|
161 | + if (empty($tax_rates)) { |
|
162 | 162 | $tax_rates = GetPaid_Tax::get_default_tax_rates(); |
163 | 163 | } |
164 | 164 | |
165 | - return apply_filters( 'getpaid_get_item_tax_rates', $tax_rates, $item, $country, $state ); |
|
165 | + return apply_filters('getpaid_get_item_tax_rates', $tax_rates, $item, $country, $state); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -172,12 +172,12 @@ discard block |
||
172 | 172 | * @param array $rates |
173 | 173 | * @return array |
174 | 174 | */ |
175 | -function getpaid_calculate_item_taxes( $amount, $rates ) { |
|
175 | +function getpaid_calculate_item_taxes($amount, $rates) { |
|
176 | 176 | |
177 | 177 | $is_inclusive = wpinv_prices_include_tax(); |
178 | - $taxes = GetPaid_Tax::calc_tax( $amount, $rates, $is_inclusive ); |
|
178 | + $taxes = GetPaid_Tax::calc_tax($amount, $rates, $is_inclusive); |
|
179 | 179 | |
180 | - return apply_filters( 'getpaid_calculate_taxes', $taxes, $amount, $rates ); |
|
180 | + return apply_filters('getpaid_calculate_taxes', $taxes, $amount, $rates); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -189,53 +189,53 @@ discard block |
||
189 | 189 | * @param float $recurring_tax_amount |
190 | 190 | * @return array |
191 | 191 | */ |
192 | -function getpaid_prepare_item_tax( $item, $tax_name, $tax_amount, $recurring_tax_amount ) { |
|
192 | +function getpaid_prepare_item_tax($item, $tax_name, $tax_amount, $recurring_tax_amount) { |
|
193 | 193 | |
194 | - $initial_tax = $tax_amount; |
|
194 | + $initial_tax = $tax_amount; |
|
195 | 195 | $recurring_tax = 0; |
196 | 196 | |
197 | - if ( $item->is_recurring() ) { |
|
197 | + if ($item->is_recurring()) { |
|
198 | 198 | $recurring_tax = $recurring_tax_amount; |
199 | 199 | } |
200 | 200 | |
201 | 201 | return array( |
202 | - 'name' => sanitize_text_field( $tax_name ), |
|
202 | + 'name' => sanitize_text_field($tax_name), |
|
203 | 203 | 'initial_tax' => $initial_tax, |
204 | 204 | 'recurring_tax' => $recurring_tax, |
205 | 205 | ); |
206 | 206 | |
207 | 207 | } |
208 | 208 | |
209 | -function wpinv_sales_tax_for_year( $year = null ) { |
|
210 | - return wpinv_price( wpinv_format_amount( wpinv_get_sales_tax_for_year( $year ) ) ); |
|
209 | +function wpinv_sales_tax_for_year($year = null) { |
|
210 | + return wpinv_price(wpinv_format_amount(wpinv_get_sales_tax_for_year($year))); |
|
211 | 211 | } |
212 | 212 | |
213 | -function wpinv_get_sales_tax_for_year( $year = null ) { |
|
213 | +function wpinv_get_sales_tax_for_year($year = null) { |
|
214 | 214 | global $wpdb; |
215 | 215 | |
216 | 216 | // Start at zero |
217 | 217 | $tax = 0; |
218 | 218 | |
219 | - if ( ! empty( $year ) ) { |
|
219 | + if (!empty($year)) { |
|
220 | 220 | $args = array( |
221 | 221 | 'post_type' => 'wpi_invoice', |
222 | - 'post_status' => array( 'publish' ), |
|
222 | + 'post_status' => array('publish'), |
|
223 | 223 | 'posts_per_page' => -1, |
224 | 224 | 'year' => $year, |
225 | 225 | 'fields' => 'ids' |
226 | 226 | ); |
227 | 227 | |
228 | - $payments = get_posts( $args ); |
|
229 | - $payment_ids = implode( ',', $payments ); |
|
228 | + $payments = get_posts($args); |
|
229 | + $payment_ids = implode(',', $payments); |
|
230 | 230 | |
231 | - if ( count( $payments ) > 0 ) { |
|
231 | + if (count($payments) > 0) { |
|
232 | 232 | $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )"; |
233 | - $tax = $wpdb->get_var( $sql ); |
|
233 | + $tax = $wpdb->get_var($sql); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | } |
237 | 237 | |
238 | - return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year ); |
|
238 | + return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | function wpinv_is_cart_taxed() { |
@@ -244,33 +244,33 @@ discard block |
||
244 | 244 | |
245 | 245 | function wpinv_prices_show_tax_on_checkout() { |
246 | 246 | return false; // TODO |
247 | - $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
247 | + $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
248 | 248 | |
249 | - return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret ); |
|
249 | + return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | function wpinv_display_tax_rate() { |
253 | - $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false ); |
|
253 | + $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false); |
|
254 | 254 | |
255 | - return apply_filters( 'wpinv_display_tax_rate', $ret ); |
|
255 | + return apply_filters('wpinv_display_tax_rate', $ret); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | function wpinv_cart_needs_tax_address_fields() { |
259 | - if( !wpinv_is_cart_taxed() ) |
|
259 | + if (!wpinv_is_cart_taxed()) |
|
260 | 260 | return false; |
261 | 261 | |
262 | - return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' ); |
|
262 | + return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields'); |
|
263 | 263 | } |
264 | 264 | |
265 | -function wpinv_item_is_tax_exclusive( $item_id = 0 ) { |
|
266 | - $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false ); |
|
267 | - return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id ); |
|
265 | +function wpinv_item_is_tax_exclusive($item_id = 0) { |
|
266 | + $ret = (bool) get_post_meta($item_id, '_wpinv_tax_exclusive', false); |
|
267 | + return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id); |
|
268 | 268 | } |
269 | 269 | |
270 | -function wpinv_currency_decimal_filter( $decimals = 2 ) { |
|
270 | +function wpinv_currency_decimal_filter($decimals = 2) { |
|
271 | 271 | $currency = wpinv_get_currency(); |
272 | 272 | |
273 | - switch ( $currency ) { |
|
273 | + switch ($currency) { |
|
274 | 274 | case 'RIAL' : |
275 | 275 | case 'JPY' : |
276 | 276 | case 'TWD' : |
@@ -279,50 +279,50 @@ discard block |
||
279 | 279 | break; |
280 | 280 | } |
281 | 281 | |
282 | - return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency ); |
|
282 | + return apply_filters('wpinv_currency_decimal_count', $decimals, $currency); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | function wpinv_tax_amount() { |
286 | 286 | $output = 0.00; |
287 | 287 | |
288 | - return apply_filters( 'wpinv_tax_amount', $output ); |
|
288 | + return apply_filters('wpinv_tax_amount', $output); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | // VAT Settings |
292 | -function wpinv_vat_rate_add_callback( $args ) { |
|
292 | +function wpinv_vat_rate_add_callback($args) { |
|
293 | 293 | ?> |
294 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e( 'Add', 'invoicing' );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
294 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
295 | 295 | <?php |
296 | 296 | } |
297 | 297 | |
298 | -function wpinv_vat_rate_delete_callback( $args ) { |
|
298 | +function wpinv_vat_rate_delete_callback($args) { |
|
299 | 299 | global $wpinv_euvat; |
300 | 300 | |
301 | 301 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
302 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : ''; |
|
303 | - if ( isset( $vat_classes[$vat_class] ) ) { |
|
302 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : ''; |
|
303 | + if (isset($vat_classes[$vat_class])) { |
|
304 | 304 | ?> |
305 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf( esc_attr__( 'Delete class "%s"', 'invoicing' ), $vat_classes[$vat_class] );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
305 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf(esc_attr__('Delete class "%s"', 'invoicing'), $vat_classes[$vat_class]); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
306 | 306 | <?php |
307 | 307 | } |
308 | 308 | } |
309 | 309 | |
310 | -function wpinv_vat_rates_callback( $args ) { |
|
310 | +function wpinv_vat_rates_callback($args) { |
|
311 | 311 | global $wpinv_euvat; |
312 | 312 | |
313 | 313 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
314 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_standard'; |
|
314 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_standard'; |
|
315 | 315 | |
316 | 316 | $eu_states = $wpinv_euvat->get_eu_states(); |
317 | 317 | $countries = wpinv_get_country_list(); |
318 | 318 | $vat_groups = $wpinv_euvat->get_vat_groups(); |
319 | - $rates = $wpinv_euvat->get_vat_rates( $vat_class ); |
|
319 | + $rates = $wpinv_euvat->get_vat_rates($vat_class); |
|
320 | 320 | ob_start(); |
321 | 321 | ?> |
322 | 322 | </td><tr> |
323 | 323 | <td colspan="2" class="wpinv_vat_tdbox"> |
324 | - <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class;?>" /> |
|
325 | - <p><?php echo ( isset( $args['desc'] ) ? $args['desc'] : '' ); ?></p> |
|
324 | + <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class; ?>" /> |
|
325 | + <p><?php echo (isset($args['desc']) ? $args['desc'] : ''); ?></p> |
|
326 | 326 | <table id="wpinv_vat_rates" class="wp-list-table widefat fixed posts"> |
327 | 327 | <colgroup> |
328 | 328 | <col width="50px" /> |
@@ -334,43 +334,43 @@ discard block |
||
334 | 334 | </colgroup> |
335 | 335 | <thead> |
336 | 336 | <tr> |
337 | - <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e( 'Country', 'invoicing' ); ?></th> |
|
338 | - <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e( 'Apply rate to whole country', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th> |
|
339 | - <th scope="col" class="wpinv_vat_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> |
|
340 | - <th scope="col" class="wpinv_vat_name"><?php _e( 'VAT Name', 'invoicing' ); ?></th> |
|
341 | - <th scope="col" class="wpinv_vat_group"><?php _e( 'Tax Group', 'invoicing' ); ?></th> |
|
337 | + <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e('Country', 'invoicing'); ?></th> |
|
338 | + <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e('Apply rate to whole country', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th> |
|
339 | + <th scope="col" class="wpinv_vat_rate"><?php _e('Rate %', 'invoicing'); ?></th> |
|
340 | + <th scope="col" class="wpinv_vat_name"><?php _e('VAT Name', 'invoicing'); ?></th> |
|
341 | + <th scope="col" class="wpinv_vat_group"><?php _e('Tax Group', 'invoicing'); ?></th> |
|
342 | 342 | </tr> |
343 | 343 | </thead> |
344 | 344 | <tbody> |
345 | - <?php if( !empty( $eu_states ) ) { ?> |
|
345 | + <?php if (!empty($eu_states)) { ?> |
|
346 | 346 | <?php |
347 | - foreach ( $eu_states as $state ) { |
|
348 | - $country_name = isset( $countries[$state] ) ? $countries[$state] : ''; |
|
347 | + foreach ($eu_states as $state) { |
|
348 | + $country_name = isset($countries[$state]) ? $countries[$state] : ''; |
|
349 | 349 | |
350 | 350 | // Filter the rate for each country |
351 | - $country_rate = array_filter( $rates, function( $rate ) use( $state ) { return $rate['country'] === $state; } ); |
|
351 | + $country_rate = array_filter($rates, function($rate) use($state) { return $rate['country'] === $state; } ); |
|
352 | 352 | |
353 | 353 | // If one does not exist create a default |
354 | - $country_rate = is_array( $country_rate ) && count( $country_rate ) > 0 ? reset( $country_rate ) : array(); |
|
354 | + $country_rate = is_array($country_rate) && count($country_rate) > 0 ? reset($country_rate) : array(); |
|
355 | 355 | |
356 | - $vat_global = isset( $country_rate['global'] ) ? !empty( $country_rate['global'] ) : true; |
|
357 | - $vat_rate = isset( $country_rate['rate'] ) ? $country_rate['rate'] : ''; |
|
358 | - $vat_name = !empty( $country_rate['name'] ) ? esc_attr( stripslashes( $country_rate['name'] ) ) : ''; |
|
359 | - $vat_group = !empty( $country_rate['group'] ) ? $country_rate['group'] : ( $vat_class === '_standard' ? 'standard' : 'reduced' ); |
|
356 | + $vat_global = isset($country_rate['global']) ? !empty($country_rate['global']) : true; |
|
357 | + $vat_rate = isset($country_rate['rate']) ? $country_rate['rate'] : ''; |
|
358 | + $vat_name = !empty($country_rate['name']) ? esc_attr(stripslashes($country_rate['name'])) : ''; |
|
359 | + $vat_group = !empty($country_rate['group']) ? $country_rate['group'] : ($vat_class === '_standard' ? 'standard' : 'reduced'); |
|
360 | 360 | ?> |
361 | 361 | <tr> |
362 | 362 | <td class="wpinv_vat_country"><?php echo $state; ?><input type="hidden" name="vat_rates[<?php echo $state; ?>][country]" value="<?php echo $state; ?>" /><input type="hidden" name="vat_rates[<?php echo $state; ?>][state]" value="" /></td> |
363 | 363 | <td class="wpinv_vat_country_name"><?php echo $country_name; ?></td> |
364 | 364 | <td class="wpinv_vat_global"> |
365 | - <input type="checkbox" name="vat_rates[<?php echo $state;?>][global]" id="vat_rates[<?php echo $state;?>][global]" value="1" <?php checked( true, $vat_global );?> disabled="disabled" /> |
|
366 | - <label for="tax_rates[<?php echo $state;?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label> |
|
367 | - <input type="hidden" name="vat_rates[<?php echo $state;?>][global]" value="1" checked="checked" /> |
|
365 | + <input type="checkbox" name="vat_rates[<?php echo $state; ?>][global]" id="vat_rates[<?php echo $state; ?>][global]" value="1" <?php checked(true, $vat_global); ?> disabled="disabled" /> |
|
366 | + <label for="tax_rates[<?php echo $state; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label> |
|
367 | + <input type="hidden" name="vat_rates[<?php echo $state; ?>][global]" value="1" checked="checked" /> |
|
368 | 368 | </td> |
369 | - <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state;?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
370 | - <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state;?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
369 | + <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state; ?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
370 | + <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state; ?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
371 | 371 | <td class="wpinv_vat_group"> |
372 | 372 | <?php |
373 | - echo wpinv_html_select( array( |
|
373 | + echo wpinv_html_select(array( |
|
374 | 374 | 'name' => 'vat_rates[' . $state . '][group]', |
375 | 375 | 'selected' => $vat_group, |
376 | 376 | 'id' => 'vat_rates[' . $state . '][group]', |
@@ -379,14 +379,14 @@ discard block |
||
379 | 379 | 'multiple' => false, |
380 | 380 | 'show_option_all' => false, |
381 | 381 | 'show_option_none' => false |
382 | - ) ); |
|
382 | + )); |
|
383 | 383 | ?> |
384 | 384 | </td> |
385 | 385 | </tr> |
386 | 386 | <?php } ?> |
387 | 387 | <tr> |
388 | 388 | <td colspan="6" style="background-color:#fafafa;"> |
389 | - <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e( 'Update EU VAT Rates', 'invoicing' ); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
389 | + <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e('Update EU VAT Rates', 'invoicing'); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
390 | 390 | </td> |
391 | 391 | </tr> |
392 | 392 | <?php } ?> |
@@ -398,21 +398,21 @@ discard block |
||
398 | 398 | echo $content; |
399 | 399 | } |
400 | 400 | |
401 | -function wpinv_vat_number_callback( $args ) { |
|
401 | +function wpinv_vat_number_callback($args) { |
|
402 | 402 | global $wpinv_euvat; |
403 | 403 | |
404 | 404 | $vat_number = $wpinv_euvat->get_vat_number(); |
405 | 405 | $vat_valid = $wpinv_euvat->is_vat_validated(); |
406 | 406 | |
407 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
408 | - $validated_text = $vat_valid ? __( 'VAT number validated', 'invoicing' ) : __( 'VAT number not validated', 'invoicing' ); |
|
407 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
408 | + $validated_text = $vat_valid ? __('VAT number validated', 'invoicing') : __('VAT number not validated', 'invoicing'); |
|
409 | 409 | $disabled = $vat_valid ? 'disabled="disabled"' : " "; |
410 | 410 | |
411 | - $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr( stripslashes( $vat_number ) ) . '"/>'; |
|
412 | - $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__( 'Validate VAT Number', 'invoicing' ) . '" /></span>'; |
|
413 | - $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int)$vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>'; |
|
414 | - $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __( 'Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing' ).'</p>' . '</label>'; |
|
415 | - $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce( 'vat_validation' ) . '">'; |
|
411 | + $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr(stripslashes($vat_number)) . '"/>'; |
|
412 | + $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__('Validate VAT Number', 'invoicing') . '" /></span>'; |
|
413 | + $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int) $vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>'; |
|
414 | + $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __('Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing') . '</p>' . '</label>'; |
|
415 | + $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce('vat_validation') . '">'; |
|
416 | 416 | |
417 | 417 | echo $html; |
418 | 418 | } |
@@ -422,22 +422,22 @@ discard block |
||
422 | 422 | * |
423 | 423 | * @param string|bool|null $vat_rule |
424 | 424 | */ |
425 | -function getpaid_filter_vat_rule( $vat_rule ) { |
|
425 | +function getpaid_filter_vat_rule($vat_rule) { |
|
426 | 426 | |
427 | - if ( empty( $vat_rule ) ) { |
|
427 | + if (empty($vat_rule)) { |
|
428 | 428 | return getpaid_tax()->allow_vat_rules() ? 'digital' : 'physical'; |
429 | 429 | } |
430 | 430 | |
431 | 431 | return $vat_rule; |
432 | 432 | } |
433 | -add_filter( 'wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule' ); |
|
433 | +add_filter('wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule'); |
|
434 | 434 | |
435 | 435 | /** |
436 | 436 | * Filters the VAT class to ensure that each item has a VAT class. |
437 | 437 | * |
438 | 438 | * @param string|bool|null $vat_rule |
439 | 439 | */ |
440 | -function getpaid_filter_vat_class( $vat_class ) { |
|
441 | - return empty( $vat_class ) ? '_standard' : $vat_class; |
|
440 | +function getpaid_filter_vat_class($vat_class) { |
|
441 | + return empty($vat_class) ? '_standard' : $vat_class; |
|
442 | 442 | } |
443 | -add_filter( 'wpinv_get_item_vat_class', 'getpaid_filter_vat_class' ); |
|
443 | +add_filter('wpinv_get_item_vat_class', 'getpaid_filter_vat_class'); |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @version 1.0.19 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | return array( |
14 | 14 | |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | 'global' => true, |
19 | 19 | 'rate' => 20, |
20 | 20 | 'reduced_rate' => 13, |
21 | - 'name' => __( 'VAT', 'invoicing' ), |
|
21 | + 'name' => __('VAT', 'invoicing'), |
|
22 | 22 | ), |
23 | 23 | |
24 | 24 | array( |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | 'global' => true, |
28 | 28 | 'rate' => 21, |
29 | 29 | 'reduced_rate' => 12, |
30 | - 'name' => __( 'VAT', 'invoicing' ), |
|
30 | + 'name' => __('VAT', 'invoicing'), |
|
31 | 31 | ), |
32 | 32 | |
33 | 33 | array( |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | 'global' => true, |
37 | 37 | 'rate' => 20, |
38 | 38 | 'reduced_rate' => 9, |
39 | - 'name' => __( 'VAT', 'invoicing' ), |
|
39 | + 'name' => __('VAT', 'invoicing'), |
|
40 | 40 | ), |
41 | 41 | |
42 | 42 | array( |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | 'global' => true, |
46 | 46 | 'rate' => 19, |
47 | 47 | 'reduced_rate' => 9, |
48 | - 'name' => __( 'VAT', 'invoicing' ), |
|
48 | + 'name' => __('VAT', 'invoicing'), |
|
49 | 49 | ), |
50 | 50 | |
51 | 51 | array( |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | 'global' => true, |
55 | 55 | 'rate' => 21, |
56 | 56 | 'reduced_rate' => 15, |
57 | - 'name' => __( 'VAT', 'invoicing' ), |
|
57 | + 'name' => __('VAT', 'invoicing'), |
|
58 | 58 | ), |
59 | 59 | |
60 | 60 | array( |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | 'global' => true, |
64 | 64 | 'rate' => 25, |
65 | 65 | 'reduced_rate' => 25, |
66 | - 'name' => __( 'VAT', 'invoicing' ), |
|
66 | + 'name' => __('VAT', 'invoicing'), |
|
67 | 67 | ), |
68 | 68 | |
69 | 69 | array( |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | 'global' => true, |
73 | 73 | 'rate' => 16, |
74 | 74 | 'reduced_rate' => 5, |
75 | - 'name' => __( 'VAT', 'invoicing' ), |
|
75 | + 'name' => __('VAT', 'invoicing'), |
|
76 | 76 | ), |
77 | 77 | |
78 | 78 | array( |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | 'global' => true, |
82 | 82 | 'rate' => 20, |
83 | 83 | 'reduced_rate' => 9, |
84 | - 'name' => __( 'VAT', 'invoicing' ), |
|
84 | + 'name' => __('VAT', 'invoicing'), |
|
85 | 85 | ), |
86 | 86 | |
87 | 87 | array( |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | 'global' => true, |
91 | 91 | 'rate' => 24, |
92 | 92 | 'reduced_rate' => 13, |
93 | - 'name' => __( 'VAT', 'invoicing' ), |
|
93 | + 'name' => __('VAT', 'invoicing'), |
|
94 | 94 | ), |
95 | 95 | |
96 | 96 | array( |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | 'global' => true, |
100 | 100 | 'rate' => 21, |
101 | 101 | 'reduced_rate' => 10, |
102 | - 'name' => __( 'VAT', 'invoicing' ), |
|
102 | + 'name' => __('VAT', 'invoicing'), |
|
103 | 103 | ), |
104 | 104 | |
105 | 105 | array( |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | 'global' => true, |
109 | 109 | 'rate' => 24, |
110 | 110 | 'reduced_rate' => 14, |
111 | - 'name' => __( 'VAT', 'invoicing' ), |
|
111 | + 'name' => __('VAT', 'invoicing'), |
|
112 | 112 | ), |
113 | 113 | |
114 | 114 | array( |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | 'global' => true, |
118 | 118 | 'rate' => 20, |
119 | 119 | 'reduced_rate' => 10, |
120 | - 'name' => __( 'VAT', 'invoicing' ), |
|
120 | + 'name' => __('VAT', 'invoicing'), |
|
121 | 121 | ), |
122 | 122 | |
123 | 123 | array( |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | 'global' => true, |
127 | 127 | 'rate' => 25, |
128 | 128 | 'reduced_rate' => 13, |
129 | - 'name' => __( 'VAT', 'invoicing' ), |
|
129 | + 'name' => __('VAT', 'invoicing'), |
|
130 | 130 | ), |
131 | 131 | |
132 | 132 | array( |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | 'global' => true, |
136 | 136 | 'rate' => 25, |
137 | 137 | 'reduced_rate' => 13, |
138 | - 'name' => __( 'VAT', 'invoicing' ), |
|
138 | + 'name' => __('VAT', 'invoicing'), |
|
139 | 139 | ), |
140 | 140 | |
141 | 141 | array( |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | 'global' => true, |
145 | 145 | 'rate' => 22, |
146 | 146 | 'reduced_rate' => 10, |
147 | - 'name' => __( 'VAT', 'invoicing' ), |
|
147 | + 'name' => __('VAT', 'invoicing'), |
|
148 | 148 | ), |
149 | 149 | |
150 | 150 | array( |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | 'global' => true, |
154 | 154 | 'rate' => 21, |
155 | 155 | 'reduced_rate' => 12, |
156 | - 'name' => __( 'VAT', 'invoicing' ), |
|
156 | + 'name' => __('VAT', 'invoicing'), |
|
157 | 157 | ), |
158 | 158 | |
159 | 159 | array( |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | 'global' => true, |
163 | 163 | 'rate' => 21, |
164 | 164 | 'reduced_rate' => 9, |
165 | - 'name' => __( 'VAT', 'invoicing' ), |
|
165 | + 'name' => __('VAT', 'invoicing'), |
|
166 | 166 | ), |
167 | 167 | |
168 | 168 | array( |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | 'global' => true, |
172 | 172 | 'rate' => 17, |
173 | 173 | 'reduced_rate' => 14, |
174 | - 'name' => __( 'VAT', 'invoicing' ), |
|
174 | + 'name' => __('VAT', 'invoicing'), |
|
175 | 175 | ), |
176 | 176 | |
177 | 177 | array( |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | 'global' => true, |
181 | 181 | 'rate' => 27, |
182 | 182 | 'reduced_rate' => 18, |
183 | - 'name' => __( 'VAT', 'invoicing' ), |
|
183 | + 'name' => __('VAT', 'invoicing'), |
|
184 | 184 | ), |
185 | 185 | |
186 | 186 | array( |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | 'global' => true, |
190 | 190 | 'rate' => 21, |
191 | 191 | 'reduced_rate' => 13.5, |
192 | - 'name' => __( 'VAT', 'invoicing' ), |
|
192 | + 'name' => __('VAT', 'invoicing'), |
|
193 | 193 | ), |
194 | 194 | |
195 | 195 | array( |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | 'global' => true, |
199 | 199 | 'rate' => 18, |
200 | 200 | 'reduced_rate' => 7, |
201 | - 'name' => __( 'VAT', 'invoicing' ), |
|
201 | + 'name' => __('VAT', 'invoicing'), |
|
202 | 202 | ), |
203 | 203 | |
204 | 204 | array( |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | 'global' => true, |
208 | 208 | 'rate' => 21, |
209 | 209 | 'reduced_rate' => 9, |
210 | - 'name' => __( 'VAT', 'invoicing' ), |
|
210 | + 'name' => __('VAT', 'invoicing'), |
|
211 | 211 | ), |
212 | 212 | |
213 | 213 | array( |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | 'global' => true, |
217 | 217 | 'rate' => 23, |
218 | 218 | 'reduced_rate' => 8, |
219 | - 'name' => __( 'VAT', 'invoicing' ), |
|
219 | + 'name' => __('VAT', 'invoicing'), |
|
220 | 220 | ), |
221 | 221 | |
222 | 222 | array( |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | 'global' => true, |
226 | 226 | 'rate' => 23, |
227 | 227 | 'reduced_rate' => 13, |
228 | - 'name' => __( 'VAT', 'invoicing' ), |
|
228 | + 'name' => __('VAT', 'invoicing'), |
|
229 | 229 | ), |
230 | 230 | |
231 | 231 | array( |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | 'global' => true, |
235 | 235 | 'rate' => 19, |
236 | 236 | 'reduced_rate' => 9, |
237 | - 'name' => __( 'VAT', 'invoicing' ), |
|
237 | + 'name' => __('VAT', 'invoicing'), |
|
238 | 238 | ), |
239 | 239 | |
240 | 240 | array( |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | 'global' => true, |
244 | 244 | 'rate' => 22, |
245 | 245 | 'reduced_rate' => 9.5, |
246 | - 'name' => __( 'VAT', 'invoicing' ), |
|
246 | + 'name' => __('VAT', 'invoicing'), |
|
247 | 247 | ), |
248 | 248 | |
249 | 249 | array( |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | 'global' => true, |
253 | 253 | 'rate' => 20, |
254 | 254 | 'reduced_rate' => 10, |
255 | - 'name' => __( 'VAT', 'invoicing' ), |
|
255 | + 'name' => __('VAT', 'invoicing'), |
|
256 | 256 | ), |
257 | 257 | |
258 | 258 | array( |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | 'global' => true, |
262 | 262 | 'rate' => 25, |
263 | 263 | 'reduced_rate' => 12, |
264 | - 'name' => __( 'VAT', 'invoicing' ), |
|
264 | + 'name' => __('VAT', 'invoicing'), |
|
265 | 265 | ), |
266 | 266 | |
267 | 267 | array( |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | 'global' => true, |
271 | 271 | 'rate' => 20, |
272 | 272 | 'reduced_rate' => 5, |
273 | - 'name' => __( 'VAT', 'invoicing' ), |
|
273 | + 'name' => __('VAT', 'invoicing'), |
|
274 | 274 | ) |
275 | 275 | |
276 | 276 | ); |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Class GetPaid_Tax |
@@ -21,15 +21,15 @@ discard block |
||
21 | 21 | * @param boolean $price_includes_tax Whether the passed price has taxes included. |
22 | 22 | * @return array Array of tax name => tax amount. |
23 | 23 | */ |
24 | - public static function calc_tax( $price, $rates, $price_includes_tax = false ) { |
|
24 | + public static function calc_tax($price, $rates, $price_includes_tax = false) { |
|
25 | 25 | |
26 | - if ( $price_includes_tax ) { |
|
27 | - $taxes = self::calc_inclusive_tax( $price, $rates ); |
|
26 | + if ($price_includes_tax) { |
|
27 | + $taxes = self::calc_inclusive_tax($price, $rates); |
|
28 | 28 | } else { |
29 | - $taxes = self::calc_exclusive_tax( $price, $rates ); |
|
29 | + $taxes = self::calc_exclusive_tax($price, $rates); |
|
30 | 30 | } |
31 | 31 | |
32 | - return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax ); |
|
32 | + return apply_filters('getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax); |
|
33 | 33 | |
34 | 34 | } |
35 | 35 | |
@@ -40,22 +40,22 @@ discard block |
||
40 | 40 | * @param array $rates Array of tax rates. |
41 | 41 | * @return array |
42 | 42 | */ |
43 | - public static function calc_inclusive_tax( $price, $rates ) { |
|
43 | + public static function calc_inclusive_tax($price, $rates) { |
|
44 | 44 | $taxes = array(); |
45 | - $tax_rates = wp_list_pluck( $rates, 'rate', 'name' ); |
|
45 | + $tax_rates = wp_list_pluck($rates, 'rate', 'name'); |
|
46 | 46 | |
47 | 47 | // Add tax rates. |
48 | - $tax_rate = 1 + ( array_sum( $tax_rates ) / 100 ); |
|
48 | + $tax_rate = 1 + (array_sum($tax_rates) / 100); |
|
49 | 49 | |
50 | - foreach ( $tax_rates as $name => $rate ) { |
|
51 | - $the_rate = ( $rate / 100 ) / $tax_rate; |
|
52 | - $net_price = $price - ( $the_rate * $price ); |
|
53 | - $tax_amount = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price ); |
|
54 | - $taxes[ $name ] = $tax_amount; |
|
50 | + foreach ($tax_rates as $name => $rate) { |
|
51 | + $the_rate = ($rate / 100) / $tax_rate; |
|
52 | + $net_price = $price - ($the_rate * $price); |
|
53 | + $tax_amount = apply_filters('getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price); |
|
54 | + $taxes[$name] = $tax_amount; |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | // Round all taxes to precision (4DP) before passing them back. |
58 | - $taxes = array_map( array( __CLASS__, 'round' ), $taxes ); |
|
58 | + $taxes = array_map(array(__CLASS__, 'round'), $taxes); |
|
59 | 59 | |
60 | 60 | return $taxes; |
61 | 61 | } |
@@ -67,19 +67,19 @@ discard block |
||
67 | 67 | * @param array $rates Array of tax rates. |
68 | 68 | * @return array |
69 | 69 | */ |
70 | - public static function calc_exclusive_tax( $price, $rates ) { |
|
70 | + public static function calc_exclusive_tax($price, $rates) { |
|
71 | 71 | $taxes = array(); |
72 | - $tax_rates = wp_list_pluck( $rates, 'rate', 'name' ); |
|
72 | + $tax_rates = wp_list_pluck($rates, 'rate', 'name'); |
|
73 | 73 | |
74 | - foreach ( $tax_rates as $name => $rate ) { |
|
74 | + foreach ($tax_rates as $name => $rate) { |
|
75 | 75 | |
76 | - $tax_amount = $price * ( $rate / 100 ); |
|
77 | - $taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price ); |
|
76 | + $tax_amount = $price * ($rate / 100); |
|
77 | + $taxes[$name] = apply_filters('getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price); |
|
78 | 78 | |
79 | 79 | } |
80 | 80 | |
81 | 81 | // Round all taxes to precision (4DP) before passing them back. |
82 | - $taxes = array_map( array( __CLASS__, 'round' ), $taxes ); |
|
82 | + $taxes = array_map(array(__CLASS__, 'round'), $taxes); |
|
83 | 83 | |
84 | 84 | return $taxes; |
85 | 85 | } |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public static function get_all_tax_rates() { |
93 | 93 | |
94 | - $rates = get_option( 'wpinv_tax_rates', array() ); |
|
94 | + $rates = get_option('wpinv_tax_rates', array()); |
|
95 | 95 | |
96 | 96 | return apply_filters( |
97 | 97 | 'getpaid_get_all_tax_rates', |
98 | - array_filter( wpinv_parse_list( $rates ) ) |
|
98 | + array_filter(wpinv_parse_list($rates)) |
|
99 | 99 | ); |
100 | 100 | |
101 | 101 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | 'state' => wpinv_get_default_state(), |
116 | 116 | 'global' => true, |
117 | 117 | 'rate' => wpinv_get_default_tax_rate(), |
118 | - 'name' => __( 'Base Tax', 'invoicing' ), |
|
118 | + 'name' => __('Base Tax', 'invoicing'), |
|
119 | 119 | ) |
120 | 120 | ) |
121 | 121 | ); |
@@ -129,24 +129,24 @@ discard block |
||
129 | 129 | * @param string $state |
130 | 130 | * @return array |
131 | 131 | */ |
132 | - public static function get_address_tax_rates( $country, $state ) { |
|
132 | + public static function get_address_tax_rates($country, $state) { |
|
133 | 133 | |
134 | 134 | $all_tax_rates = self::get_all_tax_rates(); |
135 | 135 | $matching_rates = array_merge( |
136 | - wp_list_filter( $all_tax_rates, array( 'country' => $country ) ), |
|
137 | - wp_list_filter( $all_tax_rates, array( 'country' => '' ) ) |
|
136 | + wp_list_filter($all_tax_rates, array('country' => $country)), |
|
137 | + wp_list_filter($all_tax_rates, array('country' => '')) |
|
138 | 138 | ); |
139 | 139 | |
140 | - foreach ( $matching_rates as $i => $rate ) { |
|
140 | + foreach ($matching_rates as $i => $rate) { |
|
141 | 141 | |
142 | - $states = array_filter( wpinv_clean( explode( ',', $rate['state'] ) ) ); |
|
143 | - if ( empty( $rate['global'] ) && ! in_array( $state, $states ) ) { |
|
144 | - unset( $matching_rates[ $i ] ); |
|
142 | + $states = array_filter(wpinv_clean(explode(',', $rate['state']))); |
|
143 | + if (empty($rate['global']) && !in_array($state, $states)) { |
|
144 | + unset($matching_rates[$i]); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | } |
148 | 148 | |
149 | - return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state ); |
|
149 | + return apply_filters('getpaid_get_address_tax_rates', $matching_rates, $country, $state); |
|
150 | 150 | |
151 | 151 | } |
152 | 152 | |
@@ -156,8 +156,8 @@ discard block |
||
156 | 156 | * @param array $taxes Array of taxes. |
157 | 157 | * @return float |
158 | 158 | */ |
159 | - public static function get_tax_total( $taxes ) { |
|
160 | - return self::round( array_sum( $taxes ) ); |
|
159 | + public static function get_tax_total($taxes) { |
|
160 | + return self::round(array_sum($taxes)); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -173,8 +173,8 @@ discard block |
||
173 | 173 | * @param float|int $in Value to round. |
174 | 174 | * @return float |
175 | 175 | */ |
176 | - public static function round( $in ) { |
|
177 | - return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in ); |
|
176 | + public static function round($in) { |
|
177 | + return apply_filters('getpaid_tax_round', round($in, 4), $in); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | } |