Locations and verification
Validate Build / validate-build (push) Failing after 35s
Validate Build / validate-build (push) Failing after 35s
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user