Skip to content

Commit 24cec6b

Browse files
k1sul1Antti Kuosmanen
authored andcommitted
rework save_email_copy to allow multiple recipients... (#15)
* rework save_email_copy to allow multiple recipients in comma separated form * remove extra trim
1 parent 9363a0d commit 24cec6b

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

classes/class-cpt-wplf-form.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,25 @@ function save_cpt( $post_id ) {
384384

385385
// save email copy
386386
if ( isset( $_POST['wplf_email_copy_to'] ) ) {
387-
update_post_meta( $post_id, '_wplf_email_copy_to', sanitize_email( $_POST['wplf_email_copy_to'] ) );
387+
$emailField = $_POST['wplf_email_copy_to'];
388+
$to = '';
389+
390+
if( strpos( $emailField, "," ) > 0 ) {
391+
// Intentional. Makes no sense if the first character is a comma, so pass it along as a single address.
392+
// sanitize_email() should take care of the rest.
393+
$emailArray = explode( ",", $emailField );
394+
foreach($emailArray as $email){
395+
$email = trim($email);
396+
$email = sanitize_email( $email ) . ", ";
397+
$to .= $email;
398+
}
399+
$to = rtrim( $to, ", " );
400+
}
401+
else {
402+
$to = sanitize_email( $emailField );
403+
}
404+
405+
update_post_meta( $post_id, '_wplf_email_copy_to', $to );
388406
}
389407

390408
// save title format

0 commit comments

Comments
 (0)