Code Duplication    Length = 43-43 lines in 3 locations

includes/wpinv-email-functions.php 3 locations

@@ 88-130 (lines=43) @@
85
    do_action_ref_array( $function, $args );
86
}
87
88
function wpinv_new_invoice_notification( $invoice_id, $new_status = '' ) {
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 );
104
    if ( !is_email( $recipient ) ) {
105
        return false;
106
    }
107
108
    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type, true );
109
110
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
111
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
112
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
113
    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
114
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
115
116
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
117
            'invoice'       => $invoice,
118
            'email_type'    => $email_type,
119
            'email_heading' => $email_heading,
120
            'sent_to_admin' => true,
121
            'plain_text'    => false,
122
            'message_body'  => $message_body,
123
        ) );
124
125
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
126
127
    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type, true );
128
129
    return $sent;
130
}
131
132
function wpinv_cancelled_invoice_notification( $invoice_id, $new_status = '' ) {
133
    $email_type = 'cancelled_invoice';
@@ 132-174 (lines=43) @@
129
    return $sent;
130
}
131
132
function wpinv_cancelled_invoice_notification( $invoice_id, $new_status = '' ) {
133
    $email_type = 'cancelled_invoice';
134
    if ( !wpinv_email_is_enabled( $email_type ) ) {
135
        return false;
136
    }
137
138
    $invoice = wpinv_get_invoice( $invoice_id );
139
    if ( empty( $invoice ) ) {
140
        return false;
141
    }
142
143
    if ( !("wpi_invoice" === $invoice->post_type) ) {
144
        return false;
145
    }
146
147
    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
148
    if ( !is_email( $recipient ) ) {
149
        return false;
150
    }
151
152
    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type, true );
153
154
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
155
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
156
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
157
    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
158
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
159
160
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
161
            'invoice'       => $invoice,
162
            'email_type'    => $email_type,
163
            'email_heading' => $email_heading,
164
            'sent_to_admin' => true,
165
            'plain_text'    => false,
166
            'message_body'  => $message_body,
167
        ) );
168
169
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
170
171
    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type, true );
172
173
    return $sent;
174
}
175
176
function wpinv_failed_invoice_notification( $invoice_id, $new_status = '' ) {
177
    $email_type = 'failed_invoice';
@@ 176-218 (lines=43) @@
173
    return $sent;
174
}
175
176
function wpinv_failed_invoice_notification( $invoice_id, $new_status = '' ) {
177
    $email_type = 'failed_invoice';
178
    if ( !wpinv_email_is_enabled( $email_type ) ) {
179
        return false;
180
    }
181
    
182
    $invoice = wpinv_get_invoice( $invoice_id );
183
    if ( empty( $invoice ) ) {
184
        return false;
185
    }
186
187
    if ( !("wpi_invoice" === $invoice->post_type) ) {
188
        return false;
189
    }
190
191
    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
192
    if ( !is_email( $recipient ) ) {
193
        return false;
194
    }
195
196
    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type, true );
197
198
    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
199
    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
200
    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
201
    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
202
    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
203
    
204
    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
205
            'invoice'       => $invoice,
206
            'email_type'    => $email_type,
207
            'email_heading' => $email_heading,
208
            'sent_to_admin' => true,
209
            'plain_text'    => false,
210
            'message_body'  => $message_body,
211
        ) );
212
213
    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
214
215
    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type, true );
216
217
    return $sent;
218
}
219
220
function wpinv_onhold_invoice_notification( $invoice_id, $new_status = '' ) {
221
    $email_type = 'onhold_invoice';