• chrishecker

    (@chrishecker)


    Here’s a patch to disable the captcha for people who are logged in, or who have the correct cookies set from previous approved comments.

    As a side effect, this fixes the bug where if you use the admin panel to reply to a comment directly, wp-recaptcha spams it because there was no captcha solved, which shouldn’t happen obviously.

    Chris

    Edit: cleaned it up a bit

    === modified file 'wp-content/plugins/wp-recaptcha/recaptcha.php'
    --- wp-content/plugins/wp-recaptcha/recaptcha.php       2014-11-20 08:52:32 +0000
    +++ wp-content/plugins/wp-recaptcha/recaptcha.php       2014-11-22 10:10:53 +0000
    @@ -271,8 +271,32 @@
                 '"></script>';
         }
    
    +    function disable_recaptcha_for_commenter() {
    +       if(is_user_logged_in()) {
    +         return true;
    +       }
    +
    +       $commenter = wp_get_current_commenter();
    +       $author = $commenter['comment_author'];  // Escaped by sanitize_comment_cookies() in wp-settings.php
    +       $email = $commenter['comment_author_email']; // Escaped by sanitize_comment_cookies() in wp-settings.php
    +       if ( $author != '' && $email != '' ) {
    +         $author = esc_sql($author);
    +         $email = esc_sql($email);
    +         global $wpdb;
    +         $ok_to_comment = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_author = '$author' AND comment_author_email = '$email' and comment_approved = '1' LIMIT 1");
    +         if($ok_to_comment) {
    +           return true;
    +         }
    +       }
    +       return false;
    +    }
    +
         function show_recaptcha_in_comments() {
             global $user_ID;
    +
    +       if($this->disable_recaptcha_for_commenter()) {
    +         return;
    +       }
    
             //modify the comment form for the reCAPTCHA widget
             add_action('wp_footer', array(&$this, 'save_comment_script'));
    @@ -320,7 +344,7 @@
                     $_SERVER['REMOTE_ADDR'],
                     $_POST['g-recaptcha-response']);
    
    -            if (!$response->success) {
    +            if (!$this->disable_recaptcha_for_commenter() && !$response->success) {
                     $this->_saved_error = $response->error;
                     add_filter('pre_comment_approved',
                         create_function('$a', 'return \'spam\';'));

    https://www.ads-software.com/plugins/wp-recaptcha/

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘patch to disable recaptcha for logged in users and approved commenters’ is closed to new replies.