Last active
May 5, 2020 10:00
-
-
Save vfontjr/146c663e2c86c71d6cc653751b4164bc to your computer and use it in GitHub Desktop.
Source code for https://victorfont.com/encrypt-decrypt-formidable-form-fields/
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
<?php | |
add_filter( 'frm_include_credit_card', '__return_true' ); |
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
<?php | |
function vmf_encrypt( $data ) { | |
$key = FORMIDABLE_SALT; | |
$method = FORMIDABLE_METHOD; | |
$options = FORMIDABLE_OPTIONS; | |
$iv = FORMIDABLE_IV; | |
return openssl_encrypt ( $data, $method, $key, $options, $iv); | |
} | |
function vmf_decrypt( $encrypted ) { | |
$key = FORMIDABLE_SALT; | |
$method = FORMIDABLE_METHOD; | |
$options = FORMIDABLE_OPTIONS; | |
$iv = FORMIDABLE_IV; | |
return openssl_decrypt ( $encrypted, $method, $key, $options, $iv); | |
} |
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
<?php | |
define('FORMIDABLE_SALT', 'Si-+7^9Xtv5.vb`<T~F)wG?~,v76T [h%7N,h3/4=QVrW~&,QV|uXu63a(K$e.G^'); | |
define('FORMIDABLE_METHOD', 'AES-256-CBC'); | |
define('FORMIDABLE_OPTIONS', 0); | |
define('FORMIDABLE_IV', ';8qRaMk*jhFDYy3p'); |
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
<?php | |
add_filter('frmpro_fields_replace_shortcodes', 'decrypt_my_field_for_view', 10, 4); | |
function decrypt_my_field_for_view($replace_with, $tag, $atts, $field){ | |
if(isset($atts['decrypt'])){ | |
$encrypted = $replace_with; | |
$replace_with = vmf_decrypt($encrypted); | |
} | |
return $replace_with; | |
} |
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
<?php | |
add_filter('frm_setup_edit_fields_vars', 'decrypt_my_field', 20, 3); | |
function decrypt_my_field($values, $field, $args){ | |
if($field->id == 125){//Replace with the ID of your field | |
$encrypted = $values['value']; | |
$values['value'] = vmf_decrypt($encrypted); | |
} | |
return $values; | |
} |
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
<?php | |
add_filter('frm_pre_create_entry', 'encrypt_my_field'); | |
add_filter('frm_pre_update_entry', 'encrypt_my_field'); | |
function encrypt_my_field($values){ | |
if ( $values['form_id'] == 5 ) { //change 5 to your form id | |
$current_value = $values['item_meta'][25]; // change 25 to to id of your field | |
$encrypted_value = vmf_encrypt( $current_value ); | |
// store the encrypted value to the DB | |
$values['item_meta'][25] = $encrypted_value; | |
} | |
return $values; | |
} |
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
<?php | |
openssl_encrypt ( string $data , string $method , string $key [, int $options = 0 [, string $iv = "" [, string &$tag = NULL [, string $aad = "" [, int $tag_length = 16 ]]]]] ) | |
openssl_decrypt ( string $data , string $method , string $key [, int $options = 0 [, string $iv = "" [, string $tag = "" [, string $aad = "" ]]]] ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment