Completed
Push — master ( 2f3eab...3ff0dd )
by Stiofan
13s
created

wpinv-email-functions.php ➔ wpinv_email_before_note_details()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 2
nop 4
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
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_pending_to_processing',
17
        'wpinv_status_pending_to_publish',
18
        'wpinv_status_pending_to_cancelled',
19
        'wpinv_status_pending_to_failed',
20
        'wpinv_status_pending_to_onhold',
21
        'wpinv_status_failed_to_processing',
22
        'wpinv_status_failed_to_publish',
23
        'wpinv_status_failed_to_onhold',
24
        'wpinv_status_onhold_to_processing',
25
        'wpinv_status_onhold_to_cancelled',
26
        'wpinv_status_onhold_to_failed',
27
        'wpinv_status_publish',
28
        'wpinv_fully_refunded',
29
        'wpinv_partially_refunded',
30
        'wpinv_new_invoice_note'
31
    ) );
32
33
    foreach ( $email_actions as $action ) {
34
        add_action( $action, 'wpinv_send_transactional_email', 10, 10 );
35
    }
36
}
37
add_action( 'init', 'wpinv_init_transactional_emails' );
38
39
// New invoice email
40
add_action( 'wpinv_status_pending_to_processing_notification', 'wpinv_new_invoice_notification' );
41
add_action( 'wpinv_status_pending_to_publish_notification', 'wpinv_new_invoice_notification' );
42
add_action( 'wpinv_status_pending_to_onhold_notification', 'wpinv_new_invoice_notification' );
43
add_action( 'wpinv_status_failed_to_processing_notification', 'wpinv_new_invoice_notification' );
44
add_action( 'wpinv_status_failed_to_publish_notification', 'wpinv_new_invoice_notification' );
45
add_action( 'wpinv_status_failed_to_onhold_notification', 'wpinv_new_invoice_notification' );
46
47
// Cancelled invoice email
48
add_action( 'wpinv_status_pending_to_cancelled_notification', 'wpinv_cancelled_invoice_notification' );
49
add_action( 'wpinv_status_onhold_to_cancelled_notification', 'wpinv_cancelled_invoice_notification' );
50
51
// Failed invoice email
52
add_action( 'wpinv_status_pending_to_failed_notification', 'wpinv_failed_invoice_notification' );
53
add_action( 'wpinv_status_onhold_to_failed_notification', 'wpinv_failed_invoice_notification' );
54
55
// On hold invoice email
56
add_action( 'wpinv_status_pending_to_onhold_notification', 'wpinv_onhold_invoice_notification' );
57
add_action( 'wpinv_status_failed_to_onhold_notification', 'wpinv_onhold_invoice_notification' );
58
59
// Processing invoice email
60
add_action( 'wpinv_status_pending_to_processing_notification', 'wpinv_processing_invoice_notification' );
61
62
// Paid invoice email
63
add_action( 'wpinv_status_publish_notification', 'wpinv_completed_invoice_notification' );
64
65
// Refunded invoice email
66
add_action( 'wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification' );
67
add_action( 'wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification' );
68
69
// Invoice note
70
add_action( 'wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification' );
71
72
add_action( 'wpinv_email_header', 'wpinv_email_header' );
73
add_action( 'wpinv_email_footer', 'wpinv_email_footer' );
74
add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 );
75
add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 );
76
add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 );
77
add_action( 'wpinv_email_before_note_details', 'wpinv_email_before_note_details', 10, 4 );
78
79
function wpinv_send_transactional_email() {
80
    $args       = func_get_args();
81
    $function   = current_filter() . '_notification';
82
    do_action_ref_array( $function, $args );
83
}
84
    
85 View Code Duplication
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.

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

Loading history...
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
86
    global $wpinv_email_search, $wpinv_email_replace;
87
    
88
    $email_type = 'new_invoice';
89
    if ( !wpinv_email_is_enabled( $email_type ) ) {
90
        return false;
91
    }
92
    
93
    $invoice = wpinv_get_invoice( $invoice_id );
94
    if ( empty( $invoice ) ) {
95
        return false;
96
    }
97
98
    if ( !("wpi_invoice" === $invoice->post_type) ) {
99
        return false;
100
    }
101
    
102
    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
103
    if ( !is_email( $recipient ) ) {
104
        return false;
105
    }
106
        
107
    $search                     = array();
108
    $search['invoice_number']   = '{invoice_number}';
109
    $search['invoice_date']     = '{invoice_date}';
110
    $search['name']             = '{name}';
111
    
112
    $replace                    = array();
113
    $replace['invoice_number']  = $invoice->get_number();
114
    $replace['invoice_date']    = $invoice->get_invoice_date();
115
    $replace['name']            = $invoice->get_user_full_name();
116
    
117
    $wpinv_email_search     = $search;
118
    $wpinv_email_replace    = $replace;
119
    
120
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
121
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
122
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
123
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
124
    
125
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
126
            'invoice'       => $invoice,
127
            'email_type'    => $email_type,
128
            'email_heading' => $email_heading,
129
            'sent_to_admin' => true,
130
            'plain_text'    => false,
131
        ) );
132
    
133
    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
134
}
135
136 View Code Duplication
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.

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

Loading history...
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
137
    global $wpinv_email_search, $wpinv_email_replace;
138
    
139
    $email_type = 'cancelled_invoice';
140
    if ( !wpinv_email_is_enabled( $email_type ) ) {
141
        return false;
142
    }
143
    
144
    $invoice = wpinv_get_invoice( $invoice_id );
145
    if ( empty( $invoice ) ) {
146
        return false;
147
    }
148
149
    if ( !("wpi_invoice" === $invoice->post_type) ) {
150
        return false;
151
    }
152
    
153
    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
154
    if ( !is_email( $recipient ) ) {
155
        return false;
156
    }
157
        
158
    $search                     = array();
159
    $search['invoice_number']   = '{invoice_number}';
160
    $search['invoice_date']     = '{invoice_date}';
161
    $search['name']             = '{name}';
162
    
163
    $replace                    = array();
164
    $replace['invoice_number']  = $invoice->get_number();
165
    $replace['invoice_date']    = $invoice->get_invoice_date();
166
    $replace['name']            = $invoice->get_user_full_name();
167
    
168
    $wpinv_email_search     = $search;
169
    $wpinv_email_replace    = $replace;
170
    
171
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
172
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
173
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
174
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
175
    
176
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
177
            'invoice'       => $invoice,
178
            'email_type'    => $email_type,
179
            'email_heading' => $email_heading,
180
            'sent_to_admin' => true,
181
            'plain_text'    => false,
182
        ) );
183
    
184
    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
185
}
186
187 View Code Duplication
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.

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

Loading history...
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
188
    global $wpinv_email_search, $wpinv_email_replace;
189
    
190
    $email_type = 'failed_invoice';
191
    if ( !wpinv_email_is_enabled( $email_type ) ) {
192
        return false;
193
    }
194
    
195
    $invoice = wpinv_get_invoice( $invoice_id );
196
    if ( empty( $invoice ) ) {
197
        return false;
198
    }
199
200
    if ( !("wpi_invoice" === $invoice->post_type) ) {
201
        return false;
202
    }
203
    
204
    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
205
    if ( !is_email( $recipient ) ) {
206
        return false;
207
    }
208
        
209
    $search                     = array();
210
    $search['invoice_number']   = '{invoice_number}';
211
    $search['invoice_date']     = '{invoice_date}';
212
    $search['name']             = '{name}';
213
    
214
    $replace                    = array();
215
    $replace['invoice_number']  = $invoice->get_number();
216
    $replace['invoice_date']    = $invoice->get_invoice_date();
217
    $replace['name']            = $invoice->get_user_full_name();
218
    
219
    $wpinv_email_search     = $search;
220
    $wpinv_email_replace    = $replace;
221
    
222
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
223
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
224
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
225
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
226
    
227
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
228
            'invoice'       => $invoice,
229
            'email_type'    => $email_type,
230
            'email_heading' => $email_heading,
231
            'sent_to_admin' => true,
232
            'plain_text'    => false,
233
        ) );
234
    
235
    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
236
}
237
238 View Code Duplication
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.

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

Loading history...
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
239
    global $wpinv_email_search, $wpinv_email_replace;
240
    
241
    $email_type = 'onhold_invoice';
242
    if ( !wpinv_email_is_enabled( $email_type ) ) {
243
        return false;
244
    }
245
    
246
    $invoice = wpinv_get_invoice( $invoice_id );
247
    if ( empty( $invoice ) ) {
248
        return false;
249
    }
250
251
    if ( !("wpi_invoice" === $invoice->post_type) ) {
252
        return false;
253
    }
254
    
255
    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
256
    if ( !is_email( $recipient ) ) {
257
        return false;
258
    }
259
        
260
    $search                     = array();
261
    $search['invoice_number']   = '{invoice_number}';
262
    $search['invoice_date']     = '{invoice_date}';
263
    $search['name']             = '{name}';
264
    
265
    $replace                    = array();
266
    $replace['invoice_number']  = $invoice->get_number();
267
    $replace['invoice_date']    = $invoice->get_invoice_date();
268
    $replace['name']            = $invoice->get_user_full_name();
269
    
270
    $wpinv_email_search     = $search;
271
    $wpinv_email_replace    = $replace;
272
    
273
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
274
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
275
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
276
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
277
    
278
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
279
            'invoice'       => $invoice,
280
            'email_type'    => $email_type,
281
            'email_heading' => $email_heading,
282
            'sent_to_admin' => false,
283
            'plain_text'    => false,
284
        ) );
285
    
286
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
287
    
288
    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
289
        $recipient  = wpinv_get_admin_email();
290
        $subject    .= ' - ADMIN BCC COPY';
291
        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
292
    }
293
    
294
    return $sent;
295
}
296
297 View Code Duplication
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.

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

Loading history...
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
298
    global $wpinv_email_search, $wpinv_email_replace;
299
    
300
    $email_type = 'processing_invoice';
301
    if ( !wpinv_email_is_enabled( $email_type ) ) {
302
        return false;
303
    }
304
    
305
    $invoice = wpinv_get_invoice( $invoice_id );
306
    if ( empty( $invoice ) ) {
307
        return false;
308
    }
309
310
    if ( !("wpi_invoice" === $invoice->post_type) ) {
311
        return false;
312
    }
313
    
314
    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
315
    if ( !is_email( $recipient ) ) {
316
        return false;
317
    }
318
        
319
    $search                     = array();
320
    $search['invoice_number']   = '{invoice_number}';
321
    $search['invoice_date']     = '{invoice_date}';
322
    $search['name']             = '{name}';
323
    
324
    $replace                    = array();
325
    $replace['invoice_number']  = $invoice->get_number();
326
    $replace['invoice_date']    = $invoice->get_invoice_date();
327
    $replace['name']            = $invoice->get_user_full_name();
328
    
329
    $wpinv_email_search     = $search;
330
    $wpinv_email_replace    = $replace;
331
    
332
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
333
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
334
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
335
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
336
    
337
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
338
            'invoice'       => $invoice,
339
            'email_type'    => $email_type,
340
            'email_heading' => $email_heading,
341
            'sent_to_admin' => false,
342
            'plain_text'    => false,
343
        ) );
344
    
345
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
346
    
347
    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
348
        $recipient  = wpinv_get_admin_email();
349
        $subject    .= ' - ADMIN BCC COPY';
350
        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
351
    }
352
    
353
    return $sent;
354
}
355
356 View Code Duplication
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.

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

Loading history...
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
357
    global $wpinv_email_search, $wpinv_email_replace;
358
    
359
    $email_type = 'completed_invoice';
360
    if ( !wpinv_email_is_enabled( $email_type ) ) {
361
        return false;
362
    }
363
    
364
    $invoice = wpinv_get_invoice( $invoice_id );
365
    if ( empty( $invoice ) ) {
366
        return false;
367
    }
368
369
    if ( !("wpi_invoice" === $invoice->post_type) ) {
370
        return false;
371
    }
372
    
373
    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
374
    if ( !is_email( $recipient ) ) {
375
        return false;
376
    }
377
        
378
    $search                     = array();
379
    $search['invoice_number']   = '{invoice_number}';
380
    $search['invoice_date']     = '{invoice_date}';
381
    $search['name']             = '{name}';
382
    
383
    $replace                    = array();
384
    $replace['invoice_number']  = $invoice->get_number();
385
    $replace['invoice_date']    = $invoice->get_invoice_date();
386
    $replace['name']            = $invoice->get_user_full_name();
387
    
388
    $wpinv_email_search     = $search;
389
    $wpinv_email_replace    = $replace;
390
    
391
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
392
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
393
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
394
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
395
    
396
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
397
            'invoice'       => $invoice,
398
            'email_type'    => $email_type,
399
            'email_heading' => $email_heading,
400
            'sent_to_admin' => false,
401
            'plain_text'    => false,
402
        ) );
403
    
404
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
405
    
406
    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
407
        $recipient  = wpinv_get_admin_email();
408
        $subject    .= ' - ADMIN BCC COPY';
409
        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
410
    }
411
    
412
    return $sent;
413
}
414
415 View Code Duplication
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.

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

Loading history...
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
416
    global $wpinv_email_search, $wpinv_email_replace;
417
    
418
    $email_type = 'refunded_invoice';
419
    if ( !wpinv_email_is_enabled( $email_type ) ) {
420
        return false;
421
    }
422
    
423
    $invoice = wpinv_get_invoice( $invoice_id );
424
    if ( empty( $invoice ) ) {
425
        return false;
426
    }
427
428
    if ( !("wpi_invoice" === $invoice->post_type) ) {
429
        return false;
430
    }
431
    
432
    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
433
    if ( !is_email( $recipient ) ) {
434
        return false;
435
    }
436
        
437
    $search                     = array();
438
    $search['invoice_number']   = '{invoice_number}';
439
    $search['invoice_date']     = '{invoice_date}';
440
    $search['name']             = '{name}';
441
    
442
    $replace                    = array();
443
    $replace['invoice_number']  = $invoice->get_number();
444
    $replace['invoice_date']    = $invoice->get_invoice_date();
445
    $replace['name']            = $invoice->get_user_full_name();
446
    
447
    $wpinv_email_search     = $search;
448
    $wpinv_email_replace    = $replace;
449
    
450
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
451
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
452
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
453
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
454
    
455
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
456
            'invoice'           => $invoice,
457
            'email_type'        => $email_type,
458
            'email_heading'     => $email_heading,
459
            'sent_to_admin'     => false,
460
            'plain_text'        => false,
461
            'partial_refund'    => false
462
        ) );
463
    
464
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
465
    
466
    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
467
        $recipient  = wpinv_get_admin_email();
468
        $subject    .= ' - ADMIN BCC COPY';
469
        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
470
    }
471
    
472
    return $sent;
473
}
474
475 View Code Duplication
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.

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

Loading history...
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
476
    global $wpinv_email_search, $wpinv_email_replace;
477
    
478
    $email_type = 'refunded_invoice';
479
    if ( !wpinv_email_is_enabled( $email_type ) ) {
480
        return false;
481
    }
482
    
483
    $invoice = wpinv_get_invoice( $invoice_id );
484
    if ( empty( $invoice ) ) {
485
        return false;
486
    }
487
488
    if ( !("wpi_invoice" === $invoice->post_type) ) {
489
        return false;
490
    }
491
    
492
    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
493
    if ( !is_email( $recipient ) ) {
494
        return false;
495
    }
496
        
497
    $search                     = array();
498
    $search['invoice_number']   = '{invoice_number}';
499
    $search['invoice_date']     = '{invoice_date}';
500
    $search['name']             = '{name}';
501
    
502
    $replace                    = array();
503
    $replace['invoice_number']  = $invoice->get_number();
504
    $replace['invoice_date']    = $invoice->get_invoice_date();
505
    $replace['name']            = $invoice->get_user_full_name();
506
    
507
    $wpinv_email_search     = $search;
508
    $wpinv_email_replace    = $replace;
509
    
510
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
511
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
512
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
513
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
514
    
515
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
516
            'invoice'           => $invoice,
517
            'email_type'        => $email_type,
518
            'email_heading'     => $email_heading,
519
            'sent_to_admin'     => false,
520
            'plain_text'        => false,
521
            'partial_refund'    => true
522
        ) );
523
    
524
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
525
    
526
    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
527
        $recipient  = wpinv_get_admin_email();
528
        $subject    .= ' - ADMIN BCC COPY';
529
        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
530
    }
531
    
532
    return $sent;
533
}
534
535
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.

This check looks from 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.

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

Loading history...
536
}
537
538
function wpinv_user_invoice_notification( $invoice_id ) {
539
    global $wpinv_email_search, $wpinv_email_replace;
540
    
541
    $email_type = 'user_invoice';
542
    if ( !wpinv_email_is_enabled( $email_type ) ) {
543
        return false;
544
    }
545
    
546
    $invoice = wpinv_get_invoice( $invoice_id );
547
    if ( empty( $invoice ) ) {
548
        return false;
549
    }
550
551
    if ( !("wpi_invoice" === $invoice->post_type) ) {
552
        return false;
553
    }
554
    
555
    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
556
    if ( !is_email( $recipient ) ) {
557
        return false;
558
    }
559
        
560
    $search                     = array();
561
    $search['invoice_number']   = '{invoice_number}';
562
    $search['invoice_date']     = '{invoice_date}';
563
    $search['name']             = '{name}';
564
    
565
    $replace                    = array();
566
    $replace['invoice_number']  = $invoice->get_number();
567
    $replace['invoice_date']    = $invoice->get_invoice_date();
568
    $replace['name']            = $invoice->get_user_full_name();
569
    
570
    $wpinv_email_search     = $search;
571
    $wpinv_email_replace    = $replace;
572
    
573
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
574
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
575
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
576
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
577
    
578
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
579
            'invoice'       => $invoice,
580
            'email_type'    => $email_type,
581
            'email_heading' => $email_heading,
582
            'sent_to_admin' => false,
583
            'plain_text'    => false,
584
        ) );
585
    
586
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
587
    
588
    if ( $sent ) {
589
        $note = __( 'Invoice has been emailed to the user.', 'invoicing' );
590
    } else {
591
        $note = __( 'Fail to send invoice to the user!', 'invoicing' );
592
    }
593
    $invoice->add_note( $note ); // Add private note.
594
    
595
    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
596
        $recipient  = wpinv_get_admin_email();
597
        $subject    .= ' - ADMIN BCC COPY';
598
        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
599
    }
600
    
601
    return $sent;
602
}
603
604
function wpinv_user_note_notification( $invoice_id, $args = array() ) {
605
    global $wpinv_email_search, $wpinv_email_replace;
606
    
607
    $email_type = 'user_note';
608
    if ( !wpinv_email_is_enabled( $email_type ) ) {
609
        return false;
610
    }
611
    
612
    $invoice = wpinv_get_invoice( $invoice_id );
613
    if ( empty( $invoice ) ) {
614
        return false;
615
    }
616
    
617
    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
618
    if ( !is_email( $recipient ) ) {
619
        return false;
620
    }
621
    
622
    $defaults = array(
623
        'user_note' => ''
624
    );
625
626
    $args = wp_parse_args( $args, $defaults );
627
        
628
    $search                     = array();
629
    $search['invoice_number']   = '{invoice_number}';
630
    $search['invoice_date']     = '{invoice_date}';
631
    $search['name']             = '{name}';
632
    $search['customer_note']    = '{customer_note}';
633
    $search['invoice_quote']    = '{invoice_quote}';
634
635
    $replace                    = array();
636
    $replace['invoice_number']  = $invoice->get_number();
637
    $replace['invoice_date']    = $invoice->get_invoice_date();
638
    $replace['name']            = $invoice->get_user_full_name();
639
    $replace['customer_note']   = $args['user_note'];
640
    $replace['invoice_quote']   = $invoice->get_invoice_quote_type($invoice_id);
641
642
    $wpinv_email_search     = $search;
643
    $wpinv_email_replace    = $replace;
644
    
645
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
646
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
647
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
648
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
649
    
650
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
651
            'invoice'       => $invoice,
652
            'email_type'    => $email_type,
653
            'email_heading' => $email_heading,
654
            'sent_to_admin' => false,
655
            'plain_text'    => false,
656
            'customer_note' => $args['user_note']
657
        ) );
658
        
659
    $content        = wpinv_email_format_text( $content );
660
    
661
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
662
        
663
    return $sent;
664
}
665
666
function wpinv_mail_get_from_address() {
667
    $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) );
668
    return sanitize_email( $from_address );
669
}
670
671
function wpinv_mail_get_from_name() {
672
    $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name' ) );
673
    return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES );
674
}
675
676
function wpinv_mail_admin_bcc_active( $mail_type = '' ) {
677
    $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) );
678
    return ( $active ? true : false );
679
}
680
    
681
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.

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

Loading history...
682
    $email_type = apply_filters( 'wpinv_mail_content_type', $email_type );
683
    
684
    switch ( $email_type ) {
685
        case 'html' :
686
            $content_type = 'text/html';
687
            break;
688
        case 'multipart' :
689
            $content_type = 'multipart/alternative';
690
            break;
691
        default :
692
            $content_type = 'text/plain';
693
            break;
694
    }
695
    
696
    return $content_type;
697
}
698
    
699
function wpinv_mail_send( $to, $subject, $message, $headers, $attachments ) {
700
    add_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
701
    add_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
702
    add_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
703
704
    $message = wpinv_email_style_body( $message );
705
    $message = apply_filters( 'wpinv_mail_content', $message );
706
    
707
    $sent  = wp_mail( $to, $subject, $message, $headers, $attachments );
708
    
709
    if ( !$sent ) {
710
        $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 );
711
        wpinv_error_log( $log_message, __( "Email from Invoicing plugin failed to send", 'invoicing' ), __FILE__, __LINE__ );
712
    }
713
714
    remove_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
715
    remove_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
716
    remove_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
717
718
    return $sent;
719
}
720
    
721
function wpinv_get_emails() {
722
    $overdue_days_options       = array();
723
    $overdue_days_options[0]    = __( 'On the Due Date', 'invoicing' );
724
    $overdue_days_options[1]    = __( '1 day after Due Date', 'invoicing' );
725
    
726
    for ( $i = 2; $i <= 10; $i++ ) {
727
        $overdue_days_options[$i]   = wp_sprintf( __( '%d days after Due Date', 'invoicing' ), $i );
728
    }
729
730
	// Default, built-in gateways
731
	$emails = array(
732
            'new_invoice' => array(
733
            'email_new_invoice_header' => array(
734
                'id'   => 'email_new_invoice_header',
735
                'name' => '<h3>' . __( 'New Invoice', 'invoicing' ) . '</h3>',
736
                'desc' => __( 'New invoice emails are sent to admin when a new invoice is received.', 'invoicing' ),
737
                'type' => 'header',
738
            ),
739
            'email_new_invoice_active' => array(
740
                'id'   => 'email_new_invoice_active',
741
                'name' => __( 'Enable/Disable', 'invoicing' ),
742
                'desc' => __( 'Enable this email notification', 'invoicing' ),
743
                'type' => 'checkbox',
744
                'std'  => 1
745
            ),
746
            'email_new_invoice_subject' => array(
747
                'id'   => 'email_new_invoice_subject',
748
                'name' => __( 'Subject', 'invoicing' ),
749
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
750
                'type' => 'text',
751
                'std'  => __( '[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing' ),
752
                'size' => 'large'
753
            ),
754
            'email_new_invoice_heading' => array(
755
                'id'   => 'email_new_invoice_heading',
756
                'name' => __( 'Email Heading', 'invoicing' ),
757
                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
758
                'type' => 'text',
759
                'std'  => __( 'New payment invoice', 'invoicing' ),
760
                'size' => 'large'
761
            ),
762
        ),
763
        'cancelled_invoice' => array(
764
            'email_cancelled_invoice_header' => array(
765
                'id'   => 'email_cancelled_invoice_header',
766
                'name' => '<h3>' . __( 'Cancelled Invoice', 'invoicing' ) . '</h3>',
767
                'desc' => __( 'Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing' ),
768
                'type' => 'header',
769
            ),
770
            'email_cancelled_invoice_active' => array(
771
                'id'   => 'email_cancelled_invoice_active',
772
                'name' => __( 'Enable/Disable', 'invoicing' ),
773
                'desc' => __( 'Enable this email notification', 'invoicing' ),
774
                'type' => 'checkbox',
775
                'std'  => 1
776
            ),
777
            'email_cancelled_invoice_subject' => array(
778
                'id'   => 'email_cancelled_invoice_subject',
779
                'name' => __( 'Subject', 'invoicing' ),
780
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
781
                'type' => 'text',
782
                'std'  => __( '[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing' ),
783
                'size' => 'large'
784
            ),
785
            'email_cancelled_invoice_heading' => array(
786
                'id'   => 'email_cancelled_invoice_heading',
787
                'name' => __( 'Email Heading', 'invoicing' ),
788
                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
789
                'type' => 'text',
790
                'std'  => __( 'Cancelled invoice', 'invoicing' ),
791
                'size' => 'large'
792
            ),
793
        ),
794
        'failed_invoice' => array(
795
            'email_failed_invoice_header' => array(
796
                'id'   => 'email_failed_invoice_header',
797
                'name' => '<h3>' . __( 'Failed Invoice', 'invoicing' ) . '</h3>',
798
                'desc' => __( 'Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing' ),
799
                'type' => 'header',
800
            ),
801
            'email_failed_invoice_active' => array(
802
                'id'   => 'email_failed_invoice_active',
803
                'name' => __( 'Enable/Disable', 'invoicing' ),
804
                'desc' => __( 'Enable this email notification', 'invoicing' ),
805
                'type' => 'checkbox',
806
                'std'  => 1
807
            ),
808
            'email_failed_invoice_subject' => array(
809
                'id'   => 'email_failed_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}] Failed invoice ({invoice_number})', 'invoicing' ),
814
                'size' => 'large'
815
            ),
816
            'email_failed_invoice_heading' => array(
817
                'id'   => 'email_failed_invoice_heading',
818
                'name' => __( 'Email Heading', 'invoicing' ),
819
                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
820
                'type' => 'text',
821
                'std'  => __( 'Failed invoice', 'invoicing' ),
822
                'size' => 'large'
823
            )
824
        ),
825
        'onhold_invoice' => array(
826
            'email_onhold_invoice_header' => array(
827
                'id'   => 'email_onhold_invoice_header',
828
                'name' => '<h3>' . __( 'On Hold Invoice', 'invoicing' ) . '</h3>',
829
                'desc' => __( 'This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing' ),
830
                'type' => 'header',
831
            ),
832
            'email_onhold_invoice_active' => array(
833
                'id'   => 'email_onhold_invoice_active',
834
                'name' => __( 'Enable/Disable', 'invoicing' ),
835
                'desc' => __( 'Enable this email notification', 'invoicing' ),
836
                'type' => 'checkbox',
837
                'std'  => 1
838
            ),
839
            'email_onhold_invoice_subject' => array(
840
                'id'   => 'email_onhold_invoice_subject',
841
                'name' => __( 'Subject', 'invoicing' ),
842
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
843
                'type' => 'text',
844
                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
845
                'size' => 'large'
846
            ),
847
            'email_onhold_invoice_heading' => array(
848
                'id'   => 'email_onhold_invoice_heading',
849
                'name' => __( 'Email Heading', 'invoicing' ),
850
                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
851
                'type' => 'text',
852
                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
853
                'size' => 'large'
854
            ),
855
            'email_onhold_invoice_admin_bcc' => array(
856
                'id'   => 'email_onhold_invoice_admin_bcc',
857
                'name' => __( 'Enable Admin BCC', 'invoicing' ),
858
                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
859
                'type' => 'checkbox',
860
                'std'  => 1
861
            ),
862
        ),
863
        'processing_invoice' => array(
864
            'email_processing_invoice_header' => array(
865
                'id'   => 'email_processing_invoice_header',
866
                'name' => '<h3>' . __( 'Processing Invoice', 'invoicing' ) . '</h3>',
867
                'desc' => __( 'This is an invoice notification sent to users containing invoice details after payment.', 'invoicing' ),
868
                'type' => 'header',
869
            ),
870
            'email_processing_invoice_active' => array(
871
                'id'   => 'email_processing_invoice_active',
872
                'name' => __( 'Enable/Disable', 'invoicing' ),
873
                'desc' => __( 'Enable this email notification', 'invoicing' ),
874
                'type' => 'checkbox',
875
                'std'  => 1
876
            ),
877
            'email_processing_invoice_subject' => array(
878
                'id'   => 'email_processing_invoice_subject',
879
                'name' => __( 'Subject', 'invoicing' ),
880
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
881
                'type' => 'text',
882
                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
883
                'size' => 'large'
884
            ),
885
            'email_processing_invoice_heading' => array(
886
                'id'   => 'email_processing_invoice_heading',
887
                'name' => __( 'Email Heading', 'invoicing' ),
888
                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
889
                'type' => 'text',
890
                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
891
                'size' => 'large'
892
            ),
893
            'email_processing_invoice_admin_bcc' => array(
894
                'id'   => 'email_processing_invoice_admin_bcc',
895
                'name' => __( 'Enable Admin BCC', 'invoicing' ),
896
                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
897
                'type' => 'checkbox',
898
                'std'  => 1
899
            ),
900
        ),
901
        'completed_invoice' => array(
902
            'email_completed_invoice_header' => array(
903
                'id'   => 'email_completed_invoice_header',
904
                'name' => '<h3>' . __( 'Paid Invoice', 'invoicing' ) . '</h3>',
905
                'desc' => __( 'Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing' ),
906
                'type' => 'header',
907
            ),
908
            'email_completed_invoice_active' => array(
909
                'id'   => 'email_completed_invoice_active',
910
                'name' => __( 'Enable/Disable', 'invoicing' ),
911
                'desc' => __( 'Enable this email notification', 'invoicing' ),
912
                'type' => 'checkbox',
913
                'std'  => 1
914
            ),
915
            'email_completed_invoice_subject' => array(
916
                'id'   => 'email_completed_invoice_subject',
917
                'name' => __( 'Subject', 'invoicing' ),
918
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
919
                'type' => 'text',
920
                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing' ),
921
                'size' => 'large'
922
            ),
923
            'email_completed_invoice_heading' => array(
924
                'id'   => 'email_completed_invoice_heading',
925
                'name' => __( 'Email Heading', 'invoicing' ),
926
                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
927
                'type' => 'text',
928
                'std'  => __( 'Your invoice has been paid', 'invoicing' ),
929
                'size' => 'large'
930
            ),
931
            'email_completed_invoice_admin_bcc' => array(
932
                'id'   => 'email_completed_invoice_admin_bcc',
933
                'name' => __( 'Enable Admin BCC', 'invoicing' ),
934
                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
935
                'type' => 'checkbox',
936
            ),
937
            'std'  => 1
938
        ),
939
        'refunded_invoice' => array(
940
            'email_refunded_invoice_header' => array(
941
                'id'   => 'email_refunded_invoice_header',
942
                'name' => '<h3>' . __( 'Refunded Invoice', 'invoicing' ) . '</h3>',
943
                'desc' => __( 'Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing' ),
944
                'type' => 'header',
945
            ),
946
            'email_refunded_invoice_active' => array(
947
                'id'   => 'email_refunded_invoice_active',
948
                'name' => __( 'Enable/Disable', 'invoicing' ),
949
                'desc' => __( 'Enable this email notification', 'invoicing' ),
950
                'type' => 'checkbox',
951
                'std'  => 1
952
            ),
953
            'email_refunded_invoice_subject' => array(
954
                'id'   => 'email_refunded_invoice_subject',
955
                'name' => __( 'Subject', 'invoicing' ),
956
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
957
                'type' => 'text',
958
                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing' ),
959
                'size' => 'large'
960
            ),
961
            'email_refunded_invoice_heading' => array(
962
                'id'   => 'email_refunded_invoice_heading',
963
                'name' => __( 'Email Heading', 'invoicing' ),
964
                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
965
                'type' => 'text',
966
                'std'  => __( 'Your invoice has been refunded', 'invoicing' ),
967
                'size' => 'large'
968
            ),
969
            'email_refunded_invoice_admin_bcc' => array(
970
                'id'   => 'email_refunded_invoice_admin_bcc',
971
                'name' => __( 'Enable Admin BCC', 'invoicing' ),
972
                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
973
                'type' => 'checkbox',
974
                'std'  => 1
975
            ),
976
        ),
977
        'user_invoice' => array(
978
            'email_user_invoice_header' => array(
979
                'id'   => 'email_user_invoice_header',
980
                'name' => '<h3>' . __( 'Customer Invoice', 'invoicing' ) . '</h3>',
981
                'desc' => __( 'Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing' ),
982
                'type' => 'header',
983
            ),
984
            'email_user_invoice_active' => array(
985
                'id'   => 'email_user_invoice_active',
986
                'name' => __( 'Enable/Disable', 'invoicing' ),
987
                'desc' => __( 'Enable this email notification', 'invoicing' ),
988
                'type' => 'checkbox',
989
                'std'  => 1
990
            ),
991
            'email_user_invoice_subject' => array(
992
                'id'   => 'email_user_invoice_subject',
993
                'name' => __( 'Subject', 'invoicing' ),
994
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
995
                'type' => 'text',
996
                'std'  => __( '[{site_title}] Your invoice from {invoice_date}', 'invoicing' ),
997
                'size' => 'large'
998
            ),
999
            'email_user_invoice_heading' => array(
1000
                'id'   => 'email_user_invoice_heading',
1001
                'name' => __( 'Email Heading', 'invoicing' ),
1002
                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
1003
                'type' => 'text',
1004
                'std'  => __( 'Your invoice {invoice_number} details', 'invoicing' ),
1005
                'size' => 'large'
1006
            ),
1007
            'email_user_invoice_admin_bcc' => array(
1008
                'id'   => 'email_user_invoice_admin_bcc',
1009
                'name' => __( 'Enable Admin BCC', 'invoicing' ),
1010
                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
1011
                'type' => 'checkbox',
1012
                'std'  => 1
1013
            ),
1014
        ),
1015
        'user_note' => array(
1016
            'email_user_note_header' => array(
1017
                'id'   => 'email_user_note_header',
1018
                'name' => '<h3>' . __( 'Customer Note', 'invoicing' ) . '</h3>',
1019
                'desc' => __( 'Customer note emails are sent when you add a note to an invoice.', 'invoicing' ),
1020
                'type' => 'header',
1021
            ),
1022
            'email_user_note_active' => array(
1023
                'id'   => 'email_user_note_active',
1024
                'name' => __( 'Enable/Disable', 'invoicing' ),
1025
                'desc' => __( 'Enable this email notification', 'invoicing' ),
1026
                'type' => 'checkbox',
1027
                'std'  => 1
1028
            ),
1029
            'email_user_note_subject' => array(
1030
                'id'   => 'email_user_note_subject',
1031
                'name' => __( 'Subject', 'invoicing' ),
1032
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
1033
                'type' => 'text',
1034
                'std'  => __( '[{site_title}] Note added to your invoice #{invoice_number} from {invoice_date}', 'invoicing' ),
1035
                'size' => 'large'
1036
            ),
1037
            'email_user_note_heading' => array(
1038
                'id'   => 'email_user_note_heading',
1039
                'name' => __( 'Email Heading', 'invoicing' ),
1040
                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
1041
                'type' => 'text',
1042
                'std'  => __( 'A note has been added to your invoice', 'invoicing' ),
1043
                'size' => 'large'
1044
            ),
1045
        ),
1046
        'overdue' => array(
1047
            'email_overdue_header' => array(
1048
                'id'   => 'email_overdue_header',
1049
                'name' => '<h3>' . __( 'Payment Reminder', 'invoicing' ) . '</h3>',
1050
                'desc' => __( 'Payment reminder emails are sent to user automatically.', 'invoicing' ),
1051
                'type' => 'header',
1052
            ),
1053
            'email_overdue_active' => array(
1054
                'id'   => 'email_overdue_active',
1055
                'name' => __( 'Enable/Disable', 'invoicing' ),
1056
                'desc' => __( 'Enable this email notification', 'invoicing' ),
1057
                'type' => 'checkbox',
1058
                'std'  => 1
1059
            ),
1060
            'email_due_reminder_days' => array(
1061
                'id'        => 'email_due_reminder_days',
1062
                'name'      => __( 'When to Send', 'sliced-invoices' ),
1063
                'desc'      => __( 'Check when you would like payment reminders sent out.', 'invoicing' ),
1064
                'default'   => '',
1065
                'type'      => 'multicheck',
1066
                'options'   => $overdue_days_options,
1067
            ),
1068
            'email_overdue_subject' => array(
1069
                'id'   => 'email_overdue_subject',
1070
                'name' => __( 'Subject', 'invoicing' ),
1071
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
1072
                'type' => 'text',
1073
                'std'  => __( '[{site_title}] Payment Reminder', 'invoicing' ),
1074
                'size' => 'large'
1075
            ),
1076
            'email_overdue_heading' => array(
1077
                'id'   => 'email_overdue_heading',
1078
                'name' => __( 'Email Heading', 'invoicing' ),
1079
                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
1080
                'type' => 'text',
1081
                'std'  => __( 'Payment reminder for your invoice', 'invoicing' ),
1082
                'size' => 'large'
1083
            ),
1084
            'email_overdue_body' => array(
1085
                'id'   => 'email_overdue_body',
1086
                'name' => __( 'Email Content', 'invoicing' ),
1087
                'desc' => __( 'The content of the email.', 'invoicing' ),
1088
                'type' => 'rich_editor',
1089
                'std'  => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder 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 pay now for this invoice please use the following link: <a href="{invoice_pay_link}">Pay Now</a></p>', 'invoicing' ),
1090
                'class' => 'large',
1091
                'size'  => 10,
1092
            ),
1093
        ),
1094
    );
1095
1096
    return apply_filters( 'wpinv_get_emails', $emails );
1097
}
1098
1099
function wpinv_settings_emails( $settings = array() ) {
1100
    $emails = wpinv_get_emails();
1101
    
1102
    if ( !empty( $emails ) ) {
1103
        foreach ( $emails as $key => $email ) {
1104
            $settings[$key] = $email;
1105
        }
1106
    }
1107
    
1108
    return apply_filters( 'wpinv_settings_get_emails', $settings );
1109
}
1110
add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 );
1111
1112
function wpinv_settings_sections_emails( $settings ) {
1113
    $emails = wpinv_get_emails();
1114
    
1115
    if (!empty($emails)) {
1116
        foreach  ($emails as $key => $email) {
1117
            $settings[$key] = !empty( $email['email_' . $key . '_header']['name'] ) ? strip_tags( $email['email_' . $key . '_header']['name'] ) : $key;
1118
        }
1119
    }
1120
    
1121
    return $settings;    
1122
}
1123
add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 );
1124
1125
function wpinv_email_is_enabled( $email_type ) {
1126
    $emails = wpinv_get_emails();
1127
    $enabled = isset( $emails[$email_type] ) && wpinv_get_option( $email_type . '_active', 1 ) ? true : false;
0 ignored issues
show
Documentation introduced by
1 is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1128
1129
    return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type );
1130
}
1131
1132
function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1133
    switch ( $email_type ) {
1134
        case 'new_invoice':
1135
        case 'cancelled_invoice':
1136
        case 'failed_invoice':
1137
            $recipient  = wpinv_get_admin_email();
1138
        break;
1139
        default:
1140
            $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1141
            $recipient  = !empty( $invoice ) ? $invoice->get_email() : '';
1142
        break;
1143
    }
1144
    
1145
    return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice );
1146
}
1147
1148
function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1149
    $subject    = wpinv_get_option( 'email_' . $email_type . '_subject' );
1150
    
1151
    $subject    = wpinv_email_format_text( $subject );
1152
    
1153
    return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice );
1154
}
1155
1156
function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1157
    $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' );
1158
    
1159
    $email_heading = wpinv_email_format_text( $email_heading );
1160
    
1161
    return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice );
1162
}
1163
1164
function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1165
    $content    = wpinv_get_option( 'email_' . $email_type . '_body' );
1166
    
1167
    $content    = wpinv_email_format_text( $content );
1168
    
1169
    return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice );
1170
}
1171
1172
function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1173
    $from_name = wpinv_mail_get_from_address();
1174
    $from_email = wpinv_mail_get_from_address();
1175
    
1176
    $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1177
    
1178
    $headers    = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n";
1179
    $headers    .= "Reply-To: ". $from_email . "\r\n";
1180
    $headers    .= "Content-Type: " . wpinv_mail_get_content_type() . "\r\n";
1181
    
1182
    return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice );
1183
}
1184
1185
function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1186
    $attachments = array();
1187
    
1188
    return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice );
1189
}
1190
1191
function wpinv_email_global_vars() {
1192
    $blogname = wpinv_get_blogname();
1193
    
1194
    $search                 = array();
1195
    $replace                = array();
1196
    
1197
    $search['blogname']     = '{blogname}';
1198
    $search['sitename']     = '{sitename}';
1199
    $search['site-title']   = '{site_title}';
1200
    
1201
    $replace['blogname']    = $blogname;
1202
    $replace['sitename']    = $blogname;
1203
    $replace['site-title']  = $blogname;
1204
    
1205
    return apply_filters( 'wpinv_email_global_vars', array( $search, $replace ) );
1206
}
1207
1208
function wpinv_email_format_text( $content ) {
1209
    global $wpinv_email_search, $wpinv_email_replace;
1210
    
1211
    if ( empty( $wpinv_email_search ) ) {
1212
        $wpinv_email_search = array();
1213
    }
1214
    
1215
    if ( empty( $wpinv_email_replace ) ) {
1216
        $wpinv_email_replace = array();
1217
    }
1218
    
1219
    $wpinv_email_search     = (array)apply_filters( 'wpinv_email_format_text_search', $wpinv_email_search );
1220
    $wpinv_email_replace    = (array)apply_filters( 'wpinv_email_format_text_replace', $wpinv_email_replace );
1221
    
1222
    $global_vars    = wpinv_email_global_vars();
1223
    
1224
    $search         = array_merge( $global_vars[0], $wpinv_email_search );
1225
    $replace        = array_merge( $global_vars[1], $wpinv_email_replace );
1226
    
1227
    if ( empty( $search ) || empty( $replace ) || !is_array( $search ) || !is_array( $replace ) ) {
1228
        return  $content;
1229
    }
1230
        
1231
    return str_replace( $search, $replace, $content );
1232
}
1233
1234
function wpinv_email_style_body( $content ) {
1235
    // make sure we only inline CSS for html emails
1236
    if ( in_array( wpinv_mail_get_content_type(), array( 'text/html', 'multipart/alternative' ) ) && class_exists( 'DOMDocument' ) ) {
1237
        ob_start();
1238
        wpinv_get_template( 'emails/wpinv-email-styles.php' );
1239
        $css = apply_filters( 'wpinv_email_styles', ob_get_clean() );
1240
        
1241
        // apply CSS styles inline for picky email clients
1242
        try {
1243
            $emogrifier = new Emogrifier( $content, $css );
1244
            $content    = $emogrifier->emogrify();
1245
        } catch ( Exception $e ) {
1246
            wpinv_error_log( $e->getMessage(), 'emogrifier' );
1247
        }
1248
    }
1249
    return $content;
1250
}
1251
1252
function wpinv_email_header( $email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1253
    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 ) );
1254
}
1255
1256
/**
1257
 * Get the email footer.
1258
 */
1259
function wpinv_email_footer( $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1260
    wpinv_get_template( 'emails/wpinv-email-footer.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1261
}
1262
1263
function wpinv_email_wrap_message( $message ) {
1264
    // Buffer
1265
    ob_start();
1266
1267
    do_action( 'wpinv_email_header' );
1268
1269
    echo wpautop( wptexturize( $message ) );
1270
1271
    do_action( 'wpinv_email_footer' );
1272
1273
    // Get contents
1274
    $message = ob_get_clean();
1275
1276
    return $message;
1277
}
1278
1279
function wpinv_email_invoice_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1280
    wpinv_get_template( 'emails/wpinv-email-invoice-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1281
}
1282
1283
function wpinv_email_invoice_items( $invoice, $email_type = '', $sent_to_admin = false ) {
1284
    wpinv_get_template( 'emails/wpinv-email-invoice-items.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1285
}
1286
1287
function wpinv_email_billing_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1288
    wpinv_get_template( 'emails/wpinv-email-billing-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1289
}
1290
1291 View Code Duplication
function wpinv_send_customer_invoice( $data = array() ) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1292
    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1293
    
1294
    if ( empty( $invoice_id ) ) {
1295
        return;
1296
    }
1297
1298
    if ( !current_user_can( 'manage_options' ) ) {
1299
        wp_die( __( 'You do not have permission to send invoice notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1300
    }
1301
    
1302
    $sent = wpinv_user_invoice_notification( $invoice_id );
1303
    
1304
    $status = $sent ? 'email_sent' : 'email_fail';
1305
    
1306
    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1307
    wp_redirect( $redirect );
1308
    exit;
1309
}
1310
add_action( 'wpinv_send_invoice', 'wpinv_send_customer_invoice' );
1311
1312 View Code Duplication
function wpinv_send_overdue_reminder( $data = array() ) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1313
    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1314
    
1315
    if ( empty( $invoice_id ) ) {
1316
        return;
1317
    }
1318
1319
    if ( !current_user_can( 'manage_options' ) ) {
1320
        wp_die( __( 'You do not have permission to send reminder notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1321
    }
1322
    
1323
    $sent = wpinv_send_payment_reminder_notification( $invoice_id );
1324
    
1325
    $status = $sent ? 'email_sent' : 'email_fail';
1326
    
1327
    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1328
    wp_redirect( $redirect );
1329
    exit;
1330
}
1331
add_action( 'wpinv_send_reminder', 'wpinv_send_overdue_reminder' );
1332
1333
function wpinv_send_customer_note_email( $data ) {
1334
    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1335
    
1336
    if ( empty( $invoice_id ) ) {
1337
        return;
1338
    }
1339
    
1340
    $sent = wpinv_user_note_notification( $invoice_id, $data );
0 ignored issues
show
Unused Code introduced by
$sent is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1341
}
1342
add_action( 'wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1 );
1343
1344
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.

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

Loading history...
1345
    if ( !empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->ID, true ) ) {
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1346
        $date_format = get_option( 'date_format' );
1347
        $time_format = get_option( 'time_format' );
1348
        ?>
1349
        <div id="wpinv-email-notes">
1350
            <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3>
1351
            <ol class="wpinv-notes-lists">
1352
        <?php
1353
        foreach ( $invoice_notes as $note ) {
1354
            $note_time = strtotime( $note->comment_date );
1355
            ?>
1356
            <li class="comment wpinv-note">
1357
            <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>
1358
            <div class="wpinv-note-desc description"><?php echo wpautop( wptexturize( $note->comment_content ) ); ?></div>
1359
            </li>
1360
            <?php
1361
        }
1362
        ?>  </ol>
1363
        </div>
1364
        <?php
1365
    }
1366
}
1367
add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 );
1368
1369
function wpinv_email_payment_reminders() {    
1370
    global $wpi_auto_reminder;
1371
    if ( !wpinv_get_option( 'email_overdue_active' ) ) {
1372
        return;
1373
    }
1374
    
1375
    if ( $reminder_days = wpinv_get_option( 'email_due_reminder_days' ) ) {
1376
        $reminder_days  = is_array( $reminder_days ) ? array_values( $reminder_days ) : '';
1377
        
1378
        if ( empty( $reminder_days ) ) {
1379
            return;
1380
        }
1381
        $reminder_days  = array_unique( array_map( 'absint', $reminder_days ) );
1382
        
1383
        $args = array(
1384
            'post_type'     => 'wpi_invoice',
1385
            'post_status'   => 'pending',
1386
            'fields'        => 'ids',
1387
            'numberposts'   => '-1',
1388
            'meta_query'    => array(
1389
                array(
1390
                    'key'       =>  '_wpinv_due_date',
1391
                    'value'     =>  array( '', 'none' ),
1392
                    'compare'   =>  'NOT IN',
1393
                )
1394
            ),
1395
            'meta_key'      => '_wpinv_due_date',
1396
            'orderby'       => 'meta_value',
1397
            'order'         => 'ASC',
1398
        );
1399
        
1400
        $invoices = get_posts( $args );
1401
        
1402
        if ( empty( $invoices ) ) {
1403
            return;
1404
        }
1405
        
1406
        $date_to_send   = array();
1407
        
1408
        foreach ( $invoices as $id ) {
1409
            $due_date = get_post_meta( $id, '_wpinv_due_date', true );
1410
            
1411
            foreach ( $reminder_days as $key => $days ) {
1412
                if ( $days !== '' ) {
1413
                    $date_to_send[$id][] = date_i18n( 'Y-m-d', strtotime( $due_date ) + ( $days * DAY_IN_SECONDS ) );
1414
                }
1415
            }
1416
        }
1417
1418
        $today              = date_i18n( 'Y-m-d' );
1419
        $wpi_auto_reminder  = true;
1420
1421
        foreach ( $date_to_send as $id => $values ) {
1422
            if ( in_array( $today, $values ) ) {
1423
                $sent = get_post_meta( $id, '_wpinv_reminder_sent', true );
1424
1425
                if ( isset( $sent ) && !empty( $sent ) ) {
1426
                    if ( !in_array( $today, $sent ) ) {
1427
                        do_action( 'wpinv_send_payment_reminder_notification', $id );
1428
                    }
1429
                } else {
1430
                    do_action( 'wpinv_send_payment_reminder_notification', $id );
1431
                }
1432
            }
1433
        }
1434
        
1435
        $wpi_auto_reminder  = false;
1436
    }
1437
}
1438
1439
function wpinv_send_payment_reminder_notification( $invoice_id ) {
1440
    global $wpinv_email_search, $wpinv_email_replace;
1441
    
1442
    $email_type = 'overdue';
1443
    if ( !wpinv_email_is_enabled( $email_type ) ) {
1444
        return false;
1445
    }
1446
    
1447
    $invoice    = wpinv_get_invoice( $invoice_id );
1448
    if ( empty( $invoice ) ) {
1449
        return false;
1450
    }
1451
    
1452
    if ( !$invoice->needs_payment() ) {
1453
        return false;
1454
    }
1455
    
1456
    $recipient  = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1457
    if ( !is_email( $recipient ) ) {
1458
        return false;
1459
    }
1460
        
1461
    $search                     = array();
1462
    $search['full_name']        = '{full_name}';
1463
    $search['invoice_number']   = '{invoice_number}';
1464
    $search['invoice_due_date'] = '{invoice_due_date}';
1465
    $search['invoice_total']    = '{invoice_total}';
1466
    $search['invoice_link']     = '{invoice_link}';
1467
    $search['invoice_pay_link'] = '{invoice_pay_link}';
1468
    $search['is_was']           = '{is_was}';
1469
    
1470
    $replace                    = array();
1471
    $replace['full_name']       = $invoice->get_user_full_name();
1472
    $replace['invoice_number']  = $invoice->get_number();
1473
    $replace['invoice_due_date']= $invoice->get_due_date( true );
1474
    $replace['invoice_total']   = $invoice->get_total( true );
1475
    $replace['invoice_link']    = $invoice->get_view_url( true );
1476
    $replace['invoice_pay_link']= $invoice->get_checkout_payment_url( false, true );
1477
    $replace['is_was']          = strtotime( $invoice->get_due_date() ) < strtotime( date_i18n( 'Y-m-d' ) ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' );
1478
1479
    $wpinv_email_search         = $search;
1480
    $wpinv_email_replace        = $replace;
1481
    
1482
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1483
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1484
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1485
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1486
    
1487
    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1488
    
1489
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
1490
            'invoice'       => $invoice,
1491
            'email_type'    => $email_type,
1492
            'email_heading' => $email_heading,
1493
            'sent_to_admin' => false,
1494
            'plain_text'    => false,
1495
            'message_body'  => $message_body
1496
        ) );
1497
        
1498
    $content        = wpinv_email_format_text( $content );
1499
1500
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
1501
    if ( $sent ) {
1502
        do_action( 'wpinv_payment_reminder_sent', $invoice_id, $invoice );
1503
    }
1504
        
1505
    return $sent;
1506
}
1507
add_action( 'wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1 );
1508
1509
function wpinv_payment_reminder_sent( $invoice_id, $invoice ) {
1510
    global $wpi_auto_reminder;
1511
    
1512
    $sent = get_post_meta( $invoice_id, '_wpinv_reminder_sent', true );
1513
    
1514
    if ( empty( $sent ) ) {
1515
        $sent = array();
1516
    }
1517
    $sent[] = date_i18n( 'Y-m-d' );
1518
    
1519
    update_post_meta( $invoice_id, '_wpinv_reminder_sent', $sent );
1520
    
1521
    if ( $wpi_auto_reminder ) { // Auto reminder note.
1522
        $note = __( 'Manual reminder sent to the user.', 'invoicing' );
1523
        $invoice->add_note( $note, false, false, true );
1524
    } else { // Menual reminder note.
1525
        $note = __( 'Manual reminder sent to the user.', 'invoicing' );
1526
        $invoice->add_note( $note );
1527
    }
1528
}
1529
add_action( 'wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2 );
1530
1531
function wpinv_email_before_note_details( $invoice, $email_type, $sent_to_admin, $customer_note ) {
0 ignored issues
show
Unused Code introduced by
The parameter $email_type is not used and could be removed.

This check looks from 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 $sent_to_admin is not used and could be removed.

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

Loading history...
1532
    if("wpi_invoice" === $invoice->post_type && !empty($customer_note)){
1533
        $before_note = '';
1534
        $before_note .= __( 'Hello, a note has just been added to your invoice:', 'invoicing' );
1535
        $before_note .= '<blockquote class="wpinv-note">'.wpautop( wptexturize( $customer_note ) ).'</blockquote>';
1536
        $before_note .= __( 'For your reference, your invoice details are shown below.', 'invoicing' );
1537
        echo $before_note;
1538
    }
1539
}