Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/fluentform/app/Modules/HCaptcha/HCaptcha.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
3
+
namespace FluentForm\App\Modules\HCaptcha;
4
+
5
+
use FluentForm\Framework\Helpers\ArrayHelper;
6
+
7
+
class HCaptcha
8
+
{
9
+
/**
10
+
* Verify hCaptcha response.
11
+
*
12
+
* @param string $token response from the user.
13
+
* @param null $secret provided or already stored secret key.
14
+
*
15
+
* @return bool
16
+
*/
17
+
public static function validate($token, $secret = null)
18
+
{
19
+
$verifyUrl = 'https://hcaptcha.com/siteverify';
20
+
21
+
$secret = $secret ?: ArrayHelper::get(get_option('_fluentform_hCaptcha_details'), 'secretKey');
22
+
23
+
$response = wp_remote_post($verifyUrl, [
24
+
'method' => 'POST',
25
+
'body' => [
26
+
'secret' => $secret,
27
+
'response' => $token,
28
+
],
29
+
]);
30
+
31
+
$isValid = false;
32
+
33
+
if (!is_wp_error($response)) {
34
+
$result = json_decode(wp_remote_retrieve_body($response));
35
+
$isValid = $result->success;
36
+
}
37
+
38
+
return $isValid;
39
+
}
40
+
}
41
+