Locations and verification
Validate Build / validate-build (push) Failing after 35s

This commit is contained in:
Cooper Dalrymple
2026-06-04 17:05:42 -05:00
parent 471e5dd053
commit e8b8fc1871
11 changed files with 538 additions and 13 deletions
+55
View File
@@ -0,0 +1,55 @@
<?php
/**
* @package ogre-captcha
* @author cleverogre
* @copyright 2026 CleverOgre
* @license GLP-3.0-or-later
* @version 0.0.0
* @since 0.0.0
*/
namespace Ogre\Captcha;
use Ogre\Captcha\Settings;
defined('ABSPATH') || exit;
final class API {
private static function transaction(string $url, array $data):array|string|bool {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, wp_json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'content-type: application/json',
'accept: application/json',
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
if ($result === false || !is_string($result) || empty($result)) return 'Invalid response';
$result = json_decode($result, true);
if (!is_array($result) || is_null($result)) return 'Invalid formatting';
if (isset($result['error']) && !empty($result['error'])) return $result['error'];
if (isset($result['success']) && is_bool($result['success'])) return $result['success'];
return $result;
}
private static function get_siteverify_url():string {
if (!Settings::is_connected()) return '';
return Settings::get_instance_url(Settings::get_site_key() . '/siteverify');
}
public static function verify(string $token):bool {
if (empty($token) || !Settings::is_connected()) return false;
$result = self::transaction(self::get_siteverify_url(), [
'secret' => Settings::get_secret_key(),
'response' => $token,
]);
return is_bool($result) ? $result : false;
}
}