PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.0
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 2.0, at includes/Core/Util/HttpHelper.php

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