@@ -13,128 +13,128 @@ |
||
13 | 13 | class GetPaid_Payment_Forms { |
14 | 14 | |
15 | 15 | /** |
16 | - * Class constructor |
|
17 | - * |
|
18 | - */ |
|
19 | - public function __construct() { |
|
20 | - |
|
21 | - // Update a payment form's revenue whenever an invoice is paid for or refunded. |
|
22 | - add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) ); |
|
23 | - add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) ); |
|
24 | - |
|
25 | - // Sync form amount whenever invoice statuses change. |
|
26 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 ); |
|
27 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 ); |
|
28 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 ); |
|
29 | - |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * Increments a form's revenue whenever there is a payment. |
|
34 | - * |
|
35 | - * @param WPInv_Invoice $invoice |
|
36 | - */ |
|
37 | - public function increment_form_revenue( $invoice ) { |
|
38 | - |
|
39 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
40 | - if ( $form->get_id() ) { |
|
41 | - $form->set_earned( $form->get_earned() + $invoice->get_total() ); |
|
42 | - $form->save(); |
|
43 | - } |
|
44 | - |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Decreases form revenue whenever invoice payment changes. |
|
49 | - * |
|
50 | - * @param WPInv_Invoice $invoice |
|
51 | - */ |
|
52 | - public function decrease_form_revenue( $invoice ) { |
|
53 | - |
|
54 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
55 | - if ( $form->get_id() ) { |
|
56 | - $form->set_earned( $form->get_earned() - $invoice->get_total() ); |
|
57 | - $form->save(); |
|
58 | - } |
|
59 | - |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Updates a form's failed amount. |
|
64 | - * |
|
65 | - * @param WPInv_Invoice $invoice |
|
66 | - * @param string $from |
|
67 | - * @param string $to |
|
68 | - */ |
|
69 | - public function update_form_failed_amount( $invoice, $from, $to ) { |
|
70 | - |
|
71 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
72 | - if ( $form->get_id() ) { |
|
73 | - return; |
|
74 | - } |
|
75 | - |
|
76 | - if ( 'wpi-failed' == $from ) { |
|
77 | - $form->set_failed( $form->get_failed() - $invoice->get_total() ); |
|
78 | - $form->save(); |
|
79 | - } |
|
80 | - |
|
81 | - if ( 'wpi-failed' == $to ) { |
|
82 | - $form->set_failed( $form->get_failed() + $invoice->get_total() ); |
|
83 | - $form->save(); |
|
84 | - } |
|
85 | - |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Updates a form's refunded amount. |
|
90 | - * |
|
91 | - * @param WPInv_Invoice $invoice |
|
92 | - * @param string $from |
|
93 | - * @param string $to |
|
94 | - */ |
|
95 | - public function update_form_refunded_amount( $invoice, $from, $to ) { |
|
96 | - |
|
97 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
98 | - if ( $form->get_id() ) { |
|
99 | - return; |
|
100 | - } |
|
101 | - |
|
102 | - if ( 'wpi-refunded' == $from ) { |
|
103 | - $form->set_refunded( $form->get_refunded() - $invoice->get_total() ); |
|
104 | - $form->save(); |
|
105 | - } |
|
106 | - |
|
107 | - if ( 'wpi-refunded' == $to ) { |
|
108 | - $form->set_refunded( $form->get_refunded() + $invoice->get_total() ); |
|
109 | - $form->save(); |
|
110 | - } |
|
111 | - |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Updates a form's cancelled amount. |
|
116 | - * |
|
117 | - * @param WPInv_Invoice $invoice |
|
118 | - * @param string $from |
|
119 | - * @param string $to |
|
120 | - */ |
|
121 | - public function update_form_cancelled_amount( $invoice, $from, $to ) { |
|
122 | - |
|
123 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
124 | - if ( $form->get_id() ) { |
|
125 | - return; |
|
126 | - } |
|
127 | - |
|
128 | - if ( 'wpi-cancelled' == $from ) { |
|
129 | - $form->set_cancelled( $form->get_cancelled() - $invoice->get_total() ); |
|
130 | - $form->save(); |
|
131 | - } |
|
132 | - |
|
133 | - if ( 'wpi-cancelled' == $to ) { |
|
134 | - $form->set_cancelled( $form->get_cancelled() + $invoice->get_total() ); |
|
135 | - $form->save(); |
|
136 | - } |
|
137 | - |
|
138 | - } |
|
16 | + * Class constructor |
|
17 | + * |
|
18 | + */ |
|
19 | + public function __construct() { |
|
20 | + |
|
21 | + // Update a payment form's revenue whenever an invoice is paid for or refunded. |
|
22 | + add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) ); |
|
23 | + add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) ); |
|
24 | + |
|
25 | + // Sync form amount whenever invoice statuses change. |
|
26 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 ); |
|
27 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 ); |
|
28 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 ); |
|
29 | + |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * Increments a form's revenue whenever there is a payment. |
|
34 | + * |
|
35 | + * @param WPInv_Invoice $invoice |
|
36 | + */ |
|
37 | + public function increment_form_revenue( $invoice ) { |
|
38 | + |
|
39 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
40 | + if ( $form->get_id() ) { |
|
41 | + $form->set_earned( $form->get_earned() + $invoice->get_total() ); |
|
42 | + $form->save(); |
|
43 | + } |
|
44 | + |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Decreases form revenue whenever invoice payment changes. |
|
49 | + * |
|
50 | + * @param WPInv_Invoice $invoice |
|
51 | + */ |
|
52 | + public function decrease_form_revenue( $invoice ) { |
|
53 | + |
|
54 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
55 | + if ( $form->get_id() ) { |
|
56 | + $form->set_earned( $form->get_earned() - $invoice->get_total() ); |
|
57 | + $form->save(); |
|
58 | + } |
|
59 | + |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Updates a form's failed amount. |
|
64 | + * |
|
65 | + * @param WPInv_Invoice $invoice |
|
66 | + * @param string $from |
|
67 | + * @param string $to |
|
68 | + */ |
|
69 | + public function update_form_failed_amount( $invoice, $from, $to ) { |
|
70 | + |
|
71 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
72 | + if ( $form->get_id() ) { |
|
73 | + return; |
|
74 | + } |
|
75 | + |
|
76 | + if ( 'wpi-failed' == $from ) { |
|
77 | + $form->set_failed( $form->get_failed() - $invoice->get_total() ); |
|
78 | + $form->save(); |
|
79 | + } |
|
80 | + |
|
81 | + if ( 'wpi-failed' == $to ) { |
|
82 | + $form->set_failed( $form->get_failed() + $invoice->get_total() ); |
|
83 | + $form->save(); |
|
84 | + } |
|
85 | + |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Updates a form's refunded amount. |
|
90 | + * |
|
91 | + * @param WPInv_Invoice $invoice |
|
92 | + * @param string $from |
|
93 | + * @param string $to |
|
94 | + */ |
|
95 | + public function update_form_refunded_amount( $invoice, $from, $to ) { |
|
96 | + |
|
97 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
98 | + if ( $form->get_id() ) { |
|
99 | + return; |
|
100 | + } |
|
101 | + |
|
102 | + if ( 'wpi-refunded' == $from ) { |
|
103 | + $form->set_refunded( $form->get_refunded() - $invoice->get_total() ); |
|
104 | + $form->save(); |
|
105 | + } |
|
106 | + |
|
107 | + if ( 'wpi-refunded' == $to ) { |
|
108 | + $form->set_refunded( $form->get_refunded() + $invoice->get_total() ); |
|
109 | + $form->save(); |
|
110 | + } |
|
111 | + |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Updates a form's cancelled amount. |
|
116 | + * |
|
117 | + * @param WPInv_Invoice $invoice |
|
118 | + * @param string $from |
|
119 | + * @param string $to |
|
120 | + */ |
|
121 | + public function update_form_cancelled_amount( $invoice, $from, $to ) { |
|
122 | + |
|
123 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
124 | + if ( $form->get_id() ) { |
|
125 | + return; |
|
126 | + } |
|
127 | + |
|
128 | + if ( 'wpi-cancelled' == $from ) { |
|
129 | + $form->set_cancelled( $form->get_cancelled() - $invoice->get_total() ); |
|
130 | + $form->save(); |
|
131 | + } |
|
132 | + |
|
133 | + if ( 'wpi-cancelled' == $to ) { |
|
134 | + $form->set_cancelled( $form->get_cancelled() + $invoice->get_total() ); |
|
135 | + $form->save(); |
|
136 | + } |
|
137 | + |
|
138 | + } |
|
139 | 139 | |
140 | 140 | } |
@@ -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 | * Payment forms controller class |
@@ -19,13 +19,13 @@ discard block |
||
19 | 19 | public function __construct() { |
20 | 20 | |
21 | 21 | // Update a payment form's revenue whenever an invoice is paid for or refunded. |
22 | - add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) ); |
|
23 | - add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) ); |
|
22 | + add_action('getpaid_invoice_payment_status_changed', array($this, 'increment_form_revenue')); |
|
23 | + add_action('getpaid_invoice_payment_status_reversed', array($this, 'decrease_form_revenue')); |
|
24 | 24 | |
25 | 25 | // Sync form amount whenever invoice statuses change. |
26 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 ); |
|
27 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 ); |
|
28 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 ); |
|
26 | + add_action('getpaid_invoice_status_changed', array($this, 'update_form_failed_amount'), 10, 3); |
|
27 | + add_action('getpaid_invoice_status_changed', array($this, 'update_form_refunded_amount'), 10, 3); |
|
28 | + add_action('getpaid_invoice_status_changed', array($this, 'update_form_cancelled_amount'), 10, 3); |
|
29 | 29 | |
30 | 30 | } |
31 | 31 | |
@@ -34,11 +34,11 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @param WPInv_Invoice $invoice |
36 | 36 | */ |
37 | - public function increment_form_revenue( $invoice ) { |
|
37 | + public function increment_form_revenue($invoice) { |
|
38 | 38 | |
39 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
40 | - if ( $form->get_id() ) { |
|
41 | - $form->set_earned( $form->get_earned() + $invoice->get_total() ); |
|
39 | + $form = new GetPaid_Payment_Form($invoice->get_payment_form()); |
|
40 | + if ($form->get_id()) { |
|
41 | + $form->set_earned($form->get_earned() + $invoice->get_total()); |
|
42 | 42 | $form->save(); |
43 | 43 | } |
44 | 44 | |
@@ -49,11 +49,11 @@ discard block |
||
49 | 49 | * |
50 | 50 | * @param WPInv_Invoice $invoice |
51 | 51 | */ |
52 | - public function decrease_form_revenue( $invoice ) { |
|
52 | + public function decrease_form_revenue($invoice) { |
|
53 | 53 | |
54 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
55 | - if ( $form->get_id() ) { |
|
56 | - $form->set_earned( $form->get_earned() - $invoice->get_total() ); |
|
54 | + $form = new GetPaid_Payment_Form($invoice->get_payment_form()); |
|
55 | + if ($form->get_id()) { |
|
56 | + $form->set_earned($form->get_earned() - $invoice->get_total()); |
|
57 | 57 | $form->save(); |
58 | 58 | } |
59 | 59 | |
@@ -66,20 +66,20 @@ discard block |
||
66 | 66 | * @param string $from |
67 | 67 | * @param string $to |
68 | 68 | */ |
69 | - public function update_form_failed_amount( $invoice, $from, $to ) { |
|
69 | + public function update_form_failed_amount($invoice, $from, $to) { |
|
70 | 70 | |
71 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
72 | - if ( $form->get_id() ) { |
|
71 | + $form = new GetPaid_Payment_Form($invoice->get_payment_form()); |
|
72 | + if ($form->get_id()) { |
|
73 | 73 | return; |
74 | 74 | } |
75 | 75 | |
76 | - if ( 'wpi-failed' == $from ) { |
|
77 | - $form->set_failed( $form->get_failed() - $invoice->get_total() ); |
|
76 | + if ('wpi-failed' == $from) { |
|
77 | + $form->set_failed($form->get_failed() - $invoice->get_total()); |
|
78 | 78 | $form->save(); |
79 | 79 | } |
80 | 80 | |
81 | - if ( 'wpi-failed' == $to ) { |
|
82 | - $form->set_failed( $form->get_failed() + $invoice->get_total() ); |
|
81 | + if ('wpi-failed' == $to) { |
|
82 | + $form->set_failed($form->get_failed() + $invoice->get_total()); |
|
83 | 83 | $form->save(); |
84 | 84 | } |
85 | 85 | |
@@ -92,20 +92,20 @@ discard block |
||
92 | 92 | * @param string $from |
93 | 93 | * @param string $to |
94 | 94 | */ |
95 | - public function update_form_refunded_amount( $invoice, $from, $to ) { |
|
95 | + public function update_form_refunded_amount($invoice, $from, $to) { |
|
96 | 96 | |
97 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
98 | - if ( $form->get_id() ) { |
|
97 | + $form = new GetPaid_Payment_Form($invoice->get_payment_form()); |
|
98 | + if ($form->get_id()) { |
|
99 | 99 | return; |
100 | 100 | } |
101 | 101 | |
102 | - if ( 'wpi-refunded' == $from ) { |
|
103 | - $form->set_refunded( $form->get_refunded() - $invoice->get_total() ); |
|
102 | + if ('wpi-refunded' == $from) { |
|
103 | + $form->set_refunded($form->get_refunded() - $invoice->get_total()); |
|
104 | 104 | $form->save(); |
105 | 105 | } |
106 | 106 | |
107 | - if ( 'wpi-refunded' == $to ) { |
|
108 | - $form->set_refunded( $form->get_refunded() + $invoice->get_total() ); |
|
107 | + if ('wpi-refunded' == $to) { |
|
108 | + $form->set_refunded($form->get_refunded() + $invoice->get_total()); |
|
109 | 109 | $form->save(); |
110 | 110 | } |
111 | 111 | |
@@ -118,20 +118,20 @@ discard block |
||
118 | 118 | * @param string $from |
119 | 119 | * @param string $to |
120 | 120 | */ |
121 | - public function update_form_cancelled_amount( $invoice, $from, $to ) { |
|
121 | + public function update_form_cancelled_amount($invoice, $from, $to) { |
|
122 | 122 | |
123 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
124 | - if ( $form->get_id() ) { |
|
123 | + $form = new GetPaid_Payment_Form($invoice->get_payment_form()); |
|
124 | + if ($form->get_id()) { |
|
125 | 125 | return; |
126 | 126 | } |
127 | 127 | |
128 | - if ( 'wpi-cancelled' == $from ) { |
|
129 | - $form->set_cancelled( $form->get_cancelled() - $invoice->get_total() ); |
|
128 | + if ('wpi-cancelled' == $from) { |
|
129 | + $form->set_cancelled($form->get_cancelled() - $invoice->get_total()); |
|
130 | 130 | $form->save(); |
131 | 131 | } |
132 | 132 | |
133 | - if ( 'wpi-cancelled' == $to ) { |
|
134 | - $form->set_cancelled( $form->get_cancelled() + $invoice->get_total() ); |
|
133 | + if ('wpi-cancelled' == $to) { |
|
134 | + $form->set_cancelled($form->get_cancelled() + $invoice->get_total()); |
|
135 | 135 | $form->save(); |
136 | 136 | } |
137 | 137 |
@@ -7,24 +7,24 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | -$bg = wpinv_get_option( 'email_background_color', '#f5f5f5' ); |
|
13 | -$body = wpinv_get_option( 'email_body_background_color', '#fdfdfd' ); |
|
14 | -$base = wpinv_get_option( 'email_base_color', '#557da2' ); |
|
15 | -$base_text = wpinv_light_or_dark( $base, '#202020', '#ffffff' ); |
|
16 | -$text = wpinv_get_option( 'email_text_color', '#505050' ); |
|
12 | +$bg = wpinv_get_option('email_background_color', '#f5f5f5'); |
|
13 | +$body = wpinv_get_option('email_body_background_color', '#fdfdfd'); |
|
14 | +$base = wpinv_get_option('email_base_color', '#557da2'); |
|
15 | +$base_text = wpinv_light_or_dark($base, '#202020', '#ffffff'); |
|
16 | +$text = wpinv_get_option('email_text_color', '#505050'); |
|
17 | 17 | |
18 | -$bg_darker_10 = wpinv_hex_darker( $bg, 10 ); |
|
19 | -$body_darker_10 = wpinv_hex_darker( $body, 10 ); |
|
20 | -$base_lighter_20 = wpinv_hex_lighter( $base, 20 ); |
|
21 | -$base_lighter_40 = wpinv_hex_lighter( $base, 40 ); |
|
22 | -$text_lighter_20 = wpinv_hex_lighter( $text, 20 ); |
|
18 | +$bg_darker_10 = wpinv_hex_darker($bg, 10); |
|
19 | +$body_darker_10 = wpinv_hex_darker($body, 10); |
|
20 | +$base_lighter_20 = wpinv_hex_lighter($base, 20); |
|
21 | +$base_lighter_40 = wpinv_hex_lighter($base, 40); |
|
22 | +$text_lighter_20 = wpinv_hex_lighter($text, 20); |
|
23 | 23 | |
24 | 24 | // !important; is a gmail hack to prevent styles being stripped if it doesn't like something. |
25 | 25 | ?> |
26 | 26 | #wrapper { |
27 | - background-color: <?php echo esc_attr( $bg ); ?>; |
|
27 | + background-color: <?php echo esc_attr($bg); ?>; |
|
28 | 28 | margin: 0; |
29 | 29 | -webkit-text-size-adjust: none !important; |
30 | 30 | padding: 3%; |
@@ -45,15 +45,15 @@ discard block |
||
45 | 45 | |
46 | 46 | #template_container { |
47 | 47 | box-shadow: 0 1px 4px rgba(0,0,0,0.1) !important; |
48 | - background-color: <?php echo esc_attr( $body ); ?>; |
|
49 | - border: 1px solid <?php echo esc_attr( $bg_darker_10 ); ?>; |
|
48 | + background-color: <?php echo esc_attr($body); ?>; |
|
49 | + border: 1px solid <?php echo esc_attr($bg_darker_10); ?>; |
|
50 | 50 | border-radius: 3px !important; |
51 | 51 | } |
52 | 52 | |
53 | 53 | #template_header { |
54 | - background-color: <?php echo esc_attr( $base ); ?>; |
|
54 | + background-color: <?php echo esc_attr($base); ?>; |
|
55 | 55 | border-radius: 3px 3px 0 0 !important; |
56 | - color: <?php echo esc_attr( $base_text ); ?>; |
|
56 | + color: <?php echo esc_attr($base_text); ?>; |
|
57 | 57 | border-bottom: 0; |
58 | 58 | font-weight: bold; |
59 | 59 | line-height: 100%; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | #template_header h1 { |
69 | - color: <?php echo esc_attr( $base_text ); ?>; |
|
69 | + color: <?php echo esc_attr($base_text); ?>; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | #template_footer td { |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | |
78 | 78 | #template_footer #credit { |
79 | 79 | border:0; |
80 | - color: <?php echo esc_attr( $base_lighter_40 ); ?>; |
|
80 | + color: <?php echo esc_attr($base_lighter_40); ?>; |
|
81 | 81 | font-family: Arial; |
82 | 82 | font-size:12px; |
83 | 83 | line-height:125%; |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | } |
87 | 87 | |
88 | 88 | #body_content { |
89 | - background-color: <?php echo esc_attr( $body ); ?>; |
|
89 | + background-color: <?php echo esc_attr($body); ?>; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | #body_content table td { |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | } |
107 | 107 | |
108 | 108 | #body_content_inner { |
109 | - color: <?php echo esc_attr( $text_lighter_20 ); ?>; |
|
109 | + color: <?php echo esc_attr($text_lighter_20); ?>; |
|
110 | 110 | font-family: Arial,Helvetica,sans-serif; |
111 | 111 | font-size: 14px; |
112 | 112 | line-height: 150%; |
@@ -114,17 +114,17 @@ discard block |
||
114 | 114 | } |
115 | 115 | |
116 | 116 | .td { |
117 | - color: <?php echo esc_attr( $text_lighter_20 ); ?>; |
|
118 | - border: 1px solid <?php echo esc_attr( $body_darker_10 ); ?>; |
|
117 | + color: <?php echo esc_attr($text_lighter_20); ?>; |
|
118 | + border: 1px solid <?php echo esc_attr($body_darker_10); ?>; |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | .text { |
122 | - color: <?php echo esc_attr( $text ); ?>; |
|
122 | + color: <?php echo esc_attr($text); ?>; |
|
123 | 123 | font-family: Arial,Helvetica,sans-serif; |
124 | 124 | } |
125 | 125 | |
126 | 126 | .link { |
127 | - color: <?php echo esc_attr( $base ); ?>; |
|
127 | + color: <?php echo esc_attr($base); ?>; |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | #header_wrapper { |
@@ -133,19 +133,19 @@ discard block |
||
133 | 133 | } |
134 | 134 | |
135 | 135 | h1 { |
136 | - color: <?php echo esc_attr( $base ); ?>; |
|
136 | + color: <?php echo esc_attr($base); ?>; |
|
137 | 137 | font-family: Arial,Helvetica,sans-serif; |
138 | 138 | font-size: 30px; |
139 | 139 | font-weight: 300; |
140 | 140 | line-height: 150%; |
141 | 141 | margin: 0; |
142 | 142 | text-align: <?php echo is_rtl() ? 'right' : 'left'; ?>; |
143 | - text-shadow: 0 1px 0 <?php echo esc_attr( $base_lighter_20 ); ?>; |
|
143 | + text-shadow: 0 1px 0 <?php echo esc_attr($base_lighter_20); ?>; |
|
144 | 144 | -webkit-font-smoothing: antialiased; |
145 | 145 | } |
146 | 146 | |
147 | 147 | h2 { |
148 | - color: <?php echo esc_attr( $base ); ?>; |
|
148 | + color: <?php echo esc_attr($base); ?>; |
|
149 | 149 | display: block; |
150 | 150 | font-family: Arial,Helvetica,sans-serif; |
151 | 151 | font-size: 18px; |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | } |
157 | 157 | |
158 | 158 | h3 { |
159 | - color: <?php echo esc_attr( $base ); ?>; |
|
159 | + color: <?php echo esc_attr($base); ?>; |
|
160 | 160 | display: block; |
161 | 161 | font-family: Arial,Helvetica,sans-serif; |
162 | 162 | font-size: 16px; |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | } |
168 | 168 | |
169 | 169 | a { |
170 | - color: <?php echo esc_attr( $base ); ?>; |
|
170 | + color: <?php echo esc_attr($base); ?>; |
|
171 | 171 | font-weight: normal; |
172 | 172 | text-decoration: underline; |
173 | 173 | } |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | } |
186 | 186 | |
187 | 187 | .table-bordered { |
188 | - border: 1px solid <?php echo esc_attr( $body_darker_10 ); ?>; |
|
188 | + border: 1px solid <?php echo esc_attr($body_darker_10); ?>; |
|
189 | 189 | border-collapse: collapse; |
190 | 190 | border-spacing: 0; |
191 | 191 | width: 100%; |
@@ -193,8 +193,8 @@ discard block |
||
193 | 193 | |
194 | 194 | .table-bordered th, |
195 | 195 | .table-bordered td { |
196 | - border: 1px solid <?php echo esc_attr( $body_darker_10 ); ?>; |
|
197 | - color: <?php echo esc_attr( $text_lighter_20 ); ?>; |
|
196 | + border: 1px solid <?php echo esc_attr($body_darker_10); ?>; |
|
197 | + color: <?php echo esc_attr($text_lighter_20); ?>; |
|
198 | 198 | font-size: 14px; |
199 | 199 | } |
200 | 200 | .small { |
@@ -294,9 +294,9 @@ discard block |
||
294 | 294 | text-decoration: none; |
295 | 295 | } |
296 | 296 | .btn-default { |
297 | - color: <?php echo esc_attr( $base_text ); ?>; |
|
298 | - background-color: <?php echo esc_attr( $base ); ?>; |
|
299 | - border-color: <?php echo esc_attr( $base ); ?>; |
|
297 | + color: <?php echo esc_attr($base_text); ?>; |
|
298 | + background-color: <?php echo esc_attr($base); ?>; |
|
299 | + border-color: <?php echo esc_attr($base); ?>; |
|
300 | 300 | } |
301 | 301 | .btn-primary { |
302 | 302 | color: #fff; |
@@ -56,7 +56,7 @@ |
||
56 | 56 | } |
57 | 57 | |
58 | 58 | function wpinv_admin_messages() { |
59 | - settings_errors( 'wpinv-notices' ); |
|
59 | + settings_errors( 'wpinv-notices' ); |
|
60 | 60 | } |
61 | 61 | add_action( 'admin_notices', 'wpinv_admin_messages' ); |
62 | 62 |
@@ -7,81 +7,81 @@ 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 | -function wpinv_bulk_actions( $actions ) { |
|
15 | - if ( isset( $actions['edit'] ) ) { |
|
16 | - unset( $actions['edit'] ); |
|
14 | +function wpinv_bulk_actions($actions) { |
|
15 | + if (isset($actions['edit'])) { |
|
16 | + unset($actions['edit']); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | return $actions; |
20 | 20 | } |
21 | -add_filter( 'bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions' ); |
|
22 | -add_filter( 'bulk_actions-edit-wpi_item', 'wpinv_bulk_actions' ); |
|
21 | +add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions'); |
|
22 | +add_filter('bulk_actions-edit-wpi_item', 'wpinv_bulk_actions'); |
|
23 | 23 | |
24 | -function wpinv_admin_post_id( $id = 0 ) { |
|
24 | +function wpinv_admin_post_id($id = 0) { |
|
25 | 25 | global $post; |
26 | 26 | |
27 | - if ( isset( $id ) && ! empty( $id ) ) { |
|
28 | - return (int)$id; |
|
29 | - } elseif ( get_the_ID() ) { |
|
27 | + if (isset($id) && !empty($id)) { |
|
28 | + return (int) $id; |
|
29 | + } elseif (get_the_ID()) { |
|
30 | 30 | return (int) get_the_ID(); |
31 | - } elseif ( isset( $post->ID ) && ! empty( $post->ID ) ) { |
|
31 | + } elseif (isset($post->ID) && !empty($post->ID)) { |
|
32 | 32 | return (int) $post->ID; |
33 | - } elseif ( isset( $_GET['post'] ) && ! empty( $_GET['post'] ) ) { |
|
33 | + } elseif (isset($_GET['post']) && !empty($_GET['post'])) { |
|
34 | 34 | return (int) $_GET['post']; |
35 | - } elseif ( isset( $_GET['id'] ) && ! empty( $_GET['id'] ) ) { |
|
35 | + } elseif (isset($_GET['id']) && !empty($_GET['id'])) { |
|
36 | 36 | return (int) $_GET['id']; |
37 | - } elseif ( isset( $_POST['id'] ) && ! empty( $_POST['id'] ) ) { |
|
37 | + } elseif (isset($_POST['id']) && !empty($_POST['id'])) { |
|
38 | 38 | return (int) $_POST['id']; |
39 | 39 | } |
40 | 40 | |
41 | 41 | return null; |
42 | 42 | } |
43 | 43 | |
44 | -function wpinv_admin_post_type( $id = 0 ) { |
|
45 | - if ( ! $id ) { |
|
44 | +function wpinv_admin_post_type($id = 0) { |
|
45 | + if (!$id) { |
|
46 | 46 | $id = wpinv_admin_post_id(); |
47 | 47 | } |
48 | 48 | |
49 | - $type = get_post_type( $id ); |
|
49 | + $type = get_post_type($id); |
|
50 | 50 | |
51 | - if ( ! $type ) { |
|
52 | - $type = isset( $_GET['post_type'] ) && ! empty( $_GET['post_type'] ) ? sanitize_text_field( $_GET['post_type'] ) : null; |
|
51 | + if (!$type) { |
|
52 | + $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : null; |
|
53 | 53 | } |
54 | 54 | |
55 | - return apply_filters( 'wpinv_admin_post_type', $type, $id ); |
|
55 | + return apply_filters('wpinv_admin_post_type', $type, $id); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | function wpinv_admin_messages() { |
59 | - settings_errors( 'wpinv-notices' ); |
|
59 | + settings_errors('wpinv-notices'); |
|
60 | 60 | } |
61 | -add_action( 'admin_notices', 'wpinv_admin_messages' ); |
|
61 | +add_action('admin_notices', 'wpinv_admin_messages'); |
|
62 | 62 | |
63 | -add_action( 'admin_init', 'wpinv_show_test_payment_gateway_notice' ); |
|
63 | +add_action('admin_init', 'wpinv_show_test_payment_gateway_notice'); |
|
64 | 64 | function wpinv_show_test_payment_gateway_notice() { |
65 | - add_action( 'admin_notices', 'wpinv_test_payment_gateway_messages' ); |
|
65 | + add_action('admin_notices', 'wpinv_test_payment_gateway_messages'); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | function wpinv_test_payment_gateway_messages() { |
69 | 69 | $gateways = wpinv_get_enabled_payment_gateways(); |
70 | 70 | $name = array(); $test_gateways = ''; |
71 | - if ( $gateways ) { |
|
72 | - foreach ( $gateways as $id => $gateway ) { |
|
73 | - if ( wpinv_is_test_mode( $id ) ) { |
|
71 | + if ($gateways) { |
|
72 | + foreach ($gateways as $id => $gateway) { |
|
73 | + if (wpinv_is_test_mode($id)) { |
|
74 | 74 | $name[] = $gateway['checkout_label']; |
75 | 75 | } |
76 | 76 | } |
77 | - $test_gateways = implode( ', ', $name ); |
|
77 | + $test_gateways = implode(', ', $name); |
|
78 | 78 | } |
79 | - if ( isset( $test_gateways ) && ! empty( $test_gateways ) && wpinv_current_user_can_manage_invoicing() ) { |
|
80 | - $link = admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
81 | - $notice = wp_sprintf( __( '<strong>Important:</strong> Payment Gateway(s) %1$s are in testing mode and will not receive real payments. Go to <a href="%2$s"> Gateway Settings</a>.', 'invoicing' ), $test_gateways, $link ); |
|
79 | + if (isset($test_gateways) && !empty($test_gateways) && wpinv_current_user_can_manage_invoicing()) { |
|
80 | + $link = admin_url('admin.php?page=wpinv-settings&tab=gateways'); |
|
81 | + $notice = wp_sprintf(__('<strong>Important:</strong> Payment Gateway(s) %1$s are in testing mode and will not receive real payments. Go to <a href="%2$s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link); |
|
82 | 82 | ?> |
83 | 83 | <div class="notice notice-warning is-dismissible"> |
84 | - <p><?php echo wp_kses_post( $notice ); ?></p> |
|
84 | + <p><?php echo wp_kses_post($notice); ?></p> |
|
85 | 85 | </div> |
86 | 86 | <?php |
87 | 87 | } |
@@ -95,37 +95,37 @@ discard block |
||
95 | 95 | global $wpdb; |
96 | 96 | |
97 | 97 | // Only do this on our settings page. |
98 | - if ( empty( $_GET['page'] ) || 'wpinv-settings' !== $_GET['page'] ) { |
|
98 | + if (empty($_GET['page']) || 'wpinv-settings' !== $_GET['page']) { |
|
99 | 99 | return; |
100 | 100 | } |
101 | 101 | |
102 | 102 | // Check tables. |
103 | - $tables = array( |
|
103 | + $tables = array( |
|
104 | 104 | "{$wpdb->prefix}wpinv_subscriptions", |
105 | 105 | "{$wpdb->prefix}getpaid_invoices", |
106 | 106 | "{$wpdb->prefix}getpaid_invoice_items", |
107 | 107 | ); |
108 | 108 | |
109 | - foreach ( $tables as $table ) { |
|
110 | - if ( $table != $wpdb->get_var( "SHOW TABLES LIKE '$table'" ) ) { |
|
109 | + foreach ($tables as $table) { |
|
110 | + if ($table != $wpdb->get_var("SHOW TABLES LIKE '$table'")) { |
|
111 | 111 | |
112 | - $url = wp_nonce_url( |
|
113 | - add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ), |
|
112 | + $url = wp_nonce_url( |
|
113 | + add_query_arg('getpaid-admin-action', 'create_missing_tables'), |
|
114 | 114 | 'getpaid-nonce', |
115 | 115 | 'getpaid-nonce' |
116 | 116 | ); |
117 | - $message = __( 'Some GetPaid database tables are missing. To use GetPaid without any issues, click on the button below to create the missing tables.', 'invoicing' ); |
|
118 | - $message2 = __( 'Create Tables', 'invoicing' ); |
|
119 | - echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" ); |
|
117 | + $message = __('Some GetPaid database tables are missing. To use GetPaid without any issues, click on the button below to create the missing tables.', 'invoicing'); |
|
118 | + $message2 = __('Create Tables', 'invoicing'); |
|
119 | + echo wp_kses_post("<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"); |
|
120 | 120 | break; |
121 | 121 | |
122 | 122 | } |
123 | 123 | } |
124 | 124 | |
125 | 125 | } |
126 | -add_action( 'admin_notices', 'wpinv_check_for_missing_tables' ); |
|
126 | +add_action('admin_notices', 'wpinv_check_for_missing_tables'); |
|
127 | 127 | |
128 | -add_action( 'admin_init', 'wpinv_admin_search_by_invoice' ); |
|
128 | +add_action('admin_init', 'wpinv_admin_search_by_invoice'); |
|
129 | 129 | |
130 | 130 | /** |
131 | 131 | * hook the posts search if we're on the admin page for our type |
@@ -133,8 +133,8 @@ discard block |
||
133 | 133 | function wpinv_admin_search_by_invoice() { |
134 | 134 | global $typenow; |
135 | 135 | |
136 | - if ( $typenow === 'wpi_invoice' || $typenow === 'wpi_quote' ) { |
|
137 | - add_filter( 'posts_search', 'wpinv_posts_search_example_type', 10, 2 ); |
|
136 | + if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote') { |
|
137 | + add_filter('posts_search', 'wpinv_posts_search_example_type', 10, 2); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
@@ -144,13 +144,13 @@ discard block |
||
144 | 144 | * @param WP_Query $query |
145 | 145 | * @return string |
146 | 146 | */ |
147 | -function wpinv_posts_search_example_type( $search, $query ) { |
|
147 | +function wpinv_posts_search_example_type($search, $query) { |
|
148 | 148 | global $wpdb; |
149 | 149 | |
150 | - if ( $query->is_main_query() && ! empty( $query->query['s'] ) ) { |
|
151 | - $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql( $query->query['s'] ) . "%' )"; |
|
152 | - if ( ! empty( $search ) ) { |
|
153 | - $search = preg_replace( '/^ AND /', '', $search ); |
|
150 | + if ($query->is_main_query() && !empty($query->query['s'])) { |
|
151 | + $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql($query->query['s']) . "%' )"; |
|
152 | + if (!empty($search)) { |
|
153 | + $search = preg_replace('/^ AND /', '', $search); |
|
154 | 154 | $search = " AND ( {$search} OR ( {$conditions_str} ) )"; |
155 | 155 | } else { |
156 | 156 | $search = " AND ( {$conditions_str} )"; |
@@ -164,16 +164,16 @@ discard block |
||
164 | 164 | * Resets invoice counts. |
165 | 165 | */ |
166 | 166 | function wpinv_reset_invoice_count() { |
167 | - if ( ! empty( $_GET['reset_invoice_count'] ) && isset( $_GET['_nonce'] ) && wp_verify_nonce( sanitize_text_field( $_GET['_nonce'] ), 'reset_invoice_count' ) ) { |
|
168 | - wpinv_update_option( 'invoice_sequence_start', 1 ); |
|
169 | - delete_option( 'wpinv_last_invoice_number' ); |
|
170 | - getpaid_admin()->show_success( __( 'Invoice number sequence reset successfully.', 'invoicing' ) ); |
|
171 | - $url = remove_query_arg( array( 'reset_invoice_count', '_nonce' ) ); |
|
172 | - wp_redirect( $url ); |
|
167 | + if (!empty($_GET['reset_invoice_count']) && isset($_GET['_nonce']) && wp_verify_nonce(sanitize_text_field($_GET['_nonce']), 'reset_invoice_count')) { |
|
168 | + wpinv_update_option('invoice_sequence_start', 1); |
|
169 | + delete_option('wpinv_last_invoice_number'); |
|
170 | + getpaid_admin()->show_success(__('Invoice number sequence reset successfully.', 'invoicing')); |
|
171 | + $url = remove_query_arg(array('reset_invoice_count', '_nonce')); |
|
172 | + wp_redirect($url); |
|
173 | 173 | exit(); |
174 | 174 | } |
175 | 175 | } |
176 | -add_action( 'admin_init', 'wpinv_reset_invoice_count' ); |
|
176 | +add_action('admin_init', 'wpinv_reset_invoice_count'); |
|
177 | 177 | |
178 | 178 | /** |
179 | 179 | * Displays line items on the invoice edit page. |
@@ -182,29 +182,29 @@ discard block |
||
182 | 182 | * @param array $columns |
183 | 183 | * @return string |
184 | 184 | */ |
185 | -function wpinv_admin_get_line_items( $invoice, $columns ) { |
|
185 | +function wpinv_admin_get_line_items($invoice, $columns) { |
|
186 | 186 | |
187 | 187 | ob_start(); |
188 | 188 | |
189 | - do_action( 'getpaid_admin_before_line_items', $invoice ); |
|
189 | + do_action('getpaid_admin_before_line_items', $invoice); |
|
190 | 190 | |
191 | 191 | $count = 0; |
192 | - foreach ( $invoice->get_items() as $item ) { |
|
192 | + foreach ($invoice->get_items() as $item) { |
|
193 | 193 | |
194 | - $item_price = wpinv_price( $item->get_price(), $invoice->get_currency() ); |
|
194 | + $item_price = wpinv_price($item->get_price(), $invoice->get_currency()); |
|
195 | 195 | $quantity = (int) $item->get_quantity(); |
196 | - $item_subtotal = wpinv_price( $item->get_sub_total(), $invoice->get_currency() ); |
|
197 | - $summary = apply_filters( 'getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice ); |
|
196 | + $item_subtotal = wpinv_price($item->get_sub_total(), $invoice->get_currency()); |
|
197 | + $summary = apply_filters('getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice); |
|
198 | 198 | $item_tax = $item->item_tax; |
199 | - $tax_rate = wpinv_round_amount( getpaid_get_invoice_tax_rate( $invoice, $item ), 2, true ) . '%'; |
|
200 | - $tax_rate = empty( $tax_rate ) ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : ''; |
|
199 | + $tax_rate = wpinv_round_amount(getpaid_get_invoice_tax_rate($invoice, $item), 2, true) . '%'; |
|
200 | + $tax_rate = empty($tax_rate) ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : ''; |
|
201 | 201 | $line_item_tax = $item_tax . $tax_rate; |
202 | - $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . esc_attr( $item->get_id() ) . '">'; |
|
202 | + $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . esc_attr($item->get_id()) . '">'; |
|
203 | 203 | $line_item .= '<td class="id">' . (int) $item->get_id() . '</td>'; |
204 | - $line_item .= '<td class="title"><a href="' . get_edit_post_link( $item->get_id() ) . '" target="_blank">' . $item->get_name() . '</a>'; |
|
204 | + $line_item .= '<td class="title"><a href="' . get_edit_post_link($item->get_id()) . '" target="_blank">' . $item->get_name() . '</a>'; |
|
205 | 205 | |
206 | - if ( $summary !== '' ) { |
|
207 | - $line_item .= '<span class="meta">' . wp_kses_post( wpautop( $summary ) ) . '</span>'; |
|
206 | + if ($summary !== '') { |
|
207 | + $line_item .= '<span class="meta">' . wp_kses_post(wpautop($summary)) . '</span>'; |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | $line_item .= '</td>'; |
@@ -212,23 +212,23 @@ discard block |
||
212 | 212 | $line_item .= '<td class="qty" data-quantity="' . $quantity . '"> × ' . $quantity . '</td>'; |
213 | 213 | $line_item .= '<td class="total">' . $item_subtotal . '</td>'; |
214 | 214 | |
215 | - if ( wpinv_use_taxes() && $invoice->is_taxable() ) { |
|
215 | + if (wpinv_use_taxes() && $invoice->is_taxable()) { |
|
216 | 216 | $line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
217 | 217 | } |
218 | 218 | |
219 | 219 | $line_item .= '<td class="action">'; |
220 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
220 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
221 | 221 | $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>'; |
222 | 222 | } |
223 | 223 | $line_item .= '</td>'; |
224 | 224 | $line_item .= '</tr>'; |
225 | 225 | |
226 | - echo wp_kses_post( apply_filters( 'getpaid_admin_line_item', $line_item, $item, $invoice ) ); |
|
226 | + echo wp_kses_post(apply_filters('getpaid_admin_line_item', $line_item, $item, $invoice)); |
|
227 | 227 | |
228 | 228 | $count++; |
229 | 229 | } |
230 | 230 | |
231 | - do_action( 'getpaid_admin_after_line_items', $invoice ); |
|
231 | + do_action('getpaid_admin_after_line_items', $invoice); |
|
232 | 232 | |
233 | 233 | return ob_get_clean(); |
234 | 234 | } |
@@ -13,154 +13,154 @@ |
||
13 | 13 | */ |
14 | 14 | class GetPaid_MaxMind_Database_Service { |
15 | 15 | |
16 | - /** |
|
17 | - * The name of the MaxMind database to utilize. |
|
18 | - */ |
|
19 | - const DATABASE = 'GeoLite2-Country'; |
|
20 | - |
|
21 | - /** |
|
22 | - * The extension for the MaxMind database. |
|
23 | - */ |
|
24 | - const DATABASE_EXTENSION = '.mmdb'; |
|
25 | - |
|
26 | - /** |
|
27 | - * A prefix for the MaxMind database filename. |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - private $database_prefix; |
|
32 | - |
|
33 | - /** |
|
34 | - * Class constructor. |
|
35 | - * |
|
36 | - * @param string|null $database_prefix A prefix for the MaxMind database filename. |
|
37 | - */ |
|
38 | - public function __construct( $database_prefix ) { |
|
39 | - $this->database_prefix = $database_prefix; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Fetches the path that the database should be stored. |
|
44 | - * |
|
45 | - * @return string The local database path. |
|
46 | - */ |
|
47 | - public function get_database_path() { |
|
48 | - $uploads_dir = wp_upload_dir(); |
|
49 | - |
|
50 | - $database_path = trailingslashit( $uploads_dir['basedir'] ) . 'invoicing/'; |
|
51 | - if ( ! empty( $this->database_prefix ) ) { |
|
52 | - $database_path .= $this->database_prefix . '-'; |
|
53 | - } |
|
54 | - $database_path .= self::DATABASE . self::DATABASE_EXTENSION; |
|
55 | - |
|
56 | - // Filter the geolocation database storage path. |
|
57 | - return apply_filters( 'getpaid_maxmind_geolocation_database_path', $database_path ); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Fetches the database from the MaxMind service. |
|
62 | - * |
|
63 | - * @param string $license_key The license key to be used when downloading the database. |
|
64 | - * @return string|WP_Error The path to the database file or an error if invalid. |
|
65 | - */ |
|
66 | - public function download_database( $license_key ) { |
|
67 | - |
|
68 | - $download_uri = add_query_arg( |
|
69 | - array( |
|
70 | - 'edition_id' => self::DATABASE, |
|
71 | - 'license_key' => urlencode( wpinv_clean( $license_key ) ), |
|
72 | - 'suffix' => 'tar.gz', |
|
73 | - ), |
|
74 | - 'https://download.maxmind.com/app/geoip_download' |
|
75 | - ); |
|
76 | - |
|
77 | - // Needed for the download_url call right below. |
|
78 | - require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
79 | - |
|
80 | - $tmp_archive_path = download_url( esc_url_raw( $download_uri ) ); |
|
81 | - |
|
82 | - if ( is_wp_error( $tmp_archive_path ) ) { |
|
83 | - // Transform the error into something more informative. |
|
84 | - $error_data = $tmp_archive_path->get_error_data(); |
|
85 | - if ( isset( $error_data['code'] ) && $error_data['code'] == 401 ) { |
|
86 | - return new WP_Error( |
|
87 | - 'getpaid_maxmind_geolocation_database_license_key', |
|
88 | - __( 'The MaxMind license key is invalid. If you have recently created this key, you may need to wait for it to become active.', 'invoicing' ) |
|
89 | - ); |
|
90 | - } |
|
91 | - |
|
92 | - return new WP_Error( 'getpaid_maxmind_geolocation_database_download', __( 'Failed to download the MaxMind database.', 'invoicing' ) ); |
|
93 | - } |
|
94 | - |
|
95 | - // Extract the database from the archive. |
|
96 | - return $this->extract_downloaded_database( $tmp_archive_path ); |
|
97 | - |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Extracts the downloaded database. |
|
102 | - * |
|
103 | - * @param string $tmp_archive_path The database archive path. |
|
104 | - * @return string|WP_Error The path to the database file or an error if invalid. |
|
105 | - */ |
|
106 | - protected function extract_downloaded_database( $tmp_archive_path ) { |
|
107 | - |
|
108 | - // Extract the database from the archive. |
|
109 | - $tmp_database_path = ''; |
|
110 | - |
|
111 | - try { |
|
112 | - |
|
113 | - $file = new PharData( $tmp_archive_path ); |
|
114 | - $tmp_database_path = trailingslashit( dirname( $tmp_archive_path ) ) . trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION; |
|
115 | - |
|
116 | - $file->extractTo( |
|
117 | - dirname( $tmp_archive_path ), |
|
118 | - trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION, |
|
119 | - true |
|
120 | - ); |
|
121 | - |
|
122 | - } catch ( Exception $exception ) { |
|
123 | - return new WP_Error( 'invoicing_maxmind_geolocation_database_archive', $exception->getMessage() ); |
|
124 | - } finally { |
|
125 | - // Remove the archive since we only care about a single file in it. |
|
126 | - unlink( $tmp_archive_path ); |
|
127 | - } |
|
128 | - |
|
129 | - return $tmp_database_path; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Fetches the ISO country code associated with an IP address. |
|
134 | - * |
|
135 | - * @param string $ip_address The IP address to find the country code for. |
|
136 | - * @return string The country code for the IP address, or empty if not found. |
|
137 | - */ |
|
138 | - public function get_iso_country_code_for_ip( $ip_address ) { |
|
139 | - $country_code = ''; |
|
140 | - |
|
141 | - if ( ! class_exists( 'MaxMind\Db\Reader' ) ) { |
|
142 | - return $country_code; |
|
143 | - } |
|
144 | - |
|
145 | - $database_path = $this->get_database_path(); |
|
146 | - if ( ! file_exists( $database_path ) ) { |
|
147 | - return $country_code; |
|
148 | - } |
|
149 | - |
|
150 | - try { |
|
151 | - $reader = new MaxMind\Db\Reader( $database_path ); |
|
152 | - $data = $reader->get( $ip_address ); |
|
153 | - |
|
154 | - if ( isset( $data['country']['iso_code'] ) ) { |
|
155 | - $country_code = $data['country']['iso_code']; |
|
156 | - } |
|
157 | - |
|
158 | - $reader->close(); |
|
159 | - } catch ( Exception $e ) { |
|
160 | - wpinv_error_log( $e->getMessage(), 'SOURCE: MaxMind GeoLocation' ); |
|
161 | - } |
|
162 | - |
|
163 | - return $country_code; |
|
164 | - } |
|
16 | + /** |
|
17 | + * The name of the MaxMind database to utilize. |
|
18 | + */ |
|
19 | + const DATABASE = 'GeoLite2-Country'; |
|
20 | + |
|
21 | + /** |
|
22 | + * The extension for the MaxMind database. |
|
23 | + */ |
|
24 | + const DATABASE_EXTENSION = '.mmdb'; |
|
25 | + |
|
26 | + /** |
|
27 | + * A prefix for the MaxMind database filename. |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + private $database_prefix; |
|
32 | + |
|
33 | + /** |
|
34 | + * Class constructor. |
|
35 | + * |
|
36 | + * @param string|null $database_prefix A prefix for the MaxMind database filename. |
|
37 | + */ |
|
38 | + public function __construct( $database_prefix ) { |
|
39 | + $this->database_prefix = $database_prefix; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Fetches the path that the database should be stored. |
|
44 | + * |
|
45 | + * @return string The local database path. |
|
46 | + */ |
|
47 | + public function get_database_path() { |
|
48 | + $uploads_dir = wp_upload_dir(); |
|
49 | + |
|
50 | + $database_path = trailingslashit( $uploads_dir['basedir'] ) . 'invoicing/'; |
|
51 | + if ( ! empty( $this->database_prefix ) ) { |
|
52 | + $database_path .= $this->database_prefix . '-'; |
|
53 | + } |
|
54 | + $database_path .= self::DATABASE . self::DATABASE_EXTENSION; |
|
55 | + |
|
56 | + // Filter the geolocation database storage path. |
|
57 | + return apply_filters( 'getpaid_maxmind_geolocation_database_path', $database_path ); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Fetches the database from the MaxMind service. |
|
62 | + * |
|
63 | + * @param string $license_key The license key to be used when downloading the database. |
|
64 | + * @return string|WP_Error The path to the database file or an error if invalid. |
|
65 | + */ |
|
66 | + public function download_database( $license_key ) { |
|
67 | + |
|
68 | + $download_uri = add_query_arg( |
|
69 | + array( |
|
70 | + 'edition_id' => self::DATABASE, |
|
71 | + 'license_key' => urlencode( wpinv_clean( $license_key ) ), |
|
72 | + 'suffix' => 'tar.gz', |
|
73 | + ), |
|
74 | + 'https://download.maxmind.com/app/geoip_download' |
|
75 | + ); |
|
76 | + |
|
77 | + // Needed for the download_url call right below. |
|
78 | + require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
79 | + |
|
80 | + $tmp_archive_path = download_url( esc_url_raw( $download_uri ) ); |
|
81 | + |
|
82 | + if ( is_wp_error( $tmp_archive_path ) ) { |
|
83 | + // Transform the error into something more informative. |
|
84 | + $error_data = $tmp_archive_path->get_error_data(); |
|
85 | + if ( isset( $error_data['code'] ) && $error_data['code'] == 401 ) { |
|
86 | + return new WP_Error( |
|
87 | + 'getpaid_maxmind_geolocation_database_license_key', |
|
88 | + __( 'The MaxMind license key is invalid. If you have recently created this key, you may need to wait for it to become active.', 'invoicing' ) |
|
89 | + ); |
|
90 | + } |
|
91 | + |
|
92 | + return new WP_Error( 'getpaid_maxmind_geolocation_database_download', __( 'Failed to download the MaxMind database.', 'invoicing' ) ); |
|
93 | + } |
|
94 | + |
|
95 | + // Extract the database from the archive. |
|
96 | + return $this->extract_downloaded_database( $tmp_archive_path ); |
|
97 | + |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Extracts the downloaded database. |
|
102 | + * |
|
103 | + * @param string $tmp_archive_path The database archive path. |
|
104 | + * @return string|WP_Error The path to the database file or an error if invalid. |
|
105 | + */ |
|
106 | + protected function extract_downloaded_database( $tmp_archive_path ) { |
|
107 | + |
|
108 | + // Extract the database from the archive. |
|
109 | + $tmp_database_path = ''; |
|
110 | + |
|
111 | + try { |
|
112 | + |
|
113 | + $file = new PharData( $tmp_archive_path ); |
|
114 | + $tmp_database_path = trailingslashit( dirname( $tmp_archive_path ) ) . trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION; |
|
115 | + |
|
116 | + $file->extractTo( |
|
117 | + dirname( $tmp_archive_path ), |
|
118 | + trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION, |
|
119 | + true |
|
120 | + ); |
|
121 | + |
|
122 | + } catch ( Exception $exception ) { |
|
123 | + return new WP_Error( 'invoicing_maxmind_geolocation_database_archive', $exception->getMessage() ); |
|
124 | + } finally { |
|
125 | + // Remove the archive since we only care about a single file in it. |
|
126 | + unlink( $tmp_archive_path ); |
|
127 | + } |
|
128 | + |
|
129 | + return $tmp_database_path; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Fetches the ISO country code associated with an IP address. |
|
134 | + * |
|
135 | + * @param string $ip_address The IP address to find the country code for. |
|
136 | + * @return string The country code for the IP address, or empty if not found. |
|
137 | + */ |
|
138 | + public function get_iso_country_code_for_ip( $ip_address ) { |
|
139 | + $country_code = ''; |
|
140 | + |
|
141 | + if ( ! class_exists( 'MaxMind\Db\Reader' ) ) { |
|
142 | + return $country_code; |
|
143 | + } |
|
144 | + |
|
145 | + $database_path = $this->get_database_path(); |
|
146 | + if ( ! file_exists( $database_path ) ) { |
|
147 | + return $country_code; |
|
148 | + } |
|
149 | + |
|
150 | + try { |
|
151 | + $reader = new MaxMind\Db\Reader( $database_path ); |
|
152 | + $data = $reader->get( $ip_address ); |
|
153 | + |
|
154 | + if ( isset( $data['country']['iso_code'] ) ) { |
|
155 | + $country_code = $data['country']['iso_code']; |
|
156 | + } |
|
157 | + |
|
158 | + $reader->close(); |
|
159 | + } catch ( Exception $e ) { |
|
160 | + wpinv_error_log( $e->getMessage(), 'SOURCE: MaxMind GeoLocation' ); |
|
161 | + } |
|
162 | + |
|
163 | + return $country_code; |
|
164 | + } |
|
165 | 165 | |
166 | 166 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * The service class responsible for interacting with MaxMind databases. |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @param string|null $database_prefix A prefix for the MaxMind database filename. |
37 | 37 | */ |
38 | - public function __construct( $database_prefix ) { |
|
38 | + public function __construct($database_prefix) { |
|
39 | 39 | $this->database_prefix = $database_prefix; |
40 | 40 | } |
41 | 41 | |
@@ -47,14 +47,14 @@ discard block |
||
47 | 47 | public function get_database_path() { |
48 | 48 | $uploads_dir = wp_upload_dir(); |
49 | 49 | |
50 | - $database_path = trailingslashit( $uploads_dir['basedir'] ) . 'invoicing/'; |
|
51 | - if ( ! empty( $this->database_prefix ) ) { |
|
50 | + $database_path = trailingslashit($uploads_dir['basedir']) . 'invoicing/'; |
|
51 | + if (!empty($this->database_prefix)) { |
|
52 | 52 | $database_path .= $this->database_prefix . '-'; |
53 | 53 | } |
54 | 54 | $database_path .= self::DATABASE . self::DATABASE_EXTENSION; |
55 | 55 | |
56 | 56 | // Filter the geolocation database storage path. |
57 | - return apply_filters( 'getpaid_maxmind_geolocation_database_path', $database_path ); |
|
57 | + return apply_filters('getpaid_maxmind_geolocation_database_path', $database_path); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -63,12 +63,12 @@ discard block |
||
63 | 63 | * @param string $license_key The license key to be used when downloading the database. |
64 | 64 | * @return string|WP_Error The path to the database file or an error if invalid. |
65 | 65 | */ |
66 | - public function download_database( $license_key ) { |
|
66 | + public function download_database($license_key) { |
|
67 | 67 | |
68 | 68 | $download_uri = add_query_arg( |
69 | 69 | array( |
70 | 70 | 'edition_id' => self::DATABASE, |
71 | - 'license_key' => urlencode( wpinv_clean( $license_key ) ), |
|
71 | + 'license_key' => urlencode(wpinv_clean($license_key)), |
|
72 | 72 | 'suffix' => 'tar.gz', |
73 | 73 | ), |
74 | 74 | 'https://download.maxmind.com/app/geoip_download' |
@@ -77,23 +77,23 @@ discard block |
||
77 | 77 | // Needed for the download_url call right below. |
78 | 78 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
79 | 79 | |
80 | - $tmp_archive_path = download_url( esc_url_raw( $download_uri ) ); |
|
80 | + $tmp_archive_path = download_url(esc_url_raw($download_uri)); |
|
81 | 81 | |
82 | - if ( is_wp_error( $tmp_archive_path ) ) { |
|
82 | + if (is_wp_error($tmp_archive_path)) { |
|
83 | 83 | // Transform the error into something more informative. |
84 | 84 | $error_data = $tmp_archive_path->get_error_data(); |
85 | - if ( isset( $error_data['code'] ) && $error_data['code'] == 401 ) { |
|
85 | + if (isset($error_data['code']) && $error_data['code'] == 401) { |
|
86 | 86 | return new WP_Error( |
87 | 87 | 'getpaid_maxmind_geolocation_database_license_key', |
88 | - __( 'The MaxMind license key is invalid. If you have recently created this key, you may need to wait for it to become active.', 'invoicing' ) |
|
88 | + __('The MaxMind license key is invalid. If you have recently created this key, you may need to wait for it to become active.', 'invoicing') |
|
89 | 89 | ); |
90 | 90 | } |
91 | 91 | |
92 | - return new WP_Error( 'getpaid_maxmind_geolocation_database_download', __( 'Failed to download the MaxMind database.', 'invoicing' ) ); |
|
92 | + return new WP_Error('getpaid_maxmind_geolocation_database_download', __('Failed to download the MaxMind database.', 'invoicing')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | // Extract the database from the archive. |
96 | - return $this->extract_downloaded_database( $tmp_archive_path ); |
|
96 | + return $this->extract_downloaded_database($tmp_archive_path); |
|
97 | 97 | |
98 | 98 | } |
99 | 99 | |
@@ -103,27 +103,27 @@ discard block |
||
103 | 103 | * @param string $tmp_archive_path The database archive path. |
104 | 104 | * @return string|WP_Error The path to the database file or an error if invalid. |
105 | 105 | */ |
106 | - protected function extract_downloaded_database( $tmp_archive_path ) { |
|
106 | + protected function extract_downloaded_database($tmp_archive_path) { |
|
107 | 107 | |
108 | 108 | // Extract the database from the archive. |
109 | 109 | $tmp_database_path = ''; |
110 | 110 | |
111 | 111 | try { |
112 | 112 | |
113 | - $file = new PharData( $tmp_archive_path ); |
|
114 | - $tmp_database_path = trailingslashit( dirname( $tmp_archive_path ) ) . trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION; |
|
113 | + $file = new PharData($tmp_archive_path); |
|
114 | + $tmp_database_path = trailingslashit(dirname($tmp_archive_path)) . trailingslashit($file->current()->getFilename()) . self::DATABASE . self::DATABASE_EXTENSION; |
|
115 | 115 | |
116 | 116 | $file->extractTo( |
117 | - dirname( $tmp_archive_path ), |
|
118 | - trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION, |
|
117 | + dirname($tmp_archive_path), |
|
118 | + trailingslashit($file->current()->getFilename()) . self::DATABASE . self::DATABASE_EXTENSION, |
|
119 | 119 | true |
120 | 120 | ); |
121 | 121 | |
122 | - } catch ( Exception $exception ) { |
|
123 | - return new WP_Error( 'invoicing_maxmind_geolocation_database_archive', $exception->getMessage() ); |
|
122 | + } catch (Exception $exception) { |
|
123 | + return new WP_Error('invoicing_maxmind_geolocation_database_archive', $exception->getMessage()); |
|
124 | 124 | } finally { |
125 | 125 | // Remove the archive since we only care about a single file in it. |
126 | - unlink( $tmp_archive_path ); |
|
126 | + unlink($tmp_archive_path); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | return $tmp_database_path; |
@@ -135,29 +135,29 @@ discard block |
||
135 | 135 | * @param string $ip_address The IP address to find the country code for. |
136 | 136 | * @return string The country code for the IP address, or empty if not found. |
137 | 137 | */ |
138 | - public function get_iso_country_code_for_ip( $ip_address ) { |
|
138 | + public function get_iso_country_code_for_ip($ip_address) { |
|
139 | 139 | $country_code = ''; |
140 | 140 | |
141 | - if ( ! class_exists( 'MaxMind\Db\Reader' ) ) { |
|
141 | + if (!class_exists('MaxMind\Db\Reader')) { |
|
142 | 142 | return $country_code; |
143 | 143 | } |
144 | 144 | |
145 | 145 | $database_path = $this->get_database_path(); |
146 | - if ( ! file_exists( $database_path ) ) { |
|
146 | + if (!file_exists($database_path)) { |
|
147 | 147 | return $country_code; |
148 | 148 | } |
149 | 149 | |
150 | 150 | try { |
151 | - $reader = new MaxMind\Db\Reader( $database_path ); |
|
152 | - $data = $reader->get( $ip_address ); |
|
151 | + $reader = new MaxMind\Db\Reader($database_path); |
|
152 | + $data = $reader->get($ip_address); |
|
153 | 153 | |
154 | - if ( isset( $data['country']['iso_code'] ) ) { |
|
154 | + if (isset($data['country']['iso_code'])) { |
|
155 | 155 | $country_code = $data['country']['iso_code']; |
156 | 156 | } |
157 | 157 | |
158 | 158 | $reader->close(); |
159 | - } catch ( Exception $e ) { |
|
160 | - wpinv_error_log( $e->getMessage(), 'SOURCE: MaxMind GeoLocation' ); |
|
159 | + } catch (Exception $e) { |
|
160 | + wpinv_error_log($e->getMessage(), 'SOURCE: MaxMind GeoLocation'); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | return $country_code; |
@@ -215,16 +215,16 @@ discard block |
||
215 | 215 | function getpaid_prepare_item_tax( $item, $tax_name, $tax_amount, $recurring_tax_amount ) { |
216 | 216 | |
217 | 217 | $initial_tax = $tax_amount; |
218 | - $recurring_tax = 0; |
|
218 | + $recurring_tax = 0; |
|
219 | 219 | |
220 | 220 | if ( $item->is_recurring() ) { |
221 | - $recurring_tax = $recurring_tax_amount; |
|
222 | - } |
|
221 | + $recurring_tax = $recurring_tax_amount; |
|
222 | + } |
|
223 | 223 | |
224 | - return array( |
|
225 | - 'name' => sanitize_text_field( $tax_name ), |
|
226 | - 'initial_tax' => $initial_tax, |
|
227 | - 'recurring_tax' => $recurring_tax, |
|
224 | + return array( |
|
225 | + 'name' => sanitize_text_field( $tax_name ), |
|
226 | + 'initial_tax' => $initial_tax, |
|
227 | + 'recurring_tax' => $recurring_tax, |
|
228 | 228 | ); |
229 | 229 | |
230 | 230 | } |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | */ |
329 | 329 | function wpinv_should_validate_vat_number() { |
330 | 330 | $validate = wpinv_get_option( 'validate_vat_number' ); |
331 | - return ! empty( $validate ); |
|
331 | + return ! empty( $validate ); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | function wpinv_sales_tax_for_year( $year = null ) { |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Returns an array of eu states. |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * @return array |
13 | 13 | */ |
14 | 14 | function getpaid_get_eu_states() { |
15 | - return wpinv_get_data( 'eu-states' ); |
|
15 | + return wpinv_get_data('eu-states'); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | /** |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @return bool |
22 | 22 | */ |
23 | -function getpaid_is_eu_state( $country ) { |
|
24 | - return ! empty( $country ) && in_array( strtoupper( $country ), getpaid_get_eu_states(), true ) ? true : false; |
|
23 | +function getpaid_is_eu_state($country) { |
|
24 | + return !empty($country) && in_array(strtoupper($country), getpaid_get_eu_states(), true) ? true : false; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @return array |
31 | 31 | */ |
32 | 32 | function getpaid_get_gst_states() { |
33 | - return array( 'AU', 'NZ', 'CA', 'CN' ); |
|
33 | + return array('AU', 'NZ', 'CA', 'CN'); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @return bool |
40 | 40 | */ |
41 | -function getpaid_is_gst_country( $country ) { |
|
42 | - return ! empty( $country ) && in_array( strtoupper( $country ), getpaid_get_gst_states(), true ) ? true : false; |
|
41 | +function getpaid_is_gst_country($country) { |
|
42 | + return !empty($country) && in_array(strtoupper($country), getpaid_get_gst_states(), true) ? true : false; |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | */ |
50 | 50 | function wpinv_use_taxes() { |
51 | 51 | |
52 | - $ret = wpinv_get_option( 'enable_taxes', false ); |
|
53 | - return (bool) apply_filters( 'wpinv_use_taxes', ! empty( $ret ) ); |
|
52 | + $ret = wpinv_get_option('enable_taxes', false); |
|
53 | + return (bool) apply_filters('wpinv_use_taxes', !empty($ret)); |
|
54 | 54 | |
55 | 55 | } |
56 | 56 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @param WPInv_Invoice $invoice |
61 | 61 | * @return bool |
62 | 62 | */ |
63 | -function wpinv_is_invoice_taxable( $invoice ) { |
|
63 | +function wpinv_is_invoice_taxable($invoice) { |
|
64 | 64 | return $invoice->is_taxable(); |
65 | 65 | } |
66 | 66 | |
@@ -70,11 +70,11 @@ discard block |
||
70 | 70 | * @param string $country |
71 | 71 | * @return bool |
72 | 72 | */ |
73 | -function wpinv_is_country_taxable( $country ) { |
|
74 | - $is_eu = getpaid_is_eu_state( $country ); |
|
75 | - $is_exempt = ! $is_eu && wpinv_is_base_country( $country ) && wpinv_same_country_exempt_vat(); |
|
73 | +function wpinv_is_country_taxable($country) { |
|
74 | + $is_eu = getpaid_is_eu_state($country); |
|
75 | + $is_exempt = !$is_eu && wpinv_is_base_country($country) && wpinv_same_country_exempt_vat(); |
|
76 | 76 | |
77 | - return (bool) apply_filters( 'wpinv_is_country_taxable', ! $is_exempt, $country ); |
|
77 | + return (bool) apply_filters('wpinv_is_country_taxable', !$is_exempt, $country); |
|
78 | 78 | |
79 | 79 | } |
80 | 80 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @param WPInv_Item|GetPaid_Form_Item $item |
85 | 85 | * @return bool |
86 | 86 | */ |
87 | -function wpinv_is_item_taxable( $item ) { |
|
87 | +function wpinv_is_item_taxable($item) { |
|
88 | 88 | return '_exempt' !== $item->get_vat_rule(); |
89 | 89 | } |
90 | 90 | |
@@ -93,15 +93,15 @@ discard block |
||
93 | 93 | * |
94 | 94 | * @return bool |
95 | 95 | */ |
96 | -function wpinv_use_store_address_as_tax_base( $tax_rule = false ) { |
|
97 | - $use_base = wpinv_get_option( 'tax_base', 'billing' ) === 'base'; |
|
96 | +function wpinv_use_store_address_as_tax_base($tax_rule = false) { |
|
97 | + $use_base = wpinv_get_option('tax_base', 'billing') === 'base'; |
|
98 | 98 | |
99 | - if ( $tax_rule ) { |
|
100 | - $rules = getpaid_get_tax_rules( 'tax_base' ); |
|
101 | - $use_base = isset( $rules[ $tax_rule ] ) ? 'base' === $rules[ $tax_rule ] : $use_base; |
|
99 | + if ($tax_rule) { |
|
100 | + $rules = getpaid_get_tax_rules('tax_base'); |
|
101 | + $use_base = isset($rules[$tax_rule]) ? 'base' === $rules[$tax_rule] : $use_base; |
|
102 | 102 | } |
103 | 103 | |
104 | - return (bool) apply_filters( 'wpinv_use_store_address_as_tax_base', $use_base, $tax_rule ); |
|
104 | + return (bool) apply_filters('wpinv_use_store_address_as_tax_base', $use_base, $tax_rule); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -109,15 +109,15 @@ discard block |
||
109 | 109 | * |
110 | 110 | * @return bool |
111 | 111 | */ |
112 | -function wpinv_get_vat_same_country_rule( $tax_rule = false ) { |
|
113 | - $rule = wpinv_get_option( 'vat_same_country_rule', 'vat_too' ); |
|
112 | +function wpinv_get_vat_same_country_rule($tax_rule = false) { |
|
113 | + $rule = wpinv_get_option('vat_same_country_rule', 'vat_too'); |
|
114 | 114 | |
115 | - if ( $tax_rule ) { |
|
116 | - $rules = getpaid_get_tax_rules( 'same_country_rule' ); |
|
117 | - $rule = isset( $rules[ $tax_rule ] ) ? $rules[ $tax_rule ] : $rule; |
|
115 | + if ($tax_rule) { |
|
116 | + $rules = getpaid_get_tax_rules('same_country_rule'); |
|
117 | + $rule = isset($rules[$tax_rule]) ? $rules[$tax_rule] : $rule; |
|
118 | 118 | } |
119 | 119 | |
120 | - return (bool) apply_filters( 'wpinv_get_vat_same_country_rule', $rule, $tax_rule ); |
|
120 | + return (bool) apply_filters('wpinv_get_vat_same_country_rule', $rule, $tax_rule); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | * @return bool |
127 | 127 | */ |
128 | 128 | function wpinv_prices_include_tax() { |
129 | - $is_inclusive = wpinv_get_option( 'prices_include_tax', 'no' ) === 'yes'; |
|
130 | - return (bool) apply_filters( 'wpinv_prices_include_tax', $is_inclusive ); |
|
129 | + $is_inclusive = wpinv_get_option('prices_include_tax', 'no') === 'yes'; |
|
130 | + return (bool) apply_filters('wpinv_prices_include_tax', $is_inclusive); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | * @return bool |
137 | 137 | */ |
138 | 138 | function wpinv_round_tax_per_tax_rate() { |
139 | - $subtotal_rounding = wpinv_get_option( 'tax_subtotal_rounding', 1 ); |
|
140 | - return (bool) apply_filters( 'wpinv_round_tax_per_tax_rate', empty( $subtotal_rounding ) ); |
|
139 | + $subtotal_rounding = wpinv_get_option('tax_subtotal_rounding', 1); |
|
140 | + return (bool) apply_filters('wpinv_round_tax_per_tax_rate', empty($subtotal_rounding)); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | * @return bool |
147 | 147 | */ |
148 | 148 | function wpinv_display_individual_tax_rates() { |
149 | - $individual = wpinv_get_option( 'tax_display_totals', 'single' ) === 'individual'; |
|
150 | - return (bool) apply_filters( 'wpinv_display_individual_tax_rates', $individual ); |
|
149 | + $individual = wpinv_get_option('tax_display_totals', 'single') === 'individual'; |
|
150 | + return (bool) apply_filters('wpinv_display_individual_tax_rates', $individual); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -156,8 +156,8 @@ discard block |
||
156 | 156 | * @return float |
157 | 157 | */ |
158 | 158 | function wpinv_get_default_tax_rate() { |
159 | - $rate = wpinv_get_option( 'tax_rate', 0 ); |
|
160 | - return (float) apply_filters( 'wpinv_get_default_tax_rate', floatval( $rate ) ); |
|
159 | + $rate = wpinv_get_option('tax_rate', 0); |
|
160 | + return (float) apply_filters('wpinv_get_default_tax_rate', floatval($rate)); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * @return bool |
167 | 167 | */ |
168 | 168 | function wpinv_same_country_exempt_vat() { |
169 | - return 'no' === wpinv_get_option( 'vat_same_country_rule', 'vat_too' ); |
|
169 | + return 'no' === wpinv_get_option('vat_same_country_rule', 'vat_too'); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -186,28 +186,28 @@ discard block |
||
186 | 186 | * @param string $state |
187 | 187 | * @return array |
188 | 188 | */ |
189 | -function getpaid_get_item_tax_rates( $item, $country = '', $state = '' ) { |
|
189 | +function getpaid_get_item_tax_rates($item, $country = '', $state = '') { |
|
190 | 190 | |
191 | 191 | // Abort if the item is not taxable. |
192 | - if ( ! wpinv_is_item_taxable( $item ) ) { |
|
192 | + if (!wpinv_is_item_taxable($item)) { |
|
193 | 193 | return array(); |
194 | 194 | } |
195 | 195 | |
196 | 196 | // Maybe use the store address. |
197 | - if ( wpinv_use_store_address_as_tax_base( $item->get_vat_rule() ) ) { |
|
197 | + if (wpinv_use_store_address_as_tax_base($item->get_vat_rule())) { |
|
198 | 198 | $country = wpinv_get_default_country(); |
199 | 199 | $state = wpinv_get_default_state(); |
200 | 200 | } |
201 | 201 | |
202 | 202 | // Retrieve tax rates. |
203 | - $tax_rates = GetPaid_Tax::get_address_tax_rates( $country, $state ); |
|
203 | + $tax_rates = GetPaid_Tax::get_address_tax_rates($country, $state); |
|
204 | 204 | |
205 | 205 | // Fallback to the default tax rates if non were found. |
206 | - if ( empty( $tax_rates ) ) { |
|
206 | + if (empty($tax_rates)) { |
|
207 | 207 | $tax_rates = GetPaid_Tax::get_default_tax_rates(); |
208 | 208 | } |
209 | 209 | |
210 | - return apply_filters( 'getpaid_get_item_tax_rates', $tax_rates, $item, $country, $state ); |
|
210 | + return apply_filters('getpaid_get_item_tax_rates', $tax_rates, $item, $country, $state); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
@@ -217,22 +217,22 @@ discard block |
||
217 | 217 | * @param array $rates |
218 | 218 | * @return array |
219 | 219 | */ |
220 | -function getpaid_filter_item_tax_rates( $item, $rates ) { |
|
220 | +function getpaid_filter_item_tax_rates($item, $rates) { |
|
221 | 221 | |
222 | 222 | $tax_class = $item->get_vat_class(); |
223 | 223 | |
224 | - foreach ( $rates as $i => $rate ) { |
|
224 | + foreach ($rates as $i => $rate) { |
|
225 | 225 | |
226 | - if ( '_reduced' === $tax_class ) { |
|
227 | - $rates[ $i ]['rate'] = empty( $rate['reduced_rate'] ) ? 0 : $rate['reduced_rate']; |
|
226 | + if ('_reduced' === $tax_class) { |
|
227 | + $rates[$i]['rate'] = empty($rate['reduced_rate']) ? 0 : $rate['reduced_rate']; |
|
228 | 228 | } |
229 | 229 | |
230 | - if ( '_exempt' === $tax_class ) { |
|
231 | - $rates[ $i ]['rate'] = 0; |
|
230 | + if ('_exempt' === $tax_class) { |
|
231 | + $rates[$i]['rate'] = 0; |
|
232 | 232 | } |
233 | 233 | } |
234 | 234 | |
235 | - return apply_filters( 'getpaid_filter_item_tax_rates', $rates, $item ); |
|
235 | + return apply_filters('getpaid_filter_item_tax_rates', $rates, $item); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
@@ -242,12 +242,12 @@ discard block |
||
242 | 242 | * @param array $rates |
243 | 243 | * @return array |
244 | 244 | */ |
245 | -function getpaid_calculate_item_taxes( $amount, $rates ) { |
|
245 | +function getpaid_calculate_item_taxes($amount, $rates) { |
|
246 | 246 | |
247 | 247 | $is_inclusive = wpinv_prices_include_tax(); |
248 | - $taxes = GetPaid_Tax::calc_tax( $amount, $rates, $is_inclusive ); |
|
248 | + $taxes = GetPaid_Tax::calc_tax($amount, $rates, $is_inclusive); |
|
249 | 249 | |
250 | - return apply_filters( 'getpaid_calculate_taxes', $taxes, $amount, $rates ); |
|
250 | + return apply_filters('getpaid_calculate_taxes', $taxes, $amount, $rates); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -259,17 +259,17 @@ discard block |
||
259 | 259 | * @param float $recurring_tax_amount |
260 | 260 | * @return array |
261 | 261 | */ |
262 | -function getpaid_prepare_item_tax( $item, $tax_name, $tax_amount, $recurring_tax_amount ) { |
|
262 | +function getpaid_prepare_item_tax($item, $tax_name, $tax_amount, $recurring_tax_amount) { |
|
263 | 263 | |
264 | - $initial_tax = $tax_amount; |
|
264 | + $initial_tax = $tax_amount; |
|
265 | 265 | $recurring_tax = 0; |
266 | 266 | |
267 | - if ( $item->is_recurring() ) { |
|
267 | + if ($item->is_recurring()) { |
|
268 | 268 | $recurring_tax = $recurring_tax_amount; |
269 | 269 | } |
270 | 270 | |
271 | 271 | return array( |
272 | - 'name' => sanitize_text_field( $tax_name ), |
|
272 | + 'name' => sanitize_text_field($tax_name), |
|
273 | 273 | 'initial_tax' => $initial_tax, |
274 | 274 | 'recurring_tax' => $recurring_tax, |
275 | 275 | ); |
@@ -282,8 +282,8 @@ discard block |
||
282 | 282 | * @param string $vat_number |
283 | 283 | * @return string |
284 | 284 | */ |
285 | -function wpinv_sanitize_vat_number( $vat_number ) { |
|
286 | - return str_replace( array( ' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) ); |
|
285 | +function wpinv_sanitize_vat_number($vat_number) { |
|
286 | + return str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number))); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | /** |
@@ -292,22 +292,22 @@ discard block |
||
292 | 292 | * @param string $vat_number |
293 | 293 | * @return bool |
294 | 294 | */ |
295 | -function wpinv_regex_validate_vat_number( $vat_number ) { |
|
295 | +function wpinv_regex_validate_vat_number($vat_number) { |
|
296 | 296 | |
297 | - $country = substr( $vat_number, 0, 2 ); |
|
298 | - $vatin = substr( $vat_number, 2 ); |
|
299 | - $regexes = wpinv_get_data( 'vat-number-regexes' ); |
|
297 | + $country = substr($vat_number, 0, 2); |
|
298 | + $vatin = substr($vat_number, 2); |
|
299 | + $regexes = wpinv_get_data('vat-number-regexes'); |
|
300 | 300 | |
301 | - if ( isset( $regexes[ $country ] ) ) { |
|
301 | + if (isset($regexes[$country])) { |
|
302 | 302 | |
303 | - $regex = $regexes[ $country ]; |
|
303 | + $regex = $regexes[$country]; |
|
304 | 304 | $regex = '/^(?:' . $regex . ')$/'; |
305 | - return 1 === preg_match( $regex, $vatin ); |
|
305 | + return 1 === preg_match($regex, $vatin); |
|
306 | 306 | |
307 | 307 | } |
308 | 308 | |
309 | 309 | // Not an EU state, use filters to validate the number. |
310 | - return apply_filters( 'wpinv_regex_validate_vat_number', true, $vat_number ); |
|
310 | + return apply_filters('wpinv_regex_validate_vat_number', true, $vat_number); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | /** |
@@ -316,29 +316,29 @@ discard block |
||
316 | 316 | * @param string $vat_number |
317 | 317 | * @return bool |
318 | 318 | */ |
319 | -function wpinv_vies_validate_vat_number( $vat_number ) { |
|
319 | +function wpinv_vies_validate_vat_number($vat_number) { |
|
320 | 320 | |
321 | - $country = substr( $vat_number, 0, 2 ); |
|
322 | - $vatin = substr( $vat_number, 2 ); |
|
321 | + $country = substr($vat_number, 0, 2); |
|
322 | + $vatin = substr($vat_number, 2); |
|
323 | 323 | |
324 | 324 | $url = add_query_arg( |
325 | 325 | array( |
326 | - 'ms' => rawurlencode( $country ), |
|
327 | - 'iso' => rawurlencode( $country ), |
|
328 | - 'vat' => rawurlencode( $vatin ), |
|
326 | + 'ms' => rawurlencode($country), |
|
327 | + 'iso' => rawurlencode($country), |
|
328 | + 'vat' => rawurlencode($vatin), |
|
329 | 329 | ), |
330 | 330 | 'http://ec.europa.eu/taxation_customs/vies/viesquer.do' |
331 | 331 | ); |
332 | 332 | |
333 | - $response = wp_remote_get( $url ); |
|
334 | - $response = wp_remote_retrieve_body( $response ); |
|
333 | + $response = wp_remote_get($url); |
|
334 | + $response = wp_remote_retrieve_body($response); |
|
335 | 335 | |
336 | 336 | // Fallback gracefully if the VIES website is down. |
337 | - if ( empty( $response ) ) { |
|
337 | + if (empty($response)) { |
|
338 | 338 | return true; |
339 | 339 | } |
340 | 340 | |
341 | - return 1 !== preg_match( '/invalid VAT number/i', $response ); |
|
341 | + return 1 !== preg_match('/invalid VAT number/i', $response); |
|
342 | 342 | |
343 | 343 | } |
344 | 344 | |
@@ -349,17 +349,17 @@ discard block |
||
349 | 349 | * @param string $country |
350 | 350 | * @return bool |
351 | 351 | */ |
352 | -function wpinv_validate_vat_number( $vat_number, $country ) { |
|
352 | +function wpinv_validate_vat_number($vat_number, $country) { |
|
353 | 353 | |
354 | 354 | // In case the vat number does not have a country code... |
355 | - $vat_number = wpinv_sanitize_vat_number( $vat_number ); |
|
356 | - $_country = substr( $vat_number, 0, 2 ); |
|
355 | + $vat_number = wpinv_sanitize_vat_number($vat_number); |
|
356 | + $_country = substr($vat_number, 0, 2); |
|
357 | 357 | |
358 | - if ( wpinv_country_name( $_country ) === $_country ) { |
|
359 | - $vat_number = strtoupper( $country ) . $vat_number; |
|
358 | + if (wpinv_country_name($_country) === $_country) { |
|
359 | + $vat_number = strtoupper($country) . $vat_number; |
|
360 | 360 | } |
361 | 361 | |
362 | - return wpinv_regex_validate_vat_number( $vat_number ) && wpinv_vies_validate_vat_number( $vat_number ); |
|
362 | + return wpinv_regex_validate_vat_number($vat_number) && wpinv_vies_validate_vat_number($vat_number); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
@@ -368,39 +368,39 @@ discard block |
||
368 | 368 | * @return bool |
369 | 369 | */ |
370 | 370 | function wpinv_should_validate_vat_number() { |
371 | - $validate = wpinv_get_option( 'validate_vat_number' ); |
|
372 | - return ! empty( $validate ); |
|
371 | + $validate = wpinv_get_option('validate_vat_number'); |
|
372 | + return !empty($validate); |
|
373 | 373 | } |
374 | 374 | |
375 | -function wpinv_sales_tax_for_year( $year = null ) { |
|
376 | - return wpinv_price( wpinv_get_sales_tax_for_year( $year ) ); |
|
375 | +function wpinv_sales_tax_for_year($year = null) { |
|
376 | + return wpinv_price(wpinv_get_sales_tax_for_year($year)); |
|
377 | 377 | } |
378 | 378 | |
379 | -function wpinv_get_sales_tax_for_year( $year = null ) { |
|
379 | +function wpinv_get_sales_tax_for_year($year = null) { |
|
380 | 380 | global $wpdb; |
381 | 381 | |
382 | 382 | // Start at zero |
383 | 383 | $tax = 0; |
384 | 384 | |
385 | - if ( ! empty( $year ) ) { |
|
385 | + if (!empty($year)) { |
|
386 | 386 | $args = array( |
387 | 387 | 'post_type' => 'wpi_invoice', |
388 | - 'post_status' => array( 'publish' ), |
|
388 | + 'post_status' => array('publish'), |
|
389 | 389 | 'posts_per_page' => -1, |
390 | 390 | 'year' => $year, |
391 | 391 | 'fields' => 'ids', |
392 | 392 | ); |
393 | 393 | |
394 | - $payments = get_posts( $args ); |
|
395 | - $payment_ids = implode( ',', $payments ); |
|
394 | + $payments = get_posts($args); |
|
395 | + $payment_ids = implode(',', $payments); |
|
396 | 396 | |
397 | - if ( count( $payments ) > 0 ) { |
|
397 | + if (count($payments) > 0) { |
|
398 | 398 | $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )"; |
399 | - $tax = $wpdb->get_var( $sql ); |
|
399 | + $tax = $wpdb->get_var($sql); |
|
400 | 400 | } |
401 | 401 | } |
402 | 402 | |
403 | - return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year ); |
|
403 | + return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | function wpinv_is_cart_taxed() { |
@@ -409,34 +409,34 @@ discard block |
||
409 | 409 | |
410 | 410 | function wpinv_prices_show_tax_on_checkout() { |
411 | 411 | return false; // TODO |
412 | - $ret = ( wpinv_get_option( 'checkout_include_tax', false ) === 'yes' && wpinv_use_taxes() ); |
|
412 | + $ret = (wpinv_get_option('checkout_include_tax', false) === 'yes' && wpinv_use_taxes()); |
|
413 | 413 | |
414 | - return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret ); |
|
414 | + return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | function wpinv_display_tax_rate() { |
418 | - $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false ); |
|
418 | + $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false); |
|
419 | 419 | |
420 | - return apply_filters( 'wpinv_display_tax_rate', $ret ); |
|
420 | + return apply_filters('wpinv_display_tax_rate', $ret); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | function wpinv_cart_needs_tax_address_fields() { |
424 | - if ( ! wpinv_is_cart_taxed() ) { |
|
424 | + if (!wpinv_is_cart_taxed()) { |
|
425 | 425 | return false; |
426 | 426 | } |
427 | 427 | |
428 | - return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' ); |
|
428 | + return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields'); |
|
429 | 429 | } |
430 | 430 | |
431 | -function wpinv_item_is_tax_exclusive( $item_id = 0 ) { |
|
432 | - $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false ); |
|
433 | - return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id ); |
|
431 | +function wpinv_item_is_tax_exclusive($item_id = 0) { |
|
432 | + $ret = (bool) get_post_meta($item_id, '_wpinv_tax_exclusive', false); |
|
433 | + return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id); |
|
434 | 434 | } |
435 | 435 | |
436 | -function wpinv_currency_decimal_filter( $decimals = 2 ) { |
|
436 | +function wpinv_currency_decimal_filter($decimals = 2) { |
|
437 | 437 | $currency = wpinv_get_currency(); |
438 | 438 | |
439 | - switch ( $currency ) { |
|
439 | + switch ($currency) { |
|
440 | 440 | case 'RIAL': |
441 | 441 | case 'JPY': |
442 | 442 | case 'TWD': |
@@ -445,13 +445,13 @@ discard block |
||
445 | 445 | break; |
446 | 446 | } |
447 | 447 | |
448 | - return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency ); |
|
448 | + return apply_filters('wpinv_currency_decimal_count', $decimals, $currency); |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | function wpinv_tax_amount() { |
452 | 452 | $output = 0.00; |
453 | 453 | |
454 | - return apply_filters( 'wpinv_tax_amount', $output ); |
|
454 | + return apply_filters('wpinv_tax_amount', $output); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | /** |
@@ -459,25 +459,25 @@ discard block |
||
459 | 459 | * |
460 | 460 | * @param string|bool|null $vat_rule |
461 | 461 | */ |
462 | -function getpaid_filter_vat_rule( $vat_rule ) { |
|
462 | +function getpaid_filter_vat_rule($vat_rule) { |
|
463 | 463 | |
464 | - if ( empty( $vat_rule ) ) { |
|
464 | + if (empty($vat_rule)) { |
|
465 | 465 | return 'digital'; |
466 | 466 | } |
467 | 467 | |
468 | 468 | return $vat_rule; |
469 | 469 | } |
470 | -add_filter( 'wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule' ); |
|
470 | +add_filter('wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule'); |
|
471 | 471 | |
472 | 472 | /** |
473 | 473 | * Filters the VAT class to ensure that each item has a VAT class. |
474 | 474 | * |
475 | 475 | * @param string|bool|null $vat_rule |
476 | 476 | */ |
477 | -function getpaid_filter_vat_class( $vat_class ) { |
|
478 | - return empty( $vat_class ) ? '_standard' : $vat_class; |
|
477 | +function getpaid_filter_vat_class($vat_class) { |
|
478 | + return empty($vat_class) ? '_standard' : $vat_class; |
|
479 | 479 | } |
480 | -add_filter( 'wpinv_get_item_vat_class', 'getpaid_filter_vat_class' ); |
|
480 | +add_filter('wpinv_get_item_vat_class', 'getpaid_filter_vat_class'); |
|
481 | 481 | |
482 | 482 | /** |
483 | 483 | * Returns a list of all tax classes. |
@@ -489,9 +489,9 @@ discard block |
||
489 | 489 | return apply_filters( |
490 | 490 | 'getpaid_tax_classes', |
491 | 491 | array( |
492 | - '_standard' => __( 'Standard Tax Rate', 'invoicing' ), |
|
493 | - '_reduced' => __( 'Reduced Tax Rate', 'invoicing' ), |
|
494 | - '_exempt' => __( 'Tax Exempt', 'invoicing' ), |
|
492 | + '_standard' => __('Standard Tax Rate', 'invoicing'), |
|
493 | + '_reduced' => __('Reduced Tax Rate', 'invoicing'), |
|
494 | + '_exempt' => __('Tax Exempt', 'invoicing'), |
|
495 | 495 | ) |
496 | 496 | ); |
497 | 497 | |
@@ -502,8 +502,8 @@ discard block |
||
502 | 502 | * |
503 | 503 | * @return array |
504 | 504 | */ |
505 | -function getpaid_get_tax_rules( $return = 'label' ) { |
|
506 | - return wp_list_pluck( GetPaid_Tax::get_all_tax_rules(), $return, 'key' ); |
|
505 | +function getpaid_get_tax_rules($return = 'label') { |
|
506 | + return wp_list_pluck(GetPaid_Tax::get_all_tax_rules(), $return, 'key'); |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | /** |
@@ -512,15 +512,15 @@ discard block |
||
512 | 512 | * @param string $tax_class |
513 | 513 | * @return string |
514 | 514 | */ |
515 | -function getpaid_get_tax_class_label( $tax_class ) { |
|
515 | +function getpaid_get_tax_class_label($tax_class) { |
|
516 | 516 | |
517 | 517 | $classes = getpaid_get_tax_classes(); |
518 | 518 | |
519 | - if ( isset( $classes[ $tax_class ] ) ) { |
|
520 | - return sanitize_text_field( $classes[ $tax_class ] ); |
|
519 | + if (isset($classes[$tax_class])) { |
|
520 | + return sanitize_text_field($classes[$tax_class]); |
|
521 | 521 | } |
522 | 522 | |
523 | - return sanitize_text_field( $tax_class ); |
|
523 | + return sanitize_text_field($tax_class); |
|
524 | 524 | |
525 | 525 | } |
526 | 526 | |
@@ -530,15 +530,15 @@ discard block |
||
530 | 530 | * @param string $tax_rule |
531 | 531 | * @return string |
532 | 532 | */ |
533 | -function getpaid_get_tax_rule_label( $tax_rule ) { |
|
533 | +function getpaid_get_tax_rule_label($tax_rule) { |
|
534 | 534 | |
535 | 535 | $rules = getpaid_get_tax_rules(); |
536 | 536 | |
537 | - if ( isset( $rules[ $tax_rule ] ) ) { |
|
538 | - return sanitize_text_field( $rules[ $tax_rule ] ); |
|
537 | + if (isset($rules[$tax_rule])) { |
|
538 | + return sanitize_text_field($rules[$tax_rule]); |
|
539 | 539 | } |
540 | 540 | |
541 | - return sanitize_text_field( $tax_rule ); |
|
541 | + return sanitize_text_field($tax_rule); |
|
542 | 542 | |
543 | 543 | } |
544 | 544 | |
@@ -549,11 +549,11 @@ discard block |
||
549 | 549 | * @param string $recurring |
550 | 550 | * @return string |
551 | 551 | */ |
552 | -function getpaid_get_taxable_amount( $item, $recurring = false ) { |
|
552 | +function getpaid_get_taxable_amount($item, $recurring = false) { |
|
553 | 553 | |
554 | 554 | $taxable_amount = $recurring ? $item->get_recurring_sub_total() : $item->get_sub_total(); |
555 | 555 | $taxable_amount -= $recurring ? $item->recurring_item_discount : $item->item_discount; |
556 | - $taxable_amount = max( 0, $taxable_amount ); |
|
557 | - return apply_filters( 'getpaid_taxable_amount', $taxable_amount, $item, $recurring ); |
|
556 | + $taxable_amount = max(0, $taxable_amount); |
|
557 | + return apply_filters('getpaid_taxable_amount', $taxable_amount, $item, $recurring); |
|
558 | 558 | |
559 | 559 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | class GetPaid_Meta_Box_Item_VAT { |
18 | 18 | |
19 | 19 | /** |
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | 24 | public static function output( $post ) { |
25 | 25 | |
26 | 26 | // Prepare the item. |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | - * Output the VAT rules settings. |
|
50 | - * |
|
51 | - * @param WPInv_Item $item |
|
52 | - */ |
|
49 | + * Output the VAT rules settings. |
|
50 | + * |
|
51 | + * @param WPInv_Item $item |
|
52 | + */ |
|
53 | 53 | public static function output_vat_rules( $item ) { |
54 | 54 | ?> |
55 | 55 | |
@@ -87,10 +87,10 @@ discard block |
||
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
90 | - * Output the VAT class settings. |
|
91 | - * |
|
92 | - * @param WPInv_Item $item |
|
93 | - */ |
|
90 | + * Output the VAT class settings. |
|
91 | + * |
|
92 | + * @param WPInv_Item $item |
|
93 | + */ |
|
94 | 94 | public static function output_vat_classes( $item ) { |
95 | 95 | ?> |
96 | 96 |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if (!defined('ABSPATH')) { |
|
11 | 11 | exit; // Exit if accessed directly |
12 | 12 | } |
13 | 13 | |
@@ -21,26 +21,26 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param WP_Post $post |
23 | 23 | */ |
24 | - public static function output( $post ) { |
|
24 | + public static function output($post) { |
|
25 | 25 | |
26 | 26 | // Prepare the item. |
27 | - $item = new WPInv_Item( $post ); |
|
27 | + $item = new WPInv_Item($post); |
|
28 | 28 | |
29 | 29 | echo "<div class='bsui' style='max-width: 600px;padding-top: 10px;'>"; |
30 | 30 | |
31 | - do_action( 'wpinv_item_before_vat_metabox', $item ); |
|
31 | + do_action('wpinv_item_before_vat_metabox', $item); |
|
32 | 32 | |
33 | 33 | // Output the vat rules settings. |
34 | - do_action( 'wpinv_item_vat_metabox_before_vat_rules', $item ); |
|
35 | - self::output_vat_rules( $item ); |
|
36 | - do_action( 'wpinv_item_vat_metabox_vat_rules', $item ); |
|
34 | + do_action('wpinv_item_vat_metabox_before_vat_rules', $item); |
|
35 | + self::output_vat_rules($item); |
|
36 | + do_action('wpinv_item_vat_metabox_vat_rules', $item); |
|
37 | 37 | |
38 | 38 | // Output vat class settings. |
39 | - do_action( 'wpinv_item_vat_metabox_before_vat_rules', $item ); |
|
40 | - self::output_vat_classes( $item ); |
|
41 | - do_action( 'wpinv_item_vat_metabox_vat_class', $item ); |
|
39 | + do_action('wpinv_item_vat_metabox_before_vat_rules', $item); |
|
40 | + self::output_vat_classes($item); |
|
41 | + do_action('wpinv_item_vat_metabox_vat_class', $item); |
|
42 | 42 | |
43 | - do_action( 'wpinv_item_vat_metabox', $item ); |
|
43 | + do_action('wpinv_item_vat_metabox', $item); |
|
44 | 44 | |
45 | 45 | echo '</div>'; |
46 | 46 | } |
@@ -50,14 +50,14 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @param WPInv_Item $item |
52 | 52 | */ |
53 | - public static function output_vat_rules( $item ) { |
|
53 | + public static function output_vat_rules($item) { |
|
54 | 54 | ?> |
55 | 55 | |
56 | 56 | <div class="wpinv_vat_rules"> |
57 | 57 | |
58 | 58 | <div class="form-group mb-3 row"> |
59 | 59 | <label for="wpinv_vat_rules" class="col-sm-3 col-form-label"> |
60 | - <?php esc_html_e( 'Tax Rule', 'invoicing' ); ?> |
|
60 | + <?php esc_html_e('Tax Rule', 'invoicing'); ?> |
|
61 | 61 | </label> |
62 | 62 | <div class="col-sm-8"> |
63 | 63 | <?php |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | array( |
66 | 66 | 'id' => 'wpinv_vat_rules', |
67 | 67 | 'name' => 'wpinv_vat_rules', |
68 | - 'placeholder' => __( 'Select tax rule', 'invoicing' ), |
|
69 | - 'value' => $item->get_vat_rule( 'edit' ), |
|
68 | + 'placeholder' => __('Select tax rule', 'invoicing'), |
|
69 | + 'value' => $item->get_vat_rule('edit'), |
|
70 | 70 | 'select2' => true, |
71 | 71 | 'data-allow-clear' => 'false', |
72 | 72 | 'no_wrap' => true, |
@@ -89,14 +89,14 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @param WPInv_Item $item |
91 | 91 | */ |
92 | - public static function output_vat_classes( $item ) { |
|
92 | + public static function output_vat_classes($item) { |
|
93 | 93 | ?> |
94 | 94 | |
95 | 95 | <div class="wpinv_vat_classes"> |
96 | 96 | |
97 | 97 | <div class="form-group mb-3 row"> |
98 | 98 | <label for="wpinv_vat_class" class="col-sm-3 col-form-label"> |
99 | - <?php esc_html_e( 'Tax Class', 'invoicing' ); ?> |
|
99 | + <?php esc_html_e('Tax Class', 'invoicing'); ?> |
|
100 | 100 | </label> |
101 | 101 | <div class="col-sm-8"> |
102 | 102 | <?php |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | array( |
105 | 105 | 'id' => 'wpinv_vat_class', |
106 | 106 | 'name' => 'wpinv_vat_class', |
107 | - 'placeholder' => __( 'Select tax class', 'invoicing' ), |
|
108 | - 'value' => $item->get_vat_class( 'edit' ), |
|
107 | + 'placeholder' => __('Select tax class', 'invoicing'), |
|
108 | + 'value' => $item->get_vat_class('edit'), |
|
109 | 109 | 'select2' => true, |
110 | 110 | 'data-allow-clear' => 'false', |
111 | 111 | 'no_wrap' => true, |
@@ -55,27 +55,27 @@ |
||
55 | 55 | public static function vat_rates_settings() {} |
56 | 56 | |
57 | 57 | /** |
58 | - * |
|
59 | - * @deprecated |
|
60 | - */ |
|
58 | + * |
|
59 | + * @deprecated |
|
60 | + */ |
|
61 | 61 | public static function vat_settings() {} |
62 | 62 | |
63 | 63 | /** |
64 | - * |
|
65 | - * @deprecated |
|
66 | - */ |
|
64 | + * |
|
65 | + * @deprecated |
|
66 | + */ |
|
67 | 67 | public static function maxmind_folder() {} |
68 | 68 | |
69 | 69 | /** |
70 | - * |
|
71 | - * @deprecated |
|
72 | - */ |
|
70 | + * |
|
71 | + * @deprecated |
|
72 | + */ |
|
73 | 73 | public static function geoip2_download_database() {} |
74 | 74 | |
75 | 75 | /** |
76 | - * |
|
77 | - * @deprecated |
|
78 | - */ |
|
76 | + * |
|
77 | + * @deprecated |
|
78 | + */ |
|
79 | 79 | public static function geoip2_download_file() {} |
80 | 80 | |
81 | 81 | /** |
@@ -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 | * @deprecated |
@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | /** |
39 | 39 | * @deprecated |
40 | 40 | */ |
41 | - public static function is_eu_state( $country_code ) { |
|
42 | - return getpaid_is_eu_state( $country_code ); |
|
41 | + public static function is_eu_state($country_code) { |
|
42 | + return getpaid_is_eu_state($country_code); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
46 | 46 | * @deprecated |
47 | 47 | */ |
48 | - public static function is_gst_country( $country_code ) { |
|
49 | - return getpaid_is_gst_country( $country_code ); |
|
48 | + public static function is_gst_country($country_code) { |
|
49 | + return getpaid_is_gst_country($country_code); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -6,7 +6,7 @@ |
||
6 | 6 | * @version 1.0.19 |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | return array( |
12 | 12 | 'AT', |
@@ -9,31 +9,31 @@ |
||
9 | 9 | defined( 'ABSPATH' ) || exit; |
10 | 10 | |
11 | 11 | return array( |
12 | - 'AT', |
|
13 | - 'BE', |
|
14 | - 'BG', |
|
15 | - 'HR', |
|
16 | - 'CY', |
|
17 | - 'CZ', |
|
18 | - 'DK', |
|
19 | - 'EE', |
|
20 | - 'FI', |
|
21 | - 'FR', |
|
22 | - 'DE', |
|
23 | - 'GR', |
|
24 | - 'HU', |
|
25 | - 'IE', |
|
26 | - 'IT', |
|
27 | - 'LV', |
|
28 | - 'LT', |
|
29 | - 'LU', |
|
30 | - 'MT', |
|
31 | - 'NL', |
|
32 | - 'PL', |
|
33 | - 'PT', |
|
34 | - 'RO', |
|
35 | - 'SK', |
|
36 | - 'SI', |
|
37 | - 'ES', |
|
38 | - 'SE', |
|
12 | + 'AT', |
|
13 | + 'BE', |
|
14 | + 'BG', |
|
15 | + 'HR', |
|
16 | + 'CY', |
|
17 | + 'CZ', |
|
18 | + 'DK', |
|
19 | + 'EE', |
|
20 | + 'FI', |
|
21 | + 'FR', |
|
22 | + 'DE', |
|
23 | + 'GR', |
|
24 | + 'HU', |
|
25 | + 'IE', |
|
26 | + 'IT', |
|
27 | + 'LV', |
|
28 | + 'LT', |
|
29 | + 'LU', |
|
30 | + 'MT', |
|
31 | + 'NL', |
|
32 | + 'PL', |
|
33 | + 'PT', |
|
34 | + 'RO', |
|
35 | + 'SK', |
|
36 | + 'SI', |
|
37 | + 'ES', |
|
38 | + 'SE', |
|
39 | 39 | ); |
@@ -7,24 +7,24 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 | |
14 | - <?php do_action( 'getpaid_before_invoice_details_top', $invoice ); ?> |
|
14 | + <?php do_action('getpaid_before_invoice_details_top', $invoice); ?> |
|
15 | 15 | |
16 | 16 | <div class="getpaid-invoice-details-top mb-5"> |
17 | 17 | <div class="row"> |
18 | 18 | <div class="col-12 col-sm-6 text-sm-left"> |
19 | - <?php do_action( 'getpaid_invoice_details_top_left', $invoice ); ?> |
|
19 | + <?php do_action('getpaid_invoice_details_top_left', $invoice); ?> |
|
20 | 20 | </div> |
21 | 21 | |
22 | 22 | <div class="col-12 col-sm-6 text-sm-right"> |
23 | - <?php do_action( 'getpaid_invoice_details_top_right', $invoice ); ?> |
|
23 | + <?php do_action('getpaid_invoice_details_top_right', $invoice); ?> |
|
24 | 24 | </div> |
25 | 25 | </div> |
26 | 26 | </div> |
27 | 27 | |
28 | - <?php do_action( 'getpaid_after_invoice_details_top', $invoice ); ?> |
|
28 | + <?php do_action('getpaid_after_invoice_details_top', $invoice); ?> |
|
29 | 29 | |
30 | 30 | <?php |