Add code to display the invisible ReCaptcha in the frontend

This commit adds the required code to display the invisible ReCaptcha in
the frontend when a form is rendered and this type of captcha is
selected in the admin.

[MAILPOET-4145]
This commit is contained in:
Rodrigo Primo
2022-04-18 14:51:47 -03:00
committed by Veljko V
parent 84e22b82bd
commit c1bd52b964
6 changed files with 152 additions and 83 deletions

View File

@@ -216,15 +216,21 @@ class SubscriberSubscribeController {
}
}
if ($captchaSettings['type'] === Captcha::TYPE_RECAPTCHA && empty($data['recaptcha'])) {
if (Captcha::isReCaptcha($captchaSettings['type']) && empty($data['recaptcha'])) {
return ['error' => __('Please check the CAPTCHA.', 'mailpoet')];
}
if ($captchaSettings['type'] === Captcha::TYPE_RECAPTCHA) {
if (Captcha::isReCaptcha($captchaSettings['type'])) {
if ($captchaSettings['type'] === Captcha::TYPE_RECAPTCHA_INVISIBLE) {
$secretToken = $captchaSettings['recaptcha_invisible_secret_token'];
} else {
$secretToken = $captchaSettings['recaptcha_secret_token'];
}
$response = empty($data['recaptcha']) ? $data['recaptcha-no-js'] : $data['recaptcha'];
$response = $this->wp->wpRemotePost('https://www.google.com/recaptcha/api/siteverify', [
'body' => [
'secret' => $captchaSettings['recaptcha_secret_token'],
'secret' => $secretToken,
'response' => $response,
],
]);