@@ -13,9 +13,9 @@ discard block |
||
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 | /** |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | function wpinv_sanitize_country( $country ) { |
38 | 38 | |
39 | - // Enure the country is specified |
|
39 | + // Enure the country is specified |
|
40 | 40 | if ( empty( $country ) ) { |
41 | 41 | $country = wpinv_get_default_country(); |
42 | 42 | } |
@@ -66,9 +66,9 @@ discard block |
||
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 | 74 | function wpinv_state_name( $state_code = '', $country_code = '' ) { |
@@ -299,11 +299,11 @@ discard block |
||
299 | 299 | |
300 | 300 | $country = wpinv_sanitize_country( $country ); |
301 | 301 | |
302 | - foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
303 | - if ( false !== array_search( $country, $countries, true ) ) { |
|
304 | - return $continent_code; |
|
305 | - } |
|
306 | - } |
|
302 | + foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
303 | + if ( false !== array_search( $country, $countries, true ) ) { |
|
304 | + return $continent_code; |
|
305 | + } |
|
306 | + } |
|
307 | 307 | |
308 | 308 | return ''; |
309 | 309 | |
@@ -595,31 +595,31 @@ discard block |
||
595 | 595 | } |
596 | 596 | |
597 | 597 | function wpinv_get_states_field() { |
598 | - if ( empty( $_POST['country'] ) ) { |
|
599 | - $_POST['country'] = wpinv_get_default_country(); |
|
600 | - } |
|
601 | - $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
598 | + if ( empty( $_POST['country'] ) ) { |
|
599 | + $_POST['country'] = wpinv_get_default_country(); |
|
600 | + } |
|
601 | + $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
602 | 602 | |
603 | - if ( ! empty( $states ) ) { |
|
604 | - $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
603 | + if ( ! empty( $states ) ) { |
|
604 | + $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
605 | 605 | |
606 | 606 | $class = isset( $_POST['class'] ) ? esc_attr( sanitize_text_field( $_POST['class'] ) ) : ''; |
607 | 607 | $class .= " $sanitized_field_name getpaid_js_field-state custom-select wpinv-select wpi_select2"; |
608 | 608 | |
609 | 609 | $args = array( |
610 | - 'name' => $sanitized_field_name, |
|
611 | - 'id' => $sanitized_field_name, |
|
612 | - 'class' => implode( ' ', array_unique( explode( ' ', $class ) ) ), |
|
613 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
614 | - 'show_option_all' => false, |
|
615 | - 'show_option_none' => false, |
|
616 | - ); |
|
617 | - |
|
618 | - wpinv_html_select( $args ); |
|
619 | - |
|
620 | - } else { |
|
621 | - echo 'nostates'; |
|
622 | - } |
|
610 | + 'name' => $sanitized_field_name, |
|
611 | + 'id' => $sanitized_field_name, |
|
612 | + 'class' => implode( ' ', array_unique( explode( ' ', $class ) ) ), |
|
613 | + 'options' => array_merge( array( '' => '' ), $states ), |
|
614 | + 'show_option_all' => false, |
|
615 | + 'show_option_none' => false, |
|
616 | + ); |
|
617 | + |
|
618 | + wpinv_html_select( $args ); |
|
619 | + |
|
620 | + } else { |
|
621 | + echo 'nostates'; |
|
622 | + } |
|
623 | 623 | |
624 | 624 | } |
625 | 625 | |
@@ -638,47 +638,47 @@ discard block |
||
638 | 638 | */ |
639 | 639 | function wpinv_get_address_formats() { |
640 | 640 | |
641 | - return apply_filters( |
|
641 | + return apply_filters( |
|
642 | 642 | 'wpinv_localisation_address_formats', |
643 | - array( |
|
644 | - 'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}", |
|
645 | - 'AU' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}", |
|
646 | - 'AT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
647 | - 'BE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
648 | - 'CA' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}} {{zip}}\n{{country}}", |
|
649 | - 'CH' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
650 | - 'CL' => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}", |
|
651 | - 'CN' => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}", |
|
652 | - 'CZ' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
653 | - 'DE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
654 | - 'EE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
655 | - 'FI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
656 | - 'DK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
657 | - 'FR' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}", |
|
658 | - 'HK' => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}", |
|
659 | - 'HU' => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}", |
|
660 | - 'IN' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}", |
|
661 | - 'IS' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
662 | - 'IT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}", |
|
663 | - 'JP' => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}", |
|
664 | - 'TW' => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}", |
|
665 | - 'LI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
666 | - 'NL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
667 | - 'NZ' => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}", |
|
668 | - 'NO' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
669 | - 'PL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
670 | - 'PT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
671 | - 'SK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
672 | - 'RS' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
673 | - 'SI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
674 | - 'ES' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}", |
|
675 | - 'SE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
676 | - 'TR' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}", |
|
677 | - 'UG' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}", |
|
678 | - 'US' => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}", |
|
679 | - 'VN' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}", |
|
680 | - ) |
|
681 | - ); |
|
643 | + array( |
|
644 | + 'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}", |
|
645 | + 'AU' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}", |
|
646 | + 'AT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
647 | + 'BE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
648 | + 'CA' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}} {{zip}}\n{{country}}", |
|
649 | + 'CH' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
650 | + 'CL' => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}", |
|
651 | + 'CN' => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}", |
|
652 | + 'CZ' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
653 | + 'DE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
654 | + 'EE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
655 | + 'FI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
656 | + 'DK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
657 | + 'FR' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}", |
|
658 | + 'HK' => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}", |
|
659 | + 'HU' => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}", |
|
660 | + 'IN' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}", |
|
661 | + 'IS' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
662 | + 'IT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}", |
|
663 | + 'JP' => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}", |
|
664 | + 'TW' => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}", |
|
665 | + 'LI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
666 | + 'NL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
667 | + 'NZ' => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}", |
|
668 | + 'NO' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
669 | + 'PL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
670 | + 'PT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
671 | + 'SK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
672 | + 'RS' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
673 | + 'SI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
674 | + 'ES' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}", |
|
675 | + 'SE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
676 | + 'TR' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}", |
|
677 | + 'UG' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}", |
|
678 | + 'US' => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}", |
|
679 | + 'VN' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}", |
|
680 | + ) |
|
681 | + ); |
|
682 | 682 | } |
683 | 683 | |
684 | 684 | /** |
@@ -695,21 +695,21 @@ discard block |
||
695 | 695 | } |
696 | 696 | |
697 | 697 | // Get all formats. |
698 | - $formats = wpinv_get_address_formats(); |
|
698 | + $formats = wpinv_get_address_formats(); |
|
699 | 699 | |
700 | - // Get format for the specified country. |
|
701 | - $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
700 | + // Get format for the specified country. |
|
701 | + $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
702 | 702 | |
703 | 703 | /** |
704 | - * Filters the address format to use on Invoices. |
|
704 | + * Filters the address format to use on Invoices. |
|
705 | 705 | * |
706 | 706 | * New lines will be replaced by a `br` element. Double new lines will be replaced by a paragraph. HTML tags are allowed. |
707 | - * |
|
708 | - * @since 1.0.13 |
|
709 | - * |
|
710 | - * @param string $format The address format to use. |
|
707 | + * |
|
708 | + * @since 1.0.13 |
|
709 | + * |
|
710 | + * @param string $format The address format to use. |
|
711 | 711 | * @param string $country The country who's address format is being retrieved. |
712 | - */ |
|
712 | + */ |
|
713 | 713 | return apply_filters( 'wpinv_get_full_address_format', $format, $country ); |
714 | 714 | } |
715 | 715 | |
@@ -730,8 +730,8 @@ discard block |
||
730 | 730 | 'country' => '', |
731 | 731 | 'zip' => '', |
732 | 732 | 'first_name' => '', |
733 | - 'last_name' => '', |
|
734 | - 'company' => '', |
|
733 | + 'last_name' => '', |
|
734 | + 'company' => '', |
|
735 | 735 | ); |
736 | 736 | |
737 | 737 | $args = map_deep( wp_parse_args( array_filter( $billing_details ), $default_args ), 'trim' ); |
@@ -752,14 +752,14 @@ discard block |
||
752 | 752 | $args['country_code'] = $country; |
753 | 753 | |
754 | 754 | /** |
755 | - * Filters the address format replacements to use on Invoices. |
|
755 | + * Filters the address format replacements to use on Invoices. |
|
756 | + * |
|
757 | + * |
|
758 | + * @since 1.0.13 |
|
756 | 759 | * |
757 | - * |
|
758 | - * @since 1.0.13 |
|
759 | - * |
|
760 | - * @param array $replacements The address replacements to use. |
|
760 | + * @param array $replacements The address replacements to use. |
|
761 | 761 | * @param array $billing_details The billing details to use. |
762 | - */ |
|
762 | + */ |
|
763 | 763 | $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details ); |
764 | 764 | |
765 | 765 | $return = array(); |
@@ -782,5 +782,5 @@ discard block |
||
782 | 782 | * @return string |
783 | 783 | */ |
784 | 784 | function wpinv_trim_formatted_address_line( $line ) { |
785 | - return trim( $line, ', ' ); |
|
785 | + return trim( $line, ', ' ); |
|
786 | 786 | } |
@@ -7,15 +7,15 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( ! defined( 'WPINC' ) ) { |
|
10 | +if (!defined('WPINC')) { |
|
11 | 11 | exit; |
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 | } |
@@ -128,22 +128,22 @@ discard block |
||
128 | 128 | $address_fields = apply_filters( |
129 | 129 | 'getpaid_user_address_fields', |
130 | 130 | array( |
131 | - 'first_name' => __( 'First Name', 'invoicing' ), |
|
132 | - 'last_name' => __( 'Last Name', 'invoicing' ), |
|
133 | - 'address' => __( 'Address', 'invoicing' ), |
|
134 | - 'city' => __( 'City', 'invoicing' ), |
|
135 | - 'country' => __( 'Country', 'invoicing' ), |
|
136 | - 'state' => __( 'State', 'invoicing' ), |
|
137 | - 'zip' => __( 'Zip/Postal Code', 'invoicing' ), |
|
138 | - 'phone' => __( 'Phone Number', 'invoicing' ), |
|
139 | - 'company' => __( 'Company', 'invoicing' ), |
|
140 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
141 | - 'vat_number' => __( 'VAT Number', 'invoicing' ), |
|
131 | + 'first_name' => __('First Name', 'invoicing'), |
|
132 | + 'last_name' => __('Last Name', 'invoicing'), |
|
133 | + 'address' => __('Address', 'invoicing'), |
|
134 | + 'city' => __('City', 'invoicing'), |
|
135 | + 'country' => __('Country', 'invoicing'), |
|
136 | + 'state' => __('State', 'invoicing'), |
|
137 | + 'zip' => __('Zip/Postal Code', 'invoicing'), |
|
138 | + 'phone' => __('Phone Number', 'invoicing'), |
|
139 | + 'company' => __('Company', 'invoicing'), |
|
140 | + 'company_id' => __('Company ID', 'invoicing'), |
|
141 | + 'vat_number' => __('VAT Number', 'invoicing'), |
|
142 | 142 | ) |
143 | 143 | ); |
144 | 144 | |
145 | - if ( ! wpinv_use_taxes() && isset( $address_fields['vat_number'] ) && ! wp_doing_ajax() ) { |
|
146 | - unset( $address_fields['vat_number'] ); |
|
145 | + if (!wpinv_use_taxes() && isset($address_fields['vat_number']) && !wp_doing_ajax()) { |
|
146 | + unset($address_fields['vat_number']); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | return $address_fields; |
@@ -154,8 +154,8 @@ discard block |
||
154 | 154 | * |
155 | 155 | * @return bool |
156 | 156 | */ |
157 | -function getpaid_is_address_field_whitelisted( $key ) { |
|
158 | - return array_key_exists( $key, getpaid_user_address_fields() ); |
|
157 | +function getpaid_is_address_field_whitelisted($key) { |
|
158 | + return array_key_exists($key, getpaid_user_address_fields()); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -165,30 +165,30 @@ discard block |
||
165 | 165 | * |
166 | 166 | * @param WPInv_Invoice $invoice |
167 | 167 | */ |
168 | -function getpaid_save_invoice_user_address( $invoice ) { |
|
168 | +function getpaid_save_invoice_user_address($invoice) { |
|
169 | 169 | |
170 | 170 | // Retrieve the invoice. |
171 | - $invoice = wpinv_get_invoice( $invoice ); |
|
171 | + $invoice = wpinv_get_invoice($invoice); |
|
172 | 172 | |
173 | 173 | // Abort if it does not exist. |
174 | - if ( empty( $invoice ) || $invoice->is_renewal() ) { |
|
174 | + if (empty($invoice) || $invoice->is_renewal()) { |
|
175 | 175 | return; |
176 | 176 | } |
177 | 177 | |
178 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
178 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
179 | 179 | |
180 | - if ( is_callable( array( $invoice, "get_$field" ) ) ) { |
|
181 | - $value = call_user_func( array( $invoice, "get_$field" ) ); |
|
180 | + if (is_callable(array($invoice, "get_$field"))) { |
|
181 | + $value = call_user_func(array($invoice, "get_$field")); |
|
182 | 182 | |
183 | 183 | // Only save if it is not empty. |
184 | - if ( ! empty( $value ) ) { |
|
185 | - update_user_meta( $invoice->get_user_id(), '_wpinv_' . $field, $value ); |
|
184 | + if (!empty($value)) { |
|
185 | + update_user_meta($invoice->get_user_id(), '_wpinv_' . $field, $value); |
|
186 | 186 | } |
187 | 187 | } |
188 | 188 | } |
189 | 189 | |
190 | 190 | } |
191 | -add_action( 'getpaid_checkout_invoice_updated', 'getpaid_save_invoice_user_address' ); |
|
191 | +add_action('getpaid_checkout_invoice_updated', 'getpaid_save_invoice_user_address'); |
|
192 | 192 | |
193 | 193 | /** |
194 | 194 | * Retrieves a saved user address. |
@@ -196,14 +196,14 @@ discard block |
||
196 | 196 | * @param int $user_id The user id whose address we should get. Defaults to the current user id. |
197 | 197 | * @return array |
198 | 198 | */ |
199 | -function wpinv_get_user_address( $user_id = 0 ) { |
|
199 | +function wpinv_get_user_address($user_id = 0) { |
|
200 | 200 | |
201 | 201 | // Prepare the user id. |
202 | - $user_id = empty( $user_id ) ? get_current_user_id() : $user_id; |
|
203 | - $user_info = get_userdata( $user_id ); |
|
202 | + $user_id = empty($user_id) ? get_current_user_id() : $user_id; |
|
203 | + $user_info = get_userdata($user_id); |
|
204 | 204 | |
205 | 205 | // Abort if non exists. |
206 | - if ( empty( $user_info ) ) { |
|
206 | + if (empty($user_info)) { |
|
207 | 207 | return array(); |
208 | 208 | } |
209 | 209 | |
@@ -214,11 +214,11 @@ discard block |
||
214 | 214 | 'display_name' => $user_info->display_name, |
215 | 215 | ); |
216 | 216 | |
217 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
218 | - $address[ $field ] = getpaid_get_user_address_field( $user_id, $field ); |
|
217 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
218 | + $address[$field] = getpaid_get_user_address_field($user_id, $field); |
|
219 | 219 | } |
220 | 220 | |
221 | - $address = array_filter( $address ); |
|
221 | + $address = array_filter($address); |
|
222 | 222 | |
223 | 223 | $defaults = array( |
224 | 224 | 'first_name' => $user_info->first_name, |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | 'country' => wpinv_get_default_country(), |
228 | 228 | ); |
229 | 229 | |
230 | - return getpaid_array_merge_if_empty( $address, $defaults ); |
|
230 | + return getpaid_array_merge_if_empty($address, $defaults); |
|
231 | 231 | |
232 | 232 | } |
233 | 233 | |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | * @param string $field The field to use. |
239 | 239 | * @return string|null |
240 | 240 | */ |
241 | -function getpaid_get_user_address_field( $user_id, $field ) { |
|
241 | +function getpaid_get_user_address_field($user_id, $field) { |
|
242 | 242 | |
243 | 243 | $prefixes = array( |
244 | 244 | '_wpinv_', |
@@ -246,15 +246,15 @@ discard block |
||
246 | 246 | '', |
247 | 247 | ); |
248 | 248 | |
249 | - foreach ( $prefixes as $prefix ) { |
|
249 | + foreach ($prefixes as $prefix) { |
|
250 | 250 | |
251 | 251 | // Meta table. |
252 | - $value = get_user_meta( $user_id, $prefix . $field, true ); |
|
252 | + $value = get_user_meta($user_id, $prefix . $field, true); |
|
253 | 253 | |
254 | 254 | // UWP table. |
255 | - $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value; |
|
255 | + $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value; |
|
256 | 256 | |
257 | - if ( ! empty( $value ) ) { |
|
257 | + if (!empty($value)) { |
|
258 | 258 | return $value; |
259 | 259 | } |
260 | 260 | } |
@@ -270,16 +270,16 @@ discard block |
||
270 | 270 | * @param string $return What to return. |
271 | 271 | * @return array |
272 | 272 | */ |
273 | -function wpinv_get_continents( $return = 'all' ) { |
|
273 | +function wpinv_get_continents($return = 'all') { |
|
274 | 274 | |
275 | - $continents = wpinv_get_data( 'continents' ); |
|
275 | + $continents = wpinv_get_data('continents'); |
|
276 | 276 | |
277 | - switch ( $return ) { |
|
277 | + switch ($return) { |
|
278 | 278 | case 'name': |
279 | - return wp_list_pluck( $continents, 'name' ); |
|
279 | + return wp_list_pluck($continents, 'name'); |
|
280 | 280 | break; |
281 | 281 | case 'countries': |
282 | - return wp_list_pluck( $continents, 'countries' ); |
|
282 | + return wp_list_pluck($continents, 'countries'); |
|
283 | 283 | break; |
284 | 284 | default: |
285 | 285 | return $continents; |
@@ -295,12 +295,12 @@ discard block |
||
295 | 295 | * @param string $country Country code. If no code is specified, defaults to the default country. |
296 | 296 | * @return string |
297 | 297 | */ |
298 | -function wpinv_get_continent_code_for_country( $country = false ) { |
|
298 | +function wpinv_get_continent_code_for_country($country = false) { |
|
299 | 299 | |
300 | - $country = wpinv_sanitize_country( $country ); |
|
300 | + $country = wpinv_sanitize_country($country); |
|
301 | 301 | |
302 | - foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
303 | - if ( false !== array_search( $country, $countries, true ) ) { |
|
302 | + foreach (wpinv_get_continents('countries') as $continent_code => $countries) { |
|
303 | + if (false !== array_search($country, $countries, true)) { |
|
304 | 304 | return $continent_code; |
305 | 305 | } |
306 | 306 | } |
@@ -316,13 +316,13 @@ discard block |
||
316 | 316 | * @param string $country Country code. If no code is specified, defaults to the default country. |
317 | 317 | * @return array |
318 | 318 | */ |
319 | -function wpinv_get_country_calling_code( $country = null ) { |
|
319 | +function wpinv_get_country_calling_code($country = null) { |
|
320 | 320 | |
321 | - $country = wpinv_sanitize_country( $country ); |
|
322 | - $codes = wpinv_get_data( 'phone-codes' ); |
|
323 | - $code = isset( $codes[ $country ] ) ? $codes[ $country ] : ''; |
|
321 | + $country = wpinv_sanitize_country($country); |
|
322 | + $codes = wpinv_get_data('phone-codes'); |
|
323 | + $code = isset($codes[$country]) ? $codes[$country] : ''; |
|
324 | 324 | |
325 | - if ( is_array( $code ) ) { |
|
325 | + if (is_array($code)) { |
|
326 | 326 | return $code[0]; |
327 | 327 | } |
328 | 328 | return $code; |
@@ -335,8 +335,8 @@ discard block |
||
335 | 335 | * @param bool $first_empty Whether or not the first item in the list should be empty |
336 | 336 | * @return array |
337 | 337 | */ |
338 | -function wpinv_get_country_list( $first_empty = false ) { |
|
339 | - return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty ); |
|
338 | +function wpinv_get_country_list($first_empty = false) { |
|
339 | + return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | /** |
@@ -346,22 +346,22 @@ discard block |
||
346 | 346 | * @param bool $first_empty Whether or not the first item in the list should be empty |
347 | 347 | * @return array |
348 | 348 | */ |
349 | -function wpinv_get_country_states( $country = null, $first_empty = false ) { |
|
349 | +function wpinv_get_country_states($country = null, $first_empty = false) { |
|
350 | 350 | |
351 | 351 | // Prepare the country. |
352 | - $country = wpinv_sanitize_country( $country ); |
|
352 | + $country = wpinv_sanitize_country($country); |
|
353 | 353 | |
354 | 354 | // Fetch all states. |
355 | - $all_states = wpinv_get_data( 'states' ); |
|
355 | + $all_states = wpinv_get_data('states'); |
|
356 | 356 | |
357 | 357 | // Fetch the specified country's states. |
358 | - $states = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array(); |
|
359 | - $states = apply_filters( "wpinv_{$country}_states", $states ); |
|
360 | - $states = apply_filters( 'wpinv_country_states', $states, $country ); |
|
358 | + $states = isset($all_states[$country]) ? $all_states[$country] : array(); |
|
359 | + $states = apply_filters("wpinv_{$country}_states", $states); |
|
360 | + $states = apply_filters('wpinv_country_states', $states, $country); |
|
361 | 361 | |
362 | - asort( $states ); |
|
362 | + asort($states); |
|
363 | 363 | |
364 | - return wpinv_maybe_add_empty_option( $states, $first_empty ); |
|
364 | + return wpinv_maybe_add_empty_option($states, $first_empty); |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | /** |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | * @return array |
372 | 372 | */ |
373 | 373 | function wpinv_get_us_states_list() { |
374 | - return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) ); |
|
374 | + return apply_filters('wpinv_usa_states', wpinv_get_country_states('US')); |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | /** |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | * @return array |
382 | 382 | */ |
383 | 383 | function wpinv_get_canada_states_list() { |
384 | - return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) ); |
|
384 | + return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA')); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | /** |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | * @return array |
392 | 392 | */ |
393 | 393 | function wpinv_get_australia_states_list() { |
394 | - return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) ); |
|
394 | + return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU')); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | /** |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | * @return array |
402 | 402 | */ |
403 | 403 | function wpinv_get_bangladesh_states_list() { |
404 | - return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) ); |
|
404 | + return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD')); |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | /** |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | * @return array |
412 | 412 | */ |
413 | 413 | function wpinv_get_brazil_states_list() { |
414 | - return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) ); |
|
414 | + return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR')); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | /** |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | * @return array |
422 | 422 | */ |
423 | 423 | function wpinv_get_bulgaria_states_list() { |
424 | - return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) ); |
|
424 | + return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG')); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | * @return array |
432 | 432 | */ |
433 | 433 | function wpinv_get_hong_kong_states_list() { |
434 | - return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) ); |
|
434 | + return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK')); |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | /** |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | * @return array |
442 | 442 | */ |
443 | 443 | function wpinv_get_hungary_states_list() { |
444 | - return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) ); |
|
444 | + return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU')); |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | /** |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | * @return array |
452 | 452 | */ |
453 | 453 | function wpinv_get_japan_states_list() { |
454 | - return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) ); |
|
454 | + return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP')); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | /** |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | * @return array |
462 | 462 | */ |
463 | 463 | function wpinv_get_china_states_list() { |
464 | - return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) ); |
|
464 | + return apply_filters('wpinv_china_states', wpinv_get_country_states('CN')); |
|
465 | 465 | } |
466 | 466 | |
467 | 467 | /** |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | * @return array |
472 | 472 | */ |
473 | 473 | function wpinv_get_new_zealand_states_list() { |
474 | - return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) ); |
|
474 | + return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ')); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | * @return array |
482 | 482 | */ |
483 | 483 | function wpinv_get_peru_states_list() { |
484 | - return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) ); |
|
484 | + return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE')); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | * @return array |
492 | 492 | */ |
493 | 493 | function wpinv_get_indonesia_states_list() { |
494 | - return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) ); |
|
494 | + return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID')); |
|
495 | 495 | } |
496 | 496 | |
497 | 497 | /** |
@@ -501,7 +501,7 @@ discard block |
||
501 | 501 | * @return array |
502 | 502 | */ |
503 | 503 | function wpinv_get_india_states_list() { |
504 | - return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) ); |
|
504 | + return apply_filters('wpinv_india_states', wpinv_get_country_states('IN')); |
|
505 | 505 | } |
506 | 506 | |
507 | 507 | /** |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | * @return array |
512 | 512 | */ |
513 | 513 | function wpinv_get_iran_states_list() { |
514 | - return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) ); |
|
514 | + return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR')); |
|
515 | 515 | } |
516 | 516 | |
517 | 517 | /** |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | * @return array |
522 | 522 | */ |
523 | 523 | function wpinv_get_italy_states_list() { |
524 | - return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) ); |
|
524 | + return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT')); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | /** |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | * @return array |
532 | 532 | */ |
533 | 533 | function wpinv_get_malaysia_states_list() { |
534 | - return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) ); |
|
534 | + return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY')); |
|
535 | 535 | } |
536 | 536 | |
537 | 537 | /** |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | * @return array |
542 | 542 | */ |
543 | 543 | function wpinv_get_mexico_states_list() { |
544 | - return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) ); |
|
544 | + return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX')); |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
@@ -551,7 +551,7 @@ discard block |
||
551 | 551 | * @return array |
552 | 552 | */ |
553 | 553 | function wpinv_get_nepal_states_list() { |
554 | - return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) ); |
|
554 | + return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP')); |
|
555 | 555 | } |
556 | 556 | |
557 | 557 | /** |
@@ -561,7 +561,7 @@ discard block |
||
561 | 561 | * @return array |
562 | 562 | */ |
563 | 563 | function wpinv_get_south_africa_states_list() { |
564 | - return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) ); |
|
564 | + return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA')); |
|
565 | 565 | } |
566 | 566 | |
567 | 567 | /** |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | * @return array |
572 | 572 | */ |
573 | 573 | function wpinv_get_thailand_states_list() { |
574 | - return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) ); |
|
574 | + return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH')); |
|
575 | 575 | } |
576 | 576 | |
577 | 577 | /** |
@@ -581,7 +581,7 @@ discard block |
||
581 | 581 | * @return array |
582 | 582 | */ |
583 | 583 | function wpinv_get_turkey_states_list() { |
584 | - return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) ); |
|
584 | + return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR')); |
|
585 | 585 | } |
586 | 586 | |
587 | 587 | /** |
@@ -591,31 +591,31 @@ discard block |
||
591 | 591 | * @return array |
592 | 592 | */ |
593 | 593 | function wpinv_get_spain_states_list() { |
594 | - return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) ); |
|
594 | + return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES')); |
|
595 | 595 | } |
596 | 596 | |
597 | 597 | function wpinv_get_states_field() { |
598 | - if ( empty( $_POST['country'] ) ) { |
|
598 | + if (empty($_POST['country'])) { |
|
599 | 599 | $_POST['country'] = wpinv_get_default_country(); |
600 | 600 | } |
601 | - $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
601 | + $states = wpinv_get_country_states(sanitize_text_field($_POST['country'])); |
|
602 | 602 | |
603 | - if ( ! empty( $states ) ) { |
|
604 | - $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
603 | + if (!empty($states)) { |
|
604 | + $sanitized_field_name = sanitize_text_field($_POST['field_name']); |
|
605 | 605 | |
606 | - $class = isset( $_POST['class'] ) ? esc_attr( sanitize_text_field( $_POST['class'] ) ) : ''; |
|
606 | + $class = isset($_POST['class']) ? esc_attr(sanitize_text_field($_POST['class'])) : ''; |
|
607 | 607 | $class .= " $sanitized_field_name getpaid_js_field-state custom-select wpinv-select wpi_select2"; |
608 | 608 | |
609 | - $args = array( |
|
609 | + $args = array( |
|
610 | 610 | 'name' => $sanitized_field_name, |
611 | 611 | 'id' => $sanitized_field_name, |
612 | - 'class' => implode( ' ', array_unique( explode( ' ', $class ) ) ), |
|
613 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
612 | + 'class' => implode(' ', array_unique(explode(' ', $class))), |
|
613 | + 'options' => array_merge(array('' => ''), $states), |
|
614 | 614 | 'show_option_all' => false, |
615 | 615 | 'show_option_none' => false, |
616 | 616 | ); |
617 | 617 | |
618 | - wpinv_html_select( $args ); |
|
618 | + wpinv_html_select($args); |
|
619 | 619 | |
620 | 620 | } else { |
621 | 621 | echo 'nostates'; |
@@ -623,10 +623,10 @@ discard block |
||
623 | 623 | |
624 | 624 | } |
625 | 625 | |
626 | -function wpinv_default_billing_country( $country = '', $user_id = 0 ) { |
|
627 | - $country = ! empty( $country ) ? $country : wpinv_get_default_country(); |
|
626 | +function wpinv_default_billing_country($country = '', $user_id = 0) { |
|
627 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
628 | 628 | |
629 | - return apply_filters( 'wpinv_default_billing_country', $country, $user_id ); |
|
629 | + return apply_filters('wpinv_default_billing_country', $country, $user_id); |
|
630 | 630 | } |
631 | 631 | |
632 | 632 | /** |
@@ -688,9 +688,9 @@ discard block |
||
688 | 688 | * @see `wpinv_get_invoice_address_replacements` |
689 | 689 | * @return string |
690 | 690 | */ |
691 | -function wpinv_get_full_address_format( $country = false ) { |
|
691 | +function wpinv_get_full_address_format($country = false) { |
|
692 | 692 | |
693 | - if ( empty( $country ) ) { |
|
693 | + if (empty($country)) { |
|
694 | 694 | $country = wpinv_get_default_country(); |
695 | 695 | } |
696 | 696 | |
@@ -698,7 +698,7 @@ discard block |
||
698 | 698 | $formats = wpinv_get_address_formats(); |
699 | 699 | |
700 | 700 | // Get format for the specified country. |
701 | - $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
701 | + $format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default']; |
|
702 | 702 | |
703 | 703 | /** |
704 | 704 | * Filters the address format to use on Invoices. |
@@ -710,7 +710,7 @@ discard block |
||
710 | 710 | * @param string $format The address format to use. |
711 | 711 | * @param string $country The country who's address format is being retrieved. |
712 | 712 | */ |
713 | - return apply_filters( 'wpinv_get_full_address_format', $format, $country ); |
|
713 | + return apply_filters('wpinv_get_full_address_format', $format, $country); |
|
714 | 714 | } |
715 | 715 | |
716 | 716 | /** |
@@ -721,7 +721,7 @@ discard block |
||
721 | 721 | * @param array $billing_details customer's billing details |
722 | 722 | * @return array |
723 | 723 | */ |
724 | -function wpinv_get_invoice_address_replacements( $billing_details ) { |
|
724 | +function wpinv_get_invoice_address_replacements($billing_details) { |
|
725 | 725 | |
726 | 726 | $default_args = array( |
727 | 727 | 'address' => '', |
@@ -734,15 +734,15 @@ discard block |
||
734 | 734 | 'company' => '', |
735 | 735 | ); |
736 | 736 | |
737 | - $args = map_deep( wp_parse_args( array_filter( $billing_details ), $default_args ), 'trim' ); |
|
737 | + $args = map_deep(wp_parse_args(array_filter($billing_details), $default_args), 'trim'); |
|
738 | 738 | $state = $args['state']; |
739 | 739 | $country = $args['country']; |
740 | 740 | |
741 | 741 | // Handle full country name. |
742 | - $full_country = empty( $country ) ? $country : wpinv_country_name( $country ); |
|
742 | + $full_country = empty($country) ? $country : wpinv_country_name($country); |
|
743 | 743 | |
744 | 744 | // Handle full state name. |
745 | - $full_state = ( $country && $state ) ? wpinv_state_name( $state, $country ) : $state; |
|
745 | + $full_state = ($country && $state) ? wpinv_state_name($state, $country) : $state; |
|
746 | 746 | |
747 | 747 | $args['postcode'] = $args['zip']; |
748 | 748 | $args['name'] = $args['first_name'] . ' ' . $args['last_name']; |
@@ -760,14 +760,14 @@ discard block |
||
760 | 760 | * @param array $replacements The address replacements to use. |
761 | 761 | * @param array $billing_details The billing details to use. |
762 | 762 | */ |
763 | - $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details ); |
|
763 | + $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details); |
|
764 | 764 | |
765 | 765 | $return = array(); |
766 | 766 | |
767 | - foreach ( $replacements as $key => $value ) { |
|
768 | - $value = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : ''; |
|
769 | - $return[ '{{' . $key . '}}' ] = $value; |
|
770 | - $return[ '{{' . $key . '_upper}}' ] = wpinv_utf8_strtoupper( $value ); |
|
767 | + foreach ($replacements as $key => $value) { |
|
768 | + $value = is_scalar($value) ? trim(sanitize_text_field($value)) : ''; |
|
769 | + $return['{{' . $key . '}}'] = $value; |
|
770 | + $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value); |
|
771 | 771 | } |
772 | 772 | |
773 | 773 | return $return; |
@@ -781,6 +781,6 @@ discard block |
||
781 | 781 | * @since 1.0.14 |
782 | 782 | * @return string |
783 | 783 | */ |
784 | -function wpinv_trim_formatted_address_line( $line ) { |
|
785 | - return trim( $line, ', ' ); |
|
784 | +function wpinv_trim_formatted_address_line($line) { |
|
785 | + return trim($line, ', '); |
|
786 | 786 | } |
@@ -12,493 +12,493 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Invoice_Notification_Emails { |
14 | 14 | |
15 | - /** |
|
16 | - * The array of invoice email actions. |
|
17 | - * |
|
18 | - * @param array |
|
19 | - */ |
|
20 | - public $invoice_actions; |
|
21 | - |
|
22 | - /** |
|
23 | - * Class constructor |
|
24 | - * |
|
25 | - */ |
|
26 | - public function __construct() { |
|
27 | - |
|
28 | - $this->invoice_actions = apply_filters( |
|
29 | - 'getpaid_notification_email_invoice_triggers', |
|
30 | - array( |
|
31 | - 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
32 | - 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
33 | - 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
34 | - 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
35 | - 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
36 | - 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
37 | - 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
38 | - 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
39 | - 'getpaid_new_customer_note' => 'user_note', |
|
40 | - 'getpaid_daily_maintenance' => 'overdue', |
|
41 | - ) |
|
42 | - ); |
|
43 | - |
|
44 | - $this->init_hooks(); |
|
45 | - |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Registers email hooks. |
|
50 | - */ |
|
51 | - public function init_hooks() { |
|
52 | - |
|
53 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | - add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
55 | - |
|
56 | - foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | - $this->init_email_type_hook( $hook, $email_type ); |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Registers an email hook for an invoice action. |
|
63 | - * |
|
64 | - * @param string $hook |
|
65 | - * @param string|array $email_type |
|
66 | - */ |
|
67 | - public function init_email_type_hook( $hook, $email_type ) { |
|
68 | - |
|
69 | - $email_type = wpinv_parse_list( $email_type ); |
|
70 | - |
|
71 | - foreach ( $email_type as $type ) { |
|
72 | - |
|
73 | - $email = new GetPaid_Notification_Email( $type ); |
|
74 | - |
|
75 | - // Abort if it is not active. |
|
76 | - if ( ! $email->is_active() ) { |
|
77 | - continue; |
|
78 | - } |
|
79 | - |
|
80 | - if ( method_exists( $this, $type ) ) { |
|
81 | - add_action( $hook, array( $this, $type ), 100, 2 ); |
|
82 | - continue; |
|
83 | - } |
|
84 | - |
|
85 | - do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
86 | - } |
|
87 | - |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Filters invoice merge tags. |
|
92 | - * |
|
93 | - * @param array $merge_tags |
|
94 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
95 | - */ |
|
96 | - public function invoice_merge_tags( $merge_tags, $object ) { |
|
97 | - |
|
98 | - if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
99 | - return array_merge( |
|
100 | - $merge_tags, |
|
101 | - $this->get_invoice_merge_tags( $object ) |
|
102 | - ); |
|
103 | - } |
|
104 | - |
|
105 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
106 | - return array_merge( |
|
107 | - $merge_tags, |
|
108 | - $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
109 | - ); |
|
110 | - } |
|
111 | - |
|
112 | - return $merge_tags; |
|
113 | - |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Generates invoice merge tags. |
|
118 | - * |
|
119 | - * @param WPInv_Invoice $invoice |
|
120 | - * @return array |
|
121 | - */ |
|
122 | - public function get_invoice_merge_tags( $invoice ) { |
|
123 | - |
|
124 | - // Abort if it does not exist. |
|
125 | - if ( ! $invoice->get_id() ) { |
|
126 | - return array(); |
|
127 | - } |
|
128 | - |
|
129 | - $due_date = $invoice->get_due_date(); |
|
130 | - $due_date = empty( $due_date ) ? time() + MINUTE_IN_SECONDS : strtotime( $due_date ) + ( (int) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
|
131 | - $merge_tags = array( |
|
132 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
133 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
134 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
135 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
136 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
137 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
138 | - '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
139 | - '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
140 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
141 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
142 | - '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ), |
|
143 | - '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
144 | - '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
145 | - '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
146 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
147 | - '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
148 | - '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
149 | - '{is_was}' => $due_date < time() ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
150 | - ); |
|
151 | - |
|
152 | - $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
153 | - |
|
154 | - if ( is_array( $payment_form_data ) ) { |
|
155 | - |
|
156 | - foreach ( $payment_form_data as $label => $value ) { |
|
157 | - |
|
158 | - $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
159 | - $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
160 | - |
|
161 | - if ( is_scalar( $value ) ) { |
|
162 | - $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
163 | - } |
|
164 | - } |
|
165 | - } |
|
166 | - |
|
167 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Helper function to send an email. |
|
172 | - * |
|
173 | - * @param WPInv_Invoice $invoice |
|
174 | - * @param GetPaid_Notification_Email $email |
|
175 | - * @param string $type |
|
176 | - * @param string|array $recipients |
|
177 | - * @param array $extra_args Extra template args. |
|
178 | - */ |
|
179 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
180 | - |
|
181 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
182 | - |
|
183 | - $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
184 | - if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
185 | - return; |
|
186 | - } |
|
187 | - |
|
188 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
189 | - $merge_tags = $email->get_merge_tags(); |
|
190 | - |
|
191 | - $result = $mailer->send( |
|
192 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
193 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
194 | - $email->get_content( $merge_tags, $extra_args ), |
|
195 | - $email->get_attachments() |
|
196 | - ); |
|
197 | - |
|
198 | - // Maybe send a copy to the admin. |
|
199 | - if ( $email->include_admin_bcc() ) { |
|
200 | - $mailer->send( |
|
201 | - wpinv_get_admin_email(), |
|
202 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
203 | - $email->get_content( $merge_tags ), |
|
204 | - $email->get_attachments() |
|
205 | - ); |
|
206 | - } |
|
207 | - |
|
208 | - if ( $result ) { |
|
209 | - $invoice->add_system_note( |
|
210 | - sprintf( |
|
211 | - // translators: %1 is the email type, %2 is the invoice recipient. |
|
212 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
213 | - sanitize_key( $type ), |
|
214 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
215 | - ) |
|
216 | - ); |
|
217 | - } else { |
|
218 | - $invoice->add_system_note( |
|
219 | - sprintf( |
|
220 | - // translators: %1 is the email type, %2 is the invoice recipient. |
|
221 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
222 | - sanitize_key( $type ), |
|
223 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
224 | - ) |
|
225 | - ); |
|
226 | - } |
|
227 | - |
|
228 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
229 | - |
|
230 | - return $result; |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * Also send emails to any cc users. |
|
235 | - * |
|
236 | - * @param array $recipients |
|
237 | - * @param GetPaid_Notification_Email $email |
|
238 | - */ |
|
239 | - public function filter_email_recipients( $recipients, $email ) { |
|
240 | - |
|
241 | - if ( ! $email->is_admin_email() ) { |
|
242 | - $cc = $email->object->get_email_cc(); |
|
243 | - $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
244 | - |
|
245 | - if ( ! empty( $cc ) ) { |
|
246 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
247 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
248 | - } |
|
249 | - |
|
250 | - if ( ! empty( $cc_2 ) ) { |
|
251 | - $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
252 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
253 | - } |
|
254 | - } |
|
255 | - |
|
256 | - return $recipients; |
|
257 | - |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Sends a new invoice notification. |
|
262 | - * |
|
263 | - * @param WPInv_Invoice $invoice |
|
264 | - */ |
|
265 | - public function new_invoice( $invoice ) { |
|
266 | - |
|
267 | - // Only send this email for invoices created via the admin page. |
|
268 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
269 | - return; |
|
270 | - } |
|
271 | - |
|
272 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
273 | - $recipient = wpinv_get_admin_email(); |
|
274 | - |
|
275 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
276 | - |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Sends a cancelled invoice notification. |
|
281 | - * |
|
282 | - * @param WPInv_Invoice $invoice |
|
283 | - */ |
|
284 | - public function cancelled_invoice( $invoice ) { |
|
285 | - |
|
286 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
287 | - $recipient = $invoice->get_email(); |
|
288 | - |
|
289 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Sends a failed invoice notification. |
|
294 | - * |
|
295 | - * @param WPInv_Invoice $invoice |
|
296 | - */ |
|
297 | - public function failed_invoice( $invoice ) { |
|
298 | - |
|
299 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
300 | - $recipient = wpinv_get_admin_email(); |
|
301 | - |
|
302 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
303 | - |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Sends a notification whenever an invoice is put on hold. |
|
308 | - * |
|
309 | - * @param WPInv_Invoice $invoice |
|
310 | - */ |
|
311 | - public function onhold_invoice( $invoice ) { |
|
312 | - |
|
313 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
314 | - $recipient = $invoice->get_email(); |
|
315 | - |
|
316 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
317 | - |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * Sends a notification whenever an invoice is marked as processing payment. |
|
322 | - * |
|
323 | - * @param WPInv_Invoice $invoice |
|
324 | - */ |
|
325 | - public function processing_invoice( $invoice ) { |
|
326 | - |
|
327 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
328 | - $recipient = $invoice->get_email(); |
|
329 | - |
|
330 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
331 | - |
|
332 | - } |
|
333 | - |
|
334 | - /** |
|
335 | - * Sends a notification whenever an invoice is paid. |
|
336 | - * |
|
337 | - * @param WPInv_Invoice $invoice |
|
338 | - */ |
|
339 | - public function completed_invoice( $invoice ) { |
|
340 | - |
|
341 | - // (Maybe) abort if it is a renewal invoice. |
|
342 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
343 | - return; |
|
344 | - } |
|
345 | - |
|
346 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
347 | - $recipient = $invoice->get_email(); |
|
348 | - |
|
349 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
350 | - |
|
351 | - } |
|
15 | + /** |
|
16 | + * The array of invoice email actions. |
|
17 | + * |
|
18 | + * @param array |
|
19 | + */ |
|
20 | + public $invoice_actions; |
|
21 | + |
|
22 | + /** |
|
23 | + * Class constructor |
|
24 | + * |
|
25 | + */ |
|
26 | + public function __construct() { |
|
27 | + |
|
28 | + $this->invoice_actions = apply_filters( |
|
29 | + 'getpaid_notification_email_invoice_triggers', |
|
30 | + array( |
|
31 | + 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
32 | + 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
33 | + 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
34 | + 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
35 | + 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
36 | + 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
37 | + 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
38 | + 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
39 | + 'getpaid_new_customer_note' => 'user_note', |
|
40 | + 'getpaid_daily_maintenance' => 'overdue', |
|
41 | + ) |
|
42 | + ); |
|
43 | + |
|
44 | + $this->init_hooks(); |
|
45 | + |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Registers email hooks. |
|
50 | + */ |
|
51 | + public function init_hooks() { |
|
52 | + |
|
53 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | + add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
55 | + |
|
56 | + foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | + $this->init_email_type_hook( $hook, $email_type ); |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Registers an email hook for an invoice action. |
|
63 | + * |
|
64 | + * @param string $hook |
|
65 | + * @param string|array $email_type |
|
66 | + */ |
|
67 | + public function init_email_type_hook( $hook, $email_type ) { |
|
68 | + |
|
69 | + $email_type = wpinv_parse_list( $email_type ); |
|
70 | + |
|
71 | + foreach ( $email_type as $type ) { |
|
72 | + |
|
73 | + $email = new GetPaid_Notification_Email( $type ); |
|
74 | + |
|
75 | + // Abort if it is not active. |
|
76 | + if ( ! $email->is_active() ) { |
|
77 | + continue; |
|
78 | + } |
|
79 | + |
|
80 | + if ( method_exists( $this, $type ) ) { |
|
81 | + add_action( $hook, array( $this, $type ), 100, 2 ); |
|
82 | + continue; |
|
83 | + } |
|
84 | + |
|
85 | + do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
86 | + } |
|
87 | + |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Filters invoice merge tags. |
|
92 | + * |
|
93 | + * @param array $merge_tags |
|
94 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
95 | + */ |
|
96 | + public function invoice_merge_tags( $merge_tags, $object ) { |
|
97 | + |
|
98 | + if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
99 | + return array_merge( |
|
100 | + $merge_tags, |
|
101 | + $this->get_invoice_merge_tags( $object ) |
|
102 | + ); |
|
103 | + } |
|
104 | + |
|
105 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
106 | + return array_merge( |
|
107 | + $merge_tags, |
|
108 | + $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
109 | + ); |
|
110 | + } |
|
111 | + |
|
112 | + return $merge_tags; |
|
113 | + |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Generates invoice merge tags. |
|
118 | + * |
|
119 | + * @param WPInv_Invoice $invoice |
|
120 | + * @return array |
|
121 | + */ |
|
122 | + public function get_invoice_merge_tags( $invoice ) { |
|
123 | + |
|
124 | + // Abort if it does not exist. |
|
125 | + if ( ! $invoice->get_id() ) { |
|
126 | + return array(); |
|
127 | + } |
|
128 | + |
|
129 | + $due_date = $invoice->get_due_date(); |
|
130 | + $due_date = empty( $due_date ) ? time() + MINUTE_IN_SECONDS : strtotime( $due_date ) + ( (int) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
|
131 | + $merge_tags = array( |
|
132 | + '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
133 | + '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
134 | + '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
135 | + '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
136 | + '{email}' => sanitize_email( $invoice->get_email() ), |
|
137 | + '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
138 | + '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
139 | + '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
140 | + '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
141 | + '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
142 | + '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ), |
|
143 | + '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
144 | + '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
145 | + '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
146 | + '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
147 | + '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
148 | + '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
149 | + '{is_was}' => $due_date < time() ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
150 | + ); |
|
151 | + |
|
152 | + $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
153 | + |
|
154 | + if ( is_array( $payment_form_data ) ) { |
|
155 | + |
|
156 | + foreach ( $payment_form_data as $label => $value ) { |
|
157 | + |
|
158 | + $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
159 | + $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
160 | + |
|
161 | + if ( is_scalar( $value ) ) { |
|
162 | + $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
163 | + } |
|
164 | + } |
|
165 | + } |
|
166 | + |
|
167 | + return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
168 | + } |
|
352 | 169 | |
353 | - /** |
|
354 | - * Sends a notification whenever an invoice is refunded. |
|
355 | - * |
|
356 | - * @param WPInv_Invoice $invoice |
|
357 | - */ |
|
358 | - public function refunded_invoice( $invoice ) { |
|
359 | - |
|
360 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
361 | - $recipient = $invoice->get_email(); |
|
362 | - |
|
363 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
364 | - |
|
365 | - } |
|
170 | + /** |
|
171 | + * Helper function to send an email. |
|
172 | + * |
|
173 | + * @param WPInv_Invoice $invoice |
|
174 | + * @param GetPaid_Notification_Email $email |
|
175 | + * @param string $type |
|
176 | + * @param string|array $recipients |
|
177 | + * @param array $extra_args Extra template args. |
|
178 | + */ |
|
179 | + public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
366 | 180 | |
367 | - /** |
|
368 | - * Notifies a user about new invoices |
|
369 | - * |
|
370 | - * @param WPInv_Invoice $invoice |
|
371 | - * @param bool $force |
|
372 | - */ |
|
373 | - public function user_invoice( $invoice, $force = false ) { |
|
181 | + do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
374 | 182 | |
375 | - if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
376 | - return; |
|
377 | - } |
|
378 | - |
|
379 | - // Only send this email for invoices created via the admin page. |
|
380 | - if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
381 | - return; |
|
382 | - } |
|
383 | - |
|
384 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
385 | - $recipient = $invoice->get_email(); |
|
386 | - |
|
387 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
388 | - |
|
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * Checks if an invoice is a payment form invoice. |
|
393 | - * |
|
394 | - * @param int $invoice |
|
395 | - * @return bool |
|
396 | - */ |
|
397 | - public function is_payment_form_invoice( $invoice ) { |
|
398 | - $created_via = get_post_meta( $invoice, 'wpinv_created_via', true ); |
|
399 | - $is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via; |
|
400 | - $is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
401 | - return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice; |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Notifies admin about new invoice notes |
|
406 | - * |
|
407 | - * @param WPInv_Invoice $invoice |
|
408 | - * @param string $note |
|
409 | - */ |
|
410 | - public function user_note( $invoice, $note ) { |
|
411 | - |
|
412 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
413 | - $recipient = $invoice->get_email(); |
|
414 | - |
|
415 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
416 | - |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * (Force) Sends overdue notices. |
|
421 | - * |
|
422 | - * @param WPInv_Invoice $invoice |
|
423 | - */ |
|
424 | - public function force_send_overdue_notice( $invoice ) { |
|
425 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
426 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
427 | - } |
|
428 | - |
|
429 | - /** |
|
430 | - * Sends overdue notices. |
|
431 | - * |
|
432 | - * @TODO: Create an invoices query class. |
|
433 | - */ |
|
434 | - public function overdue() { |
|
435 | - global $wpdb; |
|
436 | - |
|
437 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
438 | - |
|
439 | - // Fetch reminder days. |
|
440 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
441 | - |
|
442 | - // Abort if non is set. |
|
443 | - if ( empty( $reminder_days ) ) { |
|
444 | - return; |
|
445 | - } |
|
446 | - |
|
447 | - // Retrieve date query. |
|
448 | - $date_query = $this->get_date_query( $reminder_days ); |
|
449 | - |
|
450 | - // Invoices table. |
|
451 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
452 | - |
|
453 | - // Fetch invoices. |
|
454 | - $invoices = $wpdb->get_col( |
|
455 | - "SELECT posts.ID FROM $wpdb->posts as posts |
|
183 | + $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
184 | + if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
185 | + return; |
|
186 | + } |
|
187 | + |
|
188 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
189 | + $merge_tags = $email->get_merge_tags(); |
|
190 | + |
|
191 | + $result = $mailer->send( |
|
192 | + apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
193 | + $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
194 | + $email->get_content( $merge_tags, $extra_args ), |
|
195 | + $email->get_attachments() |
|
196 | + ); |
|
197 | + |
|
198 | + // Maybe send a copy to the admin. |
|
199 | + if ( $email->include_admin_bcc() ) { |
|
200 | + $mailer->send( |
|
201 | + wpinv_get_admin_email(), |
|
202 | + $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
203 | + $email->get_content( $merge_tags ), |
|
204 | + $email->get_attachments() |
|
205 | + ); |
|
206 | + } |
|
207 | + |
|
208 | + if ( $result ) { |
|
209 | + $invoice->add_system_note( |
|
210 | + sprintf( |
|
211 | + // translators: %1 is the email type, %2 is the invoice recipient. |
|
212 | + __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
213 | + sanitize_key( $type ), |
|
214 | + $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
215 | + ) |
|
216 | + ); |
|
217 | + } else { |
|
218 | + $invoice->add_system_note( |
|
219 | + sprintf( |
|
220 | + // translators: %1 is the email type, %2 is the invoice recipient. |
|
221 | + __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
222 | + sanitize_key( $type ), |
|
223 | + $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
224 | + ) |
|
225 | + ); |
|
226 | + } |
|
227 | + |
|
228 | + do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
229 | + |
|
230 | + return $result; |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * Also send emails to any cc users. |
|
235 | + * |
|
236 | + * @param array $recipients |
|
237 | + * @param GetPaid_Notification_Email $email |
|
238 | + */ |
|
239 | + public function filter_email_recipients( $recipients, $email ) { |
|
240 | + |
|
241 | + if ( ! $email->is_admin_email() ) { |
|
242 | + $cc = $email->object->get_email_cc(); |
|
243 | + $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
244 | + |
|
245 | + if ( ! empty( $cc ) ) { |
|
246 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
247 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
248 | + } |
|
249 | + |
|
250 | + if ( ! empty( $cc_2 ) ) { |
|
251 | + $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
252 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
253 | + } |
|
254 | + } |
|
255 | + |
|
256 | + return $recipients; |
|
257 | + |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Sends a new invoice notification. |
|
262 | + * |
|
263 | + * @param WPInv_Invoice $invoice |
|
264 | + */ |
|
265 | + public function new_invoice( $invoice ) { |
|
266 | + |
|
267 | + // Only send this email for invoices created via the admin page. |
|
268 | + if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
269 | + return; |
|
270 | + } |
|
271 | + |
|
272 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
273 | + $recipient = wpinv_get_admin_email(); |
|
274 | + |
|
275 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
276 | + |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Sends a cancelled invoice notification. |
|
281 | + * |
|
282 | + * @param WPInv_Invoice $invoice |
|
283 | + */ |
|
284 | + public function cancelled_invoice( $invoice ) { |
|
285 | + |
|
286 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
287 | + $recipient = $invoice->get_email(); |
|
288 | + |
|
289 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Sends a failed invoice notification. |
|
294 | + * |
|
295 | + * @param WPInv_Invoice $invoice |
|
296 | + */ |
|
297 | + public function failed_invoice( $invoice ) { |
|
298 | + |
|
299 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
300 | + $recipient = wpinv_get_admin_email(); |
|
301 | + |
|
302 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
303 | + |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Sends a notification whenever an invoice is put on hold. |
|
308 | + * |
|
309 | + * @param WPInv_Invoice $invoice |
|
310 | + */ |
|
311 | + public function onhold_invoice( $invoice ) { |
|
312 | + |
|
313 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
314 | + $recipient = $invoice->get_email(); |
|
315 | + |
|
316 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
317 | + |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * Sends a notification whenever an invoice is marked as processing payment. |
|
322 | + * |
|
323 | + * @param WPInv_Invoice $invoice |
|
324 | + */ |
|
325 | + public function processing_invoice( $invoice ) { |
|
326 | + |
|
327 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
328 | + $recipient = $invoice->get_email(); |
|
329 | + |
|
330 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
331 | + |
|
332 | + } |
|
333 | + |
|
334 | + /** |
|
335 | + * Sends a notification whenever an invoice is paid. |
|
336 | + * |
|
337 | + * @param WPInv_Invoice $invoice |
|
338 | + */ |
|
339 | + public function completed_invoice( $invoice ) { |
|
340 | + |
|
341 | + // (Maybe) abort if it is a renewal invoice. |
|
342 | + if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
343 | + return; |
|
344 | + } |
|
345 | + |
|
346 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
347 | + $recipient = $invoice->get_email(); |
|
348 | + |
|
349 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
350 | + |
|
351 | + } |
|
352 | + |
|
353 | + /** |
|
354 | + * Sends a notification whenever an invoice is refunded. |
|
355 | + * |
|
356 | + * @param WPInv_Invoice $invoice |
|
357 | + */ |
|
358 | + public function refunded_invoice( $invoice ) { |
|
359 | + |
|
360 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
361 | + $recipient = $invoice->get_email(); |
|
362 | + |
|
363 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
364 | + |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * Notifies a user about new invoices |
|
369 | + * |
|
370 | + * @param WPInv_Invoice $invoice |
|
371 | + * @param bool $force |
|
372 | + */ |
|
373 | + public function user_invoice( $invoice, $force = false ) { |
|
374 | + |
|
375 | + if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
376 | + return; |
|
377 | + } |
|
378 | + |
|
379 | + // Only send this email for invoices created via the admin page. |
|
380 | + if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
381 | + return; |
|
382 | + } |
|
383 | + |
|
384 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
385 | + $recipient = $invoice->get_email(); |
|
386 | + |
|
387 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
388 | + |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * Checks if an invoice is a payment form invoice. |
|
393 | + * |
|
394 | + * @param int $invoice |
|
395 | + * @return bool |
|
396 | + */ |
|
397 | + public function is_payment_form_invoice( $invoice ) { |
|
398 | + $created_via = get_post_meta( $invoice, 'wpinv_created_via', true ); |
|
399 | + $is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via; |
|
400 | + $is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
401 | + return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice; |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Notifies admin about new invoice notes |
|
406 | + * |
|
407 | + * @param WPInv_Invoice $invoice |
|
408 | + * @param string $note |
|
409 | + */ |
|
410 | + public function user_note( $invoice, $note ) { |
|
411 | + |
|
412 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
413 | + $recipient = $invoice->get_email(); |
|
414 | + |
|
415 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
416 | + |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * (Force) Sends overdue notices. |
|
421 | + * |
|
422 | + * @param WPInv_Invoice $invoice |
|
423 | + */ |
|
424 | + public function force_send_overdue_notice( $invoice ) { |
|
425 | + $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
426 | + return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
427 | + } |
|
428 | + |
|
429 | + /** |
|
430 | + * Sends overdue notices. |
|
431 | + * |
|
432 | + * @TODO: Create an invoices query class. |
|
433 | + */ |
|
434 | + public function overdue() { |
|
435 | + global $wpdb; |
|
436 | + |
|
437 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
438 | + |
|
439 | + // Fetch reminder days. |
|
440 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
441 | + |
|
442 | + // Abort if non is set. |
|
443 | + if ( empty( $reminder_days ) ) { |
|
444 | + return; |
|
445 | + } |
|
446 | + |
|
447 | + // Retrieve date query. |
|
448 | + $date_query = $this->get_date_query( $reminder_days ); |
|
449 | + |
|
450 | + // Invoices table. |
|
451 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
452 | + |
|
453 | + // Fetch invoices. |
|
454 | + $invoices = $wpdb->get_col( |
|
455 | + "SELECT posts.ID FROM $wpdb->posts as posts |
|
456 | 456 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
457 | 457 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query" |
458 | 458 | ); |
459 | 459 | |
460 | - foreach ( $invoices as $invoice ) { |
|
460 | + foreach ( $invoices as $invoice ) { |
|
461 | 461 | |
462 | - // Only send this email for invoices created via the admin page. |
|
463 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
464 | - $invoice = new WPInv_Invoice( $invoice ); |
|
465 | - $email->object = $invoice; |
|
462 | + // Only send this email for invoices created via the admin page. |
|
463 | + if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
464 | + $invoice = new WPInv_Invoice( $invoice ); |
|
465 | + $email->object = $invoice; |
|
466 | 466 | |
467 | - if ( $invoice->needs_payment() && ! $invoice->is_renewal() ) { |
|
468 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
469 | - } |
|
470 | - } |
|
471 | - } |
|
467 | + if ( $invoice->needs_payment() && ! $invoice->is_renewal() ) { |
|
468 | + $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
469 | + } |
|
470 | + } |
|
471 | + } |
|
472 | 472 | |
473 | - } |
|
473 | + } |
|
474 | 474 | |
475 | - /** |
|
476 | - * Calculates the date query for an invoices query |
|
477 | - * |
|
478 | - * @param array $reminder_days |
|
479 | - * @return string |
|
480 | - */ |
|
481 | - public function get_date_query( $reminder_days ) { |
|
475 | + /** |
|
476 | + * Calculates the date query for an invoices query |
|
477 | + * |
|
478 | + * @param array $reminder_days |
|
479 | + * @return string |
|
480 | + */ |
|
481 | + public function get_date_query( $reminder_days ) { |
|
482 | 482 | |
483 | - $date_query = array( |
|
484 | - 'relation' => 'OR', |
|
485 | - ); |
|
483 | + $date_query = array( |
|
484 | + 'relation' => 'OR', |
|
485 | + ); |
|
486 | 486 | |
487 | - foreach ( $reminder_days as $days ) { |
|
488 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
487 | + foreach ( $reminder_days as $days ) { |
|
488 | + $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
489 | 489 | |
490 | - $date_query[] = array( |
|
491 | - 'year' => $date['year'], |
|
492 | - 'month' => $date['month'], |
|
493 | - 'day' => $date['day'], |
|
494 | - ); |
|
490 | + $date_query[] = array( |
|
491 | + 'year' => $date['year'], |
|
492 | + 'month' => $date['month'], |
|
493 | + 'day' => $date['day'], |
|
494 | + ); |
|
495 | 495 | |
496 | - } |
|
496 | + } |
|
497 | 497 | |
498 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
498 | + $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
499 | 499 | |
500 | - return $date_query->get_sql(); |
|
500 | + return $date_query->get_sql(); |
|
501 | 501 | |
502 | - } |
|
502 | + } |
|
503 | 503 | |
504 | 504 | } |
@@ -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 | * This class handles invoice notificaiton emails. |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | $this->invoice_actions = apply_filters( |
29 | 29 | 'getpaid_notification_email_invoice_triggers', |
30 | 30 | array( |
31 | - 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
31 | + 'getpaid_new_invoice' => array('new_invoice', 'user_invoice'), |
|
32 | 32 | 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
33 | 33 | 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
34 | 34 | 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function init_hooks() { |
52 | 52 | |
53 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | - add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
53 | + add_filter('getpaid_get_email_merge_tags', array($this, 'invoice_merge_tags'), 10, 2); |
|
54 | + add_filter('getpaid_invoice_email_recipients', array($this, 'filter_email_recipients'), 10, 2); |
|
55 | 55 | |
56 | - foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | - $this->init_email_type_hook( $hook, $email_type ); |
|
56 | + foreach ($this->invoice_actions as $hook => $email_type) { |
|
57 | + $this->init_email_type_hook($hook, $email_type); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
@@ -64,25 +64,25 @@ discard block |
||
64 | 64 | * @param string $hook |
65 | 65 | * @param string|array $email_type |
66 | 66 | */ |
67 | - public function init_email_type_hook( $hook, $email_type ) { |
|
67 | + public function init_email_type_hook($hook, $email_type) { |
|
68 | 68 | |
69 | - $email_type = wpinv_parse_list( $email_type ); |
|
69 | + $email_type = wpinv_parse_list($email_type); |
|
70 | 70 | |
71 | - foreach ( $email_type as $type ) { |
|
71 | + foreach ($email_type as $type) { |
|
72 | 72 | |
73 | - $email = new GetPaid_Notification_Email( $type ); |
|
73 | + $email = new GetPaid_Notification_Email($type); |
|
74 | 74 | |
75 | 75 | // Abort if it is not active. |
76 | - if ( ! $email->is_active() ) { |
|
76 | + if (!$email->is_active()) { |
|
77 | 77 | continue; |
78 | 78 | } |
79 | 79 | |
80 | - if ( method_exists( $this, $type ) ) { |
|
81 | - add_action( $hook, array( $this, $type ), 100, 2 ); |
|
80 | + if (method_exists($this, $type)) { |
|
81 | + add_action($hook, array($this, $type), 100, 2); |
|
82 | 82 | continue; |
83 | 83 | } |
84 | 84 | |
85 | - do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
85 | + do_action('getpaid_invoice_init_email_type_hook', $type, $hook); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | } |
@@ -93,19 +93,19 @@ discard block |
||
93 | 93 | * @param array $merge_tags |
94 | 94 | * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
95 | 95 | */ |
96 | - public function invoice_merge_tags( $merge_tags, $object ) { |
|
96 | + public function invoice_merge_tags($merge_tags, $object) { |
|
97 | 97 | |
98 | - if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
98 | + if (is_a($object, 'WPInv_Invoice')) { |
|
99 | 99 | return array_merge( |
100 | 100 | $merge_tags, |
101 | - $this->get_invoice_merge_tags( $object ) |
|
101 | + $this->get_invoice_merge_tags($object) |
|
102 | 102 | ); |
103 | 103 | } |
104 | 104 | |
105 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
105 | + if (is_a($object, 'WPInv_Subscription')) { |
|
106 | 106 | return array_merge( |
107 | 107 | $merge_tags, |
108 | - $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
108 | + $this->get_invoice_merge_tags($object->get_parent_payment()) |
|
109 | 109 | ); |
110 | 110 | } |
111 | 111 | |
@@ -119,52 +119,52 @@ discard block |
||
119 | 119 | * @param WPInv_Invoice $invoice |
120 | 120 | * @return array |
121 | 121 | */ |
122 | - public function get_invoice_merge_tags( $invoice ) { |
|
122 | + public function get_invoice_merge_tags($invoice) { |
|
123 | 123 | |
124 | 124 | // Abort if it does not exist. |
125 | - if ( ! $invoice->get_id() ) { |
|
125 | + if (!$invoice->get_id()) { |
|
126 | 126 | return array(); |
127 | 127 | } |
128 | 128 | |
129 | 129 | $due_date = $invoice->get_due_date(); |
130 | - $due_date = empty( $due_date ) ? time() + MINUTE_IN_SECONDS : strtotime( $due_date ) + ( (int) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
|
130 | + $due_date = empty($due_date) ? time() + MINUTE_IN_SECONDS : strtotime($due_date) + ((int) get_option('gmt_offset') * HOUR_IN_SECONDS); |
|
131 | 131 | $merge_tags = array( |
132 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
133 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
134 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
135 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
136 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
137 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
138 | - '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
139 | - '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
140 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
141 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
142 | - '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ), |
|
143 | - '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
144 | - '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
145 | - '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
146 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
147 | - '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
148 | - '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
149 | - '{is_was}' => $due_date < time() ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
132 | + '{name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
133 | + '{full_name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
134 | + '{first_name}' => sanitize_text_field($invoice->get_first_name()), |
|
135 | + '{last_name}' => sanitize_text_field($invoice->get_last_name()), |
|
136 | + '{email}' => sanitize_email($invoice->get_email()), |
|
137 | + '{invoice_number}' => sanitize_text_field($invoice->get_number()), |
|
138 | + '{invoice_currency}' => sanitize_text_field($invoice->get_currency()), |
|
139 | + '{invoice_total}' => sanitize_text_field(wpinv_price($invoice->get_total(), $invoice->get_currency())), |
|
140 | + '{invoice_link}' => esc_url($invoice->get_view_url()), |
|
141 | + '{invoice_pay_link}' => esc_url($invoice->get_checkout_payment_url()), |
|
142 | + '{invoice_receipt_link}' => esc_url($invoice->get_receipt_url()), |
|
143 | + '{invoice_date}' => getpaid_format_date_value($invoice->get_date_created()), |
|
144 | + '{invoice_due_date}' => getpaid_format_date_value($invoice->get_due_date(), __('on receipt', 'invoicing')), |
|
145 | + '{invoice_quote}' => sanitize_text_field(strtolower($invoice->get_label())), |
|
146 | + '{invoice_label}' => sanitize_text_field(ucfirst($invoice->get_label())), |
|
147 | + '{invoice_description}' => wp_kses_post($invoice->get_description()), |
|
148 | + '{subscription_name}' => wp_kses_post($invoice->get_subscription_name()), |
|
149 | + '{is_was}' => $due_date < time() ? __('was', 'invoicing') : __('is', 'invoicing'), |
|
150 | 150 | ); |
151 | 151 | |
152 | - $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
152 | + $payment_form_data = $invoice->get_meta('payment_form_data', true); |
|
153 | 153 | |
154 | - if ( is_array( $payment_form_data ) ) { |
|
154 | + if (is_array($payment_form_data)) { |
|
155 | 155 | |
156 | - foreach ( $payment_form_data as $label => $value ) { |
|
156 | + foreach ($payment_form_data as $label => $value) { |
|
157 | 157 | |
158 | - $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
159 | - $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
158 | + $label = preg_replace('/[^a-z0-9]+/', '_', strtolower($label)); |
|
159 | + $value = is_array($value) ? implode(', ', $value) : $value; |
|
160 | 160 | |
161 | - if ( is_scalar( $value ) ) { |
|
162 | - $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
161 | + if (is_scalar($value)) { |
|
162 | + $merge_tags["{{$label}}"] = wp_kses_post($value); |
|
163 | 163 | } |
164 | 164 | } |
165 | 165 | } |
166 | 166 | |
167 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
167 | + return apply_filters('getpaid_invoice_email_merge_tags', $merge_tags, $invoice); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -176,12 +176,12 @@ discard block |
||
176 | 176 | * @param string|array $recipients |
177 | 177 | * @param array $extra_args Extra template args. |
178 | 178 | */ |
179 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
179 | + public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) { |
|
180 | 180 | |
181 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
181 | + do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email); |
|
182 | 182 | |
183 | - $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
184 | - if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
183 | + $skip = $invoice->is_free() && wpinv_get_option('skip_email_free_invoice'); |
|
184 | + if (apply_filters('getpaid_skip_invoice_email', $skip, $type, $invoice)) { |
|
185 | 185 | return; |
186 | 186 | } |
187 | 187 | |
@@ -189,43 +189,43 @@ discard block |
||
189 | 189 | $merge_tags = $email->get_merge_tags(); |
190 | 190 | |
191 | 191 | $result = $mailer->send( |
192 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
193 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
194 | - $email->get_content( $merge_tags, $extra_args ), |
|
192 | + apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email), |
|
193 | + $email->add_merge_tags($email->get_subject(), $merge_tags), |
|
194 | + $email->get_content($merge_tags, $extra_args), |
|
195 | 195 | $email->get_attachments() |
196 | 196 | ); |
197 | 197 | |
198 | 198 | // Maybe send a copy to the admin. |
199 | - if ( $email->include_admin_bcc() ) { |
|
199 | + if ($email->include_admin_bcc()) { |
|
200 | 200 | $mailer->send( |
201 | 201 | wpinv_get_admin_email(), |
202 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
203 | - $email->get_content( $merge_tags ), |
|
202 | + $email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags), |
|
203 | + $email->get_content($merge_tags), |
|
204 | 204 | $email->get_attachments() |
205 | 205 | ); |
206 | 206 | } |
207 | 207 | |
208 | - if ( $result ) { |
|
208 | + if ($result) { |
|
209 | 209 | $invoice->add_system_note( |
210 | 210 | sprintf( |
211 | 211 | // translators: %1 is the email type, %2 is the invoice recipient. |
212 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
213 | - sanitize_key( $type ), |
|
214 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
212 | + __('Successfully sent %1$s notification email to %2$s.', 'invoicing'), |
|
213 | + sanitize_key($type), |
|
214 | + $email->is_admin_email() ? __('admin', 'invoicing') : __('the customer', 'invoicing') |
|
215 | 215 | ) |
216 | 216 | ); |
217 | 217 | } else { |
218 | 218 | $invoice->add_system_note( |
219 | 219 | sprintf( |
220 | 220 | // translators: %1 is the email type, %2 is the invoice recipient. |
221 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
222 | - sanitize_key( $type ), |
|
223 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
221 | + __('Failed sending %1$s notification email to %2$s.', 'invoicing'), |
|
222 | + sanitize_key($type), |
|
223 | + $email->is_admin_email() ? __('admin', 'invoicing') : __('the customer', 'invoicing') |
|
224 | 224 | ) |
225 | 225 | ); |
226 | 226 | } |
227 | 227 | |
228 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
228 | + do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email); |
|
229 | 229 | |
230 | 230 | return $result; |
231 | 231 | } |
@@ -236,20 +236,20 @@ discard block |
||
236 | 236 | * @param array $recipients |
237 | 237 | * @param GetPaid_Notification_Email $email |
238 | 238 | */ |
239 | - public function filter_email_recipients( $recipients, $email ) { |
|
239 | + public function filter_email_recipients($recipients, $email) { |
|
240 | 240 | |
241 | - if ( ! $email->is_admin_email() ) { |
|
241 | + if (!$email->is_admin_email()) { |
|
242 | 242 | $cc = $email->object->get_email_cc(); |
243 | - $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
243 | + $cc_2 = get_user_meta($email->object->get_user_id(), '_wpinv_email_cc', true); |
|
244 | 244 | |
245 | - if ( ! empty( $cc ) ) { |
|
246 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
247 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
245 | + if (!empty($cc)) { |
|
246 | + $cc = array_map('sanitize_email', wpinv_parse_list($cc)); |
|
247 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc))); |
|
248 | 248 | } |
249 | 249 | |
250 | - if ( ! empty( $cc_2 ) ) { |
|
251 | - $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
252 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
250 | + if (!empty($cc_2)) { |
|
251 | + $cc_2 = array_map('sanitize_email', wpinv_parse_list($cc_2)); |
|
252 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc_2))); |
|
253 | 253 | } |
254 | 254 | } |
255 | 255 | |
@@ -262,17 +262,17 @@ discard block |
||
262 | 262 | * |
263 | 263 | * @param WPInv_Invoice $invoice |
264 | 264 | */ |
265 | - public function new_invoice( $invoice ) { |
|
265 | + public function new_invoice($invoice) { |
|
266 | 266 | |
267 | 267 | // Only send this email for invoices created via the admin page. |
268 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
268 | + if (!$invoice->is_type('invoice') || $invoice->is_paid() || $this->is_payment_form_invoice($invoice->get_id())) { |
|
269 | 269 | return; |
270 | 270 | } |
271 | 271 | |
272 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
272 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
273 | 273 | $recipient = wpinv_get_admin_email(); |
274 | 274 | |
275 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
275 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
276 | 276 | |
277 | 277 | } |
278 | 278 | |
@@ -281,12 +281,12 @@ discard block |
||
281 | 281 | * |
282 | 282 | * @param WPInv_Invoice $invoice |
283 | 283 | */ |
284 | - public function cancelled_invoice( $invoice ) { |
|
284 | + public function cancelled_invoice($invoice) { |
|
285 | 285 | |
286 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
286 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
287 | 287 | $recipient = $invoice->get_email(); |
288 | 288 | |
289 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
289 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
@@ -294,12 +294,12 @@ discard block |
||
294 | 294 | * |
295 | 295 | * @param WPInv_Invoice $invoice |
296 | 296 | */ |
297 | - public function failed_invoice( $invoice ) { |
|
297 | + public function failed_invoice($invoice) { |
|
298 | 298 | |
299 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
299 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
300 | 300 | $recipient = wpinv_get_admin_email(); |
301 | 301 | |
302 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
302 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
303 | 303 | |
304 | 304 | } |
305 | 305 | |
@@ -308,12 +308,12 @@ discard block |
||
308 | 308 | * |
309 | 309 | * @param WPInv_Invoice $invoice |
310 | 310 | */ |
311 | - public function onhold_invoice( $invoice ) { |
|
311 | + public function onhold_invoice($invoice) { |
|
312 | 312 | |
313 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
313 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
314 | 314 | $recipient = $invoice->get_email(); |
315 | 315 | |
316 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
316 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
317 | 317 | |
318 | 318 | } |
319 | 319 | |
@@ -322,12 +322,12 @@ discard block |
||
322 | 322 | * |
323 | 323 | * @param WPInv_Invoice $invoice |
324 | 324 | */ |
325 | - public function processing_invoice( $invoice ) { |
|
325 | + public function processing_invoice($invoice) { |
|
326 | 326 | |
327 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
327 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
328 | 328 | $recipient = $invoice->get_email(); |
329 | 329 | |
330 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
330 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
331 | 331 | |
332 | 332 | } |
333 | 333 | |
@@ -336,17 +336,17 @@ discard block |
||
336 | 336 | * |
337 | 337 | * @param WPInv_Invoice $invoice |
338 | 338 | */ |
339 | - public function completed_invoice( $invoice ) { |
|
339 | + public function completed_invoice($invoice) { |
|
340 | 340 | |
341 | 341 | // (Maybe) abort if it is a renewal invoice. |
342 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
342 | + if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) { |
|
343 | 343 | return; |
344 | 344 | } |
345 | 345 | |
346 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
346 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
347 | 347 | $recipient = $invoice->get_email(); |
348 | 348 | |
349 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
349 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
350 | 350 | |
351 | 351 | } |
352 | 352 | |
@@ -355,12 +355,12 @@ discard block |
||
355 | 355 | * |
356 | 356 | * @param WPInv_Invoice $invoice |
357 | 357 | */ |
358 | - public function refunded_invoice( $invoice ) { |
|
358 | + public function refunded_invoice($invoice) { |
|
359 | 359 | |
360 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
360 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
361 | 361 | $recipient = $invoice->get_email(); |
362 | 362 | |
363 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
363 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
364 | 364 | |
365 | 365 | } |
366 | 366 | |
@@ -370,21 +370,21 @@ discard block |
||
370 | 370 | * @param WPInv_Invoice $invoice |
371 | 371 | * @param bool $force |
372 | 372 | */ |
373 | - public function user_invoice( $invoice, $force = false ) { |
|
373 | + public function user_invoice($invoice, $force = false) { |
|
374 | 374 | |
375 | - if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
375 | + if (!$force && !empty($GLOBALS['wpinv_skip_invoice_notification'])) { |
|
376 | 376 | return; |
377 | 377 | } |
378 | 378 | |
379 | 379 | // Only send this email for invoices created via the admin page. |
380 | - if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
380 | + if (!$invoice->is_type('invoice') || (empty($force) && $invoice->is_paid()) || (empty($force) && $this->is_payment_form_invoice($invoice->get_id()))) { |
|
381 | 381 | return; |
382 | 382 | } |
383 | 383 | |
384 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
384 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
385 | 385 | $recipient = $invoice->get_email(); |
386 | 386 | |
387 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
387 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
388 | 388 | |
389 | 389 | } |
390 | 390 | |
@@ -394,11 +394,11 @@ discard block |
||
394 | 394 | * @param int $invoice |
395 | 395 | * @return bool |
396 | 396 | */ |
397 | - public function is_payment_form_invoice( $invoice ) { |
|
398 | - $created_via = get_post_meta( $invoice, 'wpinv_created_via', true ); |
|
397 | + public function is_payment_form_invoice($invoice) { |
|
398 | + $created_via = get_post_meta($invoice, 'wpinv_created_via', true); |
|
399 | 399 | $is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via; |
400 | - $is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
401 | - return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice; |
|
400 | + $is_payment_form_invoice = apply_filters('getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice); |
|
401 | + return empty($_GET['getpaid-admin-action']) && $is_payment_form_invoice; |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | /** |
@@ -407,12 +407,12 @@ discard block |
||
407 | 407 | * @param WPInv_Invoice $invoice |
408 | 408 | * @param string $note |
409 | 409 | */ |
410 | - public function user_note( $invoice, $note ) { |
|
410 | + public function user_note($invoice, $note) { |
|
411 | 411 | |
412 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
412 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
413 | 413 | $recipient = $invoice->get_email(); |
414 | 414 | |
415 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
415 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note)); |
|
416 | 416 | |
417 | 417 | } |
418 | 418 | |
@@ -421,9 +421,9 @@ discard block |
||
421 | 421 | * |
422 | 422 | * @param WPInv_Invoice $invoice |
423 | 423 | */ |
424 | - public function force_send_overdue_notice( $invoice ) { |
|
425 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
426 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
424 | + public function force_send_overdue_notice($invoice) { |
|
425 | + $email = new GetPaid_Notification_Email('overdue', $invoice); |
|
426 | + return $this->send_email($invoice, $email, 'overdue', $invoice->get_email()); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | /** |
@@ -434,38 +434,38 @@ discard block |
||
434 | 434 | public function overdue() { |
435 | 435 | global $wpdb; |
436 | 436 | |
437 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
437 | + $email = new GetPaid_Notification_Email(__FUNCTION__); |
|
438 | 438 | |
439 | 439 | // Fetch reminder days. |
440 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
440 | + $reminder_days = array_unique(wp_parse_id_list($email->get_option('days'))); |
|
441 | 441 | |
442 | 442 | // Abort if non is set. |
443 | - if ( empty( $reminder_days ) ) { |
|
443 | + if (empty($reminder_days)) { |
|
444 | 444 | return; |
445 | 445 | } |
446 | 446 | |
447 | 447 | // Retrieve date query. |
448 | - $date_query = $this->get_date_query( $reminder_days ); |
|
448 | + $date_query = $this->get_date_query($reminder_days); |
|
449 | 449 | |
450 | 450 | // Invoices table. |
451 | 451 | $table = $wpdb->prefix . 'getpaid_invoices'; |
452 | 452 | |
453 | 453 | // Fetch invoices. |
454 | - $invoices = $wpdb->get_col( |
|
454 | + $invoices = $wpdb->get_col( |
|
455 | 455 | "SELECT posts.ID FROM $wpdb->posts as posts |
456 | 456 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
457 | 457 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query" |
458 | 458 | ); |
459 | 459 | |
460 | - foreach ( $invoices as $invoice ) { |
|
460 | + foreach ($invoices as $invoice) { |
|
461 | 461 | |
462 | 462 | // Only send this email for invoices created via the admin page. |
463 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
464 | - $invoice = new WPInv_Invoice( $invoice ); |
|
463 | + if (!$this->is_payment_form_invoice($invoice)) { |
|
464 | + $invoice = new WPInv_Invoice($invoice); |
|
465 | 465 | $email->object = $invoice; |
466 | 466 | |
467 | - if ( $invoice->needs_payment() && ! $invoice->is_renewal() ) { |
|
468 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
467 | + if ($invoice->needs_payment() && !$invoice->is_renewal()) { |
|
468 | + $this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email()); |
|
469 | 469 | } |
470 | 470 | } |
471 | 471 | } |
@@ -478,14 +478,14 @@ discard block |
||
478 | 478 | * @param array $reminder_days |
479 | 479 | * @return string |
480 | 480 | */ |
481 | - public function get_date_query( $reminder_days ) { |
|
481 | + public function get_date_query($reminder_days) { |
|
482 | 482 | |
483 | 483 | $date_query = array( |
484 | 484 | 'relation' => 'OR', |
485 | 485 | ); |
486 | 486 | |
487 | - foreach ( $reminder_days as $days ) { |
|
488 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
487 | + foreach ($reminder_days as $days) { |
|
488 | + $date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp')))); |
|
489 | 489 | |
490 | 490 | $date_query[] = array( |
491 | 491 | 'year' => $date['year'], |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | |
496 | 496 | } |
497 | 497 | |
498 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
498 | + $date_query = new WP_Date_Query($date_query, 'invoices.due_date'); |
|
499 | 499 | |
500 | 500 | return $date_query->get_sql(); |
501 | 501 |