Filter hook to modify email_fields array before data export

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

Filter hook to modify email_fields array before data export
(note this is injected AFTER validation, so make sure to not allow unfiltered user input)

In this example an attachment field “File is attached:” is removed.

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_email_fields_posted($email_fields, $form_id_num) {

##################################
 // control which forms you want this on
 $all_forms = false; // 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 $email_fields;

  // make some code here to modify or add a field
  //'my_field' is the field tag, change as needed
  $email_fields['my_field'] = str_replace('File is attached:','', $email_fields['my_field']);

   return $email_fields;

}
// filter hook to add any custom fields to email_fields array (not validated)  
add_filter('si_contact_email_fields_posted', 'my_action_email_fields_posted', 1, 2);

Do you need help?

Send us a Donation:

Donate to Mike Challis