$secret, 'response' => $token, 'remoteip' => WebTotem::getUserIP(), ); $response = wp_remote_post(self::WTOTEM_RECAPTCHA_ENDPOINT, array( 'body' => $payload, 'headers' => array( 'Referer' => false, ), 'timeout' => $timeout, 'blocking' => true, )); if (!is_wp_error($response)) { $jsonResponse = wp_remote_retrieve_body($response); $decoded = @json_decode($jsonResponse, true); if (is_array($decoded) && isset($decoded['success']) && isset($decoded['score']) && isset($decoded['action'])) { if ($decoded['success'] && $decoded['action'] == $action) { return (float) $decoded['score']; } return 0.0; } } } catch (\Exception $e) { //Fall through } return 0.0; } /** * Get the captcha token provided with the current request * @param string $key if specified, override the default token parameter * @return string|null the captcha token, if present, null otherwise */ public static function get_token($key = 'wtotem-recaptcha-token') { return (isset($_POST[$key]) && is_string($_POST[$key]) && !empty($_POST[$key]) ? $_POST[$key] : null); } }