I've to rewrite the encrypt and decrypt function as what you wrote is not helpful.
With the following code snippet of WP Code:
- hidden link
I've adjusted the encrypt function as given under:
add_action('cred_save_data', 'my_save_data_action',99,2);
function my_save_data_action($post_id, $form_data) {
// if a specific form
if ($form_data['id']==1004 || $form_data['id']==1000)
{
if (isset($_POST['wpcf-nombre']))
{
$ciphertext = encrypt_dato($post_id, $_POST['wpcf-nombre']);
// add it to saved post meta
update_post_meta($post_id, 'wpcf-nombre', $ciphertext);
}
}
}
// función de encriptación
function encrypt_dato( $post_id, $dato ) {
$key = get_option( 'encryption_key' );
$ciphering = "AES-128-CTR";
// Use OpenSSl Encryption method
$iv_length = openssl_cipher_iv_length($ciphering);
$options = 0;
// Non-NULL Initialization Vector for encryption
$encryption_iv = '1234567891011121';
// Use openssl_encrypt() function to encrypt the data
$encryption = openssl_encrypt($dato, $ciphering,$key, $options, $encryption_iv);
return $encryption;
}
To decrypt the value of the custom field, I've added the following code snippet to "Custom Code" section offered by Toolset:
=> hidden link
add_shortcode('show_decrypt_value', 'func_decrypt_dato');
function func_decrypt_dato($atts) {
global $post;
$decryption = '';
$key = get_option( 'encryption_key' );
//$ciphering = "aes-128-gcm";
$ciphering = "AES-128-CTR";
$decryption_iv = '1234567891011121';
$options = 0;
$ciphertext = get_post_meta( $post->ID, 'wpcf-'.$atts['field'], true );
$decryption=openssl_decrypt ($ciphertext, $ciphering,$key, $options, $decryption_iv);
return $decryption;
}
Then I've added the following entry using the form: hidden link
=> hidden link
Then with your view's "Loop item in Buscador de pacientes" section I've added the above shortcode as given under:
=> hidden link
<td>[types field="nombre"][/types]==[show_decrypt_value field="nombre"]</td>
It displays as given under on the frontend with your view:
- hidden link
As you can see it displays first the original value and then decrypted value using the shortcode:
- [show_decrypt_value field="nombre"]
You can adjust the output as required.