IMPLEMENTED: Integrating cloudflare turnstile into forms

Hey dev team,

just curious if there is any interest or plans to integrate cloudflare turnstile captcha replacement solution? https://www.cloudflare.com/products/turnstile/

turnstile_gif

I’ve been using it on other non-Bricks build and it works great! much faster than google recaptcha and seems to also be privacy respecting for website visitors.

Would be brilliant if this can be integrated as a recaptcha replacement!

thanks

4 Likes

The form widget has weak spam protection. I don’t use recaptcha-type services. :frowning:
For example, I would like to see protection by the type of the Honeypot field and question-answer protection.

4 Likes

Yep, same here. Looking forward to ditch the terrible UI of reCaptcha…

You can try this - Get the site key and secret key from cloudflare dashboard and add them to the below code.

Custom Code Script:

<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>

functions.php script

function wpp_cloudflare_turnstile($submit_field) { 
    $submit_field['submit_field'] = '<div class="cf-turnstile" data-sitekey="your-site-key" data-callback="javascriptCallback"></div>'.$submit_field['submit_field']; 
    return $submit_field; 
} 
 
if (!is_user_logged_in()) { 
    add_filter('comment_form_defaults', 'wpp_cloudflare_turnstile'); 
} 
function wppturnstile_check() {
  
    $postdata =$_POST['cf-turnstile-response'];
   //add secret key
    $secret = 'your-secret-key';
    $headers = array(
        'body' => [
            'secret' => $secret,
            'response' => $postdata
        ]
    );
    $verify = wp_remote_post('https://challenges.cloudflare.com/turnstile/v0/siteverify', $headers);
    $verify = wp_remote_retrieve_body($verify);
    $response = json_decode($verify);
    if($response->success) {
        $results['success'] = $response->success;
    } else {
        $results['success'] = false;
    }
    if(empty($postdata)){ 
        wp_die(__("<b>ERROR: </b><b>Please click the captcha checkbox.</b><p><a href='javascript:history.back()'>« Back</a></p>")); 
    } elseif(!$results['success']){ 
        wp_die(__("<b>Sorry, spam detected!</b>")); 
    } else {
        return true;
    }   
}
if (!is_user_logged_in()) { 
    add_action('pre_comment_on_post', 'wppturnstile_check'); 
}

Reference Link

Hi guys,

We’ve added this feature request in Bricks 1.9.2 beta, now available as a manual download in your account (see changelog).

Please let us know if you are still experiencing issues.

As with any beta release, please do not use it on any production/live website. It is only meant for testing in a local/staging environment.

3 Likes

Does Turnstile work correctly for everyone? I’ve noticed that forms are submitted even when the Turnstile box is left unchecked.

Harness the power of Cloudflare’s Turnstile, an integration introduced in Bricks 1.9.2.

This step-by-step tutorial demonstrates how to quickly integrate this amazing reCaptcha alternative onto your Bricks website.