Skip to content

Instantly share code, notes, and snippets.

@bhwebworks
Created December 1, 2016 02:59
Show Gist options
  • Select an option

  • Save bhwebworks/b64bec11a0b451865edfb6d1953e8a53 to your computer and use it in GitHub Desktop.

Select an option

Save bhwebworks/b64bec11a0b451865edfb6d1953e8a53 to your computer and use it in GitHub Desktop.
The Gravity Forms {all_fields} merge tag in notifications includes all fields which had data entered, it doesn't include HTML fields, Section Break descriptions, nor does it allow you to omit fields from the notification. By adding the following code to your themes functions.php file you will gain the ability to include HTML fields, and Section …
/**
* to exclude field from notifications give field the CSS Class Name 'gf_exclude'
* to include HTML field / Section Break field description in notifications give field the CSS Class Name 'gf_include'
* add 'extra_options' option to {all_fields} tag. Example: {all_fields:extra_options}
* see http://www.gravityhelp.com/documentation/page/Merge_Tags for a list of standard options
*/
add_filter( 'gform_merge_tag_filter', 'all_fields_extra_options', 10, 4 );
function all_fields_extra_options( $value, $merge_tag, $options, $field ) {
$options_array = explode( ",", $options );
$extra_options = in_array( "extra_options", $options_array );
if ( $merge_tag == "all_fields" && $extra_options == true ) {
$class_array = explode( " ", $field["cssClass"] );
$include_class = in_array( "gf_include", $class_array );
$exclude_class = in_array( "gf_exclude", $class_array );
if ( $exclude_class == true ) {
GFCommon::log_debug( "all_fields_extra_options(): Field ID: {$field["id"]} (Type: {$field["type"]}) - Field excluded." );
return false;
} elseif ( $include_class == true && $field["type"] == "html" ) {
GFCommon::log_debug( "all_fields_extra_options(): Field ID: {$field["id"]} (Type: {$field["type"]}) - Field included." );
return $field["content"];
} elseif ( $include_class == true && $field["type"] == "section" ) {
$field_value = $value . sprintf( '<tr bgcolor="#FFFFFF">
<td width="20">&nbsp;</td>
<td>
<font style="font-family: sans-serif; font-size:12px;">%s</font>
</td>
</tr>
', $field["description"] );
GFCommon::log_debug( "all_fields_extra_options(): Field ID: {$field["id"]} (Type: {$field["type"]}) - Description included." );
return $field_value;
} else {
GFCommon::log_debug( "all_fields_extra_options(): Field ID: {$field["id"]} (Type: {$field["type"]}) - Field handled normally." );
return $value;
}
}
else
return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment