Support » Plugin: Comment Reply Email Notification » GDPR check client side

  • Plugin Author Arno Welzel

    (@awelzel)


    It would be nice, if the GDPR checkobox would also be checked client side using JavaScript. Then visitors would not be that confused when they just see a blank page with an error message by WordPress.

    The way I do this in my custom GDPR extension (the checkbox is named wp-comment-privacy-consent in my case and the submit button of a comment form is named submit):

    
    function my_privacy_comment_javascript(){
        if (!is_user_logged_in() && is_single() && comments_open()){
            wp_enqueue_script('jquery');
    ?>
    <script type="text/javascript">
    jQuery(document).ready(function($) {
    	$("#submit").click(function(e) {
    		if(!$('#wp-comment-privacy-consent').prop('checked')) {
    			e.preventDefault();
    			alert('<?php echo __('You must agree to the privacy policy to submit a comment.', 'my_textdomain'); ?>');
    			return false;
    		}
    	});
    });
    </script>
    <?php
        }
    }
    add_action('wp_footer','my_privacy_comment_javascript');
    

    See in action here: https://arnowelzel.de/en/

  • You must be logged in to reply to this topic.