Skip to content

Instantly share code, notes, and snippets.

@hiranthi
Last active January 30, 2019 15:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiranthi/637b467fe8171d2270076b46e5309f48 to your computer and use it in GitHub Desktop.
Save hiranthi/637b467fe8171d2270076b46e5309f48 to your computer and use it in GitHub Desktop.
Encrypt & decrypt Gravity Forms velden
<?php
# Like on: https://docs.gravityforms.com/gform_get_input_value/
add_filter( 'gform_get_input_value', 'gf_custom_decode_field', 10, 4 );
function gf_custom_decrypt_field( $value, $entry, $field, $input_id )
{
return GFCommon::decrypt( $value );
}
// end gf_custom_decrypt_field
<?php
# Like on: https://docs.gravityforms.com/gform_get_input_value/
add_filter( 'gform_get_input_value', 'gf_custom_decode_field', 10, 4 );
function gf_custom_decrypt_field( $value, $entry, $field, $input_id )
{
# Add a check to see if a field has to be decrypted,
# because it's possible you're adding this after already having entries
$date_implemented = '2018-03-18 09:00:00'; # format: yyyy-mm-dd hh:mi:ss
$date_entry = rgar( $entry, 'date_created' );
# Entry is from after implementing encrypting entries
if ( strtotime( $date_entry ) >= $date_implemented )
return GFCommon::decrypt( $value );
# Entry is from before implementing encrypting entries
return $value;
}
// end gf_custom_decrypt_field
<?php
# Like on: https://docs.gravityforms.com/gform_save_field_value/
add_filter( 'gform_save_field_value', 'gf_custom_save_field_value', 10, 4 );
function gf_custom_save_field_value( $value, $lead, $field, $form )
{
return GFCommon::encrypt( $value );
}
// end gf_custom_save_field_value
@hiranthi
Copy link
Author

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