PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.7
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.7
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Modules / Ai / FluentFormAIAPI.php

FluentFormAIAPI.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.7, at app/Modules/Ai/FluentFormAIAPI.php

58 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Modules\Ai;
4
5 defined('ABSPATH') or die;
6
7 /**
8 * Handling AI Api.
9 * @since 6.0.0
10 */
11 class FluentFormAIAPI
12 {
13 private $url = 'https://ai.fluentforms.com/';
14
15 public function makeRequest($requestData = [])
16 {
17 $headers = [
18 'Content-Type' => 'application/json',
19 ];
20
21 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- http_request_timeout is a WordPress core hook
22 $originalTimeout = apply_filters('http_request_timeout', 5);
23
24 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- http_request_timeout is a WordPress core hook
25 add_filter('http_request_timeout', function ($timeout) {
26 return 60;
27 });
28
29 $response = wp_remote_post($this->url, [
30 'headers' => $headers,
31 'body' => json_encode($requestData),
32 ]);
33
34 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- http_request_timeout is a WordPress core hook
35 add_filter('http_request_timeout', function ($timeout) use ($originalTimeout) {
36 return $originalTimeout;
37 });
38
39 if (is_wp_error($response)) {
40 return new \WP_Error(423, $response->get_error_message());
41 }
42
43 $body = json_decode(wp_remote_retrieve_body($response), true);
44 $code = wp_remote_retrieve_response_code($response);
45
46 $error_message = __('Something went wrong.', 'fluentform');
47 if (isset($body['error']['message'])) {
48 $error_message = $body['error']['message'];
49 }
50
51 if ($code !== 200) {
52 return new \WP_Error(423, $error_message);
53 }
54
55 return $body;
56 }
57 }
58