Gform user notification attachments

This hook has been deprecated in v. 1.7. Please use gform_notification instead.

Description

This filter can be used to add attachments to the user notification email.

Usage

<?php
add_filter("gform_user_notification_attachments", "add_attachment", 10, 3);
?>

You can also target a specific form by adding the form id after the hook name.

<?php
//This filter declaration targets a form whose id is 6
add_filter("gform_user_notification_attachments_6", "add_attachment", 10, 3);
?>

Parameters

$attachments

(string/array) The attachments to be filtered. This parameter will be passed to the filter as a blank string. To add attachments, set it to a string (containing the full file path) for one attachment or an array of strings (file paths) for multiple attachments.

$entry

(Entry Object) Current entry object.

$form

(Form Object) Current form object.

Examples

This example attaches all file upload fields in the form to the user notification email.


<?php
add_filter("gform_user_notification_attachments", "add_attachment", 10, 3);
function add_attachment($attachments, $lead, $form){
    $fileupload_fields = GFCommon::get_fields_by_type($form, array("fileupload"));

    if(!is_array($fileupload_fields))
        return $attachments;

    $attachments = array();
    $upload_root = RGFormsModel::get_upload_root();
    foreach($fileupload_fields as $field){
        $url = $lead[$field["id"]];		
		$attachment = preg_replace('|^(.*?)/gravity_forms/|', $upload_root, $url);
		if($attachment){
			$attachments[] = $attachment;
		}            
	}

    return $attachments;
}
?>

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

This filter is located in common.php

Search the Documentation