Skip to content

Instantly share code, notes, and snippets.

@sanzeeb3
Last active April 15, 2022 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanzeeb3/56163ad314ccf86451e0c667051d57e7 to your computer and use it in GitHub Desktop.
Save sanzeeb3/56163ad314ccf86451e0c667051d57e7 to your computer and use it in GitHub Desktop.
Attach files from WPForms file upload field directly to an email
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