Passed
Pull Request — master (#126)
by Kiran
03:46
created

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

Complexity

Conditions 4
Paths 4

Size

Total Lines 36
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 26
nc 4
nop 2
dl 0
loc 36
rs 8.5806
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_to_wpi-refunded',
28
        'wpinv_status_wpi-processing_to_wpi-refunded',
29
        'wpinv_status_publish',
30
        'wpinv_fully_refunded',
31
        'wpinv_partially_refunded',
32
        'wpinv_new_invoice_note'
33
    ) );
34
35
    foreach ( $email_actions as $action ) {
36
        add_action( $action, 'wpinv_send_transactional_email', 10, 10 );
37
    }
38
}
39
add_action( 'init', 'wpinv_init_transactional_emails' );
40
41
// New invoice email
42
add_action( 'wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_new_invoice_notification' );
43
add_action( 'wpinv_status_wpi-pending_to_publish_notification', 'wpinv_new_invoice_notification' );
44
add_action( 'wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_new_invoice_notification' );
45
add_action( 'wpinv_status_wpi-failed_to_wpi-processing_notification', 'wpinv_new_invoice_notification' );
46
add_action( 'wpinv_status_wpi-failed_to_publish_notification', 'wpinv_new_invoice_notification' );
47
add_action( 'wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_new_invoice_notification' );
48
49
// Cancelled invoice email
50
add_action( 'wpinv_status_wpi-pending_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification' );
51
add_action( 'wpinv_status_wpi-onhold_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification' );
52
53
// Failed invoice email
54
add_action( 'wpinv_status_wpi-pending_to_wpi-failed_notification', 'wpinv_failed_invoice_notification' );
55
add_action( 'wpinv_status_wpi-onhold_to_wpi-failed_notification', 'wpinv_failed_invoice_notification' );
56
57
// On hold invoice email
58
add_action( 'wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification' );
59
add_action( 'wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification' );
60
61
// Processing invoice email
62
add_action( 'wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_processing_invoice_notification' );
63
64
// Paid invoice email
65
add_action( 'wpinv_status_publish_notification', 'wpinv_completed_invoice_notification' );
66
67
// Refunded invoice email
68
add_action( 'wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification' );
69
add_action( 'wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification' );
70
add_action( 'wpinv_status_publish_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification' );
71
add_action( 'wpinv_status_wpi-processing_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification' );
72
73
// Invoice note
74
add_action( 'wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification' );
75
76
add_action( 'wpinv_email_header', 'wpinv_email_header' );
77
add_action( 'wpinv_email_footer', 'wpinv_email_footer' );
78
add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 );
79
add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 );
80
add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 );
81
82
function wpinv_send_transactional_email() {
83
    $args       = func_get_args();
84
    $function   = current_filter() . '_notification';
85
    do_action_ref_array( $function, $args );
86
}
87
88 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...
89
    $email_type = 'new_invoice';
90
    if ( !wpinv_email_is_enabled( $email_type ) ) {
91
        return false;
92
    }
93
94
    $invoice = wpinv_get_invoice( $invoice_id );
95
    if ( empty( $invoice ) ) {
96
        return false;
97
    }
98
99
    if ( !("wpi_invoice" === $invoice->post_type) ) {
100
        return false;
101
    }
102
103
    $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...
104
    if ( !is_email( $recipient ) ) {
105
        return false;
106
    }
107
108
    $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...
109
    $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...
110
    $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...
111
    $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...
112
    $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...
113
114
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
115
            'invoice'       => $invoice,
116
            'email_type'    => $email_type,
117
            'email_heading' => $email_heading,
118
            'sent_to_admin' => true,
119
            'plain_text'    => false,
120
            'message_body'  => $message_body,
121
        ) );
122
123
    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
124
}
125
126 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...
127
    $email_type = 'cancelled_invoice';
128
    if ( !wpinv_email_is_enabled( $email_type ) ) {
129
        return false;
130
    }
131
132
    $invoice = wpinv_get_invoice( $invoice_id );
133
    if ( empty( $invoice ) ) {
134
        return false;
135
    }
136
137
    if ( !("wpi_invoice" === $invoice->post_type) ) {
138
        return false;
139
    }
140
141
    $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...
142
    if ( !is_email( $recipient ) ) {
143
        return false;
144
    }
145
146
    $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...
147
    $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...
148
    $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...
149
    $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...
150
    $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...
151
152
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
153
            'invoice'       => $invoice,
154
            'email_type'    => $email_type,
155
            'email_heading' => $email_heading,
156
            'sent_to_admin' => true,
157
            'plain_text'    => false,
158
            'message_body'  => $message_body,
159
        ) );
160
161
    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
162
}
163
164 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...
165
    $email_type = 'failed_invoice';
166
    if ( !wpinv_email_is_enabled( $email_type ) ) {
167
        return false;
168
    }
169
    
170
    $invoice = wpinv_get_invoice( $invoice_id );
171
    if ( empty( $invoice ) ) {
172
        return false;
173
    }
174
175
    if ( !("wpi_invoice" === $invoice->post_type) ) {
176
        return false;
177
    }
178
179
    $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...
180
    if ( !is_email( $recipient ) ) {
181
        return false;
182
    }
183
184
    $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...
185
    $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...
186
    $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...
187
    $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...
188
    $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...
189
    
190
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
191
            'invoice'       => $invoice,
192
            'email_type'    => $email_type,
193
            'email_heading' => $email_heading,
194
            'sent_to_admin' => true,
195
            'plain_text'    => false,
196
            'message_body'  => $message_body,
197
        ) );
198
    
199
    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
200
}
201
202
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...
203
    $email_type = 'onhold_invoice';
204
    if ( !wpinv_email_is_enabled( $email_type ) ) {
205
        return false;
206
    }
207
208
    $invoice = wpinv_get_invoice( $invoice_id );
209
    if ( empty( $invoice ) ) {
210
        return false;
211
    }
212
213
    if ( !("wpi_invoice" === $invoice->post_type) ) {
214
        return false;
215
    }
216
217
    $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...
218
    if ( !is_email( $recipient ) ) {
219
        return false;
220
    }
221
222
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

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

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

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

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
225
    $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...
226
    $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...
227
    
228
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
229
            'invoice'       => $invoice,
230
            'email_type'    => $email_type,
231
            'email_heading' => $email_heading,
232
            'sent_to_admin' => false,
233
            'plain_text'    => false,
234
            'message_body'  => $message_body,
235
        ) );
236
    
237
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
238
    
239
    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
240
        $recipient  = wpinv_get_admin_email();
241
        $subject    .= ' - ADMIN BCC COPY';
242
        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
243
    }
244
    
245
    return $sent;
246
}
247
248
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...
249
    $email_type = 'processing_invoice';
250
    if ( !wpinv_email_is_enabled( $email_type ) ) {
251
        return false;
252
    }
253
254
    $invoice = wpinv_get_invoice( $invoice_id );
255
    if ( empty( $invoice ) ) {
256
        return false;
257
    }
258
259
    if ( !("wpi_invoice" === $invoice->post_type) ) {
260
        return false;
261
    }
262
263
    $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...
264
    if ( !is_email( $recipient ) ) {
265
        return false;
266
    }
267
268
    $search                     = array();
269
    $search['invoice_number']   = '{invoice_number}';
270
    $search['invoice_date']     = '{invoice_date}';
271
    $search['name']             = '{name}';
272
273
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

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

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

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

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
276
    $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...
277
    $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...
278
    
279
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
280
            'invoice'       => $invoice,
281
            'email_type'    => $email_type,
282
            'email_heading' => $email_heading,
283
            'sent_to_admin' => false,
284
            'plain_text'    => false,
285
            'message_body'  => $message_body,
286
        ) );
287
288
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
289
290
    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
291
        $recipient  = wpinv_get_admin_email();
292
        $subject    .= ' - ADMIN BCC COPY';
293
        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
294
    }
295
296
    return $sent;
297
}
298
299
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...
300
    $email_type = 'completed_invoice';
301
    if ( !wpinv_email_is_enabled( $email_type ) ) {
302
        return false;
303
    }
304
305
    $invoice = wpinv_get_invoice( $invoice_id );
306
    if ( empty( $invoice ) ) {
307
        return false;
308
    }
309
310
    if ( !("wpi_invoice" === $invoice->post_type) ) {
311
        return false;
312
    }
313
314
    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
0 ignored issues
show
Documentation introduced by
$invoice is of type object<WPInv_Invoice>, but the function expects a array.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

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