dev-master
9999999-dev
GPL-2.0
The Requires
- php >=5.5.0
- composer/installers ~1.0
by Oleksandr Strikha
wordpress plugins captcha recaptcha
Helps to protect website with Google reCAPTCHA v3 or Cloudflare Turnstile. This plugin provides Login and Lost Password forms protection by default, but it's possible to add protection to any form by following this documentation., (*1)
, (*2)
, (*3)
, (*4)
, (*5)
Preferable way is to use Composer:, (*6)
composer require wp-digital/wp-recaptcha
By default, it will be installed as Must Use Plugin.
But it's possible to control with extra.installer-paths
in composer.json
., (*7)
Alternate way is to clone this repo to wp-content/mu-plugins/
or wp-content/plugins/
:, (*8)
cd wp-content/plugins/ git clone git@github.com:wp-digital/wp-recaptcha.git cd wp-recaptcha/ composer install
If plugin was installed as regular plugin then activate Bot Protection from Plugins page
or WP-CLI: wp plugin activate wp-recaptcha
., (*9)
Add required constants (usually to wp-config.php
):, (*10)
define( 'WPD_RECAPTCHA_KEY', '' ); define( 'WPD_RECAPTCHA_SECRET', '' );
or just:, (*11)
define( 'RECAPTCHA_KEY', '' ); define( 'RECAPTCHA_SECRET', '' );
Depending on constants, plugin will use Google reCAPTCHA v3 or Cloudflare Turnstile. If both constants are empty then plugin will be disabled., (*12)
Cloudflare Turnstile is detecting based on WPD_RECAPTCHA_KEY
or RECAPTCHA_KEY
constant,
by using regex: ^\dx
., (*13)
There are two ways to allow IP addresses to bypass verification:, (*14)
Add IP addresses to WPD_RECAPTCHA_ALLOWED_IPS
constant:, (*15)
define( 'WPD_RECAPTCHA_ALLOWED_IPS', '' ); // comma separated list of IP addresses
Add IP in admin area: Settings -> Bot Protection -> Allowed IPs, one IP per line (see screenshots)., (*16)
Change verification email subject:, (*17)
/** * @param string $subject * @param string $code * @param WP_User $user * * @return string */ add_filter( 'wpd_recaptcha_verification_email_subject', function ( string $subject, string $code, WP_User $user ): string { return 'New subject'; }, 10, 3 );
Change verification email message body:, (*18)
/** * @param string $message * @param string $code * @param WP_User $user * * @return string */ add_filter( 'wpd_recaptcha_verification_email_message', function ( string $message, string $code, WP_User $user ): string { return 'New message'; }, 10, 3 );
Modify verification link:, (*19)
/** * @param string $link * @param string $code * @param WP_User $user * * @return string */ add_filter( 'wpd_recaptcha_verification_link', function ( string $link, string $code, WP_User $user ): string { return 'https://example.com/verify/' . $code; }, 10, 3 );
Change verification code length:, (*20)
/** * @param int $length * * @return int */ add_filter( 'wpd_recaptcha_verification_code_length', function ( int $length ): int { return 10; } );
wpd_recaptcha_loaded
- Fires when plugin is loaded. Accepts one argument: WPD\Recaptcha\Plugin
instance.wpd_recaptcha_verify
- Fires when verification is required. Accepts one argument: WP_User
instance.wpd_recaptcha_form_success
- Fires when reCAPTCHA or Turnstile validation is successful. Accepts two arguments:
WPD\Forms\FormInterface
instance and WPD\Recaptcha\Response
instance.Add protection to custom form:, (*21)
Create class which implements form interface WPD\Forms\FormInterface
:, (*22)
<?php use WPD\Forms\FormInterface; class CustomForm implements FormInterface { // @TODO: implement methods }
Add form to wpd_recaptcha_forms
filter:, (*23)
/** * @param array $forms * * @return array */ add_filter( 'wpd_recaptcha_forms', function ( array $forms ): array { $forms[] = new CustomForm(); return $forms; } );
GPL-2.0
wordpress plugins captcha recaptcha