Created
June 17, 2014 21:32
-
-
Save deckerweb/d9149fa707d8c9687295 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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"> </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