Skip to content

Instantly share code, notes, and snippets.

@raideus
Created September 25, 2012 14:26
Show Gist options
  • Save raideus/3782256 to your computer and use it in GitHub Desktop.
Save raideus/3782256 to your computer and use it in GitHub Desktop.
Gravity Forms notifcation attachments
<?php
function gs_has_http($url) {
$http = substr($url, 0, 7);
$https = substr($url, 0, 8);
if ( $http == 'http://' ) {
return true;
} elseif ( $https == 'https://' ) {
return true;
} else {
return false;
}
}
add_filter("gform_user_notification_attachments_2", "add_attachment", 10, 3);
function add_attachment($attachments, $lead, $form){
$checkbox_fields = GFCommon::get_fields_by_type($form, array("checkbox"));
/**
* Build an array containing the ID's of every checkbox
* in this form.
*
*/
$checkboxes = array();
foreach ($checkbox_fields as $checkbox_field) {
$inputs = $checkbox_field["inputs"];
foreach($inputs as $input) {
$input_id = $input["id"];
$checkboxes[] = $input_id;
}
}
/**
* Cycle through the form's checkboxes
*
* If a checkbox was selected and is assigned to a URL value, add
* that URL as a file attachment to the notification email.
*/
$attachments = array();
foreach ($checkboxes as $checkbox) {
if ($lead[$checkbox] && gs_has_http($lead[$checkbox])) {
$attachment = $_SERVER['DOCUMENT_ROOT'] . wp_make_link_relative($lead[$checkbox]);
$attachments[] = $attachment;
}
}
return $attachments;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment