'; } */ /* For all users */ $recaptcha_site_key = 'Site key'; echo '
'; $submit_before = '
'; $submit_after = '
'; return $submit_before . $submit_button . $submit_after; } function verify_recaptcha_response() { $recaptcha_secret_key = 'Secret Key'; $recaptcha_site_key = 'Site Key'; if ( isset ( $_POST['g-recaptcha-response'] ) ) { $captcha_response = $_POST['g-recaptcha-response']; } else { return false; } // Verify the captcha response from Google $response = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', array( 'body' => array( 'secret' => $recaptcha_secret_key, 'response' => $captcha_response ) ) ); $success = false; if ( $response && is_array( $response ) ) { $decoded_response = json_decode( $response['body'] ); $success = $decoded_response->success; } return $success; } add_action('preprocess_comment', "preprocess_comment_cb"); function preprocess_comment_cb($commentdata) { /* ReCaptcha only for anonymous users global $user_ID; if ($user_ID) { return $commentdata; } */ if ( ! verify_recaptcha_response() ) { echo '

You are not verified reCaptcha test. Return to the previous page and try again.'; exit; } return $commentdata; }