Hooks

Docs Hooks Pro · PHP hooks

modal_kit_pro_captcha_providers

filter

Pro

PHP

Add, replace or remove the bot check services offered under Bot check on Modal Kit → Settings → Integrations.

Builds the list of bot check services: Cloudflare Turnstile, hCaptcha, and Google reCAPTCHA v2 and v3. One is active per site, chosen under Bot check on Modal Kit → Settings → Integrations. Its site key goes in the page; its secret stays in WordPress.

Each item extends ModalKit\Pro\Captcha\Provider. The site checks every token itself, on the form relay and when a game is played, by posting it to the provider’s siteverify address.

Parameters

Parameter

Description

$list

Provider[]

Turnstile (turnstile), hCaptcha (hcaptcha), reCAPTCHA v2 (recaptcha-v2) and reCAPTCHA v3 (recaptcha-v3).

Returns

Provider[] The providers. Anything that isn’t a ModalKit\Pro\Captcha\Provider is dropped. A later provider with the same id() replaces an earlier one and keeps its saved keys.

Examples

Load reCAPTCHA from recaptcha.net

Google serves reCAPTCHA from www.recaptcha.net for visitors who can’t reach www.google.com. Reusing the recaptcha-v2 id replaces the built-in provider and keeps its keys.

PHP

add_filter( 'modal_kit_pro_captcha_providers', function ( $providers ) {
  $providers[] = new class() extends \ModalKit\Pro\Captcha\RecaptchaV2 {
    protected function verify_url() {
      return 'https://www.recaptcha.net/recaptcha/api/siteverify';
    }

    public function script( $site ) {
      unset( $site );

      return 'https://www.recaptcha.net/recaptcha/api.js?render=explicit';
    }
  };

  return $providers;
} );

Offer only Turnstile and hCaptcha

For an agency that doesn’t use Google services on client sites.

PHP

add_filter( 'modal_kit_pro_captcha_providers', function ( $providers ) {
  return array_values(
    array_filter(
      $providers,
      function ( $provider ) {
        return $provider instanceof \ModalKit\Pro\Captcha\Provider
          && 0 !== strpos( $provider->id(), 'recaptcha' );
      }
    )
  );
} );

Good to know

Must implement: id(), label(), keys_url() (where site owners get keys), script( $site ) (the script address) and the protected verify_url() (the siteverify address). May override: interactive() (false for a score-only check with no widget), scored() (shows the minimum score setting), test_secrets(), body() (the siteverify request) and check() (more checks on an accepted answer, such as action and score). RecaptchaV2 can be extended; the other built-in classes are final.

The browser knows three script APIs: window.turnstile for the id turnstile, window.hcaptcha for hcaptcha, and window.grecaptcha for every other id. A new service needs a script with the reCAPTCHA API: render, getResponse and reset, or ready and execute when interactive() returns false. The runtime adds onload to the script address, and hl for every provider but Turnstile.

The siteverify answer must be JSON with success and a hostname in the allowed list (see modal_kit_pro_captcha_hostnames), unless the secret is one of test_secrets(). Visitors always see “Complete the security check, then try again.”

Removing the service a site has chosen switches the bot check off until another is chosen. Forms with the check on then go out unchecked, and don’t receive codes sent from the site.

Applied in modal-kit-pro/includes/Captcha.php.

Need a hook that isn’t here?