Skip to content

Instantly share code, notes, and snippets.

@deckerweb
Created June 17, 2014 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deckerweb/d9149fa707d8c9687295 to your computer and use it in GitHub Desktop.
Save deckerweb/d9149fa707d8c9687295 to your computer and use it in GitHub Desktop.
/**
* to exclude field from notification add 'exclude[ID]' option to {all_fields} tag
* 'include[ID]' option includes HTML field / Section Break field description / Signature image in notification
* see http://www.gravityhelp.com/documentation/page/Merge_Tags for a list of standard options
* example: {all_fields:exclude[2,3]}
* example: {all_fields:include[6]}
* example: {all_fields:include[6],exclude[2,3]}
*/
add_filter( 'gform_merge_tag_filter', 'all_fields_extra_options', 11, 5 );
function all_fields_extra_options( $value, $merge_tag, $options, $field, $raw_value ) {
if ( $merge_tag != 'all_fields' ) {
return $value;
}
// usage: {all_fields:include[ID],exclude[ID,ID]}
$include = preg_match( "/include\[(.*?)\]/", $options , $include_match );
$include_array = explode( ',', rgar( $include_match, 1 ) );
$exclude = preg_match( "/exclude\[(.*?)\]/", $options , $exclude_match );
$exclude_array = explode( ',', rgar( $exclude_match, 1 ) );
$log = "all_fields_extra_options(): {$field['label']}({$field['id']} - {$field['type']}) - ";
if ( $include && in_array( $field['id'], $include_array ) ) {
switch ( $field['type'] ) {
case 'html' :
$value = $field['content'];
break;
case 'section' :
$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'] );
break;
case 'signature' :
$url = GFSignature::get_signature_url( $raw_value );
$value = "<img alt='signature' src='{$url}'/>";
break;
}
GFCommon::log_debug( $log . 'included.' );
}
if ( $exclude && in_array( $field['id'], $exclude_array ) ) {
GFCommon::log_debug( $log . 'excluded.' );
return false;
}
return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment