@@ -14,71 +14,71 @@ discard block |
||
14 | 14 | class GetPaid_Admin { |
15 | 15 | |
16 | 16 | /** |
17 | - * Local path to this plugins admin directory |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $admin_path; |
|
22 | - |
|
23 | - /** |
|
24 | - * Web path to this plugins admin directory |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - public $admin_url; |
|
17 | + * Local path to this plugins admin directory |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $admin_path; |
|
22 | + |
|
23 | + /** |
|
24 | + * Web path to this plugins admin directory |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + public $admin_url; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Reports components. |
|
32 | - * |
|
33 | - * @var GetPaid_Reports |
|
34 | - */ |
|
30 | + /** |
|
31 | + * Reports components. |
|
32 | + * |
|
33 | + * @var GetPaid_Reports |
|
34 | + */ |
|
35 | 35 | public $reports; |
36 | 36 | |
37 | 37 | /** |
38 | - * Class constructor. |
|
39 | - */ |
|
40 | - public function __construct(){ |
|
38 | + * Class constructor. |
|
39 | + */ |
|
40 | + public function __construct(){ |
|
41 | 41 | |
42 | 42 | $this->admin_path = plugin_dir_path( __FILE__ ); |
43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | - $this->reports = new GetPaid_Reports(); |
|
43 | + $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | + $this->reports = new GetPaid_Reports(); |
|
45 | 45 | |
46 | 46 | if ( is_admin() ) { |
47 | - $this->init_admin_hooks(); |
|
47 | + $this->init_admin_hooks(); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | - * Init action and filter hooks |
|
54 | - * |
|
55 | - */ |
|
56 | - private function init_admin_hooks() { |
|
53 | + * Init action and filter hooks |
|
54 | + * |
|
55 | + */ |
|
56 | + private function init_admin_hooks() { |
|
57 | 57 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) ); |
58 | 58 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
59 | 59 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
60 | 60 | add_action( 'admin_init', array( $this, 'activation_redirect') ); |
61 | 61 | add_action( 'admin_init', array( $this, 'maybe_do_admin_action') ); |
62 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
64 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
62 | + add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
64 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
65 | 65 | add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
66 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
66 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
67 | 67 | |
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
71 | - * Register admin scripts |
|
72 | - * |
|
73 | - */ |
|
74 | - public function enqeue_scripts() { |
|
71 | + * Register admin scripts |
|
72 | + * |
|
73 | + */ |
|
74 | + public function enqeue_scripts() { |
|
75 | 75 | global $current_screen, $pagenow; |
76 | 76 | |
77 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
78 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
77 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
78 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
79 | 79 | |
80 | 80 | if ( ! empty( $current_screen->post_type ) ) { |
81 | - $page = $current_screen->post_type; |
|
81 | + $page = $current_screen->post_type; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | // General styles. |
@@ -102,26 +102,26 @@ discard block |
||
102 | 102 | } |
103 | 103 | |
104 | 104 | // Payment form scripts. |
105 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
105 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
106 | 106 | $this->load_payment_form_scripts(); |
107 | 107 | } |
108 | 108 | |
109 | 109 | if ( $page == 'wpinv-subscriptions' ) { |
110 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
111 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
112 | - } |
|
110 | + wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
111 | + wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
112 | + } |
|
113 | 113 | |
114 | - if ( $page == 'wpinv-subscriptions' ) { |
|
115 | - wp_enqueue_script( 'postbox' ); |
|
116 | - } |
|
114 | + if ( $page == 'wpinv-subscriptions' ) { |
|
115 | + wp_enqueue_script( 'postbox' ); |
|
116 | + } |
|
117 | 117 | |
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | - * Returns admin js translations. |
|
122 | - * |
|
123 | - */ |
|
124 | - protected function get_admin_i18() { |
|
121 | + * Returns admin js translations. |
|
122 | + * |
|
123 | + */ |
|
124 | + protected function get_admin_i18() { |
|
125 | 125 | global $post; |
126 | 126 | |
127 | 127 | $i18n = array( |
@@ -157,50 +157,50 @@ discard block |
||
157 | 157 | 'searching' => __( 'Searching', 'invoicing' ), |
158 | 158 | ); |
159 | 159 | |
160 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
160 | + if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
161 | 161 | |
162 | - $invoice = new WPInv_Invoice( $post ); |
|
163 | - $i18n['save_invoice'] = sprintf( |
|
164 | - __( 'Save %s', 'invoicing' ), |
|
165 | - ucfirst( $invoice->get_type() ) |
|
166 | - ); |
|
162 | + $invoice = new WPInv_Invoice( $post ); |
|
163 | + $i18n['save_invoice'] = sprintf( |
|
164 | + __( 'Save %s', 'invoicing' ), |
|
165 | + ucfirst( $invoice->get_type() ) |
|
166 | + ); |
|
167 | 167 | |
168 | - $i18n['invoice_description'] = sprintf( |
|
169 | - __( '%s Description', 'invoicing' ), |
|
170 | - ucfirst( $invoice->get_type() ) |
|
171 | - ); |
|
168 | + $i18n['invoice_description'] = sprintf( |
|
169 | + __( '%s Description', 'invoicing' ), |
|
170 | + ucfirst( $invoice->get_type() ) |
|
171 | + ); |
|
172 | 172 | |
173 | - } |
|
174 | - return $i18n; |
|
173 | + } |
|
174 | + return $i18n; |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
178 | - * Loads payment form js. |
|
179 | - * |
|
180 | - */ |
|
181 | - protected function load_payment_form_scripts() { |
|
178 | + * Loads payment form js. |
|
179 | + * |
|
180 | + */ |
|
181 | + protected function load_payment_form_scripts() { |
|
182 | 182 | global $post; |
183 | 183 | |
184 | 184 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
185 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
186 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
185 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
186 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
187 | 187 | |
188 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
189 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
188 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
189 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
190 | 190 | |
191 | - wp_localize_script( |
|
191 | + wp_localize_script( |
|
192 | 192 | 'wpinv-admin-payment-form-script', |
193 | 193 | 'wpinvPaymentFormAdmin', |
194 | 194 | array( |
195 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
196 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
197 | - 'currency' => wpinv_currency_symbol(), |
|
198 | - 'position' => wpinv_currency_position(), |
|
199 | - 'decimals' => (int) wpinv_decimals(), |
|
200 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
201 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
202 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
203 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
195 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
196 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
197 | + 'currency' => wpinv_currency_symbol(), |
|
198 | + 'position' => wpinv_currency_position(), |
|
199 | + 'decimals' => (int) wpinv_decimals(), |
|
200 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
201 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
202 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
203 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
204 | 204 | ) |
205 | 205 | ); |
206 | 206 | |
@@ -209,20 +209,20 @@ discard block |
||
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
212 | - * Add our classes to admin pages. |
|
212 | + * Add our classes to admin pages. |
|
213 | 213 | * |
214 | 214 | * @param string $classes |
215 | 215 | * @return string |
216 | - * |
|
217 | - */ |
|
216 | + * |
|
217 | + */ |
|
218 | 218 | public function admin_body_class( $classes ) { |
219 | - global $pagenow, $post, $current_screen; |
|
219 | + global $pagenow, $post, $current_screen; |
|
220 | 220 | |
221 | 221 | |
222 | 222 | $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
223 | 223 | |
224 | 224 | if ( ! empty( $current_screen->post_type ) ) { |
225 | - $page = $current_screen->post_type; |
|
225 | + $page = $current_screen->post_type; |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -231,29 +231,29 @@ discard block |
||
231 | 231 | |
232 | 232 | if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
233 | 233 | $classes .= ' wpinv-cpt wpinv'; |
234 | - } |
|
234 | + } |
|
235 | 235 | |
236 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
236 | + if ( getpaid_is_invoice_post_type( $page ) ) { |
|
237 | 237 | $classes .= ' getpaid-is-invoice-cpt'; |
238 | 238 | } |
239 | 239 | |
240 | - return $classes; |
|
240 | + return $classes; |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
244 | - * Maybe show the AyeCode Connect Notice. |
|
245 | - */ |
|
246 | - public function init_ayecode_connect_helper(){ |
|
244 | + * Maybe show the AyeCode Connect Notice. |
|
245 | + */ |
|
246 | + public function init_ayecode_connect_helper(){ |
|
247 | 247 | |
248 | 248 | new AyeCode_Connect_Helper( |
249 | 249 | array( |
250 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
251 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
252 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
253 | - 'connect_button' => __("Connect Site","invoicing"), |
|
254 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
255 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
256 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
250 | + 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
251 | + 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
252 | + 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
253 | + 'connect_button' => __("Connect Site","invoicing"), |
|
254 | + 'connecting_button' => __("Connecting...","invoicing"), |
|
255 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
256 | + 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
257 | 257 | ), |
258 | 258 | array( 'wpi-addons' ) |
259 | 259 | ); |
@@ -265,21 +265,21 @@ discard block |
||
265 | 265 | */ |
266 | 266 | public function activation_redirect() { |
267 | 267 | |
268 | - // Bail if no activation redirect. |
|
269 | - if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) { |
|
270 | - return; |
|
271 | - } |
|
268 | + // Bail if no activation redirect. |
|
269 | + if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) { |
|
270 | + return; |
|
271 | + } |
|
272 | 272 | |
273 | - // Delete the redirect transient. |
|
274 | - delete_transient( '_wpinv_activation_redirect' ); |
|
273 | + // Delete the redirect transient. |
|
274 | + delete_transient( '_wpinv_activation_redirect' ); |
|
275 | 275 | |
276 | - // Bail if activating from network, or bulk |
|
277 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
278 | - return; |
|
279 | - } |
|
276 | + // Bail if activating from network, or bulk |
|
277 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
278 | + return; |
|
279 | + } |
|
280 | 280 | |
281 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
282 | - exit; |
|
281 | + wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
282 | + exit; |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
@@ -294,162 +294,162 @@ discard block |
||
294 | 294 | |
295 | 295 | } |
296 | 296 | |
297 | - /** |
|
297 | + /** |
|
298 | 298 | * Sends a payment reminder to a customer. |
299 | - * |
|
300 | - * @param array $args |
|
299 | + * |
|
300 | + * @param array $args |
|
301 | 301 | */ |
302 | 302 | public function send_customer_invoice( $args ) { |
303 | - $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
303 | + $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
304 | 304 | |
305 | - if ( $sent ) { |
|
306 | - $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
307 | - } else { |
|
308 | - $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
309 | - } |
|
305 | + if ( $sent ) { |
|
306 | + $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
307 | + } else { |
|
308 | + $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
309 | + } |
|
310 | 310 | |
311 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
312 | - exit; |
|
313 | - } |
|
311 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
312 | + exit; |
|
313 | + } |
|
314 | 314 | |
315 | - /** |
|
315 | + /** |
|
316 | 316 | * Sends a payment reminder to a customer. |
317 | - * |
|
318 | - * @param array $args |
|
317 | + * |
|
318 | + * @param array $args |
|
319 | 319 | */ |
320 | 320 | public function send_customer_payment_reminder( $args ) { |
321 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
321 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
322 | 322 | |
323 | - if ( $sent ) { |
|
324 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
325 | - } else { |
|
326 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
327 | - } |
|
323 | + if ( $sent ) { |
|
324 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
325 | + } else { |
|
326 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
327 | + } |
|
328 | 328 | |
329 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
330 | - exit; |
|
331 | - } |
|
329 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
330 | + exit; |
|
331 | + } |
|
332 | 332 | |
333 | - /** |
|
333 | + /** |
|
334 | 334 | * Resets tax rates. |
335 | - * |
|
335 | + * |
|
336 | 336 | */ |
337 | 337 | public function admin_reset_tax_rates() { |
338 | 338 | |
339 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
340 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
341 | - exit; |
|
339 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
340 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
341 | + exit; |
|
342 | 342 | |
343 | - } |
|
343 | + } |
|
344 | 344 | |
345 | 345 | /** |
346 | - * Returns an array of admin notices. |
|
347 | - * |
|
348 | - * @since 1.0.19 |
|
346 | + * Returns an array of admin notices. |
|
347 | + * |
|
348 | + * @since 1.0.19 |
|
349 | 349 | * @return array |
350 | - */ |
|
351 | - public function get_notices() { |
|
352 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
350 | + */ |
|
351 | + public function get_notices() { |
|
352 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
353 | 353 | return is_array( $notices ) ? $notices : array(); |
354 | - } |
|
355 | - |
|
356 | - /** |
|
357 | - * Clears all admin notices |
|
358 | - * |
|
359 | - * @access public |
|
360 | - * @since 1.0.19 |
|
361 | - */ |
|
362 | - public function clear_notices() { |
|
363 | - delete_option( 'wpinv_admin_notices' ); |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Saves a new admin notice |
|
368 | - * |
|
369 | - * @access public |
|
370 | - * @since 1.0.19 |
|
371 | - */ |
|
372 | - public function save_notice( $type, $message ) { |
|
373 | - $notices = $this->get_notices(); |
|
374 | - |
|
375 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
376 | - $notices[ $type ] = array(); |
|
377 | - } |
|
378 | - |
|
379 | - $notices[ $type ][] = $message; |
|
380 | - |
|
381 | - update_option( 'wpinv_admin_notices', $notices ); |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * Displays a success notice |
|
386 | - * |
|
387 | - * @param string $msg The message to qeue. |
|
388 | - * @access public |
|
389 | - * @since 1.0.19 |
|
390 | - */ |
|
391 | - public function show_success( $msg ) { |
|
392 | - $this->save_notice( 'success', $msg ); |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Displays a error notice |
|
397 | - * |
|
398 | - * @access public |
|
399 | - * @param string $msg The message to qeue. |
|
400 | - * @since 1.0.19 |
|
401 | - */ |
|
402 | - public function show_error( $msg ) { |
|
403 | - $this->save_notice( 'error', $msg ); |
|
404 | - } |
|
405 | - |
|
406 | - /** |
|
407 | - * Displays a warning notice |
|
408 | - * |
|
409 | - * @access public |
|
410 | - * @param string $msg The message to qeue. |
|
411 | - * @since 1.0.19 |
|
412 | - */ |
|
413 | - public function show_warning( $msg ) { |
|
414 | - $this->save_notice( 'warning', $msg ); |
|
415 | - } |
|
416 | - |
|
417 | - /** |
|
418 | - * Displays a info notice |
|
419 | - * |
|
420 | - * @access public |
|
421 | - * @param string $msg The message to qeue. |
|
422 | - * @since 1.0.19 |
|
423 | - */ |
|
424 | - public function show_info( $msg ) { |
|
425 | - $this->save_notice( 'info', $msg ); |
|
426 | - } |
|
427 | - |
|
428 | - /** |
|
429 | - * Show notices |
|
430 | - * |
|
431 | - * @access public |
|
432 | - * @since 1.0.19 |
|
433 | - */ |
|
434 | - public function show_notices() { |
|
354 | + } |
|
355 | + |
|
356 | + /** |
|
357 | + * Clears all admin notices |
|
358 | + * |
|
359 | + * @access public |
|
360 | + * @since 1.0.19 |
|
361 | + */ |
|
362 | + public function clear_notices() { |
|
363 | + delete_option( 'wpinv_admin_notices' ); |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Saves a new admin notice |
|
368 | + * |
|
369 | + * @access public |
|
370 | + * @since 1.0.19 |
|
371 | + */ |
|
372 | + public function save_notice( $type, $message ) { |
|
373 | + $notices = $this->get_notices(); |
|
374 | + |
|
375 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
376 | + $notices[ $type ] = array(); |
|
377 | + } |
|
378 | + |
|
379 | + $notices[ $type ][] = $message; |
|
380 | + |
|
381 | + update_option( 'wpinv_admin_notices', $notices ); |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * Displays a success notice |
|
386 | + * |
|
387 | + * @param string $msg The message to qeue. |
|
388 | + * @access public |
|
389 | + * @since 1.0.19 |
|
390 | + */ |
|
391 | + public function show_success( $msg ) { |
|
392 | + $this->save_notice( 'success', $msg ); |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Displays a error notice |
|
397 | + * |
|
398 | + * @access public |
|
399 | + * @param string $msg The message to qeue. |
|
400 | + * @since 1.0.19 |
|
401 | + */ |
|
402 | + public function show_error( $msg ) { |
|
403 | + $this->save_notice( 'error', $msg ); |
|
404 | + } |
|
405 | + |
|
406 | + /** |
|
407 | + * Displays a warning notice |
|
408 | + * |
|
409 | + * @access public |
|
410 | + * @param string $msg The message to qeue. |
|
411 | + * @since 1.0.19 |
|
412 | + */ |
|
413 | + public function show_warning( $msg ) { |
|
414 | + $this->save_notice( 'warning', $msg ); |
|
415 | + } |
|
416 | + |
|
417 | + /** |
|
418 | + * Displays a info notice |
|
419 | + * |
|
420 | + * @access public |
|
421 | + * @param string $msg The message to qeue. |
|
422 | + * @since 1.0.19 |
|
423 | + */ |
|
424 | + public function show_info( $msg ) { |
|
425 | + $this->save_notice( 'info', $msg ); |
|
426 | + } |
|
427 | + |
|
428 | + /** |
|
429 | + * Show notices |
|
430 | + * |
|
431 | + * @access public |
|
432 | + * @since 1.0.19 |
|
433 | + */ |
|
434 | + public function show_notices() { |
|
435 | 435 | |
436 | 436 | $notices = $this->get_notices(); |
437 | 437 | $this->clear_notices(); |
438 | 438 | |
439 | - foreach ( $notices as $type => $messages ) { |
|
439 | + foreach ( $notices as $type => $messages ) { |
|
440 | 440 | |
441 | - if ( ! is_array( $messages ) ) { |
|
442 | - continue; |
|
443 | - } |
|
441 | + if ( ! is_array( $messages ) ) { |
|
442 | + continue; |
|
443 | + } |
|
444 | 444 | |
445 | 445 | $type = sanitize_key( $type ); |
446 | - foreach ( $messages as $message ) { |
|
446 | + foreach ( $messages as $message ) { |
|
447 | 447 | $message = wp_kses_post( $message ); |
448 | - echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
448 | + echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | } |
452 | 452 | |
453 | - } |
|
453 | + } |
|
454 | 454 | |
455 | 455 | } |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | $cb = "wpinv_{$option['type']}_callback"; |
197 | 197 | $section = "wpinv_settings_{$tab}_$section"; |
198 | 198 | |
199 | - if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) { |
|
200 | - $tip = esc_attr( $option['desc'] ); |
|
201 | - $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
|
202 | - unset( $option['desc'] ); |
|
203 | - } |
|
199 | + if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) { |
|
200 | + $tip = esc_attr( $option['desc'] ); |
|
201 | + $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
|
202 | + unset( $option['desc'] ); |
|
203 | + } |
|
204 | 204 | |
205 | 205 | // Loop through all tabs. |
206 | 206 | add_settings_field( |
@@ -279,10 +279,10 @@ discard block |
||
279 | 279 | } |
280 | 280 | |
281 | 281 | // General filter |
282 | - $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
282 | + $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
283 | 283 | |
284 | - // Key specific filter. |
|
285 | - $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] ); |
|
284 | + // Key specific filter. |
|
285 | + $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] ); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | // Loop through the whitelist and unset any that are empty for the tab being saved |
@@ -338,14 +338,14 @@ discard block |
||
338 | 338 | |
339 | 339 | foreach ( $new_rates as $rate ) { |
340 | 340 | |
341 | - $rate['rate'] = wpinv_sanitize_amount( $rate['rate'] ); |
|
342 | - $rate['name'] = sanitize_text_field( $rate['name'] ); |
|
343 | - $rate['state'] = sanitize_text_field( $rate['state'] ); |
|
344 | - $rate['country'] = sanitize_text_field( $rate['country'] ); |
|
345 | - $rate['global'] = empty( $rate['state'] ); |
|
346 | - $tax_rates[] = $rate; |
|
341 | + $rate['rate'] = wpinv_sanitize_amount( $rate['rate'] ); |
|
342 | + $rate['name'] = sanitize_text_field( $rate['name'] ); |
|
343 | + $rate['state'] = sanitize_text_field( $rate['state'] ); |
|
344 | + $rate['country'] = sanitize_text_field( $rate['country'] ); |
|
345 | + $rate['global'] = empty( $rate['state'] ); |
|
346 | + $tax_rates[] = $rate; |
|
347 | 347 | |
348 | - } |
|
348 | + } |
|
349 | 349 | |
350 | 350 | update_option( 'wpinv_tax_rates', $tax_rates ); |
351 | 351 | |
@@ -425,51 +425,51 @@ discard block |
||
425 | 425 | } |
426 | 426 | |
427 | 427 | function wpinv_get_pages( $with_slug = false, $default_label = NULL ) { |
428 | - $pages_options = array(); |
|
428 | + $pages_options = array(); |
|
429 | 429 | |
430 | - if( $default_label !== NULL && $default_label !== false ) { |
|
431 | - $pages_options = array( '' => $default_label ); // Blank option |
|
432 | - } |
|
430 | + if( $default_label !== NULL && $default_label !== false ) { |
|
431 | + $pages_options = array( '' => $default_label ); // Blank option |
|
432 | + } |
|
433 | 433 | |
434 | - $pages = get_pages(); |
|
435 | - if ( $pages ) { |
|
436 | - foreach ( $pages as $page ) { |
|
437 | - $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
434 | + $pages = get_pages(); |
|
435 | + if ( $pages ) { |
|
436 | + foreach ( $pages as $page ) { |
|
437 | + $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
438 | 438 | $pages_options[ $page->ID ] = $title; |
439 | - } |
|
440 | - } |
|
439 | + } |
|
440 | + } |
|
441 | 441 | |
442 | - return $pages_options; |
|
442 | + return $pages_options; |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | function wpinv_header_callback( $args ) { |
446 | - if ( !empty( $args['desc'] ) ) { |
|
446 | + if ( !empty( $args['desc'] ) ) { |
|
447 | 447 | echo $args['desc']; |
448 | 448 | } |
449 | 449 | } |
450 | 450 | |
451 | 451 | function wpinv_hidden_callback( $args ) { |
452 | - global $wpinv_options; |
|
453 | - |
|
454 | - if ( isset( $args['set_value'] ) ) { |
|
455 | - $value = $args['set_value']; |
|
456 | - } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
457 | - $value = $wpinv_options[ $args['id'] ]; |
|
458 | - } else { |
|
459 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
460 | - } |
|
461 | - |
|
462 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
463 | - $args['readonly'] = true; |
|
464 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
465 | - $name = ''; |
|
466 | - } else { |
|
467 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
468 | - } |
|
469 | - |
|
470 | - $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
452 | + global $wpinv_options; |
|
453 | + |
|
454 | + if ( isset( $args['set_value'] ) ) { |
|
455 | + $value = $args['set_value']; |
|
456 | + } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
457 | + $value = $wpinv_options[ $args['id'] ]; |
|
458 | + } else { |
|
459 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
460 | + } |
|
461 | + |
|
462 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
463 | + $args['readonly'] = true; |
|
464 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
465 | + $name = ''; |
|
466 | + } else { |
|
467 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
468 | + } |
|
469 | + |
|
470 | + $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
471 | 471 | |
472 | - echo $html; |
|
472 | + echo $html; |
|
473 | 473 | } |
474 | 474 | |
475 | 475 | /** |
@@ -477,12 +477,12 @@ discard block |
||
477 | 477 | */ |
478 | 478 | function wpinv_checkbox_callback( $args ) { |
479 | 479 | |
480 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
481 | - $std = wpinv_get_option( $args['id'], $std ); |
|
482 | - $id = esc_attr( $args['id'] ); |
|
480 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
481 | + $std = wpinv_get_option( $args['id'], $std ); |
|
482 | + $id = esc_attr( $args['id'] ); |
|
483 | 483 | |
484 | - getpaid_hidden_field( "wpinv_settings[$id]", '0' ); |
|
485 | - ?> |
|
484 | + getpaid_hidden_field( "wpinv_settings[$id]", '0' ); |
|
485 | + ?> |
|
486 | 486 | <fieldset> |
487 | 487 | <label> |
488 | 488 | <input id="wpinv-settings-<?php echo $id; ?>" name="wpinv_settings[<?php echo $id; ?>]" <?php checked( empty( $std ), false ); ?> value="1" type="checkbox"> |
@@ -494,77 +494,77 @@ discard block |
||
494 | 494 | |
495 | 495 | function wpinv_multicheck_callback( $args ) { |
496 | 496 | |
497 | - global $wpinv_options; |
|
497 | + global $wpinv_options; |
|
498 | 498 | |
499 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
500 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
499 | + $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
500 | + $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
501 | 501 | |
502 | - if ( ! empty( $args['options'] ) ) { |
|
502 | + if ( ! empty( $args['options'] ) ) { |
|
503 | 503 | |
504 | - $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
505 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
504 | + $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
505 | + $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
506 | 506 | |
507 | - echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">'; |
|
507 | + echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">'; |
|
508 | 508 | foreach( $args['options'] as $key => $option ): |
509 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
510 | - if ( in_array( $sanitize_key, $value ) ) { |
|
511 | - $enabled = $sanitize_key; |
|
512 | - } else { |
|
513 | - $enabled = NULL; |
|
514 | - } |
|
515 | - echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
516 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
517 | - endforeach; |
|
518 | - echo '</div>'; |
|
519 | - echo '<p class="description">' . $args['desc'] . '</p>'; |
|
520 | - } |
|
509 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
510 | + if ( in_array( $sanitize_key, $value ) ) { |
|
511 | + $enabled = $sanitize_key; |
|
512 | + } else { |
|
513 | + $enabled = NULL; |
|
514 | + } |
|
515 | + echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
516 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
517 | + endforeach; |
|
518 | + echo '</div>'; |
|
519 | + echo '<p class="description">' . $args['desc'] . '</p>'; |
|
520 | + } |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | function wpinv_payment_icons_callback( $args ) { |
524 | - global $wpinv_options; |
|
524 | + global $wpinv_options; |
|
525 | 525 | |
526 | 526 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
527 | 527 | |
528 | - if ( ! empty( $args['options'] ) ) { |
|
529 | - foreach( $args['options'] as $key => $option ) { |
|
528 | + if ( ! empty( $args['options'] ) ) { |
|
529 | + foreach( $args['options'] as $key => $option ) { |
|
530 | 530 | $sanitize_key = wpinv_sanitize_key( $key ); |
531 | 531 | |
532 | - if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
533 | - $enabled = $option; |
|
534 | - } else { |
|
535 | - $enabled = NULL; |
|
536 | - } |
|
537 | - |
|
538 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
539 | - |
|
540 | - echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
541 | - |
|
542 | - if ( wpinv_string_is_image_url( $key ) ) { |
|
543 | - echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
544 | - } else { |
|
545 | - $card = strtolower( str_replace( ' ', '', $option ) ); |
|
546 | - |
|
547 | - if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
548 | - $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
549 | - } else { |
|
550 | - $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
551 | - $content_dir = WP_CONTENT_DIR; |
|
552 | - |
|
553 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
554 | - // Replaces backslashes with forward slashes for Windows systems |
|
555 | - $image = wp_normalize_path( $image ); |
|
556 | - $content_dir = wp_normalize_path( $content_dir ); |
|
557 | - } |
|
558 | - |
|
559 | - $image = str_replace( $content_dir, content_url(), $image ); |
|
560 | - } |
|
561 | - |
|
562 | - echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
563 | - } |
|
564 | - echo $option . '</label>'; |
|
565 | - } |
|
566 | - echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
567 | - } |
|
532 | + if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
533 | + $enabled = $option; |
|
534 | + } else { |
|
535 | + $enabled = NULL; |
|
536 | + } |
|
537 | + |
|
538 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
539 | + |
|
540 | + echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
541 | + |
|
542 | + if ( wpinv_string_is_image_url( $key ) ) { |
|
543 | + echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
544 | + } else { |
|
545 | + $card = strtolower( str_replace( ' ', '', $option ) ); |
|
546 | + |
|
547 | + if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
548 | + $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
549 | + } else { |
|
550 | + $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
551 | + $content_dir = WP_CONTENT_DIR; |
|
552 | + |
|
553 | + if ( function_exists( 'wp_normalize_path' ) ) { |
|
554 | + // Replaces backslashes with forward slashes for Windows systems |
|
555 | + $image = wp_normalize_path( $image ); |
|
556 | + $content_dir = wp_normalize_path( $content_dir ); |
|
557 | + } |
|
558 | + |
|
559 | + $image = str_replace( $content_dir, content_url(), $image ); |
|
560 | + } |
|
561 | + |
|
562 | + echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
563 | + } |
|
564 | + echo $option . '</label>'; |
|
565 | + } |
|
566 | + echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
567 | + } |
|
568 | 568 | } |
569 | 569 | |
570 | 570 | /** |
@@ -572,9 +572,9 @@ discard block |
||
572 | 572 | */ |
573 | 573 | function wpinv_radio_callback( $args ) { |
574 | 574 | |
575 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
576 | - $std = wpinv_get_option( $args['id'], $std ); |
|
577 | - ?> |
|
575 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
576 | + $std = wpinv_get_option( $args['id'], $std ); |
|
577 | + ?> |
|
578 | 578 | <fieldset> |
579 | 579 | <ul id="wpinv-settings-<?php echo esc_attr( $args['id'] ); ?>" style="margin-top: 0;"> |
580 | 580 | <?php foreach( $args['options'] as $key => $option ) : ?> |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | </ul> |
589 | 589 | </fieldset> |
590 | 590 | <?php |
591 | - getpaid_settings_description_callback( $args ); |
|
591 | + getpaid_settings_description_callback( $args ); |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | /** |
@@ -596,176 +596,176 @@ discard block |
||
596 | 596 | */ |
597 | 597 | function getpaid_settings_description_callback( $args ) { |
598 | 598 | |
599 | - if ( ! empty( $args['desc'] ) ) { |
|
600 | - $description = wp_kses_post( $args['desc'] ); |
|
601 | - echo "<p class='description'>$description</p>"; |
|
602 | - } |
|
599 | + if ( ! empty( $args['desc'] ) ) { |
|
600 | + $description = wp_kses_post( $args['desc'] ); |
|
601 | + echo "<p class='description'>$description</p>"; |
|
602 | + } |
|
603 | 603 | |
604 | 604 | } |
605 | 605 | |
606 | 606 | function wpinv_gateways_callback( $args ) { |
607 | - global $wpinv_options; |
|
607 | + global $wpinv_options; |
|
608 | 608 | |
609 | 609 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
610 | 610 | |
611 | - foreach ( $args['options'] as $key => $option ) : |
|
612 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
611 | + foreach ( $args['options'] as $key => $option ) : |
|
612 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
613 | 613 | |
614 | 614 | if ( isset( $wpinv_options['gateways'][ $key ] ) ) |
615 | - $enabled = '1'; |
|
616 | - else |
|
617 | - $enabled = null; |
|
615 | + $enabled = '1'; |
|
616 | + else |
|
617 | + $enabled = null; |
|
618 | 618 | |
619 | - echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
620 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
621 | - endforeach; |
|
619 | + echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
620 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
621 | + endforeach; |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | function wpinv_gateway_select_callback($args) { |
625 | - global $wpinv_options; |
|
625 | + global $wpinv_options; |
|
626 | 626 | |
627 | 627 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
628 | 628 | $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
629 | 629 | |
630 | - echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >'; |
|
630 | + echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >'; |
|
631 | 631 | |
632 | - foreach ( $args['options'] as $key => $option ) : |
|
633 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
632 | + foreach ( $args['options'] as $key => $option ) : |
|
633 | + if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
634 | 634 | $selected = selected( $key, $args['selected'], false ); |
635 | 635 | } else { |
636 | 636 | $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : ''; |
637 | 637 | } |
638 | - echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
639 | - endforeach; |
|
638 | + echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
639 | + endforeach; |
|
640 | 640 | |
641 | - echo '</select>'; |
|
642 | - echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
641 | + echo '</select>'; |
|
642 | + echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
643 | 643 | } |
644 | 644 | |
645 | 645 | function wpinv_text_callback( $args ) { |
646 | - global $wpinv_options; |
|
646 | + global $wpinv_options; |
|
647 | 647 | |
648 | 648 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
649 | 649 | |
650 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
651 | - $value = $wpinv_options[ $args['id'] ]; |
|
652 | - } else { |
|
653 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
654 | - } |
|
655 | - |
|
656 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
657 | - $args['readonly'] = true; |
|
658 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
659 | - $name = ''; |
|
660 | - } else { |
|
661 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
662 | - } |
|
663 | - $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
664 | - |
|
665 | - $readonly = $args['readonly'] === true ? ' readonly="readonly"' : ''; |
|
666 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
667 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>'; |
|
668 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
669 | - |
|
670 | - echo $html; |
|
650 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
651 | + $value = $wpinv_options[ $args['id'] ]; |
|
652 | + } else { |
|
653 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
654 | + } |
|
655 | + |
|
656 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
657 | + $args['readonly'] = true; |
|
658 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
659 | + $name = ''; |
|
660 | + } else { |
|
661 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
662 | + } |
|
663 | + $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
664 | + |
|
665 | + $readonly = $args['readonly'] === true ? ' readonly="readonly"' : ''; |
|
666 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
667 | + $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>'; |
|
668 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
669 | + |
|
670 | + echo $html; |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | function wpinv_number_callback( $args ) { |
674 | - global $wpinv_options; |
|
674 | + global $wpinv_options; |
|
675 | 675 | |
676 | 676 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
677 | 677 | |
678 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
679 | - $value = $wpinv_options[ $args['id'] ]; |
|
680 | - } else { |
|
681 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
682 | - } |
|
683 | - |
|
684 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
685 | - $args['readonly'] = true; |
|
686 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
687 | - $name = ''; |
|
688 | - } else { |
|
689 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
690 | - } |
|
691 | - |
|
692 | - $max = isset( $args['max'] ) ? $args['max'] : 999999; |
|
693 | - $min = isset( $args['min'] ) ? $args['min'] : 0; |
|
694 | - $step = isset( $args['step'] ) ? $args['step'] : 1; |
|
695 | - $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
696 | - |
|
697 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
698 | - $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
699 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
700 | - |
|
701 | - echo $html; |
|
678 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
679 | + $value = $wpinv_options[ $args['id'] ]; |
|
680 | + } else { |
|
681 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
682 | + } |
|
683 | + |
|
684 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
685 | + $args['readonly'] = true; |
|
686 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
687 | + $name = ''; |
|
688 | + } else { |
|
689 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
690 | + } |
|
691 | + |
|
692 | + $max = isset( $args['max'] ) ? $args['max'] : 999999; |
|
693 | + $min = isset( $args['min'] ) ? $args['min'] : 0; |
|
694 | + $step = isset( $args['step'] ) ? $args['step'] : 1; |
|
695 | + $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
696 | + |
|
697 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
698 | + $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
699 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
700 | + |
|
701 | + echo $html; |
|
702 | 702 | } |
703 | 703 | |
704 | 704 | function wpinv_textarea_callback( $args ) { |
705 | - global $wpinv_options; |
|
705 | + global $wpinv_options; |
|
706 | 706 | |
707 | 707 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
708 | 708 | |
709 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
710 | - $value = $wpinv_options[ $args['id'] ]; |
|
711 | - } else { |
|
712 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
713 | - } |
|
709 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
710 | + $value = $wpinv_options[ $args['id'] ]; |
|
711 | + } else { |
|
712 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
713 | + } |
|
714 | 714 | |
715 | 715 | $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
716 | 716 | $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text'; |
717 | 717 | |
718 | - $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
719 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
718 | + $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
719 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
720 | 720 | |
721 | - echo $html; |
|
721 | + echo $html; |
|
722 | 722 | } |
723 | 723 | |
724 | 724 | function wpinv_password_callback( $args ) { |
725 | - global $wpinv_options; |
|
725 | + global $wpinv_options; |
|
726 | 726 | |
727 | 727 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
728 | 728 | |
729 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
730 | - $value = $wpinv_options[ $args['id'] ]; |
|
731 | - } else { |
|
732 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
733 | - } |
|
729 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
730 | + $value = $wpinv_options[ $args['id'] ]; |
|
731 | + } else { |
|
732 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
733 | + } |
|
734 | 734 | |
735 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
736 | - $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
737 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
735 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
736 | + $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
737 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
738 | 738 | |
739 | - echo $html; |
|
739 | + echo $html; |
|
740 | 740 | } |
741 | 741 | |
742 | 742 | function wpinv_missing_callback($args) { |
743 | - printf( |
|
744 | - __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
745 | - '<strong>' . $args['id'] . '</strong>' |
|
746 | - ); |
|
743 | + printf( |
|
744 | + __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
745 | + '<strong>' . $args['id'] . '</strong>' |
|
746 | + ); |
|
747 | 747 | } |
748 | 748 | |
749 | 749 | function wpinv_select_callback($args) { |
750 | - global $wpinv_options; |
|
750 | + global $wpinv_options; |
|
751 | 751 | |
752 | 752 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
753 | 753 | |
754 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
755 | - $value = $wpinv_options[ $args['id'] ]; |
|
756 | - } else { |
|
757 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
758 | - } |
|
754 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
755 | + $value = $wpinv_options[ $args['id'] ]; |
|
756 | + } else { |
|
757 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
758 | + } |
|
759 | 759 | |
760 | 760 | if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
761 | 761 | $value = $args['selected']; |
762 | 762 | } |
763 | 763 | |
764 | - if ( isset( $args['placeholder'] ) ) { |
|
765 | - $placeholder = $args['placeholder']; |
|
766 | - } else { |
|
767 | - $placeholder = ''; |
|
768 | - } |
|
764 | + if ( isset( $args['placeholder'] ) ) { |
|
765 | + $placeholder = $args['placeholder']; |
|
766 | + } else { |
|
767 | + $placeholder = ''; |
|
768 | + } |
|
769 | 769 | |
770 | 770 | if( !empty( $args['onchange'] ) ) { |
771 | 771 | $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
@@ -775,137 +775,137 @@ discard block |
||
775 | 775 | |
776 | 776 | $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
777 | 777 | |
778 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />'; |
|
778 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />'; |
|
779 | 779 | |
780 | - foreach ( $args['options'] as $option => $name ) { |
|
781 | - $selected = selected( $option, $value, false ); |
|
782 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
783 | - } |
|
780 | + foreach ( $args['options'] as $option => $name ) { |
|
781 | + $selected = selected( $option, $value, false ); |
|
782 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
783 | + } |
|
784 | 784 | |
785 | - $html .= '</select>'; |
|
786 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
785 | + $html .= '</select>'; |
|
786 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
787 | 787 | |
788 | - echo $html; |
|
788 | + echo $html; |
|
789 | 789 | } |
790 | 790 | |
791 | 791 | function wpinv_color_select_callback( $args ) { |
792 | - global $wpinv_options; |
|
792 | + global $wpinv_options; |
|
793 | 793 | |
794 | 794 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
795 | 795 | |
796 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
797 | - $value = $wpinv_options[ $args['id'] ]; |
|
798 | - } else { |
|
799 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
800 | - } |
|
796 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
797 | + $value = $wpinv_options[ $args['id'] ]; |
|
798 | + } else { |
|
799 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
800 | + } |
|
801 | 801 | |
802 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
802 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
803 | 803 | |
804 | - foreach ( $args['options'] as $option => $color ) { |
|
805 | - $selected = selected( $option, $value, false ); |
|
806 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
807 | - } |
|
804 | + foreach ( $args['options'] as $option => $color ) { |
|
805 | + $selected = selected( $option, $value, false ); |
|
806 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
807 | + } |
|
808 | 808 | |
809 | - $html .= '</select>'; |
|
810 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
809 | + $html .= '</select>'; |
|
810 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
811 | 811 | |
812 | - echo $html; |
|
812 | + echo $html; |
|
813 | 813 | } |
814 | 814 | |
815 | 815 | function wpinv_rich_editor_callback( $args ) { |
816 | - global $wpinv_options, $wp_version; |
|
816 | + global $wpinv_options, $wp_version; |
|
817 | 817 | |
818 | 818 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
819 | 819 | |
820 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
821 | - $value = $wpinv_options[ $args['id'] ]; |
|
820 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
821 | + $value = $wpinv_options[ $args['id'] ]; |
|
822 | 822 | |
823 | - if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
824 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
825 | - } |
|
826 | - } else { |
|
827 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
828 | - } |
|
823 | + if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
824 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
825 | + } |
|
826 | + } else { |
|
827 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
828 | + } |
|
829 | 829 | |
830 | - $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
830 | + $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
831 | 831 | |
832 | - $html = '<div class="getpaid-settings-editor-input">'; |
|
833 | - if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
834 | - ob_start(); |
|
835 | - wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
836 | - $html .= ob_get_clean(); |
|
837 | - } else { |
|
838 | - $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
839 | - } |
|
832 | + $html = '<div class="getpaid-settings-editor-input">'; |
|
833 | + if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
834 | + ob_start(); |
|
835 | + wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
836 | + $html .= ob_get_clean(); |
|
837 | + } else { |
|
838 | + $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
839 | + } |
|
840 | 840 | |
841 | - $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
841 | + $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
842 | 842 | |
843 | - echo $html; |
|
843 | + echo $html; |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | function wpinv_upload_callback( $args ) { |
847 | - global $wpinv_options; |
|
847 | + global $wpinv_options; |
|
848 | 848 | |
849 | 849 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
850 | 850 | |
851 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
852 | - $value = $wpinv_options[$args['id']]; |
|
853 | - } else { |
|
854 | - $value = isset($args['std']) ? $args['std'] : ''; |
|
855 | - } |
|
851 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
852 | + $value = $wpinv_options[$args['id']]; |
|
853 | + } else { |
|
854 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
855 | + } |
|
856 | 856 | |
857 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
858 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
859 | - $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
860 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
857 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
858 | + $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
859 | + $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
860 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
861 | 861 | |
862 | - echo $html; |
|
862 | + echo $html; |
|
863 | 863 | } |
864 | 864 | |
865 | 865 | function wpinv_color_callback( $args ) { |
866 | - global $wpinv_options; |
|
866 | + global $wpinv_options; |
|
867 | 867 | |
868 | 868 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
869 | 869 | |
870 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
871 | - $value = $wpinv_options[ $args['id'] ]; |
|
872 | - } else { |
|
873 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
874 | - } |
|
870 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
871 | + $value = $wpinv_options[ $args['id'] ]; |
|
872 | + } else { |
|
873 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
874 | + } |
|
875 | 875 | |
876 | - $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
876 | + $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
877 | 877 | |
878 | - $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
879 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
878 | + $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
879 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
880 | 880 | |
881 | - echo $html; |
|
881 | + echo $html; |
|
882 | 882 | } |
883 | 883 | |
884 | 884 | function wpinv_country_states_callback($args) { |
885 | - global $wpinv_options; |
|
885 | + global $wpinv_options; |
|
886 | 886 | |
887 | 887 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
888 | 888 | |
889 | - if ( isset( $args['placeholder'] ) ) { |
|
890 | - $placeholder = $args['placeholder']; |
|
891 | - } else { |
|
892 | - $placeholder = ''; |
|
893 | - } |
|
889 | + if ( isset( $args['placeholder'] ) ) { |
|
890 | + $placeholder = $args['placeholder']; |
|
891 | + } else { |
|
892 | + $placeholder = ''; |
|
893 | + } |
|
894 | 894 | |
895 | - $states = wpinv_get_country_states(); |
|
895 | + $states = wpinv_get_country_states(); |
|
896 | 896 | |
897 | - $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
898 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
897 | + $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
898 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
899 | 899 | |
900 | - foreach ( $states as $option => $name ) { |
|
901 | - $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
902 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
903 | - } |
|
900 | + foreach ( $states as $option => $name ) { |
|
901 | + $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
902 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
903 | + } |
|
904 | 904 | |
905 | - $html .= '</select>'; |
|
906 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
905 | + $html .= '</select>'; |
|
906 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
907 | 907 | |
908 | - echo $html; |
|
908 | + echo $html; |
|
909 | 909 | } |
910 | 910 | |
911 | 911 | /** |
@@ -913,7 +913,7 @@ discard block |
||
913 | 913 | */ |
914 | 914 | function wpinv_tax_rates_callback() { |
915 | 915 | |
916 | - ?> |
|
916 | + ?> |
|
917 | 917 | </td> |
918 | 918 | </tr> |
919 | 919 | <tr class="bsui"> |
@@ -928,17 +928,17 @@ discard block |
||
928 | 928 | * Displays a tax rate' edit row. |
929 | 929 | */ |
930 | 930 | function wpinv_tax_rate_callback( $tax_rate, $key, $echo = true ) { |
931 | - ob_start(); |
|
931 | + ob_start(); |
|
932 | 932 | |
933 | - $key = sanitize_key( $key ); |
|
934 | - $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate']; |
|
935 | - include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php'; |
|
933 | + $key = sanitize_key( $key ); |
|
934 | + $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate']; |
|
935 | + include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php'; |
|
936 | 936 | |
937 | - if ( $echo ) { |
|
938 | - echo ob_get_clean( $echo ); |
|
939 | - } else { |
|
940 | - return ob_get_clean( $echo ); |
|
941 | - } |
|
937 | + if ( $echo ) { |
|
938 | + echo ob_get_clean( $echo ); |
|
939 | + } else { |
|
940 | + return ob_get_clean( $echo ); |
|
941 | + } |
|
942 | 942 | |
943 | 943 | } |
944 | 944 | |
@@ -966,15 +966,15 @@ discard block |
||
966 | 966 | } |
967 | 967 | |
968 | 968 | function wpinv_descriptive_text_callback( $args ) { |
969 | - echo wp_kses_post( $args['desc'] ); |
|
969 | + echo wp_kses_post( $args['desc'] ); |
|
970 | 970 | } |
971 | 971 | |
972 | 972 | function wpinv_hook_callback( $args ) { |
973 | - do_action( 'wpinv_' . $args['id'], $args ); |
|
973 | + do_action( 'wpinv_' . $args['id'], $args ); |
|
974 | 974 | } |
975 | 975 | |
976 | 976 | function wpinv_set_settings_cap() { |
977 | - return wpinv_get_capability(); |
|
977 | + return wpinv_get_capability(); |
|
978 | 978 | } |
979 | 979 | add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' ); |
980 | 980 |
@@ -13,168 +13,168 @@ |
||
13 | 13 | */ |
14 | 14 | class GetPaid_Tax { |
15 | 15 | |
16 | - /** |
|
17 | - * Calculates tax for a line item. |
|
18 | - * |
|
19 | - * @param float $price The price to calc tax on. |
|
20 | - * @param array $rates The rates to apply. |
|
21 | - * @param boolean $price_includes_tax Whether the passed price has taxes included. |
|
22 | - * @return array Array of tax name => tax amount. |
|
23 | - */ |
|
24 | - public static function calc_tax( $price, $rates, $price_includes_tax = false ) { |
|
25 | - |
|
26 | - if ( $price_includes_tax ) { |
|
27 | - $taxes = self::calc_inclusive_tax( $price, $rates ); |
|
28 | - } else { |
|
29 | - $taxes = self::calc_exclusive_tax( $price, $rates ); |
|
30 | - } |
|
31 | - |
|
32 | - return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax ); |
|
33 | - |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * Calc tax from inclusive price. |
|
38 | - * |
|
39 | - * @param float $price Price to calculate tax for. |
|
40 | - * @param array $rates Array of tax rates. |
|
41 | - * @return array |
|
42 | - */ |
|
43 | - public static function calc_inclusive_tax( $price, $rates ) { |
|
44 | - $taxes = array(); |
|
45 | - $tax_rates = wp_list_pluck( $rates, 'rate', 'name' ); |
|
46 | - |
|
47 | - // Add tax rates. |
|
48 | - $tax_rate = 1 + ( array_sum( $tax_rates ) / 100 ); |
|
49 | - |
|
50 | - foreach ( $tax_rates as $name => $rate ) { |
|
51 | - $the_rate = ( $rate / 100 ) / $tax_rate; |
|
52 | - $net_price = $price - ( $the_rate * $price ); |
|
53 | - $tax_amount = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price ); |
|
54 | - $taxes[ $name ] = $tax_amount; |
|
55 | - } |
|
56 | - |
|
57 | - // Round all taxes to precision (4DP) before passing them back. |
|
58 | - $taxes = array_map( array( __CLASS__, 'round' ), $taxes ); |
|
59 | - |
|
60 | - return $taxes; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Calc tax from exclusive price. |
|
65 | - * |
|
66 | - * @param float $price Price to calculate tax for. |
|
67 | - * @param array $rates Array of tax rates. |
|
68 | - * @return array |
|
69 | - */ |
|
70 | - public static function calc_exclusive_tax( $price, $rates ) { |
|
71 | - $taxes = array(); |
|
72 | - $tax_rates = wp_list_pluck( $rates, 'rate', 'name' ); |
|
73 | - |
|
74 | - foreach ( $tax_rates as $name => $rate ) { |
|
75 | - |
|
76 | - $tax_amount = $price * ( $rate / 100 ); |
|
77 | - $taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price ); |
|
78 | - |
|
79 | - } |
|
80 | - |
|
81 | - // Round all taxes to precision (4DP) before passing them back. |
|
82 | - $taxes = array_map( array( __CLASS__, 'round' ), $taxes ); |
|
83 | - |
|
84 | - return $taxes; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Get's an array of all tax rates. |
|
89 | - * |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - public static function get_all_tax_rates() { |
|
93 | - |
|
94 | - $rates = get_option( 'wpinv_tax_rates', array() ); |
|
95 | - |
|
96 | - return apply_filters( |
|
97 | - 'getpaid_get_all_tax_rates', |
|
98 | - array_filter( wpinv_parse_list( $rates ) ) |
|
99 | - ); |
|
100 | - |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Get's an array of default tax rates. |
|
105 | - * |
|
106 | - * @return array |
|
107 | - */ |
|
108 | - public static function get_default_tax_rates() { |
|
109 | - |
|
110 | - return apply_filters( |
|
111 | - 'getpaid_get_default_tax_rates', |
|
112 | - array( |
|
113 | - array( |
|
114 | - 'country' => wpinv_get_default_country(), |
|
115 | - 'state' => wpinv_get_default_state(), |
|
116 | - 'global' => true, |
|
117 | - 'rate' => wpinv_get_default_tax_rate(), |
|
118 | - 'name' => __( 'Base Tax', 'invoicing' ), |
|
119 | - ) |
|
120 | - ) |
|
121 | - ); |
|
122 | - |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Get's an array of tax rates for a given address. |
|
127 | - * |
|
128 | - * @param string $country |
|
129 | - * @param string $state |
|
130 | - * @return array |
|
131 | - */ |
|
132 | - public static function get_address_tax_rates( $country, $state ) { |
|
133 | - |
|
134 | - $all_tax_rates = self::get_all_tax_rates(); |
|
135 | - $matching_rates = array_merge( |
|
136 | - wp_list_filter( $all_tax_rates, array( 'country' => $country ) ), |
|
137 | - wp_list_filter( $all_tax_rates, array( 'country' => '' ) ) |
|
138 | - ); |
|
139 | - |
|
140 | - foreach ( $matching_rates as $i => $rate ) { |
|
141 | - |
|
142 | - $states = array_filter( wpinv_clean( explode( ',', $rate['state'] ) ) ); |
|
143 | - if ( empty( $rate['global'] ) && ! in_array( $state, $states ) ) { |
|
144 | - unset( $matching_rates[ $i ] ); |
|
145 | - } |
|
146 | - |
|
147 | - } |
|
148 | - |
|
149 | - return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state ); |
|
150 | - |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Sums a set of taxes to form a single total. Result is rounded to precision. |
|
155 | - * |
|
156 | - * @param array $taxes Array of taxes. |
|
157 | - * @return float |
|
158 | - */ |
|
159 | - public static function get_tax_total( $taxes ) { |
|
160 | - return self::round( array_sum( $taxes ) ); |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Round to precision. |
|
165 | - * |
|
166 | - * Filter example: to return rounding to .5 cents you'd use: |
|
167 | - * |
|
168 | - * function euro_5cent_rounding( $in ) { |
|
169 | - * return round( $in / 5, 2 ) * 5; |
|
170 | - * } |
|
171 | - * add_filter( 'getpaid_tax_round', 'euro_5cent_rounding' ); |
|
172 | - * |
|
173 | - * @param float|int $in Value to round. |
|
174 | - * @return float |
|
175 | - */ |
|
176 | - public static function round( $in ) { |
|
177 | - return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in ); |
|
178 | - } |
|
16 | + /** |
|
17 | + * Calculates tax for a line item. |
|
18 | + * |
|
19 | + * @param float $price The price to calc tax on. |
|
20 | + * @param array $rates The rates to apply. |
|
21 | + * @param boolean $price_includes_tax Whether the passed price has taxes included. |
|
22 | + * @return array Array of tax name => tax amount. |
|
23 | + */ |
|
24 | + public static function calc_tax( $price, $rates, $price_includes_tax = false ) { |
|
25 | + |
|
26 | + if ( $price_includes_tax ) { |
|
27 | + $taxes = self::calc_inclusive_tax( $price, $rates ); |
|
28 | + } else { |
|
29 | + $taxes = self::calc_exclusive_tax( $price, $rates ); |
|
30 | + } |
|
31 | + |
|
32 | + return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax ); |
|
33 | + |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * Calc tax from inclusive price. |
|
38 | + * |
|
39 | + * @param float $price Price to calculate tax for. |
|
40 | + * @param array $rates Array of tax rates. |
|
41 | + * @return array |
|
42 | + */ |
|
43 | + public static function calc_inclusive_tax( $price, $rates ) { |
|
44 | + $taxes = array(); |
|
45 | + $tax_rates = wp_list_pluck( $rates, 'rate', 'name' ); |
|
46 | + |
|
47 | + // Add tax rates. |
|
48 | + $tax_rate = 1 + ( array_sum( $tax_rates ) / 100 ); |
|
49 | + |
|
50 | + foreach ( $tax_rates as $name => $rate ) { |
|
51 | + $the_rate = ( $rate / 100 ) / $tax_rate; |
|
52 | + $net_price = $price - ( $the_rate * $price ); |
|
53 | + $tax_amount = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price ); |
|
54 | + $taxes[ $name ] = $tax_amount; |
|
55 | + } |
|
56 | + |
|
57 | + // Round all taxes to precision (4DP) before passing them back. |
|
58 | + $taxes = array_map( array( __CLASS__, 'round' ), $taxes ); |
|
59 | + |
|
60 | + return $taxes; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Calc tax from exclusive price. |
|
65 | + * |
|
66 | + * @param float $price Price to calculate tax for. |
|
67 | + * @param array $rates Array of tax rates. |
|
68 | + * @return array |
|
69 | + */ |
|
70 | + public static function calc_exclusive_tax( $price, $rates ) { |
|
71 | + $taxes = array(); |
|
72 | + $tax_rates = wp_list_pluck( $rates, 'rate', 'name' ); |
|
73 | + |
|
74 | + foreach ( $tax_rates as $name => $rate ) { |
|
75 | + |
|
76 | + $tax_amount = $price * ( $rate / 100 ); |
|
77 | + $taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price ); |
|
78 | + |
|
79 | + } |
|
80 | + |
|
81 | + // Round all taxes to precision (4DP) before passing them back. |
|
82 | + $taxes = array_map( array( __CLASS__, 'round' ), $taxes ); |
|
83 | + |
|
84 | + return $taxes; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Get's an array of all tax rates. |
|
89 | + * |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + public static function get_all_tax_rates() { |
|
93 | + |
|
94 | + $rates = get_option( 'wpinv_tax_rates', array() ); |
|
95 | + |
|
96 | + return apply_filters( |
|
97 | + 'getpaid_get_all_tax_rates', |
|
98 | + array_filter( wpinv_parse_list( $rates ) ) |
|
99 | + ); |
|
100 | + |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Get's an array of default tax rates. |
|
105 | + * |
|
106 | + * @return array |
|
107 | + */ |
|
108 | + public static function get_default_tax_rates() { |
|
109 | + |
|
110 | + return apply_filters( |
|
111 | + 'getpaid_get_default_tax_rates', |
|
112 | + array( |
|
113 | + array( |
|
114 | + 'country' => wpinv_get_default_country(), |
|
115 | + 'state' => wpinv_get_default_state(), |
|
116 | + 'global' => true, |
|
117 | + 'rate' => wpinv_get_default_tax_rate(), |
|
118 | + 'name' => __( 'Base Tax', 'invoicing' ), |
|
119 | + ) |
|
120 | + ) |
|
121 | + ); |
|
122 | + |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Get's an array of tax rates for a given address. |
|
127 | + * |
|
128 | + * @param string $country |
|
129 | + * @param string $state |
|
130 | + * @return array |
|
131 | + */ |
|
132 | + public static function get_address_tax_rates( $country, $state ) { |
|
133 | + |
|
134 | + $all_tax_rates = self::get_all_tax_rates(); |
|
135 | + $matching_rates = array_merge( |
|
136 | + wp_list_filter( $all_tax_rates, array( 'country' => $country ) ), |
|
137 | + wp_list_filter( $all_tax_rates, array( 'country' => '' ) ) |
|
138 | + ); |
|
139 | + |
|
140 | + foreach ( $matching_rates as $i => $rate ) { |
|
141 | + |
|
142 | + $states = array_filter( wpinv_clean( explode( ',', $rate['state'] ) ) ); |
|
143 | + if ( empty( $rate['global'] ) && ! in_array( $state, $states ) ) { |
|
144 | + unset( $matching_rates[ $i ] ); |
|
145 | + } |
|
146 | + |
|
147 | + } |
|
148 | + |
|
149 | + return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state ); |
|
150 | + |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Sums a set of taxes to form a single total. Result is rounded to precision. |
|
155 | + * |
|
156 | + * @param array $taxes Array of taxes. |
|
157 | + * @return float |
|
158 | + */ |
|
159 | + public static function get_tax_total( $taxes ) { |
|
160 | + return self::round( array_sum( $taxes ) ); |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Round to precision. |
|
165 | + * |
|
166 | + * Filter example: to return rounding to .5 cents you'd use: |
|
167 | + * |
|
168 | + * function euro_5cent_rounding( $in ) { |
|
169 | + * return round( $in / 5, 2 ) * 5; |
|
170 | + * } |
|
171 | + * add_filter( 'getpaid_tax_round', 'euro_5cent_rounding' ); |
|
172 | + * |
|
173 | + * @param float|int $in Value to round. |
|
174 | + * @return float |
|
175 | + */ |
|
176 | + public static function round( $in ) { |
|
177 | + return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in ); |
|
178 | + } |
|
179 | 179 | |
180 | 180 | } |