Added Gravity Forms Addon

This commit is contained in:
Cooper Dalrymple
2026-06-05 17:44:26 -05:00
parent 7da66983a9
commit 15a89a140f
9 changed files with 210 additions and 32 deletions
+18
View File
@@ -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;
}
}