Description
The WP_Members_Captcha object class has a number of functions that you may call statically in order to implement custom instances of the captchas supported by WP-Members. This includes the following captcha types:
- Google reCAPTCHA v2 (API key required)
- Google reCAPTCHA v3 (API key required)
- Really Simple CAPTCHA (Really Simple CAPTCHA plugin required)
- hCaptcha (API key required)
Methods
There are two methods required to implement one of the captchas – one to display the captcha, the other to validate that it passed.
show()
The show() method is used to display the captcha using the following parameters:
$type The type of captcha being displayed. Required (recaptcha_v2|recaptcha_v3|rs_captcha|hcaptcha)
$key The “public” key for the captcha being displayed. For reCAPTCHA, this is your public API key, for hCatpcha it is your API key. This parameter is omitted for Really Simple CAPTCHA.
Return value is a string of HTML for the captcha being displayed.
validate()
The validate() method is used to validate form submission and make sure the captcha was passed.
$type The type of captcha being used. Required (recaptcha_v2|recaptcha_v3|rs_captcha|hcaptcha)
$key The “private/secret” key for the captcha being displayed. For reCAPTCHA, this is your private API key, for hCatpcha it is your secret key. This parameter is omitted for Really Simple CAPTCHA.
Return value is a true|false boolean
Usage
[snippet slug=wp_members_captcha lang=php]
Notes
- Really Simple CAPTCHA requires that you have the Really Simple CAPTCHA plugin installed and activated.
- Really Simple CAPTCHA does not use an API key for display or validation, so omit the second argument of the method.
Changelog
- Introduced in WP-Members 3.3.5
Source
The WP_Members_Captcha static methods are in /includes/class-wp-members-captcha.php