settings = $settings;
$this->captchaValidator = $captchaValidator;
$this->captchaRenderer = $captchaRenderer;
}
public function isEnabled(): bool {
if (!$this->settings->get(CaptchaConstants::ON_REGISTER_FORMS_SETTING_NAME, false)) {
return false;
}
$type = $this->settings->get('captcha.type');
return CaptchaConstants::isBuiltIn($type)
|| (CaptchaConstants::isDisabled($type) && $this->captchaRenderer->isSupported());
}
public function renderInWPRegisterForm() {
$this->render('form#registerform', CaptchaUrlFactory::REFERER_WP_FORM);
}
public function renderInWCRegisterForm() {
$this->render('form.woocommerce-form-register', CaptchaUrlFactory::REFERER_WC_FORM);
}
private function render($formSelector, $referrer) {
// phpcs:disable WordPress.Security.EscapeOutput.HeredocOutputNotEscaped
echo <<
HTML;
// phpcs:enable WordPress.Security.EscapeOutput.HeredocOutputNotEscaped
}
public function validate(\WP_Error $errors) {
try {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$this->captchaValidator->validate($_POST['data'] ?? []);
} catch (ValidationError $e) {
$errors->add('captcha_failed', $e->getMessage());
}
return $errors;
}
}