@@ -1,66 +1,66 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | -function wpinv_get_option( $key = '', $default = false ) { |
|
7 | +function wpinv_get_option($key = '', $default = false) { |
|
8 | 8 | global $wpinv_options; |
9 | 9 | |
10 | - $value = isset( $wpinv_options[ $key ] ) ? $wpinv_options[ $key ] : $default; |
|
11 | - $value = apply_filters( 'wpinv_get_option', $value, $key, $default ); |
|
10 | + $value = isset($wpinv_options[$key]) ? $wpinv_options[$key] : $default; |
|
11 | + $value = apply_filters('wpinv_get_option', $value, $key, $default); |
|
12 | 12 | |
13 | - return apply_filters( 'wpinv_get_option_' . $key, $value, $key, $default ); |
|
13 | + return apply_filters('wpinv_get_option_' . $key, $value, $key, $default); |
|
14 | 14 | } |
15 | 15 | |
16 | -function wpinv_update_option( $key = '', $value = false ) { |
|
16 | +function wpinv_update_option($key = '', $value = false) { |
|
17 | 17 | // If no key, exit |
18 | - if ( empty( $key ) ) { |
|
18 | + if (empty($key)) { |
|
19 | 19 | return false; |
20 | 20 | } |
21 | 21 | |
22 | - if ( empty( $value ) ) { |
|
23 | - $remove_option = wpinv_delete_option( $key ); |
|
22 | + if (empty($value)) { |
|
23 | + $remove_option = wpinv_delete_option($key); |
|
24 | 24 | return $remove_option; |
25 | 25 | } |
26 | 26 | |
27 | 27 | // First let's grab the current settings |
28 | - $options = get_option( 'wpinv_settings' ); |
|
28 | + $options = get_option('wpinv_settings'); |
|
29 | 29 | |
30 | 30 | // Let's let devs alter that value coming in |
31 | - $value = apply_filters( 'wpinv_update_option', $value, $key ); |
|
31 | + $value = apply_filters('wpinv_update_option', $value, $key); |
|
32 | 32 | |
33 | 33 | // Next let's try to update the value |
34 | - $options[ $key ] = $value; |
|
35 | - $did_update = update_option( 'wpinv_settings', $options ); |
|
34 | + $options[$key] = $value; |
|
35 | + $did_update = update_option('wpinv_settings', $options); |
|
36 | 36 | |
37 | 37 | // If it updated, let's update the global variable |
38 | - if ( $did_update ) { |
|
38 | + if ($did_update) { |
|
39 | 39 | global $wpinv_options; |
40 | - $wpinv_options[ $key ] = $value; |
|
40 | + $wpinv_options[$key] = $value; |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | return $did_update; |
44 | 44 | } |
45 | 45 | |
46 | -function wpinv_delete_option( $key = '' ) { |
|
46 | +function wpinv_delete_option($key = '') { |
|
47 | 47 | // If no key, exit |
48 | - if ( empty( $key ) ) { |
|
48 | + if (empty($key)) { |
|
49 | 49 | return false; |
50 | 50 | } |
51 | 51 | |
52 | 52 | // First let's grab the current settings |
53 | - $options = get_option( 'wpinv_settings' ); |
|
53 | + $options = get_option('wpinv_settings'); |
|
54 | 54 | |
55 | 55 | // Next let's try to update the value |
56 | - if( isset( $options[ $key ] ) ) { |
|
57 | - unset( $options[ $key ] ); |
|
56 | + if (isset($options[$key])) { |
|
57 | + unset($options[$key]); |
|
58 | 58 | } |
59 | 59 | |
60 | - $did_update = update_option( 'wpinv_settings', $options ); |
|
60 | + $did_update = update_option('wpinv_settings', $options); |
|
61 | 61 | |
62 | 62 | // If it updated, let's update the global variable |
63 | - if ( $did_update ){ |
|
63 | + if ($did_update) { |
|
64 | 64 | global $wpinv_options; |
65 | 65 | $wpinv_options = $options; |
66 | 66 | } |
@@ -69,37 +69,37 @@ discard block |
||
69 | 69 | } |
70 | 70 | |
71 | 71 | function wpinv_get_settings() { |
72 | - $settings = get_option( 'wpinv_settings' ); |
|
72 | + $settings = get_option('wpinv_settings'); |
|
73 | 73 | |
74 | - if ( empty( $settings ) ) { |
|
74 | + if (empty($settings)) { |
|
75 | 75 | // Update old settings with new single option |
76 | - $general_settings = is_array( get_option( 'wpinv_settings_general' ) ) ? get_option( 'wpinv_settings_general' ) : array(); |
|
77 | - $gateways_settings = is_array( get_option( 'wpinv_settings_gateways' ) ) ? get_option( 'wpinv_settings_gateways' ) : array(); |
|
78 | - $email_settings = is_array( get_option( 'wpinv_settings_emails' ) ) ? get_option( 'wpinv_settings_emails' ) : array(); |
|
79 | - $tax_settings = is_array( get_option( 'wpinv_settings_taxes' ) ) ? get_option( 'wpinv_settings_taxes' ) : array(); |
|
80 | - $misc_settings = is_array( get_option( 'wpinv_settings_misc' ) ) ? get_option( 'wpinv_settings_misc' ) : array(); |
|
81 | - $tool_settings = is_array( get_option( 'wpinv_settings_tools' ) ) ? get_option( 'wpinv_settings_tools' ) : array(); |
|
76 | + $general_settings = is_array(get_option('wpinv_settings_general')) ? get_option('wpinv_settings_general') : array(); |
|
77 | + $gateways_settings = is_array(get_option('wpinv_settings_gateways')) ? get_option('wpinv_settings_gateways') : array(); |
|
78 | + $email_settings = is_array(get_option('wpinv_settings_emails')) ? get_option('wpinv_settings_emails') : array(); |
|
79 | + $tax_settings = is_array(get_option('wpinv_settings_taxes')) ? get_option('wpinv_settings_taxes') : array(); |
|
80 | + $misc_settings = is_array(get_option('wpinv_settings_misc')) ? get_option('wpinv_settings_misc') : array(); |
|
81 | + $tool_settings = is_array(get_option('wpinv_settings_tools')) ? get_option('wpinv_settings_tools') : array(); |
|
82 | 82 | |
83 | - $settings = array_merge( $general_settings, $gateways_settings, $tax_settings, $tool_settings ); |
|
83 | + $settings = array_merge($general_settings, $gateways_settings, $tax_settings, $tool_settings); |
|
84 | 84 | |
85 | - update_option( 'wpinv_settings', $settings ); |
|
85 | + update_option('wpinv_settings', $settings); |
|
86 | 86 | |
87 | 87 | } |
88 | - return apply_filters( 'wpinv_get_settings', $settings ); |
|
88 | + return apply_filters('wpinv_get_settings', $settings); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | function wpinv_register_settings() { |
92 | - if ( false == get_option( 'wpinv_settings' ) ) { |
|
93 | - add_option( 'wpinv_settings' ); |
|
92 | + if (false == get_option('wpinv_settings')) { |
|
93 | + add_option('wpinv_settings'); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | $register_settings = wpinv_get_registered_settings(); |
97 | 97 | |
98 | - foreach ( $register_settings as $tab => $sections ) { |
|
99 | - foreach ( $sections as $section => $settings) { |
|
98 | + foreach ($register_settings as $tab => $sections) { |
|
99 | + foreach ($sections as $section => $settings) { |
|
100 | 100 | // Check for backwards compatibility |
101 | - $section_tabs = wpinv_get_settings_tab_sections( $tab ); |
|
102 | - if ( ! is_array( $section_tabs ) || ! array_key_exists( $section, $section_tabs ) ) { |
|
101 | + $section_tabs = wpinv_get_settings_tab_sections($tab); |
|
102 | + if (!is_array($section_tabs) || !array_key_exists($section, $section_tabs)) { |
|
103 | 103 | $section = 'main'; |
104 | 104 | $settings = $sections; |
105 | 105 | } |
@@ -111,42 +111,42 @@ discard block |
||
111 | 111 | 'wpinv_settings_' . $tab . '_' . $section |
112 | 112 | ); |
113 | 113 | |
114 | - foreach ( $settings as $option ) { |
|
114 | + foreach ($settings as $option) { |
|
115 | 115 | // For backwards compatibility |
116 | - if ( empty( $option['id'] ) ) { |
|
116 | + if (empty($option['id'])) { |
|
117 | 117 | continue; |
118 | 118 | } |
119 | 119 | |
120 | - $name = isset( $option['name'] ) ? $option['name'] : ''; |
|
120 | + $name = isset($option['name']) ? $option['name'] : ''; |
|
121 | 121 | |
122 | 122 | add_settings_field( |
123 | 123 | 'wpinv_settings[' . $option['id'] . ']', |
124 | 124 | $name, |
125 | - function_exists( 'wpinv_' . $option['type'] . '_callback' ) ? 'wpinv_' . $option['type'] . '_callback' : 'wpinv_missing_callback', |
|
125 | + function_exists('wpinv_' . $option['type'] . '_callback') ? 'wpinv_' . $option['type'] . '_callback' : 'wpinv_missing_callback', |
|
126 | 126 | 'wpinv_settings_' . $tab . '_' . $section, |
127 | 127 | 'wpinv_settings_' . $tab . '_' . $section, |
128 | 128 | array( |
129 | 129 | 'section' => $section, |
130 | - 'id' => isset( $option['id'] ) ? $option['id'] : null, |
|
131 | - 'desc' => ! empty( $option['desc'] ) ? $option['desc'] : '', |
|
132 | - 'name' => isset( $option['name'] ) ? $option['name'] : null, |
|
133 | - 'size' => isset( $option['size'] ) ? $option['size'] : null, |
|
134 | - 'options' => isset( $option['options'] ) ? $option['options'] : '', |
|
135 | - 'selected' => isset( $option['selected'] ) ? $option['selected'] : null, |
|
136 | - 'std' => isset( $option['std'] ) ? $option['std'] : '', |
|
137 | - 'min' => isset( $option['min'] ) ? $option['min'] : null, |
|
138 | - 'max' => isset( $option['max'] ) ? $option['max'] : null, |
|
139 | - 'step' => isset( $option['step'] ) ? $option['step'] : null, |
|
140 | - 'chosen' => isset( $option['chosen'] ) ? $option['chosen'] : null, |
|
141 | - 'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : null, |
|
142 | - 'allow_blank' => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true, |
|
143 | - 'readonly' => isset( $option['readonly'] ) ? $option['readonly'] : false, |
|
144 | - 'faux' => isset( $option['faux'] ) ? $option['faux'] : false, |
|
145 | - 'onchange' => !empty( $option['onchange'] ) ? $option['onchange'] : '', |
|
146 | - 'custom' => !empty( $option['custom'] ) ? $option['custom'] : '', |
|
147 | - 'class' => !empty( $option['class'] ) ? $option['class'] : '', |
|
148 | - 'cols' => !empty( $option['cols'] ) && (int)$option['cols'] > 0 ? (int)$option['cols'] : 50, |
|
149 | - 'rows' => !empty( $option['rows'] ) && (int)$option['rows'] > 0 ? (int)$option['rows'] : 5, |
|
130 | + 'id' => isset($option['id']) ? $option['id'] : null, |
|
131 | + 'desc' => !empty($option['desc']) ? $option['desc'] : '', |
|
132 | + 'name' => isset($option['name']) ? $option['name'] : null, |
|
133 | + 'size' => isset($option['size']) ? $option['size'] : null, |
|
134 | + 'options' => isset($option['options']) ? $option['options'] : '', |
|
135 | + 'selected' => isset($option['selected']) ? $option['selected'] : null, |
|
136 | + 'std' => isset($option['std']) ? $option['std'] : '', |
|
137 | + 'min' => isset($option['min']) ? $option['min'] : null, |
|
138 | + 'max' => isset($option['max']) ? $option['max'] : null, |
|
139 | + 'step' => isset($option['step']) ? $option['step'] : null, |
|
140 | + 'chosen' => isset($option['chosen']) ? $option['chosen'] : null, |
|
141 | + 'placeholder' => isset($option['placeholder']) ? $option['placeholder'] : null, |
|
142 | + 'allow_blank' => isset($option['allow_blank']) ? $option['allow_blank'] : true, |
|
143 | + 'readonly' => isset($option['readonly']) ? $option['readonly'] : false, |
|
144 | + 'faux' => isset($option['faux']) ? $option['faux'] : false, |
|
145 | + 'onchange' => !empty($option['onchange']) ? $option['onchange'] : '', |
|
146 | + 'custom' => !empty($option['custom']) ? $option['custom'] : '', |
|
147 | + 'class' => !empty($option['class']) ? $option['class'] : '', |
|
148 | + 'cols' => !empty($option['cols']) && (int)$option['cols'] > 0 ? (int)$option['cols'] : 50, |
|
149 | + 'rows' => !empty($option['rows']) && (int)$option['rows'] > 0 ? (int)$option['rows'] : 5, |
|
150 | 150 | ) |
151 | 151 | ); |
152 | 152 | } |
@@ -154,162 +154,162 @@ discard block |
||
154 | 154 | } |
155 | 155 | |
156 | 156 | // Creates our settings in the options table |
157 | - register_setting( 'wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize' ); |
|
157 | + register_setting('wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize'); |
|
158 | 158 | } |
159 | -add_action( 'admin_init', 'wpinv_register_settings' ); |
|
159 | +add_action('admin_init', 'wpinv_register_settings'); |
|
160 | 160 | |
161 | 161 | function wpinv_get_registered_settings() { |
162 | - $pages = wpinv_get_pages( true ); |
|
162 | + $pages = wpinv_get_pages(true); |
|
163 | 163 | |
164 | 164 | $due_payment_options = array(); |
165 | - $due_payment_options[0] = __( 'Now', 'invoicing' ); |
|
166 | - for ( $i = 1; $i <= 30; $i++ ) { |
|
165 | + $due_payment_options[0] = __('Now', 'invoicing'); |
|
166 | + for ($i = 1; $i <= 30; $i++) { |
|
167 | 167 | $due_payment_options[$i] = $i; |
168 | 168 | } |
169 | 169 | |
170 | 170 | $invoice_number_padd_options = array(); |
171 | - for ( $i = 0; $i <= 20; $i++ ) { |
|
171 | + for ($i = 0; $i <= 20; $i++) { |
|
172 | 172 | $invoice_number_padd_options[$i] = $i; |
173 | 173 | } |
174 | 174 | |
175 | 175 | $alert_wrapper_start = '<p style="color: #F00">'; |
176 | 176 | $alert_wrapper_close = '</p>'; |
177 | 177 | $wpinv_settings = array( |
178 | - 'general' => apply_filters( 'wpinv_settings_general', |
|
178 | + 'general' => apply_filters('wpinv_settings_general', |
|
179 | 179 | array( |
180 | 180 | 'main' => array( |
181 | 181 | 'location_settings' => array( |
182 | 182 | 'id' => 'location_settings', |
183 | - 'name' => '<h3>' . __( 'Default Location', 'invoicing' ) . '</h3>', |
|
183 | + 'name' => '<h3>' . __('Default Location', 'invoicing') . '</h3>', |
|
184 | 184 | 'desc' => '', |
185 | 185 | 'type' => 'header', |
186 | 186 | ), |
187 | 187 | 'default_country' => array( |
188 | 188 | 'id' => 'default_country', |
189 | - 'name' => __( 'Default Country', 'invoicing' ), |
|
190 | - 'desc' => __( 'Where does your store operate from?', 'invoicing' ), |
|
189 | + 'name' => __('Default Country', 'invoicing'), |
|
190 | + 'desc' => __('Where does your store operate from?', 'invoicing'), |
|
191 | 191 | 'type' => 'select', |
192 | 192 | 'options' => wpinv_get_country_list(), |
193 | 193 | 'std' => 'GB', |
194 | 194 | 'chosen' => true, |
195 | - 'placeholder' => __( 'Select a country', 'invoicing' ), |
|
195 | + 'placeholder' => __('Select a country', 'invoicing'), |
|
196 | 196 | ), |
197 | 197 | 'default_state' => array( |
198 | 198 | 'id' => 'default_state', |
199 | - 'name' => __( 'Default State / Province', 'invoicing' ), |
|
200 | - 'desc' => __( 'What state / province does your store operate from?', 'invoicing' ), |
|
199 | + 'name' => __('Default State / Province', 'invoicing'), |
|
200 | + 'desc' => __('What state / province does your store operate from?', 'invoicing'), |
|
201 | 201 | 'type' => 'country_states', |
202 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
202 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
203 | 203 | ), |
204 | 204 | 'store_name' => array( |
205 | 205 | 'id' => 'store_name', |
206 | - 'name' => __( 'Store Name', 'invoicing' ), |
|
207 | - 'desc' => __( 'Store name to print on invoices.', 'invoicing' ), |
|
206 | + 'name' => __('Store Name', 'invoicing'), |
|
207 | + 'desc' => __('Store name to print on invoices.', 'invoicing'), |
|
208 | 208 | 'std' => get_option('blogname'), |
209 | 209 | 'type' => 'text', |
210 | 210 | ), |
211 | 211 | 'logo' => array( |
212 | 212 | 'id' => 'logo', |
213 | - 'name' => __( 'Logo URL', 'invoicing' ), |
|
214 | - 'desc' => __( 'Store logo to print on invoices.', 'invoicing' ), |
|
213 | + 'name' => __('Logo URL', 'invoicing'), |
|
214 | + 'desc' => __('Store logo to print on invoices.', 'invoicing'), |
|
215 | 215 | 'type' => 'text', |
216 | 216 | ), |
217 | 217 | 'store_address' => array( |
218 | 218 | 'id' => 'store_address', |
219 | - 'name' => __( 'Store Address', 'invoicing' ), |
|
220 | - 'desc' => __( 'Enter the store address to display on invoice', 'invoicing' ), |
|
219 | + 'name' => __('Store Address', 'invoicing'), |
|
220 | + 'desc' => __('Enter the store address to display on invoice', 'invoicing'), |
|
221 | 221 | 'type' => 'textarea', |
222 | 222 | ), |
223 | 223 | 'page_settings' => array( |
224 | 224 | 'id' => 'page_settings', |
225 | - 'name' => '<h3>' . __( 'Page Settings', 'invoicing' ) . '</h3>', |
|
225 | + 'name' => '<h3>' . __('Page Settings', 'invoicing') . '</h3>', |
|
226 | 226 | 'desc' => '', |
227 | 227 | 'type' => 'header', |
228 | 228 | ), |
229 | 229 | 'checkout_page' => array( |
230 | 230 | 'id' => 'checkout_page', |
231 | - 'name' => __( 'Checkout Page', 'invoicing' ), |
|
232 | - 'desc' => __( 'This is the checkout page where buyers will complete their payments. The <b>[wpinv_checkout]</b> short code must be on this page.', 'invoicing' ), |
|
231 | + 'name' => __('Checkout Page', 'invoicing'), |
|
232 | + 'desc' => __('This is the checkout page where buyers will complete their payments. The <b>[wpinv_checkout]</b> short code must be on this page.', 'invoicing'), |
|
233 | 233 | 'type' => 'select', |
234 | 234 | 'options' => $pages, |
235 | 235 | 'chosen' => true, |
236 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
236 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
237 | 237 | ), |
238 | 238 | 'success_page' => array( |
239 | 239 | 'id' => 'success_page', |
240 | - 'name' => __( 'Success Page', 'invoicing' ), |
|
241 | - 'desc' => __( 'This is the page buyers are sent to after completing their payments. The <b>[wpinv_receipt]</b> short code should be on this page.', 'invoicing' ), |
|
240 | + 'name' => __('Success Page', 'invoicing'), |
|
241 | + 'desc' => __('This is the page buyers are sent to after completing their payments. The <b>[wpinv_receipt]</b> short code should be on this page.', 'invoicing'), |
|
242 | 242 | 'type' => 'select', |
243 | 243 | 'options' => $pages, |
244 | 244 | 'chosen' => true, |
245 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
245 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
246 | 246 | ), |
247 | 247 | 'failure_page' => array( |
248 | 248 | 'id' => 'failure_page', |
249 | - 'name' => __( 'Failed Transaction Page', 'invoicing' ), |
|
250 | - 'desc' => __( 'This is the page buyers are sent to if their transaction is cancelled or fails', 'invoicing' ), |
|
249 | + 'name' => __('Failed Transaction Page', 'invoicing'), |
|
250 | + 'desc' => __('This is the page buyers are sent to if their transaction is cancelled or fails', 'invoicing'), |
|
251 | 251 | 'type' => 'select', |
252 | 252 | 'options' => $pages, |
253 | 253 | 'chosen' => true, |
254 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
254 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
255 | 255 | ), |
256 | 256 | 'invoice_history_page' => array( |
257 | 257 | 'id' => 'invoice_history_page', |
258 | - 'name' => __( 'Invoice History Page', 'invoicing' ), |
|
259 | - 'desc' => __( 'This page shows a invoice history for the current user', 'invoicing' ), |
|
258 | + 'name' => __('Invoice History Page', 'invoicing'), |
|
259 | + 'desc' => __('This page shows a invoice history for the current user', 'invoicing'), |
|
260 | 260 | 'type' => 'select', |
261 | 261 | 'options' => $pages, |
262 | 262 | 'chosen' => true, |
263 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
263 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
264 | 264 | ) |
265 | 265 | ), |
266 | 266 | 'currency_section' => array( |
267 | 267 | 'currency_settings' => array( |
268 | 268 | 'id' => 'currency_settings', |
269 | - 'name' => '<h3>' . __( 'Currency Settings', 'invoicing' ) . '</h3>', |
|
269 | + 'name' => '<h3>' . __('Currency Settings', 'invoicing') . '</h3>', |
|
270 | 270 | 'desc' => '', |
271 | 271 | 'type' => 'header', |
272 | 272 | ), |
273 | 273 | 'currency' => array( |
274 | 274 | 'id' => 'currency', |
275 | - 'name' => __( 'Currency', 'invoicing' ), |
|
276 | - 'desc' => __( 'Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing' ), |
|
275 | + 'name' => __('Currency', 'invoicing'), |
|
276 | + 'desc' => __('Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing'), |
|
277 | 277 | 'type' => 'select', |
278 | 278 | 'options' => wpinv_get_currencies(), |
279 | 279 | 'chosen' => true, |
280 | 280 | ), |
281 | 281 | 'currency_position' => array( |
282 | 282 | 'id' => 'currency_position', |
283 | - 'name' => __( 'Currency Position', 'invoicing' ), |
|
284 | - 'desc' => __( 'Choose the location of the currency sign.', 'invoicing' ), |
|
283 | + 'name' => __('Currency Position', 'invoicing'), |
|
284 | + 'desc' => __('Choose the location of the currency sign.', 'invoicing'), |
|
285 | 285 | 'type' => 'select', |
286 | 286 | 'options' => array( |
287 | - 'left' => __( 'Left', 'invoicing' ) . ' (' . wpinv_currency_symbol() . '99.99)', |
|
288 | - 'right' => __( 'Right', 'invoicing' ) . ' (99.99' . wpinv_currency_symbol() . ')', |
|
289 | - 'left_space' => __( 'Left with space', 'invoicing' ) . ' (' . wpinv_currency_symbol() . ' 99.99)', |
|
290 | - 'right_space' => __( 'Right with space', 'invoicing' ) . ' (99.99 ' . wpinv_currency_symbol() . ')' |
|
287 | + 'left' => __('Left', 'invoicing') . ' (' . wpinv_currency_symbol() . '99.99)', |
|
288 | + 'right' => __('Right', 'invoicing') . ' (99.99' . wpinv_currency_symbol() . ')', |
|
289 | + 'left_space' => __('Left with space', 'invoicing') . ' (' . wpinv_currency_symbol() . ' 99.99)', |
|
290 | + 'right_space' => __('Right with space', 'invoicing') . ' (99.99 ' . wpinv_currency_symbol() . ')' |
|
291 | 291 | ) |
292 | 292 | ), |
293 | 293 | 'thousands_separator' => array( |
294 | 294 | 'id' => 'thousands_separator', |
295 | - 'name' => __( 'Thousands Separator', 'invoicing' ), |
|
296 | - 'desc' => __( 'The symbol (usually , or .) to separate thousands', 'invoicing' ), |
|
295 | + 'name' => __('Thousands Separator', 'invoicing'), |
|
296 | + 'desc' => __('The symbol (usually , or .) to separate thousands', 'invoicing'), |
|
297 | 297 | 'type' => 'text', |
298 | 298 | 'size' => 'small', |
299 | 299 | 'std' => ',', |
300 | 300 | ), |
301 | 301 | 'decimal_separator' => array( |
302 | 302 | 'id' => 'decimal_separator', |
303 | - 'name' => __( 'Decimal Separator', 'invoicing' ), |
|
304 | - 'desc' => __( 'The symbol (usually , or .) to separate decimal points', 'invoicing' ), |
|
303 | + 'name' => __('Decimal Separator', 'invoicing'), |
|
304 | + 'desc' => __('The symbol (usually , or .) to separate decimal points', 'invoicing'), |
|
305 | 305 | 'type' => 'text', |
306 | 306 | 'size' => 'small', |
307 | 307 | 'std' => '.', |
308 | 308 | ), |
309 | 309 | 'decimals' => array( |
310 | 310 | 'id' => 'decimals', |
311 | - 'name' => __( 'Number of Decimals', 'invoicing' ), |
|
312 | - 'desc' => __( 'This sets the number of decimal points shown in displayed prices.', 'invoicing' ), |
|
311 | + 'name' => __('Number of Decimals', 'invoicing'), |
|
312 | + 'desc' => __('This sets the number of decimal points shown in displayed prices.', 'invoicing'), |
|
313 | 313 | 'type' => 'number', |
314 | 314 | 'size' => 'small', |
315 | 315 | 'std' => '2', |
@@ -321,29 +321,29 @@ discard block |
||
321 | 321 | 'labels' => array( |
322 | 322 | 'labels' => array( |
323 | 323 | 'id' => 'labels_settings', |
324 | - 'name' => '<h3>' . __( 'Invoice Labels', 'invoicing' ) . '</h3>', |
|
324 | + 'name' => '<h3>' . __('Invoice Labels', 'invoicing') . '</h3>', |
|
325 | 325 | 'desc' => '', |
326 | 326 | 'type' => 'header', |
327 | 327 | ), |
328 | 328 | 'vat_name' => array( |
329 | 329 | 'id' => 'vat_name', |
330 | - 'name' => __( 'VAT Name', 'invoicing' ), |
|
331 | - 'desc' => __( 'Enter the VAT name', 'invoicing' ), |
|
330 | + 'name' => __('VAT Name', 'invoicing'), |
|
331 | + 'desc' => __('Enter the VAT name', 'invoicing'), |
|
332 | 332 | 'type' => 'text', |
333 | 333 | 'size' => 'regular', |
334 | 334 | 'std' => 'VAT' |
335 | 335 | ), |
336 | 336 | 'vat_invoice_notice_label' => array( |
337 | 337 | 'id' => 'vat_invoice_notice_label', |
338 | - 'name' => __( 'Invoice notice label', 'invoicing' ), |
|
339 | - 'desc' => __( 'Use this to add a invoice notice section (label) to your invoices', 'invoicing' ), |
|
338 | + 'name' => __('Invoice notice label', 'invoicing'), |
|
339 | + 'desc' => __('Use this to add a invoice notice section (label) to your invoices', 'invoicing'), |
|
340 | 340 | 'type' => 'text', |
341 | 341 | 'size' => 'regular', |
342 | 342 | ), |
343 | 343 | 'vat_invoice_notice' => array( |
344 | 344 | 'id' => 'vat_invoice_notice', |
345 | - 'name' => __( 'Invoice notice', 'invoicing' ), |
|
346 | - 'desc' => __( 'Use this to add a invoice notice section (description) to your invoices', 'invoicing' ), |
|
345 | + 'name' => __('Invoice notice', 'invoicing'), |
|
346 | + 'desc' => __('Use this to add a invoice notice section (description) to your invoices', 'invoicing'), |
|
347 | 347 | 'type' => 'text', |
348 | 348 | 'size' => 'regular', |
349 | 349 | ) |
@@ -355,22 +355,22 @@ discard block |
||
355 | 355 | 'main' => array( |
356 | 356 | 'gateway_settings' => array( |
357 | 357 | 'id' => 'api_header', |
358 | - 'name' => '<h3>' . __( 'Gateway Settings', 'invoicing' ) . '</h3>', |
|
358 | + 'name' => '<h3>' . __('Gateway Settings', 'invoicing') . '</h3>', |
|
359 | 359 | 'desc' => '', |
360 | 360 | 'type' => 'header', |
361 | 361 | ), |
362 | 362 | 'gateways' => array( |
363 | 363 | 'id' => 'gateways', |
364 | - 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
365 | - 'desc' => __( 'Choose the payment gateways you want to enable.', 'invoicing' ), |
|
364 | + 'name' => __('Payment Gateways', 'invoicing'), |
|
365 | + 'desc' => __('Choose the payment gateways you want to enable.', 'invoicing'), |
|
366 | 366 | 'type' => 'gateways', |
367 | 367 | 'std' => array('manual'=>1), |
368 | 368 | 'options' => wpinv_get_payment_gateways(), |
369 | 369 | ), |
370 | 370 | 'default_gateway' => array( |
371 | 371 | 'id' => 'default_gateway', |
372 | - 'name' => __( 'Default Gateway', 'invoicing' ), |
|
373 | - 'desc' => __( 'This gateway will be loaded automatically with the checkout page.', 'invoicing' ), |
|
372 | + 'name' => __('Default Gateway', 'invoicing'), |
|
373 | + 'desc' => __('This gateway will be loaded automatically with the checkout page.', 'invoicing'), |
|
374 | 374 | 'type' => 'gateway_select', |
375 | 375 | 'std' => 'manual', |
376 | 376 | 'options' => wpinv_get_payment_gateways(), |
@@ -384,19 +384,19 @@ discard block |
||
384 | 384 | 'main' => array( |
385 | 385 | 'tax_settings' => array( |
386 | 386 | 'id' => 'tax_settings', |
387 | - 'name' => '<h3>' . __( 'Tax Settings', 'invoicing' ) . '</h3>', |
|
387 | + 'name' => '<h3>' . __('Tax Settings', 'invoicing') . '</h3>', |
|
388 | 388 | 'type' => 'header', |
389 | 389 | ), |
390 | 390 | 'enable_taxes' => array( |
391 | 391 | 'id' => 'enable_taxes', |
392 | - 'name' => __( 'Enable Taxes', 'invoicing' ), |
|
393 | - 'desc' => __( 'Check this to enable taxes on invoices.', 'invoicing' ), |
|
392 | + 'name' => __('Enable Taxes', 'invoicing'), |
|
393 | + 'desc' => __('Check this to enable taxes on invoices.', 'invoicing'), |
|
394 | 394 | 'type' => 'checkbox', |
395 | 395 | ), |
396 | 396 | 'tax_rate' => array( |
397 | 397 | 'id' => 'tax_rate', |
398 | - 'name' => __( 'Fallback Tax Rate', 'invoicing' ), |
|
399 | - 'desc' => __( 'Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing' ), |
|
398 | + 'name' => __('Fallback Tax Rate', 'invoicing'), |
|
399 | + 'desc' => __('Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing'), |
|
400 | 400 | 'type' => 'number', |
401 | 401 | 'size' => 'small', |
402 | 402 | 'min' => '0', |
@@ -408,8 +408,8 @@ discard block |
||
408 | 408 | 'rates' => array( |
409 | 409 | 'tax_rates' => array( |
410 | 410 | 'id' => 'tax_rates', |
411 | - 'name' => '<h3>' . __( 'Tax Rates', 'invoicing' ) . '</h3>', |
|
412 | - 'desc' => __( 'Enter tax rates for specific regions.', 'invoicing' ), |
|
411 | + 'name' => '<h3>' . __('Tax Rates', 'invoicing') . '</h3>', |
|
412 | + 'desc' => __('Enter tax rates for specific regions.', 'invoicing'), |
|
413 | 413 | 'type' => 'tax_rates', |
414 | 414 | ), |
415 | 415 | ) |
@@ -421,62 +421,62 @@ discard block |
||
421 | 421 | 'main' => array( |
422 | 422 | 'email_settings_header' => array( |
423 | 423 | 'id' => 'email_settings_header', |
424 | - 'name' => '<h3>' . __( 'Email Sender Options', 'invoicing' ) . '</h3>', |
|
424 | + 'name' => '<h3>' . __('Email Sender Options', 'invoicing') . '</h3>', |
|
425 | 425 | 'type' => 'header', |
426 | 426 | ), |
427 | 427 | 'email_from_name' => array( |
428 | 428 | 'id' => 'email_from_name', |
429 | - 'name' => __( 'From Name', 'invoicing' ), |
|
430 | - 'desc' => __( 'Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing' ), |
|
431 | - 'std' => esc_attr( get_bloginfo( 'name', 'display' ) ), |
|
429 | + 'name' => __('From Name', 'invoicing'), |
|
430 | + 'desc' => __('Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing'), |
|
431 | + 'std' => esc_attr(get_bloginfo('name', 'display')), |
|
432 | 432 | 'type' => 'text', |
433 | 433 | ), |
434 | 434 | 'email_from' => array( |
435 | 435 | 'id' => 'email_from', |
436 | - 'name' => __( 'From Email', 'invoicing' ), |
|
437 | - 'desc' => sprintf (__( 'Email address to send invoice emails from. This will act as the "from" and "reply-to" address. %s If emails are not being sent it may be that your hosting prevents emails being sent if the email domains do not match.%s', 'invoicing' ), $alert_wrapper_start, $alert_wrapper_close), |
|
438 | - 'std' => get_option( 'admin_email' ), |
|
436 | + 'name' => __('From Email', 'invoicing'), |
|
437 | + 'desc' => sprintf(__('Email address to send invoice emails from. This will act as the "from" and "reply-to" address. %s If emails are not being sent it may be that your hosting prevents emails being sent if the email domains do not match.%s', 'invoicing'), $alert_wrapper_start, $alert_wrapper_close), |
|
438 | + 'std' => get_option('admin_email'), |
|
439 | 439 | 'type' => 'text', |
440 | 440 | ), |
441 | 441 | 'overdue_settings_header' => array( |
442 | 442 | 'id' => 'overdue_settings_header', |
443 | - 'name' => '<h3>' . __( 'Due Date Settings', 'invoicing' ) . '</h3>', |
|
443 | + 'name' => '<h3>' . __('Due Date Settings', 'invoicing') . '</h3>', |
|
444 | 444 | 'type' => 'header', |
445 | 445 | ), |
446 | 446 | 'overdue_active' => array( |
447 | 447 | 'id' => 'overdue_active', |
448 | - 'name' => __( 'Enable Due Date', 'invoicing' ), |
|
449 | - 'desc' => __( 'Check this to enable due date option for invoices.', 'invoicing' ), |
|
448 | + 'name' => __('Enable Due Date', 'invoicing'), |
|
449 | + 'desc' => __('Check this to enable due date option for invoices.', 'invoicing'), |
|
450 | 450 | 'type' => 'checkbox', |
451 | 451 | 'std' => false, |
452 | 452 | ), |
453 | 453 | 'overdue_days' => array( |
454 | 454 | 'id' => 'overdue_days', |
455 | - 'name' => __( 'Default Due Date', 'invoicing' ), |
|
456 | - 'desc' => __( 'Number of days each Invoice is due after the created date. This will automatically set the date in the "Due Date" field. Can be overridden on individual Invoices.', 'invoicing' ), |
|
455 | + 'name' => __('Default Due Date', 'invoicing'), |
|
456 | + 'desc' => __('Number of days each Invoice is due after the created date. This will automatically set the date in the "Due Date" field. Can be overridden on individual Invoices.', 'invoicing'), |
|
457 | 457 | 'type' => 'select', |
458 | 458 | 'options' => $due_payment_options, |
459 | 459 | 'chosen' => true, |
460 | 460 | 'std' => 0, |
461 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
461 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
462 | 462 | ), |
463 | 463 | 'email_template_header' => array( |
464 | 464 | 'id' => 'email_template_header', |
465 | - 'name' => '<h3>' . __( 'Email Template', 'invoicing' ) . '</h3>', |
|
465 | + 'name' => '<h3>' . __('Email Template', 'invoicing') . '</h3>', |
|
466 | 466 | 'type' => 'header', |
467 | 467 | ), |
468 | 468 | 'email_header_image' => array( |
469 | 469 | 'id' => 'email_header_image', |
470 | - 'name' => __( 'Header Image', 'invoicing' ), |
|
471 | - 'desc' => __( 'URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing' ), |
|
470 | + 'name' => __('Header Image', 'invoicing'), |
|
471 | + 'desc' => __('URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing'), |
|
472 | 472 | 'std' => '', |
473 | 473 | 'type' => 'text', |
474 | 474 | ), |
475 | 475 | 'email_footer_text' => array( |
476 | 476 | 'id' => 'email_footer_text', |
477 | - 'name' => __( 'Footer Text', 'invoicing' ), |
|
478 | - 'desc' => __( 'The text to appear in the footer of all invoice emails.', 'invoicing' ), |
|
479 | - 'std' => get_bloginfo( 'name', 'display' ) . ' - ' . __( 'Powered by GeoDirectory', 'invoicing' ), |
|
477 | + 'name' => __('Footer Text', 'invoicing'), |
|
478 | + 'desc' => __('The text to appear in the footer of all invoice emails.', 'invoicing'), |
|
479 | + 'std' => get_bloginfo('name', 'display') . ' - ' . __('Powered by GeoDirectory', 'invoicing'), |
|
480 | 480 | 'type' => 'textarea', |
481 | 481 | 'class' => 'regular-text', |
482 | 482 | 'rows' => 2, |
@@ -484,29 +484,29 @@ discard block |
||
484 | 484 | ), |
485 | 485 | 'email_base_color' => array( |
486 | 486 | 'id' => 'email_base_color', |
487 | - 'name' => __( 'Base Color', 'invoicing' ), |
|
488 | - 'desc' => __( 'The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing' ), |
|
487 | + 'name' => __('Base Color', 'invoicing'), |
|
488 | + 'desc' => __('The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing'), |
|
489 | 489 | 'std' => '#557da2', |
490 | 490 | 'type' => 'color', |
491 | 491 | ), |
492 | 492 | 'email_background_color' => array( |
493 | 493 | 'id' => 'email_background_color', |
494 | - 'name' => __( 'Background Color', 'invoicing' ), |
|
495 | - 'desc' => __( 'The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing' ), |
|
494 | + 'name' => __('Background Color', 'invoicing'), |
|
495 | + 'desc' => __('The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing'), |
|
496 | 496 | 'std' => '#f5f5f5', |
497 | 497 | 'type' => 'color', |
498 | 498 | ), |
499 | 499 | 'email_body_background_color' => array( |
500 | 500 | 'id' => 'email_body_background_color', |
501 | - 'name' => __( 'Body Background Color', 'invoicing' ), |
|
502 | - 'desc' => __( 'The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing' ), |
|
501 | + 'name' => __('Body Background Color', 'invoicing'), |
|
502 | + 'desc' => __('The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing'), |
|
503 | 503 | 'std' => '#fdfdfd', |
504 | 504 | 'type' => 'color', |
505 | 505 | ), |
506 | 506 | 'email_text_color' => array( |
507 | 507 | 'id' => 'email_text_color', |
508 | - 'name' => __( 'Body Text Color', 'invoicing' ), |
|
509 | - 'desc' => __( 'The main body text color. Default <code>#505050</code>.', 'invoicing' ), |
|
508 | + 'name' => __('Body Text Color', 'invoicing'), |
|
509 | + 'desc' => __('The main body text color. Default <code>#505050</code>.', 'invoicing'), |
|
510 | 510 | 'std' => '#505050', |
511 | 511 | 'type' => 'color', |
512 | 512 | ), |
@@ -525,25 +525,25 @@ discard block |
||
525 | 525 | 'main' => array( |
526 | 526 | 'fields_settings' => array( |
527 | 527 | 'id' => 'fields_settings', |
528 | - 'name' => '<h3>' . __( 'Fields Settings', 'invoicing' ) . '</h3>', |
|
528 | + 'name' => '<h3>' . __('Fields Settings', 'invoicing') . '</h3>', |
|
529 | 529 | 'type' => 'header', |
530 | 530 | ), |
531 | 531 | 'phone_mandatory' => array( |
532 | 532 | 'id' => 'phone_mandatory', |
533 | - 'name' => __( 'Phone No. Mandatory?', 'invoicing' ), |
|
534 | - 'desc' => __( 'Tick this to make phone number mandatory in invoice address fields.', 'invoicing' ), |
|
533 | + 'name' => __('Phone No. Mandatory?', 'invoicing'), |
|
534 | + 'desc' => __('Tick this to make phone number mandatory in invoice address fields.', 'invoicing'), |
|
535 | 535 | 'type' => 'checkbox', |
536 | 536 | 'std' => true, |
537 | 537 | ), |
538 | 538 | 'invoice_number_format_settings' => array( |
539 | 539 | 'id' => 'invoice_number_format_settings', |
540 | - 'name' => '<h3>' . __( 'Invoice Number', 'invoicing' ) . '</h3>', |
|
540 | + 'name' => '<h3>' . __('Invoice Number', 'invoicing') . '</h3>', |
|
541 | 541 | 'type' => 'header', |
542 | 542 | ), |
543 | 543 | 'invoice_number_padd' => array( |
544 | 544 | 'id' => 'invoice_number_padd', |
545 | - 'name' => __( 'Minimum digits', 'invoicing' ), |
|
546 | - 'desc' => __( 'If the invoice number has less digits than this number, it is left padded with 0s. Ex: invoice number 108 will padded to 00108 if digits set to 5. The default 0 means no padding.', 'invoicing' ), |
|
545 | + 'name' => __('Minimum digits', 'invoicing'), |
|
546 | + 'desc' => __('If the invoice number has less digits than this number, it is left padded with 0s. Ex: invoice number 108 will padded to 00108 if digits set to 5. The default 0 means no padding.', 'invoicing'), |
|
547 | 547 | 'type' => 'select', |
548 | 548 | 'options' => $invoice_number_padd_options, |
549 | 549 | 'std' => 5, |
@@ -551,8 +551,8 @@ discard block |
||
551 | 551 | ), |
552 | 552 | 'invoice_number_prefix' => array( |
553 | 553 | 'id' => 'invoice_number_prefix', |
554 | - 'name' => __( 'Invoice Number prefix', 'invoicing' ), |
|
555 | - 'desc' => __( 'A prefix to prepend to all invoice numbers. Ex: WPINV-', 'invoicing' ), |
|
554 | + 'name' => __('Invoice Number prefix', 'invoicing'), |
|
555 | + 'desc' => __('A prefix to prepend to all invoice numbers. Ex: WPINV-', 'invoicing'), |
|
556 | 556 | 'type' => 'text', |
557 | 557 | 'size' => 'regular', |
558 | 558 | 'std' => 'WPINV-', |
@@ -560,25 +560,25 @@ discard block |
||
560 | 560 | ), |
561 | 561 | 'invoice_number_postfix' => array( |
562 | 562 | 'id' => 'invoice_number_postfix', |
563 | - 'name' => __( 'Invoice Number postfix', 'invoicing' ), |
|
564 | - 'desc' => __( 'A postfix to append to all invoice numbers.', 'invoicing' ), |
|
563 | + 'name' => __('Invoice Number postfix', 'invoicing'), |
|
564 | + 'desc' => __('A postfix to append to all invoice numbers.', 'invoicing'), |
|
565 | 565 | 'type' => 'text', |
566 | 566 | 'size' => 'regular', |
567 | 567 | 'std' => '' |
568 | 568 | ), |
569 | 569 | 'guest_checkout_settings' => array( |
570 | 570 | 'id' => 'guest_checkout_settings', |
571 | - 'name' => '<h3>' . __( 'Pay via Invoice Link', 'invoicing' ) . '</h3>', |
|
571 | + 'name' => '<h3>' . __('Pay via Invoice Link', 'invoicing') . '</h3>', |
|
572 | 572 | 'type' => 'header', |
573 | 573 | ), |
574 | 574 | 'guest_checkout' => array( |
575 | 575 | 'type' => 'radio', |
576 | 576 | 'id' => 'guest_checkout', |
577 | - 'name' => __( 'Pay via Invoice Link for non logged in user', 'invoicing' ), |
|
578 | - 'desc' => __( 'Select how invoice should be paid when non logged in user clicks on the invoice link that sent to them via for pay for invoice.', 'invoicing' ), |
|
577 | + 'name' => __('Pay via Invoice Link for non logged in user', 'invoicing'), |
|
578 | + 'desc' => __('Select how invoice should be paid when non logged in user clicks on the invoice link that sent to them via for pay for invoice.', 'invoicing'), |
|
579 | 579 | 'options' => array( |
580 | - 0 => __( 'Ask them to log-in and redirect back to invoice checkout to pay.', 'invoicing' ), |
|
581 | - 1 => __( 'Auto log-in the user via invoice link and take them to invoice checkout to pay.', 'invoicing' ), |
|
580 | + 0 => __('Ask them to log-in and redirect back to invoice checkout to pay.', 'invoicing'), |
|
581 | + 1 => __('Auto log-in the user via invoice link and take them to invoice checkout to pay.', 'invoicing'), |
|
582 | 582 | ), |
583 | 583 | 'std' => 0, |
584 | 584 | ), |
@@ -591,8 +591,8 @@ discard block |
||
591 | 591 | 'main' => array( |
592 | 592 | 'tool_settings' => array( |
593 | 593 | 'id' => 'tool_settings', |
594 | - 'name' => '<h3>' . __( 'Diagnostic Tools', 'invoicing' ) . '</h3>', |
|
595 | - 'desc' => __( 'Invoicing diagnostic tools', 'invoicing' ), |
|
594 | + 'name' => '<h3>' . __('Diagnostic Tools', 'invoicing') . '</h3>', |
|
595 | + 'desc' => __('Invoicing diagnostic tools', 'invoicing'), |
|
596 | 596 | 'type' => 'tools', |
597 | 597 | ), |
598 | 598 | ), |
@@ -600,96 +600,96 @@ discard block |
||
600 | 600 | ) |
601 | 601 | ); |
602 | 602 | |
603 | - return apply_filters( 'wpinv_registered_settings', $wpinv_settings ); |
|
603 | + return apply_filters('wpinv_registered_settings', $wpinv_settings); |
|
604 | 604 | } |
605 | 605 | |
606 | -function wpinv_settings_sanitize( $input = array() ) { |
|
606 | +function wpinv_settings_sanitize($input = array()) { |
|
607 | 607 | global $wpinv_options; |
608 | 608 | |
609 | - if ( empty( $_POST['_wp_http_referer'] ) ) { |
|
609 | + if (empty($_POST['_wp_http_referer'])) { |
|
610 | 610 | return $input; |
611 | 611 | } |
612 | 612 | |
613 | - parse_str( $_POST['_wp_http_referer'], $referrer ); |
|
613 | + parse_str($_POST['_wp_http_referer'], $referrer); |
|
614 | 614 | |
615 | 615 | $settings = wpinv_get_registered_settings(); |
616 | - $tab = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general'; |
|
617 | - $section = isset( $referrer['section'] ) ? $referrer['section'] : 'main'; |
|
616 | + $tab = isset($referrer['tab']) ? $referrer['tab'] : 'general'; |
|
617 | + $section = isset($referrer['section']) ? $referrer['section'] : 'main'; |
|
618 | 618 | |
619 | 619 | $input = $input ? $input : array(); |
620 | - $input = apply_filters( 'wpinv_settings_tab_' . $tab . '_sanitize', $input ); |
|
621 | - $input = apply_filters( 'wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input ); |
|
620 | + $input = apply_filters('wpinv_settings_tab_' . $tab . '_sanitize', $input); |
|
621 | + $input = apply_filters('wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input); |
|
622 | 622 | |
623 | 623 | // Loop through each setting being saved and pass it through a sanitization filter |
624 | - foreach ( $input as $key => $value ) { |
|
624 | + foreach ($input as $key => $value) { |
|
625 | 625 | // Get the setting type (checkbox, select, etc) |
626 | - $type = isset( $settings[ $tab ][ $key ]['type'] ) ? $settings[ $tab ][ $key ]['type'] : false; |
|
626 | + $type = isset($settings[$tab][$key]['type']) ? $settings[$tab][$key]['type'] : false; |
|
627 | 627 | |
628 | - if ( $type ) { |
|
628 | + if ($type) { |
|
629 | 629 | // Field type specific filter |
630 | - $input[$key] = apply_filters( 'wpinv_settings_sanitize_' . $type, $value, $key ); |
|
630 | + $input[$key] = apply_filters('wpinv_settings_sanitize_' . $type, $value, $key); |
|
631 | 631 | } |
632 | 632 | |
633 | 633 | // General filter |
634 | - $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
634 | + $input[$key] = apply_filters('wpinv_settings_sanitize', $input[$key], $key); |
|
635 | 635 | } |
636 | 636 | |
637 | 637 | // Loop through the whitelist and unset any that are empty for the tab being saved |
638 | - $main_settings = $section == 'main' ? $settings[ $tab ] : array(); // Check for extensions that aren't using new sections |
|
639 | - $section_settings = ! empty( $settings[ $tab ][ $section ] ) ? $settings[ $tab ][ $section ] : array(); |
|
638 | + $main_settings = $section == 'main' ? $settings[$tab] : array(); // Check for extensions that aren't using new sections |
|
639 | + $section_settings = !empty($settings[$tab][$section]) ? $settings[$tab][$section] : array(); |
|
640 | 640 | |
641 | - $found_settings = array_merge( $main_settings, $section_settings ); |
|
641 | + $found_settings = array_merge($main_settings, $section_settings); |
|
642 | 642 | |
643 | - if ( ! empty( $found_settings ) ) { |
|
644 | - foreach ( $found_settings as $key => $value ) { |
|
643 | + if (!empty($found_settings)) { |
|
644 | + foreach ($found_settings as $key => $value) { |
|
645 | 645 | |
646 | 646 | // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work |
647 | - if ( is_numeric( $key ) ) { |
|
647 | + if (is_numeric($key)) { |
|
648 | 648 | $key = $value['id']; |
649 | 649 | } |
650 | 650 | |
651 | - if ( empty( $input[ $key ] ) ) { |
|
652 | - unset( $wpinv_options[ $key ] ); |
|
651 | + if (empty($input[$key])) { |
|
652 | + unset($wpinv_options[$key]); |
|
653 | 653 | } |
654 | 654 | } |
655 | 655 | } |
656 | 656 | |
657 | 657 | // Merge our new settings with the existing |
658 | - $output = array_merge( $wpinv_options, $input ); |
|
658 | + $output = array_merge($wpinv_options, $input); |
|
659 | 659 | |
660 | - add_settings_error( 'wpinv-notices', '', __( 'Settings updated.', 'invoicing' ), 'updated' ); |
|
660 | + add_settings_error('wpinv-notices', '', __('Settings updated.', 'invoicing'), 'updated'); |
|
661 | 661 | |
662 | 662 | return $output; |
663 | 663 | } |
664 | 664 | |
665 | -function wpinv_settings_sanitize_misc_accounting( $input ) { |
|
665 | +function wpinv_settings_sanitize_misc_accounting($input) { |
|
666 | 666 | global $wpinv_options, $wpi_session; |
667 | 667 | |
668 | - if ( !current_user_can( 'manage_options' ) ) { |
|
668 | + if (!current_user_can('manage_options')) { |
|
669 | 669 | return $input; |
670 | 670 | } |
671 | 671 | |
672 | - if( ! empty( $input['enable_sequential'] ) && !wpinv_get_option( 'enable_sequential' ) ) { |
|
672 | + if (!empty($input['enable_sequential']) && !wpinv_get_option('enable_sequential')) { |
|
673 | 673 | // Shows an admin notice about upgrading previous order numbers |
674 | - $wpi_session->set( 'upgrade_sequential', '1' ); |
|
674 | + $wpi_session->set('upgrade_sequential', '1'); |
|
675 | 675 | } |
676 | 676 | |
677 | 677 | return $input; |
678 | 678 | } |
679 | -add_filter( 'wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting' ); |
|
679 | +add_filter('wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting'); |
|
680 | 680 | |
681 | -function wpinv_settings_sanitize_tax_rates( $input ) { |
|
682 | - if( !current_user_can( 'manage_options' ) ) { |
|
681 | +function wpinv_settings_sanitize_tax_rates($input) { |
|
682 | + if (!current_user_can('manage_options')) { |
|
683 | 683 | return $input; |
684 | 684 | } |
685 | 685 | |
686 | - $new_rates = !empty( $_POST['tax_rates'] ) ? array_values( $_POST['tax_rates'] ) : array(); |
|
686 | + $new_rates = !empty($_POST['tax_rates']) ? array_values($_POST['tax_rates']) : array(); |
|
687 | 687 | |
688 | 688 | $tax_rates = array(); |
689 | 689 | |
690 | - if ( !empty( $new_rates ) ) { |
|
691 | - foreach ( $new_rates as $rate ) { |
|
692 | - if ( isset( $rate['country'] ) && empty( $rate['country'] ) && empty( $rate['state'] ) ) { |
|
690 | + if (!empty($new_rates)) { |
|
691 | + foreach ($new_rates as $rate) { |
|
692 | + if (isset($rate['country']) && empty($rate['country']) && empty($rate['state'])) { |
|
693 | 693 | continue; |
694 | 694 | } |
695 | 695 | |
@@ -697,36 +697,36 @@ discard block |
||
697 | 697 | } |
698 | 698 | } |
699 | 699 | |
700 | - update_option( 'wpinv_tax_rates', $tax_rates ); |
|
700 | + update_option('wpinv_tax_rates', $tax_rates); |
|
701 | 701 | |
702 | 702 | return $input; |
703 | 703 | } |
704 | -add_filter( 'wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates' ); |
|
704 | +add_filter('wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates'); |
|
705 | 705 | |
706 | -function wpinv_sanitize_text_field( $input ) { |
|
707 | - return trim( $input ); |
|
706 | +function wpinv_sanitize_text_field($input) { |
|
707 | + return trim($input); |
|
708 | 708 | } |
709 | -add_filter( 'wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field' ); |
|
709 | +add_filter('wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field'); |
|
710 | 710 | |
711 | 711 | function wpinv_get_settings_tabs() { |
712 | 712 | $tabs = array(); |
713 | - $tabs['general'] = __( 'General', 'invoicing' ); |
|
714 | - $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' ); |
|
715 | - $tabs['taxes'] = __( 'Taxes', 'invoicing' ); |
|
716 | - $tabs['emails'] = __( 'Emails', 'invoicing' ); |
|
717 | - $tabs['misc'] = __( 'Misc', 'invoicing' ); |
|
718 | - $tabs['tools'] = __( 'Tools', 'invoicing' ); |
|
719 | - |
|
720 | - return apply_filters( 'wpinv_settings_tabs', $tabs ); |
|
713 | + $tabs['general'] = __('General', 'invoicing'); |
|
714 | + $tabs['gateways'] = __('Payment Gateways', 'invoicing'); |
|
715 | + $tabs['taxes'] = __('Taxes', 'invoicing'); |
|
716 | + $tabs['emails'] = __('Emails', 'invoicing'); |
|
717 | + $tabs['misc'] = __('Misc', 'invoicing'); |
|
718 | + $tabs['tools'] = __('Tools', 'invoicing'); |
|
719 | + |
|
720 | + return apply_filters('wpinv_settings_tabs', $tabs); |
|
721 | 721 | } |
722 | 722 | |
723 | -function wpinv_get_settings_tab_sections( $tab = false ) { |
|
723 | +function wpinv_get_settings_tab_sections($tab = false) { |
|
724 | 724 | $tabs = false; |
725 | 725 | $sections = wpinv_get_registered_settings_sections(); |
726 | 726 | |
727 | - if( $tab && ! empty( $sections[ $tab ] ) ) { |
|
728 | - $tabs = $sections[ $tab ]; |
|
729 | - } else if ( $tab ) { |
|
727 | + if ($tab && !empty($sections[$tab])) { |
|
728 | + $tabs = $sections[$tab]; |
|
729 | + } else if ($tab) { |
|
730 | 730 | $tabs = false; |
731 | 731 | } |
732 | 732 | |
@@ -736,135 +736,135 @@ discard block |
||
736 | 736 | function wpinv_get_registered_settings_sections() { |
737 | 737 | static $sections = false; |
738 | 738 | |
739 | - if ( false !== $sections ) { |
|
739 | + if (false !== $sections) { |
|
740 | 740 | return $sections; |
741 | 741 | } |
742 | 742 | |
743 | 743 | $sections = array( |
744 | - 'general' => apply_filters( 'wpinv_settings_sections_general', array( |
|
745 | - 'main' => __( 'General Settings', 'invoicing' ), |
|
746 | - 'currency_section' => __( 'Currency Settings', 'invoicing' ), |
|
747 | - 'labels' => __( 'Label Texts', 'invoicing' ), |
|
748 | - ) ), |
|
749 | - 'gateways' => apply_filters( 'wpinv_settings_sections_gateways', array( |
|
750 | - 'main' => __( 'Gateway Settings', 'invoicing' ), |
|
751 | - ) ), |
|
752 | - 'taxes' => apply_filters( 'wpinv_settings_sections_taxes', array( |
|
753 | - 'main' => __( 'Tax Settings', 'invoicing' ), |
|
754 | - 'rates' => __( 'Tax Rates', 'invoicing' ), |
|
755 | - ) ), |
|
756 | - 'emails' => apply_filters( 'wpinv_settings_sections_emails', array( |
|
757 | - 'main' => __( 'Email Settings', 'invoicing' ), |
|
758 | - ) ), |
|
759 | - 'misc' => apply_filters( 'wpinv_settings_sections_misc', array( |
|
760 | - 'main' => __( 'Misc Settings', 'invoicing' ), |
|
761 | - ) ), |
|
762 | - 'tools' => apply_filters( 'wpinv_settings_sections_tools', array( |
|
763 | - 'main' => __( 'Diagnostic Tools', 'invoicing' ), |
|
764 | - ) ), |
|
744 | + 'general' => apply_filters('wpinv_settings_sections_general', array( |
|
745 | + 'main' => __('General Settings', 'invoicing'), |
|
746 | + 'currency_section' => __('Currency Settings', 'invoicing'), |
|
747 | + 'labels' => __('Label Texts', 'invoicing'), |
|
748 | + )), |
|
749 | + 'gateways' => apply_filters('wpinv_settings_sections_gateways', array( |
|
750 | + 'main' => __('Gateway Settings', 'invoicing'), |
|
751 | + )), |
|
752 | + 'taxes' => apply_filters('wpinv_settings_sections_taxes', array( |
|
753 | + 'main' => __('Tax Settings', 'invoicing'), |
|
754 | + 'rates' => __('Tax Rates', 'invoicing'), |
|
755 | + )), |
|
756 | + 'emails' => apply_filters('wpinv_settings_sections_emails', array( |
|
757 | + 'main' => __('Email Settings', 'invoicing'), |
|
758 | + )), |
|
759 | + 'misc' => apply_filters('wpinv_settings_sections_misc', array( |
|
760 | + 'main' => __('Misc Settings', 'invoicing'), |
|
761 | + )), |
|
762 | + 'tools' => apply_filters('wpinv_settings_sections_tools', array( |
|
763 | + 'main' => __('Diagnostic Tools', 'invoicing'), |
|
764 | + )), |
|
765 | 765 | ); |
766 | 766 | |
767 | - $sections = apply_filters( 'wpinv_settings_sections', $sections ); |
|
767 | + $sections = apply_filters('wpinv_settings_sections', $sections); |
|
768 | 768 | |
769 | 769 | return $sections; |
770 | 770 | } |
771 | 771 | |
772 | -function wpinv_get_pages( $with_slug = false, $default_label = NULL ) { |
|
772 | +function wpinv_get_pages($with_slug = false, $default_label = NULL) { |
|
773 | 773 | $pages_options = array(); |
774 | 774 | |
775 | - if( $default_label !== NULL && $default_label !== false ) { |
|
776 | - $pages_options = array( '' => $default_label ); // Blank option |
|
775 | + if ($default_label !== NULL && $default_label !== false) { |
|
776 | + $pages_options = array('' => $default_label); // Blank option |
|
777 | 777 | } |
778 | 778 | |
779 | 779 | $pages = get_pages(); |
780 | - if ( $pages ) { |
|
781 | - foreach ( $pages as $page ) { |
|
780 | + if ($pages) { |
|
781 | + foreach ($pages as $page) { |
|
782 | 782 | $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
783 | - $pages_options[ $page->ID ] = $title; |
|
783 | + $pages_options[$page->ID] = $title; |
|
784 | 784 | } |
785 | 785 | } |
786 | 786 | |
787 | 787 | return $pages_options; |
788 | 788 | } |
789 | 789 | |
790 | -function wpinv_header_callback( $args ) { |
|
791 | - if ( !empty( $args['desc'] ) ) { |
|
790 | +function wpinv_header_callback($args) { |
|
791 | + if (!empty($args['desc'])) { |
|
792 | 792 | echo $args['desc']; |
793 | 793 | } |
794 | 794 | } |
795 | 795 | |
796 | -function wpinv_hidden_callback( $args ) { |
|
796 | +function wpinv_hidden_callback($args) { |
|
797 | 797 | global $wpinv_options; |
798 | 798 | |
799 | - if ( isset( $args['set_value'] ) ) { |
|
799 | + if (isset($args['set_value'])) { |
|
800 | 800 | $value = $args['set_value']; |
801 | - } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
802 | - $value = $wpinv_options[ $args['id'] ]; |
|
801 | + } elseif (isset($wpinv_options[$args['id']])) { |
|
802 | + $value = $wpinv_options[$args['id']]; |
|
803 | 803 | } else { |
804 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
804 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
805 | 805 | } |
806 | 806 | |
807 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
807 | + if (isset($args['faux']) && true === $args['faux']) { |
|
808 | 808 | $args['readonly'] = true; |
809 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
809 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
810 | 810 | $name = ''; |
811 | 811 | } else { |
812 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
812 | + $name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"'; |
|
813 | 813 | } |
814 | 814 | |
815 | - $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
815 | + $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key($args['id']) . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '" />'; |
|
816 | 816 | |
817 | 817 | echo $html; |
818 | 818 | } |
819 | 819 | |
820 | -function wpinv_checkbox_callback( $args ) { |
|
820 | +function wpinv_checkbox_callback($args) { |
|
821 | 821 | global $wpinv_options; |
822 | 822 | |
823 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
823 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
824 | 824 | |
825 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
825 | + if (isset($args['faux']) && true === $args['faux']) { |
|
826 | 826 | $name = ''; |
827 | 827 | } else { |
828 | 828 | $name = 'name="wpinv_settings[' . $sanitize_id . ']"'; |
829 | 829 | } |
830 | 830 | |
831 | - $checked = isset( $wpinv_options[ $args['id'] ] ) ? checked( 1, $wpinv_options[ $args['id'] ], false ) : ''; |
|
831 | + $checked = isset($wpinv_options[$args['id']]) ? checked(1, $wpinv_options[$args['id']], false) : ''; |
|
832 | 832 | $html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>'; |
833 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
833 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
834 | 834 | |
835 | 835 | echo $html; |
836 | 836 | } |
837 | 837 | |
838 | -function wpinv_multicheck_callback( $args ) { |
|
838 | +function wpinv_multicheck_callback($args) { |
|
839 | 839 | global $wpinv_options; |
840 | 840 | |
841 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
841 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
842 | 842 | |
843 | - if ( ! empty( $args['options'] ) ) { |
|
844 | - foreach( $args['options'] as $key => $option ): |
|
845 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
846 | - if ( isset( $wpinv_options[$args['id']][$sanitize_key] ) ) { |
|
843 | + if (!empty($args['options'])) { |
|
844 | + foreach ($args['options'] as $key => $option): |
|
845 | + $sanitize_key = wpinv_sanitize_key($key); |
|
846 | + if (isset($wpinv_options[$args['id']][$sanitize_key])) { |
|
847 | 847 | $enabled = $sanitize_key; |
848 | 848 | } else { |
849 | 849 | $enabled = NULL; |
850 | 850 | } |
851 | - echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
852 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label><br/>'; |
|
851 | + echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($sanitize_key) . '" ' . checked($sanitize_key, $enabled, false) . '/> '; |
|
852 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post($option) . '</label><br/>'; |
|
853 | 853 | endforeach; |
854 | 854 | echo '<p class="description">' . $args['desc'] . '</p>'; |
855 | 855 | } |
856 | 856 | } |
857 | 857 | |
858 | -function wpinv_payment_icons_callback( $args ) { |
|
858 | +function wpinv_payment_icons_callback($args) { |
|
859 | 859 | global $wpinv_options; |
860 | 860 | |
861 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
861 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
862 | 862 | |
863 | - if ( ! empty( $args['options'] ) ) { |
|
864 | - foreach( $args['options'] as $key => $option ) { |
|
865 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
863 | + if (!empty($args['options'])) { |
|
864 | + foreach ($args['options'] as $key => $option) { |
|
865 | + $sanitize_key = wpinv_sanitize_key($key); |
|
866 | 866 | |
867 | - if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
867 | + if (isset($wpinv_options[$args['id']][$key])) { |
|
868 | 868 | $enabled = $option; |
869 | 869 | } else { |
870 | 870 | $enabled = NULL; |
@@ -872,194 +872,194 @@ discard block |
||
872 | 872 | |
873 | 873 | echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
874 | 874 | |
875 | - echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
875 | + echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($option) . '" ' . checked($option, $enabled, false) . '/> '; |
|
876 | 876 | |
877 | - if ( wpinv_string_is_image_url( $key ) ) { |
|
878 | - echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
877 | + if (wpinv_string_is_image_url($key)) { |
|
878 | + echo '<img class="payment-icon" src="' . esc_url($key) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
879 | 879 | } else { |
880 | - $card = strtolower( str_replace( ' ', '', $option ) ); |
|
880 | + $card = strtolower(str_replace(' ', '', $option)); |
|
881 | 881 | |
882 | - if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
883 | - $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
882 | + if (has_filter('wpinv_accepted_payment_' . $card . '_image')) { |
|
883 | + $image = apply_filters('wpinv_accepted_payment_' . $card . '_image', ''); |
|
884 | 884 | } else { |
885 | - $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
885 | + $image = wpinv_locate_template('images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false); |
|
886 | 886 | $content_dir = WP_CONTENT_DIR; |
887 | 887 | |
888 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
888 | + if (function_exists('wp_normalize_path')) { |
|
889 | 889 | // Replaces backslashes with forward slashes for Windows systems |
890 | - $image = wp_normalize_path( $image ); |
|
891 | - $content_dir = wp_normalize_path( $content_dir ); |
|
890 | + $image = wp_normalize_path($image); |
|
891 | + $content_dir = wp_normalize_path($content_dir); |
|
892 | 892 | } |
893 | 893 | |
894 | - $image = str_replace( $content_dir, content_url(), $image ); |
|
894 | + $image = str_replace($content_dir, content_url(), $image); |
|
895 | 895 | } |
896 | 896 | |
897 | - echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
897 | + echo '<img class="payment-icon" src="' . esc_url($image) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
898 | 898 | } |
899 | 899 | echo $option . '</label>'; |
900 | 900 | } |
901 | - echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
901 | + echo '<p class="description" style="margin-top:16px;">' . wp_kses_post($args['desc']) . '</p>'; |
|
902 | 902 | } |
903 | 903 | } |
904 | 904 | |
905 | -function wpinv_radio_callback( $args ) { |
|
905 | +function wpinv_radio_callback($args) { |
|
906 | 906 | global $wpinv_options; |
907 | 907 | |
908 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
908 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
909 | 909 | |
910 | - foreach ( $args['options'] as $key => $option ) : |
|
911 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
910 | + foreach ($args['options'] as $key => $option) : |
|
911 | + $sanitize_key = wpinv_sanitize_key($key); |
|
912 | 912 | |
913 | 913 | $checked = false; |
914 | 914 | |
915 | - if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key ) |
|
915 | + if (isset($wpinv_options[$args['id']]) && $wpinv_options[$args['id']] == $key) |
|
916 | 916 | $checked = true; |
917 | - elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) ) |
|
917 | + elseif (isset($args['std']) && $args['std'] == $key && !isset($wpinv_options[$args['id']])) |
|
918 | 918 | $checked = true; |
919 | 919 | |
920 | 920 | echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/> '; |
921 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>'; |
|
921 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option) . '</label><br/>'; |
|
922 | 922 | endforeach; |
923 | 923 | |
924 | - echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
924 | + echo '<p class="description">' . wp_kses_post($args['desc']) . '</p>'; |
|
925 | 925 | } |
926 | 926 | |
927 | -function wpinv_gateways_callback( $args ) { |
|
927 | +function wpinv_gateways_callback($args) { |
|
928 | 928 | global $wpinv_options; |
929 | 929 | |
930 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
930 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
931 | 931 | |
932 | - foreach ( $args['options'] as $key => $option ) : |
|
933 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
932 | + foreach ($args['options'] as $key => $option) : |
|
933 | + $sanitize_key = wpinv_sanitize_key($key); |
|
934 | 934 | |
935 | - if ( isset( $wpinv_options['gateways'][ $key ] ) ) |
|
935 | + if (isset($wpinv_options['gateways'][$key])) |
|
936 | 936 | $enabled = '1'; |
937 | 937 | else |
938 | 938 | $enabled = null; |
939 | 939 | |
940 | - echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
941 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
940 | + echo '<input name="wpinv_settings[' . esc_attr($args['id']) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
941 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option['admin_label']) . '</label><br/>'; |
|
942 | 942 | endforeach; |
943 | 943 | } |
944 | 944 | |
945 | 945 | function wpinv_gateway_select_callback($args) { |
946 | 946 | global $wpinv_options; |
947 | 947 | |
948 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
948 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
949 | 949 | |
950 | 950 | echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']">'; |
951 | 951 | |
952 | - foreach ( $args['options'] as $key => $option ) : |
|
953 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
954 | - $selected = selected( $key, $args['selected'], false ); |
|
952 | + foreach ($args['options'] as $key => $option) : |
|
953 | + if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) { |
|
954 | + $selected = selected($key, $args['selected'], false); |
|
955 | 955 | } else { |
956 | - $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : ''; |
|
956 | + $selected = isset($wpinv_options[$args['id']]) ? selected($key, $wpinv_options[$args['id']], false) : ''; |
|
957 | 957 | } |
958 | - echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
958 | + echo '<option value="' . wpinv_sanitize_key($key) . '"' . $selected . '>' . esc_html($option['admin_label']) . '</option>'; |
|
959 | 959 | endforeach; |
960 | 960 | |
961 | 961 | echo '</select>'; |
962 | - echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
962 | + echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
963 | 963 | } |
964 | 964 | |
965 | -function wpinv_text_callback( $args ) { |
|
965 | +function wpinv_text_callback($args) { |
|
966 | 966 | global $wpinv_options; |
967 | 967 | |
968 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
968 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
969 | 969 | |
970 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
971 | - $value = $wpinv_options[ $args['id'] ]; |
|
970 | + if (isset($wpinv_options[$args['id']])) { |
|
971 | + $value = $wpinv_options[$args['id']]; |
|
972 | 972 | } else { |
973 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
973 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
974 | 974 | } |
975 | 975 | |
976 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
976 | + if (isset($args['faux']) && true === $args['faux']) { |
|
977 | 977 | $args['readonly'] = true; |
978 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
978 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
979 | 979 | $name = ''; |
980 | 980 | } else { |
981 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
981 | + $name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"'; |
|
982 | 982 | } |
983 | 983 | |
984 | 984 | $readonly = $args['readonly'] === true ? ' readonly="readonly"' : ''; |
985 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
986 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>'; |
|
987 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
985 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
986 | + $html = '<input type="text" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"' . $readonly . '/>'; |
|
987 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
988 | 988 | |
989 | 989 | echo $html; |
990 | 990 | } |
991 | 991 | |
992 | -function wpinv_number_callback( $args ) { |
|
992 | +function wpinv_number_callback($args) { |
|
993 | 993 | global $wpinv_options; |
994 | 994 | |
995 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
995 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
996 | 996 | |
997 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
998 | - $value = $wpinv_options[ $args['id'] ]; |
|
997 | + if (isset($wpinv_options[$args['id']])) { |
|
998 | + $value = $wpinv_options[$args['id']]; |
|
999 | 999 | } else { |
1000 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1000 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
1001 | 1001 | } |
1002 | 1002 | |
1003 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
1003 | + if (isset($args['faux']) && true === $args['faux']) { |
|
1004 | 1004 | $args['readonly'] = true; |
1005 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1005 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
1006 | 1006 | $name = ''; |
1007 | 1007 | } else { |
1008 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
1008 | + $name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"'; |
|
1009 | 1009 | } |
1010 | 1010 | |
1011 | - $max = isset( $args['max'] ) ? $args['max'] : 999999; |
|
1012 | - $min = isset( $args['min'] ) ? $args['min'] : 0; |
|
1013 | - $step = isset( $args['step'] ) ? $args['step'] : 1; |
|
1011 | + $max = isset($args['max']) ? $args['max'] : 999999; |
|
1012 | + $min = isset($args['min']) ? $args['min'] : 0; |
|
1013 | + $step = isset($args['step']) ? $args['step'] : 1; |
|
1014 | 1014 | |
1015 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
1016 | - $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
1017 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1015 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
1016 | + $html = '<input type="number" step="' . esc_attr($step) . '" max="' . esc_attr($max) . '" min="' . esc_attr($min) . '" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"/>'; |
|
1017 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
1018 | 1018 | |
1019 | 1019 | echo $html; |
1020 | 1020 | } |
1021 | 1021 | |
1022 | -function wpinv_textarea_callback( $args ) { |
|
1022 | +function wpinv_textarea_callback($args) { |
|
1023 | 1023 | global $wpinv_options; |
1024 | 1024 | |
1025 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
1025 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
1026 | 1026 | |
1027 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1028 | - $value = $wpinv_options[ $args['id'] ]; |
|
1027 | + if (isset($wpinv_options[$args['id']])) { |
|
1028 | + $value = $wpinv_options[$args['id']]; |
|
1029 | 1029 | } else { |
1030 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1030 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
1031 | 1031 | } |
1032 | 1032 | |
1033 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
1034 | - $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text'; |
|
1033 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
1034 | + $class = (isset($args['class']) && !is_null($args['class'])) ? $args['class'] : 'large-text'; |
|
1035 | 1035 | |
1036 | - $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
1037 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1036 | + $html = '<textarea class="' . sanitize_html_class($class) . ' txtarea-' . sanitize_html_class($size) . ' wpi-' . esc_attr(sanitize_html_class($sanitize_id)) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']">' . esc_textarea(stripslashes($value)) . '</textarea>'; |
|
1037 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
1038 | 1038 | |
1039 | 1039 | echo $html; |
1040 | 1040 | } |
1041 | 1041 | |
1042 | -function wpinv_password_callback( $args ) { |
|
1042 | +function wpinv_password_callback($args) { |
|
1043 | 1043 | global $wpinv_options; |
1044 | 1044 | |
1045 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
1045 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
1046 | 1046 | |
1047 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1048 | - $value = $wpinv_options[ $args['id'] ]; |
|
1047 | + if (isset($wpinv_options[$args['id']])) { |
|
1048 | + $value = $wpinv_options[$args['id']]; |
|
1049 | 1049 | } else { |
1050 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1050 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
1051 | 1051 | } |
1052 | 1052 | |
1053 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
1054 | - $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
1055 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1053 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
1054 | + $html = '<input type="password" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '"/>'; |
|
1055 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
1056 | 1056 | |
1057 | 1057 | echo $html; |
1058 | 1058 | } |
1059 | 1059 | |
1060 | 1060 | function wpinv_missing_callback($args) { |
1061 | 1061 | printf( |
1062 | - __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
1062 | + __('The callback function used for the %s setting is missing.', 'invoicing'), |
|
1063 | 1063 | '<strong>' . $args['id'] . '</strong>' |
1064 | 1064 | ); |
1065 | 1065 | } |
@@ -1067,137 +1067,137 @@ discard block |
||
1067 | 1067 | function wpinv_select_callback($args) { |
1068 | 1068 | global $wpinv_options; |
1069 | 1069 | |
1070 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
1070 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
1071 | 1071 | |
1072 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1073 | - $value = $wpinv_options[ $args['id'] ]; |
|
1072 | + if (isset($wpinv_options[$args['id']])) { |
|
1073 | + $value = $wpinv_options[$args['id']]; |
|
1074 | 1074 | } else { |
1075 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1075 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
1076 | 1076 | } |
1077 | 1077 | |
1078 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
1078 | + if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) { |
|
1079 | 1079 | $value = $args['selected']; |
1080 | 1080 | } |
1081 | 1081 | |
1082 | - if ( isset( $args['placeholder'] ) ) { |
|
1082 | + if (isset($args['placeholder'])) { |
|
1083 | 1083 | $placeholder = $args['placeholder']; |
1084 | 1084 | } else { |
1085 | 1085 | $placeholder = ''; |
1086 | 1086 | } |
1087 | 1087 | |
1088 | - if ( isset( $args['chosen'] ) ) { |
|
1088 | + if (isset($args['chosen'])) { |
|
1089 | 1089 | $chosen = 'class="wpinv-chosen"'; |
1090 | 1090 | } else { |
1091 | 1091 | $chosen = ''; |
1092 | 1092 | } |
1093 | 1093 | |
1094 | - if( !empty( $args['onchange'] ) ) { |
|
1095 | - $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
1094 | + if (!empty($args['onchange'])) { |
|
1095 | + $onchange = ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
1096 | 1096 | } else { |
1097 | 1097 | $onchange = ''; |
1098 | 1098 | } |
1099 | 1099 | |
1100 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" ' . $chosen . 'data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />'; |
|
1100 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" ' . $chosen . 'data-placeholder="' . esc_html($placeholder) . '"' . $onchange . ' />'; |
|
1101 | 1101 | |
1102 | - foreach ( $args['options'] as $option => $name ) { |
|
1103 | - $selected = selected( $option, $value, false ); |
|
1104 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
1102 | + foreach ($args['options'] as $option => $name) { |
|
1103 | + $selected = selected($option, $value, false); |
|
1104 | + $html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>'; |
|
1105 | 1105 | } |
1106 | 1106 | |
1107 | 1107 | $html .= '</select>'; |
1108 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1108 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
1109 | 1109 | |
1110 | 1110 | echo $html; |
1111 | 1111 | } |
1112 | 1112 | |
1113 | -function wpinv_color_select_callback( $args ) { |
|
1113 | +function wpinv_color_select_callback($args) { |
|
1114 | 1114 | global $wpinv_options; |
1115 | 1115 | |
1116 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
1116 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
1117 | 1117 | |
1118 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1119 | - $value = $wpinv_options[ $args['id'] ]; |
|
1118 | + if (isset($wpinv_options[$args['id']])) { |
|
1119 | + $value = $wpinv_options[$args['id']]; |
|
1120 | 1120 | } else { |
1121 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1121 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
1122 | 1122 | } |
1123 | 1123 | |
1124 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
1124 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"/>'; |
|
1125 | 1125 | |
1126 | - foreach ( $args['options'] as $option => $color ) { |
|
1127 | - $selected = selected( $option, $value, false ); |
|
1128 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
1126 | + foreach ($args['options'] as $option => $color) { |
|
1127 | + $selected = selected($option, $value, false); |
|
1128 | + $html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($color['label']) . '</option>'; |
|
1129 | 1129 | } |
1130 | 1130 | |
1131 | 1131 | $html .= '</select>'; |
1132 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1132 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
1133 | 1133 | |
1134 | 1134 | echo $html; |
1135 | 1135 | } |
1136 | 1136 | |
1137 | -function wpinv_rich_editor_callback( $args ) { |
|
1137 | +function wpinv_rich_editor_callback($args) { |
|
1138 | 1138 | global $wpinv_options, $wp_version; |
1139 | 1139 | |
1140 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
1140 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
1141 | 1141 | |
1142 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1143 | - $value = $wpinv_options[ $args['id'] ]; |
|
1142 | + if (isset($wpinv_options[$args['id']])) { |
|
1143 | + $value = $wpinv_options[$args['id']]; |
|
1144 | 1144 | |
1145 | - if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
1146 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1145 | + if (empty($args['allow_blank']) && empty($value)) { |
|
1146 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
1147 | 1147 | } |
1148 | 1148 | } else { |
1149 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1149 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
1150 | 1150 | } |
1151 | 1151 | |
1152 | - $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
1152 | + $rows = isset($args['size']) ? $args['size'] : 20; |
|
1153 | 1153 | |
1154 | - if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
1154 | + if ($wp_version >= 3.3 && function_exists('wp_editor')) { |
|
1155 | 1155 | ob_start(); |
1156 | - wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ) ) ); |
|
1156 | + wp_editor(stripslashes($value), 'wpinv_settings_' . esc_attr($args['id']), array('textarea_name' => 'wpinv_settings[' . esc_attr($args['id']) . ']', 'textarea_rows' => absint($rows))); |
|
1157 | 1157 | $html = ob_get_clean(); |
1158 | 1158 | } else { |
1159 | - $html = '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
1159 | + $html = '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" class="wpi-' . esc_attr(sanitize_html_class($args['id'])) . '">' . esc_textarea(stripslashes($value)) . '</textarea>'; |
|
1160 | 1160 | } |
1161 | 1161 | |
1162 | - $html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1162 | + $html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
1163 | 1163 | |
1164 | 1164 | echo $html; |
1165 | 1165 | } |
1166 | 1166 | |
1167 | -function wpinv_upload_callback( $args ) { |
|
1167 | +function wpinv_upload_callback($args) { |
|
1168 | 1168 | global $wpinv_options; |
1169 | 1169 | |
1170 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
1170 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
1171 | 1171 | |
1172 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1172 | + if (isset($wpinv_options[$args['id']])) { |
|
1173 | 1173 | $value = $wpinv_options[$args['id']]; |
1174 | 1174 | } else { |
1175 | 1175 | $value = isset($args['std']) ? $args['std'] : ''; |
1176 | 1176 | } |
1177 | 1177 | |
1178 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
1179 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
1180 | - $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
1181 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1178 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
1179 | + $html = '<input type="text" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr(stripslashes($value)) . '"/>'; |
|
1180 | + $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __('Upload File', 'invoicing') . '"/></span>'; |
|
1181 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
1182 | 1182 | |
1183 | 1183 | echo $html; |
1184 | 1184 | } |
1185 | 1185 | |
1186 | -function wpinv_color_callback( $args ) { |
|
1186 | +function wpinv_color_callback($args) { |
|
1187 | 1187 | global $wpinv_options; |
1188 | 1188 | |
1189 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
1189 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
1190 | 1190 | |
1191 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1192 | - $value = $wpinv_options[ $args['id'] ]; |
|
1191 | + if (isset($wpinv_options[$args['id']])) { |
|
1192 | + $value = $wpinv_options[$args['id']]; |
|
1193 | 1193 | } else { |
1194 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1194 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
1195 | 1195 | } |
1196 | 1196 | |
1197 | - $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
1197 | + $default = isset($args['std']) ? $args['std'] : ''; |
|
1198 | 1198 | |
1199 | - $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
1200 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1199 | + $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '" data-default-color="' . esc_attr($default) . '" />'; |
|
1200 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
1201 | 1201 | |
1202 | 1202 | echo $html; |
1203 | 1203 | } |
@@ -1205,9 +1205,9 @@ discard block |
||
1205 | 1205 | function wpinv_country_states_callback($args) { |
1206 | 1206 | global $wpinv_options; |
1207 | 1207 | |
1208 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
1208 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
1209 | 1209 | |
1210 | - if ( isset( $args['placeholder'] ) ) { |
|
1210 | + if (isset($args['placeholder'])) { |
|
1211 | 1211 | $placeholder = $args['placeholder']; |
1212 | 1212 | } else { |
1213 | 1213 | $placeholder = ''; |
@@ -1215,17 +1215,17 @@ discard block |
||
1215 | 1215 | |
1216 | 1216 | $states = wpinv_get_country_states(); |
1217 | 1217 | |
1218 | - $chosen = ( $args['chosen'] ? ' wpinv-chosen' : '' ); |
|
1219 | - $class = empty( $states ) ? ' class="wpinv-no-states' . $chosen . '"' : 'class="' . $chosen . '"'; |
|
1220 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
1218 | + $chosen = ($args['chosen'] ? ' wpinv-chosen' : ''); |
|
1219 | + $class = empty($states) ? ' class="wpinv-no-states' . $chosen . '"' : 'class="' . $chosen . '"'; |
|
1220 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"' . $class . 'data-placeholder="' . esc_html($placeholder) . '"/>'; |
|
1221 | 1221 | |
1222 | - foreach ( $states as $option => $name ) { |
|
1223 | - $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
1224 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
1222 | + foreach ($states as $option => $name) { |
|
1223 | + $selected = isset($wpinv_options[$args['id']]) ? selected($option, $wpinv_options[$args['id']], false) : ''; |
|
1224 | + $html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>'; |
|
1225 | 1225 | } |
1226 | 1226 | |
1227 | 1227 | $html .= '</select>'; |
1228 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1228 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
1229 | 1229 | |
1230 | 1230 | echo $html; |
1231 | 1231 | } |
@@ -1240,25 +1240,25 @@ discard block |
||
1240 | 1240 | <table id="wpinv_tax_rates" class="wp-list-table widefat fixed posts"> |
1241 | 1241 | <thead> |
1242 | 1242 | <tr> |
1243 | - <th scope="col" class="wpinv_tax_country"><?php _e( 'Country', 'invoicing' ); ?></th> |
|
1244 | - <th scope="col" class="wpinv_tax_state"><?php _e( 'State / Province', 'invoicing' ); ?></th> |
|
1245 | - <th scope="col" class="wpinv_tax_global" title="<?php esc_attr_e( 'Apply rate to whole country, regardless of state / province', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th> |
|
1246 | - <th scope="col" class="wpinv_tax_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> |
|
1247 | - <th scope="col" class="wpinv_tax_name"><?php _e( 'Tax Name', 'invoicing' ); ?></th> |
|
1248 | - <th scope="col" class="wpinv_tax_action"><?php _e( 'Remove', 'invoicing' ); ?></th> |
|
1243 | + <th scope="col" class="wpinv_tax_country"><?php _e('Country', 'invoicing'); ?></th> |
|
1244 | + <th scope="col" class="wpinv_tax_state"><?php _e('State / Province', 'invoicing'); ?></th> |
|
1245 | + <th scope="col" class="wpinv_tax_global" title="<?php esc_attr_e('Apply rate to whole country, regardless of state / province', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th> |
|
1246 | + <th scope="col" class="wpinv_tax_rate"><?php _e('Rate %', 'invoicing'); ?></th> |
|
1247 | + <th scope="col" class="wpinv_tax_name"><?php _e('Tax Name', 'invoicing'); ?></th> |
|
1248 | + <th scope="col" class="wpinv_tax_action"><?php _e('Remove', 'invoicing'); ?></th> |
|
1249 | 1249 | </tr> |
1250 | 1250 | </thead> |
1251 | 1251 | <tbody> |
1252 | - <?php if( !empty( $rates ) ) : ?> |
|
1253 | - <?php foreach( $rates as $key => $rate ) : ?> |
|
1252 | + <?php if (!empty($rates)) : ?> |
|
1253 | + <?php foreach ($rates as $key => $rate) : ?> |
|
1254 | 1254 | <?php |
1255 | - $sanitized_key = wpinv_sanitize_key( $key ); |
|
1255 | + $sanitized_key = wpinv_sanitize_key($key); |
|
1256 | 1256 | ?> |
1257 | 1257 | <tr> |
1258 | 1258 | <td class="wpinv_tax_country"> |
1259 | 1259 | <?php |
1260 | - echo wpinv_html_select( array( |
|
1261 | - 'options' => wpinv_get_country_list( true ), |
|
1260 | + echo wpinv_html_select(array( |
|
1261 | + 'options' => wpinv_get_country_list(true), |
|
1262 | 1262 | 'name' => 'tax_rates[' . $sanitized_key . '][country]', |
1263 | 1263 | 'id' => 'tax_rates[' . $sanitized_key . '][country]', |
1264 | 1264 | 'selected' => $rate['country'], |
@@ -1266,72 +1266,72 @@ discard block |
||
1266 | 1266 | 'show_option_none' => false, |
1267 | 1267 | 'class' => 'wpinv-tax-country', |
1268 | 1268 | 'chosen' => false, |
1269 | - 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
1270 | - ) ); |
|
1269 | + 'placeholder' => __('Choose a country', 'invoicing') |
|
1270 | + )); |
|
1271 | 1271 | ?> |
1272 | 1272 | </td> |
1273 | 1273 | <td class="wpinv_tax_state"> |
1274 | 1274 | <?php |
1275 | - $states = wpinv_get_country_states( $rate['country'] ); |
|
1276 | - if( !empty( $states ) ) { |
|
1277 | - echo wpinv_html_select( array( |
|
1278 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
1275 | + $states = wpinv_get_country_states($rate['country']); |
|
1276 | + if (!empty($states)) { |
|
1277 | + echo wpinv_html_select(array( |
|
1278 | + 'options' => array_merge(array('' => ''), $states), |
|
1279 | 1279 | 'name' => 'tax_rates[' . $sanitized_key . '][state]', |
1280 | 1280 | 'id' => 'tax_rates[' . $sanitized_key . '][state]', |
1281 | 1281 | 'selected' => $rate['state'], |
1282 | 1282 | 'show_option_all' => false, |
1283 | 1283 | 'show_option_none' => false, |
1284 | 1284 | 'chosen' => false, |
1285 | - 'placeholder' => __( 'Choose a state', 'invoicing' ) |
|
1286 | - ) ); |
|
1285 | + 'placeholder' => __('Choose a state', 'invoicing') |
|
1286 | + )); |
|
1287 | 1287 | } else { |
1288 | - echo wpinv_html_text( array( |
|
1288 | + echo wpinv_html_text(array( |
|
1289 | 1289 | 'name' => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'], |
1290 | - 'value' => ! empty( $rate['state'] ) ? $rate['state'] : '', |
|
1290 | + 'value' => !empty($rate['state']) ? $rate['state'] : '', |
|
1291 | 1291 | 'id' => 'tax_rates[' . $sanitized_key . '][state]', |
1292 | - ) ); |
|
1292 | + )); |
|
1293 | 1293 | } |
1294 | 1294 | ?> |
1295 | 1295 | </td> |
1296 | 1296 | <td class="wpinv_tax_global"> |
1297 | - <input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked( true, ! empty( $rate['global'] ) ); ?>/> |
|
1298 | - <label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label> |
|
1297 | + <input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked(true, !empty($rate['global'])); ?>/> |
|
1298 | + <label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label> |
|
1299 | 1299 | </td> |
1300 | - <td class="wpinv_tax_rate"><input type="number" class="small-text" step="0.10" min="0.00" max="99" name="tax_rates[<?php echo $sanitized_key; ?>][rate]" value="<?php echo esc_html( $rate['rate'] ); ?>"/></td> |
|
1301 | - <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[<?php echo $sanitized_key; ?>][name]" value="<?php echo esc_html( $rate['name'] ); ?>"/></td> |
|
1302 | - <td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td> |
|
1300 | + <td class="wpinv_tax_rate"><input type="number" class="small-text" step="0.10" min="0.00" max="99" name="tax_rates[<?php echo $sanitized_key; ?>][rate]" value="<?php echo esc_html($rate['rate']); ?>"/></td> |
|
1301 | + <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[<?php echo $sanitized_key; ?>][name]" value="<?php echo esc_html($rate['name']); ?>"/></td> |
|
1302 | + <td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td> |
|
1303 | 1303 | </tr> |
1304 | 1304 | <?php endforeach; ?> |
1305 | 1305 | <?php else : ?> |
1306 | 1306 | <tr> |
1307 | 1307 | <td class="wpinv_tax_country"> |
1308 | 1308 | <?php |
1309 | - echo wpinv_html_select( array( |
|
1310 | - 'options' => wpinv_get_country_list( true ), |
|
1309 | + echo wpinv_html_select(array( |
|
1310 | + 'options' => wpinv_get_country_list(true), |
|
1311 | 1311 | 'name' => 'tax_rates[0][country]', |
1312 | 1312 | 'show_option_all' => false, |
1313 | 1313 | 'show_option_none' => false, |
1314 | 1314 | 'class' => 'wpinv-tax-country', |
1315 | 1315 | 'chosen' => false, |
1316 | - 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
1317 | - ) ); ?> |
|
1316 | + 'placeholder' => __('Choose a country', 'invoicing') |
|
1317 | + )); ?> |
|
1318 | 1318 | </td> |
1319 | 1319 | <td class="wpinv_tax_state"> |
1320 | - <?php echo wpinv_html_text( array( |
|
1320 | + <?php echo wpinv_html_text(array( |
|
1321 | 1321 | 'name' => 'tax_rates[0][state]' |
1322 | - ) ); ?> |
|
1322 | + )); ?> |
|
1323 | 1323 | </td> |
1324 | 1324 | <td class="wpinv_tax_global"> |
1325 | 1325 | <input type="checkbox" name="tax_rates[0][global]" id="tax_rates[0][global]" value="1"/> |
1326 | - <label for="tax_rates[0][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label> |
|
1326 | + <label for="tax_rates[0][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label> |
|
1327 | 1327 | </td> |
1328 | - <td class="wpinv_tax_rate"><input type="number" class="small-text" step="0.10" min="0.00" name="tax_rates[0][rate]" placeholder="<?php echo (float)wpinv_get_option( 'tax_rate', 0 ) ;?>" value="<?php echo (float)wpinv_get_option( 'tax_rate', 0 ) ;?>"/></td> |
|
1328 | + <td class="wpinv_tax_rate"><input type="number" class="small-text" step="0.10" min="0.00" name="tax_rates[0][rate]" placeholder="<?php echo (float)wpinv_get_option('tax_rate', 0); ?>" value="<?php echo (float)wpinv_get_option('tax_rate', 0); ?>"/></td> |
|
1329 | 1329 | <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[0][name]" /></td> |
1330 | - <td><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td> |
|
1330 | + <td><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td> |
|
1331 | 1331 | </tr> |
1332 | 1332 | <?php endif; ?> |
1333 | 1333 | </tbody> |
1334 | - <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e( 'Add Tax Rate', 'invoicing' ); ?></span></td></tr></tfoot> |
|
1334 | + <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e('Add Tax Rate', 'invoicing'); ?></span></td></tr></tfoot> |
|
1335 | 1335 | </table> |
1336 | 1336 | <?php |
1337 | 1337 | echo ob_get_clean(); |
@@ -1342,34 +1342,34 @@ discard block |
||
1342 | 1342 | ob_start(); ?> |
1343 | 1343 | </td><tr> |
1344 | 1344 | <td colspan="2" class="wpinv_tools_tdbox"> |
1345 | - <?php if ( $args['desc'] ) { ?><p><?php echo $args['desc']; ?></p><?php } ?> |
|
1346 | - <?php do_action( 'wpinv_tools_before' ); ?> |
|
1345 | + <?php if ($args['desc']) { ?><p><?php echo $args['desc']; ?></p><?php } ?> |
|
1346 | + <?php do_action('wpinv_tools_before'); ?> |
|
1347 | 1347 | <table id="wpinv_tools_table" class="wp-list-table widefat fixed posts"> |
1348 | 1348 | <thead> |
1349 | 1349 | <tr> |
1350 | - <th scope="col" class="wpinv-th-tool"><?php _e( 'Tool', 'invoicing' ); ?></th> |
|
1351 | - <th scope="col" class="wpinv-th-desc"><?php _e( 'Description', 'invoicing' ); ?></th> |
|
1352 | - <th scope="col" class="wpinv-th-action"><?php _e( 'Action', 'invoicing' ); ?></th> |
|
1350 | + <th scope="col" class="wpinv-th-tool"><?php _e('Tool', 'invoicing'); ?></th> |
|
1351 | + <th scope="col" class="wpinv-th-desc"><?php _e('Description', 'invoicing'); ?></th> |
|
1352 | + <th scope="col" class="wpinv-th-action"><?php _e('Action', 'invoicing'); ?></th> |
|
1353 | 1353 | </tr> |
1354 | 1354 | </thead> |
1355 | - <?php do_action( 'wpinv_tools_row' ); ?> |
|
1355 | + <?php do_action('wpinv_tools_row'); ?> |
|
1356 | 1356 | <tbody> |
1357 | 1357 | </tbody> |
1358 | 1358 | </table> |
1359 | - <?php do_action( 'wpinv_tools_after' ); ?> |
|
1359 | + <?php do_action('wpinv_tools_after'); ?> |
|
1360 | 1360 | <?php |
1361 | 1361 | echo ob_get_clean(); |
1362 | 1362 | } |
1363 | 1363 | |
1364 | -function wpinv_descriptive_text_callback( $args ) { |
|
1365 | - echo wp_kses_post( $args['desc'] ); |
|
1364 | +function wpinv_descriptive_text_callback($args) { |
|
1365 | + echo wp_kses_post($args['desc']); |
|
1366 | 1366 | } |
1367 | 1367 | |
1368 | -function wpinv_hook_callback( $args ) { |
|
1369 | - do_action( 'wpinv_' . $args['id'], $args ); |
|
1368 | +function wpinv_hook_callback($args) { |
|
1369 | + do_action('wpinv_' . $args['id'], $args); |
|
1370 | 1370 | } |
1371 | 1371 | |
1372 | 1372 | function wpinv_set_settings_cap() { |
1373 | 1373 | return 'manage_options'; |
1374 | 1374 | } |
1375 | -add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' ); |
|
1375 | +add_filter('option_page_capability_wpinv_settings', 'wpinv_set_settings_cap'); |
@@ -1,61 +1,61 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | function wpinv_print_errors() { |
8 | 8 | $errors = wpinv_get_errors(); |
9 | 9 | |
10 | - if ( $errors ) { |
|
11 | - $classes = apply_filters( 'wpinv_error_class', array( |
|
10 | + if ($errors) { |
|
11 | + $classes = apply_filters('wpinv_error_class', array( |
|
12 | 12 | 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-error' |
13 | - ) ); |
|
14 | - echo '<div class="' . implode( ' ', $classes ) . '">'; |
|
13 | + )); |
|
14 | + echo '<div class="' . implode(' ', $classes) . '">'; |
|
15 | 15 | // Loop error codes and display errors |
16 | - foreach ( $errors as $error_id => $error ) { |
|
17 | - echo '<p class="wpinv_error" id="wpinv_error_' . $error_id . '"><strong>' . __( 'Error', 'invoicing' ) . '</strong>: ' . $error . '</p>'; |
|
16 | + foreach ($errors as $error_id => $error) { |
|
17 | + echo '<p class="wpinv_error" id="wpinv_error_' . $error_id . '"><strong>' . __('Error', 'invoicing') . '</strong>: ' . $error . '</p>'; |
|
18 | 18 | } |
19 | 19 | echo '</div>'; |
20 | 20 | wpinv_clear_errors(); |
21 | 21 | } |
22 | 22 | } |
23 | -add_action( 'wpinv_purchase_form_before_submit', 'wpinv_print_errors' ); |
|
24 | -add_action( 'wpinv_ajax_checkout_errors', 'wpinv_print_errors' ); |
|
23 | +add_action('wpinv_purchase_form_before_submit', 'wpinv_print_errors'); |
|
24 | +add_action('wpinv_ajax_checkout_errors', 'wpinv_print_errors'); |
|
25 | 25 | |
26 | 26 | function wpinv_get_errors() { |
27 | 27 | global $wpi_session; |
28 | 28 | |
29 | - return $wpi_session->get( 'wpinv_errors' ); |
|
29 | + return $wpi_session->get('wpinv_errors'); |
|
30 | 30 | } |
31 | 31 | |
32 | -function wpinv_set_error( $error_id, $error_message ) { |
|
32 | +function wpinv_set_error($error_id, $error_message) { |
|
33 | 33 | global $wpi_session; |
34 | 34 | |
35 | 35 | $errors = wpinv_get_errors(); |
36 | 36 | |
37 | - if ( ! $errors ) { |
|
37 | + if (!$errors) { |
|
38 | 38 | $errors = array(); |
39 | 39 | } |
40 | 40 | |
41 | - $errors[ $error_id ] = $error_message; |
|
42 | - $wpi_session->set( 'wpinv_errors', $errors ); |
|
41 | + $errors[$error_id] = $error_message; |
|
42 | + $wpi_session->set('wpinv_errors', $errors); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | function wpinv_clear_errors() { |
46 | 46 | global $wpi_session; |
47 | 47 | |
48 | - $wpi_session->set( 'wpinv_errors', null ); |
|
48 | + $wpi_session->set('wpinv_errors', null); |
|
49 | 49 | } |
50 | 50 | |
51 | -function wpinv_unset_error( $error_id ) { |
|
51 | +function wpinv_unset_error($error_id) { |
|
52 | 52 | global $wpi_session; |
53 | 53 | |
54 | 54 | $errors = wpinv_get_errors(); |
55 | 55 | |
56 | - if ( $errors ) { |
|
57 | - unset( $errors[ $error_id ] ); |
|
58 | - $wpi_session->set( 'wpinv_errors', $errors ); |
|
56 | + if ($errors) { |
|
57 | + unset($errors[$error_id]); |
|
58 | + $wpi_session->set('wpinv_errors', $errors); |
|
59 | 59 | } |
60 | 60 | } |
61 | 61 | |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | die(); |
64 | 64 | } |
65 | 65 | |
66 | -function wpinv_die( $message = '', $title = '', $status = 400 ) { |
|
67 | - add_filter( 'wp_die_ajax_handler', 'wpinv_die_handler', 10, 3 ); |
|
68 | - add_filter( 'wp_die_handler', 'wpinv_die_handler', 10, 3 ); |
|
69 | - wp_die( $message, $title, array( 'response' => $status )); |
|
66 | +function wpinv_die($message = '', $title = '', $status = 400) { |
|
67 | + add_filter('wp_die_ajax_handler', 'wpinv_die_handler', 10, 3); |
|
68 | + add_filter('wp_die_handler', 'wpinv_die_handler', 10, 3); |
|
69 | + wp_die($message, $title, array('response' => $status)); |
|
70 | 70 | } |
@@ -7,206 +7,206 @@ 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 | function wpinv_get_payment_gateways() { |
15 | 15 | // Default, built-in gateways |
16 | 16 | $gateways = array( |
17 | 17 | 'paypal' => array( |
18 | - 'admin_label' => __( 'PayPal Standard', 'invoicing' ), |
|
19 | - 'checkout_label' => __( 'PayPal Standard', 'invoicing' ), |
|
18 | + 'admin_label' => __('PayPal Standard', 'invoicing'), |
|
19 | + 'checkout_label' => __('PayPal Standard', 'invoicing'), |
|
20 | 20 | 'ordering' => 1, |
21 | 21 | ), |
22 | 22 | 'authorizenet' => array( |
23 | - 'admin_label' => __( 'Authorize.Net (AIM)', 'invoicing' ), |
|
24 | - 'checkout_label' => __( 'Authorize.Net - Credit Card / Debit Card', 'invoicing' ), |
|
23 | + 'admin_label' => __('Authorize.Net (AIM)', 'invoicing'), |
|
24 | + 'checkout_label' => __('Authorize.Net - Credit Card / Debit Card', 'invoicing'), |
|
25 | 25 | 'ordering' => 4, |
26 | 26 | ), |
27 | 27 | 'worldpay' => array( |
28 | - 'admin_label' => __( 'Worldpay', 'invoicing' ), |
|
29 | - 'checkout_label' => __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ), |
|
28 | + 'admin_label' => __('Worldpay', 'invoicing'), |
|
29 | + 'checkout_label' => __('Worldpay - Credit Card / Debit Card', 'invoicing'), |
|
30 | 30 | 'ordering' => 5, |
31 | 31 | ), |
32 | 32 | 'bank_transfer' => array( |
33 | - 'admin_label' => __( 'Pre Bank Transfer', 'invoicing' ), |
|
34 | - 'checkout_label' => __( 'Pre Bank Transfer', 'invoicing' ), |
|
33 | + 'admin_label' => __('Pre Bank Transfer', 'invoicing'), |
|
34 | + 'checkout_label' => __('Pre Bank Transfer', 'invoicing'), |
|
35 | 35 | 'ordering' => 11, |
36 | 36 | ), |
37 | 37 | 'manual' => array( |
38 | - 'admin_label' => __( 'Test Payment', 'invoicing' ), |
|
39 | - 'checkout_label' => __( 'Test Payment', 'invoicing' ), |
|
38 | + 'admin_label' => __('Test Payment', 'invoicing'), |
|
39 | + 'checkout_label' => __('Test Payment', 'invoicing'), |
|
40 | 40 | 'ordering' => 12, |
41 | 41 | ), |
42 | 42 | ); |
43 | 43 | |
44 | - return apply_filters( 'wpinv_payment_gateways', $gateways ); |
|
44 | + return apply_filters('wpinv_payment_gateways', $gateways); |
|
45 | 45 | } |
46 | 46 | |
47 | -function wpinv_payment_gateway_titles( $all_gateways ) { |
|
47 | +function wpinv_payment_gateway_titles($all_gateways) { |
|
48 | 48 | global $wpinv_options; |
49 | 49 | |
50 | 50 | $gateways = array(); |
51 | - foreach ( $all_gateways as $key => $gateway ) { |
|
52 | - if ( !empty( $wpinv_options[$key . '_title'] ) ) { |
|
53 | - $all_gateways[$key]['checkout_label'] = __( $wpinv_options[$key . '_title'], 'invoicing' ); |
|
51 | + foreach ($all_gateways as $key => $gateway) { |
|
52 | + if (!empty($wpinv_options[$key . '_title'])) { |
|
53 | + $all_gateways[$key]['checkout_label'] = __($wpinv_options[$key . '_title'], 'invoicing'); |
|
54 | 54 | } |
55 | 55 | |
56 | - $gateways[$key] = isset( $wpinv_options[$key . '_ordering'] ) ? $wpinv_options[$key . '_ordering'] : ( isset( $gateway['ordering'] ) ? $gateway['ordering'] : '' ); |
|
56 | + $gateways[$key] = isset($wpinv_options[$key . '_ordering']) ? $wpinv_options[$key . '_ordering'] : (isset($gateway['ordering']) ? $gateway['ordering'] : ''); |
|
57 | 57 | } |
58 | 58 | |
59 | - asort( $gateways ); |
|
59 | + asort($gateways); |
|
60 | 60 | |
61 | - foreach ( $gateways as $gateway => $key ) { |
|
61 | + foreach ($gateways as $gateway => $key) { |
|
62 | 62 | $gateways[$gateway] = $all_gateways[$gateway]; |
63 | 63 | } |
64 | 64 | |
65 | 65 | return $gateways; |
66 | 66 | } |
67 | -add_filter( 'wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1 ); |
|
67 | +add_filter('wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1); |
|
68 | 68 | |
69 | -function wpinv_get_enabled_payment_gateways( $sort = false ) { |
|
69 | +function wpinv_get_enabled_payment_gateways($sort = false) { |
|
70 | 70 | $gateways = wpinv_get_payment_gateways(); |
71 | - $enabled = wpinv_get_option( 'gateways', false ); |
|
71 | + $enabled = wpinv_get_option('gateways', false); |
|
72 | 72 | |
73 | 73 | $gateway_list = array(); |
74 | 74 | |
75 | - foreach ( $gateways as $key => $gateway ) { |
|
76 | - if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) { |
|
77 | - $gateway_list[ $key ] = $gateway; |
|
75 | + foreach ($gateways as $key => $gateway) { |
|
76 | + if (isset($enabled[$key]) && $enabled[$key] == 1) { |
|
77 | + $gateway_list[$key] = $gateway; |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
81 | - if ( true === $sort ) { |
|
82 | - uasort( $gateway_list, 'wpinv_sort_gateway_order' ); |
|
81 | + if (true === $sort) { |
|
82 | + uasort($gateway_list, 'wpinv_sort_gateway_order'); |
|
83 | 83 | |
84 | 84 | // Reorder our gateways so the default is first |
85 | 85 | $default_gateway_id = wpinv_get_default_gateway(); |
86 | 86 | |
87 | - if ( wpinv_is_gateway_active( $default_gateway_id ) ) { |
|
88 | - $default_gateway = array( $default_gateway_id => $gateway_list[ $default_gateway_id ] ); |
|
89 | - unset( $gateway_list[ $default_gateway_id ] ); |
|
87 | + if (wpinv_is_gateway_active($default_gateway_id)) { |
|
88 | + $default_gateway = array($default_gateway_id => $gateway_list[$default_gateway_id]); |
|
89 | + unset($gateway_list[$default_gateway_id]); |
|
90 | 90 | |
91 | - $gateway_list = array_merge( $default_gateway, $gateway_list ); |
|
91 | + $gateway_list = array_merge($default_gateway, $gateway_list); |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
95 | - return apply_filters( 'wpinv_enabled_payment_gateways', $gateway_list ); |
|
95 | + return apply_filters('wpinv_enabled_payment_gateways', $gateway_list); |
|
96 | 96 | } |
97 | 97 | |
98 | -function wpinv_sort_gateway_order( $a, $b ) { |
|
98 | +function wpinv_sort_gateway_order($a, $b) { |
|
99 | 99 | return $a['ordering'] - $b['ordering']; |
100 | 100 | } |
101 | 101 | |
102 | -function wpinv_is_gateway_active( $gateway ) { |
|
102 | +function wpinv_is_gateway_active($gateway) { |
|
103 | 103 | $gateways = wpinv_get_enabled_payment_gateways(); |
104 | 104 | |
105 | - $ret = is_array($gateways) && $gateway ? array_key_exists( $gateway, $gateways ) : false; |
|
105 | + $ret = is_array($gateways) && $gateway ? array_key_exists($gateway, $gateways) : false; |
|
106 | 106 | |
107 | - return apply_filters( 'wpinv_is_gateway_active', $ret, $gateway, $gateways ); |
|
107 | + return apply_filters('wpinv_is_gateway_active', $ret, $gateway, $gateways); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | function wpinv_get_default_gateway() { |
111 | - $default = wpinv_get_option( 'default_gateway', 'paypal' ); |
|
111 | + $default = wpinv_get_option('default_gateway', 'paypal'); |
|
112 | 112 | |
113 | - if ( !wpinv_is_gateway_active( $default ) ) { |
|
113 | + if (!wpinv_is_gateway_active($default)) { |
|
114 | 114 | $gateways = wpinv_get_enabled_payment_gateways(); |
115 | - $gateways = array_keys( $gateways ); |
|
116 | - $default = reset( $gateways ); |
|
115 | + $gateways = array_keys($gateways); |
|
116 | + $default = reset($gateways); |
|
117 | 117 | } |
118 | 118 | |
119 | - return apply_filters( 'wpinv_default_gateway', $default ); |
|
119 | + return apply_filters('wpinv_default_gateway', $default); |
|
120 | 120 | } |
121 | 121 | |
122 | -function wpinv_get_gateway_admin_label( $gateway ) { |
|
122 | +function wpinv_get_gateway_admin_label($gateway) { |
|
123 | 123 | $gateways = wpinv_get_payment_gateways(); |
124 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway; |
|
125 | - $payment = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : false; |
|
124 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway; |
|
125 | + $payment = isset($_GET['id']) ? absint($_GET['id']) : false; |
|
126 | 126 | |
127 | - if( $gateway == 'manual' && $payment ) { |
|
128 | - if( wpinv_get_payment_amount( $payment ) == 0 ) { |
|
129 | - $label = __( 'Manual Payment', 'invoicing' ); |
|
127 | + if ($gateway == 'manual' && $payment) { |
|
128 | + if (wpinv_get_payment_amount($payment) == 0) { |
|
129 | + $label = __('Manual Payment', 'invoicing'); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
133 | - return apply_filters( 'wpinv_gateway_admin_label', $label, $gateway ); |
|
133 | + return apply_filters('wpinv_gateway_admin_label', $label, $gateway); |
|
134 | 134 | } |
135 | 135 | |
136 | -function wpinv_get_gateway_description( $gateway ) { |
|
136 | +function wpinv_get_gateway_description($gateway) { |
|
137 | 137 | global $wpinv_options; |
138 | 138 | |
139 | - $description = isset( $wpinv_options[$gateway . '_desc'] ) ? $wpinv_options[$gateway . '_desc'] : ''; |
|
139 | + $description = isset($wpinv_options[$gateway . '_desc']) ? $wpinv_options[$gateway . '_desc'] : ''; |
|
140 | 140 | |
141 | - return apply_filters( 'wpinv_gateway_description', $description, $gateway ); |
|
141 | + return apply_filters('wpinv_gateway_description', $description, $gateway); |
|
142 | 142 | } |
143 | 143 | |
144 | -function wpinv_get_gateway_button_label( $gateway ) { |
|
145 | - return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' ); |
|
144 | +function wpinv_get_gateway_button_label($gateway) { |
|
145 | + return apply_filters('wpinv_gateway_' . $gateway . '_button_label', ''); |
|
146 | 146 | } |
147 | 147 | |
148 | -function wpinv_get_gateway_checkout_label( $gateway ) { |
|
148 | +function wpinv_get_gateway_checkout_label($gateway) { |
|
149 | 149 | $gateways = wpinv_get_payment_gateways(); |
150 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway; |
|
150 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway; |
|
151 | 151 | |
152 | - if( $gateway == 'manual' ) { |
|
153 | - $label = __( 'Manual Payment', 'invoicing' ); |
|
152 | + if ($gateway == 'manual') { |
|
153 | + $label = __('Manual Payment', 'invoicing'); |
|
154 | 154 | } |
155 | 155 | |
156 | - return apply_filters( 'wpinv_gateway_checkout_label', $label, $gateway ); |
|
156 | + return apply_filters('wpinv_gateway_checkout_label', $label, $gateway); |
|
157 | 157 | } |
158 | 158 | |
159 | -function wpinv_settings_sections_gateways( $settings ) { |
|
159 | +function wpinv_settings_sections_gateways($settings) { |
|
160 | 160 | $gateways = wpinv_get_payment_gateways(); |
161 | 161 | |
162 | 162 | if (!empty($gateways)) { |
163 | - foreach ($gateways as $key => $gateway) { |
|
163 | + foreach ($gateways as $key => $gateway) { |
|
164 | 164 | $settings[$key] = $gateway['admin_label']; |
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
168 | 168 | return $settings; |
169 | 169 | } |
170 | -add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 ); |
|
170 | +add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1); |
|
171 | 171 | |
172 | -function wpinv_settings_gateways( $settings ) { |
|
172 | +function wpinv_settings_gateways($settings) { |
|
173 | 173 | $gateways = wpinv_get_payment_gateways(); |
174 | 174 | |
175 | 175 | if (!empty($gateways)) { |
176 | - foreach ($gateways as $key => $gateway) { |
|
176 | + foreach ($gateways as $key => $gateway) { |
|
177 | 177 | $setting = array(); |
178 | 178 | $setting[$key . '_header'] = array( |
179 | 179 | 'id' => 'gateway_header', |
180 | - 'name' => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>', |
|
180 | + 'name' => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>', |
|
181 | 181 | 'custom' => $key, |
182 | 182 | 'type' => 'gateway_header', |
183 | 183 | ); |
184 | 184 | $setting[$key . '_active'] = array( |
185 | 185 | 'id' => $key . '_active', |
186 | - 'name' => __( 'Active', 'invoicing' ), |
|
187 | - 'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ), |
|
186 | + 'name' => __('Active', 'invoicing'), |
|
187 | + 'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']), |
|
188 | 188 | 'type' => 'checkbox', |
189 | 189 | ); |
190 | 190 | |
191 | 191 | $setting[$key . '_title'] = array( |
192 | 192 | 'id' => $key . '_title', |
193 | - 'name' => __( 'Title', 'invoicing' ), |
|
194 | - 'desc' => __( 'This controls the title which the user sees during checkout.', 'invoicing' ), |
|
193 | + 'name' => __('Title', 'invoicing'), |
|
194 | + 'desc' => __('This controls the title which the user sees during checkout.', 'invoicing'), |
|
195 | 195 | 'type' => 'text', |
196 | 196 | 'std' => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : '' |
197 | 197 | ); |
198 | 198 | |
199 | 199 | $setting[$key . '_desc'] = array( |
200 | 200 | 'id' => $key . '_desc', |
201 | - 'name' => __( 'Description', 'invoicing' ), |
|
202 | - 'desc' => __( 'This controls the description which the user sees during checkout.', 'invoicing' ), |
|
201 | + 'name' => __('Description', 'invoicing'), |
|
202 | + 'desc' => __('This controls the description which the user sees during checkout.', 'invoicing'), |
|
203 | 203 | 'type' => 'text', |
204 | 204 | 'size' => 'large' |
205 | 205 | ); |
206 | 206 | |
207 | 207 | $setting[$key . '_ordering'] = array( |
208 | 208 | 'id' => $key . '_ordering', |
209 | - 'name' => __( 'Display Order', 'invoicing' ), |
|
209 | + 'name' => __('Display Order', 'invoicing'), |
|
210 | 210 | 'type' => 'number', |
211 | 211 | 'size' => 'small', |
212 | 212 | 'std' => isset($gateway['ordering']) ? $gateway['ordering'] : '10', |
@@ -215,8 +215,8 @@ discard block |
||
215 | 215 | 'step' => '1' |
216 | 216 | ); |
217 | 217 | |
218 | - $setting = apply_filters( 'wpinv_gateway_settings', $setting, $key ); |
|
219 | - $setting = apply_filters( 'wpinv_gateway_settings_' . $key, $setting ); |
|
218 | + $setting = apply_filters('wpinv_gateway_settings', $setting, $key); |
|
219 | + $setting = apply_filters('wpinv_gateway_settings_' . $key, $setting); |
|
220 | 220 | |
221 | 221 | $settings[$key] = $setting; |
222 | 222 | } |
@@ -224,106 +224,106 @@ discard block |
||
224 | 224 | |
225 | 225 | return $settings; |
226 | 226 | } |
227 | -add_filter( 'wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1 ); |
|
227 | +add_filter('wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1); |
|
228 | 228 | |
229 | -function wpinv_gateway_header_callback( $args ) { |
|
230 | - echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr( $args['custom'] ) . '" />'; |
|
229 | +function wpinv_gateway_header_callback($args) { |
|
230 | + echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr($args['custom']) . '" />'; |
|
231 | 231 | } |
232 | 232 | |
233 | -function wpinv_get_gateway_supports( $gateway ) { |
|
233 | +function wpinv_get_gateway_supports($gateway) { |
|
234 | 234 | $gateways = wpinv_get_enabled_payment_gateways(); |
235 | - $supports = isset( $gateways[ $gateway ]['supports'] ) ? $gateways[ $gateway ]['supports'] : array(); |
|
236 | - return apply_filters( 'wpinv_gateway_supports', $supports, $gateway ); |
|
235 | + $supports = isset($gateways[$gateway]['supports']) ? $gateways[$gateway]['supports'] : array(); |
|
236 | + return apply_filters('wpinv_gateway_supports', $supports, $gateway); |
|
237 | 237 | } |
238 | 238 | |
239 | -function wpinv_gateway_supports_buy_now( $gateway ) { |
|
240 | - $supports = wpinv_get_gateway_supports( $gateway ); |
|
241 | - $ret = in_array( 'buy_now', $supports ); |
|
242 | - return apply_filters( 'wpinv_gateway_supports_buy_now', $ret, $gateway ); |
|
239 | +function wpinv_gateway_supports_buy_now($gateway) { |
|
240 | + $supports = wpinv_get_gateway_supports($gateway); |
|
241 | + $ret = in_array('buy_now', $supports); |
|
242 | + return apply_filters('wpinv_gateway_supports_buy_now', $ret, $gateway); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | function wpinv_shop_supports_buy_now() { |
246 | 246 | $gateways = wpinv_get_enabled_payment_gateways(); |
247 | 247 | $ret = false; |
248 | 248 | |
249 | - if ( !wpinv_use_taxes() && $gateways ) { |
|
250 | - foreach ( $gateways as $gateway_id => $gateway ) { |
|
251 | - if ( wpinv_gateway_supports_buy_now( $gateway_id ) ) { |
|
249 | + if (!wpinv_use_taxes() && $gateways) { |
|
250 | + foreach ($gateways as $gateway_id => $gateway) { |
|
251 | + if (wpinv_gateway_supports_buy_now($gateway_id)) { |
|
252 | 252 | $ret = true; |
253 | 253 | break; |
254 | 254 | } |
255 | 255 | } |
256 | 256 | } |
257 | 257 | |
258 | - return apply_filters( 'wpinv_shop_supports_buy_now', $ret ); |
|
258 | + return apply_filters('wpinv_shop_supports_buy_now', $ret); |
|
259 | 259 | } |
260 | 260 | |
261 | -function wpinv_send_to_gateway( $gateway, $payment_data ) { |
|
262 | - $payment_data['gateway_nonce'] = wp_create_nonce( 'wpi-gateway' ); |
|
261 | +function wpinv_send_to_gateway($gateway, $payment_data) { |
|
262 | + $payment_data['gateway_nonce'] = wp_create_nonce('wpi-gateway'); |
|
263 | 263 | |
264 | 264 | // $gateway must match the ID used when registering the gateway |
265 | - do_action( 'wpinv_gateway_' . $gateway, $payment_data ); |
|
265 | + do_action('wpinv_gateway_' . $gateway, $payment_data); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | function wpinv_show_gateways() { |
269 | 269 | $gateways = wpinv_get_enabled_payment_gateways(); |
270 | 270 | $show_gateways = false; |
271 | 271 | |
272 | - $chosen_gateway = isset( $_GET['payment-mode'] ) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode'] ) : false; |
|
272 | + $chosen_gateway = isset($_GET['payment-mode']) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode']) : false; |
|
273 | 273 | |
274 | - if ( count( $gateways ) > 1 && empty( $chosen_gateway ) ) { |
|
274 | + if (count($gateways) > 1 && empty($chosen_gateway)) { |
|
275 | 275 | $show_gateways = true; |
276 | - if ( wpinv_get_cart_total() <= 0 ) { |
|
276 | + if (wpinv_get_cart_total() <= 0) { |
|
277 | 277 | $show_gateways = false; |
278 | 278 | } |
279 | 279 | } |
280 | 280 | |
281 | - if ( !$show_gateways && wpinv_cart_has_recurring_item() ) { |
|
281 | + if (!$show_gateways && wpinv_cart_has_recurring_item()) { |
|
282 | 282 | $show_gateways = true; |
283 | 283 | } |
284 | 284 | |
285 | - return apply_filters( 'wpinv_show_gateways', $show_gateways ); |
|
285 | + return apply_filters('wpinv_show_gateways', $show_gateways); |
|
286 | 286 | } |
287 | 287 | |
288 | -function wpinv_get_chosen_gateway( $invoice_id = 0 ) { |
|
289 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
288 | +function wpinv_get_chosen_gateway($invoice_id = 0) { |
|
289 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
290 | 290 | |
291 | 291 | $chosen = false; |
292 | - if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
292 | + if ($invoice_id > 0 && $invoice = wpinv_get_invoice($invoice_id)) { |
|
293 | 293 | $chosen = $invoice->get_gateway(); |
294 | 294 | } |
295 | 295 | |
296 | - $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
296 | + $chosen = isset($_REQUEST['payment-mode']) ? sanitize_text_field($_REQUEST['payment-mode']) : $chosen; |
|
297 | 297 | |
298 | - if ( false !== $chosen ) { |
|
299 | - $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
298 | + if (false !== $chosen) { |
|
299 | + $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen); |
|
300 | 300 | } |
301 | 301 | |
302 | - if ( ! empty ( $chosen ) ) { |
|
303 | - $enabled_gateway = urldecode( $chosen ); |
|
304 | - } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
302 | + if (!empty ($chosen)) { |
|
303 | + $enabled_gateway = urldecode($chosen); |
|
304 | + } else if (!empty($invoice) && (float)$invoice->get_subtotal() <= 0) { |
|
305 | 305 | $enabled_gateway = 'manual'; |
306 | 306 | } else { |
307 | 307 | $enabled_gateway = wpinv_get_default_gateway(); |
308 | 308 | } |
309 | 309 | |
310 | - if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) { |
|
311 | - if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){ |
|
310 | + if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) { |
|
311 | + if (wpinv_is_gateway_active(wpinv_get_default_gateway())) { |
|
312 | 312 | $enabled_gateway = wpinv_get_default_gateway(); |
313 | - }else{ |
|
313 | + } else { |
|
314 | 314 | $enabled_gateway = $gateways[0]; |
315 | 315 | } |
316 | 316 | |
317 | 317 | } |
318 | 318 | |
319 | - return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
319 | + return apply_filters('wpinv_chosen_gateway', $enabled_gateway); |
|
320 | 320 | } |
321 | 321 | |
322 | -function wpinv_record_gateway_error( $title = '', $message = '', $parent = 0 ) { |
|
323 | - return wpinv_error_log( $message, $title ); |
|
322 | +function wpinv_record_gateway_error($title = '', $message = '', $parent = 0) { |
|
323 | + return wpinv_error_log($message, $title); |
|
324 | 324 | } |
325 | 325 | |
326 | -function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) { |
|
326 | +function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') { |
|
327 | 327 | $ret = 0; |
328 | 328 | $args = array( |
329 | 329 | 'meta_key' => '_wpinv_gateway', |
@@ -334,48 +334,48 @@ discard block |
||
334 | 334 | 'fields' => 'ids' |
335 | 335 | ); |
336 | 336 | |
337 | - $payments = new WP_Query( $args ); |
|
337 | + $payments = new WP_Query($args); |
|
338 | 338 | |
339 | - if( $payments ) |
|
339 | + if ($payments) |
|
340 | 340 | $ret = $payments->post_count; |
341 | 341 | return $ret; |
342 | 342 | } |
343 | 343 | |
344 | -function wpinv_settings_update_gateways( $input ) { |
|
344 | +function wpinv_settings_update_gateways($input) { |
|
345 | 345 | global $wpinv_options; |
346 | 346 | |
347 | - if ( !empty( $input['save_gateway'] ) ) { |
|
348 | - $gateways = wpinv_get_option( 'gateways', false ); |
|
347 | + if (!empty($input['save_gateway'])) { |
|
348 | + $gateways = wpinv_get_option('gateways', false); |
|
349 | 349 | $gateways = !empty($gateways) ? $gateways : array(); |
350 | 350 | $gateway = $input['save_gateway']; |
351 | 351 | |
352 | - if ( !empty( $input[$gateway . '_active'] ) ) { |
|
352 | + if (!empty($input[$gateway . '_active'])) { |
|
353 | 353 | $gateways[$gateway] = 1; |
354 | 354 | } else { |
355 | - if ( isset( $gateways[$gateway] ) ) { |
|
356 | - unset( $gateways[$gateway] ); |
|
355 | + if (isset($gateways[$gateway])) { |
|
356 | + unset($gateways[$gateway]); |
|
357 | 357 | } |
358 | 358 | } |
359 | 359 | |
360 | 360 | $input['gateways'] = $gateways; |
361 | 361 | } |
362 | 362 | |
363 | - if ( !empty( $input['default_gateway'] ) ) { |
|
363 | + if (!empty($input['default_gateway'])) { |
|
364 | 364 | $gateways = wpinv_get_payment_gateways(); |
365 | 365 | |
366 | - foreach ( $gateways as $key => $gateway ) { |
|
367 | - $active = 0; |
|
368 | - if ( !empty( $input['gateways'] ) && !empty( $input['gateways'][$key] ) ) { |
|
366 | + foreach ($gateways as $key => $gateway) { |
|
367 | + $active = 0; |
|
368 | + if (!empty($input['gateways']) && !empty($input['gateways'][$key])) { |
|
369 | 369 | $active = 1; |
370 | 370 | } |
371 | 371 | |
372 | 372 | $input[$key . '_active'] = $active; |
373 | 373 | |
374 | - if ( empty( $wpinv_options[$key . '_title'] ) ) { |
|
374 | + if (empty($wpinv_options[$key . '_title'])) { |
|
375 | 375 | $input[$key . '_title'] = $gateway['checkout_label']; |
376 | 376 | } |
377 | 377 | |
378 | - if ( !isset( $wpinv_options[$key . '_ordering'] ) && isset( $gateway['ordering'] ) ) { |
|
378 | + if (!isset($wpinv_options[$key . '_ordering']) && isset($gateway['ordering'])) { |
|
379 | 379 | $input[$key . '_ordering'] = $gateway['ordering']; |
380 | 380 | } |
381 | 381 | } |
@@ -383,26 +383,26 @@ discard block |
||
383 | 383 | |
384 | 384 | return $input; |
385 | 385 | } |
386 | -add_filter( 'wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1 ); |
|
386 | +add_filter('wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1); |
|
387 | 387 | |
388 | 388 | // PayPal Standard settings |
389 | -function wpinv_gateway_settings_paypal( $setting ) { |
|
390 | - $setting['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
|
389 | +function wpinv_gateway_settings_paypal($setting) { |
|
390 | + $setting['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing'); |
|
391 | 391 | |
392 | 392 | $setting['paypal_sandbox'] = array( |
393 | 393 | 'type' => 'checkbox', |
394 | 394 | 'id' => 'paypal_sandbox', |
395 | - 'name' => __( 'PayPal Sandbox', 'invoicing' ), |
|
396 | - 'desc' => __( 'PayPal sandbox can be used to test payments.', 'invoicing' ), |
|
395 | + 'name' => __('PayPal Sandbox', 'invoicing'), |
|
396 | + 'desc' => __('PayPal sandbox can be used to test payments.', 'invoicing'), |
|
397 | 397 | 'std' => 1 |
398 | 398 | ); |
399 | 399 | |
400 | 400 | $setting['paypal_email'] = array( |
401 | 401 | 'type' => 'text', |
402 | 402 | 'id' => 'paypal_email', |
403 | - 'name' => __( 'PayPal Email', 'invoicing' ), |
|
404 | - 'desc' => __( 'Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing' ), |
|
405 | - 'std' => __( '[email protected]', 'invoicing' ), |
|
403 | + 'name' => __('PayPal Email', 'invoicing'), |
|
404 | + 'desc' => __('Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing'), |
|
405 | + 'std' => __('[email protected]', 'invoicing'), |
|
406 | 406 | ); |
407 | 407 | /* |
408 | 408 | $setting['paypal_ipn_url'] = array( |
@@ -416,116 +416,116 @@ discard block |
||
416 | 416 | |
417 | 417 | return $setting; |
418 | 418 | } |
419 | -add_filter( 'wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1 ); |
|
419 | +add_filter('wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1); |
|
420 | 420 | |
421 | 421 | // Pre Bank Transfer settings |
422 | -function wpinv_gateway_settings_bank_transfer( $setting ) { |
|
423 | - $setting['bank_transfer_desc']['std'] = __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' ); |
|
422 | +function wpinv_gateway_settings_bank_transfer($setting) { |
|
423 | + $setting['bank_transfer_desc']['std'] = __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing'); |
|
424 | 424 | |
425 | 425 | $setting['bank_transfer_ac_name'] = array( |
426 | 426 | 'type' => 'text', |
427 | 427 | 'id' => 'bank_transfer_ac_name', |
428 | - 'name' => __( 'Account Name', 'invoicing' ), |
|
429 | - 'desc' => __( 'Enter the bank account name to which you want to transfer payment.', 'invoicing' ), |
|
430 | - 'std' => __( 'Mr. John Martin', 'invoicing' ), |
|
428 | + 'name' => __('Account Name', 'invoicing'), |
|
429 | + 'desc' => __('Enter the bank account name to which you want to transfer payment.', 'invoicing'), |
|
430 | + 'std' => __('Mr. John Martin', 'invoicing'), |
|
431 | 431 | ); |
432 | 432 | |
433 | 433 | $setting['bank_transfer_ac_no'] = array( |
434 | 434 | 'type' => 'text', |
435 | 435 | 'id' => 'bank_transfer_ac_no', |
436 | - 'name' => __( 'Account Number', 'invoicing' ), |
|
437 | - 'desc' => __( 'Enter your bank account number.', 'invoicing' ), |
|
438 | - 'std' => __( 'TEST1234567890', 'invoicing' ), |
|
436 | + 'name' => __('Account Number', 'invoicing'), |
|
437 | + 'desc' => __('Enter your bank account number.', 'invoicing'), |
|
438 | + 'std' => __('TEST1234567890', 'invoicing'), |
|
439 | 439 | ); |
440 | 440 | |
441 | 441 | $setting['bank_transfer_bank_name'] = array( |
442 | 442 | 'type' => 'text', |
443 | 443 | 'id' => 'bank_transfer_bank_name', |
444 | - 'name' => __( 'Bank Name', 'invoicing' ), |
|
445 | - 'desc' => __( 'Enter the bank name to which you want to transfer payment.', 'invoicing' ), |
|
446 | - 'std' => __( 'ICICI Bank', 'invoicing' ), |
|
444 | + 'name' => __('Bank Name', 'invoicing'), |
|
445 | + 'desc' => __('Enter the bank name to which you want to transfer payment.', 'invoicing'), |
|
446 | + 'std' => __('ICICI Bank', 'invoicing'), |
|
447 | 447 | ); |
448 | 448 | |
449 | 449 | $setting['bank_transfer_ifsc'] = array( |
450 | 450 | 'type' => 'text', |
451 | 451 | 'id' => 'bank_transfer_ifsc', |
452 | - 'name' => __( 'IFSC code', 'invoicing' ), |
|
453 | - 'desc' => __( 'Enter your bank IFSC code.', 'invoicing' ), |
|
454 | - 'std' => __( 'ICIC0001234', 'invoicing' ), |
|
452 | + 'name' => __('IFSC code', 'invoicing'), |
|
453 | + 'desc' => __('Enter your bank IFSC code.', 'invoicing'), |
|
454 | + 'std' => __('ICIC0001234', 'invoicing'), |
|
455 | 455 | ); |
456 | 456 | |
457 | 457 | $setting['bank_transfer_iban'] = array( |
458 | 458 | 'type' => 'text', |
459 | 459 | 'id' => 'bank_transfer_iban', |
460 | - 'name' => __( 'IBAN', 'invoicing' ), |
|
461 | - 'desc' => __( 'Enter your International Bank Account Number(IBAN).', 'invoicing' ), |
|
462 | - 'std' => __( 'GB29NWBK60161331926819', 'invoicing' ), |
|
460 | + 'name' => __('IBAN', 'invoicing'), |
|
461 | + 'desc' => __('Enter your International Bank Account Number(IBAN).', 'invoicing'), |
|
462 | + 'std' => __('GB29NWBK60161331926819', 'invoicing'), |
|
463 | 463 | ); |
464 | 464 | |
465 | 465 | $setting['bank_transfer_bic'] = array( |
466 | 466 | 'type' => 'text', |
467 | 467 | 'id' => 'bank_transfer_bic', |
468 | - 'name' => __( 'BIC/Swift code', 'invoicing' ), |
|
469 | - 'std' => __( 'ICICGB2L129', 'invoicing' ), |
|
468 | + 'name' => __('BIC/Swift code', 'invoicing'), |
|
469 | + 'std' => __('ICICGB2L129', 'invoicing'), |
|
470 | 470 | ); |
471 | 471 | |
472 | 472 | $setting['bank_transfer_info'] = array( |
473 | 473 | 'id' => 'bank_transfer_info', |
474 | - 'name' => __( 'Instructions', 'invoicing' ), |
|
475 | - 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
|
474 | + 'name' => __('Instructions', 'invoicing'), |
|
475 | + 'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'), |
|
476 | 476 | 'type' => 'textarea', |
477 | - 'std' => __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' ), |
|
477 | + 'std' => __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing'), |
|
478 | 478 | 'cols' => 37, |
479 | 479 | 'rows' => 5 |
480 | 480 | ); |
481 | 481 | |
482 | 482 | return $setting; |
483 | 483 | } |
484 | -add_filter( 'wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1 ); |
|
484 | +add_filter('wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1); |
|
485 | 485 | |
486 | 486 | // Authorize.Net settings |
487 | -function wpinv_gateway_settings_authorizenet( $setting ) { |
|
488 | - $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __( '( currencies supported: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing' ); |
|
489 | - $setting['authorizenet_desc']['std'] = __( 'Pay using a Authorize.Net to process credit card / debit card transactions.', 'invoicing' ); |
|
487 | +function wpinv_gateway_settings_authorizenet($setting) { |
|
488 | + $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __('( currencies supported: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing'); |
|
489 | + $setting['authorizenet_desc']['std'] = __('Pay using a Authorize.Net to process credit card / debit card transactions.', 'invoicing'); |
|
490 | 490 | |
491 | 491 | $setting['authorizenet_sandbox'] = array( |
492 | 492 | 'type' => 'checkbox', |
493 | 493 | 'id' => 'authorizenet_sandbox', |
494 | - 'name' => __( 'Authorize.Net Test Mode', 'invoicing' ), |
|
495 | - 'desc' => __( 'Enable Authorize.Net test mode to test payments.', 'invoicing' ), |
|
494 | + 'name' => __('Authorize.Net Test Mode', 'invoicing'), |
|
495 | + 'desc' => __('Enable Authorize.Net test mode to test payments.', 'invoicing'), |
|
496 | 496 | 'std' => 1 |
497 | 497 | ); |
498 | 498 | |
499 | 499 | $setting['authorizenet_login_id'] = array( |
500 | 500 | 'type' => 'text', |
501 | 501 | 'id' => 'authorizenet_login_id', |
502 | - 'name' => __( 'API Login ID', 'invoicing' ), |
|
503 | - 'desc' => __( 'API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing' ), |
|
502 | + 'name' => __('API Login ID', 'invoicing'), |
|
503 | + 'desc' => __('API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing'), |
|
504 | 504 | 'std' => '2j4rBekUnD', |
505 | 505 | ); |
506 | 506 | |
507 | 507 | $setting['authorizenet_transaction_key'] = array( |
508 | 508 | 'type' => 'text', |
509 | 509 | 'id' => 'authorizenet_transaction_key', |
510 | - 'name' => __( 'Transaction Key', 'invoicing' ), |
|
511 | - 'desc' => __( 'Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing' ), |
|
510 | + 'name' => __('Transaction Key', 'invoicing'), |
|
511 | + 'desc' => __('Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing'), |
|
512 | 512 | 'std' => '4vyBUOJgR74679xa', |
513 | 513 | ); |
514 | 514 | |
515 | 515 | $setting['authorizenet_md5_hash'] = array( |
516 | 516 | 'type' => 'text', |
517 | 517 | 'id' => 'authorizenet_md5_hash', |
518 | - 'name' => __( 'MD5-Hash', 'invoicing' ), |
|
519 | - 'desc' => __( 'The MD5 Hash security feature allows you to authenticate transaction responses from the Authorize.Net. If you are accepting recurring payments then md5 hash will helps to validate response from Authorize.net. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing' ), |
|
518 | + 'name' => __('MD5-Hash', 'invoicing'), |
|
519 | + 'desc' => __('The MD5 Hash security feature allows you to authenticate transaction responses from the Authorize.Net. If you are accepting recurring payments then md5 hash will helps to validate response from Authorize.net. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing'), |
|
520 | 520 | 'std' => '', |
521 | 521 | ); |
522 | 522 | |
523 | 523 | $setting['authorizenet_ipn_url'] = array( |
524 | 524 | 'type' => 'ipn_url', |
525 | 525 | 'id' => 'authorizenet_ipn_url', |
526 | - 'name' => __( 'Silent Post URL', 'invoicing' ), |
|
527 | - 'std' => wpinv_get_ipn_url( 'authorizenet' ), |
|
528 | - 'desc' => __( 'If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing' ), |
|
526 | + 'name' => __('Silent Post URL', 'invoicing'), |
|
527 | + 'std' => wpinv_get_ipn_url('authorizenet'), |
|
528 | + 'desc' => __('If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing'), |
|
529 | 529 | 'size' => 'large', |
530 | 530 | 'custom' => 'authorizenet', |
531 | 531 | 'readonly' => true |
@@ -533,25 +533,25 @@ discard block |
||
533 | 533 | |
534 | 534 | return $setting; |
535 | 535 | } |
536 | -add_filter( 'wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1 ); |
|
536 | +add_filter('wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1); |
|
537 | 537 | |
538 | 538 | // Worldpay settings |
539 | -function wpinv_gateway_settings_worldpay( $setting ) { |
|
540 | - $setting['worldpay_desc']['std'] = __( 'Pay using a Worldpay account to process credit card / debit card transactions.', 'invoicing' ); |
|
539 | +function wpinv_gateway_settings_worldpay($setting) { |
|
540 | + $setting['worldpay_desc']['std'] = __('Pay using a Worldpay account to process credit card / debit card transactions.', 'invoicing'); |
|
541 | 541 | |
542 | 542 | $setting['worldpay_sandbox'] = array( |
543 | 543 | 'type' => 'checkbox', |
544 | 544 | 'id' => 'worldpay_sandbox', |
545 | - 'name' => __( 'Worldpay Test Mode', 'invoicing' ), |
|
546 | - 'desc' => __( 'This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing' ), |
|
545 | + 'name' => __('Worldpay Test Mode', 'invoicing'), |
|
546 | + 'desc' => __('This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing'), |
|
547 | 547 | 'std' => 1 |
548 | 548 | ); |
549 | 549 | |
550 | 550 | $setting['worldpay_instId'] = array( |
551 | 551 | 'type' => 'text', |
552 | 552 | 'id' => 'worldpay_instId', |
553 | - 'name' => __( 'Installation Id', 'invoicing' ), |
|
554 | - 'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ), |
|
553 | + 'name' => __('Installation Id', 'invoicing'), |
|
554 | + 'desc' => __('Your installation id. Ex: 211616', 'invoicing'), |
|
555 | 555 | 'std' => '211616', |
556 | 556 | ); |
557 | 557 | /* |
@@ -567,9 +567,9 @@ discard block |
||
567 | 567 | $setting['worldpay_ipn_url'] = array( |
568 | 568 | 'type' => 'ipn_url', |
569 | 569 | 'id' => 'worldpay_ipn_url', |
570 | - 'name' => __( 'Worldpay Callback Url', 'invoicing' ), |
|
571 | - 'std' => wpinv_get_ipn_url( 'worldpay' ), |
|
572 | - 'desc' => wp_sprintf( __( 'Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing' ), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url( 'worldpay' ) . '</font>', '<font style="color:#000;font-style:normal"><wpdisplay item=MC_callback></font>' ), |
|
570 | + 'name' => __('Worldpay Callback Url', 'invoicing'), |
|
571 | + 'std' => wpinv_get_ipn_url('worldpay'), |
|
572 | + 'desc' => wp_sprintf(__('Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing'), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url('worldpay') . '</font>', '<font style="color:#000;font-style:normal"><wpdisplay item=MC_callback></font>'), |
|
573 | 573 | 'size' => 'large', |
574 | 574 | 'custom' => 'worldpay', |
575 | 575 | 'readonly' => true |
@@ -577,95 +577,95 @@ discard block |
||
577 | 577 | |
578 | 578 | return $setting; |
579 | 579 | } |
580 | -add_filter( 'wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1 ); |
|
580 | +add_filter('wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1); |
|
581 | 581 | |
582 | -function wpinv_ipn_url_callback( $args ) { |
|
583 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
582 | +function wpinv_ipn_url_callback($args) { |
|
583 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
584 | 584 | |
585 | 585 | $attrs = $args['readonly'] ? ' readonly' : ''; |
586 | 586 | |
587 | - $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr( $args['std'] ) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">'; |
|
588 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>'; |
|
587 | + $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr($args['std']) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">'; |
|
588 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>'; |
|
589 | 589 | |
590 | 590 | echo $html; |
591 | 591 | } |
592 | 592 | |
593 | -function wpinv_is_test_mode( $gateway = '' ) { |
|
594 | - if ( empty( $gateway ) ) { |
|
593 | +function wpinv_is_test_mode($gateway = '') { |
|
594 | + if (empty($gateway)) { |
|
595 | 595 | return false; |
596 | 596 | } |
597 | 597 | |
598 | - $is_test_mode = wpinv_get_option( $gateway . '_sandbox', false ); |
|
598 | + $is_test_mode = wpinv_get_option($gateway . '_sandbox', false); |
|
599 | 599 | |
600 | - return apply_filters( 'wpinv_is_test_mode', $is_test_mode, $gateway ); |
|
600 | + return apply_filters('wpinv_is_test_mode', $is_test_mode, $gateway); |
|
601 | 601 | } |
602 | 602 | |
603 | -function wpinv_get_ipn_url( $gateway = '', $args = array() ) { |
|
604 | - $data = array( 'wpi-listener' => 'IPN' ); |
|
603 | +function wpinv_get_ipn_url($gateway = '', $args = array()) { |
|
604 | + $data = array('wpi-listener' => 'IPN'); |
|
605 | 605 | |
606 | - if ( !empty( $gateway ) ) { |
|
607 | - $data['wpi-gateway'] = wpinv_sanitize_key( $gateway ); |
|
606 | + if (!empty($gateway)) { |
|
607 | + $data['wpi-gateway'] = wpinv_sanitize_key($gateway); |
|
608 | 608 | } |
609 | 609 | |
610 | - $args = !empty( $args ) && is_array( $args ) ? array_merge( $data, $args ) : $data; |
|
610 | + $args = !empty($args) && is_array($args) ? array_merge($data, $args) : $data; |
|
611 | 611 | |
612 | - $ipn_url = add_query_arg( $args, home_url( 'index.php' ) ); |
|
612 | + $ipn_url = add_query_arg($args, home_url('index.php')); |
|
613 | 613 | |
614 | - return apply_filters( 'wpinv_ipn_url', $ipn_url ); |
|
614 | + return apply_filters('wpinv_ipn_url', $ipn_url); |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | function wpinv_listen_for_payment_ipn() { |
618 | 618 | // Regular PayPal IPN |
619 | - if ( isset( $_GET['wpi-listener'] ) && $_GET['wpi-listener'] == 'IPN' ) { |
|
620 | - do_action( 'wpinv_verify_payment_ipn' ); |
|
619 | + if (isset($_GET['wpi-listener']) && $_GET['wpi-listener'] == 'IPN') { |
|
620 | + do_action('wpinv_verify_payment_ipn'); |
|
621 | 621 | |
622 | - if ( !empty( $_GET['wpi-gateway'] ) ) { |
|
623 | - wpinv_error_log( sanitize_text_field( $_GET['wpi-gateway'] ), 'wpinv_listen_for_payment_ipn()', __FILE__, __LINE__ ); |
|
624 | - do_action( 'wpinv_verify_' . sanitize_text_field( $_GET['wpi-gateway'] ) . '_ipn' ); |
|
622 | + if (!empty($_GET['wpi-gateway'])) { |
|
623 | + wpinv_error_log(sanitize_text_field($_GET['wpi-gateway']), 'wpinv_listen_for_payment_ipn()', __FILE__, __LINE__); |
|
624 | + do_action('wpinv_verify_' . sanitize_text_field($_GET['wpi-gateway']) . '_ipn'); |
|
625 | 625 | } |
626 | 626 | } |
627 | 627 | } |
628 | -add_action( 'init', 'wpinv_listen_for_payment_ipn' ); |
|
628 | +add_action('init', 'wpinv_listen_for_payment_ipn'); |
|
629 | 629 | |
630 | 630 | function wpinv_get_bank_instructions() { |
631 | - $bank_instructions = wpinv_get_option( 'bank_transfer_info' ); |
|
631 | + $bank_instructions = wpinv_get_option('bank_transfer_info'); |
|
632 | 632 | |
633 | - return apply_filters( 'wpinv_bank_instructions', $bank_instructions ); |
|
633 | + return apply_filters('wpinv_bank_instructions', $bank_instructions); |
|
634 | 634 | } |
635 | 635 | |
636 | -function wpinv_get_bank_info( $filtered = false ) { |
|
636 | +function wpinv_get_bank_info($filtered = false) { |
|
637 | 637 | $bank_fields = array( |
638 | - 'bank_transfer_ac_name' => __( 'Account Name', 'invoicing' ), |
|
639 | - 'bank_transfer_ac_no' => __( 'Account Number', 'invoicing' ), |
|
640 | - 'bank_transfer_bank_name' => __( 'Bank Name', 'invoicing' ), |
|
641 | - 'bank_transfer_ifsc' => __( 'IFSC code', 'invoicing' ), |
|
642 | - 'bank_transfer_iban' => __( 'IBAN', 'invoicing' ), |
|
643 | - 'bank_transfer_bic' => __( 'BIC/Swift code', 'invoicing' ) |
|
638 | + 'bank_transfer_ac_name' => __('Account Name', 'invoicing'), |
|
639 | + 'bank_transfer_ac_no' => __('Account Number', 'invoicing'), |
|
640 | + 'bank_transfer_bank_name' => __('Bank Name', 'invoicing'), |
|
641 | + 'bank_transfer_ifsc' => __('IFSC code', 'invoicing'), |
|
642 | + 'bank_transfer_iban' => __('IBAN', 'invoicing'), |
|
643 | + 'bank_transfer_bic' => __('BIC/Swift code', 'invoicing') |
|
644 | 644 | ); |
645 | 645 | |
646 | 646 | $bank_info = array(); |
647 | - foreach ( $bank_fields as $field => $label ) { |
|
648 | - if ( $filtered && !( $value = wpinv_get_option( $field ) ) ) { |
|
647 | + foreach ($bank_fields as $field => $label) { |
|
648 | + if ($filtered && !($value = wpinv_get_option($field))) { |
|
649 | 649 | continue; |
650 | 650 | } |
651 | 651 | |
652 | - $bank_info[$field] = array( 'label' => $label, 'value' => $value ); |
|
652 | + $bank_info[$field] = array('label' => $label, 'value' => $value); |
|
653 | 653 | } |
654 | 654 | |
655 | - return apply_filters( 'wpinv_bank_info', $bank_info, $filtered ); |
|
655 | + return apply_filters('wpinv_bank_info', $bank_info, $filtered); |
|
656 | 656 | } |
657 | 657 | |
658 | -function wpinv_process_before_send_to_gateway( $invoice, $invoice_data = array() ) { |
|
659 | - if ( !empty( $invoice ) && $invoice->is_recurring() && $subscription_item = $invoice->get_recurring( true ) ) { |
|
658 | +function wpinv_process_before_send_to_gateway($invoice, $invoice_data = array()) { |
|
659 | + if (!empty($invoice) && $invoice->is_recurring() && $subscription_item = $invoice->get_recurring(true)) { |
|
660 | 660 | $args = array(); |
661 | 661 | $args['item_id'] = $subscription_item->ID; |
662 | - $args['initial_amount'] = wpinv_format_amount( $invoice->get_total() ); |
|
663 | - $args['recurring_amount'] = wpinv_format_amount( $invoice->get_recurring_details( 'total' ) ); |
|
662 | + $args['initial_amount'] = wpinv_format_amount($invoice->get_total()); |
|
663 | + $args['recurring_amount'] = wpinv_format_amount($invoice->get_recurring_details('total')); |
|
664 | 664 | $args['currency'] = $invoice->get_currency(); |
665 | - $args['period'] = $subscription_item->get_recurring_period( true ); |
|
665 | + $args['period'] = $subscription_item->get_recurring_period(true); |
|
666 | 666 | $args['interval'] = $subscription_item->get_recurring_interval(); |
667 | - if ( $subscription_item->has_free_trial() ) { |
|
668 | - $args['trial_period'] = $subscription_item->get_trial_period( true ); |
|
667 | + if ($subscription_item->has_free_trial()) { |
|
668 | + $args['trial_period'] = $subscription_item->get_trial_period(true); |
|
669 | 669 | $args['trial_interval'] = $subscription_item->get_trial_interval(); |
670 | 670 | } else { |
671 | 671 | $args['trial_period'] = ''; |
@@ -673,25 +673,25 @@ discard block |
||
673 | 673 | } |
674 | 674 | $args['bill_times'] = (int)$subscription_item->get_recurring_limit(); |
675 | 675 | |
676 | - $invoice->update_subscription( $args ); |
|
676 | + $invoice->update_subscription($args); |
|
677 | 677 | } |
678 | 678 | } |
679 | -add_action( 'wpinv_checkout_before_send_to_gateway', 'wpinv_process_before_send_to_gateway', 10, 2 ); |
|
679 | +add_action('wpinv_checkout_before_send_to_gateway', 'wpinv_process_before_send_to_gateway', 10, 2); |
|
680 | 680 | |
681 | -function wpinv_get_post_data( $method = 'request' ) { |
|
681 | +function wpinv_get_post_data($method = 'request') { |
|
682 | 682 | $data = array(); |
683 | 683 | $request = $_REQUEST; |
684 | 684 | |
685 | - if ( $method == 'post' ) { |
|
686 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
685 | + if ($method == 'post') { |
|
686 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') { |
|
687 | 687 | return $data; |
688 | 688 | } |
689 | 689 | |
690 | 690 | $request = $_POST; |
691 | 691 | } |
692 | 692 | |
693 | - if ( $method == 'get' ) { |
|
694 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'GET' ) { |
|
693 | + if ($method == 'get') { |
|
694 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'GET') { |
|
695 | 695 | return $data; |
696 | 696 | } |
697 | 697 | |
@@ -702,11 +702,11 @@ discard block |
||
702 | 702 | $post_data = ''; |
703 | 703 | |
704 | 704 | // Fallback just in case post_max_size is lower than needed |
705 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
706 | - $post_data = file_get_contents( 'php://input' ); |
|
705 | + if (ini_get('allow_url_fopen')) { |
|
706 | + $post_data = file_get_contents('php://input'); |
|
707 | 707 | } else { |
708 | 708 | // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
709 | - ini_set( 'post_max_size', '12M' ); |
|
709 | + ini_set('post_max_size', '12M'); |
|
710 | 710 | } |
711 | 711 | // Start the encoded data collection with notification command |
712 | 712 | $encoded_data = 'cmd=_notify-validate'; |
@@ -715,58 +715,58 @@ discard block |
||
715 | 715 | $arg_separator = wpinv_get_php_arg_separator_output(); |
716 | 716 | |
717 | 717 | // Verify there is a post_data |
718 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
718 | + if ($post_data || strlen($post_data) > 0) { |
|
719 | 719 | // Append the data |
720 | 720 | $encoded_data .= $arg_separator . $post_data; |
721 | 721 | } else { |
722 | 722 | // Check if POST is empty |
723 | - if ( empty( $request ) ) { |
|
723 | + if (empty($request)) { |
|
724 | 724 | // Nothing to do |
725 | 725 | return; |
726 | 726 | } else { |
727 | 727 | // Loop through each POST |
728 | - foreach ( $request as $key => $value ) { |
|
728 | + foreach ($request as $key => $value) { |
|
729 | 729 | // Encode the value and append the data |
730 | - $encoded_data .= $arg_separator . "$key=" . urlencode( $value ); |
|
730 | + $encoded_data .= $arg_separator . "$key=" . urlencode($value); |
|
731 | 731 | } |
732 | 732 | } |
733 | 733 | } |
734 | 734 | |
735 | 735 | // Convert collected post data to an array |
736 | - parse_str( $encoded_data, $data ); |
|
736 | + parse_str($encoded_data, $data); |
|
737 | 737 | |
738 | - foreach ( $data as $key => $value ) { |
|
739 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
740 | - $new_key = str_replace( '&', '&', $key ); |
|
741 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
738 | + foreach ($data as $key => $value) { |
|
739 | + if (false !== strpos($key, 'amp;')) { |
|
740 | + $new_key = str_replace('&', '&', $key); |
|
741 | + $new_key = str_replace('amp;', '&', $new_key); |
|
742 | 742 | |
743 | - unset( $data[ $key ] ); |
|
744 | - $data[ $new_key ] = sanitize_text_field( $value ); |
|
743 | + unset($data[$key]); |
|
744 | + $data[$new_key] = sanitize_text_field($value); |
|
745 | 745 | } |
746 | 746 | } |
747 | 747 | |
748 | 748 | return $data; |
749 | 749 | } |
750 | 750 | |
751 | -function wpinv_gateway_support_subscription( $gateway ) { |
|
751 | +function wpinv_gateway_support_subscription($gateway) { |
|
752 | 752 | $return = false; |
753 | 753 | |
754 | - if ( wpinv_is_gateway_active( $gateway ) ) { |
|
755 | - $return = apply_filters( 'wpinv_' . $gateway . '_support_subscription', false ); |
|
754 | + if (wpinv_is_gateway_active($gateway)) { |
|
755 | + $return = apply_filters('wpinv_' . $gateway . '_support_subscription', false); |
|
756 | 756 | } |
757 | 757 | |
758 | 758 | return $return; |
759 | 759 | } |
760 | 760 | |
761 | -function wpinv_payment_gateways_on_cart( $gateways = array() ) { |
|
762 | - if ( !empty( $gateways ) && wpinv_cart_has_recurring_item() ) { |
|
763 | - foreach ( $gateways as $gateway => $info ) { |
|
764 | - if ( !wpinv_gateway_support_subscription( $gateway ) ) { |
|
765 | - unset( $gateways[$gateway] ); |
|
761 | +function wpinv_payment_gateways_on_cart($gateways = array()) { |
|
762 | + if (!empty($gateways) && wpinv_cart_has_recurring_item()) { |
|
763 | + foreach ($gateways as $gateway => $info) { |
|
764 | + if (!wpinv_gateway_support_subscription($gateway)) { |
|
765 | + unset($gateways[$gateway]); |
|
766 | 766 | } |
767 | 767 | } |
768 | 768 | } |
769 | 769 | |
770 | 770 | return $gateways; |
771 | 771 | } |
772 | -add_filter( 'wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1 ); |
|
773 | 772 | \ No newline at end of file |
773 | +add_filter('wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1); |
|
774 | 774 | \ No newline at end of file |
@@ -7,22 +7,22 @@ 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_API { |
15 | 15 | protected $post_type = 'wpi_invoice'; |
16 | 16 | |
17 | - public function __construct( $params = array() ) { |
|
17 | + public function __construct($params = array()) { |
|
18 | 18 | } |
19 | - public function insert_invoice( $data ) { |
|
19 | + public function insert_invoice($data) { |
|
20 | 20 | global $wpdb; |
21 | 21 | //wpinv_transaction_query( 'start' ); |
22 | 22 | |
23 | 23 | try { |
24 | - if ( ! isset( $data['invoice'] ) ) { |
|
25 | - throw new WPInv_API_Exception( 'wpinv_api_missing_invoice_data', sprintf( __( 'No %1$s data specified to create %1$s', 'invoicing' ), 'invoice' ), 400 ); |
|
24 | + if (!isset($data['invoice'])) { |
|
25 | + throw new WPInv_API_Exception('wpinv_api_missing_invoice_data', sprintf(__('No %1$s data specified to create %1$s', 'invoicing'), 'invoice'), 400); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | $data = $data['invoice']; |
@@ -32,37 +32,37 @@ discard block |
||
32 | 32 | //throw new WPInv_API_Exception( 'wpinv_api_user_cannot_create_invoice', __( 'You do not have permission to create invoices', 'invoicing' ), 401 ); |
33 | 33 | //} |
34 | 34 | |
35 | - $data = apply_filters( 'wpinv_api_create_invoice_data', $data, $this ); |
|
35 | + $data = apply_filters('wpinv_api_create_invoice_data', $data, $this); |
|
36 | 36 | |
37 | - $invoice = wpinv_insert_invoice( $data ); |
|
38 | - if ( is_wp_error( $invoice ) ) { |
|
39 | - throw new WPInv_API_Exception( 'wpinv_api_cannot_create_invoice', sprintf( __( 'Cannot create invoice: %s', 'invoicing' ), implode( ', ', $invoice->get_error_messages() ) ), 400 ); |
|
37 | + $invoice = wpinv_insert_invoice($data); |
|
38 | + if (is_wp_error($invoice)) { |
|
39 | + throw new WPInv_API_Exception('wpinv_api_cannot_create_invoice', sprintf(__('Cannot create invoice: %s', 'invoicing'), implode(', ', $invoice->get_error_messages())), 400); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | // HTTP 201 Created |
43 | - $this->send_status( 201 ); |
|
43 | + $this->send_status(201); |
|
44 | 44 | |
45 | - do_action( 'wpinv_api_create_invoice', $invoice->ID, $data, $this ); |
|
45 | + do_action('wpinv_api_create_invoice', $invoice->ID, $data, $this); |
|
46 | 46 | |
47 | 47 | //wpinv_transaction_query( 'commit' ); |
48 | 48 | |
49 | - return wpinv_get_invoice( $invoice->ID ); |
|
49 | + return wpinv_get_invoice($invoice->ID); |
|
50 | 50 | |
51 | - } catch ( WPInv_API_Exception $e ) { |
|
51 | + } catch (WPInv_API_Exception $e) { |
|
52 | 52 | |
53 | 53 | //wpinv_transaction_query( 'rollback' ); |
54 | 54 | |
55 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
55 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
59 | - public function create_invoice( $data ) { |
|
59 | + public function create_invoice($data) { |
|
60 | 60 | global $wpdb; |
61 | 61 | //wpinv_transaction_query( 'start' ); |
62 | 62 | |
63 | 63 | try { |
64 | - if ( ! isset( $data['invoice'] ) ) { |
|
65 | - throw new WPInv_API_Exception( 'wpinv_api_missing_invoice_data', sprintf( __( 'No %1$s data specified to create %1$s', 'invoicing' ), 'invoice' ), 400 ); |
|
64 | + if (!isset($data['invoice'])) { |
|
65 | + throw new WPInv_API_Exception('wpinv_api_missing_invoice_data', sprintf(__('No %1$s data specified to create %1$s', 'invoicing'), 'invoice'), 400); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | $data = $data['invoice']; |
@@ -72,111 +72,111 @@ discard block |
||
72 | 72 | //throw new WPInv_API_Exception( 'wpinv_api_user_cannot_create_invoice', __( 'You do not have permission to create invoices', 'invoicing' ), 401 ); |
73 | 73 | //} |
74 | 74 | |
75 | - $data = apply_filters( 'wpinv_api_create_invoice_data', $data, $this ); |
|
75 | + $data = apply_filters('wpinv_api_create_invoice_data', $data, $this); |
|
76 | 76 | |
77 | 77 | // default invoice args, note that status is checked for validity in wpinv_create_invoice() |
78 | 78 | $default_invoice_args = array( |
79 | - 'status' => isset( $data['status'] ) ? $data['status'] : '', |
|
80 | - 'user_note' => isset( $data['note'] ) ? $data['note'] : null, |
|
81 | - 'invoice_id' => isset( $data['invoice_id'] ) ? (int)$data['invoice_id'] : 0, |
|
79 | + 'status' => isset($data['status']) ? $data['status'] : '', |
|
80 | + 'user_note' => isset($data['note']) ? $data['note'] : null, |
|
81 | + 'invoice_id' => isset($data['invoice_id']) ? (int)$data['invoice_id'] : 0, |
|
82 | 82 | ); |
83 | 83 | |
84 | 84 | // if creating invoice for existing user |
85 | - if ( ! empty( $data['user_id'] ) ) { |
|
85 | + if (!empty($data['user_id'])) { |
|
86 | 86 | // make sure user exists |
87 | - if ( false === get_user_by( 'id', $data['user_id'] ) ) { |
|
88 | - throw new WPInv_API_Exception( 'wpinv_api_invalid_user_id', __( 'User ID is invalid', 'invoicing' ), 400 ); |
|
87 | + if (false === get_user_by('id', $data['user_id'])) { |
|
88 | + throw new WPInv_API_Exception('wpinv_api_invalid_user_id', __('User ID is invalid', 'invoicing'), 400); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | $default_invoice_args['user_id'] = $data['user_id']; |
92 | 92 | } |
93 | 93 | |
94 | 94 | // create the pending invoice |
95 | - $invoice = $this->create_base_invoice( $default_invoice_args, $data ); |
|
95 | + $invoice = $this->create_base_invoice($default_invoice_args, $data); |
|
96 | 96 | |
97 | - if ( is_wp_error( $invoice ) ) { |
|
98 | - throw new WPInv_API_Exception( 'wpinv_api_cannot_create_invoice', sprintf( __( 'Cannot create invoice: %s', 'invoicing' ), implode( ', ', $invoice->get_error_messages() ) ), 400 ); |
|
97 | + if (is_wp_error($invoice)) { |
|
98 | + throw new WPInv_API_Exception('wpinv_api_cannot_create_invoice', sprintf(__('Cannot create invoice: %s', 'invoicing'), implode(', ', $invoice->get_error_messages())), 400); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | // Add note |
102 | - if ( !empty( $data['user_note'] ) ) { |
|
103 | - $invoice->add_note( $data['user_note'], true ); |
|
102 | + if (!empty($data['user_note'])) { |
|
103 | + $invoice->add_note($data['user_note'], true); |
|
104 | 104 | } |
105 | 105 | |
106 | - if ( !empty( $data['private_note'] ) ) { |
|
107 | - $invoice->add_note( $data['private_note'] ); |
|
106 | + if (!empty($data['private_note'])) { |
|
107 | + $invoice->add_note($data['private_note']); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | // billing address |
111 | - $invoice = $this->set_billing_details( $invoice, $data ); |
|
111 | + $invoice = $this->set_billing_details($invoice, $data); |
|
112 | 112 | |
113 | 113 | // items |
114 | - $invoice = $this->set_discount( $invoice, $data ); |
|
114 | + $invoice = $this->set_discount($invoice, $data); |
|
115 | 115 | |
116 | 116 | // items |
117 | - $invoice = $this->set_items( $invoice, $data ); |
|
117 | + $invoice = $this->set_items($invoice, $data); |
|
118 | 118 | |
119 | 119 | // payment method (and payment_complete() if `paid` == true) |
120 | - if ( isset( $data['payment_details'] ) && is_array( $data['payment_details'] ) ) { |
|
120 | + if (isset($data['payment_details']) && is_array($data['payment_details'])) { |
|
121 | 121 | // method ID & title are required |
122 | - if ( empty( $data['payment_details']['method_id'] ) || empty( $data['payment_details']['method_title'] ) ) { |
|
123 | - throw new WPInv_API_Exception( 'wpinv_invalid_payment_details', __( 'Payment method ID and title are required', 'invoicing' ), 400 ); |
|
122 | + if (empty($data['payment_details']['method_id']) || empty($data['payment_details']['method_title'])) { |
|
123 | + throw new WPInv_API_Exception('wpinv_invalid_payment_details', __('Payment method ID and title are required', 'invoicing'), 400); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | // set invoice currency |
127 | - if ( isset( $data['payment_details']['currency'] ) ) { |
|
128 | - if ( ! array_key_exists( $data['payment_details']['currency'], wpinv_get_currencies() ) ) { |
|
129 | - throw new WPInv_API_Exception( 'wpinv_invalid_invoice_currency', __( 'Provided invoice currency is invalid', 'invoicing' ), 400 ); |
|
127 | + if (isset($data['payment_details']['currency'])) { |
|
128 | + if (!array_key_exists($data['payment_details']['currency'], wpinv_get_currencies())) { |
|
129 | + throw new WPInv_API_Exception('wpinv_invalid_invoice_currency', __('Provided invoice currency is invalid', 'invoicing'), 400); |
|
130 | 130 | } |
131 | 131 | |
132 | - update_post_meta( $invoice->ID, '_wpinv_currency', $data['payment_details']['currency'] ); |
|
132 | + update_post_meta($invoice->ID, '_wpinv_currency', $data['payment_details']['currency']); |
|
133 | 133 | |
134 | 134 | $invoice->currency = $data['payment_details']['currency']; |
135 | 135 | } |
136 | 136 | |
137 | - update_post_meta( $invoice->ID, '_wpinv_gateway', $data['payment_details']['method_id'] ); |
|
138 | - update_post_meta( $invoice->ID, '_wpinv_gateway_title', $data['payment_details']['method_title'] ); |
|
137 | + update_post_meta($invoice->ID, '_wpinv_gateway', $data['payment_details']['method_id']); |
|
138 | + update_post_meta($invoice->ID, '_wpinv_gateway_title', $data['payment_details']['method_title']); |
|
139 | 139 | |
140 | 140 | $invoice->gateway = $data['payment_details']['method_id']; |
141 | 141 | $invoice->gateway_title = $data['payment_details']['method_title']; |
142 | 142 | |
143 | 143 | // mark as paid if set |
144 | - if ( isset( $data['payment_details']['paid'] ) && true === $data['payment_details']['paid'] ) { |
|
144 | + if (isset($data['payment_details']['paid']) && true === $data['payment_details']['paid']) { |
|
145 | 145 | //$invoice->payment_complete( isset( $data['payment_details']['transaction_id'] ) ? $data['payment_details']['transaction_id'] : $invoice->ID ); |
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
149 | 149 | // set invoice meta |
150 | - if ( isset( $data['invoice_meta'] ) && is_array( $data['invoice_meta'] ) ) { |
|
151 | - $this->set_invoice_meta( $invoice->ID, $data['invoice_meta'] ); |
|
150 | + if (isset($data['invoice_meta']) && is_array($data['invoice_meta'])) { |
|
151 | + $this->set_invoice_meta($invoice->ID, $data['invoice_meta']); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | // HTTP 201 Created |
155 | - $this->send_status( 201 ); |
|
155 | + $this->send_status(201); |
|
156 | 156 | |
157 | - do_action( 'wpinv_api_create_invoice', $invoice->ID, $data, $this ); |
|
157 | + do_action('wpinv_api_create_invoice', $invoice->ID, $data, $this); |
|
158 | 158 | |
159 | 159 | //wpinv_transaction_query( 'commit' ); |
160 | 160 | |
161 | - return wpinv_get_invoice( $invoice->ID ); |
|
161 | + return wpinv_get_invoice($invoice->ID); |
|
162 | 162 | |
163 | - } catch ( WPInv_API_Exception $e ) { |
|
163 | + } catch (WPInv_API_Exception $e) { |
|
164 | 164 | |
165 | 165 | //wpinv_transaction_query( 'rollback' ); |
166 | 166 | |
167 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
167 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
171 | - public function send_status( $code ) { |
|
172 | - status_header( $code ); |
|
171 | + public function send_status($code) { |
|
172 | + status_header($code); |
|
173 | 173 | } |
174 | 174 | |
175 | - protected function create_base_invoice( $args, $data ) { |
|
176 | - return wpinv_create_invoice( $args, $data ); |
|
175 | + protected function create_base_invoice($args, $data) { |
|
176 | + return wpinv_create_invoice($args, $data); |
|
177 | 177 | } |
178 | 178 | |
179 | - protected function set_billing_details( $invoice, $data ) { |
|
179 | + protected function set_billing_details($invoice, $data) { |
|
180 | 180 | $address_fields = array( |
181 | 181 | 'user_id', |
182 | 182 | 'first_name', |
@@ -195,66 +195,66 @@ discard block |
||
195 | 195 | $billing_details = array(); |
196 | 196 | $user_id = $invoice->get_user_id(); |
197 | 197 | |
198 | - foreach ( $address_fields as $field ) { |
|
199 | - if ( isset( $data['billing_details'][ $field ] ) ) { |
|
200 | - $value = sanitize_text_field( $data['billing_details'][ $field ] ); |
|
198 | + foreach ($address_fields as $field) { |
|
199 | + if (isset($data['billing_details'][$field])) { |
|
200 | + $value = sanitize_text_field($data['billing_details'][$field]); |
|
201 | 201 | |
202 | - if ( $field == 'country' && empty( $value ) ) { |
|
203 | - if ( !empty( $invoice->country ) ) { |
|
202 | + if ($field == 'country' && empty($value)) { |
|
203 | + if (!empty($invoice->country)) { |
|
204 | 204 | $value = $invoice->country; |
205 | 205 | } else { |
206 | - $value = wpinv_default_billing_country( '', $user_id ); |
|
206 | + $value = wpinv_default_billing_country('', $user_id); |
|
207 | 207 | } |
208 | 208 | } |
209 | 209 | |
210 | - if ( $field == 'state' && empty( $value ) ) { |
|
211 | - if ( !empty( $invoice->state ) ) { |
|
210 | + if ($field == 'state' && empty($value)) { |
|
211 | + if (!empty($invoice->state)) { |
|
212 | 212 | $value = $invoice->state; |
213 | 213 | } else { |
214 | 214 | $value = wpinv_get_default_state(); |
215 | 215 | } |
216 | 216 | } |
217 | 217 | |
218 | - $invoice->set( $field, $value ); |
|
218 | + $invoice->set($field, $value); |
|
219 | 219 | |
220 | - update_post_meta( $invoice->ID, '_wpinv_' . $field, $value ); |
|
220 | + update_post_meta($invoice->ID, '_wpinv_' . $field, $value); |
|
221 | 221 | } |
222 | 222 | } |
223 | 223 | |
224 | 224 | return $invoice; |
225 | 225 | } |
226 | 226 | |
227 | - protected function set_discount( $invoice, $data ) { |
|
228 | - if ( isset( $data['discount'] ) ) { |
|
229 | - $invoice->set( 'discount', wpinv_format_amount( $data['discount'], NULL, true ) ); |
|
227 | + protected function set_discount($invoice, $data) { |
|
228 | + if (isset($data['discount'])) { |
|
229 | + $invoice->set('discount', wpinv_format_amount($data['discount'], NULL, true)); |
|
230 | 230 | |
231 | - update_post_meta( $invoice->ID, '_wpinv_discount', wpinv_format_amount( $data['discount'], NULL, true ) ); |
|
231 | + update_post_meta($invoice->ID, '_wpinv_discount', wpinv_format_amount($data['discount'], NULL, true)); |
|
232 | 232 | |
233 | - if ( isset( $data['discount_code'] ) ) { |
|
234 | - $invoice->set( 'discount_code', $data['discount_code'] ); |
|
233 | + if (isset($data['discount_code'])) { |
|
234 | + $invoice->set('discount_code', $data['discount_code']); |
|
235 | 235 | |
236 | - update_post_meta( $invoice->ID, '_wpinv_discount_code', $data['discount_code'] ); |
|
236 | + update_post_meta($invoice->ID, '_wpinv_discount_code', $data['discount_code']); |
|
237 | 237 | } |
238 | 238 | } |
239 | 239 | |
240 | 240 | return $invoice; |
241 | 241 | } |
242 | 242 | |
243 | - protected function set_items( $invoice, $data ) { |
|
244 | - if ( !empty( $data['items'] ) && is_array( $data['items'] ) ) { |
|
243 | + protected function set_items($invoice, $data) { |
|
244 | + if (!empty($data['items']) && is_array($data['items'])) { |
|
245 | 245 | $items_array = array(); |
246 | 246 | |
247 | - if ( !empty( $invoice->country ) ) { |
|
247 | + if (!empty($invoice->country)) { |
|
248 | 248 | $country = $invoice->country; |
249 | - } else if ( !empty( $data['billing_details']['country'] ) ) { |
|
249 | + } else if (!empty($data['billing_details']['country'])) { |
|
250 | 250 | $country = $data['billing_details']['country']; |
251 | 251 | } else { |
252 | - $country = wpinv_default_billing_country( '', $invoice->get_user_id() ); |
|
252 | + $country = wpinv_default_billing_country('', $invoice->get_user_id()); |
|
253 | 253 | } |
254 | 254 | |
255 | - if ( !empty( $invoice->state ) ) { |
|
255 | + if (!empty($invoice->state)) { |
|
256 | 256 | $state = $invoice->state; |
257 | - } else if ( !empty( $data['billing_details']['state'] ) ) { |
|
257 | + } else if (!empty($data['billing_details']['state'])) { |
|
258 | 258 | $state = $data['billing_details']['state']; |
259 | 259 | } else { |
260 | 260 | $state = wpinv_get_default_state(); |
@@ -263,54 +263,54 @@ discard block |
||
263 | 263 | $_POST['country'] = $country; |
264 | 264 | $_POST['state'] = $state; |
265 | 265 | |
266 | - $rate = wpinv_get_tax_rate( $country, $state, 'global' ); |
|
266 | + $rate = wpinv_get_tax_rate($country, $state, 'global'); |
|
267 | 267 | |
268 | 268 | $total_tax = 0; |
269 | - foreach ( $data['items'] as $item ) { |
|
270 | - $id = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : ''; |
|
271 | - $title = isset( $item['title'] ) ? sanitize_text_field( $item['title'] ) : ''; |
|
272 | - $desc = isset( $item['description'] ) ? sanitize_text_field( $item['description'] ) : ''; |
|
273 | - $amount = isset( $item['amount'] ) ? wpinv_format_amount( $item['amount'], NULL, true ) : 0; |
|
269 | + foreach ($data['items'] as $item) { |
|
270 | + $id = isset($item['id']) ? sanitize_text_field($item['id']) : ''; |
|
271 | + $title = isset($item['title']) ? sanitize_text_field($item['title']) : ''; |
|
272 | + $desc = isset($item['description']) ? sanitize_text_field($item['description']) : ''; |
|
273 | + $amount = isset($item['amount']) ? wpinv_format_amount($item['amount'], NULL, true) : 0; |
|
274 | 274 | |
275 | - if ( !empty( $item['vat_rates_class'] ) ) { |
|
275 | + if (!empty($item['vat_rates_class'])) { |
|
276 | 276 | $vat_rates_class = $item['vat_rates_class']; |
277 | 277 | } else { |
278 | 278 | $vat_rates_class = '_standard'; |
279 | 279 | } |
280 | - $vat_rate = wpinv_get_tax_rate( $country, $state, $id ); |
|
280 | + $vat_rate = wpinv_get_tax_rate($country, $state, $id); |
|
281 | 281 | |
282 | - $tax = $amount > 0 ? ( $amount * 0.01 * (float)$vat_rate ) : 0; |
|
282 | + $tax = $amount > 0 ? ($amount * 0.01 * (float)$vat_rate) : 0; |
|
283 | 283 | $total_tax += $tax; |
284 | 284 | |
285 | 285 | $items_array[] = array( |
286 | 286 | 'id' => $id, |
287 | - 'title' => esc_html( $title ), |
|
288 | - 'description' => esc_html( $desc ), |
|
289 | - 'amount' => $amount > 0 ? wpinv_format_amount( $amount, NULL, true ) : 0, |
|
290 | - 'subtotal' => $amount > 0 ? wpinv_format_amount( $amount, NULL, true ) : 0, |
|
287 | + 'title' => esc_html($title), |
|
288 | + 'description' => esc_html($desc), |
|
289 | + 'amount' => $amount > 0 ? wpinv_format_amount($amount, NULL, true) : 0, |
|
290 | + 'subtotal' => $amount > 0 ? wpinv_format_amount($amount, NULL, true) : 0, |
|
291 | 291 | 'vat_rates_class' => $vat_rates_class, |
292 | - 'vat_rate' => $vat_rate > 0 ? wpinv_format_amount( $vat_rate, NULL, true ) : 0, |
|
293 | - 'tax' => $tax > 0 ? wpinv_format_amount( $tax, NULL, true ) : 0, |
|
292 | + 'vat_rate' => $vat_rate > 0 ? wpinv_format_amount($vat_rate, NULL, true) : 0, |
|
293 | + 'tax' => $tax > 0 ? wpinv_format_amount($tax, NULL, true) : 0, |
|
294 | 294 | ); |
295 | 295 | } |
296 | 296 | |
297 | - update_post_meta( $invoice->ID, '_wpinv_tax', wpinv_format_amount( $total_tax, NULL, true ) ); |
|
298 | - $invoice->set( 'tax', wpinv_format_amount( $total_tax, NULL, true ) ); |
|
297 | + update_post_meta($invoice->ID, '_wpinv_tax', wpinv_format_amount($total_tax, NULL, true)); |
|
298 | + $invoice->set('tax', wpinv_format_amount($total_tax, NULL, true)); |
|
299 | 299 | |
300 | - $items_array = apply_filters( 'wpinv_save_invoice_items', $items_array, $data['items'], $invoice ); |
|
300 | + $items_array = apply_filters('wpinv_save_invoice_items', $items_array, $data['items'], $invoice); |
|
301 | 301 | |
302 | - $invoice->set( 'items', $items_array ); |
|
303 | - update_post_meta( $invoice->ID, '_wpinv_items', $items_array ); |
|
302 | + $invoice->set('items', $items_array); |
|
303 | + update_post_meta($invoice->ID, '_wpinv_items', $items_array); |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | return $invoice; |
307 | 307 | } |
308 | 308 | |
309 | - protected function set_invoice_meta( $invoice_id, $invoice_meta ) { |
|
310 | - foreach ( $invoice_meta as $meta_key => $meta_value ) { |
|
309 | + protected function set_invoice_meta($invoice_id, $invoice_meta) { |
|
310 | + foreach ($invoice_meta as $meta_key => $meta_value) { |
|
311 | 311 | |
312 | - if ( is_string( $meta_key) && ! is_protected_meta( $meta_key ) && is_scalar( $meta_value ) ) { |
|
313 | - update_post_meta( $invoice_id, $meta_key, $meta_value ); |
|
312 | + if (is_string($meta_key) && !is_protected_meta($meta_key) && is_scalar($meta_value)) { |
|
313 | + update_post_meta($invoice_id, $meta_key, $meta_value); |
|
314 | 314 | } |
315 | 315 | } |
316 | 316 | } |
@@ -320,9 +320,9 @@ discard block |
||
320 | 320 | class WPInv_API_Exception extends Exception { |
321 | 321 | protected $error_code; |
322 | 322 | |
323 | - public function __construct( $error_code, $error_message, $http_status_code ) { |
|
323 | + public function __construct($error_code, $error_message, $http_status_code) { |
|
324 | 324 | $this->error_code = $error_code; |
325 | - parent::__construct( $error_message, $http_status_code ); |
|
325 | + parent::__construct($error_message, $http_status_code); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | public function getErrorCode() { |
@@ -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 | - @ini_set( 'display_errors', 0 ); |
|
30 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
31 | + @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 | - @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
54 | - @header( 'X-Robots-Tag: noindex' ); |
|
53 | + @header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
54 | + @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() { |
@@ -76,39 +76,39 @@ discard block |
||
76 | 76 | 'remove_discount' => false, |
77 | 77 | ); |
78 | 78 | |
79 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
80 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
79 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
80 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
81 | 81 | |
82 | - if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) { |
|
83 | - define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 ); |
|
82 | + if (!defined('WPI_AJAX_' . strtoupper($nopriv))) { |
|
83 | + define('WPI_AJAX_' . strtoupper($nopriv), 1); |
|
84 | 84 | } |
85 | 85 | |
86 | - if ( $nopriv ) { |
|
87 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
86 | + if ($nopriv) { |
|
87 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
88 | 88 | |
89 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
89 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | 94 | public static function add_note() { |
95 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
95 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
96 | 96 | |
97 | - if ( !current_user_can( 'manage_options' ) ) { |
|
97 | + if (!current_user_can('manage_options')) { |
|
98 | 98 | die(-1); |
99 | 99 | } |
100 | 100 | |
101 | - $post_id = absint( $_POST['post_id'] ); |
|
102 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
103 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
101 | + $post_id = absint($_POST['post_id']); |
|
102 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
103 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
104 | 104 | |
105 | 105 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
106 | 106 | |
107 | - if ( $post_id > 0 ) { |
|
108 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
107 | + if ($post_id > 0) { |
|
108 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
109 | 109 | |
110 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
111 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
110 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
111 | + wpinv_get_invoice_note_line_item($note_id); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
@@ -116,16 +116,16 @@ discard block |
||
116 | 116 | } |
117 | 117 | |
118 | 118 | public static function delete_note() { |
119 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
119 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
120 | 120 | |
121 | - if ( !current_user_can( 'manage_options' ) ) { |
|
121 | + if (!current_user_can('manage_options')) { |
|
122 | 122 | die(-1); |
123 | 123 | } |
124 | 124 | |
125 | 125 | $note_id = (int)$_POST['note_id']; |
126 | 126 | |
127 | - if ( $note_id > 0 ) { |
|
128 | - wp_delete_comment( $note_id, true ); |
|
127 | + if ($note_id > 0) { |
|
128 | + wp_delete_comment($note_id, true); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | die(); |
@@ -138,8 +138,8 @@ discard block |
||
138 | 138 | } |
139 | 139 | |
140 | 140 | public static function checkout() { |
141 | - if ( ! defined( 'WPINV_CHECKOUT' ) ) { |
|
142 | - define( 'WPINV_CHECKOUT', true ); |
|
141 | + if (!defined('WPINV_CHECKOUT')) { |
|
142 | + define('WPINV_CHECKOUT', true); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | wpinv_process_checkout(); |
@@ -148,53 +148,53 @@ discard block |
||
148 | 148 | |
149 | 149 | public static function add_invoice_item() { |
150 | 150 | global $wpi_userID, $wpinv_ip_address_country; |
151 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
152 | - if ( !current_user_can( 'manage_options' ) ) { |
|
151 | + check_ajax_referer('invoice-item', '_nonce'); |
|
152 | + if (!current_user_can('manage_options')) { |
|
153 | 153 | die(-1); |
154 | 154 | } |
155 | 155 | |
156 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
157 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
156 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
157 | + $invoice_id = absint($_POST['invoice_id']); |
|
158 | 158 | |
159 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
159 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
160 | 160 | die(); |
161 | 161 | } |
162 | 162 | |
163 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
164 | - if ( empty( $invoice ) ) { |
|
163 | + $invoice = wpinv_get_invoice($invoice_id); |
|
164 | + if (empty($invoice)) { |
|
165 | 165 | die(); |
166 | 166 | } |
167 | 167 | |
168 | - if ( $invoice->is_paid() ) { |
|
168 | + if ($invoice->is_paid()) { |
|
169 | 169 | die(); // Don't allow modify items for paid invoice. |
170 | 170 | } |
171 | 171 | |
172 | - if ( !empty( $_POST['user_id'] ) ) { |
|
173 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
172 | + if (!empty($_POST['user_id'])) { |
|
173 | + $wpi_userID = absint($_POST['user_id']); |
|
174 | 174 | } |
175 | 175 | |
176 | - $item = new WPInv_Item( $item_id ); |
|
177 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
176 | + $item = new WPInv_Item($item_id); |
|
177 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
178 | 178 | die(); |
179 | 179 | } |
180 | 180 | |
181 | 181 | // Validate item before adding to invoice because recurring item must be paid individually. |
182 | - if ( !empty( $invoice->cart_details ) ) { |
|
182 | + if (!empty($invoice->cart_details)) { |
|
183 | 183 | $valid = true; |
184 | 184 | |
185 | - if ( $recurring_item = $invoice->get_recurring() ) { |
|
186 | - if ( $recurring_item != $item_id ) { |
|
185 | + if ($recurring_item = $invoice->get_recurring()) { |
|
186 | + if ($recurring_item != $item_id) { |
|
187 | 187 | $valid = false; |
188 | 188 | } |
189 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
189 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
190 | 190 | $valid = false; |
191 | 191 | } |
192 | 192 | |
193 | - if ( !$valid ) { |
|
193 | + if (!$valid) { |
|
194 | 194 | $response = array(); |
195 | 195 | $response['success'] = false; |
196 | - $response['msg'] = __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' ); |
|
197 | - wp_send_json( $response ); |
|
196 | + $response['msg'] = __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing'); |
|
197 | + wp_send_json($response); |
|
198 | 198 | } |
199 | 199 | } |
200 | 200 | |
@@ -202,9 +202,9 @@ discard block |
||
202 | 202 | |
203 | 203 | $data = array(); |
204 | 204 | $data['invoice_id'] = $invoice_id; |
205 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
205 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
206 | 206 | |
207 | - wpinv_set_checkout_session( $data ); |
|
207 | + wpinv_set_checkout_session($data); |
|
208 | 208 | |
209 | 209 | $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1; |
210 | 210 | |
@@ -218,21 +218,21 @@ discard block |
||
218 | 218 | 'fees' => array() |
219 | 219 | ); |
220 | 220 | |
221 | - $invoice->add_item( $item_id, $args ); |
|
221 | + $invoice->add_item($item_id, $args); |
|
222 | 222 | $invoice->save(); |
223 | 223 | |
224 | - if ( empty( $_POST['country'] ) ) { |
|
224 | + if (empty($_POST['country'])) { |
|
225 | 225 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
226 | 226 | } |
227 | - if ( empty( $_POST['state'] ) ) { |
|
227 | + if (empty($_POST['state'])) { |
|
228 | 228 | $_POST['state'] = $invoice->state; |
229 | 229 | } |
230 | 230 | |
231 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
232 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
231 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
232 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
233 | 233 | |
234 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
235 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
234 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
235 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
236 | 236 | |
237 | 237 | $wpinv_ip_address_country = $invoice->country; |
238 | 238 | |
@@ -240,52 +240,52 @@ discard block |
||
240 | 240 | |
241 | 241 | $response = array(); |
242 | 242 | $response['success'] = true; |
243 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
243 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
244 | 244 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
245 | 245 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
246 | 246 | $response['data']['tax'] = $invoice->get_tax(); |
247 | 247 | $response['data']['taxf'] = $invoice->get_tax(true); |
248 | 248 | $response['data']['discount'] = $invoice->discount; |
249 | - $response['data']['discountf'] = wpinv_price( $invoice->discount, $invoice->get_currency() ); |
|
249 | + $response['data']['discountf'] = wpinv_price($invoice->discount, $invoice->get_currency()); |
|
250 | 250 | $response['data']['total'] = $invoice->get_total(); |
251 | 251 | $response['data']['totalf'] = $invoice->get_total(true); |
252 | 252 | |
253 | 253 | wpinv_set_checkout_session($checkout_session); |
254 | 254 | |
255 | - wp_send_json( $response ); |
|
255 | + wp_send_json($response); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | public static function remove_invoice_item() { |
259 | 259 | global $wpi_userID, $wpinv_ip_address_country; |
260 | 260 | |
261 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
262 | - if ( !current_user_can( 'manage_options' ) ) { |
|
261 | + check_ajax_referer('invoice-item', '_nonce'); |
|
262 | + if (!current_user_can('manage_options')) { |
|
263 | 263 | die(-1); |
264 | 264 | } |
265 | 265 | |
266 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
267 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
268 | - $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
266 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
267 | + $invoice_id = absint($_POST['invoice_id']); |
|
268 | + $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
269 | 269 | |
270 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
270 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
271 | 271 | die(); |
272 | 272 | } |
273 | 273 | |
274 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
275 | - if ( empty( $invoice ) ) { |
|
274 | + $invoice = wpinv_get_invoice($invoice_id); |
|
275 | + if (empty($invoice)) { |
|
276 | 276 | die(); |
277 | 277 | } |
278 | 278 | |
279 | - if ( $invoice->is_paid() ) { |
|
279 | + if ($invoice->is_paid()) { |
|
280 | 280 | die(); // Don't allow modify items for paid invoice. |
281 | 281 | } |
282 | 282 | |
283 | - if ( !empty( $_POST['user_id'] ) ) { |
|
284 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
283 | + if (!empty($_POST['user_id'])) { |
|
284 | + $wpi_userID = absint($_POST['user_id']); |
|
285 | 285 | } |
286 | 286 | |
287 | - $item = new WPInv_Item( $item_id ); |
|
288 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
287 | + $item = new WPInv_Item($item_id); |
|
288 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
289 | 289 | die(); |
290 | 290 | } |
291 | 291 | |
@@ -293,9 +293,9 @@ discard block |
||
293 | 293 | |
294 | 294 | $data = array(); |
295 | 295 | $data['invoice_id'] = $invoice_id; |
296 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
296 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
297 | 297 | |
298 | - wpinv_set_checkout_session( $data ); |
|
298 | + wpinv_set_checkout_session($data); |
|
299 | 299 | |
300 | 300 | $args = array( |
301 | 301 | 'id' => $item_id, |
@@ -303,21 +303,21 @@ discard block |
||
303 | 303 | 'cart_index' => $cart_index |
304 | 304 | ); |
305 | 305 | |
306 | - $invoice->remove_item( $item_id, $args ); |
|
306 | + $invoice->remove_item($item_id, $args); |
|
307 | 307 | $invoice->save(); |
308 | 308 | |
309 | - if ( empty( $_POST['country'] ) ) { |
|
309 | + if (empty($_POST['country'])) { |
|
310 | 310 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
311 | 311 | } |
312 | - if ( empty( $_POST['state'] ) ) { |
|
312 | + if (empty($_POST['state'])) { |
|
313 | 313 | $_POST['state'] = $invoice->state; |
314 | 314 | } |
315 | 315 | |
316 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
317 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
316 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
317 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
318 | 318 | |
319 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
320 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
319 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
320 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
321 | 321 | |
322 | 322 | $wpinv_ip_address_country = $invoice->country; |
323 | 323 | |
@@ -325,52 +325,52 @@ discard block |
||
325 | 325 | |
326 | 326 | $response = array(); |
327 | 327 | $response['success'] = true; |
328 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
328 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
329 | 329 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
330 | 330 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
331 | 331 | $response['data']['tax'] = $invoice->get_tax(); |
332 | 332 | $response['data']['taxf'] = $invoice->get_tax(true); |
333 | 333 | $response['data']['discount'] = $invoice->discount; |
334 | - $response['data']['discountf'] = wpinv_price( $invoice->discount, $invoice->get_currency() ); |
|
334 | + $response['data']['discountf'] = wpinv_price($invoice->discount, $invoice->get_currency()); |
|
335 | 335 | $response['data']['total'] = $invoice->get_total(); |
336 | 336 | $response['data']['totalf'] = $invoice->get_total(true); |
337 | 337 | |
338 | 338 | wpinv_set_checkout_session($checkout_session); |
339 | 339 | |
340 | - wp_send_json( $response ); |
|
340 | + wp_send_json($response); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | public static function create_invoice_item() { |
344 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
345 | - if ( !current_user_can( 'manage_options' ) ) { |
|
344 | + check_ajax_referer('invoice-item', '_nonce'); |
|
345 | + if (!current_user_can('manage_options')) { |
|
346 | 346 | die(-1); |
347 | 347 | } |
348 | 348 | |
349 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
349 | + $invoice_id = absint($_POST['invoice_id']); |
|
350 | 350 | |
351 | 351 | // Find the item |
352 | - if ( !is_numeric( $invoice_id ) ) { |
|
352 | + if (!is_numeric($invoice_id)) { |
|
353 | 353 | die(); |
354 | 354 | } |
355 | 355 | |
356 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
357 | - if ( empty( $invoice ) ) { |
|
356 | + $invoice = wpinv_get_invoice($invoice_id); |
|
357 | + if (empty($invoice)) { |
|
358 | 358 | die(); |
359 | 359 | } |
360 | 360 | |
361 | 361 | // Validate item before adding to invoice because recurring item must be paid individually. |
362 | - if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) { |
|
362 | + if (!empty($invoice->cart_details) && $invoice->get_recurring()) { |
|
363 | 363 | $response = array(); |
364 | 364 | $response['success'] = false; |
365 | - $response['msg'] = __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' ); |
|
366 | - wp_send_json( $response ); |
|
365 | + $response['msg'] = __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing'); |
|
366 | + wp_send_json($response); |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | $save_item = $_POST['_wpinv_quick']; |
370 | 370 | |
371 | 371 | $meta = array(); |
372 | 372 | $meta['type'] = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom'; |
373 | - $meta['price'] = !empty($save_item['price']) ? wpinv_format_amount($save_item['price'], NULL, true ) : 0; |
|
373 | + $meta['price'] = !empty($save_item['price']) ? wpinv_format_amount($save_item['price'], NULL, true) : 0; |
|
374 | 374 | $meta['vat_rule'] = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital'; |
375 | 375 | $meta['vat_class'] = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard'; |
376 | 376 | |
@@ -380,9 +380,9 @@ discard block |
||
380 | 380 | $data['meta'] = $meta; |
381 | 381 | |
382 | 382 | $item = new WPInv_Item(); |
383 | - $item->create( $data ); |
|
383 | + $item->create($data); |
|
384 | 384 | |
385 | - if ( !empty( $item ) ) { |
|
385 | + if (!empty($item)) { |
|
386 | 386 | $_POST['item_id'] = $item->ID; |
387 | 387 | $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1; |
388 | 388 | |
@@ -392,15 +392,15 @@ discard block |
||
392 | 392 | } |
393 | 393 | |
394 | 394 | public static function get_billing_details() { |
395 | - check_ajax_referer( 'get-billing-details', '_nonce' ); |
|
395 | + check_ajax_referer('get-billing-details', '_nonce'); |
|
396 | 396 | |
397 | - if ( !current_user_can( 'manage_options' ) ) { |
|
397 | + if (!current_user_can('manage_options')) { |
|
398 | 398 | die(-1); |
399 | 399 | } |
400 | 400 | |
401 | 401 | $user_id = (int)$_POST['user_id']; |
402 | 402 | $billing_details = wpinv_get_user_address($user_id); |
403 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
403 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
404 | 404 | |
405 | 405 | if (isset($billing_details['user_id'])) { |
406 | 406 | unset($billing_details['user_id']); |
@@ -414,20 +414,20 @@ discard block |
||
414 | 414 | $response['success'] = true; |
415 | 415 | $response['data']['billing_details'] = $billing_details; |
416 | 416 | |
417 | - wp_send_json( $response ); |
|
417 | + wp_send_json($response); |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | public static function admin_recalculate_totals() { |
421 | 421 | global $wpi_userID, $wpinv_ip_address_country; |
422 | 422 | |
423 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
424 | - if ( !current_user_can( 'manage_options' ) ) { |
|
423 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
424 | + if (!current_user_can('manage_options')) { |
|
425 | 425 | die(-1); |
426 | 426 | } |
427 | 427 | |
428 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
429 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
430 | - if ( empty( $invoice ) ) { |
|
428 | + $invoice_id = absint($_POST['invoice_id']); |
|
429 | + $invoice = wpinv_get_invoice($invoice_id); |
|
430 | + if (empty($invoice)) { |
|
431 | 431 | die(); |
432 | 432 | } |
433 | 433 | |
@@ -435,23 +435,23 @@ discard block |
||
435 | 435 | |
436 | 436 | $data = array(); |
437 | 437 | $data['invoice_id'] = $invoice_id; |
438 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
438 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
439 | 439 | |
440 | - wpinv_set_checkout_session( $data ); |
|
440 | + wpinv_set_checkout_session($data); |
|
441 | 441 | |
442 | - if ( !empty( $_POST['user_id'] ) ) { |
|
443 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
442 | + if (!empty($_POST['user_id'])) { |
|
443 | + $wpi_userID = absint($_POST['user_id']); |
|
444 | 444 | } |
445 | 445 | |
446 | - if ( empty( $_POST['country'] ) ) { |
|
446 | + if (empty($_POST['country'])) { |
|
447 | 447 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
448 | 448 | } |
449 | 449 | |
450 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
451 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
452 | - if ( isset( $_POST['state'] ) ) { |
|
453 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
454 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
450 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
451 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
452 | + if (isset($_POST['state'])) { |
|
453 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
454 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | $wpinv_ip_address_country = $invoice->country; |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | |
461 | 461 | $response = array(); |
462 | 462 | $response['success'] = true; |
463 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
463 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
464 | 464 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
465 | 465 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
466 | 466 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -472,25 +472,25 @@ discard block |
||
472 | 472 | |
473 | 473 | wpinv_set_checkout_session($checkout_session); |
474 | 474 | |
475 | - wp_send_json( $response ); |
|
475 | + wp_send_json($response); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | public static function admin_apply_discount() { |
479 | 479 | global $wpi_userID; |
480 | 480 | |
481 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
482 | - if ( !current_user_can( 'manage_options' ) ) { |
|
481 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
482 | + if (!current_user_can('manage_options')) { |
|
483 | 483 | die(-1); |
484 | 484 | } |
485 | 485 | |
486 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
487 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
488 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
486 | + $invoice_id = absint($_POST['invoice_id']); |
|
487 | + $discount_code = sanitize_text_field($_POST['code']); |
|
488 | + if (empty($invoice_id) || empty($discount_code)) { |
|
489 | 489 | die(); |
490 | 490 | } |
491 | 491 | |
492 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
493 | - if ( empty( $invoice ) || ( !empty( $invoice ) && $invoice->is_paid() ) ) { |
|
492 | + $invoice = wpinv_get_invoice($invoice_id); |
|
493 | + if (empty($invoice) || (!empty($invoice) && $invoice->is_paid())) { |
|
494 | 494 | die(); |
495 | 495 | } |
496 | 496 | |
@@ -498,49 +498,49 @@ discard block |
||
498 | 498 | |
499 | 499 | $data = array(); |
500 | 500 | $data['invoice_id'] = $invoice_id; |
501 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
501 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
502 | 502 | |
503 | - wpinv_set_checkout_session( $data ); |
|
503 | + wpinv_set_checkout_session($data); |
|
504 | 504 | |
505 | 505 | $response = array(); |
506 | 506 | $response['success'] = false; |
507 | - $response['msg'] = __( 'This discount is invalid.', 'invoicing' ); |
|
507 | + $response['msg'] = __('This discount is invalid.', 'invoicing'); |
|
508 | 508 | $response['data']['code'] = $discount_code; |
509 | 509 | |
510 | - if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) { |
|
511 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
510 | + if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) { |
|
511 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
512 | 512 | |
513 | 513 | $response['success'] = true; |
514 | - $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' ); |
|
515 | - } else { |
|
514 | + $response['msg'] = __('Discount has been applied successfully.', 'invoicing'); |
|
515 | + } else { |
|
516 | 516 | $errors = wpinv_get_errors(); |
517 | - if ( !empty( $errors['wpinv-discount-error'] ) ) { |
|
517 | + if (!empty($errors['wpinv-discount-error'])) { |
|
518 | 518 | $response['msg'] = $errors['wpinv-discount-error']; |
519 | 519 | } |
520 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
520 | + wpinv_unset_error('wpinv-discount-error'); |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | wpinv_set_checkout_session($checkout_session); |
524 | 524 | |
525 | - wp_send_json( $response ); |
|
525 | + wp_send_json($response); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | public static function admin_remove_discount() { |
529 | 529 | global $wpi_userID; |
530 | 530 | |
531 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
532 | - if ( !current_user_can( 'manage_options' ) ) { |
|
531 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
532 | + if (!current_user_can('manage_options')) { |
|
533 | 533 | die(-1); |
534 | 534 | } |
535 | 535 | |
536 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
537 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
538 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
536 | + $invoice_id = absint($_POST['invoice_id']); |
|
537 | + $discount_code = sanitize_text_field($_POST['code']); |
|
538 | + if (empty($invoice_id) || empty($discount_code)) { |
|
539 | 539 | die(); |
540 | 540 | } |
541 | 541 | |
542 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
543 | - if ( empty( $invoice ) || ( !empty( $invoice ) && $invoice->is_paid() ) ) { |
|
542 | + $invoice = wpinv_get_invoice($invoice_id); |
|
543 | + if (empty($invoice) || (!empty($invoice) && $invoice->is_paid())) { |
|
544 | 544 | die(); |
545 | 545 | } |
546 | 546 | |
@@ -548,38 +548,38 @@ discard block |
||
548 | 548 | |
549 | 549 | $data = array(); |
550 | 550 | $data['invoice_id'] = $invoice_id; |
551 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
551 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
552 | 552 | |
553 | - wpinv_set_checkout_session( $data ); |
|
553 | + wpinv_set_checkout_session($data); |
|
554 | 554 | |
555 | 555 | $response = array(); |
556 | 556 | $response['success'] = false; |
557 | 557 | $response['msg'] = NULL; |
558 | 558 | |
559 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
559 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
560 | 560 | $response['success'] = true; |
561 | - $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' ); |
|
561 | + $response['msg'] = __('Discount has been removed successfully.', 'invoicing'); |
|
562 | 562 | |
563 | 563 | wpinv_set_checkout_session($checkout_session); |
564 | 564 | |
565 | - wp_send_json( $response ); |
|
565 | + wp_send_json($response); |
|
566 | 566 | } |
567 | 567 | |
568 | 568 | public static function check_email() { |
569 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
570 | - if ( !current_user_can( 'manage_options' ) ) { |
|
569 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
570 | + if (!current_user_can('manage_options')) { |
|
571 | 571 | die(-1); |
572 | 572 | } |
573 | 573 | |
574 | - $email = sanitize_text_field( $_POST['email'] ); |
|
574 | + $email = sanitize_text_field($_POST['email']); |
|
575 | 575 | |
576 | 576 | $response = array(); |
577 | - if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) { |
|
577 | + if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) { |
|
578 | 578 | $user_id = $user_data->ID; |
579 | 579 | $user_login = $user_data->user_login; |
580 | 580 | $display_name = $user_data->display_name ? $user_data->display_name : $user_login; |
581 | 581 | $billing_details = wpinv_get_user_address($user_id); |
582 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
582 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
583 | 583 | |
584 | 584 | if (isset($billing_details['user_id'])) { |
585 | 585 | unset($billing_details['user_id']); |
@@ -595,31 +595,31 @@ discard block |
||
595 | 595 | $response['data']['billing_details'] = $billing_details; |
596 | 596 | } |
597 | 597 | |
598 | - wp_send_json( $response ); |
|
598 | + wp_send_json($response); |
|
599 | 599 | } |
600 | 600 | |
601 | 601 | public static function run_tool() { |
602 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
603 | - if ( !current_user_can( 'manage_options' ) ) { |
|
602 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
603 | + if (!current_user_can('manage_options')) { |
|
604 | 604 | die(-1); |
605 | 605 | } |
606 | 606 | |
607 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
607 | + $tool = sanitize_text_field($_POST['tool']); |
|
608 | 608 | |
609 | - do_action( 'wpinv_run_tool' ); |
|
609 | + do_action('wpinv_run_tool'); |
|
610 | 610 | |
611 | - if ( !empty( $tool ) ) { |
|
612 | - do_action( 'wpinv_tool_' . $tool ); |
|
611 | + if (!empty($tool)) { |
|
612 | + do_action('wpinv_tool_' . $tool); |
|
613 | 613 | } |
614 | 614 | } |
615 | 615 | |
616 | 616 | public static function apply_discount() { |
617 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
617 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
618 | 618 | |
619 | 619 | $response = array(); |
620 | 620 | |
621 | - if ( isset( $_POST['code'] ) ) { |
|
622 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
621 | + if (isset($_POST['code'])) { |
|
622 | + $discount_code = sanitize_text_field($_POST['code']); |
|
623 | 623 | |
624 | 624 | $response['success'] = false; |
625 | 625 | $response['msg'] = ''; |
@@ -627,14 +627,14 @@ discard block |
||
627 | 627 | |
628 | 628 | $user = is_user_logged_in() ? get_current_user_id() : ''; |
629 | 629 | |
630 | - if ( wpinv_is_discount_valid( $discount_code, $user ) ) { |
|
631 | - $discount = wpinv_get_discount_by_code( $discount_code ); |
|
632 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
633 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
634 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
635 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
630 | + if (wpinv_is_discount_valid($discount_code, $user)) { |
|
631 | + $discount = wpinv_get_discount_by_code($discount_code); |
|
632 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
633 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
634 | + $total = wpinv_get_cart_total(null, $discounts); |
|
635 | + $cart_totals = wpinv_recalculate_tax(true); |
|
636 | 636 | |
637 | - if ( !empty( $cart_totals ) ) { |
|
637 | + if (!empty($cart_totals)) { |
|
638 | 638 | $response['success'] = true; |
639 | 639 | $response['data'] = $cart_totals; |
640 | 640 | $response['data']['code'] = $discount_code; |
@@ -643,29 +643,29 @@ discard block |
||
643 | 643 | } |
644 | 644 | } else { |
645 | 645 | $errors = wpinv_get_errors(); |
646 | - $response['msg'] = $errors['wpinv-discount-error']; |
|
647 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
646 | + $response['msg'] = $errors['wpinv-discount-error']; |
|
647 | + wpinv_unset_error('wpinv-discount-error'); |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | // Allow for custom discount code handling |
651 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
651 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
652 | 652 | } |
653 | 653 | |
654 | - wp_send_json( $response ); |
|
654 | + wp_send_json($response); |
|
655 | 655 | } |
656 | 656 | |
657 | 657 | public static function remove_discount() { |
658 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
658 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
659 | 659 | |
660 | 660 | $response = array(); |
661 | 661 | |
662 | - if ( isset( $_POST['code'] ) ) { |
|
663 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
664 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
665 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
666 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
662 | + if (isset($_POST['code'])) { |
|
663 | + $discount_code = sanitize_text_field($_POST['code']); |
|
664 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
665 | + $total = wpinv_get_cart_total(null, $discounts); |
|
666 | + $cart_totals = wpinv_recalculate_tax(true); |
|
667 | 667 | |
668 | - if ( !empty( $cart_totals ) ) { |
|
668 | + if (!empty($cart_totals)) { |
|
669 | 669 | $response['success'] = true; |
670 | 670 | $response['data'] = $cart_totals; |
671 | 671 | $response['data']['code'] = $discount_code; |
@@ -674,10 +674,10 @@ discard block |
||
674 | 674 | } |
675 | 675 | |
676 | 676 | // Allow for custom discount code handling |
677 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
677 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
678 | 678 | } |
679 | 679 | |
680 | - wp_send_json( $response ); |
|
680 | + wp_send_json($response); |
|
681 | 681 | } |
682 | 682 | } |
683 | 683 |
@@ -7,90 +7,90 @@ 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 | function wpinv_get_discount_types() { |
15 | 15 | $discount_types = array( |
16 | - 'percent' => __( 'Percentage', 'invoicing' ), |
|
17 | - 'flat' => __( 'Flat Amount', 'invoicing' ), |
|
16 | + 'percent' => __('Percentage', 'invoicing'), |
|
17 | + 'flat' => __('Flat Amount', 'invoicing'), |
|
18 | 18 | ); |
19 | - return (array)apply_filters( 'wpinv_discount_types', $discount_types ); |
|
19 | + return (array)apply_filters('wpinv_discount_types', $discount_types); |
|
20 | 20 | } |
21 | 21 | |
22 | -function wpinv_get_discount_type_name( $type = '' ) { |
|
22 | +function wpinv_get_discount_type_name($type = '') { |
|
23 | 23 | $types = wpinv_get_discount_types(); |
24 | - return isset( $types[ $type ] ) ? $types[ $type ] : ''; |
|
24 | + return isset($types[$type]) ? $types[$type] : ''; |
|
25 | 25 | } |
26 | 26 | |
27 | -function wpinv_delete_discount( $data ) { |
|
28 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
29 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
27 | +function wpinv_delete_discount($data) { |
|
28 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
29 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
30 | 30 | } |
31 | 31 | |
32 | - if( ! current_user_can( 'manage_options' ) ) { |
|
33 | - wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
32 | + if (!current_user_can('manage_options')) { |
|
33 | + wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | $discount_id = $data['discount']; |
37 | - wpinv_remove_discount( $discount_id ); |
|
37 | + wpinv_remove_discount($discount_id); |
|
38 | 38 | } |
39 | -add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' ); |
|
39 | +add_action('wpinv_delete_discount', 'wpinv_delete_discount'); |
|
40 | 40 | |
41 | -function wpinv_activate_discount( $data ) { |
|
42 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
43 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
41 | +function wpinv_activate_discount($data) { |
|
42 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
43 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
44 | 44 | } |
45 | 45 | |
46 | - if( ! current_user_can( 'manage_options' ) ) { |
|
47 | - wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
46 | + if (!current_user_can('manage_options')) { |
|
47 | + wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
48 | 48 | } |
49 | 49 | |
50 | - $id = absint( $data['discount'] ); |
|
51 | - wpinv_update_discount_status( $id, 'publish' ); |
|
50 | + $id = absint($data['discount']); |
|
51 | + wpinv_update_discount_status($id, 'publish'); |
|
52 | 52 | } |
53 | -add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' ); |
|
53 | +add_action('wpinv_activate_discount', 'wpinv_activate_discount'); |
|
54 | 54 | |
55 | -function wpinv_deactivate_discount( $data ) { |
|
56 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
57 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
55 | +function wpinv_deactivate_discount($data) { |
|
56 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
57 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
58 | 58 | } |
59 | 59 | |
60 | - if( ! current_user_can( 'manage_options' ) ) { |
|
61 | - wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) ); |
|
60 | + if (!current_user_can('manage_options')) { |
|
61 | + wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403)); |
|
62 | 62 | } |
63 | 63 | |
64 | - $id = absint( $data['discount'] ); |
|
65 | - wpinv_update_discount_status( $id, 'pending' ); |
|
64 | + $id = absint($data['discount']); |
|
65 | + wpinv_update_discount_status($id, 'pending'); |
|
66 | 66 | } |
67 | -add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' ); |
|
67 | +add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount'); |
|
68 | 68 | |
69 | -function wpinv_get_discounts( $args = array() ) { |
|
69 | +function wpinv_get_discounts($args = array()) { |
|
70 | 70 | $defaults = array( |
71 | 71 | 'post_type' => 'wpi_discount', |
72 | 72 | 'posts_per_page' => 20, |
73 | 73 | 'paged' => null, |
74 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ) |
|
74 | + 'post_status' => array('publish', 'pending', 'draft', 'expired') |
|
75 | 75 | ); |
76 | 76 | |
77 | - $args = wp_parse_args( $args, $defaults ); |
|
77 | + $args = wp_parse_args($args, $defaults); |
|
78 | 78 | |
79 | - $discounts = get_posts( $args ); |
|
79 | + $discounts = get_posts($args); |
|
80 | 80 | |
81 | - if ( $discounts ) { |
|
81 | + if ($discounts) { |
|
82 | 82 | return $discounts; |
83 | 83 | } |
84 | 84 | |
85 | - if( ! $discounts && ! empty( $args['s'] ) ) { |
|
85 | + if (!$discounts && !empty($args['s'])) { |
|
86 | 86 | $args['meta_key'] = 'gd_discount_code'; |
87 | 87 | $args['meta_value'] = $args['s']; |
88 | 88 | $args['meta_compare'] = 'LIKE'; |
89 | - unset( $args['s'] ); |
|
90 | - $discounts = get_posts( $args ); |
|
89 | + unset($args['s']); |
|
90 | + $discounts = get_posts($args); |
|
91 | 91 | } |
92 | 92 | |
93 | - if( $discounts ) { |
|
93 | + if ($discounts) { |
|
94 | 94 | return $discounts; |
95 | 95 | } |
96 | 96 | |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | |
103 | 103 | $discounts = wpinv_get_discounts(); |
104 | 104 | |
105 | - if ( $discounts) { |
|
106 | - foreach ( $discounts as $discount ) { |
|
107 | - if ( wpinv_is_discount_active( $discount->ID ) ) { |
|
105 | + if ($discounts) { |
|
106 | + foreach ($discounts as $discount) { |
|
107 | + if (wpinv_is_discount_active($discount->ID)) { |
|
108 | 108 | $has_active = true; |
109 | 109 | break; |
110 | 110 | } |
@@ -113,38 +113,38 @@ discard block |
||
113 | 113 | return $has_active; |
114 | 114 | } |
115 | 115 | |
116 | -function wpinv_get_discount( $discount_id = 0 ) { |
|
117 | - if( empty( $discount_id ) ) { |
|
116 | +function wpinv_get_discount($discount_id = 0) { |
|
117 | + if (empty($discount_id)) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | 120 | |
121 | - if ( get_post_type( $discount_id ) != 'wpi_discount' ) { |
|
121 | + if (get_post_type($discount_id) != 'wpi_discount') { |
|
122 | 122 | return false; |
123 | 123 | } |
124 | 124 | |
125 | - $discount = get_post( $discount_id ); |
|
125 | + $discount = get_post($discount_id); |
|
126 | 126 | |
127 | 127 | return $discount; |
128 | 128 | } |
129 | 129 | |
130 | -function wpinv_get_discount_by_code( $code = '' ) { |
|
131 | - if( empty( $code ) || ! is_string( $code ) ) { |
|
130 | +function wpinv_get_discount_by_code($code = '') { |
|
131 | + if (empty($code) || !is_string($code)) { |
|
132 | 132 | return false; |
133 | 133 | } |
134 | 134 | |
135 | - return wpinv_get_discount_by( 'code', $code ); |
|
135 | + return wpinv_get_discount_by('code', $code); |
|
136 | 136 | } |
137 | 137 | |
138 | -function wpinv_get_discount_by( $field = '', $value = '' ) { |
|
139 | - if( empty( $field ) || empty( $value ) ) { |
|
138 | +function wpinv_get_discount_by($field = '', $value = '') { |
|
139 | + if (empty($field) || empty($value)) { |
|
140 | 140 | return false; |
141 | 141 | } |
142 | 142 | |
143 | - if( ! is_string( $field ) ) { |
|
143 | + if (!is_string($field)) { |
|
144 | 144 | return false; |
145 | 145 | } |
146 | 146 | |
147 | - switch( strtolower( $field ) ) { |
|
147 | + switch (strtolower($field)) { |
|
148 | 148 | |
149 | 149 | case 'code': |
150 | 150 | $meta_query = array(); |
@@ -154,32 +154,32 @@ discard block |
||
154 | 154 | 'compare' => '=' |
155 | 155 | ); |
156 | 156 | |
157 | - $discount = wpinv_get_discounts( array( |
|
157 | + $discount = wpinv_get_discounts(array( |
|
158 | 158 | 'posts_per_page' => 1, |
159 | 159 | 'post_status' => 'any', |
160 | 160 | 'meta_query' => $meta_query, |
161 | - ) ); |
|
161 | + )); |
|
162 | 162 | |
163 | - if( $discount ) { |
|
163 | + if ($discount) { |
|
164 | 164 | $discount = $discount[0]; |
165 | 165 | } |
166 | 166 | |
167 | 167 | break; |
168 | 168 | |
169 | 169 | case 'id': |
170 | - $discount = wpinv_get_discount( $value ); |
|
170 | + $discount = wpinv_get_discount($value); |
|
171 | 171 | |
172 | 172 | break; |
173 | 173 | |
174 | 174 | case 'name': |
175 | - $discount = get_posts( array( |
|
175 | + $discount = get_posts(array( |
|
176 | 176 | 'post_type' => 'wpi_discount', |
177 | 177 | 'name' => $value, |
178 | 178 | 'posts_per_page' => 1, |
179 | 179 | 'post_status' => 'any' |
180 | - ) ); |
|
180 | + )); |
|
181 | 181 | |
182 | - if( $discount ) { |
|
182 | + if ($discount) { |
|
183 | 183 | $discount = $discount[0]; |
184 | 184 | } |
185 | 185 | |
@@ -189,99 +189,99 @@ discard block |
||
189 | 189 | return false; |
190 | 190 | } |
191 | 191 | |
192 | - if( ! empty( $discount ) ) { |
|
192 | + if (!empty($discount)) { |
|
193 | 193 | return $discount; |
194 | 194 | } |
195 | 195 | |
196 | 196 | return false; |
197 | 197 | } |
198 | 198 | |
199 | -function wpinv_store_discount( $post_id, $data, $post, $update = false ) { |
|
199 | +function wpinv_store_discount($post_id, $data, $post, $update = false) { |
|
200 | 200 | $meta = array( |
201 | - 'code' => isset( $data['code'] ) ? sanitize_text_field( $data['code'] ) : '', |
|
202 | - 'type' => isset( $data['type'] ) ? sanitize_text_field( $data['type'] ) : 'percent', |
|
203 | - 'amount' => isset( $data['amount'] ) ? wpinv_sanitize_amount( $data['amount'] ) : '', |
|
204 | - 'start' => isset( $data['start'] ) ? sanitize_text_field( $data['start'] ) : '', |
|
205 | - 'expiration' => isset( $data['expiration'] ) ? sanitize_text_field( $data['expiration'] ) : '', |
|
206 | - 'min_total' => isset( $data['min_total'] ) ? wpinv_sanitize_amount( $data['min_total'] ) : '', |
|
207 | - 'max_total' => isset( $data['max_total'] ) ? wpinv_sanitize_amount( $data['max_total'] ) : '', |
|
208 | - 'max_uses' => isset( $data['max_uses'] ) ? absint( $data['max_uses'] ) : '', |
|
209 | - 'items' => isset( $data['items'] ) ? $data['items'] : array(), |
|
210 | - 'excluded_items' => isset( $data['excluded_items'] ) ? $data['excluded_items'] : array(), |
|
211 | - 'is_recurring' => isset( $data['recurring'] ) ? (bool)$data['recurring'] : false, |
|
212 | - 'is_single_use' => isset( $data['single_use'] ) ? (bool)$data['single_use'] : false, |
|
213 | - 'uses' => isset( $data['uses'] ) ? (int)$data['uses'] : false, |
|
201 | + 'code' => isset($data['code']) ? sanitize_text_field($data['code']) : '', |
|
202 | + 'type' => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent', |
|
203 | + 'amount' => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '', |
|
204 | + 'start' => isset($data['start']) ? sanitize_text_field($data['start']) : '', |
|
205 | + 'expiration' => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '', |
|
206 | + 'min_total' => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '', |
|
207 | + 'max_total' => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '', |
|
208 | + 'max_uses' => isset($data['max_uses']) ? absint($data['max_uses']) : '', |
|
209 | + 'items' => isset($data['items']) ? $data['items'] : array(), |
|
210 | + 'excluded_items' => isset($data['excluded_items']) ? $data['excluded_items'] : array(), |
|
211 | + 'is_recurring' => isset($data['recurring']) ? (bool)$data['recurring'] : false, |
|
212 | + 'is_single_use' => isset($data['single_use']) ? (bool)$data['single_use'] : false, |
|
213 | + 'uses' => isset($data['uses']) ? (int)$data['uses'] : false, |
|
214 | 214 | ); |
215 | 215 | |
216 | - $start_timestamp = strtotime( $meta['start'] ); |
|
216 | + $start_timestamp = strtotime($meta['start']); |
|
217 | 217 | |
218 | - if ( !empty( $meta['start'] ) ) { |
|
219 | - $meta['start'] = date( 'Y-m-d H:i:s', $start_timestamp ); |
|
218 | + if (!empty($meta['start'])) { |
|
219 | + $meta['start'] = date('Y-m-d H:i:s', $start_timestamp); |
|
220 | 220 | } |
221 | 221 | |
222 | - if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) { |
|
222 | + if ($meta['type'] == 'percent' && (float)$meta['amount'] > 100) { |
|
223 | 223 | $meta['amount'] = 100; |
224 | 224 | } |
225 | 225 | |
226 | - if ( !empty( $meta['expiration'] ) ) { |
|
227 | - $meta['expiration'] = date( 'Y-m-d H:i:s', strtotime( date( 'Y-m-d', strtotime( $meta['expiration'] ) ) . ' 23:59:59' ) ); |
|
228 | - $end_timestamp = strtotime( $meta['expiration'] ); |
|
226 | + if (!empty($meta['expiration'])) { |
|
227 | + $meta['expiration'] = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime($meta['expiration'])) . ' 23:59:59')); |
|
228 | + $end_timestamp = strtotime($meta['expiration']); |
|
229 | 229 | |
230 | - if ( !empty( $meta['start'] ) && $start_timestamp > $end_timestamp ) { |
|
230 | + if (!empty($meta['start']) && $start_timestamp > $end_timestamp) { |
|
231 | 231 | $meta['expiration'] = $meta['start']; // Set the expiration date to the start date if start is later than expiration date. |
232 | 232 | } |
233 | 233 | } |
234 | 234 | |
235 | - if ( $meta['uses'] === false ) { |
|
236 | - unset( $meta['uses'] ); |
|
235 | + if ($meta['uses'] === false) { |
|
236 | + unset($meta['uses']); |
|
237 | 237 | } |
238 | 238 | |
239 | - if ( ! empty( $meta['items'] ) ) { |
|
240 | - foreach ( $meta['items'] as $key => $item ) { |
|
241 | - if ( 0 === intval( $item ) ) { |
|
242 | - unset( $meta['items'][ $key ] ); |
|
239 | + if (!empty($meta['items'])) { |
|
240 | + foreach ($meta['items'] as $key => $item) { |
|
241 | + if (0 === intval($item)) { |
|
242 | + unset($meta['items'][$key]); |
|
243 | 243 | } |
244 | 244 | } |
245 | 245 | } |
246 | 246 | |
247 | - if ( ! empty( $meta['excluded_items'] ) ) { |
|
248 | - foreach ( $meta['excluded_items'] as $key => $item ) { |
|
249 | - if ( 0 === intval( $item ) ) { |
|
250 | - unset( $meta['excluded_items'][ $key ] ); |
|
247 | + if (!empty($meta['excluded_items'])) { |
|
248 | + foreach ($meta['excluded_items'] as $key => $item) { |
|
249 | + if (0 === intval($item)) { |
|
250 | + unset($meta['excluded_items'][$key]); |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 | } |
254 | 254 | |
255 | - $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post ); |
|
255 | + $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post); |
|
256 | 256 | |
257 | - do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post ); |
|
257 | + do_action('wpinv_pre_update_discount', $meta, $post_id, $post); |
|
258 | 258 | |
259 | - foreach( $meta as $key => $value ) { |
|
260 | - update_post_meta( $post_id, '_wpi_discount_' . $key, $value ); |
|
259 | + foreach ($meta as $key => $value) { |
|
260 | + update_post_meta($post_id, '_wpi_discount_' . $key, $value); |
|
261 | 261 | } |
262 | 262 | |
263 | - do_action( 'wpinv_post_update_discount', $meta, $post_id, $post ); |
|
263 | + do_action('wpinv_post_update_discount', $meta, $post_id, $post); |
|
264 | 264 | |
265 | 265 | return $post_id; |
266 | 266 | } |
267 | 267 | |
268 | -function wpinv_remove_discount( $discount_id = 0 ) { |
|
269 | - do_action( 'wpinv_pre_delete_discount', $discount_id ); |
|
268 | +function wpinv_remove_discount($discount_id = 0) { |
|
269 | + do_action('wpinv_pre_delete_discount', $discount_id); |
|
270 | 270 | |
271 | - wp_delete_post( $discount_id, true ); |
|
271 | + wp_delete_post($discount_id, true); |
|
272 | 272 | |
273 | - do_action( 'wpinv_post_delete_discount', $discount_id ); |
|
273 | + do_action('wpinv_post_delete_discount', $discount_id); |
|
274 | 274 | } |
275 | 275 | |
276 | -function wpinv_update_discount_status( $code_id = 0, $new_status = 'publish' ) { |
|
277 | - $discount = wpinv_get_discount( $code_id ); |
|
276 | +function wpinv_update_discount_status($code_id = 0, $new_status = 'publish') { |
|
277 | + $discount = wpinv_get_discount($code_id); |
|
278 | 278 | |
279 | - if ( $discount ) { |
|
280 | - do_action( 'wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status ); |
|
279 | + if ($discount) { |
|
280 | + do_action('wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status); |
|
281 | 281 | |
282 | - wp_update_post( array( 'ID' => $code_id, 'post_status' => $new_status ) ); |
|
282 | + wp_update_post(array('ID' => $code_id, 'post_status' => $new_status)); |
|
283 | 283 | |
284 | - do_action( 'wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status ); |
|
284 | + do_action('wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status); |
|
285 | 285 | |
286 | 286 | return true; |
287 | 287 | } |
@@ -289,173 +289,173 @@ discard block |
||
289 | 289 | return false; |
290 | 290 | } |
291 | 291 | |
292 | -function wpinv_discount_exists( $code_id ) { |
|
293 | - if ( wpinv_get_discount( $code_id ) ) { |
|
292 | +function wpinv_discount_exists($code_id) { |
|
293 | + if (wpinv_get_discount($code_id)) { |
|
294 | 294 | return true; |
295 | 295 | } |
296 | 296 | |
297 | 297 | return false; |
298 | 298 | } |
299 | 299 | |
300 | -function wpinv_is_discount_active( $code_id = null ) { |
|
301 | - $discount = wpinv_get_discount( $code_id ); |
|
300 | +function wpinv_is_discount_active($code_id = null) { |
|
301 | + $discount = wpinv_get_discount($code_id); |
|
302 | 302 | $return = false; |
303 | 303 | |
304 | - if ( $discount ) { |
|
305 | - if ( wpinv_is_discount_expired( $code_id ) ) { |
|
306 | - if( defined( 'DOING_AJAX' ) ) { |
|
307 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) ); |
|
304 | + if ($discount) { |
|
305 | + if (wpinv_is_discount_expired($code_id)) { |
|
306 | + if (defined('DOING_AJAX')) { |
|
307 | + wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing')); |
|
308 | 308 | } |
309 | - } elseif ( $discount->post_status == 'publish' ) { |
|
309 | + } elseif ($discount->post_status == 'publish') { |
|
310 | 310 | $return = true; |
311 | 311 | } else { |
312 | - if( defined( 'DOING_AJAX' ) ) { |
|
313 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) ); |
|
312 | + if (defined('DOING_AJAX')) { |
|
313 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing')); |
|
314 | 314 | } |
315 | 315 | } |
316 | 316 | } |
317 | 317 | |
318 | - return apply_filters( 'wpinv_is_discount_active', $return, $code_id ); |
|
318 | + return apply_filters('wpinv_is_discount_active', $return, $code_id); |
|
319 | 319 | } |
320 | 320 | |
321 | -function wpinv_get_discount_code( $code_id = null ) { |
|
322 | - $code = get_post_meta( $code_id, '_wpi_discount_code', true ); |
|
321 | +function wpinv_get_discount_code($code_id = null) { |
|
322 | + $code = get_post_meta($code_id, '_wpi_discount_code', true); |
|
323 | 323 | |
324 | - return apply_filters( 'wpinv_get_discount_code', $code, $code_id ); |
|
324 | + return apply_filters('wpinv_get_discount_code', $code, $code_id); |
|
325 | 325 | } |
326 | 326 | |
327 | -function wpinv_get_discount_start_date( $code_id = null ) { |
|
328 | - $start_date = get_post_meta( $code_id, '_wpi_discount_start', true ); |
|
327 | +function wpinv_get_discount_start_date($code_id = null) { |
|
328 | + $start_date = get_post_meta($code_id, '_wpi_discount_start', true); |
|
329 | 329 | |
330 | - return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id ); |
|
330 | + return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id); |
|
331 | 331 | } |
332 | 332 | |
333 | -function wpinv_get_discount_expiration( $code_id = null ) { |
|
334 | - $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true ); |
|
333 | +function wpinv_get_discount_expiration($code_id = null) { |
|
334 | + $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true); |
|
335 | 335 | |
336 | - return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id ); |
|
336 | + return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id); |
|
337 | 337 | } |
338 | 338 | |
339 | -function wpinv_get_discount_max_uses( $code_id = null ) { |
|
340 | - $max_uses = get_post_meta( $code_id, '_wpi_discount_max_uses', true ); |
|
339 | +function wpinv_get_discount_max_uses($code_id = null) { |
|
340 | + $max_uses = get_post_meta($code_id, '_wpi_discount_max_uses', true); |
|
341 | 341 | |
342 | - return (int) apply_filters( 'wpinv_get_discount_max_uses', $max_uses, $code_id ); |
|
342 | + return (int)apply_filters('wpinv_get_discount_max_uses', $max_uses, $code_id); |
|
343 | 343 | } |
344 | 344 | |
345 | -function wpinv_get_discount_uses( $code_id = null ) { |
|
346 | - $uses = get_post_meta( $code_id, '_wpi_discount_uses', true ); |
|
345 | +function wpinv_get_discount_uses($code_id = null) { |
|
346 | + $uses = get_post_meta($code_id, '_wpi_discount_uses', true); |
|
347 | 347 | |
348 | - return (int) apply_filters( 'wpinv_get_discount_uses', $uses, $code_id ); |
|
348 | + return (int)apply_filters('wpinv_get_discount_uses', $uses, $code_id); |
|
349 | 349 | } |
350 | 350 | |
351 | -function wpinv_get_discount_min_total( $code_id = null ) { |
|
352 | - $min_total = get_post_meta( $code_id, '_wpi_discount_min_total', true ); |
|
351 | +function wpinv_get_discount_min_total($code_id = null) { |
|
352 | + $min_total = get_post_meta($code_id, '_wpi_discount_min_total', true); |
|
353 | 353 | |
354 | - return (float) apply_filters( 'wpinv_get_discount_min_total', $min_total, $code_id ); |
|
354 | + return (float)apply_filters('wpinv_get_discount_min_total', $min_total, $code_id); |
|
355 | 355 | } |
356 | 356 | |
357 | -function wpinv_get_discount_max_total( $code_id = null ) { |
|
358 | - $max_total = get_post_meta( $code_id, '_wpi_discount_max_total', true ); |
|
357 | +function wpinv_get_discount_max_total($code_id = null) { |
|
358 | + $max_total = get_post_meta($code_id, '_wpi_discount_max_total', true); |
|
359 | 359 | |
360 | - return (float) apply_filters( 'wpinv_get_discount_max_total', $max_total, $code_id ); |
|
360 | + return (float)apply_filters('wpinv_get_discount_max_total', $max_total, $code_id); |
|
361 | 361 | } |
362 | 362 | |
363 | -function wpinv_get_discount_amount( $code_id = null ) { |
|
364 | - $amount = get_post_meta( $code_id, '_wpi_discount_amount', true ); |
|
363 | +function wpinv_get_discount_amount($code_id = null) { |
|
364 | + $amount = get_post_meta($code_id, '_wpi_discount_amount', true); |
|
365 | 365 | |
366 | - return (float) apply_filters( 'wpinv_get_discount_amount', $amount, $code_id ); |
|
366 | + return (float)apply_filters('wpinv_get_discount_amount', $amount, $code_id); |
|
367 | 367 | } |
368 | 368 | |
369 | -function wpinv_get_discount_type( $code_id = null, $name = false ) { |
|
370 | - $type = strtolower( get_post_meta( $code_id, '_wpi_discount_type', true ) ); |
|
369 | +function wpinv_get_discount_type($code_id = null, $name = false) { |
|
370 | + $type = strtolower(get_post_meta($code_id, '_wpi_discount_type', true)); |
|
371 | 371 | |
372 | - if ( $name ) { |
|
373 | - $name = wpinv_get_discount_type_name( $type ); |
|
372 | + if ($name) { |
|
373 | + $name = wpinv_get_discount_type_name($type); |
|
374 | 374 | |
375 | - return apply_filters( 'wpinv_get_discount_type_name', $name, $code_id ); |
|
375 | + return apply_filters('wpinv_get_discount_type_name', $name, $code_id); |
|
376 | 376 | } |
377 | 377 | |
378 | - return apply_filters( 'wpinv_get_discount_type', $type, $code_id ); |
|
378 | + return apply_filters('wpinv_get_discount_type', $type, $code_id); |
|
379 | 379 | } |
380 | 380 | |
381 | -function wpinv_discount_status( $status ) { |
|
382 | - switch( $status ){ |
|
381 | +function wpinv_discount_status($status) { |
|
382 | + switch ($status) { |
|
383 | 383 | case 'expired' : |
384 | - $name = __( 'Expired', 'invoicing' ); |
|
384 | + $name = __('Expired', 'invoicing'); |
|
385 | 385 | break; |
386 | 386 | case 'publish' : |
387 | 387 | case 'active' : |
388 | - $name = __( 'Active', 'invoicing' ); |
|
388 | + $name = __('Active', 'invoicing'); |
|
389 | 389 | break; |
390 | 390 | default : |
391 | - $name = __( 'Inactive', 'invoicing' ); |
|
391 | + $name = __('Inactive', 'invoicing'); |
|
392 | 392 | break; |
393 | 393 | } |
394 | 394 | return $name; |
395 | 395 | } |
396 | 396 | |
397 | -function wpinv_get_discount_excluded_items( $code_id = null ) { |
|
398 | - $excluded_items = get_post_meta( $code_id, '_wpi_discount_excluded_items', true ); |
|
397 | +function wpinv_get_discount_excluded_items($code_id = null) { |
|
398 | + $excluded_items = get_post_meta($code_id, '_wpi_discount_excluded_items', true); |
|
399 | 399 | |
400 | - if ( empty( $excluded_items ) || ! is_array( $excluded_items ) ) { |
|
400 | + if (empty($excluded_items) || !is_array($excluded_items)) { |
|
401 | 401 | $excluded_items = array(); |
402 | 402 | } |
403 | 403 | |
404 | - return (array) apply_filters( 'wpinv_get_discount_excluded_items', $excluded_items, $code_id ); |
|
404 | + return (array)apply_filters('wpinv_get_discount_excluded_items', $excluded_items, $code_id); |
|
405 | 405 | } |
406 | 406 | |
407 | -function wpinv_get_discount_item_reqs( $code_id = null ) { |
|
408 | - $item_reqs = get_post_meta( $code_id, '_wpi_discount_items', true ); |
|
407 | +function wpinv_get_discount_item_reqs($code_id = null) { |
|
408 | + $item_reqs = get_post_meta($code_id, '_wpi_discount_items', true); |
|
409 | 409 | |
410 | - if ( empty( $item_reqs ) || ! is_array( $item_reqs ) ) { |
|
410 | + if (empty($item_reqs) || !is_array($item_reqs)) { |
|
411 | 411 | $item_reqs = array(); |
412 | 412 | } |
413 | 413 | |
414 | - return (array) apply_filters( 'wpinv_get_discount_item_reqs', $item_reqs, $code_id ); |
|
414 | + return (array)apply_filters('wpinv_get_discount_item_reqs', $item_reqs, $code_id); |
|
415 | 415 | } |
416 | 416 | |
417 | -function wpinv_get_discount_item_condition( $code_id = 0 ) { |
|
418 | - return get_post_meta( $code_id, '_wpi_discount_item_condition', true ); |
|
417 | +function wpinv_get_discount_item_condition($code_id = 0) { |
|
418 | + return get_post_meta($code_id, '_wpi_discount_item_condition', true); |
|
419 | 419 | } |
420 | 420 | |
421 | -function wpinv_is_discount_not_global( $code_id = 0 ) { |
|
422 | - return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true ); |
|
421 | +function wpinv_is_discount_not_global($code_id = 0) { |
|
422 | + return (bool)get_post_meta($code_id, '_wpi_discount_is_not_global', true); |
|
423 | 423 | } |
424 | 424 | |
425 | -function wpinv_is_discount_expired( $code_id = null ) { |
|
426 | - $discount = wpinv_get_discount( $code_id ); |
|
425 | +function wpinv_is_discount_expired($code_id = null) { |
|
426 | + $discount = wpinv_get_discount($code_id); |
|
427 | 427 | $return = false; |
428 | 428 | |
429 | - if ( $discount ) { |
|
430 | - $expiration = wpinv_get_discount_expiration( $code_id ); |
|
431 | - if ( $expiration ) { |
|
432 | - $expiration = strtotime( $expiration ); |
|
433 | - if ( $expiration < current_time( 'timestamp' ) ) { |
|
429 | + if ($discount) { |
|
430 | + $expiration = wpinv_get_discount_expiration($code_id); |
|
431 | + if ($expiration) { |
|
432 | + $expiration = strtotime($expiration); |
|
433 | + if ($expiration < current_time('timestamp')) { |
|
434 | 434 | // Discount is expired |
435 | - wpinv_update_discount_status( $code_id, 'pending' ); |
|
435 | + wpinv_update_discount_status($code_id, 'pending'); |
|
436 | 436 | $return = true; |
437 | 437 | } |
438 | 438 | } |
439 | 439 | } |
440 | 440 | |
441 | - return apply_filters( 'wpinv_is_discount_expired', $return, $code_id ); |
|
441 | + return apply_filters('wpinv_is_discount_expired', $return, $code_id); |
|
442 | 442 | } |
443 | 443 | |
444 | -function wpinv_is_discount_started( $code_id = null ) { |
|
445 | - $discount = wpinv_get_discount( $code_id ); |
|
444 | +function wpinv_is_discount_started($code_id = null) { |
|
445 | + $discount = wpinv_get_discount($code_id); |
|
446 | 446 | $return = false; |
447 | 447 | |
448 | - if ( $discount ) { |
|
449 | - $start_date = wpinv_get_discount_start_date( $code_id ); |
|
448 | + if ($discount) { |
|
449 | + $start_date = wpinv_get_discount_start_date($code_id); |
|
450 | 450 | |
451 | - if ( $start_date ) { |
|
452 | - $start_date = strtotime( $start_date ); |
|
451 | + if ($start_date) { |
|
452 | + $start_date = strtotime($start_date); |
|
453 | 453 | |
454 | - if ( $start_date < current_time( 'timestamp' ) ) { |
|
454 | + if ($start_date < current_time('timestamp')) { |
|
455 | 455 | // Discount has past the start date |
456 | 456 | $return = true; |
457 | 457 | } else { |
458 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) ); |
|
458 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing')); |
|
459 | 459 | } |
460 | 460 | } else { |
461 | 461 | // No start date for this discount, so has to be true |
@@ -463,159 +463,159 @@ discard block |
||
463 | 463 | } |
464 | 464 | } |
465 | 465 | |
466 | - return apply_filters( 'wpinv_is_discount_started', $return, $code_id ); |
|
466 | + return apply_filters('wpinv_is_discount_started', $return, $code_id); |
|
467 | 467 | } |
468 | 468 | |
469 | -function wpinv_check_discount_dates( $code_id = null ) { |
|
470 | - $discount = wpinv_get_discount( $code_id ); |
|
469 | +function wpinv_check_discount_dates($code_id = null) { |
|
470 | + $discount = wpinv_get_discount($code_id); |
|
471 | 471 | $return = false; |
472 | 472 | |
473 | - if ( $discount ) { |
|
474 | - $start_date = wpinv_get_discount_start_date( $code_id ); |
|
473 | + if ($discount) { |
|
474 | + $start_date = wpinv_get_discount_start_date($code_id); |
|
475 | 475 | |
476 | - if ( $start_date ) { |
|
477 | - $start_date = strtotime( $start_date ); |
|
476 | + if ($start_date) { |
|
477 | + $start_date = strtotime($start_date); |
|
478 | 478 | |
479 | - if ( $start_date < current_time( 'timestamp' ) ) { |
|
479 | + if ($start_date < current_time('timestamp')) { |
|
480 | 480 | // Discount has past the start date |
481 | 481 | $return = true; |
482 | 482 | } else { |
483 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) ); |
|
483 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing')); |
|
484 | 484 | } |
485 | 485 | } else { |
486 | 486 | // No start date for this discount, so has to be true |
487 | 487 | $return = true; |
488 | 488 | } |
489 | 489 | |
490 | - if ( $return ) { |
|
491 | - $expiration = wpinv_get_discount_expiration( $code_id ); |
|
490 | + if ($return) { |
|
491 | + $expiration = wpinv_get_discount_expiration($code_id); |
|
492 | 492 | |
493 | - if ( $expiration ) { |
|
494 | - $expiration = strtotime( $expiration ); |
|
495 | - if ( $expiration < current_time( 'timestamp' ) ) { |
|
493 | + if ($expiration) { |
|
494 | + $expiration = strtotime($expiration); |
|
495 | + if ($expiration < current_time('timestamp')) { |
|
496 | 496 | // Discount is expired |
497 | - wpinv_update_discount_status( $code_id, 'pending' ); |
|
497 | + wpinv_update_discount_status($code_id, 'pending'); |
|
498 | 498 | $return = true; |
499 | 499 | } |
500 | 500 | } |
501 | 501 | } |
502 | 502 | } |
503 | 503 | |
504 | - return apply_filters( 'wpinv_check_discount_dates', $return, $code_id ); |
|
504 | + return apply_filters('wpinv_check_discount_dates', $return, $code_id); |
|
505 | 505 | } |
506 | 506 | |
507 | -function wpinv_is_discount_maxed_out( $code_id = null ) { |
|
508 | - $discount = wpinv_get_discount( $code_id ); |
|
507 | +function wpinv_is_discount_maxed_out($code_id = null) { |
|
508 | + $discount = wpinv_get_discount($code_id); |
|
509 | 509 | $return = false; |
510 | 510 | |
511 | - if ( $discount ) { |
|
512 | - $uses = wpinv_get_discount_uses( $code_id ); |
|
511 | + if ($discount) { |
|
512 | + $uses = wpinv_get_discount_uses($code_id); |
|
513 | 513 | // Large number that will never be reached |
514 | - $max_uses = wpinv_get_discount_max_uses( $code_id ); |
|
514 | + $max_uses = wpinv_get_discount_max_uses($code_id); |
|
515 | 515 | // Should never be greater than, but just in case |
516 | - if ( $uses >= $max_uses && ! empty( $max_uses ) ) { |
|
516 | + if ($uses >= $max_uses && !empty($max_uses)) { |
|
517 | 517 | // Discount is maxed out |
518 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) ); |
|
518 | + wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing')); |
|
519 | 519 | $return = true; |
520 | 520 | } |
521 | 521 | } |
522 | 522 | |
523 | - return apply_filters( 'wpinv_is_discount_maxed_out', $return, $code_id ); |
|
523 | + return apply_filters('wpinv_is_discount_maxed_out', $return, $code_id); |
|
524 | 524 | } |
525 | 525 | |
526 | -function wpinv_discount_is_min_met( $code_id = null ) { |
|
527 | - $discount = wpinv_get_discount( $code_id ); |
|
526 | +function wpinv_discount_is_min_met($code_id = null) { |
|
527 | + $discount = wpinv_get_discount($code_id); |
|
528 | 528 | $return = false; |
529 | 529 | |
530 | - if ( $discount ) { |
|
531 | - $min = (float)wpinv_get_discount_min_total( $code_id ); |
|
532 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id ); |
|
530 | + if ($discount) { |
|
531 | + $min = (float)wpinv_get_discount_min_total($code_id); |
|
532 | + $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id); |
|
533 | 533 | |
534 | - if ( !$min > 0 || $cart_amount >= $min ) { |
|
534 | + if (!$min > 0 || $cart_amount >= $min) { |
|
535 | 535 | // Minimum has been met |
536 | 536 | $return = true; |
537 | 537 | } else { |
538 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) ); |
|
538 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($min)))); |
|
539 | 539 | } |
540 | 540 | } |
541 | 541 | |
542 | - return apply_filters( 'wpinv_is_discount_min_met', $return, $code_id ); |
|
542 | + return apply_filters('wpinv_is_discount_min_met', $return, $code_id); |
|
543 | 543 | } |
544 | 544 | |
545 | -function wpinv_discount_is_max_met( $code_id = null ) { |
|
546 | - $discount = wpinv_get_discount( $code_id ); |
|
545 | +function wpinv_discount_is_max_met($code_id = null) { |
|
546 | + $discount = wpinv_get_discount($code_id); |
|
547 | 547 | $return = false; |
548 | 548 | |
549 | - if ( $discount ) { |
|
550 | - $max = (float)wpinv_get_discount_max_total( $code_id ); |
|
551 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id ); |
|
549 | + if ($discount) { |
|
550 | + $max = (float)wpinv_get_discount_max_total($code_id); |
|
551 | + $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id); |
|
552 | 552 | |
553 | - if ( !$max > 0 || $cart_amount <= $max ) { |
|
553 | + if (!$max > 0 || $cart_amount <= $max) { |
|
554 | 554 | // Minimum has been met |
555 | 555 | $return = true; |
556 | 556 | } else { |
557 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) ); |
|
557 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($max)))); |
|
558 | 558 | } |
559 | 559 | } |
560 | 560 | |
561 | - return apply_filters( 'wpinv_is_discount_max_met', $return, $code_id ); |
|
561 | + return apply_filters('wpinv_is_discount_max_met', $return, $code_id); |
|
562 | 562 | } |
563 | 563 | |
564 | -function wpinv_discount_is_single_use( $code_id = 0 ) { |
|
565 | - $single_use = get_post_meta( $code_id, '_wpi_discount_is_single_use', true ); |
|
566 | - return (bool) apply_filters( 'wpinv_is_discount_single_use', $single_use, $code_id ); |
|
564 | +function wpinv_discount_is_single_use($code_id = 0) { |
|
565 | + $single_use = get_post_meta($code_id, '_wpi_discount_is_single_use', true); |
|
566 | + return (bool)apply_filters('wpinv_is_discount_single_use', $single_use, $code_id); |
|
567 | 567 | } |
568 | 568 | |
569 | -function wpinv_discount_is_recurring( $code_id = 0, $code = false ) { |
|
570 | - if ( $code ) { |
|
571 | - $discount = wpinv_get_discount_by_code( $code_id ); |
|
569 | +function wpinv_discount_is_recurring($code_id = 0, $code = false) { |
|
570 | + if ($code) { |
|
571 | + $discount = wpinv_get_discount_by_code($code_id); |
|
572 | 572 | |
573 | - if ( !empty( $discount ) ) { |
|
573 | + if (!empty($discount)) { |
|
574 | 574 | $code_id = $discount->ID; |
575 | 575 | } |
576 | 576 | } |
577 | 577 | |
578 | - $recurring = get_post_meta( $code_id, '_wpi_discount_is_recurring', true ); |
|
578 | + $recurring = get_post_meta($code_id, '_wpi_discount_is_recurring', true); |
|
579 | 579 | |
580 | - return (bool) apply_filters( 'wpinv_is_discount_recurring', $recurring, $code_id, $code ); |
|
580 | + return (bool)apply_filters('wpinv_is_discount_recurring', $recurring, $code_id, $code); |
|
581 | 581 | } |
582 | 582 | |
583 | -function wpinv_discount_item_reqs_met( $code_id = null ) { |
|
584 | - $item_reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
585 | - $condition = wpinv_get_discount_item_condition( $code_id ); |
|
586 | - $excluded_ps = wpinv_get_discount_excluded_items( $code_id ); |
|
583 | +function wpinv_discount_item_reqs_met($code_id = null) { |
|
584 | + $item_reqs = wpinv_get_discount_item_reqs($code_id); |
|
585 | + $condition = wpinv_get_discount_item_condition($code_id); |
|
586 | + $excluded_ps = wpinv_get_discount_excluded_items($code_id); |
|
587 | 587 | $cart_items = wpinv_get_cart_contents(); |
588 | - $cart_ids = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null; |
|
588 | + $cart_ids = $cart_items ? wp_list_pluck($cart_items, 'id') : null; |
|
589 | 589 | $ret = false; |
590 | 590 | |
591 | - if ( empty( $item_reqs ) && empty( $excluded_ps ) ) { |
|
591 | + if (empty($item_reqs) && empty($excluded_ps)) { |
|
592 | 592 | $ret = true; |
593 | 593 | } |
594 | 594 | |
595 | 595 | // Normalize our data for item requirements, exclusions and cart data |
596 | 596 | // First absint the items, then sort, and reset the array keys |
597 | - $item_reqs = array_map( 'absint', $item_reqs ); |
|
598 | - asort( $item_reqs ); |
|
599 | - $item_reqs = array_values( $item_reqs ); |
|
597 | + $item_reqs = array_map('absint', $item_reqs); |
|
598 | + asort($item_reqs); |
|
599 | + $item_reqs = array_values($item_reqs); |
|
600 | 600 | |
601 | - $excluded_ps = array_map( 'absint', $excluded_ps ); |
|
602 | - asort( $excluded_ps ); |
|
603 | - $excluded_ps = array_values( $excluded_ps ); |
|
601 | + $excluded_ps = array_map('absint', $excluded_ps); |
|
602 | + asort($excluded_ps); |
|
603 | + $excluded_ps = array_values($excluded_ps); |
|
604 | 604 | |
605 | - $cart_ids = array_map( 'absint', $cart_ids ); |
|
606 | - asort( $cart_ids ); |
|
607 | - $cart_ids = array_values( $cart_ids ); |
|
605 | + $cart_ids = array_map('absint', $cart_ids); |
|
606 | + asort($cart_ids); |
|
607 | + $cart_ids = array_values($cart_ids); |
|
608 | 608 | |
609 | 609 | // Ensure we have requirements before proceeding |
610 | - if ( !$ret && ! empty( $item_reqs ) ) { |
|
611 | - switch( $condition ) { |
|
610 | + if (!$ret && !empty($item_reqs)) { |
|
611 | + switch ($condition) { |
|
612 | 612 | case 'all' : |
613 | 613 | // Default back to true |
614 | 614 | $ret = true; |
615 | 615 | |
616 | - foreach ( $item_reqs as $item_id ) { |
|
617 | - if ( !wpinv_item_in_cart( $item_id ) ) { |
|
618 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
616 | + foreach ($item_reqs as $item_id) { |
|
617 | + if (!wpinv_item_in_cart($item_id)) { |
|
618 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
619 | 619 | $ret = false; |
620 | 620 | break; |
621 | 621 | } |
@@ -624,15 +624,15 @@ discard block |
||
624 | 624 | break; |
625 | 625 | |
626 | 626 | default : // Any |
627 | - foreach ( $item_reqs as $item_id ) { |
|
628 | - if ( wpinv_item_in_cart( $item_id ) ) { |
|
627 | + foreach ($item_reqs as $item_id) { |
|
628 | + if (wpinv_item_in_cart($item_id)) { |
|
629 | 629 | $ret = true; |
630 | 630 | break; |
631 | 631 | } |
632 | 632 | } |
633 | 633 | |
634 | - if( ! $ret ) { |
|
635 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
634 | + if (!$ret) { |
|
635 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | break; |
@@ -641,68 +641,68 @@ discard block |
||
641 | 641 | $ret = true; |
642 | 642 | } |
643 | 643 | |
644 | - if( ! empty( $excluded_ps ) ) { |
|
644 | + if (!empty($excluded_ps)) { |
|
645 | 645 | // Check that there are items other than excluded ones in the cart |
646 | - if( $cart_ids == $excluded_ps ) { |
|
647 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) ); |
|
646 | + if ($cart_ids == $excluded_ps) { |
|
647 | + wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing')); |
|
648 | 648 | $ret = false; |
649 | 649 | } |
650 | 650 | } |
651 | 651 | |
652 | - return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition ); |
|
652 | + return (bool)apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition); |
|
653 | 653 | } |
654 | 654 | |
655 | -function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) { |
|
655 | +function wpinv_is_discount_used($code = null, $user = '', $code_id = 0) { |
|
656 | 656 | global $wpi_checkout_id; |
657 | 657 | |
658 | 658 | $return = false; |
659 | 659 | |
660 | - if ( empty( $code_id ) ) { |
|
661 | - $code_id = wpinv_get_discount_id_by_code( $code ); |
|
660 | + if (empty($code_id)) { |
|
661 | + $code_id = wpinv_get_discount_id_by_code($code); |
|
662 | 662 | |
663 | - if( empty( $code_id ) ) { |
|
663 | + if (empty($code_id)) { |
|
664 | 664 | return false; // No discount was found |
665 | 665 | } |
666 | 666 | } |
667 | 667 | |
668 | - if ( wpinv_discount_is_single_use( $code_id ) ) { |
|
668 | + if (wpinv_discount_is_single_use($code_id)) { |
|
669 | 669 | $payments = array(); |
670 | 670 | |
671 | 671 | $user_id = 0; |
672 | - if ( is_int( $user ) ) { |
|
672 | + if (is_int($user)) { |
|
673 | 673 | $user_id = $user; |
674 | - } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) { |
|
674 | + } else if (is_email($user) && $user_data = get_user_by('email', $user)) { |
|
675 | 675 | $user_id = $user_data->ID; |
676 | - } else if ( $user_data = get_user_by( 'login', $user ) ) { |
|
676 | + } else if ($user_data = get_user_by('login', $user)) { |
|
677 | 677 | $user_id = $user_data->ID; |
678 | 678 | } |
679 | 679 | |
680 | - if ( !$user_id ) { |
|
681 | - $query = array( 'user' => $user_id, 'limit' => false ); |
|
682 | - $payments = wpinv_get_invoices( $query ); // Get all payments with matching email |
|
680 | + if (!$user_id) { |
|
681 | + $query = array('user' => $user_id, 'limit' => false); |
|
682 | + $payments = wpinv_get_invoices($query); // Get all payments with matching email |
|
683 | 683 | } |
684 | 684 | |
685 | - if ( $payments ) { |
|
686 | - foreach ( $payments as $payment ) { |
|
687 | - if ( $payment->has_status( array( 'cancelled', 'failed' ) ) ) { |
|
685 | + if ($payments) { |
|
686 | + foreach ($payments as $payment) { |
|
687 | + if ($payment->has_status(array('cancelled', 'failed'))) { |
|
688 | 688 | continue; |
689 | 689 | } |
690 | 690 | |
691 | 691 | // Don't count discount used for current invoice chekcout. |
692 | - if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) { |
|
692 | + if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) { |
|
693 | 693 | continue; |
694 | 694 | } |
695 | 695 | |
696 | - $discounts = $payment->get_discounts( true ); |
|
697 | - if ( empty( $discounts ) ) { |
|
696 | + $discounts = $payment->get_discounts(true); |
|
697 | + if (empty($discounts)) { |
|
698 | 698 | continue; |
699 | 699 | } |
700 | 700 | |
701 | - $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts; |
|
701 | + $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts; |
|
702 | 702 | |
703 | - if ( !empty( $discounts ) && is_array( $discounts ) ) { |
|
704 | - if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) { |
|
705 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) ); |
|
703 | + if (!empty($discounts) && is_array($discounts)) { |
|
704 | + if (in_array(strtolower($code), array_map('strtolower', $discounts))) { |
|
705 | + wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing')); |
|
706 | 706 | $return = true; |
707 | 707 | break; |
708 | 708 | } |
@@ -711,61 +711,61 @@ discard block |
||
711 | 711 | } |
712 | 712 | } |
713 | 713 | |
714 | - return apply_filters( 'wpinv_is_discount_used', $return, $code, $user ); |
|
714 | + return apply_filters('wpinv_is_discount_used', $return, $code, $user); |
|
715 | 715 | } |
716 | 716 | |
717 | -function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) { |
|
717 | +function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) { |
|
718 | 718 | $return = false; |
719 | - $discount_id = wpinv_get_discount_id_by_code( $code ); |
|
720 | - $user = trim( $user ); |
|
719 | + $discount_id = wpinv_get_discount_id_by_code($code); |
|
720 | + $user = trim($user); |
|
721 | 721 | |
722 | - if ( wpinv_get_cart_contents() ) { |
|
723 | - if ( $discount_id ) { |
|
722 | + if (wpinv_get_cart_contents()) { |
|
723 | + if ($discount_id) { |
|
724 | 724 | if ( |
725 | - wpinv_is_discount_active( $discount_id ) && |
|
726 | - wpinv_check_discount_dates( $discount_id ) && |
|
727 | - !wpinv_is_discount_maxed_out( $discount_id ) && |
|
728 | - !wpinv_is_discount_used( $code, $user, $discount_id ) && |
|
729 | - wpinv_discount_is_min_met( $discount_id ) && |
|
730 | - wpinv_discount_is_max_met( $discount_id ) && |
|
731 | - wpinv_discount_item_reqs_met( $discount_id ) |
|
725 | + wpinv_is_discount_active($discount_id) && |
|
726 | + wpinv_check_discount_dates($discount_id) && |
|
727 | + !wpinv_is_discount_maxed_out($discount_id) && |
|
728 | + !wpinv_is_discount_used($code, $user, $discount_id) && |
|
729 | + wpinv_discount_is_min_met($discount_id) && |
|
730 | + wpinv_discount_is_max_met($discount_id) && |
|
731 | + wpinv_discount_item_reqs_met($discount_id) |
|
732 | 732 | ) { |
733 | 733 | $return = true; |
734 | 734 | } |
735 | - } elseif( $set_error ) { |
|
736 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) ); |
|
735 | + } elseif ($set_error) { |
|
736 | + wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing')); |
|
737 | 737 | } |
738 | 738 | } |
739 | 739 | |
740 | - return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user ); |
|
740 | + return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user); |
|
741 | 741 | } |
742 | 742 | |
743 | -function wpinv_get_discount_id_by_code( $code ) { |
|
744 | - $discount = wpinv_get_discount_by_code( $code ); |
|
745 | - if( $discount ) { |
|
743 | +function wpinv_get_discount_id_by_code($code) { |
|
744 | + $discount = wpinv_get_discount_by_code($code); |
|
745 | + if ($discount) { |
|
746 | 746 | return $discount->ID; |
747 | 747 | } |
748 | 748 | return false; |
749 | 749 | } |
750 | 750 | |
751 | -function wpinv_get_discounted_amount( $code, $base_price ) { |
|
751 | +function wpinv_get_discounted_amount($code, $base_price) { |
|
752 | 752 | $amount = $base_price; |
753 | - $discount_id = wpinv_get_discount_id_by_code( $code ); |
|
753 | + $discount_id = wpinv_get_discount_id_by_code($code); |
|
754 | 754 | |
755 | - if( $discount_id ) { |
|
756 | - $type = wpinv_get_discount_type( $discount_id ); |
|
757 | - $rate = wpinv_get_discount_amount( $discount_id ); |
|
755 | + if ($discount_id) { |
|
756 | + $type = wpinv_get_discount_type($discount_id); |
|
757 | + $rate = wpinv_get_discount_amount($discount_id); |
|
758 | 758 | |
759 | - if ( $type == 'flat' ) { |
|
759 | + if ($type == 'flat') { |
|
760 | 760 | // Set amount |
761 | 761 | $amount = $base_price - $rate; |
762 | - if ( $amount < 0 ) { |
|
762 | + if ($amount < 0) { |
|
763 | 763 | $amount = 0; |
764 | 764 | } |
765 | 765 | |
766 | 766 | } else { |
767 | 767 | // Percentage discount |
768 | - $amount = $base_price - ( $base_price * ( $rate / 100 ) ); |
|
768 | + $amount = $base_price - ($base_price * ($rate / 100)); |
|
769 | 769 | } |
770 | 770 | |
771 | 771 | } else { |
@@ -774,108 +774,108 @@ discard block |
||
774 | 774 | |
775 | 775 | } |
776 | 776 | |
777 | - return apply_filters( 'wpinv_discounted_amount', $amount ); |
|
777 | + return apply_filters('wpinv_discounted_amount', $amount); |
|
778 | 778 | } |
779 | 779 | |
780 | -function wpinv_increase_discount_usage( $code ) { |
|
780 | +function wpinv_increase_discount_usage($code) { |
|
781 | 781 | |
782 | - $id = wpinv_get_discount_id_by_code( $code ); |
|
783 | - $uses = wpinv_get_discount_uses( $id ); |
|
782 | + $id = wpinv_get_discount_id_by_code($code); |
|
783 | + $uses = wpinv_get_discount_uses($id); |
|
784 | 784 | |
785 | - if ( $uses ) { |
|
785 | + if ($uses) { |
|
786 | 786 | $uses++; |
787 | 787 | } else { |
788 | 788 | $uses = 1; |
789 | 789 | } |
790 | 790 | |
791 | - update_post_meta( $id, '_wpi_discount_uses', $uses ); |
|
791 | + update_post_meta($id, '_wpi_discount_uses', $uses); |
|
792 | 792 | |
793 | - do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code ); |
|
793 | + do_action('wpinv_discount_increase_use_count', $uses, $id, $code); |
|
794 | 794 | |
795 | 795 | return $uses; |
796 | 796 | |
797 | 797 | } |
798 | 798 | |
799 | -function wpinv_decrease_discount_usage( $code ) { |
|
799 | +function wpinv_decrease_discount_usage($code) { |
|
800 | 800 | |
801 | - $id = wpinv_get_discount_id_by_code( $code ); |
|
802 | - $uses = wpinv_get_discount_uses( $id ); |
|
801 | + $id = wpinv_get_discount_id_by_code($code); |
|
802 | + $uses = wpinv_get_discount_uses($id); |
|
803 | 803 | |
804 | - if ( $uses ) { |
|
804 | + if ($uses) { |
|
805 | 805 | $uses--; |
806 | 806 | } |
807 | 807 | |
808 | - if ( $uses < 0 ) { |
|
808 | + if ($uses < 0) { |
|
809 | 809 | $uses = 0; |
810 | 810 | } |
811 | 811 | |
812 | - update_post_meta( $id, '_wpi_discount_uses', $uses ); |
|
812 | + update_post_meta($id, '_wpi_discount_uses', $uses); |
|
813 | 813 | |
814 | - do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code ); |
|
814 | + do_action('wpinv_discount_decrease_use_count', $uses, $id, $code); |
|
815 | 815 | |
816 | 816 | return $uses; |
817 | 817 | |
818 | 818 | } |
819 | 819 | |
820 | -function wpinv_format_discount_rate( $type, $amount ) { |
|
821 | - if ( $type == 'flat' ) { |
|
822 | - return wpinv_price( wpinv_format_amount( $amount ) ); |
|
820 | +function wpinv_format_discount_rate($type, $amount) { |
|
821 | + if ($type == 'flat') { |
|
822 | + return wpinv_price(wpinv_format_amount($amount)); |
|
823 | 823 | } else { |
824 | 824 | return $amount . '%'; |
825 | 825 | } |
826 | 826 | } |
827 | 827 | |
828 | -function wpinv_set_cart_discount( $code = '' ) { |
|
829 | - if ( wpinv_multiple_discounts_allowed() ) { |
|
828 | +function wpinv_set_cart_discount($code = '') { |
|
829 | + if (wpinv_multiple_discounts_allowed()) { |
|
830 | 830 | // Get all active cart discounts |
831 | 831 | $discounts = wpinv_get_cart_discounts(); |
832 | 832 | } else { |
833 | 833 | $discounts = false; // Only one discount allowed per purchase, so override any existing |
834 | 834 | } |
835 | 835 | |
836 | - if ( $discounts ) { |
|
837 | - $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) ); |
|
838 | - if( false !== $key ) { |
|
839 | - unset( $discounts[ $key ] ); // Can't set the same discount more than once |
|
836 | + if ($discounts) { |
|
837 | + $key = array_search(strtolower($code), array_map('strtolower', $discounts)); |
|
838 | + if (false !== $key) { |
|
839 | + unset($discounts[$key]); // Can't set the same discount more than once |
|
840 | 840 | } |
841 | 841 | $discounts[] = $code; |
842 | 842 | } else { |
843 | 843 | $discounts = array(); |
844 | 844 | $discounts[] = $code; |
845 | 845 | } |
846 | - $discounts = array_values( $discounts ); |
|
846 | + $discounts = array_values($discounts); |
|
847 | 847 | |
848 | 848 | $data = wpinv_get_checkout_session(); |
849 | - if ( empty( $data ) ) { |
|
849 | + if (empty($data)) { |
|
850 | 850 | $data = array(); |
851 | 851 | } else { |
852 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
853 | - $payment_meta['user_info']['discount'] = implode( ',', $discounts ); |
|
854 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
852 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
853 | + $payment_meta['user_info']['discount'] = implode(',', $discounts); |
|
854 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
855 | 855 | } |
856 | 856 | } |
857 | 857 | $data['cart_discounts'] = $discounts; |
858 | 858 | |
859 | - wpinv_set_checkout_session( $data ); |
|
859 | + wpinv_set_checkout_session($data); |
|
860 | 860 | |
861 | 861 | return $discounts; |
862 | 862 | } |
863 | 863 | |
864 | -function wpinv_unset_cart_discount( $code = '' ) { |
|
864 | +function wpinv_unset_cart_discount($code = '') { |
|
865 | 865 | $discounts = wpinv_get_cart_discounts(); |
866 | 866 | |
867 | - if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) { |
|
868 | - $key = array_search( $code, $discounts ); |
|
869 | - unset( $discounts[ $key ] ); |
|
867 | + if ($code && !empty($discounts) && in_array($code, $discounts)) { |
|
868 | + $key = array_search($code, $discounts); |
|
869 | + unset($discounts[$key]); |
|
870 | 870 | |
871 | 871 | $data = wpinv_get_checkout_session(); |
872 | 872 | $data['cart_discounts'] = $discounts; |
873 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
874 | - $payment_meta['user_info']['discount'] = !empty( $discounts ) ? implode( ',', $discounts ) : ''; |
|
875 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
873 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
874 | + $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : ''; |
|
875 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
876 | 876 | } |
877 | 877 | |
878 | - wpinv_set_checkout_session( $data ); |
|
878 | + wpinv_set_checkout_session($data); |
|
879 | 879 | } |
880 | 880 | |
881 | 881 | return $discounts; |
@@ -884,27 +884,27 @@ discard block |
||
884 | 884 | function wpinv_unset_all_cart_discounts() { |
885 | 885 | $data = wpinv_get_checkout_session(); |
886 | 886 | |
887 | - if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) { |
|
888 | - unset( $data['cart_discounts'] ); |
|
887 | + if (!empty($data) && isset($data['cart_discounts'])) { |
|
888 | + unset($data['cart_discounts']); |
|
889 | 889 | |
890 | - wpinv_set_checkout_session( $data ); |
|
890 | + wpinv_set_checkout_session($data); |
|
891 | 891 | return true; |
892 | 892 | } |
893 | 893 | |
894 | 894 | return false; |
895 | 895 | } |
896 | 896 | |
897 | -function wpinv_get_cart_discounts( $items = array() ) { |
|
897 | +function wpinv_get_cart_discounts($items = array()) { |
|
898 | 898 | $session = wpinv_get_checkout_session(); |
899 | 899 | |
900 | - $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false; |
|
900 | + $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false; |
|
901 | 901 | return $discounts; |
902 | 902 | } |
903 | 903 | |
904 | -function wpinv_cart_has_discounts( $items = array() ) { |
|
904 | +function wpinv_cart_has_discounts($items = array()) { |
|
905 | 905 | $ret = false; |
906 | 906 | |
907 | - if ( wpinv_get_cart_discounts( $items ) ) { |
|
907 | + if (wpinv_get_cart_discounts($items)) { |
|
908 | 908 | $ret = true; |
909 | 909 | } |
910 | 910 | |
@@ -915,131 +915,131 @@ discard block |
||
915 | 915 | } |
916 | 916 | */ |
917 | 917 | |
918 | - return apply_filters( 'wpinv_cart_has_discounts', $ret ); |
|
918 | + return apply_filters('wpinv_cart_has_discounts', $ret); |
|
919 | 919 | } |
920 | 920 | |
921 | -function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) { |
|
921 | +function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) { |
|
922 | 922 | $amount = 0.00; |
923 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
923 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
924 | 924 | |
925 | - if ( $items ) { |
|
926 | - $discounts = wp_list_pluck( $items, 'discount' ); |
|
925 | + if ($items) { |
|
926 | + $discounts = wp_list_pluck($items, 'discount'); |
|
927 | 927 | |
928 | - if ( is_array( $discounts ) ) { |
|
929 | - $discounts = array_map( 'floatval', $discounts ); |
|
930 | - $amount = array_sum( $discounts ); |
|
928 | + if (is_array($discounts)) { |
|
929 | + $discounts = array_map('floatval', $discounts); |
|
930 | + $amount = array_sum($discounts); |
|
931 | 931 | } |
932 | 932 | } |
933 | 933 | |
934 | - return apply_filters( 'wpinv_get_cart_discounted_amount', $amount ); |
|
934 | + return apply_filters('wpinv_get_cart_discounted_amount', $amount); |
|
935 | 935 | } |
936 | 936 | |
937 | -function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) { |
|
938 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
937 | +function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) { |
|
938 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
939 | 939 | |
940 | - if ( empty( $discount ) || empty( $items ) ) { |
|
940 | + if (empty($discount) || empty($items)) { |
|
941 | 941 | return 0; |
942 | 942 | } |
943 | 943 | |
944 | 944 | $amount = 0; |
945 | 945 | |
946 | - foreach ( $items as $item ) { |
|
947 | - $amount += wpinv_get_cart_item_discount_amount( $item, $discount ); |
|
946 | + foreach ($items as $item) { |
|
947 | + $amount += wpinv_get_cart_item_discount_amount($item, $discount); |
|
948 | 948 | } |
949 | 949 | |
950 | - $amount = wpinv_format_amount( $amount ); |
|
950 | + $amount = wpinv_format_amount($amount); |
|
951 | 951 | |
952 | 952 | return $amount; |
953 | 953 | } |
954 | 954 | |
955 | -function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) { |
|
955 | +function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) { |
|
956 | 956 | global $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
957 | 957 | |
958 | 958 | $amount = 0; |
959 | 959 | |
960 | - if ( empty( $item ) || empty( $item['id'] ) ) { |
|
960 | + if (empty($item) || empty($item['id'])) { |
|
961 | 961 | return $amount; |
962 | 962 | } |
963 | 963 | |
964 | - if ( empty( $item['quantity'] ) ) { |
|
964 | + if (empty($item['quantity'])) { |
|
965 | 965 | return $amount; |
966 | 966 | } |
967 | 967 | |
968 | - if ( empty( $item['options'] ) ) { |
|
968 | + if (empty($item['options'])) { |
|
969 | 969 | $item['options'] = array(); |
970 | 970 | } |
971 | 971 | |
972 | - $price = wpinv_get_cart_item_price( $item['id'], $item['options'] ); |
|
972 | + $price = wpinv_get_cart_item_price($item['id'], $item['options']); |
|
973 | 973 | $discounted_price = $price; |
974 | 974 | |
975 | 975 | $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount; |
976 | - if ( empty( $discounts ) ) { |
|
976 | + if (empty($discounts)) { |
|
977 | 977 | return $amount; |
978 | 978 | } |
979 | 979 | |
980 | - if ( $discounts ) { |
|
981 | - if ( is_array( $discounts ) ) { |
|
982 | - $discounts = array_values( $discounts ); |
|
980 | + if ($discounts) { |
|
981 | + if (is_array($discounts)) { |
|
982 | + $discounts = array_values($discounts); |
|
983 | 983 | } else { |
984 | - $discounts = explode( ',', $discounts ); |
|
984 | + $discounts = explode(',', $discounts); |
|
985 | 985 | } |
986 | 986 | } |
987 | 987 | |
988 | - if( $discounts ) { |
|
989 | - foreach ( $discounts as $discount ) { |
|
990 | - $code_id = wpinv_get_discount_id_by_code( $discount ); |
|
988 | + if ($discounts) { |
|
989 | + foreach ($discounts as $discount) { |
|
990 | + $code_id = wpinv_get_discount_id_by_code($discount); |
|
991 | 991 | |
992 | 992 | // Check discount exists |
993 | - if( ! $code_id ) { |
|
993 | + if (!$code_id) { |
|
994 | 994 | continue; |
995 | 995 | } |
996 | 996 | |
997 | - $reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
998 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
997 | + $reqs = wpinv_get_discount_item_reqs($code_id); |
|
998 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
999 | 999 | |
1000 | 1000 | // Make sure requirements are set and that this discount shouldn't apply to the whole cart |
1001 | - if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) { |
|
1002 | - foreach ( $reqs as $item_id ) { |
|
1003 | - if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) { |
|
1004 | - $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price ); |
|
1001 | + if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) { |
|
1002 | + foreach ($reqs as $item_id) { |
|
1003 | + if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) { |
|
1004 | + $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price); |
|
1005 | 1005 | } |
1006 | 1006 | } |
1007 | 1007 | } else { |
1008 | 1008 | // This is a global cart discount |
1009 | - if ( !in_array( $item['id'], $excluded_items ) ) { |
|
1010 | - if ( 'flat' === wpinv_get_discount_type( $code_id ) ) { |
|
1009 | + if (!in_array($item['id'], $excluded_items)) { |
|
1010 | + if ('flat' === wpinv_get_discount_type($code_id)) { |
|
1011 | 1011 | $items_subtotal = 0.00; |
1012 | 1012 | $cart_items = wpinv_get_cart_contents(); |
1013 | 1013 | |
1014 | - foreach ( $cart_items as $cart_item ) { |
|
1015 | - if ( ! in_array( $cart_item['id'], $excluded_items ) ) { |
|
1016 | - $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array(); |
|
1017 | - $item_price = wpinv_get_cart_item_price( $cart_item['id'], $options ); |
|
1014 | + foreach ($cart_items as $cart_item) { |
|
1015 | + if (!in_array($cart_item['id'], $excluded_items)) { |
|
1016 | + $options = !empty($cart_item['options']) ? $cart_item['options'] : array(); |
|
1017 | + $item_price = wpinv_get_cart_item_price($cart_item['id'], $options); |
|
1018 | 1018 | $items_subtotal += $item_price * $cart_item['quantity']; |
1019 | 1019 | } |
1020 | 1020 | } |
1021 | 1021 | |
1022 | - $subtotal_percent = ( ( $price * $item['quantity'] ) / $items_subtotal ); |
|
1023 | - $code_amount = wpinv_get_discount_amount( $code_id ); |
|
1022 | + $subtotal_percent = (($price * $item['quantity']) / $items_subtotal); |
|
1023 | + $code_amount = wpinv_get_discount_amount($code_id); |
|
1024 | 1024 | $discounted_amount = $code_amount * $subtotal_percent; |
1025 | 1025 | $discounted_price -= $discounted_amount; |
1026 | 1026 | |
1027 | - $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() ); |
|
1027 | + $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter()); |
|
1028 | 1028 | |
1029 | - if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) { |
|
1029 | + if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) { |
|
1030 | 1030 | $adjustment = $code_amount - $wpinv_flat_discount_total; |
1031 | 1031 | $discounted_price -= $adjustment; |
1032 | 1032 | } |
1033 | 1033 | } else { |
1034 | - $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price ); |
|
1034 | + $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price); |
|
1035 | 1035 | } |
1036 | 1036 | } |
1037 | 1037 | } |
1038 | 1038 | } |
1039 | 1039 | |
1040 | - $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) ); |
|
1040 | + $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price)); |
|
1041 | 1041 | |
1042 | - if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) { |
|
1042 | + if ('flat' !== wpinv_get_discount_type($code_id)) { |
|
1043 | 1043 | $amount = $amount * $item['quantity']; |
1044 | 1044 | } |
1045 | 1045 | } |
@@ -1047,59 +1047,59 @@ discard block |
||
1047 | 1047 | return $amount; |
1048 | 1048 | } |
1049 | 1049 | |
1050 | -function wpinv_cart_discounts_html( $items = array() ) { |
|
1051 | - echo wpinv_get_cart_discounts_html( $items ); |
|
1050 | +function wpinv_cart_discounts_html($items = array()) { |
|
1051 | + echo wpinv_get_cart_discounts_html($items); |
|
1052 | 1052 | } |
1053 | 1053 | |
1054 | -function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) { |
|
1054 | +function wpinv_get_cart_discounts_html($items = array(), $discounts = false) { |
|
1055 | 1055 | global $wpi_cart_columns; |
1056 | 1056 | |
1057 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
1057 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
1058 | 1058 | |
1059 | - if ( !$discounts ) { |
|
1060 | - $discounts = wpinv_get_cart_discounts( $items ); |
|
1059 | + if (!$discounts) { |
|
1060 | + $discounts = wpinv_get_cart_discounts($items); |
|
1061 | 1061 | } |
1062 | 1062 | |
1063 | - if ( !$discounts ) { |
|
1063 | + if (!$discounts) { |
|
1064 | 1064 | return; |
1065 | 1065 | } |
1066 | 1066 | |
1067 | - $discounts = is_array( $discounts ) ? $discounts : array( $discounts ); |
|
1067 | + $discounts = is_array($discounts) ? $discounts : array($discounts); |
|
1068 | 1068 | |
1069 | 1069 | $html = ''; |
1070 | 1070 | |
1071 | - foreach ( $discounts as $discount ) { |
|
1072 | - $discount_id = wpinv_get_discount_id_by_code( $discount ); |
|
1073 | - $discount_value = wpinv_get_discount_amount( $discount_id ); |
|
1074 | - $rate = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value ); |
|
1075 | - $amount = wpinv_get_cart_items_discount_amount( $items, $discount ); |
|
1076 | - $remove_btn = '<a title="' . esc_attr__( 'Remove discount', 'invoicing' ) . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
1071 | + foreach ($discounts as $discount) { |
|
1072 | + $discount_id = wpinv_get_discount_id_by_code($discount); |
|
1073 | + $discount_value = wpinv_get_discount_amount($discount_id); |
|
1074 | + $rate = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value); |
|
1075 | + $amount = wpinv_get_cart_items_discount_amount($items, $discount); |
|
1076 | + $remove_btn = '<a title="' . esc_attr__('Remove discount', 'invoicing') . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
1077 | 1077 | |
1078 | 1078 | $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">'; |
1079 | 1079 | ob_start(); |
1080 | - do_action( 'wpinv_checkout_table_discount_first', $items ); |
|
1080 | + do_action('wpinv_checkout_table_discount_first', $items); |
|
1081 | 1081 | $html .= ob_get_clean(); |
1082 | - $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label( $discount, $rate, false ) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price( $amount ) . '</span></td>'; |
|
1082 | + $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label($discount, $rate, false) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price($amount) . '</span></td>'; |
|
1083 | 1083 | ob_start(); |
1084 | - do_action( 'wpinv_checkout_table_discount_last', $items ); |
|
1084 | + do_action('wpinv_checkout_table_discount_last', $items); |
|
1085 | 1085 | $html .= ob_get_clean(); |
1086 | 1086 | $html .= '</tr>'; |
1087 | 1087 | } |
1088 | 1088 | |
1089 | - return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate ); |
|
1089 | + return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate); |
|
1090 | 1090 | } |
1091 | 1091 | |
1092 | -function wpinv_display_cart_discount( $formatted = false, $echo = false ) { |
|
1092 | +function wpinv_display_cart_discount($formatted = false, $echo = false) { |
|
1093 | 1093 | $discounts = wpinv_get_cart_discounts(); |
1094 | 1094 | |
1095 | - if ( empty( $discounts ) ) { |
|
1095 | + if (empty($discounts)) { |
|
1096 | 1096 | return false; |
1097 | 1097 | } |
1098 | 1098 | |
1099 | - $discount_id = wpinv_get_discount_id_by_code( $discounts[0] ); |
|
1100 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) ); |
|
1099 | + $discount_id = wpinv_get_discount_id_by_code($discounts[0]); |
|
1100 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id)); |
|
1101 | 1101 | |
1102 | - if ( $echo ) { |
|
1102 | + if ($echo) { |
|
1103 | 1103 | echo $amount; |
1104 | 1104 | } |
1105 | 1105 | |
@@ -1107,133 +1107,133 @@ discard block |
||
1107 | 1107 | } |
1108 | 1108 | |
1109 | 1109 | function wpinv_remove_cart_discount() { |
1110 | - if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) { |
|
1110 | + if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) { |
|
1111 | 1111 | return; |
1112 | 1112 | } |
1113 | 1113 | |
1114 | - do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
1114 | + do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id'])); |
|
1115 | 1115 | |
1116 | - wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) ); |
|
1116 | + wpinv_unset_cart_discount(urldecode($_GET['discount_code'])); |
|
1117 | 1117 | |
1118 | - do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
1118 | + do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id'])); |
|
1119 | 1119 | |
1120 | - wp_redirect( wpinv_get_checkout_uri() ); wpinv_die(); |
|
1120 | + wp_redirect(wpinv_get_checkout_uri()); wpinv_die(); |
|
1121 | 1121 | } |
1122 | -add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' ); |
|
1122 | +add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount'); |
|
1123 | 1123 | |
1124 | -function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) { |
|
1124 | +function wpinv_maybe_remove_cart_discount($cart_key = 0) { |
|
1125 | 1125 | $discounts = wpinv_get_cart_discounts(); |
1126 | 1126 | |
1127 | - if ( !$discounts ) { |
|
1127 | + if (!$discounts) { |
|
1128 | 1128 | return; |
1129 | 1129 | } |
1130 | 1130 | |
1131 | - foreach ( $discounts as $discount ) { |
|
1132 | - if ( !wpinv_is_discount_valid( $discount ) ) { |
|
1133 | - wpinv_unset_cart_discount( $discount ); |
|
1131 | + foreach ($discounts as $discount) { |
|
1132 | + if (!wpinv_is_discount_valid($discount)) { |
|
1133 | + wpinv_unset_cart_discount($discount); |
|
1134 | 1134 | } |
1135 | 1135 | } |
1136 | 1136 | } |
1137 | -add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' ); |
|
1137 | +add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount'); |
|
1138 | 1138 | |
1139 | 1139 | function wpinv_multiple_discounts_allowed() { |
1140 | - $ret = wpinv_get_option( 'allow_multiple_discounts', false ); |
|
1141 | - return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret ); |
|
1140 | + $ret = wpinv_get_option('allow_multiple_discounts', false); |
|
1141 | + return (bool)apply_filters('wpinv_multiple_discounts_allowed', $ret); |
|
1142 | 1142 | } |
1143 | 1143 | |
1144 | 1144 | function wpinv_listen_for_cart_discount() { |
1145 | 1145 | global $wpi_session; |
1146 | 1146 | |
1147 | - if ( empty( $_REQUEST['discount'] ) || is_array( $_REQUEST['discount'] ) ) { |
|
1147 | + if (empty($_REQUEST['discount']) || is_array($_REQUEST['discount'])) { |
|
1148 | 1148 | return; |
1149 | 1149 | } |
1150 | 1150 | |
1151 | - $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount'] ); |
|
1151 | + $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount']); |
|
1152 | 1152 | |
1153 | - $wpi_session->set( 'preset_discount', $code ); |
|
1153 | + $wpi_session->set('preset_discount', $code); |
|
1154 | 1154 | } |
1155 | 1155 | //add_action( 'init', 'wpinv_listen_for_cart_discount', 0 ); |
1156 | 1156 | |
1157 | 1157 | function wpinv_apply_preset_discount() { |
1158 | 1158 | global $wpi_session; |
1159 | 1159 | |
1160 | - $code = $wpi_session->get( 'preset_discount' ); |
|
1160 | + $code = $wpi_session->get('preset_discount'); |
|
1161 | 1161 | |
1162 | - if ( !$code ) { |
|
1162 | + if (!$code) { |
|
1163 | 1163 | return; |
1164 | 1164 | } |
1165 | 1165 | |
1166 | - if ( !wpinv_is_discount_valid( $code, '', false ) ) { |
|
1166 | + if (!wpinv_is_discount_valid($code, '', false)) { |
|
1167 | 1167 | return; |
1168 | 1168 | } |
1169 | 1169 | |
1170 | - $code = apply_filters( 'wpinv_apply_preset_discount', $code ); |
|
1170 | + $code = apply_filters('wpinv_apply_preset_discount', $code); |
|
1171 | 1171 | |
1172 | - wpinv_set_cart_discount( $code ); |
|
1172 | + wpinv_set_cart_discount($code); |
|
1173 | 1173 | |
1174 | - $wpi_session->set( 'preset_discount', null ); |
|
1174 | + $wpi_session->set('preset_discount', null); |
|
1175 | 1175 | } |
1176 | 1176 | //add_action( 'init', 'wpinv_apply_preset_discount', 999 ); |
1177 | 1177 | |
1178 | -function wpinv_get_discount_label( $code, $echo = true ) { |
|
1179 | - $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) ); |
|
1180 | - $label = apply_filters( 'wpinv_get_discount_label', $label, $code ); |
|
1178 | +function wpinv_get_discount_label($code, $echo = true) { |
|
1179 | + $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : '')); |
|
1180 | + $label = apply_filters('wpinv_get_discount_label', $label, $code); |
|
1181 | 1181 | |
1182 | - if ( $echo ) { |
|
1182 | + if ($echo) { |
|
1183 | 1183 | echo $label; |
1184 | 1184 | } else { |
1185 | 1185 | return $label; |
1186 | 1186 | } |
1187 | 1187 | } |
1188 | 1188 | |
1189 | -function wpinv_cart_discount_label( $code, $rate, $echo = true ) { |
|
1190 | - $label = wp_sprintf( __( '%1$s Discount: %2$s', 'invoicing' ), $rate, $code ); |
|
1191 | - $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate ); |
|
1189 | +function wpinv_cart_discount_label($code, $rate, $echo = true) { |
|
1190 | + $label = wp_sprintf(__('%1$s Discount: %2$s', 'invoicing'), $rate, $code); |
|
1191 | + $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate); |
|
1192 | 1192 | |
1193 | - if ( $echo ) { |
|
1193 | + if ($echo) { |
|
1194 | 1194 | echo $label; |
1195 | 1195 | } else { |
1196 | 1196 | return $label; |
1197 | 1197 | } |
1198 | 1198 | } |
1199 | 1199 | |
1200 | -function wpinv_check_delete_discount( $check, $post, $force_delete ) { |
|
1201 | - if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) { |
|
1200 | +function wpinv_check_delete_discount($check, $post, $force_delete) { |
|
1201 | + if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) { |
|
1202 | 1202 | return true; |
1203 | 1203 | } |
1204 | 1204 | |
1205 | 1205 | return $check; |
1206 | 1206 | } |
1207 | -add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 ); |
|
1207 | +add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3); |
|
1208 | 1208 | |
1209 | 1209 | function wpinv_checkout_form_validate_discounts() { |
1210 | 1210 | $discounts = wpinv_get_cart_discounts(); |
1211 | 1211 | |
1212 | - if ( !empty( $discounts ) ) { |
|
1212 | + if (!empty($discounts)) { |
|
1213 | 1213 | $invalid = false; |
1214 | 1214 | |
1215 | - foreach ( $discounts as $key => $code ) { |
|
1216 | - if ( !wpinv_is_discount_valid( $code, get_current_user_id() ) ) { |
|
1215 | + foreach ($discounts as $key => $code) { |
|
1216 | + if (!wpinv_is_discount_valid($code, get_current_user_id())) { |
|
1217 | 1217 | $invalid = true; |
1218 | 1218 | |
1219 | - wpinv_unset_cart_discount( $code ); |
|
1219 | + wpinv_unset_cart_discount($code); |
|
1220 | 1220 | } |
1221 | 1221 | } |
1222 | 1222 | |
1223 | - if ( $invalid ) { |
|
1223 | + if ($invalid) { |
|
1224 | 1224 | $errors = wpinv_get_errors(); |
1225 | - $error = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
1226 | - $error .= __( 'The discount has been removed from cart.', 'invoicing' ); |
|
1227 | - wpinv_set_error( 'wpinv-discount-error', $error ); |
|
1225 | + $error = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
1226 | + $error .= __('The discount has been removed from cart.', 'invoicing'); |
|
1227 | + wpinv_set_error('wpinv-discount-error', $error); |
|
1228 | 1228 | |
1229 | - wpinv_recalculate_tax( true ); |
|
1229 | + wpinv_recalculate_tax(true); |
|
1230 | 1230 | } |
1231 | 1231 | } |
1232 | 1232 | } |
1233 | -add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 ); |
|
1233 | +add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10); |
|
1234 | 1234 | |
1235 | 1235 | function wpinv_discount_amount() { |
1236 | 1236 | $output = 0.00; |
1237 | 1237 | |
1238 | - return apply_filters( 'wpinv_discount_amount', $output ); |
|
1238 | + return apply_filters('wpinv_discount_amount', $output); |
|
1239 | 1239 | } |
1240 | 1240 | \ No newline at end of file |
@@ -1,121 +1,121 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | function wpinv_use_taxes() { |
8 | - $ret = wpinv_get_option( 'enable_taxes', false ); |
|
8 | + $ret = wpinv_get_option('enable_taxes', false); |
|
9 | 9 | |
10 | - return (bool) apply_filters( 'wpinv_use_taxes', $ret ); |
|
10 | + return (bool)apply_filters('wpinv_use_taxes', $ret); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | function wpinv_get_tax_rates() { |
14 | - $rates = get_option( 'wpinv_tax_rates', array() ); |
|
14 | + $rates = get_option('wpinv_tax_rates', array()); |
|
15 | 15 | |
16 | - return apply_filters( 'wpinv_get_tax_rates', $rates ); |
|
16 | + return apply_filters('wpinv_get_tax_rates', $rates); |
|
17 | 17 | } |
18 | 18 | |
19 | -function wpinv_get_tax_rate( $country = false, $state = false, $item_id = 0 ) { |
|
19 | +function wpinv_get_tax_rate($country = false, $state = false, $item_id = 0) { |
|
20 | 20 | global $wpinv_euvat, $wpi_tax_rates, $wpi_userID; |
21 | - $wpi_tax_rates = !empty( $wpi_tax_rates ) ? $wpi_tax_rates : array(); |
|
21 | + $wpi_tax_rates = !empty($wpi_tax_rates) ? $wpi_tax_rates : array(); |
|
22 | 22 | |
23 | - if ( !empty( $wpi_tax_rates ) && !empty( $item_id ) && isset( $wpi_tax_rates[$item_id] ) ) { |
|
23 | + if (!empty($wpi_tax_rates) && !empty($item_id) && isset($wpi_tax_rates[$item_id])) { |
|
24 | 24 | return $wpi_tax_rates[$item_id]; |
25 | 25 | } |
26 | 26 | |
27 | - if ( !$wpinv_euvat->item_is_taxable( $item_id, $country, $state ) ) { |
|
27 | + if (!$wpinv_euvat->item_is_taxable($item_id, $country, $state)) { |
|
28 | 28 | $wpi_tax_rates[$item_id] = 0; |
29 | 29 | return 0; |
30 | 30 | } |
31 | 31 | |
32 | 32 | $is_global = false; |
33 | - if ( $item_id == 'global' ) { |
|
33 | + if ($item_id == 'global') { |
|
34 | 34 | $is_global = true; |
35 | 35 | $item_id = 0; |
36 | 36 | } |
37 | 37 | |
38 | - $rate = (float)wpinv_get_option( 'tax_rate', 0 ); |
|
39 | - $user_address = wpinv_get_user_address( $wpi_userID ); |
|
38 | + $rate = (float)wpinv_get_option('tax_rate', 0); |
|
39 | + $user_address = wpinv_get_user_address($wpi_userID); |
|
40 | 40 | |
41 | - if( empty( $country ) ) { |
|
42 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
41 | + if (empty($country)) { |
|
42 | + if (!empty($_POST['wpinv_country'])) { |
|
43 | 43 | $country = $_POST['wpinv_country']; |
44 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
44 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
45 | 45 | $country = $_POST['wpinv_country']; |
46 | - } elseif( !empty( $_POST['country'] ) ) { |
|
46 | + } elseif (!empty($_POST['country'])) { |
|
47 | 47 | $country = $_POST['country']; |
48 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
48 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
49 | 49 | $country = $user_address['country']; |
50 | 50 | } |
51 | - $country = !empty( $country ) ? $country : wpinv_get_default_country(); |
|
51 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
52 | 52 | } |
53 | 53 | |
54 | - if( empty( $state ) ) { |
|
55 | - if( !empty( $_POST['wpinv_state'] ) ) { |
|
54 | + if (empty($state)) { |
|
55 | + if (!empty($_POST['wpinv_state'])) { |
|
56 | 56 | $state = $_POST['wpinv_state']; |
57 | - } elseif( !empty( $_POST['wpinv_state'] ) ) { |
|
57 | + } elseif (!empty($_POST['wpinv_state'])) { |
|
58 | 58 | $state = $_POST['wpinv_state']; |
59 | - } elseif( !empty( $_POST['state'] ) ) { |
|
59 | + } elseif (!empty($_POST['state'])) { |
|
60 | 60 | $state = $_POST['state']; |
61 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
61 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
62 | 62 | $state = $user_address['state']; |
63 | 63 | } |
64 | - $state = !empty( $state ) ? $state : wpinv_get_default_state(); |
|
64 | + $state = !empty($state) ? $state : wpinv_get_default_state(); |
|
65 | 65 | } |
66 | 66 | |
67 | - if( !empty( $country ) ) { |
|
68 | - $tax_rates = wpinv_get_tax_rates(); |
|
67 | + if (!empty($country)) { |
|
68 | + $tax_rates = wpinv_get_tax_rates(); |
|
69 | 69 | |
70 | - if( !empty( $tax_rates ) ) { |
|
70 | + if (!empty($tax_rates)) { |
|
71 | 71 | // Locate the tax rate for this country / state, if it exists |
72 | - foreach( $tax_rates as $key => $tax_rate ) { |
|
73 | - if( $country != $tax_rate['country'] ) |
|
72 | + foreach ($tax_rates as $key => $tax_rate) { |
|
73 | + if ($country != $tax_rate['country']) |
|
74 | 74 | continue; |
75 | 75 | |
76 | - if( !empty( $tax_rate['global'] ) ) { |
|
77 | - if( !empty( $tax_rate['rate'] ) ) { |
|
78 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
76 | + if (!empty($tax_rate['global'])) { |
|
77 | + if (!empty($tax_rate['rate'])) { |
|
78 | + $rate = number_format($tax_rate['rate'], 4); |
|
79 | 79 | } |
80 | 80 | } else { |
81 | 81 | |
82 | - if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
82 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
83 | 83 | continue; |
84 | 84 | |
85 | 85 | $state_rate = $tax_rate['rate']; |
86 | - if( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
87 | - $rate = number_format( $state_rate, 4 ); |
|
86 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
87 | + $rate = number_format($state_rate, 4); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | - $rate = apply_filters( 'wpinv_tax_rate', $rate, $country, $state, $item_id ); |
|
94 | + $rate = apply_filters('wpinv_tax_rate', $rate, $country, $state, $item_id); |
|
95 | 95 | |
96 | - if ( !empty( $item_id ) ) { |
|
96 | + if (!empty($item_id)) { |
|
97 | 97 | $wpi_tax_rates[$item_id] = $rate; |
98 | - } else if ( $is_global ) { |
|
98 | + } else if ($is_global) { |
|
99 | 99 | $wpi_tax_rates['global'] = $rate; |
100 | 100 | } |
101 | 101 | |
102 | 102 | return $rate; |
103 | 103 | } |
104 | 104 | |
105 | -function wpinv_get_formatted_tax_rate( $country = false, $state = false, $item_id ) { |
|
106 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
107 | - $rate = round( $rate, 4 ); |
|
105 | +function wpinv_get_formatted_tax_rate($country = false, $state = false, $item_id) { |
|
106 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
107 | + $rate = round($rate, 4); |
|
108 | 108 | $formatted = $rate .= '%'; |
109 | - return apply_filters( 'wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id ); |
|
109 | + return apply_filters('wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id); |
|
110 | 110 | } |
111 | 111 | |
112 | -function wpinv_calculate_tax( $amount = 0, $country = false, $state = false, $item_id = 0 ) { |
|
113 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
112 | +function wpinv_calculate_tax($amount = 0, $country = false, $state = false, $item_id = 0) { |
|
113 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
114 | 114 | $tax = 0.00; |
115 | 115 | |
116 | - if ( wpinv_use_taxes() ) { |
|
117 | - if ( wpinv_prices_include_tax() ) { |
|
118 | - $pre_tax = ( $amount / ( ( 1 + $rate ) * 0.01 ) ); |
|
116 | + if (wpinv_use_taxes()) { |
|
117 | + if (wpinv_prices_include_tax()) { |
|
118 | + $pre_tax = ($amount / ((1 + $rate) * 0.01)); |
|
119 | 119 | $tax = $amount - $pre_tax; |
120 | 120 | } else { |
121 | 121 | $tax = $amount * $rate * 0.01; |
@@ -123,46 +123,46 @@ discard block |
||
123 | 123 | |
124 | 124 | } |
125 | 125 | |
126 | - return apply_filters( 'wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id ); |
|
126 | + return apply_filters('wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | function wpinv_prices_include_tax() { |
130 | 130 | return false; // TODO |
131 | - $ret = ( wpinv_get_option( 'prices_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
131 | + $ret = (wpinv_get_option('prices_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
132 | 132 | |
133 | - return apply_filters( 'wpinv_prices_include_tax', $ret ); |
|
133 | + return apply_filters('wpinv_prices_include_tax', $ret); |
|
134 | 134 | } |
135 | 135 | |
136 | -function wpinv_sales_tax_for_year( $year = null ) { |
|
137 | - return wpinv_price( wpinv_format_amount( wpinv_get_sales_tax_for_year( $year ) ) ); |
|
136 | +function wpinv_sales_tax_for_year($year = null) { |
|
137 | + return wpinv_price(wpinv_format_amount(wpinv_get_sales_tax_for_year($year))); |
|
138 | 138 | } |
139 | 139 | |
140 | -function wpinv_get_sales_tax_for_year( $year = null ) { |
|
140 | +function wpinv_get_sales_tax_for_year($year = null) { |
|
141 | 141 | global $wpdb; |
142 | 142 | |
143 | 143 | // Start at zero |
144 | 144 | $tax = 0; |
145 | 145 | |
146 | - if ( ! empty( $year ) ) { |
|
146 | + if (!empty($year)) { |
|
147 | 147 | $args = array( |
148 | 148 | 'post_type' => 'wpi_invoice', |
149 | - 'post_status' => array( 'publish', 'revoked' ), |
|
149 | + 'post_status' => array('publish', 'revoked'), |
|
150 | 150 | 'posts_per_page' => -1, |
151 | 151 | 'year' => $year, |
152 | 152 | 'fields' => 'ids' |
153 | 153 | ); |
154 | 154 | |
155 | - $payments = get_posts( $args ); |
|
156 | - $payment_ids = implode( ',', $payments ); |
|
155 | + $payments = get_posts($args); |
|
156 | + $payment_ids = implode(',', $payments); |
|
157 | 157 | |
158 | - if ( count( $payments ) > 0 ) { |
|
158 | + if (count($payments) > 0) { |
|
159 | 159 | $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )"; |
160 | - $tax = $wpdb->get_var( $sql ); |
|
160 | + $tax = $wpdb->get_var($sql); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | } |
164 | 164 | |
165 | - return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year ); |
|
165 | + return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | function wpinv_is_cart_taxed() { |
@@ -171,33 +171,33 @@ discard block |
||
171 | 171 | |
172 | 172 | function wpinv_prices_show_tax_on_checkout() { |
173 | 173 | return false; // TODO |
174 | - $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
174 | + $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
175 | 175 | |
176 | - return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret ); |
|
176 | + return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | function wpinv_display_tax_rate() { |
180 | - $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false ); |
|
180 | + $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false); |
|
181 | 181 | |
182 | - return apply_filters( 'wpinv_display_tax_rate', $ret ); |
|
182 | + return apply_filters('wpinv_display_tax_rate', $ret); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | function wpinv_cart_needs_tax_address_fields() { |
186 | - if( !wpinv_is_cart_taxed() ) |
|
186 | + if (!wpinv_is_cart_taxed()) |
|
187 | 187 | return false; |
188 | 188 | |
189 | - return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' ); |
|
189 | + return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields'); |
|
190 | 190 | } |
191 | 191 | |
192 | -function wpinv_item_is_tax_exclusive( $item_id = 0 ) { |
|
193 | - $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false ); |
|
194 | - return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id ); |
|
192 | +function wpinv_item_is_tax_exclusive($item_id = 0) { |
|
193 | + $ret = (bool)get_post_meta($item_id, '_wpinv_tax_exclusive', false); |
|
194 | + return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id); |
|
195 | 195 | } |
196 | 196 | |
197 | -function wpinv_currency_decimal_filter( $decimals = 2 ) { |
|
197 | +function wpinv_currency_decimal_filter($decimals = 2) { |
|
198 | 198 | $currency = wpinv_get_currency(); |
199 | 199 | |
200 | - switch ( $currency ) { |
|
200 | + switch ($currency) { |
|
201 | 201 | case 'RIAL' : |
202 | 202 | case 'JPY' : |
203 | 203 | case 'TWD' : |
@@ -206,48 +206,48 @@ discard block |
||
206 | 206 | break; |
207 | 207 | } |
208 | 208 | |
209 | - return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency ); |
|
209 | + return apply_filters('wpinv_currency_decimal_count', $decimals, $currency); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | function wpinv_tax_amount() { |
213 | 213 | $output = 0.00; |
214 | 214 | |
215 | - return apply_filters( 'wpinv_tax_amount', $output ); |
|
215 | + return apply_filters('wpinv_tax_amount', $output); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | function wpinv_recalculated_tax() { |
219 | - define( 'WPINV_RECALCTAX', true ); |
|
219 | + define('WPINV_RECALCTAX', true); |
|
220 | 220 | } |
221 | -add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1 ); |
|
221 | +add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1); |
|
222 | 222 | |
223 | -function wpinv_recalculate_tax( $return = false ) { |
|
223 | +function wpinv_recalculate_tax($return = false) { |
|
224 | 224 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
225 | - if ( empty( $invoice_id ) ) { |
|
225 | + if (empty($invoice_id)) { |
|
226 | 226 | return false; |
227 | 227 | } |
228 | 228 | |
229 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
229 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
230 | 230 | |
231 | - if ( empty( $invoice ) ) { |
|
231 | + if (empty($invoice)) { |
|
232 | 232 | return false; |
233 | 233 | } |
234 | 234 | |
235 | - if ( empty( $_POST['country'] ) ) { |
|
235 | + if (empty($_POST['country'])) { |
|
236 | 236 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
237 | 237 | } |
238 | 238 | |
239 | 239 | $invoice->country = sanitize_text_field($_POST['country']); |
240 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
240 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
241 | 241 | if (isset($_POST['state'])) { |
242 | 242 | $invoice->state = sanitize_text_field($_POST['state']); |
243 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
243 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | $invoice->cart_details = wpinv_get_cart_content_details(); |
247 | 247 | |
248 | - $subtotal = wpinv_get_cart_subtotal( $invoice->cart_details ); |
|
249 | - $tax = wpinv_get_cart_tax( $invoice->cart_details ); |
|
250 | - $total = wpinv_get_cart_total( $invoice->cart_details ); |
|
248 | + $subtotal = wpinv_get_cart_subtotal($invoice->cart_details); |
|
249 | + $tax = wpinv_get_cart_tax($invoice->cart_details); |
|
250 | + $total = wpinv_get_cart_total($invoice->cart_details); |
|
251 | 251 | |
252 | 252 | $invoice->tax = $tax; |
253 | 253 | $invoice->subtotal = $subtotal; |
@@ -255,60 +255,60 @@ discard block |
||
255 | 255 | |
256 | 256 | $invoice->save(); |
257 | 257 | |
258 | - if ( $invoice->is_free_trial() ) { |
|
258 | + if ($invoice->is_free_trial()) { |
|
259 | 259 | $total = 0; |
260 | 260 | } |
261 | 261 | |
262 | 262 | $response = array( |
263 | - 'total' => html_entity_decode( wpinv_price( wpinv_format_amount( $total ) ), ENT_COMPAT, 'UTF-8' ), |
|
263 | + 'total' => html_entity_decode(wpinv_price(wpinv_format_amount($total)), ENT_COMPAT, 'UTF-8'), |
|
264 | 264 | 'total_raw' => $total, |
265 | - 'html' => wpinv_checkout_cart( $invoice->cart_details, false ), |
|
265 | + 'html' => wpinv_checkout_cart($invoice->cart_details, false), |
|
266 | 266 | ); |
267 | 267 | |
268 | - if ( $return ) { |
|
268 | + if ($return) { |
|
269 | 269 | return $response; |
270 | 270 | } |
271 | 271 | |
272 | - wp_send_json( $response ); |
|
272 | + wp_send_json($response); |
|
273 | 273 | } |
274 | -add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax' ); |
|
275 | -add_action( 'wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax' ); |
|
274 | +add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax'); |
|
275 | +add_action('wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax'); |
|
276 | 276 | |
277 | 277 | // VAT Settings |
278 | -function wpinv_vat_rate_add_callback( $args ) { |
|
278 | +function wpinv_vat_rate_add_callback($args) { |
|
279 | 279 | ?> |
280 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e( 'Add', 'invoicing' );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
280 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
281 | 281 | <?php |
282 | 282 | } |
283 | 283 | |
284 | -function wpinv_vat_rate_delete_callback( $args ) { |
|
284 | +function wpinv_vat_rate_delete_callback($args) { |
|
285 | 285 | global $wpinv_euvat; |
286 | 286 | |
287 | 287 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
288 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : ''; |
|
289 | - if ( isset( $vat_classes[$vat_class] ) ) { |
|
288 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : ''; |
|
289 | + if (isset($vat_classes[$vat_class])) { |
|
290 | 290 | ?> |
291 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf( esc_attr__( 'Delete class "%s"', 'invoicing' ), $vat_classes[$vat_class] );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
291 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf(esc_attr__('Delete class "%s"', 'invoicing'), $vat_classes[$vat_class]); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
292 | 292 | <?php |
293 | 293 | } |
294 | 294 | } |
295 | 295 | |
296 | -function wpinv_vat_rates_callback( $args ) { |
|
296 | +function wpinv_vat_rates_callback($args) { |
|
297 | 297 | global $wpinv_euvat; |
298 | 298 | |
299 | 299 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
300 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_standard'; |
|
300 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_standard'; |
|
301 | 301 | |
302 | 302 | $eu_states = $wpinv_euvat->get_eu_states(); |
303 | 303 | $countries = wpinv_get_country_list(); |
304 | 304 | $vat_groups = $wpinv_euvat->get_vat_groups(); |
305 | - $rates = $wpinv_euvat->get_vat_rates( $vat_class ); |
|
305 | + $rates = $wpinv_euvat->get_vat_rates($vat_class); |
|
306 | 306 | ob_start(); |
307 | 307 | ?> |
308 | 308 | </td><tr> |
309 | 309 | <td colspan="2" class="wpinv_vat_tdbox"> |
310 | - <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class;?>" /> |
|
311 | - <p><?php echo ( isset( $args['desc'] ) ? $args['desc'] : '' ); ?></p> |
|
310 | + <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class; ?>" /> |
|
311 | + <p><?php echo (isset($args['desc']) ? $args['desc'] : ''); ?></p> |
|
312 | 312 | <table id="wpinv_vat_rates" class="wp-list-table widefat fixed posts"> |
313 | 313 | <colgroup> |
314 | 314 | <col width="50px" /> |
@@ -320,43 +320,43 @@ discard block |
||
320 | 320 | </colgroup> |
321 | 321 | <thead> |
322 | 322 | <tr> |
323 | - <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e( 'Country', 'invoicing' ); ?></th> |
|
324 | - <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e( 'Apply rate to whole country', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th> |
|
325 | - <th scope="col" class="wpinv_vat_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> |
|
326 | - <th scope="col" class="wpinv_vat_name"><?php _e( 'VAT Name', 'invoicing' ); ?></th> |
|
327 | - <th scope="col" class="wpinv_vat_group"><?php _e( 'Tax Group', 'invoicing' ); ?></th> |
|
323 | + <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e('Country', 'invoicing'); ?></th> |
|
324 | + <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e('Apply rate to whole country', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th> |
|
325 | + <th scope="col" class="wpinv_vat_rate"><?php _e('Rate %', 'invoicing'); ?></th> |
|
326 | + <th scope="col" class="wpinv_vat_name"><?php _e('VAT Name', 'invoicing'); ?></th> |
|
327 | + <th scope="col" class="wpinv_vat_group"><?php _e('Tax Group', 'invoicing'); ?></th> |
|
328 | 328 | </tr> |
329 | 329 | </thead> |
330 | 330 | <tbody> |
331 | - <?php if( !empty( $eu_states ) ) { ?> |
|
331 | + <?php if (!empty($eu_states)) { ?> |
|
332 | 332 | <?php |
333 | - foreach ( $eu_states as $state ) { |
|
334 | - $country_name = isset( $countries[$state] ) ? $countries[$state] : ''; |
|
333 | + foreach ($eu_states as $state) { |
|
334 | + $country_name = isset($countries[$state]) ? $countries[$state] : ''; |
|
335 | 335 | |
336 | 336 | // Filter the rate for each country |
337 | - $country_rate = array_filter( $rates, function( $rate ) use( $state ) { return $rate['country'] === $state; } ); |
|
337 | + $country_rate = array_filter($rates, function($rate) use($state) { return $rate['country'] === $state; } ); |
|
338 | 338 | |
339 | 339 | // If one does not exist create a default |
340 | - $country_rate = is_array( $country_rate ) && count( $country_rate ) > 0 ? reset( $country_rate ) : array(); |
|
340 | + $country_rate = is_array($country_rate) && count($country_rate) > 0 ? reset($country_rate) : array(); |
|
341 | 341 | |
342 | - $vat_global = isset( $country_rate['global'] ) ? !empty( $country_rate['global'] ) : true; |
|
343 | - $vat_rate = isset( $country_rate['rate'] ) ? $country_rate['rate'] : ''; |
|
344 | - $vat_name = !empty( $country_rate['name'] ) ? esc_attr( stripslashes( $country_rate['name'] ) ) : ''; |
|
345 | - $vat_group = !empty( $country_rate['group'] ) ? $country_rate['group'] : ( $vat_class === '_standard' ? 'standard' : 'reduced' ); |
|
342 | + $vat_global = isset($country_rate['global']) ? !empty($country_rate['global']) : true; |
|
343 | + $vat_rate = isset($country_rate['rate']) ? $country_rate['rate'] : ''; |
|
344 | + $vat_name = !empty($country_rate['name']) ? esc_attr(stripslashes($country_rate['name'])) : ''; |
|
345 | + $vat_group = !empty($country_rate['group']) ? $country_rate['group'] : ($vat_class === '_standard' ? 'standard' : 'reduced'); |
|
346 | 346 | ?> |
347 | 347 | <tr> |
348 | 348 | <td class="wpinv_vat_country"><?php echo $state; ?><input type="hidden" name="vat_rates[<?php echo $state; ?>][country]" value="<?php echo $state; ?>" /><input type="hidden" name="vat_rates[<?php echo $state; ?>][state]" value="" /></td> |
349 | 349 | <td class="wpinv_vat_country_name"><?php echo $country_name; ?></td> |
350 | 350 | <td class="wpinv_vat_global"> |
351 | - <input type="checkbox" name="vat_rates[<?php echo $state;?>][global]" id="vat_rates[<?php echo $state;?>][global]" value="1" <?php checked( true, $vat_global );?> disabled="disabled" /> |
|
352 | - <label for="tax_rates[<?php echo $state;?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label> |
|
353 | - <input type="hidden" name="vat_rates[<?php echo $state;?>][global]" value="1" checked="checked" /> |
|
351 | + <input type="checkbox" name="vat_rates[<?php echo $state; ?>][global]" id="vat_rates[<?php echo $state; ?>][global]" value="1" <?php checked(true, $vat_global); ?> disabled="disabled" /> |
|
352 | + <label for="tax_rates[<?php echo $state; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label> |
|
353 | + <input type="hidden" name="vat_rates[<?php echo $state; ?>][global]" value="1" checked="checked" /> |
|
354 | 354 | </td> |
355 | - <td class="wpinv_vat_rate"><input type="number" class="small-text" step="0.10" min="0.00" name="vat_rates[<?php echo $state;?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
356 | - <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state;?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
355 | + <td class="wpinv_vat_rate"><input type="number" class="small-text" step="0.10" min="0.00" name="vat_rates[<?php echo $state; ?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
356 | + <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state; ?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
357 | 357 | <td class="wpinv_vat_group"> |
358 | 358 | <?php |
359 | - echo wpinv_html_select( array( |
|
359 | + echo wpinv_html_select(array( |
|
360 | 360 | 'name' => 'vat_rates[' . $state . '][group]', |
361 | 361 | 'selected' => $vat_group, |
362 | 362 | 'id' => 'vat_rates[' . $state . '][group]', |
@@ -366,14 +366,14 @@ discard block |
||
366 | 366 | 'chosen' => false, |
367 | 367 | 'show_option_all' => false, |
368 | 368 | 'show_option_none' => false |
369 | - ) ); |
|
369 | + )); |
|
370 | 370 | ?> |
371 | 371 | </td> |
372 | 372 | </tr> |
373 | 373 | <?php } ?> |
374 | 374 | <tr> |
375 | 375 | <td colspan="6" style="background-color:#fafafa;"> |
376 | - <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e( 'Update EU VAT Rates', 'invoicing' ); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
376 | + <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e('Update EU VAT Rates', 'invoicing'); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
377 | 377 | </td> |
378 | 378 | </tr> |
379 | 379 | <?php } ?> |
@@ -385,35 +385,35 @@ discard block |
||
385 | 385 | echo $content; |
386 | 386 | } |
387 | 387 | |
388 | -function wpinv_vat_number_callback( $args ) { |
|
388 | +function wpinv_vat_number_callback($args) { |
|
389 | 389 | global $wpinv_euvat; |
390 | 390 | |
391 | 391 | $vat_number = $wpinv_euvat->get_vat_number(); |
392 | 392 | $vat_valid = $wpinv_euvat->is_vat_validated(); |
393 | 393 | |
394 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
395 | - $validated_text = $vat_valid ? __( 'VAT number validated', 'invoicing' ) : __( 'VAT number not validated', 'invoicing' ); |
|
394 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
395 | + $validated_text = $vat_valid ? __('VAT number validated', 'invoicing') : __('VAT number not validated', 'invoicing'); |
|
396 | 396 | $disabled = $vat_valid ? 'disabled="disabled"' : " "; |
397 | 397 | |
398 | - $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr( stripslashes( $vat_number ) ) . '"/>'; |
|
399 | - $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__( 'Validate VAT Number', 'invoicing' ) . '" /></span>'; |
|
398 | + $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr(stripslashes($vat_number)) . '"/>'; |
|
399 | + $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__('Validate VAT Number', 'invoicing') . '" /></span>'; |
|
400 | 400 | $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int)$vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>'; |
401 | - $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __( 'Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing' ).'</p>' . '</label>'; |
|
402 | - $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce( 'vat_validation' ) . '">'; |
|
401 | + $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __('Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing') . '</p>' . '</label>'; |
|
402 | + $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce('vat_validation') . '">'; |
|
403 | 403 | |
404 | 404 | echo $html; |
405 | 405 | } |
406 | 406 | |
407 | -function wpinv_eu_fallback_rate_callback( $args ) { |
|
407 | +function wpinv_eu_fallback_rate_callback($args) { |
|
408 | 408 | global $wpinv_options; |
409 | 409 | |
410 | - $value = isset( $wpinv_options[$args['id']] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : '' ); |
|
411 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'small'; |
|
410 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : ''); |
|
411 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'small'; |
|
412 | 412 | |
413 | - $html = '<input type="number" min="0", max="99.99" step="0.10" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
414 | - $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Add EU Member States', 'invoicing' ) . '" /></span>'; |
|
415 | - $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Remove EU Member States', 'invoicing' ) . '" /></span>'; |
|
416 | - $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__( 'Update EU VAT Rates', 'invoicing' ) . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
413 | + $html = '<input type="number" min="0", max="99.99" step="0.10" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr(stripslashes($value)) . '" />'; |
|
414 | + $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Add EU Member States', 'invoicing') . '" /></span>'; |
|
415 | + $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Remove EU Member States', 'invoicing') . '" /></span>'; |
|
416 | + $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__('Update EU VAT Rates', 'invoicing') . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
417 | 417 | $html .= '<p><label for="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '">' . $args['desc'] . '</label></p>'; |
418 | 418 | echo $html; |
419 | 419 | ?> |
@@ -421,36 +421,36 @@ discard block |
||
421 | 421 | <?php |
422 | 422 | } |
423 | 423 | |
424 | -function wpinv_vat_ip_lookup_callback( $args ) { |
|
424 | +function wpinv_vat_ip_lookup_callback($args) { |
|
425 | 425 | global $wpinv_options, $wpinv_euvat; |
426 | 426 | |
427 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : 'default' ); |
|
427 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : 'default'); |
|
428 | 428 | |
429 | 429 | $options = array(); |
430 | - if ( function_exists( 'geoip_country_code_by_name' ) ) { |
|
431 | - $options['geoip'] = __( 'PHP GeoIP extension', 'invoicing' ); |
|
430 | + if (function_exists('geoip_country_code_by_name')) { |
|
431 | + $options['geoip'] = __('PHP GeoIP extension', 'invoicing'); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | $geoip2_database = $wpinv_euvat->geoip2_country_dbfile(); |
435 | 435 | |
436 | - if ( !function_exists( 'bcadd' ) ) { |
|
437 | - $geoip2_message = __( 'GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing' ); |
|
436 | + if (!function_exists('bcadd')) { |
|
437 | + $geoip2_message = __('GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing'); |
|
438 | 438 | } else { |
439 | - $geoip2_message = ini_get('safe_mode') ? __( 'GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing' ) : ''; |
|
439 | + $geoip2_message = ini_get('safe_mode') ? __('GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing') : ''; |
|
440 | 440 | } |
441 | 441 | |
442 | - if ( $geoip2_database !== false && empty( $geoip2_message ) ) { |
|
443 | - $options['geoip2'] = __( 'GeoIP2 Database', 'invoicing' ); |
|
442 | + if ($geoip2_database !== false && empty($geoip2_message)) { |
|
443 | + $options['geoip2'] = __('GeoIP2 Database', 'invoicing'); |
|
444 | 444 | } |
445 | 445 | |
446 | - if ( function_exists( 'simplexml_load_file' ) ) { |
|
447 | - $options['geoplugin'] = __( 'geoPlugin Web Service', 'invoicing' ); |
|
446 | + if (function_exists('simplexml_load_file')) { |
|
447 | + $options['geoplugin'] = __('geoPlugin Web Service', 'invoicing'); |
|
448 | 448 | } |
449 | 449 | |
450 | - $options['site'] = __( 'Use default country', 'invoicing' ); |
|
451 | - $options['default'] = __( 'Auto', 'invoicing' ); |
|
450 | + $options['site'] = __('Use default country', 'invoicing'); |
|
451 | + $options['default'] = __('Auto', 'invoicing'); |
|
452 | 452 | |
453 | - $html = wpinv_html_select( array( |
|
453 | + $html = wpinv_html_select(array( |
|
454 | 454 | 'name' => "wpinv_settings[{$args['id']}]", |
455 | 455 | 'selected' => $value, |
456 | 456 | 'id' => "wpinv_settings[{$args['id']}]", |
@@ -463,23 +463,23 @@ discard block |
||
463 | 463 | )); |
464 | 464 | |
465 | 465 | $desc = '<label for="wpinv_settings[' . $args['id'] . ']">'; |
466 | - $desc .= __( 'Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing' ); |
|
466 | + $desc .= __('Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing'); |
|
467 | 467 | $desc .= '<p>'; |
468 | - if ( empty( $geoip2_message ) ) { |
|
469 | - if ( $geoip2_database ) { |
|
468 | + if (empty($geoip2_message)) { |
|
469 | + if ($geoip2_database) { |
|
470 | 470 | $last_updated = ''; |
471 | - if ( $time_updated = wpinv_get_option( 'wpinv_geoip2_date_updated' ) ) { |
|
472 | - $date_updated = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time_updated ); |
|
473 | - $last_updated = '<br>' . sprintf( __( 'The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing' ), $date_updated ); |
|
471 | + if ($time_updated = wpinv_get_option('wpinv_geoip2_date_updated')) { |
|
472 | + $date_updated = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $time_updated); |
|
473 | + $last_updated = '<br>' . sprintf(__('The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing'), $date_updated); |
|
474 | 474 | } |
475 | - $desc .= __( 'GeoIP2 database exists:', 'invoicing' ) . $last_updated . ' <input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __( 'Update GeoIP2 database now (~55MB)', 'invoicing' ) . '"></input>'; |
|
475 | + $desc .= __('GeoIP2 database exists:', 'invoicing') . $last_updated . ' <input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __('Update GeoIP2 database now (~55MB)', 'invoicing') . '"></input>'; |
|
476 | 476 | } else { |
477 | - $desc .= __( 'GeoIP2 database does not exist:', 'invoicing' ) . ' <input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __( 'Download GeoIP2 database now', 'invoicing' ) . ' (~53MB)"></input><br>' . __( 'After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing' ); |
|
477 | + $desc .= __('GeoIP2 database does not exist:', 'invoicing') . ' <input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __('Download GeoIP2 database now', 'invoicing') . ' (~53MB)"></input><br>' . __('After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing'); |
|
478 | 478 | } |
479 | 479 | } else { |
480 | 480 | $desc .= $geoip2_message; |
481 | 481 | } |
482 | - $desc .= '</p><p>'. __( 'GeoPlugin is a great free service please consider supporting them: ', 'invoicing' ) . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>'; |
|
482 | + $desc .= '</p><p>' . __('GeoPlugin is a great free service please consider supporting them: ', 'invoicing') . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>'; |
|
483 | 483 | $desc .= '</label>'; |
484 | 484 | |
485 | 485 | $html .= $desc; |
@@ -1,28 +1,28 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -function wpinv_user_invoices( $current_page = 1 ) { |
|
5 | +function wpinv_user_invoices($current_page = 1) { |
|
6 | 6 | global $current_page; |
7 | - wpinv_get_template_part( 'wpinv-invoice-history' ); |
|
7 | + wpinv_get_template_part('wpinv-invoice-history'); |
|
8 | 8 | } |
9 | 9 | |
10 | -function wpinv_get_users_invoices( $user = 0, $number = 20, $pagination = false, $status = 'complete' ) { |
|
11 | - if ( empty( $user ) ) { |
|
10 | +function wpinv_get_users_invoices($user = 0, $number = 20, $pagination = false, $status = 'complete') { |
|
11 | + if (empty($user)) { |
|
12 | 12 | $user = get_current_user_id(); |
13 | 13 | } |
14 | 14 | |
15 | - if ( 0 === $user ) { |
|
15 | + if (0 === $user) { |
|
16 | 16 | return false; |
17 | 17 | } |
18 | 18 | |
19 | 19 | $status = $status === 'complete' ? 'publish' : $status; |
20 | 20 | |
21 | - if ( $pagination ) { |
|
22 | - if ( get_query_var( 'paged' ) ) |
|
21 | + if ($pagination) { |
|
22 | + if (get_query_var('paged')) |
|
23 | 23 | $paged = get_query_var('paged'); |
24 | - else if ( get_query_var( 'page' ) ) |
|
25 | - $paged = get_query_var( 'page' ); |
|
24 | + else if (get_query_var('page')) |
|
25 | + $paged = get_query_var('page'); |
|
26 | 26 | else |
27 | 27 | $paged = 1; |
28 | 28 | } |
@@ -31,21 +31,21 @@ discard block |
||
31 | 31 | 'post_type' => 'wpi_invoice', |
32 | 32 | 'posts_per_page' => 20, |
33 | 33 | 'paged' => null, |
34 | - 'post_status' => array( 'complete', 'publish', 'pending' ), |
|
34 | + 'post_status' => array('complete', 'publish', 'pending'), |
|
35 | 35 | 'user' => $user, |
36 | 36 | 'order' => 'date', |
37 | 37 | ); |
38 | 38 | |
39 | - $invoices = get_posts( $args ); |
|
39 | + $invoices = get_posts($args); |
|
40 | 40 | |
41 | 41 | // No invoices |
42 | - if ( ! $invoices ) |
|
42 | + if (!$invoices) |
|
43 | 43 | return false; |
44 | 44 | |
45 | 45 | return $invoices; |
46 | 46 | } |
47 | 47 | |
48 | -function wpinv_dropdown_users( $args = '' ) { |
|
48 | +function wpinv_dropdown_users($args = '') { |
|
49 | 49 | $defaults = array( |
50 | 50 | 'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '', |
51 | 51 | 'orderby' => 'display_name', 'order' => 'ASC', |
@@ -56,18 +56,18 @@ discard block |
||
56 | 56 | 'option_none_value' => -1 |
57 | 57 | ); |
58 | 58 | |
59 | - $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0; |
|
59 | + $defaults['selected'] = is_author() ? get_query_var('author') : 0; |
|
60 | 60 | |
61 | - $r = wp_parse_args( $args, $defaults ); |
|
61 | + $r = wp_parse_args($args, $defaults); |
|
62 | 62 | |
63 | - $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) ); |
|
63 | + $query_args = wp_array_slice_assoc($r, array('blog_id', 'include', 'exclude', 'orderby', 'order', 'who')); |
|
64 | 64 | |
65 | - $fields = array( 'ID', 'user_login', 'user_email' ); |
|
65 | + $fields = array('ID', 'user_login', 'user_email'); |
|
66 | 66 | |
67 | - $show = ! empty( $r['show'] ) ? $r['show'] : 'display_name'; |
|
68 | - if ( 'display_name_with_login' === $show ) { |
|
67 | + $show = !empty($r['show']) ? $r['show'] : 'display_name'; |
|
68 | + if ('display_name_with_login' === $show) { |
|
69 | 69 | $fields[] = 'display_name'; |
70 | - } else if ( 'display_name_with_email' === $show ) { |
|
70 | + } else if ('display_name_with_email' === $show) { |
|
71 | 71 | $fields[] = 'display_name'; |
72 | 72 | } else { |
73 | 73 | $fields[] = $show; |
@@ -79,99 +79,99 @@ discard block |
||
79 | 79 | $show_option_none = $r['show_option_none']; |
80 | 80 | $option_none_value = $r['option_none_value']; |
81 | 81 | |
82 | - $query_args = apply_filters( 'wpinv_dropdown_users_args', $query_args, $r ); |
|
82 | + $query_args = apply_filters('wpinv_dropdown_users_args', $query_args, $r); |
|
83 | 83 | |
84 | - $users = get_users( $query_args ); |
|
84 | + $users = get_users($query_args); |
|
85 | 85 | |
86 | 86 | $output = ''; |
87 | - if ( ! empty( $users ) && ( empty( $r['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) { |
|
88 | - $name = esc_attr( $r['name'] ); |
|
89 | - if ( $r['multi'] && ! $r['id'] ) { |
|
87 | + if (!empty($users) && (empty($r['hide_if_only_one_author']) || count($users) > 1)) { |
|
88 | + $name = esc_attr($r['name']); |
|
89 | + if ($r['multi'] && !$r['id']) { |
|
90 | 90 | $id = ''; |
91 | 91 | } else { |
92 | - $id = $r['id'] ? " id='" . esc_attr( $r['id'] ) . "'" : " id='$name'"; |
|
92 | + $id = $r['id'] ? " id='" . esc_attr($r['id']) . "'" : " id='$name'"; |
|
93 | 93 | } |
94 | 94 | $output = "<select name='{$name}'{$id} class='" . $r['class'] . "'>\n"; |
95 | 95 | |
96 | - if ( $show_option_all ) { |
|
96 | + if ($show_option_all) { |
|
97 | 97 | $output .= "\t<option value='0'>$show_option_all</option>\n"; |
98 | 98 | } |
99 | 99 | |
100 | - if ( $show_option_none ) { |
|
101 | - $_selected = selected( $option_none_value, $r['selected'], false ); |
|
102 | - $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n"; |
|
100 | + if ($show_option_none) { |
|
101 | + $_selected = selected($option_none_value, $r['selected'], false); |
|
102 | + $output .= "\t<option value='" . esc_attr($option_none_value) . "'$_selected>$show_option_none</option>\n"; |
|
103 | 103 | } |
104 | 104 | |
105 | - if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) { |
|
105 | + if ($r['include_selected'] && ($r['selected'] > 0)) { |
|
106 | 106 | $found_selected = false; |
107 | - $r['selected'] = (int) $r['selected']; |
|
108 | - foreach ( (array) $users as $user ) { |
|
109 | - $user->ID = (int) $user->ID; |
|
110 | - if ( $user->ID === $r['selected'] ) { |
|
107 | + $r['selected'] = (int)$r['selected']; |
|
108 | + foreach ((array)$users as $user) { |
|
109 | + $user->ID = (int)$user->ID; |
|
110 | + if ($user->ID === $r['selected']) { |
|
111 | 111 | $found_selected = true; |
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
115 | - if ( ! $found_selected ) { |
|
116 | - $users[] = get_userdata( $r['selected'] ); |
|
115 | + if (!$found_selected) { |
|
116 | + $users[] = get_userdata($r['selected']); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | - foreach ( (array) $users as $user ) { |
|
121 | - if ( 'display_name_with_login' === $show ) { |
|
120 | + foreach ((array)$users as $user) { |
|
121 | + if ('display_name_with_login' === $show) { |
|
122 | 122 | /* translators: 1: display name, 2: user_login */ |
123 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login ); |
|
124 | - } elseif ( 'display_name_with_email' === $show ) { |
|
123 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_login); |
|
124 | + } elseif ('display_name_with_email' === $show) { |
|
125 | 125 | /* translators: 1: display name, 2: user_email */ |
126 | - if ( $user->display_name == $user->user_email ) { |
|
126 | + if ($user->display_name == $user->user_email) { |
|
127 | 127 | $display = $user->display_name; |
128 | 128 | } else { |
129 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_email ); |
|
129 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_email); |
|
130 | 130 | } |
131 | - } elseif ( ! empty( $user->$show ) ) { |
|
131 | + } elseif (!empty($user->$show)) { |
|
132 | 132 | $display = $user->$show; |
133 | 133 | } else { |
134 | 134 | $display = '(' . $user->user_login . ')'; |
135 | 135 | } |
136 | 136 | |
137 | - $_selected = selected( $user->ID, $r['selected'], false ); |
|
138 | - $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n"; |
|
137 | + $_selected = selected($user->ID, $r['selected'], false); |
|
138 | + $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n"; |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | $output .= "</select>"; |
142 | 142 | } |
143 | 143 | |
144 | - $html = apply_filters( 'wpinv_dropdown_users', $output ); |
|
144 | + $html = apply_filters('wpinv_dropdown_users', $output); |
|
145 | 145 | |
146 | - if ( $r['echo'] ) { |
|
146 | + if ($r['echo']) { |
|
147 | 147 | echo $html; |
148 | 148 | } |
149 | 149 | return $html; |
150 | 150 | } |
151 | 151 | |
152 | -function wpinv_guest_redirect( $redirect_to, $user_id = 0 ) { |
|
153 | - if ( (int)wpinv_get_option( 'guest_checkout' ) && $user_id > 0 ) { |
|
154 | - wpinv_login_user( $user_id ); |
|
152 | +function wpinv_guest_redirect($redirect_to, $user_id = 0) { |
|
153 | + if ((int)wpinv_get_option('guest_checkout') && $user_id > 0) { |
|
154 | + wpinv_login_user($user_id); |
|
155 | 155 | } else { |
156 | - $redirect_to = wp_login_url( $redirect_to ); |
|
156 | + $redirect_to = wp_login_url($redirect_to); |
|
157 | 157 | } |
158 | 158 | |
159 | - $redirect_to = apply_filters( 'wpinv_invoice_link_guest_redirect', $redirect_to, $user_id ); |
|
159 | + $redirect_to = apply_filters('wpinv_invoice_link_guest_redirect', $redirect_to, $user_id); |
|
160 | 160 | |
161 | - wp_redirect( $redirect_to ); |
|
161 | + wp_redirect($redirect_to); |
|
162 | 162 | } |
163 | 163 | |
164 | -function wpinv_login_user( $user_id ) { |
|
165 | - if ( is_user_logged_in() ) { |
|
164 | +function wpinv_login_user($user_id) { |
|
165 | + if (is_user_logged_in()) { |
|
166 | 166 | return true; |
167 | 167 | } |
168 | 168 | |
169 | - $user = get_user_by( 'id', $user_id ); |
|
169 | + $user = get_user_by('id', $user_id); |
|
170 | 170 | |
171 | - if ( !empty( $user ) && !is_wp_error( $user ) && !empty( $user->user_login ) ) { |
|
172 | - wp_set_current_user( $user_id, $user->user_login ); |
|
173 | - wp_set_auth_cookie( $user_id ); |
|
174 | - do_action( 'wp_login', $user->user_login ); |
|
171 | + if (!empty($user) && !is_wp_error($user) && !empty($user->user_login)) { |
|
172 | + wp_set_current_user($user_id, $user->user_login); |
|
173 | + wp_set_auth_cookie($user_id); |
|
174 | + do_action('wp_login', $user->user_login); |
|
175 | 175 | |
176 | 176 | return true; |
177 | 177 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -function wpinv_get_subscriptions( $args = array() ) { |
|
3 | - if ( empty( $args['parent_invoice_id'] ) ) { |
|
2 | +function wpinv_get_subscriptions($args = array()) { |
|
3 | + if (empty($args['parent_invoice_id'])) { |
|
4 | 4 | return false; |
5 | 5 | } |
6 | 6 | |
@@ -14,18 +14,18 @@ discard block |
||
14 | 14 | ); |
15 | 15 | |
16 | 16 | $args['post_parent'] = $args['parent_invoice_id']; |
17 | - $args = wp_parse_args( $args, $defaults ); |
|
17 | + $args = wp_parse_args($args, $defaults); |
|
18 | 18 | |
19 | - if( $args['numberposts'] < 1 ) { |
|
19 | + if ($args['numberposts'] < 1) { |
|
20 | 20 | $args['numberposts'] = 999999999999; |
21 | 21 | } |
22 | 22 | |
23 | - $posts = get_posts( $args ); |
|
23 | + $posts = get_posts($args); |
|
24 | 24 | $subscriptions = array(); |
25 | - if ( !empty( $posts ) ) { |
|
26 | - foreach ( $posts as $post ) { |
|
27 | - if ( !empty( $post->ID ) ) { |
|
28 | - $subscriptions[] = wpinv_get_invoice( $post->ID ); |
|
25 | + if (!empty($posts)) { |
|
26 | + foreach ($posts as $post) { |
|
27 | + if (!empty($post->ID)) { |
|
28 | + $subscriptions[] = wpinv_get_invoice($post->ID); |
|
29 | 29 | } |
30 | 30 | } |
31 | 31 | } |
@@ -33,19 +33,19 @@ discard block |
||
33 | 33 | |
34 | 34 | return $subscriptions; |
35 | 35 | } |
36 | -function wpinv_get_subscription( $id = 0, $by_profile_id = false ) { |
|
36 | +function wpinv_get_subscription($id = 0, $by_profile_id = false) { |
|
37 | 37 | global $wpdb; |
38 | 38 | |
39 | - if ( empty( $id ) ) { |
|
39 | + if (empty($id)) { |
|
40 | 40 | return false; |
41 | 41 | } |
42 | 42 | |
43 | - $id = esc_sql( $id ); |
|
43 | + $id = esc_sql($id); |
|
44 | 44 | |
45 | - $invoice_id = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1" ); |
|
45 | + $invoice_id = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1"); |
|
46 | 46 | |
47 | - if ( $invoice_id != null ) { |
|
48 | - return wpinv_get_invoice( $invoice_id ); |
|
47 | + if ($invoice_id != null) { |
|
48 | + return wpinv_get_invoice($invoice_id); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | return false; |
@@ -55,49 +55,49 @@ discard block |
||
55 | 55 | * Records a new payment on the subscription |
56 | 56 | * |
57 | 57 | */ |
58 | -function wpinv_recurring_add_subscription_payment( $parent_invoice_id, $subscription_args = array() ) { |
|
59 | - $args = wp_parse_args( $subscription_args, array( |
|
58 | +function wpinv_recurring_add_subscription_payment($parent_invoice_id, $subscription_args = array()) { |
|
59 | + $args = wp_parse_args($subscription_args, array( |
|
60 | 60 | 'amount' => '', |
61 | 61 | 'transaction_id' => '', |
62 | 62 | 'gateway' => '' |
63 | - ) ); |
|
63 | + )); |
|
64 | 64 | |
65 | - if ( wpinv_payment_exists( $args['transaction_id'] ) ) { |
|
65 | + if (wpinv_payment_exists($args['transaction_id'])) { |
|
66 | 66 | return false; |
67 | 67 | } |
68 | 68 | |
69 | - $parent_invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
70 | - if ( empty( $parent_invoice ) ) { |
|
69 | + $parent_invoice = wpinv_get_invoice($parent_invoice_id); |
|
70 | + if (empty($parent_invoice)) { |
|
71 | 71 | return; |
72 | 72 | } |
73 | 73 | |
74 | 74 | $invoice = new WPInv_Invoice(); |
75 | - $invoice->set( 'parent_invoice', $parent_invoice_id ); |
|
76 | - $invoice->set( 'currency', $parent_invoice->get_currency() ); |
|
75 | + $invoice->set('parent_invoice', $parent_invoice_id); |
|
76 | + $invoice->set('currency', $parent_invoice->get_currency()); |
|
77 | 77 | //$invoice->set( 'status', 'publish' ); |
78 | - $invoice->set( 'transaction_id', $args['transaction_id'] ); |
|
79 | - $invoice->set( 'key', $parent_invoice->get_key() ); |
|
78 | + $invoice->set('transaction_id', $args['transaction_id']); |
|
79 | + $invoice->set('key', $parent_invoice->get_key()); |
|
80 | 80 | |
81 | - $invoice->set( 'ip', $parent_invoice->ip ); |
|
82 | - $invoice->set( 'user_id', $parent_invoice->get_user_id() ); |
|
83 | - $invoice->set( 'first_name', $parent_invoice->get_first_name() ); |
|
84 | - $invoice->set( 'last_name', $parent_invoice->get_last_name() ); |
|
81 | + $invoice->set('ip', $parent_invoice->ip); |
|
82 | + $invoice->set('user_id', $parent_invoice->get_user_id()); |
|
83 | + $invoice->set('first_name', $parent_invoice->get_first_name()); |
|
84 | + $invoice->set('last_name', $parent_invoice->get_last_name()); |
|
85 | 85 | ///$invoice->set( 'email', $parent_invoice->get_email() ); |
86 | - $invoice->set( 'phone', $parent_invoice->phone ); |
|
87 | - $invoice->set( 'address', $parent_invoice->address ); |
|
88 | - $invoice->set( 'city', $parent_invoice->city ); |
|
89 | - $invoice->set( 'country', $parent_invoice->country ); |
|
90 | - $invoice->set( 'state', $parent_invoice->state ); |
|
91 | - $invoice->set( 'zip', $parent_invoice->zip ); |
|
92 | - $invoice->set( 'company', $parent_invoice->company ); |
|
93 | - $invoice->set( 'vat_number', $parent_invoice->vat_number ); |
|
94 | - $invoice->set( 'vat_rate', $parent_invoice->vat_rate ); |
|
95 | - $invoice->set( 'adddress_confirmed', $parent_invoice->adddress_confirmed ); |
|
96 | - |
|
97 | - if ( empty( $args['gateway'] ) ) { |
|
98 | - $invoice->set( 'gateway', $parent_invoice->get_gateway() ); |
|
86 | + $invoice->set('phone', $parent_invoice->phone); |
|
87 | + $invoice->set('address', $parent_invoice->address); |
|
88 | + $invoice->set('city', $parent_invoice->city); |
|
89 | + $invoice->set('country', $parent_invoice->country); |
|
90 | + $invoice->set('state', $parent_invoice->state); |
|
91 | + $invoice->set('zip', $parent_invoice->zip); |
|
92 | + $invoice->set('company', $parent_invoice->company); |
|
93 | + $invoice->set('vat_number', $parent_invoice->vat_number); |
|
94 | + $invoice->set('vat_rate', $parent_invoice->vat_rate); |
|
95 | + $invoice->set('adddress_confirmed', $parent_invoice->adddress_confirmed); |
|
96 | + |
|
97 | + if (empty($args['gateway'])) { |
|
98 | + $invoice->set('gateway', $parent_invoice->get_gateway()); |
|
99 | 99 | } else { |
100 | - $invoice->set( 'gateway', $args['gateway'] ); |
|
100 | + $invoice->set('gateway', $args['gateway']); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | $recurring_details = $parent_invoice->get_recurring_details(); |
@@ -105,11 +105,11 @@ discard block |
||
105 | 105 | // increase the earnings for each item in the subscription |
106 | 106 | $items = $recurring_details['cart_details']; |
107 | 107 | |
108 | - if ( $items ) { |
|
108 | + if ($items) { |
|
109 | 109 | $add_items = array(); |
110 | 110 | $cart_details = array(); |
111 | 111 | |
112 | - foreach ( $items as $item ) { |
|
112 | + foreach ($items as $item) { |
|
113 | 113 | $add_item = array(); |
114 | 114 | $add_item['id'] = $item['id']; |
115 | 115 | $add_item['quantity'] = $item['quantity']; |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | break; |
120 | 120 | } |
121 | 121 | |
122 | - $invoice->set( 'items', $add_items ); |
|
122 | + $invoice->set('items', $add_items); |
|
123 | 123 | $invoice->cart_details = $cart_details; |
124 | 124 | } |
125 | 125 | |
@@ -129,277 +129,277 @@ discard block |
||
129 | 129 | $tax = $recurring_details['tax']; |
130 | 130 | $discount = $recurring_details['discount']; |
131 | 131 | |
132 | - if ( $discount > 0 ) { |
|
133 | - $invoice->set( 'discount_code', $parent_invoice->discount_code ); |
|
132 | + if ($discount > 0) { |
|
133 | + $invoice->set('discount_code', $parent_invoice->discount_code); |
|
134 | 134 | } |
135 | 135 | |
136 | - $invoice->subtotal = wpinv_format_amount( $subtotal, NULL, true ); |
|
137 | - $invoice->tax = wpinv_format_amount( $tax, NULL, true ); |
|
138 | - $invoice->discount = wpinv_format_amount( $discount, NULL, true ); |
|
139 | - $invoice->total = wpinv_format_amount( $total, NULL, true ); |
|
136 | + $invoice->subtotal = wpinv_format_amount($subtotal, NULL, true); |
|
137 | + $invoice->tax = wpinv_format_amount($tax, NULL, true); |
|
138 | + $invoice->discount = wpinv_format_amount($discount, NULL, true); |
|
139 | + $invoice->total = wpinv_format_amount($total, NULL, true); |
|
140 | 140 | $invoice->save(); |
141 | 141 | |
142 | - wpinv_update_payment_status( $invoice->ID, 'publish' ); |
|
142 | + wpinv_update_payment_status($invoice->ID, 'publish'); |
|
143 | 143 | sleep(1); |
144 | - wpinv_update_payment_status( $invoice->ID, 'renewal' ); |
|
144 | + wpinv_update_payment_status($invoice->ID, 'renewal'); |
|
145 | 145 | |
146 | - $invoice = wpinv_get_invoice( $invoice->ID ); |
|
146 | + $invoice = wpinv_get_invoice($invoice->ID); |
|
147 | 147 | |
148 | - $subscription_data = wpinv_payment_subscription_data( $parent_invoice ); |
|
148 | + $subscription_data = wpinv_payment_subscription_data($parent_invoice); |
|
149 | 149 | $subscription_data['recurring_amount'] = $invoice->get_total(); |
150 | - $subscription_data['created'] = current_time( 'mysql', 0 ); |
|
151 | - $subscription_data['expiration'] = $invoice->get_new_expiration( $subscription_data['item_id'] ); |
|
150 | + $subscription_data['created'] = current_time('mysql', 0); |
|
151 | + $subscription_data['expiration'] = $invoice->get_new_expiration($subscription_data['item_id']); |
|
152 | 152 | |
153 | 153 | // Retrieve pending subscription from database and update it's status to active and set proper profile ID |
154 | - $invoice->update_subscription( $subscription_data ); |
|
154 | + $invoice->update_subscription($subscription_data); |
|
155 | 155 | |
156 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args ); |
|
157 | - do_action( 'wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args ); |
|
156 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args); |
|
157 | + do_action('wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args); |
|
158 | 158 | |
159 | 159 | return $invoice; |
160 | 160 | } |
161 | 161 | |
162 | -function wpinv_payment_exists( $txn_id = '' ) { |
|
162 | +function wpinv_payment_exists($txn_id = '') { |
|
163 | 163 | global $wpdb; |
164 | 164 | |
165 | - if ( empty( $txn_id ) ) { |
|
165 | + if (empty($txn_id)) { |
|
166 | 166 | return false; |
167 | 167 | } |
168 | 168 | |
169 | - $txn_id = esc_sql( $txn_id ); |
|
169 | + $txn_id = esc_sql($txn_id); |
|
170 | 170 | |
171 | - $invoice = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1" ); |
|
171 | + $invoice = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1"); |
|
172 | 172 | |
173 | - if ( $invoice != null ) { |
|
173 | + if ($invoice != null) { |
|
174 | 174 | return true; |
175 | 175 | } |
176 | 176 | |
177 | 177 | return false; |
178 | 178 | } |
179 | 179 | |
180 | -function wpinv_is_subscription_payment( $invoice = '' ) { |
|
181 | - if ( empty( $invoice ) ) { |
|
180 | +function wpinv_is_subscription_payment($invoice = '') { |
|
181 | + if (empty($invoice)) { |
|
182 | 182 | return false; |
183 | 183 | } |
184 | 184 | |
185 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
186 | - $invoice = wpinv_get_invoice( $invoice ); |
|
185 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
186 | + $invoice = wpinv_get_invoice($invoice); |
|
187 | 187 | } |
188 | 188 | |
189 | - if ( empty( $invoice ) ) { |
|
189 | + if (empty($invoice)) { |
|
190 | 190 | return false; |
191 | 191 | } |
192 | 192 | |
193 | - if ( $invoice->is_renewal() ) { |
|
193 | + if ($invoice->is_renewal()) { |
|
194 | 194 | return true; |
195 | 195 | } |
196 | 196 | |
197 | 197 | return false; |
198 | 198 | } |
199 | 199 | |
200 | -function wpinv_payment_subscription_data( $invoice = '' ) { |
|
201 | - if ( empty( $invoice ) ) { |
|
200 | +function wpinv_payment_subscription_data($invoice = '') { |
|
201 | + if (empty($invoice)) { |
|
202 | 202 | return false; |
203 | 203 | } |
204 | 204 | |
205 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
206 | - $invoice = wpinv_get_invoice( $invoice ); |
|
205 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
206 | + $invoice = wpinv_get_invoice($invoice); |
|
207 | 207 | } |
208 | 208 | |
209 | - if ( empty( $invoice ) ) { |
|
209 | + if (empty($invoice)) { |
|
210 | 210 | return false; |
211 | 211 | } |
212 | 212 | |
213 | 213 | return $invoice->get_subscription_data(); |
214 | 214 | } |
215 | 215 | |
216 | -function wpinv_payment_link_transaction_id( $invoice = '' ) { |
|
217 | - if ( empty( $invoice ) ) { |
|
216 | +function wpinv_payment_link_transaction_id($invoice = '') { |
|
217 | + if (empty($invoice)) { |
|
218 | 218 | return false; |
219 | 219 | } |
220 | 220 | |
221 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
222 | - $invoice = wpinv_get_invoice( $invoice ); |
|
221 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
222 | + $invoice = wpinv_get_invoice($invoice); |
|
223 | 223 | } |
224 | 224 | |
225 | - if ( empty( $invoice ) ) { |
|
225 | + if (empty($invoice)) { |
|
226 | 226 | return false; |
227 | 227 | } |
228 | 228 | |
229 | - return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice ); |
|
229 | + return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice); |
|
230 | 230 | } |
231 | 231 | |
232 | -function wpinv_get_pretty_subscription_period( $period ) { |
|
232 | +function wpinv_get_pretty_subscription_period($period) { |
|
233 | 233 | $frequency = ''; |
234 | 234 | //Format period details |
235 | - switch ( $period ) { |
|
235 | + switch ($period) { |
|
236 | 236 | case 'D' : |
237 | 237 | case 'day' : |
238 | - $frequency = __( 'Daily', 'invoicing' ); |
|
238 | + $frequency = __('Daily', 'invoicing'); |
|
239 | 239 | break; |
240 | 240 | case 'W' : |
241 | 241 | case 'week' : |
242 | - $frequency = __( 'Weekly', 'invoicing' ); |
|
242 | + $frequency = __('Weekly', 'invoicing'); |
|
243 | 243 | break; |
244 | 244 | case 'M' : |
245 | 245 | case 'month' : |
246 | - $frequency = __( 'Monthly', 'invoicing' ); |
|
246 | + $frequency = __('Monthly', 'invoicing'); |
|
247 | 247 | break; |
248 | 248 | case 'Y' : |
249 | 249 | case 'year' : |
250 | - $frequency = __( 'Yearly', 'invoicing' ); |
|
250 | + $frequency = __('Yearly', 'invoicing'); |
|
251 | 251 | break; |
252 | 252 | default : |
253 | - $frequency = apply_filters( 'wpinv_pretty_subscription_period', $frequency, $period ); |
|
253 | + $frequency = apply_filters('wpinv_pretty_subscription_period', $frequency, $period); |
|
254 | 254 | break; |
255 | 255 | } |
256 | 256 | |
257 | 257 | return $frequency; |
258 | 258 | } |
259 | 259 | |
260 | -function wpinv_get_pretty_subscription_period_name( $period ) { |
|
260 | +function wpinv_get_pretty_subscription_period_name($period) { |
|
261 | 261 | $frequency = ''; |
262 | 262 | //Format period details |
263 | - switch ( $period ) { |
|
263 | + switch ($period) { |
|
264 | 264 | case 'D' : |
265 | 265 | case 'day' : |
266 | - $frequency = __( 'Day', 'invoicing' ); |
|
266 | + $frequency = __('Day', 'invoicing'); |
|
267 | 267 | break; |
268 | 268 | case 'W' : |
269 | 269 | case 'week' : |
270 | - $frequency = __( 'Week', 'invoicing' ); |
|
270 | + $frequency = __('Week', 'invoicing'); |
|
271 | 271 | break; |
272 | 272 | case 'M' : |
273 | 273 | case 'month' : |
274 | - $frequency = __( 'Month', 'invoicing' ); |
|
274 | + $frequency = __('Month', 'invoicing'); |
|
275 | 275 | break; |
276 | 276 | case 'Y' : |
277 | 277 | case 'year' : |
278 | - $frequency = __( 'Year', 'invoicing' ); |
|
278 | + $frequency = __('Year', 'invoicing'); |
|
279 | 279 | break; |
280 | 280 | default : |
281 | - $frequency = apply_filters( 'wpinv_pretty_subscription_period_name', $frequency, $period ); |
|
281 | + $frequency = apply_filters('wpinv_pretty_subscription_period_name', $frequency, $period); |
|
282 | 282 | break; |
283 | 283 | } |
284 | 284 | |
285 | 285 | return $frequency; |
286 | 286 | } |
287 | 287 | |
288 | -function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) { |
|
288 | +function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) { |
|
289 | 289 | $interval = (int)$interval > 0 ? (int)$interval : 1; |
290 | 290 | |
291 | - if ( $trial_interval > 0 && !empty( $trial_period ) ) { |
|
292 | - $amount = __( 'Free', 'invoicing' ); |
|
291 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
292 | + $amount = __('Free', 'invoicing'); |
|
293 | 293 | $interval = $trial_interval; |
294 | 294 | $period = $trial_period; |
295 | 295 | } |
296 | 296 | |
297 | 297 | $description = ''; |
298 | - switch ( $period ) { |
|
298 | + switch ($period) { |
|
299 | 299 | case 'D' : |
300 | 300 | case 'day' : |
301 | - $description = wp_sprintf( _n( '%s for the first day.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
301 | + $description = wp_sprintf(_n('%s for the first day.', '%s for the first %d days.', $interval, 'invoicing'), $amount, $interval); |
|
302 | 302 | break; |
303 | 303 | case 'W' : |
304 | 304 | case 'week' : |
305 | - $description = wp_sprintf( _n( '%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
305 | + $description = wp_sprintf(_n('%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
306 | 306 | break; |
307 | 307 | case 'M' : |
308 | 308 | case 'month' : |
309 | - $description = wp_sprintf( _n( '%s for the first month.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
309 | + $description = wp_sprintf(_n('%s for the first month.', '%s for the first %d months.', $interval, 'invoicing'), $amount, $interval); |
|
310 | 310 | break; |
311 | 311 | case 'Y' : |
312 | 312 | case 'year' : |
313 | - $description = wp_sprintf( _n( '%s for the first year.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
313 | + $description = wp_sprintf(_n('%s for the first year.', '%s for the first %d years.', $interval, 'invoicing'), $amount, $interval); |
|
314 | 314 | break; |
315 | 315 | } |
316 | 316 | |
317 | - return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval ); |
|
317 | + return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval); |
|
318 | 318 | } |
319 | 319 | |
320 | -function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) { |
|
320 | +function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) { |
|
321 | 321 | $interval = (int)$interval > 0 ? (int)$interval : 1; |
322 | 322 | $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0; |
323 | 323 | |
324 | 324 | $description = ''; |
325 | - switch ( $period ) { |
|
325 | + switch ($period) { |
|
326 | 326 | case 'D' : |
327 | 327 | case 'day' : |
328 | - if ( (int)$bill_times > 0 ) { |
|
329 | - if ( $interval > 1 ) { |
|
330 | - if ( $bill_times > 1 ) { |
|
331 | - $description = wp_sprintf( __( '%s for each %d days, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
328 | + if ((int)$bill_times > 0) { |
|
329 | + if ($interval > 1) { |
|
330 | + if ($bill_times > 1) { |
|
331 | + $description = wp_sprintf(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
332 | 332 | } else { |
333 | - $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval ); |
|
333 | + $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval); |
|
334 | 334 | } |
335 | 335 | } else { |
336 | - $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
336 | + $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
337 | 337 | } |
338 | 338 | } else { |
339 | - $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval ); |
|
339 | + $description = wp_sprintf(_n('%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval); |
|
340 | 340 | } |
341 | 341 | break; |
342 | 342 | case 'W' : |
343 | 343 | case 'week' : |
344 | - if ( (int)$bill_times > 0 ) { |
|
345 | - if ( $interval > 1 ) { |
|
346 | - if ( $bill_times > 1 ) { |
|
347 | - $description = wp_sprintf( __( '%s for each %d weeks, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
344 | + if ((int)$bill_times > 0) { |
|
345 | + if ($interval > 1) { |
|
346 | + if ($bill_times > 1) { |
|
347 | + $description = wp_sprintf(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
348 | 348 | } else { |
349 | - $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval ); |
|
349 | + $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval); |
|
350 | 350 | } |
351 | 351 | } else { |
352 | - $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
352 | + $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
353 | 353 | } |
354 | 354 | } else { |
355 | - $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
355 | + $description = wp_sprintf(_n('%s for each week.', '%s for each %d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
356 | 356 | } |
357 | 357 | break; |
358 | 358 | case 'M' : |
359 | 359 | case 'month' : |
360 | - if ( (int)$bill_times > 0 ) { |
|
361 | - if ( $interval > 1 ) { |
|
362 | - if ( $bill_times > 1 ) { |
|
363 | - $description = wp_sprintf( __( '%s for each %d months, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
360 | + if ((int)$bill_times > 0) { |
|
361 | + if ($interval > 1) { |
|
362 | + if ($bill_times > 1) { |
|
363 | + $description = wp_sprintf(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
364 | 364 | } else { |
365 | - $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval ); |
|
365 | + $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval); |
|
366 | 366 | } |
367 | 367 | } else { |
368 | - $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
368 | + $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
369 | 369 | } |
370 | 370 | } else { |
371 | - $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
371 | + $description = wp_sprintf(_n('%s for each month.', '%s for each %d months.', $interval, 'invoicing'), $amount, $interval); |
|
372 | 372 | } |
373 | 373 | break; |
374 | 374 | case 'Y' : |
375 | 375 | case 'year' : |
376 | - if ( (int)$bill_times > 0 ) { |
|
377 | - if ( $interval > 1 ) { |
|
378 | - if ( $bill_times > 1 ) { |
|
379 | - $description = wp_sprintf( __( '%s for each %d years, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
376 | + if ((int)$bill_times > 0) { |
|
377 | + if ($interval > 1) { |
|
378 | + if ($bill_times > 1) { |
|
379 | + $description = wp_sprintf(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
380 | 380 | } else { |
381 | - $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval ); |
|
381 | + $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval); |
|
382 | 382 | } |
383 | 383 | } else { |
384 | - $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
384 | + $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
385 | 385 | } |
386 | 386 | } else { |
387 | - $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
387 | + $description = wp_sprintf(_n('%s for each year.', '%s for each %d years.', $interval, 'invoicing'), $amount, $interval); |
|
388 | 388 | } |
389 | 389 | break; |
390 | 390 | } |
391 | 391 | |
392 | - return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
392 | + return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
393 | 393 | } |
394 | 394 | |
395 | -function wpinv_subscription_payment_desc( $invoice ) { |
|
396 | - if ( empty( $invoice ) ) { |
|
395 | +function wpinv_subscription_payment_desc($invoice) { |
|
396 | + if (empty($invoice)) { |
|
397 | 397 | return NULL; |
398 | 398 | } |
399 | 399 | |
400 | 400 | $description = ''; |
401 | - if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) { |
|
402 | - if ( $item->has_free_trial() ) { |
|
401 | + if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) { |
|
402 | + if ($item->has_free_trial()) { |
|
403 | 403 | $trial_period = $item->get_trial_period(); |
404 | 404 | $trial_interval = $item->get_trial_interval(); |
405 | 405 | } else { |
@@ -407,45 +407,45 @@ discard block |
||
407 | 407 | $trial_interval = 0; |
408 | 408 | } |
409 | 409 | |
410 | - $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() ); |
|
410 | + $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency()); |
|
411 | 411 | } |
412 | 412 | |
413 | - return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice ); |
|
413 | + return apply_filters('wpinv_subscription_payment_desc', $description, $invoice); |
|
414 | 414 | } |
415 | 415 | |
416 | -function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) { |
|
417 | - $initial_total = wpinv_format_amount( $initial ); |
|
418 | - $recurring_total = wpinv_format_amount( $recurring ); |
|
416 | +function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') { |
|
417 | + $initial_total = wpinv_format_amount($initial); |
|
418 | + $recurring_total = wpinv_format_amount($recurring); |
|
419 | 419 | |
420 | - if ( $trial_interval > 0 && !empty( $trial_period ) ) { |
|
420 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
421 | 421 | // Free trial |
422 | 422 | } else { |
423 | - if ( $bill_times == 1 ) { |
|
423 | + if ($bill_times == 1) { |
|
424 | 424 | $recurring_total = $initial_total; |
425 | - } else if ( $bill_times > 1 && $initial_total != $recurring_total ) { |
|
425 | + } else if ($bill_times > 1 && $initial_total != $recurring_total) { |
|
426 | 426 | $bill_times--; |
427 | 427 | } |
428 | 428 | } |
429 | 429 | |
430 | - $initial_amount = wpinv_price( $initial_total, $currency ); |
|
431 | - $recurring_amount = wpinv_price( $recurring_total, $currency ); |
|
430 | + $initial_amount = wpinv_price($initial_total, $currency); |
|
431 | + $recurring_amount = wpinv_price($recurring_total, $currency); |
|
432 | 432 | |
433 | - $recurring = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
433 | + $recurring = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
434 | 434 | |
435 | - if ( $initial_total != $recurring_total ) { |
|
436 | - $initial = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval ); |
|
435 | + if ($initial_total != $recurring_total) { |
|
436 | + $initial = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval); |
|
437 | 437 | |
438 | - $description = wp_sprintf( __( '%s Then %s', 'invoicing' ), $initial, $recurring ); |
|
438 | + $description = wp_sprintf(__('%s Then %s', 'invoicing'), $initial, $recurring); |
|
439 | 439 | } else { |
440 | 440 | $description = $recurring; |
441 | 441 | } |
442 | 442 | |
443 | - return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency ); |
|
443 | + return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency); |
|
444 | 444 | } |
445 | 445 | |
446 | -function wpinv_recurring_send_payment_failed( $invoice ) { |
|
447 | - if ( !empty( $invoice->ID ) ) { |
|
448 | - wpinv_failed_invoice_notification( $invoice->ID ); |
|
446 | +function wpinv_recurring_send_payment_failed($invoice) { |
|
447 | + if (!empty($invoice->ID)) { |
|
448 | + wpinv_failed_invoice_notification($invoice->ID); |
|
449 | 449 | } |
450 | 450 | } |
451 | -add_action( 'wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1 ); |
|
452 | 451 | \ No newline at end of file |
452 | +add_action('wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1); |
|
453 | 453 | \ No newline at end of file |