1

I've added the following code to my function file to add the recaptcha, however I do not know how I can validate the captcha.

/**
* Add Captcha to Comments Form
 */
add_filter('comment_form', function() {
    echo '<div class="g-recaptcha" data-sitekey="'.GOOGLE_RECAPTCHA_SITEKEY.'"></div>';
});

Is there a filter for the submission of the comments form? I will be validating the captcha server side using the following:

https://github.com/google/recaptcha

Any advise on how to implement the captcha to the comments form would be appreciated.

1 Answer 1

0

There's a preprocess_comment filter that is run before the comment is inserted in the database.

You will have access to the comment's data:

add_filter( 'preprocess_comment' , 'wpse321083_process_recaptcha' );
function wpse321083_process_recaptcha( $commentdata ) {
    // Process recaptcha here
    return $commentdata;
}

Here's also a good article on SitePoint.com explaining how to implement this feature in your website.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.