Last active
April 15, 2022 06:18
-
-
Save sanzeeb3/56163ad314ccf86451e0c667051d57e7 to your computer and use it in GitHub Desktop.
Attach files from WPForms file upload field directly to an email
This file contains hidden or 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
add_filter( 'wpforms_emails_send_email_data', 'wpf_prepare_files', 10, 2 ); | |
/** | |
* Prepare file attachment. | |
* | |
* @param Array $data Email Data. | |
* @param Obj $email_obj Email Object. | |
* | |
* @return Obj The Email Data with attachment. | |
*/ | |
function wpf_prepare_files( $data, $email_obj ) { | |
$entry = $email_obj->fields; | |
$files = array(); | |
foreach( $entry as $field ) { | |
if ( 'file-upload' !== $field['type'] || empty( $field['value'] ) ) { | |
continue; | |
} | |
$files[] = ABSPATH . wp_make_link_relative( $field['value'] ); | |
} | |
$data['attachments'] = $files; | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment