@@ -12,489 +12,489 @@ |
||
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 | - $merge_tags = array( |
|
130 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
131 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
133 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
134 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
135 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
136 | - '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
137 | - '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
138 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
139 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
140 | - '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ), |
|
141 | - '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
142 | - '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
143 | - '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
144 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
145 | - '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
146 | - '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
147 | - '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
148 | - ); |
|
149 | - |
|
150 | - $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
151 | - |
|
152 | - if ( is_array( $payment_form_data ) ) { |
|
153 | - |
|
154 | - foreach ( $payment_form_data as $label => $value ) { |
|
155 | - |
|
156 | - $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
157 | - $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
158 | - |
|
159 | - if ( is_scalar( $value ) ) { |
|
160 | - $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
161 | - } |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Helper function to send an email. |
|
170 | - * |
|
171 | - * @param WPInv_Invoice $invoice |
|
172 | - * @param GetPaid_Notification_Email $email |
|
173 | - * @param string $type |
|
174 | - * @param string|array $recipients |
|
175 | - * @param array $extra_args Extra template args. |
|
176 | - */ |
|
177 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
178 | - |
|
179 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
180 | - |
|
181 | - $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
182 | - if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
183 | - return; |
|
184 | - } |
|
185 | - |
|
186 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
187 | - $merge_tags = $email->get_merge_tags(); |
|
188 | - |
|
189 | - $result = $mailer->send( |
|
190 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
191 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
192 | - $email->get_content( $merge_tags, $extra_args ), |
|
193 | - $email->get_attachments() |
|
194 | - ); |
|
195 | - |
|
196 | - // Maybe send a copy to the admin. |
|
197 | - if ( $email->include_admin_bcc() ) { |
|
198 | - $mailer->send( |
|
199 | - wpinv_get_admin_email(), |
|
200 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
201 | - $email->get_content( $merge_tags ), |
|
202 | - $email->get_attachments() |
|
203 | - ); |
|
204 | - } |
|
205 | - |
|
206 | - if ( $result ) { |
|
207 | - $invoice->add_system_note( |
|
208 | - sprintf( |
|
209 | - // translators: %1 is the email type, %2 is the invoice recipient. |
|
210 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
211 | - sanitize_key( $type ), |
|
212 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
213 | - ) |
|
214 | - ); |
|
215 | - } else { |
|
216 | - $invoice->add_system_note( |
|
217 | - sprintf( |
|
218 | - // translators: %1 is the email type, %2 is the invoice recipient. |
|
219 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
220 | - sanitize_key( $type ), |
|
221 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
222 | - ) |
|
223 | - ); |
|
224 | - } |
|
225 | - |
|
226 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
227 | - |
|
228 | - return $result; |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * Also send emails to any cc users. |
|
233 | - * |
|
234 | - * @param array $recipients |
|
235 | - * @param GetPaid_Notification_Email $email |
|
236 | - */ |
|
237 | - public function filter_email_recipients( $recipients, $email ) { |
|
238 | - |
|
239 | - if ( ! $email->is_admin_email() ) { |
|
240 | - $cc = $email->object->get_email_cc(); |
|
241 | - $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
242 | - |
|
243 | - if ( ! empty( $cc ) ) { |
|
244 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
245 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
246 | - } |
|
247 | - |
|
248 | - if ( ! empty( $cc_2 ) ) { |
|
249 | - $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
250 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
251 | - } |
|
252 | - } |
|
253 | - |
|
254 | - return $recipients; |
|
255 | - |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Sends a new invoice notification. |
|
260 | - * |
|
261 | - * @param WPInv_Invoice $invoice |
|
262 | - */ |
|
263 | - public function new_invoice( $invoice ) { |
|
264 | - |
|
265 | - // Only send this email for invoices created via the admin page. |
|
266 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
267 | - return; |
|
268 | - } |
|
269 | - |
|
270 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
271 | - $recipient = wpinv_get_admin_email(); |
|
272 | - |
|
273 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
274 | - |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Sends a cancelled invoice notification. |
|
279 | - * |
|
280 | - * @param WPInv_Invoice $invoice |
|
281 | - */ |
|
282 | - public function cancelled_invoice( $invoice ) { |
|
283 | - |
|
284 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
285 | - $recipient = $invoice->get_email(); |
|
286 | - |
|
287 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Sends a failed invoice notification. |
|
292 | - * |
|
293 | - * @param WPInv_Invoice $invoice |
|
294 | - */ |
|
295 | - public function failed_invoice( $invoice ) { |
|
296 | - |
|
297 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
298 | - $recipient = wpinv_get_admin_email(); |
|
299 | - |
|
300 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
301 | - |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Sends a notification whenever an invoice is put on hold. |
|
306 | - * |
|
307 | - * @param WPInv_Invoice $invoice |
|
308 | - */ |
|
309 | - public function onhold_invoice( $invoice ) { |
|
310 | - |
|
311 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
312 | - $recipient = $invoice->get_email(); |
|
313 | - |
|
314 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
315 | - |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * Sends a notification whenever an invoice is marked as processing payment. |
|
320 | - * |
|
321 | - * @param WPInv_Invoice $invoice |
|
322 | - */ |
|
323 | - public function processing_invoice( $invoice ) { |
|
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 | + $merge_tags = array( |
|
130 | + '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
131 | + '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | + '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
133 | + '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
134 | + '{email}' => sanitize_email( $invoice->get_email() ), |
|
135 | + '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
136 | + '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
137 | + '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
138 | + '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
139 | + '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
140 | + '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ), |
|
141 | + '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
142 | + '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
143 | + '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
144 | + '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
145 | + '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
146 | + '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
147 | + '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
148 | + ); |
|
149 | + |
|
150 | + $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
151 | + |
|
152 | + if ( is_array( $payment_form_data ) ) { |
|
324 | 153 | |
325 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
326 | - $recipient = $invoice->get_email(); |
|
327 | - |
|
328 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
329 | - |
|
330 | - } |
|
331 | - |
|
332 | - /** |
|
333 | - * Sends a notification whenever an invoice is paid. |
|
334 | - * |
|
335 | - * @param WPInv_Invoice $invoice |
|
336 | - */ |
|
337 | - public function completed_invoice( $invoice ) { |
|
154 | + foreach ( $payment_form_data as $label => $value ) { |
|
338 | 155 | |
339 | - // (Maybe) abort if it is a renewal invoice. |
|
340 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
341 | - return; |
|
342 | - } |
|
343 | - |
|
344 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
345 | - $recipient = $invoice->get_email(); |
|
156 | + $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
157 | + $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
346 | 158 | |
347 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
159 | + if ( is_scalar( $value ) ) { |
|
160 | + $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
161 | + } |
|
162 | + } |
|
163 | + } |
|
348 | 164 | |
349 | - } |
|
165 | + return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
166 | + } |
|
350 | 167 | |
351 | - /** |
|
352 | - * Sends a notification whenever an invoice is refunded. |
|
353 | - * |
|
354 | - * @param WPInv_Invoice $invoice |
|
355 | - */ |
|
356 | - public function refunded_invoice( $invoice ) { |
|
168 | + /** |
|
169 | + * Helper function to send an email. |
|
170 | + * |
|
171 | + * @param WPInv_Invoice $invoice |
|
172 | + * @param GetPaid_Notification_Email $email |
|
173 | + * @param string $type |
|
174 | + * @param string|array $recipients |
|
175 | + * @param array $extra_args Extra template args. |
|
176 | + */ |
|
177 | + public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
357 | 178 | |
358 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
359 | - $recipient = $invoice->get_email(); |
|
360 | - |
|
361 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
179 | + do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
180 | + |
|
181 | + $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
182 | + if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
183 | + return; |
|
184 | + } |
|
185 | + |
|
186 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
187 | + $merge_tags = $email->get_merge_tags(); |
|
188 | + |
|
189 | + $result = $mailer->send( |
|
190 | + apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
191 | + $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
192 | + $email->get_content( $merge_tags, $extra_args ), |
|
193 | + $email->get_attachments() |
|
194 | + ); |
|
362 | 195 | |
363 | - } |
|
196 | + // Maybe send a copy to the admin. |
|
197 | + if ( $email->include_admin_bcc() ) { |
|
198 | + $mailer->send( |
|
199 | + wpinv_get_admin_email(), |
|
200 | + $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
201 | + $email->get_content( $merge_tags ), |
|
202 | + $email->get_attachments() |
|
203 | + ); |
|
204 | + } |
|
205 | + |
|
206 | + if ( $result ) { |
|
207 | + $invoice->add_system_note( |
|
208 | + sprintf( |
|
209 | + // translators: %1 is the email type, %2 is the invoice recipient. |
|
210 | + __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
211 | + sanitize_key( $type ), |
|
212 | + $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
213 | + ) |
|
214 | + ); |
|
215 | + } else { |
|
216 | + $invoice->add_system_note( |
|
217 | + sprintf( |
|
218 | + // translators: %1 is the email type, %2 is the invoice recipient. |
|
219 | + __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
220 | + sanitize_key( $type ), |
|
221 | + $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
222 | + ) |
|
223 | + ); |
|
224 | + } |
|
225 | + |
|
226 | + do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
227 | + |
|
228 | + return $result; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Also send emails to any cc users. |
|
233 | + * |
|
234 | + * @param array $recipients |
|
235 | + * @param GetPaid_Notification_Email $email |
|
236 | + */ |
|
237 | + public function filter_email_recipients( $recipients, $email ) { |
|
238 | + |
|
239 | + if ( ! $email->is_admin_email() ) { |
|
240 | + $cc = $email->object->get_email_cc(); |
|
241 | + $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
242 | + |
|
243 | + if ( ! empty( $cc ) ) { |
|
244 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
245 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
246 | + } |
|
247 | + |
|
248 | + if ( ! empty( $cc_2 ) ) { |
|
249 | + $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
250 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
251 | + } |
|
252 | + } |
|
253 | + |
|
254 | + return $recipients; |
|
255 | + |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Sends a new invoice notification. |
|
260 | + * |
|
261 | + * @param WPInv_Invoice $invoice |
|
262 | + */ |
|
263 | + public function new_invoice( $invoice ) { |
|
264 | + |
|
265 | + // Only send this email for invoices created via the admin page. |
|
266 | + if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
267 | + return; |
|
268 | + } |
|
269 | + |
|
270 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
271 | + $recipient = wpinv_get_admin_email(); |
|
272 | + |
|
273 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
274 | + |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Sends a cancelled invoice notification. |
|
279 | + * |
|
280 | + * @param WPInv_Invoice $invoice |
|
281 | + */ |
|
282 | + public function cancelled_invoice( $invoice ) { |
|
283 | + |
|
284 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
285 | + $recipient = $invoice->get_email(); |
|
286 | + |
|
287 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Sends a failed invoice notification. |
|
292 | + * |
|
293 | + * @param WPInv_Invoice $invoice |
|
294 | + */ |
|
295 | + public function failed_invoice( $invoice ) { |
|
296 | + |
|
297 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
298 | + $recipient = wpinv_get_admin_email(); |
|
299 | + |
|
300 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
301 | + |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Sends a notification whenever an invoice is put on hold. |
|
306 | + * |
|
307 | + * @param WPInv_Invoice $invoice |
|
308 | + */ |
|
309 | + public function onhold_invoice( $invoice ) { |
|
310 | + |
|
311 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
312 | + $recipient = $invoice->get_email(); |
|
313 | + |
|
314 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
315 | + |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * Sends a notification whenever an invoice is marked as processing payment. |
|
320 | + * |
|
321 | + * @param WPInv_Invoice $invoice |
|
322 | + */ |
|
323 | + public function processing_invoice( $invoice ) { |
|
364 | 324 | |
365 | - /** |
|
366 | - * Notifies a user about new invoices |
|
367 | - * |
|
368 | - * @param WPInv_Invoice $invoice |
|
369 | - * @param bool $force |
|
370 | - */ |
|
371 | - public function user_invoice( $invoice, $force = false ) { |
|
325 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
326 | + $recipient = $invoice->get_email(); |
|
327 | + |
|
328 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
329 | + |
|
330 | + } |
|
331 | + |
|
332 | + /** |
|
333 | + * Sends a notification whenever an invoice is paid. |
|
334 | + * |
|
335 | + * @param WPInv_Invoice $invoice |
|
336 | + */ |
|
337 | + public function completed_invoice( $invoice ) { |
|
372 | 338 | |
373 | - if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
374 | - return; |
|
375 | - } |
|
376 | - |
|
377 | - // Only send this email for invoices created via the admin page. |
|
378 | - if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
379 | - return; |
|
380 | - } |
|
339 | + // (Maybe) abort if it is a renewal invoice. |
|
340 | + if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
341 | + return; |
|
342 | + } |
|
343 | + |
|
344 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
345 | + $recipient = $invoice->get_email(); |
|
381 | 346 | |
382 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
383 | - $recipient = $invoice->get_email(); |
|
384 | - |
|
385 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
347 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
386 | 348 | |
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Checks if an invoice is a payment form invoice. |
|
391 | - * |
|
392 | - * @param int $invoice |
|
393 | - * @return bool |
|
394 | - */ |
|
395 | - public function is_payment_form_invoice( $invoice ) { |
|
396 | - $is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' === get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' === get_post_meta( $invoice, 'wpinv_created_via', true ) ); |
|
397 | - return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
398 | - } |
|
349 | + } |
|
399 | 350 | |
400 | - /** |
|
401 | - * Notifies admin about new invoice notes |
|
402 | - * |
|
403 | - * @param WPInv_Invoice $invoice |
|
404 | - * @param string $note |
|
405 | - */ |
|
406 | - public function user_note( $invoice, $note ) { |
|
407 | - |
|
408 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
409 | - $recipient = $invoice->get_email(); |
|
351 | + /** |
|
352 | + * Sends a notification whenever an invoice is refunded. |
|
353 | + * |
|
354 | + * @param WPInv_Invoice $invoice |
|
355 | + */ |
|
356 | + public function refunded_invoice( $invoice ) { |
|
410 | 357 | |
411 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
412 | - |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * (Force) Sends overdue notices. |
|
417 | - * |
|
418 | - * @param WPInv_Invoice $invoice |
|
419 | - */ |
|
420 | - public function force_send_overdue_notice( $invoice ) { |
|
421 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
422 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
423 | - } |
|
424 | - |
|
425 | - /** |
|
426 | - * Sends overdue notices. |
|
427 | - * |
|
428 | - * @TODO: Create an invoices query class. |
|
429 | - */ |
|
430 | - public function overdue() { |
|
431 | - global $wpdb; |
|
432 | - |
|
433 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
434 | - |
|
435 | - // Fetch reminder days. |
|
436 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
437 | - |
|
438 | - // Abort if non is set. |
|
439 | - if ( empty( $reminder_days ) ) { |
|
440 | - return; |
|
441 | - } |
|
442 | - |
|
443 | - // Retrieve date query. |
|
444 | - $date_query = $this->get_date_query( $reminder_days ); |
|
445 | - |
|
446 | - // Invoices table. |
|
447 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
448 | - |
|
449 | - // Fetch invoices. |
|
450 | - $invoices = $wpdb->get_col( |
|
451 | - "SELECT posts.ID FROM $wpdb->posts as posts |
|
358 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
359 | + $recipient = $invoice->get_email(); |
|
360 | + |
|
361 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
362 | + |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Notifies a user about new invoices |
|
367 | + * |
|
368 | + * @param WPInv_Invoice $invoice |
|
369 | + * @param bool $force |
|
370 | + */ |
|
371 | + public function user_invoice( $invoice, $force = false ) { |
|
372 | + |
|
373 | + if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
374 | + return; |
|
375 | + } |
|
376 | + |
|
377 | + // Only send this email for invoices created via the admin page. |
|
378 | + if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
379 | + return; |
|
380 | + } |
|
381 | + |
|
382 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
383 | + $recipient = $invoice->get_email(); |
|
384 | + |
|
385 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
386 | + |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Checks if an invoice is a payment form invoice. |
|
391 | + * |
|
392 | + * @param int $invoice |
|
393 | + * @return bool |
|
394 | + */ |
|
395 | + public function is_payment_form_invoice( $invoice ) { |
|
396 | + $is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' === get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' === get_post_meta( $invoice, 'wpinv_created_via', true ) ); |
|
397 | + return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
398 | + } |
|
399 | + |
|
400 | + /** |
|
401 | + * Notifies admin about new invoice notes |
|
402 | + * |
|
403 | + * @param WPInv_Invoice $invoice |
|
404 | + * @param string $note |
|
405 | + */ |
|
406 | + public function user_note( $invoice, $note ) { |
|
407 | + |
|
408 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
409 | + $recipient = $invoice->get_email(); |
|
410 | + |
|
411 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
412 | + |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * (Force) Sends overdue notices. |
|
417 | + * |
|
418 | + * @param WPInv_Invoice $invoice |
|
419 | + */ |
|
420 | + public function force_send_overdue_notice( $invoice ) { |
|
421 | + $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
422 | + return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
423 | + } |
|
424 | + |
|
425 | + /** |
|
426 | + * Sends overdue notices. |
|
427 | + * |
|
428 | + * @TODO: Create an invoices query class. |
|
429 | + */ |
|
430 | + public function overdue() { |
|
431 | + global $wpdb; |
|
432 | + |
|
433 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
434 | + |
|
435 | + // Fetch reminder days. |
|
436 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
437 | + |
|
438 | + // Abort if non is set. |
|
439 | + if ( empty( $reminder_days ) ) { |
|
440 | + return; |
|
441 | + } |
|
442 | + |
|
443 | + // Retrieve date query. |
|
444 | + $date_query = $this->get_date_query( $reminder_days ); |
|
445 | + |
|
446 | + // Invoices table. |
|
447 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
448 | + |
|
449 | + // Fetch invoices. |
|
450 | + $invoices = $wpdb->get_col( |
|
451 | + "SELECT posts.ID FROM $wpdb->posts as posts |
|
452 | 452 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
453 | 453 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query" |
454 | 454 | ); |
455 | 455 | |
456 | - foreach ( $invoices as $invoice ) { |
|
456 | + foreach ( $invoices as $invoice ) { |
|
457 | 457 | |
458 | - // Only send this email for invoices created via the admin page. |
|
459 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
460 | - $invoice = new WPInv_Invoice( $invoice ); |
|
461 | - $email->object = $invoice; |
|
458 | + // Only send this email for invoices created via the admin page. |
|
459 | + if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
460 | + $invoice = new WPInv_Invoice( $invoice ); |
|
461 | + $email->object = $invoice; |
|
462 | 462 | |
463 | - if ( $invoice->needs_payment() ) { |
|
464 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
465 | - } |
|
463 | + if ( $invoice->needs_payment() ) { |
|
464 | + $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
465 | + } |
|
466 | 466 | } |
467 | 467 | } |
468 | 468 | |
469 | - } |
|
469 | + } |
|
470 | 470 | |
471 | - /** |
|
472 | - * Calculates the date query for an invoices query |
|
473 | - * |
|
474 | - * @param array $reminder_days |
|
475 | - * @return string |
|
476 | - */ |
|
477 | - public function get_date_query( $reminder_days ) { |
|
471 | + /** |
|
472 | + * Calculates the date query for an invoices query |
|
473 | + * |
|
474 | + * @param array $reminder_days |
|
475 | + * @return string |
|
476 | + */ |
|
477 | + public function get_date_query( $reminder_days ) { |
|
478 | 478 | |
479 | - $date_query = array( |
|
480 | - 'relation' => 'OR', |
|
481 | - ); |
|
479 | + $date_query = array( |
|
480 | + 'relation' => 'OR', |
|
481 | + ); |
|
482 | 482 | |
483 | - foreach ( $reminder_days as $days ) { |
|
484 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
483 | + foreach ( $reminder_days as $days ) { |
|
484 | + $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
485 | 485 | |
486 | - $date_query[] = array( |
|
487 | - 'year' => $date['year'], |
|
488 | - 'month' => $date['month'], |
|
489 | - 'day' => $date['day'], |
|
490 | - ); |
|
486 | + $date_query[] = array( |
|
487 | + 'year' => $date['year'], |
|
488 | + 'month' => $date['month'], |
|
489 | + 'day' => $date['day'], |
|
490 | + ); |
|
491 | 491 | |
492 | - } |
|
492 | + } |
|
493 | 493 | |
494 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
494 | + $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
495 | 495 | |
496 | - return $date_query->get_sql(); |
|
496 | + return $date_query->get_sql(); |
|
497 | 497 | |
498 | - } |
|
498 | + } |
|
499 | 499 | |
500 | 500 | } |
@@ -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,50 +119,50 @@ 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 | $merge_tags = array( |
130 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
131 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
133 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
134 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
135 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
136 | - '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
137 | - '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
138 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
139 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
140 | - '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ), |
|
141 | - '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
142 | - '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
143 | - '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
144 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
145 | - '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
146 | - '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
147 | - '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
130 | + '{name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
131 | + '{full_name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
132 | + '{first_name}' => sanitize_text_field($invoice->get_first_name()), |
|
133 | + '{last_name}' => sanitize_text_field($invoice->get_last_name()), |
|
134 | + '{email}' => sanitize_email($invoice->get_email()), |
|
135 | + '{invoice_number}' => sanitize_text_field($invoice->get_number()), |
|
136 | + '{invoice_currency}' => sanitize_text_field($invoice->get_currency()), |
|
137 | + '{invoice_total}' => sanitize_text_field(wpinv_price($invoice->get_total(), $invoice->get_currency())), |
|
138 | + '{invoice_link}' => esc_url($invoice->get_view_url()), |
|
139 | + '{invoice_pay_link}' => esc_url($invoice->get_checkout_payment_url()), |
|
140 | + '{invoice_receipt_link}' => esc_url($invoice->get_receipt_url()), |
|
141 | + '{invoice_date}' => getpaid_format_date_value($invoice->get_date_created()), |
|
142 | + '{invoice_due_date}' => getpaid_format_date_value($invoice->get_due_date(), __('on receipt', 'invoicing')), |
|
143 | + '{invoice_quote}' => sanitize_text_field(strtolower($invoice->get_label())), |
|
144 | + '{invoice_label}' => sanitize_text_field(ucfirst($invoice->get_label())), |
|
145 | + '{invoice_description}' => wp_kses_post($invoice->get_description()), |
|
146 | + '{subscription_name}' => wp_kses_post($invoice->get_subscription_name()), |
|
147 | + '{is_was}' => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'), |
|
148 | 148 | ); |
149 | 149 | |
150 | - $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
150 | + $payment_form_data = $invoice->get_meta('payment_form_data', true); |
|
151 | 151 | |
152 | - if ( is_array( $payment_form_data ) ) { |
|
152 | + if (is_array($payment_form_data)) { |
|
153 | 153 | |
154 | - foreach ( $payment_form_data as $label => $value ) { |
|
154 | + foreach ($payment_form_data as $label => $value) { |
|
155 | 155 | |
156 | - $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
157 | - $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
156 | + $label = preg_replace('/[^a-z0-9]+/', '_', strtolower($label)); |
|
157 | + $value = is_array($value) ? implode(', ', $value) : $value; |
|
158 | 158 | |
159 | - if ( is_scalar( $value ) ) { |
|
160 | - $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
159 | + if (is_scalar($value)) { |
|
160 | + $merge_tags["{{$label}}"] = wp_kses_post($value); |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
165 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
165 | + return apply_filters('getpaid_invoice_email_merge_tags', $merge_tags, $invoice); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | * @param string|array $recipients |
175 | 175 | * @param array $extra_args Extra template args. |
176 | 176 | */ |
177 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
177 | + public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) { |
|
178 | 178 | |
179 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
179 | + do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email); |
|
180 | 180 | |
181 | - $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
182 | - if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
181 | + $skip = $invoice->is_free() && wpinv_get_option('skip_email_free_invoice'); |
|
182 | + if (apply_filters('getpaid_skip_invoice_email', $skip, $type, $invoice)) { |
|
183 | 183 | return; |
184 | 184 | } |
185 | 185 | |
@@ -187,43 +187,43 @@ discard block |
||
187 | 187 | $merge_tags = $email->get_merge_tags(); |
188 | 188 | |
189 | 189 | $result = $mailer->send( |
190 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
191 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
192 | - $email->get_content( $merge_tags, $extra_args ), |
|
190 | + apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email), |
|
191 | + $email->add_merge_tags($email->get_subject(), $merge_tags), |
|
192 | + $email->get_content($merge_tags, $extra_args), |
|
193 | 193 | $email->get_attachments() |
194 | 194 | ); |
195 | 195 | |
196 | 196 | // Maybe send a copy to the admin. |
197 | - if ( $email->include_admin_bcc() ) { |
|
197 | + if ($email->include_admin_bcc()) { |
|
198 | 198 | $mailer->send( |
199 | 199 | wpinv_get_admin_email(), |
200 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
201 | - $email->get_content( $merge_tags ), |
|
200 | + $email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags), |
|
201 | + $email->get_content($merge_tags), |
|
202 | 202 | $email->get_attachments() |
203 | 203 | ); |
204 | 204 | } |
205 | 205 | |
206 | - if ( $result ) { |
|
206 | + if ($result) { |
|
207 | 207 | $invoice->add_system_note( |
208 | 208 | sprintf( |
209 | 209 | // translators: %1 is the email type, %2 is the invoice recipient. |
210 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
211 | - sanitize_key( $type ), |
|
212 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
210 | + __('Successfully sent %1$s notification email to %2$s.', 'invoicing'), |
|
211 | + sanitize_key($type), |
|
212 | + $email->is_admin_email() ? __('admin', 'invoicing') : __('the customer', 'invoicing') |
|
213 | 213 | ) |
214 | 214 | ); |
215 | 215 | } else { |
216 | 216 | $invoice->add_system_note( |
217 | 217 | sprintf( |
218 | 218 | // translators: %1 is the email type, %2 is the invoice recipient. |
219 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
220 | - sanitize_key( $type ), |
|
221 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
219 | + __('Failed sending %1$s notification email to %2$s.', 'invoicing'), |
|
220 | + sanitize_key($type), |
|
221 | + $email->is_admin_email() ? __('admin', 'invoicing') : __('the customer', 'invoicing') |
|
222 | 222 | ) |
223 | 223 | ); |
224 | 224 | } |
225 | 225 | |
226 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
226 | + do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email); |
|
227 | 227 | |
228 | 228 | return $result; |
229 | 229 | } |
@@ -234,20 +234,20 @@ discard block |
||
234 | 234 | * @param array $recipients |
235 | 235 | * @param GetPaid_Notification_Email $email |
236 | 236 | */ |
237 | - public function filter_email_recipients( $recipients, $email ) { |
|
237 | + public function filter_email_recipients($recipients, $email) { |
|
238 | 238 | |
239 | - if ( ! $email->is_admin_email() ) { |
|
239 | + if (!$email->is_admin_email()) { |
|
240 | 240 | $cc = $email->object->get_email_cc(); |
241 | - $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
241 | + $cc_2 = get_user_meta($email->object->get_user_id(), '_wpinv_email_cc', true); |
|
242 | 242 | |
243 | - if ( ! empty( $cc ) ) { |
|
244 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
245 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
243 | + if (!empty($cc)) { |
|
244 | + $cc = array_map('sanitize_email', wpinv_parse_list($cc)); |
|
245 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc))); |
|
246 | 246 | } |
247 | 247 | |
248 | - if ( ! empty( $cc_2 ) ) { |
|
249 | - $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
250 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
248 | + if (!empty($cc_2)) { |
|
249 | + $cc_2 = array_map('sanitize_email', wpinv_parse_list($cc_2)); |
|
250 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc_2))); |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 | |
@@ -260,17 +260,17 @@ discard block |
||
260 | 260 | * |
261 | 261 | * @param WPInv_Invoice $invoice |
262 | 262 | */ |
263 | - public function new_invoice( $invoice ) { |
|
263 | + public function new_invoice($invoice) { |
|
264 | 264 | |
265 | 265 | // Only send this email for invoices created via the admin page. |
266 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
266 | + if (!$invoice->is_type('invoice') || $invoice->is_paid() || $this->is_payment_form_invoice($invoice->get_id())) { |
|
267 | 267 | return; |
268 | 268 | } |
269 | 269 | |
270 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
270 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
271 | 271 | $recipient = wpinv_get_admin_email(); |
272 | 272 | |
273 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
273 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
274 | 274 | |
275 | 275 | } |
276 | 276 | |
@@ -279,12 +279,12 @@ discard block |
||
279 | 279 | * |
280 | 280 | * @param WPInv_Invoice $invoice |
281 | 281 | */ |
282 | - public function cancelled_invoice( $invoice ) { |
|
282 | + public function cancelled_invoice($invoice) { |
|
283 | 283 | |
284 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
284 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
285 | 285 | $recipient = $invoice->get_email(); |
286 | 286 | |
287 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
287 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | /** |
@@ -292,12 +292,12 @@ discard block |
||
292 | 292 | * |
293 | 293 | * @param WPInv_Invoice $invoice |
294 | 294 | */ |
295 | - public function failed_invoice( $invoice ) { |
|
295 | + public function failed_invoice($invoice) { |
|
296 | 296 | |
297 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
297 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
298 | 298 | $recipient = wpinv_get_admin_email(); |
299 | 299 | |
300 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
300 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
301 | 301 | |
302 | 302 | } |
303 | 303 | |
@@ -306,12 +306,12 @@ discard block |
||
306 | 306 | * |
307 | 307 | * @param WPInv_Invoice $invoice |
308 | 308 | */ |
309 | - public function onhold_invoice( $invoice ) { |
|
309 | + public function onhold_invoice($invoice) { |
|
310 | 310 | |
311 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
311 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
312 | 312 | $recipient = $invoice->get_email(); |
313 | 313 | |
314 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
314 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
315 | 315 | |
316 | 316 | } |
317 | 317 | |
@@ -320,12 +320,12 @@ discard block |
||
320 | 320 | * |
321 | 321 | * @param WPInv_Invoice $invoice |
322 | 322 | */ |
323 | - public function processing_invoice( $invoice ) { |
|
323 | + public function processing_invoice($invoice) { |
|
324 | 324 | |
325 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
325 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
326 | 326 | $recipient = $invoice->get_email(); |
327 | 327 | |
328 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
328 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
329 | 329 | |
330 | 330 | } |
331 | 331 | |
@@ -334,17 +334,17 @@ discard block |
||
334 | 334 | * |
335 | 335 | * @param WPInv_Invoice $invoice |
336 | 336 | */ |
337 | - public function completed_invoice( $invoice ) { |
|
337 | + public function completed_invoice($invoice) { |
|
338 | 338 | |
339 | 339 | // (Maybe) abort if it is a renewal invoice. |
340 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
340 | + if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) { |
|
341 | 341 | return; |
342 | 342 | } |
343 | 343 | |
344 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
344 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
345 | 345 | $recipient = $invoice->get_email(); |
346 | 346 | |
347 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
347 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
348 | 348 | |
349 | 349 | } |
350 | 350 | |
@@ -353,12 +353,12 @@ discard block |
||
353 | 353 | * |
354 | 354 | * @param WPInv_Invoice $invoice |
355 | 355 | */ |
356 | - public function refunded_invoice( $invoice ) { |
|
356 | + public function refunded_invoice($invoice) { |
|
357 | 357 | |
358 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
358 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
359 | 359 | $recipient = $invoice->get_email(); |
360 | 360 | |
361 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
361 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
362 | 362 | |
363 | 363 | } |
364 | 364 | |
@@ -368,21 +368,21 @@ discard block |
||
368 | 368 | * @param WPInv_Invoice $invoice |
369 | 369 | * @param bool $force |
370 | 370 | */ |
371 | - public function user_invoice( $invoice, $force = false ) { |
|
371 | + public function user_invoice($invoice, $force = false) { |
|
372 | 372 | |
373 | - if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
373 | + if (!$force && !empty($GLOBALS['wpinv_skip_invoice_notification'])) { |
|
374 | 374 | return; |
375 | 375 | } |
376 | 376 | |
377 | 377 | // Only send this email for invoices created via the admin page. |
378 | - if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
378 | + if (!$invoice->is_type('invoice') || (empty($force) && $invoice->is_paid()) || (empty($force) && $this->is_payment_form_invoice($invoice->get_id()))) { |
|
379 | 379 | return; |
380 | 380 | } |
381 | 381 | |
382 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
382 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
383 | 383 | $recipient = $invoice->get_email(); |
384 | 384 | |
385 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
385 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
386 | 386 | |
387 | 387 | } |
388 | 388 | |
@@ -392,9 +392,9 @@ discard block |
||
392 | 392 | * @param int $invoice |
393 | 393 | * @return bool |
394 | 394 | */ |
395 | - public function is_payment_form_invoice( $invoice ) { |
|
396 | - $is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' === get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' === get_post_meta( $invoice, 'wpinv_created_via', true ) ); |
|
397 | - return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
395 | + public function is_payment_form_invoice($invoice) { |
|
396 | + $is_payment_form_invoice = empty($_GET['getpaid-admin-action']) && ('payment_form' === get_post_meta($invoice, 'wpinv_created_via', true) || 'geodirectory' === get_post_meta($invoice, 'wpinv_created_via', true)); |
|
397 | + return apply_filters('getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | /** |
@@ -403,12 +403,12 @@ discard block |
||
403 | 403 | * @param WPInv_Invoice $invoice |
404 | 404 | * @param string $note |
405 | 405 | */ |
406 | - public function user_note( $invoice, $note ) { |
|
406 | + public function user_note($invoice, $note) { |
|
407 | 407 | |
408 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
408 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
409 | 409 | $recipient = $invoice->get_email(); |
410 | 410 | |
411 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
411 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note)); |
|
412 | 412 | |
413 | 413 | } |
414 | 414 | |
@@ -417,9 +417,9 @@ discard block |
||
417 | 417 | * |
418 | 418 | * @param WPInv_Invoice $invoice |
419 | 419 | */ |
420 | - public function force_send_overdue_notice( $invoice ) { |
|
421 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
422 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
420 | + public function force_send_overdue_notice($invoice) { |
|
421 | + $email = new GetPaid_Notification_Email('overdue', $invoice); |
|
422 | + return $this->send_email($invoice, $email, 'overdue', $invoice->get_email()); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | /** |
@@ -430,38 +430,38 @@ discard block |
||
430 | 430 | public function overdue() { |
431 | 431 | global $wpdb; |
432 | 432 | |
433 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
433 | + $email = new GetPaid_Notification_Email(__FUNCTION__); |
|
434 | 434 | |
435 | 435 | // Fetch reminder days. |
436 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
436 | + $reminder_days = array_unique(wp_parse_id_list($email->get_option('days'))); |
|
437 | 437 | |
438 | 438 | // Abort if non is set. |
439 | - if ( empty( $reminder_days ) ) { |
|
439 | + if (empty($reminder_days)) { |
|
440 | 440 | return; |
441 | 441 | } |
442 | 442 | |
443 | 443 | // Retrieve date query. |
444 | - $date_query = $this->get_date_query( $reminder_days ); |
|
444 | + $date_query = $this->get_date_query($reminder_days); |
|
445 | 445 | |
446 | 446 | // Invoices table. |
447 | 447 | $table = $wpdb->prefix . 'getpaid_invoices'; |
448 | 448 | |
449 | 449 | // Fetch invoices. |
450 | - $invoices = $wpdb->get_col( |
|
450 | + $invoices = $wpdb->get_col( |
|
451 | 451 | "SELECT posts.ID FROM $wpdb->posts as posts |
452 | 452 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
453 | 453 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query" |
454 | 454 | ); |
455 | 455 | |
456 | - foreach ( $invoices as $invoice ) { |
|
456 | + foreach ($invoices as $invoice) { |
|
457 | 457 | |
458 | 458 | // Only send this email for invoices created via the admin page. |
459 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
460 | - $invoice = new WPInv_Invoice( $invoice ); |
|
459 | + if (!$this->is_payment_form_invoice($invoice)) { |
|
460 | + $invoice = new WPInv_Invoice($invoice); |
|
461 | 461 | $email->object = $invoice; |
462 | 462 | |
463 | - if ( $invoice->needs_payment() ) { |
|
464 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
463 | + if ($invoice->needs_payment()) { |
|
464 | + $this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email()); |
|
465 | 465 | } |
466 | 466 | } |
467 | 467 | } |
@@ -474,14 +474,14 @@ discard block |
||
474 | 474 | * @param array $reminder_days |
475 | 475 | * @return string |
476 | 476 | */ |
477 | - public function get_date_query( $reminder_days ) { |
|
477 | + public function get_date_query($reminder_days) { |
|
478 | 478 | |
479 | 479 | $date_query = array( |
480 | 480 | 'relation' => 'OR', |
481 | 481 | ); |
482 | 482 | |
483 | - foreach ( $reminder_days as $days ) { |
|
484 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
483 | + foreach ($reminder_days as $days) { |
|
484 | + $date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp')))); |
|
485 | 485 | |
486 | 486 | $date_query[] = array( |
487 | 487 | 'year' => $date['year'], |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | |
492 | 492 | } |
493 | 493 | |
494 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
494 | + $date_query = new WP_Date_Query($date_query, 'invoices.due_date'); |
|
495 | 495 | |
496 | 496 | return $date_query->get_sql(); |
497 | 497 |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php |
|
1 | + <?php |
|
2 | 2 | |
3 | 3 | /** |
4 | 4 | * Template that prints a single subscription's details |
@@ -10,19 +10,19 @@ 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 | -// Display errors and notices. |
|
18 | -wpinv_print_errors(); |
|
17 | + // Display errors and notices. |
|
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 | 27 | <h2 class="mb-1 h4"><?php esc_html_e( 'Subscription Details', 'invoicing' ); ?></h2> |
28 | 28 | <table class="table table-bordered"> |
@@ -39,59 +39,59 @@ 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 | - } |
|
94 | + } |
|
95 | 95 | do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
96 | 96 | |
97 | 97 | ?> |