@@ -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 | /** |
@@ -57,17 +57,17 @@ discard block |
||
57 | 57 | * @since 1.0.19 |
58 | 58 | * @return int|WP_Error |
59 | 59 | */ |
60 | -function wpinv_create_user( $email ) { |
|
60 | +function wpinv_create_user($email) { |
|
61 | 61 | |
62 | 62 | // Prepare user values. |
63 | 63 | $args = array( |
64 | - 'user_login' => wpinv_generate_user_name( $email ), |
|
64 | + 'user_login' => wpinv_generate_user_name($email), |
|
65 | 65 | 'user_pass' => wp_generate_password(), |
66 | 66 | 'user_email' => $email, |
67 | 67 | 'role' => 'subscriber', |
68 | 68 | ); |
69 | 69 | |
70 | - return wp_insert_user( $args ); |
|
70 | + return wp_insert_user($args); |
|
71 | 71 | |
72 | 72 | } |
73 | 73 | |
@@ -77,22 +77,22 @@ discard block |
||
77 | 77 | * @since 1.0.19 |
78 | 78 | * @return bool|WP_User |
79 | 79 | */ |
80 | -function wpinv_generate_user_name( $prefix = '' ) { |
|
80 | +function wpinv_generate_user_name($prefix = '') { |
|
81 | 81 | |
82 | 82 | // If prefix is an email, retrieve the part before the email. |
83 | - $prefix = strtok( $prefix, '@' ); |
|
83 | + $prefix = strtok($prefix, '@'); |
|
84 | 84 | |
85 | 85 | // Trim to 4 characters max. |
86 | - $prefix = sanitize_user( $prefix ); |
|
86 | + $prefix = sanitize_user($prefix); |
|
87 | 87 | |
88 | - $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
89 | - if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
88 | + $illegal_logins = (array) apply_filters('illegal_user_logins', array()); |
|
89 | + if (empty($prefix) || in_array(strtolower($prefix), array_map('strtolower', $illegal_logins), true)) { |
|
90 | 90 | $prefix = 'gtp'; |
91 | 91 | } |
92 | 92 | |
93 | - $username = $prefix . '_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
94 | - if ( username_exists( $username ) ) { |
|
95 | - return wpinv_generate_user_name( $username ); |
|
93 | + $username = $prefix . '_' . zeroise(wp_rand(0, 9999), 4); |
|
94 | + if (username_exists($username)) { |
|
95 | + return wpinv_generate_user_name($username); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | return $username; |
@@ -109,26 +109,26 @@ discard block |
||
109 | 109 | $tabs = array( |
110 | 110 | |
111 | 111 | 'gp-edit-address' => array( |
112 | - 'label' => __( 'Billing Address', 'invoicing' ), |
|
112 | + 'label' => __('Billing Address', 'invoicing'), |
|
113 | 113 | 'callback' => 'getpaid_display_address_edit_tab', |
114 | 114 | 'icon' => 'fas fa-credit-card', |
115 | 115 | ), |
116 | 116 | |
117 | 117 | 'gp-invoices' => array( |
118 | - 'label' => __( 'Invoices', 'invoicing' ), // Name of the tab. |
|
118 | + 'label' => __('Invoices', 'invoicing'), // Name of the tab. |
|
119 | 119 | 'content' => '[wpinv_history]', // Content of the tab. Or specify "callback" to provide a callback instead. |
120 | 120 | 'icon' => 'fas fa-file-invoice', // Shown on some profile plugins. |
121 | 121 | ), |
122 | 122 | |
123 | 123 | 'gp-subscriptions' => array( |
124 | - 'label' => __( 'Subscriptions', 'invoicing' ), |
|
124 | + 'label' => __('Subscriptions', 'invoicing'), |
|
125 | 125 | 'content' => '[wpinv_subscriptions]', |
126 | 126 | 'icon' => 'fas fa-redo', |
127 | 127 | ), |
128 | 128 | |
129 | 129 | ); |
130 | 130 | |
131 | - return apply_filters( 'getpaid_user_content_tabs', $tabs ); |
|
131 | + return apply_filters('getpaid_user_content_tabs', $tabs); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -138,19 +138,19 @@ discard block |
||
138 | 138 | * @param array $tab |
139 | 139 | * @return array |
140 | 140 | */ |
141 | -function getpaid_prepare_user_content_tab( $tab ) { |
|
141 | +function getpaid_prepare_user_content_tab($tab) { |
|
142 | 142 | |
143 | - if ( ! empty( $tab['callback'] ) ) { |
|
144 | - return call_user_func( $tab['callback'] ); |
|
143 | + if (!empty($tab['callback'])) { |
|
144 | + return call_user_func($tab['callback']); |
|
145 | 145 | } |
146 | 146 | |
147 | - if ( ! empty( $tab['content'] ) ) { |
|
148 | - return convert_smilies( capital_P_dangit( wp_filter_content_tags( do_shortcode( shortcode_unautop( wpautop( wptexturize( do_blocks( $tab['content'] ) ) ) ) ) ) ) ); |
|
147 | + if (!empty($tab['content'])) { |
|
148 | + return convert_smilies(capital_P_dangit(wp_filter_content_tags(do_shortcode(shortcode_unautop(wpautop(wptexturize(do_blocks($tab['content'])))))))); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | $notice = aui()->alert( |
152 | 152 | array( |
153 | - 'content' => __( 'This tab has no content or content callback.', 'invoicing' ), |
|
153 | + 'content' => __('This tab has no content or content callback.', 'invoicing'), |
|
154 | 154 | 'type' => 'error', |
155 | 155 | ) |
156 | 156 | ); |
@@ -166,14 +166,14 @@ discard block |
||
166 | 166 | * @param string $default |
167 | 167 | * @return array |
168 | 168 | */ |
169 | -function getpaid_get_tab_url( $tab, $default ) { |
|
169 | +function getpaid_get_tab_url($tab, $default) { |
|
170 | 170 | global $getpaid_tab_url; |
171 | 171 | |
172 | - if ( empty( $getpaid_tab_url ) ) { |
|
172 | + if (empty($getpaid_tab_url)) { |
|
173 | 173 | return $default; |
174 | 174 | } |
175 | 175 | |
176 | - return sprintf( $getpaid_tab_url, $tab ); |
|
176 | + return sprintf($getpaid_tab_url, $tab); |
|
177 | 177 | |
178 | 178 | } |
179 | 179 | |
@@ -193,19 +193,19 @@ discard block |
||
193 | 193 | |
194 | 194 | <?php |
195 | 195 | |
196 | - foreach ( getpaid_user_address_fields() as $key => $label ) { |
|
196 | + foreach (getpaid_user_address_fields() as $key => $label) { |
|
197 | 197 | |
198 | 198 | // Display the country. |
199 | - if ( 'country' == $key ) { |
|
199 | + if ('country' == $key) { |
|
200 | 200 | |
201 | 201 | echo aui()->select( |
202 | 202 | array( |
203 | 203 | 'options' => wpinv_get_country_list(), |
204 | - 'name' => esc_attr( $key ), |
|
205 | - 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
206 | - 'value' => sanitize_text_field( getpaid_get_user_address_field( get_current_user_id(), $key ) ), |
|
204 | + 'name' => esc_attr($key), |
|
205 | + 'id' => 'wpinv-' . sanitize_html_class($key), |
|
206 | + 'value' => sanitize_text_field(getpaid_get_user_address_field(get_current_user_id(), $key)), |
|
207 | 207 | 'placeholder' => $label, |
208 | - 'label' => wp_kses_post( $label ), |
|
208 | + 'label' => wp_kses_post($label), |
|
209 | 209 | 'label_type' => 'vertical', |
210 | 210 | 'class' => 'getpaid-address-field', |
211 | 211 | ) |
@@ -214,11 +214,11 @@ discard block |
||
214 | 214 | } |
215 | 215 | |
216 | 216 | // Display the state. |
217 | - else if ( 'state' == $key ) { |
|
217 | + else if ('state' == $key) { |
|
218 | 218 | |
219 | - echo getpaid_get_states_select_markup ( |
|
220 | - getpaid_get_user_address_field( get_current_user_id(), 'country' ), |
|
221 | - getpaid_get_user_address_field( get_current_user_id(), 'state' ), |
|
219 | + echo getpaid_get_states_select_markup( |
|
220 | + getpaid_get_user_address_field(get_current_user_id(), 'country'), |
|
221 | + getpaid_get_user_address_field(get_current_user_id(), 'state'), |
|
222 | 222 | $label, |
223 | 223 | $label, |
224 | 224 | '', |
@@ -231,13 +231,13 @@ discard block |
||
231 | 231 | |
232 | 232 | echo aui()->input( |
233 | 233 | array( |
234 | - 'name' => esc_attr( $key ), |
|
235 | - 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
234 | + 'name' => esc_attr($key), |
|
235 | + 'id' => 'wpinv-' . sanitize_html_class($key), |
|
236 | 236 | 'placeholder' => $label, |
237 | - 'label' => wp_kses_post( $label ), |
|
237 | + 'label' => wp_kses_post($label), |
|
238 | 238 | 'label_type' => 'vertical', |
239 | 239 | 'type' => 'text', |
240 | - 'value' => sanitize_text_field( getpaid_get_user_address_field( get_current_user_id(), $key ) ), |
|
240 | + 'value' => sanitize_text_field(getpaid_get_user_address_field(get_current_user_id(), $key)), |
|
241 | 241 | 'class' => 'getpaid-address-field', |
242 | 242 | ) |
243 | 243 | ); |
@@ -246,21 +246,21 @@ discard block |
||
246 | 246 | |
247 | 247 | } |
248 | 248 | |
249 | - do_action( 'getpaid_display_address_edit_tab' ); |
|
249 | + do_action('getpaid_display_address_edit_tab'); |
|
250 | 250 | |
251 | 251 | echo aui()->input( |
252 | 252 | array( |
253 | 253 | 'name' => 'getpaid_profile_edit_submit_button', |
254 | 254 | 'id' => 'getpaid_profile_edit_submit_button', |
255 | - 'value' => __( 'Save Address', 'invoicing' ), |
|
256 | - 'help_text' => __( 'New invoices will use this address as the billing address.', 'invoicing' ), |
|
255 | + 'value' => __('Save Address', 'invoicing'), |
|
256 | + 'help_text' => __('New invoices will use this address as the billing address.', 'invoicing'), |
|
257 | 257 | 'type' => 'submit', |
258 | 258 | 'class' => 'btn btn-primary btn-block submit-button', |
259 | 259 | ) |
260 | 260 | ); |
261 | 261 | |
262 | - wp_nonce_field( 'getpaid-nonce', 'getpaid-nonce' ); |
|
263 | - getpaid_hidden_field( 'getpaid-action', 'edit_billing_details' ); |
|
262 | + wp_nonce_field('getpaid-nonce', 'getpaid-nonce'); |
|
263 | + getpaid_hidden_field('getpaid-action', 'edit_billing_details'); |
|
264 | 264 | ?> |
265 | 265 | |
266 | 266 | </form> |
@@ -277,20 +277,20 @@ discard block |
||
277 | 277 | * @since 2.1.4 |
278 | 278 | * @param array $data |
279 | 279 | */ |
280 | -function getpaid_save_address_edit_tab( $data ) { |
|
280 | +function getpaid_save_address_edit_tab($data) { |
|
281 | 281 | |
282 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
282 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
283 | 283 | |
284 | - if ( isset( $data[ $field ] ) ) { |
|
285 | - $value = sanitize_text_field( $data[ $field ] ); |
|
286 | - update_user_meta( get_current_user_id(), '_wpinv_' . $field, $value ); |
|
284 | + if (isset($data[$field])) { |
|
285 | + $value = sanitize_text_field($data[$field]); |
|
286 | + update_user_meta(get_current_user_id(), '_wpinv_' . $field, $value); |
|
287 | 287 | } |
288 | 288 | |
289 | - wpinv_set_error( 'address_updated', __( 'You billing address has been updated', 'invoicing' ), 'success'); |
|
289 | + wpinv_set_error('address_updated', __('You billing address has been updated', 'invoicing'), 'success'); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | } |
293 | -add_action( 'getpaid_authenticated_action_edit_billing_details', 'getpaid_save_address_edit_tab' ); |
|
293 | +add_action('getpaid_authenticated_action_edit_billing_details', 'getpaid_save_address_edit_tab'); |
|
294 | 294 | |
295 | 295 | |
296 | 296 | /* |
@@ -308,27 +308,27 @@ discard block |
||
308 | 308 | * @param array $tabs |
309 | 309 | * @return array |
310 | 310 | */ |
311 | -function getpaid_filter_userswp_account_tabs( $tabs ) { |
|
311 | +function getpaid_filter_userswp_account_tabs($tabs) { |
|
312 | 312 | |
313 | 313 | // Abort if the integration is inactive. |
314 | - if ( ! getpaid_is_userswp_integration_active() ) { |
|
314 | + if (!getpaid_is_userswp_integration_active()) { |
|
315 | 315 | return $tabs; |
316 | 316 | } |
317 | 317 | |
318 | - $new_tabs = array(); |
|
318 | + $new_tabs = array(); |
|
319 | 319 | |
320 | - foreach ( getpaid_get_user_content_tabs() as $slug => $tab ) { |
|
320 | + foreach (getpaid_get_user_content_tabs() as $slug => $tab) { |
|
321 | 321 | |
322 | - $new_tabs[ $slug ] = array( |
|
323 | - 'title' => $tab[ 'label'], |
|
324 | - 'icon' => $tab[ 'icon'], |
|
322 | + $new_tabs[$slug] = array( |
|
323 | + 'title' => $tab['label'], |
|
324 | + 'icon' => $tab['icon'], |
|
325 | 325 | ); |
326 | 326 | |
327 | 327 | } |
328 | 328 | |
329 | - return array_merge( $tabs, $new_tabs ); |
|
329 | + return array_merge($tabs, $new_tabs); |
|
330 | 330 | } |
331 | -add_filter( 'uwp_account_available_tabs', 'getpaid_filter_userswp_account_tabs' ); |
|
331 | +add_filter('uwp_account_available_tabs', 'getpaid_filter_userswp_account_tabs'); |
|
332 | 332 | |
333 | 333 | /** |
334 | 334 | * Display our UsersWP account tabs. |
@@ -337,18 +337,18 @@ discard block |
||
337 | 337 | * @param array $tabs |
338 | 338 | * @return array |
339 | 339 | */ |
340 | -function getpaid_display_userswp_account_tabs( $tab ) { |
|
340 | +function getpaid_display_userswp_account_tabs($tab) { |
|
341 | 341 | global $getpaid_tab_url; |
342 | 342 | |
343 | 343 | $our_tabs = getpaid_get_user_content_tabs(); |
344 | 344 | |
345 | - if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) { |
|
346 | - $getpaid_tab_url = add_query_arg( 'type', '%s', uwp_get_account_page_url() ); |
|
347 | - echo getpaid_prepare_user_content_tab( $our_tabs[ $tab ] ); |
|
345 | + if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) { |
|
346 | + $getpaid_tab_url = add_query_arg('type', '%s', uwp_get_account_page_url()); |
|
347 | + echo getpaid_prepare_user_content_tab($our_tabs[$tab]); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | } |
351 | -add_action( 'uwp_account_form_display', 'getpaid_display_userswp_account_tabs' ); |
|
351 | +add_action('uwp_account_form_display', 'getpaid_display_userswp_account_tabs'); |
|
352 | 352 | |
353 | 353 | |
354 | 354 | /** |
@@ -359,17 +359,17 @@ discard block |
||
359 | 359 | * @param string $tab Current tab. |
360 | 360 | * @return string Title. |
361 | 361 | */ |
362 | -function getpaid_filter_userswp_account_title( $title, $tab ) { |
|
362 | +function getpaid_filter_userswp_account_title($title, $tab) { |
|
363 | 363 | |
364 | - $our_tabs = getpaid_get_user_content_tabs(); |
|
364 | + $our_tabs = getpaid_get_user_content_tabs(); |
|
365 | 365 | |
366 | - if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) { |
|
367 | - return $our_tabs[ $tab ]['label']; |
|
366 | + if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) { |
|
367 | + return $our_tabs[$tab]['label']; |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | return $title; |
371 | 371 | } |
372 | -add_filter( 'uwp_account_page_title', 'getpaid_filter_userswp_account_title', 10, 2 ); |
|
372 | +add_filter('uwp_account_page_title', 'getpaid_filter_userswp_account_title', 10, 2); |
|
373 | 373 | |
374 | 374 | /** |
375 | 375 | * Registers the UsersWP integration settings. |
@@ -378,26 +378,26 @@ discard block |
||
378 | 378 | * @param array $settings An array of integration settings. |
379 | 379 | * @return array |
380 | 380 | */ |
381 | -function getpaid_register_userswp_settings( $settings ) { |
|
381 | +function getpaid_register_userswp_settings($settings) { |
|
382 | 382 | |
383 | - if ( defined( 'USERSWP_PLUGIN_FILE' ) ) { |
|
383 | + if (defined('USERSWP_PLUGIN_FILE')) { |
|
384 | 384 | |
385 | 385 | $settings[] = array( |
386 | 386 | |
387 | 387 | 'id' => 'userswp', |
388 | - 'label' => __( 'UsersWP', 'invoicing' ), |
|
388 | + 'label' => __('UsersWP', 'invoicing'), |
|
389 | 389 | 'settings' => array( |
390 | 390 | |
391 | 391 | 'userswp_settings' => array( |
392 | 392 | 'id' => 'userswp_settings', |
393 | - 'name' => '<h3>' . __( 'UsersWP', 'invoicing' ) . '</h3>', |
|
393 | + 'name' => '<h3>' . __('UsersWP', 'invoicing') . '</h3>', |
|
394 | 394 | 'type' => 'header', |
395 | 395 | ), |
396 | 396 | |
397 | 397 | 'enable_userswp' => array( |
398 | 398 | 'id' => 'enable_userswp', |
399 | - 'name' => __( 'Enable Integration', 'invoicing' ), |
|
400 | - 'desc' => __( 'Display GetPaid items on UsersWP account page.', 'invoicing' ), |
|
399 | + 'name' => __('Enable Integration', 'invoicing'), |
|
400 | + 'desc' => __('Display GetPaid items on UsersWP account page.', 'invoicing'), |
|
401 | 401 | 'type' => 'checkbox', |
402 | 402 | 'std' => 1, |
403 | 403 | ) |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | |
411 | 411 | return $settings; |
412 | 412 | } |
413 | -add_filter( 'getpaid_integration_settings', 'getpaid_register_userswp_settings' ); |
|
413 | +add_filter('getpaid_integration_settings', 'getpaid_register_userswp_settings'); |
|
414 | 414 | |
415 | 415 | /** |
416 | 416 | * Checks if the integration is enabled. |
@@ -419,6 +419,6 @@ discard block |
||
419 | 419 | * @return bool |
420 | 420 | */ |
421 | 421 | function getpaid_is_userswp_integration_active() { |
422 | - $enabled = wpinv_get_option( 'enable_userswp', 1 ); |
|
423 | - return defined( 'USERSWP_PLUGIN_FILE' ) && ! empty( $enabled ); |
|
422 | + $enabled = wpinv_get_option('enable_userswp', 1); |
|
423 | + return defined('USERSWP_PLUGIN_FILE') && !empty($enabled); |
|
424 | 424 | } |
@@ -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 | |
@@ -101,36 +101,36 @@ discard block |
||
101 | 101 | 'payment_form_refresh_prices' => true, |
102 | 102 | ); |
103 | 103 | |
104 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
105 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
106 | - add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
104 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
105 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
106 | + add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
107 | 107 | |
108 | - if ( $nopriv ) { |
|
109 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
110 | - add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
111 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
108 | + if ($nopriv) { |
|
109 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
110 | + add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
111 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
116 | 116 | public static function add_note() { |
117 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
117 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
118 | 118 | |
119 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
119 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
120 | 120 | die(-1); |
121 | 121 | } |
122 | 122 | |
123 | - $post_id = absint( $_POST['post_id'] ); |
|
124 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
125 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
123 | + $post_id = absint($_POST['post_id']); |
|
124 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
125 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
126 | 126 | |
127 | 127 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
128 | 128 | |
129 | - if ( $post_id > 0 ) { |
|
130 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
129 | + if ($post_id > 0) { |
|
130 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
131 | 131 | |
132 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
133 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
132 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
133 | + wpinv_get_invoice_note_line_item($note_id); |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | |
@@ -138,16 +138,16 @@ discard block |
||
138 | 138 | } |
139 | 139 | |
140 | 140 | public static function delete_note() { |
141 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
141 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
142 | 142 | |
143 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
143 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
144 | 144 | die(-1); |
145 | 145 | } |
146 | 146 | |
147 | - $note_id = (int)$_POST['note_id']; |
|
147 | + $note_id = (int) $_POST['note_id']; |
|
148 | 148 | |
149 | - if ( $note_id > 0 ) { |
|
150 | - wp_delete_comment( $note_id, true ); |
|
149 | + if ($note_id > 0) { |
|
150 | + wp_delete_comment($note_id, true); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | die(); |
@@ -165,34 +165,34 @@ discard block |
||
165 | 165 | public static function get_billing_details() { |
166 | 166 | |
167 | 167 | // Verify nonce. |
168 | - check_ajax_referer( 'wpinv-nonce' ); |
|
168 | + check_ajax_referer('wpinv-nonce'); |
|
169 | 169 | |
170 | 170 | // Can the user manage the plugin? |
171 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
171 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
172 | 172 | die(-1); |
173 | 173 | } |
174 | 174 | |
175 | 175 | // Do we have a user id? |
176 | 176 | $user_id = $_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 | // Fetch the billing details. |
183 | - $billing_details = wpinv_get_user_address( $user_id ); |
|
184 | - $billing_details = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id ); |
|
183 | + $billing_details = wpinv_get_user_address($user_id); |
|
184 | + $billing_details = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id); |
|
185 | 185 | |
186 | 186 | // unset the user id and email. |
187 | - $to_ignore = array( 'user_id', 'email' ); |
|
187 | + $to_ignore = array('user_id', 'email'); |
|
188 | 188 | |
189 | - foreach ( $to_ignore as $key ) { |
|
190 | - if ( isset( $billing_details[ $key ] ) ) { |
|
191 | - unset( $billing_details[ $key ] ); |
|
189 | + foreach ($to_ignore as $key) { |
|
190 | + if (isset($billing_details[$key])) { |
|
191 | + unset($billing_details[$key]); |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | |
195 | - wp_send_json_success( $billing_details ); |
|
195 | + wp_send_json_success($billing_details); |
|
196 | 196 | |
197 | 197 | } |
198 | 198 | |
@@ -202,47 +202,47 @@ discard block |
||
202 | 202 | public static function check_new_user_email() { |
203 | 203 | |
204 | 204 | // Verify nonce. |
205 | - check_ajax_referer( 'wpinv-nonce' ); |
|
205 | + check_ajax_referer('wpinv-nonce'); |
|
206 | 206 | |
207 | 207 | // Can the user manage the plugin? |
208 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
208 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
209 | 209 | die(-1); |
210 | 210 | } |
211 | 211 | |
212 | 212 | // We need an email address. |
213 | - if ( empty( $_GET['email'] ) ) { |
|
214 | - _e( "Provide the new user's email address", 'invoicing' ); |
|
213 | + if (empty($_GET['email'])) { |
|
214 | + _e("Provide the new user's email address", 'invoicing'); |
|
215 | 215 | exit; |
216 | 216 | } |
217 | 217 | |
218 | 218 | // Ensure the email is valid. |
219 | - $email = sanitize_text_field( $_GET['email'] ); |
|
220 | - if ( ! is_email( $email ) ) { |
|
221 | - _e( 'Invalid email address', 'invoicing' ); |
|
219 | + $email = sanitize_text_field($_GET['email']); |
|
220 | + if (!is_email($email)) { |
|
221 | + _e('Invalid email address', 'invoicing'); |
|
222 | 222 | exit; |
223 | 223 | } |
224 | 224 | |
225 | 225 | // And it does not exist. |
226 | - if ( email_exists( $email ) ) { |
|
227 | - _e( 'A user with this email address already exists', 'invoicing' ); |
|
226 | + if (email_exists($email)) { |
|
227 | + _e('A user with this email address already exists', 'invoicing'); |
|
228 | 228 | exit; |
229 | 229 | } |
230 | 230 | |
231 | - wp_send_json_success( true ); |
|
231 | + wp_send_json_success(true); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | public static function run_tool() { |
235 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
236 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
235 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
236 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
237 | 237 | die(-1); |
238 | 238 | } |
239 | 239 | |
240 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
240 | + $tool = sanitize_text_field($_POST['tool']); |
|
241 | 241 | |
242 | - do_action( 'wpinv_run_tool' ); |
|
242 | + do_action('wpinv_run_tool'); |
|
243 | 243 | |
244 | - if ( !empty( $tool ) ) { |
|
245 | - do_action( 'wpinv_tool_' . $tool ); |
|
244 | + if (!empty($tool)) { |
|
245 | + do_action('wpinv_tool_' . $tool); |
|
246 | 246 | } |
247 | 247 | } |
248 | 248 | |
@@ -252,27 +252,27 @@ discard block |
||
252 | 252 | public static function get_payment_form() { |
253 | 253 | |
254 | 254 | // Check nonce. |
255 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
255 | + check_ajax_referer('getpaid_form_nonce'); |
|
256 | 256 | |
257 | 257 | // Is the request set up correctly? |
258 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
258 | + if (empty($_GET['form']) && empty($_GET['item'])) { |
|
259 | 259 | echo aui()->alert( |
260 | 260 | array( |
261 | 261 | 'type' => 'warning', |
262 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
262 | + 'content' => __('No payment form or item provided', 'invoicing'), |
|
263 | 263 | ) |
264 | 264 | ); |
265 | 265 | exit; |
266 | 266 | } |
267 | 267 | |
268 | 268 | // Payment form or button? |
269 | - if ( ! empty( $_GET['form'] ) ) { |
|
270 | - getpaid_display_payment_form( urldecode( $_GET['form'] ) ); |
|
271 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
272 | - getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) ); |
|
269 | + if (!empty($_GET['form'])) { |
|
270 | + getpaid_display_payment_form(urldecode($_GET['form'])); |
|
271 | + } else if (!empty($_GET['invoice'])) { |
|
272 | + getpaid_display_invoice_payment_form(urldecode($_GET['invoice'])); |
|
273 | 273 | } else { |
274 | - $items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) ); |
|
275 | - getpaid_display_item_payment_form( $items ); |
|
274 | + $items = getpaid_convert_items_to_array(urldecode($_GET['item'])); |
|
275 | + getpaid_display_item_payment_form($items); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | exit; |
@@ -287,17 +287,17 @@ discard block |
||
287 | 287 | public static function payment_form() { |
288 | 288 | |
289 | 289 | // Check nonce. |
290 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
290 | + check_ajax_referer('getpaid_form_nonce'); |
|
291 | 291 | |
292 | 292 | // ... form fields... |
293 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
294 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
293 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
294 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
295 | 295 | exit; |
296 | 296 | } |
297 | 297 | |
298 | 298 | // Process the payment form. |
299 | - $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' ); |
|
300 | - $checkout = new $checkout_class( new GetPaid_Payment_Form_Submission() ); |
|
299 | + $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout'); |
|
300 | + $checkout = new $checkout_class(new GetPaid_Payment_Form_Submission()); |
|
301 | 301 | $checkout->process_checkout(); |
302 | 302 | |
303 | 303 | exit; |
@@ -310,55 +310,55 @@ discard block |
||
310 | 310 | */ |
311 | 311 | public static function get_payment_form_states_field() { |
312 | 312 | |
313 | - if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) { |
|
313 | + if (empty($_GET['country']) || empty($_GET['form'])) { |
|
314 | 314 | exit; |
315 | 315 | } |
316 | 316 | |
317 | - $elements = getpaid_get_payment_form_elements( $_GET['form'] ); |
|
317 | + $elements = getpaid_get_payment_form_elements($_GET['form']); |
|
318 | 318 | |
319 | - if ( empty( $elements ) ) { |
|
319 | + if (empty($elements)) { |
|
320 | 320 | exit; |
321 | 321 | } |
322 | 322 | |
323 | 323 | $address_fields = array(); |
324 | - foreach ( $elements as $element ) { |
|
325 | - if ( 'address' === $element['type'] ) { |
|
324 | + foreach ($elements as $element) { |
|
325 | + if ('address' === $element['type']) { |
|
326 | 326 | $address_fields = $element; |
327 | 327 | break; |
328 | 328 | } |
329 | 329 | } |
330 | 330 | |
331 | - if ( empty( $address_fields ) ) { |
|
331 | + if (empty($address_fields)) { |
|
332 | 332 | exit; |
333 | 333 | } |
334 | 334 | |
335 | - foreach ( $address_fields['fields'] as $address_field ) { |
|
335 | + foreach ($address_fields['fields'] as $address_field) { |
|
336 | 336 | |
337 | - if ( 'wpinv_state' == $address_field['name'] ) { |
|
337 | + if ('wpinv_state' == $address_field['name']) { |
|
338 | 338 | |
339 | - $wrap_class = getpaid_get_form_element_grid_class( $address_field ); |
|
340 | - $wrap_class = esc_attr( "$wrap_class getpaid-address-field-wrapper" ); |
|
341 | - $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] ); |
|
342 | - $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] ); |
|
343 | - $value = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : ''; |
|
344 | - $label = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] ); |
|
339 | + $wrap_class = getpaid_get_form_element_grid_class($address_field); |
|
340 | + $wrap_class = esc_attr("$wrap_class getpaid-address-field-wrapper"); |
|
341 | + $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']); |
|
342 | + $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']); |
|
343 | + $value = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : ''; |
|
344 | + $label = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']); |
|
345 | 345 | |
346 | - if ( ! empty( $address_field['required'] ) ) { |
|
346 | + if (!empty($address_field['required'])) { |
|
347 | 347 | $label .= "<span class='text-danger'> *</span>"; |
348 | 348 | } |
349 | 349 | |
350 | - $html = getpaid_get_states_select_markup ( |
|
351 | - sanitize_text_field( $_GET['country'] ), |
|
350 | + $html = getpaid_get_states_select_markup( |
|
351 | + sanitize_text_field($_GET['country']), |
|
352 | 352 | $value, |
353 | 353 | $placeholder, |
354 | 354 | $label, |
355 | 355 | $description, |
356 | - ! empty( $address_field['required'] ), |
|
356 | + !empty($address_field['required']), |
|
357 | 357 | $wrap_class, |
358 | - wpinv_clean( $_GET['name'] ) |
|
358 | + wpinv_clean($_GET['name']) |
|
359 | 359 | ); |
360 | 360 | |
361 | - wp_send_json_success( $html ); |
|
361 | + wp_send_json_success($html); |
|
362 | 362 | exit; |
363 | 363 | |
364 | 364 | } |
@@ -374,56 +374,56 @@ discard block |
||
374 | 374 | public static function recalculate_invoice_totals() { |
375 | 375 | |
376 | 376 | // Verify nonce. |
377 | - check_ajax_referer( 'wpinv-nonce' ); |
|
377 | + check_ajax_referer('wpinv-nonce'); |
|
378 | 378 | |
379 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
379 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
380 | 380 | exit; |
381 | 381 | } |
382 | 382 | |
383 | 383 | // We need an invoice. |
384 | - if ( empty( $_POST['post_id'] ) ) { |
|
384 | + if (empty($_POST['post_id'])) { |
|
385 | 385 | exit; |
386 | 386 | } |
387 | 387 | |
388 | 388 | // Fetch the invoice. |
389 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
389 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
390 | 390 | |
391 | 391 | // Ensure it exists. |
392 | - if ( ! $invoice->get_id() ) { |
|
392 | + if (!$invoice->get_id()) { |
|
393 | 393 | exit; |
394 | 394 | } |
395 | 395 | |
396 | 396 | // Maybe set the country, state, currency. |
397 | - foreach ( array( 'country', 'state', 'currency' ) as $key ) { |
|
398 | - if ( isset( $_POST[ $key ] ) ) { |
|
397 | + foreach (array('country', 'state', 'currency') as $key) { |
|
398 | + if (isset($_POST[$key])) { |
|
399 | 399 | $method = "set_$key"; |
400 | - $invoice->$method( sanitize_text_field( $_POST[ $key ] ) ); |
|
400 | + $invoice->$method(sanitize_text_field($_POST[$key])); |
|
401 | 401 | } |
402 | 402 | } |
403 | 403 | |
404 | 404 | // Maybe disable taxes. |
405 | - $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) ); |
|
405 | + $invoice->set_disable_taxes(!empty($_POST['taxes'])); |
|
406 | 406 | |
407 | 407 | // Recalculate totals. |
408 | 408 | $invoice->recalculate_total(); |
409 | 409 | |
410 | - $total = wpinv_price( $invoice->get_total(), $invoice->get_currency() ); |
|
410 | + $total = wpinv_price($invoice->get_total(), $invoice->get_currency()); |
|
411 | 411 | |
412 | - if ( $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) { |
|
413 | - $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() ); |
|
414 | - $total .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>'; |
|
412 | + if ($invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) { |
|
413 | + $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency()); |
|
414 | + $total .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>'; |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | $totals = array( |
418 | - 'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ), |
|
419 | - 'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
|
420 | - 'tax' => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ), |
|
418 | + 'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()), |
|
419 | + 'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()), |
|
420 | + 'tax' => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()), |
|
421 | 421 | 'total' => $total, |
422 | 422 | ); |
423 | 423 | |
424 | - $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice ); |
|
424 | + $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice); |
|
425 | 425 | |
426 | - wp_send_json_success( compact( 'totals' ) ); |
|
426 | + wp_send_json_success(compact('totals')); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | /** |
@@ -432,33 +432,33 @@ discard block |
||
432 | 432 | public static function get_invoice_items() { |
433 | 433 | |
434 | 434 | // Verify nonce. |
435 | - check_ajax_referer( 'wpinv-nonce' ); |
|
435 | + check_ajax_referer('wpinv-nonce'); |
|
436 | 436 | |
437 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
437 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
438 | 438 | exit; |
439 | 439 | } |
440 | 440 | |
441 | 441 | // We need an invoice and items. |
442 | - if ( empty( $_POST['post_id'] ) ) { |
|
442 | + if (empty($_POST['post_id'])) { |
|
443 | 443 | exit; |
444 | 444 | } |
445 | 445 | |
446 | 446 | // Fetch the invoice. |
447 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
447 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
448 | 448 | |
449 | 449 | // Ensure it exists. |
450 | - if ( ! $invoice->get_id() ) { |
|
450 | + if (!$invoice->get_id()) { |
|
451 | 451 | exit; |
452 | 452 | } |
453 | 453 | |
454 | 454 | // Return an array of invoice items. |
455 | 455 | $items = array(); |
456 | 456 | |
457 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
458 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency(), $invoice->is_renewal() ); |
|
457 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
458 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal()); |
|
459 | 459 | } |
460 | 460 | |
461 | - wp_send_json_success( compact( 'items' ) ); |
|
461 | + wp_send_json_success(compact('items')); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | /** |
@@ -467,50 +467,50 @@ discard block |
||
467 | 467 | public static function edit_invoice_item() { |
468 | 468 | |
469 | 469 | // Verify nonce. |
470 | - check_ajax_referer( 'wpinv-nonce' ); |
|
470 | + check_ajax_referer('wpinv-nonce'); |
|
471 | 471 | |
472 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
472 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
473 | 473 | exit; |
474 | 474 | } |
475 | 475 | |
476 | 476 | // We need an invoice and item details. |
477 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) { |
|
477 | + if (empty($_POST['post_id']) || empty($_POST['data'])) { |
|
478 | 478 | exit; |
479 | 479 | } |
480 | 480 | |
481 | 481 | // Fetch the invoice. |
482 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
482 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
483 | 483 | |
484 | 484 | // Ensure it exists and its not been paid for. |
485 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
485 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
486 | 486 | exit; |
487 | 487 | } |
488 | 488 | |
489 | 489 | // Format the data. |
490 | - $data = wp_list_pluck( $_POST['data'], 'value', 'field' ); |
|
490 | + $data = wp_list_pluck($_POST['data'], 'value', 'field'); |
|
491 | 491 | |
492 | 492 | // Ensure that we have an item id. |
493 | - if ( empty( $data['id'] ) ) { |
|
493 | + if (empty($data['id'])) { |
|
494 | 494 | exit; |
495 | 495 | } |
496 | 496 | |
497 | 497 | // Abort if the invoice does not have the specified item. |
498 | - $item = $invoice->get_item( (int) $data['id'] ); |
|
498 | + $item = $invoice->get_item((int) $data['id']); |
|
499 | 499 | |
500 | - if ( empty( $item ) ) { |
|
500 | + if (empty($item)) { |
|
501 | 501 | exit; |
502 | 502 | } |
503 | 503 | |
504 | 504 | // Update the item. |
505 | - $item->set_price( $data['price'] ); |
|
506 | - $item->set_name( $data['name'] ); |
|
507 | - $item->set_description( $data['description'] ); |
|
508 | - $item->set_quantity( $data['quantity'] ); |
|
505 | + $item->set_price($data['price']); |
|
506 | + $item->set_name($data['name']); |
|
507 | + $item->set_description($data['description']); |
|
508 | + $item->set_quantity($data['quantity']); |
|
509 | 509 | |
510 | 510 | // Add it to the invoice. |
511 | - $error = $invoice->add_item( $item ); |
|
511 | + $error = $invoice->add_item($item); |
|
512 | 512 | $alert = false; |
513 | - if ( is_wp_error( $error ) ) { |
|
513 | + if (is_wp_error($error)) { |
|
514 | 514 | $alert = $error->get_error_message(); |
515 | 515 | } |
516 | 516 | |
@@ -523,11 +523,11 @@ discard block |
||
523 | 523 | // Return an array of invoice items. |
524 | 524 | $items = array(); |
525 | 525 | |
526 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
527 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
526 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
527 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
528 | 528 | } |
529 | 529 | |
530 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
530 | + wp_send_json_success(compact('items', 'alert')); |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | /** |
@@ -536,33 +536,33 @@ discard block |
||
536 | 536 | public static function remove_invoice_item() { |
537 | 537 | |
538 | 538 | // Verify nonce. |
539 | - check_ajax_referer( 'wpinv-nonce' ); |
|
539 | + check_ajax_referer('wpinv-nonce'); |
|
540 | 540 | |
541 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
541 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
542 | 542 | exit; |
543 | 543 | } |
544 | 544 | |
545 | 545 | // We need an invoice and an item. |
546 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
546 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
547 | 547 | exit; |
548 | 548 | } |
549 | 549 | |
550 | 550 | // Fetch the invoice. |
551 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
551 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
552 | 552 | |
553 | 553 | // Ensure it exists and its not been paid for. |
554 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
554 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
555 | 555 | exit; |
556 | 556 | } |
557 | 557 | |
558 | 558 | // Abort if the invoice does not have the specified item. |
559 | - $item = $invoice->get_item( (int) $_POST['item_id'] ); |
|
559 | + $item = $invoice->get_item((int) $_POST['item_id']); |
|
560 | 560 | |
561 | - if ( empty( $item ) ) { |
|
561 | + if (empty($item)) { |
|
562 | 562 | exit; |
563 | 563 | } |
564 | 564 | |
565 | - $invoice->remove_item( (int) $_POST['item_id'] ); |
|
565 | + $invoice->remove_item((int) $_POST['item_id']); |
|
566 | 566 | |
567 | 567 | // Update totals. |
568 | 568 | $invoice->recalculate_total(); |
@@ -573,11 +573,11 @@ discard block |
||
573 | 573 | // Return an array of invoice items. |
574 | 574 | $items = array(); |
575 | 575 | |
576 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
577 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
576 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
577 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
578 | 578 | } |
579 | 579 | |
580 | - wp_send_json_success( compact( 'items' ) ); |
|
580 | + wp_send_json_success(compact('items')); |
|
581 | 581 | } |
582 | 582 | |
583 | 583 | /** |
@@ -586,39 +586,39 @@ discard block |
||
586 | 586 | public static function add_invoice_items() { |
587 | 587 | |
588 | 588 | // Verify nonce. |
589 | - check_ajax_referer( 'wpinv-nonce' ); |
|
589 | + check_ajax_referer('wpinv-nonce'); |
|
590 | 590 | |
591 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
591 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
592 | 592 | exit; |
593 | 593 | } |
594 | 594 | |
595 | 595 | // We need an invoice and items. |
596 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) { |
|
596 | + if (empty($_POST['post_id']) || empty($_POST['items'])) { |
|
597 | 597 | exit; |
598 | 598 | } |
599 | 599 | |
600 | 600 | // Fetch the invoice. |
601 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
601 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
602 | 602 | $alert = false; |
603 | 603 | |
604 | 604 | // Ensure it exists and its not been paid for. |
605 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
605 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
606 | 606 | exit; |
607 | 607 | } |
608 | 608 | |
609 | 609 | // Add the items. |
610 | - foreach ( $_POST['items'] as $data ) { |
|
610 | + foreach ($_POST['items'] as $data) { |
|
611 | 611 | |
612 | - $item = new GetPaid_Form_Item( $data[ 'id' ] ); |
|
612 | + $item = new GetPaid_Form_Item($data['id']); |
|
613 | 613 | |
614 | - if ( is_numeric( $data[ 'qty' ] ) && (float) $data[ 'qty' ] > 0 ) { |
|
615 | - $item->set_quantity( $data[ 'qty' ] ); |
|
614 | + if (is_numeric($data['qty']) && (float) $data['qty'] > 0) { |
|
615 | + $item->set_quantity($data['qty']); |
|
616 | 616 | } |
617 | 617 | |
618 | - if ( $item->get_id() > 0 ) { |
|
619 | - $error = $invoice->add_item( $item ); |
|
618 | + if ($item->get_id() > 0) { |
|
619 | + $error = $invoice->add_item($item); |
|
620 | 620 | |
621 | - if ( is_wp_error( $error ) ) { |
|
621 | + if (is_wp_error($error)) { |
|
622 | 622 | $alert = $error->get_error_message(); |
623 | 623 | } |
624 | 624 | |
@@ -633,11 +633,11 @@ discard block |
||
633 | 633 | // Return an array of invoice items. |
634 | 634 | $items = array(); |
635 | 635 | |
636 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
637 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
636 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
637 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
638 | 638 | } |
639 | 639 | |
640 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
640 | + wp_send_json_success(compact('items', 'alert')); |
|
641 | 641 | } |
642 | 642 | |
643 | 643 | /** |
@@ -646,15 +646,15 @@ discard block |
||
646 | 646 | public static function get_invoicing_items() { |
647 | 647 | |
648 | 648 | // Verify nonce. |
649 | - check_ajax_referer( 'wpinv-nonce' ); |
|
649 | + check_ajax_referer('wpinv-nonce'); |
|
650 | 650 | |
651 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
651 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
652 | 652 | exit; |
653 | 653 | } |
654 | 654 | |
655 | 655 | // We need a search term. |
656 | - if ( empty( $_GET['search'] ) ) { |
|
657 | - wp_send_json_success( array() ); |
|
656 | + if (empty($_GET['search'])) { |
|
657 | + wp_send_json_success(array()); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | // Retrieve items. |
@@ -663,8 +663,8 @@ discard block |
||
663 | 663 | 'orderby' => 'title', |
664 | 664 | 'order' => 'ASC', |
665 | 665 | 'posts_per_page' => -1, |
666 | - 'post_status' => array( 'publish' ), |
|
667 | - 's' => trim( $_GET['search'] ), |
|
666 | + 'post_status' => array('publish'), |
|
667 | + 's' => trim($_GET['search']), |
|
668 | 668 | 'meta_query' => array( |
669 | 669 | array( |
670 | 670 | 'key' => '_wpinv_type', |
@@ -674,22 +674,22 @@ discard block |
||
674 | 674 | ) |
675 | 675 | ); |
676 | 676 | |
677 | - $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) ); |
|
677 | + $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args)); |
|
678 | 678 | $data = array(); |
679 | 679 | |
680 | 680 | |
681 | - $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) ); |
|
681 | + $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id'])); |
|
682 | 682 | |
683 | - foreach ( $items as $item ) { |
|
684 | - $item = new GetPaid_Form_Item( $item ); |
|
683 | + foreach ($items as $item) { |
|
684 | + $item = new GetPaid_Form_Item($item); |
|
685 | 685 | $data[] = array( |
686 | 686 | 'id' => (int) $item->get_id(), |
687 | - 'text' => strip_tags( $item->get_name() ), |
|
688 | - 'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '', |
|
687 | + 'text' => strip_tags($item->get_name()), |
|
688 | + 'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '', |
|
689 | 689 | ); |
690 | 690 | } |
691 | 691 | |
692 | - wp_send_json_success( $data ); |
|
692 | + wp_send_json_success($data); |
|
693 | 693 | |
694 | 694 | } |
695 | 695 | |
@@ -699,28 +699,28 @@ discard block |
||
699 | 699 | public static function get_aui_states_field() { |
700 | 700 | |
701 | 701 | // Verify nonce. |
702 | - check_ajax_referer( 'wpinv-nonce' ); |
|
702 | + check_ajax_referer('wpinv-nonce'); |
|
703 | 703 | |
704 | 704 | // We need a country. |
705 | - if ( empty( $_GET['country'] ) ) { |
|
705 | + if (empty($_GET['country'])) { |
|
706 | 706 | exit; |
707 | 707 | } |
708 | 708 | |
709 | - $states = wpinv_get_country_states( sanitize_text_field( $_GET['country'] ) ); |
|
710 | - $state = isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : wpinv_get_default_state(); |
|
711 | - $name = isset( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : 'wpinv_state'; |
|
712 | - $class = isset( $_GET['class'] ) ? sanitize_text_field( $_GET['class'] ) : 'form-control-sm'; |
|
709 | + $states = wpinv_get_country_states(sanitize_text_field($_GET['country'])); |
|
710 | + $state = isset($_GET['state']) ? sanitize_text_field($_GET['state']) : wpinv_get_default_state(); |
|
711 | + $name = isset($_GET['name']) ? sanitize_text_field($_GET['name']) : 'wpinv_state'; |
|
712 | + $class = isset($_GET['class']) ? sanitize_text_field($_GET['class']) : 'form-control-sm'; |
|
713 | 713 | |
714 | - if ( empty( $states ) ) { |
|
714 | + if (empty($states)) { |
|
715 | 715 | |
716 | 716 | $html = aui()->input( |
717 | 717 | array( |
718 | 718 | 'type' => 'text', |
719 | 719 | 'id' => 'wpinv_state', |
720 | 720 | 'name' => $name, |
721 | - 'label' => __( 'State', 'invoicing' ), |
|
721 | + 'label' => __('State', 'invoicing'), |
|
722 | 722 | 'label_type' => 'vertical', |
723 | - 'placeholder' => __( 'State', 'invoicing' ), |
|
723 | + 'placeholder' => __('State', 'invoicing'), |
|
724 | 724 | 'class' => $class, |
725 | 725 | 'value' => $state, |
726 | 726 | ) |
@@ -732,9 +732,9 @@ discard block |
||
732 | 732 | array( |
733 | 733 | 'id' => 'wpinv_state', |
734 | 734 | 'name' => $name, |
735 | - 'label' => __( 'State', 'invoicing' ), |
|
735 | + 'label' => __('State', 'invoicing'), |
|
736 | 736 | 'label_type' => 'vertical', |
737 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
737 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
738 | 738 | 'class' => $class, |
739 | 739 | 'value' => $state, |
740 | 740 | 'options' => $states, |
@@ -748,7 +748,7 @@ discard block |
||
748 | 748 | wp_send_json_success( |
749 | 749 | array( |
750 | 750 | 'html' => $html, |
751 | - 'select' => ! empty ( $states ) |
|
751 | + 'select' => !empty ($states) |
|
752 | 752 | ) |
753 | 753 | ); |
754 | 754 | |
@@ -762,11 +762,11 @@ discard block |
||
762 | 762 | public static function payment_form_refresh_prices() { |
763 | 763 | |
764 | 764 | // Check nonce. |
765 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
765 | + check_ajax_referer('getpaid_form_nonce'); |
|
766 | 766 | |
767 | 767 | // ... form fields... |
768 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
769 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
768 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
769 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
770 | 770 | exit; |
771 | 771 | } |
772 | 772 | |
@@ -774,18 +774,18 @@ discard block |
||
774 | 774 | $submission = new GetPaid_Payment_Form_Submission(); |
775 | 775 | |
776 | 776 | // Do we have an error? |
777 | - if ( ! empty( $submission->last_error ) ) { |
|
777 | + if (!empty($submission->last_error)) { |
|
778 | 778 | echo $submission->last_error; |
779 | 779 | exit; |
780 | 780 | } |
781 | 781 | |
782 | 782 | // Prepare the response. |
783 | - $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission ); |
|
783 | + $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission); |
|
784 | 784 | |
785 | 785 | // Filter the response. |
786 | - $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission ); |
|
786 | + $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission); |
|
787 | 787 | |
788 | - wp_send_json_success( $response ); |
|
788 | + wp_send_json_success($response); |
|
789 | 789 | } |
790 | 790 | |
791 | 791 | } |
@@ -14,536 +14,536 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class WPInv_Plugin { |
16 | 16 | |
17 | - /** |
|
18 | - * GetPaid version. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $version; |
|
23 | - |
|
24 | - /** |
|
25 | - * Data container. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * Form elements instance. |
|
33 | - * |
|
34 | - * @var WPInv_Payment_Form_Elements |
|
35 | - */ |
|
36 | - public $form_elements; |
|
37 | - |
|
38 | - /** |
|
39 | - * @param array An array of payment gateways. |
|
40 | - */ |
|
41 | - public $gateways; |
|
42 | - |
|
43 | - /** |
|
44 | - * Class constructor. |
|
45 | - */ |
|
46 | - public function __construct() { |
|
47 | - $this->define_constants(); |
|
48 | - $this->includes(); |
|
49 | - $this->init_hooks(); |
|
50 | - $this->set_properties(); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Sets a custom data property. |
|
55 | - * |
|
56 | - * @param string $prop The prop to set. |
|
57 | - * @param mixed $value The value to retrieve. |
|
58 | - */ |
|
59 | - public function set( $prop, $value ) { |
|
60 | - $this->data[ $prop ] = $value; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Gets a custom data property. |
|
65 | - * |
|
66 | - * @param string $prop The prop to set. |
|
67 | - * @return mixed The value. |
|
68 | - */ |
|
69 | - public function get( $prop ) { |
|
70 | - |
|
71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
72 | - return $this->data[ $prop ]; |
|
73 | - } |
|
74 | - |
|
75 | - return null; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Define class properties. |
|
80 | - */ |
|
81 | - public function set_properties() { |
|
82 | - |
|
83 | - // Sessions. |
|
84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
86 | - $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
87 | - |
|
88 | - // Init other objects. |
|
89 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | - $this->set( 'notes', new WPInv_Notes() ); |
|
91 | - $this->set( 'api', new WPInv_API() ); |
|
92 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | - $this->set( 'template', new GetPaid_Template() ); |
|
94 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Define plugin constants. |
|
106 | - */ |
|
107 | - public function define_constants() { |
|
108 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
110 | - $this->version = WPINV_VERSION; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Hook into actions and filters. |
|
115 | - * |
|
116 | - * @since 1.0.19 |
|
117 | - */ |
|
118 | - protected function init_hooks() { |
|
119 | - /* Internationalize the text strings used. */ |
|
120 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
121 | - |
|
122 | - // Init the plugin after WordPress inits. |
|
123 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
127 | - |
|
128 | - if ( class_exists( 'BuddyPress' ) ) { |
|
129 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
130 | - } |
|
131 | - |
|
132 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
133 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
134 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
135 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
136 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
137 | - |
|
138 | - // Fires after registering actions. |
|
139 | - do_action( 'wpinv_actions', $this ); |
|
140 | - do_action( 'getpaid_actions', $this ); |
|
141 | - |
|
142 | - } |
|
143 | - |
|
144 | - public function plugins_loaded() { |
|
145 | - /* Internationalize the text strings used. */ |
|
146 | - $this->load_textdomain(); |
|
147 | - |
|
148 | - do_action( 'wpinv_loaded' ); |
|
149 | - |
|
150 | - // Fix oxygen page builder conflict |
|
151 | - if ( function_exists( 'ct_css_output' ) ) { |
|
152 | - wpinv_oxygen_fix_conflict(); |
|
153 | - } |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Load the translation of the plugin. |
|
158 | - * |
|
159 | - * @since 1.0 |
|
160 | - */ |
|
161 | - public function load_textdomain( $locale = NULL ) { |
|
162 | - if ( empty( $locale ) ) { |
|
163 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
164 | - } |
|
165 | - |
|
166 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
167 | - |
|
168 | - unload_textdomain( 'invoicing' ); |
|
169 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
170 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
171 | - |
|
172 | - /** |
|
173 | - * Define language constants. |
|
174 | - */ |
|
175 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Include required core files used in admin and on the frontend. |
|
180 | - */ |
|
181 | - public function includes() { |
|
182 | - |
|
183 | - // Start with the settings. |
|
184 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
185 | - |
|
186 | - // Packages/libraries. |
|
187 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
188 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
189 | - |
|
190 | - // Load functions. |
|
191 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
192 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
193 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
194 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
195 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
198 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
199 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' ); |
|
205 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
206 | - |
|
207 | - // Register autoloader. |
|
208 | - try { |
|
209 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
210 | - } catch ( Exception $e ) { |
|
211 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
212 | - } |
|
213 | - |
|
214 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
215 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
216 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
217 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
218 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
219 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
220 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
221 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
222 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
234 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
235 | - |
|
236 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
237 | - GetPaid_Post_Types_Admin::init(); |
|
238 | - |
|
239 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
240 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
241 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
242 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
243 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
244 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
245 | - // load the user class only on the users.php page |
|
246 | - global $pagenow; |
|
247 | - if($pagenow=='users.php'){ |
|
248 | - new WPInv_Admin_Users(); |
|
249 | - } |
|
250 | - } |
|
251 | - |
|
252 | - // Register cli commands |
|
253 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
254 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
255 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
256 | - } |
|
257 | - |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Class autoloader |
|
262 | - * |
|
263 | - * @param string $class_name The name of the class to load. |
|
264 | - * @access public |
|
265 | - * @since 1.0.19 |
|
266 | - * @return void |
|
267 | - */ |
|
268 | - public function autoload( $class_name ) { |
|
269 | - |
|
270 | - // Normalize the class name... |
|
271 | - $class_name = strtolower( $class_name ); |
|
272 | - |
|
273 | - // ... and make sure it is our class. |
|
274 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
275 | - return; |
|
276 | - } |
|
277 | - |
|
278 | - // Next, prepare the file name from the class. |
|
279 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
280 | - |
|
281 | - // Base path of the classes. |
|
282 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
283 | - |
|
284 | - // And an array of possible locations in order of importance. |
|
285 | - $locations = array( |
|
286 | - "$plugin_path/includes", |
|
287 | - "$plugin_path/includes/data-stores", |
|
288 | - "$plugin_path/includes/gateways", |
|
289 | - "$plugin_path/includes/payments", |
|
290 | - "$plugin_path/includes/geolocation", |
|
291 | - "$plugin_path/includes/reports", |
|
292 | - "$plugin_path/includes/api", |
|
293 | - "$plugin_path/includes/admin", |
|
294 | - "$plugin_path/includes/admin/meta-boxes", |
|
295 | - ); |
|
296 | - |
|
297 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
298 | - |
|
299 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
300 | - include trailingslashit( $location ) . $file_name; |
|
301 | - break; |
|
302 | - } |
|
303 | - |
|
304 | - } |
|
305 | - |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Inits hooks etc. |
|
310 | - */ |
|
311 | - public function init() { |
|
312 | - |
|
313 | - // Fires before getpaid inits. |
|
314 | - do_action( 'before_getpaid_init', $this ); |
|
315 | - |
|
316 | - // Maybe upgrade. |
|
317 | - $this->maybe_upgrade_database(); |
|
318 | - |
|
319 | - // Load default gateways. |
|
320 | - $gateways = apply_filters( |
|
321 | - 'getpaid_default_gateways', |
|
322 | - array( |
|
323 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
324 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
325 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
326 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
327 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
328 | - ) |
|
329 | - ); |
|
330 | - |
|
331 | - foreach ( $gateways as $id => $class ) { |
|
332 | - $this->gateways[ $id ] = new $class(); |
|
333 | - } |
|
334 | - |
|
335 | - // Fires after getpaid inits. |
|
336 | - do_action( 'getpaid_init', $this ); |
|
337 | - |
|
338 | - } |
|
339 | - |
|
340 | - /** |
|
341 | - * Checks if this is an IPN request and processes it. |
|
342 | - */ |
|
343 | - public function maybe_process_ipn() { |
|
344 | - |
|
345 | - // Ensure that this is an IPN request. |
|
346 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
347 | - return; |
|
348 | - } |
|
349 | - |
|
350 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
351 | - |
|
352 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
353 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
354 | - exit; |
|
355 | - |
|
356 | - } |
|
357 | - |
|
358 | - public function enqueue_scripts() { |
|
359 | - |
|
360 | - // Fires before adding scripts. |
|
361 | - do_action( 'getpaid_enqueue_scripts' ); |
|
362 | - |
|
363 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
364 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
365 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
366 | - |
|
367 | - $localize = array(); |
|
368 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
369 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
370 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
371 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
372 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
373 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
374 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
375 | - |
|
376 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
377 | - |
|
378 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
379 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
380 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
381 | - } |
|
382 | - |
|
383 | - public function wpinv_actions() { |
|
384 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
385 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
386 | - } |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
17 | + /** |
|
18 | + * GetPaid version. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $version; |
|
23 | + |
|
24 | + /** |
|
25 | + * Data container. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * Form elements instance. |
|
33 | + * |
|
34 | + * @var WPInv_Payment_Form_Elements |
|
35 | + */ |
|
36 | + public $form_elements; |
|
37 | + |
|
38 | + /** |
|
39 | + * @param array An array of payment gateways. |
|
40 | + */ |
|
41 | + public $gateways; |
|
42 | + |
|
43 | + /** |
|
44 | + * Class constructor. |
|
45 | + */ |
|
46 | + public function __construct() { |
|
47 | + $this->define_constants(); |
|
48 | + $this->includes(); |
|
49 | + $this->init_hooks(); |
|
50 | + $this->set_properties(); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Sets a custom data property. |
|
55 | + * |
|
56 | + * @param string $prop The prop to set. |
|
57 | + * @param mixed $value The value to retrieve. |
|
58 | + */ |
|
59 | + public function set( $prop, $value ) { |
|
60 | + $this->data[ $prop ] = $value; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Gets a custom data property. |
|
65 | + * |
|
66 | + * @param string $prop The prop to set. |
|
67 | + * @return mixed The value. |
|
68 | + */ |
|
69 | + public function get( $prop ) { |
|
70 | + |
|
71 | + if ( isset( $this->data[ $prop ] ) ) { |
|
72 | + return $this->data[ $prop ]; |
|
73 | + } |
|
74 | + |
|
75 | + return null; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Define class properties. |
|
80 | + */ |
|
81 | + public function set_properties() { |
|
82 | + |
|
83 | + // Sessions. |
|
84 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
86 | + $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
87 | + |
|
88 | + // Init other objects. |
|
89 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | + $this->set( 'notes', new WPInv_Notes() ); |
|
91 | + $this->set( 'api', new WPInv_API() ); |
|
92 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | + $this->set( 'template', new GetPaid_Template() ); |
|
94 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Define plugin constants. |
|
106 | + */ |
|
107 | + public function define_constants() { |
|
108 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
110 | + $this->version = WPINV_VERSION; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Hook into actions and filters. |
|
115 | + * |
|
116 | + * @since 1.0.19 |
|
117 | + */ |
|
118 | + protected function init_hooks() { |
|
119 | + /* Internationalize the text strings used. */ |
|
120 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
121 | + |
|
122 | + // Init the plugin after WordPress inits. |
|
123 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
127 | + |
|
128 | + if ( class_exists( 'BuddyPress' ) ) { |
|
129 | + add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
130 | + } |
|
131 | + |
|
132 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
133 | + add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
134 | + add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
135 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
136 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
137 | + |
|
138 | + // Fires after registering actions. |
|
139 | + do_action( 'wpinv_actions', $this ); |
|
140 | + do_action( 'getpaid_actions', $this ); |
|
141 | + |
|
142 | + } |
|
143 | + |
|
144 | + public function plugins_loaded() { |
|
145 | + /* Internationalize the text strings used. */ |
|
146 | + $this->load_textdomain(); |
|
147 | + |
|
148 | + do_action( 'wpinv_loaded' ); |
|
149 | + |
|
150 | + // Fix oxygen page builder conflict |
|
151 | + if ( function_exists( 'ct_css_output' ) ) { |
|
152 | + wpinv_oxygen_fix_conflict(); |
|
153 | + } |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Load the translation of the plugin. |
|
158 | + * |
|
159 | + * @since 1.0 |
|
160 | + */ |
|
161 | + public function load_textdomain( $locale = NULL ) { |
|
162 | + if ( empty( $locale ) ) { |
|
163 | + $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
164 | + } |
|
165 | + |
|
166 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
167 | + |
|
168 | + unload_textdomain( 'invoicing' ); |
|
169 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
170 | + load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
171 | + |
|
172 | + /** |
|
173 | + * Define language constants. |
|
174 | + */ |
|
175 | + require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Include required core files used in admin and on the frontend. |
|
180 | + */ |
|
181 | + public function includes() { |
|
182 | + |
|
183 | + // Start with the settings. |
|
184 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
185 | + |
|
186 | + // Packages/libraries. |
|
187 | + require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
188 | + require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
189 | + |
|
190 | + // Load functions. |
|
191 | + require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
192 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
193 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
194 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
195 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
196 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
197 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
198 | + require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
199 | + require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
200 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
201 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
202 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
203 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
204 | + require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' ); |
|
205 | + require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
206 | + |
|
207 | + // Register autoloader. |
|
208 | + try { |
|
209 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
210 | + } catch ( Exception $e ) { |
|
211 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
212 | + } |
|
213 | + |
|
214 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
215 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
216 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
217 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
218 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
219 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
220 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
221 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
222 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
223 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
224 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
225 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
226 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
227 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
228 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
229 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
230 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
231 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
232 | + require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
233 | + require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
234 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
235 | + |
|
236 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
237 | + GetPaid_Post_Types_Admin::init(); |
|
238 | + |
|
239 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
240 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
241 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
242 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
243 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
244 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
245 | + // load the user class only on the users.php page |
|
246 | + global $pagenow; |
|
247 | + if($pagenow=='users.php'){ |
|
248 | + new WPInv_Admin_Users(); |
|
249 | + } |
|
250 | + } |
|
251 | + |
|
252 | + // Register cli commands |
|
253 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
254 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
255 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
256 | + } |
|
257 | + |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Class autoloader |
|
262 | + * |
|
263 | + * @param string $class_name The name of the class to load. |
|
264 | + * @access public |
|
265 | + * @since 1.0.19 |
|
266 | + * @return void |
|
267 | + */ |
|
268 | + public function autoload( $class_name ) { |
|
269 | + |
|
270 | + // Normalize the class name... |
|
271 | + $class_name = strtolower( $class_name ); |
|
272 | + |
|
273 | + // ... and make sure it is our class. |
|
274 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
275 | + return; |
|
276 | + } |
|
277 | + |
|
278 | + // Next, prepare the file name from the class. |
|
279 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
280 | + |
|
281 | + // Base path of the classes. |
|
282 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
283 | + |
|
284 | + // And an array of possible locations in order of importance. |
|
285 | + $locations = array( |
|
286 | + "$plugin_path/includes", |
|
287 | + "$plugin_path/includes/data-stores", |
|
288 | + "$plugin_path/includes/gateways", |
|
289 | + "$plugin_path/includes/payments", |
|
290 | + "$plugin_path/includes/geolocation", |
|
291 | + "$plugin_path/includes/reports", |
|
292 | + "$plugin_path/includes/api", |
|
293 | + "$plugin_path/includes/admin", |
|
294 | + "$plugin_path/includes/admin/meta-boxes", |
|
295 | + ); |
|
296 | + |
|
297 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
298 | + |
|
299 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
300 | + include trailingslashit( $location ) . $file_name; |
|
301 | + break; |
|
302 | + } |
|
303 | + |
|
304 | + } |
|
305 | + |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Inits hooks etc. |
|
310 | + */ |
|
311 | + public function init() { |
|
312 | + |
|
313 | + // Fires before getpaid inits. |
|
314 | + do_action( 'before_getpaid_init', $this ); |
|
315 | + |
|
316 | + // Maybe upgrade. |
|
317 | + $this->maybe_upgrade_database(); |
|
318 | + |
|
319 | + // Load default gateways. |
|
320 | + $gateways = apply_filters( |
|
321 | + 'getpaid_default_gateways', |
|
322 | + array( |
|
323 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
324 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
325 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
326 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
327 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
328 | + ) |
|
329 | + ); |
|
330 | + |
|
331 | + foreach ( $gateways as $id => $class ) { |
|
332 | + $this->gateways[ $id ] = new $class(); |
|
333 | + } |
|
334 | + |
|
335 | + // Fires after getpaid inits. |
|
336 | + do_action( 'getpaid_init', $this ); |
|
337 | + |
|
338 | + } |
|
339 | + |
|
340 | + /** |
|
341 | + * Checks if this is an IPN request and processes it. |
|
342 | + */ |
|
343 | + public function maybe_process_ipn() { |
|
344 | + |
|
345 | + // Ensure that this is an IPN request. |
|
346 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
347 | + return; |
|
348 | + } |
|
349 | + |
|
350 | + $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
351 | + |
|
352 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
353 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
354 | + exit; |
|
355 | + |
|
356 | + } |
|
357 | + |
|
358 | + public function enqueue_scripts() { |
|
359 | + |
|
360 | + // Fires before adding scripts. |
|
361 | + do_action( 'getpaid_enqueue_scripts' ); |
|
362 | + |
|
363 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
364 | + wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
365 | + wp_enqueue_style( 'wpinv_front_style' ); |
|
366 | + |
|
367 | + $localize = array(); |
|
368 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
369 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
370 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
371 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
372 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
373 | + $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
374 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
375 | + |
|
376 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
377 | + |
|
378 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
379 | + wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
380 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
381 | + } |
|
382 | + |
|
383 | + public function wpinv_actions() { |
|
384 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
385 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
386 | + } |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | 390 | * Fires an action after verifying that a user can fire them. |
391 | - * |
|
392 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
393 | - * current user owns the invoice/subscription. |
|
391 | + * |
|
392 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
393 | + * current user owns the invoice/subscription. |
|
394 | 394 | */ |
395 | 395 | public function maybe_do_authenticated_action() { |
396 | 396 | |
397 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
397 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
398 | + |
|
399 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
400 | + $data = wp_unslash( $_REQUEST ); |
|
401 | + if ( is_user_logged_in() ) { |
|
402 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
403 | + } |
|
398 | 404 | |
399 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
400 | - $data = wp_unslash( $_REQUEST ); |
|
401 | - if ( is_user_logged_in() ) { |
|
402 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
403 | - } |
|
405 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
406 | + |
|
407 | + } |
|
408 | + |
|
409 | + } |
|
404 | 410 | |
405 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
411 | + public function pre_get_posts( $wp_query ) { |
|
406 | 412 | |
407 | - } |
|
413 | + if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
414 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
415 | + } |
|
408 | 416 | |
417 | + return $wp_query; |
|
409 | 418 | } |
410 | 419 | |
411 | - public function pre_get_posts( $wp_query ) { |
|
412 | - |
|
413 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
414 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
415 | - } |
|
416 | - |
|
417 | - return $wp_query; |
|
418 | - } |
|
419 | - |
|
420 | - public function bp_invoicing_init() { |
|
421 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
422 | - } |
|
423 | - |
|
424 | - /** |
|
425 | - * Register widgets |
|
426 | - * |
|
427 | - */ |
|
428 | - public function register_widgets() { |
|
429 | - |
|
430 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
431 | - // So we disable our widgets when editing a page with UX Builder. |
|
432 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
433 | - return; |
|
434 | - } |
|
435 | - |
|
436 | - $widgets = apply_filters( |
|
437 | - 'getpaid_widget_classes', |
|
438 | - array( |
|
439 | - 'WPInv_Checkout_Widget', |
|
440 | - 'WPInv_History_Widget', |
|
441 | - 'WPInv_Receipt_Widget', |
|
442 | - 'WPInv_Subscriptions_Widget', |
|
443 | - 'WPInv_Buy_Item_Widget', |
|
444 | - 'WPInv_Messages_Widget', |
|
445 | - 'WPInv_GetPaid_Widget' |
|
446 | - ) |
|
447 | - ); |
|
448 | - |
|
449 | - foreach ( $widgets as $widget ) { |
|
450 | - register_widget( $widget ); |
|
451 | - } |
|
420 | + public function bp_invoicing_init() { |
|
421 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
422 | + } |
|
423 | + |
|
424 | + /** |
|
425 | + * Register widgets |
|
426 | + * |
|
427 | + */ |
|
428 | + public function register_widgets() { |
|
429 | + |
|
430 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
431 | + // So we disable our widgets when editing a page with UX Builder. |
|
432 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
433 | + return; |
|
434 | + } |
|
435 | + |
|
436 | + $widgets = apply_filters( |
|
437 | + 'getpaid_widget_classes', |
|
438 | + array( |
|
439 | + 'WPInv_Checkout_Widget', |
|
440 | + 'WPInv_History_Widget', |
|
441 | + 'WPInv_Receipt_Widget', |
|
442 | + 'WPInv_Subscriptions_Widget', |
|
443 | + 'WPInv_Buy_Item_Widget', |
|
444 | + 'WPInv_Messages_Widget', |
|
445 | + 'WPInv_GetPaid_Widget' |
|
446 | + ) |
|
447 | + ); |
|
448 | + |
|
449 | + foreach ( $widgets as $widget ) { |
|
450 | + register_widget( $widget ); |
|
451 | + } |
|
452 | 452 | |
453 | - } |
|
453 | + } |
|
454 | 454 | |
455 | - /** |
|
456 | - * Upgrades the database. |
|
457 | - * |
|
458 | - * @since 2.0.2 |
|
459 | - */ |
|
460 | - public function maybe_upgrade_database() { |
|
455 | + /** |
|
456 | + * Upgrades the database. |
|
457 | + * |
|
458 | + * @since 2.0.2 |
|
459 | + */ |
|
460 | + public function maybe_upgrade_database() { |
|
461 | 461 | |
462 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
462 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
463 | 463 | |
464 | - if ( $wpi_version == WPINV_VERSION ) { |
|
465 | - return; |
|
466 | - } |
|
464 | + if ( $wpi_version == WPINV_VERSION ) { |
|
465 | + return; |
|
466 | + } |
|
467 | 467 | |
468 | - $installer = new GetPaid_Installer(); |
|
468 | + $installer = new GetPaid_Installer(); |
|
469 | 469 | |
470 | - if ( empty( $wpi_version ) ) { |
|
471 | - return $installer->upgrade_db( 0 ); |
|
472 | - } |
|
470 | + if ( empty( $wpi_version ) ) { |
|
471 | + return $installer->upgrade_db( 0 ); |
|
472 | + } |
|
473 | 473 | |
474 | - $upgrades = array( |
|
475 | - '0.0.5' => '004', |
|
476 | - '1.0.3' => '102', |
|
477 | - '2.0.0' => '118', |
|
478 | - '2.0.8' => '207', |
|
479 | - ); |
|
474 | + $upgrades = array( |
|
475 | + '0.0.5' => '004', |
|
476 | + '1.0.3' => '102', |
|
477 | + '2.0.0' => '118', |
|
478 | + '2.0.8' => '207', |
|
479 | + ); |
|
480 | 480 | |
481 | - foreach ( $upgrades as $key => $method ) { |
|
481 | + foreach ( $upgrades as $key => $method ) { |
|
482 | 482 | |
483 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
484 | - return $installer->upgrade_db( $method ); |
|
485 | - } |
|
483 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
484 | + return $installer->upgrade_db( $method ); |
|
485 | + } |
|
486 | 486 | |
487 | - } |
|
487 | + } |
|
488 | 488 | |
489 | - } |
|
489 | + } |
|
490 | 490 | |
491 | - /** |
|
492 | - * Flushes the permalinks if needed. |
|
493 | - * |
|
494 | - * @since 2.0.8 |
|
495 | - */ |
|
496 | - public function maybe_flush_permalinks() { |
|
491 | + /** |
|
492 | + * Flushes the permalinks if needed. |
|
493 | + * |
|
494 | + * @since 2.0.8 |
|
495 | + */ |
|
496 | + public function maybe_flush_permalinks() { |
|
497 | 497 | |
498 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
498 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
499 | 499 | |
500 | - if ( ! empty( $flush ) ) { |
|
501 | - flush_rewrite_rules(); |
|
502 | - delete_option( 'wpinv_flush_permalinks' ); |
|
503 | - } |
|
500 | + if ( ! empty( $flush ) ) { |
|
501 | + flush_rewrite_rules(); |
|
502 | + delete_option( 'wpinv_flush_permalinks' ); |
|
503 | + } |
|
504 | 504 | |
505 | - } |
|
505 | + } |
|
506 | 506 | |
507 | - /** |
|
508 | - * Remove our pages from yoast sitemaps. |
|
509 | - * |
|
510 | - * @since 1.0.19 |
|
511 | - * @param int[] $excluded_posts_ids |
|
512 | - */ |
|
513 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
507 | + /** |
|
508 | + * Remove our pages from yoast sitemaps. |
|
509 | + * |
|
510 | + * @since 1.0.19 |
|
511 | + * @param int[] $excluded_posts_ids |
|
512 | + */ |
|
513 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
514 | 514 | |
515 | - // Ensure that we have an array. |
|
516 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
517 | - $excluded_posts_ids = array(); |
|
518 | - } |
|
515 | + // Ensure that we have an array. |
|
516 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
517 | + $excluded_posts_ids = array(); |
|
518 | + } |
|
519 | 519 | |
520 | - // Prepare our pages. |
|
521 | - $our_pages = array(); |
|
520 | + // Prepare our pages. |
|
521 | + $our_pages = array(); |
|
522 | 522 | |
523 | - // Checkout page. |
|
524 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
523 | + // Checkout page. |
|
524 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
525 | 525 | |
526 | - // Success page. |
|
527 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
526 | + // Success page. |
|
527 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
528 | 528 | |
529 | - // Failure page. |
|
530 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
529 | + // Failure page. |
|
530 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
531 | 531 | |
532 | - // History page. |
|
533 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
532 | + // History page. |
|
533 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
534 | 534 | |
535 | - // Subscriptions page. |
|
536 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
535 | + // Subscriptions page. |
|
536 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
537 | 537 | |
538 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
538 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
539 | 539 | |
540 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
541 | - return array_unique( $excluded_posts_ids ); |
|
540 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
541 | + return array_unique( $excluded_posts_ids ); |
|
542 | 542 | |
543 | - } |
|
543 | + } |
|
544 | 544 | |
545 | - public function wp_footer() { |
|
546 | - echo ' |
|
545 | + public function wp_footer() { |
|
546 | + echo ' |
|
547 | 547 | <div class="bsui"> |
548 | 548 | <div id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog"> |
549 | 549 | <div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;"> |
@@ -559,6 +559,6 @@ discard block |
||
559 | 559 | </div> |
560 | 560 | </div> |
561 | 561 | '; |
562 | - } |
|
562 | + } |
|
563 | 563 | |
564 | 564 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 1.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Main Invoicing class. |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | * @param string $prop The prop to set. |
57 | 57 | * @param mixed $value The value to retrieve. |
58 | 58 | */ |
59 | - public function set( $prop, $value ) { |
|
60 | - $this->data[ $prop ] = $value; |
|
59 | + public function set($prop, $value) { |
|
60 | + $this->data[$prop] = $value; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | * @param string $prop The prop to set. |
67 | 67 | * @return mixed The value. |
68 | 68 | */ |
69 | - public function get( $prop ) { |
|
69 | + public function get($prop) { |
|
70 | 70 | |
71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
72 | - return $this->data[ $prop ]; |
|
71 | + if (isset($this->data[$prop])) { |
|
72 | + return $this->data[$prop]; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | return null; |
@@ -81,23 +81,23 @@ discard block |
||
81 | 81 | public function set_properties() { |
82 | 82 | |
83 | 83 | // Sessions. |
84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
84 | + $this->set('session', new WPInv_Session_Handler()); |
|
85 | + $GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility. |
|
86 | 86 | $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
87 | 87 | |
88 | 88 | // Init other objects. |
89 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | - $this->set( 'notes', new WPInv_Notes() ); |
|
91 | - $this->set( 'api', new WPInv_API() ); |
|
92 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | - $this->set( 'template', new GetPaid_Template() ); |
|
94 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
89 | + $this->set('session', new WPInv_Session_Handler()); |
|
90 | + $this->set('notes', new WPInv_Notes()); |
|
91 | + $this->set('api', new WPInv_API()); |
|
92 | + $this->set('post_types', new GetPaid_Post_Types()); |
|
93 | + $this->set('template', new GetPaid_Template()); |
|
94 | + $this->set('admin', new GetPaid_Admin()); |
|
95 | + $this->set('subscriptions', new WPInv_Subscriptions()); |
|
96 | + $this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails()); |
|
97 | + $this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails()); |
|
98 | + $this->set('daily_maintenace', new GetPaid_Daily_Maintenance()); |
|
99 | + $this->set('payment_forms', new GetPaid_Payment_Forms()); |
|
100 | + $this->set('maxmind', new GetPaid_MaxMind_Geolocation()); |
|
101 | 101 | |
102 | 102 | } |
103 | 103 | |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | * Define plugin constants. |
106 | 106 | */ |
107 | 107 | public function define_constants() { |
108 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
108 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
109 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
110 | 110 | $this->version = WPINV_VERSION; |
111 | 111 | } |
112 | 112 | |
@@ -117,27 +117,27 @@ discard block |
||
117 | 117 | */ |
118 | 118 | protected function init_hooks() { |
119 | 119 | /* Internationalize the text strings used. */ |
120 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
120 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
121 | 121 | |
122 | 122 | // Init the plugin after WordPress inits. |
123 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
123 | + add_action('init', array($this, 'init'), 1); |
|
124 | + add_action('init', array($this, 'maybe_process_ipn'), 10); |
|
125 | + add_action('init', array($this, 'wpinv_actions')); |
|
126 | + add_action('init', array($this, 'maybe_do_authenticated_action'), 100); |
|
127 | 127 | |
128 | - if ( class_exists( 'BuddyPress' ) ) { |
|
129 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
128 | + if (class_exists('BuddyPress')) { |
|
129 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
130 | 130 | } |
131 | 131 | |
132 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
133 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
134 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
135 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
136 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
132 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 11); |
|
133 | + add_action('wp_footer', array(&$this, 'wp_footer')); |
|
134 | + add_action('widgets_init', array(&$this, 'register_widgets')); |
|
135 | + add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids')); |
|
136 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
137 | 137 | |
138 | 138 | // Fires after registering actions. |
139 | - do_action( 'wpinv_actions', $this ); |
|
140 | - do_action( 'getpaid_actions', $this ); |
|
139 | + do_action('wpinv_actions', $this); |
|
140 | + do_action('getpaid_actions', $this); |
|
141 | 141 | |
142 | 142 | } |
143 | 143 | |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | /* Internationalize the text strings used. */ |
146 | 146 | $this->load_textdomain(); |
147 | 147 | |
148 | - do_action( 'wpinv_loaded' ); |
|
148 | + do_action('wpinv_loaded'); |
|
149 | 149 | |
150 | 150 | // Fix oxygen page builder conflict |
151 | - if ( function_exists( 'ct_css_output' ) ) { |
|
151 | + if (function_exists('ct_css_output')) { |
|
152 | 152 | wpinv_oxygen_fix_conflict(); |
153 | 153 | } |
154 | 154 | } |
@@ -158,21 +158,21 @@ discard block |
||
158 | 158 | * |
159 | 159 | * @since 1.0 |
160 | 160 | */ |
161 | - public function load_textdomain( $locale = NULL ) { |
|
162 | - if ( empty( $locale ) ) { |
|
163 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
161 | + public function load_textdomain($locale = NULL) { |
|
162 | + if (empty($locale)) { |
|
163 | + $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
164 | 164 | } |
165 | 165 | |
166 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
166 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
167 | 167 | |
168 | - unload_textdomain( 'invoicing' ); |
|
169 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
170 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
168 | + unload_textdomain('invoicing'); |
|
169 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
170 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
171 | 171 | |
172 | 172 | /** |
173 | 173 | * Define language constants. |
174 | 174 | */ |
175 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
175 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -181,78 +181,78 @@ discard block |
||
181 | 181 | public function includes() { |
182 | 182 | |
183 | 183 | // Start with the settings. |
184 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
184 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
185 | 185 | |
186 | 186 | // Packages/libraries. |
187 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
188 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
187 | + require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php'); |
|
188 | + require_once(WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'); |
|
189 | 189 | |
190 | 190 | // Load functions. |
191 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
192 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
193 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
194 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
195 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
198 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
199 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' ); |
|
205 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
191 | + require_once(WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'); |
|
192 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
193 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
194 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
195 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
196 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
197 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
198 | + require_once(WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'); |
|
199 | + require_once(WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'); |
|
200 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
201 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
202 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
203 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
204 | + require_once(WPINV_PLUGIN_DIR . 'includes/user-functions.php'); |
|
205 | + require_once(WPINV_PLUGIN_DIR . 'includes/error-functions.php'); |
|
206 | 206 | |
207 | 207 | // Register autoloader. |
208 | 208 | try { |
209 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
210 | - } catch ( Exception $e ) { |
|
211 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
209 | + spl_autoload_register(array($this, 'autoload'), true); |
|
210 | + } catch (Exception $e) { |
|
211 | + wpinv_error_log($e->getMessage(), '', __FILE__, 149, true); |
|
212 | 212 | } |
213 | 213 | |
214 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
215 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
216 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
217 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
218 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
219 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
220 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
221 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
222 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
234 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
235 | - |
|
236 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
214 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'); |
|
215 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'); |
|
216 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
217 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
218 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
219 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'); |
|
220 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'); |
|
221 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'); |
|
222 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'); |
|
223 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'); |
|
224 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'); |
|
225 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'); |
|
226 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'); |
|
227 | + require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php'); |
|
228 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'); |
|
229 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'); |
|
230 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'); |
|
231 | + require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'); |
|
232 | + require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php'); |
|
233 | + require_once(WPINV_PLUGIN_DIR . 'widgets/getpaid.php'); |
|
234 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
235 | + |
|
236 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
237 | 237 | GetPaid_Post_Types_Admin::init(); |
238 | 238 | |
239 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
240 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
241 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
242 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
243 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
244 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
239 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
240 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'); |
|
241 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
242 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'); |
|
243 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'); |
|
244 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'); |
|
245 | 245 | // load the user class only on the users.php page |
246 | 246 | global $pagenow; |
247 | - if($pagenow=='users.php'){ |
|
247 | + if ($pagenow == 'users.php') { |
|
248 | 248 | new WPInv_Admin_Users(); |
249 | 249 | } |
250 | 250 | } |
251 | 251 | |
252 | 252 | // Register cli commands |
253 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
254 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
255 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
253 | + if (defined('WP_CLI') && WP_CLI) { |
|
254 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'); |
|
255 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | } |
@@ -265,21 +265,21 @@ discard block |
||
265 | 265 | * @since 1.0.19 |
266 | 266 | * @return void |
267 | 267 | */ |
268 | - public function autoload( $class_name ) { |
|
268 | + public function autoload($class_name) { |
|
269 | 269 | |
270 | 270 | // Normalize the class name... |
271 | - $class_name = strtolower( $class_name ); |
|
271 | + $class_name = strtolower($class_name); |
|
272 | 272 | |
273 | 273 | // ... and make sure it is our class. |
274 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
274 | + if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) { |
|
275 | 275 | return; |
276 | 276 | } |
277 | 277 | |
278 | 278 | // Next, prepare the file name from the class. |
279 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
279 | + $file_name = 'class-' . str_replace('_', '-', $class_name) . '.php'; |
|
280 | 280 | |
281 | 281 | // Base path of the classes. |
282 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
282 | + $plugin_path = untrailingslashit(WPINV_PLUGIN_DIR); |
|
283 | 283 | |
284 | 284 | // And an array of possible locations in order of importance. |
285 | 285 | $locations = array( |
@@ -294,10 +294,10 @@ discard block |
||
294 | 294 | "$plugin_path/includes/admin/meta-boxes", |
295 | 295 | ); |
296 | 296 | |
297 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
297 | + foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) { |
|
298 | 298 | |
299 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
300 | - include trailingslashit( $location ) . $file_name; |
|
299 | + if (file_exists(trailingslashit($location) . $file_name)) { |
|
300 | + include trailingslashit($location) . $file_name; |
|
301 | 301 | break; |
302 | 302 | } |
303 | 303 | |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | public function init() { |
312 | 312 | |
313 | 313 | // Fires before getpaid inits. |
314 | - do_action( 'before_getpaid_init', $this ); |
|
314 | + do_action('before_getpaid_init', $this); |
|
315 | 315 | |
316 | 316 | // Maybe upgrade. |
317 | 317 | $this->maybe_upgrade_database(); |
@@ -328,12 +328,12 @@ discard block |
||
328 | 328 | ) |
329 | 329 | ); |
330 | 330 | |
331 | - foreach ( $gateways as $id => $class ) { |
|
332 | - $this->gateways[ $id ] = new $class(); |
|
331 | + foreach ($gateways as $id => $class) { |
|
332 | + $this->gateways[$id] = new $class(); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | // Fires after getpaid inits. |
336 | - do_action( 'getpaid_init', $this ); |
|
336 | + do_action('getpaid_init', $this); |
|
337 | 337 | |
338 | 338 | } |
339 | 339 | |
@@ -343,14 +343,14 @@ discard block |
||
343 | 343 | public function maybe_process_ipn() { |
344 | 344 | |
345 | 345 | // Ensure that this is an IPN request. |
346 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
346 | + if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) { |
|
347 | 347 | return; |
348 | 348 | } |
349 | 349 | |
350 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
350 | + $gateway = wpinv_clean($_GET['wpi-gateway']); |
|
351 | 351 | |
352 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
353 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
352 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
353 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
354 | 354 | exit; |
355 | 355 | |
356 | 356 | } |
@@ -358,31 +358,31 @@ discard block |
||
358 | 358 | public function enqueue_scripts() { |
359 | 359 | |
360 | 360 | // Fires before adding scripts. |
361 | - do_action( 'getpaid_enqueue_scripts' ); |
|
361 | + do_action('getpaid_enqueue_scripts'); |
|
362 | 362 | |
363 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
364 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
365 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
363 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css'); |
|
364 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version); |
|
365 | + wp_enqueue_style('wpinv_front_style'); |
|
366 | 366 | |
367 | 367 | $localize = array(); |
368 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
369 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
370 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
368 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
369 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
370 | + $localize['txtComplete'] = __('Continue', 'invoicing'); |
|
371 | 371 | $localize['UseTaxes'] = wpinv_use_taxes(); |
372 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
373 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
374 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
372 | + $localize['formNonce'] = wp_create_nonce('getpaid_form_nonce'); |
|
373 | + $localize['loading'] = __('Loading...', 'invoicing'); |
|
374 | + $localize['connectionError'] = __('Could not establish a connection to the server.', 'invoicing'); |
|
375 | 375 | |
376 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
376 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
377 | 377 | |
378 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
379 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
380 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
378 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js'); |
|
379 | + wp_enqueue_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('jquery'), $version, true); |
|
380 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | public function wpinv_actions() { |
384 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
385 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
384 | + if (isset($_REQUEST['wpi_action'])) { |
|
385 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
386 | 386 | } |
387 | 387 | } |
388 | 388 | |
@@ -394,31 +394,31 @@ discard block |
||
394 | 394 | */ |
395 | 395 | public function maybe_do_authenticated_action() { |
396 | 396 | |
397 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
397 | + if (isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
398 | 398 | |
399 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
400 | - $data = wp_unslash( $_REQUEST ); |
|
401 | - if ( is_user_logged_in() ) { |
|
402 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
399 | + $key = sanitize_key($_REQUEST['getpaid-action']); |
|
400 | + $data = wp_unslash($_REQUEST); |
|
401 | + if (is_user_logged_in()) { |
|
402 | + do_action("getpaid_authenticated_action_$key", $data); |
|
403 | 403 | } |
404 | 404 | |
405 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
405 | + do_action("getpaid_unauthenticated_action_$key", $data); |
|
406 | 406 | |
407 | 407 | } |
408 | 408 | |
409 | 409 | } |
410 | 410 | |
411 | - public function pre_get_posts( $wp_query ) { |
|
411 | + public function pre_get_posts($wp_query) { |
|
412 | 412 | |
413 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
414 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
413 | + if (!is_admin() && !empty($wp_query->query_vars['post_type']) && getpaid_is_invoice_post_type($wp_query->query_vars['post_type']) && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
414 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses(false, false, $wp_query->query_vars['post_type'])); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | return $wp_query; |
418 | 418 | } |
419 | 419 | |
420 | 420 | public function bp_invoicing_init() { |
421 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
421 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | /** |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | |
430 | 430 | // Currently, UX Builder does not work particulaly well with SuperDuper. |
431 | 431 | // So we disable our widgets when editing a page with UX Builder. |
432 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
432 | + if (function_exists('ux_builder_is_active') && ux_builder_is_active()) { |
|
433 | 433 | return; |
434 | 434 | } |
435 | 435 | |
@@ -446,8 +446,8 @@ discard block |
||
446 | 446 | ) |
447 | 447 | ); |
448 | 448 | |
449 | - foreach ( $widgets as $widget ) { |
|
450 | - register_widget( $widget ); |
|
449 | + foreach ($widgets as $widget) { |
|
450 | + register_widget($widget); |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | } |
@@ -459,29 +459,29 @@ discard block |
||
459 | 459 | */ |
460 | 460 | public function maybe_upgrade_database() { |
461 | 461 | |
462 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
462 | + $wpi_version = get_option('wpinv_version', 0); |
|
463 | 463 | |
464 | - if ( $wpi_version == WPINV_VERSION ) { |
|
464 | + if ($wpi_version == WPINV_VERSION) { |
|
465 | 465 | return; |
466 | 466 | } |
467 | 467 | |
468 | 468 | $installer = new GetPaid_Installer(); |
469 | 469 | |
470 | - if ( empty( $wpi_version ) ) { |
|
471 | - return $installer->upgrade_db( 0 ); |
|
470 | + if (empty($wpi_version)) { |
|
471 | + return $installer->upgrade_db(0); |
|
472 | 472 | } |
473 | 473 | |
474 | - $upgrades = array( |
|
474 | + $upgrades = array( |
|
475 | 475 | '0.0.5' => '004', |
476 | 476 | '1.0.3' => '102', |
477 | 477 | '2.0.0' => '118', |
478 | 478 | '2.0.8' => '207', |
479 | 479 | ); |
480 | 480 | |
481 | - foreach ( $upgrades as $key => $method ) { |
|
481 | + foreach ($upgrades as $key => $method) { |
|
482 | 482 | |
483 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
484 | - return $installer->upgrade_db( $method ); |
|
483 | + if (version_compare($wpi_version, $key, '<')) { |
|
484 | + return $installer->upgrade_db($method); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | } |
@@ -495,11 +495,11 @@ discard block |
||
495 | 495 | */ |
496 | 496 | public function maybe_flush_permalinks() { |
497 | 497 | |
498 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
498 | + $flush = get_option('wpinv_flush_permalinks', 0); |
|
499 | 499 | |
500 | - if ( ! empty( $flush ) ) { |
|
500 | + if (!empty($flush)) { |
|
501 | 501 | flush_rewrite_rules(); |
502 | - delete_option( 'wpinv_flush_permalinks' ); |
|
502 | + delete_option('wpinv_flush_permalinks'); |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | } |
@@ -510,10 +510,10 @@ discard block |
||
510 | 510 | * @since 1.0.19 |
511 | 511 | * @param int[] $excluded_posts_ids |
512 | 512 | */ |
513 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
513 | + public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) { |
|
514 | 514 | |
515 | 515 | // Ensure that we have an array. |
516 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
516 | + if (!is_array($excluded_posts_ids)) { |
|
517 | 517 | $excluded_posts_ids = array(); |
518 | 518 | } |
519 | 519 | |
@@ -521,24 +521,24 @@ discard block |
||
521 | 521 | $our_pages = array(); |
522 | 522 | |
523 | 523 | // Checkout page. |
524 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
524 | + $our_pages[] = wpinv_get_option('checkout_page', false); |
|
525 | 525 | |
526 | 526 | // Success page. |
527 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
527 | + $our_pages[] = wpinv_get_option('success_page', false); |
|
528 | 528 | |
529 | 529 | // Failure page. |
530 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
530 | + $our_pages[] = wpinv_get_option('failure_page', false); |
|
531 | 531 | |
532 | 532 | // History page. |
533 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
533 | + $our_pages[] = wpinv_get_option('invoice_history_page', false); |
|
534 | 534 | |
535 | 535 | // Subscriptions page. |
536 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
536 | + $our_pages[] = wpinv_get_option('invoice_subscription_page', false); |
|
537 | 537 | |
538 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
538 | + $our_pages = array_map('intval', array_filter($our_pages)); |
|
539 | 539 | |
540 | 540 | $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
541 | - return array_unique( $excluded_posts_ids ); |
|
541 | + return array_unique($excluded_posts_ids); |
|
542 | 542 | |
543 | 543 | } |
544 | 544 | |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | <div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;"> |
550 | 550 | <div class="modal-content"> |
551 | 551 | <div class="modal-body"> |
552 | - <button type="button" class="close p-2 getpaid-payment-modal-close d-sm-none" data-dismiss="modal" aria-label="' . esc_attr__( 'Close', 'invoicing' ) . '"> |
|
552 | + <button type="button" class="close p-2 getpaid-payment-modal-close d-sm-none" data-dismiss="modal" aria-label="' . esc_attr__('Close', 'invoicing') . '"> |
|
553 | 553 | <i class="fa fa-times" aria-hidden="true"></i> |
554 | 554 | </button> |
555 | 555 | <div class="modal-body-wrapper"></div> |