@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | $cb = "wpinv_{$option['type']}_callback"; |
197 | 197 | $section = "wpinv_settings_{$tab}_$section"; |
198 | 198 | |
199 | - if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) { |
|
200 | - $tip = esc_attr( $option['desc'] ); |
|
201 | - $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
|
202 | - unset( $option['desc'] ); |
|
203 | - } |
|
199 | + if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) { |
|
200 | + $tip = esc_attr( $option['desc'] ); |
|
201 | + $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
|
202 | + unset( $option['desc'] ); |
|
203 | + } |
|
204 | 204 | |
205 | 205 | // Loop through all tabs. |
206 | 206 | add_settings_field( |
@@ -279,10 +279,10 @@ discard block |
||
279 | 279 | } |
280 | 280 | |
281 | 281 | // General filter |
282 | - $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
282 | + $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
283 | 283 | |
284 | - // Key specific filter. |
|
285 | - $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] ); |
|
284 | + // Key specific filter. |
|
285 | + $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] ); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | // Loop through the whitelist and unset any that are empty for the tab being saved |
@@ -427,333 +427,333 @@ discard block |
||
427 | 427 | } |
428 | 428 | |
429 | 429 | function wpinv_get_pages( $with_slug = false, $default_label = NULL ) { |
430 | - $pages_options = array(); |
|
430 | + $pages_options = array(); |
|
431 | 431 | |
432 | - if( $default_label !== NULL && $default_label !== false ) { |
|
433 | - $pages_options = array( '' => $default_label ); // Blank option |
|
434 | - } |
|
432 | + if( $default_label !== NULL && $default_label !== false ) { |
|
433 | + $pages_options = array( '' => $default_label ); // Blank option |
|
434 | + } |
|
435 | 435 | |
436 | - $pages = get_pages(); |
|
437 | - if ( $pages ) { |
|
438 | - foreach ( $pages as $page ) { |
|
439 | - $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
436 | + $pages = get_pages(); |
|
437 | + if ( $pages ) { |
|
438 | + foreach ( $pages as $page ) { |
|
439 | + $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
440 | 440 | $pages_options[ $page->ID ] = $title; |
441 | - } |
|
442 | - } |
|
441 | + } |
|
442 | + } |
|
443 | 443 | |
444 | - return $pages_options; |
|
444 | + return $pages_options; |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | function wpinv_header_callback( $args ) { |
448 | - if ( !empty( $args['desc'] ) ) { |
|
448 | + if ( !empty( $args['desc'] ) ) { |
|
449 | 449 | echo $args['desc']; |
450 | 450 | } |
451 | 451 | } |
452 | 452 | |
453 | 453 | function wpinv_hidden_callback( $args ) { |
454 | - global $wpinv_options; |
|
455 | - |
|
456 | - if ( isset( $args['set_value'] ) ) { |
|
457 | - $value = $args['set_value']; |
|
458 | - } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
459 | - $value = $wpinv_options[ $args['id'] ]; |
|
460 | - } else { |
|
461 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
462 | - } |
|
463 | - |
|
464 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
465 | - $args['readonly'] = true; |
|
466 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
467 | - $name = ''; |
|
468 | - } else { |
|
469 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
470 | - } |
|
471 | - |
|
472 | - $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
454 | + global $wpinv_options; |
|
455 | + |
|
456 | + if ( isset( $args['set_value'] ) ) { |
|
457 | + $value = $args['set_value']; |
|
458 | + } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
459 | + $value = $wpinv_options[ $args['id'] ]; |
|
460 | + } else { |
|
461 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
462 | + } |
|
463 | + |
|
464 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
465 | + $args['readonly'] = true; |
|
466 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
467 | + $name = ''; |
|
468 | + } else { |
|
469 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
470 | + } |
|
471 | + |
|
472 | + $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
473 | 473 | |
474 | - echo $html; |
|
474 | + echo $html; |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | function wpinv_checkbox_callback( $args ) { |
478 | - global $wpinv_options; |
|
478 | + global $wpinv_options; |
|
479 | 479 | |
480 | 480 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
481 | 481 | |
482 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
483 | - $name = ''; |
|
484 | - } else { |
|
485 | - $name = 'name="wpinv_settings[' . $sanitize_id . ']"'; |
|
486 | - } |
|
482 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
483 | + $name = ''; |
|
484 | + } else { |
|
485 | + $name = 'name="wpinv_settings[' . $sanitize_id . ']"'; |
|
486 | + } |
|
487 | 487 | |
488 | - $std = isset( $args['std'] ) ? $args['std'] : 0; |
|
489 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
490 | - $checked = checked( empty( $value ), false, false ); |
|
488 | + $std = isset( $args['std'] ) ? $args['std'] : 0; |
|
489 | + $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
490 | + $checked = checked( empty( $value ), false, false ); |
|
491 | 491 | |
492 | - $html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>'; |
|
493 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
492 | + $html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>'; |
|
493 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
494 | 494 | |
495 | - echo $html; |
|
495 | + echo $html; |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | function wpinv_multicheck_callback( $args ) { |
499 | - global $wpinv_options; |
|
499 | + global $wpinv_options; |
|
500 | 500 | |
501 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
502 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
501 | + $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
502 | + $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
503 | 503 | |
504 | - if ( ! empty( $args['options'] ) ) { |
|
504 | + if ( ! empty( $args['options'] ) ) { |
|
505 | 505 | |
506 | - $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
507 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
506 | + $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
507 | + $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
508 | 508 | |
509 | - echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">'; |
|
509 | + echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">'; |
|
510 | 510 | foreach( $args['options'] as $key => $option ): |
511 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
512 | - if ( in_array( $sanitize_key, $value ) ) { |
|
513 | - $enabled = $sanitize_key; |
|
514 | - } else { |
|
515 | - $enabled = NULL; |
|
516 | - } |
|
517 | - echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
518 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
519 | - endforeach; |
|
520 | - echo '</div>'; |
|
521 | - echo '<p class="description">' . $args['desc'] . '</p>'; |
|
522 | - } |
|
511 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
512 | + if ( in_array( $sanitize_key, $value ) ) { |
|
513 | + $enabled = $sanitize_key; |
|
514 | + } else { |
|
515 | + $enabled = NULL; |
|
516 | + } |
|
517 | + echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
518 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
519 | + endforeach; |
|
520 | + echo '</div>'; |
|
521 | + echo '<p class="description">' . $args['desc'] . '</p>'; |
|
522 | + } |
|
523 | 523 | } |
524 | 524 | |
525 | 525 | function wpinv_payment_icons_callback( $args ) { |
526 | - global $wpinv_options; |
|
526 | + global $wpinv_options; |
|
527 | 527 | |
528 | 528 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
529 | 529 | |
530 | - if ( ! empty( $args['options'] ) ) { |
|
531 | - foreach( $args['options'] as $key => $option ) { |
|
530 | + if ( ! empty( $args['options'] ) ) { |
|
531 | + foreach( $args['options'] as $key => $option ) { |
|
532 | 532 | $sanitize_key = wpinv_sanitize_key( $key ); |
533 | 533 | |
534 | - if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
535 | - $enabled = $option; |
|
536 | - } else { |
|
537 | - $enabled = NULL; |
|
538 | - } |
|
539 | - |
|
540 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
541 | - |
|
542 | - echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
543 | - |
|
544 | - if ( wpinv_string_is_image_url( $key ) ) { |
|
545 | - echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
546 | - } else { |
|
547 | - $card = strtolower( str_replace( ' ', '', $option ) ); |
|
548 | - |
|
549 | - if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
550 | - $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
551 | - } else { |
|
552 | - $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
553 | - $content_dir = WP_CONTENT_DIR; |
|
554 | - |
|
555 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
556 | - // Replaces backslashes with forward slashes for Windows systems |
|
557 | - $image = wp_normalize_path( $image ); |
|
558 | - $content_dir = wp_normalize_path( $content_dir ); |
|
559 | - } |
|
560 | - |
|
561 | - $image = str_replace( $content_dir, content_url(), $image ); |
|
562 | - } |
|
563 | - |
|
564 | - echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
565 | - } |
|
566 | - echo $option . '</label>'; |
|
567 | - } |
|
568 | - echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
569 | - } |
|
534 | + if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
535 | + $enabled = $option; |
|
536 | + } else { |
|
537 | + $enabled = NULL; |
|
538 | + } |
|
539 | + |
|
540 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
541 | + |
|
542 | + echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
543 | + |
|
544 | + if ( wpinv_string_is_image_url( $key ) ) { |
|
545 | + echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
546 | + } else { |
|
547 | + $card = strtolower( str_replace( ' ', '', $option ) ); |
|
548 | + |
|
549 | + if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
550 | + $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
551 | + } else { |
|
552 | + $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
553 | + $content_dir = WP_CONTENT_DIR; |
|
554 | + |
|
555 | + if ( function_exists( 'wp_normalize_path' ) ) { |
|
556 | + // Replaces backslashes with forward slashes for Windows systems |
|
557 | + $image = wp_normalize_path( $image ); |
|
558 | + $content_dir = wp_normalize_path( $content_dir ); |
|
559 | + } |
|
560 | + |
|
561 | + $image = str_replace( $content_dir, content_url(), $image ); |
|
562 | + } |
|
563 | + |
|
564 | + echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
565 | + } |
|
566 | + echo $option . '</label>'; |
|
567 | + } |
|
568 | + echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
569 | + } |
|
570 | 570 | } |
571 | 571 | |
572 | 572 | function wpinv_radio_callback( $args ) { |
573 | - global $wpinv_options; |
|
573 | + global $wpinv_options; |
|
574 | 574 | |
575 | 575 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
576 | 576 | |
577 | 577 | foreach ( $args['options'] as $key => $option ) : |
578 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
578 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
579 | 579 | |
580 | 580 | $checked = false; |
581 | 581 | |
582 | - if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key ) |
|
583 | - $checked = true; |
|
584 | - elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) ) |
|
585 | - $checked = true; |
|
582 | + if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key ) |
|
583 | + $checked = true; |
|
584 | + elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) ) |
|
585 | + $checked = true; |
|
586 | 586 | |
587 | - echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/> '; |
|
588 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>'; |
|
589 | - endforeach; |
|
587 | + echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/> '; |
|
588 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>'; |
|
589 | + endforeach; |
|
590 | 590 | |
591 | - echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
591 | + echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | function wpinv_gateways_callback( $args ) { |
595 | - global $wpinv_options; |
|
595 | + global $wpinv_options; |
|
596 | 596 | |
597 | 597 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
598 | 598 | |
599 | - foreach ( $args['options'] as $key => $option ) : |
|
600 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
599 | + foreach ( $args['options'] as $key => $option ) : |
|
600 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
601 | 601 | |
602 | 602 | if ( isset( $wpinv_options['gateways'][ $key ] ) ) |
603 | - $enabled = '1'; |
|
604 | - else |
|
605 | - $enabled = null; |
|
603 | + $enabled = '1'; |
|
604 | + else |
|
605 | + $enabled = null; |
|
606 | 606 | |
607 | - echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
608 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
609 | - endforeach; |
|
607 | + echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
608 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
609 | + endforeach; |
|
610 | 610 | } |
611 | 611 | |
612 | 612 | function wpinv_gateway_select_callback($args) { |
613 | - global $wpinv_options; |
|
613 | + global $wpinv_options; |
|
614 | 614 | |
615 | 615 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
616 | 616 | $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
617 | 617 | |
618 | - echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >'; |
|
618 | + echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >'; |
|
619 | 619 | |
620 | - foreach ( $args['options'] as $key => $option ) : |
|
621 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
620 | + foreach ( $args['options'] as $key => $option ) : |
|
621 | + if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
622 | 622 | $selected = selected( $key, $args['selected'], false ); |
623 | 623 | } else { |
624 | 624 | $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : ''; |
625 | 625 | } |
626 | - echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
627 | - endforeach; |
|
626 | + echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
627 | + endforeach; |
|
628 | 628 | |
629 | - echo '</select>'; |
|
630 | - echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
629 | + echo '</select>'; |
|
630 | + echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
631 | 631 | } |
632 | 632 | |
633 | 633 | function wpinv_text_callback( $args ) { |
634 | - global $wpinv_options; |
|
634 | + global $wpinv_options; |
|
635 | 635 | |
636 | 636 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
637 | 637 | |
638 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
639 | - $value = $wpinv_options[ $args['id'] ]; |
|
640 | - } else { |
|
641 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
642 | - } |
|
643 | - |
|
644 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
645 | - $args['readonly'] = true; |
|
646 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
647 | - $name = ''; |
|
648 | - } else { |
|
649 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
650 | - } |
|
651 | - $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
652 | - |
|
653 | - $readonly = $args['readonly'] === true ? ' readonly="readonly"' : ''; |
|
654 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
655 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>'; |
|
656 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
657 | - |
|
658 | - echo $html; |
|
638 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
639 | + $value = $wpinv_options[ $args['id'] ]; |
|
640 | + } else { |
|
641 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
642 | + } |
|
643 | + |
|
644 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
645 | + $args['readonly'] = true; |
|
646 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
647 | + $name = ''; |
|
648 | + } else { |
|
649 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
650 | + } |
|
651 | + $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
652 | + |
|
653 | + $readonly = $args['readonly'] === true ? ' readonly="readonly"' : ''; |
|
654 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
655 | + $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>'; |
|
656 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
657 | + |
|
658 | + echo $html; |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | function wpinv_number_callback( $args ) { |
662 | - global $wpinv_options; |
|
662 | + global $wpinv_options; |
|
663 | 663 | |
664 | 664 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
665 | 665 | |
666 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
667 | - $value = $wpinv_options[ $args['id'] ]; |
|
668 | - } else { |
|
669 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
670 | - } |
|
671 | - |
|
672 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
673 | - $args['readonly'] = true; |
|
674 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
675 | - $name = ''; |
|
676 | - } else { |
|
677 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
678 | - } |
|
679 | - |
|
680 | - $max = isset( $args['max'] ) ? $args['max'] : 999999; |
|
681 | - $min = isset( $args['min'] ) ? $args['min'] : 0; |
|
682 | - $step = isset( $args['step'] ) ? $args['step'] : 1; |
|
683 | - $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
684 | - |
|
685 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
686 | - $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
687 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
688 | - |
|
689 | - echo $html; |
|
666 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
667 | + $value = $wpinv_options[ $args['id'] ]; |
|
668 | + } else { |
|
669 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
670 | + } |
|
671 | + |
|
672 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
673 | + $args['readonly'] = true; |
|
674 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
675 | + $name = ''; |
|
676 | + } else { |
|
677 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
678 | + } |
|
679 | + |
|
680 | + $max = isset( $args['max'] ) ? $args['max'] : 999999; |
|
681 | + $min = isset( $args['min'] ) ? $args['min'] : 0; |
|
682 | + $step = isset( $args['step'] ) ? $args['step'] : 1; |
|
683 | + $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
684 | + |
|
685 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
686 | + $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
687 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
688 | + |
|
689 | + echo $html; |
|
690 | 690 | } |
691 | 691 | |
692 | 692 | function wpinv_textarea_callback( $args ) { |
693 | - global $wpinv_options; |
|
693 | + global $wpinv_options; |
|
694 | 694 | |
695 | 695 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
696 | 696 | |
697 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
698 | - $value = $wpinv_options[ $args['id'] ]; |
|
699 | - } else { |
|
700 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
701 | - } |
|
697 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
698 | + $value = $wpinv_options[ $args['id'] ]; |
|
699 | + } else { |
|
700 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
701 | + } |
|
702 | 702 | |
703 | 703 | $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
704 | 704 | $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text'; |
705 | 705 | |
706 | - $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
707 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
706 | + $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
707 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
708 | 708 | |
709 | - echo $html; |
|
709 | + echo $html; |
|
710 | 710 | } |
711 | 711 | |
712 | 712 | function wpinv_password_callback( $args ) { |
713 | - global $wpinv_options; |
|
713 | + global $wpinv_options; |
|
714 | 714 | |
715 | 715 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
716 | 716 | |
717 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
718 | - $value = $wpinv_options[ $args['id'] ]; |
|
719 | - } else { |
|
720 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
721 | - } |
|
717 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
718 | + $value = $wpinv_options[ $args['id'] ]; |
|
719 | + } else { |
|
720 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
721 | + } |
|
722 | 722 | |
723 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
724 | - $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
725 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
723 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
724 | + $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
725 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
726 | 726 | |
727 | - echo $html; |
|
727 | + echo $html; |
|
728 | 728 | } |
729 | 729 | |
730 | 730 | function wpinv_missing_callback($args) { |
731 | - printf( |
|
732 | - __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
733 | - '<strong>' . $args['id'] . '</strong>' |
|
734 | - ); |
|
731 | + printf( |
|
732 | + __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
733 | + '<strong>' . $args['id'] . '</strong>' |
|
734 | + ); |
|
735 | 735 | } |
736 | 736 | |
737 | 737 | function wpinv_select_callback($args) { |
738 | - global $wpinv_options; |
|
738 | + global $wpinv_options; |
|
739 | 739 | |
740 | 740 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
741 | 741 | |
742 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
743 | - $value = $wpinv_options[ $args['id'] ]; |
|
744 | - } else { |
|
745 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
746 | - } |
|
742 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
743 | + $value = $wpinv_options[ $args['id'] ]; |
|
744 | + } else { |
|
745 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
746 | + } |
|
747 | 747 | |
748 | 748 | if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
749 | 749 | $value = $args['selected']; |
750 | 750 | } |
751 | 751 | |
752 | - if ( isset( $args['placeholder'] ) ) { |
|
753 | - $placeholder = $args['placeholder']; |
|
754 | - } else { |
|
755 | - $placeholder = ''; |
|
756 | - } |
|
752 | + if ( isset( $args['placeholder'] ) ) { |
|
753 | + $placeholder = $args['placeholder']; |
|
754 | + } else { |
|
755 | + $placeholder = ''; |
|
756 | + } |
|
757 | 757 | |
758 | 758 | if( !empty( $args['onchange'] ) ) { |
759 | 759 | $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
@@ -763,143 +763,143 @@ discard block |
||
763 | 763 | |
764 | 764 | $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
765 | 765 | |
766 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />'; |
|
766 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />'; |
|
767 | 767 | |
768 | - foreach ( $args['options'] as $option => $name ) { |
|
769 | - $selected = selected( $option, $value, false ); |
|
770 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
771 | - } |
|
768 | + foreach ( $args['options'] as $option => $name ) { |
|
769 | + $selected = selected( $option, $value, false ); |
|
770 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
771 | + } |
|
772 | 772 | |
773 | - $html .= '</select>'; |
|
774 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
773 | + $html .= '</select>'; |
|
774 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
775 | 775 | |
776 | - echo $html; |
|
776 | + echo $html; |
|
777 | 777 | } |
778 | 778 | |
779 | 779 | function wpinv_color_select_callback( $args ) { |
780 | - global $wpinv_options; |
|
780 | + global $wpinv_options; |
|
781 | 781 | |
782 | 782 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
783 | 783 | |
784 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
785 | - $value = $wpinv_options[ $args['id'] ]; |
|
786 | - } else { |
|
787 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
788 | - } |
|
784 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
785 | + $value = $wpinv_options[ $args['id'] ]; |
|
786 | + } else { |
|
787 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
788 | + } |
|
789 | 789 | |
790 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
790 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
791 | 791 | |
792 | - foreach ( $args['options'] as $option => $color ) { |
|
793 | - $selected = selected( $option, $value, false ); |
|
794 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
795 | - } |
|
792 | + foreach ( $args['options'] as $option => $color ) { |
|
793 | + $selected = selected( $option, $value, false ); |
|
794 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
795 | + } |
|
796 | 796 | |
797 | - $html .= '</select>'; |
|
798 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
797 | + $html .= '</select>'; |
|
798 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
799 | 799 | |
800 | - echo $html; |
|
800 | + echo $html; |
|
801 | 801 | } |
802 | 802 | |
803 | 803 | function wpinv_rich_editor_callback( $args ) { |
804 | - global $wpinv_options, $wp_version; |
|
804 | + global $wpinv_options, $wp_version; |
|
805 | 805 | |
806 | 806 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
807 | 807 | |
808 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
809 | - $value = $wpinv_options[ $args['id'] ]; |
|
808 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
809 | + $value = $wpinv_options[ $args['id'] ]; |
|
810 | 810 | |
811 | - if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
812 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
813 | - } |
|
814 | - } else { |
|
815 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
816 | - } |
|
811 | + if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
812 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
813 | + } |
|
814 | + } else { |
|
815 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
816 | + } |
|
817 | 817 | |
818 | - $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
818 | + $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
819 | 819 | |
820 | - $html = '<div class="getpaid-settings-editor-input">'; |
|
821 | - if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
822 | - ob_start(); |
|
823 | - wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
824 | - $html .= ob_get_clean(); |
|
825 | - } else { |
|
826 | - $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
827 | - } |
|
820 | + $html = '<div class="getpaid-settings-editor-input">'; |
|
821 | + if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
822 | + ob_start(); |
|
823 | + wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
824 | + $html .= ob_get_clean(); |
|
825 | + } else { |
|
826 | + $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
827 | + } |
|
828 | 828 | |
829 | - $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
829 | + $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
830 | 830 | |
831 | - echo $html; |
|
831 | + echo $html; |
|
832 | 832 | } |
833 | 833 | |
834 | 834 | function wpinv_upload_callback( $args ) { |
835 | - global $wpinv_options; |
|
835 | + global $wpinv_options; |
|
836 | 836 | |
837 | 837 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
838 | 838 | |
839 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
840 | - $value = $wpinv_options[$args['id']]; |
|
841 | - } else { |
|
842 | - $value = isset($args['std']) ? $args['std'] : ''; |
|
843 | - } |
|
839 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
840 | + $value = $wpinv_options[$args['id']]; |
|
841 | + } else { |
|
842 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
843 | + } |
|
844 | 844 | |
845 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
846 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
847 | - $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
848 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
845 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
846 | + $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
847 | + $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
848 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
849 | 849 | |
850 | - echo $html; |
|
850 | + echo $html; |
|
851 | 851 | } |
852 | 852 | |
853 | 853 | function wpinv_color_callback( $args ) { |
854 | - global $wpinv_options; |
|
854 | + global $wpinv_options; |
|
855 | 855 | |
856 | 856 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
857 | 857 | |
858 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
859 | - $value = $wpinv_options[ $args['id'] ]; |
|
860 | - } else { |
|
861 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
862 | - } |
|
858 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
859 | + $value = $wpinv_options[ $args['id'] ]; |
|
860 | + } else { |
|
861 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
862 | + } |
|
863 | 863 | |
864 | - $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
864 | + $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
865 | 865 | |
866 | - $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
867 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
866 | + $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
867 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
868 | 868 | |
869 | - echo $html; |
|
869 | + echo $html; |
|
870 | 870 | } |
871 | 871 | |
872 | 872 | function wpinv_country_states_callback($args) { |
873 | - global $wpinv_options; |
|
873 | + global $wpinv_options; |
|
874 | 874 | |
875 | 875 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
876 | 876 | |
877 | - if ( isset( $args['placeholder'] ) ) { |
|
878 | - $placeholder = $args['placeholder']; |
|
879 | - } else { |
|
880 | - $placeholder = ''; |
|
881 | - } |
|
877 | + if ( isset( $args['placeholder'] ) ) { |
|
878 | + $placeholder = $args['placeholder']; |
|
879 | + } else { |
|
880 | + $placeholder = ''; |
|
881 | + } |
|
882 | 882 | |
883 | - $states = wpinv_get_country_states(); |
|
883 | + $states = wpinv_get_country_states(); |
|
884 | 884 | |
885 | - $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
886 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
885 | + $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
886 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
887 | 887 | |
888 | - foreach ( $states as $option => $name ) { |
|
889 | - $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
890 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
891 | - } |
|
888 | + foreach ( $states as $option => $name ) { |
|
889 | + $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
890 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
891 | + } |
|
892 | 892 | |
893 | - $html .= '</select>'; |
|
894 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
893 | + $html .= '</select>'; |
|
894 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
895 | 895 | |
896 | - echo $html; |
|
896 | + echo $html; |
|
897 | 897 | } |
898 | 898 | |
899 | 899 | function wpinv_tax_rates_callback($args) { |
900 | - global $wpinv_options; |
|
901 | - $rates = wpinv_get_tax_rates(); |
|
902 | - ob_start(); ?> |
|
900 | + global $wpinv_options; |
|
901 | + $rates = wpinv_get_tax_rates(); |
|
902 | + ob_start(); ?> |
|
903 | 903 | </td><tr> |
904 | 904 | <td colspan="2" class="wpinv_tax_tdbox"> |
905 | 905 | <p><?php echo $args['desc']; ?></p> |
@@ -923,40 +923,40 @@ discard block |
||
923 | 923 | <tr> |
924 | 924 | <td class="wpinv_tax_country"> |
925 | 925 | <?php |
926 | - echo wpinv_html_select( array( |
|
927 | - 'options' => wpinv_get_country_list( true ), |
|
928 | - 'name' => 'tax_rates[' . $sanitized_key . '][country]', |
|
926 | + echo wpinv_html_select( array( |
|
927 | + 'options' => wpinv_get_country_list( true ), |
|
928 | + 'name' => 'tax_rates[' . $sanitized_key . '][country]', |
|
929 | 929 | 'id' => 'tax_rates[' . $sanitized_key . '][country]', |
930 | - 'selected' => $rate['country'], |
|
931 | - 'show_option_all' => false, |
|
932 | - 'show_option_none' => false, |
|
933 | - 'class' => 'wpinv-tax-country wpi_select2', |
|
934 | - 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
935 | - ) ); |
|
936 | - ?> |
|
930 | + 'selected' => $rate['country'], |
|
931 | + 'show_option_all' => false, |
|
932 | + 'show_option_none' => false, |
|
933 | + 'class' => 'wpinv-tax-country wpi_select2', |
|
934 | + 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
935 | + ) ); |
|
936 | + ?> |
|
937 | 937 | </td> |
938 | 938 | <td class="wpinv_tax_state"> |
939 | 939 | <?php |
940 | - $states = wpinv_get_country_states( $rate['country'] ); |
|
941 | - if( !empty( $states ) ) { |
|
942 | - echo wpinv_html_select( array( |
|
943 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
944 | - 'name' => 'tax_rates[' . $sanitized_key . '][state]', |
|
940 | + $states = wpinv_get_country_states( $rate['country'] ); |
|
941 | + if( !empty( $states ) ) { |
|
942 | + echo wpinv_html_select( array( |
|
943 | + 'options' => array_merge( array( '' => '' ), $states ), |
|
944 | + 'name' => 'tax_rates[' . $sanitized_key . '][state]', |
|
945 | 945 | 'id' => 'tax_rates[' . $sanitized_key . '][state]', |
946 | - 'selected' => $rate['state'], |
|
947 | - 'show_option_all' => false, |
|
948 | - 'show_option_none' => false, |
|
946 | + 'selected' => $rate['state'], |
|
947 | + 'show_option_all' => false, |
|
948 | + 'show_option_none' => false, |
|
949 | 949 | 'class' => 'wpi_select2', |
950 | - 'placeholder' => __( 'Choose a state', 'invoicing' ) |
|
951 | - ) ); |
|
952 | - } else { |
|
953 | - echo wpinv_html_text( array( |
|
954 | - 'name' => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'], |
|
955 | - 'value' => ! empty( $rate['state'] ) ? $rate['state'] : '', |
|
950 | + 'placeholder' => __( 'Choose a state', 'invoicing' ) |
|
951 | + ) ); |
|
952 | + } else { |
|
953 | + echo wpinv_html_text( array( |
|
954 | + 'name' => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'], |
|
955 | + 'value' => ! empty( $rate['state'] ) ? $rate['state'] : '', |
|
956 | 956 | 'id' => 'tax_rates[' . $sanitized_key . '][state]', |
957 | - ) ); |
|
958 | - } |
|
959 | - ?> |
|
957 | + ) ); |
|
958 | + } |
|
959 | + ?> |
|
960 | 960 | </td> |
961 | 961 | <td class="wpinv_tax_global"> |
962 | 962 | <input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked( true, ! empty( $rate['global'] ) ); ?>/> |
@@ -971,19 +971,19 @@ discard block |
||
971 | 971 | <tr> |
972 | 972 | <td class="wpinv_tax_country"> |
973 | 973 | <?php |
974 | - echo wpinv_html_select( array( |
|
975 | - 'options' => wpinv_get_country_list( true ), |
|
976 | - 'name' => 'tax_rates[0][country]', |
|
977 | - 'show_option_all' => false, |
|
978 | - 'show_option_none' => false, |
|
979 | - 'class' => 'wpinv-tax-country wpi_select2', |
|
980 | - 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
981 | - ) ); ?> |
|
974 | + echo wpinv_html_select( array( |
|
975 | + 'options' => wpinv_get_country_list( true ), |
|
976 | + 'name' => 'tax_rates[0][country]', |
|
977 | + 'show_option_all' => false, |
|
978 | + 'show_option_none' => false, |
|
979 | + 'class' => 'wpinv-tax-country wpi_select2', |
|
980 | + 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
981 | + ) ); ?> |
|
982 | 982 | </td> |
983 | 983 | <td class="wpinv_tax_state"> |
984 | 984 | <?php echo wpinv_html_text( array( |
985 | - 'name' => 'tax_rates[0][state]' |
|
986 | - ) ); ?> |
|
985 | + 'name' => 'tax_rates[0][state]' |
|
986 | + ) ); ?> |
|
987 | 987 | </td> |
988 | 988 | <td class="wpinv_tax_global"> |
989 | 989 | <input type="checkbox" name="tax_rates[0][global]" id="tax_rates[0][global]" value="1"/> |
@@ -998,7 +998,7 @@ discard block |
||
998 | 998 | <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e( 'Add Tax Rate', 'invoicing' ); ?></span></td></tr></tfoot> |
999 | 999 | </table> |
1000 | 1000 | <?php |
1001 | - echo ob_get_clean(); |
|
1001 | + echo ob_get_clean(); |
|
1002 | 1002 | } |
1003 | 1003 | |
1004 | 1004 | function wpinv_tools_callback($args) { |
@@ -1026,15 +1026,15 @@ discard block |
||
1026 | 1026 | } |
1027 | 1027 | |
1028 | 1028 | function wpinv_descriptive_text_callback( $args ) { |
1029 | - echo wp_kses_post( $args['desc'] ); |
|
1029 | + echo wp_kses_post( $args['desc'] ); |
|
1030 | 1030 | } |
1031 | 1031 | |
1032 | 1032 | function wpinv_hook_callback( $args ) { |
1033 | - do_action( 'wpinv_' . $args['id'], $args ); |
|
1033 | + do_action( 'wpinv_' . $args['id'], $args ); |
|
1034 | 1034 | } |
1035 | 1035 | |
1036 | 1036 | function wpinv_set_settings_cap() { |
1037 | - return wpinv_get_capability(); |
|
1037 | + return wpinv_get_capability(); |
|
1038 | 1038 | } |
1039 | 1039 | add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' ); |
1040 | 1040 |
@@ -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 | * Retrieves all default settings. |
@@ -16,13 +16,13 @@ discard block |
||
16 | 16 | function wpinv_get_settings() { |
17 | 17 | $defaults = array(); |
18 | 18 | |
19 | - foreach ( array_values( wpinv_get_registered_settings() ) as $tab_settings ) { |
|
19 | + foreach (array_values(wpinv_get_registered_settings()) as $tab_settings) { |
|
20 | 20 | |
21 | - foreach ( array_values( $tab_settings ) as $section_settings ) { |
|
21 | + foreach (array_values($tab_settings) as $section_settings) { |
|
22 | 22 | |
23 | - foreach ( $section_settings as $key => $setting ) { |
|
24 | - if ( isset( $setting['std'] ) ) { |
|
25 | - $defaults[ $key ] = $setting['std']; |
|
23 | + foreach ($section_settings as $key => $setting) { |
|
24 | + if (isset($setting['std'])) { |
|
25 | + $defaults[$key] = $setting['std']; |
|
26 | 26 | } |
27 | 27 | } |
28 | 28 | |
@@ -43,12 +43,12 @@ discard block |
||
43 | 43 | global $wpinv_options; |
44 | 44 | |
45 | 45 | // Try fetching the saved options. |
46 | - if ( ! is_array( $wpinv_options ) ) { |
|
47 | - $wpinv_options = get_option( 'wpinv_settings' ); |
|
46 | + if (!is_array($wpinv_options)) { |
|
47 | + $wpinv_options = get_option('wpinv_settings'); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | // If that fails, don't fetch the default settings to prevent a loop. |
51 | - if ( ! is_array( $wpinv_options ) ) { |
|
51 | + if (!is_array($wpinv_options)) { |
|
52 | 52 | $wpinv_options = array(); |
53 | 53 | } |
54 | 54 | |
@@ -62,13 +62,13 @@ discard block |
||
62 | 62 | * @param mixed $default The default value to use if the setting has not been set. |
63 | 63 | * @return mixed |
64 | 64 | */ |
65 | -function wpinv_get_option( $key = '', $default = false ) { |
|
65 | +function wpinv_get_option($key = '', $default = false) { |
|
66 | 66 | |
67 | 67 | $options = wpinv_get_options(); |
68 | - $value = isset( $options[ $key ] ) ? $options[ $key ] : $default; |
|
69 | - $value = apply_filters( 'wpinv_get_option', $value, $key, $default ); |
|
68 | + $value = isset($options[$key]) ? $options[$key] : $default; |
|
69 | + $value = apply_filters('wpinv_get_option', $value, $key, $default); |
|
70 | 70 | |
71 | - return apply_filters( 'wpinv_get_option_' . $key, $value, $key, $default ); |
|
71 | + return apply_filters('wpinv_get_option_' . $key, $value, $key, $default); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -77,11 +77,11 @@ discard block |
||
77 | 77 | * @param array $options the new options. |
78 | 78 | * @return bool |
79 | 79 | */ |
80 | -function wpinv_update_options( $options ) { |
|
80 | +function wpinv_update_options($options) { |
|
81 | 81 | global $wpinv_options; |
82 | 82 | |
83 | 83 | // update the option. |
84 | - if ( is_array( $options ) && update_option( 'wpinv_settings', $options ) ) { |
|
84 | + if (is_array($options) && update_option('wpinv_settings', $options)) { |
|
85 | 85 | $wpinv_options = $options; |
86 | 86 | return true; |
87 | 87 | } |
@@ -96,24 +96,24 @@ discard block |
||
96 | 96 | * @param mixed $value The setting value. |
97 | 97 | * @return bool |
98 | 98 | */ |
99 | -function wpinv_update_option( $key = '', $value = false ) { |
|
99 | +function wpinv_update_option($key = '', $value = false) { |
|
100 | 100 | |
101 | 101 | // If no key, exit. |
102 | - if ( empty( $key ) ) { |
|
102 | + if (empty($key)) { |
|
103 | 103 | return false; |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Maybe delete the option instead. |
107 | - if ( is_null( $value ) ) { |
|
108 | - return wpinv_delete_option( $key ); |
|
107 | + if (is_null($value)) { |
|
108 | + return wpinv_delete_option($key); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | // Prepare the new options. |
112 | 112 | $options = wpinv_get_options(); |
113 | - $options[ $key ] = apply_filters( 'wpinv_update_option', $value, $key ); |
|
113 | + $options[$key] = apply_filters('wpinv_update_option', $value, $key); |
|
114 | 114 | |
115 | 115 | // Save the new options. |
116 | - return wpinv_update_options( $options ); |
|
116 | + return wpinv_update_options($options); |
|
117 | 117 | |
118 | 118 | } |
119 | 119 | |
@@ -123,18 +123,18 @@ discard block |
||
123 | 123 | * @param string $key the setting key. |
124 | 124 | * @return bool |
125 | 125 | */ |
126 | -function wpinv_delete_option( $key = '' ) { |
|
126 | +function wpinv_delete_option($key = '') { |
|
127 | 127 | |
128 | 128 | // If no key, exit |
129 | - if ( empty( $key ) ) { |
|
129 | + if (empty($key)) { |
|
130 | 130 | return false; |
131 | 131 | } |
132 | 132 | |
133 | 133 | $options = wpinv_get_options(); |
134 | 134 | |
135 | - if ( isset( $options[ $key ] ) ) { |
|
136 | - unset( $options[ $key ] ); |
|
137 | - return wpinv_update_options( $options ); |
|
135 | + if (isset($options[$key])) { |
|
136 | + unset($options[$key]); |
|
137 | + return wpinv_update_options($options); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | return true; |
@@ -148,14 +148,14 @@ discard block |
||
148 | 148 | function wpinv_register_settings() { |
149 | 149 | |
150 | 150 | // Loop through all tabs. |
151 | - foreach ( wpinv_get_registered_settings() as $tab => $sections ) { |
|
151 | + foreach (wpinv_get_registered_settings() as $tab => $sections) { |
|
152 | 152 | |
153 | 153 | // In each tab, loop through sections. |
154 | - foreach ( $sections as $section => $settings ) { |
|
154 | + foreach ($sections as $section => $settings) { |
|
155 | 155 | |
156 | 156 | // Check for backwards compatibility |
157 | - $section_tabs = wpinv_get_settings_tab_sections( $tab ); |
|
158 | - if ( ! is_array( $section_tabs ) || ! array_key_exists( $section, $section_tabs ) ) { |
|
157 | + $section_tabs = wpinv_get_settings_tab_sections($tab); |
|
158 | + if (!is_array($section_tabs) || !array_key_exists($section, $section_tabs)) { |
|
159 | 159 | $section = 'main'; |
160 | 160 | $settings = $sections; |
161 | 161 | } |
@@ -168,9 +168,9 @@ discard block |
||
168 | 168 | 'wpinv_settings_' . $tab . '_' . $section |
169 | 169 | ); |
170 | 170 | |
171 | - foreach ( $settings as $option ) { |
|
172 | - if ( ! empty( $option['id'] ) ) { |
|
173 | - wpinv_register_settings_option( $tab, $section, $option ); |
|
171 | + foreach ($settings as $option) { |
|
172 | + if (!empty($option['id'])) { |
|
173 | + wpinv_register_settings_option($tab, $section, $option); |
|
174 | 174 | } |
175 | 175 | } |
176 | 176 | |
@@ -178,9 +178,9 @@ discard block |
||
178 | 178 | } |
179 | 179 | |
180 | 180 | // Creates our settings in the options table. |
181 | - register_setting( 'wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize' ); |
|
181 | + register_setting('wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize'); |
|
182 | 182 | } |
183 | -add_action( 'admin_init', 'wpinv_register_settings' ); |
|
183 | +add_action('admin_init', 'wpinv_register_settings'); |
|
184 | 184 | |
185 | 185 | /** |
186 | 186 | * Register a single settings option. |
@@ -190,46 +190,46 @@ discard block |
||
190 | 190 | * @param string $option |
191 | 191 | * |
192 | 192 | */ |
193 | -function wpinv_register_settings_option( $tab, $section, $option ) { |
|
193 | +function wpinv_register_settings_option($tab, $section, $option) { |
|
194 | 194 | |
195 | - $name = isset( $option['name'] ) ? $option['name'] : ''; |
|
195 | + $name = isset($option['name']) ? $option['name'] : ''; |
|
196 | 196 | $cb = "wpinv_{$option['type']}_callback"; |
197 | 197 | $section = "wpinv_settings_{$tab}_$section"; |
198 | 198 | |
199 | - if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) { |
|
200 | - $tip = esc_attr( $option['desc'] ); |
|
199 | + if (isset($option['desc']) && !empty($option['help-tip'])) { |
|
200 | + $tip = esc_attr($option['desc']); |
|
201 | 201 | $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
202 | - unset( $option['desc'] ); |
|
202 | + unset($option['desc']); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | // Loop through all tabs. |
206 | 206 | add_settings_field( |
207 | 207 | 'wpinv_settings[' . $option['id'] . ']', |
208 | 208 | $name, |
209 | - function_exists( $cb ) ? $cb : 'wpinv_missing_callback', |
|
209 | + function_exists($cb) ? $cb : 'wpinv_missing_callback', |
|
210 | 210 | $section, |
211 | 211 | $section, |
212 | 212 | array( |
213 | 213 | 'section' => $section, |
214 | - 'id' => isset( $option['id'] ) ? $option['id'] : null, |
|
215 | - 'desc' => isset( $option['desc'] ) ? $option['desc'] : '', |
|
214 | + 'id' => isset($option['id']) ? $option['id'] : null, |
|
215 | + 'desc' => isset($option['desc']) ? $option['desc'] : '', |
|
216 | 216 | 'name' => $name, |
217 | - 'size' => isset( $option['size'] ) ? $option['size'] : null, |
|
218 | - 'options' => isset( $option['options'] ) ? $option['options'] : '', |
|
219 | - 'selected' => isset( $option['selected'] ) ? $option['selected'] : null, |
|
220 | - 'std' => isset( $option['std'] ) ? $option['std'] : '', |
|
221 | - 'min' => isset( $option['min'] ) ? $option['min'] : null, |
|
222 | - 'max' => isset( $option['max'] ) ? $option['max'] : null, |
|
223 | - 'step' => isset( $option['step'] ) ? $option['step'] : null, |
|
224 | - 'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : null, |
|
225 | - 'allow_blank' => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true, |
|
226 | - 'readonly' => isset( $option['readonly'] ) ? $option['readonly'] : false, |
|
227 | - 'faux' => isset( $option['faux'] ) ? $option['faux'] : false, |
|
228 | - 'onchange' => isset( $option['onchange'] ) ? $option['onchange'] : '', |
|
229 | - 'custom' => isset( $option['custom'] ) ? $option['custom'] : '', |
|
230 | - 'class' => isset( $option['class'] ) ? $option['class'] : '', |
|
231 | - 'cols' => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50, |
|
232 | - 'rows' => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5, |
|
217 | + 'size' => isset($option['size']) ? $option['size'] : null, |
|
218 | + 'options' => isset($option['options']) ? $option['options'] : '', |
|
219 | + 'selected' => isset($option['selected']) ? $option['selected'] : null, |
|
220 | + 'std' => isset($option['std']) ? $option['std'] : '', |
|
221 | + 'min' => isset($option['min']) ? $option['min'] : null, |
|
222 | + 'max' => isset($option['max']) ? $option['max'] : null, |
|
223 | + 'step' => isset($option['step']) ? $option['step'] : null, |
|
224 | + 'placeholder' => isset($option['placeholder']) ? $option['placeholder'] : null, |
|
225 | + 'allow_blank' => isset($option['allow_blank']) ? $option['allow_blank'] : true, |
|
226 | + 'readonly' => isset($option['readonly']) ? $option['readonly'] : false, |
|
227 | + 'faux' => isset($option['faux']) ? $option['faux'] : false, |
|
228 | + 'onchange' => isset($option['onchange']) ? $option['onchange'] : '', |
|
229 | + 'custom' => isset($option['custom']) ? $option['custom'] : '', |
|
230 | + 'class' => isset($option['class']) ? $option['class'] : '', |
|
231 | + 'cols' => isset($option['cols']) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50, |
|
232 | + 'rows' => isset($option['rows']) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5, |
|
233 | 233 | ) |
234 | 234 | ); |
235 | 235 | |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @return array |
242 | 242 | */ |
243 | 243 | function wpinv_get_registered_settings() { |
244 | - return apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ); |
|
244 | + return apply_filters('wpinv_registered_settings', wpinv_get_data('admin-settings')); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -249,137 +249,137 @@ discard block |
||
249 | 249 | * |
250 | 250 | * @return array |
251 | 251 | */ |
252 | -function wpinv_settings_sanitize( $input = array() ) { |
|
252 | +function wpinv_settings_sanitize($input = array()) { |
|
253 | 253 | |
254 | 254 | $wpinv_options = wpinv_get_options(); |
255 | 255 | |
256 | - if ( empty( wp_get_raw_referer() ) ) { |
|
256 | + if (empty(wp_get_raw_referer())) { |
|
257 | 257 | return $input; |
258 | 258 | } |
259 | 259 | |
260 | - wp_parse_str( wp_get_raw_referer(), $referrer ); |
|
260 | + wp_parse_str(wp_get_raw_referer(), $referrer); |
|
261 | 261 | |
262 | 262 | $settings = wpinv_get_registered_settings(); |
263 | - $tab = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general'; |
|
264 | - $section = isset( $referrer['section'] ) ? $referrer['section'] : 'main'; |
|
263 | + $tab = isset($referrer['tab']) ? $referrer['tab'] : 'general'; |
|
264 | + $section = isset($referrer['section']) ? $referrer['section'] : 'main'; |
|
265 | 265 | |
266 | 266 | $input = $input ? $input : array(); |
267 | - $input = apply_filters( 'wpinv_settings_tab_' . $tab . '_sanitize', $input ); |
|
268 | - $input = apply_filters( 'wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input ); |
|
267 | + $input = apply_filters('wpinv_settings_tab_' . $tab . '_sanitize', $input); |
|
268 | + $input = apply_filters('wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input); |
|
269 | 269 | |
270 | 270 | // Loop through each setting being saved and pass it through a sanitization filter |
271 | - foreach ( $input as $key => $value ) { |
|
271 | + foreach ($input as $key => $value) { |
|
272 | 272 | |
273 | 273 | // Get the setting type (checkbox, select, etc) |
274 | - $type = isset( $settings[ $tab ][$section][ $key ]['type'] ) ? $settings[ $tab ][$section][ $key ]['type'] : false; |
|
274 | + $type = isset($settings[$tab][$section][$key]['type']) ? $settings[$tab][$section][$key]['type'] : false; |
|
275 | 275 | |
276 | - if ( $type ) { |
|
276 | + if ($type) { |
|
277 | 277 | // Field type specific filter |
278 | - $input[$key] = apply_filters( 'wpinv_settings_sanitize_' . $type, $value, $key ); |
|
278 | + $input[$key] = apply_filters('wpinv_settings_sanitize_' . $type, $value, $key); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | // General filter |
282 | - $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
282 | + $input[$key] = apply_filters('wpinv_settings_sanitize', $input[$key], $key); |
|
283 | 283 | |
284 | 284 | // Key specific filter. |
285 | - $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] ); |
|
285 | + $input[$key] = apply_filters("wpinv_settings_sanitize_$key", $input[$key]); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | // Loop through the whitelist and unset any that are empty for the tab being saved |
289 | - $main_settings = $section == 'main' ? $settings[ $tab ] : array(); // Check for extensions that aren't using new sections |
|
290 | - $section_settings = ! empty( $settings[ $tab ][ $section ] ) ? $settings[ $tab ][ $section ] : array(); |
|
289 | + $main_settings = $section == 'main' ? $settings[$tab] : array(); // Check for extensions that aren't using new sections |
|
290 | + $section_settings = !empty($settings[$tab][$section]) ? $settings[$tab][$section] : array(); |
|
291 | 291 | |
292 | - $found_settings = array_merge( $main_settings, $section_settings ); |
|
292 | + $found_settings = array_merge($main_settings, $section_settings); |
|
293 | 293 | |
294 | - if ( ! empty( $found_settings ) ) { |
|
295 | - foreach ( $found_settings as $key => $value ) { |
|
294 | + if (!empty($found_settings)) { |
|
295 | + foreach ($found_settings as $key => $value) { |
|
296 | 296 | |
297 | 297 | // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work |
298 | - if ( is_numeric( $key ) ) { |
|
298 | + if (is_numeric($key)) { |
|
299 | 299 | $key = $value['id']; |
300 | 300 | } |
301 | 301 | |
302 | - if ( ! isset( $input[ $key ] ) && isset( $wpinv_options[ $key ] ) ) { |
|
303 | - unset( $wpinv_options[ $key ] ); |
|
302 | + if (!isset($input[$key]) && isset($wpinv_options[$key])) { |
|
303 | + unset($wpinv_options[$key]); |
|
304 | 304 | } |
305 | 305 | } |
306 | 306 | } |
307 | 307 | |
308 | 308 | // Merge our new settings with the existing |
309 | - $output = array_merge( $wpinv_options, $input ); |
|
309 | + $output = array_merge($wpinv_options, $input); |
|
310 | 310 | |
311 | - add_settings_error( 'wpinv-notices', '', __( 'Settings updated.', 'invoicing' ), 'updated' ); |
|
311 | + add_settings_error('wpinv-notices', '', __('Settings updated.', 'invoicing'), 'updated'); |
|
312 | 312 | |
313 | 313 | return $output; |
314 | 314 | } |
315 | 315 | |
316 | -function wpinv_settings_sanitize_misc_accounting( $input ) { |
|
316 | +function wpinv_settings_sanitize_misc_accounting($input) { |
|
317 | 317 | |
318 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
318 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
319 | 319 | return $input; |
320 | 320 | } |
321 | 321 | |
322 | - if( ! empty( $input['enable_sequential'] ) && !wpinv_get_option( 'enable_sequential' ) ) { |
|
322 | + if (!empty($input['enable_sequential']) && !wpinv_get_option('enable_sequential')) { |
|
323 | 323 | // Shows an admin notice about upgrading previous order numbers |
324 | - getpaid_session()->set( 'upgrade_sequential', '1' ); |
|
324 | + getpaid_session()->set('upgrade_sequential', '1'); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | return $input; |
328 | 328 | } |
329 | -add_filter( 'wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting' ); |
|
329 | +add_filter('wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting'); |
|
330 | 330 | |
331 | -function wpinv_settings_sanitize_tax_rates( $input ) { |
|
332 | - if( ! wpinv_current_user_can_manage_invoicing() ) { |
|
331 | +function wpinv_settings_sanitize_tax_rates($input) { |
|
332 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
333 | 333 | return $input; |
334 | 334 | } |
335 | 335 | |
336 | - $new_rates = !empty( $_POST['tax_rates'] ) ? array_values( $_POST['tax_rates'] ) : array(); |
|
336 | + $new_rates = !empty($_POST['tax_rates']) ? array_values($_POST['tax_rates']) : array(); |
|
337 | 337 | |
338 | 338 | $tax_rates = array(); |
339 | 339 | |
340 | - if ( !empty( $new_rates ) ) { |
|
341 | - foreach ( $new_rates as $rate ) { |
|
342 | - if ( isset( $rate['country'] ) && empty( $rate['country'] ) && empty( $rate['state'] ) ) { |
|
340 | + if (!empty($new_rates)) { |
|
341 | + foreach ($new_rates as $rate) { |
|
342 | + if (isset($rate['country']) && empty($rate['country']) && empty($rate['state'])) { |
|
343 | 343 | continue; |
344 | 344 | } |
345 | 345 | |
346 | - $rate['rate'] = wpinv_sanitize_amount( $rate['rate'], 4 ); |
|
346 | + $rate['rate'] = wpinv_sanitize_amount($rate['rate'], 4); |
|
347 | 347 | |
348 | 348 | $tax_rates[] = $rate; |
349 | 349 | } |
350 | 350 | } |
351 | 351 | |
352 | - update_option( 'wpinv_tax_rates', $tax_rates ); |
|
352 | + update_option('wpinv_tax_rates', $tax_rates); |
|
353 | 353 | |
354 | 354 | return $input; |
355 | 355 | } |
356 | -add_filter( 'wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates' ); |
|
356 | +add_filter('wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates'); |
|
357 | 357 | |
358 | -function wpinv_sanitize_text_field( $input ) { |
|
359 | - return trim( $input ); |
|
358 | +function wpinv_sanitize_text_field($input) { |
|
359 | + return trim($input); |
|
360 | 360 | } |
361 | -add_filter( 'wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field' ); |
|
361 | +add_filter('wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field'); |
|
362 | 362 | |
363 | 363 | function wpinv_get_settings_tabs() { |
364 | 364 | $tabs = array(); |
365 | - $tabs['general'] = __( 'General', 'invoicing' ); |
|
366 | - $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' ); |
|
367 | - $tabs['taxes'] = __( 'Taxes', 'invoicing' ); |
|
368 | - $tabs['emails'] = __( 'Emails', 'invoicing' ); |
|
369 | - $tabs['privacy'] = __( 'Privacy', 'invoicing' ); |
|
370 | - $tabs['misc'] = __( 'Misc', 'invoicing' ); |
|
371 | - $tabs['tools'] = __( 'Tools', 'invoicing' ); |
|
372 | - |
|
373 | - return apply_filters( 'wpinv_settings_tabs', $tabs ); |
|
365 | + $tabs['general'] = __('General', 'invoicing'); |
|
366 | + $tabs['gateways'] = __('Payment Gateways', 'invoicing'); |
|
367 | + $tabs['taxes'] = __('Taxes', 'invoicing'); |
|
368 | + $tabs['emails'] = __('Emails', 'invoicing'); |
|
369 | + $tabs['privacy'] = __('Privacy', 'invoicing'); |
|
370 | + $tabs['misc'] = __('Misc', 'invoicing'); |
|
371 | + $tabs['tools'] = __('Tools', 'invoicing'); |
|
372 | + |
|
373 | + return apply_filters('wpinv_settings_tabs', $tabs); |
|
374 | 374 | } |
375 | 375 | |
376 | -function wpinv_get_settings_tab_sections( $tab = false ) { |
|
376 | +function wpinv_get_settings_tab_sections($tab = false) { |
|
377 | 377 | $tabs = false; |
378 | 378 | $sections = wpinv_get_registered_settings_sections(); |
379 | 379 | |
380 | - if( $tab && ! empty( $sections[ $tab ] ) ) { |
|
381 | - $tabs = $sections[ $tab ]; |
|
382 | - } else if ( $tab ) { |
|
380 | + if ($tab && !empty($sections[$tab])) { |
|
381 | + $tabs = $sections[$tab]; |
|
382 | + } else if ($tab) { |
|
383 | 383 | $tabs = false; |
384 | 384 | } |
385 | 385 | |
@@ -389,149 +389,149 @@ discard block |
||
389 | 389 | function wpinv_get_registered_settings_sections() { |
390 | 390 | static $sections = false; |
391 | 391 | |
392 | - if ( false !== $sections ) { |
|
392 | + if (false !== $sections) { |
|
393 | 393 | return $sections; |
394 | 394 | } |
395 | 395 | |
396 | 396 | $sections = array( |
397 | - 'general' => apply_filters( 'wpinv_settings_sections_general', array( |
|
398 | - 'main' => __( 'General Settings', 'invoicing' ), |
|
399 | - 'currency_section' => __( 'Currency Settings', 'invoicing' ), |
|
400 | - 'labels' => __( 'Label Texts', 'invoicing' ), |
|
401 | - ) ), |
|
402 | - 'gateways' => apply_filters( 'wpinv_settings_sections_gateways', array( |
|
403 | - 'main' => __( 'Gateway Settings', 'invoicing' ), |
|
404 | - ) ), |
|
405 | - 'taxes' => apply_filters( 'wpinv_settings_sections_taxes', array( |
|
406 | - 'main' => __( 'Tax Settings', 'invoicing' ), |
|
407 | - 'rates' => __( 'Tax Rates', 'invoicing' ), |
|
408 | - ) ), |
|
409 | - 'emails' => apply_filters( 'wpinv_settings_sections_emails', array( |
|
410 | - 'main' => __( 'Email Settings', 'invoicing' ), |
|
411 | - ) ), |
|
412 | - 'privacy' => apply_filters( 'wpinv_settings_sections_privacy', array( |
|
413 | - 'main' => __( 'Privacy policy', 'invoicing' ), |
|
414 | - ) ), |
|
415 | - 'misc' => apply_filters( 'wpinv_settings_sections_misc', array( |
|
416 | - 'main' => __( 'Miscellaneous', 'invoicing' ), |
|
417 | - 'custom-css' => __( 'Custom CSS', 'invoicing' ), |
|
418 | - ) ), |
|
419 | - 'tools' => apply_filters( 'wpinv_settings_sections_tools', array( |
|
420 | - 'main' => __( 'Diagnostic Tools', 'invoicing' ), |
|
421 | - ) ), |
|
397 | + 'general' => apply_filters('wpinv_settings_sections_general', array( |
|
398 | + 'main' => __('General Settings', 'invoicing'), |
|
399 | + 'currency_section' => __('Currency Settings', 'invoicing'), |
|
400 | + 'labels' => __('Label Texts', 'invoicing'), |
|
401 | + )), |
|
402 | + 'gateways' => apply_filters('wpinv_settings_sections_gateways', array( |
|
403 | + 'main' => __('Gateway Settings', 'invoicing'), |
|
404 | + )), |
|
405 | + 'taxes' => apply_filters('wpinv_settings_sections_taxes', array( |
|
406 | + 'main' => __('Tax Settings', 'invoicing'), |
|
407 | + 'rates' => __('Tax Rates', 'invoicing'), |
|
408 | + )), |
|
409 | + 'emails' => apply_filters('wpinv_settings_sections_emails', array( |
|
410 | + 'main' => __('Email Settings', 'invoicing'), |
|
411 | + )), |
|
412 | + 'privacy' => apply_filters('wpinv_settings_sections_privacy', array( |
|
413 | + 'main' => __('Privacy policy', 'invoicing'), |
|
414 | + )), |
|
415 | + 'misc' => apply_filters('wpinv_settings_sections_misc', array( |
|
416 | + 'main' => __('Miscellaneous', 'invoicing'), |
|
417 | + 'custom-css' => __('Custom CSS', 'invoicing'), |
|
418 | + )), |
|
419 | + 'tools' => apply_filters('wpinv_settings_sections_tools', array( |
|
420 | + 'main' => __('Diagnostic Tools', 'invoicing'), |
|
421 | + )), |
|
422 | 422 | ); |
423 | 423 | |
424 | - $sections = apply_filters( 'wpinv_settings_sections', $sections ); |
|
424 | + $sections = apply_filters('wpinv_settings_sections', $sections); |
|
425 | 425 | |
426 | 426 | return $sections; |
427 | 427 | } |
428 | 428 | |
429 | -function wpinv_get_pages( $with_slug = false, $default_label = NULL ) { |
|
429 | +function wpinv_get_pages($with_slug = false, $default_label = NULL) { |
|
430 | 430 | $pages_options = array(); |
431 | 431 | |
432 | - if( $default_label !== NULL && $default_label !== false ) { |
|
433 | - $pages_options = array( '' => $default_label ); // Blank option |
|
432 | + if ($default_label !== NULL && $default_label !== false) { |
|
433 | + $pages_options = array('' => $default_label); // Blank option |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | $pages = get_pages(); |
437 | - if ( $pages ) { |
|
438 | - foreach ( $pages as $page ) { |
|
437 | + if ($pages) { |
|
438 | + foreach ($pages as $page) { |
|
439 | 439 | $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
440 | - $pages_options[ $page->ID ] = $title; |
|
440 | + $pages_options[$page->ID] = $title; |
|
441 | 441 | } |
442 | 442 | } |
443 | 443 | |
444 | 444 | return $pages_options; |
445 | 445 | } |
446 | 446 | |
447 | -function wpinv_header_callback( $args ) { |
|
448 | - if ( !empty( $args['desc'] ) ) { |
|
447 | +function wpinv_header_callback($args) { |
|
448 | + if (!empty($args['desc'])) { |
|
449 | 449 | echo $args['desc']; |
450 | 450 | } |
451 | 451 | } |
452 | 452 | |
453 | -function wpinv_hidden_callback( $args ) { |
|
453 | +function wpinv_hidden_callback($args) { |
|
454 | 454 | global $wpinv_options; |
455 | 455 | |
456 | - if ( isset( $args['set_value'] ) ) { |
|
456 | + if (isset($args['set_value'])) { |
|
457 | 457 | $value = $args['set_value']; |
458 | - } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
459 | - $value = $wpinv_options[ $args['id'] ]; |
|
458 | + } elseif (isset($wpinv_options[$args['id']])) { |
|
459 | + $value = $wpinv_options[$args['id']]; |
|
460 | 460 | } else { |
461 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
461 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
462 | 462 | } |
463 | 463 | |
464 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
464 | + if (isset($args['faux']) && true === $args['faux']) { |
|
465 | 465 | $args['readonly'] = true; |
466 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
466 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
467 | 467 | $name = ''; |
468 | 468 | } else { |
469 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
469 | + $name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"'; |
|
470 | 470 | } |
471 | 471 | |
472 | - $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
472 | + $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key($args['id']) . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '" />'; |
|
473 | 473 | |
474 | 474 | echo $html; |
475 | 475 | } |
476 | 476 | |
477 | -function wpinv_checkbox_callback( $args ) { |
|
477 | +function wpinv_checkbox_callback($args) { |
|
478 | 478 | global $wpinv_options; |
479 | 479 | |
480 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
480 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
481 | 481 | |
482 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
482 | + if (isset($args['faux']) && true === $args['faux']) { |
|
483 | 483 | $name = ''; |
484 | 484 | } else { |
485 | 485 | $name = 'name="wpinv_settings[' . $sanitize_id . ']"'; |
486 | 486 | } |
487 | 487 | |
488 | - $std = isset( $args['std'] ) ? $args['std'] : 0; |
|
489 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
490 | - $checked = checked( empty( $value ), false, false ); |
|
488 | + $std = isset($args['std']) ? $args['std'] : 0; |
|
489 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : $std; |
|
490 | + $checked = checked(empty($value), false, false); |
|
491 | 491 | |
492 | 492 | $html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>'; |
493 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
493 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
494 | 494 | |
495 | 495 | echo $html; |
496 | 496 | } |
497 | 497 | |
498 | -function wpinv_multicheck_callback( $args ) { |
|
498 | +function wpinv_multicheck_callback($args) { |
|
499 | 499 | global $wpinv_options; |
500 | 500 | |
501 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
502 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
501 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
502 | + $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : ''; |
|
503 | 503 | |
504 | - if ( ! empty( $args['options'] ) ) { |
|
504 | + if (!empty($args['options'])) { |
|
505 | 505 | |
506 | - $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
507 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
506 | + $std = isset($args['std']) ? $args['std'] : array(); |
|
507 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : $std; |
|
508 | 508 | |
509 | 509 | echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">'; |
510 | - foreach( $args['options'] as $key => $option ): |
|
511 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
512 | - if ( in_array( $sanitize_key, $value ) ) { |
|
510 | + foreach ($args['options'] as $key => $option): |
|
511 | + $sanitize_key = wpinv_sanitize_key($key); |
|
512 | + if (in_array($sanitize_key, $value)) { |
|
513 | 513 | $enabled = $sanitize_key; |
514 | 514 | } else { |
515 | 515 | $enabled = NULL; |
516 | 516 | } |
517 | - echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
518 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
517 | + echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($sanitize_key) . '" ' . checked($sanitize_key, $enabled, false) . '/> '; |
|
518 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post($option) . '</label></div>'; |
|
519 | 519 | endforeach; |
520 | 520 | echo '</div>'; |
521 | 521 | echo '<p class="description">' . $args['desc'] . '</p>'; |
522 | 522 | } |
523 | 523 | } |
524 | 524 | |
525 | -function wpinv_payment_icons_callback( $args ) { |
|
525 | +function wpinv_payment_icons_callback($args) { |
|
526 | 526 | global $wpinv_options; |
527 | 527 | |
528 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
528 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
529 | 529 | |
530 | - if ( ! empty( $args['options'] ) ) { |
|
531 | - foreach( $args['options'] as $key => $option ) { |
|
532 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
530 | + if (!empty($args['options'])) { |
|
531 | + foreach ($args['options'] as $key => $option) { |
|
532 | + $sanitize_key = wpinv_sanitize_key($key); |
|
533 | 533 | |
534 | - if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
534 | + if (isset($wpinv_options[$args['id']][$key])) { |
|
535 | 535 | $enabled = $option; |
536 | 536 | } else { |
537 | 537 | $enabled = NULL; |
@@ -539,197 +539,197 @@ discard block |
||
539 | 539 | |
540 | 540 | echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
541 | 541 | |
542 | - echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
542 | + echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($option) . '" ' . checked($option, $enabled, false) . '/> '; |
|
543 | 543 | |
544 | - if ( wpinv_string_is_image_url( $key ) ) { |
|
545 | - echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
544 | + if (wpinv_string_is_image_url($key)) { |
|
545 | + echo '<img class="payment-icon" src="' . esc_url($key) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
546 | 546 | } else { |
547 | - $card = strtolower( str_replace( ' ', '', $option ) ); |
|
547 | + $card = strtolower(str_replace(' ', '', $option)); |
|
548 | 548 | |
549 | - if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
550 | - $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
549 | + if (has_filter('wpinv_accepted_payment_' . $card . '_image')) { |
|
550 | + $image = apply_filters('wpinv_accepted_payment_' . $card . '_image', ''); |
|
551 | 551 | } else { |
552 | - $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
552 | + $image = wpinv_locate_template('images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false); |
|
553 | 553 | $content_dir = WP_CONTENT_DIR; |
554 | 554 | |
555 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
555 | + if (function_exists('wp_normalize_path')) { |
|
556 | 556 | // Replaces backslashes with forward slashes for Windows systems |
557 | - $image = wp_normalize_path( $image ); |
|
558 | - $content_dir = wp_normalize_path( $content_dir ); |
|
557 | + $image = wp_normalize_path($image); |
|
558 | + $content_dir = wp_normalize_path($content_dir); |
|
559 | 559 | } |
560 | 560 | |
561 | - $image = str_replace( $content_dir, content_url(), $image ); |
|
561 | + $image = str_replace($content_dir, content_url(), $image); |
|
562 | 562 | } |
563 | 563 | |
564 | - echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
564 | + echo '<img class="payment-icon" src="' . esc_url($image) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
565 | 565 | } |
566 | 566 | echo $option . '</label>'; |
567 | 567 | } |
568 | - echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
568 | + echo '<p class="description" style="margin-top:16px;">' . wp_kses_post($args['desc']) . '</p>'; |
|
569 | 569 | } |
570 | 570 | } |
571 | 571 | |
572 | -function wpinv_radio_callback( $args ) { |
|
572 | +function wpinv_radio_callback($args) { |
|
573 | 573 | global $wpinv_options; |
574 | 574 | |
575 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
575 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
576 | 576 | |
577 | - foreach ( $args['options'] as $key => $option ) : |
|
578 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
577 | + foreach ($args['options'] as $key => $option) : |
|
578 | + $sanitize_key = wpinv_sanitize_key($key); |
|
579 | 579 | |
580 | 580 | $checked = false; |
581 | 581 | |
582 | - if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key ) |
|
582 | + if (isset($wpinv_options[$args['id']]) && $wpinv_options[$args['id']] == $key) |
|
583 | 583 | $checked = true; |
584 | - elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) ) |
|
584 | + elseif (isset($args['std']) && $args['std'] == $key && !isset($wpinv_options[$args['id']])) |
|
585 | 585 | $checked = true; |
586 | 586 | |
587 | 587 | echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/> '; |
588 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>'; |
|
588 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option) . '</label><br/>'; |
|
589 | 589 | endforeach; |
590 | 590 | |
591 | - echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
591 | + echo '<p class="description">' . wp_kses_post($args['desc']) . '</p>'; |
|
592 | 592 | } |
593 | 593 | |
594 | -function wpinv_gateways_callback( $args ) { |
|
594 | +function wpinv_gateways_callback($args) { |
|
595 | 595 | global $wpinv_options; |
596 | 596 | |
597 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
597 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
598 | 598 | |
599 | - foreach ( $args['options'] as $key => $option ) : |
|
600 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
599 | + foreach ($args['options'] as $key => $option) : |
|
600 | + $sanitize_key = wpinv_sanitize_key($key); |
|
601 | 601 | |
602 | - if ( isset( $wpinv_options['gateways'][ $key ] ) ) |
|
602 | + if (isset($wpinv_options['gateways'][$key])) |
|
603 | 603 | $enabled = '1'; |
604 | 604 | else |
605 | 605 | $enabled = null; |
606 | 606 | |
607 | - echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
608 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
607 | + echo '<input name="wpinv_settings[' . esc_attr($args['id']) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
608 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option['admin_label']) . '</label><br/>'; |
|
609 | 609 | endforeach; |
610 | 610 | } |
611 | 611 | |
612 | 612 | function wpinv_gateway_select_callback($args) { |
613 | 613 | global $wpinv_options; |
614 | 614 | |
615 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
616 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
615 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
616 | + $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : ''; |
|
617 | 617 | |
618 | - echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >'; |
|
618 | + echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="' . $class . '" >'; |
|
619 | 619 | |
620 | - foreach ( $args['options'] as $key => $option ) : |
|
621 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
622 | - $selected = selected( $key, $args['selected'], false ); |
|
620 | + foreach ($args['options'] as $key => $option) : |
|
621 | + if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) { |
|
622 | + $selected = selected($key, $args['selected'], false); |
|
623 | 623 | } else { |
624 | - $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : ''; |
|
624 | + $selected = isset($wpinv_options[$args['id']]) ? selected($key, $wpinv_options[$args['id']], false) : ''; |
|
625 | 625 | } |
626 | - echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
626 | + echo '<option value="' . wpinv_sanitize_key($key) . '"' . $selected . '>' . esc_html($option['admin_label']) . '</option>'; |
|
627 | 627 | endforeach; |
628 | 628 | |
629 | 629 | echo '</select>'; |
630 | - echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
630 | + echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
631 | 631 | } |
632 | 632 | |
633 | -function wpinv_text_callback( $args ) { |
|
633 | +function wpinv_text_callback($args) { |
|
634 | 634 | global $wpinv_options; |
635 | 635 | |
636 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
636 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
637 | 637 | |
638 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
639 | - $value = $wpinv_options[ $args['id'] ]; |
|
638 | + if (isset($wpinv_options[$args['id']])) { |
|
639 | + $value = $wpinv_options[$args['id']]; |
|
640 | 640 | } else { |
641 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
641 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
642 | 642 | } |
643 | 643 | |
644 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
644 | + if (isset($args['faux']) && true === $args['faux']) { |
|
645 | 645 | $args['readonly'] = true; |
646 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
646 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
647 | 647 | $name = ''; |
648 | 648 | } else { |
649 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
649 | + $name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"'; |
|
650 | 650 | } |
651 | - $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
651 | + $class = !empty($args['class']) ? sanitize_html_class($args['class']) : ''; |
|
652 | 652 | |
653 | 653 | $readonly = $args['readonly'] === true ? ' readonly="readonly"' : ''; |
654 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
655 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>'; |
|
656 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
654 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
655 | + $html = '<input type="text" class="' . sanitize_html_class($size) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"' . $readonly . '/>'; |
|
656 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
657 | 657 | |
658 | 658 | echo $html; |
659 | 659 | } |
660 | 660 | |
661 | -function wpinv_number_callback( $args ) { |
|
661 | +function wpinv_number_callback($args) { |
|
662 | 662 | global $wpinv_options; |
663 | 663 | |
664 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
664 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
665 | 665 | |
666 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
667 | - $value = $wpinv_options[ $args['id'] ]; |
|
666 | + if (isset($wpinv_options[$args['id']])) { |
|
667 | + $value = $wpinv_options[$args['id']]; |
|
668 | 668 | } else { |
669 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
669 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
670 | 670 | } |
671 | 671 | |
672 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
672 | + if (isset($args['faux']) && true === $args['faux']) { |
|
673 | 673 | $args['readonly'] = true; |
674 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
674 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
675 | 675 | $name = ''; |
676 | 676 | } else { |
677 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
677 | + $name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"'; |
|
678 | 678 | } |
679 | 679 | |
680 | - $max = isset( $args['max'] ) ? $args['max'] : 999999; |
|
681 | - $min = isset( $args['min'] ) ? $args['min'] : 0; |
|
682 | - $step = isset( $args['step'] ) ? $args['step'] : 1; |
|
683 | - $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
680 | + $max = isset($args['max']) ? $args['max'] : 999999; |
|
681 | + $min = isset($args['min']) ? $args['min'] : 0; |
|
682 | + $step = isset($args['step']) ? $args['step'] : 1; |
|
683 | + $class = !empty($args['class']) ? sanitize_html_class($args['class']) : ''; |
|
684 | 684 | |
685 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
686 | - $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
687 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
685 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
686 | + $html = '<input type="number" step="' . esc_attr($step) . '" max="' . esc_attr($max) . '" min="' . esc_attr($min) . '" class="' . sanitize_html_class($size) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"/>'; |
|
687 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
688 | 688 | |
689 | 689 | echo $html; |
690 | 690 | } |
691 | 691 | |
692 | -function wpinv_textarea_callback( $args ) { |
|
692 | +function wpinv_textarea_callback($args) { |
|
693 | 693 | global $wpinv_options; |
694 | 694 | |
695 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
695 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
696 | 696 | |
697 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
698 | - $value = $wpinv_options[ $args['id'] ]; |
|
697 | + if (isset($wpinv_options[$args['id']])) { |
|
698 | + $value = $wpinv_options[$args['id']]; |
|
699 | 699 | } else { |
700 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
700 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
701 | 701 | } |
702 | 702 | |
703 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
704 | - $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text'; |
|
703 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
704 | + $class = (isset($args['class']) && !is_null($args['class'])) ? $args['class'] : 'large-text'; |
|
705 | 705 | |
706 | - $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
707 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
706 | + $html = '<textarea class="' . sanitize_html_class($class) . ' txtarea-' . sanitize_html_class($size) . ' wpi-' . esc_attr(sanitize_html_class($sanitize_id)) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']">' . esc_textarea(stripslashes($value)) . '</textarea>'; |
|
707 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
708 | 708 | |
709 | 709 | echo $html; |
710 | 710 | } |
711 | 711 | |
712 | -function wpinv_password_callback( $args ) { |
|
712 | +function wpinv_password_callback($args) { |
|
713 | 713 | global $wpinv_options; |
714 | 714 | |
715 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
715 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
716 | 716 | |
717 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
718 | - $value = $wpinv_options[ $args['id'] ]; |
|
717 | + if (isset($wpinv_options[$args['id']])) { |
|
718 | + $value = $wpinv_options[$args['id']]; |
|
719 | 719 | } else { |
720 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
720 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
721 | 721 | } |
722 | 722 | |
723 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
724 | - $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
725 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
723 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
724 | + $html = '<input type="password" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '"/>'; |
|
725 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
726 | 726 | |
727 | 727 | echo $html; |
728 | 728 | } |
729 | 729 | |
730 | 730 | function wpinv_missing_callback($args) { |
731 | 731 | printf( |
732 | - __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
732 | + __('The callback function used for the %s setting is missing.', 'invoicing'), |
|
733 | 733 | '<strong>' . $args['id'] . '</strong>' |
734 | 734 | ); |
735 | 735 | } |
@@ -737,134 +737,134 @@ discard block |
||
737 | 737 | function wpinv_select_callback($args) { |
738 | 738 | global $wpinv_options; |
739 | 739 | |
740 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
740 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
741 | 741 | |
742 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
743 | - $value = $wpinv_options[ $args['id'] ]; |
|
742 | + if (isset($wpinv_options[$args['id']])) { |
|
743 | + $value = $wpinv_options[$args['id']]; |
|
744 | 744 | } else { |
745 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
745 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
746 | 746 | } |
747 | 747 | |
748 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
748 | + if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) { |
|
749 | 749 | $value = $args['selected']; |
750 | 750 | } |
751 | 751 | |
752 | - if ( isset( $args['placeholder'] ) ) { |
|
752 | + if (isset($args['placeholder'])) { |
|
753 | 753 | $placeholder = $args['placeholder']; |
754 | 754 | } else { |
755 | 755 | $placeholder = ''; |
756 | 756 | } |
757 | 757 | |
758 | - if( !empty( $args['onchange'] ) ) { |
|
759 | - $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
758 | + if (!empty($args['onchange'])) { |
|
759 | + $onchange = ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
760 | 760 | } else { |
761 | 761 | $onchange = ''; |
762 | 762 | } |
763 | 763 | |
764 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
764 | + $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : ''; |
|
765 | 765 | |
766 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />'; |
|
766 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="' . $class . '" name="wpinv_settings[' . esc_attr($args['id']) . ']" data-placeholder="' . esc_html($placeholder) . '"' . $onchange . ' />'; |
|
767 | 767 | |
768 | - foreach ( $args['options'] as $option => $name ) { |
|
769 | - $selected = selected( $option, $value, false ); |
|
770 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
768 | + foreach ($args['options'] as $option => $name) { |
|
769 | + $selected = selected($option, $value, false); |
|
770 | + $html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>'; |
|
771 | 771 | } |
772 | 772 | |
773 | 773 | $html .= '</select>'; |
774 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
774 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
775 | 775 | |
776 | 776 | echo $html; |
777 | 777 | } |
778 | 778 | |
779 | -function wpinv_color_select_callback( $args ) { |
|
779 | +function wpinv_color_select_callback($args) { |
|
780 | 780 | global $wpinv_options; |
781 | 781 | |
782 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
782 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
783 | 783 | |
784 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
785 | - $value = $wpinv_options[ $args['id'] ]; |
|
784 | + if (isset($wpinv_options[$args['id']])) { |
|
785 | + $value = $wpinv_options[$args['id']]; |
|
786 | 786 | } else { |
787 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
787 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
788 | 788 | } |
789 | 789 | |
790 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
790 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"/>'; |
|
791 | 791 | |
792 | - foreach ( $args['options'] as $option => $color ) { |
|
793 | - $selected = selected( $option, $value, false ); |
|
794 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
792 | + foreach ($args['options'] as $option => $color) { |
|
793 | + $selected = selected($option, $value, false); |
|
794 | + $html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($color['label']) . '</option>'; |
|
795 | 795 | } |
796 | 796 | |
797 | 797 | $html .= '</select>'; |
798 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
798 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
799 | 799 | |
800 | 800 | echo $html; |
801 | 801 | } |
802 | 802 | |
803 | -function wpinv_rich_editor_callback( $args ) { |
|
803 | +function wpinv_rich_editor_callback($args) { |
|
804 | 804 | global $wpinv_options, $wp_version; |
805 | 805 | |
806 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
806 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
807 | 807 | |
808 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
809 | - $value = $wpinv_options[ $args['id'] ]; |
|
808 | + if (isset($wpinv_options[$args['id']])) { |
|
809 | + $value = $wpinv_options[$args['id']]; |
|
810 | 810 | |
811 | - if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
812 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
811 | + if (empty($args['allow_blank']) && empty($value)) { |
|
812 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
813 | 813 | } |
814 | 814 | } else { |
815 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
815 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
816 | 816 | } |
817 | 817 | |
818 | - $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
818 | + $rows = isset($args['size']) ? $args['size'] : 20; |
|
819 | 819 | |
820 | 820 | $html = '<div class="getpaid-settings-editor-input">'; |
821 | - if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
821 | + if ($wp_version >= 3.3 && function_exists('wp_editor')) { |
|
822 | 822 | ob_start(); |
823 | - wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
823 | + wp_editor(stripslashes($value), 'wpinv_settings_' . esc_attr($args['id']), array('textarea_name' => 'wpinv_settings[' . esc_attr($args['id']) . ']', 'textarea_rows' => absint($rows), 'media_buttons' => false)); |
|
824 | 824 | $html .= ob_get_clean(); |
825 | 825 | } else { |
826 | - $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
826 | + $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" class="wpi-' . esc_attr(sanitize_html_class($args['id'])) . '">' . esc_textarea(stripslashes($value)) . '</textarea>'; |
|
827 | 827 | } |
828 | 828 | |
829 | - $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
829 | + $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
830 | 830 | |
831 | 831 | echo $html; |
832 | 832 | } |
833 | 833 | |
834 | -function wpinv_upload_callback( $args ) { |
|
834 | +function wpinv_upload_callback($args) { |
|
835 | 835 | global $wpinv_options; |
836 | 836 | |
837 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
837 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
838 | 838 | |
839 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
839 | + if (isset($wpinv_options[$args['id']])) { |
|
840 | 840 | $value = $wpinv_options[$args['id']]; |
841 | 841 | } else { |
842 | 842 | $value = isset($args['std']) ? $args['std'] : ''; |
843 | 843 | } |
844 | 844 | |
845 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
846 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
847 | - $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
848 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
845 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
846 | + $html = '<input type="text" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr(stripslashes($value)) . '"/>'; |
|
847 | + $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __('Upload File', 'invoicing') . '"/></span>'; |
|
848 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
849 | 849 | |
850 | 850 | echo $html; |
851 | 851 | } |
852 | 852 | |
853 | -function wpinv_color_callback( $args ) { |
|
853 | +function wpinv_color_callback($args) { |
|
854 | 854 | global $wpinv_options; |
855 | 855 | |
856 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
856 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
857 | 857 | |
858 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
859 | - $value = $wpinv_options[ $args['id'] ]; |
|
858 | + if (isset($wpinv_options[$args['id']])) { |
|
859 | + $value = $wpinv_options[$args['id']]; |
|
860 | 860 | } else { |
861 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
861 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
862 | 862 | } |
863 | 863 | |
864 | - $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
864 | + $default = isset($args['std']) ? $args['std'] : ''; |
|
865 | 865 | |
866 | - $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
867 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
866 | + $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '" data-default-color="' . esc_attr($default) . '" />'; |
|
867 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
868 | 868 | |
869 | 869 | echo $html; |
870 | 870 | } |
@@ -872,9 +872,9 @@ discard block |
||
872 | 872 | function wpinv_country_states_callback($args) { |
873 | 873 | global $wpinv_options; |
874 | 874 | |
875 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
875 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
876 | 876 | |
877 | - if ( isset( $args['placeholder'] ) ) { |
|
877 | + if (isset($args['placeholder'])) { |
|
878 | 878 | $placeholder = $args['placeholder']; |
879 | 879 | } else { |
880 | 880 | $placeholder = ''; |
@@ -882,16 +882,16 @@ discard block |
||
882 | 882 | |
883 | 883 | $states = wpinv_get_country_states(); |
884 | 884 | |
885 | - $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
886 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
885 | + $class = empty($states) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
886 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"' . $class . 'data-placeholder="' . esc_html($placeholder) . '"/>'; |
|
887 | 887 | |
888 | - foreach ( $states as $option => $name ) { |
|
889 | - $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
890 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
888 | + foreach ($states as $option => $name) { |
|
889 | + $selected = isset($wpinv_options[$args['id']]) ? selected($option, $wpinv_options[$args['id']], false) : ''; |
|
890 | + $html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>'; |
|
891 | 891 | } |
892 | 892 | |
893 | 893 | $html .= '</select>'; |
894 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
894 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
895 | 895 | |
896 | 896 | echo $html; |
897 | 897 | } |
@@ -906,96 +906,96 @@ discard block |
||
906 | 906 | <table id="wpinv_tax_rates" class="wp-list-table widefat fixed posts"> |
907 | 907 | <thead> |
908 | 908 | <tr> |
909 | - <th scope="col" class="wpinv_tax_country"><?php _e( 'Country', 'invoicing' ); ?></th> |
|
910 | - <th scope="col" class="wpinv_tax_state"><?php _e( 'State / Province', 'invoicing' ); ?></th> |
|
911 | - <th scope="col" class="wpinv_tax_global" title="<?php esc_attr_e( 'Apply rate to whole country, regardless of state / province', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th> |
|
912 | - <th scope="col" class="wpinv_tax_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> |
|
913 | - <th scope="col" class="wpinv_tax_name"><?php _e( 'Tax Name', 'invoicing' ); ?></th> |
|
914 | - <th scope="col" class="wpinv_tax_action"><?php _e( 'Remove', 'invoicing' ); ?></th> |
|
909 | + <th scope="col" class="wpinv_tax_country"><?php _e('Country', 'invoicing'); ?></th> |
|
910 | + <th scope="col" class="wpinv_tax_state"><?php _e('State / Province', 'invoicing'); ?></th> |
|
911 | + <th scope="col" class="wpinv_tax_global" title="<?php esc_attr_e('Apply rate to whole country, regardless of state / province', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th> |
|
912 | + <th scope="col" class="wpinv_tax_rate"><?php _e('Rate %', 'invoicing'); ?></th> |
|
913 | + <th scope="col" class="wpinv_tax_name"><?php _e('Tax Name', 'invoicing'); ?></th> |
|
914 | + <th scope="col" class="wpinv_tax_action"><?php _e('Remove', 'invoicing'); ?></th> |
|
915 | 915 | </tr> |
916 | 916 | </thead> |
917 | 917 | <tbody> |
918 | - <?php if( !empty( $rates ) ) : ?> |
|
919 | - <?php foreach( $rates as $key => $rate ) : ?> |
|
918 | + <?php if (!empty($rates)) : ?> |
|
919 | + <?php foreach ($rates as $key => $rate) : ?> |
|
920 | 920 | <?php |
921 | - $sanitized_key = wpinv_sanitize_key( $key ); |
|
921 | + $sanitized_key = wpinv_sanitize_key($key); |
|
922 | 922 | ?> |
923 | 923 | <tr> |
924 | 924 | <td class="wpinv_tax_country"> |
925 | 925 | <?php |
926 | - echo wpinv_html_select( array( |
|
927 | - 'options' => wpinv_get_country_list( true ), |
|
926 | + echo wpinv_html_select(array( |
|
927 | + 'options' => wpinv_get_country_list(true), |
|
928 | 928 | 'name' => 'tax_rates[' . $sanitized_key . '][country]', |
929 | 929 | 'id' => 'tax_rates[' . $sanitized_key . '][country]', |
930 | 930 | 'selected' => $rate['country'], |
931 | 931 | 'show_option_all' => false, |
932 | 932 | 'show_option_none' => false, |
933 | 933 | 'class' => 'wpinv-tax-country wpi_select2', |
934 | - 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
935 | - ) ); |
|
934 | + 'placeholder' => __('Choose a country', 'invoicing') |
|
935 | + )); |
|
936 | 936 | ?> |
937 | 937 | </td> |
938 | 938 | <td class="wpinv_tax_state"> |
939 | 939 | <?php |
940 | - $states = wpinv_get_country_states( $rate['country'] ); |
|
941 | - if( !empty( $states ) ) { |
|
942 | - echo wpinv_html_select( array( |
|
943 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
940 | + $states = wpinv_get_country_states($rate['country']); |
|
941 | + if (!empty($states)) { |
|
942 | + echo wpinv_html_select(array( |
|
943 | + 'options' => array_merge(array('' => ''), $states), |
|
944 | 944 | 'name' => 'tax_rates[' . $sanitized_key . '][state]', |
945 | 945 | 'id' => 'tax_rates[' . $sanitized_key . '][state]', |
946 | 946 | 'selected' => $rate['state'], |
947 | 947 | 'show_option_all' => false, |
948 | 948 | 'show_option_none' => false, |
949 | 949 | 'class' => 'wpi_select2', |
950 | - 'placeholder' => __( 'Choose a state', 'invoicing' ) |
|
951 | - ) ); |
|
950 | + 'placeholder' => __('Choose a state', 'invoicing') |
|
951 | + )); |
|
952 | 952 | } else { |
953 | - echo wpinv_html_text( array( |
|
953 | + echo wpinv_html_text(array( |
|
954 | 954 | 'name' => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'], |
955 | - 'value' => ! empty( $rate['state'] ) ? $rate['state'] : '', |
|
955 | + 'value' => !empty($rate['state']) ? $rate['state'] : '', |
|
956 | 956 | 'id' => 'tax_rates[' . $sanitized_key . '][state]', |
957 | - ) ); |
|
957 | + )); |
|
958 | 958 | } |
959 | 959 | ?> |
960 | 960 | </td> |
961 | 961 | <td class="wpinv_tax_global"> |
962 | - <input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked( true, ! empty( $rate['global'] ) ); ?>/> |
|
963 | - <label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label> |
|
962 | + <input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked(true, !empty($rate['global'])); ?>/> |
|
963 | + <label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label> |
|
964 | 964 | </td> |
965 | - <td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[<?php echo $sanitized_key; ?>][rate]" value="<?php echo esc_html( $rate['rate'] ); ?>"/></td> |
|
966 | - <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[<?php echo $sanitized_key; ?>][name]" value="<?php echo esc_html( $rate['name'] ); ?>"/></td> |
|
967 | - <td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td> |
|
965 | + <td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[<?php echo $sanitized_key; ?>][rate]" value="<?php echo esc_html($rate['rate']); ?>"/></td> |
|
966 | + <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[<?php echo $sanitized_key; ?>][name]" value="<?php echo esc_html($rate['name']); ?>"/></td> |
|
967 | + <td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td> |
|
968 | 968 | </tr> |
969 | 969 | <?php endforeach; ?> |
970 | 970 | <?php else : ?> |
971 | 971 | <tr> |
972 | 972 | <td class="wpinv_tax_country"> |
973 | 973 | <?php |
974 | - echo wpinv_html_select( array( |
|
975 | - 'options' => wpinv_get_country_list( true ), |
|
974 | + echo wpinv_html_select(array( |
|
975 | + 'options' => wpinv_get_country_list(true), |
|
976 | 976 | 'name' => 'tax_rates[0][country]', |
977 | 977 | 'show_option_all' => false, |
978 | 978 | 'show_option_none' => false, |
979 | 979 | 'class' => 'wpinv-tax-country wpi_select2', |
980 | - 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
981 | - ) ); ?> |
|
980 | + 'placeholder' => __('Choose a country', 'invoicing') |
|
981 | + )); ?> |
|
982 | 982 | </td> |
983 | 983 | <td class="wpinv_tax_state"> |
984 | - <?php echo wpinv_html_text( array( |
|
984 | + <?php echo wpinv_html_text(array( |
|
985 | 985 | 'name' => 'tax_rates[0][state]' |
986 | - ) ); ?> |
|
986 | + )); ?> |
|
987 | 987 | </td> |
988 | 988 | <td class="wpinv_tax_global"> |
989 | 989 | <input type="checkbox" name="tax_rates[0][global]" id="tax_rates[0][global]" value="1"/> |
990 | - <label for="tax_rates[0][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label> |
|
990 | + <label for="tax_rates[0][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label> |
|
991 | 991 | </td> |
992 | - <td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[0][rate]" placeholder="<?php echo (float)wpinv_get_option( 'tax_rate', 0 ) ;?>" value="<?php echo (float)wpinv_get_option( 'tax_rate', 0 ) ;?>"/></td> |
|
992 | + <td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[0][rate]" placeholder="<?php echo (float) wpinv_get_option('tax_rate', 0); ?>" value="<?php echo (float) wpinv_get_option('tax_rate', 0); ?>"/></td> |
|
993 | 993 | <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[0][name]" /></td> |
994 | - <td><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td> |
|
994 | + <td><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td> |
|
995 | 995 | </tr> |
996 | 996 | <?php endif; ?> |
997 | 997 | </tbody> |
998 | - <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e( 'Add Tax Rate', 'invoicing' ); ?></span></td></tr></tfoot> |
|
998 | + <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e('Add Tax Rate', 'invoicing'); ?></span></td></tr></tfoot> |
|
999 | 999 | </table> |
1000 | 1000 | <?php |
1001 | 1001 | echo ob_get_clean(); |
@@ -1006,76 +1006,76 @@ discard block |
||
1006 | 1006 | ob_start(); ?> |
1007 | 1007 | </td><tr> |
1008 | 1008 | <td colspan="2" class="wpinv_tools_tdbox"> |
1009 | - <?php if ( $args['desc'] ) { ?><p><?php echo $args['desc']; ?></p><?php } ?> |
|
1010 | - <?php do_action( 'wpinv_tools_before' ); ?> |
|
1009 | + <?php if ($args['desc']) { ?><p><?php echo $args['desc']; ?></p><?php } ?> |
|
1010 | + <?php do_action('wpinv_tools_before'); ?> |
|
1011 | 1011 | <table id="wpinv_tools_table" class="wp-list-table widefat fixed posts"> |
1012 | 1012 | <thead> |
1013 | 1013 | <tr> |
1014 | - <th scope="col" class="wpinv-th-tool"><?php _e( 'Tool', 'invoicing' ); ?></th> |
|
1015 | - <th scope="col" class="wpinv-th-desc"><?php _e( 'Description', 'invoicing' ); ?></th> |
|
1016 | - <th scope="col" class="wpinv-th-action"><?php _e( 'Action', 'invoicing' ); ?></th> |
|
1014 | + <th scope="col" class="wpinv-th-tool"><?php _e('Tool', 'invoicing'); ?></th> |
|
1015 | + <th scope="col" class="wpinv-th-desc"><?php _e('Description', 'invoicing'); ?></th> |
|
1016 | + <th scope="col" class="wpinv-th-action"><?php _e('Action', 'invoicing'); ?></th> |
|
1017 | 1017 | </tr> |
1018 | 1018 | </thead> |
1019 | - <?php do_action( 'wpinv_tools_row' ); ?> |
|
1019 | + <?php do_action('wpinv_tools_row'); ?> |
|
1020 | 1020 | <tbody> |
1021 | 1021 | </tbody> |
1022 | 1022 | </table> |
1023 | - <?php do_action( 'wpinv_tools_after' ); ?> |
|
1023 | + <?php do_action('wpinv_tools_after'); ?> |
|
1024 | 1024 | <?php |
1025 | 1025 | echo ob_get_clean(); |
1026 | 1026 | } |
1027 | 1027 | |
1028 | -function wpinv_descriptive_text_callback( $args ) { |
|
1029 | - echo wp_kses_post( $args['desc'] ); |
|
1028 | +function wpinv_descriptive_text_callback($args) { |
|
1029 | + echo wp_kses_post($args['desc']); |
|
1030 | 1030 | } |
1031 | 1031 | |
1032 | -function wpinv_hook_callback( $args ) { |
|
1033 | - do_action( 'wpinv_' . $args['id'], $args ); |
|
1032 | +function wpinv_hook_callback($args) { |
|
1033 | + do_action('wpinv_' . $args['id'], $args); |
|
1034 | 1034 | } |
1035 | 1035 | |
1036 | 1036 | function wpinv_set_settings_cap() { |
1037 | 1037 | return wpinv_get_capability(); |
1038 | 1038 | } |
1039 | -add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' ); |
|
1039 | +add_filter('option_page_capability_wpinv_settings', 'wpinv_set_settings_cap'); |
|
1040 | 1040 | |
1041 | -function wpinv_settings_sanitize_input( $value, $key ) { |
|
1042 | - if ( $key == 'tax_rate' || $key == 'eu_fallback_rate' ) { |
|
1043 | - $value = wpinv_sanitize_amount( $value, 4 ); |
|
1041 | +function wpinv_settings_sanitize_input($value, $key) { |
|
1042 | + if ($key == 'tax_rate' || $key == 'eu_fallback_rate') { |
|
1043 | + $value = wpinv_sanitize_amount($value, 4); |
|
1044 | 1044 | $value = $value >= 100 ? 99 : $value; |
1045 | 1045 | } |
1046 | 1046 | |
1047 | 1047 | return $value; |
1048 | 1048 | } |
1049 | -add_filter( 'wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2 ); |
|
1049 | +add_filter('wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2); |
|
1050 | 1050 | |
1051 | -function wpinv_on_update_settings( $old_value, $value, $option ) { |
|
1052 | - $old = !empty( $old_value['remove_data_on_unistall'] ) ? 1 : ''; |
|
1053 | - $new = !empty( $value['remove_data_on_unistall'] ) ? 1 : ''; |
|
1051 | +function wpinv_on_update_settings($old_value, $value, $option) { |
|
1052 | + $old = !empty($old_value['remove_data_on_unistall']) ? 1 : ''; |
|
1053 | + $new = !empty($value['remove_data_on_unistall']) ? 1 : ''; |
|
1054 | 1054 | |
1055 | - if ( $old != $new ) { |
|
1056 | - update_option( 'wpinv_remove_data_on_invoice_unistall', $new ); |
|
1055 | + if ($old != $new) { |
|
1056 | + update_option('wpinv_remove_data_on_invoice_unistall', $new); |
|
1057 | 1057 | } |
1058 | 1058 | } |
1059 | -add_action( 'update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3 ); |
|
1060 | -add_action( 'wpinv_settings_tab_bottom_emails_new_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1061 | -add_action( 'wpinv_settings_tab_bottom_emails_cancelled_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1062 | -add_action( 'wpinv_settings_tab_bottom_emails_failed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1063 | -add_action( 'wpinv_settings_tab_bottom_emails_onhold_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1064 | -add_action( 'wpinv_settings_tab_bottom_emails_processing_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1065 | -add_action( 'wpinv_settings_tab_bottom_emails_completed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1066 | -add_action( 'wpinv_settings_tab_bottom_emails_refunded_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1067 | -add_action( 'wpinv_settings_tab_bottom_emails_user_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1068 | -add_action( 'wpinv_settings_tab_bottom_emails_user_note', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1069 | -add_action( 'wpinv_settings_tab_bottom_emails_overdue', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1070 | - |
|
1071 | -function wpinv_settings_tab_bottom_emails( $active_tab, $section ) { |
|
1059 | +add_action('update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3); |
|
1060 | +add_action('wpinv_settings_tab_bottom_emails_new_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1061 | +add_action('wpinv_settings_tab_bottom_emails_cancelled_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1062 | +add_action('wpinv_settings_tab_bottom_emails_failed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1063 | +add_action('wpinv_settings_tab_bottom_emails_onhold_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1064 | +add_action('wpinv_settings_tab_bottom_emails_processing_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1065 | +add_action('wpinv_settings_tab_bottom_emails_completed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1066 | +add_action('wpinv_settings_tab_bottom_emails_refunded_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1067 | +add_action('wpinv_settings_tab_bottom_emails_user_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1068 | +add_action('wpinv_settings_tab_bottom_emails_user_note', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1069 | +add_action('wpinv_settings_tab_bottom_emails_overdue', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1070 | + |
|
1071 | +function wpinv_settings_tab_bottom_emails($active_tab, $section) { |
|
1072 | 1072 | ?> |
1073 | 1073 | <div class="wpinv-email-wc-row "> |
1074 | 1074 | <div class="wpinv-email-wc-td"> |
1075 | - <h3 class="wpinv-email-wc-title"><?php echo apply_filters( 'wpinv_settings_email_wildcards_title', __( 'Wildcards For Emails', 'invoicing' ) ); ?></h3> |
|
1075 | + <h3 class="wpinv-email-wc-title"><?php echo apply_filters('wpinv_settings_email_wildcards_title', __('Wildcards For Emails', 'invoicing')); ?></h3> |
|
1076 | 1076 | <p class="wpinv-email-wc-description"> |
1077 | 1077 | <?php |
1078 | - $description = __( 'The following wildcards can be used in email subjects, heading and content:<br> |
|
1078 | + $description = __('The following wildcards can be used in email subjects, heading and content:<br> |
|
1079 | 1079 | <strong>{site_title} :</strong> Site Title<br> |
1080 | 1080 | <strong>{name} :</strong> Customer\'s full name<br> |
1081 | 1081 | <strong>{first_name} :</strong> Customer\'s first name<br> |
@@ -1089,7 +1089,7 @@ discard block |
||
1089 | 1089 | <strong>{invoice_due_date} :</strong> The date the invoice is due<br> |
1090 | 1090 | <strong>{date} :</strong> Today\'s date.<br> |
1091 | 1091 | <strong>{is_was} :</strong> If due date of invoice is past, displays "was" otherwise displays "is"<br> |
1092 | - <strong>{invoice_label} :</strong> Invoices/quotes singular name. Ex: Invoice/Quote<br>', 'invoicing' ); |
|
1092 | + <strong>{invoice_label} :</strong> Invoices/quotes singular name. Ex: Invoice/Quote<br>', 'invoicing'); |
|
1093 | 1093 | echo apply_filters('wpinv_settings_email_wildcards_description', $description, $active_tab, $section); |
1094 | 1094 | ?> |
1095 | 1095 | </p> |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Setup menus in WP admin. |
4 | 4 | */ |
5 | 5 | |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * WC_Admin_Menus Class. |
@@ -13,25 +13,25 @@ discard block |
||
13 | 13 | * Hook in tabs. |
14 | 14 | */ |
15 | 15 | public function __construct() { |
16 | - add_action( 'admin_menu', array( $this, 'admin_menu' ), 10 ); |
|
17 | - add_action( 'admin_menu', array( $this, 'add_customers_menu' ), 18 ); |
|
18 | - add_action( 'admin_menu', array( $this, 'add_subscriptions_menu' ), 40 ); |
|
19 | - add_action( 'admin_menu', array( $this, 'add_addons_menu' ), 100 ); |
|
20 | - add_action( 'admin_menu', array( $this, 'add_settings_menu' ), 60 ); |
|
21 | - add_action( 'admin_menu', array( $this, 'remove_admin_submenus' ), 10 ); |
|
22 | - add_action( 'admin_head-nav-menus.php', array( $this, 'add_nav_menu_meta_boxes' ) ); |
|
16 | + add_action('admin_menu', array($this, 'admin_menu'), 10); |
|
17 | + add_action('admin_menu', array($this, 'add_customers_menu'), 18); |
|
18 | + add_action('admin_menu', array($this, 'add_subscriptions_menu'), 40); |
|
19 | + add_action('admin_menu', array($this, 'add_addons_menu'), 100); |
|
20 | + add_action('admin_menu', array($this, 'add_settings_menu'), 60); |
|
21 | + add_action('admin_menu', array($this, 'remove_admin_submenus'), 10); |
|
22 | + add_action('admin_head-nav-menus.php', array($this, 'add_nav_menu_meta_boxes')); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | public function admin_menu() { |
26 | 26 | |
27 | - $capability = apply_filters( 'invoicing_capability', wpinv_get_capability() ); |
|
27 | + $capability = apply_filters('invoicing_capability', wpinv_get_capability()); |
|
28 | 28 | add_menu_page( |
29 | - __( 'GetPaid', 'invoicing' ), |
|
30 | - __( 'GetPaid', 'invoicing' ), |
|
29 | + __('GetPaid', 'invoicing'), |
|
30 | + __('GetPaid', 'invoicing'), |
|
31 | 31 | $capability, |
32 | 32 | 'wpinv', |
33 | 33 | null, |
34 | - 'data:image/svg+xml;base64,' . base64_encode( file_get_contents( WPINV_PLUGIN_DIR . 'assets/images/GetPaid.svg' ) ), |
|
34 | + 'data:image/svg+xml;base64,' . base64_encode(file_get_contents(WPINV_PLUGIN_DIR . 'assets/images/GetPaid.svg')), |
|
35 | 35 | '54.123460' |
36 | 36 | ); |
37 | 37 | |
@@ -43,11 +43,11 @@ discard block |
||
43 | 43 | public function add_customers_menu() { |
44 | 44 | add_submenu_page( |
45 | 45 | 'wpinv', |
46 | - __( 'Customers', 'invoicing' ), |
|
47 | - __( 'Customers', 'invoicing' ), |
|
46 | + __('Customers', 'invoicing'), |
|
47 | + __('Customers', 'invoicing'), |
|
48 | 48 | wpinv_get_capability(), |
49 | 49 | 'wpinv-customers', |
50 | - array( $this, 'customers_page' ) |
|
50 | + array($this, 'customers_page') |
|
51 | 51 | ); |
52 | 52 | } |
53 | 53 | |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | public function add_subscriptions_menu() { |
58 | 58 | add_submenu_page( |
59 | 59 | 'wpinv', |
60 | - __( 'Subscriptions', 'invoicing' ), |
|
61 | - __( 'Subscriptions', 'invoicing' ), |
|
60 | + __('Subscriptions', 'invoicing'), |
|
61 | + __('Subscriptions', 'invoicing'), |
|
62 | 62 | wpinv_get_capability(), |
63 | 63 | 'wpinv-subscriptions', |
64 | 64 | 'wpinv_subscriptions_page' |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * Displays the customers page. |
70 | 70 | */ |
71 | 71 | public function customers_page() { |
72 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-customers-table.php' ); |
|
72 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-customers-table.php'); |
|
73 | 73 | ?> |
74 | 74 | <div class="wrap wpi-customers-wrap"> |
75 | 75 | <style> |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | width: 30%; |
78 | 78 | } |
79 | 79 | </style> |
80 | - <h1><?php echo esc_html( __( 'Customers', 'invoicing' ) ); ?></h1> |
|
80 | + <h1><?php echo esc_html(__('Customers', 'invoicing')); ?></h1> |
|
81 | 81 | <?php |
82 | 82 | $table = new WPInv_Customers_Table(); |
83 | 83 | $table->prepare_items(); |
@@ -93,16 +93,16 @@ discard block |
||
93 | 93 | public function add_settings_menu() { |
94 | 94 | add_submenu_page( |
95 | 95 | 'wpinv', |
96 | - __( 'Invoice Settings', 'invoicing' ), |
|
97 | - __( 'Settings', 'invoicing' ), |
|
98 | - apply_filters( 'invoicing_capability', wpinv_get_capability() ), |
|
96 | + __('Invoice Settings', 'invoicing'), |
|
97 | + __('Settings', 'invoicing'), |
|
98 | + apply_filters('invoicing_capability', wpinv_get_capability()), |
|
99 | 99 | 'wpinv-settings', |
100 | - array( $this, 'options_page' ) |
|
100 | + array($this, 'options_page') |
|
101 | 101 | ); |
102 | 102 | } |
103 | 103 | |
104 | - public function add_addons_menu(){ |
|
105 | - if ( !apply_filters( 'wpi_show_addons_page', true ) ) { |
|
104 | + public function add_addons_menu() { |
|
105 | + if (!apply_filters('wpi_show_addons_page', true)) { |
|
106 | 106 | return; |
107 | 107 | } |
108 | 108 | |
@@ -112,78 +112,78 @@ discard block |
||
112 | 112 | __('Extensions', 'invoicing'), |
113 | 113 | 'manage_options', |
114 | 114 | 'wpi-addons', |
115 | - array( $this, 'addons_page' ) |
|
115 | + array($this, 'addons_page') |
|
116 | 116 | ); |
117 | 117 | } |
118 | 118 | |
119 | - public function addons_page(){ |
|
119 | + public function addons_page() { |
|
120 | 120 | $addon_obj = new WPInv_Admin_Addons(); |
121 | 121 | $addon_obj->output(); |
122 | 122 | } |
123 | 123 | |
124 | 124 | function options_page() { |
125 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
125 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
126 | 126 | |
127 | - if ( $page !== 'wpinv-settings' ) { |
|
127 | + if ($page !== 'wpinv-settings') { |
|
128 | 128 | return; |
129 | 129 | } |
130 | 130 | |
131 | 131 | $settings_tabs = wpinv_get_settings_tabs(); |
132 | 132 | $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs; |
133 | - $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general'; |
|
134 | - $sections = wpinv_get_settings_tab_sections( $active_tab ); |
|
133 | + $active_tab = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general'; |
|
134 | + $sections = wpinv_get_settings_tab_sections($active_tab); |
|
135 | 135 | $key = 'main'; |
136 | 136 | |
137 | - if ( is_array( $sections ) ) { |
|
138 | - $key = key( $sections ); |
|
137 | + if (is_array($sections)) { |
|
138 | + $key = key($sections); |
|
139 | 139 | } |
140 | 140 | |
141 | - $registered_sections = wpinv_get_settings_tab_sections( $active_tab ); |
|
142 | - $section = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key; |
|
141 | + $registered_sections = wpinv_get_settings_tab_sections($active_tab); |
|
142 | + $section = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key; |
|
143 | 143 | ob_start(); |
144 | 144 | ?> |
145 | 145 | <div class="wrap"> |
146 | 146 | <h1 class="nav-tab-wrapper"> |
147 | 147 | <?php |
148 | - foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) { |
|
149 | - $tab_url = add_query_arg( array( |
|
148 | + foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) { |
|
149 | + $tab_url = add_query_arg(array( |
|
150 | 150 | 'settings-updated' => false, |
151 | 151 | 'tab' => $tab_id, |
152 | - ) ); |
|
152 | + )); |
|
153 | 153 | |
154 | 154 | // Remove the section from the tabs so we always end up at the main section |
155 | - $tab_url = remove_query_arg( 'section', $tab_url ); |
|
156 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
|
155 | + $tab_url = remove_query_arg('section', $tab_url); |
|
156 | + $tab_url = remove_query_arg('wpi_sub', $tab_url); |
|
157 | 157 | |
158 | 158 | $active = $active_tab == $tab_id ? ' nav-tab-active' : ''; |
159 | 159 | |
160 | - echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">'; |
|
161 | - echo esc_html( $tab_name ); |
|
160 | + echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">'; |
|
161 | + echo esc_html($tab_name); |
|
162 | 162 | echo '</a>'; |
163 | 163 | } |
164 | 164 | ?> |
165 | 165 | </h1> |
166 | 166 | <?php |
167 | - $number_of_sections = count( $sections ); |
|
167 | + $number_of_sections = count($sections); |
|
168 | 168 | $number = 0; |
169 | - if ( $number_of_sections > 1 ) { |
|
169 | + if ($number_of_sections > 1) { |
|
170 | 170 | echo '<div><ul class="subsubsub">'; |
171 | - foreach( $sections as $section_id => $section_name ) { |
|
171 | + foreach ($sections as $section_id => $section_name) { |
|
172 | 172 | echo '<li>'; |
173 | 173 | $number++; |
174 | - $tab_url = add_query_arg( array( |
|
174 | + $tab_url = add_query_arg(array( |
|
175 | 175 | 'settings-updated' => false, |
176 | 176 | 'tab' => $active_tab, |
177 | 177 | 'section' => $section_id |
178 | - ) ); |
|
179 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
|
178 | + )); |
|
179 | + $tab_url = remove_query_arg('wpi_sub', $tab_url); |
|
180 | 180 | $class = ''; |
181 | - if ( $section == $section_id ) { |
|
181 | + if ($section == $section_id) { |
|
182 | 182 | $class = 'current'; |
183 | 183 | } |
184 | - echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>'; |
|
184 | + echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>'; |
|
185 | 185 | |
186 | - if ( $number != $number_of_sections ) { |
|
186 | + if ($number != $number_of_sections) { |
|
187 | 187 | echo ' | '; |
188 | 188 | } |
189 | 189 | echo '</li>'; |
@@ -195,20 +195,20 @@ discard block |
||
195 | 195 | <form method="post" action="options.php"> |
196 | 196 | <table class="form-table"> |
197 | 197 | <?php |
198 | - settings_fields( 'wpinv_settings' ); |
|
198 | + settings_fields('wpinv_settings'); |
|
199 | 199 | |
200 | - if ( 'main' === $section ) { |
|
201 | - do_action( 'wpinv_settings_tab_top', $active_tab ); |
|
200 | + if ('main' === $section) { |
|
201 | + do_action('wpinv_settings_tab_top', $active_tab); |
|
202 | 202 | } |
203 | 203 | |
204 | - do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
205 | - do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
206 | - do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
207 | - do_action( 'getpaid_settings_tab_bottom', $active_tab, $section ); |
|
204 | + do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section); |
|
205 | + do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section); |
|
206 | + do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section); |
|
207 | + do_action('getpaid_settings_tab_bottom', $active_tab, $section); |
|
208 | 208 | |
209 | 209 | // For backwards compatibility |
210 | - if ( 'main' === $section ) { |
|
211 | - do_action( 'wpinv_settings_tab_bottom', $active_tab ); |
|
210 | + if ('main' === $section) { |
|
211 | + do_action('wpinv_settings_tab_bottom', $active_tab); |
|
212 | 212 | } |
213 | 213 | ?> |
214 | 214 | </table> |
@@ -222,18 +222,18 @@ discard block |
||
222 | 222 | } |
223 | 223 | |
224 | 224 | public function remove_admin_submenus() { |
225 | - remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' ); |
|
225 | + remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice'); |
|
226 | 226 | } |
227 | 227 | |
228 | - public function add_nav_menu_meta_boxes(){ |
|
229 | - add_meta_box( 'wpinv_endpoints_nav_link', __( 'Invoicing Pages', 'invoicing' ), array( $this, 'nav_menu_links' ), 'nav-menus', 'side', 'low' ); |
|
228 | + public function add_nav_menu_meta_boxes() { |
|
229 | + add_meta_box('wpinv_endpoints_nav_link', __('Invoicing Pages', 'invoicing'), array($this, 'nav_menu_links'), 'nav-menus', 'side', 'low'); |
|
230 | 230 | } |
231 | 231 | |
232 | - public function nav_menu_links(){ |
|
232 | + public function nav_menu_links() { |
|
233 | 233 | $endpoints = $this->get_menu_items(); |
234 | 234 | ?> |
235 | 235 | <div id="invoicing-endpoints" class="posttypediv"> |
236 | - <?php if(!empty($endpoints['pages'])){ ?> |
|
236 | + <?php if (!empty($endpoints['pages'])) { ?> |
|
237 | 237 | <div id="tabs-panel-invoicing-endpoints" class="tabs-panel tabs-panel-active"> |
238 | 238 | <ul id="invoicing-endpoints-checklist" class="categorychecklist form-no-clear"> |
239 | 239 | <?php |
@@ -245,29 +245,29 @@ discard block |
||
245 | 245 | <?php } ?> |
246 | 246 | <p class="button-controls"> |
247 | 247 | <span class="list-controls"> |
248 | - <a href="<?php echo admin_url( 'nav-menus.php?page-tab=all&selectall=1#invoicing-endpoints' ); ?>" class="select-all"><?php _e( 'Select all', 'invoicing' ); ?></a> |
|
248 | + <a href="<?php echo admin_url('nav-menus.php?page-tab=all&selectall=1#invoicing-endpoints'); ?>" class="select-all"><?php _e('Select all', 'invoicing'); ?></a> |
|
249 | 249 | </span> |
250 | 250 | <span class="add-to-menu"> |
251 | - <input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to menu', 'invoicing' ); ?>" name="add-post-type-menu-item" id="submit-invoicing-endpoints"> |
|
251 | + <input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to menu', 'invoicing'); ?>" name="add-post-type-menu-item" id="submit-invoicing-endpoints"> |
|
252 | 252 | <span class="spinner"></span> |
253 | 253 | </span> |
254 | 254 | </p> |
255 | 255 | <?php |
256 | 256 | } |
257 | 257 | |
258 | - public function get_menu_items(){ |
|
258 | + public function get_menu_items() { |
|
259 | 259 | $items = array(); |
260 | 260 | |
261 | - $wpinv_history_page_id = (int)wpinv_get_option( 'invoice_history_page' ); |
|
262 | - if($wpinv_history_page_id > 0){ |
|
261 | + $wpinv_history_page_id = (int) wpinv_get_option('invoice_history_page'); |
|
262 | + if ($wpinv_history_page_id > 0) { |
|
263 | 263 | $item = new stdClass(); |
264 | 264 | $item->object_id = $wpinv_history_page_id; |
265 | 265 | $item->db_id = 0; |
266 | - $item->object = 'page'; |
|
266 | + $item->object = 'page'; |
|
267 | 267 | $item->menu_item_parent = 0; |
268 | 268 | $item->type = 'post_type'; |
269 | - $item->title = __('Invoice History Page','invoicing'); |
|
270 | - $item->url = get_permalink( $wpinv_history_page_id ); |
|
269 | + $item->title = __('Invoice History Page', 'invoicing'); |
|
270 | + $item->url = get_permalink($wpinv_history_page_id); |
|
271 | 271 | $item->target = ''; |
272 | 272 | $item->attr_title = ''; |
273 | 273 | $item->classes = array('wpinv-menu-item'); |
@@ -276,16 +276,16 @@ discard block |
||
276 | 276 | $items['pages'][] = $item; |
277 | 277 | } |
278 | 278 | |
279 | - $wpinv_sub_history_page_id = (int)wpinv_get_option( 'invoice_subscription_page' ); |
|
280 | - if($wpinv_sub_history_page_id > 0){ |
|
279 | + $wpinv_sub_history_page_id = (int) wpinv_get_option('invoice_subscription_page'); |
|
280 | + if ($wpinv_sub_history_page_id > 0) { |
|
281 | 281 | $item = new stdClass(); |
282 | 282 | $item->object_id = $wpinv_sub_history_page_id; |
283 | 283 | $item->db_id = 0; |
284 | - $item->object = 'page'; |
|
284 | + $item->object = 'page'; |
|
285 | 285 | $item->menu_item_parent = 0; |
286 | 286 | $item->type = 'post_type'; |
287 | - $item->title = __('Invoice Subscriptions Page','invoicing'); |
|
288 | - $item->url = get_permalink( $wpinv_sub_history_page_id ); |
|
287 | + $item->title = __('Invoice Subscriptions Page', 'invoicing'); |
|
288 | + $item->url = get_permalink($wpinv_sub_history_page_id); |
|
289 | 289 | $item->target = ''; |
290 | 290 | $item->attr_title = ''; |
291 | 291 | $item->classes = array('wpinv-menu-item'); |
@@ -294,16 +294,16 @@ discard block |
||
294 | 294 | $items['pages'][] = $item; |
295 | 295 | } |
296 | 296 | |
297 | - $wpinv_checkout_page_id = (int)wpinv_get_option( 'checkout_page' ); |
|
298 | - if($wpinv_checkout_page_id > 0){ |
|
297 | + $wpinv_checkout_page_id = (int) wpinv_get_option('checkout_page'); |
|
298 | + if ($wpinv_checkout_page_id > 0) { |
|
299 | 299 | $item = new stdClass(); |
300 | 300 | $item->object_id = $wpinv_checkout_page_id; |
301 | 301 | $item->db_id = 0; |
302 | - $item->object = 'page'; |
|
302 | + $item->object = 'page'; |
|
303 | 303 | $item->menu_item_parent = 0; |
304 | 304 | $item->type = 'post_type'; |
305 | - $item->title = __('Checkout Page','invoicing'); |
|
306 | - $item->url = get_permalink( $wpinv_checkout_page_id ); |
|
305 | + $item->title = __('Checkout Page', 'invoicing'); |
|
306 | + $item->url = get_permalink($wpinv_checkout_page_id); |
|
307 | 307 | $item->target = ''; |
308 | 308 | $item->attr_title = ''; |
309 | 309 | $item->classes = array('wpinv-menu-item'); |
@@ -312,16 +312,16 @@ discard block |
||
312 | 312 | $items['pages'][] = $item; |
313 | 313 | } |
314 | 314 | |
315 | - $wpinv_success_page_id = (int)wpinv_get_option( 'success_page' ); |
|
316 | - if($wpinv_success_page_id > 0){ |
|
315 | + $wpinv_success_page_id = (int) wpinv_get_option('success_page'); |
|
316 | + if ($wpinv_success_page_id > 0) { |
|
317 | 317 | $item = new stdClass(); |
318 | 318 | $item->object_id = $wpinv_success_page_id; |
319 | 319 | $item->db_id = 0; |
320 | - $item->object = 'page'; |
|
320 | + $item->object = 'page'; |
|
321 | 321 | $item->menu_item_parent = 0; |
322 | 322 | $item->type = 'post_type'; |
323 | - $item->title = __('Success Page','invoicing'); |
|
324 | - $item->url = get_permalink( $wpinv_success_page_id ); |
|
323 | + $item->title = __('Success Page', 'invoicing'); |
|
324 | + $item->url = get_permalink($wpinv_success_page_id); |
|
325 | 325 | $item->target = ''; |
326 | 326 | $item->attr_title = ''; |
327 | 327 | $item->classes = array('wpinv-menu-item'); |
@@ -330,16 +330,16 @@ discard block |
||
330 | 330 | $items['pages'][] = $item; |
331 | 331 | } |
332 | 332 | |
333 | - $wpinv_failure_page_id = (int)wpinv_get_option( 'failure_page' ); |
|
334 | - if($wpinv_failure_page_id > 0){ |
|
333 | + $wpinv_failure_page_id = (int) wpinv_get_option('failure_page'); |
|
334 | + if ($wpinv_failure_page_id > 0) { |
|
335 | 335 | $item = new stdClass(); |
336 | 336 | $item->object_id = $wpinv_failure_page_id; |
337 | 337 | $item->db_id = 0; |
338 | - $item->object = 'page'; |
|
338 | + $item->object = 'page'; |
|
339 | 339 | $item->menu_item_parent = 0; |
340 | 340 | $item->type = 'post_type'; |
341 | - $item->title = __('Failed Transaction Page','invoicing'); |
|
342 | - $item->url = get_permalink( $wpinv_failure_page_id ); |
|
341 | + $item->title = __('Failed Transaction Page', 'invoicing'); |
|
342 | + $item->url = get_permalink($wpinv_failure_page_id); |
|
343 | 343 | $item->target = ''; |
344 | 344 | $item->attr_title = ''; |
345 | 345 | $item->classes = array('wpinv-menu-item'); |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | $items['pages'][] = $item; |
349 | 349 | } |
350 | 350 | |
351 | - return apply_filters( 'wpinv_menu_items', $items ); |
|
351 | + return apply_filters('wpinv_menu_items', $items); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | } |
@@ -16,164 +16,164 @@ |
||
16 | 16 | */ |
17 | 17 | class GetPaid_MaxMind_Geolocation { |
18 | 18 | |
19 | - /** |
|
20 | - * The service responsible for interacting with the MaxMind database. |
|
21 | - * |
|
22 | - * @var GetPaid_MaxMind_Database_Service |
|
23 | - */ |
|
24 | - private $database_service; |
|
25 | - |
|
26 | - /** |
|
27 | - * Initialize the integration. |
|
28 | - */ |
|
29 | - public function __construct() { |
|
30 | - |
|
31 | - /** |
|
32 | - * Supports overriding the database service to be used. |
|
33 | - * |
|
34 | - * @since 1.0.19 |
|
35 | - * @return mixed|null The geolocation database service. |
|
36 | - */ |
|
37 | - $this->database_service = apply_filters( 'getpaid_maxmind_geolocation_database_service', null ); |
|
38 | - if ( null === $this->database_service ) { |
|
39 | - $this->database_service = new GetPaid_MaxMind_Database_Service( $this->get_database_prefix() ); |
|
40 | - } |
|
41 | - |
|
42 | - // Bind to the scheduled updater action. |
|
43 | - add_action( 'getpaid_update_geoip_databases', array( $this, 'update_database' ) ); |
|
44 | - |
|
45 | - // Bind to the geolocation filter for MaxMind database lookups. |
|
46 | - add_filter( 'getpaid_get_geolocation', array( $this, 'get_geolocation' ), 10, 2 ); |
|
47 | - |
|
48 | - // Handle maxmind key updates. |
|
49 | - add_filter( 'wpinv_settings_sanitize_maxmind_license_key', array( $this, 'handle_key_updates' ) ); |
|
50 | - |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Get database service. |
|
55 | - * |
|
56 | - * @return GetPaid_MaxMind_Database_Service|null |
|
57 | - */ |
|
58 | - public function get_database_service() { |
|
59 | - return $this->database_service; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Checks to make sure that the license key is valid. |
|
64 | - * |
|
65 | - * @param string $license_key The new license key. |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function handle_key_updates( $license_key ) { |
|
69 | - |
|
70 | - // Trim whitespaces and strip slashes. |
|
71 | - $license_key = trim( $license_key ); |
|
72 | - |
|
73 | - // Abort if the license key is empty or unchanged. |
|
74 | - if ( empty( $license_key ) ) { |
|
75 | - return $license_key; |
|
76 | - } |
|
77 | - |
|
78 | - // Abort if a database exists and the license key is unchaged. |
|
79 | - if ( file_exists( $this->database_service->get_database_path() && $license_key == wpinv_get_option( 'maxmind_license_key' ) ) ) { |
|
80 | - return $license_key; |
|
81 | - } |
|
82 | - |
|
83 | - // Check the license key by attempting to download the Geolocation database. |
|
84 | - $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
85 | - if ( is_wp_error( $tmp_database_path ) ) { |
|
86 | - getpaid_admin()->show_error( $tmp_database_path->get_error_message() ); |
|
87 | - return $license_key; |
|
88 | - } |
|
89 | - |
|
90 | - $this->update_database( $tmp_database_path ); |
|
91 | - |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Updates the database used for geolocation queries. |
|
96 | - * |
|
97 | - * @param string $tmp_database_path Temporary database path. |
|
98 | - */ |
|
99 | - public function update_database( $tmp_database_path = null ) { |
|
100 | - |
|
101 | - // Allow us to easily interact with the filesystem. |
|
102 | - require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
103 | - WP_Filesystem(); |
|
104 | - global $wp_filesystem; |
|
105 | - |
|
106 | - // Remove any existing archives to comply with the MaxMind TOS. |
|
107 | - $target_database_path = $this->database_service->get_database_path(); |
|
108 | - |
|
109 | - // If there's no database path, we can't store the database. |
|
110 | - if ( empty( $target_database_path ) ) { |
|
111 | - return; |
|
112 | - } |
|
113 | - |
|
114 | - if ( $wp_filesystem->exists( $target_database_path ) ) { |
|
115 | - $wp_filesystem->delete( $target_database_path ); |
|
116 | - } |
|
117 | - |
|
118 | - // We can't download a database if there's no license key configured. |
|
119 | - $license_key = wpinv_get_option( 'maxmind_license_key' ); |
|
120 | - if ( empty( $license_key ) ) { |
|
121 | - return; |
|
122 | - } |
|
123 | - |
|
124 | - if ( empty( $tmp_database_path ) ) { |
|
125 | - $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
126 | - } |
|
127 | - |
|
128 | - if ( is_wp_error( $tmp_database_path ) ) { |
|
129 | - wpinv_error_log( $tmp_database_path->get_error_message() ); |
|
130 | - return; |
|
131 | - } |
|
132 | - |
|
133 | - // Move the new database into position. |
|
134 | - $wp_filesystem->move( $tmp_database_path, $target_database_path, true ); |
|
135 | - $wp_filesystem->delete( dirname( $tmp_database_path ) ); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Performs a geolocation lookup against the MaxMind database for the given IP address. |
|
140 | - * |
|
141 | - * @param array $data Geolocation data. |
|
142 | - * @param string $ip_address The IP address to geolocate. |
|
143 | - * @return array Geolocation including country code, state, city and postcode based on an IP address. |
|
144 | - */ |
|
145 | - public function get_geolocation( $data, $ip_address ) { |
|
146 | - |
|
147 | - if ( ! empty( $data['country'] ) || empty( $ip_address ) ) { |
|
148 | - return $data; |
|
149 | - } |
|
150 | - |
|
151 | - $country_code = $this->database_service->get_iso_country_code_for_ip( $ip_address ); |
|
152 | - |
|
153 | - return array( |
|
154 | - 'country' => $country_code, |
|
155 | - 'state' => '', |
|
156 | - 'city' => '', |
|
157 | - 'postcode' => '', |
|
158 | - ); |
|
159 | - |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Fetches the prefix for the MaxMind database file. |
|
164 | - * |
|
165 | - * @return string |
|
166 | - */ |
|
167 | - private function get_database_prefix() { |
|
168 | - |
|
169 | - $prefix = get_option( 'wpinv_maxmind_database_prefix' ); |
|
170 | - |
|
171 | - if ( empty( $prefix ) ) { |
|
172 | - $prefix = md5( uniqid( 'wpinv' ) ); |
|
173 | - update_option( 'wpinv_maxmind_database_prefix', $prefix ); |
|
174 | - } |
|
175 | - |
|
176 | - return $prefix; |
|
177 | - } |
|
19 | + /** |
|
20 | + * The service responsible for interacting with the MaxMind database. |
|
21 | + * |
|
22 | + * @var GetPaid_MaxMind_Database_Service |
|
23 | + */ |
|
24 | + private $database_service; |
|
25 | + |
|
26 | + /** |
|
27 | + * Initialize the integration. |
|
28 | + */ |
|
29 | + public function __construct() { |
|
30 | + |
|
31 | + /** |
|
32 | + * Supports overriding the database service to be used. |
|
33 | + * |
|
34 | + * @since 1.0.19 |
|
35 | + * @return mixed|null The geolocation database service. |
|
36 | + */ |
|
37 | + $this->database_service = apply_filters( 'getpaid_maxmind_geolocation_database_service', null ); |
|
38 | + if ( null === $this->database_service ) { |
|
39 | + $this->database_service = new GetPaid_MaxMind_Database_Service( $this->get_database_prefix() ); |
|
40 | + } |
|
41 | + |
|
42 | + // Bind to the scheduled updater action. |
|
43 | + add_action( 'getpaid_update_geoip_databases', array( $this, 'update_database' ) ); |
|
44 | + |
|
45 | + // Bind to the geolocation filter for MaxMind database lookups. |
|
46 | + add_filter( 'getpaid_get_geolocation', array( $this, 'get_geolocation' ), 10, 2 ); |
|
47 | + |
|
48 | + // Handle maxmind key updates. |
|
49 | + add_filter( 'wpinv_settings_sanitize_maxmind_license_key', array( $this, 'handle_key_updates' ) ); |
|
50 | + |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Get database service. |
|
55 | + * |
|
56 | + * @return GetPaid_MaxMind_Database_Service|null |
|
57 | + */ |
|
58 | + public function get_database_service() { |
|
59 | + return $this->database_service; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Checks to make sure that the license key is valid. |
|
64 | + * |
|
65 | + * @param string $license_key The new license key. |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function handle_key_updates( $license_key ) { |
|
69 | + |
|
70 | + // Trim whitespaces and strip slashes. |
|
71 | + $license_key = trim( $license_key ); |
|
72 | + |
|
73 | + // Abort if the license key is empty or unchanged. |
|
74 | + if ( empty( $license_key ) ) { |
|
75 | + return $license_key; |
|
76 | + } |
|
77 | + |
|
78 | + // Abort if a database exists and the license key is unchaged. |
|
79 | + if ( file_exists( $this->database_service->get_database_path() && $license_key == wpinv_get_option( 'maxmind_license_key' ) ) ) { |
|
80 | + return $license_key; |
|
81 | + } |
|
82 | + |
|
83 | + // Check the license key by attempting to download the Geolocation database. |
|
84 | + $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
85 | + if ( is_wp_error( $tmp_database_path ) ) { |
|
86 | + getpaid_admin()->show_error( $tmp_database_path->get_error_message() ); |
|
87 | + return $license_key; |
|
88 | + } |
|
89 | + |
|
90 | + $this->update_database( $tmp_database_path ); |
|
91 | + |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Updates the database used for geolocation queries. |
|
96 | + * |
|
97 | + * @param string $tmp_database_path Temporary database path. |
|
98 | + */ |
|
99 | + public function update_database( $tmp_database_path = null ) { |
|
100 | + |
|
101 | + // Allow us to easily interact with the filesystem. |
|
102 | + require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
103 | + WP_Filesystem(); |
|
104 | + global $wp_filesystem; |
|
105 | + |
|
106 | + // Remove any existing archives to comply with the MaxMind TOS. |
|
107 | + $target_database_path = $this->database_service->get_database_path(); |
|
108 | + |
|
109 | + // If there's no database path, we can't store the database. |
|
110 | + if ( empty( $target_database_path ) ) { |
|
111 | + return; |
|
112 | + } |
|
113 | + |
|
114 | + if ( $wp_filesystem->exists( $target_database_path ) ) { |
|
115 | + $wp_filesystem->delete( $target_database_path ); |
|
116 | + } |
|
117 | + |
|
118 | + // We can't download a database if there's no license key configured. |
|
119 | + $license_key = wpinv_get_option( 'maxmind_license_key' ); |
|
120 | + if ( empty( $license_key ) ) { |
|
121 | + return; |
|
122 | + } |
|
123 | + |
|
124 | + if ( empty( $tmp_database_path ) ) { |
|
125 | + $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
126 | + } |
|
127 | + |
|
128 | + if ( is_wp_error( $tmp_database_path ) ) { |
|
129 | + wpinv_error_log( $tmp_database_path->get_error_message() ); |
|
130 | + return; |
|
131 | + } |
|
132 | + |
|
133 | + // Move the new database into position. |
|
134 | + $wp_filesystem->move( $tmp_database_path, $target_database_path, true ); |
|
135 | + $wp_filesystem->delete( dirname( $tmp_database_path ) ); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Performs a geolocation lookup against the MaxMind database for the given IP address. |
|
140 | + * |
|
141 | + * @param array $data Geolocation data. |
|
142 | + * @param string $ip_address The IP address to geolocate. |
|
143 | + * @return array Geolocation including country code, state, city and postcode based on an IP address. |
|
144 | + */ |
|
145 | + public function get_geolocation( $data, $ip_address ) { |
|
146 | + |
|
147 | + if ( ! empty( $data['country'] ) || empty( $ip_address ) ) { |
|
148 | + return $data; |
|
149 | + } |
|
150 | + |
|
151 | + $country_code = $this->database_service->get_iso_country_code_for_ip( $ip_address ); |
|
152 | + |
|
153 | + return array( |
|
154 | + 'country' => $country_code, |
|
155 | + 'state' => '', |
|
156 | + 'city' => '', |
|
157 | + 'postcode' => '', |
|
158 | + ); |
|
159 | + |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Fetches the prefix for the MaxMind database file. |
|
164 | + * |
|
165 | + * @return string |
|
166 | + */ |
|
167 | + private function get_database_prefix() { |
|
168 | + |
|
169 | + $prefix = get_option( 'wpinv_maxmind_database_prefix' ); |
|
170 | + |
|
171 | + if ( empty( $prefix ) ) { |
|
172 | + $prefix = md5( uniqid( 'wpinv' ) ); |
|
173 | + update_option( 'wpinv_maxmind_database_prefix', $prefix ); |
|
174 | + } |
|
175 | + |
|
176 | + return $prefix; |
|
177 | + } |
|
178 | 178 | |
179 | 179 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * Uses MaxMind for Geolocation |
@@ -34,19 +34,19 @@ discard block |
||
34 | 34 | * @since 1.0.19 |
35 | 35 | * @return mixed|null The geolocation database service. |
36 | 36 | */ |
37 | - $this->database_service = apply_filters( 'getpaid_maxmind_geolocation_database_service', null ); |
|
38 | - if ( null === $this->database_service ) { |
|
39 | - $this->database_service = new GetPaid_MaxMind_Database_Service( $this->get_database_prefix() ); |
|
37 | + $this->database_service = apply_filters('getpaid_maxmind_geolocation_database_service', null); |
|
38 | + if (null === $this->database_service) { |
|
39 | + $this->database_service = new GetPaid_MaxMind_Database_Service($this->get_database_prefix()); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | // Bind to the scheduled updater action. |
43 | - add_action( 'getpaid_update_geoip_databases', array( $this, 'update_database' ) ); |
|
43 | + add_action('getpaid_update_geoip_databases', array($this, 'update_database')); |
|
44 | 44 | |
45 | 45 | // Bind to the geolocation filter for MaxMind database lookups. |
46 | - add_filter( 'getpaid_get_geolocation', array( $this, 'get_geolocation' ), 10, 2 ); |
|
46 | + add_filter('getpaid_get_geolocation', array($this, 'get_geolocation'), 10, 2); |
|
47 | 47 | |
48 | 48 | // Handle maxmind key updates. |
49 | - add_filter( 'wpinv_settings_sanitize_maxmind_license_key', array( $this, 'handle_key_updates' ) ); |
|
49 | + add_filter('wpinv_settings_sanitize_maxmind_license_key', array($this, 'handle_key_updates')); |
|
50 | 50 | |
51 | 51 | } |
52 | 52 | |
@@ -65,29 +65,29 @@ discard block |
||
65 | 65 | * @param string $license_key The new license key. |
66 | 66 | * @return string |
67 | 67 | */ |
68 | - public function handle_key_updates( $license_key ) { |
|
68 | + public function handle_key_updates($license_key) { |
|
69 | 69 | |
70 | 70 | // Trim whitespaces and strip slashes. |
71 | - $license_key = trim( $license_key ); |
|
71 | + $license_key = trim($license_key); |
|
72 | 72 | |
73 | 73 | // Abort if the license key is empty or unchanged. |
74 | - if ( empty( $license_key ) ) { |
|
74 | + if (empty($license_key)) { |
|
75 | 75 | return $license_key; |
76 | 76 | } |
77 | 77 | |
78 | 78 | // Abort if a database exists and the license key is unchaged. |
79 | - if ( file_exists( $this->database_service->get_database_path() && $license_key == wpinv_get_option( 'maxmind_license_key' ) ) ) { |
|
79 | + if (file_exists($this->database_service->get_database_path() && $license_key == wpinv_get_option('maxmind_license_key'))) { |
|
80 | 80 | return $license_key; |
81 | 81 | } |
82 | 82 | |
83 | 83 | // Check the license key by attempting to download the Geolocation database. |
84 | - $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
85 | - if ( is_wp_error( $tmp_database_path ) ) { |
|
86 | - getpaid_admin()->show_error( $tmp_database_path->get_error_message() ); |
|
84 | + $tmp_database_path = $this->database_service->download_database($license_key); |
|
85 | + if (is_wp_error($tmp_database_path)) { |
|
86 | + getpaid_admin()->show_error($tmp_database_path->get_error_message()); |
|
87 | 87 | return $license_key; |
88 | 88 | } |
89 | 89 | |
90 | - $this->update_database( $tmp_database_path ); |
|
90 | + $this->update_database($tmp_database_path); |
|
91 | 91 | |
92 | 92 | } |
93 | 93 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * |
97 | 97 | * @param string $tmp_database_path Temporary database path. |
98 | 98 | */ |
99 | - public function update_database( $tmp_database_path = null ) { |
|
99 | + public function update_database($tmp_database_path = null) { |
|
100 | 100 | |
101 | 101 | // Allow us to easily interact with the filesystem. |
102 | 102 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
@@ -107,32 +107,32 @@ discard block |
||
107 | 107 | $target_database_path = $this->database_service->get_database_path(); |
108 | 108 | |
109 | 109 | // If there's no database path, we can't store the database. |
110 | - if ( empty( $target_database_path ) ) { |
|
110 | + if (empty($target_database_path)) { |
|
111 | 111 | return; |
112 | 112 | } |
113 | 113 | |
114 | - if ( $wp_filesystem->exists( $target_database_path ) ) { |
|
115 | - $wp_filesystem->delete( $target_database_path ); |
|
114 | + if ($wp_filesystem->exists($target_database_path)) { |
|
115 | + $wp_filesystem->delete($target_database_path); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | // We can't download a database if there's no license key configured. |
119 | - $license_key = wpinv_get_option( 'maxmind_license_key' ); |
|
120 | - if ( empty( $license_key ) ) { |
|
119 | + $license_key = wpinv_get_option('maxmind_license_key'); |
|
120 | + if (empty($license_key)) { |
|
121 | 121 | return; |
122 | 122 | } |
123 | 123 | |
124 | - if ( empty( $tmp_database_path ) ) { |
|
125 | - $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
124 | + if (empty($tmp_database_path)) { |
|
125 | + $tmp_database_path = $this->database_service->download_database($license_key); |
|
126 | 126 | } |
127 | 127 | |
128 | - if ( is_wp_error( $tmp_database_path ) ) { |
|
129 | - wpinv_error_log( $tmp_database_path->get_error_message() ); |
|
128 | + if (is_wp_error($tmp_database_path)) { |
|
129 | + wpinv_error_log($tmp_database_path->get_error_message()); |
|
130 | 130 | return; |
131 | 131 | } |
132 | 132 | |
133 | 133 | // Move the new database into position. |
134 | - $wp_filesystem->move( $tmp_database_path, $target_database_path, true ); |
|
135 | - $wp_filesystem->delete( dirname( $tmp_database_path ) ); |
|
134 | + $wp_filesystem->move($tmp_database_path, $target_database_path, true); |
|
135 | + $wp_filesystem->delete(dirname($tmp_database_path)); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -142,13 +142,13 @@ discard block |
||
142 | 142 | * @param string $ip_address The IP address to geolocate. |
143 | 143 | * @return array Geolocation including country code, state, city and postcode based on an IP address. |
144 | 144 | */ |
145 | - public function get_geolocation( $data, $ip_address ) { |
|
145 | + public function get_geolocation($data, $ip_address) { |
|
146 | 146 | |
147 | - if ( ! empty( $data['country'] ) || empty( $ip_address ) ) { |
|
147 | + if (!empty($data['country']) || empty($ip_address)) { |
|
148 | 148 | return $data; |
149 | 149 | } |
150 | 150 | |
151 | - $country_code = $this->database_service->get_iso_country_code_for_ip( $ip_address ); |
|
151 | + $country_code = $this->database_service->get_iso_country_code_for_ip($ip_address); |
|
152 | 152 | |
153 | 153 | return array( |
154 | 154 | 'country' => $country_code, |
@@ -166,11 +166,11 @@ discard block |
||
166 | 166 | */ |
167 | 167 | private function get_database_prefix() { |
168 | 168 | |
169 | - $prefix = get_option( 'wpinv_maxmind_database_prefix' ); |
|
169 | + $prefix = get_option('wpinv_maxmind_database_prefix'); |
|
170 | 170 | |
171 | - if ( empty( $prefix ) ) { |
|
172 | - $prefix = md5( uniqid( 'wpinv' ) ); |
|
173 | - update_option( 'wpinv_maxmind_database_prefix', $prefix ); |
|
171 | + if (empty($prefix)) { |
|
172 | + $prefix = md5(uniqid('wpinv')); |
|
173 | + update_option('wpinv_maxmind_database_prefix', $prefix); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | return $prefix; |
@@ -13,264 +13,264 @@ |
||
13 | 13 | */ |
14 | 14 | class GetPaid_Geolocation { |
15 | 15 | |
16 | - /** |
|
17 | - * Holds the current user's IP Address. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public static $current_user_ip; |
|
22 | - |
|
23 | - /** |
|
24 | - * API endpoints for looking up a user IP address. |
|
25 | - * |
|
26 | - * For example, in case a user is on localhost. |
|
27 | - * |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - protected static $ip_lookup_apis = array( |
|
31 | - 'ipify' => 'http://api.ipify.org/', |
|
32 | - 'ipecho' => 'http://ipecho.net/plain', |
|
33 | - 'ident' => 'http://ident.me', |
|
34 | - 'whatismyipaddress' => 'http://bot.whatismyipaddress.com', |
|
35 | - ); |
|
36 | - |
|
37 | - /** |
|
38 | - * API endpoints for geolocating an IP address |
|
39 | - * |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - protected static $geoip_apis = array( |
|
43 | - 'ipinfo.io' => 'https://ipinfo.io/%s/json', |
|
44 | - 'ip-api.com' => 'http://ip-api.com/json/%s', |
|
45 | - ); |
|
46 | - |
|
47 | - /** |
|
48 | - * Get current user IP Address. |
|
49 | - * |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - public static function get_ip_address() { |
|
53 | - return wpinv_get_ip(); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Get user IP Address using an external service. |
|
58 | - * This can be used as a fallback for users on localhost where |
|
59 | - * get_ip_address() will be a local IP and non-geolocatable. |
|
60 | - * |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - public static function get_external_ip_address() { |
|
64 | - |
|
65 | - $transient_name = 'external_ip_address_0.0.0.0'; |
|
66 | - |
|
67 | - if ( '' !== self::get_ip_address() ) { |
|
68 | - $transient_name = 'external_ip_address_' . self::get_ip_address(); |
|
69 | - } |
|
70 | - |
|
71 | - // Try retrieving from cache. |
|
72 | - $external_ip_address = get_transient( $transient_name ); |
|
73 | - |
|
74 | - if ( false === $external_ip_address ) { |
|
75 | - $external_ip_address = '0.0.0.0'; |
|
76 | - $ip_lookup_services = apply_filters( 'getpaid_geolocation_ip_lookup_apis', self::$ip_lookup_apis ); |
|
77 | - $ip_lookup_services_keys = array_keys( $ip_lookup_services ); |
|
78 | - shuffle( $ip_lookup_services_keys ); |
|
79 | - |
|
80 | - foreach ( $ip_lookup_services_keys as $service_name ) { |
|
81 | - $service_endpoint = $ip_lookup_services[ $service_name ]; |
|
82 | - $response = wp_safe_remote_get( $service_endpoint, array( 'timeout' => 2 ) ); |
|
83 | - |
|
84 | - if ( ! is_wp_error( $response ) && rest_is_ip_address( $response['body'] ) ) { |
|
85 | - $external_ip_address = apply_filters( 'getpaid_geolocation_ip_lookup_api_response', wpinv_clean( $response['body'] ), $service_name ); |
|
86 | - break; |
|
87 | - } |
|
88 | - |
|
89 | - } |
|
90 | - |
|
91 | - set_transient( $transient_name, $external_ip_address, WEEK_IN_SECONDS ); |
|
92 | - } |
|
93 | - |
|
94 | - return $external_ip_address; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Geolocate an IP address. |
|
99 | - * |
|
100 | - * @param string $ip_address IP Address. |
|
101 | - * @param bool $fallback If true, fallbacks to alternative IP detection (can be slower). |
|
102 | - * @param bool $api_fallback If true, uses geolocation APIs if the database file doesn't exist (can be slower). |
|
103 | - * @return array |
|
104 | - */ |
|
105 | - public static function geolocate_ip( $ip_address = '', $fallback = false, $api_fallback = true ) { |
|
106 | - |
|
107 | - if ( empty( $ip_address ) ) { |
|
108 | - $ip_address = self::get_ip_address(); |
|
109 | - } |
|
110 | - |
|
111 | - // Update the current user's IP Address. |
|
112 | - self::$current_user_ip = $ip_address; |
|
113 | - |
|
114 | - // Filter to allow custom geolocation of the IP address. |
|
115 | - $country_code = apply_filters( 'getpaid_geolocate_ip', false, $ip_address, $fallback, $api_fallback ); |
|
116 | - |
|
117 | - if ( false !== $country_code ) { |
|
118 | - |
|
119 | - return array( |
|
120 | - 'country' => $country_code, |
|
121 | - 'state' => '', |
|
122 | - 'city' => '', |
|
123 | - 'postcode' => '', |
|
124 | - ); |
|
125 | - |
|
126 | - } |
|
127 | - |
|
128 | - $country_code = self::get_country_code_from_headers(); |
|
129 | - |
|
130 | - /** |
|
131 | - * Get geolocation filter. |
|
132 | - * |
|
133 | - * @since 1.0.19 |
|
134 | - * @param array $geolocation Geolocation data, including country, state, city, and postcode. |
|
135 | - * @param string $ip_address IP Address. |
|
136 | - */ |
|
137 | - $geolocation = apply_filters( |
|
138 | - 'getpaid_get_geolocation', |
|
139 | - array( |
|
140 | - 'country' => $country_code, |
|
141 | - 'state' => '', |
|
142 | - 'city' => '', |
|
143 | - 'postcode' => '', |
|
144 | - ), |
|
145 | - $ip_address |
|
146 | - ); |
|
147 | - |
|
148 | - // If we still haven't found a country code, let's consider doing an API lookup. |
|
149 | - if ( '' === $geolocation['country'] && $api_fallback ) { |
|
150 | - $geolocation['country'] = self::geolocate_via_api( $ip_address ); |
|
151 | - } |
|
152 | - |
|
153 | - // It's possible that we're in a local environment, in which case the geolocation needs to be done from the |
|
154 | - // external address. |
|
155 | - if ( '' === $geolocation['country'] && $fallback ) { |
|
156 | - $external_ip_address = self::get_external_ip_address(); |
|
157 | - |
|
158 | - // Only bother with this if the external IP differs. |
|
159 | - if ( '0.0.0.0' !== $external_ip_address && $external_ip_address !== $ip_address ) { |
|
160 | - return self::geolocate_ip( $external_ip_address, false, $api_fallback ); |
|
161 | - } |
|
162 | - |
|
163 | - } |
|
164 | - |
|
165 | - return array( |
|
166 | - 'country' => $geolocation['country'], |
|
167 | - 'state' => $geolocation['state'], |
|
168 | - 'city' => $geolocation['city'], |
|
169 | - 'postcode' => $geolocation['postcode'], |
|
170 | - ); |
|
171 | - |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Fetches the country code from the request headers, if one is available. |
|
176 | - * |
|
177 | - * @since 1.0.19 |
|
178 | - * @return string The country code pulled from the headers, or empty string if one was not found. |
|
179 | - */ |
|
180 | - protected static function get_country_code_from_headers() { |
|
181 | - $country_code = ''; |
|
182 | - |
|
183 | - $headers = array( |
|
184 | - 'MM_COUNTRY_CODE', |
|
185 | - 'GEOIP_COUNTRY_CODE', |
|
186 | - 'HTTP_CF_IPCOUNTRY', |
|
187 | - 'HTTP_X_COUNTRY_CODE', |
|
188 | - ); |
|
189 | - |
|
190 | - foreach ( $headers as $header ) { |
|
191 | - if ( empty( $_SERVER[ $header ] ) ) { |
|
192 | - continue; |
|
193 | - } |
|
194 | - |
|
195 | - $country_code = strtoupper( sanitize_text_field( wp_unslash( $_SERVER[ $header ] ) ) ); |
|
196 | - break; |
|
197 | - } |
|
198 | - |
|
199 | - return $country_code; |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Use APIs to Geolocate the user. |
|
204 | - * |
|
205 | - * Geolocation APIs can be added through the use of the getpaid_geolocation_geoip_apis filter. |
|
206 | - * Provide a name=>value pair for service-slug=>endpoint. |
|
207 | - * |
|
208 | - * If APIs are defined, one will be chosen at random to fulfil the request. After completing, the result |
|
209 | - * will be cached in a transient. |
|
210 | - * |
|
211 | - * @param string $ip_address IP address. |
|
212 | - * @return string |
|
213 | - */ |
|
214 | - protected static function geolocate_via_api( $ip_address ) { |
|
215 | - |
|
216 | - // Retrieve from cache... |
|
217 | - $country_code = get_transient( 'geoip_' . $ip_address ); |
|
218 | - |
|
219 | - // If missing, retrieve from the API. |
|
220 | - if ( false === $country_code ) { |
|
221 | - $geoip_services = apply_filters( 'getpaid_geolocation_geoip_apis', self::$geoip_apis ); |
|
222 | - |
|
223 | - if ( empty( $geoip_services ) ) { |
|
224 | - return ''; |
|
225 | - } |
|
226 | - |
|
227 | - $geoip_services_keys = array_keys( $geoip_services ); |
|
228 | - |
|
229 | - shuffle( $geoip_services_keys ); |
|
230 | - |
|
231 | - foreach ( $geoip_services_keys as $service_name ) { |
|
232 | - |
|
233 | - $service_endpoint = $geoip_services[ $service_name ]; |
|
234 | - $response = wp_safe_remote_get( sprintf( $service_endpoint, $ip_address ), array( 'timeout' => 2 ) ); |
|
235 | - $country_code = sanitize_text_field( strtoupper( self::handle_geolocation_response( $response, $service_name ) ) ); |
|
236 | - |
|
237 | - if ( ! empty( $country_code ) ) { |
|
238 | - break; |
|
239 | - } |
|
240 | - |
|
241 | - } |
|
242 | - |
|
243 | - set_transient( 'geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS ); |
|
244 | - } |
|
245 | - |
|
246 | - return $country_code; |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * Handles geolocation response |
|
251 | - * |
|
252 | - * @param WP_Error|String $geolocation_response |
|
253 | - * @param String $geolocation_service |
|
254 | - * @return string Country code |
|
255 | - */ |
|
256 | - protected static function handle_geolocation_response( $geolocation_response, $geolocation_service ) { |
|
257 | - |
|
258 | - if ( is_wp_error( $geolocation_response ) || empty( $geolocation_response['body'] ) ) { |
|
259 | - return ''; |
|
260 | - } |
|
261 | - |
|
262 | - if ( $geolocation_service === 'ipinfo.io' ) { |
|
263 | - $data = json_decode( $geolocation_response['body'] ); |
|
264 | - return empty( $data ) ? '' : $data->country; |
|
265 | - } |
|
266 | - |
|
267 | - if ( $geolocation_service === 'ip-api.com' ) { |
|
268 | - $data = json_decode( $geolocation_response['body'] ); |
|
269 | - return empty( $data ) ? '' : $data->countryCode; |
|
270 | - } |
|
271 | - |
|
272 | - return apply_filters( 'getpaid_geolocation_geoip_response_' . $geolocation_service, '', $geolocation_response['body'] ); |
|
273 | - |
|
274 | - } |
|
16 | + /** |
|
17 | + * Holds the current user's IP Address. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public static $current_user_ip; |
|
22 | + |
|
23 | + /** |
|
24 | + * API endpoints for looking up a user IP address. |
|
25 | + * |
|
26 | + * For example, in case a user is on localhost. |
|
27 | + * |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + protected static $ip_lookup_apis = array( |
|
31 | + 'ipify' => 'http://api.ipify.org/', |
|
32 | + 'ipecho' => 'http://ipecho.net/plain', |
|
33 | + 'ident' => 'http://ident.me', |
|
34 | + 'whatismyipaddress' => 'http://bot.whatismyipaddress.com', |
|
35 | + ); |
|
36 | + |
|
37 | + /** |
|
38 | + * API endpoints for geolocating an IP address |
|
39 | + * |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + protected static $geoip_apis = array( |
|
43 | + 'ipinfo.io' => 'https://ipinfo.io/%s/json', |
|
44 | + 'ip-api.com' => 'http://ip-api.com/json/%s', |
|
45 | + ); |
|
46 | + |
|
47 | + /** |
|
48 | + * Get current user IP Address. |
|
49 | + * |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + public static function get_ip_address() { |
|
53 | + return wpinv_get_ip(); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Get user IP Address using an external service. |
|
58 | + * This can be used as a fallback for users on localhost where |
|
59 | + * get_ip_address() will be a local IP and non-geolocatable. |
|
60 | + * |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + public static function get_external_ip_address() { |
|
64 | + |
|
65 | + $transient_name = 'external_ip_address_0.0.0.0'; |
|
66 | + |
|
67 | + if ( '' !== self::get_ip_address() ) { |
|
68 | + $transient_name = 'external_ip_address_' . self::get_ip_address(); |
|
69 | + } |
|
70 | + |
|
71 | + // Try retrieving from cache. |
|
72 | + $external_ip_address = get_transient( $transient_name ); |
|
73 | + |
|
74 | + if ( false === $external_ip_address ) { |
|
75 | + $external_ip_address = '0.0.0.0'; |
|
76 | + $ip_lookup_services = apply_filters( 'getpaid_geolocation_ip_lookup_apis', self::$ip_lookup_apis ); |
|
77 | + $ip_lookup_services_keys = array_keys( $ip_lookup_services ); |
|
78 | + shuffle( $ip_lookup_services_keys ); |
|
79 | + |
|
80 | + foreach ( $ip_lookup_services_keys as $service_name ) { |
|
81 | + $service_endpoint = $ip_lookup_services[ $service_name ]; |
|
82 | + $response = wp_safe_remote_get( $service_endpoint, array( 'timeout' => 2 ) ); |
|
83 | + |
|
84 | + if ( ! is_wp_error( $response ) && rest_is_ip_address( $response['body'] ) ) { |
|
85 | + $external_ip_address = apply_filters( 'getpaid_geolocation_ip_lookup_api_response', wpinv_clean( $response['body'] ), $service_name ); |
|
86 | + break; |
|
87 | + } |
|
88 | + |
|
89 | + } |
|
90 | + |
|
91 | + set_transient( $transient_name, $external_ip_address, WEEK_IN_SECONDS ); |
|
92 | + } |
|
93 | + |
|
94 | + return $external_ip_address; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Geolocate an IP address. |
|
99 | + * |
|
100 | + * @param string $ip_address IP Address. |
|
101 | + * @param bool $fallback If true, fallbacks to alternative IP detection (can be slower). |
|
102 | + * @param bool $api_fallback If true, uses geolocation APIs if the database file doesn't exist (can be slower). |
|
103 | + * @return array |
|
104 | + */ |
|
105 | + public static function geolocate_ip( $ip_address = '', $fallback = false, $api_fallback = true ) { |
|
106 | + |
|
107 | + if ( empty( $ip_address ) ) { |
|
108 | + $ip_address = self::get_ip_address(); |
|
109 | + } |
|
110 | + |
|
111 | + // Update the current user's IP Address. |
|
112 | + self::$current_user_ip = $ip_address; |
|
113 | + |
|
114 | + // Filter to allow custom geolocation of the IP address. |
|
115 | + $country_code = apply_filters( 'getpaid_geolocate_ip', false, $ip_address, $fallback, $api_fallback ); |
|
116 | + |
|
117 | + if ( false !== $country_code ) { |
|
118 | + |
|
119 | + return array( |
|
120 | + 'country' => $country_code, |
|
121 | + 'state' => '', |
|
122 | + 'city' => '', |
|
123 | + 'postcode' => '', |
|
124 | + ); |
|
125 | + |
|
126 | + } |
|
127 | + |
|
128 | + $country_code = self::get_country_code_from_headers(); |
|
129 | + |
|
130 | + /** |
|
131 | + * Get geolocation filter. |
|
132 | + * |
|
133 | + * @since 1.0.19 |
|
134 | + * @param array $geolocation Geolocation data, including country, state, city, and postcode. |
|
135 | + * @param string $ip_address IP Address. |
|
136 | + */ |
|
137 | + $geolocation = apply_filters( |
|
138 | + 'getpaid_get_geolocation', |
|
139 | + array( |
|
140 | + 'country' => $country_code, |
|
141 | + 'state' => '', |
|
142 | + 'city' => '', |
|
143 | + 'postcode' => '', |
|
144 | + ), |
|
145 | + $ip_address |
|
146 | + ); |
|
147 | + |
|
148 | + // If we still haven't found a country code, let's consider doing an API lookup. |
|
149 | + if ( '' === $geolocation['country'] && $api_fallback ) { |
|
150 | + $geolocation['country'] = self::geolocate_via_api( $ip_address ); |
|
151 | + } |
|
152 | + |
|
153 | + // It's possible that we're in a local environment, in which case the geolocation needs to be done from the |
|
154 | + // external address. |
|
155 | + if ( '' === $geolocation['country'] && $fallback ) { |
|
156 | + $external_ip_address = self::get_external_ip_address(); |
|
157 | + |
|
158 | + // Only bother with this if the external IP differs. |
|
159 | + if ( '0.0.0.0' !== $external_ip_address && $external_ip_address !== $ip_address ) { |
|
160 | + return self::geolocate_ip( $external_ip_address, false, $api_fallback ); |
|
161 | + } |
|
162 | + |
|
163 | + } |
|
164 | + |
|
165 | + return array( |
|
166 | + 'country' => $geolocation['country'], |
|
167 | + 'state' => $geolocation['state'], |
|
168 | + 'city' => $geolocation['city'], |
|
169 | + 'postcode' => $geolocation['postcode'], |
|
170 | + ); |
|
171 | + |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Fetches the country code from the request headers, if one is available. |
|
176 | + * |
|
177 | + * @since 1.0.19 |
|
178 | + * @return string The country code pulled from the headers, or empty string if one was not found. |
|
179 | + */ |
|
180 | + protected static function get_country_code_from_headers() { |
|
181 | + $country_code = ''; |
|
182 | + |
|
183 | + $headers = array( |
|
184 | + 'MM_COUNTRY_CODE', |
|
185 | + 'GEOIP_COUNTRY_CODE', |
|
186 | + 'HTTP_CF_IPCOUNTRY', |
|
187 | + 'HTTP_X_COUNTRY_CODE', |
|
188 | + ); |
|
189 | + |
|
190 | + foreach ( $headers as $header ) { |
|
191 | + if ( empty( $_SERVER[ $header ] ) ) { |
|
192 | + continue; |
|
193 | + } |
|
194 | + |
|
195 | + $country_code = strtoupper( sanitize_text_field( wp_unslash( $_SERVER[ $header ] ) ) ); |
|
196 | + break; |
|
197 | + } |
|
198 | + |
|
199 | + return $country_code; |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Use APIs to Geolocate the user. |
|
204 | + * |
|
205 | + * Geolocation APIs can be added through the use of the getpaid_geolocation_geoip_apis filter. |
|
206 | + * Provide a name=>value pair for service-slug=>endpoint. |
|
207 | + * |
|
208 | + * If APIs are defined, one will be chosen at random to fulfil the request. After completing, the result |
|
209 | + * will be cached in a transient. |
|
210 | + * |
|
211 | + * @param string $ip_address IP address. |
|
212 | + * @return string |
|
213 | + */ |
|
214 | + protected static function geolocate_via_api( $ip_address ) { |
|
215 | + |
|
216 | + // Retrieve from cache... |
|
217 | + $country_code = get_transient( 'geoip_' . $ip_address ); |
|
218 | + |
|
219 | + // If missing, retrieve from the API. |
|
220 | + if ( false === $country_code ) { |
|
221 | + $geoip_services = apply_filters( 'getpaid_geolocation_geoip_apis', self::$geoip_apis ); |
|
222 | + |
|
223 | + if ( empty( $geoip_services ) ) { |
|
224 | + return ''; |
|
225 | + } |
|
226 | + |
|
227 | + $geoip_services_keys = array_keys( $geoip_services ); |
|
228 | + |
|
229 | + shuffle( $geoip_services_keys ); |
|
230 | + |
|
231 | + foreach ( $geoip_services_keys as $service_name ) { |
|
232 | + |
|
233 | + $service_endpoint = $geoip_services[ $service_name ]; |
|
234 | + $response = wp_safe_remote_get( sprintf( $service_endpoint, $ip_address ), array( 'timeout' => 2 ) ); |
|
235 | + $country_code = sanitize_text_field( strtoupper( self::handle_geolocation_response( $response, $service_name ) ) ); |
|
236 | + |
|
237 | + if ( ! empty( $country_code ) ) { |
|
238 | + break; |
|
239 | + } |
|
240 | + |
|
241 | + } |
|
242 | + |
|
243 | + set_transient( 'geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS ); |
|
244 | + } |
|
245 | + |
|
246 | + return $country_code; |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * Handles geolocation response |
|
251 | + * |
|
252 | + * @param WP_Error|String $geolocation_response |
|
253 | + * @param String $geolocation_service |
|
254 | + * @return string Country code |
|
255 | + */ |
|
256 | + protected static function handle_geolocation_response( $geolocation_response, $geolocation_service ) { |
|
257 | + |
|
258 | + if ( is_wp_error( $geolocation_response ) || empty( $geolocation_response['body'] ) ) { |
|
259 | + return ''; |
|
260 | + } |
|
261 | + |
|
262 | + if ( $geolocation_service === 'ipinfo.io' ) { |
|
263 | + $data = json_decode( $geolocation_response['body'] ); |
|
264 | + return empty( $data ) ? '' : $data->country; |
|
265 | + } |
|
266 | + |
|
267 | + if ( $geolocation_service === 'ip-api.com' ) { |
|
268 | + $data = json_decode( $geolocation_response['body'] ); |
|
269 | + return empty( $data ) ? '' : $data->countryCode; |
|
270 | + } |
|
271 | + |
|
272 | + return apply_filters( 'getpaid_geolocation_geoip_response_' . $geolocation_service, '', $geolocation_response['body'] ); |
|
273 | + |
|
274 | + } |
|
275 | 275 | |
276 | 276 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * GetPaid_Geolocation Class. |
@@ -64,31 +64,31 @@ discard block |
||
64 | 64 | |
65 | 65 | $transient_name = 'external_ip_address_0.0.0.0'; |
66 | 66 | |
67 | - if ( '' !== self::get_ip_address() ) { |
|
68 | - $transient_name = 'external_ip_address_' . self::get_ip_address(); |
|
67 | + if ('' !== self::get_ip_address()) { |
|
68 | + $transient_name = 'external_ip_address_' . self::get_ip_address(); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | // Try retrieving from cache. |
72 | - $external_ip_address = get_transient( $transient_name ); |
|
72 | + $external_ip_address = get_transient($transient_name); |
|
73 | 73 | |
74 | - if ( false === $external_ip_address ) { |
|
74 | + if (false === $external_ip_address) { |
|
75 | 75 | $external_ip_address = '0.0.0.0'; |
76 | - $ip_lookup_services = apply_filters( 'getpaid_geolocation_ip_lookup_apis', self::$ip_lookup_apis ); |
|
77 | - $ip_lookup_services_keys = array_keys( $ip_lookup_services ); |
|
78 | - shuffle( $ip_lookup_services_keys ); |
|
76 | + $ip_lookup_services = apply_filters('getpaid_geolocation_ip_lookup_apis', self::$ip_lookup_apis); |
|
77 | + $ip_lookup_services_keys = array_keys($ip_lookup_services); |
|
78 | + shuffle($ip_lookup_services_keys); |
|
79 | 79 | |
80 | - foreach ( $ip_lookup_services_keys as $service_name ) { |
|
81 | - $service_endpoint = $ip_lookup_services[ $service_name ]; |
|
82 | - $response = wp_safe_remote_get( $service_endpoint, array( 'timeout' => 2 ) ); |
|
80 | + foreach ($ip_lookup_services_keys as $service_name) { |
|
81 | + $service_endpoint = $ip_lookup_services[$service_name]; |
|
82 | + $response = wp_safe_remote_get($service_endpoint, array('timeout' => 2)); |
|
83 | 83 | |
84 | - if ( ! is_wp_error( $response ) && rest_is_ip_address( $response['body'] ) ) { |
|
85 | - $external_ip_address = apply_filters( 'getpaid_geolocation_ip_lookup_api_response', wpinv_clean( $response['body'] ), $service_name ); |
|
84 | + if (!is_wp_error($response) && rest_is_ip_address($response['body'])) { |
|
85 | + $external_ip_address = apply_filters('getpaid_geolocation_ip_lookup_api_response', wpinv_clean($response['body']), $service_name); |
|
86 | 86 | break; |
87 | 87 | } |
88 | 88 | |
89 | 89 | } |
90 | 90 | |
91 | - set_transient( $transient_name, $external_ip_address, WEEK_IN_SECONDS ); |
|
91 | + set_transient($transient_name, $external_ip_address, WEEK_IN_SECONDS); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | return $external_ip_address; |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | * @param bool $api_fallback If true, uses geolocation APIs if the database file doesn't exist (can be slower). |
103 | 103 | * @return array |
104 | 104 | */ |
105 | - public static function geolocate_ip( $ip_address = '', $fallback = false, $api_fallback = true ) { |
|
105 | + public static function geolocate_ip($ip_address = '', $fallback = false, $api_fallback = true) { |
|
106 | 106 | |
107 | - if ( empty( $ip_address ) ) { |
|
107 | + if (empty($ip_address)) { |
|
108 | 108 | $ip_address = self::get_ip_address(); |
109 | 109 | } |
110 | 110 | |
@@ -112,9 +112,9 @@ discard block |
||
112 | 112 | self::$current_user_ip = $ip_address; |
113 | 113 | |
114 | 114 | // Filter to allow custom geolocation of the IP address. |
115 | - $country_code = apply_filters( 'getpaid_geolocate_ip', false, $ip_address, $fallback, $api_fallback ); |
|
115 | + $country_code = apply_filters('getpaid_geolocate_ip', false, $ip_address, $fallback, $api_fallback); |
|
116 | 116 | |
117 | - if ( false !== $country_code ) { |
|
117 | + if (false !== $country_code) { |
|
118 | 118 | |
119 | 119 | return array( |
120 | 120 | 'country' => $country_code, |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * @param array $geolocation Geolocation data, including country, state, city, and postcode. |
135 | 135 | * @param string $ip_address IP Address. |
136 | 136 | */ |
137 | - $geolocation = apply_filters( |
|
137 | + $geolocation = apply_filters( |
|
138 | 138 | 'getpaid_get_geolocation', |
139 | 139 | array( |
140 | 140 | 'country' => $country_code, |
@@ -146,18 +146,18 @@ discard block |
||
146 | 146 | ); |
147 | 147 | |
148 | 148 | // If we still haven't found a country code, let's consider doing an API lookup. |
149 | - if ( '' === $geolocation['country'] && $api_fallback ) { |
|
150 | - $geolocation['country'] = self::geolocate_via_api( $ip_address ); |
|
149 | + if ('' === $geolocation['country'] && $api_fallback) { |
|
150 | + $geolocation['country'] = self::geolocate_via_api($ip_address); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | // It's possible that we're in a local environment, in which case the geolocation needs to be done from the |
154 | 154 | // external address. |
155 | - if ( '' === $geolocation['country'] && $fallback ) { |
|
155 | + if ('' === $geolocation['country'] && $fallback) { |
|
156 | 156 | $external_ip_address = self::get_external_ip_address(); |
157 | 157 | |
158 | 158 | // Only bother with this if the external IP differs. |
159 | - if ( '0.0.0.0' !== $external_ip_address && $external_ip_address !== $ip_address ) { |
|
160 | - return self::geolocate_ip( $external_ip_address, false, $api_fallback ); |
|
159 | + if ('0.0.0.0' !== $external_ip_address && $external_ip_address !== $ip_address) { |
|
160 | + return self::geolocate_ip($external_ip_address, false, $api_fallback); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | } |
@@ -187,12 +187,12 @@ discard block |
||
187 | 187 | 'HTTP_X_COUNTRY_CODE', |
188 | 188 | ); |
189 | 189 | |
190 | - foreach ( $headers as $header ) { |
|
191 | - if ( empty( $_SERVER[ $header ] ) ) { |
|
190 | + foreach ($headers as $header) { |
|
191 | + if (empty($_SERVER[$header])) { |
|
192 | 192 | continue; |
193 | 193 | } |
194 | 194 | |
195 | - $country_code = strtoupper( sanitize_text_field( wp_unslash( $_SERVER[ $header ] ) ) ); |
|
195 | + $country_code = strtoupper(sanitize_text_field(wp_unslash($_SERVER[$header]))); |
|
196 | 196 | break; |
197 | 197 | } |
198 | 198 | |
@@ -211,36 +211,36 @@ discard block |
||
211 | 211 | * @param string $ip_address IP address. |
212 | 212 | * @return string |
213 | 213 | */ |
214 | - protected static function geolocate_via_api( $ip_address ) { |
|
214 | + protected static function geolocate_via_api($ip_address) { |
|
215 | 215 | |
216 | 216 | // Retrieve from cache... |
217 | - $country_code = get_transient( 'geoip_' . $ip_address ); |
|
217 | + $country_code = get_transient('geoip_' . $ip_address); |
|
218 | 218 | |
219 | 219 | // If missing, retrieve from the API. |
220 | - if ( false === $country_code ) { |
|
221 | - $geoip_services = apply_filters( 'getpaid_geolocation_geoip_apis', self::$geoip_apis ); |
|
220 | + if (false === $country_code) { |
|
221 | + $geoip_services = apply_filters('getpaid_geolocation_geoip_apis', self::$geoip_apis); |
|
222 | 222 | |
223 | - if ( empty( $geoip_services ) ) { |
|
223 | + if (empty($geoip_services)) { |
|
224 | 224 | return ''; |
225 | 225 | } |
226 | 226 | |
227 | - $geoip_services_keys = array_keys( $geoip_services ); |
|
227 | + $geoip_services_keys = array_keys($geoip_services); |
|
228 | 228 | |
229 | - shuffle( $geoip_services_keys ); |
|
229 | + shuffle($geoip_services_keys); |
|
230 | 230 | |
231 | - foreach ( $geoip_services_keys as $service_name ) { |
|
231 | + foreach ($geoip_services_keys as $service_name) { |
|
232 | 232 | |
233 | - $service_endpoint = $geoip_services[ $service_name ]; |
|
234 | - $response = wp_safe_remote_get( sprintf( $service_endpoint, $ip_address ), array( 'timeout' => 2 ) ); |
|
235 | - $country_code = sanitize_text_field( strtoupper( self::handle_geolocation_response( $response, $service_name ) ) ); |
|
233 | + $service_endpoint = $geoip_services[$service_name]; |
|
234 | + $response = wp_safe_remote_get(sprintf($service_endpoint, $ip_address), array('timeout' => 2)); |
|
235 | + $country_code = sanitize_text_field(strtoupper(self::handle_geolocation_response($response, $service_name))); |
|
236 | 236 | |
237 | - if ( ! empty( $country_code ) ) { |
|
237 | + if (!empty($country_code)) { |
|
238 | 238 | break; |
239 | 239 | } |
240 | 240 | |
241 | 241 | } |
242 | 242 | |
243 | - set_transient( 'geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS ); |
|
243 | + set_transient('geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | return $country_code; |
@@ -253,23 +253,23 @@ discard block |
||
253 | 253 | * @param String $geolocation_service |
254 | 254 | * @return string Country code |
255 | 255 | */ |
256 | - protected static function handle_geolocation_response( $geolocation_response, $geolocation_service ) { |
|
256 | + protected static function handle_geolocation_response($geolocation_response, $geolocation_service) { |
|
257 | 257 | |
258 | - if ( is_wp_error( $geolocation_response ) || empty( $geolocation_response['body'] ) ) { |
|
258 | + if (is_wp_error($geolocation_response) || empty($geolocation_response['body'])) { |
|
259 | 259 | return ''; |
260 | 260 | } |
261 | 261 | |
262 | - if ( $geolocation_service === 'ipinfo.io' ) { |
|
263 | - $data = json_decode( $geolocation_response['body'] ); |
|
264 | - return empty( $data ) ? '' : $data->country; |
|
262 | + if ($geolocation_service === 'ipinfo.io') { |
|
263 | + $data = json_decode($geolocation_response['body']); |
|
264 | + return empty($data) ? '' : $data->country; |
|
265 | 265 | } |
266 | 266 | |
267 | - if ( $geolocation_service === 'ip-api.com' ) { |
|
268 | - $data = json_decode( $geolocation_response['body'] ); |
|
269 | - return empty( $data ) ? '' : $data->countryCode; |
|
267 | + if ($geolocation_service === 'ip-api.com') { |
|
268 | + $data = json_decode($geolocation_response['body']); |
|
269 | + return empty($data) ? '' : $data->countryCode; |
|
270 | 270 | } |
271 | 271 | |
272 | - return apply_filters( 'getpaid_geolocation_geoip_response_' . $geolocation_service, '', $geolocation_response['body'] ); |
|
272 | + return apply_filters('getpaid_geolocation_geoip_response_' . $geolocation_service, '', $geolocation_response['body']); |
|
273 | 273 | |
274 | 274 | } |
275 | 275 |
@@ -13,152 +13,152 @@ |
||
13 | 13 | */ |
14 | 14 | class GetPaid_MaxMind_Database_Service { |
15 | 15 | |
16 | - /** |
|
17 | - * The name of the MaxMind database to utilize. |
|
18 | - */ |
|
19 | - const DATABASE = 'GeoLite2-Country'; |
|
20 | - |
|
21 | - /** |
|
22 | - * The extension for the MaxMind database. |
|
23 | - */ |
|
24 | - const DATABASE_EXTENSION = '.mmdb'; |
|
25 | - |
|
26 | - /** |
|
27 | - * A prefix for the MaxMind database filename. |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - private $database_prefix; |
|
32 | - |
|
33 | - /** |
|
34 | - * Class constructor. |
|
35 | - * |
|
36 | - * @param string|null $database_prefix A prefix for the MaxMind database filename. |
|
37 | - */ |
|
38 | - public function __construct( $database_prefix ) { |
|
39 | - $this->database_prefix = $database_prefix; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Fetches the path that the database should be stored. |
|
44 | - * |
|
45 | - * @return string The local database path. |
|
46 | - */ |
|
47 | - public function get_database_path() { |
|
48 | - $uploads_dir = wp_upload_dir(); |
|
49 | - |
|
50 | - $database_path = trailingslashit( $uploads_dir['basedir'] ) . 'invoicing/'; |
|
51 | - if ( ! empty( $this->database_prefix ) ) { |
|
52 | - $database_path .= $this->database_prefix . '-'; |
|
53 | - } |
|
54 | - $database_path .= self::DATABASE . self::DATABASE_EXTENSION; |
|
55 | - |
|
56 | - // Filter the geolocation database storage path. |
|
57 | - return apply_filters( 'getpaid_maxmind_geolocation_database_path', $database_path ); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Fetches the database from the MaxMind service. |
|
62 | - * |
|
63 | - * @param string $license_key The license key to be used when downloading the database. |
|
64 | - * @return string|WP_Error The path to the database file or an error if invalid. |
|
65 | - */ |
|
66 | - public function download_database( $license_key ) { |
|
67 | - |
|
68 | - $download_uri = add_query_arg( |
|
69 | - array( |
|
70 | - 'edition_id' => self::DATABASE, |
|
71 | - 'license_key' => urlencode( wpinv_clean( $license_key ) ), |
|
72 | - 'suffix' => 'tar.gz', |
|
73 | - ), |
|
74 | - 'https://download.maxmind.com/app/geoip_download' |
|
75 | - ); |
|
76 | - |
|
77 | - // Needed for the download_url call right below. |
|
78 | - require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
79 | - |
|
80 | - $tmp_archive_path = download_url( esc_url_raw( $download_uri ) ); |
|
81 | - |
|
82 | - if ( is_wp_error( $tmp_archive_path ) ) { |
|
83 | - // Transform the error into something more informative. |
|
84 | - $error_data = $tmp_archive_path->get_error_data(); |
|
85 | - if ( isset( $error_data['code'] ) && $error_data['code'] == 401 ) { |
|
86 | - return new WP_Error( |
|
87 | - 'getpaid_maxmind_geolocation_database_license_key', |
|
88 | - __( 'The MaxMind license key is invalid. If you have recently created this key, you may need to wait for it to become active.', 'invoicing' ) |
|
89 | - ); |
|
90 | - } |
|
91 | - |
|
92 | - return new WP_Error( 'getpaid_maxmind_geolocation_database_download', __( 'Failed to download the MaxMind database.', 'invoicing' ) ); |
|
93 | - } |
|
94 | - |
|
95 | - // Extract the database from the archive. |
|
96 | - return $this->extract_downloaded_database( $tmp_archive_path ); |
|
97 | - |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Extracts the downloaded database. |
|
102 | - * |
|
103 | - * @param string $tmp_archive_path The database archive path. |
|
104 | - * @return string|WP_Error The path to the database file or an error if invalid. |
|
105 | - */ |
|
106 | - protected function extract_downloaded_database( $tmp_archive_path ) { |
|
107 | - |
|
108 | - // Extract the database from the archive. |
|
109 | - try { |
|
110 | - |
|
111 | - $file = new PharData( $tmp_archive_path ); |
|
112 | - $tmp_database_path = trailingslashit( dirname( $tmp_archive_path ) ) . trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION; |
|
113 | - |
|
114 | - $file->extractTo( |
|
115 | - dirname( $tmp_archive_path ), |
|
116 | - trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION, |
|
117 | - true |
|
118 | - ); |
|
119 | - |
|
120 | - } catch ( Exception $exception ) { |
|
121 | - return new WP_Error( 'invoicing_maxmind_geolocation_database_archive', $exception->getMessage() ); |
|
122 | - } finally { |
|
123 | - // Remove the archive since we only care about a single file in it. |
|
124 | - unlink( $tmp_archive_path ); |
|
125 | - } |
|
126 | - |
|
127 | - return $tmp_database_path; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Fetches the ISO country code associated with an IP address. |
|
132 | - * |
|
133 | - * @param string $ip_address The IP address to find the country code for. |
|
134 | - * @return string The country code for the IP address, or empty if not found. |
|
135 | - */ |
|
136 | - public function get_iso_country_code_for_ip( $ip_address ) { |
|
137 | - $country_code = ''; |
|
138 | - |
|
139 | - if ( ! class_exists( 'MaxMind\Db\Reader' ) ) { |
|
140 | - return $country_code; |
|
141 | - } |
|
142 | - |
|
143 | - $database_path = $this->get_database_path(); |
|
144 | - if ( ! file_exists( $database_path ) ) { |
|
145 | - return $country_code; |
|
146 | - } |
|
147 | - |
|
148 | - try { |
|
149 | - $reader = new MaxMind\Db\Reader( $database_path ); |
|
150 | - $data = $reader->get( $ip_address ); |
|
151 | - |
|
152 | - if ( isset( $data['country']['iso_code'] ) ) { |
|
153 | - $country_code = $data['country']['iso_code']; |
|
154 | - } |
|
155 | - |
|
156 | - $reader->close(); |
|
157 | - } catch ( Exception $e ) { |
|
158 | - wpinv_error_log( $e->getMessage(), 'SOURCE: MaxMind GeoLocation' ); |
|
159 | - } |
|
160 | - |
|
161 | - return $country_code; |
|
162 | - } |
|
16 | + /** |
|
17 | + * The name of the MaxMind database to utilize. |
|
18 | + */ |
|
19 | + const DATABASE = 'GeoLite2-Country'; |
|
20 | + |
|
21 | + /** |
|
22 | + * The extension for the MaxMind database. |
|
23 | + */ |
|
24 | + const DATABASE_EXTENSION = '.mmdb'; |
|
25 | + |
|
26 | + /** |
|
27 | + * A prefix for the MaxMind database filename. |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + private $database_prefix; |
|
32 | + |
|
33 | + /** |
|
34 | + * Class constructor. |
|
35 | + * |
|
36 | + * @param string|null $database_prefix A prefix for the MaxMind database filename. |
|
37 | + */ |
|
38 | + public function __construct( $database_prefix ) { |
|
39 | + $this->database_prefix = $database_prefix; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Fetches the path that the database should be stored. |
|
44 | + * |
|
45 | + * @return string The local database path. |
|
46 | + */ |
|
47 | + public function get_database_path() { |
|
48 | + $uploads_dir = wp_upload_dir(); |
|
49 | + |
|
50 | + $database_path = trailingslashit( $uploads_dir['basedir'] ) . 'invoicing/'; |
|
51 | + if ( ! empty( $this->database_prefix ) ) { |
|
52 | + $database_path .= $this->database_prefix . '-'; |
|
53 | + } |
|
54 | + $database_path .= self::DATABASE . self::DATABASE_EXTENSION; |
|
55 | + |
|
56 | + // Filter the geolocation database storage path. |
|
57 | + return apply_filters( 'getpaid_maxmind_geolocation_database_path', $database_path ); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Fetches the database from the MaxMind service. |
|
62 | + * |
|
63 | + * @param string $license_key The license key to be used when downloading the database. |
|
64 | + * @return string|WP_Error The path to the database file or an error if invalid. |
|
65 | + */ |
|
66 | + public function download_database( $license_key ) { |
|
67 | + |
|
68 | + $download_uri = add_query_arg( |
|
69 | + array( |
|
70 | + 'edition_id' => self::DATABASE, |
|
71 | + 'license_key' => urlencode( wpinv_clean( $license_key ) ), |
|
72 | + 'suffix' => 'tar.gz', |
|
73 | + ), |
|
74 | + 'https://download.maxmind.com/app/geoip_download' |
|
75 | + ); |
|
76 | + |
|
77 | + // Needed for the download_url call right below. |
|
78 | + require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
79 | + |
|
80 | + $tmp_archive_path = download_url( esc_url_raw( $download_uri ) ); |
|
81 | + |
|
82 | + if ( is_wp_error( $tmp_archive_path ) ) { |
|
83 | + // Transform the error into something more informative. |
|
84 | + $error_data = $tmp_archive_path->get_error_data(); |
|
85 | + if ( isset( $error_data['code'] ) && $error_data['code'] == 401 ) { |
|
86 | + return new WP_Error( |
|
87 | + 'getpaid_maxmind_geolocation_database_license_key', |
|
88 | + __( 'The MaxMind license key is invalid. If you have recently created this key, you may need to wait for it to become active.', 'invoicing' ) |
|
89 | + ); |
|
90 | + } |
|
91 | + |
|
92 | + return new WP_Error( 'getpaid_maxmind_geolocation_database_download', __( 'Failed to download the MaxMind database.', 'invoicing' ) ); |
|
93 | + } |
|
94 | + |
|
95 | + // Extract the database from the archive. |
|
96 | + return $this->extract_downloaded_database( $tmp_archive_path ); |
|
97 | + |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Extracts the downloaded database. |
|
102 | + * |
|
103 | + * @param string $tmp_archive_path The database archive path. |
|
104 | + * @return string|WP_Error The path to the database file or an error if invalid. |
|
105 | + */ |
|
106 | + protected function extract_downloaded_database( $tmp_archive_path ) { |
|
107 | + |
|
108 | + // Extract the database from the archive. |
|
109 | + try { |
|
110 | + |
|
111 | + $file = new PharData( $tmp_archive_path ); |
|
112 | + $tmp_database_path = trailingslashit( dirname( $tmp_archive_path ) ) . trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION; |
|
113 | + |
|
114 | + $file->extractTo( |
|
115 | + dirname( $tmp_archive_path ), |
|
116 | + trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION, |
|
117 | + true |
|
118 | + ); |
|
119 | + |
|
120 | + } catch ( Exception $exception ) { |
|
121 | + return new WP_Error( 'invoicing_maxmind_geolocation_database_archive', $exception->getMessage() ); |
|
122 | + } finally { |
|
123 | + // Remove the archive since we only care about a single file in it. |
|
124 | + unlink( $tmp_archive_path ); |
|
125 | + } |
|
126 | + |
|
127 | + return $tmp_database_path; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Fetches the ISO country code associated with an IP address. |
|
132 | + * |
|
133 | + * @param string $ip_address The IP address to find the country code for. |
|
134 | + * @return string The country code for the IP address, or empty if not found. |
|
135 | + */ |
|
136 | + public function get_iso_country_code_for_ip( $ip_address ) { |
|
137 | + $country_code = ''; |
|
138 | + |
|
139 | + if ( ! class_exists( 'MaxMind\Db\Reader' ) ) { |
|
140 | + return $country_code; |
|
141 | + } |
|
142 | + |
|
143 | + $database_path = $this->get_database_path(); |
|
144 | + if ( ! file_exists( $database_path ) ) { |
|
145 | + return $country_code; |
|
146 | + } |
|
147 | + |
|
148 | + try { |
|
149 | + $reader = new MaxMind\Db\Reader( $database_path ); |
|
150 | + $data = $reader->get( $ip_address ); |
|
151 | + |
|
152 | + if ( isset( $data['country']['iso_code'] ) ) { |
|
153 | + $country_code = $data['country']['iso_code']; |
|
154 | + } |
|
155 | + |
|
156 | + $reader->close(); |
|
157 | + } catch ( Exception $e ) { |
|
158 | + wpinv_error_log( $e->getMessage(), 'SOURCE: MaxMind GeoLocation' ); |
|
159 | + } |
|
160 | + |
|
161 | + return $country_code; |
|
162 | + } |
|
163 | 163 | |
164 | 164 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * The service class responsible for interacting with MaxMind databases. |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @param string|null $database_prefix A prefix for the MaxMind database filename. |
37 | 37 | */ |
38 | - public function __construct( $database_prefix ) { |
|
38 | + public function __construct($database_prefix) { |
|
39 | 39 | $this->database_prefix = $database_prefix; |
40 | 40 | } |
41 | 41 | |
@@ -47,14 +47,14 @@ discard block |
||
47 | 47 | public function get_database_path() { |
48 | 48 | $uploads_dir = wp_upload_dir(); |
49 | 49 | |
50 | - $database_path = trailingslashit( $uploads_dir['basedir'] ) . 'invoicing/'; |
|
51 | - if ( ! empty( $this->database_prefix ) ) { |
|
50 | + $database_path = trailingslashit($uploads_dir['basedir']) . 'invoicing/'; |
|
51 | + if (!empty($this->database_prefix)) { |
|
52 | 52 | $database_path .= $this->database_prefix . '-'; |
53 | 53 | } |
54 | 54 | $database_path .= self::DATABASE . self::DATABASE_EXTENSION; |
55 | 55 | |
56 | 56 | // Filter the geolocation database storage path. |
57 | - return apply_filters( 'getpaid_maxmind_geolocation_database_path', $database_path ); |
|
57 | + return apply_filters('getpaid_maxmind_geolocation_database_path', $database_path); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -63,12 +63,12 @@ discard block |
||
63 | 63 | * @param string $license_key The license key to be used when downloading the database. |
64 | 64 | * @return string|WP_Error The path to the database file or an error if invalid. |
65 | 65 | */ |
66 | - public function download_database( $license_key ) { |
|
66 | + public function download_database($license_key) { |
|
67 | 67 | |
68 | 68 | $download_uri = add_query_arg( |
69 | 69 | array( |
70 | 70 | 'edition_id' => self::DATABASE, |
71 | - 'license_key' => urlencode( wpinv_clean( $license_key ) ), |
|
71 | + 'license_key' => urlencode(wpinv_clean($license_key)), |
|
72 | 72 | 'suffix' => 'tar.gz', |
73 | 73 | ), |
74 | 74 | 'https://download.maxmind.com/app/geoip_download' |
@@ -77,23 +77,23 @@ discard block |
||
77 | 77 | // Needed for the download_url call right below. |
78 | 78 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
79 | 79 | |
80 | - $tmp_archive_path = download_url( esc_url_raw( $download_uri ) ); |
|
80 | + $tmp_archive_path = download_url(esc_url_raw($download_uri)); |
|
81 | 81 | |
82 | - if ( is_wp_error( $tmp_archive_path ) ) { |
|
82 | + if (is_wp_error($tmp_archive_path)) { |
|
83 | 83 | // Transform the error into something more informative. |
84 | 84 | $error_data = $tmp_archive_path->get_error_data(); |
85 | - if ( isset( $error_data['code'] ) && $error_data['code'] == 401 ) { |
|
85 | + if (isset($error_data['code']) && $error_data['code'] == 401) { |
|
86 | 86 | return new WP_Error( |
87 | 87 | 'getpaid_maxmind_geolocation_database_license_key', |
88 | - __( 'The MaxMind license key is invalid. If you have recently created this key, you may need to wait for it to become active.', 'invoicing' ) |
|
88 | + __('The MaxMind license key is invalid. If you have recently created this key, you may need to wait for it to become active.', 'invoicing') |
|
89 | 89 | ); |
90 | 90 | } |
91 | 91 | |
92 | - return new WP_Error( 'getpaid_maxmind_geolocation_database_download', __( 'Failed to download the MaxMind database.', 'invoicing' ) ); |
|
92 | + return new WP_Error('getpaid_maxmind_geolocation_database_download', __('Failed to download the MaxMind database.', 'invoicing')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | // Extract the database from the archive. |
96 | - return $this->extract_downloaded_database( $tmp_archive_path ); |
|
96 | + return $this->extract_downloaded_database($tmp_archive_path); |
|
97 | 97 | |
98 | 98 | } |
99 | 99 | |
@@ -103,25 +103,25 @@ discard block |
||
103 | 103 | * @param string $tmp_archive_path The database archive path. |
104 | 104 | * @return string|WP_Error The path to the database file or an error if invalid. |
105 | 105 | */ |
106 | - protected function extract_downloaded_database( $tmp_archive_path ) { |
|
106 | + protected function extract_downloaded_database($tmp_archive_path) { |
|
107 | 107 | |
108 | 108 | // Extract the database from the archive. |
109 | 109 | try { |
110 | 110 | |
111 | - $file = new PharData( $tmp_archive_path ); |
|
112 | - $tmp_database_path = trailingslashit( dirname( $tmp_archive_path ) ) . trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION; |
|
111 | + $file = new PharData($tmp_archive_path); |
|
112 | + $tmp_database_path = trailingslashit(dirname($tmp_archive_path)) . trailingslashit($file->current()->getFilename()) . self::DATABASE . self::DATABASE_EXTENSION; |
|
113 | 113 | |
114 | 114 | $file->extractTo( |
115 | - dirname( $tmp_archive_path ), |
|
116 | - trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION, |
|
115 | + dirname($tmp_archive_path), |
|
116 | + trailingslashit($file->current()->getFilename()) . self::DATABASE . self::DATABASE_EXTENSION, |
|
117 | 117 | true |
118 | 118 | ); |
119 | 119 | |
120 | - } catch ( Exception $exception ) { |
|
121 | - return new WP_Error( 'invoicing_maxmind_geolocation_database_archive', $exception->getMessage() ); |
|
120 | + } catch (Exception $exception) { |
|
121 | + return new WP_Error('invoicing_maxmind_geolocation_database_archive', $exception->getMessage()); |
|
122 | 122 | } finally { |
123 | 123 | // Remove the archive since we only care about a single file in it. |
124 | - unlink( $tmp_archive_path ); |
|
124 | + unlink($tmp_archive_path); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | return $tmp_database_path; |
@@ -133,29 +133,29 @@ discard block |
||
133 | 133 | * @param string $ip_address The IP address to find the country code for. |
134 | 134 | * @return string The country code for the IP address, or empty if not found. |
135 | 135 | */ |
136 | - public function get_iso_country_code_for_ip( $ip_address ) { |
|
136 | + public function get_iso_country_code_for_ip($ip_address) { |
|
137 | 137 | $country_code = ''; |
138 | 138 | |
139 | - if ( ! class_exists( 'MaxMind\Db\Reader' ) ) { |
|
139 | + if (!class_exists('MaxMind\Db\Reader')) { |
|
140 | 140 | return $country_code; |
141 | 141 | } |
142 | 142 | |
143 | 143 | $database_path = $this->get_database_path(); |
144 | - if ( ! file_exists( $database_path ) ) { |
|
144 | + if (!file_exists($database_path)) { |
|
145 | 145 | return $country_code; |
146 | 146 | } |
147 | 147 | |
148 | 148 | try { |
149 | - $reader = new MaxMind\Db\Reader( $database_path ); |
|
150 | - $data = $reader->get( $ip_address ); |
|
149 | + $reader = new MaxMind\Db\Reader($database_path); |
|
150 | + $data = $reader->get($ip_address); |
|
151 | 151 | |
152 | - if ( isset( $data['country']['iso_code'] ) ) { |
|
152 | + if (isset($data['country']['iso_code'])) { |
|
153 | 153 | $country_code = $data['country']['iso_code']; |
154 | 154 | } |
155 | 155 | |
156 | 156 | $reader->close(); |
157 | - } catch ( Exception $e ) { |
|
158 | - wpinv_error_log( $e->getMessage(), 'SOURCE: MaxMind GeoLocation' ); |
|
157 | + } catch (Exception $e) { |
|
158 | + wpinv_error_log($e->getMessage(), 'SOURCE: MaxMind GeoLocation'); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | return $country_code; |
@@ -7,15 +7,15 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | |
15 | 15 | function wpinv_get_default_country() { |
16 | - $country = wpinv_get_option( 'default_country', 'UK' ); |
|
16 | + $country = wpinv_get_option('default_country', 'UK'); |
|
17 | 17 | |
18 | - return apply_filters( 'wpinv_default_country', $country ); |
|
18 | + return apply_filters('wpinv_default_country', $country); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @return string |
25 | 25 | */ |
26 | -function getpaid_get_ip_country( $ip_address = '' ) { |
|
27 | - $country = GetPaid_Geolocation::geolocate_ip( $ip_address, true ); |
|
26 | +function getpaid_get_ip_country($ip_address = '') { |
|
27 | + $country = GetPaid_Geolocation::geolocate_ip($ip_address, true); |
|
28 | 28 | return $country['country']; |
29 | 29 | } |
30 | 30 | |
@@ -34,59 +34,59 @@ discard block |
||
34 | 34 | * @param string $country The country code to sanitize |
35 | 35 | * @return array |
36 | 36 | */ |
37 | -function wpinv_sanitize_country( $country ) { |
|
37 | +function wpinv_sanitize_country($country) { |
|
38 | 38 | |
39 | 39 | // Enure the country is specified |
40 | - if ( empty( $country ) ) { |
|
40 | + if (empty($country)) { |
|
41 | 41 | $country = wpinv_get_default_country(); |
42 | 42 | } |
43 | - return trim( wpinv_utf8_strtoupper( $country ) ); |
|
43 | + return trim(wpinv_utf8_strtoupper($country)); |
|
44 | 44 | |
45 | 45 | } |
46 | 46 | |
47 | -function wpinv_is_base_country( $country ) { |
|
47 | +function wpinv_is_base_country($country) { |
|
48 | 48 | $base_country = wpinv_get_default_country(); |
49 | 49 | |
50 | - if ( $base_country === 'UK' ) { |
|
50 | + if ($base_country === 'UK') { |
|
51 | 51 | $base_country = 'GB'; |
52 | 52 | } |
53 | - if ( $country == 'UK' ) { |
|
53 | + if ($country == 'UK') { |
|
54 | 54 | $country = 'GB'; |
55 | 55 | } |
56 | 56 | |
57 | - return ( $country && $country === $base_country ) ? true : false; |
|
57 | + return ($country && $country === $base_country) ? true : false; |
|
58 | 58 | } |
59 | 59 | |
60 | -function wpinv_country_name( $country_code = '' ) { |
|
60 | +function wpinv_country_name($country_code = '') { |
|
61 | 61 | $countries = wpinv_get_country_list(); |
62 | 62 | $country_code = $country_code == 'UK' ? 'GB' : $country_code; |
63 | - $country = isset( $countries[$country_code] ) ? $countries[$country_code] : $country_code; |
|
63 | + $country = isset($countries[$country_code]) ? $countries[$country_code] : $country_code; |
|
64 | 64 | |
65 | - return apply_filters( 'wpinv_country_name', $country, $country_code ); |
|
65 | + return apply_filters('wpinv_country_name', $country, $country_code); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | function wpinv_get_default_state() { |
69 | - $state = wpinv_get_option( 'default_state', '' ); |
|
69 | + $state = wpinv_get_option('default_state', ''); |
|
70 | 70 | |
71 | - return apply_filters( 'wpinv_default_state', $state ); |
|
71 | + return apply_filters('wpinv_default_state', $state); |
|
72 | 72 | } |
73 | 73 | |
74 | -function wpinv_state_name( $state_code = '', $country_code = '' ) { |
|
74 | +function wpinv_state_name($state_code = '', $country_code = '') { |
|
75 | 75 | $state = $state_code; |
76 | 76 | |
77 | - if ( !empty( $country_code ) ) { |
|
78 | - $states = wpinv_get_country_states( $country_code ); |
|
77 | + if (!empty($country_code)) { |
|
78 | + $states = wpinv_get_country_states($country_code); |
|
79 | 79 | |
80 | - $state = !empty( $states ) && isset( $states[$state_code] ) ? $states[$state_code] : $state; |
|
80 | + $state = !empty($states) && isset($states[$state_code]) ? $states[$state_code] : $state; |
|
81 | 81 | } |
82 | 82 | |
83 | - return apply_filters( 'wpinv_state_name', $state, $state_code, $country_code ); |
|
83 | + return apply_filters('wpinv_state_name', $state, $state_code, $country_code); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | function wpinv_store_address() { |
87 | - $address = wpinv_get_option( 'store_address', '' ); |
|
87 | + $address = wpinv_get_option('store_address', ''); |
|
88 | 88 | |
89 | - return apply_filters( 'wpinv_store_address', $address ); |
|
89 | + return apply_filters('wpinv_store_address', $address); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -94,24 +94,24 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @param WPInv_Invoice $invoice |
96 | 96 | */ |
97 | -function getpaid_maybe_add_default_address( &$invoice ) { |
|
97 | +function getpaid_maybe_add_default_address(&$invoice) { |
|
98 | 98 | |
99 | 99 | $user_id = $invoice->get_user_id(); |
100 | 100 | |
101 | 101 | // Abort if the invoice belongs to no one. |
102 | - if ( empty( $user_id ) ) { |
|
102 | + if (empty($user_id)) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Fill in defaults whenever necessary. |
107 | - foreach ( wpinv_get_user_address( $user_id ) as $key => $value ) { |
|
107 | + foreach (wpinv_get_user_address($user_id) as $key => $value) { |
|
108 | 108 | |
109 | - if ( is_callable( $invoice, "get_$key" ) ) { |
|
110 | - $current = call_user_func( array( $invoice, "get_$key" ) ); |
|
109 | + if (is_callable($invoice, "get_$key")) { |
|
110 | + $current = call_user_func(array($invoice, "get_$key")); |
|
111 | 111 | |
112 | - if ( empty( $current ) ) { |
|
112 | + if (empty($current)) { |
|
113 | 113 | $method = "set_$key"; |
114 | - $invoice->$method( $value ); |
|
114 | + $invoice->$method($value); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | } |
@@ -150,24 +150,24 @@ discard block |
||
150 | 150 | * |
151 | 151 | * @param WPInv_Invoice $invoice |
152 | 152 | */ |
153 | -function getpaid_save_invoice_user_address( $invoice ) { |
|
153 | +function getpaid_save_invoice_user_address($invoice) { |
|
154 | 154 | |
155 | 155 | // Retrieve the invoice. |
156 | - $invoice = wpinv_get_invoice( $invoice ); |
|
156 | + $invoice = wpinv_get_invoice($invoice); |
|
157 | 157 | |
158 | 158 | // Abort if it does not exist. |
159 | - if ( empty( $invoice ) ) { |
|
159 | + if (empty($invoice)) { |
|
160 | 160 | return; |
161 | 161 | } |
162 | 162 | |
163 | - foreach ( getpaid_user_address_fields() as $field ) { |
|
163 | + foreach (getpaid_user_address_fields() as $field) { |
|
164 | 164 | |
165 | - if ( is_callable( array( $invoice, "get_$field" ) ) ) { |
|
166 | - $value = call_user_func( array( $invoice, "get_$field" ) ); |
|
165 | + if (is_callable(array($invoice, "get_$field"))) { |
|
166 | + $value = call_user_func(array($invoice, "get_$field")); |
|
167 | 167 | |
168 | 168 | // Only save if it is not empty. |
169 | - if ( ! empty( $value ) ) { |
|
170 | - update_user_meta( $invoice->get_user_id(), '_wpinv_' . $field, $value ); |
|
169 | + if (!empty($value)) { |
|
170 | + update_user_meta($invoice->get_user_id(), '_wpinv_' . $field, $value); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | } |
@@ -175,8 +175,8 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | } |
178 | -add_action( 'getpaid_new_invoice', 'getpaid_save_invoice_user_address' ); |
|
179 | -add_action( 'getpaid_update_invoice', 'getpaid_save_invoice_user_address' ); |
|
178 | +add_action('getpaid_new_invoice', 'getpaid_save_invoice_user_address'); |
|
179 | +add_action('getpaid_update_invoice', 'getpaid_save_invoice_user_address'); |
|
180 | 180 | |
181 | 181 | /** |
182 | 182 | * Retrieves a saved user address. |
@@ -185,14 +185,14 @@ discard block |
||
185 | 185 | * @param bool $with_default Whether or not we should use the default country and state. |
186 | 186 | * @return array |
187 | 187 | */ |
188 | -function wpinv_get_user_address( $user_id = 0, $with_default = true ) { |
|
188 | +function wpinv_get_user_address($user_id = 0, $with_default = true) { |
|
189 | 189 | |
190 | 190 | // Prepare the user id. |
191 | - $user_id = empty( $user_id ) ? get_current_user_id() : $user_id; |
|
192 | - $user_info = get_userdata( $user_id ); |
|
191 | + $user_id = empty($user_id) ? get_current_user_id() : $user_id; |
|
192 | + $user_info = get_userdata($user_id); |
|
193 | 193 | |
194 | 194 | // Abort if non exists. |
195 | - if ( empty( $user_info ) ) { |
|
195 | + if (empty($user_info)) { |
|
196 | 196 | return array(); |
197 | 197 | } |
198 | 198 | |
@@ -202,27 +202,27 @@ discard block |
||
202 | 202 | 'email' => $user_info->user_email, |
203 | 203 | ); |
204 | 204 | |
205 | - foreach ( getpaid_user_address_fields() as $field ) { |
|
206 | - $address[$field] = getpaid_get_user_address_field( $user_id, $field ); |
|
205 | + foreach (getpaid_user_address_fields() as $field) { |
|
206 | + $address[$field] = getpaid_get_user_address_field($user_id, $field); |
|
207 | 207 | } |
208 | 208 | |
209 | - if ( ! $with_default ) { |
|
209 | + if (!$with_default) { |
|
210 | 210 | return $address; |
211 | 211 | } |
212 | 212 | |
213 | - if ( isset( $address['first_name'] ) && empty( $address['first_name'] ) ) { |
|
213 | + if (isset($address['first_name']) && empty($address['first_name'])) { |
|
214 | 214 | $address['first_name'] = $user_info->first_name; |
215 | 215 | } |
216 | 216 | |
217 | - if ( isset( $address['last_name'] ) && empty( $address['last_name'] ) ) { |
|
217 | + if (isset($address['last_name']) && empty($address['last_name'])) { |
|
218 | 218 | $address['last_name'] = $user_info->last_name; |
219 | 219 | } |
220 | 220 | |
221 | - if ( isset( $address['state'] ) && empty( $address['state'] ) ) { |
|
221 | + if (isset($address['state']) && empty($address['state'])) { |
|
222 | 222 | $address['state'] = wpinv_get_default_state(); |
223 | 223 | } |
224 | 224 | |
225 | - if ( isset( $address['country'] ) && empty( $address['country'] ) ) { |
|
225 | + if (isset($address['country']) && empty($address['country'])) { |
|
226 | 226 | $address['country'] = wpinv_get_default_country(); |
227 | 227 | } |
228 | 228 | |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | * @param string $field The field to use. |
237 | 237 | * @return string|null |
238 | 238 | */ |
239 | -function getpaid_get_user_address_field( $user_id, $field ) { |
|
239 | +function getpaid_get_user_address_field($user_id, $field) { |
|
240 | 240 | |
241 | 241 | $prefixes = array( |
242 | 242 | '_wpinv_', |
@@ -244,15 +244,15 @@ discard block |
||
244 | 244 | '' |
245 | 245 | ); |
246 | 246 | |
247 | - foreach ( $prefixes as $prefix ) { |
|
247 | + foreach ($prefixes as $prefix) { |
|
248 | 248 | |
249 | 249 | // Meta table. |
250 | - $value = get_user_meta( $user_id, $prefix . $field, true ); |
|
250 | + $value = get_user_meta($user_id, $prefix . $field, true); |
|
251 | 251 | |
252 | 252 | // UWP table. |
253 | - $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value; |
|
253 | + $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value; |
|
254 | 254 | |
255 | - if ( ! empty( $value ) ) { |
|
255 | + if (!empty($value)) { |
|
256 | 256 | return $value; |
257 | 257 | } |
258 | 258 | |
@@ -269,16 +269,16 @@ discard block |
||
269 | 269 | * @param string $return What to return. |
270 | 270 | * @return array |
271 | 271 | */ |
272 | -function wpinv_get_continents( $return = 'all' ) { |
|
272 | +function wpinv_get_continents($return = 'all') { |
|
273 | 273 | |
274 | - $continents = wpinv_get_data( 'continents' ); |
|
274 | + $continents = wpinv_get_data('continents'); |
|
275 | 275 | |
276 | - switch( $return ) { |
|
276 | + switch ($return) { |
|
277 | 277 | case 'name' : |
278 | - return wp_list_pluck( $continents, 'name' ); |
|
278 | + return wp_list_pluck($continents, 'name'); |
|
279 | 279 | break; |
280 | 280 | case 'countries' : |
281 | - return wp_list_pluck( $continents, 'countries' ); |
|
281 | + return wp_list_pluck($continents, 'countries'); |
|
282 | 282 | break; |
283 | 283 | default : |
284 | 284 | return $continents; |
@@ -294,12 +294,12 @@ discard block |
||
294 | 294 | * @param string $country Country code. If no code is specified, defaults to the default country. |
295 | 295 | * @return string |
296 | 296 | */ |
297 | -function wpinv_get_continent_code_for_country( $country = false ) { |
|
297 | +function wpinv_get_continent_code_for_country($country = false) { |
|
298 | 298 | |
299 | - $country = wpinv_sanitize_country( $country ); |
|
299 | + $country = wpinv_sanitize_country($country); |
|
300 | 300 | |
301 | - foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
302 | - if ( false !== array_search( $country, $countries, true ) ) { |
|
301 | + foreach (wpinv_get_continents('countries') as $continent_code => $countries) { |
|
302 | + if (false !== array_search($country, $countries, true)) { |
|
303 | 303 | return $continent_code; |
304 | 304 | } |
305 | 305 | } |
@@ -315,13 +315,13 @@ discard block |
||
315 | 315 | * @param string $country Country code. If no code is specified, defaults to the default country. |
316 | 316 | * @return array |
317 | 317 | */ |
318 | -function wpinv_get_country_calling_code( $country = null) { |
|
318 | +function wpinv_get_country_calling_code($country = null) { |
|
319 | 319 | |
320 | - $country = wpinv_sanitize_country( $country ); |
|
321 | - $codes = wpinv_get_data( 'phone-codes' ); |
|
322 | - $code = isset( $codes[ $country ] ) ? $codes[ $country ] : ''; |
|
320 | + $country = wpinv_sanitize_country($country); |
|
321 | + $codes = wpinv_get_data('phone-codes'); |
|
322 | + $code = isset($codes[$country]) ? $codes[$country] : ''; |
|
323 | 323 | |
324 | - if ( is_array( $code ) ) { |
|
324 | + if (is_array($code)) { |
|
325 | 325 | return $code[0]; |
326 | 326 | } |
327 | 327 | return $code; |
@@ -334,8 +334,8 @@ discard block |
||
334 | 334 | * @param bool $first_empty Whether or not the first item in the list should be empty |
335 | 335 | * @return array |
336 | 336 | */ |
337 | -function wpinv_get_country_list( $first_empty = false ) { |
|
338 | - return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty ); |
|
337 | +function wpinv_get_country_list($first_empty = false) { |
|
338 | + return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -345,22 +345,22 @@ discard block |
||
345 | 345 | * @param bool $first_empty Whether or not the first item in the list should be empty |
346 | 346 | * @return array |
347 | 347 | */ |
348 | -function wpinv_get_country_states( $country = null, $first_empty = false ) { |
|
348 | +function wpinv_get_country_states($country = null, $first_empty = false) { |
|
349 | 349 | |
350 | 350 | // Prepare the country. |
351 | - $country = wpinv_sanitize_country( $country ); |
|
351 | + $country = wpinv_sanitize_country($country); |
|
352 | 352 | |
353 | 353 | // Fetch all states. |
354 | - $all_states = wpinv_get_data( 'states' ); |
|
354 | + $all_states = wpinv_get_data('states'); |
|
355 | 355 | |
356 | 356 | // Fetch the specified country's states. |
357 | - $states = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array() ; |
|
358 | - $states = apply_filters( "wpinv_{$country}_states", $states ); |
|
359 | - $states = apply_filters( 'wpinv_country_states', $states, $country ); |
|
357 | + $states = isset($all_states[$country]) ? $all_states[$country] : array(); |
|
358 | + $states = apply_filters("wpinv_{$country}_states", $states); |
|
359 | + $states = apply_filters('wpinv_country_states', $states, $country); |
|
360 | 360 | |
361 | - asort( $states ); |
|
361 | + asort($states); |
|
362 | 362 | |
363 | - return wpinv_maybe_add_empty_option( $states, $first_empty ); |
|
363 | + return wpinv_maybe_add_empty_option($states, $first_empty); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | /** |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | * @return array |
371 | 371 | */ |
372 | 372 | function wpinv_get_us_states_list() { |
373 | - return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) ); |
|
373 | + return apply_filters('wpinv_usa_states', wpinv_get_country_states('US')); |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | /** |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | * @return array |
381 | 381 | */ |
382 | 382 | function wpinv_get_canada_states_list() { |
383 | - return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) ); |
|
383 | + return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA')); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | /** |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | * @return array |
391 | 391 | */ |
392 | 392 | function wpinv_get_australia_states_list() { |
393 | - return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) ); |
|
393 | + return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU')); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | /** |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | * @return array |
401 | 401 | */ |
402 | 402 | function wpinv_get_bangladesh_states_list() { |
403 | - return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) ); |
|
403 | + return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD')); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | /** |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | * @return array |
411 | 411 | */ |
412 | 412 | function wpinv_get_brazil_states_list() { |
413 | - return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) ); |
|
413 | + return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR')); |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | * @return array |
421 | 421 | */ |
422 | 422 | function wpinv_get_bulgaria_states_list() { |
423 | - return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) ); |
|
423 | + return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG')); |
|
424 | 424 | } |
425 | 425 | |
426 | 426 | /** |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | * @return array |
431 | 431 | */ |
432 | 432 | function wpinv_get_hong_kong_states_list() { |
433 | - return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) ); |
|
433 | + return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK')); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | /** |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | * @return array |
441 | 441 | */ |
442 | 442 | function wpinv_get_hungary_states_list() { |
443 | - return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) ); |
|
443 | + return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU')); |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | /** |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | * @return array |
451 | 451 | */ |
452 | 452 | function wpinv_get_japan_states_list() { |
453 | - return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) ); |
|
453 | + return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP')); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | /** |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | * @return array |
461 | 461 | */ |
462 | 462 | function wpinv_get_china_states_list() { |
463 | - return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) ); |
|
463 | + return apply_filters('wpinv_china_states', wpinv_get_country_states('CN')); |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | /** |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | * @return array |
471 | 471 | */ |
472 | 472 | function wpinv_get_new_zealand_states_list() { |
473 | - return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) ); |
|
473 | + return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ')); |
|
474 | 474 | } |
475 | 475 | |
476 | 476 | /** |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | * @return array |
481 | 481 | */ |
482 | 482 | function wpinv_get_peru_states_list() { |
483 | - return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) ); |
|
483 | + return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE')); |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | /** |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | * @return array |
491 | 491 | */ |
492 | 492 | function wpinv_get_indonesia_states_list() { |
493 | - return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) ); |
|
493 | + return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID')); |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | /** |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | * @return array |
501 | 501 | */ |
502 | 502 | function wpinv_get_india_states_list() { |
503 | - return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) ); |
|
503 | + return apply_filters('wpinv_india_states', wpinv_get_country_states('IN')); |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | /** |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | * @return array |
511 | 511 | */ |
512 | 512 | function wpinv_get_iran_states_list() { |
513 | - return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) ); |
|
513 | + return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR')); |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | /** |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | * @return array |
521 | 521 | */ |
522 | 522 | function wpinv_get_italy_states_list() { |
523 | - return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) ); |
|
523 | + return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT')); |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | /** |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | * @return array |
531 | 531 | */ |
532 | 532 | function wpinv_get_malaysia_states_list() { |
533 | - return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) ); |
|
533 | + return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY')); |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | /** |
@@ -540,7 +540,7 @@ discard block |
||
540 | 540 | * @return array |
541 | 541 | */ |
542 | 542 | function wpinv_get_mexico_states_list() { |
543 | - return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) ); |
|
543 | + return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX')); |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | /** |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | * @return array |
551 | 551 | */ |
552 | 552 | function wpinv_get_nepal_states_list() { |
553 | - return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) ); |
|
553 | + return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP')); |
|
554 | 554 | } |
555 | 555 | |
556 | 556 | /** |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | * @return array |
561 | 561 | */ |
562 | 562 | function wpinv_get_south_africa_states_list() { |
563 | - return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) ); |
|
563 | + return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA')); |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | /** |
@@ -570,7 +570,7 @@ discard block |
||
570 | 570 | * @return array |
571 | 571 | */ |
572 | 572 | function wpinv_get_thailand_states_list() { |
573 | - return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) ); |
|
573 | + return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH')); |
|
574 | 574 | } |
575 | 575 | |
576 | 576 | /** |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | * @return array |
581 | 581 | */ |
582 | 582 | function wpinv_get_turkey_states_list() { |
583 | - return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) ); |
|
583 | + return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR')); |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | /** |
@@ -590,28 +590,28 @@ discard block |
||
590 | 590 | * @return array |
591 | 591 | */ |
592 | 592 | function wpinv_get_spain_states_list() { |
593 | - return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) ); |
|
593 | + return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES')); |
|
594 | 594 | } |
595 | 595 | |
596 | 596 | function wpinv_get_states_field() { |
597 | - if( empty( $_POST['country'] ) ) { |
|
597 | + if (empty($_POST['country'])) { |
|
598 | 598 | $_POST['country'] = wpinv_get_default_country(); |
599 | 599 | } |
600 | - $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
600 | + $states = wpinv_get_country_states(sanitize_text_field($_POST['country'])); |
|
601 | 601 | |
602 | - if( !empty( $states ) ) { |
|
603 | - $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
602 | + if (!empty($states)) { |
|
603 | + $sanitized_field_name = sanitize_text_field($_POST['field_name']); |
|
604 | 604 | |
605 | 605 | $args = array( |
606 | 606 | 'name' => $sanitized_field_name, |
607 | 607 | 'id' => $sanitized_field_name, |
608 | 608 | 'class' => $sanitized_field_name . 'custom-select wpinv-select wpi_select2', |
609 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
609 | + 'options' => array_merge(array('' => ''), $states), |
|
610 | 610 | 'show_option_all' => false, |
611 | 611 | 'show_option_none' => false |
612 | 612 | ); |
613 | 613 | |
614 | - $response = wpinv_html_select( $args ); |
|
614 | + $response = wpinv_html_select($args); |
|
615 | 615 | |
616 | 616 | } else { |
617 | 617 | $response = 'nostates'; |
@@ -620,10 +620,10 @@ discard block |
||
620 | 620 | return $response; |
621 | 621 | } |
622 | 622 | |
623 | -function wpinv_default_billing_country( $country = '', $user_id = 0 ) { |
|
624 | - $country = !empty( $country ) ? $country : wpinv_get_default_country(); |
|
623 | +function wpinv_default_billing_country($country = '', $user_id = 0) { |
|
624 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
625 | 625 | |
626 | - return apply_filters( 'wpinv_default_billing_country', $country, $user_id ); |
|
626 | + return apply_filters('wpinv_default_billing_country', $country, $user_id); |
|
627 | 627 | } |
628 | 628 | |
629 | 629 | /** |
@@ -635,7 +635,7 @@ discard block |
||
635 | 635 | */ |
636 | 636 | function wpinv_get_address_formats() { |
637 | 637 | |
638 | - return apply_filters( 'wpinv_localisation_address_formats', |
|
638 | + return apply_filters('wpinv_localisation_address_formats', |
|
639 | 639 | array( |
640 | 640 | 'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}", |
641 | 641 | 'AU' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}", |
@@ -684,9 +684,9 @@ discard block |
||
684 | 684 | * @see `wpinv_get_invoice_address_replacements` |
685 | 685 | * @return string |
686 | 686 | */ |
687 | -function wpinv_get_full_address_format( $country = false) { |
|
687 | +function wpinv_get_full_address_format($country = false) { |
|
688 | 688 | |
689 | - if( empty( $country ) ) { |
|
689 | + if (empty($country)) { |
|
690 | 690 | $country = wpinv_get_default_country(); |
691 | 691 | } |
692 | 692 | |
@@ -694,7 +694,7 @@ discard block |
||
694 | 694 | $formats = wpinv_get_address_formats(); |
695 | 695 | |
696 | 696 | // Get format for the specified country. |
697 | - $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
697 | + $format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default']; |
|
698 | 698 | |
699 | 699 | /** |
700 | 700 | * Filters the address format to use on Invoices. |
@@ -706,7 +706,7 @@ discard block |
||
706 | 706 | * @param string $format The address format to use. |
707 | 707 | * @param string $country The country who's address format is being retrieved. |
708 | 708 | */ |
709 | - return apply_filters( 'wpinv_get_full_address_format', $format, $country ); |
|
709 | + return apply_filters('wpinv_get_full_address_format', $format, $country); |
|
710 | 710 | } |
711 | 711 | |
712 | 712 | /** |
@@ -717,7 +717,7 @@ discard block |
||
717 | 717 | * @param array $billing_details customer's billing details |
718 | 718 | * @return array |
719 | 719 | */ |
720 | -function wpinv_get_invoice_address_replacements( $billing_details ) { |
|
720 | +function wpinv_get_invoice_address_replacements($billing_details) { |
|
721 | 721 | |
722 | 722 | $default_args = array( |
723 | 723 | 'address' => '', |
@@ -730,22 +730,22 @@ discard block |
||
730 | 730 | 'company' => '', |
731 | 731 | ); |
732 | 732 | |
733 | - $args = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' ); |
|
733 | + $args = map_deep(wp_parse_args($billing_details, $default_args), 'trim'); |
|
734 | 734 | $state = $args['state']; |
735 | 735 | $country = $args['country']; |
736 | 736 | |
737 | 737 | // Handle full country name. |
738 | - $full_country = empty( $country ) ? $country : wpinv_country_name( $country ); |
|
738 | + $full_country = empty($country) ? $country : wpinv_country_name($country); |
|
739 | 739 | |
740 | 740 | // Handle full state name. |
741 | - $full_state = ( $country && $state ) ? wpinv_state_name( $state, $country ) : $state; |
|
741 | + $full_state = ($country && $state) ? wpinv_state_name($state, $country) : $state; |
|
742 | 742 | |
743 | 743 | $args['postcode'] = $args['zip']; |
744 | 744 | $args['name'] = $args['first_name'] . ' ' . $args['last_name']; |
745 | 745 | $args['state'] = $full_state; |
746 | 746 | $args['state_code'] = $state; |
747 | 747 | $args['country'] = $full_country; |
748 | - $args['country_code']= $country; |
|
748 | + $args['country_code'] = $country; |
|
749 | 749 | |
750 | 750 | /** |
751 | 751 | * Filters the address format replacements to use on Invoices. |
@@ -756,14 +756,14 @@ discard block |
||
756 | 756 | * @param array $replacements The address replacements to use. |
757 | 757 | * @param array $billing_details The billing details to use. |
758 | 758 | */ |
759 | - $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details ); |
|
759 | + $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details); |
|
760 | 760 | |
761 | 761 | $return = array(); |
762 | 762 | |
763 | - foreach( $replacements as $key => $value ) { |
|
764 | - $value = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : ''; |
|
763 | + foreach ($replacements as $key => $value) { |
|
764 | + $value = is_scalar($value) ? trim(sanitize_text_field($value)) : ''; |
|
765 | 765 | $return['{{' . $key . '}}'] = $value; |
766 | - $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper( $value ); |
|
766 | + $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value); |
|
767 | 767 | } |
768 | 768 | |
769 | 769 | return $return; |
@@ -777,6 +777,6 @@ discard block |
||
777 | 777 | * @since 1.0.14 |
778 | 778 | * @return string |
779 | 779 | */ |
780 | -function wpinv_trim_formatted_address_line( $line ) { |
|
781 | - return trim( $line, ', ' ); |
|
780 | +function wpinv_trim_formatted_address_line($line) { |
|
781 | + return trim($line, ', '); |
|
782 | 782 | } |
783 | 783 | \ No newline at end of file |
@@ -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 | * Are we supporting item quantities? |
@@ -20,35 +20,35 @@ discard block |
||
20 | 20 | */ |
21 | 21 | function wpinv_get_ip() { |
22 | 22 | |
23 | - if ( isset( $_SERVER['HTTP_X_REAL_IP'] ) ) { |
|
24 | - return sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_REAL_IP'] ) ); |
|
23 | + if (isset($_SERVER['HTTP_X_REAL_IP'])) { |
|
24 | + return sanitize_text_field(wp_unslash($_SERVER['HTTP_X_REAL_IP'])); |
|
25 | 25 | } |
26 | 26 | |
27 | - if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { |
|
27 | + if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
28 | 28 | // Proxy servers can send through this header like this: X-Forwarded-For: client1, proxy1, proxy2 |
29 | 29 | // Make sure we always only send through the first IP in the list which should always be the client IP. |
30 | - return (string) rest_is_ip_address( trim( current( preg_split( '/,/', sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ) ) ) ); |
|
30 | + return (string) rest_is_ip_address(trim(current(preg_split('/,/', sanitize_text_field(wp_unslash($_SERVER['HTTP_X_FORWARDED_FOR'])))))); |
|
31 | 31 | } |
32 | 32 | |
33 | - if ( isset( $_SERVER['HTTP_CLIENT_IP'] ) ) { |
|
34 | - return sanitize_text_field( wp_unslash( $_SERVER['HTTP_CLIENT_IP'] ) ); |
|
33 | + if (isset($_SERVER['HTTP_CLIENT_IP'])) { |
|
34 | + return sanitize_text_field(wp_unslash($_SERVER['HTTP_CLIENT_IP'])); |
|
35 | 35 | } |
36 | 36 | |
37 | - if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { |
|
38 | - return sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ); |
|
37 | + if (isset($_SERVER['REMOTE_ADDR'])) { |
|
38 | + return sanitize_text_field(wp_unslash($_SERVER['REMOTE_ADDR'])); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | return ''; |
42 | 42 | } |
43 | 43 | |
44 | 44 | function wpinv_get_user_agent() { |
45 | - if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
|
46 | - $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ); |
|
45 | + if (!empty($_SERVER['HTTP_USER_AGENT'])) { |
|
46 | + $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']); |
|
47 | 47 | } else { |
48 | 48 | $user_agent = ''; |
49 | 49 | } |
50 | 50 | |
51 | - return apply_filters( 'wpinv_get_user_agent', $user_agent ); |
|
51 | + return apply_filters('wpinv_get_user_agent', $user_agent); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -56,27 +56,27 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @param string $amount The amount to sanitize. |
58 | 58 | */ |
59 | -function wpinv_sanitize_amount( $amount ) { |
|
59 | +function wpinv_sanitize_amount($amount) { |
|
60 | 60 | |
61 | 61 | // Format decimals. |
62 | - $amount = str_replace( wpinv_decimal_separator(), '.', $amount ); |
|
62 | + $amount = str_replace(wpinv_decimal_separator(), '.', $amount); |
|
63 | 63 | |
64 | 64 | // Remove thousands. |
65 | - $amount = str_replace( wpinv_thousands_separator(), '', $amount ); |
|
65 | + $amount = str_replace(wpinv_thousands_separator(), '', $amount); |
|
66 | 66 | |
67 | 67 | // Cast the remaining to a float. |
68 | - return (float) preg_replace( '/[^0-9\.\-]/', '', $amount ); |
|
68 | + return (float) preg_replace('/[^0-9\.\-]/', '', $amount); |
|
69 | 69 | |
70 | 70 | } |
71 | 71 | |
72 | -function wpinv_round_amount( $amount, $decimals = NULL ) { |
|
73 | - if ( $decimals === NULL ) { |
|
72 | +function wpinv_round_amount($amount, $decimals = NULL) { |
|
73 | + if ($decimals === NULL) { |
|
74 | 74 | $decimals = wpinv_decimals(); |
75 | 75 | } |
76 | 76 | |
77 | - $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) ); |
|
77 | + $amount = round((double) $amount, wpinv_currency_decimal_filter(absint($decimals))); |
|
78 | 78 | |
79 | - return apply_filters( 'wpinv_round_amount', $amount, $decimals ); |
|
79 | + return apply_filters('wpinv_round_amount', $amount, $decimals); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -88,32 +88,32 @@ discard block |
||
88 | 88 | * @param string|WPInv_Invoice $invoice The invoice object|post type|type |
89 | 89 | * @return array |
90 | 90 | */ |
91 | -function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) { |
|
91 | +function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) { |
|
92 | 92 | |
93 | 93 | $invoice_statuses = array( |
94 | - 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
95 | - 'publish' => _x( 'Paid', 'Invoice status', 'invoicing' ), |
|
96 | - 'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
97 | - 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
98 | - 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
99 | - 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
100 | - 'wpi-failed' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
101 | - 'wpi-renewal' => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ), |
|
94 | + 'wpi-pending' => _x('Pending payment', 'Invoice status', 'invoicing'), |
|
95 | + 'publish' => _x('Paid', 'Invoice status', 'invoicing'), |
|
96 | + 'wpi-processing' => _x('Processing', 'Invoice status', 'invoicing'), |
|
97 | + 'wpi-onhold' => _x('On hold', 'Invoice status', 'invoicing'), |
|
98 | + 'wpi-cancelled' => _x('Cancelled', 'Invoice status', 'invoicing'), |
|
99 | + 'wpi-refunded' => _x('Refunded', 'Invoice status', 'invoicing'), |
|
100 | + 'wpi-failed' => _x('Failed', 'Invoice status', 'invoicing'), |
|
101 | + 'wpi-renewal' => _x('Renewal Payment', 'Invoice status', 'invoicing'), |
|
102 | 102 | ); |
103 | 103 | |
104 | - if ( $draft ) { |
|
105 | - $invoice_statuses['draft'] = __( 'Draft', 'invoicing' ); |
|
104 | + if ($draft) { |
|
105 | + $invoice_statuses['draft'] = __('Draft', 'invoicing'); |
|
106 | 106 | } |
107 | 107 | |
108 | - if ( $trashed ) { |
|
109 | - $invoice_statuses['trash'] = __( 'Trash', 'invoicing' ); |
|
108 | + if ($trashed) { |
|
109 | + $invoice_statuses['trash'] = __('Trash', 'invoicing'); |
|
110 | 110 | } |
111 | 111 | |
112 | - if ( $invoice instanceof WPInv_Invoice ) { |
|
112 | + if ($invoice instanceof WPInv_Invoice) { |
|
113 | 113 | $invoice = $invoice->get_post_type(); |
114 | 114 | } |
115 | 115 | |
116 | - return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
116 | + return apply_filters('wpinv_statuses', $invoice_statuses, $invoice); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -122,11 +122,11 @@ discard block |
||
122 | 122 | * @param string $status The raw status |
123 | 123 | * @param string|WPInv_Invoice $invoice The invoice object|post type|type |
124 | 124 | */ |
125 | -function wpinv_status_nicename( $status, $invoice = false ) { |
|
126 | - $statuses = wpinv_get_invoice_statuses( true, true, $invoice ); |
|
127 | - $status = isset( $statuses[$status] ) ? $statuses[$status] : $status; |
|
125 | +function wpinv_status_nicename($status, $invoice = false) { |
|
126 | + $statuses = wpinv_get_invoice_statuses(true, true, $invoice); |
|
127 | + $status = isset($statuses[$status]) ? $statuses[$status] : $status; |
|
128 | 128 | |
129 | - return sanitize_text_field( $status ); |
|
129 | + return sanitize_text_field($status); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -134,13 +134,13 @@ discard block |
||
134 | 134 | * |
135 | 135 | * @param string $current |
136 | 136 | */ |
137 | -function wpinv_get_currency( $current = '' ) { |
|
137 | +function wpinv_get_currency($current = '') { |
|
138 | 138 | |
139 | - if ( empty( $current ) ) { |
|
140 | - $current = apply_filters( 'wpinv_currency', wpinv_get_option( 'currency', 'USD' ) ); |
|
139 | + if (empty($current)) { |
|
140 | + $current = apply_filters('wpinv_currency', wpinv_get_option('currency', 'USD')); |
|
141 | 141 | } |
142 | 142 | |
143 | - return trim( strtoupper( $current ) ); |
|
143 | + return trim(strtoupper($current)); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -148,25 +148,25 @@ discard block |
||
148 | 148 | * |
149 | 149 | * @param string|null $currency The currency code. Defaults to the default currency. |
150 | 150 | */ |
151 | -function wpinv_currency_symbol( $currency = null ) { |
|
151 | +function wpinv_currency_symbol($currency = null) { |
|
152 | 152 | |
153 | 153 | // Prepare the currency. |
154 | - $currency = empty( $currency ) ? wpinv_get_currency() : wpinv_clean( $currency ); |
|
154 | + $currency = empty($currency) ? wpinv_get_currency() : wpinv_clean($currency); |
|
155 | 155 | |
156 | 156 | // Fetch all symbols. |
157 | 157 | $symbols = wpinv_get_currency_symbols(); |
158 | 158 | |
159 | 159 | // Fetch this currencies symbol. |
160 | - $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : $currency; |
|
160 | + $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency; |
|
161 | 161 | |
162 | 162 | // Filter the symbol. |
163 | - return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency ); |
|
163 | + return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | function wpinv_currency_position() { |
167 | - $position = wpinv_get_option( 'currency_position', 'left' ); |
|
167 | + $position = wpinv_get_option('currency_position', 'left'); |
|
168 | 168 | |
169 | - return apply_filters( 'wpinv_currency_position', $position ); |
|
169 | + return apply_filters('wpinv_currency_position', $position); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -174,13 +174,13 @@ discard block |
||
174 | 174 | * |
175 | 175 | * @param $string|null $current |
176 | 176 | */ |
177 | -function wpinv_thousands_separator( $current = null ) { |
|
177 | +function wpinv_thousands_separator($current = null) { |
|
178 | 178 | |
179 | - if ( null == $current ) { |
|
180 | - $current = wpinv_get_option( 'thousands_separator', '.' ); |
|
179 | + if (null == $current) { |
|
180 | + $current = wpinv_get_option('thousands_separator', '.'); |
|
181 | 181 | } |
182 | 182 | |
183 | - return trim( $current ); |
|
183 | + return trim($current); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -188,13 +188,13 @@ discard block |
||
188 | 188 | * |
189 | 189 | * @param $string|null $current |
190 | 190 | */ |
191 | -function wpinv_decimal_separator( $current = null ) { |
|
191 | +function wpinv_decimal_separator($current = null) { |
|
192 | 192 | |
193 | - if ( null == $current ) { |
|
194 | - $current = wpinv_get_option( 'decimal_separator', '.' ); |
|
193 | + if (null == $current) { |
|
194 | + $current = wpinv_get_option('decimal_separator', '.'); |
|
195 | 195 | } |
196 | 196 | |
197 | - return trim( $current ); |
|
197 | + return trim($current); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
@@ -202,27 +202,27 @@ discard block |
||
202 | 202 | * |
203 | 203 | * @param $string|null $current |
204 | 204 | */ |
205 | -function wpinv_decimals( $current = null ) { |
|
205 | +function wpinv_decimals($current = null) { |
|
206 | 206 | |
207 | - if ( null == $current ) { |
|
208 | - $current = wpinv_get_option( 'decimals', 2 ); |
|
207 | + if (null == $current) { |
|
208 | + $current = wpinv_get_option('decimals', 2); |
|
209 | 209 | } |
210 | 210 | |
211 | - return absint( $current ); |
|
211 | + return absint($current); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
215 | 215 | * Retrieves a list of all supported currencies. |
216 | 216 | */ |
217 | 217 | function wpinv_get_currencies() { |
218 | - return apply_filters( 'wpinv_currencies', wpinv_get_data( 'currencies' ) ); |
|
218 | + return apply_filters('wpinv_currencies', wpinv_get_data('currencies')); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
222 | 222 | * Retrieves a list of all currency symbols. |
223 | 223 | */ |
224 | 224 | function wpinv_get_currency_symbols() { |
225 | - return apply_filters( 'wpinv_currency_symbols', wpinv_get_data( 'currency-symbols' ) ); |
|
225 | + return apply_filters('wpinv_currency_symbols', wpinv_get_data('currency-symbols')); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | $currency_pos = wpinv_currency_position(); |
235 | 235 | $format = '%1$s%2$s'; |
236 | 236 | |
237 | - switch ( $currency_pos ) { |
|
237 | + switch ($currency_pos) { |
|
238 | 238 | case 'left': |
239 | 239 | $format = '%1$s%2$s'; |
240 | 240 | break; |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | break; |
250 | 250 | } |
251 | 251 | |
252 | - return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
252 | + return apply_filters('getpaid_price_format', $format, $currency_pos); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
@@ -259,25 +259,25 @@ discard block |
||
259 | 259 | * @param string $currency Currency. |
260 | 260 | * @return string |
261 | 261 | */ |
262 | -function wpinv_price( $amount = 0, $currency = '' ) { |
|
262 | +function wpinv_price($amount = 0, $currency = '') { |
|
263 | 263 | |
264 | 264 | // Backwards compatibility. |
265 | - $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
265 | + $amount = floatval(wpinv_sanitize_amount($amount)); |
|
266 | 266 | |
267 | 267 | // Prepare variables. |
268 | - $currency = wpinv_get_currency( $currency ); |
|
268 | + $currency = wpinv_get_currency($currency); |
|
269 | 269 | $amount = (float) $amount; |
270 | 270 | $unformatted_amount = $amount; |
271 | 271 | $negative = $amount < 0; |
272 | - $amount = apply_filters( 'getpaid_raw_amount', floatval( $negative ? $amount * -1 : $amount ) ); |
|
273 | - $amount = wpinv_format_amount( $amount ); |
|
272 | + $amount = apply_filters('getpaid_raw_amount', floatval($negative ? $amount * -1 : $amount)); |
|
273 | + $amount = wpinv_format_amount($amount); |
|
274 | 274 | |
275 | 275 | // Format the amount. |
276 | 276 | $format = getpaid_get_price_format(); |
277 | - $formatted_amount = ( $negative ? '-' : '' ) . sprintf( $format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol( $currency ) . '</span>', $amount ); |
|
277 | + $formatted_amount = ($negative ? '-' : '') . sprintf($format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol($currency) . '</span>', $amount); |
|
278 | 278 | |
279 | 279 | // Filter the formatting. |
280 | - return apply_filters( 'wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount ); |
|
280 | + return apply_filters('wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | /** |
@@ -288,33 +288,33 @@ discard block |
||
288 | 288 | * @param bool $calculate Whether or not to apply separators. |
289 | 289 | * @return string |
290 | 290 | */ |
291 | -function wpinv_format_amount( $amount, $decimals = null, $calculate = false ) { |
|
291 | +function wpinv_format_amount($amount, $decimals = null, $calculate = false) { |
|
292 | 292 | $thousands_sep = wpinv_thousands_separator(); |
293 | 293 | $decimal_sep = wpinv_decimal_separator(); |
294 | - $decimals = wpinv_decimals( $decimals ); |
|
294 | + $decimals = wpinv_decimals($decimals); |
|
295 | 295 | |
296 | 296 | // Format decimals. |
297 | - $amount = str_replace( $decimal_sep, '.', $amount ); |
|
297 | + $amount = str_replace($decimal_sep, '.', $amount); |
|
298 | 298 | |
299 | 299 | // Remove thousands. |
300 | - $amount = str_replace( $thousands_sep, '', $amount ); |
|
300 | + $amount = str_replace($thousands_sep, '', $amount); |
|
301 | 301 | |
302 | 302 | // Cast the remaining to a float. |
303 | - $amount = floatval( $amount ); |
|
303 | + $amount = floatval($amount); |
|
304 | 304 | |
305 | - if ( $calculate ) { |
|
305 | + if ($calculate) { |
|
306 | 306 | return $amount; |
307 | 307 | } |
308 | 308 | |
309 | 309 | // Fomart the amount. |
310 | - return number_format( $amount, $decimals, $decimal_sep, $thousands_sep ); |
|
310 | + return number_format($amount, $decimals, $decimal_sep, $thousands_sep); |
|
311 | 311 | } |
312 | 312 | |
313 | -function wpinv_sanitize_key( $key ) { |
|
313 | +function wpinv_sanitize_key($key) { |
|
314 | 314 | $raw_key = $key; |
315 | - $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key ); |
|
315 | + $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key); |
|
316 | 316 | |
317 | - return apply_filters( 'wpinv_sanitize_key', $key, $raw_key ); |
|
317 | + return apply_filters('wpinv_sanitize_key', $key, $raw_key); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | /** |
@@ -322,8 +322,8 @@ discard block |
||
322 | 322 | * |
323 | 323 | * @param $str the file whose extension should be retrieved. |
324 | 324 | */ |
325 | -function wpinv_get_file_extension( $str ) { |
|
326 | - $filetype = wp_check_filetype( $str ); |
|
325 | +function wpinv_get_file_extension($str) { |
|
326 | + $filetype = wp_check_filetype($str); |
|
327 | 327 | return $filetype['ext']; |
328 | 328 | } |
329 | 329 | |
@@ -332,16 +332,16 @@ discard block |
||
332 | 332 | * |
333 | 333 | * @param string $string |
334 | 334 | */ |
335 | -function wpinv_string_is_image_url( $string ) { |
|
336 | - $extension = strtolower( wpinv_get_file_extension( $string ) ); |
|
337 | - return in_array( $extension, array( 'jpeg', 'jpg', 'png', 'gif', 'ico' ), true ); |
|
335 | +function wpinv_string_is_image_url($string) { |
|
336 | + $extension = strtolower(wpinv_get_file_extension($string)); |
|
337 | + return in_array($extension, array('jpeg', 'jpg', 'png', 'gif', 'ico'), true); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | /** |
341 | 341 | * Returns the current URL. |
342 | 342 | */ |
343 | 343 | function wpinv_get_current_page_url() { |
344 | - return ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
|
344 | + return (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | /** |
@@ -351,46 +351,46 @@ discard block |
||
351 | 351 | * @param string $name Constant name. |
352 | 352 | * @param mixed $value Value. |
353 | 353 | */ |
354 | -function getpaid_maybe_define_constant( $name, $value ) { |
|
355 | - if ( ! defined( $name ) ) { |
|
356 | - define( $name, $value ); |
|
354 | +function getpaid_maybe_define_constant($name, $value) { |
|
355 | + if (!defined($name)) { |
|
356 | + define($name, $value); |
|
357 | 357 | } |
358 | 358 | } |
359 | 359 | |
360 | 360 | function wpinv_get_php_arg_separator_output() { |
361 | - return ini_get( 'arg_separator.output' ); |
|
361 | + return ini_get('arg_separator.output'); |
|
362 | 362 | } |
363 | 363 | |
364 | -function wpinv_rgb_from_hex( $color ) { |
|
365 | - $color = str_replace( '#', '', $color ); |
|
364 | +function wpinv_rgb_from_hex($color) { |
|
365 | + $color = str_replace('#', '', $color); |
|
366 | 366 | |
367 | 367 | // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" |
368 | - $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); |
|
369 | - if ( empty( $color ) ) { |
|
368 | + $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color); |
|
369 | + if (empty($color)) { |
|
370 | 370 | return NULL; |
371 | 371 | } |
372 | 372 | |
373 | - $color = str_split( $color ); |
|
373 | + $color = str_split($color); |
|
374 | 374 | |
375 | 375 | $rgb = array(); |
376 | - $rgb['R'] = hexdec( $color[0] . $color[1] ); |
|
377 | - $rgb['G'] = hexdec( $color[2] . $color[3] ); |
|
378 | - $rgb['B'] = hexdec( $color[4] . $color[5] ); |
|
376 | + $rgb['R'] = hexdec($color[0] . $color[1]); |
|
377 | + $rgb['G'] = hexdec($color[2] . $color[3]); |
|
378 | + $rgb['B'] = hexdec($color[4] . $color[5]); |
|
379 | 379 | |
380 | 380 | return $rgb; |
381 | 381 | } |
382 | 382 | |
383 | -function wpinv_hex_darker( $color, $factor = 30 ) { |
|
384 | - $base = wpinv_rgb_from_hex( $color ); |
|
383 | +function wpinv_hex_darker($color, $factor = 30) { |
|
384 | + $base = wpinv_rgb_from_hex($color); |
|
385 | 385 | $color = '#'; |
386 | 386 | |
387 | - foreach ( $base as $k => $v ) { |
|
387 | + foreach ($base as $k => $v) { |
|
388 | 388 | $amount = $v / 100; |
389 | - $amount = round( $amount * $factor ); |
|
389 | + $amount = round($amount * $factor); |
|
390 | 390 | $new_decimal = $v - $amount; |
391 | 391 | |
392 | - $new_hex_component = dechex( $new_decimal ); |
|
393 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
392 | + $new_hex_component = dechex($new_decimal); |
|
393 | + if (strlen($new_hex_component) < 2) { |
|
394 | 394 | $new_hex_component = "0" . $new_hex_component; |
395 | 395 | } |
396 | 396 | $color .= $new_hex_component; |
@@ -399,18 +399,18 @@ discard block |
||
399 | 399 | return $color; |
400 | 400 | } |
401 | 401 | |
402 | -function wpinv_hex_lighter( $color, $factor = 30 ) { |
|
403 | - $base = wpinv_rgb_from_hex( $color ); |
|
402 | +function wpinv_hex_lighter($color, $factor = 30) { |
|
403 | + $base = wpinv_rgb_from_hex($color); |
|
404 | 404 | $color = '#'; |
405 | 405 | |
406 | - foreach ( $base as $k => $v ) { |
|
406 | + foreach ($base as $k => $v) { |
|
407 | 407 | $amount = 255 - $v; |
408 | 408 | $amount = $amount / 100; |
409 | - $amount = round( $amount * $factor ); |
|
409 | + $amount = round($amount * $factor); |
|
410 | 410 | $new_decimal = $v + $amount; |
411 | 411 | |
412 | - $new_hex_component = dechex( $new_decimal ); |
|
413 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
412 | + $new_hex_component = dechex($new_decimal); |
|
413 | + if (strlen($new_hex_component) < 2) { |
|
414 | 414 | $new_hex_component = "0" . $new_hex_component; |
415 | 415 | } |
416 | 416 | $color .= $new_hex_component; |
@@ -419,22 +419,22 @@ discard block |
||
419 | 419 | return $color; |
420 | 420 | } |
421 | 421 | |
422 | -function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { |
|
423 | - $hex = str_replace( '#', '', $color ); |
|
422 | +function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') { |
|
423 | + $hex = str_replace('#', '', $color); |
|
424 | 424 | |
425 | - $c_r = hexdec( substr( $hex, 0, 2 ) ); |
|
426 | - $c_g = hexdec( substr( $hex, 2, 2 ) ); |
|
427 | - $c_b = hexdec( substr( $hex, 4, 2 ) ); |
|
425 | + $c_r = hexdec(substr($hex, 0, 2)); |
|
426 | + $c_g = hexdec(substr($hex, 2, 2)); |
|
427 | + $c_b = hexdec(substr($hex, 4, 2)); |
|
428 | 428 | |
429 | - $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; |
|
429 | + $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000; |
|
430 | 430 | |
431 | 431 | return $brightness > 155 ? $dark : $light; |
432 | 432 | } |
433 | 433 | |
434 | -function wpinv_format_hex( $hex ) { |
|
435 | - $hex = trim( str_replace( '#', '', $hex ) ); |
|
434 | +function wpinv_format_hex($hex) { |
|
435 | + $hex = trim(str_replace('#', '', $hex)); |
|
436 | 436 | |
437 | - if ( strlen( $hex ) == 3 ) { |
|
437 | + if (strlen($hex) == 3) { |
|
438 | 438 | $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; |
439 | 439 | } |
440 | 440 | |
@@ -454,12 +454,12 @@ discard block |
||
454 | 454 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
455 | 455 | * @return string |
456 | 456 | */ |
457 | -function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) { |
|
458 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
459 | - return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding ); |
|
457 | +function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') { |
|
458 | + if (function_exists('mb_strimwidth')) { |
|
459 | + return mb_strimwidth($str, $start, $width, $trimmaker, $encoding); |
|
460 | 460 | } |
461 | 461 | |
462 | - return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker; |
|
462 | + return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker; |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | /** |
@@ -471,28 +471,28 @@ discard block |
||
471 | 471 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
472 | 472 | * @return int Returns the number of characters in string. |
473 | 473 | */ |
474 | -function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) { |
|
475 | - if ( function_exists( 'mb_strlen' ) ) { |
|
476 | - return mb_strlen( $str, $encoding ); |
|
474 | +function wpinv_utf8_strlen($str, $encoding = 'UTF-8') { |
|
475 | + if (function_exists('mb_strlen')) { |
|
476 | + return mb_strlen($str, $encoding); |
|
477 | 477 | } |
478 | 478 | |
479 | - return strlen( $str ); |
|
479 | + return strlen($str); |
|
480 | 480 | } |
481 | 481 | |
482 | -function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) { |
|
483 | - if ( function_exists( 'mb_strtolower' ) ) { |
|
484 | - return mb_strtolower( $str, $encoding ); |
|
482 | +function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') { |
|
483 | + if (function_exists('mb_strtolower')) { |
|
484 | + return mb_strtolower($str, $encoding); |
|
485 | 485 | } |
486 | 486 | |
487 | - return strtolower( $str ); |
|
487 | + return strtolower($str); |
|
488 | 488 | } |
489 | 489 | |
490 | -function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) { |
|
491 | - if ( function_exists( 'mb_strtoupper' ) ) { |
|
492 | - return mb_strtoupper( $str, $encoding ); |
|
490 | +function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') { |
|
491 | + if (function_exists('mb_strtoupper')) { |
|
492 | + return mb_strtoupper($str, $encoding); |
|
493 | 493 | } |
494 | 494 | |
495 | - return strtoupper( $str ); |
|
495 | + return strtoupper($str); |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | /** |
@@ -506,12 +506,12 @@ discard block |
||
506 | 506 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
507 | 507 | * @return int Returns the position of the first occurrence of search in the string. |
508 | 508 | */ |
509 | -function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
510 | - if ( function_exists( 'mb_strpos' ) ) { |
|
511 | - return mb_strpos( $str, $find, $offset, $encoding ); |
|
509 | +function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
510 | + if (function_exists('mb_strpos')) { |
|
511 | + return mb_strpos($str, $find, $offset, $encoding); |
|
512 | 512 | } |
513 | 513 | |
514 | - return strpos( $str, $find, $offset ); |
|
514 | + return strpos($str, $find, $offset); |
|
515 | 515 | } |
516 | 516 | |
517 | 517 | /** |
@@ -525,12 +525,12 @@ discard block |
||
525 | 525 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
526 | 526 | * @return int Returns the position of the last occurrence of search. |
527 | 527 | */ |
528 | -function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
529 | - if ( function_exists( 'mb_strrpos' ) ) { |
|
530 | - return mb_strrpos( $str, $find, $offset, $encoding ); |
|
528 | +function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
529 | + if (function_exists('mb_strrpos')) { |
|
530 | + return mb_strrpos($str, $find, $offset, $encoding); |
|
531 | 531 | } |
532 | 532 | |
533 | - return strrpos( $str, $find, $offset ); |
|
533 | + return strrpos($str, $find, $offset); |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | /** |
@@ -545,16 +545,16 @@ discard block |
||
545 | 545 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
546 | 546 | * @return string |
547 | 547 | */ |
548 | -function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) { |
|
549 | - if ( function_exists( 'mb_substr' ) ) { |
|
550 | - if ( $length === null ) { |
|
551 | - return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
548 | +function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') { |
|
549 | + if (function_exists('mb_substr')) { |
|
550 | + if ($length === null) { |
|
551 | + return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
552 | 552 | } else { |
553 | - return mb_substr( $str, $start, $length, $encoding ); |
|
553 | + return mb_substr($str, $start, $length, $encoding); |
|
554 | 554 | } |
555 | 555 | } |
556 | 556 | |
557 | - return substr( $str, $start, $length ); |
|
557 | + return substr($str, $start, $length); |
|
558 | 558 | } |
559 | 559 | |
560 | 560 | /** |
@@ -566,48 +566,48 @@ discard block |
||
566 | 566 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
567 | 567 | * @return string The width of string. |
568 | 568 | */ |
569 | -function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) { |
|
570 | - if ( function_exists( 'mb_strwidth' ) ) { |
|
571 | - return mb_strwidth( $str, $encoding ); |
|
569 | +function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') { |
|
570 | + if (function_exists('mb_strwidth')) { |
|
571 | + return mb_strwidth($str, $encoding); |
|
572 | 572 | } |
573 | 573 | |
574 | - return wpinv_utf8_strlen( $str, $encoding ); |
|
574 | + return wpinv_utf8_strlen($str, $encoding); |
|
575 | 575 | } |
576 | 576 | |
577 | -function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) { |
|
578 | - if ( function_exists( 'mb_strlen' ) ) { |
|
579 | - $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding ); |
|
577 | +function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') { |
|
578 | + if (function_exists('mb_strlen')) { |
|
579 | + $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding); |
|
580 | 580 | $str_end = ""; |
581 | 581 | |
582 | - if ( $lower_str_end ) { |
|
583 | - $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding ); |
|
582 | + if ($lower_str_end) { |
|
583 | + $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding); |
|
584 | 584 | } else { |
585 | - $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
585 | + $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
586 | 586 | } |
587 | 587 | |
588 | 588 | return $first_letter . $str_end; |
589 | 589 | } |
590 | 590 | |
591 | - return ucfirst( $str ); |
|
591 | + return ucfirst($str); |
|
592 | 592 | } |
593 | 593 | |
594 | -function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) { |
|
595 | - if ( function_exists( 'mb_convert_case' ) ) { |
|
596 | - return mb_convert_case( $str, MB_CASE_TITLE, $encoding ); |
|
594 | +function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') { |
|
595 | + if (function_exists('mb_convert_case')) { |
|
596 | + return mb_convert_case($str, MB_CASE_TITLE, $encoding); |
|
597 | 597 | } |
598 | 598 | |
599 | - return ucwords( $str ); |
|
599 | + return ucwords($str); |
|
600 | 600 | } |
601 | 601 | |
602 | -function wpinv_period_in_days( $period, $unit ) { |
|
603 | - $period = absint( $period ); |
|
602 | +function wpinv_period_in_days($period, $unit) { |
|
603 | + $period = absint($period); |
|
604 | 604 | |
605 | - if ( $period > 0 ) { |
|
606 | - if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) { |
|
605 | + if ($period > 0) { |
|
606 | + if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) { |
|
607 | 607 | $period = $period * 7; |
608 | - } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) { |
|
608 | + } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) { |
|
609 | 609 | $period = $period * 30; |
610 | - } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) { |
|
610 | + } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) { |
|
611 | 611 | $period = $period * 365; |
612 | 612 | } |
613 | 613 | } |
@@ -615,14 +615,14 @@ discard block |
||
615 | 615 | return $period; |
616 | 616 | } |
617 | 617 | |
618 | -function wpinv_cal_days_in_month( $calendar, $month, $year ) { |
|
619 | - if ( function_exists( 'cal_days_in_month' ) ) { |
|
620 | - return cal_days_in_month( $calendar, $month, $year ); |
|
618 | +function wpinv_cal_days_in_month($calendar, $month, $year) { |
|
619 | + if (function_exists('cal_days_in_month')) { |
|
620 | + return cal_days_in_month($calendar, $month, $year); |
|
621 | 621 | } |
622 | 622 | |
623 | 623 | // Fallback in case the calendar extension is not loaded in PHP |
624 | 624 | // Only supports Gregorian calendar |
625 | - return date( 't', mktime( 0, 0, 0, $month, 1, $year ) ); |
|
625 | + return date('t', mktime(0, 0, 0, $month, 1, $year)); |
|
626 | 626 | } |
627 | 627 | |
628 | 628 | /** |
@@ -633,12 +633,12 @@ discard block |
||
633 | 633 | * |
634 | 634 | * @return string |
635 | 635 | */ |
636 | -function wpi_help_tip( $tip, $allow_html = false ) { |
|
636 | +function wpi_help_tip($tip, $allow_html = false) { |
|
637 | 637 | |
638 | - if ( $allow_html ) { |
|
639 | - $tip = wpi_sanitize_tooltip( $tip ); |
|
638 | + if ($allow_html) { |
|
639 | + $tip = wpi_sanitize_tooltip($tip); |
|
640 | 640 | } else { |
641 | - $tip = esc_attr( $tip ); |
|
641 | + $tip = esc_attr($tip); |
|
642 | 642 | } |
643 | 643 | |
644 | 644 | return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
@@ -652,8 +652,8 @@ discard block |
||
652 | 652 | * @param string $var |
653 | 653 | * @return string |
654 | 654 | */ |
655 | -function wpi_sanitize_tooltip( $var ) { |
|
656 | - return wp_kses( html_entity_decode( $var ), array( |
|
655 | +function wpi_sanitize_tooltip($var) { |
|
656 | + return wp_kses(html_entity_decode($var), array( |
|
657 | 657 | 'br' => array(), |
658 | 658 | 'em' => array(), |
659 | 659 | 'strong' => array(), |
@@ -664,7 +664,7 @@ discard block |
||
664 | 664 | 'li' => array(), |
665 | 665 | 'ol' => array(), |
666 | 666 | 'p' => array(), |
667 | - ) ); |
|
667 | + )); |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | /** |
@@ -674,7 +674,7 @@ discard block |
||
674 | 674 | */ |
675 | 675 | function wpinv_get_screen_ids() { |
676 | 676 | |
677 | - $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) ); |
|
677 | + $screen_id = sanitize_title(__('Invoicing', 'invoicing')); |
|
678 | 678 | |
679 | 679 | $screen_ids = array( |
680 | 680 | 'toplevel_page_' . $screen_id, |
@@ -692,7 +692,7 @@ discard block |
||
692 | 692 | 'invoicing_page_wpi-addons', |
693 | 693 | ); |
694 | 694 | |
695 | - return apply_filters( 'wpinv_screen_ids', $screen_ids ); |
|
695 | + return apply_filters('wpinv_screen_ids', $screen_ids); |
|
696 | 696 | } |
697 | 697 | |
698 | 698 | /** |
@@ -703,14 +703,14 @@ discard block |
||
703 | 703 | * @param array|string $list List of values. |
704 | 704 | * @return array Sanitized array of values. |
705 | 705 | */ |
706 | -function wpinv_parse_list( $list ) { |
|
706 | +function wpinv_parse_list($list) { |
|
707 | 707 | |
708 | - if ( empty( $list ) ) { |
|
708 | + if (empty($list)) { |
|
709 | 709 | $list = array(); |
710 | 710 | } |
711 | 711 | |
712 | - if ( ! is_array( $list ) ) { |
|
713 | - return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
712 | + if (!is_array($list)) { |
|
713 | + return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY); |
|
714 | 714 | } |
715 | 715 | |
716 | 716 | return $list; |
@@ -724,16 +724,16 @@ discard block |
||
724 | 724 | * @param string $key Type of data to fetch. |
725 | 725 | * @return mixed Fetched data. |
726 | 726 | */ |
727 | -function wpinv_get_data( $key ) { |
|
727 | +function wpinv_get_data($key) { |
|
728 | 728 | |
729 | 729 | // Try fetching it from the cache. |
730 | - $data = wp_cache_get( "wpinv-data-$key", 'wpinv' ); |
|
731 | - if( $data ) { |
|
730 | + $data = wp_cache_get("wpinv-data-$key", 'wpinv'); |
|
731 | + if ($data) { |
|
732 | 732 | return $data; |
733 | 733 | } |
734 | 734 | |
735 | - $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" ); |
|
736 | - wp_cache_set( "wpinv-data-$key", $data, 'wpinv' ); |
|
735 | + $data = apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php"); |
|
736 | + wp_cache_set("wpinv-data-$key", $data, 'wpinv'); |
|
737 | 737 | |
738 | 738 | return $data; |
739 | 739 | } |
@@ -747,10 +747,10 @@ discard block |
||
747 | 747 | * @param bool $first_empty Whether or not the first item in the list should be empty |
748 | 748 | * @return mixed Fetched data. |
749 | 749 | */ |
750 | -function wpinv_maybe_add_empty_option( $options, $first_empty ) { |
|
750 | +function wpinv_maybe_add_empty_option($options, $first_empty) { |
|
751 | 751 | |
752 | - if ( ! empty( $options ) && $first_empty ) { |
|
753 | - return array_merge( array( '' => '' ), $options ); |
|
752 | + if (!empty($options) && $first_empty) { |
|
753 | + return array_merge(array('' => ''), $options); |
|
754 | 754 | } |
755 | 755 | return $options; |
756 | 756 | |
@@ -762,21 +762,21 @@ discard block |
||
762 | 762 | * @param mixed $var Data to sanitize. |
763 | 763 | * @return string|array |
764 | 764 | */ |
765 | -function wpinv_clean( $var ) { |
|
765 | +function wpinv_clean($var) { |
|
766 | 766 | |
767 | - if ( is_array( $var ) ) { |
|
768 | - return array_map( 'wpinv_clean', $var ); |
|
767 | + if (is_array($var)) { |
|
768 | + return array_map('wpinv_clean', $var); |
|
769 | 769 | } |
770 | 770 | |
771 | - if ( is_object( $var ) ) { |
|
772 | - $object_vars = get_object_vars( $var ); |
|
773 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
774 | - $var->$property_name = wpinv_clean( $property_value ); |
|
771 | + if (is_object($var)) { |
|
772 | + $object_vars = get_object_vars($var); |
|
773 | + foreach ($object_vars as $property_name => $property_value) { |
|
774 | + $var->$property_name = wpinv_clean($property_value); |
|
775 | 775 | } |
776 | 776 | return $var; |
777 | 777 | } |
778 | 778 | |
779 | - return is_string( $var ) ? sanitize_text_field( $var ) : $var; |
|
779 | + return is_string($var) ? sanitize_text_field($var) : $var; |
|
780 | 780 | } |
781 | 781 | |
782 | 782 | /** |
@@ -785,43 +785,43 @@ discard block |
||
785 | 785 | * @param string $str Data to convert. |
786 | 786 | * @return string|array |
787 | 787 | */ |
788 | -function getpaid_convert_price_string_to_options( $str ) { |
|
788 | +function getpaid_convert_price_string_to_options($str) { |
|
789 | 789 | |
790 | - $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
791 | - $options = array(); |
|
790 | + $raw_options = array_map('trim', explode(',', $str)); |
|
791 | + $options = array(); |
|
792 | 792 | |
793 | - foreach ( $raw_options as $option ) { |
|
793 | + foreach ($raw_options as $option) { |
|
794 | 794 | |
795 | - if ( '' == $option ) { |
|
795 | + if ('' == $option) { |
|
796 | 796 | continue; |
797 | 797 | } |
798 | 798 | |
799 | - $option = array_map( 'trim', explode( '|', $option ) ); |
|
799 | + $option = array_map('trim', explode('|', $option)); |
|
800 | 800 | |
801 | 801 | $price = null; |
802 | 802 | $label = null; |
803 | 803 | |
804 | - if ( isset( $option[0] ) && '' != $option[0] ) { |
|
805 | - $label = $option[0]; |
|
804 | + if (isset($option[0]) && '' != $option[0]) { |
|
805 | + $label = $option[0]; |
|
806 | 806 | } |
807 | 807 | |
808 | - if ( isset( $option[1] ) && '' != $option[1] ) { |
|
808 | + if (isset($option[1]) && '' != $option[1]) { |
|
809 | 809 | $price = $option[1]; |
810 | 810 | } |
811 | 811 | |
812 | - if ( ! isset( $price ) ) { |
|
812 | + if (!isset($price)) { |
|
813 | 813 | $price = $label; |
814 | 814 | } |
815 | 815 | |
816 | - if ( ! isset( $price ) || ! is_numeric( $price ) ) { |
|
816 | + if (!isset($price) || !is_numeric($price)) { |
|
817 | 817 | continue; |
818 | 818 | } |
819 | 819 | |
820 | - if ( ! isset( $label ) ) { |
|
820 | + if (!isset($label)) { |
|
821 | 821 | $label = $price; |
822 | 822 | } |
823 | 823 | |
824 | - $options[ $price ] = $label; |
|
824 | + $options[$price] = $label; |
|
825 | 825 | } |
826 | 826 | |
827 | 827 | return $options; |
@@ -830,22 +830,22 @@ discard block |
||
830 | 830 | /** |
831 | 831 | * Returns the help tip. |
832 | 832 | */ |
833 | -function getpaid_get_help_tip( $tip, $additional_classes = '' ) { |
|
834 | - $additional_classes = sanitize_html_class( $additional_classes ); |
|
835 | - $tip = esc_attr__( $tip ); |
|
833 | +function getpaid_get_help_tip($tip, $additional_classes = '') { |
|
834 | + $additional_classes = sanitize_html_class($additional_classes); |
|
835 | + $tip = esc_attr__($tip); |
|
836 | 836 | return "<span class='wpi-help-tip dashicons dashicons-editor-help $additional_classes' title='$tip'></span>"; |
837 | 837 | } |
838 | 838 | |
839 | 839 | /** |
840 | 840 | * Formats a date |
841 | 841 | */ |
842 | -function getpaid_format_date( $date ) { |
|
842 | +function getpaid_format_date($date) { |
|
843 | 843 | |
844 | - if ( empty( $date ) || $date == '0000-00-00 00:00:00' ) { |
|
844 | + if (empty($date) || $date == '0000-00-00 00:00:00') { |
|
845 | 845 | return ''; |
846 | 846 | } |
847 | 847 | |
848 | - return date_i18n( getpaid_date_format(), strtotime( $date ) ); |
|
848 | + return date_i18n(getpaid_date_format(), strtotime($date)); |
|
849 | 849 | |
850 | 850 | } |
851 | 851 | |
@@ -854,9 +854,9 @@ discard block |
||
854 | 854 | * |
855 | 855 | * @return string |
856 | 856 | */ |
857 | -function getpaid_format_date_value( $date, $default = "—" ) { |
|
858 | - $date = getpaid_format_date( $date ); |
|
859 | - return empty( $date ) ? $default : $date; |
|
857 | +function getpaid_format_date_value($date, $default = "—") { |
|
858 | + $date = getpaid_format_date($date); |
|
859 | + return empty($date) ? $default : $date; |
|
860 | 860 | } |
861 | 861 | |
862 | 862 | /** |
@@ -865,7 +865,7 @@ discard block |
||
865 | 865 | * @return string |
866 | 866 | */ |
867 | 867 | function getpaid_date_format() { |
868 | - return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
868 | + return apply_filters('getpaid_date_format', get_option('date_format')); |
|
869 | 869 | } |
870 | 870 | |
871 | 871 | /** |
@@ -874,7 +874,7 @@ discard block |
||
874 | 874 | * @return string |
875 | 875 | */ |
876 | 876 | function getpaid_time_format() { |
877 | - return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
877 | + return apply_filters('getpaid_time_format', get_option('time_format')); |
|
878 | 878 | } |
879 | 879 | |
880 | 880 | /** |
@@ -884,16 +884,16 @@ discard block |
||
884 | 884 | * @param integer $limit Limit size in characters. |
885 | 885 | * @return string |
886 | 886 | */ |
887 | -function getpaid_limit_length( $string, $limit ) { |
|
887 | +function getpaid_limit_length($string, $limit) { |
|
888 | 888 | $str_limit = $limit - 3; |
889 | 889 | |
890 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
891 | - if ( mb_strlen( $string ) > $limit ) { |
|
892 | - $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
890 | + if (function_exists('mb_strimwidth')) { |
|
891 | + if (mb_strlen($string) > $limit) { |
|
892 | + $string = mb_strimwidth($string, 0, $str_limit) . '...'; |
|
893 | 893 | } |
894 | 894 | } else { |
895 | - if ( strlen( $string ) > $limit ) { |
|
896 | - $string = substr( $string, 0, $str_limit ) . '...'; |
|
895 | + if (strlen($string) > $limit) { |
|
896 | + $string = substr($string, 0, $str_limit) . '...'; |
|
897 | 897 | } |
898 | 898 | } |
899 | 899 | return $string; |
@@ -907,7 +907,7 @@ discard block |
||
907 | 907 | * @since 1.0.19 |
908 | 908 | */ |
909 | 909 | function getpaid_api() { |
910 | - return getpaid()->get( 'api' ); |
|
910 | + return getpaid()->get('api'); |
|
911 | 911 | } |
912 | 912 | |
913 | 913 | /** |
@@ -917,7 +917,7 @@ discard block |
||
917 | 917 | * @since 1.0.19 |
918 | 918 | */ |
919 | 919 | function getpaid_post_types() { |
920 | - return getpaid()->get( 'post_types' ); |
|
920 | + return getpaid()->get('post_types'); |
|
921 | 921 | } |
922 | 922 | |
923 | 923 | /** |
@@ -927,7 +927,7 @@ discard block |
||
927 | 927 | * @since 1.0.19 |
928 | 928 | */ |
929 | 929 | function getpaid_session() { |
930 | - return getpaid()->get( 'session' ); |
|
930 | + return getpaid()->get('session'); |
|
931 | 931 | } |
932 | 932 | |
933 | 933 | /** |
@@ -937,7 +937,7 @@ discard block |
||
937 | 937 | * @since 1.0.19 |
938 | 938 | */ |
939 | 939 | function getpaid_notes() { |
940 | - return getpaid()->get( 'notes' ); |
|
940 | + return getpaid()->get('notes'); |
|
941 | 941 | } |
942 | 942 | |
943 | 943 | /** |
@@ -946,7 +946,7 @@ discard block |
||
946 | 946 | * @return GetPaid_Admin |
947 | 947 | */ |
948 | 948 | function getpaid_admin() { |
949 | - return getpaid()->get( 'admin' ); |
|
949 | + return getpaid()->get('admin'); |
|
950 | 950 | } |
951 | 951 | |
952 | 952 | /** |
@@ -956,8 +956,8 @@ discard block |
||
956 | 956 | * @param string $base the base url |
957 | 957 | * @return string |
958 | 958 | */ |
959 | -function getpaid_get_authenticated_action_url( $action, $base = false ) { |
|
960 | - return wp_nonce_url( add_query_arg( 'getpaid-action', $action, $base ), 'getpaid-nonce', 'getpaid-nonce' ); |
|
959 | +function getpaid_get_authenticated_action_url($action, $base = false) { |
|
960 | + return wp_nonce_url(add_query_arg('getpaid-action', $action, $base), 'getpaid-nonce', 'getpaid-nonce'); |
|
961 | 961 | } |
962 | 962 | |
963 | 963 | /** |
@@ -965,11 +965,11 @@ discard block |
||
965 | 965 | * |
966 | 966 | * @return string |
967 | 967 | */ |
968 | -function getpaid_get_post_type_label( $post_type, $plural = true ) { |
|
968 | +function getpaid_get_post_type_label($post_type, $plural = true) { |
|
969 | 969 | |
970 | - $post_type = get_post_type_object( $post_type ); |
|
970 | + $post_type = get_post_type_object($post_type); |
|
971 | 971 | |
972 | - if ( ! is_object( $post_type ) ) { |
|
972 | + if (!is_object($post_type)) { |
|
973 | 973 | return null; |
974 | 974 | } |
975 | 975 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Returns the tax class objet. |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @return bool |
22 | 22 | */ |
23 | -function getpaid_is_eu_state( $country ) { |
|
24 | - return WPInv_EUVat::is_eu_state( $country ); |
|
23 | +function getpaid_is_eu_state($country) { |
|
24 | + return WPInv_EUVat::is_eu_state($country); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @return bool |
31 | 31 | */ |
32 | -function getpaid_is_gst_country( $country ) { |
|
33 | - return WPInv_EUVat::is_gst_country( $country ); |
|
32 | +function getpaid_is_gst_country($country) { |
|
33 | + return WPInv_EUVat::is_gst_country($country); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -44,117 +44,117 @@ discard block |
||
44 | 44 | |
45 | 45 | |
46 | 46 | function wpinv_use_taxes() { |
47 | - $ret = wpinv_get_option( 'enable_taxes', false ); |
|
47 | + $ret = wpinv_get_option('enable_taxes', false); |
|
48 | 48 | |
49 | - return (bool) apply_filters( 'wpinv_use_taxes', $ret ); |
|
49 | + return (bool) apply_filters('wpinv_use_taxes', $ret); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | function wpinv_get_tax_rates() { |
53 | - $rates = get_option( 'wpinv_tax_rates', array() ); |
|
53 | + $rates = get_option('wpinv_tax_rates', array()); |
|
54 | 54 | |
55 | - return apply_filters( 'wpinv_get_tax_rates', $rates ); |
|
55 | + return apply_filters('wpinv_get_tax_rates', $rates); |
|
56 | 56 | } |
57 | 57 | |
58 | -function wpinv_get_tax_rate( $country = false, $state = false, $item_id = 0 ) { |
|
58 | +function wpinv_get_tax_rate($country = false, $state = false, $item_id = 0) { |
|
59 | 59 | global $wpinv_euvat, $wpi_tax_rates, $wpi_userID; |
60 | - $wpi_tax_rates = !empty( $wpi_tax_rates ) ? $wpi_tax_rates : array(); |
|
60 | + $wpi_tax_rates = !empty($wpi_tax_rates) ? $wpi_tax_rates : array(); |
|
61 | 61 | |
62 | - if ( !empty( $wpi_tax_rates ) && !empty( $item_id ) && isset( $wpi_tax_rates[$item_id] ) ) { |
|
62 | + if (!empty($wpi_tax_rates) && !empty($item_id) && isset($wpi_tax_rates[$item_id])) { |
|
63 | 63 | return $wpi_tax_rates[$item_id]; |
64 | 64 | } |
65 | 65 | |
66 | - if ( !$wpinv_euvat->item_is_taxable( $item_id, $country, $state ) ) { |
|
66 | + if (!$wpinv_euvat->item_is_taxable($item_id, $country, $state)) { |
|
67 | 67 | $wpi_tax_rates[$item_id] = 0; |
68 | 68 | return 0; |
69 | 69 | } |
70 | 70 | |
71 | 71 | $is_global = false; |
72 | - if ( $item_id == 'global' ) { |
|
72 | + if ($item_id == 'global') { |
|
73 | 73 | $is_global = true; |
74 | 74 | $item_id = 0; |
75 | 75 | } |
76 | 76 | |
77 | - $rate = (float)wpinv_get_option( 'tax_rate', 0 ); |
|
78 | - $user_address = wpinv_get_user_address( $wpi_userID ); |
|
77 | + $rate = (float) wpinv_get_option('tax_rate', 0); |
|
78 | + $user_address = wpinv_get_user_address($wpi_userID); |
|
79 | 79 | |
80 | - if( empty( $country ) ) { |
|
81 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
80 | + if (empty($country)) { |
|
81 | + if (!empty($_POST['wpinv_country'])) { |
|
82 | 82 | $country = $_POST['wpinv_country']; |
83 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
83 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
84 | 84 | $country = $_POST['wpinv_country']; |
85 | - } elseif( !empty( $_POST['country'] ) ) { |
|
85 | + } elseif (!empty($_POST['country'])) { |
|
86 | 86 | $country = $_POST['country']; |
87 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
87 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
88 | 88 | $country = $user_address['country']; |
89 | 89 | } |
90 | - $country = !empty( $country ) ? $country : wpinv_get_default_country(); |
|
90 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
91 | 91 | } |
92 | 92 | |
93 | - if( empty( $state ) ) { |
|
94 | - if( !empty( $_POST['wpinv_state'] ) ) { |
|
93 | + if (empty($state)) { |
|
94 | + if (!empty($_POST['wpinv_state'])) { |
|
95 | 95 | $state = $_POST['wpinv_state']; |
96 | - } elseif( !empty( $_POST['wpinv_state'] ) ) { |
|
96 | + } elseif (!empty($_POST['wpinv_state'])) { |
|
97 | 97 | $state = $_POST['wpinv_state']; |
98 | - } elseif( !empty( $_POST['state'] ) ) { |
|
98 | + } elseif (!empty($_POST['state'])) { |
|
99 | 99 | $state = $_POST['state']; |
100 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
100 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
101 | 101 | $state = $user_address['state']; |
102 | 102 | } |
103 | - $state = !empty( $state ) ? $state : wpinv_get_default_state(); |
|
103 | + $state = !empty($state) ? $state : wpinv_get_default_state(); |
|
104 | 104 | } |
105 | 105 | |
106 | - if( !empty( $country ) ) { |
|
107 | - $tax_rates = wpinv_get_tax_rates(); |
|
106 | + if (!empty($country)) { |
|
107 | + $tax_rates = wpinv_get_tax_rates(); |
|
108 | 108 | |
109 | - if( !empty( $tax_rates ) ) { |
|
109 | + if (!empty($tax_rates)) { |
|
110 | 110 | // Locate the tax rate for this country / state, if it exists |
111 | - foreach( $tax_rates as $key => $tax_rate ) { |
|
112 | - if( $country != $tax_rate['country'] ) |
|
111 | + foreach ($tax_rates as $key => $tax_rate) { |
|
112 | + if ($country != $tax_rate['country']) |
|
113 | 113 | continue; |
114 | 114 | |
115 | - if( !empty( $tax_rate['global'] ) ) { |
|
116 | - if( !empty( $tax_rate['rate'] ) ) { |
|
117 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
115 | + if (!empty($tax_rate['global'])) { |
|
116 | + if (!empty($tax_rate['rate'])) { |
|
117 | + $rate = number_format($tax_rate['rate'], 4); |
|
118 | 118 | } |
119 | 119 | } else { |
120 | 120 | |
121 | - if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
121 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
122 | 122 | continue; |
123 | 123 | |
124 | 124 | $state_rate = $tax_rate['rate']; |
125 | - if( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
126 | - $rate = number_format( $state_rate, 4 ); |
|
125 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
126 | + $rate = number_format($state_rate, 4); |
|
127 | 127 | } |
128 | 128 | } |
129 | 129 | } |
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
133 | - $rate = apply_filters( 'wpinv_tax_rate', $rate, $country, $state, $item_id ); |
|
133 | + $rate = apply_filters('wpinv_tax_rate', $rate, $country, $state, $item_id); |
|
134 | 134 | |
135 | - if ( !empty( $item_id ) ) { |
|
135 | + if (!empty($item_id)) { |
|
136 | 136 | $wpi_tax_rates[$item_id] = $rate; |
137 | - } else if ( $is_global ) { |
|
137 | + } else if ($is_global) { |
|
138 | 138 | $wpi_tax_rates['global'] = $rate; |
139 | 139 | } |
140 | 140 | |
141 | 141 | return $rate; |
142 | 142 | } |
143 | 143 | |
144 | -function wpinv_get_formatted_tax_rate( $country = false, $state = false, $item_id ) { |
|
145 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
146 | - $rate = round( $rate, 4 ); |
|
144 | +function wpinv_get_formatted_tax_rate($country = false, $state = false, $item_id) { |
|
145 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
146 | + $rate = round($rate, 4); |
|
147 | 147 | $formatted = $rate .= '%'; |
148 | - return apply_filters( 'wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id ); |
|
148 | + return apply_filters('wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id); |
|
149 | 149 | } |
150 | 150 | |
151 | -function wpinv_calculate_tax( $amount = 0, $country = false, $state = false, $item_id = 0 ) { |
|
152 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
151 | +function wpinv_calculate_tax($amount = 0, $country = false, $state = false, $item_id = 0) { |
|
152 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
153 | 153 | $tax = 0.00; |
154 | 154 | |
155 | - if ( wpinv_use_taxes() ) { |
|
156 | - if ( wpinv_prices_include_tax() ) { |
|
157 | - $pre_tax = ( $amount / ( ( 1 + $rate ) * 0.01 ) ); |
|
155 | + if (wpinv_use_taxes()) { |
|
156 | + if (wpinv_prices_include_tax()) { |
|
157 | + $pre_tax = ($amount / ((1 + $rate) * 0.01)); |
|
158 | 158 | $tax = $amount - $pre_tax; |
159 | 159 | } else { |
160 | 160 | $tax = $amount * $rate * 0.01; |
@@ -162,46 +162,46 @@ discard block |
||
162 | 162 | |
163 | 163 | } |
164 | 164 | |
165 | - return apply_filters( 'wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id ); |
|
165 | + return apply_filters('wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | function wpinv_prices_include_tax() { |
169 | 169 | return false; // TODO |
170 | - $ret = ( wpinv_get_option( 'prices_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
170 | + $ret = (wpinv_get_option('prices_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
171 | 171 | |
172 | - return apply_filters( 'wpinv_prices_include_tax', $ret ); |
|
172 | + return apply_filters('wpinv_prices_include_tax', $ret); |
|
173 | 173 | } |
174 | 174 | |
175 | -function wpinv_sales_tax_for_year( $year = null ) { |
|
176 | - return wpinv_price( wpinv_format_amount( wpinv_get_sales_tax_for_year( $year ) ) ); |
|
175 | +function wpinv_sales_tax_for_year($year = null) { |
|
176 | + return wpinv_price(wpinv_format_amount(wpinv_get_sales_tax_for_year($year))); |
|
177 | 177 | } |
178 | 178 | |
179 | -function wpinv_get_sales_tax_for_year( $year = null ) { |
|
179 | +function wpinv_get_sales_tax_for_year($year = null) { |
|
180 | 180 | global $wpdb; |
181 | 181 | |
182 | 182 | // Start at zero |
183 | 183 | $tax = 0; |
184 | 184 | |
185 | - if ( ! empty( $year ) ) { |
|
185 | + if (!empty($year)) { |
|
186 | 186 | $args = array( |
187 | 187 | 'post_type' => 'wpi_invoice', |
188 | - 'post_status' => array( 'publish' ), |
|
188 | + 'post_status' => array('publish'), |
|
189 | 189 | 'posts_per_page' => -1, |
190 | 190 | 'year' => $year, |
191 | 191 | 'fields' => 'ids' |
192 | 192 | ); |
193 | 193 | |
194 | - $payments = get_posts( $args ); |
|
195 | - $payment_ids = implode( ',', $payments ); |
|
194 | + $payments = get_posts($args); |
|
195 | + $payment_ids = implode(',', $payments); |
|
196 | 196 | |
197 | - if ( count( $payments ) > 0 ) { |
|
197 | + if (count($payments) > 0) { |
|
198 | 198 | $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )"; |
199 | - $tax = $wpdb->get_var( $sql ); |
|
199 | + $tax = $wpdb->get_var($sql); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | } |
203 | 203 | |
204 | - return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year ); |
|
204 | + return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | function wpinv_is_cart_taxed() { |
@@ -210,33 +210,33 @@ discard block |
||
210 | 210 | |
211 | 211 | function wpinv_prices_show_tax_on_checkout() { |
212 | 212 | return false; // TODO |
213 | - $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
213 | + $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
214 | 214 | |
215 | - return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret ); |
|
215 | + return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | function wpinv_display_tax_rate() { |
219 | - $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false ); |
|
219 | + $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false); |
|
220 | 220 | |
221 | - return apply_filters( 'wpinv_display_tax_rate', $ret ); |
|
221 | + return apply_filters('wpinv_display_tax_rate', $ret); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | function wpinv_cart_needs_tax_address_fields() { |
225 | - if( !wpinv_is_cart_taxed() ) |
|
225 | + if (!wpinv_is_cart_taxed()) |
|
226 | 226 | return false; |
227 | 227 | |
228 | - return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' ); |
|
228 | + return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields'); |
|
229 | 229 | } |
230 | 230 | |
231 | -function wpinv_item_is_tax_exclusive( $item_id = 0 ) { |
|
232 | - $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false ); |
|
233 | - return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id ); |
|
231 | +function wpinv_item_is_tax_exclusive($item_id = 0) { |
|
232 | + $ret = (bool) get_post_meta($item_id, '_wpinv_tax_exclusive', false); |
|
233 | + return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id); |
|
234 | 234 | } |
235 | 235 | |
236 | -function wpinv_currency_decimal_filter( $decimals = 2 ) { |
|
236 | +function wpinv_currency_decimal_filter($decimals = 2) { |
|
237 | 237 | $currency = wpinv_get_currency(); |
238 | 238 | |
239 | - switch ( $currency ) { |
|
239 | + switch ($currency) { |
|
240 | 240 | case 'RIAL' : |
241 | 241 | case 'JPY' : |
242 | 242 | case 'TWD' : |
@@ -245,50 +245,50 @@ discard block |
||
245 | 245 | break; |
246 | 246 | } |
247 | 247 | |
248 | - return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency ); |
|
248 | + return apply_filters('wpinv_currency_decimal_count', $decimals, $currency); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | function wpinv_tax_amount() { |
252 | 252 | $output = 0.00; |
253 | 253 | |
254 | - return apply_filters( 'wpinv_tax_amount', $output ); |
|
254 | + return apply_filters('wpinv_tax_amount', $output); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | // VAT Settings |
258 | -function wpinv_vat_rate_add_callback( $args ) { |
|
258 | +function wpinv_vat_rate_add_callback($args) { |
|
259 | 259 | ?> |
260 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e( 'Add', 'invoicing' );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
260 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
261 | 261 | <?php |
262 | 262 | } |
263 | 263 | |
264 | -function wpinv_vat_rate_delete_callback( $args ) { |
|
264 | +function wpinv_vat_rate_delete_callback($args) { |
|
265 | 265 | global $wpinv_euvat; |
266 | 266 | |
267 | 267 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
268 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : ''; |
|
269 | - if ( isset( $vat_classes[$vat_class] ) ) { |
|
268 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : ''; |
|
269 | + if (isset($vat_classes[$vat_class])) { |
|
270 | 270 | ?> |
271 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf( esc_attr__( 'Delete class "%s"', 'invoicing' ), $vat_classes[$vat_class] );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
271 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf(esc_attr__('Delete class "%s"', 'invoicing'), $vat_classes[$vat_class]); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
272 | 272 | <?php |
273 | 273 | } |
274 | 274 | } |
275 | 275 | |
276 | -function wpinv_vat_rates_callback( $args ) { |
|
276 | +function wpinv_vat_rates_callback($args) { |
|
277 | 277 | global $wpinv_euvat; |
278 | 278 | |
279 | 279 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
280 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_standard'; |
|
280 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_standard'; |
|
281 | 281 | |
282 | 282 | $eu_states = $wpinv_euvat->get_eu_states(); |
283 | 283 | $countries = wpinv_get_country_list(); |
284 | 284 | $vat_groups = $wpinv_euvat->get_vat_groups(); |
285 | - $rates = $wpinv_euvat->get_vat_rates( $vat_class ); |
|
285 | + $rates = $wpinv_euvat->get_vat_rates($vat_class); |
|
286 | 286 | ob_start(); |
287 | 287 | ?> |
288 | 288 | </td><tr> |
289 | 289 | <td colspan="2" class="wpinv_vat_tdbox"> |
290 | - <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class;?>" /> |
|
291 | - <p><?php echo ( isset( $args['desc'] ) ? $args['desc'] : '' ); ?></p> |
|
290 | + <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class; ?>" /> |
|
291 | + <p><?php echo (isset($args['desc']) ? $args['desc'] : ''); ?></p> |
|
292 | 292 | <table id="wpinv_vat_rates" class="wp-list-table widefat fixed posts"> |
293 | 293 | <colgroup> |
294 | 294 | <col width="50px" /> |
@@ -300,43 +300,43 @@ discard block |
||
300 | 300 | </colgroup> |
301 | 301 | <thead> |
302 | 302 | <tr> |
303 | - <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e( 'Country', 'invoicing' ); ?></th> |
|
304 | - <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e( 'Apply rate to whole country', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th> |
|
305 | - <th scope="col" class="wpinv_vat_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> |
|
306 | - <th scope="col" class="wpinv_vat_name"><?php _e( 'VAT Name', 'invoicing' ); ?></th> |
|
307 | - <th scope="col" class="wpinv_vat_group"><?php _e( 'Tax Group', 'invoicing' ); ?></th> |
|
303 | + <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e('Country', 'invoicing'); ?></th> |
|
304 | + <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e('Apply rate to whole country', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th> |
|
305 | + <th scope="col" class="wpinv_vat_rate"><?php _e('Rate %', 'invoicing'); ?></th> |
|
306 | + <th scope="col" class="wpinv_vat_name"><?php _e('VAT Name', 'invoicing'); ?></th> |
|
307 | + <th scope="col" class="wpinv_vat_group"><?php _e('Tax Group', 'invoicing'); ?></th> |
|
308 | 308 | </tr> |
309 | 309 | </thead> |
310 | 310 | <tbody> |
311 | - <?php if( !empty( $eu_states ) ) { ?> |
|
311 | + <?php if (!empty($eu_states)) { ?> |
|
312 | 312 | <?php |
313 | - foreach ( $eu_states as $state ) { |
|
314 | - $country_name = isset( $countries[$state] ) ? $countries[$state] : ''; |
|
313 | + foreach ($eu_states as $state) { |
|
314 | + $country_name = isset($countries[$state]) ? $countries[$state] : ''; |
|
315 | 315 | |
316 | 316 | // Filter the rate for each country |
317 | - $country_rate = array_filter( $rates, function( $rate ) use( $state ) { return $rate['country'] === $state; } ); |
|
317 | + $country_rate = array_filter($rates, function($rate) use($state) { return $rate['country'] === $state; } ); |
|
318 | 318 | |
319 | 319 | // If one does not exist create a default |
320 | - $country_rate = is_array( $country_rate ) && count( $country_rate ) > 0 ? reset( $country_rate ) : array(); |
|
320 | + $country_rate = is_array($country_rate) && count($country_rate) > 0 ? reset($country_rate) : array(); |
|
321 | 321 | |
322 | - $vat_global = isset( $country_rate['global'] ) ? !empty( $country_rate['global'] ) : true; |
|
323 | - $vat_rate = isset( $country_rate['rate'] ) ? $country_rate['rate'] : ''; |
|
324 | - $vat_name = !empty( $country_rate['name'] ) ? esc_attr( stripslashes( $country_rate['name'] ) ) : ''; |
|
325 | - $vat_group = !empty( $country_rate['group'] ) ? $country_rate['group'] : ( $vat_class === '_standard' ? 'standard' : 'reduced' ); |
|
322 | + $vat_global = isset($country_rate['global']) ? !empty($country_rate['global']) : true; |
|
323 | + $vat_rate = isset($country_rate['rate']) ? $country_rate['rate'] : ''; |
|
324 | + $vat_name = !empty($country_rate['name']) ? esc_attr(stripslashes($country_rate['name'])) : ''; |
|
325 | + $vat_group = !empty($country_rate['group']) ? $country_rate['group'] : ($vat_class === '_standard' ? 'standard' : 'reduced'); |
|
326 | 326 | ?> |
327 | 327 | <tr> |
328 | 328 | <td class="wpinv_vat_country"><?php echo $state; ?><input type="hidden" name="vat_rates[<?php echo $state; ?>][country]" value="<?php echo $state; ?>" /><input type="hidden" name="vat_rates[<?php echo $state; ?>][state]" value="" /></td> |
329 | 329 | <td class="wpinv_vat_country_name"><?php echo $country_name; ?></td> |
330 | 330 | <td class="wpinv_vat_global"> |
331 | - <input type="checkbox" name="vat_rates[<?php echo $state;?>][global]" id="vat_rates[<?php echo $state;?>][global]" value="1" <?php checked( true, $vat_global );?> disabled="disabled" /> |
|
332 | - <label for="tax_rates[<?php echo $state;?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label> |
|
333 | - <input type="hidden" name="vat_rates[<?php echo $state;?>][global]" value="1" checked="checked" /> |
|
331 | + <input type="checkbox" name="vat_rates[<?php echo $state; ?>][global]" id="vat_rates[<?php echo $state; ?>][global]" value="1" <?php checked(true, $vat_global); ?> disabled="disabled" /> |
|
332 | + <label for="tax_rates[<?php echo $state; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label> |
|
333 | + <input type="hidden" name="vat_rates[<?php echo $state; ?>][global]" value="1" checked="checked" /> |
|
334 | 334 | </td> |
335 | - <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state;?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
336 | - <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state;?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
335 | + <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state; ?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
336 | + <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state; ?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
337 | 337 | <td class="wpinv_vat_group"> |
338 | 338 | <?php |
339 | - echo wpinv_html_select( array( |
|
339 | + echo wpinv_html_select(array( |
|
340 | 340 | 'name' => 'vat_rates[' . $state . '][group]', |
341 | 341 | 'selected' => $vat_group, |
342 | 342 | 'id' => 'vat_rates[' . $state . '][group]', |
@@ -345,14 +345,14 @@ discard block |
||
345 | 345 | 'multiple' => false, |
346 | 346 | 'show_option_all' => false, |
347 | 347 | 'show_option_none' => false |
348 | - ) ); |
|
348 | + )); |
|
349 | 349 | ?> |
350 | 350 | </td> |
351 | 351 | </tr> |
352 | 352 | <?php } ?> |
353 | 353 | <tr> |
354 | 354 | <td colspan="6" style="background-color:#fafafa;"> |
355 | - <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e( 'Update EU VAT Rates', 'invoicing' ); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
355 | + <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e('Update EU VAT Rates', 'invoicing'); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
356 | 356 | </td> |
357 | 357 | </tr> |
358 | 358 | <?php } ?> |
@@ -364,35 +364,35 @@ discard block |
||
364 | 364 | echo $content; |
365 | 365 | } |
366 | 366 | |
367 | -function wpinv_vat_number_callback( $args ) { |
|
367 | +function wpinv_vat_number_callback($args) { |
|
368 | 368 | global $wpinv_euvat; |
369 | 369 | |
370 | 370 | $vat_number = $wpinv_euvat->get_vat_number(); |
371 | 371 | $vat_valid = $wpinv_euvat->is_vat_validated(); |
372 | 372 | |
373 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
374 | - $validated_text = $vat_valid ? __( 'VAT number validated', 'invoicing' ) : __( 'VAT number not validated', 'invoicing' ); |
|
373 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
374 | + $validated_text = $vat_valid ? __('VAT number validated', 'invoicing') : __('VAT number not validated', 'invoicing'); |
|
375 | 375 | $disabled = $vat_valid ? 'disabled="disabled"' : " "; |
376 | 376 | |
377 | - $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr( stripslashes( $vat_number ) ) . '"/>'; |
|
378 | - $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__( 'Validate VAT Number', 'invoicing' ) . '" /></span>'; |
|
379 | - $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int)$vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>'; |
|
380 | - $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __( 'Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing' ).'</p>' . '</label>'; |
|
381 | - $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce( 'vat_validation' ) . '">'; |
|
377 | + $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr(stripslashes($vat_number)) . '"/>'; |
|
378 | + $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__('Validate VAT Number', 'invoicing') . '" /></span>'; |
|
379 | + $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int) $vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>'; |
|
380 | + $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __('Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing') . '</p>' . '</label>'; |
|
381 | + $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce('vat_validation') . '">'; |
|
382 | 382 | |
383 | 383 | echo $html; |
384 | 384 | } |
385 | 385 | |
386 | -function wpinv_eu_fallback_rate_callback( $args ) { |
|
386 | +function wpinv_eu_fallback_rate_callback($args) { |
|
387 | 387 | global $wpinv_options; |
388 | 388 | |
389 | - $value = isset( $wpinv_options[$args['id']] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : '' ); |
|
390 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'small'; |
|
389 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : ''); |
|
390 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'small'; |
|
391 | 391 | |
392 | - $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
393 | - $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Add EU Member States', 'invoicing' ) . '" /></span>'; |
|
394 | - $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Remove EU Member States', 'invoicing' ) . '" /></span>'; |
|
395 | - $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__( 'Update EU VAT Rates', 'invoicing' ) . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
392 | + $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr(stripslashes($value)) . '" />'; |
|
393 | + $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Add EU Member States', 'invoicing') . '" /></span>'; |
|
394 | + $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Remove EU Member States', 'invoicing') . '" /></span>'; |
|
395 | + $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__('Update EU VAT Rates', 'invoicing') . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
396 | 396 | $html .= '<p><label for="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '">' . $args['desc'] . '</label></p>'; |
397 | 397 | echo $html; |
398 | 398 | ?> |
@@ -405,22 +405,22 @@ discard block |
||
405 | 405 | * |
406 | 406 | * @param string|bool|null $vat_rule |
407 | 407 | */ |
408 | -function getpaid_filter_vat_rule( $vat_rule ) { |
|
408 | +function getpaid_filter_vat_rule($vat_rule) { |
|
409 | 409 | |
410 | - if ( empty( $vat_rule ) ) { |
|
410 | + if (empty($vat_rule)) { |
|
411 | 411 | return getpaid_tax()->allow_vat_rules() ? 'digital' : 'physical'; |
412 | 412 | } |
413 | 413 | |
414 | 414 | return $vat_rule; |
415 | 415 | } |
416 | -add_filter( 'wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule' ); |
|
416 | +add_filter('wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule'); |
|
417 | 417 | |
418 | 418 | /** |
419 | 419 | * Filters the VAT class to ensure that each item has a VAT class. |
420 | 420 | * |
421 | 421 | * @param string|bool|null $vat_rule |
422 | 422 | */ |
423 | -function getpaid_filter_vat_class( $vat_class ) { |
|
424 | - return empty( $vat_class ) ? '_standard' : $vat_class; |
|
423 | +function getpaid_filter_vat_class($vat_class) { |
|
424 | + return empty($vat_class) ? '_standard' : $vat_class; |
|
425 | 425 | } |
426 | -add_filter( 'wpinv_get_item_vat_class', 'getpaid_filter_vat_class' ); |
|
426 | +add_filter('wpinv_get_item_vat_class', 'getpaid_filter_vat_class'); |
@@ -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( $_GET['form'] ); |
|
271 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
272 | - getpaid_display_invoice_payment_form( $_GET['invoice'] ); |
|
269 | + if (!empty($_GET['form'])) { |
|
270 | + getpaid_display_payment_form($_GET['form']); |
|
271 | + } else if (!empty($_GET['invoice'])) { |
|
272 | + getpaid_display_invoice_payment_form($_GET['invoice']); |
|
273 | 273 | } else { |
274 | - $items = getpaid_convert_items_to_array( $_GET['item'] ); |
|
275 | - getpaid_display_item_payment_form( $items ); |
|
274 | + $items = getpaid_convert_items_to_array($_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,54 +310,54 @@ 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 | 358 | ); |
359 | 359 | |
360 | - wp_send_json_success( $html ); |
|
360 | + wp_send_json_success($html); |
|
361 | 361 | exit; |
362 | 362 | |
363 | 363 | } |
@@ -373,56 +373,56 @@ discard block |
||
373 | 373 | public static function recalculate_invoice_totals() { |
374 | 374 | |
375 | 375 | // Verify nonce. |
376 | - check_ajax_referer( 'wpinv-nonce' ); |
|
376 | + check_ajax_referer('wpinv-nonce'); |
|
377 | 377 | |
378 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
378 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
379 | 379 | exit; |
380 | 380 | } |
381 | 381 | |
382 | 382 | // We need an invoice. |
383 | - if ( empty( $_POST['post_id'] ) ) { |
|
383 | + if (empty($_POST['post_id'])) { |
|
384 | 384 | exit; |
385 | 385 | } |
386 | 386 | |
387 | 387 | // Fetch the invoice. |
388 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
388 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
389 | 389 | |
390 | 390 | // Ensure it exists. |
391 | - if ( ! $invoice->get_id() ) { |
|
391 | + if (!$invoice->get_id()) { |
|
392 | 392 | exit; |
393 | 393 | } |
394 | 394 | |
395 | 395 | // Maybe set the country, state, currency. |
396 | - foreach ( array( 'country', 'state', 'currency' ) as $key ) { |
|
397 | - if ( isset( $_POST[ $key ] ) ) { |
|
396 | + foreach (array('country', 'state', 'currency') as $key) { |
|
397 | + if (isset($_POST[$key])) { |
|
398 | 398 | $method = "set_$key"; |
399 | - $invoice->$method( $_POST[ $key ] ); |
|
399 | + $invoice->$method($_POST[$key]); |
|
400 | 400 | } |
401 | 401 | } |
402 | 402 | |
403 | 403 | // Maybe disable taxes. |
404 | - $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) ); |
|
404 | + $invoice->set_disable_taxes(!empty($_POST['taxes'])); |
|
405 | 405 | |
406 | 406 | // Recalculate totals. |
407 | 407 | $invoice->recalculate_total(); |
408 | 408 | |
409 | - $total = wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() ); |
|
409 | + $total = wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency()); |
|
410 | 410 | |
411 | - if ( $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) { |
|
412 | - $recurring_total = wpinv_price( wpinv_format_amount( $invoice->get_recurring_total() ), $invoice->get_currency() ); |
|
413 | - $total .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>'; |
|
411 | + if ($invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) { |
|
412 | + $recurring_total = wpinv_price(wpinv_format_amount($invoice->get_recurring_total()), $invoice->get_currency()); |
|
413 | + $total .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>'; |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | $totals = array( |
417 | - 'subtotal' => wpinv_price( wpinv_format_amount( $invoice->get_subtotal() ), $invoice->get_currency() ), |
|
418 | - 'discount' => wpinv_price( wpinv_format_amount( $invoice->get_total_discount() ), $invoice->get_currency() ), |
|
419 | - 'tax' => wpinv_price( wpinv_format_amount( $invoice->get_total_tax() ), $invoice->get_currency() ), |
|
417 | + 'subtotal' => wpinv_price(wpinv_format_amount($invoice->get_subtotal()), $invoice->get_currency()), |
|
418 | + 'discount' => wpinv_price(wpinv_format_amount($invoice->get_total_discount()), $invoice->get_currency()), |
|
419 | + 'tax' => wpinv_price(wpinv_format_amount($invoice->get_total_tax()), $invoice->get_currency()), |
|
420 | 420 | 'total' => $total, |
421 | 421 | ); |
422 | 422 | |
423 | - $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice ); |
|
423 | + $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice); |
|
424 | 424 | |
425 | - wp_send_json_success( compact( 'totals' ) ); |
|
425 | + wp_send_json_success(compact('totals')); |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | /** |
@@ -431,33 +431,33 @@ discard block |
||
431 | 431 | public static function get_invoice_items() { |
432 | 432 | |
433 | 433 | // Verify nonce. |
434 | - check_ajax_referer( 'wpinv-nonce' ); |
|
434 | + check_ajax_referer('wpinv-nonce'); |
|
435 | 435 | |
436 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
436 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
437 | 437 | exit; |
438 | 438 | } |
439 | 439 | |
440 | 440 | // We need an invoice and items. |
441 | - if ( empty( $_POST['post_id'] ) ) { |
|
441 | + if (empty($_POST['post_id'])) { |
|
442 | 442 | exit; |
443 | 443 | } |
444 | 444 | |
445 | 445 | // Fetch the invoice. |
446 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
446 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
447 | 447 | |
448 | 448 | // Ensure it exists. |
449 | - if ( ! $invoice->get_id() ) { |
|
449 | + if (!$invoice->get_id()) { |
|
450 | 450 | exit; |
451 | 451 | } |
452 | 452 | |
453 | 453 | // Return an array of invoice items. |
454 | 454 | $items = array(); |
455 | 455 | |
456 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
457 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
456 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
457 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
458 | 458 | } |
459 | 459 | |
460 | - wp_send_json_success( compact( 'items' ) ); |
|
460 | + wp_send_json_success(compact('items')); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | /** |
@@ -466,50 +466,50 @@ discard block |
||
466 | 466 | public static function edit_invoice_item() { |
467 | 467 | |
468 | 468 | // Verify nonce. |
469 | - check_ajax_referer( 'wpinv-nonce' ); |
|
469 | + check_ajax_referer('wpinv-nonce'); |
|
470 | 470 | |
471 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
471 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
472 | 472 | exit; |
473 | 473 | } |
474 | 474 | |
475 | 475 | // We need an invoice and item details. |
476 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) { |
|
476 | + if (empty($_POST['post_id']) || empty($_POST['data'])) { |
|
477 | 477 | exit; |
478 | 478 | } |
479 | 479 | |
480 | 480 | // Fetch the invoice. |
481 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
481 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
482 | 482 | |
483 | 483 | // Ensure it exists and its not been paid for. |
484 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
484 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
485 | 485 | exit; |
486 | 486 | } |
487 | 487 | |
488 | 488 | // Format the data. |
489 | - $data = wp_list_pluck( $_POST['data'], 'value', 'field' ); |
|
489 | + $data = wp_list_pluck($_POST['data'], 'value', 'field'); |
|
490 | 490 | |
491 | 491 | // Ensure that we have an item id. |
492 | - if ( empty( $data['id'] ) ) { |
|
492 | + if (empty($data['id'])) { |
|
493 | 493 | exit; |
494 | 494 | } |
495 | 495 | |
496 | 496 | // Abort if the invoice does not have the specified item. |
497 | - $item = $invoice->get_item( (int) $data['id'] ); |
|
497 | + $item = $invoice->get_item((int) $data['id']); |
|
498 | 498 | |
499 | - if ( empty( $item ) ) { |
|
499 | + if (empty($item)) { |
|
500 | 500 | exit; |
501 | 501 | } |
502 | 502 | |
503 | 503 | // Update the item. |
504 | - $item->set_price( $data['price'] ); |
|
505 | - $item->set_name( $data['name'] ); |
|
506 | - $item->set_description( $data['description'] ); |
|
507 | - $item->set_quantity( $data['quantity'] ); |
|
504 | + $item->set_price($data['price']); |
|
505 | + $item->set_name($data['name']); |
|
506 | + $item->set_description($data['description']); |
|
507 | + $item->set_quantity($data['quantity']); |
|
508 | 508 | |
509 | 509 | // Add it to the invoice. |
510 | - $error = $invoice->add_item( $item ); |
|
510 | + $error = $invoice->add_item($item); |
|
511 | 511 | $alert = false; |
512 | - if ( is_wp_error( $error ) ) { |
|
512 | + if (is_wp_error($error)) { |
|
513 | 513 | $alert = $error->get_error_message(); |
514 | 514 | } |
515 | 515 | |
@@ -522,11 +522,11 @@ discard block |
||
522 | 522 | // Return an array of invoice items. |
523 | 523 | $items = array(); |
524 | 524 | |
525 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
526 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
525 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
526 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
527 | 527 | } |
528 | 528 | |
529 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
529 | + wp_send_json_success(compact('items', 'alert')); |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | /** |
@@ -535,33 +535,33 @@ discard block |
||
535 | 535 | public static function remove_invoice_item() { |
536 | 536 | |
537 | 537 | // Verify nonce. |
538 | - check_ajax_referer( 'wpinv-nonce' ); |
|
538 | + check_ajax_referer('wpinv-nonce'); |
|
539 | 539 | |
540 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
540 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
541 | 541 | exit; |
542 | 542 | } |
543 | 543 | |
544 | 544 | // We need an invoice and an item. |
545 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
545 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
546 | 546 | exit; |
547 | 547 | } |
548 | 548 | |
549 | 549 | // Fetch the invoice. |
550 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
550 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
551 | 551 | |
552 | 552 | // Ensure it exists and its not been paid for. |
553 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
553 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
554 | 554 | exit; |
555 | 555 | } |
556 | 556 | |
557 | 557 | // Abort if the invoice does not have the specified item. |
558 | - $item = $invoice->get_item( (int) $_POST['item_id'] ); |
|
558 | + $item = $invoice->get_item((int) $_POST['item_id']); |
|
559 | 559 | |
560 | - if ( empty( $item ) ) { |
|
560 | + if (empty($item)) { |
|
561 | 561 | exit; |
562 | 562 | } |
563 | 563 | |
564 | - $invoice->remove_item( (int) $_POST['item_id'] ); |
|
564 | + $invoice->remove_item((int) $_POST['item_id']); |
|
565 | 565 | |
566 | 566 | // Update totals. |
567 | 567 | $invoice->recalculate_total(); |
@@ -572,11 +572,11 @@ discard block |
||
572 | 572 | // Return an array of invoice items. |
573 | 573 | $items = array(); |
574 | 574 | |
575 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
576 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
575 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
576 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
577 | 577 | } |
578 | 578 | |
579 | - wp_send_json_success( compact( 'items' ) ); |
|
579 | + wp_send_json_success(compact('items')); |
|
580 | 580 | } |
581 | 581 | |
582 | 582 | /** |
@@ -585,39 +585,39 @@ discard block |
||
585 | 585 | public static function add_invoice_items() { |
586 | 586 | |
587 | 587 | // Verify nonce. |
588 | - check_ajax_referer( 'wpinv-nonce' ); |
|
588 | + check_ajax_referer('wpinv-nonce'); |
|
589 | 589 | |
590 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
590 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
591 | 591 | exit; |
592 | 592 | } |
593 | 593 | |
594 | 594 | // We need an invoice and items. |
595 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) { |
|
595 | + if (empty($_POST['post_id']) || empty($_POST['items'])) { |
|
596 | 596 | exit; |
597 | 597 | } |
598 | 598 | |
599 | 599 | // Fetch the invoice. |
600 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
600 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
601 | 601 | $alert = false; |
602 | 602 | |
603 | 603 | // Ensure it exists and its not been paid for. |
604 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
604 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
605 | 605 | exit; |
606 | 606 | } |
607 | 607 | |
608 | 608 | // Add the items. |
609 | - foreach ( $_POST['items'] as $data ) { |
|
609 | + foreach ($_POST['items'] as $data) { |
|
610 | 610 | |
611 | - $item = new GetPaid_Form_Item( $data[ 'id' ] ); |
|
611 | + $item = new GetPaid_Form_Item($data['id']); |
|
612 | 612 | |
613 | - if ( is_numeric( $data[ 'qty' ] ) && (int) $data[ 'qty' ] > 0 ) { |
|
614 | - $item->set_quantity( $data[ 'qty' ] ); |
|
613 | + if (is_numeric($data['qty']) && (int) $data['qty'] > 0) { |
|
614 | + $item->set_quantity($data['qty']); |
|
615 | 615 | } |
616 | 616 | |
617 | - if ( $item->get_id() > 0 ) { |
|
618 | - $error = $invoice->add_item( $item ); |
|
617 | + if ($item->get_id() > 0) { |
|
618 | + $error = $invoice->add_item($item); |
|
619 | 619 | |
620 | - if ( is_wp_error( $error ) ) { |
|
620 | + if (is_wp_error($error)) { |
|
621 | 621 | $alert = $error->get_error_message(); |
622 | 622 | } |
623 | 623 | |
@@ -632,11 +632,11 @@ discard block |
||
632 | 632 | // Return an array of invoice items. |
633 | 633 | $items = array(); |
634 | 634 | |
635 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
636 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
635 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
636 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
637 | 637 | } |
638 | 638 | |
639 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
639 | + wp_send_json_success(compact('items', 'alert')); |
|
640 | 640 | } |
641 | 641 | |
642 | 642 | /** |
@@ -645,15 +645,15 @@ discard block |
||
645 | 645 | public static function get_invoicing_items() { |
646 | 646 | |
647 | 647 | // Verify nonce. |
648 | - check_ajax_referer( 'wpinv-nonce' ); |
|
648 | + check_ajax_referer('wpinv-nonce'); |
|
649 | 649 | |
650 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
650 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
651 | 651 | exit; |
652 | 652 | } |
653 | 653 | |
654 | 654 | // We need a search term. |
655 | - if ( empty( $_GET['search'] ) ) { |
|
656 | - wp_send_json_success( array() ); |
|
655 | + if (empty($_GET['search'])) { |
|
656 | + wp_send_json_success(array()); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | // Retrieve items. |
@@ -662,8 +662,8 @@ discard block |
||
662 | 662 | 'orderby' => 'title', |
663 | 663 | 'order' => 'ASC', |
664 | 664 | 'posts_per_page' => -1, |
665 | - 'post_status' => array( 'publish' ), |
|
666 | - 's' => trim( $_GET['search'] ), |
|
665 | + 'post_status' => array('publish'), |
|
666 | + 's' => trim($_GET['search']), |
|
667 | 667 | 'meta_query' => array( |
668 | 668 | array( |
669 | 669 | 'key' => '_wpinv_type', |
@@ -673,22 +673,22 @@ discard block |
||
673 | 673 | ) |
674 | 674 | ); |
675 | 675 | |
676 | - $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) ); |
|
676 | + $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args)); |
|
677 | 677 | $data = array(); |
678 | 678 | |
679 | 679 | |
680 | - $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) ); |
|
680 | + $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id'])); |
|
681 | 681 | |
682 | - foreach ( $items as $item ) { |
|
683 | - $item = new GetPaid_Form_Item( $item ); |
|
682 | + foreach ($items as $item) { |
|
683 | + $item = new GetPaid_Form_Item($item); |
|
684 | 684 | $data[] = array( |
685 | 685 | 'id' => (int) $item->get_id(), |
686 | - 'text' => strip_tags( $item->get_name() ), |
|
687 | - 'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '', |
|
686 | + 'text' => strip_tags($item->get_name()), |
|
687 | + 'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '', |
|
688 | 688 | ); |
689 | 689 | } |
690 | 690 | |
691 | - wp_send_json_success( $data ); |
|
691 | + wp_send_json_success($data); |
|
692 | 692 | |
693 | 693 | } |
694 | 694 | |
@@ -698,24 +698,24 @@ discard block |
||
698 | 698 | public static function get_aui_states_field() { |
699 | 699 | |
700 | 700 | // Verify nonce. |
701 | - check_ajax_referer( 'wpinv-nonce' ); |
|
701 | + check_ajax_referer('wpinv-nonce'); |
|
702 | 702 | |
703 | 703 | // We need a country. |
704 | - if ( empty( $_GET['country'] ) ) { |
|
704 | + if (empty($_GET['country'])) { |
|
705 | 705 | exit; |
706 | 706 | } |
707 | 707 | |
708 | - $states = wpinv_get_country_states( trim( $_GET['country'] ) ); |
|
709 | - $state = isset( $_GET['state'] ) ? trim( $_GET['state'] ) : wpinv_get_default_state(); |
|
708 | + $states = wpinv_get_country_states(trim($_GET['country'])); |
|
709 | + $state = isset($_GET['state']) ? trim($_GET['state']) : wpinv_get_default_state(); |
|
710 | 710 | |
711 | - if ( empty( $states ) ) { |
|
711 | + if (empty($states)) { |
|
712 | 712 | |
713 | 713 | $html = aui()->input( |
714 | 714 | array( |
715 | 715 | 'type' => 'text', |
716 | 716 | 'id' => 'wpinv_state', |
717 | 717 | 'name' => 'wpinv_state', |
718 | - 'label' => __( 'State', 'invoicing' ), |
|
718 | + 'label' => __('State', 'invoicing'), |
|
719 | 719 | 'label_type' => 'vertical', |
720 | 720 | 'placeholder' => 'Liège', |
721 | 721 | 'class' => 'form-control-sm', |
@@ -729,9 +729,9 @@ discard block |
||
729 | 729 | array( |
730 | 730 | 'id' => 'wpinv_state', |
731 | 731 | 'name' => 'wpinv_state', |
732 | - 'label' => __( 'State', 'invoicing' ), |
|
732 | + 'label' => __('State', 'invoicing'), |
|
733 | 733 | 'label_type' => 'vertical', |
734 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
734 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
735 | 735 | 'class' => 'form-control-sm', |
736 | 736 | 'value' => $state, |
737 | 737 | 'options' => $states, |
@@ -745,7 +745,7 @@ discard block |
||
745 | 745 | wp_send_json_success( |
746 | 746 | array( |
747 | 747 | 'html' => $html, |
748 | - 'select' => ! empty ( $states ) |
|
748 | + 'select' => !empty ($states) |
|
749 | 749 | ) |
750 | 750 | ); |
751 | 751 | |
@@ -759,11 +759,11 @@ discard block |
||
759 | 759 | public static function payment_form_refresh_prices() { |
760 | 760 | |
761 | 761 | // Check nonce. |
762 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
762 | + check_ajax_referer('getpaid_form_nonce'); |
|
763 | 763 | |
764 | 764 | // ... form fields... |
765 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
766 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
765 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
766 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
767 | 767 | exit; |
768 | 768 | } |
769 | 769 | |
@@ -771,18 +771,18 @@ discard block |
||
771 | 771 | $submission = new GetPaid_Payment_Form_Submission(); |
772 | 772 | |
773 | 773 | // Do we have an error? |
774 | - if ( ! empty( $submission->last_error ) ) { |
|
774 | + if (!empty($submission->last_error)) { |
|
775 | 775 | echo $submission->last_error; |
776 | 776 | exit; |
777 | 777 | } |
778 | 778 | |
779 | 779 | // Prepare the response. |
780 | - $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission ); |
|
780 | + $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission); |
|
781 | 781 | |
782 | 782 | // Filter the response. |
783 | - $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission ); |
|
783 | + $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission); |
|
784 | 784 | |
785 | - wp_send_json_success( $response ); |
|
785 | + wp_send_json_success($response); |
|
786 | 786 | } |
787 | 787 | |
788 | 788 | } |