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

72 lines 2.3 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 {
7 public static function post($url, $data, $headers = null, $options = null)
8 {
9 $defaultOptions = [
10 'headers' => $headers,
11 'body' => $data,
12 'timeout' => 30
13 ];
14
15 $options = wp_parse_args($options, $defaultOptions);
16 $requestReponse = wp_remote_post($url, $options);
17 if (is_wp_error($requestReponse)) {
18 return $requestReponse;
19 }
20 // $responseCode = wp_remote_retrieve_response_code($requestReponse);
21 // if (!\is_null($responseCode) && $responseCode != 200) {
22 // return wp_remote_retrieve_response_message($requestReponse);
23 // }
24 $responseBody = wp_remote_retrieve_body($requestReponse);
25 $jsonData = json_decode($responseBody);
26 return \is_null($jsonData) ? $responseBody : $jsonData;
27 }
28
29 public static function get($url, $data, $headers = null, $options = null)
30 {
31 $defaultOptions = [
32 'headers' => $headers,
33 'body' => $data,
34 'timeout' => 30
35 ];
36 $options = wp_parse_args($options, $defaultOptions);
37 $requestReponse = wp_remote_get($url, $options);
38 if (is_wp_error($requestReponse)) {
39 return $requestReponse;
40 }
41 // $responseCode = wp_remote_retrieve_response_code($requestReponse);
42 // if (!\is_null($responseCode) && $responseCode != 200) {
43 // return wp_remote_retrieve_response_message($requestReponse);
44 // }
45 $responseBody = wp_remote_retrieve_body($requestReponse);
46 $jsonData = json_decode($responseBody);
47 return \is_null($jsonData) ? $responseBody : $jsonData;
48 }
49
50 public static function request($url, $type, $data, $headers = null, $options = null)
51 {
52 $defaultOptions = [
53 'method' => $type,
54 'headers' => $headers,
55 'body' => $data,
56 'timeout' => 30
57 ];
58 $options = wp_parse_args($options, $defaultOptions);
59 $requestReponse = wp_remote_request($url, $options);
60 if (is_wp_error($requestReponse)) {
61 return $requestReponse;
62 }
63 // $responseCode = wp_remote_retrieve_response_code($requestReponse);
64 // if (!\is_null($responseCode) && $responseCode != 200) {
65 // return wp_remote_retrieve_response_message($requestReponse);
66 // }
67 $responseBody = wp_remote_retrieve_body($requestReponse);
68 $jsonData = json_decode($responseBody);
69 return \is_null($jsonData) ? $responseBody : $jsonData;
70 }
71 }
72