最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

filters - How to validate recaptcha on comments form?

matteradmin10PV0评论

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:

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

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/google/recaptcha

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

Share Improve this question edited Dec 5, 2018 at 13:59 Johansson 15.4k11 gold badges44 silver badges80 bronze badges asked Dec 5, 2018 at 13:17 lkylky 2812 silver badges8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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 explaining how to implement this feature in your website.

Post a comment

comment list (0)

  1. No comments so far