I still have my problem with the Data Protection Act. In my country it is also mandatory that the user who fills in and sends comments also accepts a checkbox and saves the acceptance.
I have seen a code that I have downloaded that says it does this but I can’t get it to work, something I am doing wrong.
Would you be so kind to take a look to see if it is not well done. Thank you very much.
/* Privacy check box after the comment form */
add_filter( 'comment_form_field_comment', 'mi_campo_de_privacidad_en_comentarios' );
function mi_campo_de_privacidad_en_comentarios( $comment_field ) {
return $comment_field.'<label><input type="checkbox" name="privacy" value="privacy-key" class="privacyBox" aria-req="true"> Acepto la <a target="blank" href="https://ayudawp.com/legal/">política de privacidad</a></label>';
}
//validación por javascript
add_action('wp_footer','valdate_privacy_comment_javascript');
function valdate_privacy_comment_javascript(){
if (is_single() && comments_open()){
wp_enqueue_script('jquery');
?>
<script type="text/javascript">
jQuery(document).ready(function($){
$("#submit").click(function(e)){
if (!$('.privacyBox').prop('checked')){
e.preventDefault();
alert('Debes aceptar nuestra política de privacidad marcando la casilla ....');
return false;
}
}
});
</script>
<?php
}
}
//sin validación js
add_filter( 'preprocess_comment', 'verify_comment_privacy' );
function verify_comment_meta_data( $commentdata ) {
if ( ! isset( $_POST['privacy'] ) )
wp_die( __( 'Error: Debes aceptar nuestra política de privacidad marcando la casilla ....' ) );
return $commentdata;
}
//guarda el campo como comment meta
add_action( 'comment_post', 'save_comment_privacy' );
function save_comment_meta_data( $comment_id ) {
add_comment_meta( $comment_id, 'privacy', $_POST[ 'privacy' ] );
}