This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.
Use this hook to attach files to email notifications. The file must be uploaded to your site before it can be included in the email. All variations of this hook require the absolute path to the file. In WordPress, ABSPATH will give you the path to the root of your site. In most cases, your path will look like this:
ABSPATH . '/' . 'wp-content/uploads/2015/02/filename.pdf'
Usage
add_filter('frm_notification_attachment', 'add_my_attachment', 10, 3); function add_my_attachment($attachments, $form, $args)
Parameters
- $attachments (array)
- $form (object)
- $args (array)
- $args[email_key] (string)
- $args[entry] (object)
Examples
Attach a static file
Attach an image to all emails notifications sent from a specific form.
Update: This option is now built-in. No need to use the code example.
add_filter('frm_notification_attachment', 'add_my_attachment', 10, 3);
function add_my_attachment($attachments, $form, $args){
//$args['entry'] includes the entry object
if ( $args['email_key'] == 1277 ) { //change 1277 to the ID of your email notification
$attachments[] = ABSPATH . '/'.'wp-content/uploads/2015/02/filename.pdf'; //set the ABSOLUTE path to the image here
}
return $attachments;
}
Remove attachments for a single notification
When the box to include uploaded files in the email is checked in an upload field, you can remove the attachment from an email notification.
add_filter('frm_notification_attachment', 'remove_my_attachment', 10, 3);
function remove_my_attachment($attachments, $form, $args) {
if ( $args['email_key'] == 1277 ) { //change 1277 to the email ID that you would like to DROP the attachment for
$attachments = array(); //remove all attachments
}
return $attachments;
}
Find more information on how to find the email ID.
Remove attachments for all notifications
Use this code example if you want to remove all automatic attachments from all email notifications.
add_filter('frm_notification_attachment', 'remove_my_attachment', 10, 3);
function remove_my_attachment($attachments, $form, $args) {
{
$attachments = array(); //remove all attachments
}
return $attachments;
}
Remove attachments for specific notifications
Use this code example to remove all attachments from specific email notifications by filtering an array of email action IDs.
add_filter('frm_notification_attachment', 'remove_my_attachment', 10, 3);
function remove_my_attachment($attachments, $form, $args) {
// Replace with your specific notification IDs
$notification_ids_to_exclude = array( '123', '456', '789' );
if ( in_array( $args['email_key'], $notification_ids_to_exclude ) ) {
$attachments = array(); // Remove attachments for specific notifications
}
return $attachments;
}