Add JSON endpoint for CAPTCHA rendering

To be used inside WP/WC registration form to construct URL for CAPTCHA page.

[MAILPOET-6325]
This commit is contained in:
Mustapha Hadid
2024-11-15 21:50:45 +03:00
committed by David Remer
parent d2ebfba8c3
commit df171fdcc7
7 changed files with 101 additions and 9 deletions

View File

@ -28,6 +28,7 @@ class API {
private $availableApiVersions = [
'v1',
];
/** @var ContainerInterface */
private $container;
@ -71,7 +72,7 @@ class API {
}
public function init() {
// admin security token and API version
// admin security token and API version
WPFunctions::get()->addAction(
'admin_head',
[$this, 'setTokenAndAPIVersion']
@ -106,10 +107,12 @@ class API {
}
$ignoreToken = (
$this->settings->get('captcha.type') != CaptchaConstants::TYPE_DISABLED &&
$this->requestEndpoint === 'subscribers' &&
$this->requestMethod === 'subscribe'
);
$this->settings->get('captcha.type') != CaptchaConstants::TYPE_DISABLED &&
$this->requestEndpoint === 'subscribers' &&
$this->requestMethod === 'subscribe'
) || (
$this->requestEndpoint === 'captcha'
);
if (!$ignoreToken && $this->wp->wpVerifyNonce($this->requestToken, 'mailpoet_token') === false) {
$errorMessage = __("Sorry, but we couldn't connect to the MailPoet server. Please refresh the web page and try again.", 'mailpoet');