Passed
Pull Request — master (#113)
by
unknown
03:31
created

wpinv-email-functions.php ➔ wpinv_email_format_text()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 27
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 20
nc 4
nop 2
dl 0
loc 27
rs 8.8571
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_wpi-pending_to_wpi-processing',
17
        'wpinv_status_wpi-pending_to_publish',
18
        'wpinv_status_wpi-pending_to_wpi-cancelled',
19
        'wpinv_status_wpi-pending_to_wpi-failed',
20
        'wpinv_status_wpi-pending_to_wpi-onhold',
21
        'wpinv_status_wpi-failed_to_wpi-processing',
22
        'wpinv_status_wpi-failed_to_publish',
23
        'wpinv_status_wpi-failed_to_wpi-onhold',
24
        'wpinv_status_wpi-onhold_wpi-to_processing',
25
        'wpinv_status_wpi-onhold_to_wpi-cancelled',
26
        'wpinv_status_wpi-onhold_to_wpi-failed',
27
        'wpinv_status_publish',
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_wpi-pending_to_wpi-processing_notification', 'wpinv_new_invoice_notification' );
41
add_action( 'wpinv_status_wpi-pending_to_publish_notification', 'wpinv_new_invoice_notification' );
42
add_action( 'wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_new_invoice_notification' );
43
add_action( 'wpinv_status_wpi-failed_to_wpi-processing_notification', 'wpinv_new_invoice_notification' );
44
add_action( 'wpinv_status_wpi-failed_to_publish_notification', 'wpinv_new_invoice_notification' );
45
add_action( 'wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_new_invoice_notification' );
46
47
// Cancelled invoice email
48
add_action( 'wpinv_status_wpi-pending_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification' );
49
add_action( 'wpinv_status_wpi-onhold_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification' );
50
51
// Failed invoice email
52
add_action( 'wpinv_status_wpi-pending_to_wpi-failed_notification', 'wpinv_failed_invoice_notification' );
53
add_action( 'wpinv_status_wpi-onhold_to_wpi-failed_notification', 'wpinv_failed_invoice_notification' );
54
55
// On hold invoice email
56
add_action( 'wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification' );
57
add_action( 'wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification' );
58
59
// Processing invoice email
60
add_action( 'wpinv_status_wpi-pending_to_wpi-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
78
function wpinv_send_transactional_email() {
79
    $args       = func_get_args();
80
    $function   = current_filter() . '_notification';
81
    do_action_ref_array( $function, $args );
82
}
83
    
84 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...
85
    $email_type = 'new_invoice';
86
    if ( !wpinv_email_is_enabled( $email_type ) ) {
87
        return false;
88
    }
89
    
90
    $invoice = wpinv_get_invoice( $invoice_id );
91
    if ( empty( $invoice ) ) {
92
        return false;
93
    }
94
95
    if ( !("wpi_invoice" === $invoice->post_type) ) {
96
        return false;
97
    }
98
    
99
    $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...
100
    if ( !is_email( $recipient ) ) {
101
        return false;
102
    }
103
104
    $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...
105
    $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...
106
    $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...
107
    $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...
108
    $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...
109
    
110
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
111
            'invoice'       => $invoice,
112
            'email_type'    => $email_type,
113
            'email_heading' => $email_heading,
114
            'sent_to_admin' => true,
115
            'plain_text'    => false,
116
            'message_body'    => $message_body,
117
        ) );
118
    
119
    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
120
}
121
122 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...
123
    $email_type = 'cancelled_invoice';
124
    if ( !wpinv_email_is_enabled( $email_type ) ) {
125
        return false;
126
    }
127
    
128
    $invoice = wpinv_get_invoice( $invoice_id );
129
    if ( empty( $invoice ) ) {
130
        return false;
131
    }
132
133
    if ( !("wpi_invoice" === $invoice->post_type) ) {
134
        return false;
135
    }
136
    
137
    $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...
138
    if ( !is_email( $recipient ) ) {
139
        return false;
140
    }
141
    
142
    $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...
143
    $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...
144
    $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...
145
    $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...
146
    $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...
147
    
148
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
149
            'invoice'       => $invoice,
150
            'email_type'    => $email_type,
151
            'email_heading' => $email_heading,
152
            'sent_to_admin' => true,
153
            'plain_text'    => false,
154
            'message_body'    => $message_body,
155
        ) );
156
    
157
    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
158
}
159
160 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...
161
    $email_type = 'failed_invoice';
162
    if ( !wpinv_email_is_enabled( $email_type ) ) {
163
        return false;
164
    }
165
    
166
    $invoice = wpinv_get_invoice( $invoice_id );
167
    if ( empty( $invoice ) ) {
168
        return false;
169
    }
170
171
    if ( !("wpi_invoice" === $invoice->post_type) ) {
172
        return false;
173
    }
174
    
175
    $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...
176
    if ( !is_email( $recipient ) ) {
177
        return false;
178
    }
179
    
180
    $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...
181
    $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...
182
    $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...
183
    $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...
184
    $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...
185
    
186
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
187
            'invoice'       => $invoice,
188
            'email_type'    => $email_type,
189
            'email_heading' => $email_heading,
190
            'sent_to_admin' => true,
191
            'plain_text'    => false,
192
            'message_body'    => $message_body,
193
        ) );
194
    
195
    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
196
}
197
198 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...
199
    $email_type = 'onhold_invoice';
200
    if ( !wpinv_email_is_enabled( $email_type ) ) {
201
        return false;
202
    }
203
    
204
    $invoice = wpinv_get_invoice( $invoice_id );
205
    if ( empty( $invoice ) ) {
206
        return false;
207
    }
208
209
    if ( !("wpi_invoice" === $invoice->post_type) ) {
210
        return false;
211
    }
212
    
213
    $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...
214
    if ( !is_email( $recipient ) ) {
215
        return false;
216
    }
217
    
218
    $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...
219
    $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...
220
    $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...
221
    $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...
222
    $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...
223
    
224
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
225
            'invoice'       => $invoice,
226
            'email_type'    => $email_type,
227
            'email_heading' => $email_heading,
228
            'sent_to_admin' => false,
229
            'plain_text'    => false,
230
            'message_body'    => $message_body,
231
        ) );
232
    
233
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
234
    
235
    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
236
        $recipient  = wpinv_get_admin_email();
237
        $subject    .= ' - ADMIN BCC COPY';
238
        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
239
    }
240
    
241
    return $sent;
242
}
243
244 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...
245
    $email_type = 'processing_invoice';
246
    if ( !wpinv_email_is_enabled( $email_type ) ) {
247
        return false;
248
    }
249
    
250
    $invoice = wpinv_get_invoice( $invoice_id );
251
    if ( empty( $invoice ) ) {
252
        return false;
253
    }
254
255
    if ( !("wpi_invoice" === $invoice->post_type) ) {
256
        return false;
257
    }
258
    
259
    $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...
260
    if ( !is_email( $recipient ) ) {
261
        return false;
262
    }
263
    
264
    $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...
265
    $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...
266
    $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...
267
    $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...
268
    $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...
269
    
270
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
271
            'invoice'       => $invoice,
272
            'email_type'    => $email_type,
273
            'email_heading' => $email_heading,
274
            'sent_to_admin' => false,
275
            'plain_text'    => false,
276
            'message_body'    => $message_body,
277
        ) );
278
    
279
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
280
    
281
    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
282
        $recipient  = wpinv_get_admin_email();
283
        $subject    .= ' - ADMIN BCC COPY';
284
        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
285
    }
286
    
287
    return $sent;
288
}
289
290 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...
291
    $email_type = 'completed_invoice';
292
    if ( !wpinv_email_is_enabled( $email_type ) ) {
293
        return false;
294
    }
295
    
296
    $invoice = wpinv_get_invoice( $invoice_id );
297
    if ( empty( $invoice ) ) {
298
        return false;
299
    }
300
301
    if ( !("wpi_invoice" === $invoice->post_type) ) {
302
        return false;
303
    }
304
    
305
    $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...
306
    if ( !is_email( $recipient ) ) {
307
        return false;
308
    }
309
    
310
    $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...
311
    $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...
312
    $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...
313
    $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...
314
    $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...
315
    
316
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
317
            'invoice'       => $invoice,
318
            'email_type'    => $email_type,
319
            'email_heading' => $email_heading,
320
            'sent_to_admin' => false,
321
            'plain_text'    => false,
322
            'message_body'    => $message_body,
323
        ) );
324
    
325
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
326
    
327
    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
328
        $recipient  = wpinv_get_admin_email();
329
        $subject    .= ' - ADMIN BCC COPY';
330
        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
331
    }
332
    
333
    return $sent;
334
}
335
336 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...
337
    $email_type = 'refunded_invoice';
338
    if ( !wpinv_email_is_enabled( $email_type ) ) {
339
        return false;
340
    }
341
    
342
    $invoice = wpinv_get_invoice( $invoice_id );
343
    if ( empty( $invoice ) ) {
344
        return false;
345
    }
346
347
    if ( !("wpi_invoice" === $invoice->post_type) ) {
348
        return false;
349
    }
350
    
351
    $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...
352
    if ( !is_email( $recipient ) ) {
353
        return false;
354
    }
355
    
356
    $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...
357
    $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...
358
    $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...
359
    $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...
360
    $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...
361
    
362
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
363
            'invoice'           => $invoice,
364
            'email_type'        => $email_type,
365
            'email_heading'     => $email_heading,
366
            'sent_to_admin'     => false,
367
            'plain_text'        => false,
368
            'message_body'    => $message_body,
369
        ) );
370
    
371
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
372
    
373
    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
374
        $recipient  = wpinv_get_admin_email();
375
        $subject    .= ' - ADMIN BCC COPY';
376
        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
377
    }
378
    
379
    return $sent;
380
}
381
382 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...
383
    $email_type = 'refunded_invoice';
384
    if ( !wpinv_email_is_enabled( $email_type ) ) {
385
        return false;
386
    }
387
    
388
    $invoice = wpinv_get_invoice( $invoice_id );
389
    if ( empty( $invoice ) ) {
390
        return false;
391
    }
392
393
    if ( !("wpi_invoice" === $invoice->post_type) ) {
394
        return false;
395
    }
396
    
397
    $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...
398
    if ( !is_email( $recipient ) ) {
399
        return false;
400
    }
401
    
402
    $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...
403
    $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...
404
    $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...
405
    $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...
406
    $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...
407
408
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
409
            'invoice'           => $invoice,
410
            'email_type'        => $email_type,
411
            'email_heading'     => $email_heading,
412
            'sent_to_admin'     => false,
413
            'plain_text'        => false,
414
            'partial_refund'    => true,
415
            'message_body'    => $message_body,
416
        ) );
417
    
418
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
419
    
420
    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
421
        $recipient  = wpinv_get_admin_email();
422
        $subject    .= ' - ADMIN BCC COPY';
423
        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
424
    }
425
    
426
    return $sent;
427
}
428
429
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...
430
}
431
432
function wpinv_user_invoice_notification( $invoice_id ) {
433
    $email_type = 'user_invoice';
434
    if ( !wpinv_email_is_enabled( $email_type ) ) {
435
        return false;
436
    }
437
    
438
    $invoice = wpinv_get_invoice( $invoice_id );
439
    if ( empty( $invoice ) ) {
440
        return false;
441
    }
442
443
    if ( !("wpi_invoice" === $invoice->post_type) ) {
444
        return false;
445
    }
446
    
447
    $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...
448
    if ( !is_email( $recipient ) ) {
449
        return false;
450
    }
451
    
452
    $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...
453
    $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...
454
    $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...
455
    $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...
456
    $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...
457
    
458
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
459
            'invoice'       => $invoice,
460
            'email_type'    => $email_type,
461
            'email_heading' => $email_heading,
462
            'sent_to_admin' => false,
463
            'plain_text'    => false,
464
            'message_body'  => $message_body
465
        ) );
466
    
467
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
468
    
469
    if ( $sent ) {
470
        $note = __( 'Invoice has been emailed to the user.', 'invoicing' );
471
    } else {
472
        $note = __( 'Fail to send invoice to the user!', 'invoicing' );
473
    }
474
    
475
    $invoice->add_note( $note, '', '', true ); // Add system note.
0 ignored issues
show
Documentation introduced by
'' is of type string, 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...
476
477
    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
478
        $recipient  = wpinv_get_admin_email();
479
        $subject    .= ' - ADMIN BCC COPY';
480
        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
481
    }
482
    
483
    return $sent;
484
}
485
486
function wpinv_user_note_notification( $invoice_id, $args = array() ) {
487
    $email_type = 'user_note';
488
    if ( !wpinv_email_is_enabled( $email_type ) ) {
489
        return false;
490
    }
491
    
492
    $invoice = wpinv_get_invoice( $invoice_id );
493
    if ( empty( $invoice ) ) {
494
        return false;
495
    }
496
    
497
    $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...
498
    if ( !is_email( $recipient ) ) {
499
        return false;
500
    }
501
    
502
    $defaults = array(
503
        'user_note' => ''
504
    );
505
506
    $args = wp_parse_args( $args, $defaults );
507
    
508
    $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...
509
    $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...
510
    $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...
511
    $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...
512
    $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...
513
    $message_body = str_replace( '{customer_note}', $args['user_note'], $message_body );
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
            'message_body'  => $message_body,
522
        ) );
523
        
524
    $content = wpinv_email_format_text( $content, $invoice );
525
    
526
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
527
        
528
    return $sent;
529
}
530
531
function wpinv_mail_get_from_address() {
532
    $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) );
533
    return sanitize_email( $from_address );
534
}
535
536
function wpinv_mail_get_from_name() {
537
    $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name' ) );
538
    return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES );
539
}
540
541
function wpinv_mail_admin_bcc_active( $mail_type = '' ) {
542
    $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) );
543
    return ( $active ? true : false );
544
}
545
    
546
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...
547
    $email_type = apply_filters( 'wpinv_mail_content_type', $email_type );
548
    
549
    switch ( $email_type ) {
550
        case 'html' :
551
            $content_type = 'text/html';
552
            break;
553
        case 'multipart' :
554
            $content_type = 'multipart/alternative';
555
            break;
556
        default :
557
            $content_type = 'text/plain';
558
            break;
559
    }
560
    
561
    return $content_type;
562
}
563
    
564
function wpinv_mail_send( $to, $subject, $message, $headers, $attachments ) {
565
    add_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
566
    add_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
567
    add_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
568
569
    $message = wpinv_email_style_body( $message );
570
    $message = apply_filters( 'wpinv_mail_content', $message );
571
    
572
    $sent  = wp_mail( $to, $subject, $message, $headers, $attachments );
573
    
574
    if ( !$sent ) {
575
        $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 );
576
        wpinv_error_log( $log_message, __( "Email from Invoicing plugin failed to send", 'invoicing' ), __FILE__, __LINE__ );
577
    }
578
579
    remove_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
580
    remove_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
581
    remove_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
582
583
    return $sent;
584
}
585
    
586
function wpinv_get_emails() {
587
    $overdue_days_options       = array();
588
    $overdue_days_options[0]    = __( 'On the Due Date', 'invoicing' );
589
    $overdue_days_options[1]    = __( '1 day after Due Date', 'invoicing' );
590
    
591
    for ( $i = 2; $i <= 10; $i++ ) {
592
        $overdue_days_options[$i]   = wp_sprintf( __( '%d days after Due Date', 'invoicing' ), $i );
593
    }
594
595
    // Default, built-in gateways
596
    $emails = array(
597
            'new_invoice' => array(
598
            'email_new_invoice_header' => array(
599
                'id'   => 'email_new_invoice_header',
600
                'name' => '<h3>' . __( 'New Invoice', 'invoicing' ) . '</h3>',
601
                'desc' => __( 'New invoice emails are sent to admin when a new invoice is received.', 'invoicing' ),
602
                'type' => 'header',
603
            ),
604
            'email_new_invoice_active' => array(
605
                'id'   => 'email_new_invoice_active',
606
                'name' => __( 'Enable/Disable', 'invoicing' ),
607
                'desc' => __( 'Enable this email notification', 'invoicing' ),
608
                'type' => 'checkbox',
609
                'std'  => 1
610
            ),
611
            'email_new_invoice_subject' => array(
612
                'id'   => 'email_new_invoice_subject',
613
                'name' => __( 'Subject', 'invoicing' ),
614
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
615
                'type' => 'text',
616
                'std'  => __( '[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing' ),
617
                'size' => 'large'
618
            ),
619
            'email_new_invoice_heading' => array(
620
                'id'   => 'email_new_invoice_heading',
621
                'name' => __( 'Email Heading', 'invoicing' ),
622
                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
623
                'type' => 'text',
624
                'std'  => __( 'New payment invoice', 'invoicing' ),
625
                'size' => 'large'
626
            ),
627
            'email_new_invoice_body' => array(
628
                'id'   => 'email_new_invoice_body',
629
                'name' => __( 'Email Content', 'invoicing' ),
630
                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
631
                'type' => 'rich_editor',
632
                'std'  => __( '<p>Hi Admin,</p><p>You have received payment from {name}..</p>', 'invoicing' ),
633
                'class' => 'large',
634
                'size' => '10'
635
            ),
636
        ),
637
        'cancelled_invoice' => array(
638
            'email_cancelled_invoice_header' => array(
639
                'id'   => 'email_cancelled_invoice_header',
640
                'name' => '<h3>' . __( 'Cancelled Invoice', 'invoicing' ) . '</h3>',
641
                'desc' => __( 'Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing' ),
642
                'type' => 'header',
643
            ),
644
            'email_cancelled_invoice_active' => array(
645
                'id'   => 'email_cancelled_invoice_active',
646
                'name' => __( 'Enable/Disable', 'invoicing' ),
647
                'desc' => __( 'Enable this email notification', 'invoicing' ),
648
                'type' => 'checkbox',
649
                'std'  => 1
650
            ),
651
            'email_cancelled_invoice_subject' => array(
652
                'id'   => 'email_cancelled_invoice_subject',
653
                'name' => __( 'Subject', 'invoicing' ),
654
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
655
                'type' => 'text',
656
                'std'  => __( '[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing' ),
657
                'size' => 'large'
658
            ),
659
            'email_cancelled_invoice_heading' => array(
660
                'id'   => 'email_cancelled_invoice_heading',
661
                'name' => __( 'Email Heading', 'invoicing' ),
662
                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
663
                'type' => 'text',
664
                'std'  => __( 'Cancelled invoice', 'invoicing' ),
665
                'size' => 'large'
666
            ),
667
            'email_cancelled_invoice_body' => array(
668
                'id'   => 'email_cancelled_invoice_body',
669
                'name' => __( 'Email Content', 'invoicing' ),
670
                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
671
                'type' => 'rich_editor',
672
                'std'  => __( '<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing' ),
673
                'class' => 'large',
674
                'size' => '10'
675
            ),
676
        ),
677
        'failed_invoice' => array(
678
            'email_failed_invoice_header' => array(
679
                'id'   => 'email_failed_invoice_header',
680
                'name' => '<h3>' . __( 'Failed Invoice', 'invoicing' ) . '</h3>',
681
                'desc' => __( 'Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing' ),
682
                'type' => 'header',
683
            ),
684
            'email_failed_invoice_active' => array(
685
                'id'   => 'email_failed_invoice_active',
686
                'name' => __( 'Enable/Disable', 'invoicing' ),
687
                'desc' => __( 'Enable this email notification', 'invoicing' ),
688
                'type' => 'checkbox',
689
                'std'  => 1
690
            ),
691
            'email_failed_invoice_subject' => array(
692
                'id'   => 'email_failed_invoice_subject',
693
                'name' => __( 'Subject', 'invoicing' ),
694
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
695
                'type' => 'text',
696
                'std'  => __( '[{site_title}] Failed invoice ({invoice_number})', 'invoicing' ),
697
                'size' => 'large'
698
            ),
699
            'email_failed_invoice_heading' => array(
700
                'id'   => 'email_failed_invoice_heading',
701
                'name' => __( 'Email Heading', 'invoicing' ),
702
                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
703
                'type' => 'text',
704
                'std'  => __( 'Failed invoice', 'invoicing' ),
705
                'size' => 'large'
706
            ),
707
            'email_failed_invoice_body' => array(
708
                'id'   => 'email_failed_invoice_body',
709
                'name' => __( 'Email Content', 'invoicing' ),
710
                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
711
                'type' => 'rich_editor',
712
                'std'  => __( '<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing' ),
713
                'class' => 'large',
714
                'size' => '10'
715
            ),
716
        ),
717
        'onhold_invoice' => array(
718
            'email_onhold_invoice_header' => array(
719
                'id'   => 'email_onhold_invoice_header',
720
                'name' => '<h3>' . __( 'On Hold Invoice', 'invoicing' ) . '</h3>',
721
                'desc' => __( 'This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing' ),
722
                'type' => 'header',
723
            ),
724
            'email_onhold_invoice_active' => array(
725
                'id'   => 'email_onhold_invoice_active',
726
                'name' => __( 'Enable/Disable', 'invoicing' ),
727
                'desc' => __( 'Enable this email notification', 'invoicing' ),
728
                'type' => 'checkbox',
729
                'std'  => 1
730
            ),
731
            'email_onhold_invoice_subject' => array(
732
                'id'   => 'email_onhold_invoice_subject',
733
                'name' => __( 'Subject', 'invoicing' ),
734
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
735
                'type' => 'text',
736
                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
737
                'size' => 'large'
738
            ),
739
            'email_onhold_invoice_heading' => array(
740
                'id'   => 'email_onhold_invoice_heading',
741
                'name' => __( 'Email Heading', 'invoicing' ),
742
                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
743
                'type' => 'text',
744
                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
745
                'size' => 'large'
746
            ),
747
            'email_onhold_invoice_admin_bcc' => array(
748
                'id'   => 'email_onhold_invoice_admin_bcc',
749
                'name' => __( 'Enable Admin BCC', 'invoicing' ),
750
                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
751
                'type' => 'checkbox',
752
                'std'  => 1
753
            ),
754
            'email_onhold_invoice_body' => array(
755
                'id'   => 'email_onhold_invoice_body',
756
                'name' => __( 'Email Content', 'invoicing' ),
757
                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
758
                'type' => 'rich_editor',
759
                'std'  => __( '<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing' ),
760
                'class' => 'large',
761
                'size' => '10'
762
            ),
763
        ),
764
        'processing_invoice' => array(
765
            'email_processing_invoice_header' => array(
766
                'id'   => 'email_processing_invoice_header',
767
                'name' => '<h3>' . __( 'Processing Invoice', 'invoicing' ) . '</h3>',
768
                'desc' => __( 'This is an invoice notification sent to users containing invoice details after payment.', 'invoicing' ),
769
                'type' => 'header',
770
            ),
771
            'email_processing_invoice_active' => array(
772
                'id'   => 'email_processing_invoice_active',
773
                'name' => __( 'Enable/Disable', 'invoicing' ),
774
                'desc' => __( 'Enable this email notification', 'invoicing' ),
775
                'type' => 'checkbox',
776
                'std'  => 1
777
            ),
778
            'email_processing_invoice_subject' => array(
779
                'id'   => 'email_processing_invoice_subject',
780
                'name' => __( 'Subject', 'invoicing' ),
781
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
782
                'type' => 'text',
783
                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
784
                'size' => 'large'
785
            ),
786
            'email_processing_invoice_heading' => array(
787
                'id'   => 'email_processing_invoice_heading',
788
                'name' => __( 'Email Heading', 'invoicing' ),
789
                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
790
                'type' => 'text',
791
                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
792
                'size' => 'large'
793
            ),
794
            'email_processing_invoice_admin_bcc' => array(
795
                'id'   => 'email_processing_invoice_admin_bcc',
796
                'name' => __( 'Enable Admin BCC', 'invoicing' ),
797
                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
798
                'type' => 'checkbox',
799
                'std'  => 1
800
            ),
801
            'email_processing_invoice_body' => array(
802
                'id'   => 'email_processing_invoice_body',
803
                'name' => __( 'Email Content', 'invoicing' ),
804
                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
805
                'type' => 'rich_editor',
806
                'std'  => __( '<p>Hi {name},</p><p>Your invoice has been received and is now being processed.</p>', 'invoicing' ),
807
                'class' => 'large',
808
                'size' => '10'
809
            ),
810
        ),
811
        'completed_invoice' => array(
812
            'email_completed_invoice_header' => array(
813
                'id'   => 'email_completed_invoice_header',
814
                'name' => '<h3>' . __( 'Paid Invoice', 'invoicing' ) . '</h3>',
815
                'desc' => __( 'Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing' ),
816
                'type' => 'header',
817
            ),
818
            'email_completed_invoice_active' => array(
819
                'id'   => 'email_completed_invoice_active',
820
                'name' => __( 'Enable/Disable', 'invoicing' ),
821
                'desc' => __( 'Enable this email notification', 'invoicing' ),
822
                'type' => 'checkbox',
823
                'std'  => 1
824
            ),
825
            'email_completed_invoice_subject' => array(
826
                'id'   => 'email_completed_invoice_subject',
827
                'name' => __( 'Subject', 'invoicing' ),
828
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
829
                'type' => 'text',
830
                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing' ),
831
                'size' => 'large'
832
            ),
833
            'email_completed_invoice_heading' => array(
834
                'id'   => 'email_completed_invoice_heading',
835
                'name' => __( 'Email Heading', 'invoicing' ),
836
                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
837
                'type' => 'text',
838
                'std'  => __( 'Your invoice has been paid', 'invoicing' ),
839
                'size' => 'large'
840
            ),
841
            'email_completed_invoice_admin_bcc' => array(
842
                'id'   => 'email_completed_invoice_admin_bcc',
843
                'name' => __( 'Enable Admin BCC', 'invoicing' ),
844
                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
845
                'type' => 'checkbox',
846
            ),
847
            'email_completed_invoice_body' => array(
848
                'id'   => 'email_processing_invoice_body',
849
                'name' => __( 'Email Content', 'invoicing' ),
850
                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
851
                'type' => 'rich_editor',
852
                'std'  => __( '<p>Hi {name},</p><p>Your recent invoice on {site_title} has been paid.</p>', 'invoicing' ),
853
                'class' => 'large',
854
                'size' => '10'
855
            ),
856
            'std'  => 1
857
        ),
858
        'refunded_invoice' => array(
859
            'email_refunded_invoice_header' => array(
860
                'id'   => 'email_refunded_invoice_header',
861
                'name' => '<h3>' . __( 'Refunded Invoice', 'invoicing' ) . '</h3>',
862
                'desc' => __( 'Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing' ),
863
                'type' => 'header',
864
            ),
865
            'email_refunded_invoice_active' => array(
866
                'id'   => 'email_refunded_invoice_active',
867
                'name' => __( 'Enable/Disable', 'invoicing' ),
868
                'desc' => __( 'Enable this email notification', 'invoicing' ),
869
                'type' => 'checkbox',
870
                'std'  => 1
871
            ),
872
            'email_refunded_invoice_subject' => array(
873
                'id'   => 'email_refunded_invoice_subject',
874
                'name' => __( 'Subject', 'invoicing' ),
875
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
876
                'type' => 'text',
877
                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing' ),
878
                'size' => 'large'
879
            ),
880
            'email_refunded_invoice_heading' => array(
881
                'id'   => 'email_refunded_invoice_heading',
882
                'name' => __( 'Email Heading', 'invoicing' ),
883
                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
884
                'type' => 'text',
885
                'std'  => __( 'Your invoice has been refunded', 'invoicing' ),
886
                'size' => 'large'
887
            ),
888
            'email_refunded_invoice_admin_bcc' => array(
889
                'id'   => 'email_refunded_invoice_admin_bcc',
890
                'name' => __( 'Enable Admin BCC', 'invoicing' ),
891
                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
892
                'type' => 'checkbox',
893
                'std'  => 1
894
            ),
895
            'email_refunded_invoice_body' => array(
896
                'id'   => 'email_refunded_invoice_body',
897
                'name' => __( 'Email Content', 'invoicing' ),
898
                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
899
                'type' => 'rich_editor',
900
                'std'  => __( '<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing' ),
901
                'class' => 'large',
902
                'size' => '10'
903
            ),
904
        ),
905
        'user_invoice' => array(
906
            'email_user_invoice_header' => array(
907
                'id'   => 'email_user_invoice_header',
908
                'name' => '<h3>' . __( 'Customer Invoice', 'invoicing' ) . '</h3>',
909
                'desc' => __( 'Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing' ),
910
                'type' => 'header',
911
            ),
912
            'email_user_invoice_active' => array(
913
                'id'   => 'email_user_invoice_active',
914
                'name' => __( 'Enable/Disable', 'invoicing' ),
915
                'desc' => __( 'Enable this email notification', 'invoicing' ),
916
                'type' => 'checkbox',
917
                'std'  => 1
918
            ),
919
            'email_user_invoice_subject' => array(
920
                'id'   => 'email_user_invoice_subject',
921
                'name' => __( 'Subject', 'invoicing' ),
922
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
923
                'type' => 'text',
924
                'std'  => __( '[{site_title}] Your invoice from {invoice_date}', 'invoicing' ),
925
                'size' => 'large'
926
            ),
927
            'email_user_invoice_heading' => array(
928
                'id'   => 'email_user_invoice_heading',
929
                'name' => __( 'Email Heading', 'invoicing' ),
930
                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
931
                'type' => 'text',
932
                'std'  => __( 'Your invoice {invoice_number} details', 'invoicing' ),
933
                'size' => 'large'
934
            ),
935
            'email_user_invoice_admin_bcc' => array(
936
                'id'   => 'email_user_invoice_admin_bcc',
937
                'name' => __( 'Enable Admin BCC', 'invoicing' ),
938
                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
939
                'type' => 'checkbox',
940
                'std'  => 1
941
            ),
942
            'email_user_invoice_body' => array(
943
                'id'   => 'email_user_invoice_body',
944
                'name' => __( 'Email Content', 'invoicing' ),
945
                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
946
                'type' => 'rich_editor',
947
                'std'  => __( '<p>Hi {name},</p><p>An invoice has been created for you on {site_title}. To view / pay for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ),
948
                'class' => 'large',
949
                'size' => '10'
950
            ),
951
        ),
952
        'user_note' => array(
953
            'email_user_note_header' => array(
954
                'id'   => 'email_user_note_header',
955
                'name' => '<h3>' . __( 'Customer Note', 'invoicing' ) . '</h3>',
956
                'desc' => __( 'Customer note emails are sent when you add a note to an invoice/quote.', 'invoicing' ),
957
                'type' => 'header',
958
            ),
959
            'email_user_note_active' => array(
960
                'id'   => 'email_user_note_active',
961
                'name' => __( 'Enable/Disable', 'invoicing' ),
962
                'desc' => __( 'Enable this email notification', 'invoicing' ),
963
                'type' => 'checkbox',
964
                'std'  => 1
965
            ),
966
            'email_user_note_subject' => array(
967
                'id'   => 'email_user_note_subject',
968
                'name' => __( 'Subject', 'invoicing' ),
969
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
970
                'type' => 'text',
971
                'std'  => __( '[{site_title}] Note added to your {invoice_quote} #{invoice_number} from {invoice_date}', 'invoicing' ),
972
                'size' => 'large'
973
            ),
974
            'email_user_note_heading' => array(
975
                'id'   => 'email_user_note_heading',
976
                'name' => __( 'Email Heading', 'invoicing' ),
977
                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
978
                'type' => 'text',
979
                'std'  => __( 'A note has been added to your {invoice_quote}', 'invoicing' ),
980
                'size' => 'large'
981
            ),
982
            'email_user_note_body' => array(
983
                'id'   => 'email_user_note_body',
984
                'name' => __( 'Email Content', 'invoicing' ),
985
                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
986
                'type' => 'rich_editor',
987
                'std'  => __( '<p>Hi {name},</p><p>Following note has been added to your invoice:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing' ),
988
                'class' => 'large',
989
                'size' => '10'
990
            ),
991
        ),
992
        'overdue' => array(
993
            'email_overdue_header' => array(
994
                'id'   => 'email_overdue_header',
995
                'name' => '<h3>' . __( 'Payment Reminder', 'invoicing' ) . '</h3>',
996
                'desc' => __( 'Payment reminder emails are sent to user automatically.', 'invoicing' ),
997
                'type' => 'header',
998
            ),
999
            'email_overdue_active' => array(
1000
                'id'   => 'email_overdue_active',
1001
                'name' => __( 'Enable/Disable', 'invoicing' ),
1002
                'desc' => __( 'Enable this email notification', 'invoicing' ),
1003
                'type' => 'checkbox',
1004
                'std'  => 1
1005
            ),
1006
            'email_due_reminder_days' => array(
1007
                'id'        => 'email_due_reminder_days',
1008
                'name'      => __( 'When to Send', 'sliced-invoices' ),
1009
                'desc'      => __( 'Check when you would like payment reminders sent out.', 'invoicing' ),
1010
                'default'   => '',
1011
                'type'      => 'multicheck',
1012
                'options'   => $overdue_days_options,
1013
            ),
1014
            'email_overdue_subject' => array(
1015
                'id'   => 'email_overdue_subject',
1016
                'name' => __( 'Subject', 'invoicing' ),
1017
                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
1018
                'type' => 'text',
1019
                'std'  => __( '[{site_title}] Payment Reminder', 'invoicing' ),
1020
                'size' => 'large'
1021
            ),
1022
            'email_overdue_heading' => array(
1023
                'id'   => 'email_overdue_heading',
1024
                'name' => __( 'Email Heading', 'invoicing' ),
1025
                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
1026
                'type' => 'text',
1027
                'std'  => __( 'Payment reminder for your invoice', 'invoicing' ),
1028
                'size' => 'large'
1029
            ),
1030
            'email_overdue_body' => array(
1031
                'id'   => 'email_overdue_body',
1032
                'name' => __( 'Email Content', 'invoicing' ),
1033
                'desc' => __( 'The content of the email.', 'invoicing' ),
1034
                'type' => 'rich_editor',
1035
                'std'  => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder that your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ),
1036
                'class' => 'large',
1037
                'size'  => 10,
1038
            ),
1039
        ),
1040
    );
1041
1042
    return apply_filters( 'wpinv_get_emails', $emails );
1043
}
1044
1045
function wpinv_settings_emails( $settings = array() ) {
1046
    $emails = wpinv_get_emails();
1047
    
1048
    if ( !empty( $emails ) ) {
1049
        foreach ( $emails as $key => $email ) {
1050
            $settings[$key] = $email;
1051
        }
1052
    }
1053
    
1054
    return apply_filters( 'wpinv_settings_get_emails', $settings );
1055
}
1056
add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 );
1057
1058
function wpinv_settings_sections_emails( $settings ) {
1059
    $emails = wpinv_get_emails();
1060
    
1061
    if (!empty($emails)) {
1062
        foreach  ($emails as $key => $email) {
1063
            $settings[$key] = !empty( $email['email_' . $key . '_header']['name'] ) ? strip_tags( $email['email_' . $key . '_header']['name'] ) : $key;
1064
        }
1065
    }
1066
    
1067
    return $settings;    
1068
}
1069
add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 );
1070
1071
function wpinv_email_is_enabled( $email_type ) {
1072
    $emails = wpinv_get_emails();
1073
    $enabled = isset( $emails[$email_type] ) && wpinv_get_option( 'email_'. $email_type . '_active', 0 ) ? true : false;
0 ignored issues
show
Documentation introduced by
0 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...
1074
1075
    return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type );
1076
}
1077
1078
function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1079
    switch ( $email_type ) {
1080
        case 'new_invoice':
1081
        case 'cancelled_invoice':
1082
        case 'failed_invoice':
1083
            $recipient  = wpinv_get_admin_email();
1084
        break;
1085
        default:
1086
            $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1087
            $recipient  = !empty( $invoice ) ? $invoice->get_email() : '';
1088
        break;
1089
    }
1090
    
1091
    return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice );
1092
}
1093
1094
function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1095
    $subject    = wpinv_get_option( 'email_' . $email_type . '_subject' );
1096
    
1097
    $subject    = wpinv_email_format_text( $subject, $invoice );
1098
    
1099
    return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice );
1100
}
1101
1102
function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1103
    $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' );
1104
    
1105
    $email_heading = wpinv_email_format_text( $email_heading, $invoice );
1106
    
1107
    return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice );
1108
}
1109
1110
function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1111
    $content    = wpinv_get_option( 'email_' . $email_type . '_body' );
1112
    
1113
    $content    = wpinv_email_format_text( $content, $invoice );
1114
    
1115
    return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice );
1116
}
1117
1118
function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1119
    $from_name = wpinv_mail_get_from_address();
1120
    $from_email = wpinv_mail_get_from_address();
1121
    
1122
    $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1123
    
1124
    $headers    = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n";
1125
    $headers    .= "Reply-To: ". $from_email . "\r\n";
1126
    $headers    .= "Content-Type: " . wpinv_mail_get_content_type() . "\r\n";
1127
    
1128
    return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice );
1129
}
1130
1131
function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1132
    $attachments = array();
1133
    
1134
    return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice );
1135
}
1136
1137
function wpinv_email_format_text( $content, $invoice ) {
1138
1139
    $replace_array = array(
1140
        '{site_title}'      => wpinv_get_blogname(),
1141
        '{name}'            => $invoice->get_user_full_name(),
1142
        '{first_name}'      => $invoice->get_first_name(),
1143
        '{last_name}'       => $invoice->get_last_name(),
1144
        '{email}'           => $invoice->get_email(),
1145
        '{invoice_number}'  => $invoice->get_number(),
1146
        '{invoice_total}'   => $invoice->get_total(),
1147
        '{invoice_link}'    => $invoice->get_view_url( true ),
1148
        '{invoice_pay_link}'=> $invoice->get_view_url( true ),
1149
        '{invoice_date}'    => $invoice->get_invoice_date( true ),
1150
        '{invoice_due_date}'=> $invoice->get_due_date( true ),
1151
        '{invoice_quote}'   => $invoice->get_invoice_quote_type($invoice->ID),
1152
        '{is_was}'          => strtotime( $invoice->get_due_date() ) < strtotime( date_i18n( 'Y-m-d' ) ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
1153
        '{date}'            => date_i18n( get_option( 'date_format' ), (int) current_time( 'timestamp' ) ),
1154
    );
1155
1156
    $replace_array = apply_filters('wpinv_email_format_text', $replace_array, $content, $invoice->ID);
1157
1158
    foreach ($replace_array as $key => $value) {
1159
        $content = str_replace( $key, $value, $content );
1160
    }
1161
1162
    return apply_filters( 'wpinv_email_content_replace', $content );
1163
}
1164
1165
function wpinv_email_style_body( $content ) {
1166
    // make sure we only inline CSS for html emails
1167
    if ( in_array( wpinv_mail_get_content_type(), array( 'text/html', 'multipart/alternative' ) ) && class_exists( 'DOMDocument' ) ) {
1168
        ob_start();
1169
        wpinv_get_template( 'emails/wpinv-email-styles.php' );
1170
        $css = apply_filters( 'wpinv_email_styles', ob_get_clean() );
1171
        
1172
        // apply CSS styles inline for picky email clients
1173
        try {
1174
            $emogrifier = new Emogrifier( $content, $css );
1175
            $content    = $emogrifier->emogrify();
1176
        } catch ( Exception $e ) {
1177
            wpinv_error_log( $e->getMessage(), 'emogrifier' );
1178
        }
1179
    }
1180
    return $content;
1181
}
1182
1183
function wpinv_email_header( $email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1184
    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 ) );
1185
}
1186
1187
/**
1188
 * Get the email footer.
1189
 */
1190
function wpinv_email_footer( $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1191
    wpinv_get_template( 'emails/wpinv-email-footer.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1192
}
1193
1194
function wpinv_email_wrap_message( $message ) {
1195
    // Buffer
1196
    ob_start();
1197
1198
    do_action( 'wpinv_email_header' );
1199
1200
    echo wpautop( wptexturize( $message ) );
1201
1202
    do_action( 'wpinv_email_footer' );
1203
1204
    // Get contents
1205
    $message = ob_get_clean();
1206
1207
    return $message;
1208
}
1209
1210
function wpinv_email_invoice_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1211
    wpinv_get_template( 'emails/wpinv-email-invoice-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1212
}
1213
1214
function wpinv_email_invoice_items( $invoice, $email_type = '', $sent_to_admin = false ) {
1215
    wpinv_get_template( 'emails/wpinv-email-invoice-items.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1216
}
1217
1218
function wpinv_email_billing_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1219
    wpinv_get_template( 'emails/wpinv-email-billing-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1220
}
1221
1222 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...
1223
    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1224
    
1225
    if ( empty( $invoice_id ) ) {
1226
        return;
1227
    }
1228
1229
    if ( !current_user_can( 'manage_options' ) ) {
1230
        wp_die( __( 'You do not have permission to send invoice notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1231
    }
1232
    
1233
    $sent = wpinv_user_invoice_notification( $invoice_id );
1234
    
1235
    $status = $sent ? 'email_sent' : 'email_fail';
1236
    
1237
    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1238
    wp_redirect( $redirect );
1239
    exit;
1240
}
1241
add_action( 'wpinv_send_invoice', 'wpinv_send_customer_invoice' );
1242
1243 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...
1244
    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1245
    
1246
    if ( empty( $invoice_id ) ) {
1247
        return;
1248
    }
1249
1250
    if ( !current_user_can( 'manage_options' ) ) {
1251
        wp_die( __( 'You do not have permission to send reminder notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1252
    }
1253
    
1254
    $sent = wpinv_send_payment_reminder_notification( $invoice_id );
1255
    
1256
    $status = $sent ? 'email_sent' : 'email_fail';
1257
    
1258
    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1259
    wp_redirect( $redirect );
1260
    exit;
1261
}
1262
add_action( 'wpinv_send_reminder', 'wpinv_send_overdue_reminder' );
1263
1264
function wpinv_send_customer_note_email( $data ) {
1265
    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1266
    
1267
    if ( empty( $invoice_id ) ) {
1268
        return;
1269
    }
1270
    
1271
    $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...
1272
}
1273
add_action( 'wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1 );
1274
1275
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...
1276
    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...
1277
        $date_format = get_option( 'date_format' );
1278
        $time_format = get_option( 'time_format' );
1279
        ?>
1280
        <div id="wpinv-email-notes">
1281
            <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3>
1282
            <ol class="wpinv-notes-lists">
1283
        <?php
1284
        foreach ( $invoice_notes as $note ) {
1285
            $note_time = strtotime( $note->comment_date );
1286
            ?>
1287
            <li class="comment wpinv-note">
1288
            <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>
1289
            <div class="wpinv-note-desc description"><?php echo wpautop( wptexturize( $note->comment_content ) ); ?></div>
1290
            </li>
1291
            <?php
1292
        }
1293
        ?>  </ol>
1294
        </div>
1295
        <?php
1296
    }
1297
}
1298
add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 );
1299
1300
function wpinv_email_payment_reminders() {    
1301
    global $wpi_auto_reminder;
1302
    if ( !wpinv_get_option( 'email_overdue_active' ) ) {
1303
        return;
1304
    }
1305
    
1306
    if ( $reminder_days = wpinv_get_option( 'email_due_reminder_days' ) ) {
1307
        $reminder_days  = is_array( $reminder_days ) ? array_values( $reminder_days ) : '';
1308
        
1309
        if ( empty( $reminder_days ) ) {
1310
            return;
1311
        }
1312
        $reminder_days  = array_unique( array_map( 'absint', $reminder_days ) );
1313
        
1314
        $args = array(
1315
            'post_type'     => 'wpi_invoice',
1316
            'post_status'   => 'wpi-pending',
1317
            'fields'        => 'ids',
1318
            'numberposts'   => '-1',
1319
            'meta_query'    => array(
1320
                array(
1321
                    'key'       =>  '_wpinv_due_date',
1322
                    'value'     =>  array( '', 'none' ),
1323
                    'compare'   =>  'NOT IN',
1324
                )
1325
            ),
1326
            'meta_key'      => '_wpinv_due_date',
1327
            'orderby'       => 'meta_value',
1328
            'order'         => 'ASC',
1329
        );
1330
        
1331
        $invoices = get_posts( $args );
1332
        
1333
        if ( empty( $invoices ) ) {
1334
            return;
1335
        }
1336
        
1337
        $date_to_send   = array();
1338
        
1339
        foreach ( $invoices as $id ) {
1340
            $due_date = get_post_meta( $id, '_wpinv_due_date', true );
1341
            
1342
            foreach ( $reminder_days as $key => $days ) {
1343
                if ( $days !== '' ) {
1344
                    $date_to_send[$id][] = date_i18n( 'Y-m-d', strtotime( $due_date ) + ( $days * DAY_IN_SECONDS ) );
1345
                }
1346
            }
1347
        }
1348
1349
        $today              = date_i18n( 'Y-m-d' );
1350
        $wpi_auto_reminder  = true;
1351
1352
        foreach ( $date_to_send as $id => $values ) {
1353
            if ( in_array( $today, $values ) ) {
1354
                $sent = get_post_meta( $id, '_wpinv_reminder_sent', true );
1355
1356
                if ( isset( $sent ) && !empty( $sent ) ) {
1357
                    if ( !in_array( $today, $sent ) ) {
1358
                        do_action( 'wpinv_send_payment_reminder_notification', $id );
1359
                    }
1360
                } else {
1361
                    do_action( 'wpinv_send_payment_reminder_notification', $id );
1362
                }
1363
            }
1364
        }
1365
        
1366
        $wpi_auto_reminder  = false;
1367
    }
1368
}
1369
1370
function wpinv_send_payment_reminder_notification( $invoice_id ) {
1371
    $email_type = 'overdue';
1372
    if ( !wpinv_email_is_enabled( $email_type ) ) {
1373
        return false;
1374
    }
1375
    
1376
    $invoice    = wpinv_get_invoice( $invoice_id );
1377
    if ( empty( $invoice ) ) {
1378
        return false;
1379
    }
1380
    
1381
    if ( !$invoice->needs_payment() ) {
1382
        return false;
1383
    }
1384
    
1385
    $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...
1386
    if ( !is_email( $recipient ) ) {
1387
        return false;
1388
    }
1389
    
1390
    $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...
1391
    $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...
1392
    $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...
1393
    $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...
1394
    $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...
1395
    
1396
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
1397
            'invoice'       => $invoice,
1398
            'email_type'    => $email_type,
1399
            'email_heading' => $email_heading,
1400
            'sent_to_admin' => false,
1401
            'plain_text'    => false,
1402
            'message_body'  => $message_body
1403
        ) );
1404
        
1405
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
1406
1407
    if ( $sent ) {
1408
        do_action( 'wpinv_payment_reminder_sent', $invoice_id, $invoice );
1409
    }
1410
        
1411
    return $sent;
1412
}
1413
add_action( 'wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1 );
1414
1415
function wpinv_payment_reminder_sent( $invoice_id, $invoice ) {
1416
    global $wpi_auto_reminder;
1417
    
1418
    $sent = get_post_meta( $invoice_id, '_wpinv_reminder_sent', true );
1419
    
1420
    if ( empty( $sent ) ) {
1421
        $sent = array();
1422
    }
1423
    $sent[] = date_i18n( 'Y-m-d' );
1424
    
1425
    update_post_meta( $invoice_id, '_wpinv_reminder_sent', $sent );
1426
    
1427
    if ( $wpi_auto_reminder ) { // Auto reminder note.
1428
        $note = __( 'Manual reminder sent to the user.', 'invoicing' );
1429
        $invoice->add_note( $note, false, false, true );
1430
    } else { // Menual reminder note.
1431
        $note = __( 'Manual reminder sent to the user.', 'invoicing' );
1432
        $invoice->add_note( $note );
1433
    }
1434
}
1435
add_action( 'wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2 );