Added Gravity Forms Addon
This commit is contained in:
@@ -10,12 +10,17 @@
|
||||
|
||||
namespace Ogre\Captcha;
|
||||
|
||||
use Ogre\Captcha as Plugin;
|
||||
use Ogre\Captcha\Settings;
|
||||
use WP_Error;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
final class API {
|
||||
|
||||
public const ERROR_EMPTY_TOKEN = 'empty_captcha_token';
|
||||
public const ERROR_INVALID_CAPTCHA = 'invalid_captcha_result';
|
||||
|
||||
private static function transaction(string $url, array $data):array|string|bool {
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, wp_json_encode($data));
|
||||
@@ -52,4 +57,17 @@ final class API {
|
||||
return is_bool($result) ? $result : false;
|
||||
}
|
||||
|
||||
public static function process(string $token, WP_Error|null $errors = null): WP_Error {
|
||||
if (is_null($errors)) $errors = new WP_Error();
|
||||
if (!Settings::is_connected()) return $errors;
|
||||
|
||||
if (empty($token)) {
|
||||
$errors->add(self::ERROR_EMPTY_TOKEN, Plugin::__('Please complete CAPTCHA verification.'));
|
||||
} else if (!API::verify($token)) {
|
||||
$errors->add(self::ERROR_INVALID_CAPTCHA, Plugin::__('Your answer was incorrect - please try again.'));
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user