Filter hook to disable emailing the attachment

Posted by on Sep 29, 2013 in How To, Tips

Filter hook to disable emailing the attachment

This custom modification is useful for when “Enable to not delete email attachments from the server”
setting is checked on the Advanced tab. Maybe you only want the attachments uploaded to the server and not sent in email.

There is a setting to the ‘Advanced’ tab on the 4.XX version
“Enable to not delete email attachments from the server”.
If you enable that, the email attachments will not be deleted automatically. They will stay in the /plugins/si-contact-form/attachments folder until you delete them. Note: use this feature at your own risk, because storing the files there could potentially expose privacy if the files uploaded contain private information.

Add the following code to your theme’s functions.php file or to a custom plugin.
Be sure to set the setting in the function to control which forms you want this on.
These filters only work with versions 4.xx and up, not the 3.xx versions or lower.

function my_action_send_attachments($send_attachments, $form_id_num) {
##################################
 // control which forms you want this on
 $all_forms = true; // set to true for process on all forms, or false to use settings below
 $forms = array('1','2');  // one or more individual forms
 
 ##################################
 if ( !in_array($form_id_num, $forms) && $all_forms != true)
 return $send_attachments;

  // disables emailing the attachment
  $send_attachments = false;

   return $send_attachments;

}
//filter hook to disable emailing the attachment 
// (useful for when "Enable to not delete email attachments from the server" 
// is checked and you don't want it emailed).
add_filter('si_contact_send_attachments', 'my_action_send_attachments', 1, 2);

Do you need help?

Send us a Donation:

Donate to Mike Challis