PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 1.1.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v1.1.1
V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 2.10.2 All 137 releases
bit-form / includes / Core / Util / HttpHelper.php

HttpHelper.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 1.1.1, at includes/Core/Util/HttpHelper.php

60 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace BitCode\BitForm\Core\Util;
3
4 final class HttpHelper
5 {
6 public static function post($url, $data, $headers = null, $options = null)
7 {
8 $defaultOptions =[
9 'headers' => $headers,
10 'body' => $data,
11 "timeout" => 30
12 ];
13
14 $options = wp_parse_args($options, $defaultOptions);
15 $requestReponse = wp_remote_post($url, $options);
16
17 if (is_wp_error($requestReponse)) {
18 return $requestReponse;
19 }
20 $responseBody = wp_remote_retrieve_body($requestReponse);
21 $jsonData = json_decode($responseBody);
22 return \is_null($jsonData) ? $responseBody : $jsonData;
23 }
24
25 public static function get($url, $data, $headers = null, $options = null)
26 {
27 $defaultOptions =[
28 'headers' => $headers,
29 'body' => $data,
30 "timeout" => 30
31 ];
32 $options = wp_parse_args($options, $defaultOptions);
33 $requestReponse = wp_remote_get($url, $options);
34 if (is_wp_error($requestReponse)) {
35 return $requestReponse;
36 }
37 $responseBody = wp_remote_retrieve_body($requestReponse);
38 $jsonData = json_decode($responseBody);
39 return \is_null($jsonData) ? $responseBody : $jsonData;
40 }
41
42 public static function request($url, $type, $data, $headers = null, $options = null)
43 {
44 $defaultOptions =[
45 'method' => $type,
46 'headers' => $headers,
47 'body' => $data,
48 "timeout" => 30
49 ];
50 $options = wp_parse_args($options, $defaultOptions);
51 $requestReponse = wp_remote_request($url, $options);
52 if (is_wp_error($requestReponse)) {
53 return $requestReponse;
54 }
55 $responseBody = wp_remote_retrieve_body($requestReponse);
56 $jsonData = json_decode($responseBody);
57 return \is_null($jsonData) ? $responseBody : $jsonData;
58 }
59 }
60