Shortcode to place the Turnstile within your contact form layout:
add_shortcode( 'ccom_turnstile', function() {
if( ! function_exists( 'cfturnstile_field_show' ) ) {
return;
}
ob_start();
cfturnstile_field_show( '', '', 'ccom_turnstile', mt_rand() );
return ob_get_clean();
} );
Function to tie into your contact form’s submit action (hook and code depends on which forms plugin or custom code that you use):
add_action( 'contact_form_submit', function() {
if( ! function_exists( 'cfturnstile_check' ) ) {
return false;
}
if( ! get_option( 'cfturnstile_key' ) ) {
return false;
}
if( empty( $_POST['cf-turnstile-response'] ) ) {
return false;
}
$check = cfturnstile_check();
$success = $check['success'];
return $success === true;
} );