I’ve found my mistake.
I was hooking twice the same code, one in the ‘edit_user_profile’ and other in ‘edit_user_profile_update’.
I have separated the display code from de update code and now it works like have to:
<?php
function privacity_user_profile_fields() {
global $user_id;
$data_consent = get_user_meta($user_id, 'gdpr_user_register_consent', true);
$data_consent_text="He leído y entendido el cómo se tratarán los datos
introducidos durante el registro en esta web.";
?>
<h2 id="privacity">Opciones de privacidad</h2>
<p>
<input type="checkbox" name="gdpr_data_consent_field" id="data-consent-field" value="true" <?php echo ($data_consent == 'true') ? 'checked' : '' ?> />
<label for="data-consent-field"><?php echo $data_consent_text; ?></label>
</p>
<?php
}
add_action('edit_user_profile', 'privacity_user_profile_fields');
function privacity_user_profile_update() {
global $user_id;
if ($_POST['gdpr_data_consent_field'] == 'true' ){
update_user_meta( $user_id, 'gdpr_user_register_consent', 'true' );
} else {
update_user_meta( $user_id, 'gdpr_user_register_consent', 'false' );
}
}
add_action( 'edit_user_profile_update', 'privacity_user_profile_update' );
?>