hCaptcha integration

Marc Wag­ner

March 11, 2025

1 min read|

The Forge12 Dou­­b­le-Opt-In Plug­in(Ava­da | Ele­men­tor | CF7) Plug­in makes it pos­si­ble to inte­gra­te exter­nal captcha tools using the built-in hooks.

WordPress Captcha Plugin from Forge12

We offer a captcha plug­in that effec­tively pro­tects against bots and spam. This is available free of char­ge in the Word­Press plug­in store and is com­pa­ti­ble with the dou­ble opt-in plug­in.

Integration of hCaptcha #

To use the dou­ble opt-in plug­in with hCaptcha, you must inte­gra­te the fol­lo­wing code. We recom­mend the WP Code plug­in for this. Alter­na­tively, you can easi­ly insert the code in your functions.php.

add_action('f12_cf7_doubleoptin_before_send_default_mail', 'disable_hcaptcha');
/**
 * Disables the hCaptcha verification by removing the related filter from the specified WordPress filter hook.
 *
 * This function searches for a specific callback function in the predefined WordPress filter and
 * removes it if found, effectively disabling the hCaptcha verification process.
 *
 * @return void
 * @global array $wp_filter The global WordPress filters array.
 */
function disable_hcaptcha()
{
	global $wp_filter;
	$tag = 'wpcf7_validate';
	$function_to_remove = 'verify_hcaptcha';

	if (isset($wp_filter[$tag])) {
		foreach($wp_filter[$tag]->callbacks as $priority => $hook){
			foreach($hook as $function_name => $callbacks){
				if(str_contains($function_name, $function_to_remove)){
					foreach($callbacks as $callback){
						$wp_filter[$tag]->remove_filter($tag, $callback, $priority);
					}
				}
			}
		}
	}
}

The code tem­po­r­a­ri­ly remo­ves the hCaptcha vali­da­ti­on when the opt-in is con­firm­ed, allo­wing the opt-in mail to be sent.

88e86fcb816eff22bc917094df2862d8dd5c0e978b333e6dd5f36f808990c261 96

Artic­le from:

Marc Wag­ner

Hi Marc here. I’m the foun­der of Forge12 Inter­ac­ti­ve and have been pas­sio­na­te about buil­ding web­sites, online stores, appli­ca­ti­ons and SaaS solu­ti­ons for busi­nesses for over 20 years. Befo­re foun­ding the com­pa­ny, I alre­a­dy work­ed in publicly lis­ted com­pa­nies and acqui­red all kinds of know­ledge. Now I want to pass this know­ledge on to my cus­to­mers.

Do you have a ques­ti­on? Plea­se lea­ve a com­ment