@@ -7,37 +7,37 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | $value = $query_value; |
13 | 13 | $class = ''; |
14 | 14 | |
15 | -if ( ! empty( $form->invoice ) ) { |
|
16 | - $value = sanitize_email( $form->invoice->get_email() ); |
|
17 | -} elseif ( is_user_logged_in() ) { |
|
15 | +if (!empty($form->invoice)) { |
|
16 | + $value = sanitize_email($form->invoice->get_email()); |
|
17 | +} elseif (is_user_logged_in()) { |
|
18 | 18 | $user = wp_get_current_user(); |
19 | - $value = sanitize_email( $user->user_email ); |
|
19 | + $value = sanitize_email($user->user_email); |
|
20 | 20 | } |
21 | 21 | |
22 | -if ( ! empty( $value ) && ! empty( $hide_billing_email ) ) { |
|
22 | +if (!empty($value) && !empty($hide_billing_email)) { |
|
23 | 23 | $class = 'd-none'; |
24 | 24 | } |
25 | 25 | |
26 | -do_action( 'getpaid_before_payment_form_billing_email', $form ); |
|
26 | +do_action('getpaid_before_payment_form_billing_email', $form); |
|
27 | 27 | |
28 | -echo "<span class='" . esc_attr( $class ) . "'>"; |
|
28 | +echo "<span class='" . esc_attr($class) . "'>"; |
|
29 | 29 | |
30 | 30 | aui()->input( |
31 | 31 | array( |
32 | 32 | 'name' => 'billing_email', |
33 | - 'id' => esc_attr( $element_id ), |
|
34 | - 'placeholder' => empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
35 | - 'required' => ! empty( $required ), |
|
36 | - 'label' => empty( $label ) ? '' : wp_kses_post( $label ) . '<span class="text-danger"> *</span>', |
|
33 | + 'id' => esc_attr($element_id), |
|
34 | + 'placeholder' => empty($placeholder) ? '' : esc_attr($placeholder), |
|
35 | + 'required' => !empty($required), |
|
36 | + 'label' => empty($label) ? '' : wp_kses_post($label) . '<span class="text-danger"> *</span>', |
|
37 | 37 | 'label_type' => 'vertical', |
38 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
38 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
39 | 39 | 'type' => 'email', |
40 | - 'value' => apply_filters ( 'getpaid_payment_form_billing_email_value', $value ), |
|
40 | + 'value' => apply_filters('getpaid_payment_form_billing_email_value', $value), |
|
41 | 41 | 'class' => 'wpinv_billing_email getpaid-refresh-on-change', |
42 | 42 | 'extra_attributes' => array( |
43 | 43 | 'autocomplete' => 'billing email', |
@@ -48,4 +48,4 @@ discard block |
||
48 | 48 | |
49 | 49 | echo '</span>'; |
50 | 50 | |
51 | -do_action( 'getpaid_after_payment_form_billing_email', $form ); |
|
51 | +do_action('getpaid_after_payment_form_billing_email', $form); |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php |
|
1 | + <?php |
|
2 | 2 | /** |
3 | 3 | * Displays a billing email input in payment form |
4 | 4 | * |
@@ -7,45 +7,45 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | + defined( 'ABSPATH' ) || exit; |
|
11 | 11 | |
12 | -$value = $query_value; |
|
13 | -$class = ''; |
|
12 | + $value = $query_value; |
|
13 | + $class = ''; |
|
14 | 14 | |
15 | -if ( ! empty( $form->invoice ) ) { |
|
16 | - $value = sanitize_email( $form->invoice->get_email() ); |
|
15 | + if ( ! empty( $form->invoice ) ) { |
|
16 | + $value = sanitize_email( $form->invoice->get_email() ); |
|
17 | 17 | } elseif ( is_user_logged_in() ) { |
18 | - $user = wp_get_current_user(); |
|
19 | - $value = sanitize_email( $user->user_email ); |
|
18 | + $user = wp_get_current_user(); |
|
19 | + $value = sanitize_email( $user->user_email ); |
|
20 | 20 | } |
21 | 21 | |
22 | -if ( ! empty( $value ) && ! empty( $hide_billing_email ) ) { |
|
23 | - $class = 'd-none'; |
|
22 | + if ( ! empty( $value ) && ! empty( $hide_billing_email ) ) { |
|
23 | + $class = 'd-none'; |
|
24 | 24 | } |
25 | 25 | |
26 | -do_action( 'getpaid_before_payment_form_billing_email', $form ); |
|
27 | - |
|
28 | -echo "<span class='" . esc_attr( $class ) . "'>"; |
|
29 | - |
|
30 | -aui()->input( |
|
31 | - array( |
|
32 | - 'name' => 'billing_email', |
|
33 | - 'id' => esc_attr( $element_id ), |
|
34 | - 'placeholder' => empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
35 | - 'required' => ! empty( $required ), |
|
36 | - 'label' => empty( $label ) ? '' : wp_kses_post( $label ) . '<span class="text-danger"> *</span>', |
|
37 | - 'label_type' => 'vertical', |
|
38 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
39 | - 'type' => 'email', |
|
40 | - 'value' => apply_filters ( 'getpaid_payment_form_billing_email_value', $value ), |
|
41 | - 'class' => 'wpinv_billing_email getpaid-refresh-on-change', |
|
42 | - 'extra_attributes' => array( |
|
43 | - 'autocomplete' => 'billing email', |
|
26 | + do_action( 'getpaid_before_payment_form_billing_email', $form ); |
|
27 | + |
|
28 | + echo "<span class='" . esc_attr( $class ) . "'>"; |
|
29 | + |
|
30 | + aui()->input( |
|
31 | + array( |
|
32 | + 'name' => 'billing_email', |
|
33 | + 'id' => esc_attr( $element_id ), |
|
34 | + 'placeholder' => empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
35 | + 'required' => ! empty( $required ), |
|
36 | + 'label' => empty( $label ) ? '' : wp_kses_post( $label ) . '<span class="text-danger"> *</span>', |
|
37 | + 'label_type' => 'vertical', |
|
38 | + 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
39 | + 'type' => 'email', |
|
40 | + 'value' => apply_filters ( 'getpaid_payment_form_billing_email_value', $value ), |
|
41 | + 'class' => 'wpinv_billing_email getpaid-refresh-on-change', |
|
42 | + 'extra_attributes' => array( |
|
43 | + 'autocomplete' => 'billing email', |
|
44 | + ), |
|
44 | 45 | ), |
45 | - ), |
|
46 | - true |
|
47 | -); |
|
46 | + true |
|
47 | + ); |
|
48 | 48 | |
49 | -echo '</span>'; |
|
49 | + echo '</span>'; |
|
50 | 50 | |
51 | -do_action( 'getpaid_after_payment_form_billing_email', $form ); |
|
51 | + do_action( 'getpaid_after_payment_form_billing_email', $form ); |
@@ -160,50 +160,50 @@ |
||
160 | 160 | */ |
161 | 161 | function getpaid_calculate_invoice_discount( $invoice, $discount ) { |
162 | 162 | |
163 | - $initial_discount = 0; |
|
164 | - $recurring_discount = 0; |
|
163 | + $initial_discount = 0; |
|
164 | + $recurring_discount = 0; |
|
165 | 165 | |
166 | - foreach ( $invoice->get_items() as $item ) { |
|
166 | + foreach ( $invoice->get_items() as $item ) { |
|
167 | 167 | |
168 | - // Abort if it is not valid for this item. |
|
169 | - if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
170 | - continue; |
|
171 | - } |
|
168 | + // Abort if it is not valid for this item. |
|
169 | + if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
170 | + continue; |
|
171 | + } |
|
172 | 172 | |
173 | - // Calculate the initial amount... |
|
174 | - $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
175 | - $recurring_item_discount = 0; |
|
173 | + // Calculate the initial amount... |
|
174 | + $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
175 | + $recurring_item_discount = 0; |
|
176 | 176 | |
177 | - // ... and maybe the recurring amount. |
|
178 | - if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
179 | - $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
180 | - } |
|
177 | + // ... and maybe the recurring amount. |
|
178 | + if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
179 | + $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
180 | + } |
|
181 | 181 | |
182 | - // Discount should not exceed discounted amount. |
|
183 | - if ( ! $discount->is_type( 'percent' ) ) { |
|
182 | + // Discount should not exceed discounted amount. |
|
183 | + if ( ! $discount->is_type( 'percent' ) ) { |
|
184 | 184 | |
185 | - if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
186 | - $item_discount = $discount->get_amount() - $initial_discount; |
|
187 | - } |
|
185 | + if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
186 | + $item_discount = $discount->get_amount() - $initial_discount; |
|
187 | + } |
|
188 | 188 | |
189 | - if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
190 | - $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
|
191 | - } |
|
189 | + if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
190 | + $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
|
191 | + } |
|
192 | 192 | } |
193 | 193 | |
194 | - $initial_discount += $item_discount; |
|
195 | - $recurring_discount += $recurring_item_discount; |
|
196 | - $item->item_discount = $item_discount; |
|
197 | - $item->recurring_item_discount = $recurring_item_discount; |
|
194 | + $initial_discount += $item_discount; |
|
195 | + $recurring_discount += $recurring_item_discount; |
|
196 | + $item->item_discount = $item_discount; |
|
197 | + $item->recurring_item_discount = $recurring_item_discount; |
|
198 | 198 | |
199 | - } |
|
199 | + } |
|
200 | 200 | |
201 | - return array( |
|
202 | - 'name' => 'discount_code', |
|
203 | - 'discount_code' => $discount->get_code(), |
|
204 | - 'initial_discount' => $initial_discount, |
|
205 | - 'recurring_discount' => $recurring_discount, |
|
206 | - ); |
|
201 | + return array( |
|
202 | + 'name' => 'discount_code', |
|
203 | + 'discount_code' => $discount->get_code(), |
|
204 | + 'initial_discount' => $initial_discount, |
|
205 | + 'recurring_discount' => $recurring_discount, |
|
206 | + ); |
|
207 | 207 | |
208 | 208 | } |
209 | 209 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Returns an array of discount type. |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | return apply_filters( |
18 | 18 | 'wpinv_discount_types', |
19 | 19 | array( |
20 | - 'percent' => __( 'Percentage', 'invoicing' ), |
|
21 | - 'flat' => __( 'Flat Amount', 'invoicing' ), |
|
20 | + 'percent' => __('Percentage', 'invoicing'), |
|
21 | + 'flat' => __('Flat Amount', 'invoicing'), |
|
22 | 22 | ) |
23 | 23 | ); |
24 | 24 | } |
@@ -28,46 +28,46 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return string |
30 | 30 | */ |
31 | -function wpinv_get_discount_type_name( $type = '' ) { |
|
31 | +function wpinv_get_discount_type_name($type = '') { |
|
32 | 32 | $types = wpinv_get_discount_types(); |
33 | - return isset( $types[ $type ] ) ? $types[ $type ] : $type; |
|
33 | + return isset($types[$type]) ? $types[$type] : $type; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Deletes a discount via the admin page. |
38 | 38 | * |
39 | 39 | */ |
40 | -function wpinv_delete_discount( $data ) { |
|
40 | +function wpinv_delete_discount($data) { |
|
41 | 41 | |
42 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
43 | - $discount->delete( true ); |
|
42 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
43 | + $discount->delete(true); |
|
44 | 44 | |
45 | 45 | } |
46 | -add_action( 'getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount' ); |
|
46 | +add_action('getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount'); |
|
47 | 47 | |
48 | 48 | /** |
49 | 49 | * Deactivates a discount via the admin page. |
50 | 50 | */ |
51 | -function wpinv_activate_discount( $data ) { |
|
51 | +function wpinv_activate_discount($data) { |
|
52 | 52 | |
53 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
54 | - $discount->set_status( 'publish' ); |
|
53 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
54 | + $discount->set_status('publish'); |
|
55 | 55 | $discount->save(); |
56 | 56 | |
57 | 57 | } |
58 | -add_action( 'getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount' ); |
|
58 | +add_action('getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount'); |
|
59 | 59 | |
60 | 60 | /** |
61 | 61 | * Activates a discount via the admin page. |
62 | 62 | */ |
63 | -function wpinv_deactivate_discount( $data ) { |
|
63 | +function wpinv_deactivate_discount($data) { |
|
64 | 64 | |
65 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
66 | - $discount->set_status( 'pending' ); |
|
65 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
66 | + $discount->set_status('pending'); |
|
67 | 67 | $discount->save(); |
68 | 68 | |
69 | 69 | } |
70 | -add_action( 'getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount' ); |
|
70 | +add_action('getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount'); |
|
71 | 71 | |
72 | 72 | /** |
73 | 73 | * Fetches a discount object. |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | * @since 1.0.15 |
77 | 77 | * @return WPInv_Discount |
78 | 78 | */ |
79 | -function wpinv_get_discount( $discount ) { |
|
80 | - return new WPInv_Discount( $discount ); |
|
79 | +function wpinv_get_discount($discount) { |
|
80 | + return new WPInv_Discount($discount); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | * @since 1.0.15 |
88 | 88 | * @return WPInv_Discount |
89 | 89 | */ |
90 | -function wpinv_get_discount_obj( $discount = 0 ) { |
|
91 | - return new WPInv_Discount( $discount ); |
|
90 | +function wpinv_get_discount_obj($discount = 0) { |
|
91 | + return new WPInv_Discount($discount); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -98,10 +98,10 @@ discard block |
||
98 | 98 | * @param string|int $value The field value |
99 | 99 | * @return bool|WPInv_Discount |
100 | 100 | */ |
101 | -function wpinv_get_discount_by( $deprecated = null, $value = '' ) { |
|
102 | - $discount = new WPInv_Discount( $value ); |
|
101 | +function wpinv_get_discount_by($deprecated = null, $value = '') { |
|
102 | + $discount = new WPInv_Discount($value); |
|
103 | 103 | |
104 | - if ( $discount->get_id() != 0 ) { |
|
104 | + if ($discount->get_id() != 0) { |
|
105 | 105 | return $discount; |
106 | 106 | } |
107 | 107 | |
@@ -116,9 +116,9 @@ discard block |
||
116 | 116 | function wpinv_get_discount_statuses() { |
117 | 117 | |
118 | 118 | return array( |
119 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
120 | - 'publish' => __( 'Active', 'invoicing' ), |
|
121 | - 'inactive' => __( 'Inactive', 'invoicing' ), |
|
119 | + 'expired' => __('Expired', 'invoicing'), |
|
120 | + 'publish' => __('Active', 'invoicing'), |
|
121 | + 'inactive' => __('Inactive', 'invoicing'), |
|
122 | 122 | ); |
123 | 123 | |
124 | 124 | } |
@@ -126,9 +126,9 @@ discard block |
||
126 | 126 | /** |
127 | 127 | * Retrieves an invoice status label. |
128 | 128 | */ |
129 | -function wpinv_discount_status( $status ) { |
|
129 | +function wpinv_discount_status($status) { |
|
130 | 130 | $statuses = wpinv_get_discount_statuses(); |
131 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : __( 'Inactive', 'invoicing' ); |
|
131 | + return isset($statuses[$status]) ? $statuses[$status] : __('Inactive', 'invoicing'); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | * @param int|array|string|WPInv_Discount $code discount data, object, ID or code. |
139 | 139 | * @return bool |
140 | 140 | */ |
141 | -function wpinv_discount_is_recurring( $discount = 0, $code = 0 ) { |
|
141 | +function wpinv_discount_is_recurring($discount = 0, $code = 0) { |
|
142 | 142 | |
143 | - if ( ! empty( $discount ) ) { |
|
144 | - $discount = wpinv_get_discount_obj( $discount ); |
|
143 | + if (!empty($discount)) { |
|
144 | + $discount = wpinv_get_discount_obj($discount); |
|
145 | 145 | } else { |
146 | - $discount = wpinv_get_discount_obj( $code ); |
|
146 | + $discount = wpinv_get_discount_obj($code); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | return $discount->get_is_recurring(); |
@@ -158,35 +158,35 @@ discard block |
||
158 | 158 | * @param WPInv_Discount $discount |
159 | 159 | * @return array |
160 | 160 | */ |
161 | -function getpaid_calculate_invoice_discount( $invoice, $discount ) { |
|
161 | +function getpaid_calculate_invoice_discount($invoice, $discount) { |
|
162 | 162 | |
163 | 163 | $initial_discount = 0; |
164 | 164 | $recurring_discount = 0; |
165 | 165 | |
166 | - foreach ( $invoice->get_items() as $item ) { |
|
166 | + foreach ($invoice->get_items() as $item) { |
|
167 | 167 | |
168 | 168 | // Abort if it is not valid for this item. |
169 | - if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
169 | + if (!$discount->is_valid_for_items(array($item->get_id()))) { |
|
170 | 170 | continue; |
171 | 171 | } |
172 | 172 | |
173 | 173 | // Calculate the initial amount... |
174 | - $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
174 | + $item_discount = $discount->get_discounted_amount($item->get_sub_total()); |
|
175 | 175 | $recurring_item_discount = 0; |
176 | 176 | |
177 | 177 | // ... and maybe the recurring amount. |
178 | - if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
179 | - $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
178 | + if ($item->is_recurring() && $discount->is_recurring()) { |
|
179 | + $recurring_item_discount = $discount->get_discounted_amount($item->get_recurring_sub_total()); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | // Discount should not exceed discounted amount. |
183 | - if ( ! $discount->is_type( 'percent' ) ) { |
|
183 | + if (!$discount->is_type('percent')) { |
|
184 | 184 | |
185 | - if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
185 | + if (($initial_discount + $item_discount) > $discount->get_amount()) { |
|
186 | 186 | $item_discount = $discount->get_amount() - $initial_discount; |
187 | 187 | } |
188 | 188 | |
189 | - if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
189 | + if (($recurring_discount + $recurring_item_discount) > $discount->get_amount()) { |
|
190 | 190 | $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
191 | 191 | } |
192 | 192 | } |
@@ -218,10 +218,10 @@ discard block |
||
218 | 218 | array( |
219 | 219 | 'post_type' => 'wpi_discount', |
220 | 220 | 'numberposts' => 1, |
221 | - 'fields' => array( 'ids' ), |
|
221 | + 'fields' => array('ids'), |
|
222 | 222 | ) |
223 | 223 | ); |
224 | 224 | |
225 | - return ! empty( $discounts ); |
|
225 | + return !empty($discounts); |
|
226 | 226 | |
227 | 227 | } |
@@ -13,9 +13,9 @@ discard block |
||
13 | 13 | |
14 | 14 | |
15 | 15 | function wpinv_get_default_country() { |
16 | - $country = wpinv_get_option( 'default_country', 'UK' ); |
|
16 | + $country = wpinv_get_option( 'default_country', 'UK' ); |
|
17 | 17 | |
18 | - return apply_filters( 'wpinv_default_country', $country ); |
|
18 | + return apply_filters( 'wpinv_default_country', $country ); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | function wpinv_sanitize_country( $country ) { |
38 | 38 | |
39 | - // Enure the country is specified |
|
39 | + // Enure the country is specified |
|
40 | 40 | if ( empty( $country ) ) { |
41 | 41 | $country = wpinv_get_default_country(); |
42 | 42 | } |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | function wpinv_get_default_state() { |
69 | - $state = wpinv_get_option( 'default_state', '' ); |
|
69 | + $state = wpinv_get_option( 'default_state', '' ); |
|
70 | 70 | |
71 | - return apply_filters( 'wpinv_default_state', $state ); |
|
71 | + return apply_filters( 'wpinv_default_state', $state ); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | function wpinv_state_name( $state_code = '', $country_code = '' ) { |
@@ -299,11 +299,11 @@ discard block |
||
299 | 299 | |
300 | 300 | $country = wpinv_sanitize_country( $country ); |
301 | 301 | |
302 | - foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
303 | - if ( false !== array_search( $country, $countries, true ) ) { |
|
304 | - return $continent_code; |
|
305 | - } |
|
306 | - } |
|
302 | + foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
303 | + if ( false !== array_search( $country, $countries, true ) ) { |
|
304 | + return $continent_code; |
|
305 | + } |
|
306 | + } |
|
307 | 307 | |
308 | 308 | return ''; |
309 | 309 | |
@@ -595,31 +595,31 @@ discard block |
||
595 | 595 | } |
596 | 596 | |
597 | 597 | function wpinv_get_states_field() { |
598 | - if ( empty( $_POST['country'] ) ) { |
|
599 | - $_POST['country'] = wpinv_get_default_country(); |
|
600 | - } |
|
601 | - $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
598 | + if ( empty( $_POST['country'] ) ) { |
|
599 | + $_POST['country'] = wpinv_get_default_country(); |
|
600 | + } |
|
601 | + $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
602 | 602 | |
603 | - if ( ! empty( $states ) ) { |
|
604 | - $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
603 | + if ( ! empty( $states ) ) { |
|
604 | + $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
605 | 605 | |
606 | 606 | $class = isset( $_POST['class'] ) ? esc_attr( sanitize_text_field( $_POST['class'] ) ) : ''; |
607 | 607 | $class .= " $sanitized_field_name getpaid_js_field-state custom-select wpinv-select wpi_select2"; |
608 | 608 | |
609 | 609 | $args = array( |
610 | - 'name' => $sanitized_field_name, |
|
611 | - 'id' => $sanitized_field_name, |
|
612 | - 'class' => implode( ' ', array_unique( explode( ' ', $class ) ) ), |
|
613 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
614 | - 'show_option_all' => false, |
|
615 | - 'show_option_none' => false, |
|
616 | - ); |
|
617 | - |
|
618 | - wpinv_html_select( $args ); |
|
619 | - |
|
620 | - } else { |
|
621 | - echo 'nostates'; |
|
622 | - } |
|
610 | + 'name' => $sanitized_field_name, |
|
611 | + 'id' => $sanitized_field_name, |
|
612 | + 'class' => implode( ' ', array_unique( explode( ' ', $class ) ) ), |
|
613 | + 'options' => array_merge( array( '' => '' ), $states ), |
|
614 | + 'show_option_all' => false, |
|
615 | + 'show_option_none' => false, |
|
616 | + ); |
|
617 | + |
|
618 | + wpinv_html_select( $args ); |
|
619 | + |
|
620 | + } else { |
|
621 | + echo 'nostates'; |
|
622 | + } |
|
623 | 623 | |
624 | 624 | } |
625 | 625 | |
@@ -638,47 +638,47 @@ discard block |
||
638 | 638 | */ |
639 | 639 | function wpinv_get_address_formats() { |
640 | 640 | |
641 | - return apply_filters( |
|
641 | + return apply_filters( |
|
642 | 642 | 'wpinv_localisation_address_formats', |
643 | - array( |
|
644 | - 'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}", |
|
645 | - 'AU' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}", |
|
646 | - 'AT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
647 | - 'BE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
648 | - 'CA' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}} {{zip}}\n{{country}}", |
|
649 | - 'CH' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
650 | - 'CL' => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}", |
|
651 | - 'CN' => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}", |
|
652 | - 'CZ' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
653 | - 'DE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
654 | - 'EE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
655 | - 'FI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
656 | - 'DK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
657 | - 'FR' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}", |
|
658 | - 'HK' => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}", |
|
659 | - 'HU' => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}", |
|
660 | - 'IN' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}", |
|
661 | - 'IS' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
662 | - 'IT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}", |
|
663 | - 'JP' => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}", |
|
664 | - 'TW' => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}", |
|
665 | - 'LI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
666 | - 'NL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
667 | - 'NZ' => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}", |
|
668 | - 'NO' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
669 | - 'PL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
670 | - 'PT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
671 | - 'SK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
672 | - 'RS' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
673 | - 'SI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
674 | - 'ES' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}", |
|
675 | - 'SE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
676 | - 'TR' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}", |
|
677 | - 'UG' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}", |
|
678 | - 'US' => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}", |
|
679 | - 'VN' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}", |
|
680 | - ) |
|
681 | - ); |
|
643 | + array( |
|
644 | + 'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}", |
|
645 | + 'AU' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}", |
|
646 | + 'AT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
647 | + 'BE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
648 | + 'CA' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}} {{zip}}\n{{country}}", |
|
649 | + 'CH' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
650 | + 'CL' => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}", |
|
651 | + 'CN' => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}", |
|
652 | + 'CZ' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
653 | + 'DE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
654 | + 'EE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
655 | + 'FI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
656 | + 'DK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
657 | + 'FR' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}", |
|
658 | + 'HK' => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}", |
|
659 | + 'HU' => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}", |
|
660 | + 'IN' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}", |
|
661 | + 'IS' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
662 | + 'IT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}", |
|
663 | + 'JP' => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}", |
|
664 | + 'TW' => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}", |
|
665 | + 'LI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
666 | + 'NL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
667 | + 'NZ' => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}", |
|
668 | + 'NO' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
669 | + 'PL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
670 | + 'PT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
671 | + 'SK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
672 | + 'RS' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
673 | + 'SI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
674 | + 'ES' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}", |
|
675 | + 'SE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
676 | + 'TR' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}", |
|
677 | + 'UG' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}", |
|
678 | + 'US' => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}", |
|
679 | + 'VN' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}", |
|
680 | + ) |
|
681 | + ); |
|
682 | 682 | } |
683 | 683 | |
684 | 684 | /** |
@@ -695,21 +695,21 @@ discard block |
||
695 | 695 | } |
696 | 696 | |
697 | 697 | // Get all formats. |
698 | - $formats = wpinv_get_address_formats(); |
|
698 | + $formats = wpinv_get_address_formats(); |
|
699 | 699 | |
700 | - // Get format for the specified country. |
|
701 | - $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
700 | + // Get format for the specified country. |
|
701 | + $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
702 | 702 | |
703 | 703 | /** |
704 | - * Filters the address format to use on Invoices. |
|
704 | + * Filters the address format to use on Invoices. |
|
705 | 705 | * |
706 | 706 | * New lines will be replaced by a `br` element. Double new lines will be replaced by a paragraph. HTML tags are allowed. |
707 | - * |
|
708 | - * @since 1.0.13 |
|
709 | - * |
|
710 | - * @param string $format The address format to use. |
|
707 | + * |
|
708 | + * @since 1.0.13 |
|
709 | + * |
|
710 | + * @param string $format The address format to use. |
|
711 | 711 | * @param string $country The country who's address format is being retrieved. |
712 | - */ |
|
712 | + */ |
|
713 | 713 | return apply_filters( 'wpinv_get_full_address_format', $format, $country ); |
714 | 714 | } |
715 | 715 | |
@@ -730,8 +730,8 @@ discard block |
||
730 | 730 | 'country' => '', |
731 | 731 | 'zip' => '', |
732 | 732 | 'first_name' => '', |
733 | - 'last_name' => '', |
|
734 | - 'company' => '', |
|
733 | + 'last_name' => '', |
|
734 | + 'company' => '', |
|
735 | 735 | ); |
736 | 736 | |
737 | 737 | $args = map_deep( wp_parse_args( array_filter( $billing_details ), $default_args ), 'trim' ); |
@@ -752,14 +752,14 @@ discard block |
||
752 | 752 | $args['country_code'] = $country; |
753 | 753 | |
754 | 754 | /** |
755 | - * Filters the address format replacements to use on Invoices. |
|
755 | + * Filters the address format replacements to use on Invoices. |
|
756 | + * |
|
757 | + * |
|
758 | + * @since 1.0.13 |
|
756 | 759 | * |
757 | - * |
|
758 | - * @since 1.0.13 |
|
759 | - * |
|
760 | - * @param array $replacements The address replacements to use. |
|
760 | + * @param array $replacements The address replacements to use. |
|
761 | 761 | * @param array $billing_details The billing details to use. |
762 | - */ |
|
762 | + */ |
|
763 | 763 | $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details ); |
764 | 764 | |
765 | 765 | $return = array(); |
@@ -782,5 +782,5 @@ discard block |
||
782 | 782 | * @return string |
783 | 783 | */ |
784 | 784 | function wpinv_trim_formatted_address_line( $line ) { |
785 | - return trim( $line, ', ' ); |
|
785 | + return trim( $line, ', ' ); |
|
786 | 786 | } |
@@ -7,15 +7,15 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( ! defined( 'WPINC' ) ) { |
|
10 | +if (!defined('WPINC')) { |
|
11 | 11 | exit; |
12 | 12 | } |
13 | 13 | |
14 | 14 | |
15 | 15 | function wpinv_get_default_country() { |
16 | - $country = wpinv_get_option( 'default_country', 'UK' ); |
|
16 | + $country = wpinv_get_option('default_country', 'UK'); |
|
17 | 17 | |
18 | - return apply_filters( 'wpinv_default_country', $country ); |
|
18 | + return apply_filters('wpinv_default_country', $country); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @return string |
25 | 25 | */ |
26 | -function getpaid_get_ip_country( $ip_address = '' ) { |
|
27 | - $country = GetPaid_Geolocation::geolocate_ip( $ip_address, true ); |
|
26 | +function getpaid_get_ip_country($ip_address = '') { |
|
27 | + $country = GetPaid_Geolocation::geolocate_ip($ip_address, true); |
|
28 | 28 | return $country['country']; |
29 | 29 | } |
30 | 30 | |
@@ -34,59 +34,59 @@ discard block |
||
34 | 34 | * @param string $country The country code to sanitize |
35 | 35 | * @return array |
36 | 36 | */ |
37 | -function wpinv_sanitize_country( $country ) { |
|
37 | +function wpinv_sanitize_country($country) { |
|
38 | 38 | |
39 | 39 | // Enure the country is specified |
40 | - if ( empty( $country ) ) { |
|
40 | + if (empty($country)) { |
|
41 | 41 | $country = wpinv_get_default_country(); |
42 | 42 | } |
43 | - return trim( wpinv_utf8_strtoupper( $country ) ); |
|
43 | + return trim(wpinv_utf8_strtoupper($country)); |
|
44 | 44 | |
45 | 45 | } |
46 | 46 | |
47 | -function wpinv_is_base_country( $country ) { |
|
47 | +function wpinv_is_base_country($country) { |
|
48 | 48 | $base_country = wpinv_get_default_country(); |
49 | 49 | |
50 | - if ( $base_country === 'UK' ) { |
|
50 | + if ($base_country === 'UK') { |
|
51 | 51 | $base_country = 'GB'; |
52 | 52 | } |
53 | - if ( $country == 'UK' ) { |
|
53 | + if ($country == 'UK') { |
|
54 | 54 | $country = 'GB'; |
55 | 55 | } |
56 | 56 | |
57 | - return ( $country && $country === $base_country ) ? true : false; |
|
57 | + return ($country && $country === $base_country) ? true : false; |
|
58 | 58 | } |
59 | 59 | |
60 | -function wpinv_country_name( $country_code = '' ) { |
|
60 | +function wpinv_country_name($country_code = '') { |
|
61 | 61 | $countries = wpinv_get_country_list(); |
62 | 62 | $country_code = $country_code == 'UK' ? 'GB' : $country_code; |
63 | - $country = isset( $countries[ $country_code ] ) ? $countries[ $country_code ] : $country_code; |
|
63 | + $country = isset($countries[$country_code]) ? $countries[$country_code] : $country_code; |
|
64 | 64 | |
65 | - return apply_filters( 'wpinv_country_name', $country, $country_code ); |
|
65 | + return apply_filters('wpinv_country_name', $country, $country_code); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | function wpinv_get_default_state() { |
69 | - $state = wpinv_get_option( 'default_state', '' ); |
|
69 | + $state = wpinv_get_option('default_state', ''); |
|
70 | 70 | |
71 | - return apply_filters( 'wpinv_default_state', $state ); |
|
71 | + return apply_filters('wpinv_default_state', $state); |
|
72 | 72 | } |
73 | 73 | |
74 | -function wpinv_state_name( $state_code = '', $country_code = '' ) { |
|
74 | +function wpinv_state_name($state_code = '', $country_code = '') { |
|
75 | 75 | $state = $state_code; |
76 | 76 | |
77 | - if ( ! empty( $country_code ) ) { |
|
78 | - $states = wpinv_get_country_states( $country_code ); |
|
77 | + if (!empty($country_code)) { |
|
78 | + $states = wpinv_get_country_states($country_code); |
|
79 | 79 | |
80 | - $state = ! empty( $states ) && isset( $states[ $state_code ] ) ? $states[ $state_code ] : $state; |
|
80 | + $state = !empty($states) && isset($states[$state_code]) ? $states[$state_code] : $state; |
|
81 | 81 | } |
82 | 82 | |
83 | - return apply_filters( 'wpinv_state_name', $state, $state_code, $country_code ); |
|
83 | + return apply_filters('wpinv_state_name', $state, $state_code, $country_code); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | function wpinv_store_address() { |
87 | - $address = wpinv_get_option( 'store_address', '' ); |
|
87 | + $address = wpinv_get_option('store_address', ''); |
|
88 | 88 | |
89 | - return apply_filters( 'wpinv_store_address', $address ); |
|
89 | + return apply_filters('wpinv_store_address', $address); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -94,24 +94,24 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @param WPInv_Invoice $invoice |
96 | 96 | */ |
97 | -function getpaid_maybe_add_default_address( &$invoice ) { |
|
97 | +function getpaid_maybe_add_default_address(&$invoice) { |
|
98 | 98 | |
99 | 99 | $user_id = $invoice->get_user_id(); |
100 | 100 | |
101 | 101 | // Abort if the invoice belongs to no one. |
102 | - if ( empty( $user_id ) ) { |
|
102 | + if (empty($user_id)) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Fill in defaults whenever necessary. |
107 | - foreach ( wpinv_get_user_address( $user_id ) as $key => $value ) { |
|
107 | + foreach (wpinv_get_user_address($user_id) as $key => $value) { |
|
108 | 108 | |
109 | - if ( is_callable( $invoice, "get_$key" ) ) { |
|
110 | - $current = call_user_func( array( $invoice, "get_$key" ) ); |
|
109 | + if (is_callable($invoice, "get_$key")) { |
|
110 | + $current = call_user_func(array($invoice, "get_$key")); |
|
111 | 111 | |
112 | - if ( empty( $current ) ) { |
|
112 | + if (empty($current)) { |
|
113 | 113 | $method = "set_$key"; |
114 | - $invoice->$method( $value ); |
|
114 | + $invoice->$method($value); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | } |
@@ -123,27 +123,27 @@ discard block |
||
123 | 123 | * |
124 | 124 | * @return array |
125 | 125 | */ |
126 | -function getpaid_user_address_fields( $force_vat = false ) { |
|
126 | +function getpaid_user_address_fields($force_vat = false) { |
|
127 | 127 | |
128 | 128 | $address_fields = apply_filters( |
129 | 129 | 'getpaid_user_address_fields', |
130 | 130 | array( |
131 | - 'first_name' => __( 'First Name', 'invoicing' ), |
|
132 | - 'last_name' => __( 'Last Name', 'invoicing' ), |
|
133 | - 'address' => __( 'Address', 'invoicing' ), |
|
134 | - 'city' => __( 'City', 'invoicing' ), |
|
135 | - 'country' => __( 'Country', 'invoicing' ), |
|
136 | - 'state' => __( 'State', 'invoicing' ), |
|
137 | - 'zip' => __( 'Zip/Postal Code', 'invoicing' ), |
|
138 | - 'phone' => __( 'Phone Number', 'invoicing' ), |
|
139 | - 'company' => __( 'Company', 'invoicing' ), |
|
140 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
141 | - 'vat_number' => __( 'VAT Number', 'invoicing' ), |
|
131 | + 'first_name' => __('First Name', 'invoicing'), |
|
132 | + 'last_name' => __('Last Name', 'invoicing'), |
|
133 | + 'address' => __('Address', 'invoicing'), |
|
134 | + 'city' => __('City', 'invoicing'), |
|
135 | + 'country' => __('Country', 'invoicing'), |
|
136 | + 'state' => __('State', 'invoicing'), |
|
137 | + 'zip' => __('Zip/Postal Code', 'invoicing'), |
|
138 | + 'phone' => __('Phone Number', 'invoicing'), |
|
139 | + 'company' => __('Company', 'invoicing'), |
|
140 | + 'company_id' => __('Company ID', 'invoicing'), |
|
141 | + 'vat_number' => __('VAT Number', 'invoicing'), |
|
142 | 142 | ) |
143 | 143 | ); |
144 | 144 | |
145 | - if ( ! wpinv_use_taxes() && isset( $address_fields['vat_number'] ) && ! wp_doing_ajax() && ! $force_vat ) { |
|
146 | - unset( $address_fields['vat_number'] ); |
|
145 | + if (!wpinv_use_taxes() && isset($address_fields['vat_number']) && !wp_doing_ajax() && !$force_vat) { |
|
146 | + unset($address_fields['vat_number']); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | return $address_fields; |
@@ -154,8 +154,8 @@ discard block |
||
154 | 154 | * |
155 | 155 | * @return bool |
156 | 156 | */ |
157 | -function getpaid_is_address_field_whitelisted( $key ) { |
|
158 | - return array_key_exists( $key, getpaid_user_address_fields() ); |
|
157 | +function getpaid_is_address_field_whitelisted($key) { |
|
158 | + return array_key_exists($key, getpaid_user_address_fields()); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -165,44 +165,44 @@ discard block |
||
165 | 165 | * |
166 | 166 | * @param WPInv_Invoice $invoice |
167 | 167 | */ |
168 | -function getpaid_save_invoice_user_address( $invoice ) { |
|
168 | +function getpaid_save_invoice_user_address($invoice) { |
|
169 | 169 | |
170 | 170 | // Retrieve the invoice. |
171 | - $invoice = wpinv_get_invoice( $invoice ); |
|
171 | + $invoice = wpinv_get_invoice($invoice); |
|
172 | 172 | |
173 | 173 | // Abort if it does not exist. |
174 | - if ( empty( $invoice ) || $invoice->is_renewal() ) { |
|
174 | + if (empty($invoice) || $invoice->is_renewal()) { |
|
175 | 175 | return; |
176 | 176 | } |
177 | 177 | |
178 | - $customer = getpaid_get_customer_by_user_id( $invoice->get_user_id() ); |
|
178 | + $customer = getpaid_get_customer_by_user_id($invoice->get_user_id()); |
|
179 | 179 | |
180 | - if ( empty( $customer ) ) { |
|
181 | - $customer = new GetPaid_Customer( 0 ); |
|
182 | - $customer->clone_user( $invoice->get_user_id() ); |
|
180 | + if (empty($customer)) { |
|
181 | + $customer = new GetPaid_Customer(0); |
|
182 | + $customer->clone_user($invoice->get_user_id()); |
|
183 | 183 | } |
184 | 184 | |
185 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
185 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
186 | 186 | |
187 | - if ( is_callable( array( $invoice, "get_$field" ) ) ) { |
|
188 | - $value = call_user_func( array( $invoice, "get_$field" ) ); |
|
187 | + if (is_callable(array($invoice, "get_$field"))) { |
|
188 | + $value = call_user_func(array($invoice, "get_$field")); |
|
189 | 189 | |
190 | 190 | // Only save if it is not empty. |
191 | - if ( ! empty( $value ) ) { |
|
192 | - $customer->set( $field, sanitize_text_field( $value ) ); |
|
191 | + if (!empty($value)) { |
|
192 | + $customer->set($field, sanitize_text_field($value)); |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | } |
196 | 196 | |
197 | 197 | $customer->save(); |
198 | 198 | |
199 | - if ( ! $invoice->get_customer_id() ) { |
|
200 | - $invoice->set_customer_id( $customer->get_id() ); |
|
199 | + if (!$invoice->get_customer_id()) { |
|
200 | + $invoice->set_customer_id($customer->get_id()); |
|
201 | 201 | $invoice->save(); |
202 | 202 | } |
203 | 203 | } |
204 | -add_action( 'getpaid_new_invoice', 'getpaid_save_invoice_user_address' ); |
|
205 | -add_action( 'getpaid_update_invoice', 'getpaid_save_invoice_user_address' ); |
|
204 | +add_action('getpaid_new_invoice', 'getpaid_save_invoice_user_address'); |
|
205 | +add_action('getpaid_update_invoice', 'getpaid_save_invoice_user_address'); |
|
206 | 206 | |
207 | 207 | /** |
208 | 208 | * Retrieves a saved user address. |
@@ -210,36 +210,36 @@ discard block |
||
210 | 210 | * @param int $user_id The user id whose address we should get. Defaults to the current user id. |
211 | 211 | * @return array |
212 | 212 | */ |
213 | -function wpinv_get_user_address( $user_id = 0 ) { |
|
213 | +function wpinv_get_user_address($user_id = 0) { |
|
214 | 214 | |
215 | 215 | // Prepare the user id. |
216 | - $user_id = empty( $user_id ) ? get_current_user_id() : $user_id; |
|
217 | - $user_info = get_userdata( $user_id ); |
|
216 | + $user_id = empty($user_id) ? get_current_user_id() : $user_id; |
|
217 | + $user_info = get_userdata($user_id); |
|
218 | 218 | |
219 | 219 | // Abort if non exists. |
220 | - if ( empty( $user_info ) ) { |
|
220 | + if (empty($user_info)) { |
|
221 | 221 | return array(); |
222 | 222 | } |
223 | 223 | |
224 | - $customer = getpaid_get_customer_by_user_id( $user_id ); |
|
224 | + $customer = getpaid_get_customer_by_user_id($user_id); |
|
225 | 225 | |
226 | - if ( empty( $customer ) ) { |
|
227 | - $customer = new GetPaid_Customer( 0 ); |
|
228 | - $customer->clone_user( $user_id ); |
|
226 | + if (empty($customer)) { |
|
227 | + $customer = new GetPaid_Customer(0); |
|
228 | + $customer->clone_user($user_id); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | // Prepare the address. |
232 | 232 | $address = array( |
233 | 233 | 'user_id' => $user_id, |
234 | - 'email' => $customer->get( 'email' ), |
|
234 | + 'email' => $customer->get('email'), |
|
235 | 235 | 'display_name' => $user_info->display_name, |
236 | 236 | ); |
237 | 237 | |
238 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
239 | - $address[ $field ] = $customer->get( $field ); |
|
238 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
239 | + $address[$field] = $customer->get($field); |
|
240 | 240 | } |
241 | 241 | |
242 | - $address = array_filter( $address ); |
|
242 | + $address = array_filter($address); |
|
243 | 243 | |
244 | 244 | $defaults = array( |
245 | 245 | 'first_name' => $user_info->first_name, |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | 'country' => wpinv_get_default_country(), |
249 | 249 | ); |
250 | 250 | |
251 | - return getpaid_array_merge_if_empty( $address, $defaults ); |
|
251 | + return getpaid_array_merge_if_empty($address, $defaults); |
|
252 | 252 | |
253 | 253 | } |
254 | 254 | |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | * @return string|null |
261 | 261 | * @deprecated |
262 | 262 | */ |
263 | -function getpaid_get_user_address_field( $user_id, $field ) { |
|
263 | +function getpaid_get_user_address_field($user_id, $field) { |
|
264 | 264 | |
265 | 265 | $prefixes = array( |
266 | 266 | '_wpinv_', |
@@ -268,15 +268,15 @@ discard block |
||
268 | 268 | '', |
269 | 269 | ); |
270 | 270 | |
271 | - foreach ( $prefixes as $prefix ) { |
|
271 | + foreach ($prefixes as $prefix) { |
|
272 | 272 | |
273 | 273 | // Meta table. |
274 | - $value = get_user_meta( $user_id, $prefix . $field, true ); |
|
274 | + $value = get_user_meta($user_id, $prefix . $field, true); |
|
275 | 275 | |
276 | 276 | // UWP table. |
277 | - $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value; |
|
277 | + $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value; |
|
278 | 278 | |
279 | - if ( ! empty( $value ) ) { |
|
279 | + if (!empty($value)) { |
|
280 | 280 | return $value; |
281 | 281 | } |
282 | 282 | } |
@@ -292,16 +292,16 @@ discard block |
||
292 | 292 | * @param string $return What to return. |
293 | 293 | * @return array |
294 | 294 | */ |
295 | -function wpinv_get_continents( $return = 'all' ) { |
|
295 | +function wpinv_get_continents($return = 'all') { |
|
296 | 296 | |
297 | - $continents = wpinv_get_data( 'continents' ); |
|
297 | + $continents = wpinv_get_data('continents'); |
|
298 | 298 | |
299 | - switch ( $return ) { |
|
299 | + switch ($return) { |
|
300 | 300 | case 'name': |
301 | - return wp_list_pluck( $continents, 'name' ); |
|
301 | + return wp_list_pluck($continents, 'name'); |
|
302 | 302 | break; |
303 | 303 | case 'countries': |
304 | - return wp_list_pluck( $continents, 'countries' ); |
|
304 | + return wp_list_pluck($continents, 'countries'); |
|
305 | 305 | break; |
306 | 306 | default: |
307 | 307 | return $continents; |
@@ -317,12 +317,12 @@ discard block |
||
317 | 317 | * @param string $country Country code. If no code is specified, defaults to the default country. |
318 | 318 | * @return string |
319 | 319 | */ |
320 | -function wpinv_get_continent_code_for_country( $country = false ) { |
|
320 | +function wpinv_get_continent_code_for_country($country = false) { |
|
321 | 321 | |
322 | - $country = wpinv_sanitize_country( $country ); |
|
322 | + $country = wpinv_sanitize_country($country); |
|
323 | 323 | |
324 | - foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
325 | - if ( false !== array_search( $country, $countries, true ) ) { |
|
324 | + foreach (wpinv_get_continents('countries') as $continent_code => $countries) { |
|
325 | + if (false !== array_search($country, $countries, true)) { |
|
326 | 326 | return $continent_code; |
327 | 327 | } |
328 | 328 | } |
@@ -338,13 +338,13 @@ discard block |
||
338 | 338 | * @param string $country Country code. If no code is specified, defaults to the default country. |
339 | 339 | * @return array |
340 | 340 | */ |
341 | -function wpinv_get_country_calling_code( $country = null ) { |
|
341 | +function wpinv_get_country_calling_code($country = null) { |
|
342 | 342 | |
343 | - $country = wpinv_sanitize_country( $country ); |
|
344 | - $codes = wpinv_get_data( 'phone-codes' ); |
|
345 | - $code = isset( $codes[ $country ] ) ? $codes[ $country ] : ''; |
|
343 | + $country = wpinv_sanitize_country($country); |
|
344 | + $codes = wpinv_get_data('phone-codes'); |
|
345 | + $code = isset($codes[$country]) ? $codes[$country] : ''; |
|
346 | 346 | |
347 | - if ( is_array( $code ) ) { |
|
347 | + if (is_array($code)) { |
|
348 | 348 | return $code[0]; |
349 | 349 | } |
350 | 350 | return $code; |
@@ -357,8 +357,8 @@ discard block |
||
357 | 357 | * @param bool $first_empty Whether or not the first item in the list should be empty |
358 | 358 | * @return array |
359 | 359 | */ |
360 | -function wpinv_get_country_list( $first_empty = false ) { |
|
361 | - return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty ); |
|
360 | +function wpinv_get_country_list($first_empty = false) { |
|
361 | + return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | /** |
@@ -368,22 +368,22 @@ discard block |
||
368 | 368 | * @param bool $first_empty Whether or not the first item in the list should be empty |
369 | 369 | * @return array |
370 | 370 | */ |
371 | -function wpinv_get_country_states( $country = null, $first_empty = false ) { |
|
371 | +function wpinv_get_country_states($country = null, $first_empty = false) { |
|
372 | 372 | |
373 | 373 | // Prepare the country. |
374 | - $country = wpinv_sanitize_country( $country ); |
|
374 | + $country = wpinv_sanitize_country($country); |
|
375 | 375 | |
376 | 376 | // Fetch all states. |
377 | - $all_states = wpinv_get_data( 'states' ); |
|
377 | + $all_states = wpinv_get_data('states'); |
|
378 | 378 | |
379 | 379 | // Fetch the specified country's states. |
380 | - $states = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array(); |
|
381 | - $states = apply_filters( "wpinv_{$country}_states", $states ); |
|
382 | - $states = apply_filters( 'wpinv_country_states', $states, $country ); |
|
380 | + $states = isset($all_states[$country]) ? $all_states[$country] : array(); |
|
381 | + $states = apply_filters("wpinv_{$country}_states", $states); |
|
382 | + $states = apply_filters('wpinv_country_states', $states, $country); |
|
383 | 383 | |
384 | - asort( $states ); |
|
384 | + asort($states); |
|
385 | 385 | |
386 | - return wpinv_maybe_add_empty_option( $states, $first_empty ); |
|
386 | + return wpinv_maybe_add_empty_option($states, $first_empty); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | * @return array |
394 | 394 | */ |
395 | 395 | function wpinv_get_us_states_list() { |
396 | - return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) ); |
|
396 | + return apply_filters('wpinv_usa_states', wpinv_get_country_states('US')); |
|
397 | 397 | } |
398 | 398 | |
399 | 399 | /** |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | * @return array |
404 | 404 | */ |
405 | 405 | function wpinv_get_canada_states_list() { |
406 | - return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) ); |
|
406 | + return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA')); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | * @return array |
414 | 414 | */ |
415 | 415 | function wpinv_get_australia_states_list() { |
416 | - return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) ); |
|
416 | + return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU')); |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | /** |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | * @return array |
424 | 424 | */ |
425 | 425 | function wpinv_get_bangladesh_states_list() { |
426 | - return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) ); |
|
426 | + return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD')); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | /** |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | * @return array |
434 | 434 | */ |
435 | 435 | function wpinv_get_brazil_states_list() { |
436 | - return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) ); |
|
436 | + return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR')); |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | /** |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | * @return array |
444 | 444 | */ |
445 | 445 | function wpinv_get_bulgaria_states_list() { |
446 | - return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) ); |
|
446 | + return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG')); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | * @return array |
454 | 454 | */ |
455 | 455 | function wpinv_get_hong_kong_states_list() { |
456 | - return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) ); |
|
456 | + return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK')); |
|
457 | 457 | } |
458 | 458 | |
459 | 459 | /** |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | * @return array |
464 | 464 | */ |
465 | 465 | function wpinv_get_hungary_states_list() { |
466 | - return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) ); |
|
466 | + return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU')); |
|
467 | 467 | } |
468 | 468 | |
469 | 469 | /** |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | * @return array |
474 | 474 | */ |
475 | 475 | function wpinv_get_japan_states_list() { |
476 | - return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) ); |
|
476 | + return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP')); |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | /** |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | * @return array |
484 | 484 | */ |
485 | 485 | function wpinv_get_china_states_list() { |
486 | - return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) ); |
|
486 | + return apply_filters('wpinv_china_states', wpinv_get_country_states('CN')); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | /** |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | * @return array |
494 | 494 | */ |
495 | 495 | function wpinv_get_new_zealand_states_list() { |
496 | - return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) ); |
|
496 | + return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ')); |
|
497 | 497 | } |
498 | 498 | |
499 | 499 | /** |
@@ -503,7 +503,7 @@ discard block |
||
503 | 503 | * @return array |
504 | 504 | */ |
505 | 505 | function wpinv_get_peru_states_list() { |
506 | - return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) ); |
|
506 | + return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE')); |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | /** |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | * @return array |
514 | 514 | */ |
515 | 515 | function wpinv_get_indonesia_states_list() { |
516 | - return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) ); |
|
516 | + return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID')); |
|
517 | 517 | } |
518 | 518 | |
519 | 519 | /** |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | * @return array |
524 | 524 | */ |
525 | 525 | function wpinv_get_india_states_list() { |
526 | - return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) ); |
|
526 | + return apply_filters('wpinv_india_states', wpinv_get_country_states('IN')); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | * @return array |
534 | 534 | */ |
535 | 535 | function wpinv_get_iran_states_list() { |
536 | - return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) ); |
|
536 | + return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR')); |
|
537 | 537 | } |
538 | 538 | |
539 | 539 | /** |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | * @return array |
544 | 544 | */ |
545 | 545 | function wpinv_get_italy_states_list() { |
546 | - return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) ); |
|
546 | + return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT')); |
|
547 | 547 | } |
548 | 548 | |
549 | 549 | /** |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | * @return array |
554 | 554 | */ |
555 | 555 | function wpinv_get_malaysia_states_list() { |
556 | - return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) ); |
|
556 | + return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY')); |
|
557 | 557 | } |
558 | 558 | |
559 | 559 | /** |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | * @return array |
564 | 564 | */ |
565 | 565 | function wpinv_get_mexico_states_list() { |
566 | - return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) ); |
|
566 | + return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX')); |
|
567 | 567 | } |
568 | 568 | |
569 | 569 | /** |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | * @return array |
574 | 574 | */ |
575 | 575 | function wpinv_get_nepal_states_list() { |
576 | - return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) ); |
|
576 | + return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP')); |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | /** |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | * @return array |
584 | 584 | */ |
585 | 585 | function wpinv_get_south_africa_states_list() { |
586 | - return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) ); |
|
586 | + return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA')); |
|
587 | 587 | } |
588 | 588 | |
589 | 589 | /** |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | * @return array |
594 | 594 | */ |
595 | 595 | function wpinv_get_thailand_states_list() { |
596 | - return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) ); |
|
596 | + return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH')); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | /** |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | * @return array |
604 | 604 | */ |
605 | 605 | function wpinv_get_turkey_states_list() { |
606 | - return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) ); |
|
606 | + return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR')); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | /** |
@@ -613,31 +613,31 @@ discard block |
||
613 | 613 | * @return array |
614 | 614 | */ |
615 | 615 | function wpinv_get_spain_states_list() { |
616 | - return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) ); |
|
616 | + return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES')); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | function wpinv_get_states_field() { |
620 | - if ( empty( $_POST['country'] ) ) { |
|
620 | + if (empty($_POST['country'])) { |
|
621 | 621 | $_POST['country'] = wpinv_get_default_country(); |
622 | 622 | } |
623 | - $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
623 | + $states = wpinv_get_country_states(sanitize_text_field($_POST['country'])); |
|
624 | 624 | |
625 | - if ( ! empty( $states ) ) { |
|
626 | - $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
625 | + if (!empty($states)) { |
|
626 | + $sanitized_field_name = sanitize_text_field($_POST['field_name']); |
|
627 | 627 | |
628 | - $class = isset( $_POST['class'] ) ? esc_attr( sanitize_text_field( $_POST['class'] ) ) : ''; |
|
628 | + $class = isset($_POST['class']) ? esc_attr(sanitize_text_field($_POST['class'])) : ''; |
|
629 | 629 | $class .= " $sanitized_field_name getpaid_js_field-state custom-select wpinv-select wpi_select2"; |
630 | 630 | |
631 | - $args = array( |
|
631 | + $args = array( |
|
632 | 632 | 'name' => $sanitized_field_name, |
633 | 633 | 'id' => $sanitized_field_name, |
634 | - 'class' => implode( ' ', array_unique( explode( ' ', $class ) ) ), |
|
635 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
634 | + 'class' => implode(' ', array_unique(explode(' ', $class))), |
|
635 | + 'options' => array_merge(array('' => ''), $states), |
|
636 | 636 | 'show_option_all' => false, |
637 | 637 | 'show_option_none' => false, |
638 | 638 | ); |
639 | 639 | |
640 | - wpinv_html_select( $args ); |
|
640 | + wpinv_html_select($args); |
|
641 | 641 | |
642 | 642 | } else { |
643 | 643 | echo 'nostates'; |
@@ -645,10 +645,10 @@ discard block |
||
645 | 645 | |
646 | 646 | } |
647 | 647 | |
648 | -function wpinv_default_billing_country( $country = '', $user_id = 0 ) { |
|
649 | - $country = ! empty( $country ) ? $country : wpinv_get_default_country(); |
|
648 | +function wpinv_default_billing_country($country = '', $user_id = 0) { |
|
649 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
650 | 650 | |
651 | - return apply_filters( 'wpinv_default_billing_country', $country, $user_id ); |
|
651 | + return apply_filters('wpinv_default_billing_country', $country, $user_id); |
|
652 | 652 | } |
653 | 653 | |
654 | 654 | /** |
@@ -710,9 +710,9 @@ discard block |
||
710 | 710 | * @see `wpinv_get_invoice_address_replacements` |
711 | 711 | * @return string |
712 | 712 | */ |
713 | -function wpinv_get_full_address_format( $country = false ) { |
|
713 | +function wpinv_get_full_address_format($country = false) { |
|
714 | 714 | |
715 | - if ( empty( $country ) ) { |
|
715 | + if (empty($country)) { |
|
716 | 716 | $country = wpinv_get_default_country(); |
717 | 717 | } |
718 | 718 | |
@@ -720,7 +720,7 @@ discard block |
||
720 | 720 | $formats = wpinv_get_address_formats(); |
721 | 721 | |
722 | 722 | // Get format for the specified country. |
723 | - $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
723 | + $format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default']; |
|
724 | 724 | |
725 | 725 | /** |
726 | 726 | * Filters the address format to use on Invoices. |
@@ -732,7 +732,7 @@ discard block |
||
732 | 732 | * @param string $format The address format to use. |
733 | 733 | * @param string $country The country who's address format is being retrieved. |
734 | 734 | */ |
735 | - return apply_filters( 'wpinv_get_full_address_format', $format, $country ); |
|
735 | + return apply_filters('wpinv_get_full_address_format', $format, $country); |
|
736 | 736 | } |
737 | 737 | |
738 | 738 | /** |
@@ -743,7 +743,7 @@ discard block |
||
743 | 743 | * @param array $billing_details customer's billing details |
744 | 744 | * @return array |
745 | 745 | */ |
746 | -function wpinv_get_invoice_address_replacements( $billing_details ) { |
|
746 | +function wpinv_get_invoice_address_replacements($billing_details) { |
|
747 | 747 | |
748 | 748 | $default_args = array( |
749 | 749 | 'address' => '', |
@@ -756,15 +756,15 @@ discard block |
||
756 | 756 | 'company' => '', |
757 | 757 | ); |
758 | 758 | |
759 | - $args = map_deep( wp_parse_args( array_filter( $billing_details ), $default_args ), 'trim' ); |
|
759 | + $args = map_deep(wp_parse_args(array_filter($billing_details), $default_args), 'trim'); |
|
760 | 760 | $state = $args['state']; |
761 | 761 | $country = $args['country']; |
762 | 762 | |
763 | 763 | // Handle full country name. |
764 | - $full_country = empty( $country ) ? $country : wpinv_country_name( $country ); |
|
764 | + $full_country = empty($country) ? $country : wpinv_country_name($country); |
|
765 | 765 | |
766 | 766 | // Handle full state name. |
767 | - $full_state = ( $country && $state ) ? wpinv_state_name( $state, $country ) : $state; |
|
767 | + $full_state = ($country && $state) ? wpinv_state_name($state, $country) : $state; |
|
768 | 768 | |
769 | 769 | $args['postcode'] = $args['zip']; |
770 | 770 | $args['name'] = $args['first_name'] . ' ' . $args['last_name']; |
@@ -782,14 +782,14 @@ discard block |
||
782 | 782 | * @param array $replacements The address replacements to use. |
783 | 783 | * @param array $billing_details The billing details to use. |
784 | 784 | */ |
785 | - $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details ); |
|
785 | + $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details); |
|
786 | 786 | |
787 | 787 | $return = array(); |
788 | 788 | |
789 | - foreach ( $replacements as $key => $value ) { |
|
790 | - $value = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : ''; |
|
791 | - $return[ '{{' . $key . '}}' ] = $value; |
|
792 | - $return[ '{{' . $key . '_upper}}' ] = wpinv_utf8_strtoupper( $value ); |
|
789 | + foreach ($replacements as $key => $value) { |
|
790 | + $value = is_scalar($value) ? trim(sanitize_text_field($value)) : ''; |
|
791 | + $return['{{' . $key . '}}'] = $value; |
|
792 | + $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value); |
|
793 | 793 | } |
794 | 794 | |
795 | 795 | return $return; |
@@ -803,6 +803,6 @@ discard block |
||
803 | 803 | * @since 1.0.14 |
804 | 804 | * @return string |
805 | 805 | */ |
806 | -function wpinv_trim_formatted_address_line( $line ) { |
|
807 | - return trim( $line, ', ' ); |
|
806 | +function wpinv_trim_formatted_address_line($line) { |
|
807 | + return trim($line, ', '); |
|
808 | 808 | } |
@@ -12,493 +12,493 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Invoice_Notification_Emails { |
14 | 14 | |
15 | - /** |
|
16 | - * The array of invoice email actions. |
|
17 | - * |
|
18 | - * @param array |
|
19 | - */ |
|
20 | - public $invoice_actions; |
|
21 | - |
|
22 | - /** |
|
23 | - * Class constructor |
|
24 | - * |
|
25 | - */ |
|
26 | - public function __construct() { |
|
27 | - |
|
28 | - $this->invoice_actions = apply_filters( |
|
29 | - 'getpaid_notification_email_invoice_triggers', |
|
30 | - array( |
|
31 | - 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
32 | - 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
33 | - 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
34 | - 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
35 | - 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
36 | - 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
37 | - 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
38 | - 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
39 | - 'getpaid_new_customer_note' => 'user_note', |
|
40 | - 'getpaid_daily_maintenance' => 'overdue', |
|
41 | - ) |
|
42 | - ); |
|
43 | - |
|
44 | - $this->init_hooks(); |
|
45 | - |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Registers email hooks. |
|
50 | - */ |
|
51 | - public function init_hooks() { |
|
52 | - |
|
53 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | - add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
55 | - |
|
56 | - foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | - $this->init_email_type_hook( $hook, $email_type ); |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Registers an email hook for an invoice action. |
|
63 | - * |
|
64 | - * @param string $hook |
|
65 | - * @param string|array $email_type |
|
66 | - */ |
|
67 | - public function init_email_type_hook( $hook, $email_type ) { |
|
68 | - |
|
69 | - $email_type = wpinv_parse_list( $email_type ); |
|
70 | - |
|
71 | - foreach ( $email_type as $type ) { |
|
72 | - |
|
73 | - $email = new GetPaid_Notification_Email( $type ); |
|
74 | - |
|
75 | - // Abort if it is not active. |
|
76 | - if ( ! $email->is_active() ) { |
|
77 | - continue; |
|
78 | - } |
|
79 | - |
|
80 | - if ( method_exists( $this, $type ) ) { |
|
81 | - add_action( $hook, array( $this, $type ), 100, 2 ); |
|
82 | - continue; |
|
83 | - } |
|
84 | - |
|
85 | - do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
86 | - } |
|
87 | - |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Filters invoice merge tags. |
|
92 | - * |
|
93 | - * @param array $merge_tags |
|
94 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
95 | - */ |
|
96 | - public function invoice_merge_tags( $merge_tags, $object ) { |
|
97 | - |
|
98 | - if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
99 | - return array_merge( |
|
100 | - $merge_tags, |
|
101 | - $this->get_invoice_merge_tags( $object ) |
|
102 | - ); |
|
103 | - } |
|
104 | - |
|
105 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
106 | - return array_merge( |
|
107 | - $merge_tags, |
|
108 | - $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
109 | - ); |
|
110 | - } |
|
111 | - |
|
112 | - return $merge_tags; |
|
113 | - |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Generates invoice merge tags. |
|
118 | - * |
|
119 | - * @param WPInv_Invoice $invoice |
|
120 | - * @return array |
|
121 | - */ |
|
122 | - public function get_invoice_merge_tags( $invoice ) { |
|
123 | - |
|
124 | - // Abort if it does not exist. |
|
125 | - if ( ! $invoice->get_id() ) { |
|
126 | - return array(); |
|
127 | - } |
|
128 | - |
|
129 | - $due_date = $invoice->get_due_date(); |
|
130 | - $due_date = empty( $due_date ) ? time() + MINUTE_IN_SECONDS : strtotime( $due_date ) + ( (int) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
|
131 | - $merge_tags = array( |
|
132 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
133 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
134 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
135 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
136 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
137 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
138 | - '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
139 | - '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
140 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
141 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
142 | - '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ), |
|
143 | - '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
144 | - '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
145 | - '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
146 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
147 | - '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
148 | - '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
149 | - '{is_was}' => $due_date < time() ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
150 | - ); |
|
151 | - |
|
152 | - $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
153 | - |
|
154 | - if ( is_array( $payment_form_data ) ) { |
|
155 | - |
|
156 | - foreach ( $payment_form_data as $label => $value ) { |
|
157 | - |
|
158 | - $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
159 | - $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
160 | - |
|
161 | - if ( is_scalar( $value ) ) { |
|
162 | - $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
163 | - } |
|
164 | - } |
|
165 | - } |
|
166 | - |
|
167 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Helper function to send an email. |
|
172 | - * |
|
173 | - * @param WPInv_Invoice $invoice |
|
174 | - * @param GetPaid_Notification_Email $email |
|
175 | - * @param string $type |
|
176 | - * @param string|array $recipients |
|
177 | - * @param array $extra_args Extra template args. |
|
178 | - */ |
|
179 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
180 | - |
|
181 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
182 | - |
|
183 | - $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
184 | - if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
185 | - return; |
|
186 | - } |
|
187 | - |
|
188 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
189 | - $merge_tags = $email->get_merge_tags(); |
|
190 | - |
|
191 | - $result = $mailer->send( |
|
192 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
193 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
194 | - $email->get_content( $merge_tags, $extra_args ), |
|
195 | - $email->get_attachments() |
|
196 | - ); |
|
197 | - |
|
198 | - // Maybe send a copy to the admin. |
|
199 | - if ( $email->include_admin_bcc() ) { |
|
200 | - $mailer->send( |
|
201 | - wpinv_get_admin_email(), |
|
202 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
203 | - $email->get_content( $merge_tags ), |
|
204 | - $email->get_attachments() |
|
205 | - ); |
|
206 | - } |
|
207 | - |
|
208 | - if ( $result ) { |
|
209 | - $invoice->add_system_note( |
|
210 | - sprintf( |
|
211 | - // translators: %1 is the email type, %2 is the invoice recipient. |
|
212 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
213 | - sanitize_key( $type ), |
|
214 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
215 | - ) |
|
216 | - ); |
|
217 | - } else { |
|
218 | - $invoice->add_system_note( |
|
219 | - sprintf( |
|
220 | - // translators: %1 is the email type, %2 is the invoice recipient. |
|
221 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
222 | - sanitize_key( $type ), |
|
223 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
224 | - ) |
|
225 | - ); |
|
226 | - } |
|
227 | - |
|
228 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
229 | - |
|
230 | - return $result; |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * Also send emails to any cc users. |
|
235 | - * |
|
236 | - * @param array $recipients |
|
237 | - * @param GetPaid_Notification_Email $email |
|
238 | - */ |
|
239 | - public function filter_email_recipients( $recipients, $email ) { |
|
240 | - |
|
241 | - if ( ! $email->is_admin_email() ) { |
|
242 | - $cc = $email->object->get_email_cc(); |
|
243 | - $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
244 | - |
|
245 | - if ( ! empty( $cc ) ) { |
|
246 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
247 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
248 | - } |
|
249 | - |
|
250 | - if ( ! empty( $cc_2 ) ) { |
|
251 | - $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
252 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
253 | - } |
|
254 | - } |
|
255 | - |
|
256 | - return $recipients; |
|
257 | - |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Sends a new invoice notification. |
|
262 | - * |
|
263 | - * @param WPInv_Invoice $invoice |
|
264 | - */ |
|
265 | - public function new_invoice( $invoice ) { |
|
266 | - |
|
267 | - // Only send this email for invoices created via the admin page. |
|
268 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
269 | - return; |
|
270 | - } |
|
271 | - |
|
272 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
273 | - $recipient = wpinv_get_admin_email(); |
|
274 | - |
|
275 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
276 | - |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Sends a cancelled invoice notification. |
|
281 | - * |
|
282 | - * @param WPInv_Invoice $invoice |
|
283 | - */ |
|
284 | - public function cancelled_invoice( $invoice ) { |
|
285 | - |
|
286 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
287 | - $recipient = $invoice->get_email(); |
|
288 | - |
|
289 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Sends a failed invoice notification. |
|
294 | - * |
|
295 | - * @param WPInv_Invoice $invoice |
|
296 | - */ |
|
297 | - public function failed_invoice( $invoice ) { |
|
298 | - |
|
299 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
300 | - $recipient = wpinv_get_admin_email(); |
|
301 | - |
|
302 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
303 | - |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Sends a notification whenever an invoice is put on hold. |
|
308 | - * |
|
309 | - * @param WPInv_Invoice $invoice |
|
310 | - */ |
|
311 | - public function onhold_invoice( $invoice ) { |
|
312 | - |
|
313 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
314 | - $recipient = $invoice->get_email(); |
|
315 | - |
|
316 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
317 | - |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * Sends a notification whenever an invoice is marked as processing payment. |
|
322 | - * |
|
323 | - * @param WPInv_Invoice $invoice |
|
324 | - */ |
|
325 | - public function processing_invoice( $invoice ) { |
|
326 | - |
|
327 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
328 | - $recipient = $invoice->get_email(); |
|
329 | - |
|
330 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
331 | - |
|
332 | - } |
|
333 | - |
|
334 | - /** |
|
335 | - * Sends a notification whenever an invoice is paid. |
|
336 | - * |
|
337 | - * @param WPInv_Invoice $invoice |
|
338 | - */ |
|
339 | - public function completed_invoice( $invoice ) { |
|
340 | - |
|
341 | - // (Maybe) abort if it is a renewal invoice. |
|
342 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
343 | - return; |
|
344 | - } |
|
345 | - |
|
346 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
347 | - $recipient = $invoice->get_email(); |
|
348 | - |
|
349 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
350 | - |
|
351 | - } |
|
15 | + /** |
|
16 | + * The array of invoice email actions. |
|
17 | + * |
|
18 | + * @param array |
|
19 | + */ |
|
20 | + public $invoice_actions; |
|
21 | + |
|
22 | + /** |
|
23 | + * Class constructor |
|
24 | + * |
|
25 | + */ |
|
26 | + public function __construct() { |
|
27 | + |
|
28 | + $this->invoice_actions = apply_filters( |
|
29 | + 'getpaid_notification_email_invoice_triggers', |
|
30 | + array( |
|
31 | + 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
32 | + 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
33 | + 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
34 | + 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
35 | + 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
36 | + 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
37 | + 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
38 | + 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
39 | + 'getpaid_new_customer_note' => 'user_note', |
|
40 | + 'getpaid_daily_maintenance' => 'overdue', |
|
41 | + ) |
|
42 | + ); |
|
43 | + |
|
44 | + $this->init_hooks(); |
|
45 | + |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Registers email hooks. |
|
50 | + */ |
|
51 | + public function init_hooks() { |
|
52 | + |
|
53 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | + add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
55 | + |
|
56 | + foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | + $this->init_email_type_hook( $hook, $email_type ); |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Registers an email hook for an invoice action. |
|
63 | + * |
|
64 | + * @param string $hook |
|
65 | + * @param string|array $email_type |
|
66 | + */ |
|
67 | + public function init_email_type_hook( $hook, $email_type ) { |
|
68 | + |
|
69 | + $email_type = wpinv_parse_list( $email_type ); |
|
70 | + |
|
71 | + foreach ( $email_type as $type ) { |
|
72 | + |
|
73 | + $email = new GetPaid_Notification_Email( $type ); |
|
74 | + |
|
75 | + // Abort if it is not active. |
|
76 | + if ( ! $email->is_active() ) { |
|
77 | + continue; |
|
78 | + } |
|
79 | + |
|
80 | + if ( method_exists( $this, $type ) ) { |
|
81 | + add_action( $hook, array( $this, $type ), 100, 2 ); |
|
82 | + continue; |
|
83 | + } |
|
84 | + |
|
85 | + do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
86 | + } |
|
87 | + |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Filters invoice merge tags. |
|
92 | + * |
|
93 | + * @param array $merge_tags |
|
94 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
95 | + */ |
|
96 | + public function invoice_merge_tags( $merge_tags, $object ) { |
|
97 | + |
|
98 | + if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
99 | + return array_merge( |
|
100 | + $merge_tags, |
|
101 | + $this->get_invoice_merge_tags( $object ) |
|
102 | + ); |
|
103 | + } |
|
104 | + |
|
105 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
106 | + return array_merge( |
|
107 | + $merge_tags, |
|
108 | + $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
109 | + ); |
|
110 | + } |
|
111 | + |
|
112 | + return $merge_tags; |
|
113 | + |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Generates invoice merge tags. |
|
118 | + * |
|
119 | + * @param WPInv_Invoice $invoice |
|
120 | + * @return array |
|
121 | + */ |
|
122 | + public function get_invoice_merge_tags( $invoice ) { |
|
123 | + |
|
124 | + // Abort if it does not exist. |
|
125 | + if ( ! $invoice->get_id() ) { |
|
126 | + return array(); |
|
127 | + } |
|
128 | + |
|
129 | + $due_date = $invoice->get_due_date(); |
|
130 | + $due_date = empty( $due_date ) ? time() + MINUTE_IN_SECONDS : strtotime( $due_date ) + ( (int) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
|
131 | + $merge_tags = array( |
|
132 | + '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
133 | + '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
134 | + '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
135 | + '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
136 | + '{email}' => sanitize_email( $invoice->get_email() ), |
|
137 | + '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
138 | + '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
139 | + '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
140 | + '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
141 | + '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
142 | + '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ), |
|
143 | + '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
144 | + '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
145 | + '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
146 | + '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
147 | + '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
148 | + '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
149 | + '{is_was}' => $due_date < time() ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
150 | + ); |
|
151 | + |
|
152 | + $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
153 | + |
|
154 | + if ( is_array( $payment_form_data ) ) { |
|
155 | + |
|
156 | + foreach ( $payment_form_data as $label => $value ) { |
|
157 | + |
|
158 | + $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
159 | + $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
160 | + |
|
161 | + if ( is_scalar( $value ) ) { |
|
162 | + $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
163 | + } |
|
164 | + } |
|
165 | + } |
|
166 | + |
|
167 | + return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
168 | + } |
|
352 | 169 | |
353 | - /** |
|
354 | - * Sends a notification whenever an invoice is refunded. |
|
355 | - * |
|
356 | - * @param WPInv_Invoice $invoice |
|
357 | - */ |
|
358 | - public function refunded_invoice( $invoice ) { |
|
359 | - |
|
360 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
361 | - $recipient = $invoice->get_email(); |
|
362 | - |
|
363 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
364 | - |
|
365 | - } |
|
170 | + /** |
|
171 | + * Helper function to send an email. |
|
172 | + * |
|
173 | + * @param WPInv_Invoice $invoice |
|
174 | + * @param GetPaid_Notification_Email $email |
|
175 | + * @param string $type |
|
176 | + * @param string|array $recipients |
|
177 | + * @param array $extra_args Extra template args. |
|
178 | + */ |
|
179 | + public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
366 | 180 | |
367 | - /** |
|
368 | - * Notifies a user about new invoices |
|
369 | - * |
|
370 | - * @param WPInv_Invoice $invoice |
|
371 | - * @param bool $force |
|
372 | - */ |
|
373 | - public function user_invoice( $invoice, $force = false ) { |
|
181 | + do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
374 | 182 | |
375 | - if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
376 | - return; |
|
377 | - } |
|
378 | - |
|
379 | - // Only send this email for invoices created via the admin page. |
|
380 | - if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
381 | - return; |
|
382 | - } |
|
383 | - |
|
384 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
385 | - $recipient = $invoice->get_email(); |
|
386 | - |
|
387 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
388 | - |
|
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * Checks if an invoice is a payment form invoice. |
|
393 | - * |
|
394 | - * @param int $invoice |
|
395 | - * @return bool |
|
396 | - */ |
|
397 | - public function is_payment_form_invoice( $invoice ) { |
|
398 | - $created_via = get_post_meta( $invoice, 'wpinv_created_via', true ); |
|
399 | - $is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via; |
|
400 | - $is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
401 | - return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice; |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Notifies admin about new invoice notes |
|
406 | - * |
|
407 | - * @param WPInv_Invoice $invoice |
|
408 | - * @param string $note |
|
409 | - */ |
|
410 | - public function user_note( $invoice, $note ) { |
|
411 | - |
|
412 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
413 | - $recipient = $invoice->get_email(); |
|
414 | - |
|
415 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
416 | - |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * (Force) Sends overdue notices. |
|
421 | - * |
|
422 | - * @param WPInv_Invoice $invoice |
|
423 | - */ |
|
424 | - public function force_send_overdue_notice( $invoice ) { |
|
425 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
426 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
427 | - } |
|
428 | - |
|
429 | - /** |
|
430 | - * Sends overdue notices. |
|
431 | - * |
|
432 | - * @TODO: Create an invoices query class. |
|
433 | - */ |
|
434 | - public function overdue() { |
|
435 | - global $wpdb; |
|
436 | - |
|
437 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
438 | - |
|
439 | - // Fetch reminder days. |
|
440 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
441 | - |
|
442 | - // Abort if non is set. |
|
443 | - if ( empty( $reminder_days ) ) { |
|
444 | - return; |
|
445 | - } |
|
446 | - |
|
447 | - // Retrieve date query. |
|
448 | - $date_query = $this->get_date_query( $reminder_days ); |
|
449 | - |
|
450 | - // Invoices table. |
|
451 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
452 | - |
|
453 | - // Fetch invoices. |
|
454 | - $invoices = $wpdb->get_col( |
|
455 | - "SELECT posts.ID FROM $wpdb->posts as posts |
|
183 | + $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
184 | + if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
185 | + return; |
|
186 | + } |
|
187 | + |
|
188 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
189 | + $merge_tags = $email->get_merge_tags(); |
|
190 | + |
|
191 | + $result = $mailer->send( |
|
192 | + apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
193 | + $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
194 | + $email->get_content( $merge_tags, $extra_args ), |
|
195 | + $email->get_attachments() |
|
196 | + ); |
|
197 | + |
|
198 | + // Maybe send a copy to the admin. |
|
199 | + if ( $email->include_admin_bcc() ) { |
|
200 | + $mailer->send( |
|
201 | + wpinv_get_admin_email(), |
|
202 | + $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
203 | + $email->get_content( $merge_tags ), |
|
204 | + $email->get_attachments() |
|
205 | + ); |
|
206 | + } |
|
207 | + |
|
208 | + if ( $result ) { |
|
209 | + $invoice->add_system_note( |
|
210 | + sprintf( |
|
211 | + // translators: %1 is the email type, %2 is the invoice recipient. |
|
212 | + __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
213 | + sanitize_key( $type ), |
|
214 | + $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
215 | + ) |
|
216 | + ); |
|
217 | + } else { |
|
218 | + $invoice->add_system_note( |
|
219 | + sprintf( |
|
220 | + // translators: %1 is the email type, %2 is the invoice recipient. |
|
221 | + __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
222 | + sanitize_key( $type ), |
|
223 | + $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
224 | + ) |
|
225 | + ); |
|
226 | + } |
|
227 | + |
|
228 | + do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
229 | + |
|
230 | + return $result; |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * Also send emails to any cc users. |
|
235 | + * |
|
236 | + * @param array $recipients |
|
237 | + * @param GetPaid_Notification_Email $email |
|
238 | + */ |
|
239 | + public function filter_email_recipients( $recipients, $email ) { |
|
240 | + |
|
241 | + if ( ! $email->is_admin_email() ) { |
|
242 | + $cc = $email->object->get_email_cc(); |
|
243 | + $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
244 | + |
|
245 | + if ( ! empty( $cc ) ) { |
|
246 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
247 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
248 | + } |
|
249 | + |
|
250 | + if ( ! empty( $cc_2 ) ) { |
|
251 | + $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
252 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
253 | + } |
|
254 | + } |
|
255 | + |
|
256 | + return $recipients; |
|
257 | + |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Sends a new invoice notification. |
|
262 | + * |
|
263 | + * @param WPInv_Invoice $invoice |
|
264 | + */ |
|
265 | + public function new_invoice( $invoice ) { |
|
266 | + |
|
267 | + // Only send this email for invoices created via the admin page. |
|
268 | + if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
269 | + return; |
|
270 | + } |
|
271 | + |
|
272 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
273 | + $recipient = wpinv_get_admin_email(); |
|
274 | + |
|
275 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
276 | + |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Sends a cancelled invoice notification. |
|
281 | + * |
|
282 | + * @param WPInv_Invoice $invoice |
|
283 | + */ |
|
284 | + public function cancelled_invoice( $invoice ) { |
|
285 | + |
|
286 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
287 | + $recipient = $invoice->get_email(); |
|
288 | + |
|
289 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Sends a failed invoice notification. |
|
294 | + * |
|
295 | + * @param WPInv_Invoice $invoice |
|
296 | + */ |
|
297 | + public function failed_invoice( $invoice ) { |
|
298 | + |
|
299 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
300 | + $recipient = wpinv_get_admin_email(); |
|
301 | + |
|
302 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
303 | + |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Sends a notification whenever an invoice is put on hold. |
|
308 | + * |
|
309 | + * @param WPInv_Invoice $invoice |
|
310 | + */ |
|
311 | + public function onhold_invoice( $invoice ) { |
|
312 | + |
|
313 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
314 | + $recipient = $invoice->get_email(); |
|
315 | + |
|
316 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
317 | + |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * Sends a notification whenever an invoice is marked as processing payment. |
|
322 | + * |
|
323 | + * @param WPInv_Invoice $invoice |
|
324 | + */ |
|
325 | + public function processing_invoice( $invoice ) { |
|
326 | + |
|
327 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
328 | + $recipient = $invoice->get_email(); |
|
329 | + |
|
330 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
331 | + |
|
332 | + } |
|
333 | + |
|
334 | + /** |
|
335 | + * Sends a notification whenever an invoice is paid. |
|
336 | + * |
|
337 | + * @param WPInv_Invoice $invoice |
|
338 | + */ |
|
339 | + public function completed_invoice( $invoice ) { |
|
340 | + |
|
341 | + // (Maybe) abort if it is a renewal invoice. |
|
342 | + if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
343 | + return; |
|
344 | + } |
|
345 | + |
|
346 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
347 | + $recipient = $invoice->get_email(); |
|
348 | + |
|
349 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
350 | + |
|
351 | + } |
|
352 | + |
|
353 | + /** |
|
354 | + * Sends a notification whenever an invoice is refunded. |
|
355 | + * |
|
356 | + * @param WPInv_Invoice $invoice |
|
357 | + */ |
|
358 | + public function refunded_invoice( $invoice ) { |
|
359 | + |
|
360 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
361 | + $recipient = $invoice->get_email(); |
|
362 | + |
|
363 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
364 | + |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * Notifies a user about new invoices |
|
369 | + * |
|
370 | + * @param WPInv_Invoice $invoice |
|
371 | + * @param bool $force |
|
372 | + */ |
|
373 | + public function user_invoice( $invoice, $force = false ) { |
|
374 | + |
|
375 | + if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
376 | + return; |
|
377 | + } |
|
378 | + |
|
379 | + // Only send this email for invoices created via the admin page. |
|
380 | + if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
381 | + return; |
|
382 | + } |
|
383 | + |
|
384 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
385 | + $recipient = $invoice->get_email(); |
|
386 | + |
|
387 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
388 | + |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * Checks if an invoice is a payment form invoice. |
|
393 | + * |
|
394 | + * @param int $invoice |
|
395 | + * @return bool |
|
396 | + */ |
|
397 | + public function is_payment_form_invoice( $invoice ) { |
|
398 | + $created_via = get_post_meta( $invoice, 'wpinv_created_via', true ); |
|
399 | + $is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via; |
|
400 | + $is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
401 | + return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice; |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Notifies admin about new invoice notes |
|
406 | + * |
|
407 | + * @param WPInv_Invoice $invoice |
|
408 | + * @param string $note |
|
409 | + */ |
|
410 | + public function user_note( $invoice, $note ) { |
|
411 | + |
|
412 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
413 | + $recipient = $invoice->get_email(); |
|
414 | + |
|
415 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
416 | + |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * (Force) Sends overdue notices. |
|
421 | + * |
|
422 | + * @param WPInv_Invoice $invoice |
|
423 | + */ |
|
424 | + public function force_send_overdue_notice( $invoice ) { |
|
425 | + $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
426 | + return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
427 | + } |
|
428 | + |
|
429 | + /** |
|
430 | + * Sends overdue notices. |
|
431 | + * |
|
432 | + * @TODO: Create an invoices query class. |
|
433 | + */ |
|
434 | + public function overdue() { |
|
435 | + global $wpdb; |
|
436 | + |
|
437 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
438 | + |
|
439 | + // Fetch reminder days. |
|
440 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
441 | + |
|
442 | + // Abort if non is set. |
|
443 | + if ( empty( $reminder_days ) ) { |
|
444 | + return; |
|
445 | + } |
|
446 | + |
|
447 | + // Retrieve date query. |
|
448 | + $date_query = $this->get_date_query( $reminder_days ); |
|
449 | + |
|
450 | + // Invoices table. |
|
451 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
452 | + |
|
453 | + // Fetch invoices. |
|
454 | + $invoices = $wpdb->get_col( |
|
455 | + "SELECT posts.ID FROM $wpdb->posts as posts |
|
456 | 456 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
457 | 457 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query" |
458 | 458 | ); |
459 | 459 | |
460 | - foreach ( $invoices as $invoice ) { |
|
460 | + foreach ( $invoices as $invoice ) { |
|
461 | 461 | |
462 | - // Only send this email for invoices created via the admin page. |
|
463 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
464 | - $invoice = new WPInv_Invoice( $invoice ); |
|
465 | - $email->object = $invoice; |
|
462 | + // Only send this email for invoices created via the admin page. |
|
463 | + if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
464 | + $invoice = new WPInv_Invoice( $invoice ); |
|
465 | + $email->object = $invoice; |
|
466 | 466 | |
467 | - if ( $invoice->needs_payment() && ! $invoice->is_renewal() ) { |
|
468 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
469 | - } |
|
470 | - } |
|
471 | - } |
|
467 | + if ( $invoice->needs_payment() && ! $invoice->is_renewal() ) { |
|
468 | + $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
469 | + } |
|
470 | + } |
|
471 | + } |
|
472 | 472 | |
473 | - } |
|
473 | + } |
|
474 | 474 | |
475 | - /** |
|
476 | - * Calculates the date query for an invoices query |
|
477 | - * |
|
478 | - * @param array $reminder_days |
|
479 | - * @return string |
|
480 | - */ |
|
481 | - public function get_date_query( $reminder_days ) { |
|
475 | + /** |
|
476 | + * Calculates the date query for an invoices query |
|
477 | + * |
|
478 | + * @param array $reminder_days |
|
479 | + * @return string |
|
480 | + */ |
|
481 | + public function get_date_query( $reminder_days ) { |
|
482 | 482 | |
483 | - $date_query = array( |
|
484 | - 'relation' => 'OR', |
|
485 | - ); |
|
483 | + $date_query = array( |
|
484 | + 'relation' => 'OR', |
|
485 | + ); |
|
486 | 486 | |
487 | - foreach ( $reminder_days as $days ) { |
|
488 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
487 | + foreach ( $reminder_days as $days ) { |
|
488 | + $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
489 | 489 | |
490 | - $date_query[] = array( |
|
491 | - 'year' => $date['year'], |
|
492 | - 'month' => $date['month'], |
|
493 | - 'day' => $date['day'], |
|
494 | - ); |
|
490 | + $date_query[] = array( |
|
491 | + 'year' => $date['year'], |
|
492 | + 'month' => $date['month'], |
|
493 | + 'day' => $date['day'], |
|
494 | + ); |
|
495 | 495 | |
496 | - } |
|
496 | + } |
|
497 | 497 | |
498 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
498 | + $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
499 | 499 | |
500 | - return $date_query->get_sql(); |
|
500 | + return $date_query->get_sql(); |
|
501 | 501 | |
502 | - } |
|
502 | + } |
|
503 | 503 | |
504 | 504 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * This class handles invoice notificaiton emails. |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | $this->invoice_actions = apply_filters( |
29 | 29 | 'getpaid_notification_email_invoice_triggers', |
30 | 30 | array( |
31 | - 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
31 | + 'getpaid_new_invoice' => array('new_invoice', 'user_invoice'), |
|
32 | 32 | 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
33 | 33 | 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
34 | 34 | 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function init_hooks() { |
52 | 52 | |
53 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | - add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
53 | + add_filter('getpaid_get_email_merge_tags', array($this, 'invoice_merge_tags'), 10, 2); |
|
54 | + add_filter('getpaid_invoice_email_recipients', array($this, 'filter_email_recipients'), 10, 2); |
|
55 | 55 | |
56 | - foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | - $this->init_email_type_hook( $hook, $email_type ); |
|
56 | + foreach ($this->invoice_actions as $hook => $email_type) { |
|
57 | + $this->init_email_type_hook($hook, $email_type); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
@@ -64,25 +64,25 @@ discard block |
||
64 | 64 | * @param string $hook |
65 | 65 | * @param string|array $email_type |
66 | 66 | */ |
67 | - public function init_email_type_hook( $hook, $email_type ) { |
|
67 | + public function init_email_type_hook($hook, $email_type) { |
|
68 | 68 | |
69 | - $email_type = wpinv_parse_list( $email_type ); |
|
69 | + $email_type = wpinv_parse_list($email_type); |
|
70 | 70 | |
71 | - foreach ( $email_type as $type ) { |
|
71 | + foreach ($email_type as $type) { |
|
72 | 72 | |
73 | - $email = new GetPaid_Notification_Email( $type ); |
|
73 | + $email = new GetPaid_Notification_Email($type); |
|
74 | 74 | |
75 | 75 | // Abort if it is not active. |
76 | - if ( ! $email->is_active() ) { |
|
76 | + if (!$email->is_active()) { |
|
77 | 77 | continue; |
78 | 78 | } |
79 | 79 | |
80 | - if ( method_exists( $this, $type ) ) { |
|
81 | - add_action( $hook, array( $this, $type ), 100, 2 ); |
|
80 | + if (method_exists($this, $type)) { |
|
81 | + add_action($hook, array($this, $type), 100, 2); |
|
82 | 82 | continue; |
83 | 83 | } |
84 | 84 | |
85 | - do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
85 | + do_action('getpaid_invoice_init_email_type_hook', $type, $hook); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | } |
@@ -93,19 +93,19 @@ discard block |
||
93 | 93 | * @param array $merge_tags |
94 | 94 | * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
95 | 95 | */ |
96 | - public function invoice_merge_tags( $merge_tags, $object ) { |
|
96 | + public function invoice_merge_tags($merge_tags, $object) { |
|
97 | 97 | |
98 | - if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
98 | + if (is_a($object, 'WPInv_Invoice')) { |
|
99 | 99 | return array_merge( |
100 | 100 | $merge_tags, |
101 | - $this->get_invoice_merge_tags( $object ) |
|
101 | + $this->get_invoice_merge_tags($object) |
|
102 | 102 | ); |
103 | 103 | } |
104 | 104 | |
105 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
105 | + if (is_a($object, 'WPInv_Subscription')) { |
|
106 | 106 | return array_merge( |
107 | 107 | $merge_tags, |
108 | - $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
108 | + $this->get_invoice_merge_tags($object->get_parent_payment()) |
|
109 | 109 | ); |
110 | 110 | } |
111 | 111 | |
@@ -119,52 +119,52 @@ discard block |
||
119 | 119 | * @param WPInv_Invoice $invoice |
120 | 120 | * @return array |
121 | 121 | */ |
122 | - public function get_invoice_merge_tags( $invoice ) { |
|
122 | + public function get_invoice_merge_tags($invoice) { |
|
123 | 123 | |
124 | 124 | // Abort if it does not exist. |
125 | - if ( ! $invoice->get_id() ) { |
|
125 | + if (!$invoice->get_id()) { |
|
126 | 126 | return array(); |
127 | 127 | } |
128 | 128 | |
129 | 129 | $due_date = $invoice->get_due_date(); |
130 | - $due_date = empty( $due_date ) ? time() + MINUTE_IN_SECONDS : strtotime( $due_date ) + ( (int) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
|
130 | + $due_date = empty($due_date) ? time() + MINUTE_IN_SECONDS : strtotime($due_date) + ((int) get_option('gmt_offset') * HOUR_IN_SECONDS); |
|
131 | 131 | $merge_tags = array( |
132 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
133 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
134 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
135 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
136 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
137 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
138 | - '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
139 | - '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
140 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
141 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
142 | - '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ), |
|
143 | - '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
144 | - '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
145 | - '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
146 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
147 | - '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
148 | - '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
149 | - '{is_was}' => $due_date < time() ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
132 | + '{name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
133 | + '{full_name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
134 | + '{first_name}' => sanitize_text_field($invoice->get_first_name()), |
|
135 | + '{last_name}' => sanitize_text_field($invoice->get_last_name()), |
|
136 | + '{email}' => sanitize_email($invoice->get_email()), |
|
137 | + '{invoice_number}' => sanitize_text_field($invoice->get_number()), |
|
138 | + '{invoice_currency}' => sanitize_text_field($invoice->get_currency()), |
|
139 | + '{invoice_total}' => sanitize_text_field(wpinv_price($invoice->get_total(), $invoice->get_currency())), |
|
140 | + '{invoice_link}' => esc_url($invoice->get_view_url()), |
|
141 | + '{invoice_pay_link}' => esc_url($invoice->get_checkout_payment_url()), |
|
142 | + '{invoice_receipt_link}' => esc_url($invoice->get_receipt_url()), |
|
143 | + '{invoice_date}' => getpaid_format_date_value($invoice->get_date_created()), |
|
144 | + '{invoice_due_date}' => getpaid_format_date_value($invoice->get_due_date(), __('on receipt', 'invoicing')), |
|
145 | + '{invoice_quote}' => sanitize_text_field(strtolower($invoice->get_label())), |
|
146 | + '{invoice_label}' => sanitize_text_field(ucfirst($invoice->get_label())), |
|
147 | + '{invoice_description}' => wp_kses_post($invoice->get_description()), |
|
148 | + '{subscription_name}' => wp_kses_post($invoice->get_subscription_name()), |
|
149 | + '{is_was}' => $due_date < time() ? __('was', 'invoicing') : __('is', 'invoicing'), |
|
150 | 150 | ); |
151 | 151 | |
152 | - $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
152 | + $payment_form_data = $invoice->get_meta('payment_form_data', true); |
|
153 | 153 | |
154 | - if ( is_array( $payment_form_data ) ) { |
|
154 | + if (is_array($payment_form_data)) { |
|
155 | 155 | |
156 | - foreach ( $payment_form_data as $label => $value ) { |
|
156 | + foreach ($payment_form_data as $label => $value) { |
|
157 | 157 | |
158 | - $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
159 | - $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
158 | + $label = preg_replace('/[^a-z0-9]+/', '_', strtolower($label)); |
|
159 | + $value = is_array($value) ? implode(', ', $value) : $value; |
|
160 | 160 | |
161 | - if ( is_scalar( $value ) ) { |
|
162 | - $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
161 | + if (is_scalar($value)) { |
|
162 | + $merge_tags["{{$label}}"] = wp_kses_post($value); |
|
163 | 163 | } |
164 | 164 | } |
165 | 165 | } |
166 | 166 | |
167 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
167 | + return apply_filters('getpaid_invoice_email_merge_tags', $merge_tags, $invoice); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -176,12 +176,12 @@ discard block |
||
176 | 176 | * @param string|array $recipients |
177 | 177 | * @param array $extra_args Extra template args. |
178 | 178 | */ |
179 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
179 | + public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) { |
|
180 | 180 | |
181 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
181 | + do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email); |
|
182 | 182 | |
183 | - $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
184 | - if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
183 | + $skip = $invoice->is_free() && wpinv_get_option('skip_email_free_invoice'); |
|
184 | + if (apply_filters('getpaid_skip_invoice_email', $skip, $type, $invoice)) { |
|
185 | 185 | return; |
186 | 186 | } |
187 | 187 | |
@@ -189,43 +189,43 @@ discard block |
||
189 | 189 | $merge_tags = $email->get_merge_tags(); |
190 | 190 | |
191 | 191 | $result = $mailer->send( |
192 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
193 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
194 | - $email->get_content( $merge_tags, $extra_args ), |
|
192 | + apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email), |
|
193 | + $email->add_merge_tags($email->get_subject(), $merge_tags), |
|
194 | + $email->get_content($merge_tags, $extra_args), |
|
195 | 195 | $email->get_attachments() |
196 | 196 | ); |
197 | 197 | |
198 | 198 | // Maybe send a copy to the admin. |
199 | - if ( $email->include_admin_bcc() ) { |
|
199 | + if ($email->include_admin_bcc()) { |
|
200 | 200 | $mailer->send( |
201 | 201 | wpinv_get_admin_email(), |
202 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
203 | - $email->get_content( $merge_tags ), |
|
202 | + $email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags), |
|
203 | + $email->get_content($merge_tags), |
|
204 | 204 | $email->get_attachments() |
205 | 205 | ); |
206 | 206 | } |
207 | 207 | |
208 | - if ( $result ) { |
|
208 | + if ($result) { |
|
209 | 209 | $invoice->add_system_note( |
210 | 210 | sprintf( |
211 | 211 | // translators: %1 is the email type, %2 is the invoice recipient. |
212 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
213 | - sanitize_key( $type ), |
|
214 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
212 | + __('Successfully sent %1$s notification email to %2$s.', 'invoicing'), |
|
213 | + sanitize_key($type), |
|
214 | + $email->is_admin_email() ? __('admin', 'invoicing') : __('the customer', 'invoicing') |
|
215 | 215 | ) |
216 | 216 | ); |
217 | 217 | } else { |
218 | 218 | $invoice->add_system_note( |
219 | 219 | sprintf( |
220 | 220 | // translators: %1 is the email type, %2 is the invoice recipient. |
221 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
222 | - sanitize_key( $type ), |
|
223 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
221 | + __('Failed sending %1$s notification email to %2$s.', 'invoicing'), |
|
222 | + sanitize_key($type), |
|
223 | + $email->is_admin_email() ? __('admin', 'invoicing') : __('the customer', 'invoicing') |
|
224 | 224 | ) |
225 | 225 | ); |
226 | 226 | } |
227 | 227 | |
228 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
228 | + do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email); |
|
229 | 229 | |
230 | 230 | return $result; |
231 | 231 | } |
@@ -236,20 +236,20 @@ discard block |
||
236 | 236 | * @param array $recipients |
237 | 237 | * @param GetPaid_Notification_Email $email |
238 | 238 | */ |
239 | - public function filter_email_recipients( $recipients, $email ) { |
|
239 | + public function filter_email_recipients($recipients, $email) { |
|
240 | 240 | |
241 | - if ( ! $email->is_admin_email() ) { |
|
241 | + if (!$email->is_admin_email()) { |
|
242 | 242 | $cc = $email->object->get_email_cc(); |
243 | - $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
243 | + $cc_2 = get_user_meta($email->object->get_user_id(), '_wpinv_email_cc', true); |
|
244 | 244 | |
245 | - if ( ! empty( $cc ) ) { |
|
246 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
247 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
245 | + if (!empty($cc)) { |
|
246 | + $cc = array_map('sanitize_email', wpinv_parse_list($cc)); |
|
247 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc))); |
|
248 | 248 | } |
249 | 249 | |
250 | - if ( ! empty( $cc_2 ) ) { |
|
251 | - $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
252 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
250 | + if (!empty($cc_2)) { |
|
251 | + $cc_2 = array_map('sanitize_email', wpinv_parse_list($cc_2)); |
|
252 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc_2))); |
|
253 | 253 | } |
254 | 254 | } |
255 | 255 | |
@@ -262,17 +262,17 @@ discard block |
||
262 | 262 | * |
263 | 263 | * @param WPInv_Invoice $invoice |
264 | 264 | */ |
265 | - public function new_invoice( $invoice ) { |
|
265 | + public function new_invoice($invoice) { |
|
266 | 266 | |
267 | 267 | // Only send this email for invoices created via the admin page. |
268 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
268 | + if (!$invoice->is_type('invoice') || $invoice->is_paid() || $this->is_payment_form_invoice($invoice->get_id())) { |
|
269 | 269 | return; |
270 | 270 | } |
271 | 271 | |
272 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
272 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
273 | 273 | $recipient = wpinv_get_admin_email(); |
274 | 274 | |
275 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
275 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
276 | 276 | |
277 | 277 | } |
278 | 278 | |
@@ -281,12 +281,12 @@ discard block |
||
281 | 281 | * |
282 | 282 | * @param WPInv_Invoice $invoice |
283 | 283 | */ |
284 | - public function cancelled_invoice( $invoice ) { |
|
284 | + public function cancelled_invoice($invoice) { |
|
285 | 285 | |
286 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
286 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
287 | 287 | $recipient = $invoice->get_email(); |
288 | 288 | |
289 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
289 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
@@ -294,12 +294,12 @@ discard block |
||
294 | 294 | * |
295 | 295 | * @param WPInv_Invoice $invoice |
296 | 296 | */ |
297 | - public function failed_invoice( $invoice ) { |
|
297 | + public function failed_invoice($invoice) { |
|
298 | 298 | |
299 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
299 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
300 | 300 | $recipient = wpinv_get_admin_email(); |
301 | 301 | |
302 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
302 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
303 | 303 | |
304 | 304 | } |
305 | 305 | |
@@ -308,12 +308,12 @@ discard block |
||
308 | 308 | * |
309 | 309 | * @param WPInv_Invoice $invoice |
310 | 310 | */ |
311 | - public function onhold_invoice( $invoice ) { |
|
311 | + public function onhold_invoice($invoice) { |
|
312 | 312 | |
313 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
313 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
314 | 314 | $recipient = $invoice->get_email(); |
315 | 315 | |
316 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
316 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
317 | 317 | |
318 | 318 | } |
319 | 319 | |
@@ -322,12 +322,12 @@ discard block |
||
322 | 322 | * |
323 | 323 | * @param WPInv_Invoice $invoice |
324 | 324 | */ |
325 | - public function processing_invoice( $invoice ) { |
|
325 | + public function processing_invoice($invoice) { |
|
326 | 326 | |
327 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
327 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
328 | 328 | $recipient = $invoice->get_email(); |
329 | 329 | |
330 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
330 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
331 | 331 | |
332 | 332 | } |
333 | 333 | |
@@ -336,17 +336,17 @@ discard block |
||
336 | 336 | * |
337 | 337 | * @param WPInv_Invoice $invoice |
338 | 338 | */ |
339 | - public function completed_invoice( $invoice ) { |
|
339 | + public function completed_invoice($invoice) { |
|
340 | 340 | |
341 | 341 | // (Maybe) abort if it is a renewal invoice. |
342 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
342 | + if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) { |
|
343 | 343 | return; |
344 | 344 | } |
345 | 345 | |
346 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
346 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
347 | 347 | $recipient = $invoice->get_email(); |
348 | 348 | |
349 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
349 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
350 | 350 | |
351 | 351 | } |
352 | 352 | |
@@ -355,12 +355,12 @@ discard block |
||
355 | 355 | * |
356 | 356 | * @param WPInv_Invoice $invoice |
357 | 357 | */ |
358 | - public function refunded_invoice( $invoice ) { |
|
358 | + public function refunded_invoice($invoice) { |
|
359 | 359 | |
360 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
360 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
361 | 361 | $recipient = $invoice->get_email(); |
362 | 362 | |
363 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
363 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
364 | 364 | |
365 | 365 | } |
366 | 366 | |
@@ -370,21 +370,21 @@ discard block |
||
370 | 370 | * @param WPInv_Invoice $invoice |
371 | 371 | * @param bool $force |
372 | 372 | */ |
373 | - public function user_invoice( $invoice, $force = false ) { |
|
373 | + public function user_invoice($invoice, $force = false) { |
|
374 | 374 | |
375 | - if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
375 | + if (!$force && !empty($GLOBALS['wpinv_skip_invoice_notification'])) { |
|
376 | 376 | return; |
377 | 377 | } |
378 | 378 | |
379 | 379 | // Only send this email for invoices created via the admin page. |
380 | - if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
380 | + if (!$invoice->is_type('invoice') || (empty($force) && $invoice->is_paid()) || (empty($force) && $this->is_payment_form_invoice($invoice->get_id()))) { |
|
381 | 381 | return; |
382 | 382 | } |
383 | 383 | |
384 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
384 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
385 | 385 | $recipient = $invoice->get_email(); |
386 | 386 | |
387 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
387 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
388 | 388 | |
389 | 389 | } |
390 | 390 | |
@@ -394,11 +394,11 @@ discard block |
||
394 | 394 | * @param int $invoice |
395 | 395 | * @return bool |
396 | 396 | */ |
397 | - public function is_payment_form_invoice( $invoice ) { |
|
398 | - $created_via = get_post_meta( $invoice, 'wpinv_created_via', true ); |
|
397 | + public function is_payment_form_invoice($invoice) { |
|
398 | + $created_via = get_post_meta($invoice, 'wpinv_created_via', true); |
|
399 | 399 | $is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via; |
400 | - $is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
401 | - return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice; |
|
400 | + $is_payment_form_invoice = apply_filters('getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice); |
|
401 | + return empty($_GET['getpaid-admin-action']) && $is_payment_form_invoice; |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | /** |
@@ -407,12 +407,12 @@ discard block |
||
407 | 407 | * @param WPInv_Invoice $invoice |
408 | 408 | * @param string $note |
409 | 409 | */ |
410 | - public function user_note( $invoice, $note ) { |
|
410 | + public function user_note($invoice, $note) { |
|
411 | 411 | |
412 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
412 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
413 | 413 | $recipient = $invoice->get_email(); |
414 | 414 | |
415 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
415 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note)); |
|
416 | 416 | |
417 | 417 | } |
418 | 418 | |
@@ -421,9 +421,9 @@ discard block |
||
421 | 421 | * |
422 | 422 | * @param WPInv_Invoice $invoice |
423 | 423 | */ |
424 | - public function force_send_overdue_notice( $invoice ) { |
|
425 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
426 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
424 | + public function force_send_overdue_notice($invoice) { |
|
425 | + $email = new GetPaid_Notification_Email('overdue', $invoice); |
|
426 | + return $this->send_email($invoice, $email, 'overdue', $invoice->get_email()); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | /** |
@@ -434,38 +434,38 @@ discard block |
||
434 | 434 | public function overdue() { |
435 | 435 | global $wpdb; |
436 | 436 | |
437 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
437 | + $email = new GetPaid_Notification_Email(__FUNCTION__); |
|
438 | 438 | |
439 | 439 | // Fetch reminder days. |
440 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
440 | + $reminder_days = array_unique(wp_parse_id_list($email->get_option('days'))); |
|
441 | 441 | |
442 | 442 | // Abort if non is set. |
443 | - if ( empty( $reminder_days ) ) { |
|
443 | + if (empty($reminder_days)) { |
|
444 | 444 | return; |
445 | 445 | } |
446 | 446 | |
447 | 447 | // Retrieve date query. |
448 | - $date_query = $this->get_date_query( $reminder_days ); |
|
448 | + $date_query = $this->get_date_query($reminder_days); |
|
449 | 449 | |
450 | 450 | // Invoices table. |
451 | 451 | $table = $wpdb->prefix . 'getpaid_invoices'; |
452 | 452 | |
453 | 453 | // Fetch invoices. |
454 | - $invoices = $wpdb->get_col( |
|
454 | + $invoices = $wpdb->get_col( |
|
455 | 455 | "SELECT posts.ID FROM $wpdb->posts as posts |
456 | 456 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
457 | 457 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query" |
458 | 458 | ); |
459 | 459 | |
460 | - foreach ( $invoices as $invoice ) { |
|
460 | + foreach ($invoices as $invoice) { |
|
461 | 461 | |
462 | 462 | // Only send this email for invoices created via the admin page. |
463 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
464 | - $invoice = new WPInv_Invoice( $invoice ); |
|
463 | + if (!$this->is_payment_form_invoice($invoice)) { |
|
464 | + $invoice = new WPInv_Invoice($invoice); |
|
465 | 465 | $email->object = $invoice; |
466 | 466 | |
467 | - if ( $invoice->needs_payment() && ! $invoice->is_renewal() ) { |
|
468 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
467 | + if ($invoice->needs_payment() && !$invoice->is_renewal()) { |
|
468 | + $this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email()); |
|
469 | 469 | } |
470 | 470 | } |
471 | 471 | } |
@@ -478,14 +478,14 @@ discard block |
||
478 | 478 | * @param array $reminder_days |
479 | 479 | * @return string |
480 | 480 | */ |
481 | - public function get_date_query( $reminder_days ) { |
|
481 | + public function get_date_query($reminder_days) { |
|
482 | 482 | |
483 | 483 | $date_query = array( |
484 | 484 | 'relation' => 'OR', |
485 | 485 | ); |
486 | 486 | |
487 | - foreach ( $reminder_days as $days ) { |
|
488 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
487 | + foreach ($reminder_days as $days) { |
|
488 | + $date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp')))); |
|
489 | 489 | |
490 | 490 | $date_query[] = array( |
491 | 491 | 'year' => $date['year'], |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | |
496 | 496 | } |
497 | 497 | |
498 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
498 | + $date_query = new WP_Date_Query($date_query, 'invoices.due_date'); |
|
499 | 499 | |
500 | 500 | return $date_query->get_sql(); |
501 | 501 |
@@ -52,27 +52,27 @@ |
||
52 | 52 | |
53 | 53 | // Total Fee. |
54 | 54 | if ( 'fee' === $key ) { |
55 | - wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
55 | + wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | // Total discount. |
59 | 59 | if ( 'discount' === $key ) { |
60 | - wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
60 | + wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | // Shipping. |
64 | 64 | if ( 'shipping' === $key ) { |
65 | - wpinv_the_price( $invoice->get_shipping(), $invoice->get_currency() ); |
|
65 | + wpinv_the_price( $invoice->get_shipping(), $invoice->get_currency() ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | // Sub total. |
69 | 69 | if ( 'subtotal' === $key ) { |
70 | - wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
70 | + wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // Total. |
74 | 74 | if ( 'total' === $key ) { |
75 | - wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
75 | + wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Fires when printing a cart total. |
@@ -9,26 +9,26 @@ discard block |
||
9 | 9 | * @var WPInv_Invoice $invoice |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | // Totals rows. |
15 | -$totals = getpaid_invoice_totals_rows( $invoice ); |
|
15 | +$totals = getpaid_invoice_totals_rows($invoice); |
|
16 | 16 | |
17 | -do_action( 'getpaid_before_invoice_line_totals', $invoice, $totals ); |
|
17 | +do_action('getpaid_before_invoice_line_totals', $invoice, $totals); |
|
18 | 18 | |
19 | 19 | ?> |
20 | 20 | <div class='getpaid-invoice-line-totals'> |
21 | 21 | <div class="row"> |
22 | 22 | <div class="col-12 offset-sm-6 col-sm-6 border-sm-left pl-sm-0"> |
23 | 23 | |
24 | - <?php foreach ( $totals as $key => $label ) : ?> |
|
24 | + <?php foreach ($totals as $key => $label) : ?> |
|
25 | 25 | |
26 | - <div class="getpaid-invoice-line-totals-col <?php echo esc_attr( $key ); ?>"> |
|
26 | + <div class="getpaid-invoice-line-totals-col <?php echo esc_attr($key); ?>"> |
|
27 | 27 | |
28 | 28 | <div class="form-row row"> |
29 | 29 | |
30 | 30 | <div class="col-8 getpaid-invoice-line-totals-label"> |
31 | - <?php echo esc_html( $label ); ?> |
|
31 | + <?php echo esc_html($label); ?> |
|
32 | 32 | </div> |
33 | 33 | |
34 | 34 | <div class="col-4 getpaid-invoice-line-totals-value pl-0"> |
@@ -36,62 +36,62 @@ discard block |
||
36 | 36 | <?php |
37 | 37 | |
38 | 38 | // Total tax. |
39 | - if ( 'tax' === $key ) { |
|
40 | - wpinv_the_price( $invoice->get_total_tax(), $invoice->get_currency() ); |
|
39 | + if ('tax' === $key) { |
|
40 | + wpinv_the_price($invoice->get_total_tax(), $invoice->get_currency()); |
|
41 | 41 | |
42 | - if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
42 | + if (wpinv_use_taxes() && !$invoice->get_disable_taxes()) { |
|
43 | 43 | |
44 | 44 | $taxes = $invoice->get_total_tax(); |
45 | - if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
45 | + if (empty($taxes) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction($invoice->get_country())) { |
|
46 | 46 | echo ' <em class="text-muted small">'; |
47 | - _x( '(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing' ); |
|
47 | + _x('(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing'); |
|
48 | 48 | echo '</em>'; |
49 | 49 | } |
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
53 | 53 | // Check if field starts with tax__. |
54 | - if ( 0 === strpos( $key, 'tax__' ) ) { |
|
55 | - $tax_amount = $invoice->get_tax_total_by_name( str_replace( 'tax__', '', $key ) ); |
|
56 | - wpinv_the_price( $tax_amount, $invoice->get_currency() ); |
|
54 | + if (0 === strpos($key, 'tax__')) { |
|
55 | + $tax_amount = $invoice->get_tax_total_by_name(str_replace('tax__', '', $key)); |
|
56 | + wpinv_the_price($tax_amount, $invoice->get_currency()); |
|
57 | 57 | |
58 | - if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
58 | + if (wpinv_use_taxes() && !$invoice->get_disable_taxes()) { |
|
59 | 59 | |
60 | - if ( empty( $tax_amount ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
60 | + if (empty($tax_amount) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction($invoice->get_country())) { |
|
61 | 61 | echo ' <em class="text-muted small">'; |
62 | - _x( '(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing' ); |
|
62 | + _x('(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing'); |
|
63 | 63 | echo '</em>'; |
64 | 64 | } |
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
68 | 68 | // Total Fee. |
69 | - if ( 'fee' === $key ) { |
|
70 | - wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
69 | + if ('fee' === $key) { |
|
70 | + wpinv_the_price($invoice->get_total_fees(), $invoice->get_currency()); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // Total discount. |
74 | - if ( 'discount' === $key ) { |
|
75 | - wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
74 | + if ('discount' === $key) { |
|
75 | + wpinv_the_price($invoice->get_total_discount(), $invoice->get_currency()); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Shipping. |
79 | - if ( 'shipping' === $key ) { |
|
80 | - wpinv_the_price( $invoice->get_shipping(), $invoice->get_currency() ); |
|
79 | + if ('shipping' === $key) { |
|
80 | + wpinv_the_price($invoice->get_shipping(), $invoice->get_currency()); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | // Sub total. |
84 | - if ( 'subtotal' === $key ) { |
|
85 | - wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
84 | + if ('subtotal' === $key) { |
|
85 | + wpinv_the_price($invoice->get_subtotal(), $invoice->get_currency()); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | // Total. |
89 | - if ( 'total' === $key ) { |
|
90 | - wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
89 | + if ('total' === $key) { |
|
90 | + wpinv_the_price($invoice->get_total(), $invoice->get_currency()); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | // Fires when printing a cart total. |
94 | - do_action( "getpaid_invoice_cart_totals_$key", $invoice ); |
|
94 | + do_action("getpaid_invoice_cart_totals_$key", $invoice); |
|
95 | 95 | |
96 | 96 | ?> |
97 | 97 | |
@@ -105,4 +105,4 @@ discard block |
||
105 | 105 | </div> |
106 | 106 | </div> <!-- end .getpaid-invoice-line-totals --> |
107 | 107 | |
108 | -<?php do_action( 'getpaid_after_invoice_line_totals', $invoice, $totals ); ?> |
|
108 | +<?php do_action('getpaid_after_invoice_line_totals', $invoice, $totals); ?> |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php |
|
1 | + <?php |
|
2 | 2 | |
3 | 3 | /** |
4 | 4 | * Displays invoice cart totals |
@@ -9,14 +9,14 @@ discard block |
||
9 | 9 | * @var WPInv_Invoice $invoice |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | + defined( 'ABSPATH' ) || exit; |
|
13 | 13 | |
14 | -// Totals rows. |
|
15 | -$totals = getpaid_invoice_totals_rows( $invoice ); |
|
14 | + // Totals rows. |
|
15 | + $totals = getpaid_invoice_totals_rows( $invoice ); |
|
16 | 16 | |
17 | -do_action( 'getpaid_before_invoice_line_totals', $invoice, $totals ); |
|
17 | + do_action( 'getpaid_before_invoice_line_totals', $invoice, $totals ); |
|
18 | 18 | |
19 | -?> |
|
19 | + ?> |
|
20 | 20 | <div class='getpaid-invoice-line-totals'> |
21 | 21 | <div class="row"> |
22 | 22 | <div class="col-12 offset-sm-6 col-sm-6 border-sm-left pl-sm-0"> |
@@ -35,65 +35,65 @@ discard block |
||
35 | 35 | |
36 | 36 | <?php |
37 | 37 | |
38 | - // Total tax. |
|
39 | - if ( 'tax' === $key ) { |
|
40 | - wpinv_the_price( $invoice->get_total_tax(), $invoice->get_currency() ); |
|
38 | + // Total tax. |
|
39 | + if ( 'tax' === $key ) { |
|
40 | + wpinv_the_price( $invoice->get_total_tax(), $invoice->get_currency() ); |
|
41 | 41 | |
42 | - if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
42 | + if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
43 | 43 | |
44 | - $taxes = $invoice->get_total_tax(); |
|
45 | - if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
46 | - echo ' <em class="text-muted small">'; |
|
47 | - _x( '(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing' ); |
|
48 | - echo '</em>'; |
|
44 | + $taxes = $invoice->get_total_tax(); |
|
45 | + if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
46 | + echo ' <em class="text-muted small">'; |
|
47 | + _x( '(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing' ); |
|
48 | + echo '</em>'; |
|
49 | + } |
|
49 | 50 | } |
50 | 51 | } |
51 | - } |
|
52 | 52 | |
53 | - // Check if field starts with tax__. |
|
54 | - if ( 0 === strpos( $key, 'tax__' ) ) { |
|
55 | - $tax_amount = $invoice->get_tax_total_by_name( str_replace( 'tax__', '', $key ) ); |
|
56 | - wpinv_the_price( $tax_amount, $invoice->get_currency() ); |
|
53 | + // Check if field starts with tax__. |
|
54 | + if ( 0 === strpos( $key, 'tax__' ) ) { |
|
55 | + $tax_amount = $invoice->get_tax_total_by_name( str_replace( 'tax__', '', $key ) ); |
|
56 | + wpinv_the_price( $tax_amount, $invoice->get_currency() ); |
|
57 | 57 | |
58 | - if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
58 | + if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
59 | 59 | |
60 | - if ( empty( $tax_amount ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
61 | - echo ' <em class="text-muted small">'; |
|
62 | - _x( '(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing' ); |
|
63 | - echo '</em>'; |
|
60 | + if ( empty( $tax_amount ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
61 | + echo ' <em class="text-muted small">'; |
|
62 | + _x( '(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing' ); |
|
63 | + echo '</em>'; |
|
64 | + } |
|
64 | 65 | } |
65 | 66 | } |
66 | - } |
|
67 | 67 | |
68 | - // Total Fee. |
|
69 | - if ( 'fee' === $key ) { |
|
70 | - wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
71 | - } |
|
68 | + // Total Fee. |
|
69 | + if ( 'fee' === $key ) { |
|
70 | + wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
71 | + } |
|
72 | 72 | |
73 | - // Total discount. |
|
74 | - if ( 'discount' === $key ) { |
|
75 | - wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
76 | - } |
|
73 | + // Total discount. |
|
74 | + if ( 'discount' === $key ) { |
|
75 | + wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
76 | + } |
|
77 | 77 | |
78 | - // Shipping. |
|
79 | - if ( 'shipping' === $key ) { |
|
80 | - wpinv_the_price( $invoice->get_shipping(), $invoice->get_currency() ); |
|
81 | - } |
|
78 | + // Shipping. |
|
79 | + if ( 'shipping' === $key ) { |
|
80 | + wpinv_the_price( $invoice->get_shipping(), $invoice->get_currency() ); |
|
81 | + } |
|
82 | 82 | |
83 | - // Sub total. |
|
84 | - if ( 'subtotal' === $key ) { |
|
85 | - wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
86 | - } |
|
83 | + // Sub total. |
|
84 | + if ( 'subtotal' === $key ) { |
|
85 | + wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
86 | + } |
|
87 | 87 | |
88 | - // Total. |
|
89 | - if ( 'total' === $key ) { |
|
90 | - wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
91 | - } |
|
88 | + // Total. |
|
89 | + if ( 'total' === $key ) { |
|
90 | + wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
91 | + } |
|
92 | 92 | |
93 | - // Fires when printing a cart total. |
|
94 | - do_action( "getpaid_invoice_cart_totals_$key", $invoice ); |
|
93 | + // Fires when printing a cart total. |
|
94 | + do_action( "getpaid_invoice_cart_totals_$key", $invoice ); |
|
95 | 95 | |
96 | - ?> |
|
96 | + ?> |
|
97 | 97 | |
98 | 98 | </div> |
99 | 99 | </div> |
@@ -12,294 +12,294 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Helper { |
14 | 14 | |
15 | - /** |
|
16 | - * Get report totals such as invoice totals and discount amounts. |
|
17 | - * |
|
18 | - * Data example: |
|
19 | - * |
|
20 | - * 'subtotal' => array( |
|
21 | - * 'type' => 'invoice_data', |
|
22 | - * 'function' => 'SUM', |
|
23 | - * 'name' => 'subtotal' |
|
24 | - * ) |
|
25 | - * |
|
26 | - * @param array $args |
|
27 | - * @return mixed depending on query_type |
|
28 | - */ |
|
29 | - public static function get_invoice_report_data( $args = array() ) { |
|
30 | - global $wpdb; |
|
31 | - |
|
32 | - $default_args = array( |
|
33 | - 'data' => array(), // The data to retrieve. |
|
34 | - 'where' => array(), // An array of where queries. |
|
35 | - 'query_type' => 'get_row', // wpdb query to run. |
|
36 | - 'group_by' => '', // What to group results by. |
|
37 | - 'order_by' => '', // What to order by. |
|
38 | - 'limit' => '', // Results limit. |
|
39 | - 'filter_range' => array(), // An array of before and after dates to limit results by. |
|
40 | - 'invoice_types' => array( 'wpi_invoice' ), // An array of post types to retrieve. |
|
41 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold' ), |
|
42 | - 'parent_invoice_status' => false, // Optionally filter by parent invoice status. |
|
43 | - ); |
|
44 | - |
|
45 | - $args = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args ); |
|
46 | - $args = wp_parse_args( $args, $default_args ); |
|
47 | - |
|
48 | - extract( $args ); |
|
49 | - |
|
50 | - if ( empty( $data ) ) { |
|
51 | - return ''; |
|
52 | - } |
|
53 | - |
|
54 | - $query = array(); |
|
55 | - $query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) ); |
|
56 | - $query['from'] = "FROM {$wpdb->posts} AS posts"; |
|
57 | - $query['join'] = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) ); |
|
58 | - |
|
59 | - $query['where'] = " |
|
15 | + /** |
|
16 | + * Get report totals such as invoice totals and discount amounts. |
|
17 | + * |
|
18 | + * Data example: |
|
19 | + * |
|
20 | + * 'subtotal' => array( |
|
21 | + * 'type' => 'invoice_data', |
|
22 | + * 'function' => 'SUM', |
|
23 | + * 'name' => 'subtotal' |
|
24 | + * ) |
|
25 | + * |
|
26 | + * @param array $args |
|
27 | + * @return mixed depending on query_type |
|
28 | + */ |
|
29 | + public static function get_invoice_report_data( $args = array() ) { |
|
30 | + global $wpdb; |
|
31 | + |
|
32 | + $default_args = array( |
|
33 | + 'data' => array(), // The data to retrieve. |
|
34 | + 'where' => array(), // An array of where queries. |
|
35 | + 'query_type' => 'get_row', // wpdb query to run. |
|
36 | + 'group_by' => '', // What to group results by. |
|
37 | + 'order_by' => '', // What to order by. |
|
38 | + 'limit' => '', // Results limit. |
|
39 | + 'filter_range' => array(), // An array of before and after dates to limit results by. |
|
40 | + 'invoice_types' => array( 'wpi_invoice' ), // An array of post types to retrieve. |
|
41 | + 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold' ), |
|
42 | + 'parent_invoice_status' => false, // Optionally filter by parent invoice status. |
|
43 | + ); |
|
44 | + |
|
45 | + $args = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args ); |
|
46 | + $args = wp_parse_args( $args, $default_args ); |
|
47 | + |
|
48 | + extract( $args ); |
|
49 | + |
|
50 | + if ( empty( $data ) ) { |
|
51 | + return ''; |
|
52 | + } |
|
53 | + |
|
54 | + $query = array(); |
|
55 | + $query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) ); |
|
56 | + $query['from'] = "FROM {$wpdb->posts} AS posts"; |
|
57 | + $query['join'] = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) ); |
|
58 | + |
|
59 | + $query['where'] = " |
|
60 | 60 | WHERE posts.post_type IN ( '" . implode( "','", $invoice_types ) . "' ) |
61 | 61 | "; |
62 | 62 | |
63 | - if ( ! empty( $invoice_status ) ) { |
|
64 | - $query['where'] .= " |
|
63 | + if ( ! empty( $invoice_status ) ) { |
|
64 | + $query['where'] .= " |
|
65 | 65 | AND posts.post_status IN ( '" . implode( "','", $invoice_status ) . "' ) |
66 | 66 | "; |
67 | - } |
|
68 | - |
|
69 | - if ( ! empty( $parent_invoice_status ) ) { |
|
70 | - if ( ! empty( $invoice_status ) ) { |
|
71 | - $query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) "; |
|
72 | - } else { |
|
73 | - $query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) "; |
|
74 | - } |
|
75 | - } |
|
76 | - |
|
77 | - if ( ! empty( $filter_range['before'] ) ) { |
|
78 | - $query['where'] .= " |
|
67 | + } |
|
68 | + |
|
69 | + if ( ! empty( $parent_invoice_status ) ) { |
|
70 | + if ( ! empty( $invoice_status ) ) { |
|
71 | + $query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) "; |
|
72 | + } else { |
|
73 | + $query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) "; |
|
74 | + } |
|
75 | + } |
|
76 | + |
|
77 | + if ( ! empty( $filter_range['before'] ) ) { |
|
78 | + $query['where'] .= " |
|
79 | 79 | AND posts.post_date <= '" . gmdate( 'Y-m-d 23:59:59', strtotime( $filter_range['before'] ) ) . "' |
80 | 80 | "; |
81 | - } |
|
81 | + } |
|
82 | 82 | |
83 | - if ( ! empty( $filter_range['after'] ) ) { |
|
84 | - $query['where'] .= " |
|
83 | + if ( ! empty( $filter_range['after'] ) ) { |
|
84 | + $query['where'] .= " |
|
85 | 85 | AND posts.post_date >= '" . gmdate( 'Y-m-d 00:00:00', strtotime( $filter_range['after'] ) ) . "' |
86 | 86 | "; |
87 | - } |
|
87 | + } |
|
88 | 88 | |
89 | - if ( ! empty( $where ) ) { |
|
89 | + if ( ! empty( $where ) ) { |
|
90 | 90 | |
91 | - foreach ( $where as $value ) { |
|
91 | + foreach ( $where as $value ) { |
|
92 | 92 | |
93 | - if ( strtolower( $value['operator'] ) === 'in' || strtolower( $value['operator'] ) === 'not in' ) { |
|
94 | - |
|
95 | - if ( is_array( $value['value'] ) ) { |
|
96 | - $value['value'] = implode( "','", $value['value'] ); |
|
97 | - } |
|
98 | - |
|
99 | - if ( ! empty( $value['value'] ) ) { |
|
100 | - $where_value = "{$value['operator']} ('{$value['value']}')"; |
|
101 | - } |
|
102 | - } else { |
|
103 | - $where_value = "{$value['operator']} '{$value['value']}'"; |
|
104 | - } |
|
105 | - |
|
106 | - if ( ! empty( $where_value ) ) { |
|
107 | - $query['where'] .= " AND {$value['key']} {$where_value}"; |
|
108 | - } |
|
109 | - } |
|
110 | - } |
|
111 | - |
|
112 | - if ( $group_by ) { |
|
113 | - $query['group_by'] = "GROUP BY {$group_by}"; |
|
114 | - } |
|
115 | - |
|
116 | - if ( $order_by ) { |
|
117 | - $query['order_by'] = "ORDER BY {$order_by}"; |
|
118 | - } |
|
119 | - |
|
120 | - if ( $limit ) { |
|
121 | - $query['limit'] = "LIMIT {$limit}"; |
|
122 | - } |
|
123 | - |
|
124 | - $query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data ); |
|
125 | - $query = implode( ' ', $query ); |
|
126 | - |
|
127 | - return self::execute( $query_type, $query ); |
|
128 | - |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Prepares the data to select. |
|
133 | - * |
|
134 | - * |
|
135 | - * @param array $data |
|
136 | - * @return array |
|
137 | - */ |
|
138 | - public static function prepare_invoice_data( $data ) { |
|
139 | - |
|
140 | - $prepared = array(); |
|
141 | - |
|
142 | - foreach ( $data as $raw_key => $value ) { |
|
143 | - $key = sanitize_key( $raw_key ); |
|
144 | - $distinct = ''; |
|
145 | - |
|
146 | - if ( isset( $value['distinct'] ) ) { |
|
147 | - $distinct = 'DISTINCT'; |
|
148 | - } |
|
149 | - |
|
150 | - $get_key = self::get_invoice_table_key( $key, $value['type'] ); |
|
151 | - |
|
152 | - if ( false === $get_key ) { |
|
153 | - // Skip to the next foreach iteration else the query will be invalid. |
|
154 | - continue; |
|
155 | - } |
|
156 | - |
|
157 | - if ( ! empty( $value['function'] ) ) { |
|
158 | - $get = "{$value['function']}({$distinct} {$get_key})"; |
|
159 | - } else { |
|
160 | - $get = "{$distinct} {$get_key}"; |
|
161 | - } |
|
162 | - |
|
163 | - $prepared[] = "{$get} as {$value['name']}"; |
|
164 | - } |
|
165 | - |
|
166 | - return $prepared; |
|
167 | - |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Prepares the joins to use. |
|
172 | - * |
|
173 | - * |
|
174 | - * @param array $data |
|
175 | - * @param bool $with_parent |
|
176 | - * @return array |
|
177 | - */ |
|
178 | - public static function prepare_invoice_joins( $data, $with_parent ) { |
|
179 | - global $wpdb; |
|
180 | - |
|
181 | - $prepared = array(); |
|
182 | - |
|
183 | - foreach ( $data as $raw_key => $value ) { |
|
184 | - $join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER'; |
|
185 | - $type = isset( $value['type'] ) ? $value['type'] : false; |
|
186 | - $key = sanitize_key( $raw_key ); |
|
187 | - |
|
188 | - switch ( $type ) { |
|
189 | - case 'meta': |
|
190 | - $prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )"; |
|
191 | - break; |
|
192 | - case 'parent_meta': |
|
193 | - $prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')"; |
|
194 | - break; |
|
195 | - case 'invoice_data': |
|
196 | - $prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id"; |
|
197 | - break; |
|
198 | - case 'invoice_item': |
|
199 | - $prepared['invoice_items'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoice_items AS invoice_items ON posts.ID = invoice_items.post_id"; |
|
200 | - break; |
|
201 | - } |
|
202 | - } |
|
203 | - |
|
204 | - if ( $with_parent ) { |
|
205 | - $prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID"; |
|
206 | - } |
|
207 | - |
|
208 | - return $prepared; |
|
209 | - |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Retrieves the appropriate table key to use. |
|
214 | - * |
|
215 | - * |
|
216 | - * @param string $key |
|
217 | - * @param string $table |
|
218 | - * @return string|false |
|
219 | - */ |
|
220 | - public static function get_invoice_table_key( $key, $table ) { |
|
221 | - |
|
222 | - $keys = array( |
|
223 | - 'meta' => "meta_{$key}.meta_value", |
|
224 | - 'parent_meta' => "parent_meta_{$key}.meta_value", |
|
225 | - 'post_data' => "posts.{$key}", |
|
226 | - 'invoice_data' => "invoices.{$key}", |
|
227 | - 'invoice_item' => "invoice_items.{$key}", |
|
228 | - ); |
|
229 | - |
|
230 | - return isset( $keys[ $table ] ) ? $keys[ $table ] : false; |
|
231 | - |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Executes a query and caches the result for a minute. |
|
236 | - * |
|
237 | - * |
|
238 | - * @param string $query_type |
|
239 | - * @param string $query |
|
240 | - * @return mixed depending on query_type |
|
241 | - */ |
|
242 | - public static function execute( $query_type, $query ) { |
|
243 | - global $wpdb; |
|
244 | - |
|
245 | - $query_hash = md5( $query_type . $query ); |
|
246 | - $result = self::get_cached_query( $query_hash ); |
|
247 | - if ( $result === false ) { |
|
248 | - self::enable_big_selects(); |
|
249 | - |
|
250 | - $result = $wpdb->$query_type( $query ); |
|
251 | - self::set_cached_query( $query_hash, $result ); |
|
252 | - } |
|
253 | - |
|
254 | - return $result; |
|
255 | - |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Enables big mysql selects for reports, just once for this session. |
|
260 | - */ |
|
261 | - protected static function enable_big_selects() { |
|
262 | - static $big_selects = false; |
|
263 | - |
|
264 | - global $wpdb; |
|
265 | - |
|
266 | - if ( ! $big_selects ) { |
|
267 | - $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' ); |
|
268 | - $big_selects = true; |
|
269 | - } |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Get the cached query result or null if it's not in the cache. |
|
274 | - * |
|
275 | - * @param string $query_hash The query hash. |
|
276 | - * |
|
277 | - * @return mixed|false The cache contents on success, false on failure to retrieve contents. |
|
278 | - */ |
|
279 | - protected static function get_cached_query( $query_hash ) { |
|
280 | - |
|
281 | - return wp_cache_get( |
|
282 | - $query_hash, |
|
283 | - strtolower( __CLASS__ ) |
|
284 | - ); |
|
285 | - |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Set the cached query result. |
|
290 | - * |
|
291 | - * @param string $query_hash The query hash. |
|
292 | - * @param mixed $data The data to cache. |
|
293 | - */ |
|
294 | - protected static function set_cached_query( $query_hash, $data ) { |
|
295 | - |
|
296 | - wp_cache_set( |
|
297 | - $query_hash, |
|
298 | - $data, |
|
299 | - strtolower( __CLASS__ ), |
|
300 | - MINUTE_IN_SECONDS |
|
301 | - ); |
|
302 | - |
|
303 | - } |
|
93 | + if ( strtolower( $value['operator'] ) === 'in' || strtolower( $value['operator'] ) === 'not in' ) { |
|
94 | + |
|
95 | + if ( is_array( $value['value'] ) ) { |
|
96 | + $value['value'] = implode( "','", $value['value'] ); |
|
97 | + } |
|
98 | + |
|
99 | + if ( ! empty( $value['value'] ) ) { |
|
100 | + $where_value = "{$value['operator']} ('{$value['value']}')"; |
|
101 | + } |
|
102 | + } else { |
|
103 | + $where_value = "{$value['operator']} '{$value['value']}'"; |
|
104 | + } |
|
105 | + |
|
106 | + if ( ! empty( $where_value ) ) { |
|
107 | + $query['where'] .= " AND {$value['key']} {$where_value}"; |
|
108 | + } |
|
109 | + } |
|
110 | + } |
|
111 | + |
|
112 | + if ( $group_by ) { |
|
113 | + $query['group_by'] = "GROUP BY {$group_by}"; |
|
114 | + } |
|
115 | + |
|
116 | + if ( $order_by ) { |
|
117 | + $query['order_by'] = "ORDER BY {$order_by}"; |
|
118 | + } |
|
119 | + |
|
120 | + if ( $limit ) { |
|
121 | + $query['limit'] = "LIMIT {$limit}"; |
|
122 | + } |
|
123 | + |
|
124 | + $query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data ); |
|
125 | + $query = implode( ' ', $query ); |
|
126 | + |
|
127 | + return self::execute( $query_type, $query ); |
|
128 | + |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Prepares the data to select. |
|
133 | + * |
|
134 | + * |
|
135 | + * @param array $data |
|
136 | + * @return array |
|
137 | + */ |
|
138 | + public static function prepare_invoice_data( $data ) { |
|
139 | + |
|
140 | + $prepared = array(); |
|
141 | + |
|
142 | + foreach ( $data as $raw_key => $value ) { |
|
143 | + $key = sanitize_key( $raw_key ); |
|
144 | + $distinct = ''; |
|
145 | + |
|
146 | + if ( isset( $value['distinct'] ) ) { |
|
147 | + $distinct = 'DISTINCT'; |
|
148 | + } |
|
149 | + |
|
150 | + $get_key = self::get_invoice_table_key( $key, $value['type'] ); |
|
151 | + |
|
152 | + if ( false === $get_key ) { |
|
153 | + // Skip to the next foreach iteration else the query will be invalid. |
|
154 | + continue; |
|
155 | + } |
|
156 | + |
|
157 | + if ( ! empty( $value['function'] ) ) { |
|
158 | + $get = "{$value['function']}({$distinct} {$get_key})"; |
|
159 | + } else { |
|
160 | + $get = "{$distinct} {$get_key}"; |
|
161 | + } |
|
162 | + |
|
163 | + $prepared[] = "{$get} as {$value['name']}"; |
|
164 | + } |
|
165 | + |
|
166 | + return $prepared; |
|
167 | + |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Prepares the joins to use. |
|
172 | + * |
|
173 | + * |
|
174 | + * @param array $data |
|
175 | + * @param bool $with_parent |
|
176 | + * @return array |
|
177 | + */ |
|
178 | + public static function prepare_invoice_joins( $data, $with_parent ) { |
|
179 | + global $wpdb; |
|
180 | + |
|
181 | + $prepared = array(); |
|
182 | + |
|
183 | + foreach ( $data as $raw_key => $value ) { |
|
184 | + $join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER'; |
|
185 | + $type = isset( $value['type'] ) ? $value['type'] : false; |
|
186 | + $key = sanitize_key( $raw_key ); |
|
187 | + |
|
188 | + switch ( $type ) { |
|
189 | + case 'meta': |
|
190 | + $prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )"; |
|
191 | + break; |
|
192 | + case 'parent_meta': |
|
193 | + $prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')"; |
|
194 | + break; |
|
195 | + case 'invoice_data': |
|
196 | + $prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id"; |
|
197 | + break; |
|
198 | + case 'invoice_item': |
|
199 | + $prepared['invoice_items'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoice_items AS invoice_items ON posts.ID = invoice_items.post_id"; |
|
200 | + break; |
|
201 | + } |
|
202 | + } |
|
203 | + |
|
204 | + if ( $with_parent ) { |
|
205 | + $prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID"; |
|
206 | + } |
|
207 | + |
|
208 | + return $prepared; |
|
209 | + |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Retrieves the appropriate table key to use. |
|
214 | + * |
|
215 | + * |
|
216 | + * @param string $key |
|
217 | + * @param string $table |
|
218 | + * @return string|false |
|
219 | + */ |
|
220 | + public static function get_invoice_table_key( $key, $table ) { |
|
221 | + |
|
222 | + $keys = array( |
|
223 | + 'meta' => "meta_{$key}.meta_value", |
|
224 | + 'parent_meta' => "parent_meta_{$key}.meta_value", |
|
225 | + 'post_data' => "posts.{$key}", |
|
226 | + 'invoice_data' => "invoices.{$key}", |
|
227 | + 'invoice_item' => "invoice_items.{$key}", |
|
228 | + ); |
|
229 | + |
|
230 | + return isset( $keys[ $table ] ) ? $keys[ $table ] : false; |
|
231 | + |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Executes a query and caches the result for a minute. |
|
236 | + * |
|
237 | + * |
|
238 | + * @param string $query_type |
|
239 | + * @param string $query |
|
240 | + * @return mixed depending on query_type |
|
241 | + */ |
|
242 | + public static function execute( $query_type, $query ) { |
|
243 | + global $wpdb; |
|
244 | + |
|
245 | + $query_hash = md5( $query_type . $query ); |
|
246 | + $result = self::get_cached_query( $query_hash ); |
|
247 | + if ( $result === false ) { |
|
248 | + self::enable_big_selects(); |
|
249 | + |
|
250 | + $result = $wpdb->$query_type( $query ); |
|
251 | + self::set_cached_query( $query_hash, $result ); |
|
252 | + } |
|
253 | + |
|
254 | + return $result; |
|
255 | + |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Enables big mysql selects for reports, just once for this session. |
|
260 | + */ |
|
261 | + protected static function enable_big_selects() { |
|
262 | + static $big_selects = false; |
|
263 | + |
|
264 | + global $wpdb; |
|
265 | + |
|
266 | + if ( ! $big_selects ) { |
|
267 | + $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' ); |
|
268 | + $big_selects = true; |
|
269 | + } |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Get the cached query result or null if it's not in the cache. |
|
274 | + * |
|
275 | + * @param string $query_hash The query hash. |
|
276 | + * |
|
277 | + * @return mixed|false The cache contents on success, false on failure to retrieve contents. |
|
278 | + */ |
|
279 | + protected static function get_cached_query( $query_hash ) { |
|
280 | + |
|
281 | + return wp_cache_get( |
|
282 | + $query_hash, |
|
283 | + strtolower( __CLASS__ ) |
|
284 | + ); |
|
285 | + |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Set the cached query result. |
|
290 | + * |
|
291 | + * @param string $query_hash The query hash. |
|
292 | + * @param mixed $data The data to cache. |
|
293 | + */ |
|
294 | + protected static function set_cached_query( $query_hash, $data ) { |
|
295 | + |
|
296 | + wp_cache_set( |
|
297 | + $query_hash, |
|
298 | + $data, |
|
299 | + strtolower( __CLASS__ ), |
|
300 | + MINUTE_IN_SECONDS |
|
301 | + ); |
|
302 | + |
|
303 | + } |
|
304 | 304 | |
305 | 305 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Reports_Helper Class. |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * @param array $args |
27 | 27 | * @return mixed depending on query_type |
28 | 28 | */ |
29 | - public static function get_invoice_report_data( $args = array() ) { |
|
29 | + public static function get_invoice_report_data($args = array()) { |
|
30 | 30 | global $wpdb; |
31 | 31 | |
32 | 32 | $default_args = array( |
@@ -37,94 +37,94 @@ discard block |
||
37 | 37 | 'order_by' => '', // What to order by. |
38 | 38 | 'limit' => '', // Results limit. |
39 | 39 | 'filter_range' => array(), // An array of before and after dates to limit results by. |
40 | - 'invoice_types' => array( 'wpi_invoice' ), // An array of post types to retrieve. |
|
41 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold' ), |
|
40 | + 'invoice_types' => array('wpi_invoice'), // An array of post types to retrieve. |
|
41 | + 'invoice_status' => array('publish', 'wpi-processing', 'wpi-onhold'), |
|
42 | 42 | 'parent_invoice_status' => false, // Optionally filter by parent invoice status. |
43 | 43 | ); |
44 | 44 | |
45 | - $args = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args ); |
|
46 | - $args = wp_parse_args( $args, $default_args ); |
|
45 | + $args = apply_filters('getpaid_reports_get_invoice_report_data_args', $args); |
|
46 | + $args = wp_parse_args($args, $default_args); |
|
47 | 47 | |
48 | - extract( $args ); |
|
48 | + extract($args); |
|
49 | 49 | |
50 | - if ( empty( $data ) ) { |
|
50 | + if (empty($data)) { |
|
51 | 51 | return ''; |
52 | 52 | } |
53 | 53 | |
54 | 54 | $query = array(); |
55 | - $query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) ); |
|
55 | + $query['select'] = 'SELECT ' . implode(',', self::prepare_invoice_data($data)); |
|
56 | 56 | $query['from'] = "FROM {$wpdb->posts} AS posts"; |
57 | - $query['join'] = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) ); |
|
57 | + $query['join'] = implode(' ', self::prepare_invoice_joins($data + $where, !empty($parent_invoice_status))); |
|
58 | 58 | |
59 | 59 | $query['where'] = " |
60 | - WHERE posts.post_type IN ( '" . implode( "','", $invoice_types ) . "' ) |
|
60 | + WHERE posts.post_type IN ( '" . implode("','", $invoice_types) . "' ) |
|
61 | 61 | "; |
62 | 62 | |
63 | - if ( ! empty( $invoice_status ) ) { |
|
63 | + if (!empty($invoice_status)) { |
|
64 | 64 | $query['where'] .= " |
65 | - AND posts.post_status IN ( '" . implode( "','", $invoice_status ) . "' ) |
|
65 | + AND posts.post_status IN ( '" . implode("','", $invoice_status) . "' ) |
|
66 | 66 | "; |
67 | 67 | } |
68 | 68 | |
69 | - if ( ! empty( $parent_invoice_status ) ) { |
|
70 | - if ( ! empty( $invoice_status ) ) { |
|
71 | - $query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) "; |
|
69 | + if (!empty($parent_invoice_status)) { |
|
70 | + if (!empty($invoice_status)) { |
|
71 | + $query['where'] .= " AND ( parent.post_status IN ( '" . implode("','", $parent_invoice_status) . "' ) OR parent.ID IS NULL ) "; |
|
72 | 72 | } else { |
73 | - $query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) "; |
|
73 | + $query['where'] .= " AND parent.post_status IN ( '" . implode("','", $parent_invoice_status) . "' ) "; |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
77 | - if ( ! empty( $filter_range['before'] ) ) { |
|
77 | + if (!empty($filter_range['before'])) { |
|
78 | 78 | $query['where'] .= " |
79 | - AND posts.post_date <= '" . gmdate( 'Y-m-d 23:59:59', strtotime( $filter_range['before'] ) ) . "' |
|
79 | + AND posts.post_date <= '" . gmdate('Y-m-d 23:59:59', strtotime($filter_range['before'])) . "' |
|
80 | 80 | "; |
81 | 81 | } |
82 | 82 | |
83 | - if ( ! empty( $filter_range['after'] ) ) { |
|
83 | + if (!empty($filter_range['after'])) { |
|
84 | 84 | $query['where'] .= " |
85 | - AND posts.post_date >= '" . gmdate( 'Y-m-d 00:00:00', strtotime( $filter_range['after'] ) ) . "' |
|
85 | + AND posts.post_date >= '" . gmdate('Y-m-d 00:00:00', strtotime($filter_range['after'])) . "' |
|
86 | 86 | "; |
87 | 87 | } |
88 | 88 | |
89 | - if ( ! empty( $where ) ) { |
|
89 | + if (!empty($where)) { |
|
90 | 90 | |
91 | - foreach ( $where as $value ) { |
|
91 | + foreach ($where as $value) { |
|
92 | 92 | |
93 | - if ( strtolower( $value['operator'] ) === 'in' || strtolower( $value['operator'] ) === 'not in' ) { |
|
93 | + if (strtolower($value['operator']) === 'in' || strtolower($value['operator']) === 'not in') { |
|
94 | 94 | |
95 | - if ( is_array( $value['value'] ) ) { |
|
96 | - $value['value'] = implode( "','", $value['value'] ); |
|
95 | + if (is_array($value['value'])) { |
|
96 | + $value['value'] = implode("','", $value['value']); |
|
97 | 97 | } |
98 | 98 | |
99 | - if ( ! empty( $value['value'] ) ) { |
|
99 | + if (!empty($value['value'])) { |
|
100 | 100 | $where_value = "{$value['operator']} ('{$value['value']}')"; |
101 | 101 | } |
102 | 102 | } else { |
103 | 103 | $where_value = "{$value['operator']} '{$value['value']}'"; |
104 | 104 | } |
105 | 105 | |
106 | - if ( ! empty( $where_value ) ) { |
|
106 | + if (!empty($where_value)) { |
|
107 | 107 | $query['where'] .= " AND {$value['key']} {$where_value}"; |
108 | 108 | } |
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
112 | - if ( $group_by ) { |
|
112 | + if ($group_by) { |
|
113 | 113 | $query['group_by'] = "GROUP BY {$group_by}"; |
114 | 114 | } |
115 | 115 | |
116 | - if ( $order_by ) { |
|
116 | + if ($order_by) { |
|
117 | 117 | $query['order_by'] = "ORDER BY {$order_by}"; |
118 | 118 | } |
119 | 119 | |
120 | - if ( $limit ) { |
|
120 | + if ($limit) { |
|
121 | 121 | $query['limit'] = "LIMIT {$limit}"; |
122 | 122 | } |
123 | 123 | |
124 | - $query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data ); |
|
125 | - $query = implode( ' ', $query ); |
|
124 | + $query = apply_filters('getpaid_reports_get_invoice_report_query', $query, $data); |
|
125 | + $query = implode(' ', $query); |
|
126 | 126 | |
127 | - return self::execute( $query_type, $query ); |
|
127 | + return self::execute($query_type, $query); |
|
128 | 128 | |
129 | 129 | } |
130 | 130 | |
@@ -135,26 +135,26 @@ discard block |
||
135 | 135 | * @param array $data |
136 | 136 | * @return array |
137 | 137 | */ |
138 | - public static function prepare_invoice_data( $data ) { |
|
138 | + public static function prepare_invoice_data($data) { |
|
139 | 139 | |
140 | 140 | $prepared = array(); |
141 | 141 | |
142 | - foreach ( $data as $raw_key => $value ) { |
|
143 | - $key = sanitize_key( $raw_key ); |
|
142 | + foreach ($data as $raw_key => $value) { |
|
143 | + $key = sanitize_key($raw_key); |
|
144 | 144 | $distinct = ''; |
145 | 145 | |
146 | - if ( isset( $value['distinct'] ) ) { |
|
146 | + if (isset($value['distinct'])) { |
|
147 | 147 | $distinct = 'DISTINCT'; |
148 | 148 | } |
149 | 149 | |
150 | - $get_key = self::get_invoice_table_key( $key, $value['type'] ); |
|
150 | + $get_key = self::get_invoice_table_key($key, $value['type']); |
|
151 | 151 | |
152 | - if ( false === $get_key ) { |
|
152 | + if (false === $get_key) { |
|
153 | 153 | // Skip to the next foreach iteration else the query will be invalid. |
154 | 154 | continue; |
155 | 155 | } |
156 | 156 | |
157 | - if ( ! empty( $value['function'] ) ) { |
|
157 | + if (!empty($value['function'])) { |
|
158 | 158 | $get = "{$value['function']}({$distinct} {$get_key})"; |
159 | 159 | } else { |
160 | 160 | $get = "{$distinct} {$get_key}"; |
@@ -175,22 +175,22 @@ discard block |
||
175 | 175 | * @param bool $with_parent |
176 | 176 | * @return array |
177 | 177 | */ |
178 | - public static function prepare_invoice_joins( $data, $with_parent ) { |
|
178 | + public static function prepare_invoice_joins($data, $with_parent) { |
|
179 | 179 | global $wpdb; |
180 | 180 | |
181 | 181 | $prepared = array(); |
182 | 182 | |
183 | - foreach ( $data as $raw_key => $value ) { |
|
184 | - $join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER'; |
|
185 | - $type = isset( $value['type'] ) ? $value['type'] : false; |
|
186 | - $key = sanitize_key( $raw_key ); |
|
183 | + foreach ($data as $raw_key => $value) { |
|
184 | + $join_type = isset($value['join_type']) ? $value['join_type'] : 'INNER'; |
|
185 | + $type = isset($value['type']) ? $value['type'] : false; |
|
186 | + $key = sanitize_key($raw_key); |
|
187 | 187 | |
188 | - switch ( $type ) { |
|
188 | + switch ($type) { |
|
189 | 189 | case 'meta': |
190 | - $prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )"; |
|
190 | + $prepared["meta_{$key}"] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )"; |
|
191 | 191 | break; |
192 | 192 | case 'parent_meta': |
193 | - $prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')"; |
|
193 | + $prepared["parent_meta_{$key}"] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')"; |
|
194 | 194 | break; |
195 | 195 | case 'invoice_data': |
196 | 196 | $prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id"; |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
204 | - if ( $with_parent ) { |
|
204 | + if ($with_parent) { |
|
205 | 205 | $prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID"; |
206 | 206 | } |
207 | 207 | |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * @param string $table |
218 | 218 | * @return string|false |
219 | 219 | */ |
220 | - public static function get_invoice_table_key( $key, $table ) { |
|
220 | + public static function get_invoice_table_key($key, $table) { |
|
221 | 221 | |
222 | 222 | $keys = array( |
223 | 223 | 'meta' => "meta_{$key}.meta_value", |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | 'invoice_item' => "invoice_items.{$key}", |
228 | 228 | ); |
229 | 229 | |
230 | - return isset( $keys[ $table ] ) ? $keys[ $table ] : false; |
|
230 | + return isset($keys[$table]) ? $keys[$table] : false; |
|
231 | 231 | |
232 | 232 | } |
233 | 233 | |
@@ -239,16 +239,16 @@ discard block |
||
239 | 239 | * @param string $query |
240 | 240 | * @return mixed depending on query_type |
241 | 241 | */ |
242 | - public static function execute( $query_type, $query ) { |
|
242 | + public static function execute($query_type, $query) { |
|
243 | 243 | global $wpdb; |
244 | 244 | |
245 | - $query_hash = md5( $query_type . $query ); |
|
246 | - $result = self::get_cached_query( $query_hash ); |
|
247 | - if ( $result === false ) { |
|
245 | + $query_hash = md5($query_type . $query); |
|
246 | + $result = self::get_cached_query($query_hash); |
|
247 | + if ($result === false) { |
|
248 | 248 | self::enable_big_selects(); |
249 | 249 | |
250 | - $result = $wpdb->$query_type( $query ); |
|
251 | - self::set_cached_query( $query_hash, $result ); |
|
250 | + $result = $wpdb->$query_type($query); |
|
251 | + self::set_cached_query($query_hash, $result); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | return $result; |
@@ -263,8 +263,8 @@ discard block |
||
263 | 263 | |
264 | 264 | global $wpdb; |
265 | 265 | |
266 | - if ( ! $big_selects ) { |
|
267 | - $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' ); |
|
266 | + if (!$big_selects) { |
|
267 | + $wpdb->query('SET SESSION SQL_BIG_SELECTS=1'); |
|
268 | 268 | $big_selects = true; |
269 | 269 | } |
270 | 270 | } |
@@ -276,11 +276,11 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @return mixed|false The cache contents on success, false on failure to retrieve contents. |
278 | 278 | */ |
279 | - protected static function get_cached_query( $query_hash ) { |
|
279 | + protected static function get_cached_query($query_hash) { |
|
280 | 280 | |
281 | 281 | return wp_cache_get( |
282 | 282 | $query_hash, |
283 | - strtolower( __CLASS__ ) |
|
283 | + strtolower(__CLASS__) |
|
284 | 284 | ); |
285 | 285 | |
286 | 286 | } |
@@ -291,12 +291,12 @@ discard block |
||
291 | 291 | * @param string $query_hash The query hash. |
292 | 292 | * @param mixed $data The data to cache. |
293 | 293 | */ |
294 | - protected static function set_cached_query( $query_hash, $data ) { |
|
294 | + protected static function set_cached_query($query_hash, $data) { |
|
295 | 295 | |
296 | 296 | wp_cache_set( |
297 | 297 | $query_hash, |
298 | 298 | $data, |
299 | - strtolower( __CLASS__ ), |
|
299 | + strtolower(__CLASS__), |
|
300 | 300 | MINUTE_IN_SECONDS |
301 | 301 | ); |
302 | 302 |
@@ -12,144 +12,144 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Daily_Maintenance { |
14 | 14 | |
15 | - /** |
|
16 | - * Class constructor. |
|
17 | - */ |
|
18 | - public function __construct() { |
|
19 | - |
|
20 | - // Clear deprecated events. |
|
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | - |
|
23 | - // (Maybe) schedule a cron that runs daily. |
|
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | - |
|
26 | - // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | - add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
32 | - |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Schedules a cron to run every day at 7 a.m |
|
37 | - * |
|
38 | - */ |
|
39 | - public function maybe_create_scheduled_event() { |
|
40 | - |
|
41 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
42 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
43 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
44 | - } |
|
45 | - |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Clears deprecated events. |
|
50 | - * |
|
51 | - */ |
|
52 | - public function maybe_clear_deprecated_events() { |
|
53 | - |
|
54 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
55 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
56 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
57 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
58 | - } |
|
59 | - |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Fires the old hook for backwards compatibility. |
|
64 | - * |
|
65 | - */ |
|
66 | - public function backwards_compat() { |
|
67 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Checks for subscriptions that are scheduled to renew. |
|
72 | - * |
|
73 | - */ |
|
74 | - public function check_renewing_subscriptions() { |
|
75 | - |
|
76 | - // Fetch subscriptions that expire today. |
|
77 | - $args = array( |
|
78 | - 'number' => -1, |
|
79 | - 'count_total' => false, |
|
80 | - 'status' => 'trialling active', |
|
81 | - 'date_expires_query' => array( |
|
82 | - array( |
|
83 | - 'year' => gmdate( 'Y' ), |
|
84 | - 'month' => gmdate( 'n' ), |
|
85 | - 'day' => gmdate( 'j' ), |
|
86 | - 'compare' => '=', |
|
87 | - ), |
|
88 | - ), |
|
89 | - ); |
|
90 | - |
|
91 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
92 | - |
|
93 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
94 | - |
|
95 | - /** @var WPInv_Subscription $subscription */ |
|
96 | - if ( $subscription->is_last_renewal() ) { |
|
97 | - $subscription->complete(); |
|
98 | - } else { |
|
99 | - do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Expires expired subscriptions. |
|
107 | - * |
|
108 | - */ |
|
109 | - public function maybe_expire_subscriptions() { |
|
110 | - |
|
111 | - // Fetch expired subscriptions (skips those that expire today). |
|
112 | - $args = array( |
|
113 | - 'number' => -1, |
|
114 | - 'count_total' => false, |
|
115 | - 'status' => 'trialling active failing cancelled', |
|
116 | - 'date_expires_query' => array( |
|
117 | - 'before' => 'yesterday', |
|
118 | - 'inclusive' => false, |
|
119 | - ), |
|
120 | - ); |
|
121 | - |
|
122 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
123 | - |
|
124 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
125 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
126 | - $subscription->set_status( 'expired' ); |
|
127 | - $subscription->save(); |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Logs cron runs. |
|
135 | - * |
|
136 | - */ |
|
137 | - public function log_cron_run() { |
|
138 | - wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Updates GeoIP databases. |
|
143 | - * |
|
144 | - */ |
|
145 | - public function maybe_update_geoip_databases() { |
|
146 | - $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
147 | - |
|
148 | - if ( false === $updated ) { |
|
149 | - set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
150 | - do_action( 'getpaid_update_geoip_databases' ); |
|
151 | - } |
|
152 | - |
|
153 | - } |
|
15 | + /** |
|
16 | + * Class constructor. |
|
17 | + */ |
|
18 | + public function __construct() { |
|
19 | + |
|
20 | + // Clear deprecated events. |
|
21 | + add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | + |
|
23 | + // (Maybe) schedule a cron that runs daily. |
|
24 | + add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | + |
|
26 | + // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | + add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | + add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | + add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
32 | + |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Schedules a cron to run every day at 7 a.m |
|
37 | + * |
|
38 | + */ |
|
39 | + public function maybe_create_scheduled_event() { |
|
40 | + |
|
41 | + if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
42 | + $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
43 | + wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
44 | + } |
|
45 | + |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Clears deprecated events. |
|
50 | + * |
|
51 | + */ |
|
52 | + public function maybe_clear_deprecated_events() { |
|
53 | + |
|
54 | + if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
55 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
56 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
57 | + update_option( 'wpinv_cleared_old_events', 1 ); |
|
58 | + } |
|
59 | + |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Fires the old hook for backwards compatibility. |
|
64 | + * |
|
65 | + */ |
|
66 | + public function backwards_compat() { |
|
67 | + do_action( 'wpinv_register_schedule_event_daily' ); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Checks for subscriptions that are scheduled to renew. |
|
72 | + * |
|
73 | + */ |
|
74 | + public function check_renewing_subscriptions() { |
|
75 | + |
|
76 | + // Fetch subscriptions that expire today. |
|
77 | + $args = array( |
|
78 | + 'number' => -1, |
|
79 | + 'count_total' => false, |
|
80 | + 'status' => 'trialling active', |
|
81 | + 'date_expires_query' => array( |
|
82 | + array( |
|
83 | + 'year' => gmdate( 'Y' ), |
|
84 | + 'month' => gmdate( 'n' ), |
|
85 | + 'day' => gmdate( 'j' ), |
|
86 | + 'compare' => '=', |
|
87 | + ), |
|
88 | + ), |
|
89 | + ); |
|
90 | + |
|
91 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
92 | + |
|
93 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
94 | + |
|
95 | + /** @var WPInv_Subscription $subscription */ |
|
96 | + if ( $subscription->is_last_renewal() ) { |
|
97 | + $subscription->complete(); |
|
98 | + } else { |
|
99 | + do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Expires expired subscriptions. |
|
107 | + * |
|
108 | + */ |
|
109 | + public function maybe_expire_subscriptions() { |
|
110 | + |
|
111 | + // Fetch expired subscriptions (skips those that expire today). |
|
112 | + $args = array( |
|
113 | + 'number' => -1, |
|
114 | + 'count_total' => false, |
|
115 | + 'status' => 'trialling active failing cancelled', |
|
116 | + 'date_expires_query' => array( |
|
117 | + 'before' => 'yesterday', |
|
118 | + 'inclusive' => false, |
|
119 | + ), |
|
120 | + ); |
|
121 | + |
|
122 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
123 | + |
|
124 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
125 | + if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
126 | + $subscription->set_status( 'expired' ); |
|
127 | + $subscription->save(); |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Logs cron runs. |
|
135 | + * |
|
136 | + */ |
|
137 | + public function log_cron_run() { |
|
138 | + wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Updates GeoIP databases. |
|
143 | + * |
|
144 | + */ |
|
145 | + public function maybe_update_geoip_databases() { |
|
146 | + $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
147 | + |
|
148 | + if ( false === $updated ) { |
|
149 | + set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
150 | + do_action( 'getpaid_update_geoip_databases' ); |
|
151 | + } |
|
152 | + |
|
153 | + } |
|
154 | 154 | |
155 | 155 | } |
@@ -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 | * Daily maintenance class. |
@@ -18,17 +18,17 @@ discard block |
||
18 | 18 | public function __construct() { |
19 | 19 | |
20 | 20 | // Clear deprecated events. |
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
21 | + add_action('wp', array($this, 'maybe_clear_deprecated_events')); |
|
22 | 22 | |
23 | 23 | // (Maybe) schedule a cron that runs daily. |
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
24 | + add_action('wp', array($this, 'maybe_create_scheduled_event')); |
|
25 | 25 | |
26 | 26 | // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | - add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
27 | + add_action('getpaid_daily_maintenance', array($this, 'log_cron_run')); |
|
28 | + add_action('getpaid_daily_maintenance', array($this, 'backwards_compat')); |
|
29 | + add_action('getpaid_daily_maintenance', array($this, 'maybe_expire_subscriptions')); |
|
30 | + add_action('getpaid_daily_maintenance', array($this, 'check_renewing_subscriptions')); |
|
31 | + add_action('getpaid_daily_maintenance', array($this, 'maybe_update_geoip_databases')); |
|
32 | 32 | |
33 | 33 | } |
34 | 34 | |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function maybe_create_scheduled_event() { |
40 | 40 | |
41 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
42 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
43 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
41 | + if (!wp_next_scheduled('getpaid_daily_maintenance')) { |
|
42 | + $timestamp = strtotime('tomorrow 07:00:00', current_time('timestamp')); |
|
43 | + wp_schedule_event($timestamp, 'daily', 'getpaid_daily_maintenance'); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | } |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function maybe_clear_deprecated_events() { |
53 | 53 | |
54 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
55 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
56 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
57 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
54 | + if (!get_option('wpinv_cleared_old_events')) { |
|
55 | + wp_clear_scheduled_hook('wpinv_register_schedule_event_twicedaily'); |
|
56 | + wp_clear_scheduled_hook('wpinv_register_schedule_event_daily'); |
|
57 | + update_option('wpinv_cleared_old_events', 1); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * |
65 | 65 | */ |
66 | 66 | public function backwards_compat() { |
67 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
67 | + do_action('wpinv_register_schedule_event_daily'); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -74,29 +74,29 @@ discard block |
||
74 | 74 | public function check_renewing_subscriptions() { |
75 | 75 | |
76 | 76 | // Fetch subscriptions that expire today. |
77 | - $args = array( |
|
77 | + $args = array( |
|
78 | 78 | 'number' => -1, |
79 | 79 | 'count_total' => false, |
80 | 80 | 'status' => 'trialling active', |
81 | 81 | 'date_expires_query' => array( |
82 | 82 | array( |
83 | - 'year' => gmdate( 'Y' ), |
|
84 | - 'month' => gmdate( 'n' ), |
|
85 | - 'day' => gmdate( 'j' ), |
|
83 | + 'year' => gmdate('Y'), |
|
84 | + 'month' => gmdate('n'), |
|
85 | + 'day' => gmdate('j'), |
|
86 | 86 | 'compare' => '=', |
87 | 87 | ), |
88 | 88 | ), |
89 | 89 | ); |
90 | 90 | |
91 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
91 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
92 | 92 | |
93 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
93 | + foreach ($subscriptions->get_results() as $subscription) { |
|
94 | 94 | |
95 | 95 | /** @var WPInv_Subscription $subscription */ |
96 | - if ( $subscription->is_last_renewal() ) { |
|
96 | + if ($subscription->is_last_renewal()) { |
|
97 | 97 | $subscription->complete(); |
98 | 98 | } else { |
99 | - do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
99 | + do_action('getpaid_should_renew_subscription', $subscription); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | public function maybe_expire_subscriptions() { |
110 | 110 | |
111 | 111 | // Fetch expired subscriptions (skips those that expire today). |
112 | - $args = array( |
|
112 | + $args = array( |
|
113 | 113 | 'number' => -1, |
114 | 114 | 'count_total' => false, |
115 | 115 | 'status' => 'trialling active failing cancelled', |
@@ -119,11 +119,11 @@ discard block |
||
119 | 119 | ), |
120 | 120 | ); |
121 | 121 | |
122 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
122 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
123 | 123 | |
124 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
125 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
126 | - $subscription->set_status( 'expired' ); |
|
124 | + foreach ($subscriptions->get_results() as $subscription) { |
|
125 | + if (apply_filters('getpaid_daily_maintenance_should_expire_subscription', false, $subscription)) { |
|
126 | + $subscription->set_status('expired'); |
|
127 | 127 | $subscription->save(); |
128 | 128 | } |
129 | 129 | } |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * |
136 | 136 | */ |
137 | 137 | public function log_cron_run() { |
138 | - wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
138 | + wpinv_error_log('GetPaid Daily Cron', false); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -143,11 +143,11 @@ discard block |
||
143 | 143 | * |
144 | 144 | */ |
145 | 145 | public function maybe_update_geoip_databases() { |
146 | - $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
146 | + $updated = get_transient('getpaid_updated_geoip_databases'); |
|
147 | 147 | |
148 | - if ( false === $updated ) { |
|
149 | - set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
150 | - do_action( 'getpaid_update_geoip_databases' ); |
|
148 | + if (false === $updated) { |
|
149 | + set_transient('getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS); |
|
150 | + do_action('getpaid_update_geoip_databases'); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | } |
@@ -39,62 +39,62 @@ discard block |
||
39 | 39 | <td style="width: 65%"> |
40 | 40 | <?php |
41 | 41 | |
42 | - switch ( $key ) { |
|
42 | + switch ( $key ) { |
|
43 | 43 | |
44 | - case 'status': |
|
45 | - echo esc_html( $subscription->get_status_label() ); |
|
46 | - break; |
|
44 | + case 'status': |
|
45 | + echo esc_html( $subscription->get_status_label() ); |
|
46 | + break; |
|
47 | 47 | |
48 | - case 'start_date': |
|
49 | - echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
50 | - break; |
|
48 | + case 'start_date': |
|
49 | + echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
50 | + break; |
|
51 | 51 | |
52 | - case 'expiry_date': |
|
53 | - echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
54 | - break; |
|
52 | + case 'expiry_date': |
|
53 | + echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
54 | + break; |
|
55 | 55 | |
56 | - case 'initial_amount': |
|
57 | - echo wp_kses_post( wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ) ); |
|
56 | + case 'initial_amount': |
|
57 | + echo wp_kses_post( wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ) ); |
|
58 | 58 | |
59 | - if ( $subscription->has_trial_period() ) { |
|
59 | + if ( $subscription->has_trial_period() ) { |
|
60 | 60 | |
61 | - echo "<small class='text-muted'> "; |
|
62 | - printf( |
|
63 | - esc_html_x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
64 | - esc_html( $subscription->get_trial_period() ) |
|
65 | - ); |
|
66 | - echo '</small>'; |
|
61 | + echo "<small class='text-muted'> "; |
|
62 | + printf( |
|
63 | + esc_html_x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
64 | + esc_html( $subscription->get_trial_period() ) |
|
65 | + ); |
|
66 | + echo '</small>'; |
|
67 | 67 | |
68 | - } |
|
68 | + } |
|
69 | 69 | |
70 | - break; |
|
70 | + break; |
|
71 | 71 | |
72 | - case 'recurring_amount': |
|
73 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
74 | - $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
75 | - echo wp_kses_post( strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ) ); |
|
76 | - break; |
|
72 | + case 'recurring_amount': |
|
73 | + $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
74 | + $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
75 | + echo wp_kses_post( strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ) ); |
|
76 | + break; |
|
77 | 77 | |
78 | - case 'item': |
|
79 | - if ( empty( $subscription_group ) ) { |
|
80 | - echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
81 | - } else { |
|
82 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
83 | - echo wp_kses_post( implode( ' | ', $markup ) ); |
|
84 | - } |
|
78 | + case 'item': |
|
79 | + if ( empty( $subscription_group ) ) { |
|
80 | + echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
81 | + } else { |
|
82 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
83 | + echo wp_kses_post( implode( ' | ', $markup ) ); |
|
84 | + } |
|
85 | 85 | |
86 | - break; |
|
86 | + break; |
|
87 | 87 | |
88 | - case 'payments': |
|
89 | - $max_activations = (int) $subscription->get_bill_times(); |
|
90 | - echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_activations ) ? '∞' : (int) $max_activations ); |
|
88 | + case 'payments': |
|
89 | + $max_activations = (int) $subscription->get_bill_times(); |
|
90 | + echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_activations ) ? '∞' : (int) $max_activations ); |
|
91 | 91 | |
92 | - break; |
|
92 | + break; |
|
93 | 93 | |
94 | - } |
|
95 | - do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
94 | + } |
|
95 | + do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
96 | 96 | |
97 | - ?> |
|
97 | + ?> |
|
98 | 98 | </td> |
99 | 99 | |
100 | 100 | </tr> |
@@ -121,17 +121,17 @@ discard block |
||
121 | 121 | <span class="form-text"> |
122 | 122 | |
123 | 123 | <?php |
124 | - if ( $subscription->can_cancel() ) { |
|
125 | - printf( |
|
124 | + if ( $subscription->can_cancel() ) { |
|
125 | + printf( |
|
126 | 126 | '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
127 | 127 | esc_url( $subscription->get_cancel_url() ), |
128 | 128 | esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
129 | 129 | esc_html__( 'Cancel Subscription', 'invoicing' ) |
130 | 130 | ); |
131 | - } |
|
131 | + } |
|
132 | 132 | |
133 | - do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
134 | - ?> |
|
133 | + do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
134 | + ?> |
|
135 | 135 | |
136 | 136 | <a href="<?php echo esc_url( getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); ?>" class="btn btn-secondary btn-sm"><?php esc_html_e( 'Go Back', 'invoicing' ); ?></a> |
137 | 137 | </span> |
@@ -10,58 +10,58 @@ discard block |
||
10 | 10 | * @var WPInv_Subscriptions_Widget $widget |
11 | 11 | */ |
12 | 12 | |
13 | -defined( 'ABSPATH' ) || exit; |
|
13 | +defined('ABSPATH') || exit; |
|
14 | 14 | |
15 | -do_action( 'getpaid_single_subscription_before_notices', $subscription ); |
|
15 | +do_action('getpaid_single_subscription_before_notices', $subscription); |
|
16 | 16 | |
17 | 17 | // Display errors and notices. |
18 | 18 | wpinv_print_errors(); |
19 | 19 | |
20 | -$subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_invoice_id() ); |
|
21 | -$subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
20 | +$subscription_groups = getpaid_get_invoice_subscription_groups($subscription->get_parent_invoice_id()); |
|
21 | +$subscription_group = getpaid_get_invoice_subscription_group($subscription->get_parent_invoice_id(), $subscription->get_id()); |
|
22 | 22 | |
23 | -do_action( 'getpaid_before_single_subscription', $subscription, $subscription_groups ); |
|
23 | +do_action('getpaid_before_single_subscription', $subscription, $subscription_groups); |
|
24 | 24 | |
25 | 25 | ?> |
26 | 26 | |
27 | -<h2 class="mb-1 h4"><?php esc_html_e( 'Subscription Details', 'invoicing' ); ?></h2> |
|
27 | +<h2 class="mb-1 h4"><?php esc_html_e('Subscription Details', 'invoicing'); ?></h2> |
|
28 | 28 | <table class="table table-bordered"> |
29 | 29 | <tbody> |
30 | 30 | |
31 | - <?php foreach ( $widget->get_single_subscription_columns( $subscription ) as $key => $label ) : ?> |
|
31 | + <?php foreach ($widget->get_single_subscription_columns($subscription) as $key => $label) : ?> |
|
32 | 32 | |
33 | - <tr class="getpaid-subscription-meta-<?php echo esc_attr( $key ); ?>"> |
|
33 | + <tr class="getpaid-subscription-meta-<?php echo esc_attr($key); ?>"> |
|
34 | 34 | |
35 | 35 | <th class="font-weight-bold" style="width: 35%"> |
36 | - <?php echo esc_html( $label ); ?> |
|
36 | + <?php echo esc_html($label); ?> |
|
37 | 37 | </th> |
38 | 38 | |
39 | 39 | <td style="width: 65%"> |
40 | 40 | <?php |
41 | 41 | |
42 | - switch ( $key ) { |
|
42 | + switch ($key) { |
|
43 | 43 | |
44 | 44 | case 'status': |
45 | - echo esc_html( $subscription->get_status_label() ); |
|
45 | + echo esc_html($subscription->get_status_label()); |
|
46 | 46 | break; |
47 | 47 | |
48 | 48 | case 'start_date': |
49 | - echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
49 | + echo esc_html(getpaid_format_date_value($subscription->get_date_created())); |
|
50 | 50 | break; |
51 | 51 | |
52 | 52 | case 'expiry_date': |
53 | - echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
53 | + echo esc_html(getpaid_format_date_value($subscription->get_next_renewal_date())); |
|
54 | 54 | break; |
55 | 55 | |
56 | 56 | case 'initial_amount': |
57 | - echo wp_kses_post( wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ) ); |
|
57 | + echo wp_kses_post(wpinv_price($subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency())); |
|
58 | 58 | |
59 | - if ( $subscription->has_trial_period() ) { |
|
59 | + if ($subscription->has_trial_period()) { |
|
60 | 60 | |
61 | 61 | echo "<small class='text-muted'> "; |
62 | 62 | printf( |
63 | - esc_html_x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
64 | - esc_html( $subscription->get_trial_period() ) |
|
63 | + esc_html_x('( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing'), |
|
64 | + esc_html($subscription->get_trial_period()) |
|
65 | 65 | ); |
66 | 66 | echo '</small>'; |
67 | 67 | |
@@ -70,29 +70,29 @@ discard block |
||
70 | 70 | break; |
71 | 71 | |
72 | 72 | case 'recurring_amount': |
73 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
74 | - $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
75 | - echo wp_kses_post( strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ) ); |
|
73 | + $frequency = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''); |
|
74 | + $amount = wpinv_price($subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency()); |
|
75 | + echo wp_kses_post(strtolower("<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>")); |
|
76 | 76 | break; |
77 | 77 | |
78 | 78 | case 'item': |
79 | - if ( empty( $subscription_group ) ) { |
|
80 | - echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
79 | + if (empty($subscription_group)) { |
|
80 | + echo wp_kses_post(WPInv_Subscriptions_List_Table::generate_item_markup($subscription->get_product_id())); |
|
81 | 81 | } else { |
82 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
83 | - echo wp_kses_post( implode( ' | ', $markup ) ); |
|
82 | + $markup = array_map(array('WPInv_Subscriptions_List_Table', 'generate_item_markup'), array_keys($subscription_group['items'])); |
|
83 | + echo wp_kses_post(implode(' | ', $markup)); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | break; |
87 | 87 | |
88 | 88 | case 'payments': |
89 | 89 | $max_activations = (int) $subscription->get_bill_times(); |
90 | - echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_activations ) ? '∞' : (int) $max_activations ); |
|
90 | + echo ((int) $subscription->get_times_billed()) . ' / ' . (empty($max_activations) ? '∞' : (int) $max_activations); |
|
91 | 91 | |
92 | 92 | break; |
93 | 93 | |
94 | 94 | } |
95 | - do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
95 | + do_action("getpaid_render_single_subscription_column_$key", $subscription); |
|
96 | 96 | |
97 | 97 | ?> |
98 | 98 | </td> |
@@ -104,34 +104,34 @@ discard block |
||
104 | 104 | </tbody> |
105 | 105 | </table> |
106 | 106 | |
107 | -<?php if ( ! empty( $subscription_group ) ) : ?> |
|
108 | - <h2 class='mt-5 mb-1 h4'><?php esc_html_e( 'Subscription Items', 'invoicing' ); ?></h2> |
|
109 | - <?php getpaid_admin_subscription_item_details_metabox( $subscription ); ?> |
|
107 | +<?php if (!empty($subscription_group)) : ?> |
|
108 | + <h2 class='mt-5 mb-1 h4'><?php esc_html_e('Subscription Items', 'invoicing'); ?></h2> |
|
109 | + <?php getpaid_admin_subscription_item_details_metabox($subscription); ?> |
|
110 | 110 | <?php endif; ?> |
111 | 111 | |
112 | -<h2 class='mt-5 mb-1 h4'><?php esc_html_e( 'Related Invoices', 'invoicing' ); ?></h2> |
|
112 | +<h2 class='mt-5 mb-1 h4'><?php esc_html_e('Related Invoices', 'invoicing'); ?></h2> |
|
113 | 113 | |
114 | -<?php echo wp_kses_post( getpaid_admin_subscription_invoice_details_metabox( $subscription ) ); ?> |
|
114 | +<?php echo wp_kses_post(getpaid_admin_subscription_invoice_details_metabox($subscription)); ?> |
|
115 | 115 | |
116 | -<?php if ( 1 < count( $subscription_groups ) ) : ?> |
|
117 | - <h2 class='mt-5 mb-1 h4'><?php esc_html_e( 'Related Subscriptions', 'invoicing' ); ?></h2> |
|
118 | - <?php getpaid_admin_subscription_related_subscriptions_metabox( $subscription ); ?> |
|
116 | +<?php if (1 < count($subscription_groups)) : ?> |
|
117 | + <h2 class='mt-5 mb-1 h4'><?php esc_html_e('Related Subscriptions', 'invoicing'); ?></h2> |
|
118 | + <?php getpaid_admin_subscription_related_subscriptions_metabox($subscription); ?> |
|
119 | 119 | <?php endif; ?> |
120 | 120 | |
121 | 121 | <span class="form-text"> |
122 | 122 | |
123 | 123 | <?php |
124 | - if ( $subscription->can_cancel() ) { |
|
124 | + if ($subscription->can_cancel()) { |
|
125 | 125 | printf( |
126 | 126 | '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
127 | - esc_url( $subscription->get_cancel_url() ), |
|
128 | - esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
|
129 | - esc_html__( 'Cancel Subscription', 'invoicing' ) |
|
127 | + esc_url($subscription->get_cancel_url()), |
|
128 | + esc_attr__('Are you sure you want to cancel this subscription?', 'invoicing'), |
|
129 | + esc_html__('Cancel Subscription', 'invoicing') |
|
130 | 130 | ); |
131 | 131 | } |
132 | 132 | |
133 | - do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
133 | + do_action('getpaid-single-subscription-page-actions', $subscription); |
|
134 | 134 | ?> |
135 | 135 | |
136 | - <a href="<?php echo esc_url( getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); ?>" class="btn btn-secondary btn-sm"><?php esc_html_e( 'Go Back', 'invoicing' ); ?></a> |
|
136 | + <a href="<?php echo esc_url(getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page')))); ?>" class="btn btn-secondary btn-sm"><?php esc_html_e('Go Back', 'invoicing'); ?></a> |
|
137 | 137 | </span> |
@@ -41,55 +41,55 @@ |
||
41 | 41 | |
42 | 42 | switch ( $key ) { |
43 | 43 | |
44 | - case 'status': |
|
45 | - echo esc_html( $subscription->get_status_label() ); |
|
46 | - break; |
|
44 | + case 'status': |
|
45 | + echo esc_html( $subscription->get_status_label() ); |
|
46 | + break; |
|
47 | 47 | |
48 | - case 'start_date': |
|
49 | - echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
50 | - break; |
|
48 | + case 'start_date': |
|
49 | + echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
50 | + break; |
|
51 | 51 | |
52 | - case 'expiry_date': |
|
53 | - echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
54 | - break; |
|
52 | + case 'expiry_date': |
|
53 | + echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
54 | + break; |
|
55 | 55 | |
56 | - case 'initial_amount': |
|
57 | - echo wp_kses_post( wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ) ); |
|
56 | + case 'initial_amount': |
|
57 | + echo wp_kses_post( wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ) ); |
|
58 | 58 | |
59 | - if ( $subscription->has_trial_period() ) { |
|
59 | + if ( $subscription->has_trial_period() ) { |
|
60 | 60 | |
61 | - echo "<small class='text-muted'> "; |
|
62 | - printf( |
|
63 | - esc_html_x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
64 | - esc_html( $subscription->get_trial_period() ) |
|
65 | - ); |
|
66 | - echo '</small>'; |
|
61 | + echo "<small class='text-muted'> "; |
|
62 | + printf( |
|
63 | + esc_html_x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
64 | + esc_html( $subscription->get_trial_period() ) |
|
65 | + ); |
|
66 | + echo '</small>'; |
|
67 | 67 | |
68 | - } |
|
68 | + } |
|
69 | 69 | |
70 | - break; |
|
70 | + break; |
|
71 | 71 | |
72 | - case 'recurring_amount': |
|
73 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
74 | - $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
75 | - echo wp_kses_post( strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ) ); |
|
76 | - break; |
|
72 | + case 'recurring_amount': |
|
73 | + $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
74 | + $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
75 | + echo wp_kses_post( strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ) ); |
|
76 | + break; |
|
77 | 77 | |
78 | - case 'item': |
|
79 | - if ( empty( $subscription_group ) ) { |
|
80 | - echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
81 | - } else { |
|
82 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
83 | - echo wp_kses_post( implode( ' | ', $markup ) ); |
|
84 | - } |
|
78 | + case 'item': |
|
79 | + if ( empty( $subscription_group ) ) { |
|
80 | + echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
81 | + } else { |
|
82 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
83 | + echo wp_kses_post( implode( ' | ', $markup ) ); |
|
84 | + } |
|
85 | 85 | |
86 | - break; |
|
86 | + break; |
|
87 | 87 | |
88 | - case 'payments': |
|
89 | - $max_activations = (int) $subscription->get_bill_times(); |
|
90 | - echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_activations ) ? '∞' : (int) $max_activations ); |
|
88 | + case 'payments': |
|
89 | + $max_activations = (int) $subscription->get_bill_times(); |
|
90 | + echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_activations ) ? '∞' : (int) $max_activations ); |
|
91 | 91 | |
92 | - break; |
|
92 | + break; |
|
93 | 93 | |
94 | 94 | } |
95 | 95 | do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
@@ -0,0 +1,1 @@ |
||
1 | + |
|
0 | 2 | \ No newline at end of file |