@@ -34,11 +34,11 @@ discard block |
||
34 | 34 | */ |
35 | 35 | function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) { |
36 | 36 | |
37 | - if ( current_user_can( 'manage_options' ) ) { |
|
38 | - return 'manage_options'; |
|
39 | - }; |
|
37 | + if ( current_user_can( 'manage_options' ) ) { |
|
38 | + return 'manage_options'; |
|
39 | + }; |
|
40 | 40 | |
41 | - return $capalibilty; |
|
41 | + return $capalibilty; |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -61,9 +61,9 @@ discard block |
||
61 | 61 | * @return bool Whether the current user has the given capability. |
62 | 62 | */ |
63 | 63 | function wpinv_current_user_can( $capability, $args = array() ) { |
64 | - $can = wpinv_current_user_can_manage_invoicing(); |
|
64 | + $can = wpinv_current_user_can_manage_invoicing(); |
|
65 | 65 | |
66 | - return apply_filters( 'getpaid_current_user_can', $can, $capability, $args ); |
|
66 | + return apply_filters( 'getpaid_current_user_can', $can, $capability, $args ); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -77,10 +77,10 @@ discard block |
||
77 | 77 | // Prepare user values. |
78 | 78 | $prefix = preg_replace( '/\s+/', '', $prefix ); |
79 | 79 | $prefix = empty( $prefix ) ? $email : $prefix; |
80 | - $args = array( |
|
81 | - 'user_login' => wpinv_generate_user_name( $prefix ), |
|
82 | - 'user_pass' => wp_generate_password(), |
|
83 | - 'user_email' => $email, |
|
80 | + $args = array( |
|
81 | + 'user_login' => wpinv_generate_user_name( $prefix ), |
|
82 | + 'user_pass' => wp_generate_password(), |
|
83 | + 'user_email' => $email, |
|
84 | 84 | 'role' => 'subscriber', |
85 | 85 | ); |
86 | 86 | |
@@ -97,16 +97,16 @@ discard block |
||
97 | 97 | function wpinv_generate_user_name( $prefix = '' ) { |
98 | 98 | |
99 | 99 | // If prefix is an email, retrieve the part before the email. |
100 | - $prefix = strtok( $prefix, '@' ); |
|
100 | + $prefix = strtok( $prefix, '@' ); |
|
101 | 101 | $prefix = trim( $prefix, '.' ); |
102 | 102 | |
103 | - // Sanitize the username. |
|
104 | - $prefix = sanitize_user( $prefix, true ); |
|
103 | + // Sanitize the username. |
|
104 | + $prefix = sanitize_user( $prefix, true ); |
|
105 | 105 | |
106 | - $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
107 | - if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
108 | - $prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
109 | - } |
|
106 | + $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
107 | + if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
108 | + $prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
109 | + } |
|
110 | 110 | |
111 | 111 | $username = $prefix; |
112 | 112 | $postfix = 2; |
@@ -235,43 +235,43 @@ discard block |
||
235 | 235 | |
236 | 236 | foreach ( getpaid_user_address_fields() as $key => $label ) { |
237 | 237 | |
238 | - // Display the country. |
|
239 | - if ( 'country' == $key ) { |
|
240 | - |
|
241 | - aui()->select( |
|
242 | - array( |
|
243 | - 'options' => wpinv_get_country_list(), |
|
244 | - 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
|
245 | - 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
246 | - 'value' => sanitize_text_field( getpaid_get_user_address_field( get_current_user_id(), $key ) ), |
|
247 | - 'placeholder' => $label, |
|
248 | - 'label' => wp_kses_post( $label ), |
|
249 | - 'label_type' => 'vertical', |
|
250 | - 'class' => 'getpaid-address-field', |
|
238 | + // Display the country. |
|
239 | + if ( 'country' == $key ) { |
|
240 | + |
|
241 | + aui()->select( |
|
242 | + array( |
|
243 | + 'options' => wpinv_get_country_list(), |
|
244 | + 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
|
245 | + 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
246 | + 'value' => sanitize_text_field( getpaid_get_user_address_field( get_current_user_id(), $key ) ), |
|
247 | + 'placeholder' => $label, |
|
248 | + 'label' => wp_kses_post( $label ), |
|
249 | + 'label_type' => 'vertical', |
|
250 | + 'class' => 'getpaid-address-field', |
|
251 | 251 | ), |
252 | 252 | true |
253 | - ); |
|
254 | - |
|
255 | - } |
|
256 | - |
|
257 | - // Display the state. |
|
258 | - elseif ( 'state' == $key ) { |
|
259 | - |
|
260 | - getpaid_get_states_select_markup( |
|
261 | - getpaid_get_user_address_field( get_current_user_id(), 'country' ), |
|
262 | - getpaid_get_user_address_field( get_current_user_id(), 'state' ), |
|
263 | - $label, |
|
264 | - $label, |
|
265 | - '', |
|
266 | - false, |
|
267 | - '', |
|
268 | - 'getpaid_address[' . esc_attr( $key ) . ']', |
|
253 | + ); |
|
254 | + |
|
255 | + } |
|
256 | + |
|
257 | + // Display the state. |
|
258 | + elseif ( 'state' == $key ) { |
|
259 | + |
|
260 | + getpaid_get_states_select_markup( |
|
261 | + getpaid_get_user_address_field( get_current_user_id(), 'country' ), |
|
262 | + getpaid_get_user_address_field( get_current_user_id(), 'state' ), |
|
263 | + $label, |
|
264 | + $label, |
|
265 | + '', |
|
266 | + false, |
|
267 | + '', |
|
268 | + 'getpaid_address[' . esc_attr( $key ) . ']', |
|
269 | 269 | true |
270 | - ); |
|
270 | + ); |
|
271 | 271 | |
272 | 272 | } else { |
273 | 273 | |
274 | - aui()->input( |
|
274 | + aui()->input( |
|
275 | 275 | array( |
276 | 276 | 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
277 | 277 | 'id' => 'wpinv-' . sanitize_html_class( $key ), |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | 'class' => 'getpaid-address-field', |
284 | 284 | ), |
285 | 285 | true |
286 | - ); |
|
286 | + ); |
|
287 | 287 | |
288 | 288 | } |
289 | 289 | } |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | function getpaid_allowed_html() { |
423 | 423 | $allowed_html = wp_kses_allowed_html( 'post' ); |
424 | 424 | |
425 | - // form fields |
|
425 | + // form fields |
|
426 | 426 | $allowed_html['form'] = array( |
427 | 427 | 'action' => true, |
428 | 428 | 'accept' => true, |
@@ -434,12 +434,12 @@ discard block |
||
434 | 434 | ); |
435 | 435 | |
436 | 436 | // - input |
437 | - $allowed_html['input'] = array( |
|
438 | - 'class' => array(), |
|
439 | - 'id' => array(), |
|
440 | - 'name' => array(), |
|
441 | - 'value' => array(), |
|
442 | - 'type' => array(), |
|
437 | + $allowed_html['input'] = array( |
|
438 | + 'class' => array(), |
|
439 | + 'id' => array(), |
|
440 | + 'name' => array(), |
|
441 | + 'value' => array(), |
|
442 | + 'type' => array(), |
|
443 | 443 | 'placeholder' => array(), |
444 | 444 | 'autocomplete' => array(), |
445 | 445 | 'autofocus' => array(), |
@@ -453,33 +453,33 @@ discard block |
||
453 | 453 | 'max' => array(), |
454 | 454 | 'step' => array(), |
455 | 455 | 'size' => array(), |
456 | - ); |
|
456 | + ); |
|
457 | 457 | |
458 | 458 | // - input |
459 | - $allowed_html['textarea'] = array( |
|
460 | - 'class' => array(), |
|
461 | - 'id' => array(), |
|
462 | - 'name' => array(), |
|
463 | - 'value' => array(), |
|
464 | - ); |
|
465 | - |
|
466 | - // select |
|
467 | - $allowed_html['select'] = array( |
|
468 | - 'class' => array(), |
|
469 | - 'id' => array(), |
|
470 | - 'name' => array(), |
|
459 | + $allowed_html['textarea'] = array( |
|
460 | + 'class' => array(), |
|
461 | + 'id' => array(), |
|
462 | + 'name' => array(), |
|
463 | + 'value' => array(), |
|
464 | + ); |
|
465 | + |
|
466 | + // select |
|
467 | + $allowed_html['select'] = array( |
|
468 | + 'class' => array(), |
|
469 | + 'id' => array(), |
|
470 | + 'name' => array(), |
|
471 | 471 | 'autocomplete' => array(), |
472 | 472 | 'multiple' => array(), |
473 | - ); |
|
473 | + ); |
|
474 | 474 | |
475 | - // select options |
|
476 | - $allowed_html['option'] = array( |
|
477 | - 'selected' => array(), |
|
475 | + // select options |
|
476 | + $allowed_html['option'] = array( |
|
477 | + 'selected' => array(), |
|
478 | 478 | 'disabled' => array(), |
479 | 479 | 'value' => array(), |
480 | - ); |
|
480 | + ); |
|
481 | 481 | |
482 | - return $allowed_html; |
|
482 | + return $allowed_html; |
|
483 | 483 | |
484 | 484 | } |
485 | 485 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package GetPaid |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Generates a users select dropdown. |
@@ -16,13 +16,13 @@ discard block |
||
16 | 16 | * @param array $args |
17 | 17 | * @see wp_dropdown_users |
18 | 18 | */ |
19 | -function wpinv_dropdown_users( $args = '' ) { |
|
19 | +function wpinv_dropdown_users($args = '') { |
|
20 | 20 | |
21 | - if ( is_array( $args ) && ! empty( $args['show'] ) && 'display_name_with_email' == $args['show'] ) { |
|
21 | + if (is_array($args) && !empty($args['show']) && 'display_name_with_email' == $args['show']) { |
|
22 | 22 | $args['show'] = 'display_name_with_login'; |
23 | 23 | } |
24 | 24 | |
25 | - return wp_dropdown_users( $args ); |
|
25 | + return wp_dropdown_users($args); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | * @return string capability to check against |
33 | 33 | * @param string $capalibilty Optional. The alternative capability to check against. |
34 | 34 | */ |
35 | -function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) { |
|
35 | +function wpinv_get_capability($capalibilty = 'manage_invoicing') { |
|
36 | 36 | |
37 | - if ( current_user_can( 'manage_options' ) ) { |
|
37 | + if (current_user_can('manage_options')) { |
|
38 | 38 | return 'manage_options'; |
39 | 39 | }; |
40 | 40 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @return bool |
49 | 49 | */ |
50 | 50 | function wpinv_current_user_can_manage_invoicing() { |
51 | - return current_user_can( wpinv_get_capability() ); |
|
51 | + return current_user_can(wpinv_get_capability()); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -60,10 +60,10 @@ discard block |
||
60 | 60 | * @param mixed $args Optional further parameters, typically starting with an object. |
61 | 61 | * @return bool Whether the current user has the given capability. |
62 | 62 | */ |
63 | -function wpinv_current_user_can( $capability, $args = array() ) { |
|
63 | +function wpinv_current_user_can($capability, $args = array()) { |
|
64 | 64 | $can = wpinv_current_user_can_manage_invoicing(); |
65 | 65 | |
66 | - return apply_filters( 'getpaid_current_user_can', $can, $capability, $args ); |
|
66 | + return apply_filters('getpaid_current_user_can', $can, $capability, $args); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -72,19 +72,19 @@ discard block |
||
72 | 72 | * @since 1.0.19 |
73 | 73 | * @return int|WP_Error |
74 | 74 | */ |
75 | -function wpinv_create_user( $email, $prefix = '' ) { |
|
75 | +function wpinv_create_user($email, $prefix = '') { |
|
76 | 76 | |
77 | 77 | // Prepare user values. |
78 | - $prefix = preg_replace( '/\s+/', '', $prefix ); |
|
79 | - $prefix = empty( $prefix ) ? $email : $prefix; |
|
80 | - $args = array( |
|
81 | - 'user_login' => wpinv_generate_user_name( $prefix ), |
|
78 | + $prefix = preg_replace('/\s+/', '', $prefix); |
|
79 | + $prefix = empty($prefix) ? $email : $prefix; |
|
80 | + $args = array( |
|
81 | + 'user_login' => wpinv_generate_user_name($prefix), |
|
82 | 82 | 'user_pass' => wp_generate_password(), |
83 | 83 | 'user_email' => $email, |
84 | 84 | 'role' => 'subscriber', |
85 | 85 | ); |
86 | 86 | |
87 | - return wp_insert_user( $args ); |
|
87 | + return wp_insert_user($args); |
|
88 | 88 | |
89 | 89 | } |
90 | 90 | |
@@ -94,26 +94,26 @@ discard block |
||
94 | 94 | * @since 1.0.19 |
95 | 95 | * @return bool|WP_User |
96 | 96 | */ |
97 | -function wpinv_generate_user_name( $prefix = '' ) { |
|
97 | +function wpinv_generate_user_name($prefix = '') { |
|
98 | 98 | |
99 | 99 | // If prefix is an email, retrieve the part before the email. |
100 | - $prefix = strtok( $prefix, '@' ); |
|
101 | - $prefix = trim( $prefix, '.' ); |
|
100 | + $prefix = strtok($prefix, '@'); |
|
101 | + $prefix = trim($prefix, '.'); |
|
102 | 102 | |
103 | 103 | // Sanitize the username. |
104 | - $prefix = sanitize_user( $prefix, true ); |
|
104 | + $prefix = sanitize_user($prefix, true); |
|
105 | 105 | |
106 | - $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
107 | - if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
108 | - $prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
106 | + $illegal_logins = (array) apply_filters('illegal_user_logins', array()); |
|
107 | + if (empty($prefix) || in_array(strtolower($prefix), array_map('strtolower', $illegal_logins), true)) { |
|
108 | + $prefix = 'gtp_' . zeroise(wp_rand(0, 9999), 4); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | $username = $prefix; |
112 | 112 | $postfix = 2; |
113 | 113 | |
114 | - while ( username_exists( $username ) ) { |
|
114 | + while (username_exists($username)) { |
|
115 | 115 | $username = "{$prefix}{$postfix}"; |
116 | - $postfix ++; |
|
116 | + $postfix++; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | return $username; |
@@ -130,31 +130,31 @@ discard block |
||
130 | 130 | $tabs = array( |
131 | 131 | |
132 | 132 | 'gp-invoices' => array( |
133 | - 'label' => __( 'Invoices', 'invoicing' ), // Name of the tab. |
|
133 | + 'label' => __('Invoices', 'invoicing'), // Name of the tab. |
|
134 | 134 | 'content' => '[wpinv_history]', // Content of the tab. Or specify "callback" to provide a callback instead. |
135 | 135 | 'icon' => 'fas fa-file-invoice', // Shown on some profile plugins. |
136 | 136 | ), |
137 | 137 | |
138 | 138 | 'gp-subscriptions' => array( |
139 | - 'label' => __( 'Subscriptions', 'invoicing' ), |
|
139 | + 'label' => __('Subscriptions', 'invoicing'), |
|
140 | 140 | 'content' => '[wpinv_subscriptions]', |
141 | 141 | 'icon' => 'fas fa-redo', |
142 | 142 | ), |
143 | 143 | |
144 | 144 | 'gp-edit-address' => array( |
145 | - 'label' => __( 'Billing Address', 'invoicing' ), |
|
145 | + 'label' => __('Billing Address', 'invoicing'), |
|
146 | 146 | 'callback' => 'getpaid_display_address_edit_tab', |
147 | 147 | 'icon' => 'fas fa-credit-card', |
148 | 148 | ), |
149 | 149 | |
150 | 150 | ); |
151 | 151 | |
152 | - $tabs = apply_filters( 'getpaid_user_content_tabs', $tabs ); |
|
152 | + $tabs = apply_filters('getpaid_user_content_tabs', $tabs); |
|
153 | 153 | |
154 | 154 | // Make sure address editing is last on the list. |
155 | - if ( isset( $tabs['gp-edit-address'] ) ) { |
|
155 | + if (isset($tabs['gp-edit-address'])) { |
|
156 | 156 | $address = $tabs['gp-edit-address']; |
157 | - unset( $tabs['gp-edit-address'] ); |
|
157 | + unset($tabs['gp-edit-address']); |
|
158 | 158 | $tabs['gp-edit-address'] = $address; |
159 | 159 | } |
160 | 160 | |
@@ -168,19 +168,19 @@ discard block |
||
168 | 168 | * @param array $tab |
169 | 169 | * @return array |
170 | 170 | */ |
171 | -function getpaid_prepare_user_content_tab( $tab ) { |
|
171 | +function getpaid_prepare_user_content_tab($tab) { |
|
172 | 172 | |
173 | - if ( ! empty( $tab['callback'] ) ) { |
|
174 | - return call_user_func( $tab['callback'] ); |
|
173 | + if (!empty($tab['callback'])) { |
|
174 | + return call_user_func($tab['callback']); |
|
175 | 175 | } |
176 | 176 | |
177 | - if ( ! empty( $tab['content'] ) ) { |
|
178 | - return convert_smilies( capital_P_dangit( wp_filter_content_tags( do_shortcode( shortcode_unautop( wpautop( wptexturize( do_blocks( $tab['content'] ) ) ) ) ) ) ) ); |
|
177 | + if (!empty($tab['content'])) { |
|
178 | + return convert_smilies(capital_P_dangit(wp_filter_content_tags(do_shortcode(shortcode_unautop(wpautop(wptexturize(do_blocks($tab['content'])))))))); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | $notice = aui()->alert( |
182 | 182 | array( |
183 | - 'content' => __( 'This tab has no content or content callback.', 'invoicing' ), |
|
183 | + 'content' => __('This tab has no content or content callback.', 'invoicing'), |
|
184 | 184 | 'type' => 'error', |
185 | 185 | ) |
186 | 186 | ); |
@@ -196,14 +196,14 @@ discard block |
||
196 | 196 | * @param string $default |
197 | 197 | * @return array |
198 | 198 | */ |
199 | -function getpaid_get_tab_url( $tab, $default ) { |
|
199 | +function getpaid_get_tab_url($tab, $default) { |
|
200 | 200 | global $getpaid_tab_url; |
201 | 201 | |
202 | - if ( empty( $getpaid_tab_url ) ) { |
|
202 | + if (empty($getpaid_tab_url)) { |
|
203 | 203 | return $default; |
204 | 204 | } |
205 | 205 | |
206 | - return sprintf( $getpaid_tab_url, $tab ); |
|
206 | + return sprintf($getpaid_tab_url, $tab); |
|
207 | 207 | |
208 | 208 | } |
209 | 209 | |
@@ -215,11 +215,11 @@ discard block |
||
215 | 215 | */ |
216 | 216 | function getpaid_display_address_edit_tab() { |
217 | 217 | |
218 | - if ( 0 === get_current_user_id() ) { |
|
218 | + if (0 === get_current_user_id()) { |
|
219 | 219 | return '<div class="bsui">' . aui()->alert( |
220 | 220 | array( |
221 | 221 | 'type' => 'error', |
222 | - 'content' => __( 'Your must be logged in to view this section', 'invoicing' ), |
|
222 | + 'content' => __('Your must be logged in to view this section', 'invoicing'), |
|
223 | 223 | 'dismissible' => false, |
224 | 224 | ) |
225 | 225 | ) . '</div>'; |
@@ -233,19 +233,19 @@ discard block |
||
233 | 233 | |
234 | 234 | <?php |
235 | 235 | |
236 | - foreach ( getpaid_user_address_fields() as $key => $label ) { |
|
236 | + foreach (getpaid_user_address_fields() as $key => $label) { |
|
237 | 237 | |
238 | 238 | // Display the country. |
239 | - if ( 'country' == $key ) { |
|
239 | + if ('country' == $key) { |
|
240 | 240 | |
241 | 241 | aui()->select( |
242 | 242 | array( |
243 | 243 | 'options' => wpinv_get_country_list(), |
244 | - 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
|
245 | - 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
246 | - 'value' => sanitize_text_field( getpaid_get_user_address_field( get_current_user_id(), $key ) ), |
|
244 | + 'name' => 'getpaid_address[' . esc_attr($key) . ']', |
|
245 | + 'id' => 'wpinv-' . sanitize_html_class($key), |
|
246 | + 'value' => sanitize_text_field(getpaid_get_user_address_field(get_current_user_id(), $key)), |
|
247 | 247 | 'placeholder' => $label, |
248 | - 'label' => wp_kses_post( $label ), |
|
248 | + 'label' => wp_kses_post($label), |
|
249 | 249 | 'label_type' => 'vertical', |
250 | 250 | 'class' => 'getpaid-address-field', |
251 | 251 | ), |
@@ -255,17 +255,17 @@ discard block |
||
255 | 255 | } |
256 | 256 | |
257 | 257 | // Display the state. |
258 | - elseif ( 'state' == $key ) { |
|
258 | + elseif ('state' == $key) { |
|
259 | 259 | |
260 | 260 | getpaid_get_states_select_markup( |
261 | - getpaid_get_user_address_field( get_current_user_id(), 'country' ), |
|
262 | - getpaid_get_user_address_field( get_current_user_id(), 'state' ), |
|
261 | + getpaid_get_user_address_field(get_current_user_id(), 'country'), |
|
262 | + getpaid_get_user_address_field(get_current_user_id(), 'state'), |
|
263 | 263 | $label, |
264 | 264 | $label, |
265 | 265 | '', |
266 | 266 | false, |
267 | 267 | '', |
268 | - 'getpaid_address[' . esc_attr( $key ) . ']', |
|
268 | + 'getpaid_address[' . esc_attr($key) . ']', |
|
269 | 269 | true |
270 | 270 | ); |
271 | 271 | |
@@ -273,13 +273,13 @@ discard block |
||
273 | 273 | |
274 | 274 | aui()->input( |
275 | 275 | array( |
276 | - 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
|
277 | - 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
276 | + 'name' => 'getpaid_address[' . esc_attr($key) . ']', |
|
277 | + 'id' => 'wpinv-' . sanitize_html_class($key), |
|
278 | 278 | 'placeholder' => $label, |
279 | - 'label' => wp_kses_post( $label ), |
|
279 | + 'label' => wp_kses_post($label), |
|
280 | 280 | 'label_type' => 'vertical', |
281 | 281 | 'type' => 'text', |
282 | - 'value' => sanitize_text_field( getpaid_get_user_address_field( get_current_user_id(), $key ) ), |
|
282 | + 'value' => sanitize_text_field(getpaid_get_user_address_field(get_current_user_id(), $key)), |
|
283 | 283 | 'class' => 'getpaid-address-field', |
284 | 284 | ), |
285 | 285 | true |
@@ -293,32 +293,32 @@ discard block |
||
293 | 293 | 'name' => 'getpaid_address[email_cc]', |
294 | 294 | 'id' => 'wpinv-email_cc', |
295 | 295 | 'placeholder' => '[email protected], [email protected]', |
296 | - 'label' => __( 'Other email addresses', 'invoicing' ), |
|
296 | + 'label' => __('Other email addresses', 'invoicing'), |
|
297 | 297 | 'label_type' => 'vertical', |
298 | 298 | 'type' => 'text', |
299 | - 'value' => sanitize_text_field( get_user_meta( get_current_user_id(), '_wpinv_email_cc', true ) ), |
|
299 | + 'value' => sanitize_text_field(get_user_meta(get_current_user_id(), '_wpinv_email_cc', true)), |
|
300 | 300 | 'class' => 'getpaid-address-field', |
301 | - 'help_text' => __( 'Optionally provide other email addresses where we should send payment notifications', 'invoicing' ), |
|
301 | + 'help_text' => __('Optionally provide other email addresses where we should send payment notifications', 'invoicing'), |
|
302 | 302 | ), |
303 | 303 | true |
304 | 304 | ); |
305 | 305 | |
306 | - do_action( 'getpaid_display_address_edit_tab' ); |
|
306 | + do_action('getpaid_display_address_edit_tab'); |
|
307 | 307 | |
308 | 308 | aui()->input( |
309 | 309 | array( |
310 | 310 | 'name' => 'getpaid_profile_edit_submit_button', |
311 | 311 | 'id' => 'getpaid_profile_edit_submit_button', |
312 | - 'value' => __( 'Save Address', 'invoicing' ), |
|
313 | - 'help_text' => __( 'New invoices will use this address as the billing address.', 'invoicing' ), |
|
312 | + 'value' => __('Save Address', 'invoicing'), |
|
313 | + 'help_text' => __('New invoices will use this address as the billing address.', 'invoicing'), |
|
314 | 314 | 'type' => 'submit', |
315 | 315 | 'class' => 'btn btn-primary btn-block submit-button', |
316 | 316 | ), |
317 | 317 | true |
318 | 318 | ); |
319 | 319 | |
320 | - wp_nonce_field( 'getpaid-nonce', 'getpaid-nonce' ); |
|
321 | - getpaid_hidden_field( 'getpaid-action', 'edit_billing_details' ); |
|
320 | + wp_nonce_field('getpaid-nonce', 'getpaid-nonce'); |
|
321 | + getpaid_hidden_field('getpaid-action', 'edit_billing_details'); |
|
322 | 322 | ?> |
323 | 323 | |
324 | 324 | </form> |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | |
329 | 329 | return ob_get_clean(); |
330 | 330 | } |
331 | -add_shortcode( 'getpaid_edit_address', 'getpaid_display_address_edit_tab' ); |
|
331 | +add_shortcode('getpaid_edit_address', 'getpaid_display_address_edit_tab'); |
|
332 | 332 | |
333 | 333 | /** |
334 | 334 | * Saves the billing address edit tab. |
@@ -336,30 +336,30 @@ discard block |
||
336 | 336 | * @since 2.1.4 |
337 | 337 | * @param array $data |
338 | 338 | */ |
339 | -function getpaid_save_address_edit_tab( $data ) { |
|
339 | +function getpaid_save_address_edit_tab($data) { |
|
340 | 340 | |
341 | - if ( empty( $data['getpaid_address'] ) || ! is_array( $data['getpaid_address'] ) ) { |
|
341 | + if (empty($data['getpaid_address']) || !is_array($data['getpaid_address'])) { |
|
342 | 342 | return; |
343 | 343 | } |
344 | 344 | |
345 | 345 | $data = $data['getpaid_address']; |
346 | 346 | $user_id = get_current_user_id(); |
347 | 347 | |
348 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
348 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
349 | 349 | |
350 | - if ( isset( $data[ $field ] ) ) { |
|
351 | - $value = sanitize_text_field( $data[ $field ] ); |
|
352 | - update_user_meta( $user_id, '_wpinv_' . $field, $value ); |
|
350 | + if (isset($data[$field])) { |
|
351 | + $value = sanitize_text_field($data[$field]); |
|
352 | + update_user_meta($user_id, '_wpinv_' . $field, $value); |
|
353 | 353 | } |
354 | 354 | } |
355 | 355 | |
356 | - if ( isset( $data['email_cc'] ) ) { |
|
357 | - update_user_meta( $user_id, '_wpinv_email_cc', sanitize_text_field( $data['email_cc'] ) ); |
|
356 | + if (isset($data['email_cc'])) { |
|
357 | + update_user_meta($user_id, '_wpinv_email_cc', sanitize_text_field($data['email_cc'])); |
|
358 | 358 | } |
359 | 359 | |
360 | - wpinv_set_error( 'address_updated' ); |
|
360 | + wpinv_set_error('address_updated'); |
|
361 | 361 | } |
362 | -add_action( 'getpaid_authenticated_action_edit_billing_details', 'getpaid_save_address_edit_tab' ); |
|
362 | +add_action('getpaid_authenticated_action_edit_billing_details', 'getpaid_save_address_edit_tab'); |
|
363 | 363 | |
364 | 364 | |
365 | 365 | /* |
@@ -377,27 +377,27 @@ discard block |
||
377 | 377 | * @param array $tabs |
378 | 378 | * @return array |
379 | 379 | */ |
380 | -function getpaid_filter_userswp_account_tabs( $tabs ) { |
|
380 | +function getpaid_filter_userswp_account_tabs($tabs) { |
|
381 | 381 | |
382 | 382 | // Abort if the integration is inactive. |
383 | - if ( ! getpaid_is_userswp_integration_active() ) { |
|
383 | + if (!getpaid_is_userswp_integration_active()) { |
|
384 | 384 | return $tabs; |
385 | 385 | } |
386 | 386 | |
387 | - $new_tabs = array(); |
|
387 | + $new_tabs = array(); |
|
388 | 388 | |
389 | - foreach ( getpaid_get_user_content_tabs() as $slug => $tab ) { |
|
389 | + foreach (getpaid_get_user_content_tabs() as $slug => $tab) { |
|
390 | 390 | |
391 | - $new_tabs[ $slug ] = array( |
|
391 | + $new_tabs[$slug] = array( |
|
392 | 392 | 'title' => $tab['label'], |
393 | 393 | 'icon' => $tab['icon'], |
394 | 394 | ); |
395 | 395 | |
396 | 396 | } |
397 | 397 | |
398 | - return array_merge( $tabs, $new_tabs ); |
|
398 | + return array_merge($tabs, $new_tabs); |
|
399 | 399 | } |
400 | -add_filter( 'uwp_account_available_tabs', 'getpaid_filter_userswp_account_tabs' ); |
|
400 | +add_filter('uwp_account_available_tabs', 'getpaid_filter_userswp_account_tabs'); |
|
401 | 401 | |
402 | 402 | /** |
403 | 403 | * Display our UsersWP account tabs. |
@@ -406,21 +406,21 @@ discard block |
||
406 | 406 | * @param array $tabs |
407 | 407 | * @return array |
408 | 408 | */ |
409 | -function getpaid_display_userswp_account_tabs( $tab ) { |
|
409 | +function getpaid_display_userswp_account_tabs($tab) { |
|
410 | 410 | global $getpaid_tab_url; |
411 | 411 | |
412 | 412 | $our_tabs = getpaid_get_user_content_tabs(); |
413 | 413 | |
414 | - if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) { |
|
415 | - $getpaid_tab_url = add_query_arg( 'type', '%s', uwp_get_account_page_url() ); |
|
416 | - echo wp_kses( getpaid_prepare_user_content_tab( $our_tabs[ $tab ] ), getpaid_allowed_html() ); |
|
414 | + if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) { |
|
415 | + $getpaid_tab_url = add_query_arg('type', '%s', uwp_get_account_page_url()); |
|
416 | + echo wp_kses(getpaid_prepare_user_content_tab($our_tabs[$tab]), getpaid_allowed_html()); |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | } |
420 | -add_action( 'uwp_account_form_display', 'getpaid_display_userswp_account_tabs' ); |
|
420 | +add_action('uwp_account_form_display', 'getpaid_display_userswp_account_tabs'); |
|
421 | 421 | |
422 | 422 | function getpaid_allowed_html() { |
423 | - $allowed_html = wp_kses_allowed_html( 'post' ); |
|
423 | + $allowed_html = wp_kses_allowed_html('post'); |
|
424 | 424 | |
425 | 425 | // form fields |
426 | 426 | $allowed_html['form'] = array( |
@@ -491,17 +491,17 @@ discard block |
||
491 | 491 | * @param string $tab Current tab. |
492 | 492 | * @return string Title. |
493 | 493 | */ |
494 | -function getpaid_filter_userswp_account_title( $title, $tab ) { |
|
494 | +function getpaid_filter_userswp_account_title($title, $tab) { |
|
495 | 495 | |
496 | - $our_tabs = getpaid_get_user_content_tabs(); |
|
496 | + $our_tabs = getpaid_get_user_content_tabs(); |
|
497 | 497 | |
498 | - if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) { |
|
499 | - return $our_tabs[ $tab ]['label']; |
|
498 | + if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) { |
|
499 | + return $our_tabs[$tab]['label']; |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | return $title; |
503 | 503 | } |
504 | -add_filter( 'uwp_account_page_title', 'getpaid_filter_userswp_account_title', 10, 2 ); |
|
504 | +add_filter('uwp_account_page_title', 'getpaid_filter_userswp_account_title', 10, 2); |
|
505 | 505 | |
506 | 506 | /** |
507 | 507 | * Registers the UsersWP integration settings. |
@@ -510,26 +510,26 @@ discard block |
||
510 | 510 | * @param array $settings An array of integration settings. |
511 | 511 | * @return array |
512 | 512 | */ |
513 | -function getpaid_register_userswp_settings( $settings ) { |
|
513 | +function getpaid_register_userswp_settings($settings) { |
|
514 | 514 | |
515 | - if ( defined( 'USERSWP_PLUGIN_FILE' ) ) { |
|
515 | + if (defined('USERSWP_PLUGIN_FILE')) { |
|
516 | 516 | |
517 | 517 | $settings[] = array( |
518 | 518 | |
519 | 519 | 'id' => 'userswp', |
520 | - 'label' => __( 'UsersWP', 'invoicing' ), |
|
520 | + 'label' => __('UsersWP', 'invoicing'), |
|
521 | 521 | 'settings' => array( |
522 | 522 | |
523 | 523 | 'userswp_settings' => array( |
524 | 524 | 'id' => 'userswp_settings', |
525 | - 'name' => '<h3>' . __( 'UsersWP', 'invoicing' ) . '</h3>', |
|
525 | + 'name' => '<h3>' . __('UsersWP', 'invoicing') . '</h3>', |
|
526 | 526 | 'type' => 'header', |
527 | 527 | ), |
528 | 528 | |
529 | 529 | 'enable_userswp' => array( |
530 | 530 | 'id' => 'enable_userswp', |
531 | - 'name' => __( 'Enable Integration', 'invoicing' ), |
|
532 | - 'desc' => __( 'Display GetPaid items on UsersWP account page.', 'invoicing' ), |
|
531 | + 'name' => __('Enable Integration', 'invoicing'), |
|
532 | + 'desc' => __('Display GetPaid items on UsersWP account page.', 'invoicing'), |
|
533 | 533 | 'type' => 'checkbox', |
534 | 534 | 'std' => 1, |
535 | 535 | ), |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | |
543 | 543 | return $settings; |
544 | 544 | } |
545 | -add_filter( 'getpaid_integration_settings', 'getpaid_register_userswp_settings' ); |
|
545 | +add_filter('getpaid_integration_settings', 'getpaid_register_userswp_settings'); |
|
546 | 546 | |
547 | 547 | /** |
548 | 548 | * Ovewrites the invoices history page to UsersWP. |
@@ -550,18 +550,18 @@ discard block |
||
550 | 550 | * @since 2.3.1 |
551 | 551 | * @return bool |
552 | 552 | */ |
553 | -function getpaid_userswp_overwrite_invoice_history_page( $url, $post_type ) { |
|
553 | +function getpaid_userswp_overwrite_invoice_history_page($url, $post_type) { |
|
554 | 554 | |
555 | 555 | $our_tabs = getpaid_get_user_content_tabs(); |
556 | 556 | $tab = "gp-{$post_type}s"; |
557 | - if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) { |
|
558 | - return add_query_arg( 'type', $tab, uwp_get_account_page_url() ); |
|
557 | + if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) { |
|
558 | + return add_query_arg('type', $tab, uwp_get_account_page_url()); |
|
559 | 559 | } |
560 | 560 | |
561 | 561 | return $url; |
562 | 562 | |
563 | 563 | } |
564 | -add_filter( 'wpinv_get_history_page_uri', 'getpaid_userswp_overwrite_invoice_history_page', 10, 2 ); |
|
564 | +add_filter('wpinv_get_history_page_uri', 'getpaid_userswp_overwrite_invoice_history_page', 10, 2); |
|
565 | 565 | |
566 | 566 | /** |
567 | 567 | * Checks if the integration is enabled. |
@@ -570,8 +570,8 @@ discard block |
||
570 | 570 | * @return bool |
571 | 571 | */ |
572 | 572 | function getpaid_is_userswp_integration_active() { |
573 | - $enabled = wpinv_get_option( 'enable_userswp', 1 ); |
|
574 | - return defined( 'USERSWP_PLUGIN_FILE' ) && ! empty( $enabled ); |
|
573 | + $enabled = wpinv_get_option('enable_userswp', 1); |
|
574 | + return defined('USERSWP_PLUGIN_FILE') && !empty($enabled); |
|
575 | 575 | } |
576 | 576 | |
577 | 577 | /* |
@@ -589,26 +589,26 @@ discard block |
||
589 | 589 | * @param array $settings An array of integration settings. |
590 | 590 | * @return array |
591 | 591 | */ |
592 | -function getpaid_register_buddypress_settings( $settings ) { |
|
592 | +function getpaid_register_buddypress_settings($settings) { |
|
593 | 593 | |
594 | - if ( class_exists( 'BuddyPress' ) ) { |
|
594 | + if (class_exists('BuddyPress')) { |
|
595 | 595 | |
596 | 596 | $settings[] = array( |
597 | 597 | |
598 | 598 | 'id' => 'buddypress', |
599 | - 'label' => __( 'BuddyPress', 'invoicing' ), |
|
599 | + 'label' => __('BuddyPress', 'invoicing'), |
|
600 | 600 | 'settings' => array( |
601 | 601 | |
602 | 602 | 'buddypress_settings' => array( |
603 | 603 | 'id' => 'buddypress_settings', |
604 | - 'name' => '<h3>' . __( 'BuddyPress', 'invoicing' ) . '</h3>', |
|
604 | + 'name' => '<h3>' . __('BuddyPress', 'invoicing') . '</h3>', |
|
605 | 605 | 'type' => 'header', |
606 | 606 | ), |
607 | 607 | |
608 | 608 | 'enable_buddypress' => array( |
609 | 609 | 'id' => 'enable_buddypress', |
610 | - 'name' => __( 'Enable Integration', 'invoicing' ), |
|
611 | - 'desc' => __( 'Display GetPaid items on BuddyPress account pages.', 'invoicing' ), |
|
610 | + 'name' => __('Enable Integration', 'invoicing'), |
|
611 | + 'desc' => __('Display GetPaid items on BuddyPress account pages.', 'invoicing'), |
|
612 | 612 | 'type' => 'checkbox', |
613 | 613 | 'std' => 1, |
614 | 614 | ), |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | |
622 | 622 | return $settings; |
623 | 623 | } |
624 | -add_filter( 'getpaid_integration_settings', 'getpaid_register_buddypress_settings' ); |
|
624 | +add_filter('getpaid_integration_settings', 'getpaid_register_buddypress_settings'); |
|
625 | 625 | |
626 | 626 | /** |
627 | 627 | * Checks if the integration is enabled. |
@@ -630,8 +630,8 @@ discard block |
||
630 | 630 | * @return bool |
631 | 631 | */ |
632 | 632 | function getpaid_is_buddypress_integration_active() { |
633 | - $enabled = wpinv_get_option( 'enable_buddypress', 1 ); |
|
634 | - return class_exists( 'BuddyPress' ) && ! empty( $enabled ); |
|
633 | + $enabled = wpinv_get_option('enable_buddypress', 1); |
|
634 | + return class_exists('BuddyPress') && !empty($enabled); |
|
635 | 635 | } |
636 | 636 | |
637 | 637 | /** |
@@ -642,13 +642,13 @@ discard block |
||
642 | 642 | */ |
643 | 643 | function getpaid_setup_buddypress_integration() { |
644 | 644 | |
645 | - if ( getpaid_is_buddypress_integration_active() ) { |
|
645 | + if (getpaid_is_buddypress_integration_active()) { |
|
646 | 646 | require_once WPINV_PLUGIN_DIR . 'includes/class-bp-getpaid-component.php'; |
647 | 647 | buddypress()->getpaid = new BP_GetPaid_Component(); |
648 | 648 | } |
649 | 649 | |
650 | 650 | } |
651 | -add_action( 'bp_setup_components', 'getpaid_setup_buddypress_integration' ); |
|
651 | +add_action('bp_setup_components', 'getpaid_setup_buddypress_integration'); |
|
652 | 652 | |
653 | 653 | /** |
654 | 654 | * Checks if a given user has purchased a given item. |
@@ -657,10 +657,10 @@ discard block |
||
657 | 657 | * @param int $item_id The item id. |
658 | 658 | * @return int The IDs of users who purchased the item. |
659 | 659 | */ |
660 | -function getpaid_user_ids_who_purchased_item( $item_id ) { |
|
660 | +function getpaid_user_ids_who_purchased_item($item_id) { |
|
661 | 661 | global $wpdb; |
662 | 662 | |
663 | - if ( empty( $item_id ) ) { |
|
663 | + if (empty($item_id)) { |
|
664 | 664 | return false; |
665 | 665 | } |
666 | 666 | |
@@ -673,7 +673,7 @@ discard block |
||
673 | 673 | ) |
674 | 674 | ); |
675 | 675 | |
676 | - return wp_parse_id_list( $ids ); |
|
676 | + return wp_parse_id_list($ids); |
|
677 | 677 | } |
678 | 678 | |
679 | 679 | /** |
@@ -682,10 +682,10 @@ discard block |
||
682 | 682 | * @since 2.6.17 |
683 | 683 | * @param int $user_id The user id. |
684 | 684 | */ |
685 | -function getpaid_has_user_purchased_item( $user_id, $item_id ) { |
|
685 | +function getpaid_has_user_purchased_item($user_id, $item_id) { |
|
686 | 686 | global $wpdb; |
687 | 687 | |
688 | - if ( empty( $user_id ) ) { |
|
688 | + if (empty($user_id)) { |
|
689 | 689 | return false; |
690 | 690 | } |
691 | 691 | |
@@ -700,5 +700,5 @@ discard block |
||
700 | 700 | ) |
701 | 701 | ); |
702 | 702 | |
703 | - return ! empty( $count ); |
|
703 | + return !empty($count); |
|
704 | 704 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * WPInv_Ajax class. |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | * Hook in ajax handlers. |
18 | 18 | */ |
19 | 19 | public static function init() { |
20 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
20 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
21 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
22 | 22 | self::add_ajax_events(); |
23 | 23 | } |
24 | 24 | |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public static function define_ajax() { |
29 | 29 | |
30 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | - getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | - getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
30 | + if (!empty($_GET['wpinv-ajax'])) { |
|
31 | + getpaid_maybe_define_constant('DOING_AJAX', true); |
|
32 | + getpaid_maybe_define_constant('WPInv_DOING_AJAX', true); |
|
33 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
34 | + /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0); |
|
35 | 35 | } |
36 | 36 | $GLOBALS['wpdb']->hide_errors(); |
37 | 37 | } |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | * @since 1.0.18 |
45 | 45 | */ |
46 | 46 | private static function wpinv_ajax_headers() { |
47 | - if ( ! headers_sent() ) { |
|
47 | + if (!headers_sent()) { |
|
48 | 48 | send_origin_headers(); |
49 | 49 | send_nosniff_header(); |
50 | 50 | nocache_headers(); |
51 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | - header( 'X-Robots-Tag: noindex' ); |
|
53 | - status_header( 200 ); |
|
51 | + header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
52 | + header('X-Robots-Tag: noindex'); |
|
53 | + status_header(200); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
@@ -60,16 +60,16 @@ discard block |
||
60 | 60 | public static function do_wpinv_ajax() { |
61 | 61 | global $wp_query; |
62 | 62 | |
63 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
63 | + if (!empty($_GET['wpinv-ajax'])) { |
|
64 | + $wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax']))); |
|
65 | 65 | } |
66 | 66 | |
67 | - $action = $wp_query->get( 'wpinv-ajax' ); |
|
67 | + $action = $wp_query->get('wpinv-ajax'); |
|
68 | 68 | |
69 | - if ( $action ) { |
|
69 | + if ($action) { |
|
70 | 70 | self::wpinv_ajax_headers(); |
71 | - $action = sanitize_text_field( $action ); |
|
72 | - do_action( 'wpinv_ajax_' . $action ); |
|
71 | + $action = sanitize_text_field($action); |
|
72 | + do_action('wpinv_ajax_' . $action); |
|
73 | 73 | wp_die(); |
74 | 74 | } |
75 | 75 | |
@@ -106,36 +106,36 @@ discard block |
||
106 | 106 | 'file_upload' => true, |
107 | 107 | ); |
108 | 108 | |
109 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
110 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
111 | - add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
109 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
110 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
111 | + add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
112 | 112 | |
113 | - if ( $nopriv ) { |
|
114 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
115 | - add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
116 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
113 | + if ($nopriv) { |
|
114 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
115 | + add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
116 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
121 | 121 | public static function add_note() { |
122 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
122 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
123 | 123 | |
124 | - $post_id = absint( $_POST['post_id'] ); |
|
125 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
126 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
124 | + $post_id = absint($_POST['post_id']); |
|
125 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
126 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
127 | 127 | |
128 | - if ( ! wpinv_current_user_can( 'invoice_add_note', array( 'post_id' => $post_id, 'note_type' => $note_type ) ) ) { |
|
128 | + if (!wpinv_current_user_can('invoice_add_note', array('post_id' => $post_id, 'note_type' => $note_type))) { |
|
129 | 129 | die( -1 ); |
130 | 130 | } |
131 | 131 | |
132 | 132 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
133 | 133 | |
134 | - if ( $post_id > 0 ) { |
|
135 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
134 | + if ($post_id > 0) { |
|
135 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
136 | 136 | |
137 | - if ( $note_id > 0 && ! is_wp_error( $note_id ) ) { |
|
138 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
137 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
138 | + wpinv_get_invoice_note_line_item($note_id); |
|
139 | 139 | } |
140 | 140 | } |
141 | 141 | |
@@ -143,16 +143,16 @@ discard block |
||
143 | 143 | } |
144 | 144 | |
145 | 145 | public static function delete_note() { |
146 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
146 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
147 | 147 | |
148 | - $note_id = (int)$_POST['note_id']; |
|
148 | + $note_id = (int) $_POST['note_id']; |
|
149 | 149 | |
150 | - if ( ! wpinv_current_user_can( 'invoice_delete_note', array( 'note_id' => $note_id ) ) ) { |
|
150 | + if (!wpinv_current_user_can('invoice_delete_note', array('note_id' => $note_id))) { |
|
151 | 151 | die( -1 ); |
152 | 152 | } |
153 | 153 | |
154 | - if ( $note_id > 0 ) { |
|
155 | - wp_delete_comment( $note_id, true ); |
|
154 | + if ($note_id > 0) { |
|
155 | + wp_delete_comment($note_id, true); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | die(); |
@@ -170,34 +170,34 @@ discard block |
||
170 | 170 | public static function get_billing_details() { |
171 | 171 | |
172 | 172 | // Verify nonce. |
173 | - check_ajax_referer( 'wpinv-nonce' ); |
|
173 | + check_ajax_referer('wpinv-nonce'); |
|
174 | 174 | |
175 | 175 | // Do we have a user id? |
176 | 176 | $user_id = (int) $_GET['user_id']; |
177 | 177 | |
178 | - if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
178 | + if (empty($user_id) || !is_numeric($user_id)) { |
|
179 | 179 | die( -1 ); |
180 | 180 | } |
181 | 181 | |
182 | 182 | // Can the user manage the plugin? |
183 | - if ( ! wpinv_current_user_can( 'user_get_billing_details', array( 'user_id' => $user_id ) ) ) { |
|
183 | + if (!wpinv_current_user_can('user_get_billing_details', array('user_id' => $user_id))) { |
|
184 | 184 | die( -1 ); |
185 | 185 | } |
186 | 186 | |
187 | 187 | // Fetch the billing details. |
188 | - $billing_details = wpinv_get_user_address( $user_id ); |
|
189 | - $billing_details = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id ); |
|
188 | + $billing_details = wpinv_get_user_address($user_id); |
|
189 | + $billing_details = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id); |
|
190 | 190 | |
191 | 191 | // unset the user id and email. |
192 | - $to_ignore = array( 'user_id', 'email' ); |
|
192 | + $to_ignore = array('user_id', 'email'); |
|
193 | 193 | |
194 | - foreach ( $to_ignore as $key ) { |
|
195 | - if ( isset( $billing_details[ $key ] ) ) { |
|
196 | - unset( $billing_details[ $key ] ); |
|
194 | + foreach ($to_ignore as $key) { |
|
195 | + if (isset($billing_details[$key])) { |
|
196 | + unset($billing_details[$key]); |
|
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
200 | - wp_send_json_success( $billing_details ); |
|
200 | + wp_send_json_success($billing_details); |
|
201 | 201 | |
202 | 202 | } |
203 | 203 | |
@@ -207,47 +207,47 @@ discard block |
||
207 | 207 | public static function check_new_user_email() { |
208 | 208 | |
209 | 209 | // Verify nonce. |
210 | - check_ajax_referer( 'wpinv-nonce' ); |
|
210 | + check_ajax_referer('wpinv-nonce'); |
|
211 | 211 | |
212 | 212 | // Can the user manage the plugin? |
213 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
213 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
214 | 214 | die( -1 ); |
215 | 215 | } |
216 | 216 | |
217 | 217 | // We need an email address. |
218 | - if ( empty( $_GET['email'] ) ) { |
|
219 | - esc_html_e( "Provide the new user's email address", 'invoicing' ); |
|
218 | + if (empty($_GET['email'])) { |
|
219 | + esc_html_e("Provide the new user's email address", 'invoicing'); |
|
220 | 220 | exit; |
221 | 221 | } |
222 | 222 | |
223 | 223 | // Ensure the email is valid. |
224 | - $email = sanitize_email( $_GET['email'] ); |
|
225 | - if ( ! is_email( $email ) ) { |
|
226 | - esc_html_e( 'Invalid email address', 'invoicing' ); |
|
224 | + $email = sanitize_email($_GET['email']); |
|
225 | + if (!is_email($email)) { |
|
226 | + esc_html_e('Invalid email address', 'invoicing'); |
|
227 | 227 | exit; |
228 | 228 | } |
229 | 229 | |
230 | 230 | // And it does not exist. |
231 | - $id = email_exists( $email ); |
|
232 | - if ( $id ) { |
|
233 | - wp_send_json_success( compact( 'id' ) ); |
|
231 | + $id = email_exists($email); |
|
232 | + if ($id) { |
|
233 | + wp_send_json_success(compact('id')); |
|
234 | 234 | } |
235 | 235 | |
236 | - wp_send_json_success( true ); |
|
236 | + wp_send_json_success(true); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | public static function run_tool() { |
240 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
241 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
240 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
241 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
242 | 242 | die( -1 ); |
243 | 243 | } |
244 | 244 | |
245 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
245 | + $tool = sanitize_text_field($_POST['tool']); |
|
246 | 246 | |
247 | - do_action( 'wpinv_run_tool' ); |
|
247 | + do_action('wpinv_run_tool'); |
|
248 | 248 | |
249 | - if ( ! empty( $tool ) ) { |
|
250 | - do_action( 'wpinv_tool_' . $tool ); |
|
249 | + if (!empty($tool)) { |
|
250 | + do_action('wpinv_tool_' . $tool); |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 | |
@@ -258,11 +258,11 @@ discard block |
||
258 | 258 | global $getpaid_force_checkbox; |
259 | 259 | |
260 | 260 | // Is the request set up correctly? |
261 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) { |
|
261 | + if (empty($_GET['form']) && empty($_GET['item']) && empty($_GET['invoice'])) { |
|
262 | 262 | aui()->alert( |
263 | 263 | array( |
264 | 264 | 'type' => 'warning', |
265 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
265 | + 'content' => __('No payment form or item provided', 'invoicing'), |
|
266 | 266 | ), |
267 | 267 | true |
268 | 268 | ); |
@@ -270,29 +270,29 @@ discard block |
||
270 | 270 | } |
271 | 271 | |
272 | 272 | // Payment form or button? |
273 | - if ( ! empty( $_GET['form'] ) ) { |
|
274 | - $form = sanitize_text_field( urldecode( $_GET['form'] ) ); |
|
273 | + if (!empty($_GET['form'])) { |
|
274 | + $form = sanitize_text_field(urldecode($_GET['form'])); |
|
275 | 275 | |
276 | - if ( false !== strpos( $form, '|' ) ) { |
|
277 | - $form_pos = strpos( $form, '|' ); |
|
278 | - $_items = getpaid_convert_items_to_array( substr( $form, $form_pos + 1 ) ); |
|
279 | - $form = substr( $form, 0, $form_pos ); |
|
276 | + if (false !== strpos($form, '|')) { |
|
277 | + $form_pos = strpos($form, '|'); |
|
278 | + $_items = getpaid_convert_items_to_array(substr($form, $form_pos + 1)); |
|
279 | + $form = substr($form, 0, $form_pos); |
|
280 | 280 | |
281 | 281 | // Retrieve appropriate payment form. |
282 | - $payment_form = new GetPaid_Payment_Form( $form ); |
|
283 | - $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
282 | + $payment_form = new GetPaid_Payment_Form($form); |
|
283 | + $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
284 | 284 | |
285 | 285 | $items = array(); |
286 | 286 | $item_ids = array(); |
287 | 287 | |
288 | - foreach ( $_items as $item_id => $qty ) { |
|
289 | - if ( ! in_array( $item_id, $item_ids ) ) { |
|
290 | - $item = new GetPaid_Form_Item( $item_id ); |
|
291 | - $item->set_quantity( $qty ); |
|
288 | + foreach ($_items as $item_id => $qty) { |
|
289 | + if (!in_array($item_id, $item_ids)) { |
|
290 | + $item = new GetPaid_Form_Item($item_id); |
|
291 | + $item->set_quantity($qty); |
|
292 | 292 | |
293 | - if ( 0 == $qty ) { |
|
294 | - $item->set_allow_quantities( true ); |
|
295 | - $item->set_is_required( false ); |
|
293 | + if (0 == $qty) { |
|
294 | + $item->set_allow_quantities(true); |
|
295 | + $item->set_is_required(false); |
|
296 | 296 | $getpaid_force_checkbox = true; |
297 | 297 | } |
298 | 298 | |
@@ -301,32 +301,32 @@ discard block |
||
301 | 301 | } |
302 | 302 | } |
303 | 303 | |
304 | - if ( ! $payment_form->is_default() ) { |
|
304 | + if (!$payment_form->is_default()) { |
|
305 | 305 | |
306 | - foreach ( $payment_form->get_items() as $item ) { |
|
307 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
306 | + foreach ($payment_form->get_items() as $item) { |
|
307 | + if (!in_array($item->get_id(), $item_ids)) { |
|
308 | 308 | $item_ids[] = $item->get_id(); |
309 | 309 | $items[] = $item; |
310 | 310 | } |
311 | 311 | } |
312 | 312 | } |
313 | 313 | |
314 | - $payment_form->set_items( $items ); |
|
315 | - $extra_items = esc_attr( getpaid_convert_items_to_string( $_items ) ); |
|
316 | - $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items ); |
|
314 | + $payment_form->set_items($items); |
|
315 | + $extra_items = esc_attr(getpaid_convert_items_to_string($_items)); |
|
316 | + $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items); |
|
317 | 317 | $extra_items = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />"; |
318 | 318 | $extra_items .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />"; |
319 | - $payment_form->display( $extra_items ); |
|
319 | + $payment_form->display($extra_items); |
|
320 | 320 | $getpaid_force_checkbox = false; |
321 | 321 | |
322 | 322 | } else { |
323 | - getpaid_display_payment_form( $form ); |
|
323 | + getpaid_display_payment_form($form); |
|
324 | 324 | } |
325 | -} elseif ( ! empty( $_GET['invoice'] ) ) { |
|
326 | - getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) ); |
|
325 | +} elseif (!empty($_GET['invoice'])) { |
|
326 | + getpaid_display_invoice_payment_form((int) urldecode($_GET['invoice'])); |
|
327 | 327 | } else { |
328 | - $items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) ); |
|
329 | - getpaid_display_item_payment_form( $items ); |
|
328 | + $items = getpaid_convert_items_to_array(sanitize_text_field(urldecode($_GET['item']))); |
|
329 | + getpaid_display_item_payment_form($items); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | exit; |
@@ -341,14 +341,14 @@ discard block |
||
341 | 341 | public static function payment_form() { |
342 | 342 | |
343 | 343 | // ... form fields... |
344 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
345 | - esc_html_e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
344 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
345 | + esc_html_e('Error: Reload the page and try again.', 'invoicing'); |
|
346 | 346 | exit; |
347 | 347 | } |
348 | 348 | |
349 | 349 | // Process the payment form. |
350 | - $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' ); |
|
351 | - $checkout = new $checkout_class( new GetPaid_Payment_Form_Submission() ); |
|
350 | + $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout'); |
|
351 | + $checkout = new $checkout_class(new GetPaid_Payment_Form_Submission()); |
|
352 | 352 | $checkout->process_checkout(); |
353 | 353 | |
354 | 354 | exit; |
@@ -361,55 +361,55 @@ discard block |
||
361 | 361 | */ |
362 | 362 | public static function get_payment_form_states_field() { |
363 | 363 | |
364 | - if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) { |
|
364 | + if (empty($_GET['country']) || empty($_GET['form'])) { |
|
365 | 365 | exit; |
366 | 366 | } |
367 | 367 | |
368 | - $elements = getpaid_get_payment_form_elements( (int) $_GET['form'] ); |
|
368 | + $elements = getpaid_get_payment_form_elements((int) $_GET['form']); |
|
369 | 369 | |
370 | - if ( empty( $elements ) ) { |
|
370 | + if (empty($elements)) { |
|
371 | 371 | exit; |
372 | 372 | } |
373 | 373 | |
374 | 374 | $address_fields = array(); |
375 | - foreach ( $elements as $element ) { |
|
376 | - if ( 'address' === $element['type'] ) { |
|
375 | + foreach ($elements as $element) { |
|
376 | + if ('address' === $element['type']) { |
|
377 | 377 | $address_fields = $element; |
378 | 378 | break; |
379 | 379 | } |
380 | 380 | } |
381 | 381 | |
382 | - if ( empty( $address_fields ) ) { |
|
382 | + if (empty($address_fields)) { |
|
383 | 383 | exit; |
384 | 384 | } |
385 | 385 | |
386 | - foreach ( $address_fields['fields'] as $address_field ) { |
|
386 | + foreach ($address_fields['fields'] as $address_field) { |
|
387 | 387 | |
388 | - if ( 'wpinv_state' == $address_field['name'] ) { |
|
388 | + if ('wpinv_state' == $address_field['name']) { |
|
389 | 389 | |
390 | - $wrap_class = getpaid_get_form_element_grid_class( $address_field ); |
|
391 | - $wrap_class = esc_attr( "$wrap_class getpaid-address-field-wrapper" ); |
|
392 | - $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] ); |
|
393 | - $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] ); |
|
394 | - $value = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : ''; |
|
395 | - $label = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] ); |
|
390 | + $wrap_class = getpaid_get_form_element_grid_class($address_field); |
|
391 | + $wrap_class = esc_attr("$wrap_class getpaid-address-field-wrapper"); |
|
392 | + $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']); |
|
393 | + $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']); |
|
394 | + $value = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : ''; |
|
395 | + $label = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']); |
|
396 | 396 | |
397 | - if ( ! empty( $address_field['required'] ) ) { |
|
397 | + if (!empty($address_field['required'])) { |
|
398 | 398 | $label .= "<span class='text-danger'> *</span>"; |
399 | 399 | } |
400 | 400 | |
401 | 401 | $html = getpaid_get_states_select_markup( |
402 | - sanitize_text_field( $_GET['country'] ), |
|
402 | + sanitize_text_field($_GET['country']), |
|
403 | 403 | $value, |
404 | 404 | $placeholder, |
405 | 405 | $label, |
406 | 406 | $description, |
407 | - ! empty( $address_field['required'] ), |
|
407 | + !empty($address_field['required']), |
|
408 | 408 | $wrap_class, |
409 | - sanitize_text_field( $_GET['name'] ) |
|
409 | + sanitize_text_field($_GET['name']) |
|
410 | 410 | ); |
411 | 411 | |
412 | - wp_send_json_success( $html ); |
|
412 | + wp_send_json_success($html); |
|
413 | 413 | exit; |
414 | 414 | |
415 | 415 | } |
@@ -424,66 +424,66 @@ discard block |
||
424 | 424 | public static function recalculate_invoice_totals() { |
425 | 425 | |
426 | 426 | // Verify nonce. |
427 | - check_ajax_referer( 'wpinv-nonce' ); |
|
427 | + check_ajax_referer('wpinv-nonce'); |
|
428 | 428 | |
429 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
429 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
430 | 430 | exit; |
431 | 431 | } |
432 | 432 | |
433 | 433 | // We need an invoice. |
434 | - if ( empty( $_POST['post_id'] ) ) { |
|
434 | + if (empty($_POST['post_id'])) { |
|
435 | 435 | exit; |
436 | 436 | } |
437 | 437 | |
438 | 438 | // Fetch the invoice. |
439 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
439 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
440 | 440 | |
441 | 441 | // Ensure it exists. |
442 | - if ( ! $invoice->get_id() ) { |
|
442 | + if (!$invoice->get_id()) { |
|
443 | 443 | exit; |
444 | 444 | } |
445 | 445 | |
446 | 446 | // Maybe set the country, state, currency. |
447 | - foreach ( array( 'country', 'state', 'currency', 'vat_number', 'discount_code' ) as $key ) { |
|
448 | - if ( isset( $_POST[ $key ] ) ) { |
|
447 | + foreach (array('country', 'state', 'currency', 'vat_number', 'discount_code') as $key) { |
|
448 | + if (isset($_POST[$key])) { |
|
449 | 449 | $method = "set_$key"; |
450 | - $invoice->$method( sanitize_text_field( $_POST[ $key ] ) ); |
|
450 | + $invoice->$method(sanitize_text_field($_POST[$key])); |
|
451 | 451 | } |
452 | 452 | } |
453 | 453 | |
454 | 454 | // Maybe disable taxes. |
455 | - $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) ); |
|
455 | + $invoice->set_disable_taxes(!empty($_POST['taxes'])); |
|
456 | 456 | |
457 | 457 | // Discount code. |
458 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
459 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
460 | - if ( $discount->exists() ) { |
|
461 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
458 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
459 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
460 | + if ($discount->exists()) { |
|
461 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
462 | 462 | } else { |
463 | - $invoice->remove_discount( 'discount_code' ); |
|
463 | + $invoice->remove_discount('discount_code'); |
|
464 | 464 | } |
465 | 465 | } |
466 | 466 | |
467 | 467 | // Recalculate totals. |
468 | 468 | $invoice->recalculate_total(); |
469 | 469 | |
470 | - $total = wpinv_price( $invoice->get_total(), $invoice->get_currency() ); |
|
471 | - $suscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
472 | - if ( is_a( $suscriptions, 'WPInv_Subscription' ) && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) { |
|
473 | - $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() ); |
|
474 | - $total .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>'; |
|
470 | + $total = wpinv_price($invoice->get_total(), $invoice->get_currency()); |
|
471 | + $suscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
472 | + if (is_a($suscriptions, 'WPInv_Subscription') && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) { |
|
473 | + $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency()); |
|
474 | + $total .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>'; |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | $totals = array( |
478 | - 'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ), |
|
479 | - 'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
|
480 | - 'tax' => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ), |
|
478 | + 'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()), |
|
479 | + 'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()), |
|
480 | + 'tax' => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()), |
|
481 | 481 | 'total' => $total, |
482 | 482 | ); |
483 | 483 | |
484 | - $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice ); |
|
484 | + $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice); |
|
485 | 485 | |
486 | - wp_send_json_success( compact( 'totals' ) ); |
|
486 | + wp_send_json_success(compact('totals')); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | /** |
@@ -492,33 +492,33 @@ discard block |
||
492 | 492 | public static function get_invoice_items() { |
493 | 493 | |
494 | 494 | // Verify nonce. |
495 | - check_ajax_referer( 'wpinv-nonce' ); |
|
495 | + check_ajax_referer('wpinv-nonce'); |
|
496 | 496 | |
497 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
497 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
498 | 498 | exit; |
499 | 499 | } |
500 | 500 | |
501 | 501 | // We need an invoice and items. |
502 | - if ( empty( $_POST['post_id'] ) ) { |
|
502 | + if (empty($_POST['post_id'])) { |
|
503 | 503 | exit; |
504 | 504 | } |
505 | 505 | |
506 | 506 | // Fetch the invoice. |
507 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
507 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
508 | 508 | |
509 | 509 | // Ensure it exists. |
510 | - if ( ! $invoice->get_id() ) { |
|
510 | + if (!$invoice->get_id()) { |
|
511 | 511 | exit; |
512 | 512 | } |
513 | 513 | |
514 | 514 | // Return an array of invoice items. |
515 | 515 | $items = array(); |
516 | 516 | |
517 | - foreach ( $invoice->get_items() as $item ) { |
|
518 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency(), $invoice->is_renewal() ); |
|
517 | + foreach ($invoice->get_items() as $item) { |
|
518 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal()); |
|
519 | 519 | } |
520 | 520 | |
521 | - wp_send_json_success( compact( 'items' ) ); |
|
521 | + wp_send_json_success(compact('items')); |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | /** |
@@ -527,50 +527,50 @@ discard block |
||
527 | 527 | public static function edit_invoice_item() { |
528 | 528 | |
529 | 529 | // Verify nonce. |
530 | - check_ajax_referer( 'wpinv-nonce' ); |
|
530 | + check_ajax_referer('wpinv-nonce'); |
|
531 | 531 | |
532 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
532 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
533 | 533 | exit; |
534 | 534 | } |
535 | 535 | |
536 | 536 | // We need an invoice and item details. |
537 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) { |
|
537 | + if (empty($_POST['post_id']) || empty($_POST['data'])) { |
|
538 | 538 | exit; |
539 | 539 | } |
540 | 540 | |
541 | 541 | // Fetch the invoice. |
542 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
542 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
543 | 543 | |
544 | 544 | // Ensure it exists and its not been paid for. |
545 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
545 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
546 | 546 | exit; |
547 | 547 | } |
548 | 548 | |
549 | 549 | // Format the data. |
550 | - $data = wp_kses_post_deep( wp_unslash( wp_list_pluck( $_POST['data'], 'value', 'field' ) ) ); |
|
550 | + $data = wp_kses_post_deep(wp_unslash(wp_list_pluck($_POST['data'], 'value', 'field'))); |
|
551 | 551 | |
552 | 552 | // Ensure that we have an item id. |
553 | - if ( empty( $data['id'] ) ) { |
|
553 | + if (empty($data['id'])) { |
|
554 | 554 | exit; |
555 | 555 | } |
556 | 556 | |
557 | 557 | // Abort if the invoice does not have the specified item. |
558 | - $item = $invoice->get_item( (int) $data['id'] ); |
|
558 | + $item = $invoice->get_item((int) $data['id']); |
|
559 | 559 | |
560 | - if ( empty( $item ) ) { |
|
560 | + if (empty($item)) { |
|
561 | 561 | exit; |
562 | 562 | } |
563 | 563 | |
564 | 564 | // Update the item. |
565 | - $item->set_price( getpaid_standardize_amount( $data['price'] ) ); |
|
566 | - $item->set_name( sanitize_text_field( $data['name'] ) ); |
|
567 | - $item->set_description( wp_kses_post( $data['description'] ) ); |
|
568 | - $item->set_quantity( floatval( $data['quantity'] ) ); |
|
565 | + $item->set_price(getpaid_standardize_amount($data['price'])); |
|
566 | + $item->set_name(sanitize_text_field($data['name'])); |
|
567 | + $item->set_description(wp_kses_post($data['description'])); |
|
568 | + $item->set_quantity(floatval($data['quantity'])); |
|
569 | 569 | |
570 | 570 | // Add it to the invoice. |
571 | - $error = $invoice->add_item( $item ); |
|
571 | + $error = $invoice->add_item($item); |
|
572 | 572 | $alert = false; |
573 | - if ( is_wp_error( $error ) ) { |
|
573 | + if (is_wp_error($error)) { |
|
574 | 574 | $alert = $error->get_error_message(); |
575 | 575 | } |
576 | 576 | |
@@ -583,11 +583,11 @@ discard block |
||
583 | 583 | // Return an array of invoice items. |
584 | 584 | $items = array(); |
585 | 585 | |
586 | - foreach ( $invoice->get_items() as $item ) { |
|
587 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
586 | + foreach ($invoice->get_items() as $item) { |
|
587 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
588 | 588 | } |
589 | 589 | |
590 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
590 | + wp_send_json_success(compact('items', 'alert')); |
|
591 | 591 | } |
592 | 592 | |
593 | 593 | /** |
@@ -596,53 +596,53 @@ discard block |
||
596 | 596 | public static function create_invoice_item() { |
597 | 597 | |
598 | 598 | // Verify nonce. |
599 | - check_ajax_referer( 'wpinv-nonce' ); |
|
599 | + check_ajax_referer('wpinv-nonce'); |
|
600 | 600 | |
601 | 601 | // We need an invoice and item details. |
602 | - if ( empty( $_POST['invoice_id'] ) || empty( $_POST['_wpinv_quick'] ) ) { |
|
602 | + if (empty($_POST['invoice_id']) || empty($_POST['_wpinv_quick'])) { |
|
603 | 603 | exit; |
604 | 604 | } |
605 | 605 | |
606 | 606 | // Fetch the invoice. |
607 | - $invoice = new WPInv_Invoice( intval( $_POST['invoice_id'] ) ); |
|
607 | + $invoice = new WPInv_Invoice(intval($_POST['invoice_id'])); |
|
608 | 608 | |
609 | 609 | // Ensure it exists and its not been paid for. |
610 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
610 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
611 | 611 | exit; |
612 | 612 | } |
613 | 613 | |
614 | - if ( ! wpinv_current_user_can( 'invoice_create_item', array( 'invoice' => $invoice ) ) ) { |
|
614 | + if (!wpinv_current_user_can('invoice_create_item', array('invoice' => $invoice))) { |
|
615 | 615 | exit; |
616 | 616 | } |
617 | 617 | |
618 | 618 | // Format the data. |
619 | - $data = wp_kses_post_deep( wp_unslash( $_POST['_wpinv_quick'] ) ); |
|
619 | + $data = wp_kses_post_deep(wp_unslash($_POST['_wpinv_quick'])); |
|
620 | 620 | |
621 | 621 | $item = new WPInv_Item(); |
622 | - $item->set_price( getpaid_standardize_amount( $data['price'] ) ); |
|
623 | - $item->set_name( sanitize_text_field( $data['name'] ) ); |
|
624 | - $item->set_description( wp_kses_post( $data['description'] ) ); |
|
625 | - $item->set_type( sanitize_text_field( $data['type'] ) ); |
|
626 | - $item->set_vat_rule( sanitize_text_field( $data['vat_rule'] ) ); |
|
627 | - $item->set_vat_class( sanitize_text_field( $data['vat_class'] ) ); |
|
628 | - $item->set_status( 'publish' ); |
|
622 | + $item->set_price(getpaid_standardize_amount($data['price'])); |
|
623 | + $item->set_name(sanitize_text_field($data['name'])); |
|
624 | + $item->set_description(wp_kses_post($data['description'])); |
|
625 | + $item->set_type(sanitize_text_field($data['type'])); |
|
626 | + $item->set_vat_rule(sanitize_text_field($data['vat_rule'])); |
|
627 | + $item->set_vat_class(sanitize_text_field($data['vat_class'])); |
|
628 | + $item->set_status('publish'); |
|
629 | 629 | $item->save(); |
630 | 630 | |
631 | - if ( ! $item->exists() ) { |
|
632 | - $alert = __( 'Could not create invoice item. Please try again.', 'invoicing' ); |
|
633 | - wp_send_json_success( compact( 'alert' ) ); |
|
631 | + if (!$item->exists()) { |
|
632 | + $alert = __('Could not create invoice item. Please try again.', 'invoicing'); |
|
633 | + wp_send_json_success(compact('alert')); |
|
634 | 634 | } |
635 | 635 | |
636 | - $item = new GetPaid_Form_Item( $item->get_id() ); |
|
637 | - $item->set_quantity( floatval( $data['qty'] ) ); |
|
636 | + $item = new GetPaid_Form_Item($item->get_id()); |
|
637 | + $item->set_quantity(floatval($data['qty'])); |
|
638 | 638 | |
639 | 639 | // Add it to the invoice. |
640 | - $error = $invoice->add_item( $item ); |
|
640 | + $error = $invoice->add_item($item); |
|
641 | 641 | $alert = false; |
642 | 642 | |
643 | - if ( is_wp_error( $error ) ) { |
|
643 | + if (is_wp_error($error)) { |
|
644 | 644 | $alert = $error->get_error_message(); |
645 | - wp_send_json_success( compact( 'alert' ) ); |
|
645 | + wp_send_json_success(compact('alert')); |
|
646 | 646 | } |
647 | 647 | |
648 | 648 | // Update totals. |
@@ -655,9 +655,9 @@ discard block |
||
655 | 655 | $invoice->recalculate_total(); |
656 | 656 | $invoice->save(); |
657 | 657 | ob_start(); |
658 | - GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice ); |
|
658 | + GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice); |
|
659 | 659 | $row = ob_get_clean(); |
660 | - wp_send_json_success( compact( 'row' ) ); |
|
660 | + wp_send_json_success(compact('row')); |
|
661 | 661 | } |
662 | 662 | |
663 | 663 | /** |
@@ -666,33 +666,33 @@ discard block |
||
666 | 666 | public static function remove_invoice_item() { |
667 | 667 | |
668 | 668 | // Verify nonce. |
669 | - check_ajax_referer( 'wpinv-nonce' ); |
|
669 | + check_ajax_referer('wpinv-nonce'); |
|
670 | 670 | |
671 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
671 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
672 | 672 | exit; |
673 | 673 | } |
674 | 674 | |
675 | 675 | // We need an invoice and an item. |
676 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
676 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
677 | 677 | exit; |
678 | 678 | } |
679 | 679 | |
680 | 680 | // Fetch the invoice. |
681 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
681 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
682 | 682 | |
683 | 683 | // Ensure it exists and its not been paid for. |
684 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
684 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
685 | 685 | exit; |
686 | 686 | } |
687 | 687 | |
688 | 688 | // Abort if the invoice does not have the specified item. |
689 | - $item = $invoice->get_item( (int) $_POST['item_id'] ); |
|
689 | + $item = $invoice->get_item((int) $_POST['item_id']); |
|
690 | 690 | |
691 | - if ( empty( $item ) ) { |
|
691 | + if (empty($item)) { |
|
692 | 692 | exit; |
693 | 693 | } |
694 | 694 | |
695 | - $invoice->remove_item( (int) $_POST['item_id'] ); |
|
695 | + $invoice->remove_item((int) $_POST['item_id']); |
|
696 | 696 | |
697 | 697 | // Update totals. |
698 | 698 | $invoice->recalculate_total(); |
@@ -703,11 +703,11 @@ discard block |
||
703 | 703 | // Return an array of invoice items. |
704 | 704 | $items = array(); |
705 | 705 | |
706 | - foreach ( $invoice->get_items() as $item ) { |
|
707 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
706 | + foreach ($invoice->get_items() as $item) { |
|
707 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
708 | 708 | } |
709 | 709 | |
710 | - wp_send_json_success( compact( 'items' ) ); |
|
710 | + wp_send_json_success(compact('items')); |
|
711 | 711 | } |
712 | 712 | |
713 | 713 | /** |
@@ -716,68 +716,68 @@ discard block |
||
716 | 716 | public static function recalculate_full_prices() { |
717 | 717 | |
718 | 718 | // Verify nonce. |
719 | - check_ajax_referer( 'wpinv-nonce' ); |
|
719 | + check_ajax_referer('wpinv-nonce'); |
|
720 | 720 | |
721 | 721 | // We need an invoice and item. |
722 | - if ( empty( $_POST['post_id'] ) ) { |
|
722 | + if (empty($_POST['post_id'])) { |
|
723 | 723 | exit; |
724 | 724 | } |
725 | 725 | |
726 | 726 | // Fetch the invoice. |
727 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
727 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
728 | 728 | $alert = false; |
729 | 729 | |
730 | 730 | // Ensure it exists and its not been paid for. |
731 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
731 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
732 | 732 | exit; |
733 | 733 | } |
734 | 734 | |
735 | - if ( ! wpinv_current_user_can( 'invoice_recalculate_full_prices', array( 'invoice' => $invoice ) ) ) { |
|
735 | + if (!wpinv_current_user_can('invoice_recalculate_full_prices', array('invoice' => $invoice))) { |
|
736 | 736 | exit; |
737 | 737 | } |
738 | 738 | |
739 | - $invoice->set_items( array() ); |
|
739 | + $invoice->set_items(array()); |
|
740 | 740 | |
741 | - if ( ! empty( $_POST['getpaid_items'] ) ) { |
|
741 | + if (!empty($_POST['getpaid_items'])) { |
|
742 | 742 | |
743 | - foreach ( wp_kses_post_deep( $_POST['getpaid_items'] ) as $item_id => $args ) { |
|
744 | - $item = new GetPaid_Form_Item( $item_id ); |
|
743 | + foreach (wp_kses_post_deep($_POST['getpaid_items']) as $item_id => $args) { |
|
744 | + $item = new GetPaid_Form_Item($item_id); |
|
745 | 745 | |
746 | - if ( $item->exists() ) { |
|
747 | - $item->set_price( getpaid_standardize_amount( $args['price'] ) ); |
|
748 | - $item->set_quantity( floatval( $args['quantity'] ) ); |
|
749 | - $item->set_name( sanitize_text_field( $args['name'] ) ); |
|
750 | - $item->set_description( wp_kses_post( $args['description'] ) ); |
|
751 | - $invoice->add_item( $item ); |
|
746 | + if ($item->exists()) { |
|
747 | + $item->set_price(getpaid_standardize_amount($args['price'])); |
|
748 | + $item->set_quantity(floatval($args['quantity'])); |
|
749 | + $item->set_name(sanitize_text_field($args['name'])); |
|
750 | + $item->set_description(wp_kses_post($args['description'])); |
|
751 | + $invoice->add_item($item); |
|
752 | 752 | } |
753 | 753 | } |
754 | 754 | } |
755 | 755 | |
756 | - $invoice->set_disable_taxes( ! empty( $_POST['disable_taxes'] ) ); |
|
756 | + $invoice->set_disable_taxes(!empty($_POST['disable_taxes'])); |
|
757 | 757 | |
758 | 758 | // Maybe set the country, state, currency. |
759 | - foreach ( array( 'wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code' ) as $key ) { |
|
760 | - if ( isset( $_POST[ $key ] ) ) { |
|
761 | - $_key = str_replace( 'wpinv_', '', $key ); |
|
759 | + foreach (array('wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code') as $key) { |
|
760 | + if (isset($_POST[$key])) { |
|
761 | + $_key = str_replace('wpinv_', '', $key); |
|
762 | 762 | $method = "set_$_key"; |
763 | - $invoice->$method( sanitize_text_field( $_POST[ $key ] ) ); |
|
763 | + $invoice->$method(sanitize_text_field($_POST[$key])); |
|
764 | 764 | } |
765 | 765 | } |
766 | 766 | |
767 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
768 | - if ( $discount->exists() ) { |
|
769 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
767 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
768 | + if ($discount->exists()) { |
|
769 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
770 | 770 | } else { |
771 | - $invoice->remove_discount( 'discount_code' ); |
|
771 | + $invoice->remove_discount('discount_code'); |
|
772 | 772 | } |
773 | 773 | |
774 | 774 | // Save the invoice. |
775 | 775 | $invoice->recalculate_total(); |
776 | 776 | $invoice->save(); |
777 | 777 | ob_start(); |
778 | - GetPaid_Meta_Box_Invoice_Items::output( get_post( $invoice->get_id() ), $invoice ); |
|
778 | + GetPaid_Meta_Box_Invoice_Items::output(get_post($invoice->get_id()), $invoice); |
|
779 | 779 | $table = ob_get_clean(); |
780 | - wp_send_json_success( compact( 'table' ) ); |
|
780 | + wp_send_json_success(compact('table')); |
|
781 | 781 | } |
782 | 782 | |
783 | 783 | /** |
@@ -786,43 +786,43 @@ discard block |
||
786 | 786 | public static function admin_add_invoice_item() { |
787 | 787 | |
788 | 788 | // Verify nonce. |
789 | - check_ajax_referer( 'wpinv-nonce' ); |
|
789 | + check_ajax_referer('wpinv-nonce'); |
|
790 | 790 | |
791 | 791 | // We need an invoice and item. |
792 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
792 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
793 | 793 | exit; |
794 | 794 | } |
795 | 795 | |
796 | 796 | // Fetch the invoice. |
797 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
797 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
798 | 798 | $alert = false; |
799 | 799 | |
800 | 800 | // Ensure it exists and its not been paid for. |
801 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
801 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
802 | 802 | exit; |
803 | 803 | } |
804 | 804 | |
805 | 805 | // Add the item. |
806 | - $item = new GetPaid_Form_Item( (int) $_POST['item_id'] ); |
|
806 | + $item = new GetPaid_Form_Item((int) $_POST['item_id']); |
|
807 | 807 | |
808 | - if ( ! wpinv_current_user_can( 'invoice_add_item', array( 'invoice' => $invoice, 'invoice_item' => $item ) ) ) { |
|
808 | + if (!wpinv_current_user_can('invoice_add_item', array('invoice' => $invoice, 'invoice_item' => $item))) { |
|
809 | 809 | exit; |
810 | 810 | } |
811 | 811 | |
812 | - $error = $invoice->add_item( $item ); |
|
812 | + $error = $invoice->add_item($item); |
|
813 | 813 | |
814 | - if ( is_wp_error( $error ) ) { |
|
814 | + if (is_wp_error($error)) { |
|
815 | 815 | $alert = $error->get_error_message(); |
816 | - wp_send_json_success( compact( 'alert' ) ); |
|
816 | + wp_send_json_success(compact('alert')); |
|
817 | 817 | } |
818 | 818 | |
819 | 819 | // Save the invoice. |
820 | 820 | $invoice->recalculate_total(); |
821 | 821 | $invoice->save(); |
822 | 822 | ob_start(); |
823 | - GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice ); |
|
823 | + GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice); |
|
824 | 824 | $row = ob_get_clean(); |
825 | - wp_send_json_success( compact( 'row' ) ); |
|
825 | + wp_send_json_success(compact('row')); |
|
826 | 826 | } |
827 | 827 | |
828 | 828 | /** |
@@ -831,39 +831,39 @@ discard block |
||
831 | 831 | public static function add_invoice_items() { |
832 | 832 | |
833 | 833 | // Verify nonce. |
834 | - check_ajax_referer( 'wpinv-nonce' ); |
|
834 | + check_ajax_referer('wpinv-nonce'); |
|
835 | 835 | |
836 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
836 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
837 | 837 | exit; |
838 | 838 | } |
839 | 839 | |
840 | 840 | // We need an invoice and items. |
841 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) { |
|
841 | + if (empty($_POST['post_id']) || empty($_POST['items'])) { |
|
842 | 842 | exit; |
843 | 843 | } |
844 | 844 | |
845 | 845 | // Fetch the invoice. |
846 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
846 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
847 | 847 | $alert = false; |
848 | 848 | |
849 | 849 | // Ensure it exists and its not been paid for. |
850 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
850 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
851 | 851 | exit; |
852 | 852 | } |
853 | 853 | |
854 | 854 | // Add the items. |
855 | - foreach ( wp_kses_post_deep( wp_unslash( $_POST['items'] ) ) as $data ) { |
|
855 | + foreach (wp_kses_post_deep(wp_unslash($_POST['items'])) as $data) { |
|
856 | 856 | |
857 | - $item = new GetPaid_Form_Item( (int) $data['id'] ); |
|
857 | + $item = new GetPaid_Form_Item((int) $data['id']); |
|
858 | 858 | |
859 | - if ( is_numeric( $data['qty'] ) && (float) $data['qty'] > 0 ) { |
|
860 | - $item->set_quantity( floatval( $data['qty'] ) ); |
|
859 | + if (is_numeric($data['qty']) && (float) $data['qty'] > 0) { |
|
860 | + $item->set_quantity(floatval($data['qty'])); |
|
861 | 861 | } |
862 | 862 | |
863 | - if ( $item->get_id() > 0 ) { |
|
864 | - $error = $invoice->add_item( $item ); |
|
863 | + if ($item->get_id() > 0) { |
|
864 | + $error = $invoice->add_item($item); |
|
865 | 865 | |
866 | - if ( is_wp_error( $error ) ) { |
|
866 | + if (is_wp_error($error)) { |
|
867 | 867 | $alert = $error->get_error_message(); |
868 | 868 | } |
869 | 869 | } |
@@ -876,11 +876,11 @@ discard block |
||
876 | 876 | // Return an array of invoice items. |
877 | 877 | $items = array(); |
878 | 878 | |
879 | - foreach ( $invoice->get_items() as $item ) { |
|
880 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
879 | + foreach ($invoice->get_items() as $item) { |
|
880 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
881 | 881 | } |
882 | 882 | |
883 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
883 | + wp_send_json_success(compact('items', 'alert')); |
|
884 | 884 | } |
885 | 885 | |
886 | 886 | /** |
@@ -889,15 +889,15 @@ discard block |
||
889 | 889 | public static function get_invoicing_items() { |
890 | 890 | |
891 | 891 | // Verify nonce. |
892 | - check_ajax_referer( 'wpinv-nonce' ); |
|
892 | + check_ajax_referer('wpinv-nonce'); |
|
893 | 893 | |
894 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
894 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
895 | 895 | exit; |
896 | 896 | } |
897 | 897 | |
898 | 898 | // We need a search term. |
899 | - if ( empty( $_GET['search'] ) ) { |
|
900 | - wp_send_json_success( array() ); |
|
899 | + if (empty($_GET['search'])) { |
|
900 | + wp_send_json_success(array()); |
|
901 | 901 | } |
902 | 902 | |
903 | 903 | // Retrieve items. |
@@ -906,8 +906,8 @@ discard block |
||
906 | 906 | 'orderby' => 'title', |
907 | 907 | 'order' => 'ASC', |
908 | 908 | 'posts_per_page' => -1, |
909 | - 'post_status' => array( 'publish' ), |
|
910 | - 's' => sanitize_text_field( urldecode( $_GET['search'] ) ), |
|
909 | + 'post_status' => array('publish'), |
|
910 | + 's' => sanitize_text_field(urldecode($_GET['search'])), |
|
911 | 911 | 'meta_query' => array( |
912 | 912 | array( |
913 | 913 | 'key' => '_wpinv_type', |
@@ -917,25 +917,25 @@ discard block |
||
917 | 917 | ), |
918 | 918 | ); |
919 | 919 | |
920 | - if ( ! empty( $_GET['ignore'] ) ) { |
|
921 | - $item_args['exclude'] = wp_parse_id_list( sanitize_text_field( $_GET['ignore'] ) ); |
|
920 | + if (!empty($_GET['ignore'])) { |
|
921 | + $item_args['exclude'] = wp_parse_id_list(sanitize_text_field($_GET['ignore'])); |
|
922 | 922 | } |
923 | 923 | |
924 | - $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) ); |
|
924 | + $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args)); |
|
925 | 925 | $data = array(); |
926 | 926 | |
927 | - $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( (int) $_GET['post_id'] ) ); |
|
927 | + $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type((int) $_GET['post_id'])); |
|
928 | 928 | |
929 | - foreach ( $items as $item ) { |
|
930 | - $item = new GetPaid_Form_Item( $item ); |
|
929 | + foreach ($items as $item) { |
|
930 | + $item = new GetPaid_Form_Item($item); |
|
931 | 931 | $data[] = array( |
932 | 932 | 'id' => (int) $item->get_id(), |
933 | - 'text' => strip_tags( $item->get_name() ), |
|
934 | - 'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '', |
|
933 | + 'text' => strip_tags($item->get_name()), |
|
934 | + 'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '', |
|
935 | 935 | ); |
936 | 936 | } |
937 | 937 | |
938 | - wp_send_json_success( $data ); |
|
938 | + wp_send_json_success($data); |
|
939 | 939 | |
940 | 940 | } |
941 | 941 | |
@@ -945,37 +945,37 @@ discard block |
||
945 | 945 | public static function get_customers() { |
946 | 946 | |
947 | 947 | // Verify nonce. |
948 | - check_ajax_referer( 'wpinv-nonce' ); |
|
948 | + check_ajax_referer('wpinv-nonce'); |
|
949 | 949 | |
950 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
950 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
951 | 951 | exit; |
952 | 952 | } |
953 | 953 | |
954 | 954 | // We need a search term. |
955 | - if ( empty( $_GET['search'] ) ) { |
|
956 | - wp_send_json_success( array() ); |
|
955 | + if (empty($_GET['search'])) { |
|
956 | + wp_send_json_success(array()); |
|
957 | 957 | } |
958 | 958 | |
959 | 959 | // Retrieve customers. |
960 | 960 | |
961 | 961 | $customer_args = array( |
962 | - 'fields' => array( 'ID', 'user_email', 'display_name' ), |
|
962 | + 'fields' => array('ID', 'user_email', 'display_name'), |
|
963 | 963 | 'orderby' => 'display_name', |
964 | - 'search' => '*' . sanitize_text_field( $_GET['search'] ) . '*', |
|
965 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
964 | + 'search' => '*' . sanitize_text_field($_GET['search']) . '*', |
|
965 | + 'search_columns' => array('user_login', 'user_email', 'display_name'), |
|
966 | 966 | ); |
967 | 967 | |
968 | - $customers = get_users( apply_filters( 'getpaid_ajax_invoice_customers_query_args', $customer_args ) ); |
|
968 | + $customers = get_users(apply_filters('getpaid_ajax_invoice_customers_query_args', $customer_args)); |
|
969 | 969 | $data = array(); |
970 | 970 | |
971 | - foreach ( $customers as $customer ) { |
|
971 | + foreach ($customers as $customer) { |
|
972 | 972 | $data[] = array( |
973 | 973 | 'id' => (int) $customer->ID, |
974 | - 'text' => strip_tags( sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ) ), |
|
974 | + 'text' => strip_tags(sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email)), |
|
975 | 975 | ); |
976 | 976 | } |
977 | 977 | |
978 | - wp_send_json_success( $data ); |
|
978 | + wp_send_json_success($data); |
|
979 | 979 | |
980 | 980 | } |
981 | 981 | |
@@ -985,25 +985,25 @@ discard block |
||
985 | 985 | public static function get_aui_states_field() { |
986 | 986 | |
987 | 987 | // We need a country. |
988 | - if ( empty( $_GET['country'] ) ) { |
|
988 | + if (empty($_GET['country'])) { |
|
989 | 989 | exit; |
990 | 990 | } |
991 | 991 | |
992 | - $states = wpinv_get_country_states( sanitize_text_field( $_GET['country'] ) ); |
|
993 | - $state = isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : wpinv_get_default_state(); |
|
994 | - $name = isset( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : 'wpinv_state'; |
|
995 | - $class = isset( $_GET['class'] ) ? sanitize_text_field( $_GET['class'] ) : 'form-control-sm'; |
|
992 | + $states = wpinv_get_country_states(sanitize_text_field($_GET['country'])); |
|
993 | + $state = isset($_GET['state']) ? sanitize_text_field($_GET['state']) : wpinv_get_default_state(); |
|
994 | + $name = isset($_GET['name']) ? sanitize_text_field($_GET['name']) : 'wpinv_state'; |
|
995 | + $class = isset($_GET['class']) ? sanitize_text_field($_GET['class']) : 'form-control-sm'; |
|
996 | 996 | |
997 | - if ( empty( $states ) ) { |
|
997 | + if (empty($states)) { |
|
998 | 998 | |
999 | 999 | $html = aui()->input( |
1000 | 1000 | array( |
1001 | 1001 | 'type' => 'text', |
1002 | 1002 | 'id' => 'wpinv_state', |
1003 | 1003 | 'name' => $name, |
1004 | - 'label' => __( 'State', 'invoicing' ), |
|
1004 | + 'label' => __('State', 'invoicing'), |
|
1005 | 1005 | 'label_type' => 'vertical', |
1006 | - 'placeholder' => __( 'State', 'invoicing' ), |
|
1006 | + 'placeholder' => __('State', 'invoicing'), |
|
1007 | 1007 | 'class' => $class, |
1008 | 1008 | 'value' => $state, |
1009 | 1009 | ) |
@@ -1015,9 +1015,9 @@ discard block |
||
1015 | 1015 | array( |
1016 | 1016 | 'id' => 'wpinv_state', |
1017 | 1017 | 'name' => $name, |
1018 | - 'label' => __( 'State', 'invoicing' ), |
|
1018 | + 'label' => __('State', 'invoicing'), |
|
1019 | 1019 | 'label_type' => 'vertical', |
1020 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
1020 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
1021 | 1021 | 'class' => $class, |
1022 | 1022 | 'value' => $state, |
1023 | 1023 | 'options' => $states, |
@@ -1031,7 +1031,7 @@ discard block |
||
1031 | 1031 | wp_send_json_success( |
1032 | 1032 | array( |
1033 | 1033 | 'html' => $html, |
1034 | - 'select' => ! empty( $states ), |
|
1034 | + 'select' => !empty($states), |
|
1035 | 1035 | ) |
1036 | 1036 | ); |
1037 | 1037 | |
@@ -1045,8 +1045,8 @@ discard block |
||
1045 | 1045 | public static function payment_form_refresh_prices() { |
1046 | 1046 | |
1047 | 1047 | // ... form fields... |
1048 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
1049 | - esc_html_e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
1048 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
1049 | + esc_html_e('Error: Reload the page and try again.', 'invoicing'); |
|
1050 | 1050 | exit; |
1051 | 1051 | } |
1052 | 1052 | |
@@ -1054,7 +1054,7 @@ discard block |
||
1054 | 1054 | $submission = new GetPaid_Payment_Form_Submission(); |
1055 | 1055 | |
1056 | 1056 | // Do we have an error? |
1057 | - if ( ! empty( $submission->last_error ) ) { |
|
1057 | + if (!empty($submission->last_error)) { |
|
1058 | 1058 | wp_send_json_error( |
1059 | 1059 | array( |
1060 | 1060 | 'code' => $submission->last_error_code, |
@@ -1064,12 +1064,12 @@ discard block |
||
1064 | 1064 | } |
1065 | 1065 | |
1066 | 1066 | // Prepare the response. |
1067 | - $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission ); |
|
1067 | + $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission); |
|
1068 | 1068 | |
1069 | 1069 | // Filter the response. |
1070 | - $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission ); |
|
1070 | + $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission); |
|
1071 | 1071 | |
1072 | - wp_send_json_success( $response ); |
|
1072 | + wp_send_json_success($response); |
|
1073 | 1073 | } |
1074 | 1074 | |
1075 | 1075 | /** |
@@ -1081,63 +1081,63 @@ discard block |
||
1081 | 1081 | public static function file_upload() { |
1082 | 1082 | |
1083 | 1083 | // Check nonce. |
1084 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
1084 | + check_ajax_referer('getpaid_form_nonce'); |
|
1085 | 1085 | |
1086 | - if ( empty( $_POST['form_id'] ) || empty( $_POST['field_name'] ) || empty( $_FILES['file'] ) ) { |
|
1087 | - wp_die( esc_html_e( 'Bad Request', 'invoicing' ), 400 ); |
|
1086 | + if (empty($_POST['form_id']) || empty($_POST['field_name']) || empty($_FILES['file'])) { |
|
1087 | + wp_die(esc_html_e('Bad Request', 'invoicing'), 400); |
|
1088 | 1088 | } |
1089 | 1089 | |
1090 | 1090 | // Fetch form. |
1091 | - $form = new GetPaid_Payment_Form( intval( $_POST['form_id'] ) ); |
|
1091 | + $form = new GetPaid_Payment_Form(intval($_POST['form_id'])); |
|
1092 | 1092 | |
1093 | - if ( ! $form->is_active() ) { |
|
1094 | - wp_send_json_error( __( 'Payment form not active', 'invoicing' ) ); |
|
1093 | + if (!$form->is_active()) { |
|
1094 | + wp_send_json_error(__('Payment form not active', 'invoicing')); |
|
1095 | 1095 | } |
1096 | 1096 | |
1097 | 1097 | // Fetch appropriate field. |
1098 | - $upload_field = current( wp_list_filter( $form->get_elements(), array( 'id' => sanitize_text_field( $_POST['field_name'] ) ) ) ); |
|
1099 | - if ( empty( $upload_field ) ) { |
|
1100 | - wp_send_json_error( __( 'Invalid upload field.', 'invoicing' ) ); |
|
1098 | + $upload_field = current(wp_list_filter($form->get_elements(), array('id' => sanitize_text_field($_POST['field_name'])))); |
|
1099 | + if (empty($upload_field)) { |
|
1100 | + wp_send_json_error(__('Invalid upload field.', 'invoicing')); |
|
1101 | 1101 | } |
1102 | 1102 | |
1103 | 1103 | // Prepare allowed file types. |
1104 | - $file_types = isset( $upload_field['file_types'] ) ? $upload_field['file_types'] : array( 'jpg|jpeg|jpe', 'gif', 'png' ); |
|
1104 | + $file_types = isset($upload_field['file_types']) ? $upload_field['file_types'] : array('jpg|jpeg|jpe', 'gif', 'png'); |
|
1105 | 1105 | $all_types = getpaid_get_allowed_mime_types(); |
1106 | 1106 | $mime_types = array(); |
1107 | 1107 | |
1108 | - foreach ( $file_types as $file_type ) { |
|
1109 | - if ( isset( $all_types[ $file_type ] ) ) { |
|
1110 | - $mime_types[] = $all_types[ $file_type ]; |
|
1108 | + foreach ($file_types as $file_type) { |
|
1109 | + if (isset($all_types[$file_type])) { |
|
1110 | + $mime_types[] = $all_types[$file_type]; |
|
1111 | 1111 | } |
1112 | 1112 | } |
1113 | 1113 | |
1114 | - if ( ! in_array( $_FILES['file']['type'], $mime_types ) ) { |
|
1115 | - wp_send_json_error( __( 'Unsupported file type.', 'invoicing' ) ); |
|
1114 | + if (!in_array($_FILES['file']['type'], $mime_types)) { |
|
1115 | + wp_send_json_error(__('Unsupported file type.', 'invoicing')); |
|
1116 | 1116 | } |
1117 | 1117 | |
1118 | 1118 | // Upload file. |
1119 | - $file_name = explode( '.', strtolower( $_FILES['file']['name'] ) ); |
|
1120 | - $file_name = uniqid( 'getpaid-' ) . '.' . array_pop( $file_name ); |
|
1119 | + $file_name = explode('.', strtolower($_FILES['file']['name'])); |
|
1120 | + $file_name = uniqid('getpaid-') . '.' . array_pop($file_name); |
|
1121 | 1121 | |
1122 | 1122 | $uploaded = wp_upload_bits( |
1123 | 1123 | $file_name, |
1124 | 1124 | null, |
1125 | - file_get_contents( $_FILES['file']['tmp_name'] ) |
|
1125 | + file_get_contents($_FILES['file']['tmp_name']) |
|
1126 | 1126 | ); |
1127 | 1127 | |
1128 | - if ( ! empty( $uploaded['error'] ) ) { |
|
1129 | - wp_send_json_error( $uploaded['error'] ); |
|
1128 | + if (!empty($uploaded['error'])) { |
|
1129 | + wp_send_json_error($uploaded['error']); |
|
1130 | 1130 | } |
1131 | 1131 | |
1132 | 1132 | // Retrieve response. |
1133 | 1133 | $response = sprintf( |
1134 | 1134 | '<input type="hidden" name="%s[%s]" value="%s" />', |
1135 | - esc_attr( sanitize_text_field( $_POST['field_name'] ) ), |
|
1136 | - esc_url( $uploaded['url'] ), |
|
1137 | - esc_attr( sanitize_text_field( strtolower( $_FILES['file']['name'] ) ) ) |
|
1135 | + esc_attr(sanitize_text_field($_POST['field_name'])), |
|
1136 | + esc_url($uploaded['url']), |
|
1137 | + esc_attr(sanitize_text_field(strtolower($_FILES['file']['name']))) |
|
1138 | 1138 | ); |
1139 | 1139 | |
1140 | - wp_send_json_success( $response ); |
|
1140 | + wp_send_json_success($response); |
|
1141 | 1141 | |
1142 | 1142 | } |
1143 | 1143 |