@@ -16,23 +16,23 @@ discard block |
||
16 | 16 | */ |
17 | 17 | public function __construct() { |
18 | 18 | |
19 | - $forms = get_posts( |
|
20 | - array( |
|
21 | - 'post_type' => 'wpi_payment_form', |
|
22 | - 'orderby' => 'title', |
|
23 | - 'order' => 'ASC', |
|
24 | - 'posts_per_page' => -1, |
|
25 | - 'post_status' => array( 'publish' ), |
|
26 | - ) |
|
27 | - ); |
|
28 | - |
|
29 | - $options = array( |
|
30 | - '' => __('Select a Form','invoicing') |
|
31 | - ); |
|
32 | - |
|
33 | - foreach( $forms as $form ) { |
|
34 | - $options[ $form->ID ] = $form->post_title; |
|
35 | - } |
|
19 | + $forms = get_posts( |
|
20 | + array( |
|
21 | + 'post_type' => 'wpi_payment_form', |
|
22 | + 'orderby' => 'title', |
|
23 | + 'order' => 'ASC', |
|
24 | + 'posts_per_page' => -1, |
|
25 | + 'post_status' => array( 'publish' ), |
|
26 | + ) |
|
27 | + ); |
|
28 | + |
|
29 | + $options = array( |
|
30 | + '' => __('Select a Form','invoicing') |
|
31 | + ); |
|
32 | + |
|
33 | + foreach( $forms as $form ) { |
|
34 | + $options[ $form->ID ] = $form->post_title; |
|
35 | + } |
|
36 | 36 | |
37 | 37 | $options = array( |
38 | 38 | 'textdomain' => 'invoicing', |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | 'form' => array( |
51 | 51 | 'title' => __( 'Payment Form', 'invoicing' ), |
52 | 52 | 'desc' => __( 'Select your payment form.', 'invoicing' ), |
53 | - 'type' => 'select', |
|
54 | - 'options' => $options, |
|
53 | + 'type' => 'select', |
|
54 | + 'options' => $options, |
|
55 | 55 | 'desc_tip' => true, |
56 | 56 | 'default' => '', |
57 | 57 | 'advanced' => false |
@@ -64,60 +64,60 @@ discard block |
||
64 | 64 | parent::__construct( $options ); |
65 | 65 | } |
66 | 66 | |
67 | - /** |
|
68 | - * The Super block output function. |
|
69 | - * |
|
70 | - * @param array $args |
|
71 | - * @param array $widget_args |
|
72 | - * @param string $content |
|
73 | - * |
|
74 | - * @return string |
|
75 | - */ |
|
67 | + /** |
|
68 | + * The Super block output function. |
|
69 | + * |
|
70 | + * @param array $args |
|
71 | + * @param array $widget_args |
|
72 | + * @param string $content |
|
73 | + * |
|
74 | + * @return string |
|
75 | + */ |
|
76 | 76 | public function output( $args = array(), $widget_args = array(), $content = '' ) { |
77 | - global $invoicing; |
|
78 | - |
|
79 | - // Do we have a payment form? |
|
80 | - if ( empty( $args['form'] ) ) { |
|
81 | - return aui()->alert( |
|
82 | - array( |
|
83 | - 'type' => 'warning', |
|
84 | - 'content' => __( 'No payment form selected', 'invoicing' ), |
|
85 | - ) |
|
86 | - ); |
|
87 | - |
|
88 | - } |
|
89 | - |
|
90 | - // If yes, ensure that it is published. |
|
91 | - if ( 'publish' != get_post_status( $args['form'] ) ) { |
|
92 | - return aui()->alert( |
|
93 | - array( |
|
94 | - 'type' => 'warning', |
|
95 | - 'content' => __( 'This payment form is no longer active', 'invoicing' ), |
|
96 | - ) |
|
97 | - ); |
|
98 | - } |
|
99 | - |
|
100 | - // Get the form elements and items. |
|
101 | - $elements = $invoicing->form_elements->get_form_elements( $args['form'] ); |
|
102 | - $items = $invoicing->form_elements->get_form_items( $args['form'] ); |
|
103 | - |
|
104 | - ob_start(); |
|
105 | - echo "<form class='wpinv_payment_form'>"; |
|
106 | - echo "<input type='hidden' name='form_id' value='{$args['form']}'/>"; |
|
107 | - wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' ); |
|
108 | - wp_nonce_field( 'vat_validation', '_wpi_nonce' ); |
|
109 | - |
|
110 | - foreach ( $elements as $element ) { |
|
111 | - do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $args['form'] ); |
|
112 | - do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $args['form'] ); |
|
113 | - } |
|
114 | - |
|
115 | - echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>"; |
|
116 | - echo '</form>'; |
|
117 | - |
|
118 | - $content = ob_get_clean(); |
|
77 | + global $invoicing; |
|
78 | + |
|
79 | + // Do we have a payment form? |
|
80 | + if ( empty( $args['form'] ) ) { |
|
81 | + return aui()->alert( |
|
82 | + array( |
|
83 | + 'type' => 'warning', |
|
84 | + 'content' => __( 'No payment form selected', 'invoicing' ), |
|
85 | + ) |
|
86 | + ); |
|
87 | + |
|
88 | + } |
|
89 | + |
|
90 | + // If yes, ensure that it is published. |
|
91 | + if ( 'publish' != get_post_status( $args['form'] ) ) { |
|
92 | + return aui()->alert( |
|
93 | + array( |
|
94 | + 'type' => 'warning', |
|
95 | + 'content' => __( 'This payment form is no longer active', 'invoicing' ), |
|
96 | + ) |
|
97 | + ); |
|
98 | + } |
|
99 | + |
|
100 | + // Get the form elements and items. |
|
101 | + $elements = $invoicing->form_elements->get_form_elements( $args['form'] ); |
|
102 | + $items = $invoicing->form_elements->get_form_items( $args['form'] ); |
|
103 | + |
|
104 | + ob_start(); |
|
105 | + echo "<form class='wpinv_payment_form'>"; |
|
106 | + echo "<input type='hidden' name='form_id' value='{$args['form']}'/>"; |
|
107 | + wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' ); |
|
108 | + wp_nonce_field( 'vat_validation', '_wpi_nonce' ); |
|
109 | + |
|
110 | + foreach ( $elements as $element ) { |
|
111 | + do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $args['form'] ); |
|
112 | + do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $args['form'] ); |
|
113 | + } |
|
114 | + |
|
115 | + echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>"; |
|
116 | + echo '</form>'; |
|
117 | + |
|
118 | + $content = ob_get_clean(); |
|
119 | 119 | |
120 | - return str_replace( 'sr-only', '', $content ); |
|
120 | + return str_replace( 'sr-only', '', $content ); |
|
121 | 121 | |
122 | 122 | } |
123 | 123 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
3 | +if (!defined('ABSPATH')) { |
|
4 | 4 | exit; // Exit if accessed directly |
5 | 5 | } |
6 | 6 | |
@@ -22,16 +22,16 @@ discard block |
||
22 | 22 | 'orderby' => 'title', |
23 | 23 | 'order' => 'ASC', |
24 | 24 | 'posts_per_page' => -1, |
25 | - 'post_status' => array( 'publish' ), |
|
25 | + 'post_status' => array('publish'), |
|
26 | 26 | ) |
27 | 27 | ); |
28 | 28 | |
29 | 29 | $options = array( |
30 | - '' => __('Select a Form','invoicing') |
|
30 | + '' => __('Select a Form', 'invoicing') |
|
31 | 31 | ); |
32 | 32 | |
33 | - foreach( $forms as $form ) { |
|
34 | - $options[ $form->ID ] = $form->post_title; |
|
33 | + foreach ($forms as $form) { |
|
34 | + $options[$form->ID] = $form->post_title; |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | $options = array( |
@@ -41,15 +41,15 @@ discard block |
||
41 | 41 | 'block-keywords'=> "['invoicing','buy', 'buy item', 'pay', 'payment form']", |
42 | 42 | 'class_name' => __CLASS__, |
43 | 43 | 'base_id' => 'wpinv_payment_form', |
44 | - 'name' => __('Invoicing > Payment Form','invoicing'), |
|
44 | + 'name' => __('Invoicing > Payment Form', 'invoicing'), |
|
45 | 45 | 'widget_ops' => array( |
46 | 46 | 'classname' => 'wpinv-payment-form-class bsui', |
47 | - 'description' => esc_html__('Displays a payment form.','invoicing'), |
|
47 | + 'description' => esc_html__('Displays a payment form.', 'invoicing'), |
|
48 | 48 | ), |
49 | 49 | 'arguments' => array( |
50 | 50 | 'form' => array( |
51 | - 'title' => __( 'Payment Form', 'invoicing' ), |
|
52 | - 'desc' => __( 'Select your payment form.', 'invoicing' ), |
|
51 | + 'title' => __('Payment Form', 'invoicing'), |
|
52 | + 'desc' => __('Select your payment form.', 'invoicing'), |
|
53 | 53 | 'type' => 'select', |
54 | 54 | 'options' => $options, |
55 | 55 | 'desc_tip' => true, |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | ); |
62 | 62 | |
63 | 63 | |
64 | - parent::__construct( $options ); |
|
64 | + parent::__construct($options); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -73,43 +73,43 @@ discard block |
||
73 | 73 | * |
74 | 74 | * @return string |
75 | 75 | */ |
76 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
76 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
77 | 77 | global $invoicing; |
78 | 78 | |
79 | 79 | // Do we have a payment form? |
80 | - if ( empty( $args['form'] ) ) { |
|
80 | + if (empty($args['form'])) { |
|
81 | 81 | return aui()->alert( |
82 | 82 | array( |
83 | 83 | 'type' => 'warning', |
84 | - 'content' => __( 'No payment form selected', 'invoicing' ), |
|
84 | + 'content' => __('No payment form selected', 'invoicing'), |
|
85 | 85 | ) |
86 | 86 | ); |
87 | 87 | |
88 | 88 | } |
89 | 89 | |
90 | 90 | // If yes, ensure that it is published. |
91 | - if ( 'publish' != get_post_status( $args['form'] ) ) { |
|
91 | + if ('publish' != get_post_status($args['form'])) { |
|
92 | 92 | return aui()->alert( |
93 | 93 | array( |
94 | 94 | 'type' => 'warning', |
95 | - 'content' => __( 'This payment form is no longer active', 'invoicing' ), |
|
95 | + 'content' => __('This payment form is no longer active', 'invoicing'), |
|
96 | 96 | ) |
97 | 97 | ); |
98 | 98 | } |
99 | 99 | |
100 | 100 | // Get the form elements and items. |
101 | - $elements = $invoicing->form_elements->get_form_elements( $args['form'] ); |
|
102 | - $items = $invoicing->form_elements->get_form_items( $args['form'] ); |
|
101 | + $elements = $invoicing->form_elements->get_form_elements($args['form']); |
|
102 | + $items = $invoicing->form_elements->get_form_items($args['form']); |
|
103 | 103 | |
104 | 104 | ob_start(); |
105 | 105 | echo "<form class='wpinv_payment_form'>"; |
106 | 106 | echo "<input type='hidden' name='form_id' value='{$args['form']}'/>"; |
107 | - wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' ); |
|
108 | - wp_nonce_field( 'vat_validation', '_wpi_nonce' ); |
|
107 | + wp_nonce_field('wpinv_payment_form', 'wpinv_payment_form'); |
|
108 | + wp_nonce_field('vat_validation', '_wpi_nonce'); |
|
109 | 109 | |
110 | - foreach ( $elements as $element ) { |
|
111 | - do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $args['form'] ); |
|
112 | - do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $args['form'] ); |
|
110 | + foreach ($elements as $element) { |
|
111 | + do_action('wpinv_frontend_render_payment_form_element', $element, $items, $args['form']); |
|
112 | + do_action("wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $args['form']); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>"; |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | |
118 | 118 | $content = ob_get_clean(); |
119 | 119 | |
120 | - return str_replace( 'sr-only', '', $content ); |
|
120 | + return str_replace('sr-only', '', $content); |
|
121 | 121 | |
122 | 122 | } |
123 | 123 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
3 | +if (!defined('ABSPATH')) { |
|
4 | 4 | exit; // Exit if accessed directly |
5 | 5 | } |
6 | 6 | |
@@ -13,19 +13,19 @@ discard block |
||
13 | 13 | |
14 | 14 | public function __construct() { |
15 | 15 | |
16 | - foreach( $this->get_elements() as $element ) { |
|
16 | + foreach ($this->get_elements() as $element) { |
|
17 | 17 | $element = $element['type']; |
18 | 18 | |
19 | - if ( method_exists( $this, "render_{$element}_template" ) ) { |
|
20 | - add_action( 'wpinv_payment_form_render_element_template', array( $this, "render_{$element}_template" ), 10, 2 ); |
|
19 | + if (method_exists($this, "render_{$element}_template")) { |
|
20 | + add_action('wpinv_payment_form_render_element_template', array($this, "render_{$element}_template"), 10, 2); |
|
21 | 21 | } |
22 | 22 | |
23 | - if ( method_exists( $this, "edit_{$element}_template" ) ) { |
|
24 | - add_action( 'wpinv_payment_form_edit_element_template', array( $this, "edit_{$element}_template" ), 10, 2 ); |
|
23 | + if (method_exists($this, "edit_{$element}_template")) { |
|
24 | + add_action('wpinv_payment_form_edit_element_template', array($this, "edit_{$element}_template"), 10, 2); |
|
25 | 25 | } |
26 | 26 | |
27 | - if ( method_exists( $this, "frontend_render_{$element}_template" ) ) { |
|
28 | - add_action( "wpinv_frontend_render_payment_form_$element", array( $this, "frontend_render_{$element}_template" ), 10, 3 ); |
|
27 | + if (method_exists($this, "frontend_render_{$element}_template")) { |
|
28 | + add_action("wpinv_frontend_render_payment_form_$element", array($this, "frontend_render_{$element}_template"), 10, 3); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function get_elements() { |
39 | 39 | |
40 | - if ( ! empty( $this->elements ) ) { |
|
40 | + if (!empty($this->elements)) { |
|
41 | 41 | return $this->elements; |
42 | 42 | } |
43 | 43 | |
@@ -45,28 +45,28 @@ discard block |
||
45 | 45 | |
46 | 46 | array( |
47 | 47 | 'type' => 'heading', |
48 | - 'name' => __( 'Heading', 'invoicing' ), |
|
48 | + 'name' => __('Heading', 'invoicing'), |
|
49 | 49 | 'defaults' => array( |
50 | 50 | 'level' => 'h2', |
51 | - 'text' => __( 'Heading', 'invoicing' ), |
|
51 | + 'text' => __('Heading', 'invoicing'), |
|
52 | 52 | ) |
53 | 53 | ), |
54 | 54 | |
55 | 55 | array( |
56 | 56 | 'type' => 'paragraph', |
57 | - 'name' => __( 'Paragraph', 'invoicing' ), |
|
57 | + 'name' => __('Paragraph', 'invoicing'), |
|
58 | 58 | 'defaults' => array( |
59 | - 'text' => __( 'Paragraph text', 'invoicing' ), |
|
59 | + 'text' => __('Paragraph text', 'invoicing'), |
|
60 | 60 | ) |
61 | 61 | ), |
62 | 62 | |
63 | 63 | array( |
64 | 64 | 'type' => 'alert', |
65 | - 'name' => __( 'Alert', 'invoicing' ), |
|
65 | + 'name' => __('Alert', 'invoicing'), |
|
66 | 66 | 'defaults' => array( |
67 | 67 | 'value' => '', |
68 | 68 | 'class' => 'alert-warning', |
69 | - 'text' => __( 'Alert', 'invoicing' ), |
|
69 | + 'text' => __('Alert', 'invoicing'), |
|
70 | 70 | 'dismissible' => false, |
71 | 71 | ) |
72 | 72 | ), |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | |
83 | 83 | array( |
84 | 84 | 'type' => 'text', |
85 | - 'name' => __( 'Text Input', 'invoicing' ), |
|
85 | + 'name' => __('Text Input', 'invoicing'), |
|
86 | 86 | 'defaults' => array( |
87 | - 'placeholder' => __( 'Enter some text', 'invoicing' ), |
|
87 | + 'placeholder' => __('Enter some text', 'invoicing'), |
|
88 | 88 | 'value' => '', |
89 | - 'label' => __( 'Field Label', 'invoicing' ), |
|
89 | + 'label' => __('Field Label', 'invoicing'), |
|
90 | 90 | 'description' => '', |
91 | 91 | 'required' => false, |
92 | 92 | ) |
@@ -94,11 +94,11 @@ discard block |
||
94 | 94 | |
95 | 95 | array( |
96 | 96 | 'type' => 'textarea', |
97 | - 'name' => __( 'Textarea', 'invoicing' ), |
|
97 | + 'name' => __('Textarea', 'invoicing'), |
|
98 | 98 | 'defaults' => array( |
99 | - 'placeholder' => __( 'Enter your text hear', 'invoicing' ), |
|
99 | + 'placeholder' => __('Enter your text hear', 'invoicing'), |
|
100 | 100 | 'value' => '', |
101 | - 'label' => __( 'Textarea Label', 'invoicing' ), |
|
101 | + 'label' => __('Textarea Label', 'invoicing'), |
|
102 | 102 | 'description' => '', |
103 | 103 | 'required' => false, |
104 | 104 | ) |
@@ -106,27 +106,27 @@ discard block |
||
106 | 106 | |
107 | 107 | array( |
108 | 108 | 'type' => 'select', |
109 | - 'name' => __( 'Dropdown', 'invoicing' ), |
|
109 | + 'name' => __('Dropdown', 'invoicing'), |
|
110 | 110 | 'defaults' => array( |
111 | - 'placeholder' => __( 'Select a value', 'invoicing' ), |
|
111 | + 'placeholder' => __('Select a value', 'invoicing'), |
|
112 | 112 | 'value' => '', |
113 | - 'label' => __( 'Dropdown Label', 'invoicing' ), |
|
113 | + 'label' => __('Dropdown Label', 'invoicing'), |
|
114 | 114 | 'description' => '', |
115 | 115 | 'required' => false, |
116 | 116 | 'options' => array( |
117 | - esc_attr__( 'Option One', 'invoicing' ), |
|
118 | - esc_attr__( 'Option Two', 'invoicing' ), |
|
119 | - esc_attr__( 'Option Three', 'invoicing' ) |
|
117 | + esc_attr__('Option One', 'invoicing'), |
|
118 | + esc_attr__('Option Two', 'invoicing'), |
|
119 | + esc_attr__('Option Three', 'invoicing') |
|
120 | 120 | ), |
121 | 121 | ) |
122 | 122 | ), |
123 | 123 | |
124 | 124 | array( |
125 | 125 | 'type' => 'checkbox', |
126 | - 'name' => __( 'Checkbox', 'invoicing' ), |
|
126 | + 'name' => __('Checkbox', 'invoicing'), |
|
127 | 127 | 'defaults' => array( |
128 | 128 | 'value' => '', |
129 | - 'label' => __( 'Checkbox Label', 'invoicing' ), |
|
129 | + 'label' => __('Checkbox Label', 'invoicing'), |
|
130 | 130 | 'description' => '', |
131 | 131 | 'required' => false, |
132 | 132 | ) |
@@ -134,24 +134,24 @@ discard block |
||
134 | 134 | |
135 | 135 | array( |
136 | 136 | 'type' => 'radio', |
137 | - 'name' => __( 'Multiple Choice', 'invoicing' ), |
|
137 | + 'name' => __('Multiple Choice', 'invoicing'), |
|
138 | 138 | 'defaults' => array( |
139 | - 'label' => __( 'Select one choice', 'invoicing' ), |
|
139 | + 'label' => __('Select one choice', 'invoicing'), |
|
140 | 140 | 'options' => array( |
141 | - esc_attr__( 'Choice One', 'invoicing' ), |
|
142 | - esc_attr__( 'Choice Two', 'invoicing' ), |
|
143 | - esc_attr__( 'Choice Three', 'invoicing' ) |
|
141 | + esc_attr__('Choice One', 'invoicing'), |
|
142 | + esc_attr__('Choice Two', 'invoicing'), |
|
143 | + esc_attr__('Choice Three', 'invoicing') |
|
144 | 144 | ), |
145 | 145 | ) |
146 | 146 | ), |
147 | 147 | |
148 | 148 | array( |
149 | 149 | 'type' => 'date', |
150 | - 'name' => __( 'Date', 'invoicing' ), |
|
150 | + 'name' => __('Date', 'invoicing'), |
|
151 | 151 | 'defaults' => array( |
152 | 152 | 'placeholder' => '', |
153 | 153 | 'value' => '', |
154 | - 'label' => __( 'Date', 'invoicing' ), |
|
154 | + 'label' => __('Date', 'invoicing'), |
|
155 | 155 | 'description' => '', |
156 | 156 | 'required' => false, |
157 | 157 | ) |
@@ -159,11 +159,11 @@ discard block |
||
159 | 159 | |
160 | 160 | array( |
161 | 161 | 'type' => 'time', |
162 | - 'name' => __( 'Time', 'invoicing' ), |
|
162 | + 'name' => __('Time', 'invoicing'), |
|
163 | 163 | 'defaults' => array( |
164 | 164 | 'placeholder' => '', |
165 | 165 | 'value' => '', |
166 | - 'label' => __( 'Time', 'invoicing' ), |
|
166 | + 'label' => __('Time', 'invoicing'), |
|
167 | 167 | 'description' => '', |
168 | 168 | 'required' => false, |
169 | 169 | ) |
@@ -171,11 +171,11 @@ discard block |
||
171 | 171 | |
172 | 172 | array( |
173 | 173 | 'type' => 'number', |
174 | - 'name' => __( 'Number', 'invoicing' ), |
|
174 | + 'name' => __('Number', 'invoicing'), |
|
175 | 175 | 'defaults' => array( |
176 | 176 | 'placeholder' => '', |
177 | 177 | 'value' => '', |
178 | - 'label' => __( 'Number', 'invoicing' ), |
|
178 | + 'label' => __('Number', 'invoicing'), |
|
179 | 179 | 'description' => '', |
180 | 180 | 'required' => false, |
181 | 181 | ) |
@@ -183,11 +183,11 @@ discard block |
||
183 | 183 | |
184 | 184 | array( |
185 | 185 | 'type' => 'website', |
186 | - 'name' => __( 'Website', 'invoicing' ), |
|
186 | + 'name' => __('Website', 'invoicing'), |
|
187 | 187 | 'defaults' => array( |
188 | 188 | 'placeholder' => 'http://example.com', |
189 | 189 | 'value' => '', |
190 | - 'label' => __( 'Website', 'invoicing' ), |
|
190 | + 'label' => __('Website', 'invoicing'), |
|
191 | 191 | 'description' => '', |
192 | 192 | 'required' => false, |
193 | 193 | ) |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | |
196 | 196 | array( |
197 | 197 | 'type' => 'email', |
198 | - 'name' => __( 'Email', 'invoicing' ), |
|
198 | + 'name' => __('Email', 'invoicing'), |
|
199 | 199 | 'defaults' => array( |
200 | 200 | 'placeholder' => '[email protected]', |
201 | 201 | 'value' => '', |
202 | - 'label' => __( 'Email Address', 'invoicing' ), |
|
202 | + 'label' => __('Email Address', 'invoicing'), |
|
203 | 203 | 'description' => '', |
204 | 204 | 'required' => false, |
205 | 205 | ) |
@@ -207,14 +207,14 @@ discard block |
||
207 | 207 | |
208 | 208 | array( |
209 | 209 | 'type' => 'address', |
210 | - 'name' => __( 'Address', 'invoicing' ), |
|
210 | + 'name' => __('Address', 'invoicing'), |
|
211 | 211 | 'defaults' => array( |
212 | 212 | |
213 | 213 | 'fields' => array( |
214 | 214 | array( |
215 | 215 | 'placeholder' => 'Jon', |
216 | 216 | 'value' => '', |
217 | - 'label' => __( 'First Name', 'invoicing' ), |
|
217 | + 'label' => __('First Name', 'invoicing'), |
|
218 | 218 | 'description' => '', |
219 | 219 | 'required' => false, |
220 | 220 | 'visible' => true, |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | array( |
225 | 225 | 'placeholder' => 'Snow', |
226 | 226 | 'value' => '', |
227 | - 'label' => __( 'Last Name', 'invoicing' ), |
|
227 | + 'label' => __('Last Name', 'invoicing'), |
|
228 | 228 | 'description' => '', |
229 | 229 | 'required' => false, |
230 | 230 | 'visible' => true, |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | array( |
235 | 235 | 'placeholder' => '', |
236 | 236 | 'value' => '', |
237 | - 'label' => __( 'Address', 'invoicing' ), |
|
237 | + 'label' => __('Address', 'invoicing'), |
|
238 | 238 | 'description' => '', |
239 | 239 | 'required' => false, |
240 | 240 | 'visible' => true, |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | array( |
245 | 245 | 'placeholder' => '', |
246 | 246 | 'value' => '', |
247 | - 'label' => __( 'City', 'invoicing' ), |
|
247 | + 'label' => __('City', 'invoicing'), |
|
248 | 248 | 'description' => '', |
249 | 249 | 'required' => false, |
250 | 250 | 'visible' => true, |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | array( |
255 | 255 | 'placeholder' => '', |
256 | 256 | 'value' => '', |
257 | - 'label' => __( 'Country', 'invoicing' ), |
|
257 | + 'label' => __('Country', 'invoicing'), |
|
258 | 258 | 'description' => '', |
259 | 259 | 'required' => false, |
260 | 260 | 'visible' => true, |
@@ -262,9 +262,9 @@ discard block |
||
262 | 262 | ), |
263 | 263 | |
264 | 264 | array( |
265 | - 'placeholder' => __( 'Choose a state', 'invoicing' ), |
|
265 | + 'placeholder' => __('Choose a state', 'invoicing'), |
|
266 | 266 | 'value' => '', |
267 | - 'label' => __( 'State / Province', 'invoicing' ), |
|
267 | + 'label' => __('State / Province', 'invoicing'), |
|
268 | 268 | 'description' => '', |
269 | 269 | 'required' => false, |
270 | 270 | 'visible' => true, |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | array( |
275 | 275 | 'placeholder' => '', |
276 | 276 | 'value' => '', |
277 | - 'label' => __( 'ZIP / Postcode', 'invoicing' ), |
|
277 | + 'label' => __('ZIP / Postcode', 'invoicing'), |
|
278 | 278 | 'description' => '', |
279 | 279 | 'required' => false, |
280 | 280 | 'visible' => true, |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | array( |
285 | 285 | 'placeholder' => '', |
286 | 286 | 'value' => '', |
287 | - 'label' => __( 'Phone', 'invoicing' ), |
|
287 | + 'label' => __('Phone', 'invoicing'), |
|
288 | 288 | 'description' => '', |
289 | 289 | 'required' => false, |
290 | 290 | 'visible' => true, |
@@ -296,11 +296,11 @@ discard block |
||
296 | 296 | |
297 | 297 | array( |
298 | 298 | 'type' => 'billing_email', |
299 | - 'name' => __( 'Billing Email', 'invoicing' ), |
|
299 | + 'name' => __('Billing Email', 'invoicing'), |
|
300 | 300 | 'defaults' => array( |
301 | 301 | 'placeholder' => '[email protected]', |
302 | 302 | 'value' => '', |
303 | - 'label' => __( 'Billing Email', 'invoicing' ), |
|
303 | + 'label' => __('Billing Email', 'invoicing'), |
|
304 | 304 | 'description' => '', |
305 | 305 | 'premade' => true, |
306 | 306 | ) |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | |
320 | 320 | array( |
321 | 321 | 'type' => 'items', |
322 | - 'name' => __( 'Items', 'invoicing' ), |
|
322 | + 'name' => __('Items', 'invoicing'), |
|
323 | 323 | 'defaults' => array( |
324 | 324 | 'value' => '', |
325 | 325 | 'items_type' => 'total', |
@@ -330,25 +330,25 @@ discard block |
||
330 | 330 | |
331 | 331 | array( |
332 | 332 | 'type' => 'pay_button', |
333 | - 'name' => __( 'Payment Button', 'invoicing' ), |
|
333 | + 'name' => __('Payment Button', 'invoicing'), |
|
334 | 334 | 'defaults' => array( |
335 | 335 | 'value' => '', |
336 | 336 | 'class' => 'btn-primary', |
337 | - 'label' => __( 'Pay Now »', 'invoicing' ), |
|
338 | - 'description' => __( 'By continuing with our payment, you are agreeing to our privacy policy and terms of service.', 'invoicing' ), |
|
337 | + 'label' => __('Pay Now »', 'invoicing'), |
|
338 | + 'description' => __('By continuing with our payment, you are agreeing to our privacy policy and terms of service.', 'invoicing'), |
|
339 | 339 | 'premade' => true, |
340 | 340 | ) |
341 | 341 | ) |
342 | 342 | ); |
343 | 343 | |
344 | - $this->elements = apply_filters( 'wpinv_filter_core_payment_form_elements', $this->elements ); |
|
344 | + $this->elements = apply_filters('wpinv_filter_core_payment_form_elements', $this->elements); |
|
345 | 345 | return $this->elements; |
346 | 346 | } |
347 | 347 | |
348 | 348 | /** |
349 | 349 | * Returns the restrict markup. |
350 | 350 | */ |
351 | - public function get_restrict_markup( $field, $field_type ) { |
|
351 | + public function get_restrict_markup($field, $field_type) { |
|
352 | 352 | $restrict = "$field.type=='$field_type'"; |
353 | 353 | return "v-if=\"$restrict\""; |
354 | 354 | } |
@@ -356,15 +356,15 @@ discard block |
||
356 | 356 | /** |
357 | 357 | * Renders the title element template. |
358 | 358 | */ |
359 | - public function render_heading_template( $field ) { |
|
360 | - $restrict = $this->get_restrict_markup( $field, 'heading' ); |
|
359 | + public function render_heading_template($field) { |
|
360 | + $restrict = $this->get_restrict_markup($field, 'heading'); |
|
361 | 361 | echo "<component :is='$field.level' $restrict v-html='$field.text'></component>"; |
362 | 362 | } |
363 | 363 | |
364 | 364 | /** |
365 | 365 | * Renders the title element on the frontend. |
366 | 366 | */ |
367 | - public function frontend_render_heading_template( $field ) { |
|
367 | + public function frontend_render_heading_template($field) { |
|
368 | 368 | $tag = $field['level']; |
369 | 369 | echo "<$tag>{$field['text']}</$tag>"; |
370 | 370 | } |
@@ -372,10 +372,10 @@ discard block |
||
372 | 372 | /** |
373 | 373 | * Renders the edit title element template. |
374 | 374 | */ |
375 | - public function edit_heading_template( $field ) { |
|
376 | - $restrict = $this->get_restrict_markup( $field, 'heading' ); |
|
377 | - $label = __( 'Heading', 'invoicing' ); |
|
378 | - $label2 = __( 'Select Heading Level', 'invoicing' ); |
|
375 | + public function edit_heading_template($field) { |
|
376 | + $restrict = $this->get_restrict_markup($field, 'heading'); |
|
377 | + $label = __('Heading', 'invoicing'); |
|
378 | + $label2 = __('Select Heading Level', 'invoicing'); |
|
379 | 379 | $id = $field . '.id + "_edit"'; |
380 | 380 | $id2 = $field . '.id + "_edit2"'; |
381 | 381 | |
@@ -407,8 +407,8 @@ discard block |
||
407 | 407 | /** |
408 | 408 | * Renders a paragraph element template. |
409 | 409 | */ |
410 | - public function render_paragraph_template( $field ) { |
|
411 | - $restrict = $this->get_restrict_markup( $field, 'paragraph' ); |
|
410 | + public function render_paragraph_template($field) { |
|
411 | + $restrict = $this->get_restrict_markup($field, 'paragraph'); |
|
412 | 412 | $label = "$field.text"; |
413 | 413 | echo "<p $restrict v-html='$label' style='font-size: 16px;'></p>"; |
414 | 414 | } |
@@ -416,16 +416,16 @@ discard block |
||
416 | 416 | /** |
417 | 417 | * Renders the paragraph element on the frontend. |
418 | 418 | */ |
419 | - public function frontend_render_paragraph_template( $field ) { |
|
419 | + public function frontend_render_paragraph_template($field) { |
|
420 | 420 | echo "<p>{$field['text']}</p>"; |
421 | 421 | } |
422 | 422 | |
423 | 423 | /** |
424 | 424 | * Renders the edit paragraph element template. |
425 | 425 | */ |
426 | - public function edit_paragraph_template( $field ) { |
|
427 | - $restrict = $this->get_restrict_markup( $field, 'paragraph' ); |
|
428 | - $label = __( 'Enter your text', 'invoicing' ); |
|
426 | + public function edit_paragraph_template($field) { |
|
427 | + $restrict = $this->get_restrict_markup($field, 'paragraph'); |
|
428 | + $label = __('Enter your text', 'invoicing'); |
|
429 | 429 | $id = $field . '.id + "_edit"'; |
430 | 430 | echo " |
431 | 431 | <div $restrict> |
@@ -441,8 +441,8 @@ discard block |
||
441 | 441 | /** |
442 | 442 | * Renders the text element template. |
443 | 443 | */ |
444 | - public function render_text_template( $field ) { |
|
445 | - $restrict = $this->get_restrict_markup( $field, 'text' ); |
|
444 | + public function render_text_template($field) { |
|
445 | + $restrict = $this->get_restrict_markup($field, 'text'); |
|
446 | 446 | $label = "$field.label"; |
447 | 447 | echo " |
448 | 448 | <div $restrict> |
@@ -456,23 +456,23 @@ discard block |
||
456 | 456 | /** |
457 | 457 | * Renders the text element on the frontend. |
458 | 458 | */ |
459 | - public function frontend_render_text_template( $field ) { |
|
459 | + public function frontend_render_text_template($field) { |
|
460 | 460 | |
461 | 461 | echo "<div class='form-group'>"; |
462 | 462 | |
463 | 463 | echo aui()->input( |
464 | 464 | array( |
465 | - 'name' => esc_attr( $field['id'] ), |
|
466 | - 'id' => esc_attr( $field['id'] ), |
|
467 | - 'placeholder'=> esc_attr( $field['placeholder'] ), |
|
465 | + 'name' => esc_attr($field['id']), |
|
466 | + 'id' => esc_attr($field['id']), |
|
467 | + 'placeholder'=> esc_attr($field['placeholder']), |
|
468 | 468 | 'required' => (bool) $field['required'], |
469 | - 'label' => wp_kses_post( $field['label'] ), |
|
469 | + 'label' => wp_kses_post($field['label']), |
|
470 | 470 | 'no_wrap' => true, |
471 | 471 | ) |
472 | 472 | ); |
473 | 473 | |
474 | - if ( ! empty( $field['description'] ) ) { |
|
475 | - $description = wp_kses_post( $field['description'] ); |
|
474 | + if (!empty($field['description'])) { |
|
475 | + $description = wp_kses_post($field['description']); |
|
476 | 476 | echo "<small class='form-text text-muted'>$description</small>"; |
477 | 477 | } |
478 | 478 | |
@@ -483,16 +483,16 @@ discard block |
||
483 | 483 | /** |
484 | 484 | * Renders the edit text element template. |
485 | 485 | */ |
486 | - public function edit_text_template( $field ) { |
|
487 | - $restrict = $this->get_restrict_markup( $field, 'text' ); |
|
488 | - $label = __( 'Field Label', 'invoicing' ); |
|
486 | + public function edit_text_template($field) { |
|
487 | + $restrict = $this->get_restrict_markup($field, 'text'); |
|
488 | + $label = __('Field Label', 'invoicing'); |
|
489 | 489 | $id = $field . '.id + "_edit"'; |
490 | - $label2 = __( 'Placeholder text', 'invoicing' ); |
|
490 | + $label2 = __('Placeholder text', 'invoicing'); |
|
491 | 491 | $id2 = $field . '.id + "_edit2"'; |
492 | - $label3 = __( 'Help text', 'invoicing' ); |
|
493 | - $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
492 | + $label3 = __('Help text', 'invoicing'); |
|
493 | + $label4 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
494 | 494 | $id3 = $field . '.id + "_edit3"'; |
495 | - $label5 = __( 'Is this field required?', 'invoicing' ); |
|
495 | + $label5 = __('Is this field required?', 'invoicing'); |
|
496 | 496 | $id4 = $field . '.id + "_edit4"'; |
497 | 497 | echo " |
498 | 498 | <div $restrict> |
@@ -520,8 +520,8 @@ discard block |
||
520 | 520 | /** |
521 | 521 | * Renders the textarea element template. |
522 | 522 | */ |
523 | - public function render_textarea_template( $field ) { |
|
524 | - $restrict = $this->get_restrict_markup( $field, 'textarea' ); |
|
523 | + public function render_textarea_template($field) { |
|
524 | + $restrict = $this->get_restrict_markup($field, 'textarea'); |
|
525 | 525 | $label = "$field.label"; |
526 | 526 | echo " |
527 | 527 | <div $restrict> |
@@ -535,24 +535,24 @@ discard block |
||
535 | 535 | /** |
536 | 536 | * Renders the textarea element on the frontend. |
537 | 537 | */ |
538 | - public function frontend_render_textarea_template( $field ) { |
|
538 | + public function frontend_render_textarea_template($field) { |
|
539 | 539 | |
540 | 540 | echo "<div class='form-group'>"; |
541 | 541 | |
542 | 542 | echo aui()->textarea( |
543 | 543 | array( |
544 | - 'name' => esc_attr( $field['id'] ), |
|
545 | - 'id' => esc_attr( $field['id'] ), |
|
546 | - 'placeholder'=> esc_attr( $field['placeholder'] ), |
|
544 | + 'name' => esc_attr($field['id']), |
|
545 | + 'id' => esc_attr($field['id']), |
|
546 | + 'placeholder'=> esc_attr($field['placeholder']), |
|
547 | 547 | 'required' => (bool) $field['required'], |
548 | - 'label' => wp_kses_post( $field['label'] ), |
|
548 | + 'label' => wp_kses_post($field['label']), |
|
549 | 549 | 'no_wrap' => true, |
550 | 550 | 'rows' => 3, |
551 | 551 | ) |
552 | 552 | ); |
553 | 553 | |
554 | - if ( ! empty( $field['description'] ) ) { |
|
555 | - $description = wp_kses_post( $field['description'] ); |
|
554 | + if (!empty($field['description'])) { |
|
555 | + $description = wp_kses_post($field['description']); |
|
556 | 556 | echo "<small class='form-text text-muted'>$description</small>"; |
557 | 557 | } |
558 | 558 | |
@@ -563,16 +563,16 @@ discard block |
||
563 | 563 | /** |
564 | 564 | * Renders the edit textarea element template. |
565 | 565 | */ |
566 | - public function edit_textarea_template( $field ) { |
|
567 | - $restrict = $this->get_restrict_markup( $field, 'textarea' ); |
|
568 | - $label = __( 'Field Label', 'invoicing' ); |
|
566 | + public function edit_textarea_template($field) { |
|
567 | + $restrict = $this->get_restrict_markup($field, 'textarea'); |
|
568 | + $label = __('Field Label', 'invoicing'); |
|
569 | 569 | $id = $field . '.id + "_edit"'; |
570 | - $label2 = __( 'Placeholder text', 'invoicing' ); |
|
570 | + $label2 = __('Placeholder text', 'invoicing'); |
|
571 | 571 | $id2 = $field . '.id + "_edit2"'; |
572 | - $label3 = __( 'Help text', 'invoicing' ); |
|
573 | - $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
572 | + $label3 = __('Help text', 'invoicing'); |
|
573 | + $label4 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
574 | 574 | $id3 = $field . '.id + "_edit3"'; |
575 | - $label5 = __( 'Is this field required?', 'invoicing' ); |
|
575 | + $label5 = __('Is this field required?', 'invoicing'); |
|
576 | 576 | $id4 = $field . '.id + "_edit4"'; |
577 | 577 | echo " |
578 | 578 | <div $restrict> |
@@ -600,8 +600,8 @@ discard block |
||
600 | 600 | /** |
601 | 601 | * Renders the select element template. |
602 | 602 | */ |
603 | - public function render_select_template( $field ) { |
|
604 | - $restrict = $this->get_restrict_markup( $field, 'select' ); |
|
603 | + public function render_select_template($field) { |
|
604 | + $restrict = $this->get_restrict_markup($field, 'select'); |
|
605 | 605 | $label = "$field.label"; |
606 | 606 | $placeholder = "$field.placeholder"; |
607 | 607 | $id = $field . '.id'; |
@@ -620,24 +620,24 @@ discard block |
||
620 | 620 | /** |
621 | 621 | * Renders the select element on the frontend. |
622 | 622 | */ |
623 | - public function frontend_render_select_template( $field ) { |
|
623 | + public function frontend_render_select_template($field) { |
|
624 | 624 | |
625 | 625 | echo "<div class='form-group'>"; |
626 | 626 | |
627 | 627 | echo aui()->select( |
628 | 628 | array( |
629 | - 'name' => esc_attr( $field['id'] ), |
|
630 | - 'id' => esc_attr( $field['id'] ), |
|
631 | - 'placeholder'=> esc_attr( $field['placeholder'] ), |
|
629 | + 'name' => esc_attr($field['id']), |
|
630 | + 'id' => esc_attr($field['id']), |
|
631 | + 'placeholder'=> esc_attr($field['placeholder']), |
|
632 | 632 | 'required' => (bool) $field['required'], |
633 | - 'label' => wp_kses_post( $field['label'] ), |
|
633 | + 'label' => wp_kses_post($field['label']), |
|
634 | 634 | 'no_wrap' => true, |
635 | - 'options' => array_combine( $field['options'], $field['options'] ), |
|
635 | + 'options' => array_combine($field['options'], $field['options']), |
|
636 | 636 | ) |
637 | 637 | ); |
638 | 638 | |
639 | - if ( ! empty( $field['description'] ) ) { |
|
640 | - $description = wp_kses_post( $field['description'] ); |
|
639 | + if (!empty($field['description'])) { |
|
640 | + $description = wp_kses_post($field['description']); |
|
641 | 641 | echo "<small class='form-text text-muted'>$description</small>"; |
642 | 642 | } |
643 | 643 | |
@@ -648,18 +648,18 @@ discard block |
||
648 | 648 | /** |
649 | 649 | * Renders the edit select element template. |
650 | 650 | */ |
651 | - public function edit_select_template( $field ) { |
|
652 | - $restrict = $this->get_restrict_markup( $field, 'select' ); |
|
653 | - $label = __( 'Field Label', 'invoicing' ); |
|
651 | + public function edit_select_template($field) { |
|
652 | + $restrict = $this->get_restrict_markup($field, 'select'); |
|
653 | + $label = __('Field Label', 'invoicing'); |
|
654 | 654 | $id = $field . '.id + "_edit"'; |
655 | - $label2 = __( 'Placeholder text', 'invoicing' ); |
|
655 | + $label2 = __('Placeholder text', 'invoicing'); |
|
656 | 656 | $id2 = $field . '.id + "_edit2"'; |
657 | - $label3 = __( 'Help text', 'invoicing' ); |
|
658 | - $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
657 | + $label3 = __('Help text', 'invoicing'); |
|
658 | + $label4 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
659 | 659 | $id3 = $field . '.id + "_edit3"'; |
660 | - $label5 = __( 'Is this field required?', 'invoicing' ); |
|
660 | + $label5 = __('Is this field required?', 'invoicing'); |
|
661 | 661 | $id4 = $field . '.id + "_edit4"'; |
662 | - $label6 = __( 'Available Options', 'invoicing' ); |
|
662 | + $label6 = __('Available Options', 'invoicing'); |
|
663 | 663 | echo " |
664 | 664 | <div $restrict> |
665 | 665 | <div class='form-group'> |
@@ -697,8 +697,8 @@ discard block |
||
697 | 697 | /** |
698 | 698 | * Renders the checkbox element template. |
699 | 699 | */ |
700 | - public function render_checkbox_template( $field ) { |
|
701 | - $restrict = $this->get_restrict_markup( $field, 'checkbox' ); |
|
700 | + public function render_checkbox_template($field) { |
|
701 | + $restrict = $this->get_restrict_markup($field, 'checkbox'); |
|
702 | 702 | $label = "$field.label"; |
703 | 703 | echo " |
704 | 704 | <div class='form-check' $restrict> |
@@ -712,24 +712,24 @@ discard block |
||
712 | 712 | /** |
713 | 713 | * Renders the checkbox element on the frontend. |
714 | 714 | */ |
715 | - public function frontend_render_checkbox_template( $field ) { |
|
715 | + public function frontend_render_checkbox_template($field) { |
|
716 | 716 | |
717 | 717 | echo "<div class='form-group'>"; |
718 | 718 | |
719 | 719 | echo aui()->input( |
720 | 720 | array( |
721 | - 'name' => esc_attr( $field['id'] ), |
|
722 | - 'id' => esc_attr( $field['id'] ), |
|
721 | + 'name' => esc_attr($field['id']), |
|
722 | + 'id' => esc_attr($field['id']), |
|
723 | 723 | 'required' => (bool) $field['required'], |
724 | - 'label' => wp_kses_post( $field['label'] ), |
|
724 | + 'label' => wp_kses_post($field['label']), |
|
725 | 725 | 'no_wrap' => true, |
726 | - 'value' => esc_attr__( 'Yes', 'invoicing' ), |
|
726 | + 'value' => esc_attr__('Yes', 'invoicing'), |
|
727 | 727 | 'type' => 'checkbox', |
728 | 728 | ) |
729 | 729 | ); |
730 | 730 | |
731 | - if ( ! empty( $field['description'] ) ) { |
|
732 | - $description = wp_kses_post( $field['description'] ); |
|
731 | + if (!empty($field['description'])) { |
|
732 | + $description = wp_kses_post($field['description']); |
|
733 | 733 | echo "<small class='form-text text-muted'>$description</small>"; |
734 | 734 | } |
735 | 735 | |
@@ -740,14 +740,14 @@ discard block |
||
740 | 740 | /** |
741 | 741 | * Renders the edit checkbox element template. |
742 | 742 | */ |
743 | - public function edit_checkbox_template( $field ) { |
|
744 | - $restrict = $this->get_restrict_markup( $field, 'checkbox' ); |
|
745 | - $label = __( 'Field Label', 'invoicing' ); |
|
743 | + public function edit_checkbox_template($field) { |
|
744 | + $restrict = $this->get_restrict_markup($field, 'checkbox'); |
|
745 | + $label = __('Field Label', 'invoicing'); |
|
746 | 746 | $id = $field . '.id + "_edit"'; |
747 | - $label2 = __( 'Help text', 'invoicing' ); |
|
748 | - $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
747 | + $label2 = __('Help text', 'invoicing'); |
|
748 | + $label3 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
749 | 749 | $id2 = $field . '.id + "_edit2"'; |
750 | - $label4 = __( 'Is this field required?', 'invoicing' ); |
|
750 | + $label4 = __('Is this field required?', 'invoicing'); |
|
751 | 751 | $id3 = $field . '.id + "_edit3"'; |
752 | 752 | echo " |
753 | 753 | <div $restrict> |
@@ -771,8 +771,8 @@ discard block |
||
771 | 771 | /** |
772 | 772 | * Renders the radio element template. |
773 | 773 | */ |
774 | - public function render_radio_template( $field ) { |
|
775 | - $restrict = $this->get_restrict_markup( $field, 'radio' ); |
|
774 | + public function render_radio_template($field) { |
|
775 | + $restrict = $this->get_restrict_markup($field, 'radio'); |
|
776 | 776 | $label = "$field.label"; |
777 | 777 | $id = $field . '.id'; |
778 | 778 | echo " |
@@ -790,20 +790,20 @@ discard block |
||
790 | 790 | /** |
791 | 791 | * Renders the radio element on the frontend. |
792 | 792 | */ |
793 | - public function frontend_render_radio_template( $field ) { |
|
793 | + public function frontend_render_radio_template($field) { |
|
794 | 794 | |
795 | 795 | echo "<div class='form-group'>"; |
796 | 796 | |
797 | - if ( ! empty( $field['label'] ) ) { |
|
798 | - $label = wp_kses_post( $field['label'] ); |
|
797 | + if (!empty($field['label'])) { |
|
798 | + $label = wp_kses_post($field['label']); |
|
799 | 799 | echo "<legend class='col-form-label'>$label</legend>"; |
800 | 800 | } |
801 | 801 | |
802 | - foreach( $field['options'] as $index => $option ) { |
|
802 | + foreach ($field['options'] as $index => $option) { |
|
803 | 803 | $id = $field['id'] . $index; |
804 | 804 | $name = $field['id']; |
805 | - $value = esc_attr( $option ); |
|
806 | - $label = wp_kses_post( $option ); |
|
805 | + $value = esc_attr($option); |
|
806 | + $label = wp_kses_post($option); |
|
807 | 807 | |
808 | 808 | echo " |
809 | 809 | <div class='form-check'> |
@@ -813,8 +813,8 @@ discard block |
||
813 | 813 | "; |
814 | 814 | } |
815 | 815 | |
816 | - if ( ! empty( $field['description'] ) ) { |
|
817 | - $description = wp_kses_post( $field['description'] ); |
|
816 | + if (!empty($field['description'])) { |
|
817 | + $description = wp_kses_post($field['description']); |
|
818 | 818 | echo "<small class='form-text text-muted'>$description</small>"; |
819 | 819 | } |
820 | 820 | |
@@ -825,16 +825,16 @@ discard block |
||
825 | 825 | /** |
826 | 826 | * Renders the edit radio element template. |
827 | 827 | */ |
828 | - public function edit_radio_template( $field ) { |
|
829 | - $restrict = $this->get_restrict_markup( $field, 'radio' ); |
|
830 | - $label = __( 'Field Label', 'invoicing' ); |
|
828 | + public function edit_radio_template($field) { |
|
829 | + $restrict = $this->get_restrict_markup($field, 'radio'); |
|
830 | + $label = __('Field Label', 'invoicing'); |
|
831 | 831 | $id = $field . '.id + "_edit"'; |
832 | - $label2 = __( 'Help text', 'invoicing' ); |
|
833 | - $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
832 | + $label2 = __('Help text', 'invoicing'); |
|
833 | + $label3 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
834 | 834 | $id2 = $field . '.id + "_edit3"'; |
835 | - $label4 = __( 'Is this field required?', 'invoicing' ); |
|
835 | + $label4 = __('Is this field required?', 'invoicing'); |
|
836 | 836 | $id3 = $field . '.id + "_edit4"'; |
837 | - $label5 = __( 'Available Options', 'invoicing' ); |
|
837 | + $label5 = __('Available Options', 'invoicing'); |
|
838 | 838 | echo " |
839 | 839 | <div $restrict> |
840 | 840 | <div class='form-group'> |
@@ -868,8 +868,8 @@ discard block |
||
868 | 868 | /** |
869 | 869 | * Renders the address element template. |
870 | 870 | */ |
871 | - public function render_address_template( $field ) { |
|
872 | - $restrict = $this->get_restrict_markup( $field, 'address' ); |
|
871 | + public function render_address_template($field) { |
|
872 | + $restrict = $this->get_restrict_markup($field, 'address'); |
|
873 | 873 | |
874 | 874 | echo " |
875 | 875 | <div class='wpinv-address-wrapper' $restrict> |
@@ -887,38 +887,38 @@ discard block |
||
887 | 887 | /** |
888 | 888 | * Renders the address element on the frontend. |
889 | 889 | */ |
890 | - public function frontend_render_address_template( $field ) { |
|
890 | + public function frontend_render_address_template($field) { |
|
891 | 891 | |
892 | 892 | echo "<div class='wpinv-address-fields'>"; |
893 | 893 | |
894 | - foreach( $field['fields'] as $address_field ) { |
|
894 | + foreach ($field['fields'] as $address_field) { |
|
895 | 895 | |
896 | - if ( empty( $address_field['visible'] ) ) { |
|
896 | + if (empty($address_field['visible'])) { |
|
897 | 897 | continue; |
898 | 898 | } |
899 | 899 | |
900 | - $class = esc_attr( $address_field['name'] ); |
|
900 | + $class = esc_attr($address_field['name']); |
|
901 | 901 | echo "<div class='form-group $class'>"; |
902 | 902 | |
903 | 903 | $label = $address_field['label']; |
904 | 904 | |
905 | - if ( ! empty( $address_field['required'] ) ) { |
|
905 | + if (!empty($address_field['required'])) { |
|
906 | 906 | $label .= "<span class='text-danger'> *</span>"; |
907 | 907 | } |
908 | 908 | echo aui()->input( |
909 | 909 | array( |
910 | - 'name' => esc_attr( $address_field['name'] ), |
|
911 | - 'id' => esc_attr( $address_field['name'] ), |
|
910 | + 'name' => esc_attr($address_field['name']), |
|
911 | + 'id' => esc_attr($address_field['name']), |
|
912 | 912 | 'required' => (bool) $address_field['required'], |
913 | - 'label' => wp_kses_post( $label ), |
|
913 | + 'label' => wp_kses_post($label), |
|
914 | 914 | 'no_wrap' => true, |
915 | - 'placeholder' => esc_attr( $address_field['placeholder'] ), |
|
915 | + 'placeholder' => esc_attr($address_field['placeholder']), |
|
916 | 916 | 'type' => 'text', |
917 | 917 | ) |
918 | 918 | ); |
919 | 919 | |
920 | - if ( ! empty( $address_field['description'] ) ) { |
|
921 | - $description = wp_kses_post( $address_field['description'] ); |
|
920 | + if (!empty($address_field['description'])) { |
|
921 | + $description = wp_kses_post($address_field['description']); |
|
922 | 922 | echo "<small class='form-text text-muted'>$description</small>"; |
923 | 923 | } |
924 | 924 | |
@@ -933,13 +933,13 @@ discard block |
||
933 | 933 | /** |
934 | 934 | * Renders the edit address element template. |
935 | 935 | */ |
936 | - public function edit_address_template( $field ) { |
|
937 | - $restrict = $this->get_restrict_markup( $field, 'address' ); |
|
938 | - $label = __( 'Field Label', 'invoicing' ); |
|
939 | - $label2 = __( 'Placeholder', 'invoicing' ); |
|
940 | - $label3 = __( 'Description', 'invoicing' ); |
|
941 | - $label4 = __( 'Is required', 'invoicing' ); |
|
942 | - $label5 = __( 'Is visible', 'invoicing' ); |
|
936 | + public function edit_address_template($field) { |
|
937 | + $restrict = $this->get_restrict_markup($field, 'address'); |
|
938 | + $label = __('Field Label', 'invoicing'); |
|
939 | + $label2 = __('Placeholder', 'invoicing'); |
|
940 | + $label3 = __('Description', 'invoicing'); |
|
941 | + $label4 = __('Is required', 'invoicing'); |
|
942 | + $label5 = __('Is visible', 'invoicing'); |
|
943 | 943 | $id = $field . '.id + "_edit_label"'; |
944 | 944 | $id2 = $field . '.id + "_edit_placeholder"'; |
945 | 945 | $id3 = $field . '.id + "_edit_description"'; |
@@ -1007,8 +1007,8 @@ discard block |
||
1007 | 1007 | /** |
1008 | 1008 | * Renders the email element template. |
1009 | 1009 | */ |
1010 | - public function render_email_template( $field ) { |
|
1011 | - $restrict = $this->get_restrict_markup( $field, 'email' ); |
|
1010 | + public function render_email_template($field) { |
|
1011 | + $restrict = $this->get_restrict_markup($field, 'email'); |
|
1012 | 1012 | $label = "$field.label"; |
1013 | 1013 | echo " |
1014 | 1014 | <div $restrict> |
@@ -1022,8 +1022,8 @@ discard block |
||
1022 | 1022 | /** |
1023 | 1023 | * Renders the billing_email element template. |
1024 | 1024 | */ |
1025 | - public function render_billing_email_template( $field ) { |
|
1026 | - $restrict = $this->get_restrict_markup( $field, 'billing_email' ); |
|
1025 | + public function render_billing_email_template($field) { |
|
1026 | + $restrict = $this->get_restrict_markup($field, 'billing_email'); |
|
1027 | 1027 | $label = "$field.label"; |
1028 | 1028 | echo " |
1029 | 1029 | <div $restrict> |
@@ -1037,24 +1037,24 @@ discard block |
||
1037 | 1037 | /** |
1038 | 1038 | * Renders the email element on the frontend. |
1039 | 1039 | */ |
1040 | - public function frontend_render_email_template( $field ) { |
|
1040 | + public function frontend_render_email_template($field) { |
|
1041 | 1041 | |
1042 | 1042 | echo "<div class='form-group'>"; |
1043 | 1043 | |
1044 | 1044 | echo aui()->input( |
1045 | 1045 | array( |
1046 | - 'name' => esc_attr( $field['id'] ), |
|
1047 | - 'id' => esc_attr( $field['id'] ), |
|
1046 | + 'name' => esc_attr($field['id']), |
|
1047 | + 'id' => esc_attr($field['id']), |
|
1048 | 1048 | 'required' => (bool) $field['required'], |
1049 | - 'label' => wp_kses_post( $field['label'] ), |
|
1049 | + 'label' => wp_kses_post($field['label']), |
|
1050 | 1050 | 'no_wrap' => true, |
1051 | - 'placeholder' => esc_attr( $field['placeholder'] ), |
|
1051 | + 'placeholder' => esc_attr($field['placeholder']), |
|
1052 | 1052 | 'type' => 'email', |
1053 | 1053 | ) |
1054 | 1054 | ); |
1055 | 1055 | |
1056 | - if ( ! empty( $field['description'] ) ) { |
|
1057 | - $description = wp_kses_post( $field['description'] ); |
|
1056 | + if (!empty($field['description'])) { |
|
1057 | + $description = wp_kses_post($field['description']); |
|
1058 | 1058 | echo "<small class='form-text text-muted'>$description</small>"; |
1059 | 1059 | } |
1060 | 1060 | |
@@ -1065,30 +1065,30 @@ discard block |
||
1065 | 1065 | /** |
1066 | 1066 | * Renders the billing email element on the frontend. |
1067 | 1067 | */ |
1068 | - public function frontend_render_billing_email_template( $field ) { |
|
1068 | + public function frontend_render_billing_email_template($field) { |
|
1069 | 1069 | |
1070 | 1070 | echo "<div class='form-group'>"; |
1071 | 1071 | $value = ''; |
1072 | 1072 | |
1073 | - if ( is_user_logged_in() ) { |
|
1073 | + if (is_user_logged_in()) { |
|
1074 | 1074 | $user = wp_get_current_user(); |
1075 | - $value = sanitize_email( $user->user_email ); |
|
1075 | + $value = sanitize_email($user->user_email); |
|
1076 | 1076 | } |
1077 | 1077 | echo aui()->input( |
1078 | 1078 | array( |
1079 | 1079 | 'name' => 'billing_email', |
1080 | 1080 | 'value' => $value, |
1081 | - 'id' => esc_attr( $field['id'] ), |
|
1081 | + 'id' => esc_attr($field['id']), |
|
1082 | 1082 | 'required' => true, |
1083 | - 'label' => wp_kses_post( $field['label'] ), |
|
1083 | + 'label' => wp_kses_post($field['label']), |
|
1084 | 1084 | 'no_wrap' => true, |
1085 | - 'placeholder' => esc_attr( $field['placeholder'] ), |
|
1085 | + 'placeholder' => esc_attr($field['placeholder']), |
|
1086 | 1086 | 'type' => 'email', |
1087 | 1087 | ) |
1088 | 1088 | ); |
1089 | 1089 | |
1090 | - if ( ! empty( $field['description'] ) ) { |
|
1091 | - $description = wp_kses_post( $field['description'] ); |
|
1090 | + if (!empty($field['description'])) { |
|
1091 | + $description = wp_kses_post($field['description']); |
|
1092 | 1092 | echo "<small class='form-text text-muted'>$description</small>"; |
1093 | 1093 | } |
1094 | 1094 | |
@@ -1099,16 +1099,16 @@ discard block |
||
1099 | 1099 | /** |
1100 | 1100 | * Renders the edit email element template. |
1101 | 1101 | */ |
1102 | - public function edit_email_template( $field ) { |
|
1103 | - $restrict = $this->get_restrict_markup( $field, 'email' ); |
|
1104 | - $label = __( 'Field Label', 'invoicing' ); |
|
1102 | + public function edit_email_template($field) { |
|
1103 | + $restrict = $this->get_restrict_markup($field, 'email'); |
|
1104 | + $label = __('Field Label', 'invoicing'); |
|
1105 | 1105 | $id = $field . '.id + "_edit"'; |
1106 | - $label2 = __( 'Placeholder text', 'invoicing' ); |
|
1106 | + $label2 = __('Placeholder text', 'invoicing'); |
|
1107 | 1107 | $id2 = $field . '.id + "_edit2"'; |
1108 | - $label3 = __( 'Help text', 'invoicing' ); |
|
1109 | - $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
1108 | + $label3 = __('Help text', 'invoicing'); |
|
1109 | + $label4 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
1110 | 1110 | $id3 = $field . '.id + "_edit3"'; |
1111 | - $label5 = __( 'Is this field required?', 'invoicing' ); |
|
1111 | + $label5 = __('Is this field required?', 'invoicing'); |
|
1112 | 1112 | $id4 = $field . '.id + "_edit4"'; |
1113 | 1113 | echo " |
1114 | 1114 | <div $restrict> |
@@ -1136,16 +1136,16 @@ discard block |
||
1136 | 1136 | /** |
1137 | 1137 | * Renders the edit billing_email element template. |
1138 | 1138 | */ |
1139 | - public function edit_billing_email_template( $field ) { |
|
1140 | - $restrict = $this->get_restrict_markup( $field, 'billing_email' ); |
|
1141 | - $label = __( 'Field Label', 'invoicing' ); |
|
1139 | + public function edit_billing_email_template($field) { |
|
1140 | + $restrict = $this->get_restrict_markup($field, 'billing_email'); |
|
1141 | + $label = __('Field Label', 'invoicing'); |
|
1142 | 1142 | $id = $field . '.id + "_edit"'; |
1143 | - $label2 = __( 'Placeholder text', 'invoicing' ); |
|
1143 | + $label2 = __('Placeholder text', 'invoicing'); |
|
1144 | 1144 | $id2 = $field . '.id + "_edit2"'; |
1145 | - $label3 = __( 'Help text', 'invoicing' ); |
|
1146 | - $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
1145 | + $label3 = __('Help text', 'invoicing'); |
|
1146 | + $label4 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
1147 | 1147 | $id3 = $field . '.id + "_edit3"'; |
1148 | - $label5 = __( 'Is this field required?', 'invoicing' ); |
|
1148 | + $label5 = __('Is this field required?', 'invoicing'); |
|
1149 | 1149 | $id4 = $field . '.id + "_edit4"'; |
1150 | 1150 | echo " |
1151 | 1151 | <div $restrict> |
@@ -1169,8 +1169,8 @@ discard block |
||
1169 | 1169 | /** |
1170 | 1170 | * Renders the website element template. |
1171 | 1171 | */ |
1172 | - public function render_website_template( $field ) { |
|
1173 | - $restrict = $this->get_restrict_markup( $field, 'website' ); |
|
1172 | + public function render_website_template($field) { |
|
1173 | + $restrict = $this->get_restrict_markup($field, 'website'); |
|
1174 | 1174 | $label = "$field.label"; |
1175 | 1175 | echo " |
1176 | 1176 | <div $restrict> |
@@ -1184,24 +1184,24 @@ discard block |
||
1184 | 1184 | /** |
1185 | 1185 | * Renders the website element on the frontend. |
1186 | 1186 | */ |
1187 | - public function frontend_render_website_template( $field ) { |
|
1187 | + public function frontend_render_website_template($field) { |
|
1188 | 1188 | |
1189 | 1189 | echo "<div class='form-group'>"; |
1190 | 1190 | |
1191 | 1191 | echo aui()->input( |
1192 | 1192 | array( |
1193 | - 'name' => esc_attr( $field['id'] ), |
|
1194 | - 'id' => esc_attr( $field['id'] ), |
|
1193 | + 'name' => esc_attr($field['id']), |
|
1194 | + 'id' => esc_attr($field['id']), |
|
1195 | 1195 | 'required' => (bool) $field['required'], |
1196 | - 'label' => wp_kses_post( $field['label'] ), |
|
1196 | + 'label' => wp_kses_post($field['label']), |
|
1197 | 1197 | 'no_wrap' => true, |
1198 | - 'placeholder' => esc_attr( $field['placeholder'] ), |
|
1198 | + 'placeholder' => esc_attr($field['placeholder']), |
|
1199 | 1199 | 'type' => 'url', |
1200 | 1200 | ) |
1201 | 1201 | ); |
1202 | 1202 | |
1203 | - if ( ! empty( $field['description'] ) ) { |
|
1204 | - $description = wp_kses_post( $field['description'] ); |
|
1203 | + if (!empty($field['description'])) { |
|
1204 | + $description = wp_kses_post($field['description']); |
|
1205 | 1205 | echo "<small class='form-text text-muted'>$description</small>"; |
1206 | 1206 | } |
1207 | 1207 | |
@@ -1212,16 +1212,16 @@ discard block |
||
1212 | 1212 | /** |
1213 | 1213 | * Renders the edit website element template. |
1214 | 1214 | */ |
1215 | - public function edit_website_template( $field ) { |
|
1216 | - $restrict = $this->get_restrict_markup( $field, 'website' ); |
|
1217 | - $label = __( 'Field Label', 'invoicing' ); |
|
1215 | + public function edit_website_template($field) { |
|
1216 | + $restrict = $this->get_restrict_markup($field, 'website'); |
|
1217 | + $label = __('Field Label', 'invoicing'); |
|
1218 | 1218 | $id = $field . '.id + "_edit"'; |
1219 | - $label2 = __( 'Placeholder text', 'invoicing' ); |
|
1219 | + $label2 = __('Placeholder text', 'invoicing'); |
|
1220 | 1220 | $id2 = $field . '.id + "_edit2"'; |
1221 | - $label3 = __( 'Help text', 'invoicing' ); |
|
1222 | - $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
1221 | + $label3 = __('Help text', 'invoicing'); |
|
1222 | + $label4 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
1223 | 1223 | $id3 = $field . '.id + "_edit3"'; |
1224 | - $label5 = __( 'Is this field required?', 'invoicing' ); |
|
1224 | + $label5 = __('Is this field required?', 'invoicing'); |
|
1225 | 1225 | $id4 = $field . '.id + "_edit4"'; |
1226 | 1226 | echo " |
1227 | 1227 | <div $restrict> |
@@ -1249,8 +1249,8 @@ discard block |
||
1249 | 1249 | /** |
1250 | 1250 | * Renders the date element template. |
1251 | 1251 | */ |
1252 | - public function render_date_template( $field ) { |
|
1253 | - $restrict = $this->get_restrict_markup( $field, 'date' ); |
|
1252 | + public function render_date_template($field) { |
|
1253 | + $restrict = $this->get_restrict_markup($field, 'date'); |
|
1254 | 1254 | $label = "$field.label"; |
1255 | 1255 | echo " |
1256 | 1256 | <div $restrict> |
@@ -1264,24 +1264,24 @@ discard block |
||
1264 | 1264 | /** |
1265 | 1265 | * Renders the date element on the frontend. |
1266 | 1266 | */ |
1267 | - public function frontend_render_date_template( $field ) { |
|
1267 | + public function frontend_render_date_template($field) { |
|
1268 | 1268 | |
1269 | 1269 | echo "<div class='form-group'>"; |
1270 | 1270 | |
1271 | 1271 | echo aui()->input( |
1272 | 1272 | array( |
1273 | - 'name' => esc_attr( $field['id'] ), |
|
1274 | - 'id' => esc_attr( $field['id'] ), |
|
1273 | + 'name' => esc_attr($field['id']), |
|
1274 | + 'id' => esc_attr($field['id']), |
|
1275 | 1275 | 'required' => (bool) $field['required'], |
1276 | - 'label' => wp_kses_post( $field['label'] ), |
|
1277 | - 'placeholder' => esc_attr( $field['placeholder'] ), |
|
1276 | + 'label' => wp_kses_post($field['label']), |
|
1277 | + 'placeholder' => esc_attr($field['placeholder']), |
|
1278 | 1278 | 'no_wrap' => true, |
1279 | 1279 | 'type' => 'date', |
1280 | 1280 | ) |
1281 | 1281 | ); |
1282 | 1282 | |
1283 | - if ( ! empty( $field['description'] ) ) { |
|
1284 | - $description = wp_kses_post( $field['description'] ); |
|
1283 | + if (!empty($field['description'])) { |
|
1284 | + $description = wp_kses_post($field['description']); |
|
1285 | 1285 | echo "<small class='form-text text-muted'>$description</small>"; |
1286 | 1286 | } |
1287 | 1287 | |
@@ -1292,16 +1292,16 @@ discard block |
||
1292 | 1292 | /** |
1293 | 1293 | * Renders the edit date element template. |
1294 | 1294 | */ |
1295 | - public function edit_date_template( $field ) { |
|
1296 | - $restrict = $this->get_restrict_markup( $field, 'date' ); |
|
1297 | - $label = __( 'Field Label', 'invoicing' ); |
|
1295 | + public function edit_date_template($field) { |
|
1296 | + $restrict = $this->get_restrict_markup($field, 'date'); |
|
1297 | + $label = __('Field Label', 'invoicing'); |
|
1298 | 1298 | $id = $field . '.id + "_edit"'; |
1299 | - $label2 = __( 'Placeholder text', 'invoicing' ); |
|
1299 | + $label2 = __('Placeholder text', 'invoicing'); |
|
1300 | 1300 | $id2 = $field . '.id + "_edit2"'; |
1301 | - $label3 = __( 'Help text', 'invoicing' ); |
|
1302 | - $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
1301 | + $label3 = __('Help text', 'invoicing'); |
|
1302 | + $label4 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
1303 | 1303 | $id3 = $field . '.id + "_edit3"'; |
1304 | - $label5 = __( 'Is this field required?', 'invoicing' ); |
|
1304 | + $label5 = __('Is this field required?', 'invoicing'); |
|
1305 | 1305 | $id4 = $field . '.id + "_edit4"'; |
1306 | 1306 | echo " |
1307 | 1307 | <div $restrict> |
@@ -1329,8 +1329,8 @@ discard block |
||
1329 | 1329 | /** |
1330 | 1330 | * Renders the time element template. |
1331 | 1331 | */ |
1332 | - public function render_time_template( $field ) { |
|
1333 | - $restrict = $this->get_restrict_markup( $field, 'time' ); |
|
1332 | + public function render_time_template($field) { |
|
1333 | + $restrict = $this->get_restrict_markup($field, 'time'); |
|
1334 | 1334 | $label = "$field.label"; |
1335 | 1335 | echo " |
1336 | 1336 | <div $restrict> |
@@ -1344,24 +1344,24 @@ discard block |
||
1344 | 1344 | /** |
1345 | 1345 | * Renders the time element on the frontend. |
1346 | 1346 | */ |
1347 | - public function frontend_render_time_template( $field ) { |
|
1347 | + public function frontend_render_time_template($field) { |
|
1348 | 1348 | |
1349 | 1349 | echo "<div class='form-group'>"; |
1350 | 1350 | |
1351 | 1351 | echo aui()->input( |
1352 | 1352 | array( |
1353 | - 'name' => esc_attr( $field['id'] ), |
|
1354 | - 'id' => esc_attr( $field['id'] ), |
|
1353 | + 'name' => esc_attr($field['id']), |
|
1354 | + 'id' => esc_attr($field['id']), |
|
1355 | 1355 | 'required' => (bool) $field['required'], |
1356 | - 'label' => wp_kses_post( $field['label'] ), |
|
1356 | + 'label' => wp_kses_post($field['label']), |
|
1357 | 1357 | 'no_wrap' => true, |
1358 | - 'placeholder' => esc_attr( $field['placeholder'] ), |
|
1358 | + 'placeholder' => esc_attr($field['placeholder']), |
|
1359 | 1359 | 'type' => 'time', |
1360 | 1360 | ) |
1361 | 1361 | ); |
1362 | 1362 | |
1363 | - if ( ! empty( $field['description'] ) ) { |
|
1364 | - $description = wp_kses_post( $field['description'] ); |
|
1363 | + if (!empty($field['description'])) { |
|
1364 | + $description = wp_kses_post($field['description']); |
|
1365 | 1365 | echo "<small class='form-text text-muted'>$description</small>"; |
1366 | 1366 | } |
1367 | 1367 | |
@@ -1372,16 +1372,16 @@ discard block |
||
1372 | 1372 | /** |
1373 | 1373 | * Renders the edit time element template. |
1374 | 1374 | */ |
1375 | - public function edit_time_template( $field ) { |
|
1376 | - $restrict = $this->get_restrict_markup( $field, 'time' ); |
|
1377 | - $label = __( 'Field Label', 'invoicing' ); |
|
1375 | + public function edit_time_template($field) { |
|
1376 | + $restrict = $this->get_restrict_markup($field, 'time'); |
|
1377 | + $label = __('Field Label', 'invoicing'); |
|
1378 | 1378 | $id = $field . '.id + "_edit"'; |
1379 | - $label2 = __( 'Placeholder text', 'invoicing' ); |
|
1379 | + $label2 = __('Placeholder text', 'invoicing'); |
|
1380 | 1380 | $id2 = $field . '.id + "_edit2"'; |
1381 | - $label3 = __( 'Help text', 'invoicing' ); |
|
1382 | - $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
1381 | + $label3 = __('Help text', 'invoicing'); |
|
1382 | + $label4 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
1383 | 1383 | $id3 = $field . '.id + "_edit3"'; |
1384 | - $label5 = __( 'Is this field required?', 'invoicing' ); |
|
1384 | + $label5 = __('Is this field required?', 'invoicing'); |
|
1385 | 1385 | $id4 = $field . '.id + "_edit4"'; |
1386 | 1386 | echo " |
1387 | 1387 | <div $restrict> |
@@ -1409,8 +1409,8 @@ discard block |
||
1409 | 1409 | /** |
1410 | 1410 | * Renders the number element template. |
1411 | 1411 | */ |
1412 | - public function render_number_template( $field ) { |
|
1413 | - $restrict = $this->get_restrict_markup( $field, 'number' ); |
|
1412 | + public function render_number_template($field) { |
|
1413 | + $restrict = $this->get_restrict_markup($field, 'number'); |
|
1414 | 1414 | $label = "$field.label"; |
1415 | 1415 | echo " |
1416 | 1416 | <div $restrict> |
@@ -1424,24 +1424,24 @@ discard block |
||
1424 | 1424 | /** |
1425 | 1425 | * Renders the number element on the frontend. |
1426 | 1426 | */ |
1427 | - public function frontend_render_number_template( $field ) { |
|
1427 | + public function frontend_render_number_template($field) { |
|
1428 | 1428 | |
1429 | 1429 | echo "<div class='form-group'>"; |
1430 | 1430 | |
1431 | 1431 | echo aui()->input( |
1432 | 1432 | array( |
1433 | - 'name' => esc_attr( $field['id'] ), |
|
1434 | - 'id' => esc_attr( $field['id'] ), |
|
1433 | + 'name' => esc_attr($field['id']), |
|
1434 | + 'id' => esc_attr($field['id']), |
|
1435 | 1435 | 'required' => (bool) $field['required'], |
1436 | - 'label' => wp_kses_post( $field['label'] ), |
|
1437 | - 'placeholder' => esc_attr( $field['placeholder'] ), |
|
1436 | + 'label' => wp_kses_post($field['label']), |
|
1437 | + 'placeholder' => esc_attr($field['placeholder']), |
|
1438 | 1438 | 'no_wrap' => true, |
1439 | 1439 | 'type' => 'number', |
1440 | 1440 | ) |
1441 | 1441 | ); |
1442 | 1442 | |
1443 | - if ( ! empty( $field['description'] ) ) { |
|
1444 | - $description = wp_kses_post( $field['description'] ); |
|
1443 | + if (!empty($field['description'])) { |
|
1444 | + $description = wp_kses_post($field['description']); |
|
1445 | 1445 | echo "<small class='form-text text-muted'>$description</small>"; |
1446 | 1446 | } |
1447 | 1447 | |
@@ -1452,16 +1452,16 @@ discard block |
||
1452 | 1452 | /** |
1453 | 1453 | * Renders the edit number element template. |
1454 | 1454 | */ |
1455 | - public function edit_number_template( $field ) { |
|
1456 | - $restrict = $this->get_restrict_markup( $field, 'number' ); |
|
1457 | - $label = __( 'Field Label', 'invoicing' ); |
|
1455 | + public function edit_number_template($field) { |
|
1456 | + $restrict = $this->get_restrict_markup($field, 'number'); |
|
1457 | + $label = __('Field Label', 'invoicing'); |
|
1458 | 1458 | $id = $field . '.id + "_edit"'; |
1459 | - $label2 = __( 'Placeholder text', 'invoicing' ); |
|
1459 | + $label2 = __('Placeholder text', 'invoicing'); |
|
1460 | 1460 | $id2 = $field . '.id + "_edit2"'; |
1461 | - $label3 = __( 'Help text', 'invoicing' ); |
|
1462 | - $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
1461 | + $label3 = __('Help text', 'invoicing'); |
|
1462 | + $label4 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
1463 | 1463 | $id3 = $field . '.id + "_edit3"'; |
1464 | - $label5 = __( 'Is this field required?', 'invoicing' ); |
|
1464 | + $label5 = __('Is this field required?', 'invoicing'); |
|
1465 | 1465 | $id4 = $field . '.id + "_edit4"'; |
1466 | 1466 | echo " |
1467 | 1467 | <div $restrict> |
@@ -1489,23 +1489,23 @@ discard block |
||
1489 | 1489 | /** |
1490 | 1490 | * Renders the separator element template. |
1491 | 1491 | */ |
1492 | - public function render_separator_template( $field ) { |
|
1493 | - $restrict = $this->get_restrict_markup( $field, 'separator' ); |
|
1492 | + public function render_separator_template($field) { |
|
1493 | + $restrict = $this->get_restrict_markup($field, 'separator'); |
|
1494 | 1494 | echo "<hr class='featurette-divider mt-0 mb-2' $restrict>"; |
1495 | 1495 | } |
1496 | 1496 | |
1497 | 1497 | /** |
1498 | 1498 | * Renders the separator element on the frontend. |
1499 | 1499 | */ |
1500 | - public function frontend_render_separator_template( $field ) { |
|
1500 | + public function frontend_render_separator_template($field) { |
|
1501 | 1501 | echo '<hr class="featurette-divider mt-0 mb-2" />'; |
1502 | 1502 | } |
1503 | 1503 | |
1504 | 1504 | /** |
1505 | 1505 | * Renders the pay button element template. |
1506 | 1506 | */ |
1507 | - public function render_pay_button_template( $field ) { |
|
1508 | - $restrict = $this->get_restrict_markup( $field, 'pay_button' ); |
|
1507 | + public function render_pay_button_template($field) { |
|
1508 | + $restrict = $this->get_restrict_markup($field, 'pay_button'); |
|
1509 | 1509 | $label = "$field.label"; |
1510 | 1510 | echo " |
1511 | 1511 | <div $restrict> |
@@ -1518,28 +1518,28 @@ discard block |
||
1518 | 1518 | /** |
1519 | 1519 | * Renders the pay_button element on the frontend. |
1520 | 1520 | */ |
1521 | - public function frontend_render_pay_button_template( $field ) { |
|
1521 | + public function frontend_render_pay_button_template($field) { |
|
1522 | 1522 | |
1523 | 1523 | echo "<div class='mt-4 mb-4'>"; |
1524 | - do_action( 'wpinv_payment_mode_select' ); |
|
1524 | + do_action('wpinv_payment_mode_select'); |
|
1525 | 1525 | echo "</div>"; |
1526 | 1526 | |
1527 | 1527 | echo "<div class='form-group'>"; |
1528 | 1528 | |
1529 | - $class = 'wpinv-payment-form-submit btn btn-block submit-button ' . sanitize_html_class( $field['class'] ); |
|
1529 | + $class = 'wpinv-payment-form-submit btn btn-block submit-button ' . sanitize_html_class($field['class']); |
|
1530 | 1530 | echo aui()->input( |
1531 | 1531 | array( |
1532 | - 'name' => esc_attr( $field['id'] ), |
|
1533 | - 'id' => esc_attr( $field['id'] ), |
|
1534 | - 'value' => esc_attr( $field['label'] ), |
|
1532 | + 'name' => esc_attr($field['id']), |
|
1533 | + 'id' => esc_attr($field['id']), |
|
1534 | + 'value' => esc_attr($field['label']), |
|
1535 | 1535 | 'no_wrap' => true, |
1536 | 1536 | 'type' => 'submit', |
1537 | 1537 | 'class' => $class, |
1538 | 1538 | ) |
1539 | 1539 | ); |
1540 | 1540 | |
1541 | - if ( ! empty( $field['description'] ) ) { |
|
1542 | - $description = wp_kses_post( $field['description'] ); |
|
1541 | + if (!empty($field['description'])) { |
|
1542 | + $description = wp_kses_post($field['description']); |
|
1543 | 1543 | echo "<small class='form-text text-muted'>$description</small>"; |
1544 | 1544 | } |
1545 | 1545 | |
@@ -1550,14 +1550,14 @@ discard block |
||
1550 | 1550 | /** |
1551 | 1551 | * Renders the pay button element template. |
1552 | 1552 | */ |
1553 | - public function edit_pay_button_template( $field ) { |
|
1554 | - $restrict = $this->get_restrict_markup( $field, 'pay_button' ); |
|
1555 | - $label = __( 'Button Text', 'invoicing' ); |
|
1553 | + public function edit_pay_button_template($field) { |
|
1554 | + $restrict = $this->get_restrict_markup($field, 'pay_button'); |
|
1555 | + $label = __('Button Text', 'invoicing'); |
|
1556 | 1556 | $id = $field . '.id + "_edit"'; |
1557 | - $label2 = __( 'Help text', 'invoicing' ); |
|
1558 | - $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
1557 | + $label2 = __('Help text', 'invoicing'); |
|
1558 | + $label3 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
1559 | 1559 | $id2 = $field . '.id + "_edit2"'; |
1560 | - $label4 = esc_attr__( 'Button Type', 'invoicing' ); |
|
1560 | + $label4 = esc_attr__('Button Type', 'invoicing'); |
|
1561 | 1561 | $id3 = $field . '.id + "_edit3"'; |
1562 | 1562 | echo " |
1563 | 1563 | <div $restrict> |
@@ -1573,15 +1573,15 @@ discard block |
||
1573 | 1573 | <label :for='$id3'>$label4</label> |
1574 | 1574 | |
1575 | 1575 | <select class='form-control custom-select' :id='$id3' v-model='$field.class'> |
1576 | - <option value='btn-primary'>" . __( 'Primary', 'invoicing' ) ."</option> |
|
1577 | - <option value='btn-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option> |
|
1578 | - <option value='btn-success'>" . __( 'Success', 'invoicing' ) ."</option> |
|
1579 | - <option value='btn-danger'>" . __( 'Danger', 'invoicing' ) ."</option> |
|
1580 | - <option value='btn-warning'>" . __( 'Warning', 'invoicing' ) ."</option> |
|
1581 | - <option value='btn-info'>" . __( 'Info', 'invoicing' ) ."</option> |
|
1582 | - <option value='btn-light'>" . __( 'Light', 'invoicing' ) ."</option> |
|
1583 | - <option value='btn-dark'>" . __( 'Dark', 'invoicing' ) ."</option> |
|
1584 | - <option value='btn-link'>" . __( 'Link', 'invoicing' ) ."</option> |
|
1576 | + <option value='btn-primary'>" . __('Primary', 'invoicing') . "</option> |
|
1577 | + <option value='btn-secondary'>" . __('Secondary', 'invoicing') . "</option> |
|
1578 | + <option value='btn-success'>" . __('Success', 'invoicing') . "</option> |
|
1579 | + <option value='btn-danger'>" . __('Danger', 'invoicing') . "</option> |
|
1580 | + <option value='btn-warning'>" . __('Warning', 'invoicing') . "</option> |
|
1581 | + <option value='btn-info'>" . __('Info', 'invoicing') . "</option> |
|
1582 | + <option value='btn-light'>" . __('Light', 'invoicing') . "</option> |
|
1583 | + <option value='btn-dark'>" . __('Dark', 'invoicing') . "</option> |
|
1584 | + <option value='btn-link'>" . __('Link', 'invoicing') . "</option> |
|
1585 | 1585 | </select> |
1586 | 1586 | </div> |
1587 | 1587 | </div> |
@@ -1592,8 +1592,8 @@ discard block |
||
1592 | 1592 | /** |
1593 | 1593 | * Renders the alert element template. |
1594 | 1594 | */ |
1595 | - public function render_alert_template( $field ) { |
|
1596 | - $restrict = $this->get_restrict_markup( $field, 'alert' ); |
|
1595 | + public function render_alert_template($field) { |
|
1596 | + $restrict = $this->get_restrict_markup($field, 'alert'); |
|
1597 | 1597 | $text = "$field.text"; |
1598 | 1598 | echo " |
1599 | 1599 | <div $restrict class='alert' :class='$field.class' role='alert'> |
@@ -1608,15 +1608,15 @@ discard block |
||
1608 | 1608 | /** |
1609 | 1609 | * Renders the alert element on the frontend. |
1610 | 1610 | */ |
1611 | - public function frontend_render_alert_template( $field ) { |
|
1611 | + public function frontend_render_alert_template($field) { |
|
1612 | 1612 | |
1613 | 1613 | echo "<div class='form-group'>"; |
1614 | 1614 | |
1615 | 1615 | echo aui()->alert( |
1616 | 1616 | array( |
1617 | - 'content' => wp_kses_post( $field['text'] ), |
|
1617 | + 'content' => wp_kses_post($field['text']), |
|
1618 | 1618 | 'dismissible' => $field['dismissible'], |
1619 | - 'type' => str_replace( 'alert-', '', $field['class'] ), |
|
1619 | + 'type' => str_replace('alert-', '', $field['class']), |
|
1620 | 1620 | ) |
1621 | 1621 | ); |
1622 | 1622 | |
@@ -1627,14 +1627,14 @@ discard block |
||
1627 | 1627 | /** |
1628 | 1628 | * Renders the alert element template. |
1629 | 1629 | */ |
1630 | - public function edit_alert_template( $field ) { |
|
1631 | - $restrict = $this->get_restrict_markup( $field, 'alert' ); |
|
1632 | - $label = __( 'Alert Text', 'invoicing' ); |
|
1633 | - $label2 = esc_attr__( 'Enter your alert text here', 'invoicing' ); |
|
1630 | + public function edit_alert_template($field) { |
|
1631 | + $restrict = $this->get_restrict_markup($field, 'alert'); |
|
1632 | + $label = __('Alert Text', 'invoicing'); |
|
1633 | + $label2 = esc_attr__('Enter your alert text here', 'invoicing'); |
|
1634 | 1634 | $id = $field . '.id + "_edit"'; |
1635 | - $label3 = __( 'Is Dismissible?', 'invoicing' ); |
|
1635 | + $label3 = __('Is Dismissible?', 'invoicing'); |
|
1636 | 1636 | $id2 = $field . '.id + "_edit2"'; |
1637 | - $label4 = esc_attr__( 'Alert Type', 'invoicing' ); |
|
1637 | + $label4 = esc_attr__('Alert Type', 'invoicing'); |
|
1638 | 1638 | $id3 = $field . '.id + "_edit3"'; |
1639 | 1639 | echo " |
1640 | 1640 | <div $restrict> |
@@ -1650,14 +1650,14 @@ discard block |
||
1650 | 1650 | <label :for='$id3'>$label4</label> |
1651 | 1651 | |
1652 | 1652 | <select class='form-control custom-select' :id='$id3' v-model='$field.class'> |
1653 | - <option value='alert-primary'>" . __( 'Primary', 'invoicing' ) ."</option> |
|
1654 | - <option value='alert-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option> |
|
1655 | - <option value='alert-success'>" . __( 'Success', 'invoicing' ) ."</option> |
|
1656 | - <option value='alert-danger'>" . __( 'Danger', 'invoicing' ) ."</option> |
|
1657 | - <option value='alert-warning'>" . __( 'Warning', 'invoicing' ) ."</option> |
|
1658 | - <option value='alert-info'>" . __( 'Info', 'invoicing' ) ."</option> |
|
1659 | - <option value='alert-light'>" . __( 'Light', 'invoicing' ) ."</option> |
|
1660 | - <option value='alert-dark'>" . __( 'Dark', 'invoicing' ) ."</option> |
|
1653 | + <option value='alert-primary'>" . __('Primary', 'invoicing') . "</option> |
|
1654 | + <option value='alert-secondary'>" . __('Secondary', 'invoicing') . "</option> |
|
1655 | + <option value='alert-success'>" . __('Success', 'invoicing') . "</option> |
|
1656 | + <option value='alert-danger'>" . __('Danger', 'invoicing') . "</option> |
|
1657 | + <option value='alert-warning'>" . __('Warning', 'invoicing') . "</option> |
|
1658 | + <option value='alert-info'>" . __('Info', 'invoicing') . "</option> |
|
1659 | + <option value='alert-light'>" . __('Light', 'invoicing') . "</option> |
|
1660 | + <option value='alert-dark'>" . __('Dark', 'invoicing') . "</option> |
|
1661 | 1661 | </select> |
1662 | 1662 | </div> |
1663 | 1663 | </div> |
@@ -1668,8 +1668,8 @@ discard block |
||
1668 | 1668 | /** |
1669 | 1669 | * Renders the discount element template. |
1670 | 1670 | */ |
1671 | - public function render_discount_template( $field ) { |
|
1672 | - $restrict = $this->get_restrict_markup( $field, 'discount' ); |
|
1671 | + public function render_discount_template($field) { |
|
1672 | + $restrict = $this->get_restrict_markup($field, 'discount'); |
|
1673 | 1673 | ?> |
1674 | 1674 | |
1675 | 1675 | <div <?php echo $restrict; ?> class="discount_field border rounded p-3"> |
@@ -1686,13 +1686,13 @@ discard block |
||
1686 | 1686 | /** |
1687 | 1687 | * Renders the discount element on the frontend. |
1688 | 1688 | */ |
1689 | - public function frontend_render_discount_template( $field ) { |
|
1689 | + public function frontend_render_discount_template($field) { |
|
1690 | 1690 | |
1691 | - $placeholder = esc_attr( $field['input_label'] ); |
|
1692 | - $label = sanitize_text_field( $field['button_label'] ); |
|
1691 | + $placeholder = esc_attr($field['input_label']); |
|
1692 | + $label = sanitize_text_field($field['button_label']); |
|
1693 | 1693 | $description = ''; |
1694 | 1694 | |
1695 | - if ( ! empty( $field['description'] ) ) { |
|
1695 | + if (!empty($field['description'])) { |
|
1696 | 1696 | $description = "<small class='form-text text-muted'>{$field['description']}</small>"; |
1697 | 1697 | } |
1698 | 1698 | ?> |
@@ -1713,12 +1713,12 @@ discard block |
||
1713 | 1713 | /** |
1714 | 1714 | * Renders the discount element template. |
1715 | 1715 | */ |
1716 | - public function edit_discount_template( $field ) { |
|
1717 | - $restrict = $this->get_restrict_markup( $field, 'discount' ); |
|
1718 | - $label = __( 'Discount Input Placeholder', 'invoicing' ); |
|
1719 | - $label2 = __( 'Help Text', 'invoicing' ); |
|
1720 | - $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
1721 | - $label4 = __( 'Button Text', 'invoicing' ); |
|
1716 | + public function edit_discount_template($field) { |
|
1717 | + $restrict = $this->get_restrict_markup($field, 'discount'); |
|
1718 | + $label = __('Discount Input Placeholder', 'invoicing'); |
|
1719 | + $label2 = __('Help Text', 'invoicing'); |
|
1720 | + $label3 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
1721 | + $label4 = __('Button Text', 'invoicing'); |
|
1722 | 1722 | $id = $field . '.id + "_edit"'; |
1723 | 1723 | $id2 = $field . '.id + "_edit2"'; |
1724 | 1724 | $id3 = $field . '.id + "_edit3"'; |
@@ -1747,21 +1747,21 @@ discard block |
||
1747 | 1747 | /** |
1748 | 1748 | * Renders the items element template. |
1749 | 1749 | */ |
1750 | - public function render_items_template( $field ) { |
|
1751 | - $restrict = $this->get_restrict_markup( $field, 'items' ); |
|
1752 | - $label = __( 'Item totals will appear here. Click to set items.', 'invoicing' ); |
|
1750 | + public function render_items_template($field) { |
|
1751 | + $restrict = $this->get_restrict_markup($field, 'items'); |
|
1752 | + $label = __('Item totals will appear here. Click to set items.', 'invoicing'); |
|
1753 | 1753 | echo "<div $restrict class='item_totals p-4 bg-warning text-center'>$label</div>"; |
1754 | 1754 | } |
1755 | 1755 | |
1756 | 1756 | /** |
1757 | 1757 | * Renders the items element on the frontend. |
1758 | 1758 | */ |
1759 | - public function frontend_render_items_template( $field, $items ) { |
|
1759 | + public function frontend_render_items_template($field, $items) { |
|
1760 | 1760 | |
1761 | 1761 | echo "<div class='form-group item_totals'>"; |
1762 | 1762 | |
1763 | - $id = esc_attr( $field['id'] ); |
|
1764 | - if ( 'total' == $field[ 'items_type' ] ) { |
|
1763 | + $id = esc_attr($field['id']); |
|
1764 | + if ('total' == $field['items_type']) { |
|
1765 | 1765 | $total = 0; |
1766 | 1766 | $tax = 0; |
1767 | 1767 | $sub_total = 0; |
@@ -1770,16 +1770,16 @@ discard block |
||
1770 | 1770 | <div class="border item_totals_type_total"> |
1771 | 1771 | |
1772 | 1772 | <?php |
1773 | - foreach( $items as $item ) { |
|
1773 | + foreach ($items as $item) { |
|
1774 | 1774 | |
1775 | - $amount = floatval( $item['price'] ); |
|
1775 | + $amount = floatval($item['price']); |
|
1776 | 1776 | |
1777 | - if ( wpinv_use_taxes() ) { |
|
1777 | + if (wpinv_use_taxes()) { |
|
1778 | 1778 | |
1779 | - $rate = wpinv_get_tax_rate( false, false, (int) $item['id'] ); |
|
1779 | + $rate = wpinv_get_tax_rate(false, false, (int) $item['id']); |
|
1780 | 1780 | |
1781 | - if ( wpinv_prices_include_tax() ) { |
|
1782 | - $pre_tax = ( $amount - $amount * $rate * 0.01 ); |
|
1781 | + if (wpinv_prices_include_tax()) { |
|
1782 | + $pre_tax = ($amount - $amount * $rate * 0.01); |
|
1783 | 1783 | $item_tax = $amount - $pre_tax; |
1784 | 1784 | } else { |
1785 | 1785 | $pre_tax = $amount; |
@@ -1791,27 +1791,27 @@ discard block |
||
1791 | 1791 | $total = $sub_total + $tax; |
1792 | 1792 | |
1793 | 1793 | } else { |
1794 | - $total = $total + $amount; |
|
1794 | + $total = $total + $amount; |
|
1795 | 1795 | } |
1796 | 1796 | |
1797 | 1797 | $class = 'col-8'; |
1798 | 1798 | $class2 = ''; |
1799 | 1799 | |
1800 | - if ( ! empty( $item['allow_quantities'] ) ) { |
|
1800 | + if (!empty($item['allow_quantities'])) { |
|
1801 | 1801 | $class = 'col-6 pt-2'; |
1802 | 1802 | $class2 = 'pt-2'; |
1803 | 1803 | } |
1804 | 1804 | |
1805 | - if ( ! empty( $item['custom_price'] ) ) { |
|
1805 | + if (!empty($item['custom_price'])) { |
|
1806 | 1806 | $class .= ' pt-2'; |
1807 | 1807 | } |
1808 | 1808 | |
1809 | 1809 | ?> |
1810 | 1810 | <div class="item_totals_item"> |
1811 | 1811 | <div class='row pl-2 pr-2 pt-2'> |
1812 | - <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div> |
|
1812 | + <div class='<?php echo $class; ?>'><?php echo esc_html($item['title']) ?></div> |
|
1813 | 1813 | |
1814 | - <?php if ( ! empty( $item['allow_quantities'] ) ) { ?> |
|
1814 | + <?php if (!empty($item['allow_quantities'])) { ?> |
|
1815 | 1815 | |
1816 | 1816 | <div class='col-2'> |
1817 | 1817 | <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required> |
@@ -1819,11 +1819,11 @@ discard block |
||
1819 | 1819 | |
1820 | 1820 | <?php } else { ?> |
1821 | 1821 | <input type='hidden' class='wpinv-item-quantity-input' value='1'> |
1822 | - <?php } if ( empty( $item['custom_price'] ) ) { ?> |
|
1822 | + <?php } if (empty($item['custom_price'])) { ?> |
|
1823 | 1823 | |
1824 | 1824 | <div class='col-4 <?php echo $class2; ?>'> |
1825 | - <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?> |
|
1826 | - <input name='wpinv-items[<?php echo (int) $item['id']; ?>]' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'> |
|
1825 | + <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?> |
|
1826 | + <input name='wpinv-items[<?php echo (int) $item['id']; ?>]' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'> |
|
1827 | 1827 | </div> |
1828 | 1828 | |
1829 | 1829 | <?php } else {?> |
@@ -1831,15 +1831,15 @@ discard block |
||
1831 | 1831 | <div class='col-4'> |
1832 | 1832 | <div class='input-group'> |
1833 | 1833 | |
1834 | - <?php if ( 'left' == wpinv_currency_position() ) { ?> |
|
1834 | + <?php if ('left' == wpinv_currency_position()) { ?> |
|
1835 | 1835 | <div class='input-group-prepend'> |
1836 | 1836 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
1837 | 1837 | </div> |
1838 | 1838 | <?php } ?> |
1839 | 1839 | |
1840 | - <input type='number' name='wpinv-items[<?php echo (int) $item['id']; ?>]' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'> |
|
1840 | + <input type='number' name='wpinv-items[<?php echo (int) $item['id']; ?>]' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval($item['price']); ?>' value='<?php echo floatval($item['price']); ?>' min='<?php echo intval($item['minimum_price']); ?>'> |
|
1841 | 1841 | |
1842 | - <?php if ( 'left' != wpinv_currency_position() ) { ?> |
|
1842 | + <?php if ('left' != wpinv_currency_position()) { ?> |
|
1843 | 1843 | <div class='input-group-append'> |
1844 | 1844 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
1845 | 1845 | </div> |
@@ -1850,28 +1850,28 @@ discard block |
||
1850 | 1850 | <?php } ?> |
1851 | 1851 | |
1852 | 1852 | </div> |
1853 | - <?php if ( ! empty( $item['description'] )) { ?> |
|
1854 | - <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small> |
|
1853 | + <?php if (!empty($item['description'])) { ?> |
|
1854 | + <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small> |
|
1855 | 1855 | <?php } ?> |
1856 | 1856 | </div> |
1857 | 1857 | <?php } ?> |
1858 | 1858 | |
1859 | 1859 | <div class='mt-4 border-top item_totals_total p-2'> |
1860 | 1860 | |
1861 | - <?php if ( wpinv_use_taxes() ) { ?> |
|
1861 | + <?php if (wpinv_use_taxes()) { ?> |
|
1862 | 1862 | <div class='row'> |
1863 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div> |
|
1864 | - <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div> |
|
1863 | + <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div> |
|
1864 | + <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div> |
|
1865 | 1865 | </div> |
1866 | 1866 | <div class='row'> |
1867 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div> |
|
1868 | - <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div> |
|
1867 | + <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div> |
|
1868 | + <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div> |
|
1869 | 1869 | </div> |
1870 | 1870 | <?php } ?> |
1871 | 1871 | |
1872 | 1872 | <div class='row'> |
1873 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div> |
|
1874 | - <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div> |
|
1873 | + <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div> |
|
1874 | + <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price(wpinv_format_amount($total)) ?></strong></div> |
|
1875 | 1875 | </div> |
1876 | 1876 | |
1877 | 1877 | </div> |
@@ -1879,22 +1879,22 @@ discard block |
||
1879 | 1879 | </div> |
1880 | 1880 | <?php } ?> |
1881 | 1881 | |
1882 | - <?php if ( 'radio' == $field[ 'items_type' ] ) { ?> |
|
1882 | + <?php if ('radio' == $field['items_type']) { ?> |
|
1883 | 1883 | <div class="item_totals_type_radio"> |
1884 | 1884 | |
1885 | 1885 | <?php |
1886 | - foreach( $items as $index => $item ) { |
|
1886 | + foreach ($items as $index => $item) { |
|
1887 | 1887 | |
1888 | - if ( ! empty( $item['required'] ) ) { |
|
1888 | + if (!empty($item['required'])) { |
|
1889 | 1889 | continue; |
1890 | 1890 | } |
1891 | 1891 | ?> |
1892 | 1892 | <div class="form-check"> |
1893 | - <input class='form-check-input wpinv-items-selector' <?php checked( ! isset( $selected_radio_item ) ); $selected_radio_item = 1; ?> type='radio' value='<?php echo $item['id']; ?>' id='<?php echo $id . $index; ?>' name='wpinv-payment-form-selected-item'> |
|
1894 | - <label class='form-check-label' for='<?php echo $id . $index; ?>'><?php echo sanitize_text_field( $item['title'] ); ?> <strong><?php echo wpinv_price( wpinv_format_amount( (float) sanitize_text_field( $item['price'] ) ) ); ?></strong></label> |
|
1893 | + <input class='form-check-input wpinv-items-selector' <?php checked(!isset($selected_radio_item)); $selected_radio_item = 1; ?> type='radio' value='<?php echo $item['id']; ?>' id='<?php echo $id . $index; ?>' name='wpinv-payment-form-selected-item'> |
|
1894 | + <label class='form-check-label' for='<?php echo $id . $index; ?>'><?php echo sanitize_text_field($item['title']); ?> <strong><?php echo wpinv_price(wpinv_format_amount((float) sanitize_text_field($item['price']))); ?></strong></label> |
|
1895 | 1895 | </div> |
1896 | - <?php if ( ! empty( $item['description'] )) { ?> |
|
1897 | - <small class='form-text text-muted pl-4 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small> |
|
1896 | + <?php if (!empty($item['description'])) { ?> |
|
1897 | + <small class='form-text text-muted pl-4 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small> |
|
1898 | 1898 | <?php } ?> |
1899 | 1899 | <?php } ?> |
1900 | 1900 | |
@@ -1906,32 +1906,32 @@ discard block |
||
1906 | 1906 | $tax = 0; |
1907 | 1907 | $sub_total = 0; |
1908 | 1908 | |
1909 | - foreach ( $items as $item ) { |
|
1909 | + foreach ($items as $item) { |
|
1910 | 1910 | |
1911 | 1911 | $class = 'col-8'; |
1912 | 1912 | $class2 = ''; |
1913 | 1913 | |
1914 | - if ( ! empty( $item['allow_quantities'] ) ) { |
|
1914 | + if (!empty($item['allow_quantities'])) { |
|
1915 | 1915 | $class = 'col-6 pt-2'; |
1916 | 1916 | $class2 = 'pt-2'; |
1917 | 1917 | } |
1918 | 1918 | |
1919 | - if ( ! empty( $item['custom_price'] ) ) { |
|
1919 | + if (!empty($item['custom_price'])) { |
|
1920 | 1920 | $class .= ' pt-2'; |
1921 | 1921 | } |
1922 | 1922 | |
1923 | 1923 | $class3 = 'd-none'; |
1924 | 1924 | $name = ''; |
1925 | - if ( ! empty( $item['required'] ) || ! isset( $totals_selected_radio_item ) ) { |
|
1925 | + if (!empty($item['required']) || !isset($totals_selected_radio_item)) { |
|
1926 | 1926 | |
1927 | - $amount = floatval( $item['price'] ); |
|
1927 | + $amount = floatval($item['price']); |
|
1928 | 1928 | |
1929 | - if ( wpinv_use_taxes() ) { |
|
1929 | + if (wpinv_use_taxes()) { |
|
1930 | 1930 | |
1931 | - $rate = wpinv_get_tax_rate( false, false, (int) $item['id'] ); |
|
1931 | + $rate = wpinv_get_tax_rate(false, false, (int) $item['id']); |
|
1932 | 1932 | |
1933 | - if ( wpinv_prices_include_tax() ) { |
|
1934 | - $pre_tax = ( $amount - $amount * $rate * 0.01 ); |
|
1933 | + if (wpinv_prices_include_tax()) { |
|
1934 | + $pre_tax = ($amount - $amount * $rate * 0.01); |
|
1935 | 1935 | $item_tax = $amount - $pre_tax; |
1936 | 1936 | } else { |
1937 | 1937 | $pre_tax = $amount; |
@@ -1943,13 +1943,13 @@ discard block |
||
1943 | 1943 | $total = $sub_total + $tax; |
1944 | 1944 | |
1945 | 1945 | } else { |
1946 | - $total = $total + $amount; |
|
1946 | + $total = $total + $amount; |
|
1947 | 1947 | } |
1948 | 1948 | |
1949 | 1949 | $class3 = ''; |
1950 | 1950 | $name = "wpinv-items[{$item['id']}]"; |
1951 | 1951 | |
1952 | - if ( empty( $item['required'] ) ) { |
|
1952 | + if (empty($item['required'])) { |
|
1953 | 1953 | $totals_selected_radio_item = 1; |
1954 | 1954 | } |
1955 | 1955 | |
@@ -1961,9 +1961,9 @@ discard block |
||
1961 | 1961 | |
1962 | 1962 | <div class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>"> |
1963 | 1963 | <div class='row pl-2 pr-2 pt-2'> |
1964 | - <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div> |
|
1964 | + <div class='<?php echo $class; ?>'><?php echo esc_html($item['title']) ?></div> |
|
1965 | 1965 | |
1966 | - <?php if ( ! empty( $item['allow_quantities'] ) ) { ?> |
|
1966 | + <?php if (!empty($item['allow_quantities'])) { ?> |
|
1967 | 1967 | |
1968 | 1968 | <div class='col-2'> |
1969 | 1969 | <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required> |
@@ -1971,11 +1971,11 @@ discard block |
||
1971 | 1971 | |
1972 | 1972 | <?php } else { ?> |
1973 | 1973 | <input type='hidden' class='wpinv-item-quantity-input' value='1'> |
1974 | - <?php } if ( empty( $item['custom_price'] ) ) { ?> |
|
1974 | + <?php } if (empty($item['custom_price'])) { ?> |
|
1975 | 1975 | |
1976 | 1976 | <div class='col-4 <?php echo $class2; ?>'> |
1977 | - <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?> |
|
1978 | - <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'> |
|
1977 | + <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?> |
|
1978 | + <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'> |
|
1979 | 1979 | </div> |
1980 | 1980 | |
1981 | 1981 | <?php } else {?> |
@@ -1983,15 +1983,15 @@ discard block |
||
1983 | 1983 | <div class='col-4'> |
1984 | 1984 | <div class='input-group'> |
1985 | 1985 | |
1986 | - <?php if ( 'left' == wpinv_currency_position() ) { ?> |
|
1986 | + <?php if ('left' == wpinv_currency_position()) { ?> |
|
1987 | 1987 | <div class='input-group-prepend'> |
1988 | 1988 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
1989 | 1989 | </div> |
1990 | 1990 | <?php } ?> |
1991 | 1991 | |
1992 | - <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'> |
|
1992 | + <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval($item['price']); ?>' value='<?php echo floatval($item['price']); ?>' min='<?php echo intval($item['minimum_price']); ?>'> |
|
1993 | 1993 | |
1994 | - <?php if ( 'left' != wpinv_currency_position() ) { ?> |
|
1994 | + <?php if ('left' != wpinv_currency_position()) { ?> |
|
1995 | 1995 | <div class='input-group-append'> |
1996 | 1996 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
1997 | 1997 | </div> |
@@ -2002,27 +2002,27 @@ discard block |
||
2002 | 2002 | <?php } ?> |
2003 | 2003 | |
2004 | 2004 | </div> |
2005 | - <?php if ( ! empty( $item['description'] )) { ?> |
|
2006 | - <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small> |
|
2005 | + <?php if (!empty($item['description'])) { ?> |
|
2006 | + <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small> |
|
2007 | 2007 | <?php } ?> |
2008 | 2008 | </div> |
2009 | 2009 | <?php } ?> |
2010 | 2010 | |
2011 | 2011 | <div class='mt-4 border-top item_totals_total p-2'> |
2012 | - <?php if ( wpinv_use_taxes() ) { ?> |
|
2012 | + <?php if (wpinv_use_taxes()) { ?> |
|
2013 | 2013 | <div class='row'> |
2014 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div> |
|
2015 | - <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div> |
|
2014 | + <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div> |
|
2015 | + <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div> |
|
2016 | 2016 | </div> |
2017 | 2017 | <div class='row'> |
2018 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div> |
|
2019 | - <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div> |
|
2018 | + <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div> |
|
2019 | + <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div> |
|
2020 | 2020 | </div> |
2021 | 2021 | <?php } ?> |
2022 | 2022 | |
2023 | 2023 | <div class='row'> |
2024 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div> |
|
2025 | - <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div> |
|
2024 | + <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div> |
|
2025 | + <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price(wpinv_format_amount($total)) ?></strong></div> |
|
2026 | 2026 | </div> |
2027 | 2027 | </div> |
2028 | 2028 | |
@@ -2030,22 +2030,22 @@ discard block |
||
2030 | 2030 | </div> |
2031 | 2031 | <?php } ?> |
2032 | 2032 | |
2033 | - <?php if ( 'checkbox' == $field[ 'items_type' ] ) { ?> |
|
2033 | + <?php if ('checkbox' == $field['items_type']) { ?> |
|
2034 | 2034 | |
2035 | 2035 | <div class="item_totals_type_checkbox"> |
2036 | 2036 | |
2037 | 2037 | <?php |
2038 | - foreach ( $items as $index => $item ) { |
|
2038 | + foreach ($items as $index => $item) { |
|
2039 | 2039 | |
2040 | - if ( ! empty( $item['required'] ) ) { |
|
2040 | + if (!empty($item['required'])) { |
|
2041 | 2041 | continue; |
2042 | 2042 | } |
2043 | 2043 | |
2044 | - $title = sanitize_text_field( $item['title'] ); |
|
2045 | - $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field( $item['price'] ) ) ); |
|
2046 | - $item_id = esc_attr( $id . "_$index" ); |
|
2047 | - $value = esc_attr( $item['id'] ); |
|
2048 | - $checked = checked( ! isset( $selected_checkbox_item ), true, false ); |
|
2044 | + $title = sanitize_text_field($item['title']); |
|
2045 | + $price = wpinv_price(wpinv_format_amount((float) sanitize_text_field($item['price']))); |
|
2046 | + $item_id = esc_attr($id . "_$index"); |
|
2047 | + $value = esc_attr($item['id']); |
|
2048 | + $checked = checked(!isset($selected_checkbox_item), true, false); |
|
2049 | 2049 | $selected_checkbox_item = 1; |
2050 | 2050 | |
2051 | 2051 | echo " |
@@ -2054,7 +2054,7 @@ discard block |
||
2054 | 2054 | <label for='$item_id' class='custom-control-label'>$title ($price)</label> |
2055 | 2055 | </div>"; |
2056 | 2056 | |
2057 | - if ( ! empty( $item['description'] ) ) { |
|
2057 | + if (!empty($item['description'])) { |
|
2058 | 2058 | echo "<small class='form-text text-muted'>{$item['description']}</small>"; |
2059 | 2059 | } |
2060 | 2060 | } |
@@ -2068,31 +2068,31 @@ discard block |
||
2068 | 2068 | $tax = 0; |
2069 | 2069 | $sub_total = 0; |
2070 | 2070 | |
2071 | - foreach ( $items as $item ) { |
|
2071 | + foreach ($items as $item) { |
|
2072 | 2072 | |
2073 | 2073 | $class = 'col-8'; |
2074 | 2074 | $class2 = ''; |
2075 | 2075 | |
2076 | - if ( ! empty( $item['allow_quantities'] ) ) { |
|
2076 | + if (!empty($item['allow_quantities'])) { |
|
2077 | 2077 | $class = 'col-6 pt-2'; |
2078 | 2078 | $class2 = 'pt-2'; |
2079 | 2079 | } |
2080 | 2080 | |
2081 | - if ( ! empty( $item['custom_price'] ) ) { |
|
2081 | + if (!empty($item['custom_price'])) { |
|
2082 | 2082 | $class .= ' pt-2'; |
2083 | 2083 | } |
2084 | 2084 | |
2085 | 2085 | $class3 = 'd-none'; |
2086 | - $name = ''; |
|
2087 | - if ( ! empty( $item['required'] ) || ! isset( $totals_selected_checkbox_item ) ) { |
|
2086 | + $name = ''; |
|
2087 | + if (!empty($item['required']) || !isset($totals_selected_checkbox_item)) { |
|
2088 | 2088 | |
2089 | - $amount = floatval( $item['price'] ); |
|
2090 | - if ( wpinv_use_taxes() ) { |
|
2089 | + $amount = floatval($item['price']); |
|
2090 | + if (wpinv_use_taxes()) { |
|
2091 | 2091 | |
2092 | - $rate = wpinv_get_tax_rate( false, false, (int) $item['id'] ); |
|
2092 | + $rate = wpinv_get_tax_rate(false, false, (int) $item['id']); |
|
2093 | 2093 | |
2094 | - if ( wpinv_prices_include_tax() ) { |
|
2095 | - $pre_tax = ( $amount - $amount * $rate * 0.01 ); |
|
2094 | + if (wpinv_prices_include_tax()) { |
|
2095 | + $pre_tax = ($amount - $amount * $rate * 0.01); |
|
2096 | 2096 | $item_tax = $amount - $pre_tax; |
2097 | 2097 | } else { |
2098 | 2098 | $pre_tax = $amount; |
@@ -2104,13 +2104,13 @@ discard block |
||
2104 | 2104 | $total = $sub_total + $tax; |
2105 | 2105 | |
2106 | 2106 | } else { |
2107 | - $total = $total + $amount; |
|
2107 | + $total = $total + $amount; |
|
2108 | 2108 | } |
2109 | 2109 | |
2110 | 2110 | $class3 = ''; |
2111 | - $name = "wpinv-items[{$item['id']}]"; |
|
2111 | + $name = "wpinv-items[{$item['id']}]"; |
|
2112 | 2112 | |
2113 | - if ( empty( $item['required'] ) ) { |
|
2113 | + if (empty($item['required'])) { |
|
2114 | 2114 | $totals_selected_checkbox_item = 1; |
2115 | 2115 | } |
2116 | 2116 | |
@@ -2122,9 +2122,9 @@ discard block |
||
2122 | 2122 | |
2123 | 2123 | <div class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>"> |
2124 | 2124 | <div class='row pl-2 pr-2 pt-2'> |
2125 | - <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div> |
|
2125 | + <div class='<?php echo $class; ?>'><?php echo esc_html($item['title']) ?></div> |
|
2126 | 2126 | |
2127 | - <?php if ( ! empty( $item['allow_quantities'] ) ) { ?> |
|
2127 | + <?php if (!empty($item['allow_quantities'])) { ?> |
|
2128 | 2128 | |
2129 | 2129 | <div class='col-2'> |
2130 | 2130 | <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required> |
@@ -2132,11 +2132,11 @@ discard block |
||
2132 | 2132 | |
2133 | 2133 | <?php } else { ?> |
2134 | 2134 | <input type='hidden' class='wpinv-item-quantity-input' value='1'> |
2135 | - <?php } if ( empty( $item['custom_price'] ) ) { ?> |
|
2135 | + <?php } if (empty($item['custom_price'])) { ?> |
|
2136 | 2136 | |
2137 | 2137 | <div class='col-4 <?php echo $class2; ?>'> |
2138 | - <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?> |
|
2139 | - <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'> |
|
2138 | + <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?> |
|
2139 | + <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'> |
|
2140 | 2140 | </div> |
2141 | 2141 | |
2142 | 2142 | <?php } else {?> |
@@ -2144,15 +2144,15 @@ discard block |
||
2144 | 2144 | <div class='col-4'> |
2145 | 2145 | <div class='input-group'> |
2146 | 2146 | |
2147 | - <?php if ( 'left' == wpinv_currency_position() ) { ?> |
|
2147 | + <?php if ('left' == wpinv_currency_position()) { ?> |
|
2148 | 2148 | <div class='input-group-prepend'> |
2149 | 2149 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
2150 | 2150 | </div> |
2151 | 2151 | <?php } ?> |
2152 | 2152 | |
2153 | - <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'> |
|
2153 | + <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval($item['price']); ?>' value='<?php echo floatval($item['price']); ?>' min='<?php echo intval($item['minimum_price']); ?>'> |
|
2154 | 2154 | |
2155 | - <?php if ( 'left' != wpinv_currency_position() ) { ?> |
|
2155 | + <?php if ('left' != wpinv_currency_position()) { ?> |
|
2156 | 2156 | <div class='input-group-append'> |
2157 | 2157 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
2158 | 2158 | </div> |
@@ -2163,35 +2163,35 @@ discard block |
||
2163 | 2163 | <?php } ?> |
2164 | 2164 | |
2165 | 2165 | </div> |
2166 | - <?php if ( ! empty( $item['description'] )) { ?> |
|
2167 | - <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small> |
|
2166 | + <?php if (!empty($item['description'])) { ?> |
|
2167 | + <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small> |
|
2168 | 2168 | <?php } ?> |
2169 | 2169 | </div> |
2170 | 2170 | <?php } ?> |
2171 | 2171 | |
2172 | 2172 | <div class='mt-4 border-top item_totals_total p-2'> |
2173 | 2173 | |
2174 | - <?php if ( wpinv_use_taxes() ) { ?> |
|
2174 | + <?php if (wpinv_use_taxes()) { ?> |
|
2175 | 2175 | <div class='row'> |
2176 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div> |
|
2177 | - <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div> |
|
2176 | + <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div> |
|
2177 | + <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div> |
|
2178 | 2178 | </div> |
2179 | 2179 | <div class='row'> |
2180 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div> |
|
2181 | - <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div> |
|
2180 | + <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div> |
|
2181 | + <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div> |
|
2182 | 2182 | </div> |
2183 | 2183 | <?php } ?> |
2184 | 2184 | |
2185 | 2185 | <div class='row'> |
2186 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div> |
|
2187 | - <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div> |
|
2186 | + <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div> |
|
2187 | + <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price(wpinv_format_amount($total)) ?></strong></div> |
|
2188 | 2188 | </div> |
2189 | 2189 | </div> |
2190 | 2190 | </div> |
2191 | 2191 | </div> |
2192 | 2192 | <?php } ?> |
2193 | 2193 | |
2194 | - <?php if ( 'select' == $field[ 'items_type' ] ) { ?> |
|
2194 | + <?php if ('select' == $field['items_type']) { ?> |
|
2195 | 2195 | |
2196 | 2196 | <div class="item_totals_type_select"> |
2197 | 2197 | |
@@ -2199,17 +2199,17 @@ discard block |
||
2199 | 2199 | |
2200 | 2200 | $options = array(); |
2201 | 2201 | $selected = ''; |
2202 | - foreach ( $items as $index => $item ) { |
|
2202 | + foreach ($items as $index => $item) { |
|
2203 | 2203 | |
2204 | - if ( ! empty( $item['required'] ) ) { |
|
2204 | + if (!empty($item['required'])) { |
|
2205 | 2205 | continue; |
2206 | 2206 | } |
2207 | 2207 | |
2208 | - $title = sanitize_text_field( $item['title'] ); |
|
2209 | - $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field( $item['price'] ) ) ); |
|
2210 | - $options[ $item['id'] ] = "$title ($price)"; |
|
2208 | + $title = sanitize_text_field($item['title']); |
|
2209 | + $price = wpinv_price(wpinv_format_amount((float) sanitize_text_field($item['price']))); |
|
2210 | + $options[$item['id']] = "$title ($price)"; |
|
2211 | 2211 | |
2212 | - if ( ! isset( $selected_item ) ) { |
|
2212 | + if (!isset($selected_item)) { |
|
2213 | 2213 | $selected = $item['id']; |
2214 | 2214 | $selected_item = 1; |
2215 | 2215 | } |
@@ -2220,7 +2220,7 @@ discard block |
||
2220 | 2220 | array( |
2221 | 2221 | 'name' => 'payment-form-items', |
2222 | 2222 | 'id' => $id, |
2223 | - 'placeholder' => __( 'Select an item', 'invoicing' ), |
|
2223 | + 'placeholder' => __('Select an item', 'invoicing'), |
|
2224 | 2224 | 'no_wrap' => true, |
2225 | 2225 | 'options' => $options, |
2226 | 2226 | 'class' => 'wpi_select2 wpinv-items-select-selector', |
@@ -2237,31 +2237,31 @@ discard block |
||
2237 | 2237 | $tax = 0; |
2238 | 2238 | $sub_total = 0; |
2239 | 2239 | |
2240 | - foreach ( $items as $item ) { |
|
2240 | + foreach ($items as $item) { |
|
2241 | 2241 | |
2242 | 2242 | $class = 'col-8'; |
2243 | 2243 | $class2 = ''; |
2244 | 2244 | |
2245 | - if ( ! empty( $item['allow_quantities'] ) ) { |
|
2245 | + if (!empty($item['allow_quantities'])) { |
|
2246 | 2246 | $class = 'col-6 pt-2'; |
2247 | 2247 | $class2 = 'pt-2'; |
2248 | 2248 | } |
2249 | 2249 | |
2250 | - if ( ! empty( $item['custom_price'] ) ) { |
|
2250 | + if (!empty($item['custom_price'])) { |
|
2251 | 2251 | $class .= ' pt-2'; |
2252 | 2252 | } |
2253 | 2253 | |
2254 | 2254 | $class3 = 'd-none'; |
2255 | - $name = ''; |
|
2256 | - if ( ! empty( $item['required'] ) || ! isset( $totals_selected_select_item ) ) { |
|
2255 | + $name = ''; |
|
2256 | + if (!empty($item['required']) || !isset($totals_selected_select_item)) { |
|
2257 | 2257 | |
2258 | - $amount = floatval( $item['price'] ); |
|
2259 | - if ( wpinv_use_taxes() ) { |
|
2258 | + $amount = floatval($item['price']); |
|
2259 | + if (wpinv_use_taxes()) { |
|
2260 | 2260 | |
2261 | - $rate = wpinv_get_tax_rate( false, false, (int) $item['id'] ); |
|
2261 | + $rate = wpinv_get_tax_rate(false, false, (int) $item['id']); |
|
2262 | 2262 | |
2263 | - if ( wpinv_prices_include_tax() ) { |
|
2264 | - $pre_tax = ( $amount - $amount * $rate * 0.01 ); |
|
2263 | + if (wpinv_prices_include_tax()) { |
|
2264 | + $pre_tax = ($amount - $amount * $rate * 0.01); |
|
2265 | 2265 | $item_tax = $amount - $pre_tax; |
2266 | 2266 | } else { |
2267 | 2267 | $pre_tax = $amount; |
@@ -2273,13 +2273,13 @@ discard block |
||
2273 | 2273 | $total = $sub_total + $tax; |
2274 | 2274 | |
2275 | 2275 | } else { |
2276 | - $total = $total + $amount; |
|
2276 | + $total = $total + $amount; |
|
2277 | 2277 | } |
2278 | 2278 | |
2279 | 2279 | $class3 = ''; |
2280 | - $name = "wpinv-items[{$item['id']}]"; |
|
2280 | + $name = "wpinv-items[{$item['id']}]"; |
|
2281 | 2281 | |
2282 | - if ( empty( $item['required'] ) ) { |
|
2282 | + if (empty($item['required'])) { |
|
2283 | 2283 | $totals_selected_select_item = 1; |
2284 | 2284 | } |
2285 | 2285 | |
@@ -2291,9 +2291,9 @@ discard block |
||
2291 | 2291 | |
2292 | 2292 | <div class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>"> |
2293 | 2293 | <div class='row pl-2 pr-2 pt-2'> |
2294 | - <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div> |
|
2294 | + <div class='<?php echo $class; ?>'><?php echo esc_html($item['title']) ?></div> |
|
2295 | 2295 | |
2296 | - <?php if ( ! empty( $item['allow_quantities'] ) ) { ?> |
|
2296 | + <?php if (!empty($item['allow_quantities'])) { ?> |
|
2297 | 2297 | |
2298 | 2298 | <div class='col-2'> |
2299 | 2299 | <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required> |
@@ -2301,11 +2301,11 @@ discard block |
||
2301 | 2301 | |
2302 | 2302 | <?php } else { ?> |
2303 | 2303 | <input type='hidden' class='wpinv-item-quantity-input' value='1'> |
2304 | - <?php } if ( empty( $item['custom_price'] ) ) { ?> |
|
2304 | + <?php } if (empty($item['custom_price'])) { ?> |
|
2305 | 2305 | |
2306 | 2306 | <div class='col-4 <?php echo $class2; ?>'> |
2307 | - <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?> |
|
2308 | - <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'> |
|
2307 | + <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?> |
|
2308 | + <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'> |
|
2309 | 2309 | </div> |
2310 | 2310 | |
2311 | 2311 | <?php } else {?> |
@@ -2313,15 +2313,15 @@ discard block |
||
2313 | 2313 | <div class='col-4'> |
2314 | 2314 | <div class='input-group'> |
2315 | 2315 | |
2316 | - <?php if ( 'left' == wpinv_currency_position() ) { ?> |
|
2316 | + <?php if ('left' == wpinv_currency_position()) { ?> |
|
2317 | 2317 | <div class='input-group-prepend'> |
2318 | 2318 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
2319 | 2319 | </div> |
2320 | 2320 | <?php } ?> |
2321 | 2321 | |
2322 | - <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'> |
|
2322 | + <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval($item['price']); ?>' value='<?php echo floatval($item['price']); ?>' min='<?php echo intval($item['minimum_price']); ?>'> |
|
2323 | 2323 | |
2324 | - <?php if ( 'left' != wpinv_currency_position() ) { ?> |
|
2324 | + <?php if ('left' != wpinv_currency_position()) { ?> |
|
2325 | 2325 | <div class='input-group-append'> |
2326 | 2326 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
2327 | 2327 | </div> |
@@ -2332,34 +2332,34 @@ discard block |
||
2332 | 2332 | <?php } ?> |
2333 | 2333 | |
2334 | 2334 | </div> |
2335 | - <?php if ( ! empty( $item['description'] )) { ?> |
|
2336 | - <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small> |
|
2335 | + <?php if (!empty($item['description'])) { ?> |
|
2336 | + <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small> |
|
2337 | 2337 | <?php } ?> |
2338 | 2338 | </div> |
2339 | 2339 | <?php } ?> |
2340 | 2340 | |
2341 | 2341 | <div class='mt-4 border-top item_totals_total p-2'> |
2342 | 2342 | |
2343 | - <?php if ( wpinv_use_taxes() ) { ?> |
|
2343 | + <?php if (wpinv_use_taxes()) { ?> |
|
2344 | 2344 | <div class='row'> |
2345 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div> |
|
2346 | - <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div> |
|
2345 | + <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div> |
|
2346 | + <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div> |
|
2347 | 2347 | </div> |
2348 | 2348 | <div class='row'> |
2349 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div> |
|
2350 | - <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div> |
|
2349 | + <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div> |
|
2350 | + <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div> |
|
2351 | 2351 | </div> |
2352 | 2352 | <?php } ?> |
2353 | 2353 | <div class='row'> |
2354 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div> |
|
2355 | - <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div> |
|
2354 | + <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div> |
|
2355 | + <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price(wpinv_format_amount($total)) ?></strong></div> |
|
2356 | 2356 | </div> |
2357 | 2357 | </div> |
2358 | 2358 | |
2359 | 2359 | </div> |
2360 | 2360 | <?php } ?> |
2361 | 2361 | |
2362 | - <?php if ( 'multi_select' == $field[ 'items_type' ] ) { ?> |
|
2362 | + <?php if ('multi_select' == $field['items_type']) { ?> |
|
2363 | 2363 | |
2364 | 2364 | <div class="item_totals_type_multi_select"> |
2365 | 2365 | |
@@ -2368,18 +2368,18 @@ discard block |
||
2368 | 2368 | $options = array(); |
2369 | 2369 | $selected = array(); |
2370 | 2370 | |
2371 | - foreach ( $items as $index => $item ) { |
|
2371 | + foreach ($items as $index => $item) { |
|
2372 | 2372 | |
2373 | - if ( ! empty( $item['required'] ) ) { |
|
2373 | + if (!empty($item['required'])) { |
|
2374 | 2374 | continue; |
2375 | 2375 | } |
2376 | 2376 | |
2377 | - $title = sanitize_text_field( $item['title'] ); |
|
2378 | - $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field( $item['price'] ) ) ); |
|
2379 | - $options[ $item['id'] ] = "$title ($price)"; |
|
2377 | + $title = sanitize_text_field($item['title']); |
|
2378 | + $price = wpinv_price(wpinv_format_amount((float) sanitize_text_field($item['price']))); |
|
2379 | + $options[$item['id']] = "$title ($price)"; |
|
2380 | 2380 | |
2381 | - if ( ! isset( $selected_item ) ) { |
|
2382 | - $selected = array( $item['id'] ); |
|
2381 | + if (!isset($selected_item)) { |
|
2382 | + $selected = array($item['id']); |
|
2383 | 2383 | $selected_item = 1; |
2384 | 2384 | } |
2385 | 2385 | |
@@ -2406,31 +2406,31 @@ discard block |
||
2406 | 2406 | $tax = 0; |
2407 | 2407 | $sub_total = 0; |
2408 | 2408 | |
2409 | - foreach ( $items as $item ) { |
|
2409 | + foreach ($items as $item) { |
|
2410 | 2410 | |
2411 | 2411 | $class = 'col-8'; |
2412 | 2412 | $class2 = ''; |
2413 | 2413 | |
2414 | - if ( ! empty( $item['allow_quantities'] ) ) { |
|
2414 | + if (!empty($item['allow_quantities'])) { |
|
2415 | 2415 | $class = 'col-6 pt-2'; |
2416 | 2416 | $class2 = 'pt-2'; |
2417 | 2417 | } |
2418 | 2418 | |
2419 | - if ( ! empty( $item['custom_price'] ) ) { |
|
2419 | + if (!empty($item['custom_price'])) { |
|
2420 | 2420 | $class .= ' pt-2'; |
2421 | 2421 | } |
2422 | 2422 | |
2423 | 2423 | $class3 = 'd-none'; |
2424 | - $name = ''; |
|
2425 | - if ( ! empty( $item['required'] ) || ! isset( $totals_selected_select_item ) ) { |
|
2424 | + $name = ''; |
|
2425 | + if (!empty($item['required']) || !isset($totals_selected_select_item)) { |
|
2426 | 2426 | |
2427 | - $amount = floatval( $item['price'] ); |
|
2428 | - if ( wpinv_use_taxes() ) { |
|
2427 | + $amount = floatval($item['price']); |
|
2428 | + if (wpinv_use_taxes()) { |
|
2429 | 2429 | |
2430 | - $rate = wpinv_get_tax_rate( false, false, (int) $item['id'] ); |
|
2430 | + $rate = wpinv_get_tax_rate(false, false, (int) $item['id']); |
|
2431 | 2431 | |
2432 | - if ( wpinv_prices_include_tax() ) { |
|
2433 | - $pre_tax = ( $amount - $amount * $rate * 0.01 ); |
|
2432 | + if (wpinv_prices_include_tax()) { |
|
2433 | + $pre_tax = ($amount - $amount * $rate * 0.01); |
|
2434 | 2434 | $item_tax = $amount - $pre_tax; |
2435 | 2435 | } else { |
2436 | 2436 | $pre_tax = $amount; |
@@ -2442,13 +2442,13 @@ discard block |
||
2442 | 2442 | $total = $sub_total + $tax; |
2443 | 2443 | |
2444 | 2444 | } else { |
2445 | - $total = $total + $amount; |
|
2445 | + $total = $total + $amount; |
|
2446 | 2446 | } |
2447 | 2447 | |
2448 | 2448 | $class3 = ''; |
2449 | - $name = "wpinv-items[{$item['id']}]"; |
|
2449 | + $name = "wpinv-items[{$item['id']}]"; |
|
2450 | 2450 | |
2451 | - if ( empty( $item['required'] ) ) { |
|
2451 | + if (empty($item['required'])) { |
|
2452 | 2452 | $totals_selected_select_item = 1; |
2453 | 2453 | } |
2454 | 2454 | |
@@ -2460,9 +2460,9 @@ discard block |
||
2460 | 2460 | |
2461 | 2461 | <div class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>"> |
2462 | 2462 | <div class='row pl-2 pr-2 pt-2'> |
2463 | - <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div> |
|
2463 | + <div class='<?php echo $class; ?>'><?php echo esc_html($item['title']) ?></div> |
|
2464 | 2464 | |
2465 | - <?php if ( ! empty( $item['allow_quantities'] ) ) { ?> |
|
2465 | + <?php if (!empty($item['allow_quantities'])) { ?> |
|
2466 | 2466 | |
2467 | 2467 | <div class='col-2'> |
2468 | 2468 | <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required> |
@@ -2470,11 +2470,11 @@ discard block |
||
2470 | 2470 | |
2471 | 2471 | <?php } else { ?> |
2472 | 2472 | <input type='hidden' class='wpinv-item-quantity-input' value='1'> |
2473 | - <?php } if ( empty( $item['custom_price'] ) ) { ?> |
|
2473 | + <?php } if (empty($item['custom_price'])) { ?> |
|
2474 | 2474 | |
2475 | 2475 | <div class='col-4 <?php echo $class2; ?>'> |
2476 | - <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?> |
|
2477 | - <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'> |
|
2476 | + <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?> |
|
2477 | + <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'> |
|
2478 | 2478 | </div> |
2479 | 2479 | |
2480 | 2480 | <?php } else {?> |
@@ -2482,15 +2482,15 @@ discard block |
||
2482 | 2482 | <div class='col-4'> |
2483 | 2483 | <div class='input-group'> |
2484 | 2484 | |
2485 | - <?php if ( 'left' == wpinv_currency_position() ) { ?> |
|
2485 | + <?php if ('left' == wpinv_currency_position()) { ?> |
|
2486 | 2486 | <div class='input-group-prepend'> |
2487 | 2487 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
2488 | 2488 | </div> |
2489 | 2489 | <?php } ?> |
2490 | 2490 | |
2491 | - <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'> |
|
2491 | + <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval($item['price']); ?>' value='<?php echo floatval($item['price']); ?>' min='<?php echo intval($item['minimum_price']); ?>'> |
|
2492 | 2492 | |
2493 | - <?php if ( 'left' != wpinv_currency_position() ) { ?> |
|
2493 | + <?php if ('left' != wpinv_currency_position()) { ?> |
|
2494 | 2494 | <div class='input-group-append'> |
2495 | 2495 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
2496 | 2496 | </div> |
@@ -2501,35 +2501,35 @@ discard block |
||
2501 | 2501 | <?php } ?> |
2502 | 2502 | |
2503 | 2503 | </div> |
2504 | - <?php if ( ! empty( $item['description'] )) { ?> |
|
2505 | - <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small> |
|
2504 | + <?php if (!empty($item['description'])) { ?> |
|
2505 | + <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small> |
|
2506 | 2506 | <?php } ?> |
2507 | 2507 | </div> |
2508 | 2508 | <?php } ?> |
2509 | 2509 | |
2510 | 2510 | <div class='mt-4 border-top item_totals_total p-2'> |
2511 | 2511 | |
2512 | - <?php if ( wpinv_use_taxes() ) { ?> |
|
2512 | + <?php if (wpinv_use_taxes()) { ?> |
|
2513 | 2513 | <div class='row'> |
2514 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div> |
|
2515 | - <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div> |
|
2514 | + <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div> |
|
2515 | + <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div> |
|
2516 | 2516 | </div> |
2517 | 2517 | <div class='row'> |
2518 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div> |
|
2519 | - <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div> |
|
2518 | + <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div> |
|
2519 | + <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div> |
|
2520 | 2520 | </div> |
2521 | 2521 | <?php } ?> |
2522 | 2522 | |
2523 | 2523 | <div class='row'> |
2524 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div> |
|
2525 | - <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div> |
|
2524 | + <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div> |
|
2525 | + <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price(wpinv_format_amount($total)) ?></strong></div> |
|
2526 | 2526 | </div> |
2527 | 2527 | </div> |
2528 | 2528 | |
2529 | 2529 | </div> |
2530 | 2530 | <?php } ?> |
2531 | - <?php if ( ! empty( $field[ 'description' ] ) ) { ?> |
|
2532 | - <small class='form-text text-muted'><?php echo wp_kses_post( $field[ 'description' ] ); ?></small> |
|
2531 | + <?php if (!empty($field['description'])) { ?> |
|
2532 | + <small class='form-text text-muted'><?php echo wp_kses_post($field['description']); ?></small> |
|
2533 | 2533 | <?php } ?> |
2534 | 2534 | </div> |
2535 | 2535 | <?php |
@@ -2538,20 +2538,20 @@ discard block |
||
2538 | 2538 | /** |
2539 | 2539 | * Renders the items element template. |
2540 | 2540 | */ |
2541 | - public function edit_items_template( $field ) { |
|
2542 | - $restrict = $this->get_restrict_markup( $field, 'items' ); |
|
2543 | - $label = __( 'Let customers...', 'invoicing' ); |
|
2544 | - $label2 = __( 'Available Items', 'invoicing' ); |
|
2545 | - $label3 = esc_attr__( 'Add some help text for this element', 'invoicing' ); |
|
2541 | + public function edit_items_template($field) { |
|
2542 | + $restrict = $this->get_restrict_markup($field, 'items'); |
|
2543 | + $label = __('Let customers...', 'invoicing'); |
|
2544 | + $label2 = __('Available Items', 'invoicing'); |
|
2545 | + $label3 = esc_attr__('Add some help text for this element', 'invoicing'); |
|
2546 | 2546 | $id = $field . '.id + "_edit"'; |
2547 | 2547 | $id2 = $field . '.id + "_edit2"'; |
2548 | 2548 | $id3 = $field . '.id + "_edit3"'; |
2549 | 2549 | $id4 = $field . '.id + "_edit4"'; |
2550 | - $label4 = esc_attr__( 'This will be shown to the customer as the recommended price', 'invoicing' ); |
|
2551 | - $label5 = esc_attr__( 'Allow users to pay what they want', 'invoicing' ); |
|
2552 | - $label6 = esc_attr__( 'Enter the minimum price that a user can pay', 'invoicing' ); |
|
2553 | - $label7 = esc_attr__( 'Allow users to buy several quantities', 'invoicing' ); |
|
2554 | - $label8 = esc_attr__( 'This item is required', 'invoicing' ); |
|
2550 | + $label4 = esc_attr__('This will be shown to the customer as the recommended price', 'invoicing'); |
|
2551 | + $label5 = esc_attr__('Allow users to pay what they want', 'invoicing'); |
|
2552 | + $label6 = esc_attr__('Enter the minimum price that a user can pay', 'invoicing'); |
|
2553 | + $label7 = esc_attr__('Allow users to buy several quantities', 'invoicing'); |
|
2554 | + $label8 = esc_attr__('This item is required', 'invoicing'); |
|
2555 | 2555 | echo "<div $restrict> |
2556 | 2556 | |
2557 | 2557 | <label>$label2</label> |
@@ -2621,7 +2621,7 @@ discard block |
||
2621 | 2621 | <div class='form-group mt-2'> |
2622 | 2622 | |
2623 | 2623 | <select class='form-control custom-select' v-model='selected_item' @change='addSelectedItem'> |
2624 | - <option value=''>" . __( 'Add an existing item to the form', 'invoicing' ) ."</option> |
|
2624 | + <option value=''>" . __('Add an existing item to the form', 'invoicing') . "</option> |
|
2625 | 2625 | <option v-for='(item, index) in all_items' :value='index'>{{item.title}}</option> |
2626 | 2626 | </select> |
2627 | 2627 | |
@@ -2636,11 +2636,11 @@ discard block |
||
2636 | 2636 | <label :for='$id2'>$label</label> |
2637 | 2637 | |
2638 | 2638 | <select class='form-control custom-select' :id='$id2' v-model='$field.items_type'> |
2639 | - <option value='total'>" . __( 'Buy all items on the list', 'invoicing' ) ."</option> |
|
2640 | - <option value='radio'>" . __( 'Select a single item from the list', 'invoicing' ) ."</option> |
|
2641 | - <option value='checkbox'>" . __( 'Select one or more items on the list', 'invoicing' ) ."</option> |
|
2642 | - <option value='select'>" . __( 'Select a single item from a dropdown', 'invoicing' ) ."</option> |
|
2643 | - <option value='multi_select'>" . __( 'Select a one or more items from a dropdown', 'invoicing' ) ."</option> |
|
2639 | + <option value='total'>" . __('Buy all items on the list', 'invoicing') . "</option> |
|
2640 | + <option value='radio'>" . __('Select a single item from the list', 'invoicing') . "</option> |
|
2641 | + <option value='checkbox'>" . __('Select one or more items on the list', 'invoicing') . "</option> |
|
2642 | + <option value='select'>" . __('Select a single item from a dropdown', 'invoicing') . "</option> |
|
2643 | + <option value='multi_select'>" . __('Select a one or more items from a dropdown', 'invoicing') . "</option> |
|
2644 | 2644 | </select> |
2645 | 2645 | |
2646 | 2646 | </div> |
@@ -2665,27 +2665,27 @@ discard block |
||
2665 | 2665 | 'orderby' => 'title', |
2666 | 2666 | 'order' => 'ASC', |
2667 | 2667 | 'posts_per_page' => -1, |
2668 | - 'post_status' => array( 'publish' ), |
|
2668 | + 'post_status' => array('publish'), |
|
2669 | 2669 | ); |
2670 | 2670 | |
2671 | - $items = get_posts( apply_filters( 'wpinv_item_dropdown_query_args', $item_args ) ); |
|
2671 | + $items = get_posts(apply_filters('wpinv_item_dropdown_query_args', $item_args)); |
|
2672 | 2672 | |
2673 | - if ( empty( $items ) ) { |
|
2673 | + if (empty($items)) { |
|
2674 | 2674 | return array(); |
2675 | 2675 | } |
2676 | 2676 | |
2677 | - $options = array(); |
|
2678 | - foreach ( $items as $item ) { |
|
2679 | - $title = esc_html( $item->post_title ); |
|
2680 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
2681 | - $id = absint( $item->ID ); |
|
2682 | - $price = wpinv_sanitize_amount( get_post_meta( $id, '_wpinv_price', true ) ); |
|
2683 | - $recurring = (bool) get_post_meta( $id, '_wpinv_is_recurring', true ); |
|
2677 | + $options = array(); |
|
2678 | + foreach ($items as $item) { |
|
2679 | + $title = esc_html($item->post_title); |
|
2680 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
2681 | + $id = absint($item->ID); |
|
2682 | + $price = wpinv_sanitize_amount(get_post_meta($id, '_wpinv_price', true)); |
|
2683 | + $recurring = (bool) get_post_meta($id, '_wpinv_is_recurring', true); |
|
2684 | 2684 | $description = $item->post_excerpt; |
2685 | - $custom_price = (bool) get_post_meta( $id, '_wpinv_dynamic_pricing', true ); |
|
2686 | - $minimum_price = (float) get_post_meta( $id, '_minimum_price', true ); |
|
2685 | + $custom_price = (bool) get_post_meta($id, '_wpinv_dynamic_pricing', true); |
|
2686 | + $minimum_price = (float) get_post_meta($id, '_minimum_price', true); |
|
2687 | 2687 | $allow_quantities = false; |
2688 | - $options[] = compact( 'title', 'id', 'price', 'recurring', 'description', 'custom_price', 'minimum_price', 'allow_quantities' ); |
|
2688 | + $options[] = compact('title', 'id', 'price', 'recurring', 'description', 'custom_price', 'minimum_price', 'allow_quantities'); |
|
2689 | 2689 | |
2690 | 2690 | } |
2691 | 2691 | return $options; |
@@ -2695,47 +2695,47 @@ discard block |
||
2695 | 2695 | /** |
2696 | 2696 | * Returns an array of items for the currently being edited form. |
2697 | 2697 | */ |
2698 | - public function get_form_items( $id = false ) { |
|
2698 | + public function get_form_items($id = false) { |
|
2699 | 2699 | |
2700 | - if ( empty( $id ) ) { |
|
2701 | - return wpinv_get_data( 'sample-payment-form-items' ); |
|
2700 | + if (empty($id)) { |
|
2701 | + return wpinv_get_data('sample-payment-form-items'); |
|
2702 | 2702 | } |
2703 | 2703 | |
2704 | - $form_elements = get_post_meta( $id, 'wpinv_form_items', true ); |
|
2704 | + $form_elements = get_post_meta($id, 'wpinv_form_items', true); |
|
2705 | 2705 | |
2706 | - if ( is_array( $form_elements ) ) { |
|
2706 | + if (is_array($form_elements)) { |
|
2707 | 2707 | return $form_elements; |
2708 | 2708 | } |
2709 | 2709 | |
2710 | - return wpinv_get_data( 'sample-payment-form-items' ); |
|
2710 | + return wpinv_get_data('sample-payment-form-items'); |
|
2711 | 2711 | |
2712 | 2712 | } |
2713 | 2713 | |
2714 | 2714 | /** |
2715 | 2715 | * Returns an array of elements for the currently being edited form. |
2716 | 2716 | */ |
2717 | - public function get_form_elements( $id = false ) { |
|
2717 | + public function get_form_elements($id = false) { |
|
2718 | 2718 | |
2719 | - if ( empty( $id ) ) { |
|
2720 | - return wpinv_get_data( 'sample-payment-form' ); |
|
2719 | + if (empty($id)) { |
|
2720 | + return wpinv_get_data('sample-payment-form'); |
|
2721 | 2721 | } |
2722 | 2722 | |
2723 | - $form_elements = get_post_meta( $id, 'wpinv_form_elements', true ); |
|
2723 | + $form_elements = get_post_meta($id, 'wpinv_form_elements', true); |
|
2724 | 2724 | |
2725 | - if ( is_array( $form_elements ) ) { |
|
2725 | + if (is_array($form_elements)) { |
|
2726 | 2726 | return $form_elements; |
2727 | 2727 | } |
2728 | 2728 | |
2729 | - return wpinv_get_data( 'sample-payment-form' ); |
|
2729 | + return wpinv_get_data('sample-payment-form'); |
|
2730 | 2730 | } |
2731 | 2731 | |
2732 | 2732 | /** |
2733 | 2733 | * Sends a redrect response to payment details. |
2734 | 2734 | * |
2735 | 2735 | */ |
2736 | - public function send_redirect_response( $url ) { |
|
2737 | - $url = urlencode( $url ); |
|
2738 | - wp_send_json_success( $url ); |
|
2736 | + public function send_redirect_response($url) { |
|
2737 | + $url = urlencode($url); |
|
2738 | + wp_send_json_success($url); |
|
2739 | 2739 | } |
2740 | 2740 | |
2741 | 2741 | /** |
@@ -2746,12 +2746,12 @@ discard block |
||
2746 | 2746 | |
2747 | 2747 | $errors = wpinv_get_errors(); |
2748 | 2748 | |
2749 | - if ( ! empty( $errors ) ) { |
|
2749 | + if (!empty($errors)) { |
|
2750 | 2750 | wpinv_print_errors(); |
2751 | 2751 | exit; |
2752 | 2752 | } |
2753 | 2753 | |
2754 | - wp_send_json_error( __( 'An error occured while processing your payment. Please try again.', 'invoicing' ) ); |
|
2754 | + wp_send_json_error(__('An error occured while processing your payment. Please try again.', 'invoicing')); |
|
2755 | 2755 | exit; |
2756 | 2756 | |
2757 | 2757 | } |
@@ -7,28 +7,28 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | class WPInv_Ajax { |
15 | 15 | public static function init() { |
16 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
17 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
16 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
17 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
18 | 18 | self::add_ajax_events(); |
19 | 19 | } |
20 | 20 | |
21 | 21 | public static function define_ajax() { |
22 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
23 | - if ( ! defined( 'DOING_AJAX' ) ) { |
|
24 | - define( 'DOING_AJAX', true ); |
|
22 | + if (!empty($_GET['wpinv-ajax'])) { |
|
23 | + if (!defined('DOING_AJAX')) { |
|
24 | + define('DOING_AJAX', true); |
|
25 | 25 | } |
26 | - if ( ! defined( 'WC_DOING_AJAX' ) ) { |
|
27 | - define( 'WC_DOING_AJAX', true ); |
|
26 | + if (!defined('WC_DOING_AJAX')) { |
|
27 | + define('WC_DOING_AJAX', true); |
|
28 | 28 | } |
29 | 29 | // Turn off display_errors during AJAX events to prevent malformed JSON |
30 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
31 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
30 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
31 | + /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0); |
|
32 | 32 | } |
33 | 33 | $GLOBALS['wpdb']->hide_errors(); |
34 | 34 | } |
@@ -37,24 +37,24 @@ discard block |
||
37 | 37 | public static function do_wpinv_ajax() { |
38 | 38 | global $wp_query; |
39 | 39 | |
40 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
41 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) ); |
|
40 | + if (!empty($_GET['wpinv-ajax'])) { |
|
41 | + $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax'])); |
|
42 | 42 | } |
43 | 43 | |
44 | - if ( $action = $wp_query->get( 'wpinv-ajax' ) ) { |
|
44 | + if ($action = $wp_query->get('wpinv-ajax')) { |
|
45 | 45 | self::wpinv_ajax_headers(); |
46 | - do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) ); |
|
46 | + do_action('wpinv_ajax_' . sanitize_text_field($action)); |
|
47 | 47 | die(); |
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | 51 | private static function wpinv_ajax_headers() { |
52 | 52 | send_origin_headers(); |
53 | - /** @scrutinizer ignore-unhandled */ @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
54 | - /** @scrutinizer ignore-unhandled */ @header( 'X-Robots-Tag: noindex' ); |
|
53 | + /** @scrutinizer ignore-unhandled */ @header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
54 | + /** @scrutinizer ignore-unhandled */ @header('X-Robots-Tag: noindex'); |
|
55 | 55 | send_nosniff_header(); |
56 | 56 | nocache_headers(); |
57 | - status_header( 200 ); |
|
57 | + status_header(200); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | public static function add_ajax_events() { |
@@ -79,39 +79,39 @@ discard block |
||
79 | 79 | 'buy_items' => true, |
80 | 80 | ); |
81 | 81 | |
82 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
83 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
82 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
83 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
84 | 84 | |
85 | - if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) { |
|
86 | - define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 ); |
|
85 | + if (!defined('WPI_AJAX_' . strtoupper($nopriv))) { |
|
86 | + define('WPI_AJAX_' . strtoupper($nopriv), 1); |
|
87 | 87 | } |
88 | 88 | |
89 | - if ( $nopriv ) { |
|
90 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
89 | + if ($nopriv) { |
|
90 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
91 | 91 | |
92 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
92 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
93 | 93 | } |
94 | 94 | } |
95 | 95 | } |
96 | 96 | |
97 | 97 | public static function add_note() { |
98 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
98 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
99 | 99 | |
100 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
100 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
101 | 101 | die(-1); |
102 | 102 | } |
103 | 103 | |
104 | - $post_id = absint( $_POST['post_id'] ); |
|
105 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
106 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
104 | + $post_id = absint($_POST['post_id']); |
|
105 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
106 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
107 | 107 | |
108 | 108 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
109 | 109 | |
110 | - if ( $post_id > 0 ) { |
|
111 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
110 | + if ($post_id > 0) { |
|
111 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
112 | 112 | |
113 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
114 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
113 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
114 | + wpinv_get_invoice_note_line_item($note_id); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
@@ -119,16 +119,16 @@ discard block |
||
119 | 119 | } |
120 | 120 | |
121 | 121 | public static function delete_note() { |
122 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
122 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
123 | 123 | |
124 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
124 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
125 | 125 | die(-1); |
126 | 126 | } |
127 | 127 | |
128 | - $note_id = (int)$_POST['note_id']; |
|
128 | + $note_id = (int) $_POST['note_id']; |
|
129 | 129 | |
130 | - if ( $note_id > 0 ) { |
|
131 | - wp_delete_comment( $note_id, true ); |
|
130 | + if ($note_id > 0) { |
|
131 | + wp_delete_comment($note_id, true); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | die(); |
@@ -141,8 +141,8 @@ discard block |
||
141 | 141 | } |
142 | 142 | |
143 | 143 | public static function checkout() { |
144 | - if ( ! defined( 'WPINV_CHECKOUT' ) ) { |
|
145 | - define( 'WPINV_CHECKOUT', true ); |
|
144 | + if (!defined('WPINV_CHECKOUT')) { |
|
145 | + define('WPINV_CHECKOUT', true); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | wpinv_process_checkout(); |
@@ -151,53 +151,53 @@ discard block |
||
151 | 151 | |
152 | 152 | public static function add_invoice_item() { |
153 | 153 | global $wpi_userID, $wpinv_ip_address_country; |
154 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
155 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
154 | + check_ajax_referer('invoice-item', '_nonce'); |
|
155 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
156 | 156 | die(-1); |
157 | 157 | } |
158 | 158 | |
159 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
160 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
159 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
160 | + $invoice_id = absint($_POST['invoice_id']); |
|
161 | 161 | |
162 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
162 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
163 | 163 | die(); |
164 | 164 | } |
165 | 165 | |
166 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
167 | - if ( empty( $invoice ) ) { |
|
166 | + $invoice = wpinv_get_invoice($invoice_id); |
|
167 | + if (empty($invoice)) { |
|
168 | 168 | die(); |
169 | 169 | } |
170 | 170 | |
171 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
171 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
172 | 172 | die(); // Don't allow modify items for paid invoice. |
173 | 173 | } |
174 | 174 | |
175 | - if ( !empty( $_POST['user_id'] ) ) { |
|
176 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
175 | + if (!empty($_POST['user_id'])) { |
|
176 | + $wpi_userID = absint($_POST['user_id']); |
|
177 | 177 | } |
178 | 178 | |
179 | - $item = new WPInv_Item( $item_id ); |
|
180 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
179 | + $item = new WPInv_Item($item_id); |
|
180 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
181 | 181 | die(); |
182 | 182 | } |
183 | 183 | |
184 | 184 | // Validate item before adding to invoice because recurring item must be paid individually. |
185 | - if ( !empty( $invoice->cart_details ) ) { |
|
185 | + if (!empty($invoice->cart_details)) { |
|
186 | 186 | $valid = true; |
187 | 187 | |
188 | - if ( $recurring_item = $invoice->get_recurring() ) { |
|
189 | - if ( $recurring_item != $item_id ) { |
|
188 | + if ($recurring_item = $invoice->get_recurring()) { |
|
189 | + if ($recurring_item != $item_id) { |
|
190 | 190 | $valid = false; |
191 | 191 | } |
192 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
192 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
193 | 193 | $valid = false; |
194 | 194 | } |
195 | 195 | |
196 | - if ( !$valid ) { |
|
196 | + if (!$valid) { |
|
197 | 197 | $response = array(); |
198 | 198 | $response['success'] = false; |
199 | - $response['msg'] = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ); |
|
200 | - wp_send_json( $response ); |
|
199 | + $response['msg'] = __('You can not add item because recurring item must be paid individually!', 'invoicing'); |
|
200 | + wp_send_json($response); |
|
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
@@ -205,11 +205,11 @@ discard block |
||
205 | 205 | |
206 | 206 | $data = array(); |
207 | 207 | $data['invoice_id'] = $invoice_id; |
208 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
208 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
209 | 209 | |
210 | - wpinv_set_checkout_session( $data ); |
|
210 | + wpinv_set_checkout_session($data); |
|
211 | 211 | |
212 | - $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1; |
|
212 | + $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int) $_POST['qty'] > 0 ? (int) $_POST['qty'] : 1; |
|
213 | 213 | |
214 | 214 | $args = array( |
215 | 215 | 'id' => $item_id, |
@@ -222,21 +222,21 @@ discard block |
||
222 | 222 | 'fees' => array() |
223 | 223 | ); |
224 | 224 | |
225 | - $invoice->add_item( $item_id, $args ); |
|
225 | + $invoice->add_item($item_id, $args); |
|
226 | 226 | $invoice->save(); |
227 | 227 | |
228 | - if ( empty( $_POST['country'] ) ) { |
|
228 | + if (empty($_POST['country'])) { |
|
229 | 229 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
230 | 230 | } |
231 | - if ( empty( $_POST['state'] ) ) { |
|
231 | + if (empty($_POST['state'])) { |
|
232 | 232 | $_POST['state'] = $invoice->state; |
233 | 233 | } |
234 | 234 | |
235 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
236 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
235 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
236 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
237 | 237 | |
238 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
239 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
238 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
239 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
240 | 240 | |
241 | 241 | $wpinv_ip_address_country = $invoice->country; |
242 | 242 | |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | |
245 | 245 | $response = array(); |
246 | 246 | $response['success'] = true; |
247 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
247 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
248 | 248 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
249 | 249 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
250 | 250 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -256,41 +256,41 @@ discard block |
||
256 | 256 | |
257 | 257 | wpinv_set_checkout_session($checkout_session); |
258 | 258 | |
259 | - wp_send_json( $response ); |
|
259 | + wp_send_json($response); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | |
263 | 263 | public static function remove_invoice_item() { |
264 | 264 | global $wpi_userID, $wpinv_ip_address_country; |
265 | 265 | |
266 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
267 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
266 | + check_ajax_referer('invoice-item', '_nonce'); |
|
267 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
268 | 268 | die(-1); |
269 | 269 | } |
270 | 270 | |
271 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
272 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
273 | - $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
271 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
272 | + $invoice_id = absint($_POST['invoice_id']); |
|
273 | + $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
274 | 274 | |
275 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
275 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
276 | 276 | die(); |
277 | 277 | } |
278 | 278 | |
279 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
280 | - if ( empty( $invoice ) ) { |
|
279 | + $invoice = wpinv_get_invoice($invoice_id); |
|
280 | + if (empty($invoice)) { |
|
281 | 281 | die(); |
282 | 282 | } |
283 | 283 | |
284 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
284 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
285 | 285 | die(); // Don't allow modify items for paid invoice. |
286 | 286 | } |
287 | 287 | |
288 | - if ( !empty( $_POST['user_id'] ) ) { |
|
289 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
288 | + if (!empty($_POST['user_id'])) { |
|
289 | + $wpi_userID = absint($_POST['user_id']); |
|
290 | 290 | } |
291 | 291 | |
292 | - $item = new WPInv_Item( $item_id ); |
|
293 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
292 | + $item = new WPInv_Item($item_id); |
|
293 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
294 | 294 | die(); |
295 | 295 | } |
296 | 296 | |
@@ -298,9 +298,9 @@ discard block |
||
298 | 298 | |
299 | 299 | $data = array(); |
300 | 300 | $data['invoice_id'] = $invoice_id; |
301 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
301 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
302 | 302 | |
303 | - wpinv_set_checkout_session( $data ); |
|
303 | + wpinv_set_checkout_session($data); |
|
304 | 304 | |
305 | 305 | $args = array( |
306 | 306 | 'id' => $item_id, |
@@ -308,21 +308,21 @@ discard block |
||
308 | 308 | 'cart_index' => $cart_index |
309 | 309 | ); |
310 | 310 | |
311 | - $invoice->remove_item( $item_id, $args ); |
|
311 | + $invoice->remove_item($item_id, $args); |
|
312 | 312 | $invoice->save(); |
313 | 313 | |
314 | - if ( empty( $_POST['country'] ) ) { |
|
314 | + if (empty($_POST['country'])) { |
|
315 | 315 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
316 | 316 | } |
317 | - if ( empty( $_POST['state'] ) ) { |
|
317 | + if (empty($_POST['state'])) { |
|
318 | 318 | $_POST['state'] = $invoice->state; |
319 | 319 | } |
320 | 320 | |
321 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
322 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
321 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
322 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
323 | 323 | |
324 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
325 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
324 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
325 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
326 | 326 | |
327 | 327 | $wpinv_ip_address_country = $invoice->country; |
328 | 328 | |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | |
331 | 331 | $response = array(); |
332 | 332 | $response['success'] = true; |
333 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
333 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
334 | 334 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
335 | 335 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
336 | 336 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -342,55 +342,55 @@ discard block |
||
342 | 342 | |
343 | 343 | wpinv_set_checkout_session($checkout_session); |
344 | 344 | |
345 | - wp_send_json( $response ); |
|
345 | + wp_send_json($response); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | public static function create_invoice_item() { |
349 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
350 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
349 | + check_ajax_referer('invoice-item', '_nonce'); |
|
350 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
351 | 351 | die(-1); |
352 | 352 | } |
353 | 353 | |
354 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
354 | + $invoice_id = absint($_POST['invoice_id']); |
|
355 | 355 | |
356 | 356 | // Find the item |
357 | - if ( !is_numeric( $invoice_id ) ) { |
|
357 | + if (!is_numeric($invoice_id)) { |
|
358 | 358 | die(); |
359 | 359 | } |
360 | 360 | |
361 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
362 | - if ( empty( $invoice ) ) { |
|
361 | + $invoice = wpinv_get_invoice($invoice_id); |
|
362 | + if (empty($invoice)) { |
|
363 | 363 | die(); |
364 | 364 | } |
365 | 365 | |
366 | 366 | // Validate item before adding to invoice because recurring item must be paid individually. |
367 | - if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) { |
|
367 | + if (!empty($invoice->cart_details) && $invoice->get_recurring()) { |
|
368 | 368 | $response = array(); |
369 | 369 | $response['success'] = false; |
370 | - $response['msg'] = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ); |
|
371 | - wp_send_json( $response ); |
|
370 | + $response['msg'] = __('You can not add item because recurring item must be paid individually!', 'invoicing'); |
|
371 | + wp_send_json($response); |
|
372 | 372 | } |
373 | 373 | |
374 | - $save_item = wp_unslash( $_POST['_wpinv_quick'] ); |
|
374 | + $save_item = wp_unslash($_POST['_wpinv_quick']); |
|
375 | 375 | |
376 | 376 | $meta = array(); |
377 | 377 | $meta['type'] = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom'; |
378 | - $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0; |
|
378 | + $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0; |
|
379 | 379 | $meta['vat_rule'] = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital'; |
380 | 380 | $meta['vat_class'] = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard'; |
381 | 381 | |
382 | 382 | $data = array(); |
383 | 383 | $data['post_title'] = sanitize_text_field($save_item['name']); |
384 | 384 | $data['post_status'] = 'publish'; |
385 | - $data['post_excerpt'] = ! empty( $save_item['excerpt'] ) ? wp_kses_post( $save_item['excerpt'] ) : ''; |
|
385 | + $data['post_excerpt'] = !empty($save_item['excerpt']) ? wp_kses_post($save_item['excerpt']) : ''; |
|
386 | 386 | $data['meta'] = $meta; |
387 | 387 | |
388 | 388 | $item = new WPInv_Item(); |
389 | - $item->create( $data ); |
|
389 | + $item->create($data); |
|
390 | 390 | |
391 | - if ( !empty( $item ) ) { |
|
391 | + if (!empty($item)) { |
|
392 | 392 | $_POST['item_id'] = $item->ID; |
393 | - $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1; |
|
393 | + $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int) $save_item['qty'] : 1; |
|
394 | 394 | |
395 | 395 | self::add_invoice_item(); |
396 | 396 | } |
@@ -398,15 +398,15 @@ discard block |
||
398 | 398 | } |
399 | 399 | |
400 | 400 | public static function get_billing_details() { |
401 | - check_ajax_referer( 'get-billing-details', '_nonce' ); |
|
401 | + check_ajax_referer('get-billing-details', '_nonce'); |
|
402 | 402 | |
403 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
403 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
404 | 404 | die(-1); |
405 | 405 | } |
406 | 406 | |
407 | - $user_id = (int)$_POST['user_id']; |
|
407 | + $user_id = (int) $_POST['user_id']; |
|
408 | 408 | $billing_details = wpinv_get_user_address($user_id); |
409 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
409 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
410 | 410 | |
411 | 411 | if (isset($billing_details['user_id'])) { |
412 | 412 | unset($billing_details['user_id']); |
@@ -420,20 +420,20 @@ discard block |
||
420 | 420 | $response['success'] = true; |
421 | 421 | $response['data']['billing_details'] = $billing_details; |
422 | 422 | |
423 | - wp_send_json( $response ); |
|
423 | + wp_send_json($response); |
|
424 | 424 | } |
425 | 425 | |
426 | 426 | public static function admin_recalculate_totals() { |
427 | 427 | global $wpi_userID, $wpinv_ip_address_country; |
428 | 428 | |
429 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
430 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
429 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
430 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
431 | 431 | die(-1); |
432 | 432 | } |
433 | 433 | |
434 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
435 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
436 | - if ( empty( $invoice ) ) { |
|
434 | + $invoice_id = absint($_POST['invoice_id']); |
|
435 | + $invoice = wpinv_get_invoice($invoice_id); |
|
436 | + if (empty($invoice)) { |
|
437 | 437 | die(); |
438 | 438 | } |
439 | 439 | |
@@ -441,29 +441,29 @@ discard block |
||
441 | 441 | |
442 | 442 | $data = array(); |
443 | 443 | $data['invoice_id'] = $invoice_id; |
444 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
444 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
445 | 445 | |
446 | - wpinv_set_checkout_session( $data ); |
|
446 | + wpinv_set_checkout_session($data); |
|
447 | 447 | |
448 | - if ( !empty( $_POST['user_id'] ) ) { |
|
449 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
448 | + if (!empty($_POST['user_id'])) { |
|
449 | + $wpi_userID = absint($_POST['user_id']); |
|
450 | 450 | } |
451 | 451 | |
452 | - if ( empty( $_POST['country'] ) ) { |
|
452 | + if (empty($_POST['country'])) { |
|
453 | 453 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
454 | 454 | } |
455 | 455 | |
456 | 456 | $disable_taxes = 0; |
457 | - if ( ! empty( $_POST['disable_taxes'] ) ) { |
|
457 | + if (!empty($_POST['disable_taxes'])) { |
|
458 | 458 | $disable_taxes = 1; |
459 | 459 | } |
460 | - $invoice->set( 'disable_taxes', $disable_taxes ); |
|
460 | + $invoice->set('disable_taxes', $disable_taxes); |
|
461 | 461 | |
462 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
463 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
464 | - if ( isset( $_POST['state'] ) ) { |
|
465 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
466 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
462 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
463 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
464 | + if (isset($_POST['state'])) { |
|
465 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
466 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
467 | 467 | } |
468 | 468 | |
469 | 469 | $wpinv_ip_address_country = $invoice->country; |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | |
473 | 473 | $response = array(); |
474 | 474 | $response['success'] = true; |
475 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
475 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
476 | 476 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
477 | 477 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
478 | 478 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -484,25 +484,25 @@ discard block |
||
484 | 484 | |
485 | 485 | wpinv_set_checkout_session($checkout_session); |
486 | 486 | |
487 | - wp_send_json( $response ); |
|
487 | + wp_send_json($response); |
|
488 | 488 | } |
489 | 489 | |
490 | 490 | public static function admin_apply_discount() { |
491 | 491 | global $wpi_userID; |
492 | 492 | |
493 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
494 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
493 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
494 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
495 | 495 | die(-1); |
496 | 496 | } |
497 | 497 | |
498 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
499 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
500 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
498 | + $invoice_id = absint($_POST['invoice_id']); |
|
499 | + $discount_code = sanitize_text_field($_POST['code']); |
|
500 | + if (empty($invoice_id) || empty($discount_code)) { |
|
501 | 501 | die(); |
502 | 502 | } |
503 | 503 | |
504 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
505 | - if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { |
|
504 | + $invoice = wpinv_get_invoice($invoice_id); |
|
505 | + if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { |
|
506 | 506 | die(); |
507 | 507 | } |
508 | 508 | |
@@ -510,49 +510,49 @@ discard block |
||
510 | 510 | |
511 | 511 | $data = array(); |
512 | 512 | $data['invoice_id'] = $invoice_id; |
513 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
513 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
514 | 514 | |
515 | - wpinv_set_checkout_session( $data ); |
|
515 | + wpinv_set_checkout_session($data); |
|
516 | 516 | |
517 | 517 | $response = array(); |
518 | 518 | $response['success'] = false; |
519 | - $response['msg'] = __( 'This discount is invalid.', 'invoicing' ); |
|
519 | + $response['msg'] = __('This discount is invalid.', 'invoicing'); |
|
520 | 520 | $response['data']['code'] = $discount_code; |
521 | 521 | |
522 | - if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) { |
|
523 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
522 | + if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) { |
|
523 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
524 | 524 | |
525 | 525 | $response['success'] = true; |
526 | - $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' ); |
|
527 | - } else { |
|
526 | + $response['msg'] = __('Discount has been applied successfully.', 'invoicing'); |
|
527 | + } else { |
|
528 | 528 | $errors = wpinv_get_errors(); |
529 | - if ( !empty( $errors['wpinv-discount-error'] ) ) { |
|
529 | + if (!empty($errors['wpinv-discount-error'])) { |
|
530 | 530 | $response['msg'] = $errors['wpinv-discount-error']; |
531 | 531 | } |
532 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
532 | + wpinv_unset_error('wpinv-discount-error'); |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | wpinv_set_checkout_session($checkout_session); |
536 | 536 | |
537 | - wp_send_json( $response ); |
|
537 | + wp_send_json($response); |
|
538 | 538 | } |
539 | 539 | |
540 | 540 | public static function admin_remove_discount() { |
541 | 541 | global $wpi_userID; |
542 | 542 | |
543 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
544 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
543 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
544 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
545 | 545 | die(-1); |
546 | 546 | } |
547 | 547 | |
548 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
549 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
550 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
548 | + $invoice_id = absint($_POST['invoice_id']); |
|
549 | + $discount_code = sanitize_text_field($_POST['code']); |
|
550 | + if (empty($invoice_id) || empty($discount_code)) { |
|
551 | 551 | die(); |
552 | 552 | } |
553 | 553 | |
554 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
555 | - if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { |
|
554 | + $invoice = wpinv_get_invoice($invoice_id); |
|
555 | + if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { |
|
556 | 556 | die(); |
557 | 557 | } |
558 | 558 | |
@@ -560,38 +560,38 @@ discard block |
||
560 | 560 | |
561 | 561 | $data = array(); |
562 | 562 | $data['invoice_id'] = $invoice_id; |
563 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
563 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
564 | 564 | |
565 | - wpinv_set_checkout_session( $data ); |
|
565 | + wpinv_set_checkout_session($data); |
|
566 | 566 | |
567 | 567 | $response = array(); |
568 | 568 | $response['success'] = false; |
569 | 569 | $response['msg'] = NULL; |
570 | 570 | |
571 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
571 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
572 | 572 | $response['success'] = true; |
573 | - $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' ); |
|
573 | + $response['msg'] = __('Discount has been removed successfully.', 'invoicing'); |
|
574 | 574 | |
575 | 575 | wpinv_set_checkout_session($checkout_session); |
576 | 576 | |
577 | - wp_send_json( $response ); |
|
577 | + wp_send_json($response); |
|
578 | 578 | } |
579 | 579 | |
580 | 580 | public static function check_email() { |
581 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
582 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
581 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
582 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
583 | 583 | die(-1); |
584 | 584 | } |
585 | 585 | |
586 | - $email = sanitize_text_field( $_POST['email'] ); |
|
586 | + $email = sanitize_text_field($_POST['email']); |
|
587 | 587 | |
588 | 588 | $response = array(); |
589 | - if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) { |
|
589 | + if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) { |
|
590 | 590 | $user_id = $user_data->ID; |
591 | 591 | $user_login = $user_data->user_login; |
592 | 592 | $display_name = $user_data->display_name ? $user_data->display_name : $user_login; |
593 | 593 | $billing_details = wpinv_get_user_address($user_id); |
594 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
594 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
595 | 595 | |
596 | 596 | if (isset($billing_details['user_id'])) { |
597 | 597 | unset($billing_details['user_id']); |
@@ -607,54 +607,54 @@ discard block |
||
607 | 607 | $response['data']['billing_details'] = $billing_details; |
608 | 608 | } |
609 | 609 | |
610 | - wp_send_json( $response ); |
|
610 | + wp_send_json($response); |
|
611 | 611 | } |
612 | 612 | |
613 | 613 | public static function run_tool() { |
614 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
615 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
614 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
615 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
616 | 616 | die(-1); |
617 | 617 | } |
618 | 618 | |
619 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
619 | + $tool = sanitize_text_field($_POST['tool']); |
|
620 | 620 | |
621 | - do_action( 'wpinv_run_tool' ); |
|
621 | + do_action('wpinv_run_tool'); |
|
622 | 622 | |
623 | - if ( !empty( $tool ) ) { |
|
624 | - do_action( 'wpinv_tool_' . $tool ); |
|
623 | + if (!empty($tool)) { |
|
624 | + do_action('wpinv_tool_' . $tool); |
|
625 | 625 | } |
626 | 626 | } |
627 | 627 | |
628 | 628 | public static function apply_discount() { |
629 | 629 | global $wpi_userID; |
630 | 630 | |
631 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
631 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
632 | 632 | |
633 | 633 | $response = array(); |
634 | 634 | |
635 | - if ( isset( $_POST['code'] ) ) { |
|
636 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
635 | + if (isset($_POST['code'])) { |
|
636 | + $discount_code = sanitize_text_field($_POST['code']); |
|
637 | 637 | |
638 | 638 | $response['success'] = false; |
639 | 639 | $response['msg'] = ''; |
640 | 640 | $response['data']['code'] = $discount_code; |
641 | 641 | |
642 | 642 | $invoice = wpinv_get_invoice_cart(); |
643 | - if ( empty( $invoice->ID ) ) { |
|
644 | - $response['msg'] = __( 'Invalid checkout request.', 'invoicing' ); |
|
645 | - wp_send_json( $response ); |
|
643 | + if (empty($invoice->ID)) { |
|
644 | + $response['msg'] = __('Invalid checkout request.', 'invoicing'); |
|
645 | + wp_send_json($response); |
|
646 | 646 | } |
647 | 647 | |
648 | 648 | $wpi_userID = $invoice->get_user_id(); |
649 | 649 | |
650 | - if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) { |
|
651 | - $discount = wpinv_get_discount_by_code( $discount_code ); |
|
652 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
653 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
654 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
655 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
650 | + if (wpinv_is_discount_valid($discount_code, $wpi_userID)) { |
|
651 | + $discount = wpinv_get_discount_by_code($discount_code); |
|
652 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
653 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
654 | + $total = wpinv_get_cart_total(null, $discounts); |
|
655 | + $cart_totals = wpinv_recalculate_tax(true); |
|
656 | 656 | |
657 | - if ( !empty( $cart_totals ) ) { |
|
657 | + if (!empty($cart_totals)) { |
|
658 | 658 | $response['success'] = true; |
659 | 659 | $response['data'] = $cart_totals; |
660 | 660 | $response['data']['code'] = $discount_code; |
@@ -663,29 +663,29 @@ discard block |
||
663 | 663 | } |
664 | 664 | } else { |
665 | 665 | $errors = wpinv_get_errors(); |
666 | - $response['msg'] = $errors['wpinv-discount-error']; |
|
667 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
666 | + $response['msg'] = $errors['wpinv-discount-error']; |
|
667 | + wpinv_unset_error('wpinv-discount-error'); |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | // Allow for custom discount code handling |
671 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
671 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
672 | 672 | } |
673 | 673 | |
674 | - wp_send_json( $response ); |
|
674 | + wp_send_json($response); |
|
675 | 675 | } |
676 | 676 | |
677 | 677 | public static function remove_discount() { |
678 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
678 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
679 | 679 | |
680 | 680 | $response = array(); |
681 | 681 | |
682 | - if ( isset( $_POST['code'] ) ) { |
|
683 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
684 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
685 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
686 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
682 | + if (isset($_POST['code'])) { |
|
683 | + $discount_code = sanitize_text_field($_POST['code']); |
|
684 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
685 | + $total = wpinv_get_cart_total(null, $discounts); |
|
686 | + $cart_totals = wpinv_recalculate_tax(true); |
|
687 | 687 | |
688 | - if ( !empty( $cart_totals ) ) { |
|
688 | + if (!empty($cart_totals)) { |
|
689 | 689 | $response['success'] = true; |
690 | 690 | $response['data'] = $cart_totals; |
691 | 691 | $response['data']['code'] = $discount_code; |
@@ -694,10 +694,10 @@ discard block |
||
694 | 694 | } |
695 | 695 | |
696 | 696 | // Allow for custom discount code handling |
697 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
697 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
698 | 698 | } |
699 | 699 | |
700 | - wp_send_json( $response ); |
|
700 | + wp_send_json($response); |
|
701 | 701 | } |
702 | 702 | |
703 | 703 | /** |
@@ -709,75 +709,75 @@ discard block |
||
709 | 709 | global $invoicing, $wpi_checkout_id, $cart_total; |
710 | 710 | |
711 | 711 | // Check nonce. |
712 | - if ( ! isset( $_POST['wpinv_payment_form'] ) || ! wp_verify_nonce( $_POST['wpinv_payment_form'], 'wpinv_payment_form' ) ) { |
|
713 | - wp_send_json_error( __( 'Security checks failed.', 'invoicing' ) ); |
|
712 | + if (!isset($_POST['wpinv_payment_form']) || !wp_verify_nonce($_POST['wpinv_payment_form'], 'wpinv_payment_form')) { |
|
713 | + wp_send_json_error(__('Security checks failed.', 'invoicing')); |
|
714 | 714 | } |
715 | 715 | |
716 | 716 | // Prepare submitted data... |
717 | - $data = wp_unslash( $_POST ); |
|
717 | + $data = wp_unslash($_POST); |
|
718 | 718 | |
719 | 719 | // ... form fields... |
720 | - if ( empty( $data['form_id'] ) || 'publish' != get_post_status( $data['form_id'] ) ) { |
|
721 | - wp_send_json_error( __( 'This payment form is no longer active.', 'invoicing' ) ); |
|
720 | + if (empty($data['form_id']) || 'publish' != get_post_status($data['form_id'])) { |
|
721 | + wp_send_json_error(__('This payment form is no longer active.', 'invoicing')); |
|
722 | 722 | } |
723 | 723 | |
724 | - if ( empty( $data['billing_email'] ) || ! is_email( $data['billing_email'] ) ) { |
|
725 | - wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
|
724 | + if (empty($data['billing_email']) || !is_email($data['billing_email'])) { |
|
725 | + wp_send_json_error(__('Provide a valid billing email.', 'invoicing')); |
|
726 | 726 | } |
727 | 727 | |
728 | 728 | $prepared = array( |
729 | - 'billing_email' => sanitize_email( $data['billing_email'] ), |
|
730 | - __( 'Billing Email', 'invoicing' ) => sanitize_email( $data['billing_email'] ), |
|
731 | - __( 'Form Id', 'invoicing' ) => absint( $data['form_id'] ), |
|
729 | + 'billing_email' => sanitize_email($data['billing_email']), |
|
730 | + __('Billing Email', 'invoicing') => sanitize_email($data['billing_email']), |
|
731 | + __('Form Id', 'invoicing') => absint($data['form_id']), |
|
732 | 732 | ); |
733 | 733 | |
734 | - $prepared['billing_email'] = sanitize_email( $data['billing_email'] ); |
|
734 | + $prepared['billing_email'] = sanitize_email($data['billing_email']); |
|
735 | 735 | |
736 | - $fields = $invoicing->form_elements->get_form_elements( $data['form_id'] ); |
|
736 | + $fields = $invoicing->form_elements->get_form_elements($data['form_id']); |
|
737 | 737 | |
738 | 738 | // ... and form items. |
739 | - $items = $invoicing->form_elements->get_form_items( $data['form_id'] ); |
|
739 | + $items = $invoicing->form_elements->get_form_items($data['form_id']); |
|
740 | 740 | $prepared_items = array(); |
741 | 741 | $address_fields = array(); |
742 | 742 | |
743 | - if ( ! empty( $data['wpinv-items'] ) ) { |
|
743 | + if (!empty($data['wpinv-items'])) { |
|
744 | 744 | |
745 | - $selected_items = wpinv_clean( $data['wpinv-items'] ); |
|
745 | + $selected_items = wpinv_clean($data['wpinv-items']); |
|
746 | 746 | |
747 | - foreach ( $items as $item ) { |
|
747 | + foreach ($items as $item) { |
|
748 | 748 | |
749 | - if ( ! empty( $item['required'] ) && ! isset( $selected_items[ $item['id'] ] ) ) { |
|
750 | - wp_send_json_error( __( 'A required item is missing.', 'invoicing' ) ); |
|
749 | + if (!empty($item['required']) && !isset($selected_items[$item['id']])) { |
|
750 | + wp_send_json_error(__('A required item is missing.', 'invoicing')); |
|
751 | 751 | } |
752 | 752 | |
753 | - if ( ! isset( $selected_items[ $item['id'] ] ) ) { |
|
753 | + if (!isset($selected_items[$item['id']])) { |
|
754 | 754 | continue; |
755 | 755 | } |
756 | 756 | |
757 | 757 | $quantity = 1; |
758 | 758 | |
759 | - if ( ! empty( $item['allow_quantities'] ) && ! empty( $data["wpinv-item-{$item['id']}-quantity"] ) ) { |
|
759 | + if (!empty($item['allow_quantities']) && !empty($data["wpinv-item-{$item['id']}-quantity"])) { |
|
760 | 760 | |
761 | - $quantity = intval( $data["wpinv-item-{$item['id']}-quantity"] ); |
|
761 | + $quantity = intval($data["wpinv-item-{$item['id']}-quantity"]); |
|
762 | 762 | |
763 | - if ( empty( $quantity ) ) { |
|
763 | + if (empty($quantity)) { |
|
764 | 764 | $quantity = 1; |
765 | 765 | } |
766 | 766 | } |
767 | 767 | |
768 | 768 | // Custom pricing. |
769 | - if ( ! empty( $item['custom_price'] ) ) { |
|
769 | + if (!empty($item['custom_price'])) { |
|
770 | 770 | |
771 | - $minimum_price = wpinv_sanitize_amount( $item['minimum_price'] ); |
|
772 | - $set_price = wpinv_sanitize_amount( $selected_items[ $item['id'] ] ); |
|
771 | + $minimum_price = wpinv_sanitize_amount($item['minimum_price']); |
|
772 | + $set_price = wpinv_sanitize_amount($selected_items[$item['id']]); |
|
773 | 773 | |
774 | - if ( $set_price < $minimum_price ) { |
|
775 | - wp_send_json_error( __( 'The provided amount is less than the minimum allowed value.', 'invoicing' ) ); |
|
774 | + if ($set_price < $minimum_price) { |
|
775 | + wp_send_json_error(__('The provided amount is less than the minimum allowed value.', 'invoicing')); |
|
776 | 776 | } |
777 | 777 | |
778 | 778 | $prepared_items[] = array( |
779 | 779 | 'id' =>$item['id'], |
780 | - 'item_price' => wpinv_sanitize_amount( $item['price'] ), |
|
780 | + 'item_price' => wpinv_sanitize_amount($item['price']), |
|
781 | 781 | 'custom_price' => $set_price, |
782 | 782 | 'name' => $item['title'], |
783 | 783 | 'quantity' => $quantity, |
@@ -787,8 +787,8 @@ discard block |
||
787 | 787 | |
788 | 788 | $prepared_items[] = array( |
789 | 789 | 'id' => $item['id'], |
790 | - 'item_price' => wpinv_sanitize_amount( $item['price'] ), |
|
791 | - 'custom_price' => wpinv_sanitize_amount( $item['price'] ), |
|
790 | + 'item_price' => wpinv_sanitize_amount($item['price']), |
|
791 | + 'custom_price' => wpinv_sanitize_amount($item['price']), |
|
792 | 792 | 'name' => $item['title'], |
793 | 793 | 'quantity' => $quantity, |
794 | 794 | ); |
@@ -799,64 +799,64 @@ discard block |
||
799 | 799 | |
800 | 800 | } else { |
801 | 801 | |
802 | - wp_send_json_error( __( 'You have not selected any items.', 'invoicing' ) ); |
|
802 | + wp_send_json_error(__('You have not selected any items.', 'invoicing')); |
|
803 | 803 | |
804 | 804 | } |
805 | 805 | |
806 | 806 | // Are all required fields provided? |
807 | - foreach ( $fields as $field ) { |
|
807 | + foreach ($fields as $field) { |
|
808 | 808 | |
809 | - if ( ! empty( $field['premade'] ) ) { |
|
809 | + if (!empty($field['premade'])) { |
|
810 | 810 | continue; |
811 | 811 | } |
812 | 812 | |
813 | - if ( ! empty( $field['required'] ) && empty( $data[ $field['id'] ] ) ) { |
|
814 | - wp_send_json_error( __( 'Some required fields have not been filled.', 'invoicing' ) ); |
|
813 | + if (!empty($field['required']) && empty($data[$field['id']])) { |
|
814 | + wp_send_json_error(__('Some required fields have not been filled.', 'invoicing')); |
|
815 | 815 | } |
816 | 816 | |
817 | - if ( $field['type'] == 'address' ) { |
|
817 | + if ($field['type'] == 'address') { |
|
818 | 818 | |
819 | - foreach ( $field['fields'] as $address_field ) { |
|
819 | + foreach ($field['fields'] as $address_field) { |
|
820 | 820 | |
821 | - if ( empty( $address_field['visible'] ) ) { |
|
821 | + if (empty($address_field['visible'])) { |
|
822 | 822 | continue; |
823 | 823 | } |
824 | 824 | |
825 | - if ( ! empty( $address_field['required'] ) && empty( $data[ $address_field['name'] ] ) ) { |
|
826 | - wp_send_json_error( __( 'Some required fields have not been filled.', 'invoicing' ) ); |
|
825 | + if (!empty($address_field['required']) && empty($data[$address_field['name']])) { |
|
826 | + wp_send_json_error(__('Some required fields have not been filled.', 'invoicing')); |
|
827 | 827 | } |
828 | 828 | |
829 | - if ( isset( $data[ $address_field['name'] ] ) ) { |
|
830 | - $label = str_replace( 'wpinv_', '', $address_field['name'] ); |
|
831 | - $address_fields[ $label ] = wpinv_clean( $data[ $address_field['name'] ] ); |
|
829 | + if (isset($data[$address_field['name']])) { |
|
830 | + $label = str_replace('wpinv_', '', $address_field['name']); |
|
831 | + $address_fields[$label] = wpinv_clean($data[$address_field['name']]); |
|
832 | 832 | } |
833 | 833 | |
834 | 834 | } |
835 | 835 | |
836 | - } else if ( isset( $data[ $field['id'] ] ) ) { |
|
836 | + } else if (isset($data[$field['id']])) { |
|
837 | 837 | $label = $field['id']; |
838 | 838 | |
839 | - if ( isset( $field['label'] ) ) { |
|
839 | + if (isset($field['label'])) { |
|
840 | 840 | $label = $field['label']; |
841 | 841 | } |
842 | 842 | |
843 | - $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] ); |
|
843 | + $prepared[wpinv_clean($label)] = wpinv_clean($data[$field['id']]); |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | } |
847 | 847 | |
848 | - $user = get_user_by( 'email', $prepared['billing_email'] ); |
|
848 | + $user = get_user_by('email', $prepared['billing_email']); |
|
849 | 849 | |
850 | - if ( empty( $user ) ) { |
|
851 | - $user = wpinv_create_user( $prepared['billing_email'] ); |
|
850 | + if (empty($user)) { |
|
851 | + $user = wpinv_create_user($prepared['billing_email']); |
|
852 | 852 | } |
853 | 853 | |
854 | - if ( is_wp_error( $user ) ) { |
|
855 | - wp_send_json_error( $user->get_error_message() ); |
|
854 | + if (is_wp_error($user)) { |
|
855 | + wp_send_json_error($user->get_error_message()); |
|
856 | 856 | } |
857 | 857 | |
858 | - if ( is_numeric( $user ) ) { |
|
859 | - $user = get_user_by( 'id', $user ); |
|
858 | + if (is_numeric($user)) { |
|
859 | + $user = get_user_by('id', $user); |
|
860 | 860 | } |
861 | 861 | |
862 | 862 | // Create the invoice. |
@@ -871,34 +871,34 @@ discard block |
||
871 | 871 | true |
872 | 872 | ); |
873 | 873 | |
874 | - if ( is_wp_error( $created ) ) { |
|
875 | - wp_send_json_error( $created->get_error_message() ); |
|
874 | + if (is_wp_error($created)) { |
|
875 | + wp_send_json_error($created->get_error_message()); |
|
876 | 876 | } |
877 | 877 | |
878 | - if ( empty( $created ) ) { |
|
879 | - wp_send_json_error( __( 'Could not create your invoice.', 'invoicing' ) ); |
|
878 | + if (empty($created)) { |
|
879 | + wp_send_json_error(__('Could not create your invoice.', 'invoicing')); |
|
880 | 880 | } |
881 | 881 | |
882 | - unset( $prepared['billing_email'] ); |
|
883 | - update_post_meta( $created->ID, 'payment_form_data', $prepared ); |
|
882 | + unset($prepared['billing_email']); |
|
883 | + update_post_meta($created->ID, 'payment_form_data', $prepared); |
|
884 | 884 | |
885 | 885 | $wpi_checkout_id = $created->ID; |
886 | 886 | $cart_total = wpinv_price( |
887 | 887 | wpinv_format_amount( |
888 | - wpinv_get_cart_total( $created->get_cart_details(), NULL, $created ) ), |
|
888 | + wpinv_get_cart_total($created->get_cart_details(), NULL, $created) ), |
|
889 | 889 | $created->get_currency() |
890 | 890 | ); |
891 | 891 | |
892 | 892 | $data = array(); |
893 | 893 | $data['invoice_id'] = $created->ID; |
894 | - $data['cart_discounts'] = $created->get_discounts( true ); |
|
894 | + $data['cart_discounts'] = $created->get_discounts(true); |
|
895 | 895 | |
896 | - wpinv_set_checkout_session( $data ); |
|
897 | - add_filter( 'wp_redirect', array( $invoicing->form_elements, 'send_redirect_response' ) ); |
|
898 | - add_action( 'wpinv_pre_send_back_to_checkout', array( $invoicing->form_elements, 'checkout_error' ) ); |
|
896 | + wpinv_set_checkout_session($data); |
|
897 | + add_filter('wp_redirect', array($invoicing->form_elements, 'send_redirect_response')); |
|
898 | + add_action('wpinv_pre_send_back_to_checkout', array($invoicing->form_elements, 'checkout_error')); |
|
899 | 899 | |
900 | - if ( ! defined( 'WPINV_CHECKOUT' ) ) { |
|
901 | - define( 'WPINV_CHECKOUT', true ); |
|
900 | + if (!defined('WPINV_CHECKOUT')) { |
|
901 | + define('WPINV_CHECKOUT', true); |
|
902 | 902 | } |
903 | 903 | |
904 | 904 | wpinv_process_checkout(); |
@@ -917,67 +917,67 @@ discard block |
||
917 | 917 | global $invoicing; |
918 | 918 | |
919 | 919 | // Check nonce. |
920 | - check_ajax_referer( 'wpinv_payment_form', 'wpinv_payment_form' ); |
|
920 | + check_ajax_referer('wpinv_payment_form', 'wpinv_payment_form'); |
|
921 | 921 | |
922 | 922 | // Prepare submitted data... |
923 | - $data = wp_unslash( $_POST ); |
|
923 | + $data = wp_unslash($_POST); |
|
924 | 924 | |
925 | 925 | // ... form fields... |
926 | - if ( empty( $data['form_id'] ) || 'publish' != get_post_status( $data['form_id'] ) ) { |
|
926 | + if (empty($data['form_id']) || 'publish' != get_post_status($data['form_id'])) { |
|
927 | 927 | exit; |
928 | 928 | } |
929 | 929 | |
930 | 930 | // ... and form items. |
931 | - $items = $invoicing->form_elements->get_form_items( $data['form_id'] ); |
|
931 | + $items = $invoicing->form_elements->get_form_items($data['form_id']); |
|
932 | 932 | $total = 0; |
933 | 933 | $tax = 0; |
934 | 934 | $sub_total = 0; |
935 | 935 | |
936 | - if ( ! empty( $data['wpinv-items'] ) ) { |
|
936 | + if (!empty($data['wpinv-items'])) { |
|
937 | 937 | |
938 | - $selected_items = wpinv_clean( $data['wpinv-items'] ); |
|
938 | + $selected_items = wpinv_clean($data['wpinv-items']); |
|
939 | 939 | |
940 | - foreach ( $items as $item ) { |
|
940 | + foreach ($items as $item) { |
|
941 | 941 | |
942 | - if ( ! isset( $selected_items[ $item['id'] ] ) ) { |
|
942 | + if (!isset($selected_items[$item['id']])) { |
|
943 | 943 | continue; |
944 | 944 | } |
945 | 945 | |
946 | 946 | $quantity = 1; |
947 | 947 | |
948 | - if ( ! empty( $item['allow_quantities'] ) && ! empty( $data["wpinv-item-{$item['id']}-quantity"] ) ) { |
|
948 | + if (!empty($item['allow_quantities']) && !empty($data["wpinv-item-{$item['id']}-quantity"])) { |
|
949 | 949 | |
950 | - $quantity = intval( $data["wpinv-item-{$item['id']}-quantity"] ); |
|
950 | + $quantity = intval($data["wpinv-item-{$item['id']}-quantity"]); |
|
951 | 951 | |
952 | - if ( 1 > $quantity ) { |
|
952 | + if (1 > $quantity) { |
|
953 | 953 | $quantity = 1; |
954 | 954 | } |
955 | 955 | |
956 | 956 | } |
957 | 957 | |
958 | 958 | // Custom pricing. |
959 | - $price = wpinv_sanitize_amount( $item['price'] ); |
|
960 | - if ( ! empty( $item['custom_price'] ) ) { |
|
959 | + $price = wpinv_sanitize_amount($item['price']); |
|
960 | + if (!empty($item['custom_price'])) { |
|
961 | 961 | |
962 | - $minimum_price = wpinv_sanitize_amount( $item['minimum_price'] ); |
|
963 | - $set_price = wpinv_sanitize_amount( $selected_items[ $item['id'] ] ); |
|
962 | + $minimum_price = wpinv_sanitize_amount($item['minimum_price']); |
|
963 | + $set_price = wpinv_sanitize_amount($selected_items[$item['id']]); |
|
964 | 964 | |
965 | - if ( $set_price < $minimum_price ) { |
|
965 | + if ($set_price < $minimum_price) { |
|
966 | 966 | $set_price = $minimum_price; |
967 | 967 | } |
968 | 968 | |
969 | - $price = wpinv_sanitize_amount( $set_price ); |
|
969 | + $price = wpinv_sanitize_amount($set_price); |
|
970 | 970 | |
971 | 971 | } |
972 | 972 | |
973 | - $price = $quantity * floatval( $price ); |
|
973 | + $price = $quantity * floatval($price); |
|
974 | 974 | |
975 | - if ( wpinv_use_taxes() ) { |
|
975 | + if (wpinv_use_taxes()) { |
|
976 | 976 | |
977 | - $rate = wpinv_get_tax_rate( false, false, (int) $item['id'] ); |
|
977 | + $rate = wpinv_get_tax_rate(false, false, (int) $item['id']); |
|
978 | 978 | |
979 | - if ( ! wpinv_prices_include_tax() ) { |
|
980 | - $pre_tax = ( $price - $price * $rate * 0.01 ); |
|
979 | + if (!wpinv_prices_include_tax()) { |
|
980 | + $pre_tax = ($price - $price * $rate * 0.01); |
|
981 | 981 | $item_tax = $price - $pre_tax; |
982 | 982 | } else { |
983 | 983 | $item_tax = $price * $rate * 0.01; |
@@ -987,12 +987,12 @@ discard block |
||
987 | 987 | |
988 | 988 | } |
989 | 989 | |
990 | - if ( wpinv_use_taxes() ) { |
|
990 | + if (wpinv_use_taxes()) { |
|
991 | 991 | |
992 | - $rate = wpinv_get_tax_rate( false, false, (int) $item['id'] ); |
|
992 | + $rate = wpinv_get_tax_rate(false, false, (int) $item['id']); |
|
993 | 993 | |
994 | - if ( wpinv_prices_include_tax() ) { |
|
995 | - $pre_tax = ( $price - $price * $rate * 0.01 ); |
|
994 | + if (wpinv_prices_include_tax()) { |
|
995 | + $pre_tax = ($price - $price * $rate * 0.01); |
|
996 | 996 | $item_tax = $price - $pre_tax; |
997 | 997 | } else { |
998 | 998 | $pre_tax = $price; |
@@ -1004,17 +1004,17 @@ discard block |
||
1004 | 1004 | $total = $sub_total + $tax; |
1005 | 1005 | |
1006 | 1006 | } else { |
1007 | - $total = $total + $price; |
|
1007 | + $total = $total + $price; |
|
1008 | 1008 | } |
1009 | 1009 | |
1010 | 1010 | } |
1011 | 1011 | |
1012 | 1012 | } |
1013 | 1013 | |
1014 | - wp_send_json_success( array( |
|
1015 | - 'total' => wpinv_price( wpinv_format_amount( $total ) ), |
|
1016 | - 'tax' => wpinv_price( wpinv_format_amount( $tax ) ), |
|
1017 | - 'sub_total' => wpinv_price( wpinv_format_amount( $sub_total ) ), |
|
1014 | + wp_send_json_success(array( |
|
1015 | + 'total' => wpinv_price(wpinv_format_amount($total)), |
|
1016 | + 'tax' => wpinv_price(wpinv_format_amount($tax)), |
|
1017 | + 'sub_total' => wpinv_price(wpinv_format_amount($sub_total)), |
|
1018 | 1018 | )); |
1019 | 1019 | exit; |
1020 | 1020 | } |
@@ -1027,53 +1027,53 @@ discard block |
||
1027 | 1027 | public static function buy_items() { |
1028 | 1028 | $user_id = get_current_user_id(); |
1029 | 1029 | |
1030 | - if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page |
|
1031 | - wp_send_json( array( |
|
1032 | - 'success' => wp_login_url( wp_get_referer() ) |
|
1033 | - ) ); |
|
1030 | + if (empty($user_id)) { // If not logged in then lets redirect to the login page |
|
1031 | + wp_send_json(array( |
|
1032 | + 'success' => wp_login_url(wp_get_referer()) |
|
1033 | + )); |
|
1034 | 1034 | } else { |
1035 | 1035 | // Only check nonce if logged in as it could be cached when logged out. |
1036 | - if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) { |
|
1037 | - wp_send_json( array( |
|
1038 | - 'error' => __( 'Security checks failed.', 'invoicing' ) |
|
1039 | - ) ); |
|
1036 | + if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) { |
|
1037 | + wp_send_json(array( |
|
1038 | + 'error' => __('Security checks failed.', 'invoicing') |
|
1039 | + )); |
|
1040 | 1040 | wp_die(); |
1041 | 1041 | } |
1042 | 1042 | |
1043 | 1043 | // allow to set a custom price through post_id |
1044 | 1044 | $items = $_POST['items']; |
1045 | - $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0; |
|
1046 | - $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0; |
|
1045 | + $related_post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0; |
|
1046 | + $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0; |
|
1047 | 1047 | |
1048 | 1048 | $cart_items = array(); |
1049 | - if ( $items ) { |
|
1050 | - $items = explode( ',', $items ); |
|
1049 | + if ($items) { |
|
1050 | + $items = explode(',', $items); |
|
1051 | 1051 | |
1052 | - foreach( $items as $item ) { |
|
1052 | + foreach ($items as $item) { |
|
1053 | 1053 | $item_id = $item; |
1054 | 1054 | $quantity = 1; |
1055 | 1055 | |
1056 | - if ( strpos( $item, '|' ) !== false ) { |
|
1057 | - $item_parts = explode( '|', $item ); |
|
1056 | + if (strpos($item, '|') !== false) { |
|
1057 | + $item_parts = explode('|', $item); |
|
1058 | 1058 | $item_id = $item_parts[0]; |
1059 | 1059 | $quantity = $item_parts[1]; |
1060 | 1060 | } |
1061 | 1061 | |
1062 | - if ( $item_id && $quantity ) { |
|
1062 | + if ($item_id && $quantity) { |
|
1063 | 1063 | $cart_items_arr = array( |
1064 | - 'id' => (int)$item_id, |
|
1065 | - 'quantity' => (int)$quantity |
|
1064 | + 'id' => (int) $item_id, |
|
1065 | + 'quantity' => (int) $quantity |
|
1066 | 1066 | ); |
1067 | 1067 | |
1068 | 1068 | // If there is a related post id then add it to meta |
1069 | - if ( $related_post_id ) { |
|
1069 | + if ($related_post_id) { |
|
1070 | 1070 | $cart_items_arr['meta'] = array( |
1071 | 1071 | 'post_id' => $related_post_id |
1072 | 1072 | ); |
1073 | 1073 | } |
1074 | 1074 | |
1075 | 1075 | // If there is a custom price then set it. |
1076 | - if ( $custom_item_price ) { |
|
1076 | + if ($custom_item_price) { |
|
1077 | 1077 | $cart_items_arr['custom_price'] = $custom_item_price; |
1078 | 1078 | } |
1079 | 1079 | |
@@ -1089,37 +1089,37 @@ discard block |
||
1089 | 1089 | * @param int $related_post_id The related post id if any. |
1090 | 1090 | * @since 1.0.0 |
1091 | 1091 | */ |
1092 | - $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id ); |
|
1092 | + $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id); |
|
1093 | 1093 | |
1094 | 1094 | // Make sure its not in the cart already, if it is then redirect to checkout. |
1095 | 1095 | $cart_invoice = wpinv_get_invoice_cart(); |
1096 | 1096 | |
1097 | - if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) { |
|
1098 | - wp_send_json( array( |
|
1097 | + if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) { |
|
1098 | + wp_send_json(array( |
|
1099 | 1099 | 'success' => $cart_invoice->get_checkout_payment_url() |
1100 | - ) ); |
|
1100 | + )); |
|
1101 | 1101 | wp_die(); |
1102 | 1102 | } |
1103 | 1103 | |
1104 | 1104 | // Check if user has invoice with same items waiting to be paid. |
1105 | - $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' ); |
|
1106 | - if ( !empty( $user_invoices ) ) { |
|
1107 | - foreach( $user_invoices as $user_invoice ) { |
|
1105 | + $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending'); |
|
1106 | + if (!empty($user_invoices)) { |
|
1107 | + foreach ($user_invoices as $user_invoice) { |
|
1108 | 1108 | $user_cart_details = array(); |
1109 | - $invoice = wpinv_get_invoice( $user_invoice->ID ); |
|
1109 | + $invoice = wpinv_get_invoice($user_invoice->ID); |
|
1110 | 1110 | $cart_details = $invoice->get_cart_details(); |
1111 | 1111 | |
1112 | - if ( !empty( $cart_details ) ) { |
|
1113 | - foreach ( $cart_details as $invoice_item ) { |
|
1112 | + if (!empty($cart_details)) { |
|
1113 | + foreach ($cart_details as $invoice_item) { |
|
1114 | 1114 | $ii_arr = array(); |
1115 | - $ii_arr['id'] = (int)$invoice_item['id']; |
|
1116 | - $ii_arr['quantity'] = (int)$invoice_item['quantity']; |
|
1115 | + $ii_arr['id'] = (int) $invoice_item['id']; |
|
1116 | + $ii_arr['quantity'] = (int) $invoice_item['quantity']; |
|
1117 | 1117 | |
1118 | - if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) { |
|
1118 | + if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) { |
|
1119 | 1119 | $ii_arr['meta'] = $invoice_item['meta']; |
1120 | 1120 | } |
1121 | 1121 | |
1122 | - if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) { |
|
1122 | + if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) { |
|
1123 | 1123 | $ii_arr['custom_price'] = $invoice_item['custom_price']; |
1124 | 1124 | } |
1125 | 1125 | |
@@ -1127,17 +1127,17 @@ discard block |
||
1127 | 1127 | } |
1128 | 1128 | } |
1129 | 1129 | |
1130 | - if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) { |
|
1131 | - wp_send_json( array( |
|
1130 | + if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) { |
|
1131 | + wp_send_json(array( |
|
1132 | 1132 | 'success' => $invoice->get_checkout_payment_url() |
1133 | - ) ); |
|
1133 | + )); |
|
1134 | 1134 | wp_die(); |
1135 | 1135 | } |
1136 | 1136 | } |
1137 | 1137 | } |
1138 | 1138 | |
1139 | 1139 | // Create invoice and send user to checkout |
1140 | - if ( !empty( $cart_items ) ) { |
|
1140 | + if (!empty($cart_items)) { |
|
1141 | 1141 | $invoice_data = array( |
1142 | 1142 | 'status' => 'wpi-pending', |
1143 | 1143 | 'created_via' => 'wpi', |
@@ -1145,21 +1145,21 @@ discard block |
||
1145 | 1145 | 'cart_details' => $cart_items, |
1146 | 1146 | ); |
1147 | 1147 | |
1148 | - $invoice = wpinv_insert_invoice( $invoice_data, true ); |
|
1148 | + $invoice = wpinv_insert_invoice($invoice_data, true); |
|
1149 | 1149 | |
1150 | - if ( !empty( $invoice ) && isset( $invoice->ID ) ) { |
|
1151 | - wp_send_json( array( |
|
1150 | + if (!empty($invoice) && isset($invoice->ID)) { |
|
1151 | + wp_send_json(array( |
|
1152 | 1152 | 'success' => $invoice->get_checkout_payment_url() |
1153 | - ) ); |
|
1153 | + )); |
|
1154 | 1154 | } else { |
1155 | - wp_send_json( array( |
|
1156 | - 'error' => __( 'Invoice failed to create', 'invoicing' ) |
|
1157 | - ) ); |
|
1155 | + wp_send_json(array( |
|
1156 | + 'error' => __('Invoice failed to create', 'invoicing') |
|
1157 | + )); |
|
1158 | 1158 | } |
1159 | 1159 | } else { |
1160 | - wp_send_json( array( |
|
1161 | - 'error' => __( 'Items not valid.', 'invoicing' ) |
|
1162 | - ) ); |
|
1160 | + wp_send_json(array( |
|
1161 | + 'error' => __('Items not valid.', 'invoicing') |
|
1162 | + )); |
|
1163 | 1163 | } |
1164 | 1164 | } |
1165 | 1165 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly. |
3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | 5 | class WPInv_EUVat { |
6 | 6 | private static $is_ajax = false; |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | private static $instance = false; |
9 | 9 | |
10 | 10 | public static function get_instance() { |
11 | - if ( !self::$instance ) { |
|
11 | + if (!self::$instance) { |
|
12 | 12 | self::$instance = new self(); |
13 | 13 | self::$instance->actions(); |
14 | 14 | } |
@@ -17,137 +17,137 @@ discard block |
||
17 | 17 | } |
18 | 18 | |
19 | 19 | public function __construct() { |
20 | - self::$is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
20 | + self::$is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
21 | 21 | self::$default_country = wpinv_get_default_country(); |
22 | 22 | } |
23 | 23 | |
24 | 24 | public static function actions() { |
25 | - if ( is_admin() ) { |
|
26 | - add_action( 'admin_enqueue_scripts', array( self::$instance, 'enqueue_admin_scripts' ) ); |
|
27 | - add_action( 'wpinv_settings_sections_taxes', array( self::$instance, 'section_vat_settings' ) ); |
|
28 | - add_action( 'wpinv_settings_taxes', array( self::$instance, 'vat_settings' ) ); |
|
29 | - add_filter( 'wpinv_settings_taxes-vat_sanitize', array( self::$instance, 'sanitize_vat_settings' ) ); |
|
30 | - add_filter( 'wpinv_settings_taxes-vat_rates_sanitize', array( self::$instance, 'sanitize_vat_rates' ) ); |
|
31 | - add_action( 'wp_ajax_wpinv_add_vat_class', array( self::$instance, 'add_class' ) ); |
|
32 | - add_action( 'wp_ajax_nopriv_wpinv_add_vat_class', array( self::$instance, 'add_class' ) ); |
|
33 | - add_action( 'wp_ajax_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) ); |
|
34 | - add_action( 'wp_ajax_nopriv_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) ); |
|
35 | - add_action( 'wp_ajax_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) ); |
|
36 | - add_action( 'wp_ajax_nopriv_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) ); |
|
37 | - add_action( 'wp_ajax_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) ); |
|
38 | - add_action( 'wp_ajax_nopriv_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) ); |
|
39 | - } |
|
40 | - |
|
41 | - add_action( 'wp_enqueue_scripts', array( self::$instance, 'enqueue_vat_scripts' ) ); |
|
42 | - add_filter( 'wpinv_default_billing_country', array( self::$instance, 'get_user_country' ), 10 ); |
|
43 | - add_filter( 'wpinv_get_user_country', array( self::$instance, 'set_user_country' ), 10 ); |
|
44 | - add_action( 'wp_ajax_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) ); |
|
45 | - add_action( 'wp_ajax_nopriv_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) ); |
|
46 | - add_action( 'wp_ajax_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) ); |
|
47 | - add_action( 'wp_ajax_nopriv_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) ); |
|
48 | - add_action( 'wpinv_invoice_print_after_line_items', array( self::$instance, 'show_vat_notice' ), 999, 1 ); |
|
49 | - if ( wpinv_use_taxes() ) { |
|
50 | - add_action( 'wpinv_after_billing_fields', array( self::$instance, 'checkout_vat_fields' ) ); |
|
51 | - if ( self::allow_vat_rules() ) { |
|
52 | - add_action( 'wpinv_checkout_error_checks', array( self::$instance, 'checkout_vat_validate' ), 10, 2 ); |
|
53 | - add_filter( 'wpinv_tax_rate', array( self::$instance, 'get_rate' ), 10, 4 ); |
|
25 | + if (is_admin()) { |
|
26 | + add_action('admin_enqueue_scripts', array(self::$instance, 'enqueue_admin_scripts')); |
|
27 | + add_action('wpinv_settings_sections_taxes', array(self::$instance, 'section_vat_settings')); |
|
28 | + add_action('wpinv_settings_taxes', array(self::$instance, 'vat_settings')); |
|
29 | + add_filter('wpinv_settings_taxes-vat_sanitize', array(self::$instance, 'sanitize_vat_settings')); |
|
30 | + add_filter('wpinv_settings_taxes-vat_rates_sanitize', array(self::$instance, 'sanitize_vat_rates')); |
|
31 | + add_action('wp_ajax_wpinv_add_vat_class', array(self::$instance, 'add_class')); |
|
32 | + add_action('wp_ajax_nopriv_wpinv_add_vat_class', array(self::$instance, 'add_class')); |
|
33 | + add_action('wp_ajax_wpinv_delete_vat_class', array(self::$instance, 'delete_class')); |
|
34 | + add_action('wp_ajax_nopriv_wpinv_delete_vat_class', array(self::$instance, 'delete_class')); |
|
35 | + add_action('wp_ajax_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates')); |
|
36 | + add_action('wp_ajax_nopriv_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates')); |
|
37 | + add_action('wp_ajax_wpinv_geoip2', array(self::$instance, 'geoip2_download_database')); |
|
38 | + add_action('wp_ajax_nopriv_wpinv_geoip2', array(self::$instance, 'geoip2_download_database')); |
|
39 | + } |
|
40 | + |
|
41 | + add_action('wp_enqueue_scripts', array(self::$instance, 'enqueue_vat_scripts')); |
|
42 | + add_filter('wpinv_default_billing_country', array(self::$instance, 'get_user_country'), 10); |
|
43 | + add_filter('wpinv_get_user_country', array(self::$instance, 'set_user_country'), 10); |
|
44 | + add_action('wp_ajax_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate')); |
|
45 | + add_action('wp_ajax_nopriv_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate')); |
|
46 | + add_action('wp_ajax_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset')); |
|
47 | + add_action('wp_ajax_nopriv_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset')); |
|
48 | + add_action('wpinv_invoice_print_after_line_items', array(self::$instance, 'show_vat_notice'), 999, 1); |
|
49 | + if (wpinv_use_taxes()) { |
|
50 | + add_action('wpinv_after_billing_fields', array(self::$instance, 'checkout_vat_fields')); |
|
51 | + if (self::allow_vat_rules()) { |
|
52 | + add_action('wpinv_checkout_error_checks', array(self::$instance, 'checkout_vat_validate'), 10, 2); |
|
53 | + add_filter('wpinv_tax_rate', array(self::$instance, 'get_rate'), 10, 4); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | } |
57 | 57 | |
58 | - public static function get_eu_states( $sort = true ) { |
|
59 | - $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' ); |
|
60 | - if ( $sort ) { |
|
61 | - $sort = sort( $eu_states ); |
|
58 | + public static function get_eu_states($sort = true) { |
|
59 | + $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'); |
|
60 | + if ($sort) { |
|
61 | + $sort = sort($eu_states); |
|
62 | 62 | } |
63 | 63 | |
64 | - return apply_filters( 'wpinv_get_eu_states', $eu_states, $sort ); |
|
64 | + return apply_filters('wpinv_get_eu_states', $eu_states, $sort); |
|
65 | 65 | } |
66 | 66 | |
67 | - public static function get_gst_countries( $sort = true ) { |
|
68 | - $gst_countries = array( 'AU', 'NZ', 'CA', 'CN' ); |
|
67 | + public static function get_gst_countries($sort = true) { |
|
68 | + $gst_countries = array('AU', 'NZ', 'CA', 'CN'); |
|
69 | 69 | |
70 | - if ( $sort ) { |
|
71 | - $sort = sort( $gst_countries ); |
|
70 | + if ($sort) { |
|
71 | + $sort = sort($gst_countries); |
|
72 | 72 | } |
73 | 73 | |
74 | - return apply_filters( 'wpinv_get_gst_countries', $gst_countries, $sort ); |
|
74 | + return apply_filters('wpinv_get_gst_countries', $gst_countries, $sort); |
|
75 | 75 | } |
76 | 76 | |
77 | - public static function is_eu_state( $country_code ) { |
|
78 | - $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_eu_states() ) ? true : false; |
|
77 | + public static function is_eu_state($country_code) { |
|
78 | + $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_eu_states()) ? true : false; |
|
79 | 79 | |
80 | - return apply_filters( 'wpinv_is_eu_state', $return, $country_code ); |
|
80 | + return apply_filters('wpinv_is_eu_state', $return, $country_code); |
|
81 | 81 | } |
82 | 82 | |
83 | - public static function is_gst_country( $country_code ) { |
|
84 | - $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_gst_countries() ) ? true : false; |
|
83 | + public static function is_gst_country($country_code) { |
|
84 | + $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_gst_countries()) ? true : false; |
|
85 | 85 | |
86 | - return apply_filters( 'wpinv_is_gst_country', $return, $country_code ); |
|
86 | + return apply_filters('wpinv_is_gst_country', $return, $country_code); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | public static function enqueue_vat_scripts() { |
90 | - if( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ) { |
|
90 | + if (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules')) { |
|
91 | 91 | self::load_vat_scripts(); |
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
95 | - public static function load_vat_scripts(){ |
|
96 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
95 | + public static function load_vat_scripts() { |
|
96 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
97 | 97 | |
98 | - wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
99 | - wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
98 | + wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
99 | + wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
100 | 100 | |
101 | - $vat_name = self::get_vat_name(); |
|
101 | + $vat_name = self::get_vat_name(); |
|
102 | 102 | |
103 | 103 | $vars = array(); |
104 | 104 | $vars['UseTaxes'] = wpinv_use_taxes(); |
105 | 105 | $vars['EUStates'] = self::get_eu_states(); |
106 | - $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' ); |
|
107 | - $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' ); |
|
108 | - $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name ); |
|
109 | - $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name ); |
|
110 | - $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name ); |
|
111 | - $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name ); |
|
112 | - $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name ); |
|
113 | - $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' ); |
|
106 | + $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing'); |
|
107 | + $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing'); |
|
108 | + $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name); |
|
109 | + $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name); |
|
110 | + $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name); |
|
111 | + $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name); |
|
112 | + $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name); |
|
113 | + $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing'); |
|
114 | 114 | $vars['ApplyVATRules'] = $vars['UseTaxes'] ? self::allow_vat_rules() : false; |
115 | 115 | $vars['HideVatFields'] = $vars['ApplyVATRules'] ? self::hide_vat_fields() : true; |
116 | - $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' ); |
|
117 | - $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' ); |
|
118 | - $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' ); |
|
119 | - $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' ); |
|
120 | - $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' ); |
|
121 | - $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' ); |
|
122 | - $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' ); |
|
123 | - $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' ); |
|
124 | - $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name ); |
|
125 | - $vars['VatReseting'] = __( 'Reseting...', 'invoicing' ); |
|
126 | - $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
127 | - $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
128 | - $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' ); |
|
116 | + $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing'); |
|
117 | + $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing'); |
|
118 | + $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing'); |
|
119 | + $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing'); |
|
120 | + $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing'); |
|
121 | + $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing'); |
|
122 | + $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing'); |
|
123 | + $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing'); |
|
124 | + $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name); |
|
125 | + $vars['VatReseting'] = __('Reseting...', 'invoicing'); |
|
126 | + $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
127 | + $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
128 | + $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing'); |
|
129 | 129 | $vars['isFront'] = is_admin() ? false : true; |
130 | 130 | $vars['baseCountry'] = wpinv_get_default_country(); |
131 | - $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false ); |
|
132 | - $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false; |
|
131 | + $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false); |
|
132 | + $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false; |
|
133 | 133 | |
134 | - wp_enqueue_script( 'wpinv-vat-validation-script' ); |
|
135 | - wp_enqueue_script( 'wpinv-vat-script' ); |
|
136 | - wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars ); |
|
134 | + wp_enqueue_script('wpinv-vat-validation-script'); |
|
135 | + wp_enqueue_script('wpinv-vat-script'); |
|
136 | + wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | public static function enqueue_admin_scripts() { |
140 | - if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) { |
|
140 | + if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) { |
|
141 | 141 | self::load_vat_scripts(); |
142 | 142 | } |
143 | 143 | } |
144 | 144 | |
145 | - public static function section_vat_settings( $sections ) { |
|
146 | - if ( !empty( $sections ) ) { |
|
147 | - $sections['vat'] = __( 'EU VAT Settings', 'invoicing' ); |
|
145 | + public static function section_vat_settings($sections) { |
|
146 | + if (!empty($sections)) { |
|
147 | + $sections['vat'] = __('EU VAT Settings', 'invoicing'); |
|
148 | 148 | |
149 | - if ( self::allow_vat_classes() ) { |
|
150 | - $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' ); |
|
149 | + if (self::allow_vat_classes()) { |
|
150 | + $sections['vat_rates'] = __('EU VAT Rates', 'invoicing'); |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 | return $sections; |
@@ -156,52 +156,52 @@ discard block |
||
156 | 156 | public static function vat_rates_settings() { |
157 | 157 | $vat_classes = self::get_rate_classes(); |
158 | 158 | $vat_rates = array(); |
159 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new'; |
|
160 | - $current_url = remove_query_arg( 'wpi_sub' ); |
|
159 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new'; |
|
160 | + $current_url = remove_query_arg('wpi_sub'); |
|
161 | 161 | |
162 | 162 | $vat_rates['vat_rates_header'] = array( |
163 | 163 | 'id' => 'vat_rates_header', |
164 | - 'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>', |
|
164 | + 'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>', |
|
165 | 165 | 'desc' => '', |
166 | 166 | 'type' => 'header', |
167 | 167 | 'size' => 'regular' |
168 | 168 | ); |
169 | 169 | $vat_rates['vat_rates_class'] = array( |
170 | 170 | 'id' => 'vat_rates_class', |
171 | - 'name' => __( 'Edit VAT Rates', 'invoicing' ), |
|
172 | - 'desc' => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ), |
|
171 | + 'name' => __('Edit VAT Rates', 'invoicing'), |
|
172 | + 'desc' => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'), |
|
173 | 173 | 'type' => 'select', |
174 | - 'options' => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ), |
|
175 | - 'placeholder' => __( 'Select a VAT Rate', 'invoicing' ), |
|
174 | + 'options' => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))), |
|
175 | + 'placeholder' => __('Select a VAT Rate', 'invoicing'), |
|
176 | 176 | 'selected' => $vat_class, |
177 | 177 | 'class' => 'wpi_select2', |
178 | 178 | 'onchange' => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;', |
179 | 179 | ); |
180 | 180 | |
181 | - if ( $vat_class != '_standard' && $vat_class != '_new' ) { |
|
181 | + if ($vat_class != '_standard' && $vat_class != '_new') { |
|
182 | 182 | $vat_rates['vat_rate_delete'] = array( |
183 | 183 | 'id' => 'vat_rate_delete', |
184 | 184 | 'type' => 'vat_rate_delete', |
185 | 185 | ); |
186 | 186 | } |
187 | 187 | |
188 | - if ( $vat_class == '_new' ) { |
|
188 | + if ($vat_class == '_new') { |
|
189 | 189 | $vat_rates['vat_rates_settings'] = array( |
190 | 190 | 'id' => 'vat_rates_settings', |
191 | - 'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>', |
|
191 | + 'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>', |
|
192 | 192 | 'type' => 'header', |
193 | 193 | ); |
194 | 194 | $vat_rates['vat_rate_name'] = array( |
195 | 195 | 'id' => 'vat_rate_name', |
196 | - 'name' => __( 'Name', 'invoicing' ), |
|
197 | - 'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ), |
|
196 | + 'name' => __('Name', 'invoicing'), |
|
197 | + 'desc' => __('A short name for the new VAT Rate class', 'invoicing'), |
|
198 | 198 | 'type' => 'text', |
199 | 199 | 'size' => 'regular', |
200 | 200 | ); |
201 | 201 | $vat_rates['vat_rate_desc'] = array( |
202 | 202 | 'id' => 'vat_rate_desc', |
203 | - 'name' => __( 'Description', 'invoicing' ), |
|
204 | - 'desc' => __( 'Manage VAT Rate class', 'invoicing' ), |
|
203 | + 'name' => __('Description', 'invoicing'), |
|
204 | + 'desc' => __('Manage VAT Rate class', 'invoicing'), |
|
205 | 205 | 'type' => 'text', |
206 | 206 | 'size' => 'regular', |
207 | 207 | ); |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | $vat_rates['vat_rates'] = array( |
214 | 214 | 'id' => 'vat_rates', |
215 | 215 | 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>', |
216 | - 'desc' => self::get_class_desc( $vat_class ), |
|
216 | + 'desc' => self::get_class_desc($vat_class), |
|
217 | 217 | 'type' => 'vat_rates', |
218 | 218 | ); |
219 | 219 | } |
@@ -221,12 +221,12 @@ discard block |
||
221 | 221 | return $vat_rates; |
222 | 222 | } |
223 | 223 | |
224 | - public static function vat_settings( $settings ) { |
|
225 | - if ( !empty( $settings ) ) { |
|
224 | + public static function vat_settings($settings) { |
|
225 | + if (!empty($settings)) { |
|
226 | 226 | $vat_settings = array(); |
227 | 227 | $vat_settings['vat_company_title'] = array( |
228 | 228 | 'id' => 'vat_company_title', |
229 | - 'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>', |
|
229 | + 'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>', |
|
230 | 230 | 'desc' => '', |
231 | 231 | 'type' => 'header', |
232 | 232 | 'size' => 'regular' |
@@ -234,22 +234,22 @@ discard block |
||
234 | 234 | |
235 | 235 | $vat_settings['vat_company_name'] = array( |
236 | 236 | 'id' => 'vat_company_name', |
237 | - 'name' => __( 'Your Company Name', 'invoicing' ), |
|
238 | - '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>' ), |
|
237 | + 'name' => __('Your Company Name', 'invoicing'), |
|
238 | + '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>'), |
|
239 | 239 | 'type' => 'text', |
240 | 240 | 'size' => 'regular', |
241 | 241 | ); |
242 | 242 | |
243 | 243 | $vat_settings['vat_number'] = array( |
244 | 244 | 'id' => 'vat_number', |
245 | - 'name' => __( 'Your VAT Number', 'invoicing' ), |
|
245 | + 'name' => __('Your VAT Number', 'invoicing'), |
|
246 | 246 | 'type' => 'vat_number', |
247 | 247 | 'size' => 'regular', |
248 | 248 | ); |
249 | 249 | |
250 | 250 | $vat_settings['vat_settings_title'] = array( |
251 | 251 | 'id' => 'vat_settings_title', |
252 | - 'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>', |
|
252 | + 'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>', |
|
253 | 253 | 'desc' => '', |
254 | 254 | 'type' => 'header', |
255 | 255 | 'size' => 'regular' |
@@ -257,8 +257,8 @@ discard block |
||
257 | 257 | |
258 | 258 | $vat_settings['apply_vat_rules'] = array( |
259 | 259 | 'id' => 'apply_vat_rules', |
260 | - 'name' => __( 'Enable VAT Rules', 'invoicing' ), |
|
261 | - '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>', |
|
260 | + 'name' => __('Enable VAT Rules', 'invoicing'), |
|
261 | + '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>', |
|
262 | 262 | 'type' => 'checkbox', |
263 | 263 | 'std' => '1' |
264 | 264 | ); |
@@ -274,8 +274,8 @@ discard block |
||
274 | 274 | |
275 | 275 | $vat_settings['vat_prevent_b2c_purchase'] = array( |
276 | 276 | 'id' => 'vat_prevent_b2c_purchase', |
277 | - 'name' => __( 'Prevent EU B2C Sales', 'invoicing' ), |
|
278 | - 'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ), |
|
277 | + 'name' => __('Prevent EU B2C Sales', 'invoicing'), |
|
278 | + 'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'), |
|
279 | 279 | 'type' => 'checkbox' |
280 | 280 | ); |
281 | 281 | |
@@ -283,22 +283,22 @@ discard block |
||
283 | 283 | |
284 | 284 | $vat_settings['vat_same_country_rule'] = array( |
285 | 285 | 'id' => 'vat_same_country_rule', |
286 | - 'name' => __( 'Same Country Rule', 'invoicing' ), |
|
287 | - 'desc' => __( 'Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing' ), |
|
286 | + 'name' => __('Same Country Rule', 'invoicing'), |
|
287 | + 'desc' => __('Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing'), |
|
288 | 288 | 'type' => 'select', |
289 | 289 | 'options' => array( |
290 | - '' => __( 'Normal', 'invoicing' ), |
|
291 | - 'no' => __( 'No VAT', 'invoicing' ), |
|
292 | - 'always' => __( 'Always apply VAT', 'invoicing' ), |
|
290 | + '' => __('Normal', 'invoicing'), |
|
291 | + 'no' => __('No VAT', 'invoicing'), |
|
292 | + 'always' => __('Always apply VAT', 'invoicing'), |
|
293 | 293 | ), |
294 | - 'placeholder' => __( 'Select an option', 'invoicing' ), |
|
294 | + 'placeholder' => __('Select an option', 'invoicing'), |
|
295 | 295 | 'std' => '', |
296 | 296 | 'class' => 'wpi_select2', |
297 | 297 | ); |
298 | 298 | |
299 | 299 | $vat_settings['vat_checkout_title'] = array( |
300 | 300 | 'id' => 'vat_checkout_title', |
301 | - 'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>', |
|
301 | + 'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>', |
|
302 | 302 | 'desc' => '', |
303 | 303 | 'type' => 'header', |
304 | 304 | 'size' => 'regular' |
@@ -306,14 +306,14 @@ discard block |
||
306 | 306 | |
307 | 307 | $vat_settings['vat_disable_fields'] = array( |
308 | 308 | 'id' => 'vat_disable_fields', |
309 | - 'name' => __( 'Disable VAT Fields', 'invoicing' ), |
|
310 | - 'desc' => __( 'Disable VAT fields if Invoicing is being used for GST.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing' ) . '</font>', |
|
309 | + 'name' => __('Disable VAT Fields', 'invoicing'), |
|
310 | + 'desc' => __('Disable VAT fields if Invoicing is being used for GST.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing') . '</font>', |
|
311 | 311 | 'type' => 'checkbox' |
312 | 312 | ); |
313 | 313 | |
314 | 314 | $vat_settings['vat_ip_lookup'] = array( |
315 | 315 | 'id' => 'vat_ip_lookup', |
316 | - 'name' => __( 'IP Country Look-up', 'invoicing' ), |
|
316 | + 'name' => __('IP Country Look-up', 'invoicing'), |
|
317 | 317 | 'type' => 'vat_ip_lookup', |
318 | 318 | 'size' => 'regular', |
319 | 319 | 'std' => 'default', |
@@ -322,21 +322,21 @@ discard block |
||
322 | 322 | |
323 | 323 | $vat_settings['hide_ip_address'] = array( |
324 | 324 | 'id' => 'hide_ip_address', |
325 | - 'name' => __( 'Hide IP Info at Checkout', 'invoicing' ), |
|
326 | - 'desc' => __( 'Hide the user IP info at checkout.', 'invoicing' ), |
|
325 | + 'name' => __('Hide IP Info at Checkout', 'invoicing'), |
|
326 | + 'desc' => __('Hide the user IP info at checkout.', 'invoicing'), |
|
327 | 327 | 'type' => 'checkbox' |
328 | 328 | ); |
329 | 329 | |
330 | 330 | $vat_settings['vat_ip_country_default'] = array( |
331 | 331 | 'id' => 'vat_ip_country_default', |
332 | - 'name' => __( 'Enable IP Country as Default', 'invoicing' ), |
|
333 | - 'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ), |
|
332 | + 'name' => __('Enable IP Country as Default', 'invoicing'), |
|
333 | + 'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'), |
|
334 | 334 | 'type' => 'checkbox' |
335 | 335 | ); |
336 | 336 | |
337 | 337 | $vat_settings['vies_validation_title'] = array( |
338 | 338 | 'id' => 'vies_validation_title', |
339 | - 'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>', |
|
339 | + 'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>', |
|
340 | 340 | 'desc' => '', |
341 | 341 | 'type' => 'header', |
342 | 342 | 'size' => 'regular' |
@@ -344,37 +344,37 @@ discard block |
||
344 | 344 | |
345 | 345 | $vat_settings['vat_vies_check'] = array( |
346 | 346 | 'id' => 'vat_vies_check', |
347 | - 'name' => __( 'Disable VIES VAT ID Check', 'invoicing' ), |
|
348 | - '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>' ), |
|
347 | + 'name' => __('Disable VIES VAT ID Check', 'invoicing'), |
|
348 | + '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>'), |
|
349 | 349 | 'type' => 'checkbox' |
350 | 350 | ); |
351 | 351 | |
352 | 352 | $vat_settings['vat_disable_company_name_check'] = array( |
353 | 353 | 'id' => 'vat_disable_company_name_check', |
354 | - 'name' => __( 'Disable VIES Name Check', 'invoicing' ), |
|
355 | - '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>' ), |
|
354 | + 'name' => __('Disable VIES Name Check', 'invoicing'), |
|
355 | + '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>'), |
|
356 | 356 | 'type' => 'checkbox' |
357 | 357 | ); |
358 | 358 | |
359 | 359 | $vat_settings['vat_offline_check'] = array( |
360 | 360 | 'id' => 'vat_offline_check', |
361 | - 'name' => __( 'Disable Basic Checks', 'invoicing' ), |
|
362 | - 'desc' => __( 'Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing' ), |
|
361 | + 'name' => __('Disable Basic Checks', 'invoicing'), |
|
362 | + 'desc' => __('Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing'), |
|
363 | 363 | 'type' => 'checkbox' |
364 | 364 | ); |
365 | 365 | |
366 | 366 | |
367 | 367 | $settings['vat'] = $vat_settings; |
368 | 368 | |
369 | - if ( self::allow_vat_classes() ) { |
|
369 | + if (self::allow_vat_classes()) { |
|
370 | 370 | $settings['vat_rates'] = self::vat_rates_settings(); |
371 | 371 | } |
372 | 372 | |
373 | 373 | $eu_fallback_rate = array( |
374 | 374 | 'id' => 'eu_fallback_rate', |
375 | - 'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>', |
|
375 | + 'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>', |
|
376 | 376 | 'type' => 'eu_fallback_rate', |
377 | - 'desc' => __( 'Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing' ), |
|
377 | + 'desc' => __('Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing'), |
|
378 | 378 | 'std' => '20', |
379 | 379 | 'size' => 'small' |
380 | 380 | ); |
@@ -390,11 +390,11 @@ discard block |
||
390 | 390 | $database_url = 'http' . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on' ? 's' : '') . '://geolite.maxmind.com/download/geoip/database/'; |
391 | 391 | $destination_dir = $upload_dir['basedir'] . '/invoicing'; |
392 | 392 | |
393 | - if ( !is_dir( $destination_dir ) ) { |
|
394 | - mkdir( $destination_dir ); |
|
393 | + if (!is_dir($destination_dir)) { |
|
394 | + mkdir($destination_dir); |
|
395 | 395 | } |
396 | 396 | |
397 | - $database_files = array( |
|
397 | + $database_files = array( |
|
398 | 398 | 'country' => array( |
399 | 399 | 'source' => $database_url . 'GeoLite2-Country.mmdb.gz', |
400 | 400 | 'destination' => $destination_dir . '/GeoLite2-Country.mmdb', |
@@ -405,57 +405,57 @@ discard block |
||
405 | 405 | ) |
406 | 406 | ); |
407 | 407 | |
408 | - foreach( $database_files as $database => $files ) { |
|
409 | - $result = self::geoip2_download_file( $files['source'], $files['destination'] ); |
|
408 | + foreach ($database_files as $database => $files) { |
|
409 | + $result = self::geoip2_download_file($files['source'], $files['destination']); |
|
410 | 410 | |
411 | - if ( empty( $result['success'] ) ) { |
|
411 | + if (empty($result['success'])) { |
|
412 | 412 | echo $result['message']; |
413 | 413 | exit; |
414 | 414 | } |
415 | 415 | |
416 | - wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) ); |
|
417 | - echo sprintf(__( 'GeoIP2 %s database updated successfully.', 'invoicing' ), $database ) . ' '; |
|
416 | + wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp')); |
|
417 | + echo sprintf(__('GeoIP2 %s database updated successfully.', 'invoicing'), $database) . ' '; |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | exit; |
421 | 421 | } |
422 | 422 | |
423 | - public static function geoip2_download_file( $source_url, $destination_file ) { |
|
423 | + public static function geoip2_download_file($source_url, $destination_file) { |
|
424 | 424 | $success = false; |
425 | 425 | $message = ''; |
426 | 426 | |
427 | - if ( !function_exists( 'download_url' ) ) { |
|
428 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
427 | + if (!function_exists('download_url')) { |
|
428 | + require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
429 | 429 | } |
430 | 430 | |
431 | - $temp_file = download_url( $source_url ); |
|
431 | + $temp_file = download_url($source_url); |
|
432 | 432 | |
433 | - if ( is_wp_error( $temp_file ) ) { |
|
434 | - $message = sprintf( __( 'Error while downloading GeoIp2 database( %s ): %s', 'invoicing' ), $source_url, $temp_file->get_error_message() ); |
|
433 | + if (is_wp_error($temp_file)) { |
|
434 | + $message = sprintf(__('Error while downloading GeoIp2 database( %s ): %s', 'invoicing'), $source_url, $temp_file->get_error_message()); |
|
435 | 435 | } else { |
436 | - $handle = gzopen( $temp_file, 'rb' ); |
|
436 | + $handle = gzopen($temp_file, 'rb'); |
|
437 | 437 | |
438 | - if ( $handle ) { |
|
439 | - $fopen = fopen( $destination_file, 'wb' ); |
|
440 | - if ( $fopen ) { |
|
441 | - while ( ( $data = gzread( $handle, 4096 ) ) != false ) { |
|
442 | - fwrite( $fopen, $data ); |
|
438 | + if ($handle) { |
|
439 | + $fopen = fopen($destination_file, 'wb'); |
|
440 | + if ($fopen) { |
|
441 | + while (($data = gzread($handle, 4096)) != false) { |
|
442 | + fwrite($fopen, $data); |
|
443 | 443 | } |
444 | 444 | |
445 | - gzclose( $handle ); |
|
446 | - fclose( $fopen ); |
|
445 | + gzclose($handle); |
|
446 | + fclose($fopen); |
|
447 | 447 | |
448 | 448 | $success = true; |
449 | 449 | } else { |
450 | - gzclose( $handle ); |
|
451 | - $message = sprintf( __( 'Error could not open destination GeoIp2 database file for writing: %s', 'invoicing' ), $destination_file ); |
|
450 | + gzclose($handle); |
|
451 | + $message = sprintf(__('Error could not open destination GeoIp2 database file for writing: %s', 'invoicing'), $destination_file); |
|
452 | 452 | } |
453 | 453 | } else { |
454 | - $message = sprintf( __( 'Error could not open GeoIp2 database file for reading: %s', 'invoicing' ), $temp_file ); |
|
454 | + $message = sprintf(__('Error could not open GeoIp2 database file for reading: %s', 'invoicing'), $temp_file); |
|
455 | 455 | } |
456 | 456 | |
457 | - if ( file_exists( $temp_file ) ) { |
|
458 | - unlink( $temp_file ); |
|
457 | + if (file_exists($temp_file)) { |
|
458 | + unlink($temp_file); |
|
459 | 459 | } |
460 | 460 | } |
461 | 461 | |
@@ -467,11 +467,11 @@ discard block |
||
467 | 467 | } |
468 | 468 | |
469 | 469 | public static function load_geoip2() { |
470 | - if ( defined( 'WPINV_GEOIP2_LODDED' ) ) { |
|
470 | + if (defined('WPINV_GEOIP2_LODDED')) { |
|
471 | 471 | return; |
472 | 472 | } |
473 | 473 | |
474 | - if ( !class_exists( '\MaxMind\Db\Reader' ) ) { |
|
474 | + if (!class_exists('\MaxMind\Db\Reader')) { |
|
475 | 475 | $maxmind_db_files = array( |
476 | 476 | 'Reader/Decoder.php', |
477 | 477 | 'Reader/InvalidDatabaseException.php', |
@@ -480,12 +480,12 @@ discard block |
||
480 | 480 | 'Reader.php', |
481 | 481 | ); |
482 | 482 | |
483 | - foreach ( $maxmind_db_files as $key => $file ) { |
|
484 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file ); |
|
483 | + foreach ($maxmind_db_files as $key => $file) { |
|
484 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file); |
|
485 | 485 | } |
486 | 486 | } |
487 | 487 | |
488 | - if ( !class_exists( '\GeoIp2\Database\Reader' ) ) { |
|
488 | + if (!class_exists('\GeoIp2\Database\Reader')) { |
|
489 | 489 | $geoip2_files = array( |
490 | 490 | 'ProviderInterface.php', |
491 | 491 | 'Compat/JsonSerializable.php', |
@@ -519,23 +519,23 @@ discard block |
||
519 | 519 | 'WebService/Client.php', |
520 | 520 | ); |
521 | 521 | |
522 | - foreach ( $geoip2_files as $key => $file ) { |
|
523 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file ); |
|
522 | + foreach ($geoip2_files as $key => $file) { |
|
523 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file); |
|
524 | 524 | } |
525 | 525 | } |
526 | 526 | |
527 | - define( 'WPINV_GEOIP2_LODDED', true ); |
|
527 | + define('WPINV_GEOIP2_LODDED', true); |
|
528 | 528 | } |
529 | 529 | |
530 | 530 | public static function geoip2_country_dbfile() { |
531 | 531 | $upload_dir = wp_upload_dir(); |
532 | 532 | |
533 | - if ( !isset( $upload_dir['basedir'] ) ) { |
|
533 | + if (!isset($upload_dir['basedir'])) { |
|
534 | 534 | return false; |
535 | 535 | } |
536 | 536 | |
537 | 537 | $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb'; |
538 | - if ( !file_exists( $filename ) ) { |
|
538 | + if (!file_exists($filename)) { |
|
539 | 539 | return false; |
540 | 540 | } |
541 | 541 | |
@@ -545,12 +545,12 @@ discard block |
||
545 | 545 | public static function geoip2_city_dbfile() { |
546 | 546 | $upload_dir = wp_upload_dir(); |
547 | 547 | |
548 | - if ( !isset( $upload_dir['basedir'] ) ) { |
|
548 | + if (!isset($upload_dir['basedir'])) { |
|
549 | 549 | return false; |
550 | 550 | } |
551 | 551 | |
552 | 552 | $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb'; |
553 | - if ( !file_exists( $filename ) ) { |
|
553 | + if (!file_exists($filename)) { |
|
554 | 554 | return false; |
555 | 555 | } |
556 | 556 | |
@@ -561,10 +561,10 @@ discard block |
||
561 | 561 | try { |
562 | 562 | self::load_geoip2(); |
563 | 563 | |
564 | - if ( $filename = self::geoip2_country_dbfile() ) { |
|
565 | - return new \GeoIp2\Database\Reader( $filename ); |
|
564 | + if ($filename = self::geoip2_country_dbfile()) { |
|
565 | + return new \GeoIp2\Database\Reader($filename); |
|
566 | 566 | } |
567 | - } catch( Exception $e ) { |
|
567 | + } catch (Exception $e) { |
|
568 | 568 | return false; |
569 | 569 | } |
570 | 570 | |
@@ -575,183 +575,183 @@ discard block |
||
575 | 575 | try { |
576 | 576 | self::load_geoip2(); |
577 | 577 | |
578 | - if ( $filename = self::geoip2_city_dbfile() ) { |
|
579 | - return new \GeoIp2\Database\Reader( $filename ); |
|
578 | + if ($filename = self::geoip2_city_dbfile()) { |
|
579 | + return new \GeoIp2\Database\Reader($filename); |
|
580 | 580 | } |
581 | - } catch( Exception $e ) { |
|
581 | + } catch (Exception $e) { |
|
582 | 582 | return false; |
583 | 583 | } |
584 | 584 | |
585 | 585 | return false; |
586 | 586 | } |
587 | 587 | |
588 | - public static function geoip2_country_record( $ip_address ) { |
|
588 | + public static function geoip2_country_record($ip_address) { |
|
589 | 589 | try { |
590 | 590 | $reader = self::geoip2_country_reader(); |
591 | 591 | |
592 | - if ( $reader ) { |
|
593 | - $record = $reader->country( $ip_address ); |
|
592 | + if ($reader) { |
|
593 | + $record = $reader->country($ip_address); |
|
594 | 594 | |
595 | - if ( !empty( $record->country->isoCode ) ) { |
|
595 | + if (!empty($record->country->isoCode)) { |
|
596 | 596 | return $record; |
597 | 597 | } |
598 | 598 | } |
599 | - } catch(\InvalidArgumentException $e) { |
|
600 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
599 | + } catch (\InvalidArgumentException $e) { |
|
600 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
601 | 601 | |
602 | 602 | return false; |
603 | - } catch(\GeoIp2\Exception\AddressNotFoundException $e) { |
|
604 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
603 | + } catch (\GeoIp2\Exception\AddressNotFoundException $e) { |
|
604 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
605 | 605 | |
606 | 606 | return false; |
607 | - } catch( Exception $e ) { |
|
607 | + } catch (Exception $e) { |
|
608 | 608 | return false; |
609 | 609 | } |
610 | 610 | |
611 | 611 | return false; |
612 | 612 | } |
613 | 613 | |
614 | - public static function geoip2_city_record( $ip_address ) { |
|
614 | + public static function geoip2_city_record($ip_address) { |
|
615 | 615 | try { |
616 | 616 | $reader = self::geoip2_city_reader(); |
617 | 617 | |
618 | - if ( $reader ) { |
|
619 | - $record = $reader->city( $ip_address ); |
|
618 | + if ($reader) { |
|
619 | + $record = $reader->city($ip_address); |
|
620 | 620 | |
621 | - if ( !empty( $record->country->isoCode ) ) { |
|
621 | + if (!empty($record->country->isoCode)) { |
|
622 | 622 | return $record; |
623 | 623 | } |
624 | 624 | } |
625 | - } catch(\InvalidArgumentException $e) { |
|
626 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
625 | + } catch (\InvalidArgumentException $e) { |
|
626 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
627 | 627 | |
628 | 628 | return false; |
629 | - } catch(\GeoIp2\Exception\AddressNotFoundException $e) { |
|
630 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
629 | + } catch (\GeoIp2\Exception\AddressNotFoundException $e) { |
|
630 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
631 | 631 | |
632 | 632 | return false; |
633 | - } catch( Exception $e ) { |
|
633 | + } catch (Exception $e) { |
|
634 | 634 | return false; |
635 | 635 | } |
636 | 636 | |
637 | 637 | return false; |
638 | 638 | } |
639 | 639 | |
640 | - public static function geoip2_country_code( $ip_address ) { |
|
641 | - $record = self::geoip2_country_record( $ip_address ); |
|
642 | - return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country(); |
|
640 | + public static function geoip2_country_code($ip_address) { |
|
641 | + $record = self::geoip2_country_record($ip_address); |
|
642 | + return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country(); |
|
643 | 643 | } |
644 | 644 | |
645 | 645 | // Find country by IP address. |
646 | - public static function get_country_by_ip( $ip = '' ) { |
|
646 | + public static function get_country_by_ip($ip = '') { |
|
647 | 647 | global $wpinv_ip_address_country; |
648 | 648 | return ''; |
649 | - if ( !empty( $wpinv_ip_address_country ) ) { |
|
649 | + if (!empty($wpinv_ip_address_country)) { |
|
650 | 650 | return $wpinv_ip_address_country; |
651 | 651 | } |
652 | 652 | |
653 | - if ( empty( $ip ) ) { |
|
653 | + if (empty($ip)) { |
|
654 | 654 | $ip = wpinv_get_ip(); |
655 | 655 | } |
656 | 656 | |
657 | - $ip_country_service = wpinv_get_option( 'vat_ip_lookup' ); |
|
658 | - $is_default = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false; |
|
657 | + $ip_country_service = wpinv_get_option('vat_ip_lookup'); |
|
658 | + $is_default = empty($ip_country_service) || $ip_country_service === 'default' ? true : false; |
|
659 | 659 | |
660 | - if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country. |
|
661 | - if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) { |
|
660 | + if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country. |
|
661 | + if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) { |
|
662 | 662 | try { |
663 | - $wpinv_ip_address_country = geoip_country_code_by_name( $ip ); |
|
664 | - } catch( Exception $e ) { |
|
665 | - wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' ); |
|
663 | + $wpinv_ip_address_country = geoip_country_code_by_name($ip); |
|
664 | + } catch (Exception $e) { |
|
665 | + wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )'); |
|
666 | 666 | } |
667 | - } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) { |
|
668 | - $wpinv_ip_address_country = self::geoip2_country_code( $ip ); |
|
669 | - } else if ( function_exists( 'simplexml_load_file' ) && ini_get('allow_url_fopen') && ( $ip_country_service === 'geoplugin' || $is_default ) ) { |
|
670 | - $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip ); |
|
667 | + } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) { |
|
668 | + $wpinv_ip_address_country = self::geoip2_country_code($ip); |
|
669 | + } else if (function_exists('simplexml_load_file') && ini_get('allow_url_fopen') && ($ip_country_service === 'geoplugin' || $is_default)) { |
|
670 | + $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip); |
|
671 | 671 | |
672 | - if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) { |
|
673 | - $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode; |
|
672 | + if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) { |
|
673 | + $wpinv_ip_address_country = (string) $load_xml->geoplugin_countryCode; |
|
674 | 674 | } |
675 | - }elseif(!empty( $ip )){ |
|
675 | + }elseif (!empty($ip)) { |
|
676 | 676 | $url = 'http://ip-api.com/json/' . $ip; |
677 | 677 | $response = wp_remote_get($url); |
678 | 678 | |
679 | - if ( is_array( $response ) && wp_remote_retrieve_response_code( $response ) == '200' ) { |
|
680 | - $data = json_decode(wp_remote_retrieve_body( $response ),true); |
|
681 | - if(!empty($data['countryCode'])){ |
|
682 | - $wpinv_ip_address_country = (string)$data['countryCode']; |
|
679 | + if (is_array($response) && wp_remote_retrieve_response_code($response) == '200') { |
|
680 | + $data = json_decode(wp_remote_retrieve_body($response), true); |
|
681 | + if (!empty($data['countryCode'])) { |
|
682 | + $wpinv_ip_address_country = (string) $data['countryCode']; |
|
683 | 683 | } |
684 | 684 | } |
685 | 685 | } |
686 | 686 | } |
687 | 687 | |
688 | - if ( empty( $wpinv_ip_address_country ) ) { |
|
688 | + if (empty($wpinv_ip_address_country)) { |
|
689 | 689 | $wpinv_ip_address_country = wpinv_get_default_country(); |
690 | 690 | } |
691 | 691 | |
692 | 692 | return $wpinv_ip_address_country; |
693 | 693 | } |
694 | 694 | |
695 | - public static function sanitize_vat_settings( $input ) { |
|
695 | + public static function sanitize_vat_settings($input) { |
|
696 | 696 | global $wpinv_options; |
697 | 697 | |
698 | 698 | $valid = false; |
699 | 699 | $message = ''; |
700 | 700 | |
701 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
702 | - if ( empty( $wpinv_options['vat_offline_check'] ) ) { |
|
703 | - $valid = self::offline_check( $input['vat_number'] ); |
|
701 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
702 | + if (empty($wpinv_options['vat_offline_check'])) { |
|
703 | + $valid = self::offline_check($input['vat_number']); |
|
704 | 704 | } else { |
705 | 705 | $valid = true; |
706 | 706 | } |
707 | 707 | |
708 | - $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' ); |
|
708 | + $message = $valid ? '' : __('VAT number not validated', 'invoicing'); |
|
709 | 709 | } else { |
710 | - $result = self::check_vat( $input['vat_number'] ); |
|
710 | + $result = self::check_vat($input['vat_number']); |
|
711 | 711 | |
712 | - if ( empty( $result['valid'] ) ) { |
|
712 | + if (empty($result['valid'])) { |
|
713 | 713 | $valid = false; |
714 | 714 | $message = $result['message']; |
715 | 715 | } else { |
716 | - $valid = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] ); |
|
717 | - $message = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' ); |
|
716 | + $valid = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']); |
|
717 | + $message = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing'); |
|
718 | 718 | } |
719 | 719 | } |
720 | 720 | |
721 | - if ( $message && self::is_vat_validated() != $valid ) { |
|
722 | - add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) ); |
|
721 | + if ($message && self::is_vat_validated() != $valid) { |
|
722 | + add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error')); |
|
723 | 723 | } |
724 | 724 | |
725 | 725 | $input['vat_valid'] = $valid; |
726 | 726 | return $input; |
727 | 727 | } |
728 | 728 | |
729 | - public static function sanitize_vat_rates( $input ) { |
|
730 | - if( !wpinv_current_user_can_manage_invoicing() ) { |
|
731 | - add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' ); |
|
729 | + public static function sanitize_vat_rates($input) { |
|
730 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
731 | + add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error'); |
|
732 | 732 | return $input; |
733 | 733 | } |
734 | 734 | |
735 | 735 | $vat_classes = self::get_rate_classes(); |
736 | - $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : ''; |
|
736 | + $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : ''; |
|
737 | 737 | |
738 | - if ( empty( $vat_class ) ) { |
|
739 | - add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' ); |
|
738 | + if (empty($vat_class)) { |
|
739 | + add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error'); |
|
740 | 740 | |
741 | 741 | return $input; |
742 | 742 | } |
743 | 743 | |
744 | - $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array(); |
|
744 | + $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array(); |
|
745 | 745 | |
746 | - if ( $vat_class === '_standard' ) { |
|
746 | + if ($vat_class === '_standard') { |
|
747 | 747 | // Save the active rates in the invoice settings |
748 | - update_option( 'wpinv_tax_rates', $new_rates ); |
|
748 | + update_option('wpinv_tax_rates', $new_rates); |
|
749 | 749 | } else { |
750 | 750 | // Get the existing set of rates |
751 | 751 | $rates = self::get_non_standard_rates(); |
752 | 752 | $rates[$vat_class] = $new_rates; |
753 | 753 | |
754 | - update_option( 'wpinv_vat_rates', $rates ); |
|
754 | + update_option('wpinv_vat_rates', $rates); |
|
755 | 755 | } |
756 | 756 | |
757 | 757 | return $input; |
@@ -761,71 +761,71 @@ discard block |
||
761 | 761 | $response = array(); |
762 | 762 | $response['success'] = false; |
763 | 763 | |
764 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
765 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
766 | - wp_send_json( $response ); |
|
764 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
765 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
766 | + wp_send_json($response); |
|
767 | 767 | } |
768 | 768 | |
769 | - $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false; |
|
770 | - $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false; |
|
769 | + $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false; |
|
770 | + $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false; |
|
771 | 771 | |
772 | - if ( empty( $vat_class_name ) ) { |
|
773 | - $response['error'] = __( 'Select the VAT rate name', 'invoicing' ); |
|
774 | - wp_send_json( $response ); |
|
772 | + if (empty($vat_class_name)) { |
|
773 | + $response['error'] = __('Select the VAT rate name', 'invoicing'); |
|
774 | + wp_send_json($response); |
|
775 | 775 | } |
776 | 776 | |
777 | - $vat_classes = (array)self::get_rate_classes(); |
|
777 | + $vat_classes = (array) self::get_rate_classes(); |
|
778 | 778 | |
779 | - if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) { |
|
780 | - $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name ); |
|
781 | - wp_send_json( $response ); |
|
779 | + if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) { |
|
780 | + $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name); |
|
781 | + wp_send_json($response); |
|
782 | 782 | } |
783 | 783 | |
784 | - $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name ); |
|
785 | - $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) ); |
|
784 | + $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name); |
|
785 | + $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key)); |
|
786 | 786 | |
787 | - $vat_classes = (array)self::get_rate_classes( true ); |
|
788 | - $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc ); |
|
787 | + $vat_classes = (array) self::get_rate_classes(true); |
|
788 | + $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc); |
|
789 | 789 | |
790 | - update_option( '_wpinv_vat_rate_classes', $vat_classes ); |
|
790 | + update_option('_wpinv_vat_rate_classes', $vat_classes); |
|
791 | 791 | |
792 | 792 | $response['success'] = true; |
793 | - $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=' . $rate_class_key ); |
|
793 | + $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=' . $rate_class_key); |
|
794 | 794 | |
795 | - wp_send_json( $response ); |
|
795 | + wp_send_json($response); |
|
796 | 796 | } |
797 | 797 | |
798 | 798 | public static function delete_class() { |
799 | 799 | $response = array(); |
800 | 800 | $response['success'] = false; |
801 | 801 | |
802 | - if ( !wpinv_current_user_can_manage_invoicing() || !isset( $_POST['class'] ) ) { |
|
803 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
804 | - wp_send_json( $response ); |
|
802 | + if (!wpinv_current_user_can_manage_invoicing() || !isset($_POST['class'])) { |
|
803 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
804 | + wp_send_json($response); |
|
805 | 805 | } |
806 | 806 | |
807 | - $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false; |
|
808 | - $vat_classes = (array)self::get_rate_classes(); |
|
807 | + $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false; |
|
808 | + $vat_classes = (array) self::get_rate_classes(); |
|
809 | 809 | |
810 | - if ( !isset( $vat_classes[$vat_class] ) ) { |
|
811 | - $response['error'] = __( 'Requested class does not exists', 'invoicing' ); |
|
812 | - wp_send_json( $response ); |
|
810 | + if (!isset($vat_classes[$vat_class])) { |
|
811 | + $response['error'] = __('Requested class does not exists', 'invoicing'); |
|
812 | + wp_send_json($response); |
|
813 | 813 | } |
814 | 814 | |
815 | - if ( $vat_class == '_new' || $vat_class == '_standard' ) { |
|
816 | - $response['error'] = __( 'You can not delete standard rates class', 'invoicing' ); |
|
817 | - wp_send_json( $response ); |
|
815 | + if ($vat_class == '_new' || $vat_class == '_standard') { |
|
816 | + $response['error'] = __('You can not delete standard rates class', 'invoicing'); |
|
817 | + wp_send_json($response); |
|
818 | 818 | } |
819 | 819 | |
820 | - $vat_classes = (array)self::get_rate_classes( true ); |
|
821 | - unset( $vat_classes[$vat_class] ); |
|
820 | + $vat_classes = (array) self::get_rate_classes(true); |
|
821 | + unset($vat_classes[$vat_class]); |
|
822 | 822 | |
823 | - update_option( '_wpinv_vat_rate_classes', $vat_classes ); |
|
823 | + update_option('_wpinv_vat_rate_classes', $vat_classes); |
|
824 | 824 | |
825 | 825 | $response['success'] = true; |
826 | - $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=_new' ); |
|
826 | + $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=_new'); |
|
827 | 827 | |
828 | - wp_send_json( $response ); |
|
828 | + wp_send_json($response); |
|
829 | 829 | } |
830 | 830 | |
831 | 831 | public static function update_eu_rates() { |
@@ -834,72 +834,72 @@ discard block |
||
834 | 834 | $response['error'] = null; |
835 | 835 | $response['data'] = null; |
836 | 836 | |
837 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
838 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
839 | - wp_send_json( $response ); |
|
837 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
838 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
839 | + wp_send_json($response); |
|
840 | 840 | } |
841 | 841 | |
842 | - $group = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : ''; |
|
843 | - $euvatrates = self::request_euvatrates( $group ); |
|
842 | + $group = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : ''; |
|
843 | + $euvatrates = self::request_euvatrates($group); |
|
844 | 844 | |
845 | - if ( !empty( $euvatrates ) ) { |
|
846 | - if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) { |
|
845 | + if (!empty($euvatrates)) { |
|
846 | + if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) { |
|
847 | 847 | $response['success'] = true; |
848 | 848 | $response['data']['rates'] = $euvatrates['rates']; |
849 | - } else if ( !empty( $euvatrates['error'] ) ) { |
|
849 | + } else if (!empty($euvatrates['error'])) { |
|
850 | 850 | $response['error'] = $euvatrates['error']; |
851 | 851 | } |
852 | 852 | } |
853 | 853 | |
854 | - wp_send_json( $response ); |
|
854 | + wp_send_json($response); |
|
855 | 855 | } |
856 | 856 | |
857 | 857 | public static function hide_vat_fields() { |
858 | - $hide = wpinv_get_option( 'vat_disable_fields' ); |
|
858 | + $hide = wpinv_get_option('vat_disable_fields'); |
|
859 | 859 | |
860 | - return apply_filters( 'wpinv_hide_vat_fields', $hide ); |
|
860 | + return apply_filters('wpinv_hide_vat_fields', $hide); |
|
861 | 861 | } |
862 | 862 | |
863 | 863 | public static function same_country_rule() { |
864 | - $same_country_rule = wpinv_get_option( 'vat_same_country_rule' ); |
|
864 | + $same_country_rule = wpinv_get_option('vat_same_country_rule'); |
|
865 | 865 | |
866 | - return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule ); |
|
866 | + return apply_filters('wpinv_vat_same_country_rule', $same_country_rule); |
|
867 | 867 | } |
868 | 868 | |
869 | 869 | public static function get_vat_name() { |
870 | - $vat_name = wpinv_get_option( 'vat_name' ); |
|
871 | - $vat_name = !empty( $vat_name ) ? $vat_name : 'VAT'; |
|
870 | + $vat_name = wpinv_get_option('vat_name'); |
|
871 | + $vat_name = !empty($vat_name) ? $vat_name : 'VAT'; |
|
872 | 872 | |
873 | - return apply_filters( 'wpinv_get_owner_vat_name', $vat_name ); |
|
873 | + return apply_filters('wpinv_get_owner_vat_name', $vat_name); |
|
874 | 874 | } |
875 | 875 | |
876 | 876 | public static function get_company_name() { |
877 | - $company_name = wpinv_get_option( 'vat_company_name' ); |
|
877 | + $company_name = wpinv_get_option('vat_company_name'); |
|
878 | 878 | |
879 | - return apply_filters( 'wpinv_get_owner_company_name', $company_name ); |
|
879 | + return apply_filters('wpinv_get_owner_company_name', $company_name); |
|
880 | 880 | } |
881 | 881 | |
882 | 882 | public static function get_vat_number() { |
883 | - $vat_number = wpinv_get_option( 'vat_number' ); |
|
883 | + $vat_number = wpinv_get_option('vat_number'); |
|
884 | 884 | |
885 | - return apply_filters( 'wpinv_get_owner_vat_number', $vat_number ); |
|
885 | + return apply_filters('wpinv_get_owner_vat_number', $vat_number); |
|
886 | 886 | } |
887 | 887 | |
888 | 888 | public static function is_vat_validated() { |
889 | - $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' ); |
|
889 | + $validated = self::get_vat_number() && wpinv_get_option('vat_valid'); |
|
890 | 890 | |
891 | - return apply_filters( 'wpinv_is_owner_vat_validated', $validated ); |
|
891 | + return apply_filters('wpinv_is_owner_vat_validated', $validated); |
|
892 | 892 | } |
893 | 893 | |
894 | - public static function sanitize_vat( $vat_number, $country_code = '' ) { |
|
895 | - $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) ); |
|
894 | + public static function sanitize_vat($vat_number, $country_code = '') { |
|
895 | + $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number))); |
|
896 | 896 | |
897 | - if ( empty( $country_code ) ) { |
|
898 | - $country_code = substr( $vat_number, 0, 2 ); |
|
897 | + if (empty($country_code)) { |
|
898 | + $country_code = substr($vat_number, 0, 2); |
|
899 | 899 | } |
900 | 900 | |
901 | - if ( strpos( $vat_number , $country_code ) === 0 ) { |
|
902 | - $vat = str_replace( $country_code, '', $vat_number ); |
|
901 | + if (strpos($vat_number, $country_code) === 0) { |
|
902 | + $vat = str_replace($country_code, '', $vat_number); |
|
903 | 903 | } else { |
904 | 904 | $vat = $country_code . $vat_number; |
905 | 905 | } |
@@ -912,140 +912,140 @@ discard block |
||
912 | 912 | return $return; |
913 | 913 | } |
914 | 914 | |
915 | - public static function offline_check( $vat_number, $country_code = '', $formatted = false ) { |
|
916 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
915 | + public static function offline_check($vat_number, $country_code = '', $formatted = false) { |
|
916 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
917 | 917 | $vat_number = $vat['vat_number']; |
918 | 918 | $country_code = $vat['iso']; |
919 | 919 | $regex = array(); |
920 | 920 | |
921 | - switch ( $country_code ) { |
|
921 | + switch ($country_code) { |
|
922 | 922 | case 'AT': |
923 | - $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
923 | + $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
924 | 924 | break; |
925 | 925 | case 'BE': |
926 | - $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
926 | + $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
927 | 927 | break; |
928 | 928 | case 'BG': |
929 | - $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
929 | + $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
930 | 930 | break; |
931 | 931 | case 'CH': |
932 | 932 | case 'CHE': |
933 | - $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
933 | + $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
934 | 934 | break; |
935 | 935 | case 'CY': |
936 | - $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
936 | + $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
937 | 937 | break; |
938 | 938 | case 'CZ': |
939 | - $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
939 | + $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
940 | 940 | break; |
941 | 941 | case 'DE': |
942 | - $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
942 | + $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
943 | 943 | break; |
944 | 944 | case 'DK': |
945 | - $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
945 | + $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
946 | 946 | break; |
947 | 947 | case 'EE': |
948 | - $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
948 | + $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
949 | 949 | break; |
950 | 950 | case 'EL': |
951 | - $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
951 | + $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
952 | 952 | break; |
953 | 953 | case 'ES': |
954 | - $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
955 | - $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
956 | - $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
957 | - $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
954 | + $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
955 | + $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
956 | + $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
957 | + $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
958 | 958 | break; |
959 | 959 | case 'EU': |
960 | - $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
960 | + $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
961 | 961 | break; |
962 | 962 | case 'FI': |
963 | - $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
963 | + $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
964 | 964 | break; |
965 | 965 | case 'FR': |
966 | - $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
967 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
968 | - $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
969 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
966 | + $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
967 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
968 | + $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
969 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
970 | 970 | break; |
971 | 971 | case 'GB': |
972 | - $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
973 | - $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
974 | - $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
975 | - $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
972 | + $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
973 | + $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
974 | + $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
975 | + $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
976 | 976 | break; |
977 | 977 | case 'GR': |
978 | - $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
978 | + $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
979 | 979 | break; |
980 | 980 | case 'HR': |
981 | - $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
981 | + $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
982 | 982 | break; |
983 | 983 | case 'HU': |
984 | - $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
984 | + $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
985 | 985 | break; |
986 | 986 | case 'IE': |
987 | - $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
988 | - $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
989 | - $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
987 | + $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
988 | + $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
989 | + $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
990 | 990 | break; |
991 | 991 | case 'IT': |
992 | - $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
992 | + $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
993 | 993 | break; |
994 | 994 | case 'LV': |
995 | - $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
995 | + $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
996 | 996 | break; |
997 | 997 | case 'LT': |
998 | - $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
998 | + $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
999 | 999 | break; |
1000 | 1000 | case 'LU': |
1001 | - $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
1001 | + $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
1002 | 1002 | break; |
1003 | 1003 | case 'MT': |
1004 | - $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
1004 | + $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
1005 | 1005 | break; |
1006 | 1006 | case 'NL': |
1007 | - $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
1007 | + $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
1008 | 1008 | break; |
1009 | 1009 | case 'NO': |
1010 | - $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
1010 | + $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
1011 | 1011 | break; |
1012 | 1012 | case 'PL': |
1013 | - $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
1013 | + $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
1014 | 1014 | break; |
1015 | 1015 | case 'PT': |
1016 | - $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
1016 | + $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
1017 | 1017 | break; |
1018 | 1018 | case 'RO': |
1019 | - $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
1019 | + $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
1020 | 1020 | break; |
1021 | 1021 | case 'RS': |
1022 | - $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
1022 | + $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
1023 | 1023 | break; |
1024 | 1024 | case 'SI': |
1025 | - $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
1025 | + $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
1026 | 1026 | break; |
1027 | 1027 | case 'SK': |
1028 | - $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
1028 | + $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
1029 | 1029 | break; |
1030 | 1030 | case 'SE': |
1031 | - $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
1031 | + $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
1032 | 1032 | break; |
1033 | 1033 | default: |
1034 | 1034 | $regex = array(); |
1035 | 1035 | break; |
1036 | 1036 | } |
1037 | 1037 | |
1038 | - if ( empty( $regex ) ) { |
|
1038 | + if (empty($regex)) { |
|
1039 | 1039 | return false; |
1040 | 1040 | } |
1041 | 1041 | |
1042 | - foreach ( $regex as $pattern ) { |
|
1042 | + foreach ($regex as $pattern) { |
|
1043 | 1043 | $matches = null; |
1044 | - preg_match_all( $pattern, $vat_number, $matches ); |
|
1044 | + preg_match_all($pattern, $vat_number, $matches); |
|
1045 | 1045 | |
1046 | - if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) { |
|
1047 | - if ( $formatted ) { |
|
1048 | - return array( 'code' => $matches[1][0], 'number' => $matches[2][0] ); |
|
1046 | + if (!empty($matches[1][0]) && !empty($matches[2][0])) { |
|
1047 | + if ($formatted) { |
|
1048 | + return array('code' => $matches[1][0], 'number' => $matches[2][0]); |
|
1049 | 1049 | } else { |
1050 | 1050 | return true; |
1051 | 1051 | } |
@@ -1055,75 +1055,75 @@ discard block |
||
1055 | 1055 | return false; |
1056 | 1056 | } |
1057 | 1057 | |
1058 | - public static function vies_check( $vat_number, $country_code = '', $result = false ) { |
|
1059 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
1058 | + public static function vies_check($vat_number, $country_code = '', $result = false) { |
|
1059 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
1060 | 1060 | $vat_number = $vat['vat']; |
1061 | 1061 | $iso = $vat['iso']; |
1062 | 1062 | |
1063 | - $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number ); |
|
1063 | + $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number); |
|
1064 | 1064 | |
1065 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
1066 | - $response = file_get_contents( $url ); |
|
1067 | - } else if ( function_exists( 'curl_init' ) ) { |
|
1065 | + if (ini_get('allow_url_fopen')) { |
|
1066 | + $response = file_get_contents($url); |
|
1067 | + } else if (function_exists('curl_init')) { |
|
1068 | 1068 | $ch = curl_init(); |
1069 | 1069 | |
1070 | - curl_setopt( $ch, CURLOPT_URL, $url ); |
|
1071 | - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 ); |
|
1072 | - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); |
|
1073 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); |
|
1074 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); |
|
1070 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
1071 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); |
|
1072 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
1073 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
|
1074 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
1075 | 1075 | |
1076 | - $response = curl_exec( $ch ); |
|
1076 | + $response = curl_exec($ch); |
|
1077 | 1077 | |
1078 | - if ( curl_errno( $ch ) ) { |
|
1079 | - wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' ); |
|
1078 | + if (curl_errno($ch)) { |
|
1079 | + wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR'); |
|
1080 | 1080 | $response = ''; |
1081 | 1081 | } |
1082 | 1082 | |
1083 | - curl_close( $ch ); |
|
1083 | + curl_close($ch); |
|
1084 | 1084 | } else { |
1085 | - 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' ); |
|
1085 | + 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'); |
|
1086 | 1086 | } |
1087 | 1087 | |
1088 | - if ( empty( $response ) ) { |
|
1088 | + if (empty($response)) { |
|
1089 | 1089 | return $result; |
1090 | 1090 | } |
1091 | 1091 | |
1092 | - if ( preg_match( '/invalid VAT number/i', $response ) ) { |
|
1092 | + if (preg_match('/invalid VAT number/i', $response)) { |
|
1093 | 1093 | return false; |
1094 | - } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) { |
|
1095 | - $content = explode( "valid VAT number", htmlentities( $response ) ); |
|
1094 | + } else if (preg_match('/valid VAT number/i', $response, $matches)) { |
|
1095 | + $content = explode("valid VAT number", htmlentities($response)); |
|
1096 | 1096 | |
1097 | - if ( !empty( $content[1] ) ) { |
|
1098 | - preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches ); |
|
1097 | + if (!empty($content[1])) { |
|
1098 | + preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches); |
|
1099 | 1099 | |
1100 | - if ( !empty( $matches[2] ) && $matches[3] ) { |
|
1100 | + if (!empty($matches[2]) && $matches[3]) { |
|
1101 | 1101 | $return = array(); |
1102 | 1102 | |
1103 | - foreach ( $matches[2] as $key => $label ) { |
|
1104 | - $label = trim( $label ); |
|
1103 | + foreach ($matches[2] as $key => $label) { |
|
1104 | + $label = trim($label); |
|
1105 | 1105 | |
1106 | - switch ( strtolower( $label ) ) { |
|
1106 | + switch (strtolower($label)) { |
|
1107 | 1107 | case 'member state': |
1108 | - $return['state'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1108 | + $return['state'] = trim(strip_tags($matches[3][$key])); |
|
1109 | 1109 | break; |
1110 | 1110 | case 'vat number': |
1111 | - $return['number'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1111 | + $return['number'] = trim(strip_tags($matches[3][$key])); |
|
1112 | 1112 | break; |
1113 | 1113 | case 'name': |
1114 | - $return['company'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1114 | + $return['company'] = trim(strip_tags($matches[3][$key])); |
|
1115 | 1115 | break; |
1116 | 1116 | case 'address': |
1117 | - $address = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) ); |
|
1118 | - $return['address'] = trim( strip_tags( $address, '<br>' ) ); |
|
1117 | + $address = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key]))); |
|
1118 | + $return['address'] = trim(strip_tags($address, '<br>')); |
|
1119 | 1119 | break; |
1120 | 1120 | case 'consultation number': |
1121 | - $return['consultation'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1121 | + $return['consultation'] = trim(strip_tags($matches[3][$key])); |
|
1122 | 1122 | break; |
1123 | 1123 | } |
1124 | 1124 | } |
1125 | 1125 | |
1126 | - if ( !empty( $return ) ) { |
|
1126 | + if (!empty($return)) { |
|
1127 | 1127 | return $return; |
1128 | 1128 | } |
1129 | 1129 | } |
@@ -1135,62 +1135,62 @@ discard block |
||
1135 | 1135 | } |
1136 | 1136 | } |
1137 | 1137 | |
1138 | - public static function check_vat( $vat_number, $country_code = '' ) { |
|
1138 | + public static function check_vat($vat_number, $country_code = '') { |
|
1139 | 1139 | $vat_name = self::get_vat_name(); |
1140 | 1140 | |
1141 | 1141 | $return = array(); |
1142 | 1142 | $return['valid'] = false; |
1143 | - $return['message'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
1143 | + $return['message'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
1144 | 1144 | |
1145 | - if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) { |
|
1145 | + if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) { |
|
1146 | 1146 | return $return; |
1147 | 1147 | } |
1148 | 1148 | |
1149 | - $response = self::vies_check( $vat_number, $country_code ); |
|
1149 | + $response = self::vies_check($vat_number, $country_code); |
|
1150 | 1150 | |
1151 | - if ( $response ) { |
|
1152 | - $return['valid'] = true; |
|
1151 | + if ($response) { |
|
1152 | + $return['valid'] = true; |
|
1153 | 1153 | |
1154 | - if ( is_array( $response ) ) { |
|
1155 | - $return['company'] = isset( $response['company'] ) ? $response['company'] : ''; |
|
1156 | - $return['address'] = isset( $response['address'] ) ? $response['address'] : ''; |
|
1154 | + if (is_array($response)) { |
|
1155 | + $return['company'] = isset($response['company']) ? $response['company'] : ''; |
|
1156 | + $return['address'] = isset($response['address']) ? $response['address'] : ''; |
|
1157 | 1157 | $return['message'] = $return['company'] . '<br/>' . $return['address']; |
1158 | 1158 | } |
1159 | 1159 | } else { |
1160 | 1160 | $return['valid'] = false; |
1161 | - $return['message'] = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name ); |
|
1161 | + $return['message'] = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name); |
|
1162 | 1162 | } |
1163 | 1163 | |
1164 | 1164 | return $return; |
1165 | 1165 | } |
1166 | 1166 | |
1167 | - public static function request_euvatrates( $group ) { |
|
1167 | + public static function request_euvatrates($group) { |
|
1168 | 1168 | $response = array(); |
1169 | 1169 | $response['success'] = false; |
1170 | 1170 | $response['error'] = null; |
1171 | 1171 | $response['eurates'] = null; |
1172 | 1172 | |
1173 | 1173 | $euvatrates_url = 'https://euvatrates.com/rates.json'; |
1174 | - $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url ); |
|
1175 | - $api_response = wp_remote_get( $euvatrates_url ); |
|
1174 | + $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url); |
|
1175 | + $api_response = wp_remote_get($euvatrates_url); |
|
1176 | 1176 | |
1177 | 1177 | try { |
1178 | - if ( is_wp_error( $api_response ) ) { |
|
1179 | - $response['error'] = __( $api_response->get_error_message(), 'invoicing' ); |
|
1178 | + if (is_wp_error($api_response)) { |
|
1179 | + $response['error'] = __($api_response->get_error_message(), 'invoicing'); |
|
1180 | 1180 | } else { |
1181 | - $body = json_decode( $api_response['body'] ); |
|
1182 | - if ( isset( $body->rates ) ) { |
|
1181 | + $body = json_decode($api_response['body']); |
|
1182 | + if (isset($body->rates)) { |
|
1183 | 1183 | $rates = array(); |
1184 | 1184 | |
1185 | - foreach ( $body->rates as $country_code => $rate ) { |
|
1185 | + foreach ($body->rates as $country_code => $rate) { |
|
1186 | 1186 | $vat_rate = array(); |
1187 | 1187 | $vat_rate['country'] = $rate->country; |
1188 | - $vat_rate['standard'] = (float)$rate->standard_rate; |
|
1189 | - $vat_rate['reduced'] = (float)$rate->reduced_rate; |
|
1190 | - $vat_rate['superreduced'] = (float)$rate->super_reduced_rate; |
|
1191 | - $vat_rate['parking'] = (float)$rate->parking_rate; |
|
1188 | + $vat_rate['standard'] = (float) $rate->standard_rate; |
|
1189 | + $vat_rate['reduced'] = (float) $rate->reduced_rate; |
|
1190 | + $vat_rate['superreduced'] = (float) $rate->super_reduced_rate; |
|
1191 | + $vat_rate['parking'] = (float) $rate->parking_rate; |
|
1192 | 1192 | |
1193 | - if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) { |
|
1193 | + if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) { |
|
1194 | 1194 | $vat_rate_group = array(); |
1195 | 1195 | $vat_rate_group['country'] = $rate->country; |
1196 | 1196 | $vat_rate_group[$group] = $vat_rate[$group]; |
@@ -1202,79 +1202,79 @@ discard block |
||
1202 | 1202 | } |
1203 | 1203 | |
1204 | 1204 | $response['success'] = true; |
1205 | - $response['rates'] = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group ); |
|
1205 | + $response['rates'] = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group); |
|
1206 | 1206 | } else { |
1207 | - $response['error'] = __( 'No EU rates found!', 'invoicing' ); |
|
1207 | + $response['error'] = __('No EU rates found!', 'invoicing'); |
|
1208 | 1208 | } |
1209 | 1209 | } |
1210 | - } catch ( Exception $e ) { |
|
1211 | - $response['error'] = __( $e->getMessage(), 'invoicing' ); |
|
1210 | + } catch (Exception $e) { |
|
1211 | + $response['error'] = __($e->getMessage(), 'invoicing'); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | - return apply_filters( 'wpinv_response_euvatrates', $response, $group ); |
|
1214 | + return apply_filters('wpinv_response_euvatrates', $response, $group); |
|
1215 | 1215 | } |
1216 | 1216 | |
1217 | - public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) { |
|
1217 | + public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) { |
|
1218 | 1218 | global $wpi_item_id, $wpi_country; |
1219 | 1219 | |
1220 | - if ( !empty( $_POST['wpinv_country'] ) ) { |
|
1221 | - $country_code = trim( $_POST['wpinv_country'] ); |
|
1222 | - } else if ( !empty( $_POST['country'] ) ) { |
|
1223 | - $country_code = trim( $_POST['country'] ); |
|
1224 | - } else if ( !empty( $wpi_country ) ) { |
|
1220 | + if (!empty($_POST['wpinv_country'])) { |
|
1221 | + $country_code = trim($_POST['wpinv_country']); |
|
1222 | + } else if (!empty($_POST['country'])) { |
|
1223 | + $country_code = trim($_POST['country']); |
|
1224 | + } else if (!empty($wpi_country)) { |
|
1225 | 1225 | $country_code = $wpi_country; |
1226 | 1226 | } else { |
1227 | - $country_code = self::get_user_country( '', $user_id ); |
|
1227 | + $country_code = self::get_user_country('', $user_id); |
|
1228 | 1228 | } |
1229 | 1229 | |
1230 | - if ( $is_digital === null && $wpi_item_id ) { |
|
1231 | - $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules(); |
|
1230 | + if ($is_digital === null && $wpi_item_id) { |
|
1231 | + $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules(); |
|
1232 | 1232 | } |
1233 | 1233 | |
1234 | - if ( !empty( $country_code ) ) { |
|
1235 | - $requires_vat = ( self::is_eu_state( $country_code ) && ( self::is_eu_state( self::$default_country ) || $is_digital ) ) || ( self::is_gst_country( $country_code ) && self::is_gst_country( self::$default_country ) ); |
|
1234 | + if (!empty($country_code)) { |
|
1235 | + $requires_vat = (self::is_eu_state($country_code) && (self::is_eu_state(self::$default_country) || $is_digital)) || (self::is_gst_country($country_code) && self::is_gst_country(self::$default_country)); |
|
1236 | 1236 | } |
1237 | 1237 | |
1238 | - return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id ); |
|
1238 | + return apply_filters('wpinv_requires_vat', $requires_vat, $user_id); |
|
1239 | 1239 | } |
1240 | 1240 | |
1241 | - public static function tax_label( $label = '' ) { |
|
1241 | + public static function tax_label($label = '') { |
|
1242 | 1242 | global $wpi_requires_vat; |
1243 | 1243 | |
1244 | - if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) { |
|
1245 | - $wpi_requires_vat = self::requires_vat( 0, false ); |
|
1244 | + if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) { |
|
1245 | + $wpi_requires_vat = self::requires_vat(0, false); |
|
1246 | 1246 | } |
1247 | 1247 | |
1248 | - return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) ); |
|
1248 | + return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing')); |
|
1249 | 1249 | } |
1250 | 1250 | |
1251 | 1251 | public static function standard_rates_label() { |
1252 | - return __( 'Standard Rates', 'invoicing' ); |
|
1252 | + return __('Standard Rates', 'invoicing'); |
|
1253 | 1253 | } |
1254 | 1254 | |
1255 | - public static function get_rate_classes( $with_desc = false ) { |
|
1256 | - $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true ); |
|
1257 | - $classes = maybe_unserialize( $rate_classes_option ); |
|
1255 | + public static function get_rate_classes($with_desc = false) { |
|
1256 | + $rate_classes_option = get_option('_wpinv_vat_rate_classes', true); |
|
1257 | + $classes = maybe_unserialize($rate_classes_option); |
|
1258 | 1258 | |
1259 | - if ( empty( $classes ) || !is_array( $classes ) ) { |
|
1259 | + if (empty($classes) || !is_array($classes)) { |
|
1260 | 1260 | $classes = array(); |
1261 | 1261 | } |
1262 | 1262 | |
1263 | 1263 | $rate_classes = array(); |
1264 | - if ( !array_key_exists( '_standard', $classes ) ) { |
|
1265 | - if ( $with_desc ) { |
|
1266 | - $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) ); |
|
1264 | + if (!array_key_exists('_standard', $classes)) { |
|
1265 | + if ($with_desc) { |
|
1266 | + $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing')); |
|
1267 | 1267 | } else { |
1268 | 1268 | $rate_classes['_standard'] = self::standard_rates_label(); |
1269 | 1269 | } |
1270 | 1270 | } |
1271 | 1271 | |
1272 | - foreach ( $classes as $key => $class ) { |
|
1273 | - $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key; |
|
1274 | - $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : ''; |
|
1272 | + foreach ($classes as $key => $class) { |
|
1273 | + $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key; |
|
1274 | + $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : ''; |
|
1275 | 1275 | |
1276 | - if ( $with_desc ) { |
|
1277 | - $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc ); |
|
1276 | + if ($with_desc) { |
|
1277 | + $rate_classes[$key] = array('name' => $name, 'desc' => $desc); |
|
1278 | 1278 | } else { |
1279 | 1279 | $rate_classes[$key] = $name; |
1280 | 1280 | } |
@@ -1285,15 +1285,15 @@ discard block |
||
1285 | 1285 | |
1286 | 1286 | public static function get_all_classes() { |
1287 | 1287 | $classes = self::get_rate_classes(); |
1288 | - $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' ); |
|
1288 | + $classes['_exempt'] = __('Exempt (0%)', 'invoicing'); |
|
1289 | 1289 | |
1290 | - return apply_filters( 'wpinv_vat_get_all_classes', $classes ); |
|
1290 | + return apply_filters('wpinv_vat_get_all_classes', $classes); |
|
1291 | 1291 | } |
1292 | 1292 | |
1293 | - public static function get_class_desc( $rate_class ) { |
|
1294 | - $rate_classes = self::get_rate_classes( true ); |
|
1293 | + public static function get_class_desc($rate_class) { |
|
1294 | + $rate_classes = self::get_rate_classes(true); |
|
1295 | 1295 | |
1296 | - if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) { |
|
1296 | + if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) { |
|
1297 | 1297 | return $rate_classes[$rate_class]['desc']; |
1298 | 1298 | } |
1299 | 1299 | |
@@ -1309,107 +1309,107 @@ discard block |
||
1309 | 1309 | 'increased' => 'Increased' |
1310 | 1310 | ); |
1311 | 1311 | |
1312 | - return apply_filters( 'wpinv_get_vat_groups', $vat_groups ); |
|
1312 | + return apply_filters('wpinv_get_vat_groups', $vat_groups); |
|
1313 | 1313 | } |
1314 | 1314 | |
1315 | 1315 | public static function get_rules() { |
1316 | 1316 | $vat_rules = array( |
1317 | - 'digital' => __( 'Digital Product', 'invoicing' ), |
|
1318 | - 'physical' => __( 'Physical Product', 'invoicing' ), |
|
1319 | - '_exempt' => __( 'Tax-Free Product', 'invoicing' ), |
|
1317 | + 'digital' => __('Digital Product', 'invoicing'), |
|
1318 | + 'physical' => __('Physical Product', 'invoicing'), |
|
1319 | + '_exempt' => __('Tax-Free Product', 'invoicing'), |
|
1320 | 1320 | ); |
1321 | - return apply_filters( 'wpinv_get_vat_rules', $vat_rules ); |
|
1321 | + return apply_filters('wpinv_get_vat_rules', $vat_rules); |
|
1322 | 1322 | } |
1323 | 1323 | |
1324 | - public static function get_vat_rates( $class ) { |
|
1325 | - if ( $class === '_standard' ) { |
|
1324 | + public static function get_vat_rates($class) { |
|
1325 | + if ($class === '_standard') { |
|
1326 | 1326 | return wpinv_get_tax_rates(); |
1327 | 1327 | } |
1328 | 1328 | |
1329 | 1329 | $rates = self::get_non_standard_rates(); |
1330 | 1330 | |
1331 | - return array_key_exists( $class, $rates ) ? $rates[$class] : array(); |
|
1331 | + return array_key_exists($class, $rates) ? $rates[$class] : array(); |
|
1332 | 1332 | } |
1333 | 1333 | |
1334 | 1334 | public static function get_non_standard_rates() { |
1335 | - $option = get_option( 'wpinv_vat_rates', array()); |
|
1336 | - return is_array( $option ) ? $option : array(); |
|
1335 | + $option = get_option('wpinv_vat_rates', array()); |
|
1336 | + return is_array($option) ? $option : array(); |
|
1337 | 1337 | } |
1338 | 1338 | |
1339 | 1339 | public static function allow_vat_rules() { |
1340 | - return ( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ? true : false ); |
|
1340 | + return (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules') ? true : false); |
|
1341 | 1341 | } |
1342 | 1342 | |
1343 | 1343 | public static function allow_vat_classes() { |
1344 | 1344 | return false; // TODO |
1345 | - return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false ); |
|
1345 | + return (wpinv_get_option('vat_allow_classes') ? true : false); |
|
1346 | 1346 | } |
1347 | 1347 | |
1348 | - public static function get_item_class( $postID ) { |
|
1349 | - $class = get_post_meta( $postID, '_wpinv_vat_class', true ); |
|
1348 | + public static function get_item_class($postID) { |
|
1349 | + $class = get_post_meta($postID, '_wpinv_vat_class', true); |
|
1350 | 1350 | |
1351 | - if ( empty( $class ) ) { |
|
1351 | + if (empty($class)) { |
|
1352 | 1352 | $class = '_standard'; |
1353 | 1353 | } |
1354 | 1354 | |
1355 | - return apply_filters( 'wpinv_get_item_vat_class', $class, $postID ); |
|
1355 | + return apply_filters('wpinv_get_item_vat_class', $class, $postID); |
|
1356 | 1356 | } |
1357 | 1357 | |
1358 | - public static function item_class_label( $postID ) { |
|
1358 | + public static function item_class_label($postID) { |
|
1359 | 1359 | $vat_classes = self::get_all_classes(); |
1360 | 1360 | |
1361 | - $class = self::get_item_class( $postID ); |
|
1362 | - $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' ); |
|
1361 | + $class = self::get_item_class($postID); |
|
1362 | + $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing'); |
|
1363 | 1363 | |
1364 | - return apply_filters( 'wpinv_item_class_label', $class, $postID ); |
|
1364 | + return apply_filters('wpinv_item_class_label', $class, $postID); |
|
1365 | 1365 | } |
1366 | 1366 | |
1367 | - public static function get_item_rule( $postID ) { |
|
1368 | - $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true ); |
|
1367 | + public static function get_item_rule($postID) { |
|
1368 | + $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true); |
|
1369 | 1369 | |
1370 | - if ( empty( $rule_type ) ) { |
|
1370 | + if (empty($rule_type)) { |
|
1371 | 1371 | $rule_type = self::allow_vat_rules() ? 'digital' : 'physical'; |
1372 | 1372 | } |
1373 | 1373 | |
1374 | - return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID ); |
|
1374 | + return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID); |
|
1375 | 1375 | } |
1376 | 1376 | |
1377 | - public static function item_rule_label( $postID ) { |
|
1377 | + public static function item_rule_label($postID) { |
|
1378 | 1378 | $vat_rules = self::get_rules(); |
1379 | - $vat_rule = self::get_item_rule( $postID ); |
|
1380 | - $vat_rule = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule; |
|
1379 | + $vat_rule = self::get_item_rule($postID); |
|
1380 | + $vat_rule = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule; |
|
1381 | 1381 | |
1382 | - return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID ); |
|
1382 | + return apply_filters('wpinv_item_rule_label', $vat_rule, $postID); |
|
1383 | 1383 | } |
1384 | 1384 | |
1385 | - public static function item_has_digital_rule( $item_id = 0 ) { |
|
1386 | - return self::get_item_rule( $item_id ) == 'digital' ? true : false; |
|
1385 | + public static function item_has_digital_rule($item_id = 0) { |
|
1386 | + return self::get_item_rule($item_id) == 'digital' ? true : false; |
|
1387 | 1387 | } |
1388 | 1388 | |
1389 | - public static function invoice_has_digital_rule( $invoice = 0 ) { |
|
1390 | - if ( !self::allow_vat_rules() ) { |
|
1389 | + public static function invoice_has_digital_rule($invoice = 0) { |
|
1390 | + if (!self::allow_vat_rules()) { |
|
1391 | 1391 | return false; |
1392 | 1392 | } |
1393 | 1393 | |
1394 | - if ( empty( $invoice ) ) { |
|
1394 | + if (empty($invoice)) { |
|
1395 | 1395 | return true; |
1396 | 1396 | } |
1397 | 1397 | |
1398 | - if ( is_int( $invoice ) ) { |
|
1399 | - $invoice = new WPInv_Invoice( $invoice ); |
|
1398 | + if (is_int($invoice)) { |
|
1399 | + $invoice = new WPInv_Invoice($invoice); |
|
1400 | 1400 | } |
1401 | 1401 | |
1402 | - if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) { |
|
1402 | + if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) { |
|
1403 | 1403 | return true; |
1404 | 1404 | } |
1405 | 1405 | |
1406 | - $cart_items = $invoice->get_cart_details(); |
|
1406 | + $cart_items = $invoice->get_cart_details(); |
|
1407 | 1407 | |
1408 | - if ( !empty( $cart_items ) ) { |
|
1408 | + if (!empty($cart_items)) { |
|
1409 | 1409 | $has_digital_rule = false; |
1410 | 1410 | |
1411 | - foreach ( $cart_items as $key => $item ) { |
|
1412 | - if ( self::item_has_digital_rule( $item['id'] ) ) { |
|
1411 | + foreach ($cart_items as $key => $item) { |
|
1412 | + if (self::item_has_digital_rule($item['id'])) { |
|
1413 | 1413 | $has_digital_rule = true; |
1414 | 1414 | break; |
1415 | 1415 | } |
@@ -1421,71 +1421,71 @@ discard block |
||
1421 | 1421 | return $has_digital_rule; |
1422 | 1422 | } |
1423 | 1423 | |
1424 | - public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) { |
|
1425 | - if ( !wpinv_use_taxes() ) { |
|
1424 | + public static function item_is_taxable($item_id = 0, $country = false, $state = false) { |
|
1425 | + if (!wpinv_use_taxes()) { |
|
1426 | 1426 | return false; |
1427 | 1427 | } |
1428 | 1428 | |
1429 | 1429 | $is_taxable = true; |
1430 | 1430 | |
1431 | - if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) { |
|
1431 | + if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') { |
|
1432 | 1432 | $is_taxable = false; |
1433 | 1433 | } |
1434 | 1434 | |
1435 | - if ( !empty( $item_id ) && self::get_item_rule( $item_id ) == '_exempt' ) { |
|
1435 | + if (!empty($item_id) && self::get_item_rule($item_id) == '_exempt') { |
|
1436 | 1436 | $is_taxable = false; |
1437 | 1437 | } |
1438 | 1438 | |
1439 | - return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state ); |
|
1439 | + return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state); |
|
1440 | 1440 | } |
1441 | 1441 | |
1442 | - public static function find_rate( $country, $state, $rate, $class ) { |
|
1442 | + public static function find_rate($country, $state, $rate, $class) { |
|
1443 | 1443 | global $wpi_zero_tax; |
1444 | 1444 | |
1445 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
1445 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
1446 | 1446 | return 0; |
1447 | 1447 | } |
1448 | 1448 | |
1449 | - $tax_rates = wpinv_get_tax_rates(); |
|
1449 | + $tax_rates = wpinv_get_tax_rates(); |
|
1450 | 1450 | |
1451 | - if ( $class !== '_standard' ) { |
|
1452 | - $class_rates = self::get_vat_rates( $class ); |
|
1451 | + if ($class !== '_standard') { |
|
1452 | + $class_rates = self::get_vat_rates($class); |
|
1453 | 1453 | |
1454 | - if ( is_array( $class_rates ) ) { |
|
1454 | + if (is_array($class_rates)) { |
|
1455 | 1455 | $indexed_class_rates = array(); |
1456 | 1456 | |
1457 | - foreach ( $class_rates as $key => $cr ) { |
|
1457 | + foreach ($class_rates as $key => $cr) { |
|
1458 | 1458 | $indexed_class_rates[$cr['country']] = $cr; |
1459 | 1459 | } |
1460 | 1460 | |
1461 | - $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) { |
|
1461 | + $tax_rates = array_map(function($tr) use($indexed_class_rates) { |
|
1462 | 1462 | $tr_country = $tr['country']; |
1463 | - if ( !isset( $indexed_class_rates[$tr_country] ) ) { |
|
1463 | + if (!isset($indexed_class_rates[$tr_country])) { |
|
1464 | 1464 | return $tr; |
1465 | 1465 | } |
1466 | 1466 | $icr = $indexed_class_rates[$tr_country]; |
1467 | - return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr; |
|
1467 | + return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr; |
|
1468 | 1468 | |
1469 | - }, $tax_rates, $class_rates ); |
|
1469 | + }, $tax_rates, $class_rates); |
|
1470 | 1470 | } |
1471 | 1471 | } |
1472 | 1472 | |
1473 | - if ( !empty( $tax_rates ) ) { |
|
1474 | - foreach ( $tax_rates as $key => $tax_rate ) { |
|
1475 | - if ( $country != $tax_rate['country'] ) |
|
1473 | + if (!empty($tax_rates)) { |
|
1474 | + foreach ($tax_rates as $key => $tax_rate) { |
|
1475 | + if ($country != $tax_rate['country']) |
|
1476 | 1476 | continue; |
1477 | 1477 | |
1478 | - if ( !empty( $tax_rate['global'] ) ) { |
|
1479 | - if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) { |
|
1480 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
1478 | + if (!empty($tax_rate['global'])) { |
|
1479 | + if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) { |
|
1480 | + $rate = number_format($tax_rate['rate'], 4); |
|
1481 | 1481 | } |
1482 | 1482 | } else { |
1483 | - if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
1483 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
1484 | 1484 | continue; |
1485 | 1485 | |
1486 | 1486 | $state_rate = $tax_rate['rate']; |
1487 | - if ( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
1488 | - $rate = number_format( $state_rate, 4 ); |
|
1487 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
1488 | + $rate = number_format($state_rate, 4); |
|
1489 | 1489 | } |
1490 | 1490 | } |
1491 | 1491 | } |
@@ -1494,84 +1494,84 @@ discard block |
||
1494 | 1494 | return $rate; |
1495 | 1495 | } |
1496 | 1496 | |
1497 | - public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) { |
|
1497 | + public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) { |
|
1498 | 1498 | global $wpinv_options, $wpi_session, $wpi_item_id, $wpi_zero_tax; |
1499 | 1499 | |
1500 | 1500 | $item_id = $item_id > 0 ? $item_id : $wpi_item_id; |
1501 | 1501 | $allow_vat_classes = self::allow_vat_classes(); |
1502 | - $class = $item_id ? self::get_item_class( $item_id ) : '_standard'; |
|
1502 | + $class = $item_id ? self::get_item_class($item_id) : '_standard'; |
|
1503 | 1503 | |
1504 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
1504 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
1505 | 1505 | return 0; |
1506 | - } else if ( !$allow_vat_classes ) { |
|
1506 | + } else if (!$allow_vat_classes) { |
|
1507 | 1507 | $class = '_standard'; |
1508 | 1508 | } |
1509 | 1509 | |
1510 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
1510 | + if (!empty($_POST['wpinv_country'])) { |
|
1511 | 1511 | $post_country = $_POST['wpinv_country']; |
1512 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
1512 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
1513 | 1513 | $post_country = $_POST['wpinv_country']; |
1514 | - } elseif( !empty( $_POST['country'] ) ) { |
|
1514 | + } elseif (!empty($_POST['country'])) { |
|
1515 | 1515 | $post_country = $_POST['country']; |
1516 | 1516 | } else { |
1517 | 1517 | $post_country = ''; |
1518 | 1518 | } |
1519 | 1519 | |
1520 | - $country = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country ); |
|
1521 | - $base_country = wpinv_is_base_country( $country ); |
|
1520 | + $country = !empty($post_country) ? $post_country : wpinv_default_billing_country($country); |
|
1521 | + $base_country = wpinv_is_base_country($country); |
|
1522 | 1522 | |
1523 | - $requires_vat = self::requires_vat( 0, false ); |
|
1524 | - $is_digital = self::get_item_rule( $item_id ) == 'digital' ; |
|
1525 | - $rate = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
1523 | + $requires_vat = self::requires_vat(0, false); |
|
1524 | + $is_digital = self::get_item_rule($item_id) == 'digital'; |
|
1525 | + $rate = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
1526 | 1526 | |
1527 | - if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country |
|
1527 | + if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country |
|
1528 | 1528 | $rate = 0; |
1529 | - } else if ( $requires_vat ) { |
|
1530 | - $vat_number = self::get_user_vat_number( '', 0, true ); |
|
1529 | + } else if ($requires_vat) { |
|
1530 | + $vat_number = self::get_user_vat_number('', 0, true); |
|
1531 | 1531 | $vat_info = self::current_vat_data(); |
1532 | 1532 | |
1533 | - if ( is_array( $vat_info ) ) { |
|
1534 | - $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : ""; |
|
1533 | + if (is_array($vat_info)) { |
|
1534 | + $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : ""; |
|
1535 | 1535 | } |
1536 | 1536 | |
1537 | - if ( $country == 'UK' ) { |
|
1537 | + if ($country == 'UK') { |
|
1538 | 1538 | $country = 'GB'; |
1539 | 1539 | } |
1540 | 1540 | |
1541 | - if ( !empty( $vat_number ) ) { |
|
1541 | + if (!empty($vat_number)) { |
|
1542 | 1542 | $rate = 0; |
1543 | 1543 | } else { |
1544 | - $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 |
|
1544 | + $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 |
|
1545 | 1545 | } |
1546 | 1546 | |
1547 | - if ( empty( $vat_number ) && !$is_digital ) { |
|
1548 | - if ( $base_country ) { |
|
1549 | - $rate = self::find_rate( $country, null, $rate, $class ); |
|
1547 | + if (empty($vat_number) && !$is_digital) { |
|
1548 | + if ($base_country) { |
|
1549 | + $rate = self::find_rate($country, null, $rate, $class); |
|
1550 | 1550 | } else { |
1551 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
1551 | + if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) { |
|
1552 | 1552 | $rate = $wpinv_options['eu_fallback_rate']; |
1553 | - } else if( !empty( $country ) ) { |
|
1554 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1553 | + } else if (!empty($country)) { |
|
1554 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1555 | 1555 | } |
1556 | 1556 | } |
1557 | - } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) { |
|
1558 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
1557 | + } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) { |
|
1558 | + if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) { |
|
1559 | 1559 | $rate = $wpinv_options['eu_fallback_rate']; |
1560 | - } else if( !empty( $country ) ) { |
|
1561 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1560 | + } else if (!empty($country)) { |
|
1561 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1562 | 1562 | } |
1563 | 1563 | } |
1564 | 1564 | } else { |
1565 | - if ( $is_digital ) { |
|
1565 | + if ($is_digital) { |
|
1566 | 1566 | $ip_country_code = self::get_country_by_ip(); |
1567 | 1567 | |
1568 | - if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) { |
|
1569 | - $rate = self::find_rate( $ip_country_code, '', 0, $class ); |
|
1568 | + if ($ip_country_code && self::is_eu_state($ip_country_code)) { |
|
1569 | + $rate = self::find_rate($ip_country_code, '', 0, $class); |
|
1570 | 1570 | } else { |
1571 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1571 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1572 | 1572 | } |
1573 | 1573 | } else { |
1574 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1574 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1575 | 1575 | } |
1576 | 1576 | } |
1577 | 1577 | |
@@ -1581,48 +1581,48 @@ discard block |
||
1581 | 1581 | public static function current_vat_data() { |
1582 | 1582 | global $wpi_session; |
1583 | 1583 | |
1584 | - return $wpi_session->get( 'user_vat_data' ); |
|
1584 | + return $wpi_session->get('user_vat_data'); |
|
1585 | 1585 | } |
1586 | 1586 | |
1587 | - public static function get_user_country( $country = '', $user_id = 0 ) { |
|
1588 | - $user_address = wpinv_get_user_address( $user_id, false ); |
|
1587 | + public static function get_user_country($country = '', $user_id = 0) { |
|
1588 | + $user_address = wpinv_get_user_address($user_id, false); |
|
1589 | 1589 | |
1590 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
1590 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
1591 | 1591 | $country = ''; |
1592 | 1592 | } |
1593 | 1593 | |
1594 | - $country = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country']; |
|
1595 | - $result = apply_filters( 'wpinv_get_user_country', $country, $user_id ); |
|
1594 | + $country = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country']; |
|
1595 | + $result = apply_filters('wpinv_get_user_country', $country, $user_id); |
|
1596 | 1596 | |
1597 | - if ( empty( $result ) ) { |
|
1597 | + if (empty($result)) { |
|
1598 | 1598 | $result = self::get_country_by_ip(); |
1599 | 1599 | } |
1600 | 1600 | |
1601 | 1601 | return $result; |
1602 | 1602 | } |
1603 | 1603 | |
1604 | - public static function set_user_country( $country = '', $user_id = 0 ) { |
|
1604 | + public static function set_user_country($country = '', $user_id = 0) { |
|
1605 | 1605 | global $wpi_userID; |
1606 | 1606 | |
1607 | - if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) { |
|
1607 | + if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) { |
|
1608 | 1608 | $country = wpinv_get_default_country(); |
1609 | 1609 | } |
1610 | 1610 | |
1611 | 1611 | return $country; |
1612 | 1612 | } |
1613 | 1613 | |
1614 | - public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) { |
|
1614 | + public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) { |
|
1615 | 1615 | global $wpi_current_id, $wpi_userID; |
1616 | 1616 | |
1617 | - if ( !empty( $_POST['new_user'] ) ) { |
|
1617 | + if (!empty($_POST['new_user'])) { |
|
1618 | 1618 | return ''; |
1619 | 1619 | } |
1620 | 1620 | |
1621 | - if ( empty( $user_id ) ) { |
|
1622 | - $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() ); |
|
1621 | + if (empty($user_id)) { |
|
1622 | + $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id()); |
|
1623 | 1623 | } |
1624 | 1624 | |
1625 | - $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true ); |
|
1625 | + $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true); |
|
1626 | 1626 | |
1627 | 1627 | /* TODO |
1628 | 1628 | if ( $is_valid && $vat_number ) { |
@@ -1633,38 +1633,38 @@ discard block |
||
1633 | 1633 | } |
1634 | 1634 | */ |
1635 | 1635 | |
1636 | - return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid ); |
|
1636 | + return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid); |
|
1637 | 1637 | } |
1638 | 1638 | |
1639 | - public static function get_user_company( $company = '', $user_id = 0 ) { |
|
1639 | + public static function get_user_company($company = '', $user_id = 0) { |
|
1640 | 1640 | global $wpi_current_id, $wpi_userID; |
1641 | 1641 | |
1642 | - if ( empty( $user_id ) ) { |
|
1643 | - $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() ); |
|
1642 | + if (empty($user_id)) { |
|
1643 | + $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id()); |
|
1644 | 1644 | } |
1645 | 1645 | |
1646 | - $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true ); |
|
1646 | + $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true); |
|
1647 | 1647 | |
1648 | - return apply_filters( 'wpinv_user_company', $company, $user_id ); |
|
1648 | + return apply_filters('wpinv_user_company', $company, $user_id); |
|
1649 | 1649 | } |
1650 | 1650 | |
1651 | - public static function save_user_vat_details( $company = '', $vat_number = '' ) { |
|
1652 | - $save = apply_filters( 'wpinv_allow_save_user_vat_details', true ); |
|
1651 | + public static function save_user_vat_details($company = '', $vat_number = '') { |
|
1652 | + $save = apply_filters('wpinv_allow_save_user_vat_details', true); |
|
1653 | 1653 | |
1654 | - if ( is_user_logged_in() && $save ) { |
|
1654 | + if (is_user_logged_in() && $save) { |
|
1655 | 1655 | $user_id = get_current_user_id(); |
1656 | 1656 | |
1657 | - if ( !empty( $vat_number ) ) { |
|
1658 | - update_user_meta( $user_id, '_wpinv_vat_number', $vat_number ); |
|
1657 | + if (!empty($vat_number)) { |
|
1658 | + update_user_meta($user_id, '_wpinv_vat_number', $vat_number); |
|
1659 | 1659 | } else { |
1660 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
1660 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
1661 | 1661 | } |
1662 | 1662 | |
1663 | - if ( !empty( $company ) ) { |
|
1664 | - update_user_meta( $user_id, '_wpinv_company', $company ); |
|
1663 | + if (!empty($company)) { |
|
1664 | + update_user_meta($user_id, '_wpinv_company', $company); |
|
1665 | 1665 | } else { |
1666 | - delete_user_meta( $user_id, '_wpinv_company'); |
|
1667 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
1666 | + delete_user_meta($user_id, '_wpinv_company'); |
|
1667 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
1668 | 1668 | } |
1669 | 1669 | } |
1670 | 1670 | |
@@ -1674,113 +1674,113 @@ discard block |
||
1674 | 1674 | public static function ajax_vat_validate() { |
1675 | 1675 | global $wpinv_options, $wpi_session; |
1676 | 1676 | |
1677 | - $is_checkout = ( !empty( $_POST['source'] ) && $_POST['source'] == 'checkout' ) ? true : false; |
|
1677 | + $is_checkout = (!empty($_POST['source']) && $_POST['source'] == 'checkout') ? true : false; |
|
1678 | 1678 | $response = array(); |
1679 | 1679 | $response['success'] = false; |
1680 | 1680 | |
1681 | - if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) { |
|
1682 | - $response['error'] = __( 'Invalid security nonce', 'invoicing' ); |
|
1683 | - wp_send_json( $response ); |
|
1681 | + if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) { |
|
1682 | + $response['error'] = __('Invalid security nonce', 'invoicing'); |
|
1683 | + wp_send_json($response); |
|
1684 | 1684 | } |
1685 | 1685 | |
1686 | - $vat_name = self::get_vat_name(); |
|
1686 | + $vat_name = self::get_vat_name(); |
|
1687 | 1687 | |
1688 | - if ( $is_checkout ) { |
|
1688 | + if ($is_checkout) { |
|
1689 | 1689 | $invoice = wpinv_get_invoice_cart(); |
1690 | 1690 | |
1691 | - if ( !self::requires_vat( false, 0, self::invoice_has_digital_rule( $invoice ) ) ) { |
|
1691 | + if (!self::requires_vat(false, 0, self::invoice_has_digital_rule($invoice))) { |
|
1692 | 1692 | $vat_info = array(); |
1693 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1693 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1694 | 1694 | |
1695 | 1695 | self::save_user_vat_details(); |
1696 | 1696 | |
1697 | 1697 | $response['success'] = true; |
1698 | - $response['message'] = wp_sprintf( __( 'Ignore %s', 'invoicing' ), $vat_name ); |
|
1699 | - wp_send_json( $response ); |
|
1698 | + $response['message'] = wp_sprintf(__('Ignore %s', 'invoicing'), $vat_name); |
|
1699 | + wp_send_json($response); |
|
1700 | 1700 | } |
1701 | 1701 | } |
1702 | 1702 | |
1703 | - $company = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : ''; |
|
1704 | - $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : ''; |
|
1703 | + $company = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : ''; |
|
1704 | + $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : ''; |
|
1705 | 1705 | |
1706 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
1707 | - if ( !is_array( $vat_info ) || empty( $vat_info ) ) { |
|
1708 | - $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true ); |
|
1706 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
1707 | + if (!is_array($vat_info) || empty($vat_info)) { |
|
1708 | + $vat_info = array('company'=> $company, 'number' => '', 'valid' => true); |
|
1709 | 1709 | } |
1710 | 1710 | |
1711 | - if ( empty( $vat_number ) ) { |
|
1712 | - if ( $is_checkout ) { |
|
1711 | + if (empty($vat_number)) { |
|
1712 | + if ($is_checkout) { |
|
1713 | 1713 | $response['success'] = true; |
1714 | - $response['message'] = wp_sprintf( __( 'No %s number has been applied. %s will be added to invoice totals', 'invoicing' ), $vat_name, $vat_name ); |
|
1714 | + $response['message'] = wp_sprintf(__('No %s number has been applied. %s will be added to invoice totals', 'invoicing'), $vat_name, $vat_name); |
|
1715 | 1715 | |
1716 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
1716 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
1717 | 1717 | $vat_info['number'] = ""; |
1718 | 1718 | $vat_info['valid'] = true; |
1719 | 1719 | |
1720 | - self::save_user_vat_details( $company ); |
|
1720 | + self::save_user_vat_details($company); |
|
1721 | 1721 | } else { |
1722 | - $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name ); |
|
1722 | + $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name); |
|
1723 | 1723 | |
1724 | 1724 | $vat_info['valid'] = false; |
1725 | 1725 | } |
1726 | 1726 | |
1727 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1728 | - wp_send_json( $response ); |
|
1727 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1728 | + wp_send_json($response); |
|
1729 | 1729 | } |
1730 | 1730 | |
1731 | - if ( empty( $company ) ) { |
|
1731 | + if (empty($company)) { |
|
1732 | 1732 | $vat_info['valid'] = false; |
1733 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1733 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1734 | 1734 | |
1735 | - $response['error'] = __( 'Please enter your registered company name!', 'invoicing' ); |
|
1736 | - wp_send_json( $response ); |
|
1735 | + $response['error'] = __('Please enter your registered company name!', 'invoicing'); |
|
1736 | + wp_send_json($response); |
|
1737 | 1737 | } |
1738 | 1738 | |
1739 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
1740 | - if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) { |
|
1739 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
1740 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) { |
|
1741 | 1741 | $vat_info['valid'] = false; |
1742 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1742 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1743 | 1743 | |
1744 | - $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
1745 | - wp_send_json( $response ); |
|
1744 | + $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
1745 | + wp_send_json($response); |
|
1746 | 1746 | } |
1747 | 1747 | |
1748 | 1748 | $response['success'] = true; |
1749 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
1749 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
1750 | 1750 | } else { |
1751 | - $result = self::check_vat( $vat_number ); |
|
1751 | + $result = self::check_vat($vat_number); |
|
1752 | 1752 | |
1753 | - if ( empty( $result['valid'] ) ) { |
|
1753 | + if (empty($result['valid'])) { |
|
1754 | 1754 | $response['error'] = $result['message']; |
1755 | - wp_send_json( $response ); |
|
1755 | + wp_send_json($response); |
|
1756 | 1756 | } |
1757 | 1757 | |
1758 | - $vies_company = !empty( $result['company'] ) ? $result['company'] : ''; |
|
1759 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
1758 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
1759 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
1760 | 1760 | |
1761 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
1761 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
1762 | 1762 | |
1763 | - if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) { |
|
1763 | + if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) { |
|
1764 | 1764 | $response['success'] = true; |
1765 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
1765 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
1766 | 1766 | } else { |
1767 | 1767 | $vat_info['valid'] = false; |
1768 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1768 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1769 | 1769 | |
1770 | 1770 | $response['success'] = false; |
1771 | - $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 ); |
|
1772 | - wp_send_json( $response ); |
|
1771 | + $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); |
|
1772 | + wp_send_json($response); |
|
1773 | 1773 | } |
1774 | 1774 | } |
1775 | 1775 | |
1776 | - if ( $is_checkout ) { |
|
1777 | - self::save_user_vat_details( $company, $vat_number ); |
|
1776 | + if ($is_checkout) { |
|
1777 | + self::save_user_vat_details($company, $vat_number); |
|
1778 | 1778 | |
1779 | - $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true ); |
|
1780 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1779 | + $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true); |
|
1780 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1781 | 1781 | } |
1782 | 1782 | |
1783 | - wp_send_json( $response ); |
|
1783 | + wp_send_json($response); |
|
1784 | 1784 | } |
1785 | 1785 | |
1786 | 1786 | public static function ajax_vat_reset() { |
@@ -1789,161 +1789,161 @@ discard block |
||
1789 | 1789 | $company = is_user_logged_in() ? self::get_user_company() : ''; |
1790 | 1790 | $vat_number = self::get_user_vat_number(); |
1791 | 1791 | |
1792 | - $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => false ); |
|
1793 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1792 | + $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => false); |
|
1793 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1794 | 1794 | |
1795 | 1795 | $response = array(); |
1796 | 1796 | $response['success'] = true; |
1797 | 1797 | $response['data']['company'] = $company; |
1798 | 1798 | $response['data']['number'] = $vat_number; |
1799 | 1799 | |
1800 | - wp_send_json( $response ); |
|
1800 | + wp_send_json($response); |
|
1801 | 1801 | } |
1802 | 1802 | |
1803 | - public static function checkout_vat_validate( $valid_data, $post ) { |
|
1803 | + public static function checkout_vat_validate($valid_data, $post) { |
|
1804 | 1804 | global $wpinv_options, $wpi_session; |
1805 | 1805 | |
1806 | - $vat_name = __( self::get_vat_name(), 'invoicing' ); |
|
1806 | + $vat_name = __(self::get_vat_name(), 'invoicing'); |
|
1807 | 1807 | |
1808 | - if ( !isset( $_POST['_wpi_nonce'] ) || !wp_verify_nonce( $_POST['_wpi_nonce'], 'vat_validation' ) ) { |
|
1809 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( "Invalid %s validation request.", 'invoicing' ), $vat_name ) ); |
|
1808 | + if (!isset($_POST['_wpi_nonce']) || !wp_verify_nonce($_POST['_wpi_nonce'], 'vat_validation')) { |
|
1809 | + wpinv_set_error('vat_validation', wp_sprintf(__("Invalid %s validation request.", 'invoicing'), $vat_name)); |
|
1810 | 1810 | return; |
1811 | 1811 | } |
1812 | 1812 | |
1813 | - $vat_saved = $wpi_session->get( 'user_vat_data' ); |
|
1814 | - $wpi_session->set( 'user_vat_data', null ); |
|
1813 | + $vat_saved = $wpi_session->get('user_vat_data'); |
|
1814 | + $wpi_session->set('user_vat_data', null); |
|
1815 | 1815 | |
1816 | 1816 | $invoice = wpinv_get_invoice_cart(); |
1817 | 1817 | $amount = $invoice->get_total(); |
1818 | - $is_digital = self::invoice_has_digital_rule( $invoice ); |
|
1819 | - $no_vat = !self::requires_vat( 0, false, $is_digital ); |
|
1818 | + $is_digital = self::invoice_has_digital_rule($invoice); |
|
1819 | + $no_vat = !self::requires_vat(0, false, $is_digital); |
|
1820 | 1820 | |
1821 | - $company = !empty( $_POST['wpinv_company'] ) ? $_POST['wpinv_company'] : null; |
|
1822 | - $vat_number = !empty( $_POST['wpinv_vat_number'] ) ? $_POST['wpinv_vat_number'] : null; |
|
1823 | - $country = !empty( $_POST['wpinv_country'] ) ? $_POST['wpinv_country'] : $invoice->country; |
|
1824 | - if ( empty( $country ) ) { |
|
1821 | + $company = !empty($_POST['wpinv_company']) ? $_POST['wpinv_company'] : null; |
|
1822 | + $vat_number = !empty($_POST['wpinv_vat_number']) ? $_POST['wpinv_vat_number'] : null; |
|
1823 | + $country = !empty($_POST['wpinv_country']) ? $_POST['wpinv_country'] : $invoice->country; |
|
1824 | + if (empty($country)) { |
|
1825 | 1825 | $country = wpinv_default_billing_country(); |
1826 | 1826 | } |
1827 | 1827 | |
1828 | - if ( !$is_digital && $no_vat ) { |
|
1828 | + if (!$is_digital && $no_vat) { |
|
1829 | 1829 | return; |
1830 | 1830 | } |
1831 | 1831 | |
1832 | - $vat_data = array( 'company' => '', 'number' => '', 'valid' => false ); |
|
1832 | + $vat_data = array('company' => '', 'number' => '', 'valid' => false); |
|
1833 | 1833 | |
1834 | 1834 | $ip_country_code = self::get_country_by_ip(); |
1835 | - $is_eu_state = self::is_eu_state( $country ); |
|
1836 | - $is_eu_state_ip = self::is_eu_state( $ip_country_code ); |
|
1835 | + $is_eu_state = self::is_eu_state($country); |
|
1836 | + $is_eu_state_ip = self::is_eu_state($ip_country_code); |
|
1837 | 1837 | $is_non_eu_user = !$is_eu_state && !$is_eu_state_ip; |
1838 | 1838 | |
1839 | - if ( $is_digital && !$is_non_eu_user && empty( $vat_number ) && apply_filters( 'wpinv_checkout_requires_country', true, $amount ) ) { |
|
1839 | + if ($is_digital && !$is_non_eu_user && empty($vat_number) && apply_filters('wpinv_checkout_requires_country', true, $amount)) { |
|
1840 | 1840 | $vat_data['adddress_confirmed'] = false; |
1841 | 1841 | |
1842 | - if ( !isset( $_POST['wpinv_adddress_confirmed'] ) ) { |
|
1843 | - if ( $ip_country_code != $country ) { |
|
1844 | - wpinv_set_error( 'vat_validation', sprintf( __( 'The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing' ), '<a href="#wpinv_adddress_confirm">', '</a>' ) ); |
|
1842 | + if (!isset($_POST['wpinv_adddress_confirmed'])) { |
|
1843 | + if ($ip_country_code != $country) { |
|
1844 | + wpinv_set_error('vat_validation', sprintf(__('The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing'), '<a href="#wpinv_adddress_confirm">', '</a>')); |
|
1845 | 1845 | } |
1846 | 1846 | } else { |
1847 | 1847 | $vat_data['adddress_confirmed'] = true; |
1848 | 1848 | } |
1849 | 1849 | } |
1850 | 1850 | |
1851 | - if ( !empty( $wpinv_options['vat_prevent_b2c_purchase'] ) && !$is_non_eu_user && ( empty( $vat_number ) || $no_vat ) ) { |
|
1852 | - if ( $is_eu_state ) { |
|
1853 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing' ), $vat_name ) ); |
|
1854 | - } else if ( $is_digital && $is_eu_state_ip ) { |
|
1855 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing' ), $vat_name ) ); |
|
1851 | + if (!empty($wpinv_options['vat_prevent_b2c_purchase']) && !$is_non_eu_user && (empty($vat_number) || $no_vat)) { |
|
1852 | + if ($is_eu_state) { |
|
1853 | + wpinv_set_error('vat_validation', wp_sprintf(__('Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing'), $vat_name)); |
|
1854 | + } else if ($is_digital && $is_eu_state_ip) { |
|
1855 | + wpinv_set_error('vat_validation', wp_sprintf(__('Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing'), $vat_name)); |
|
1856 | 1856 | } |
1857 | 1857 | } |
1858 | 1858 | |
1859 | - if ( !$is_eu_state || $no_vat || empty( $vat_number ) ) { |
|
1859 | + if (!$is_eu_state || $no_vat || empty($vat_number)) { |
|
1860 | 1860 | return; |
1861 | 1861 | } |
1862 | 1862 | |
1863 | - if ( !empty( $vat_saved ) && isset( $vat_saved['valid'] ) ) { |
|
1864 | - $vat_data['valid'] = $vat_saved['valid']; |
|
1863 | + if (!empty($vat_saved) && isset($vat_saved['valid'])) { |
|
1864 | + $vat_data['valid'] = $vat_saved['valid']; |
|
1865 | 1865 | } |
1866 | 1866 | |
1867 | - if ( $company !== null ) { |
|
1867 | + if ($company !== null) { |
|
1868 | 1868 | $vat_data['company'] = $company; |
1869 | 1869 | } |
1870 | 1870 | |
1871 | 1871 | $message = ''; |
1872 | - if ( $vat_number !== null ) { |
|
1872 | + if ($vat_number !== null) { |
|
1873 | 1873 | $vat_data['number'] = $vat_number; |
1874 | 1874 | |
1875 | - if ( !$vat_data['valid'] || ( $vat_saved['number'] !== $vat_data['number'] ) || ( $vat_saved['company'] !== $vat_data['company'] ) ) { |
|
1876 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
1877 | - if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) { |
|
1875 | + if (!$vat_data['valid'] || ($vat_saved['number'] !== $vat_data['number']) || ($vat_saved['company'] !== $vat_data['company'])) { |
|
1876 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
1877 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) { |
|
1878 | 1878 | $vat_data['valid'] = false; |
1879 | 1879 | } |
1880 | 1880 | } else { |
1881 | - $result = self::check_vat( $vat_number ); |
|
1881 | + $result = self::check_vat($vat_number); |
|
1882 | 1882 | |
1883 | - if ( !empty( $result['valid'] ) ) { |
|
1883 | + if (!empty($result['valid'])) { |
|
1884 | 1884 | $vat_data['valid'] = true; |
1885 | - $vies_company = !empty( $result['company'] ) ? $result['company'] : ''; |
|
1886 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
1885 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
1886 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
1887 | 1887 | |
1888 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
1888 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
1889 | 1889 | |
1890 | - if ( !( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) ) { |
|
1890 | + if (!(!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company)) { |
|
1891 | 1891 | $vat_data['valid'] = false; |
1892 | 1892 | |
1893 | - $message = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name ); |
|
1893 | + $message = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name); |
|
1894 | 1894 | } |
1895 | 1895 | } else { |
1896 | - $message = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name ); |
|
1896 | + $message = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name); |
|
1897 | 1897 | } |
1898 | 1898 | } |
1899 | 1899 | |
1900 | - if ( !$vat_data['valid'] ) { |
|
1901 | - $error = wp_sprintf( __( 'The %s %s number %s you have entered has not been validated', 'invoicing' ), '<a href="#wpi-vat-details">', $vat_name, '</a>' ) . ( $message ? ' ( ' . $message . ' )' : '' ); |
|
1902 | - wpinv_set_error( 'vat_validation', $error ); |
|
1900 | + if (!$vat_data['valid']) { |
|
1901 | + $error = wp_sprintf(__('The %s %s number %s you have entered has not been validated', 'invoicing'), '<a href="#wpi-vat-details">', $vat_name, '</a>') . ($message ? ' ( ' . $message . ' )' : ''); |
|
1902 | + wpinv_set_error('vat_validation', $error); |
|
1903 | 1903 | } |
1904 | 1904 | } |
1905 | 1905 | } |
1906 | 1906 | |
1907 | - $wpi_session->set( 'user_vat_data', $vat_data ); |
|
1907 | + $wpi_session->set('user_vat_data', $vat_data); |
|
1908 | 1908 | } |
1909 | 1909 | |
1910 | - public static function checkout_vat_fields( $billing_details ) { |
|
1910 | + public static function checkout_vat_fields($billing_details) { |
|
1911 | 1911 | global $wpi_session, $wpinv_options, $wpi_country, $wpi_requires_vat; |
1912 | 1912 | |
1913 | 1913 | $ip_address = wpinv_get_ip(); |
1914 | 1914 | $ip_country_code = self::get_country_by_ip(); |
1915 | 1915 | |
1916 | - $tax_label = __( self::get_vat_name(), 'invoicing' ); |
|
1916 | + $tax_label = __(self::get_vat_name(), 'invoicing'); |
|
1917 | 1917 | $invoice = wpinv_get_invoice_cart(); |
1918 | - $is_digital = self::invoice_has_digital_rule( $invoice ); |
|
1918 | + $is_digital = self::invoice_has_digital_rule($invoice); |
|
1919 | 1919 | $wpi_country = $invoice->country; |
1920 | 1920 | |
1921 | - $requires_vat = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat( 0, false, $is_digital ); |
|
1921 | + $requires_vat = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat(0, false, $is_digital); |
|
1922 | 1922 | $wpi_requires_vat = $requires_vat; |
1923 | 1923 | |
1924 | 1924 | $company = self::get_user_company(); |
1925 | 1925 | $vat_number = self::get_user_vat_number(); |
1926 | 1926 | |
1927 | - $validated = $vat_number ? self::get_user_vat_number( '', 0, true ) : 1; |
|
1928 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
1927 | + $validated = $vat_number ? self::get_user_vat_number('', 0, true) : 1; |
|
1928 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
1929 | 1929 | |
1930 | - if ( is_array( $vat_info ) ) { |
|
1931 | - $company = isset( $vat_info['company'] ) ? $vat_info['company'] : ''; |
|
1932 | - $vat_number = isset( $vat_info['number'] ) ? $vat_info['number'] : ''; |
|
1933 | - $validated = isset( $vat_info['valid'] ) ? $vat_info['valid'] : false; |
|
1930 | + if (is_array($vat_info)) { |
|
1931 | + $company = isset($vat_info['company']) ? $vat_info['company'] : ''; |
|
1932 | + $vat_number = isset($vat_info['number']) ? $vat_info['number'] : ''; |
|
1933 | + $validated = isset($vat_info['valid']) ? $vat_info['valid'] : false; |
|
1934 | 1934 | } |
1935 | 1935 | |
1936 | 1936 | $selected_country = $invoice->country ? $invoice->country : wpinv_default_billing_country(); |
1937 | 1937 | |
1938 | - if ( $ip_country_code == 'UK' ) { |
|
1938 | + if ($ip_country_code == 'UK') { |
|
1939 | 1939 | $ip_country_code = 'GB'; |
1940 | 1940 | } |
1941 | 1941 | |
1942 | - if ( $selected_country == 'UK' ) { |
|
1942 | + if ($selected_country == 'UK') { |
|
1943 | 1943 | $selected_country = 'GB'; |
1944 | 1944 | } |
1945 | 1945 | |
1946 | - if ( $requires_vat && ( self::same_country_rule() == 'no' && wpinv_is_base_country( $selected_country ) || !self::allow_vat_rules() ) ) { |
|
1946 | + if ($requires_vat && (self::same_country_rule() == 'no' && wpinv_is_base_country($selected_country) || !self::allow_vat_rules())) { |
|
1947 | 1947 | $requires_vat = false; |
1948 | 1948 | } |
1949 | 1949 | |
@@ -1951,52 +1951,52 @@ discard block |
||
1951 | 1951 | $display_validate_btn = 'none'; |
1952 | 1952 | $display_reset_btn = 'none'; |
1953 | 1953 | |
1954 | - if ( !empty( $vat_number ) && $validated ) { |
|
1955 | - $vat_vailidated_text = wp_sprintf( __( '%s number validated', 'invoicing' ), $tax_label ); |
|
1954 | + if (!empty($vat_number) && $validated) { |
|
1955 | + $vat_vailidated_text = wp_sprintf(__('%s number validated', 'invoicing'), $tax_label); |
|
1956 | 1956 | $vat_vailidated_class = 'wpinv-vat-stat-1'; |
1957 | 1957 | $display_reset_btn = 'block'; |
1958 | 1958 | } else { |
1959 | - $vat_vailidated_text = empty( $vat_number ) ? '' : wp_sprintf( __( '%s number not validated', 'invoicing' ), $tax_label ); |
|
1960 | - $vat_vailidated_class = empty( $vat_number ) ? '' : 'wpinv-vat-stat-0'; |
|
1959 | + $vat_vailidated_text = empty($vat_number) ? '' : wp_sprintf(__('%s number not validated', 'invoicing'), $tax_label); |
|
1960 | + $vat_vailidated_class = empty($vat_number) ? '' : 'wpinv-vat-stat-0'; |
|
1961 | 1961 | $display_validate_btn = 'block'; |
1962 | 1962 | } |
1963 | 1963 | |
1964 | - $show_ip_country = $is_digital && ( empty( $vat_number ) || !$requires_vat ) && $ip_country_code != $selected_country ? 'block' : 'none'; |
|
1964 | + $show_ip_country = $is_digital && (empty($vat_number) || !$requires_vat) && $ip_country_code != $selected_country ? 'block' : 'none'; |
|
1965 | 1965 | ?> |
1966 | 1966 | <div id="wpi-vat-details" class="wpi-vat-details clearfix" style="display:<?php echo $display_vat_details; ?>"> |
1967 | 1967 | <div id="wpi_vat_info" class="clearfix panel panel-default"> |
1968 | - <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf( __( '%s Details', 'invoicing' ), $tax_label );?></h3></div> |
|
1968 | + <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf(__('%s Details', 'invoicing'), $tax_label); ?></h3></div> |
|
1969 | 1969 | <div id="wpinv-fields-box" class="panel-body"> |
1970 | 1970 | <p id="wpi_show_vat_note"> |
1971 | - <?php echo wp_sprintf( __( 'Validate your registered %s number to exclude tax.', 'invoicing' ), $tax_label ); ?> |
|
1971 | + <?php echo wp_sprintf(__('Validate your registered %s number to exclude tax.', 'invoicing'), $tax_label); ?> |
|
1972 | 1972 | </p> |
1973 | 1973 | <div id="wpi_vat_fields" class="wpi_vat_info"> |
1974 | 1974 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1975 | - <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?></label> |
|
1975 | + <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label> |
|
1976 | 1976 | <?php |
1977 | - echo wpinv_html_text( array( |
|
1977 | + echo wpinv_html_text(array( |
|
1978 | 1978 | 'id' => 'wpinv_company', |
1979 | 1979 | 'name' => 'wpinv_company', |
1980 | 1980 | 'value' => $company, |
1981 | 1981 | 'class' => 'wpi-input form-control', |
1982 | - 'placeholder' => __( 'Company name', 'invoicing' ), |
|
1983 | - ) ); |
|
1982 | + 'placeholder' => __('Company name', 'invoicing'), |
|
1983 | + )); |
|
1984 | 1984 | ?> |
1985 | 1985 | </p> |
1986 | 1986 | <p class="wpi-cart-field wpi-col2 wpi-coll wpi-cart-field-vat"> |
1987 | - <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf( __( '%s Number', 'invoicing' ), $tax_label );?></label> |
|
1987 | + <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf(__('%s Number', 'invoicing'), $tax_label); ?></label> |
|
1988 | 1988 | <span id="wpinv_vat_number-wrap"> |
1989 | 1989 | <label for="wpinv_vat_number" class="wpinv-label"></label> |
1990 | - <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr( wp_sprintf( __( '%s number', 'invoicing' ), $tax_label ) );?>" value="<?php esc_attr_e( $vat_number );?>" id="wpinv_vat_number" name="wpinv_vat_number"> |
|
1991 | - <span class="wpinv-vat-stat <?php echo $vat_vailidated_class;?>"><i class="fa"></i> <font><?php echo $vat_vailidated_text;?></font></span> |
|
1990 | + <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr(wp_sprintf(__('%s number', 'invoicing'), $tax_label)); ?>" value="<?php esc_attr_e($vat_number); ?>" id="wpinv_vat_number" name="wpinv_vat_number"> |
|
1991 | + <span class="wpinv-vat-stat <?php echo $vat_vailidated_class; ?>"><i class="fa"></i> <font><?php echo $vat_vailidated_text; ?></font></span> |
|
1992 | 1992 | </span> |
1993 | 1993 | </p> |
1994 | 1994 | <p class="wpi-cart-field wpi-col wpi-colf wpi-cart-field-actions"> |
1995 | - <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf( __("Validate %s Number", 'invoicing'), $tax_label ); ?></button> |
|
1996 | - <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf( __("Reset %s", 'invoicing'), $tax_label ); ?></button> |
|
1995 | + <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf(__("Validate %s Number", 'invoicing'), $tax_label); ?></button> |
|
1996 | + <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf(__("Reset %s", 'invoicing'), $tax_label); ?></button> |
|
1997 | 1997 | <span class="wpi-vat-box wpi-vat-box-info"><span id="text"></span></span> |
1998 | 1998 | <span class="wpi-vat-box wpi-vat-box-error"><span id="text"></span></span> |
1999 | - <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce( 'vat_validation' ) ?>" /> |
|
1999 | + <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce('vat_validation') ?>" /> |
|
2000 | 2000 | </p> |
2001 | 2001 | </div> |
2002 | 2002 | </div> |
@@ -2010,32 +2010,32 @@ discard block |
||
2010 | 2010 | </span> |
2011 | 2011 | </div> |
2012 | 2012 | </div> |
2013 | - <?php if ( empty( $wpinv_options['hide_ip_address'] ) ) { |
|
2014 | - $ip_link = '<a title="' . esc_attr( __( 'View more details on map', 'invoicing' ) ) . '" target="_blank" href="' . esc_url( admin_url( 'admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address ) ) . '" class="wpi-ip-address-link">' . $ip_address . ' <i class="fa fa-external-link-square" aria-hidden="true"></i></a>'; |
|
2013 | + <?php if (empty($wpinv_options['hide_ip_address'])) { |
|
2014 | + $ip_link = '<a title="' . esc_attr(__('View more details on map', 'invoicing')) . '" target="_blank" href="' . esc_url(admin_url('admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address)) . '" class="wpi-ip-address-link">' . $ip_address . ' <i class="fa fa-external-link-square" aria-hidden="true"></i></a>'; |
|
2015 | 2015 | ?> |
2016 | 2016 | <div class="wpi-ip-info clearfix panel panel-info"> |
2017 | 2017 | <div id="wpinv-fields-box" class="panel-body"> |
2018 | - <span><?php echo wp_sprintf( __( "Your IP address is: %s", 'invoicing' ), $ip_link ); ?></span> |
|
2018 | + <span><?php echo wp_sprintf(__("Your IP address is: %s", 'invoicing'), $ip_link); ?></span> |
|
2019 | 2019 | </div> |
2020 | 2020 | </div> |
2021 | 2021 | <?php } |
2022 | 2022 | } |
2023 | 2023 | |
2024 | - public static function show_vat_notice( $invoice ) { |
|
2025 | - if ( empty( $invoice ) ) { |
|
2024 | + public static function show_vat_notice($invoice) { |
|
2025 | + if (empty($invoice)) { |
|
2026 | 2026 | return NULL; |
2027 | 2027 | } |
2028 | 2028 | |
2029 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
2030 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
2031 | - if ( $label || $notice ) { |
|
2029 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
2030 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
2031 | + if ($label || $notice) { |
|
2032 | 2032 | ?> |
2033 | 2033 | <div class="row wpinv-vat-notice"> |
2034 | 2034 | <div class="col-sm-12"> |
2035 | - <?php if ( $label ) { ?> |
|
2036 | - <strong><?php _e( $label, 'invoicing' ); ?></strong> |
|
2037 | - <?php } if ( $notice ) { ?> |
|
2038 | - <?php echo wpautop( wptexturize( __( $notice, 'invoicing' ) ) ) ?> |
|
2035 | + <?php if ($label) { ?> |
|
2036 | + <strong><?php _e($label, 'invoicing'); ?></strong> |
|
2037 | + <?php } if ($notice) { ?> |
|
2038 | + <?php echo wpautop(wptexturize(__($notice, 'invoicing'))) ?> |
|
2039 | 2039 | <?php } ?> |
2040 | 2040 | </div> |
2041 | 2041 | </div> |