Skip to content

Instantly share code, notes, and snippets.

@spivurno
Last active October 25, 2021 20:12
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 spivurno/f1fb2f0f3650d63acfb5ed644296abda to your computer and use it in GitHub Desktop.
Save spivurno/f1fb2f0f3650d63acfb5ed644296abda to your computer and use it in GitHub Desktop.
Gravity Wiz // Gravity Forms // Format Date Merge Tags
<?php
/**
* Gravity Wiz // Gravity Forms // Format Date Merge Tags
* http://gravitywiz.com/
*/
add_filter( 'gform_pre_replace_merge_tags', function( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format ) {
preg_match_all( '/{[^{]*?:(\d+(\.\d+)?)(:(.*?))?}/mi', $text, $matches, PREG_SET_ORDER );
foreach ( $matches as $match ) {
$input_id = $match[1];
$field = GFFormsModel::get_field( $form, $input_id );
if( $field->get_input_type() != 'date' ) {
continue;
}
$i = $match[0][0] == '{' ? 4 : 5;
$modifier = rgar( array_map( 'trim', explode( ',', rgar( $match, $i ) ) ), 0 );
if( ! $modifier ) {
continue;
}
$value = GFFormsModel::get_lead_field_value( $entry, $field );
$value = $field->get_value_merge_tag( $value, $input_id, $entry, $form, $modifier, $value, $url_encode, $esc_html, $format, $nl2br );
$replace = date( $modifier, strtotime( $value ) );
$text = str_replace( $match[0], $replace, $text );
}
return $text;
}, 10, 7 );
@spivurno
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment