Last active
June 20, 2023 20:55
-
-
Save alfredo-wpmudev/11b5977b2321f10ec1c84badd193d5bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter('forminator_custom_form_mail_admin_headers', 'wpmudev_change_forminator_header_attachment', 10, 5); | |
function wpmudev_change_forminator_header_attachment($headers, $custom_form, $data, $entry, $cls) | |
{ | |
$form_list = array(1048104, 1045, 1050);//Please put here the formIDs | |
if (!in_array($custom_form->id, $form_list)) { | |
return $headers; | |
} | |
$headers[] = 'X-FORMINAT-ATTCH : true'; | |
$headers[] = 'X-FORMINAT-FORM-ID :'.$custom_form->id; | |
return $headers; | |
} | |
add_filter('wp_mail', 'wpmudev_attach_pdf_forminator', 10, 1); | |
function wpmudev_attach_pdf_forminator($args) | |
{ | |
//Please, here put the list of attachmantes, one per line and the format is: FormID => ATTACHMENT-FILE-PATH, | |
$attachment_list = array( | |
1048104 => WP_CONTENT_DIR . '/uploads/2023/01/333333333333333333-English.pdf', | |
1045 => WP_CONTENT_DIR . '/uploads/2023/05/ISAM-Sales-Leadership-Brochure-1045.pdf', | |
1050 => WP_CONTENT_DIR . '/uploads/2023/05/ISAM-Sales-Leadership-Brochure-1050.pdf', | |
); | |
if (is_array($args['headers'])) { | |
foreach ($args['headers'] as $key => $value) { | |
if (strpos($value, 'X-FORMINAT-FORM-ID') !== false) { | |
$formID = explode (":", $value); | |
$args['attachments'][] = $attachment_list[intval($formID[1])]; | |
} | |
} | |
} | |
return $args; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment