Passed
Push — master ( abdd42...378b1c )
by Brian
20:25 queued 15:01
created

wpinv_onhold_invoice_notification()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 49
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 32
c 2
b 0
f 0
dl 0
loc 49
rs 8.7857
cc 6
nc 6
nop 2
1
<?php
2
/**
3
 * Contains functions related to Invoicing plugin.
4
 *
5
 * @since 1.0.0
6
 * @package Invoicing
7
 */
8
9
// MUST have WordPress.
10
if ( !defined( 'WPINC' ) ) {
11
    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
12
}
13
14
function wpinv_init_transactional_emails() {
15
    $email_actions = apply_filters( 'wpinv_email_actions', array(
16
        'wpinv_status_wpi-pending_to_wpi-processing',
17
        'wpinv_status_wpi-pending_to_publish',
18
        'wpinv_status_wpi-pending_to_wpi-cancelled',
19
        'wpinv_status_wpi-pending_to_wpi-failed',
20
        'wpinv_status_wpi-pending_to_wpi-onhold',
21
        'wpinv_status_wpi-failed_to_wpi-processing',
22
        'wpinv_status_wpi-failed_to_publish',
23
        'wpinv_status_wpi-failed_to_wpi-onhold',
24
        'wpinv_status_wpi-onhold_wpi-to_processing',
25
        'wpinv_status_wpi-onhold_to_wpi-cancelled',
26
        'wpinv_status_wpi-onhold_to_wpi-failed',
27
        'wpinv_status_publish_to_wpi-refunded',
28
        'wpinv_status_wpi-processing_to_wpi-refunded',
29
        'wpinv_status_publish',
30
        'wpinv_fully_refunded',
31
        'wpinv_partially_refunded',
32
        'wpinv_new_invoice_note'
33
    ) );
34
35
    foreach ( $email_actions as $action ) {
36
        add_action( $action, 'wpinv_send_transactional_email', 10, 10 );
37
    }
38
}
39
add_action( 'init', 'wpinv_init_transactional_emails' );
40
41
// New invoice email
42
add_action( 'wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_new_invoice_notification' );
43
add_action( 'wpinv_status_wpi-pending_to_publish_notification', 'wpinv_new_invoice_notification' );
44
add_action( 'wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_new_invoice_notification' );
45
add_action( 'wpinv_status_wpi-failed_to_wpi-processing_notification', 'wpinv_new_invoice_notification' );
46
add_action( 'wpinv_status_wpi-failed_to_publish_notification', 'wpinv_new_invoice_notification' );
47
add_action( 'wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_new_invoice_notification' );
48
49
// Cancelled invoice email
50
add_action( 'wpinv_status_wpi-pending_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification' );
51
add_action( 'wpinv_status_wpi-onhold_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification' );
52
53
// Failed invoice email
54
add_action( 'wpinv_status_wpi-pending_to_wpi-failed_notification', 'wpinv_failed_invoice_notification' );
55
add_action( 'wpinv_status_wpi-onhold_to_wpi-failed_notification', 'wpinv_failed_invoice_notification' );
56
57
// On hold invoice email
58
add_action( 'wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification' );
59
add_action( 'wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification' );
60
61
// Processing invoice email
62
add_action( 'wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_processing_invoice_notification' );
63
64
// Paid invoice email
65
add_action( 'wpinv_status_publish_notification', 'wpinv_completed_invoice_notification' );
66
67
// Refunded invoice email
68
add_action( 'wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification' );
69
add_action( 'wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification' );
70
add_action( 'wpinv_status_publish_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification' );
71
add_action( 'wpinv_status_wpi-processing_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification' );
72
73
// Invoice note
74
add_action( 'wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification' );
75
76
add_action( 'wpinv_email_header', 'wpinv_email_header' );
77
add_action( 'wpinv_email_footer', 'wpinv_email_footer' );
78
add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 );
79
add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 );
80
add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 );
81
82
function wpinv_send_transactional_email() {
83
    $args       = func_get_args();
84
    $function   = current_filter() . '_notification';
85
    do_action_ref_array( $function, $args );
86
}
87
88
function wpinv_new_invoice_notification( $invoice_id, $new_status = '' ) {
0 ignored issues
show
Unused Code introduced by
The parameter $new_status is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

88
function wpinv_new_invoice_notification( $invoice_id, /** @scrutinizer ignore-unused */ $new_status = '' ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
89
    $email_type = 'new_invoice';
90
    if ( !wpinv_email_is_enabled( $email_type ) ) {
91
        return false;
92
    }
93
94
    $invoice = wpinv_get_invoice( $invoice_id );
95
    if ( empty( $invoice ) ) {
96
        return false;
97
    }
98
99
    if ( !("wpi_invoice" === $invoice->post_type) ) {
0 ignored issues
show
Bug Best Practice introduced by
The property post_type does not exist on WPInv_Invoice. Since you implemented __get, consider adding a @property annotation.
Loading history...
100
        return false;
101
    }
102
103
    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
104
    if ( !is_email( $recipient ) ) {
0 ignored issues
show
Bug introduced by
It seems like $recipient can also be of type array; however, parameter $email of is_email() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

104
    if ( !is_email( /** @scrutinizer ignore-type */ $recipient ) ) {
Loading history...
105
        return false;
106
    }
107
108
    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type, true );
109
110
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
111
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
112
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
113
    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
114
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
115
116
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
117
            'invoice'       => $invoice,
118
            'email_type'    => $email_type,
119
            'email_heading' => $email_heading,
120
            'sent_to_admin' => true,
121
            'plain_text'    => false,
122
            'message_body'  => $message_body,
123
        ) );
124
125
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
126
127
    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type, true );
128
129
    return $sent;
130
}
131
132
function wpinv_cancelled_invoice_notification( $invoice_id, $new_status = '' ) {
0 ignored issues
show
Unused Code introduced by
The parameter $new_status is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

132
function wpinv_cancelled_invoice_notification( $invoice_id, /** @scrutinizer ignore-unused */ $new_status = '' ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
133
    $email_type = 'cancelled_invoice';
134
    if ( !wpinv_email_is_enabled( $email_type ) ) {
135
        return false;
136
    }
137
138
    $invoice = wpinv_get_invoice( $invoice_id );
139
    if ( empty( $invoice ) ) {
140
        return false;
141
    }
142
143
    if ( !("wpi_invoice" === $invoice->post_type) ) {
0 ignored issues
show
Bug Best Practice introduced by
The property post_type does not exist on WPInv_Invoice. Since you implemented __get, consider adding a @property annotation.
Loading history...
144
        return false;
145
    }
146
147
    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
148
    if ( !is_email( $recipient ) ) {
0 ignored issues
show
Bug introduced by
It seems like $recipient can also be of type array; however, parameter $email of is_email() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

148
    if ( !is_email( /** @scrutinizer ignore-type */ $recipient ) ) {
Loading history...
149
        return false;
150
    }
151
152
    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type, true );
153
154
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
155
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
156
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
157
    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
158
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
159
160
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
161
            'invoice'       => $invoice,
162
            'email_type'    => $email_type,
163
            'email_heading' => $email_heading,
164
            'sent_to_admin' => true,
165
            'plain_text'    => false,
166
            'message_body'  => $message_body,
167
        ) );
168
169
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
170
171
    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type, true );
172
173
    return $sent;
174
}
175
176
function wpinv_failed_invoice_notification( $invoice_id, $new_status = '' ) {
0 ignored issues
show
Unused Code introduced by
The parameter $new_status is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

176
function wpinv_failed_invoice_notification( $invoice_id, /** @scrutinizer ignore-unused */ $new_status = '' ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
177
    $email_type = 'failed_invoice';
178
    if ( !wpinv_email_is_enabled( $email_type ) ) {
179
        return false;
180
    }
181
    
182
    $invoice = wpinv_get_invoice( $invoice_id );
183
    if ( empty( $invoice ) ) {
184
        return false;
185
    }
186
187
    if ( !("wpi_invoice" === $invoice->post_type) ) {
0 ignored issues
show
Bug Best Practice introduced by
The property post_type does not exist on WPInv_Invoice. Since you implemented __get, consider adding a @property annotation.
Loading history...
188
        return false;
189
    }
190
191
    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
192
    if ( !is_email( $recipient ) ) {
0 ignored issues
show
Bug introduced by
It seems like $recipient can also be of type array; however, parameter $email of is_email() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

192
    if ( !is_email( /** @scrutinizer ignore-type */ $recipient ) ) {
Loading history...
193
        return false;
194
    }
195
196
    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type, true );
197
198
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
199
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
200
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
201
    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
202
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
203
    
204
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
205
            'invoice'       => $invoice,
206
            'email_type'    => $email_type,
207
            'email_heading' => $email_heading,
208
            'sent_to_admin' => true,
209
            'plain_text'    => false,
210
            'message_body'  => $message_body,
211
        ) );
212
213
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
214
215
    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type, true );
216
217
    return $sent;
218
}
219
220
function wpinv_onhold_invoice_notification( $invoice_id, $new_status = '' ) {
0 ignored issues
show
Unused Code introduced by
The parameter $new_status is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

220
function wpinv_onhold_invoice_notification( $invoice_id, /** @scrutinizer ignore-unused */ $new_status = '' ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
221
    $email_type = 'onhold_invoice';
222
    if ( !wpinv_email_is_enabled( $email_type ) ) {
223
        return false;
224
    }
225
226
    $invoice = wpinv_get_invoice( $invoice_id );
227
    if ( empty( $invoice ) ) {
228
        return false;
229
    }
230
231
    if ( !("wpi_invoice" === $invoice->post_type) ) {
0 ignored issues
show
Bug Best Practice introduced by
The property post_type does not exist on WPInv_Invoice. Since you implemented __get, consider adding a @property annotation.
Loading history...
232
        return false;
233
    }
234
235
    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
236
    $extra          = wpinv_email_get_cc_recipients( $email_type, $invoice_id, $invoice );
237
    if ( !is_email( $recipient ) ) {
238
        return false;
239
    }
240
241
    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
242
243
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
244
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
245
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
246
    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
247
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
248
    
249
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
250
            'invoice'       => $invoice,
251
            'email_type'    => $email_type,
252
            'email_heading' => $email_heading,
253
            'sent_to_admin' => false,
254
            'plain_text'    => false,
255
            'message_body'  => $message_body,
256
        ) );
257
    
258
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments, $extra );
259
    
260
    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
261
        $recipient  = wpinv_get_admin_email();
262
        $subject    .= ' - ADMIN BCC COPY';
263
        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
264
    }
265
266
    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
267
268
    return $sent;
269
}
270
271
function wpinv_processing_invoice_notification( $invoice_id, $new_status = '' ) {
0 ignored issues
show
Unused Code introduced by
The parameter $new_status is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

271
function wpinv_processing_invoice_notification( $invoice_id, /** @scrutinizer ignore-unused */ $new_status = '' ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
272
    $email_type = 'processing_invoice';
273
    if ( !wpinv_email_is_enabled( $email_type ) ) {
274
        return false;
275
    }
276
277
    $invoice = wpinv_get_invoice( $invoice_id );
278
    if ( empty( $invoice ) ) {
279
        return false;
280
    }
281
282
    if ( !("wpi_invoice" === $invoice->post_type) ) {
0 ignored issues
show
Bug Best Practice introduced by
The property post_type does not exist on WPInv_Invoice. Since you implemented __get, consider adding a @property annotation.
Loading history...
283
        return false;
284
    }
285
286
    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
287
    $extra          = wpinv_email_get_cc_recipients( $email_type, $invoice_id, $invoice );
288
    if ( !is_email( $recipient ) ) {
289
        return false;
290
    }
291
292
    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
293
294
    $search                     = array();
295
    $search['invoice_number']   = '{invoice_number}';
296
    $search['invoice_date']     = '{invoice_date}';
297
    $search['name']             = '{name}';
298
299
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
300
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
301
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
302
    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
303
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
304
    
305
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
306
            'invoice'       => $invoice,
307
            'email_type'    => $email_type,
308
            'email_heading' => $email_heading,
309
            'sent_to_admin' => false,
310
            'plain_text'    => false,
311
            'message_body'  => $message_body,
312
        ) );
313
314
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments, $extra );
315
316
    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
317
        $recipient  = wpinv_get_admin_email();
318
        $subject    .= ' - ADMIN BCC COPY';
319
        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
320
    }
321
322
    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
323
324
    return $sent;
325
}
326
327
function wpinv_completed_invoice_notification( $invoice_id, $new_status = '' ) {
0 ignored issues
show
Unused Code introduced by
The parameter $new_status is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

327
function wpinv_completed_invoice_notification( $invoice_id, /** @scrutinizer ignore-unused */ $new_status = '' ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
328
    $email_type = 'completed_invoice';
329
    if ( !wpinv_email_is_enabled( $email_type ) ) {
330
        return false;
331
    }
332
333
    $invoice = wpinv_get_invoice( $invoice_id );
334
    if ( empty( $invoice ) ) {
335
        return false;
336
    }
337
338
    if ( !("wpi_invoice" === $invoice->post_type) ) {
0 ignored issues
show
Bug Best Practice introduced by
The property post_type does not exist on WPInv_Invoice. Since you implemented __get, consider adding a @property annotation.
Loading history...
339
        return false;
340
    }
341
342
    if($invoice->is_renewal() && wpinv_email_is_enabled( 'completed_invoice_renewal' )){
343
        return false;
344
    }
345
346
    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
347
    $extra          = wpinv_email_get_cc_recipients( $email_type, $invoice_id, $invoice );
348
    if ( !is_email( $recipient ) ) {
349
        return false;
350
    }
351
352
    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
353
354
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
355
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
356
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
357
    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
358
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
359
360
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
361
            'invoice'       => $invoice,
362
            'email_type'    => $email_type,
363
            'email_heading' => $email_heading,
364
            'sent_to_admin' => false,
365
            'plain_text'    => false,
366
            'message_body'  => $message_body,
367
        ) );
368
369
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments, $extra );
370
371
    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
372
        $recipient  = wpinv_get_admin_email();
373
        $subject    .= ' - ADMIN BCC COPY';
374
        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
375
    }
376
377
    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
378
379
    return $sent;
380
}
381
382
function wpinv_fully_refunded_notification( $invoice_id, $new_status = '' ) {
0 ignored issues
show
Unused Code introduced by
The parameter $new_status is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

382
function wpinv_fully_refunded_notification( $invoice_id, /** @scrutinizer ignore-unused */ $new_status = '' ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
383
    $email_type = 'refunded_invoice';
384
    if ( !wpinv_email_is_enabled( $email_type ) ) {
385
        return false;
386
    }
387
388
    $invoice = wpinv_get_invoice( $invoice_id );
389
    if ( empty( $invoice ) ) {
390
        return false;
391
    }
392
393
    if ( !("wpi_invoice" === $invoice->post_type) ) {
0 ignored issues
show
Bug Best Practice introduced by
The property post_type does not exist on WPInv_Invoice. Since you implemented __get, consider adding a @property annotation.
Loading history...
394
        return false;
395
    }
396
397
    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
398
    $extra          = wpinv_email_get_cc_recipients( $email_type, $invoice_id, $invoice );
399
    if ( !is_email( $recipient ) ) {
400
        return false;
401
    }
402
403
    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
404
405
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
406
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
407
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
408
    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
409
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
410
411
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
412
            'invoice'           => $invoice,
413
            'email_type'        => $email_type,
414
            'email_heading'     => $email_heading,
415
            'sent_to_admin'     => false,
416
            'plain_text'        => false,
417
            'partial_refund'    => false,
418
            'message_body'      => $message_body,
419
        ) );
420
421
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments, $extra );
422
423
    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
424
        $recipient  = wpinv_get_admin_email();
425
        $subject    .= ' - ADMIN BCC COPY';
426
        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
427
    }
428
429
    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
430
431
    return $sent;
432
}
433
434
function wpinv_partially_refunded_notification( $invoice_id, $new_status = '' ) {
0 ignored issues
show
Unused Code introduced by
The parameter $new_status is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

434
function wpinv_partially_refunded_notification( $invoice_id, /** @scrutinizer ignore-unused */ $new_status = '' ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
435
    $email_type = 'refunded_invoice';
436
    if ( !wpinv_email_is_enabled( $email_type ) ) {
437
        return false;
438
    }
439
440
    $invoice = wpinv_get_invoice( $invoice_id );
441
    if ( empty( $invoice ) ) {
442
        return false;
443
    }
444
445
    if ( !("wpi_invoice" === $invoice->post_type) ) {
0 ignored issues
show
Bug Best Practice introduced by
The property post_type does not exist on WPInv_Invoice. Since you implemented __get, consider adding a @property annotation.
Loading history...
446
        return false;
447
    }
448
449
    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
450
    $extra          = wpinv_email_get_cc_recipients( $email_type, $invoice_id, $invoice );
451
    if ( !is_email( $recipient ) ) {
452
        return false;
453
    }
454
455
    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
456
457
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
458
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
459
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
460
    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
461
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
462
463
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
464
            'invoice'           => $invoice,
465
            'email_type'        => $email_type,
466
            'email_heading'     => $email_heading,
467
            'sent_to_admin'     => false,
468
            'plain_text'        => false,
469
            'partial_refund'    => true,
470
            'message_body'      => $message_body,
471
        ) );
472
473
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments, $extra );
474
475
    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
476
        $recipient  = wpinv_get_admin_email();
477
        $subject    .= ' - ADMIN BCC COPY';
478
        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
479
    }
480
481
    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
482
483
    return $sent;
484
}
485
486
function wpinv_new_invoice_note_notification( $invoice_id, $new_status = '' ) {
0 ignored issues
show
Unused Code introduced by
The parameter $invoice_id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

486
function wpinv_new_invoice_note_notification( /** @scrutinizer ignore-unused */ $invoice_id, $new_status = '' ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $new_status is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

486
function wpinv_new_invoice_note_notification( $invoice_id, /** @scrutinizer ignore-unused */ $new_status = '' ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
487
}
488
489
function wpinv_user_invoice_notification( $invoice_id ) {
490
    $email_type = 'user_invoice';
491
    if ( !wpinv_email_is_enabled( $email_type ) ) {
492
        return -1;
493
    }
494
495
    $invoice = wpinv_get_invoice( $invoice_id );
496
    if ( empty( $invoice ) ) {
497
        return false;
498
    }
499
500
    if ( !("wpi_invoice" === $invoice->post_type) ) {
0 ignored issues
show
Bug Best Practice introduced by
The property post_type does not exist on WPInv_Invoice. Since you implemented __get, consider adding a @property annotation.
Loading history...
501
        return false;
502
    }
503
504
    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
505
    $extra          = wpinv_email_get_cc_recipients( $email_type, $invoice_id, $invoice );
506
    if ( !is_email( $recipient ) ) {
507
        return false;
508
    }
509
510
    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
511
512
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
513
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
514
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
515
    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
516
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
517
    
518
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
519
            'invoice'       => $invoice,
520
            'email_type'    => $email_type,
521
            'email_heading' => $email_heading,
522
            'sent_to_admin' => false,
523
            'plain_text'    => false,
524
            'message_body'  => $message_body,
525
        ) );
526
527
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments, $extra );
528
529
    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
530
        $recipient  = wpinv_get_admin_email();
531
        $subject    .= ' - ADMIN BCC COPY';
532
        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
533
    }
534
535
    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
536
537
    if ( $sent ) {
0 ignored issues
show
introduced by
The condition $sent is always true.
Loading history...
538
        $note = __( 'Invoice has been emailed to the user.', 'invoicing' );
539
    } else {
540
        $note = __( 'Fail to send invoice to the user!', 'invoicing' );
541
    }
542
543
    $invoice->add_note( $note, '', '', true ); // Add system note.
544
545
    return $sent;
546
}
547
548
function wpinv_user_note_notification( $invoice_id, $args = array() ) {
549
    $email_type = 'user_note';
550
    if ( !wpinv_email_is_enabled( $email_type ) ) {
551
        return false;
552
    }
553
554
    $invoice = wpinv_get_invoice( $invoice_id );
555
    if ( empty( $invoice ) ) {
556
        return false;
557
    }
558
559
    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
560
    $extra          = wpinv_email_get_cc_recipients( $email_type, $invoice_id, $invoice );
561
    if ( !is_email( $recipient ) ) {
562
        return false;
563
    }
564
565
    $defaults = array(
566
        'user_note' => ''
567
    );
568
569
    $args = wp_parse_args( $args, $defaults );
570
571
    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
572
573
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
574
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
575
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
576
    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
577
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
578
579
    $message_body   = str_replace( '{customer_note}', $args['user_note'], $message_body );
580
581
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
582
            'invoice'       => $invoice,
583
            'email_type'    => $email_type,
584
            'email_heading' => $email_heading,
585
            'sent_to_admin' => false,
586
            'plain_text'    => false,
587
            'message_body'  => $message_body,
588
            'customer_note' => $args['user_note']
589
        ) );
590
591
    $content        = wpinv_email_format_text( $content, $invoice );
592
593
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments, $extra );
594
595
    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
596
597
    return $sent;
598
}
599
600
function wpinv_mail_get_from_address() {
601
    $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) );
602
    return sanitize_email( $from_address );
0 ignored issues
show
Bug introduced by
It seems like $from_address can also be of type array; however, parameter $email of sanitize_email() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

602
    return sanitize_email( /** @scrutinizer ignore-type */ $from_address );
Loading history...
603
}
604
605
function wpinv_mail_get_from_name() {
606
    $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name' ) );
607
    return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES );
0 ignored issues
show
Bug introduced by
It seems like $from_name can also be of type array; however, parameter $text of esc_html() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

607
    return wp_specialchars_decode( esc_html( /** @scrutinizer ignore-type */ $from_name ), ENT_QUOTES );
Loading history...
608
}
609
610
function wpinv_mail_admin_bcc_active( $mail_type = '' ) {
611
    $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) );
612
    return ( $active ? true : false );
613
}
614
    
615
function wpinv_mail_get_content_type(  $content_type = 'text/html', $email_type = 'html' ) {
0 ignored issues
show
Unused Code introduced by
The parameter $content_type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

615
function wpinv_mail_get_content_type(  /** @scrutinizer ignore-unused */ $content_type = 'text/html', $email_type = 'html' ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
616
    $email_type = apply_filters( 'wpinv_mail_content_type', $email_type );
617
618
    switch ( $email_type ) {
619
        case 'html' :
620
            $content_type = 'text/html';
621
            break;
622
        case 'multipart' :
623
            $content_type = 'multipart/alternative';
624
            break;
625
        default :
626
            $content_type = 'text/plain';
627
            break;
628
    }
629
630
    return $content_type;
631
}
632
    
633
function wpinv_mail_send( $to, $subject, $message, $headers, $attachments, $cc = array() ) {
634
    add_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
635
    add_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
636
    add_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
637
638
    $message = wpinv_email_style_body( $message );
639
    $message = apply_filters( 'wpinv_mail_content', $message );
640
641
    if ( ! empty( $cc ) && is_array( $cc ) ) {
642
        if ( ! is_array( $to ) ) {
643
            $to = array( $to );
644
        }
645
646
        $to = array_unique( array_merge( $to, $cc ) );
647
    }
648
649
    $sent  = wp_mail( $to, $subject, $message, $headers, $attachments );
650
651
    if ( !$sent ) {
652
        $log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), ( is_array( $to ) ? implode( ', ', $to ) : $to ), $subject );
653
        wpinv_error_log( $log_message, __( "Email from Invoicing plugin failed to send", 'invoicing' ), __FILE__, __LINE__ );
654
    }
655
656
    remove_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
657
    remove_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
658
    remove_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
659
660
    return $sent;
661
}
662
    
663
function wpinv_get_emails() {
664
    $overdue_days_options       = array();
665
    $overdue_days_options[0]    = __( 'On the Due Date', 'invoicing' );
666
    $overdue_days_options[1]    = __( '1 day after Due Date', 'invoicing' );
667
668
    for ( $i = 2; $i <= 10; $i++ ) {
669
        $overdue_days_options[$i]   = wp_sprintf( __( '%d days after Due Date', 'invoicing' ), $i );
670
    }
671
672
    // Default, built-in gateways
673
    $emails = array(
674
            'new_invoice' => array(
675
            'email_new_invoice_header' => array(
676
                'id'   => 'email_new_invoice_header',
677
                'name' => '<h3>' . __( 'New Invoice', 'invoicing' ) . '</h3>',
678
                'desc' => __( 'New invoice emails are sent to admin when a new invoice is received.', 'invoicing' ),
679
                'type' => 'header',
680
            ),
681
            'email_new_invoice_active' => array(
682
                'id'   => 'email_new_invoice_active',
683
                'name' => __( 'Enable/Disable', 'invoicing' ),
684
                'desc' => __( 'Enable this email notification', 'invoicing' ),
685
                'type' => 'checkbox',
686
                'std'  => 1
687
            ),
688
            'email_new_invoice_subject' => array(
689
                'id'   => 'email_new_invoice_subject',
690
                'name' => __( 'Subject', 'invoicing' ),
691
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
692
                'type' => 'text',
693
                'std'  => __( '[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing' ),
694
                'size' => 'large'
695
            ),
696
            'email_new_invoice_heading' => array(
697
                'id'   => 'email_new_invoice_heading',
698
                'name' => __( 'Email Heading', 'invoicing' ),
699
                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
700
                'type' => 'text',
701
                'std'  => __( 'New payment invoice', 'invoicing' ),
702
                'size' => 'large'
703
            ),
704
            'email_new_invoice_body' => array(
705
                'id'   => 'email_new_invoice_body',
706
                'name' => __( 'Email Content', 'invoicing' ),
707
                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
708
                'type' => 'rich_editor',
709
                'std'  => __( '<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing' ),
710
                'class' => 'large',
711
                'size' => '10'
712
            ),
713
        ),
714
        'cancelled_invoice' => array(
715
            'email_cancelled_invoice_header' => array(
716
                'id'   => 'email_cancelled_invoice_header',
717
                'name' => '<h3>' . __( 'Cancelled Invoice', 'invoicing' ) . '</h3>',
718
                'desc' => __( 'Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing' ),
719
                'type' => 'header',
720
            ),
721
            'email_cancelled_invoice_active' => array(
722
                'id'   => 'email_cancelled_invoice_active',
723
                'name' => __( 'Enable/Disable', 'invoicing' ),
724
                'desc' => __( 'Enable this email notification', 'invoicing' ),
725
                'type' => 'checkbox',
726
                'std'  => 1
727
            ),
728
            'email_cancelled_invoice_subject' => array(
729
                'id'   => 'email_cancelled_invoice_subject',
730
                'name' => __( 'Subject', 'invoicing' ),
731
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
732
                'type' => 'text',
733
                'std'  => __( '[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing' ),
734
                'size' => 'large'
735
            ),
736
            'email_cancelled_invoice_heading' => array(
737
                'id'   => 'email_cancelled_invoice_heading',
738
                'name' => __( 'Email Heading', 'invoicing' ),
739
                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
740
                'type' => 'text',
741
                'std'  => __( 'Cancelled invoice', 'invoicing' ),
742
                'size' => 'large'
743
            ),
744
            'email_cancelled_invoice_body' => array(
745
                'id'   => 'email_cancelled_invoice_body',
746
                'name' => __( 'Email Content', 'invoicing' ),
747
                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
748
                'type' => 'rich_editor',
749
                'std'  => __( '<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing' ),
750
                'class' => 'large',
751
                'size' => '10'
752
            ),
753
        ),
754
        'failed_invoice' => array(
755
            'email_failed_invoice_header' => array(
756
                'id'   => 'email_failed_invoice_header',
757
                'name' => '<h3>' . __( 'Failed Invoice', 'invoicing' ) . '</h3>',
758
                'desc' => __( 'Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing' ),
759
                'type' => 'header',
760
            ),
761
            'email_failed_invoice_active' => array(
762
                'id'   => 'email_failed_invoice_active',
763
                'name' => __( 'Enable/Disable', 'invoicing' ),
764
                'desc' => __( 'Enable this email notification', 'invoicing' ),
765
                'type' => 'checkbox',
766
                'std'  => 1
767
            ),
768
            'email_failed_invoice_subject' => array(
769
                'id'   => 'email_failed_invoice_subject',
770
                'name' => __( 'Subject', 'invoicing' ),
771
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
772
                'type' => 'text',
773
                'std'  => __( '[{site_title}] Failed invoice ({invoice_number})', 'invoicing' ),
774
                'size' => 'large'
775
            ),
776
            'email_failed_invoice_heading' => array(
777
                'id'   => 'email_failed_invoice_heading',
778
                'name' => __( 'Email Heading', 'invoicing' ),
779
                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
780
                'type' => 'text',
781
                'std'  => __( 'Failed invoice', 'invoicing' ),
782
                'size' => 'large'
783
            ),
784
            'email_failed_invoice_body' => array(
785
                'id'   => 'email_failed_invoice_body',
786
                'name' => __( 'Email Content', 'invoicing' ),
787
                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
788
                'type' => 'rich_editor',
789
                'std'  => __( '<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing' ),
790
                'class' => 'large',
791
                'size' => '10'
792
            ),
793
        ),
794
        'onhold_invoice' => array(
795
            'email_onhold_invoice_header' => array(
796
                'id'   => 'email_onhold_invoice_header',
797
                'name' => '<h3>' . __( 'On Hold Invoice', 'invoicing' ) . '</h3>',
798
                'desc' => __( 'This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing' ),
799
                'type' => 'header',
800
            ),
801
            'email_onhold_invoice_active' => array(
802
                'id'   => 'email_onhold_invoice_active',
803
                'name' => __( 'Enable/Disable', 'invoicing' ),
804
                'desc' => __( 'Enable this email notification', 'invoicing' ),
805
                'type' => 'checkbox',
806
                'std'  => 1
807
            ),
808
            'email_onhold_invoice_subject' => array(
809
                'id'   => 'email_onhold_invoice_subject',
810
                'name' => __( 'Subject', 'invoicing' ),
811
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
812
                'type' => 'text',
813
                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
814
                'size' => 'large'
815
            ),
816
            'email_onhold_invoice_heading' => array(
817
                'id'   => 'email_onhold_invoice_heading',
818
                'name' => __( 'Email Heading', 'invoicing' ),
819
                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
820
                'type' => 'text',
821
                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
822
                'size' => 'large'
823
            ),
824
            'email_onhold_invoice_admin_bcc' => array(
825
                'id'   => 'email_onhold_invoice_admin_bcc',
826
                'name' => __( 'Enable Admin BCC', 'invoicing' ),
827
                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
828
                'type' => 'checkbox',
829
                'std'  => 1
830
            ),
831
            'email_onhold_invoice_body' => array(
832
                'id'   => 'email_onhold_invoice_body',
833
                'name' => __( 'Email Content', 'invoicing' ),
834
                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
835
                'type' => 'rich_editor',
836
                'std'  => __( '<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing' ),
837
                'class' => 'large',
838
                'size' => '10'
839
            ),
840
        ),
841
        'processing_invoice' => array(
842
            'email_processing_invoice_header' => array(
843
                'id'   => 'email_processing_invoice_header',
844
                'name' => '<h3>' . __( 'Processing Invoice', 'invoicing' ) . '</h3>',
845
                'desc' => __( 'This is an invoice notification sent to users containing invoice details after payment.', 'invoicing' ),
846
                'type' => 'header',
847
            ),
848
            'email_processing_invoice_active' => array(
849
                'id'   => 'email_processing_invoice_active',
850
                'name' => __( 'Enable/Disable', 'invoicing' ),
851
                'desc' => __( 'Enable this email notification', 'invoicing' ),
852
                'type' => 'checkbox',
853
                'std'  => 1
854
            ),
855
            'email_processing_invoice_subject' => array(
856
                'id'   => 'email_processing_invoice_subject',
857
                'name' => __( 'Subject', 'invoicing' ),
858
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
859
                'type' => 'text',
860
                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
861
                'size' => 'large'
862
            ),
863
            'email_processing_invoice_heading' => array(
864
                'id'   => 'email_processing_invoice_heading',
865
                'name' => __( 'Email Heading', 'invoicing' ),
866
                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
867
                'type' => 'text',
868
                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
869
                'size' => 'large'
870
            ),
871
            'email_processing_invoice_admin_bcc' => array(
872
                'id'   => 'email_processing_invoice_admin_bcc',
873
                'name' => __( 'Enable Admin BCC', 'invoicing' ),
874
                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
875
                'type' => 'checkbox',
876
                'std'  => 1
877
            ),
878
            'email_processing_invoice_body' => array(
879
                'id'   => 'email_processing_invoice_body',
880
                'name' => __( 'Email Content', 'invoicing' ),
881
                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
882
                'type' => 'rich_editor',
883
                'std'  => __( '<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing' ),
884
                'class' => 'large',
885
                'size' => '10'
886
            ),
887
        ),
888
        'completed_invoice' => array(
889
            'email_completed_invoice_header' => array(
890
                'id'   => 'email_completed_invoice_header',
891
                'name' => '<h3>' . __( 'Paid Invoice', 'invoicing' ) . '</h3>',
892
                'desc' => __( 'Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing' ),
893
                'type' => 'header',
894
            ),
895
            'email_completed_invoice_active' => array(
896
                'id'   => 'email_completed_invoice_active',
897
                'name' => __( 'Enable/Disable', 'invoicing' ),
898
                'desc' => __( 'Enable this email notification', 'invoicing' ),
899
                'type' => 'checkbox',
900
                'std'  => 1
901
            ),
902
            'email_completed_invoice_renewal_active' => array(
903
                'id'   => 'email_completed_invoice_renewal_active',
904
                'name' => __( 'Enable renewal notification', 'invoicing' ),
905
                'desc' => __( 'Enable renewal invoice email notification. This notification will be sent on renewal.', 'invoicing' ),
906
                'type' => 'checkbox',
907
                'std'  => 0
908
            ),
909
            'email_completed_invoice_subject' => array(
910
                'id'   => 'email_completed_invoice_subject',
911
                'name' => __( 'Subject', 'invoicing' ),
912
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
913
                'type' => 'text',
914
                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing' ),
915
                'size' => 'large'
916
            ),
917
            'email_completed_invoice_heading' => array(
918
                'id'   => 'email_completed_invoice_heading',
919
                'name' => __( 'Email Heading', 'invoicing' ),
920
                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
921
                'type' => 'text',
922
                'std'  => __( 'Your invoice has been paid', 'invoicing' ),
923
                'size' => 'large'
924
            ),
925
            'email_completed_invoice_admin_bcc' => array(
926
                'id'   => 'email_completed_invoice_admin_bcc',
927
                'name' => __( 'Enable Admin BCC', 'invoicing' ),
928
                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
929
                'type' => 'checkbox',
930
            ),
931
            'email_completed_invoice_body' => array(
932
                'id'   => 'email_completed_invoice_body',
933
                'name' => __( 'Email Content', 'invoicing' ),
934
                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
935
                'type' => 'rich_editor',
936
                'std'  => __( '<p>Hi {name},</p><p>Your recent invoice on {site_title} has been paid.</p>', 'invoicing' ),
937
                'class' => 'large',
938
                'size' => '10'
939
            ),
940
            'std'  => 1
941
        ),
942
        'refunded_invoice' => array(
943
            'email_refunded_invoice_header' => array(
944
                'id'   => 'email_refunded_invoice_header',
945
                'name' => '<h3>' . __( 'Refunded Invoice', 'invoicing' ) . '</h3>',
946
                'desc' => __( 'Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing' ),
947
                'type' => 'header',
948
            ),
949
            'email_refunded_invoice_active' => array(
950
                'id'   => 'email_refunded_invoice_active',
951
                'name' => __( 'Enable/Disable', 'invoicing' ),
952
                'desc' => __( 'Enable this email notification', 'invoicing' ),
953
                'type' => 'checkbox',
954
                'std'  => 1
955
            ),
956
            'email_refunded_invoice_subject' => array(
957
                'id'   => 'email_refunded_invoice_subject',
958
                'name' => __( 'Subject', 'invoicing' ),
959
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
960
                'type' => 'text',
961
                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing' ),
962
                'size' => 'large'
963
            ),
964
            'email_refunded_invoice_heading' => array(
965
                'id'   => 'email_refunded_invoice_heading',
966
                'name' => __( 'Email Heading', 'invoicing' ),
967
                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
968
                'type' => 'text',
969
                'std'  => __( 'Your invoice has been refunded', 'invoicing' ),
970
                'size' => 'large'
971
            ),
972
            'email_refunded_invoice_admin_bcc' => array(
973
                'id'   => 'email_refunded_invoice_admin_bcc',
974
                'name' => __( 'Enable Admin BCC', 'invoicing' ),
975
                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
976
                'type' => 'checkbox',
977
                'std'  => 1
978
            ),
979
            'email_refunded_invoice_body' => array(
980
                'id'   => 'email_refunded_invoice_body',
981
                'name' => __( 'Email Content', 'invoicing' ),
982
                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
983
                'type' => 'rich_editor',
984
                'std'  => __( '<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing' ),
985
                'class' => 'large',
986
                'size' => '10'
987
            ),
988
        ),
989
        'user_invoice' => array(
990
            'email_user_invoice_header' => array(
991
                'id'   => 'email_user_invoice_header',
992
                'name' => '<h3>' . __( 'Customer Invoice', 'invoicing' ) . '</h3>',
993
                'desc' => __( 'Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing' ),
994
                'type' => 'header',
995
            ),
996
            'email_user_invoice_active' => array(
997
                'id'   => 'email_user_invoice_active',
998
                'name' => __( 'Enable/Disable', 'invoicing' ),
999
                'desc' => __( 'Enable this email notification', 'invoicing' ),
1000
                'type' => 'checkbox',
1001
                'std'  => 1
1002
            ),
1003
            'email_user_invoice_subject' => array(
1004
                'id'   => 'email_user_invoice_subject',
1005
                'name' => __( 'Subject', 'invoicing' ),
1006
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
1007
                'type' => 'text',
1008
                'std'  => __( '[{site_title}] Your invoice from {invoice_date}', 'invoicing' ),
1009
                'size' => 'large'
1010
            ),
1011
            'email_user_invoice_heading' => array(
1012
                'id'   => 'email_user_invoice_heading',
1013
                'name' => __( 'Email Heading', 'invoicing' ),
1014
                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
1015
                'type' => 'text',
1016
                'std'  => __( 'Your invoice {invoice_number} details', 'invoicing' ),
1017
                'size' => 'large'
1018
            ),
1019
            'email_user_invoice_admin_bcc' => array(
1020
                'id'   => 'email_user_invoice_admin_bcc',
1021
                'name' => __( 'Enable Admin BCC', 'invoicing' ),
1022
                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
1023
                'type' => 'checkbox',
1024
                'std'  => 1
1025
            ),
1026
            'email_user_invoice_body' => array(
1027
                'id'   => 'email_user_invoice_body',
1028
                'name' => __( 'Email Content', 'invoicing' ),
1029
                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
1030
                'type' => 'rich_editor',
1031
                'std'  => __( '<p>Hi {name},</p><p>An invoice has been created for you on {site_title}. To view / pay for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ),
1032
                'class' => 'large',
1033
                'size' => '10'
1034
            ),
1035
        ),
1036
        'user_note' => array(
1037
            'email_user_note_header' => array(
1038
                'id'   => 'email_user_note_header',
1039
                'name' => '<h3>' . __( 'Customer Note', 'invoicing' ) . '</h3>',
1040
                'desc' => __( 'Customer note emails are sent when you add a note to an invoice/quote.', 'invoicing' ),
1041
                'type' => 'header',
1042
            ),
1043
            'email_user_note_active' => array(
1044
                'id'   => 'email_user_note_active',
1045
                'name' => __( 'Enable/Disable', 'invoicing' ),
1046
                'desc' => __( 'Enable this email notification', 'invoicing' ),
1047
                'type' => 'checkbox',
1048
                'std'  => 1
1049
            ),
1050
            'email_user_note_subject' => array(
1051
                'id'   => 'email_user_note_subject',
1052
                'name' => __( 'Subject', 'invoicing' ),
1053
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
1054
                'type' => 'text',
1055
                'std'  => __( '[{site_title}] Note added to your {invoice_label} #{invoice_number} from {invoice_date}', 'invoicing' ),
1056
                'size' => 'large'
1057
            ),
1058
            'email_user_note_heading' => array(
1059
                'id'   => 'email_user_note_heading',
1060
                'name' => __( 'Email Heading', 'invoicing' ),
1061
                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
1062
                'type' => 'text',
1063
                'std'  => __( 'A note has been added to your {invoice_label}', 'invoicing' ),
1064
                'size' => 'large'
1065
            ),
1066
            'email_user_note_body' => array(
1067
                'id'   => 'email_user_note_body',
1068
                'name' => __( 'Email Content', 'invoicing' ),
1069
                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
1070
                'type' => 'rich_editor',
1071
                'std'  => __( '<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing' ),
1072
                'class' => 'large',
1073
                'size' => '10'
1074
            ),
1075
        ),
1076
1077
        'pre_payment' => array(
1078
            'email_pre_payment_header' => array(
1079
                'id'   => 'email_pre_payment_header',
1080
                'name' => '<h3>' . __( 'Renewal Reminder', 'invoicing' ) . '</h3>',
1081
                'desc' => __( 'Renewal reminder emails are sent to user automatically.', 'invoicing' ),
1082
                'type' => 'header',
1083
            ),
1084
            'email_pre_payment_active' => array(
1085
                'id'   => 'email_pre_payment_active',
1086
                'name' => __( 'Enable/Disable', 'invoicing' ),
1087
                'desc' => __( 'Enable this email notification', 'invoicing' ),
1088
                'type' => 'checkbox',
1089
                'std'  => 1
1090
            ),
1091
            'email_pre_payment_reminder_days' => array(
1092
                'id'            => 'email_pre_payment_reminder_days',
1093
                'name'          => __( 'When to Send', 'invoicing' ),
1094
                'desc'          => __( 'Enter a comma separated list of days before renewal when this email should be sent.', 'invoicing' ),
1095
                'default'       => '',
1096
                'type'          => 'text',
1097
                'std'           => '1,5,10',
1098
            ),
1099
            'email_pre_payment_subject' => array(
1100
                'id'   => 'email_pre_payment_subject',
1101
                'name' => __( 'Subject', 'invoicing' ),
1102
                'desc' => __( 'Enter the subject line for the email.', 'invoicing' ),
1103
                'type' => 'text',
1104
                'std'  => __( '[{site_title}] Renewal Reminder', 'invoicing' ),
1105
                'size' => 'large'
1106
            ),
1107
            'email_pre_payment_heading' => array(
1108
                'id'   => 'email_pre_payment_heading',
1109
                'name' => __( 'Email Heading', 'invoicing' ),
1110
                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
1111
                'type' => 'text',
1112
                'std'  => __( 'Upcoming renewal reminder', 'invoicing' ),
1113
                'size' => 'large'
1114
            ),
1115
            'email_pre_payment_admin_bcc' => array(
1116
                'id'   => 'email_pre_payment_admin_bcc',
1117
                'name' => __( 'Enable Admin BCC', 'invoicing' ),
1118
                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
1119
                'type' => 'checkbox',
1120
                'std'  => 1
1121
            ),
1122
            'email_pre_payment_body' => array(
1123
                'id'   => 'email_pre_payment_body',
1124
                'name' => __( 'Email Content', 'invoicing' ),
1125
                'desc' => __( 'The content of the email.', 'invoicing' ),
1126
                'type' => 'rich_editor',
1127
                'std'  => __( '<p>Hi {full_name},</p><p>Your subscription for invoice <a href="{invoice_link}">#{invoice_number}</a> will renew on {subscription_renewal_date}.</p>', 'invoicing' ),
1128
                'class' => 'large',
1129
                'size'  => 10,
1130
            ),
1131
        ),
1132
1133
        'overdue' => array(
1134
            'email_overdue_header' => array(
1135
                'id'   => 'email_overdue_header',
1136
                'name' => '<h3>' . __( 'Payment Reminder', 'invoicing' ) . '</h3>',
1137
                'desc' => __( 'Payment reminder emails are sent to user automatically.', 'invoicing' ),
1138
                'type' => 'header',
1139
            ),
1140
            'email_overdue_active' => array(
1141
                'id'   => 'email_overdue_active',
1142
                'name' => __( 'Enable/Disable', 'invoicing' ),
1143
                'desc' => __( 'Enable this email notification', 'invoicing' ),
1144
                'type' => 'checkbox',
1145
                'std'  => 1
1146
            ),
1147
            'email_due_reminder_days' => array(
1148
                'id'        => 'email_due_reminder_days',
1149
                'name'      => __( 'When to Send', 'invoicing' ),
1150
                'desc'      => __( 'Check when you would like payment reminders sent out.', 'invoicing' ),
1151
                'default'   => '',
1152
                'type'      => 'multicheck',
1153
                'options'   => $overdue_days_options,
1154
            ),
1155
            'email_overdue_subject' => array(
1156
                'id'   => 'email_overdue_subject',
1157
                'name' => __( 'Subject', 'invoicing' ),
1158
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
1159
                'type' => 'text',
1160
                'std'  => __( '[{site_title}] Payment Reminder', 'invoicing' ),
1161
                'size' => 'large'
1162
            ),
1163
            'email_overdue_heading' => array(
1164
                'id'   => 'email_overdue_heading',
1165
                'name' => __( 'Email Heading', 'invoicing' ),
1166
                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
1167
                'type' => 'text',
1168
                'std'  => __( 'Payment reminder for your invoice', 'invoicing' ),
1169
                'size' => 'large'
1170
            ),
1171
            'email_overdue_admin_bcc' => array(
1172
                'id'   => 'email_overdue_admin_bcc',
1173
                'name' => __( 'Enable Admin BCC', 'invoicing' ),
1174
                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
1175
                'type' => 'checkbox',
1176
                'std'  => 1
1177
            ),
1178
            'email_overdue_body' => array(
1179
                'id'   => 'email_overdue_body',
1180
                'name' => __( 'Email Content', 'invoicing' ),
1181
                'desc' => __( 'The content of the email.', 'invoicing' ),
1182
                'type' => 'rich_editor',
1183
                'std'  => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder that your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ),
1184
                'class' => 'large',
1185
                'size'  => 10,
1186
            ),
1187
        ),
1188
    );
1189
1190
    return apply_filters( 'wpinv_get_emails', $emails );
1191
}
1192
1193
function wpinv_settings_emails( $settings = array() ) {
1194
    $emails = wpinv_get_emails();
1195
1196
    if ( !empty( $emails ) ) {
1197
        foreach ( $emails as $key => $email ) {
1198
            $settings[$key] = $email;
1199
        }
1200
    }
1201
1202
    return apply_filters( 'wpinv_settings_get_emails', $settings );
1203
}
1204
add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 );
1205
1206
function wpinv_settings_sections_emails( $settings ) {
1207
    $emails = wpinv_get_emails();
1208
1209
    if (!empty($emails)) {
1210
        foreach  ($emails as $key => $email) {
1211
            $settings[$key] = !empty( $email['email_' . $key . '_header']['name'] ) ? strip_tags( $email['email_' . $key . '_header']['name'] ) : $key;
1212
        }
1213
    }
1214
1215
    return $settings;    
1216
}
1217
add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 );
1218
1219
function wpinv_email_is_enabled( $email_type ) {
1220
    $emails = wpinv_get_emails();
1221
    $enabled = isset( $emails[$email_type] ) && wpinv_get_option( 'email_'. $email_type . '_active', 0 ) ? true : false;
1222
1223
    return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type );
1224
}
1225
1226
function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1227
    switch ( $email_type ) {
1228
        case 'new_invoice':
1229
        case 'cancelled_invoice':
1230
        case 'failed_invoice':
1231
            $recipient  = wpinv_get_admin_email();
1232
        break;
1233
        default:
1234
            $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1235
            $recipient  = !empty( $invoice ) ? $invoice->get_email() : '';
1236
        break;
1237
    }
1238
1239
    return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice );
1240
}
1241
1242
/**
1243
 * Returns invoice CC recipients
1244
 */
1245
function wpinv_email_get_cc_recipients( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1246
    switch ( $email_type ) {
1247
        case 'new_invoice':
1248
        case 'cancelled_invoice':
1249
        case 'failed_invoice':
1250
            return array();
1251
        break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1252
        default:
1253
            $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1254
            $recipient  = empty( $invoice ) ? '' : get_post_meta( $invoice->ID, 'wpinv_email_cc', true );
1255
            if ( empty( $recipient ) ) {
1256
                return array();
1257
            }
1258
            return  array_filter( array_map( 'trim', explode( ',', $recipient ) ) );
1259
        break;
1260
    }
1261
1262
}
1263
1264
function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1265
    $subject    = wpinv_get_option( 'email_' . $email_type . '_subject' );
1266
    $subject    = __( $subject, 'invoicing' );
0 ignored issues
show
Bug introduced by
$subject of type array is incompatible with the type string expected by parameter $text of __(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1266
    $subject    = __( /** @scrutinizer ignore-type */ $subject, 'invoicing' );
Loading history...
1267
1268
    $subject    = wpinv_email_format_text( $subject, $invoice );
1269
1270
    return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice );
1271
}
1272
1273
function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1274
    $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' );
1275
    $email_heading = __( $email_heading, 'invoicing' );
0 ignored issues
show
Bug introduced by
$email_heading of type array is incompatible with the type string expected by parameter $text of __(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1275
    $email_heading = __( /** @scrutinizer ignore-type */ $email_heading, 'invoicing' );
Loading history...
1276
1277
    $email_heading = wpinv_email_format_text( $email_heading, $invoice );
1278
1279
    return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice );
1280
}
1281
1282
function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1283
    $content    = wpinv_get_option( 'email_' . $email_type . '_body' );
1284
    $content    = __( $content, 'invoicing' );
0 ignored issues
show
Bug introduced by
$content of type array is incompatible with the type string expected by parameter $text of __(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1284
    $content    = __( /** @scrutinizer ignore-type */ $content, 'invoicing' );
Loading history...
1285
1286
    $content    = wpinv_email_format_text( $content, $invoice );
1287
1288
    return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice );
1289
}
1290
1291
function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1292
    $from_name = wpinv_mail_get_from_address();
1293
    $from_email = wpinv_mail_get_from_address();
1294
    
1295
    $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1296
    
1297
    $headers    = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n";
1298
    $headers    .= "Reply-To: ". $from_email . "\r\n";
1299
    $headers    .= "Content-Type: " . wpinv_mail_get_content_type() . "\r\n";
1300
    
1301
    return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice );
1302
}
1303
1304
function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1305
    $attachments = array();
1306
    
1307
    return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice );
1308
}
1309
1310
/**
1311
 * Searches for and replaces certain placeholders in an email.
1312
 */
1313
function wpinv_email_format_text( $content, $invoice ) {
1314
1315
    $replace_array = array(
1316
        '{site_title}'      => wpinv_get_blogname(),
1317
        '{date}'            => date_i18n( get_option( 'date_format' ), (int) current_time( 'timestamp' ) ),
0 ignored issues
show
Bug introduced by
It seems like get_option('date_format') can also be of type false; however, parameter $format of date_i18n() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1317
        '{date}'            => date_i18n( /** @scrutinizer ignore-type */ get_option( 'date_format' ), (int) current_time( 'timestamp' ) ),
Loading history...
1318
    );
1319
1320
    $invoice = new WPInv_Invoice( $invoice );
1321
1322
    if ( $invoice->get_id() ) {
1323
1324
        $replace_array = array_merge(
1325
            $replace_array, 
1326
            array(
1327
                '{name}'            => sanitize_text_field( $invoice->get_user_full_name() ),
1328
                '{full_name}'       => sanitize_text_field( $invoice->get_user_full_name() ),
1329
                '{first_name}'      => sanitize_text_field( $invoice->get_first_name() ),
1330
                '{last_name}'       => sanitize_text_field( $invoice->get_last_name() ),
1331
                '{email}'           => sanitize_email( $invoice->get_email() ),
1332
                '{invoice_number}'  => sanitize_text_field( $invoice->get_number() ),
1333
                '{invoice_total}'   => wpinv_price( wpinv_format_amount( $invoice->get_total( true ) ) ),
0 ignored issues
show
Unused Code introduced by
The call to WPInv_Invoice::get_total() has too many arguments starting with true. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1333
                '{invoice_total}'   => wpinv_price( wpinv_format_amount( $invoice->/** @scrutinizer ignore-call */ get_total( true ) ) ),

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1334
                '{invoice_link}'    => esc_url( $invoice->get_view_url() ),
1335
                '{invoice_pay_link}'=> esc_url( $invoice->get_checkout_payment_url() ),
1336
                '{invoice_date}'    => date( get_option( 'date_format' ), strtotime( $invoice->get_date_created(), current_time( 'timestamp' ) ) ),
0 ignored issues
show
Bug introduced by
It seems like get_option('date_format') can also be of type false; however, parameter $format of date() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1336
                '{invoice_date}'    => date( /** @scrutinizer ignore-type */ get_option( 'date_format' ), strtotime( $invoice->get_date_created(), current_time( 'timestamp' ) ) ),
Loading history...
1337
                '{invoice_due_date}'=> date( get_option( 'date_format' ), strtotime( $invoice->get_due_date(), current_time( 'timestamp' ) ) ),
1338
                '{invoice_quote}'   => sanitize_text_field( $invoice->get_type() ),
1339
                '{invoice_label}'   => sanitize_text_field( ucfirst( $invoice->get_type() ) ),
1340
                '{is_was}'          => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
1341
            )
1342
        );
1343
1344
    }
1345
1346
    // Let third party plugins filter the arra.
1347
    $replace_array = apply_filters( 'wpinv_email_format_text', $replace_array, $content, $invoice );
1348
1349
    foreach ( $replace_array as $key => $value ) {
1350
        $content = str_replace( $key, $value, $content );
1351
    }
1352
1353
    return apply_filters( 'wpinv_email_content_replace', $content );
1354
}
1355
1356
function wpinv_email_style_body( $content ) {
1357
    // make sure we only inline CSS for html emails
1358
    if ( in_array( wpinv_mail_get_content_type(), array( 'text/html', 'multipart/alternative' ) ) && class_exists( 'DOMDocument' ) ) {
1359
        ob_start();
1360
        wpinv_get_template( 'emails/wpinv-email-styles.php' );
1361
        $css = apply_filters( 'wpinv_email_styles', ob_get_clean() );
1362
1363
        // apply CSS styles inline for picky email clients
1364
        try {
1365
            $emogrifier = new Emogrifier( $content, $css );
1366
            $content    = $emogrifier->emogrify();
1367
        } catch ( Exception $e ) {
1368
            wpinv_error_log( $e->getMessage(), 'emogrifier' );
1369
        }
1370
    }
1371
    return $content;
1372
}
1373
1374
function wpinv_email_header( $email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1375
    wpinv_get_template( 'emails/wpinv-email-header.php', array( 'email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1376
}
1377
1378
/**
1379
 * Get the email footer.
1380
 */
1381
function wpinv_email_footer( $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1382
    wpinv_get_template( 'emails/wpinv-email-footer.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1383
}
1384
1385
function wpinv_email_wrap_message( $message ) {
1386
    // Buffer
1387
    ob_start();
1388
1389
    do_action( 'wpinv_email_header' );
1390
1391
    echo wpautop( wptexturize( $message ) );
1392
1393
    do_action( 'wpinv_email_footer' );
1394
1395
    // Get contents
1396
    $message = ob_get_clean();
1397
1398
    return $message;
1399
}
1400
1401
function wpinv_email_invoice_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1402
    wpinv_get_template( 'emails/wpinv-email-invoice-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1403
}
1404
1405
/**
1406
 * Display line items in emails.
1407
 * 
1408
 * @param int|WPInv_Invoice $invoice
1409
 * @param string $email_type
1410
 * @param bool $sent_to_admin
1411
 */
1412
function wpinv_email_invoice_items( $invoice, $email_type = '', $sent_to_admin = false ) {
1413
1414
    // Prepare the invoice.
1415
    $invoice = new WPInv_Invoice( $invoice );
1416
1417
    // Abort if there is no invoice.
1418
    if ( 0 == $invoice->get_id() ) {
1419
        return;
1420
    }
1421
1422
    // Prepare line items.
1423
    $columns = getpaid_invoice_item_columns( $invoice );
1424
    $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice );
1425
1426
    // Load the template.
1427
    wpinv_get_template( 'emails/wpinv-email-invoice-items.php', compact( 'invoice', 'columns', 'email_type', 'sent_to_admin' ) );
1428
}
1429
1430
function wpinv_email_billing_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1431
    wpinv_get_template( 'emails/wpinv-email-billing-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1432
}
1433
1434
function wpinv_send_customer_invoice( $data = array() ) {
1435
    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1436
1437
    if ( empty( $invoice_id ) ) {
1438
        return;
1439
    }
1440
1441
    if ( !wpinv_current_user_can_manage_invoicing() ) {
1442
        wp_die( __( 'You do not have permission to send invoice notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1443
    }
1444
    
1445
    $sent = wpinv_user_invoice_notification( $invoice_id );
1446
1447
    if ( -1 === $sent ) {
1448
        $status = 'email_disabled';
1449
    } elseif ( $sent ) {
1450
        $status = 'email_sent';
1451
    } else {
1452
        $status = 'email_fail';
1453
    }
1454
1455
    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1456
    wp_redirect( $redirect );
1457
    exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
1458
}
1459
add_action( 'wpinv_send_invoice', 'wpinv_send_customer_invoice' );
1460
1461
function wpinv_send_overdue_reminder( $data = array() ) {
1462
    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1463
1464
    if ( empty( $invoice_id ) ) {
1465
        return;
1466
    }
1467
1468
    if ( !wpinv_current_user_can_manage_invoicing() ) {
1469
        wp_die( __( 'You do not have permission to send reminder notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1470
    }
1471
1472
    $sent = wpinv_send_payment_reminder_notification( $invoice_id );
1473
    
1474
    $status = $sent ? 'email_sent' : 'email_fail';
1475
1476
    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1477
    wp_redirect( $redirect );
1478
    exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
1479
}
1480
add_action( 'wpinv_send_reminder', 'wpinv_send_overdue_reminder' );
1481
1482
function wpinv_send_customer_note_email( $data ) {
1483
    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1484
1485
    if ( empty( $invoice_id ) ) {
1486
        return;
1487
    }
1488
1489
    $sent = wpinv_user_note_notification( $invoice_id, $data );
0 ignored issues
show
Unused Code introduced by
The assignment to $sent is dead and can be removed.
Loading history...
1490
}
1491
add_action( 'wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1 );
1492
1493
function wpinv_add_notes_to_invoice_email( $invoice, $email_type, $sent_to_admin ) {
0 ignored issues
show
Unused Code introduced by
The parameter $sent_to_admin is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1493
function wpinv_add_notes_to_invoice_email( $invoice, $email_type, /** @scrutinizer ignore-unused */ $sent_to_admin ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1494
    if ( !empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->ID, true ) ) {
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type string expected by parameter $type of wpinv_get_invoice_notes(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1494
    if ( !empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->ID, /** @scrutinizer ignore-type */ true ) ) {
Loading history...
1495
        $date_format = get_option( 'date_format' );
1496
        $time_format = get_option( 'time_format' );
1497
        ?>
1498
        <div id="wpinv-email-notes">
1499
            <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3>
1500
            <ol class="wpinv-notes-lists">
1501
        <?php
1502
        foreach ( $invoice_notes as $note ) {
1503
            $note_time = strtotime( $note->comment_date );
1504
            ?>
1505
            <li class="comment wpinv-note">
1506
            <p class="wpinv-note-date meta"><?php printf( __( '%2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( $date_format, $note_time ), date_i18n( $time_format, $note_time ), $note_time ); ?></p>
0 ignored issues
show
Bug introduced by
It seems like $date_format can also be of type false; however, parameter $format of date_i18n() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1506
            <p class="wpinv-note-date meta"><?php printf( __( '%2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( /** @scrutinizer ignore-type */ $date_format, $note_time ), date_i18n( $time_format, $note_time ), $note_time ); ?></p>
Loading history...
1507
            <div class="wpinv-note-desc description"><?php echo wpautop( wptexturize( $note->comment_content ) ); ?></div>
1508
            </li>
1509
            <?php
1510
        }
1511
        ?>  </ol>
1512
        </div>
1513
        <?php
1514
    }
1515
}
1516
add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 );
1517
1518
/**
1519
 * Sends renewal reminders.
1520
 */
1521
function wpinv_email_renewal_reminders() {
1522
    global $wpdb;
1523
1524
    if ( ! wpinv_get_option( 'email_pre_payment_active' ) ) {
1525
        return;
1526
    }
1527
1528
    $reminder_days = wpinv_get_option( 'email_pre_payment_reminder_days' );
1529
1530
    if ( empty( $reminder_days ) ) {
1531
        return;
1532
    }
1533
1534
    // How many days before renewal should we send this email?
1535
    $reminder_days = array_unique( array_map( 'absint', array_filter( wpinv_parse_list( $reminder_days ) ) ) );
1536
    if ( empty( $reminder_days ) ) {
1537
        return;
1538
    }
1539
1540
    if ( 1 == count( $reminder_days ) ) {
1541
        $days  = $reminder_days[0];
1542
        $date  = date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) );
1543
        $where = $wpdb->prepare( "DATE(expiration)=%s", $date );
1544
    } else {
1545
        $in    = array();
1546
1547
        foreach ( $reminder_days as $days ) {
1548
            $date  = date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) );
1549
            $in[]  = $wpdb->prepare( "%s", $date );
1550
        }
1551
1552
        $in    = implode( ',', $in );
1553
        $where = "DATE(expiration) IN ($in)";
1554
    }
1555
1556
    // Fetch subscriptions to send out reminders for.
1557
    $table = $wpdb->prefix . 'wpinv_subscriptions';
1558
1559
    // Fetch invoices.
1560
	$subscriptions  = $wpdb->get_results(
1561
		"SELECT parent_payment_id, product_id, expiration FROM $table
1562
		WHERE
1563
            $where
1564
            AND status IN ( 'trialling', 'active' )");
1565
1566
    foreach ( $subscriptions as $subscription ) {
1567
1568
        // Skip packages.
1569
        if ( get_post_meta( $subscription->product_id, '_wpinv_type', true ) == 'package' ) {
1570
            continue;
1571
        }
1572
1573
        wpinv_send_pre_payment_reminder_notification( $subscription->parent_payment_id, $subscription->expiration );
1574
    }
1575
1576
}
1577
1578
function wpinv_email_payment_reminders() {
1579
    global $wpi_auto_reminder, $wpdb;
1580
1581
    if ( ! wpinv_get_option( 'email_overdue_active' ) ) {
1582
        return;
1583
    }
1584
1585
    if ( $reminder_days = wpinv_get_option( 'email_due_reminder_days' ) ) {
1586
1587
        // Get a list of all reminder dates.
1588
        $reminder_days  = is_array( $reminder_days ) ? array_values( $reminder_days ) : array();
0 ignored issues
show
introduced by
The condition is_array($reminder_days) is always true.
Loading history...
1589
1590
        // Ensure we have integers.
1591
        $reminder_days  = array_unique( array_map( 'absint', $reminder_days ) );
1592
1593
        // Abort if non is selected.
1594
        if ( empty( $reminder_days ) ) {
1595
            return;
1596
        }
1597
1598
        // Fetch the max reminder day.
1599
        $max_date = max( $reminder_days );
1600
1601
        // Todays date.
1602
        $today = date( 'Y-m-d', current_time( 'timestamp' ) );
1603
1604
        if ( empty( $max_date ) ) {
1605
            $where = $wpdb->prepare( "DATE(invoices.due_date)=%s", $today );
1606
        } else if ( 1 == count( $reminder_days ) ) {
1607
            $days  = $reminder_days[0];
1608
            $date  = date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) );
1609
            $where = $wpdb->prepare( "DATE(invoices.due_date)=%s", $date );
1610
        } else {
1611
            $in    = array();
1612
1613
            foreach ( $reminder_days as $days ) {
1614
                $date  = date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) );
1615
                $in[]  = $wpdb->prepare( "%s", $date );
1616
            }
1617
1618
            $in    = implode( ',', $in );
1619
            $where = "DATE(invoices.due_date) IN ($in)";
1620
        }
1621
1622
        // Invoices table.
1623
        $table = $wpdb->prefix . 'getpaid_invoices';
1624
1625
        // Fetch invoices.
1626
		$invoices  = $wpdb->get_col(
1627
			"SELECT posts.ID FROM $wpdb->posts as posts
1628
			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
1629
			WHERE
1630
                $where 
1631
				AND posts.post_type = 'wpi_invoice'
1632
                AND posts.post_status = 'wpi-pending'");
1633
1634
        $wpi_auto_reminder  = true;
1635
1636
        foreach ( $invoices as $invoice ) {
1637
1638
            if ( 'payment_form' != get_post_meta( $invoice, 'wpinv_created_via', true ) ) {
1639
                do_action( 'wpinv_send_payment_reminder_notification', $invoice );
1640
            }
1641
1642
        }
1643
1644
        $wpi_auto_reminder  = false;
1645
    }
1646
}
1647
1648
/**
1649
 * Sends an upcoming renewal notification.
1650
 */
1651
function wpinv_send_pre_payment_reminder_notification( $invoice_id, $renewal_date ) {
1652
1653
    $email_type = 'pre_payment';
1654
    if ( ! wpinv_email_is_enabled( $email_type ) ) {
1655
        return false;
1656
    }
1657
1658
    $invoice    = wpinv_get_invoice( $invoice_id );
1659
    if ( empty( $invoice ) ) {
1660
        return false;
1661
    }
1662
1663
    $recipient  = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
1664
    if ( ! is_email( $recipient ) ) {
1665
        return false;
1666
    }
1667
1668
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
1669
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
1670
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
1671
    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
1672
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
1673
1674
    $renewal_date = date_i18n( 'Y-m-d', strtotime( $renewal_date ) );
1675
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
1676
            'invoice'       => $invoice,
1677
            'email_type'    => $email_type,
1678
            'email_heading' => str_replace( '{subscription_renewal_date}', $renewal_date, $email_heading ),
1679
            'sent_to_admin' => false,
1680
            'plain_text'    => false,
1681
            'message_body'  => str_replace( '{subscription_renewal_date}', $renewal_date, $message_body )
1682
        ) );
1683
1684
    $content        = wpinv_email_format_text( $content, $invoice );
1685
1686
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
1687
1688
    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
1689
        $recipient  = wpinv_get_admin_email();
1690
        $subject    .= ' - ADMIN BCC COPY';
1691
        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
1692
    }
1693
1694
    return $sent;
1695
1696
}
1697
1698
function wpinv_send_payment_reminder_notification( $invoice_id ) {
1699
    $email_type = 'overdue';
1700
    if ( !wpinv_email_is_enabled( $email_type ) ) {
1701
        return false;
1702
    }
1703
1704
    $invoice    = wpinv_get_invoice( $invoice_id );
1705
    if ( empty( $invoice ) ) {
1706
        return false;
1707
    }
1708
1709
    if ( !$invoice->needs_payment() ) {
1710
        return false;
1711
    }
1712
1713
    $recipient  = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
1714
    if ( !is_email( $recipient ) ) {
1715
        return false;
1716
    }
1717
1718
    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
1719
1720
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
1721
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
1722
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
1723
    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
1724
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
1725
1726
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
1727
            'invoice'       => $invoice,
1728
            'email_type'    => $email_type,
1729
            'email_heading' => $email_heading,
1730
            'sent_to_admin' => false,
1731
            'plain_text'    => false,
1732
            'message_body'  => $message_body
1733
        ) );
1734
1735
    $content        = wpinv_email_format_text( $content, $invoice );
1736
1737
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
1738
    if ( $sent ) {
0 ignored issues
show
introduced by
The condition $sent is always true.
Loading history...
1739
        do_action( 'wpinv_payment_reminder_sent', $invoice_id, $invoice );
1740
    }
1741
1742
    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
1743
        $recipient  = wpinv_get_admin_email();
1744
        $subject    .= ' - ADMIN BCC COPY';
1745
        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
1746
    }
1747
1748
    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
1749
1750
    return $sent;
1751
}
1752
add_action( 'wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1 );
1753
1754
function wpinv_payment_reminder_sent( $invoice_id, $invoice ) {
1755
    global $wpi_auto_reminder;
1756
1757
    $sent = get_post_meta( $invoice_id, '_wpinv_reminder_sent', true );
1758
1759
    if ( empty( $sent ) ) {
1760
        $sent = array();
1761
    }
1762
    $sent[] = date_i18n( 'Y-m-d' );
1763
1764
    update_post_meta( $invoice_id, '_wpinv_reminder_sent', $sent );
1765
1766
    if ( $wpi_auto_reminder ) { // Auto reminder note.
1767
        $note = __( 'Automated reminder sent to the user.', 'invoicing' );
1768
        $invoice->add_note( $note, false, false, true );
1769
    } else { // Menual reminder note.
1770
        $note = __( 'Manual reminder sent to the user.', 'invoicing' );
1771
        $invoice->add_note( $note );
1772
    }
1773
}
1774
add_action( 'wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2 );
1775
1776
function wpinv_invoice_notification_set_locale( $invoice, $email_type, $site = false ) {
0 ignored issues
show
Unused Code introduced by
The parameter $email_type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1776
function wpinv_invoice_notification_set_locale( $invoice, /** @scrutinizer ignore-unused */ $email_type, $site = false ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1777
    if ( empty( $invoice ) ) {
1778
        return;
1779
    }
1780
1781
    if ( is_int( $invoice ) ) {
1782
        $invoice = wpinv_get_invoice( $invoice );
1783
    }
1784
1785
    if ( ! empty( $invoice ) && is_object( $invoice ) ) {
1786
        if ( ! $site && function_exists( 'get_user_locale' ) ) {
1787
            $locale = get_user_locale( $invoice->get_user_id() );
1788
        } else {
1789
            $locale = get_locale();
1790
        }
1791
1792
        wpinv_switch_to_locale( $locale );
1793
    }
1794
}
1795
add_action( 'wpinv_pre_send_invoice_notification', 'wpinv_invoice_notification_set_locale', 10, 3 );
1796
1797
function wpinv_invoice_notification_restore_locale( $invoice, $email_type, $site = false ) {
0 ignored issues
show
Unused Code introduced by
The parameter $site is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1797
function wpinv_invoice_notification_restore_locale( $invoice, $email_type, /** @scrutinizer ignore-unused */ $site = false ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $email_type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1797
function wpinv_invoice_notification_restore_locale( $invoice, /** @scrutinizer ignore-unused */ $email_type, $site = false ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1798
    if ( empty( $invoice ) ) {
1799
        return;
1800
    }
1801
1802
    wpinv_restore_locale();
1803
}
1804
add_action( 'wpinv_post_send_invoice_notification', 'wpinv_invoice_notification_restore_locale', 10, 3 );
1805