PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.79
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.79
5.5.84 5.5.83 5.5.82 5.5.81 5.5.80 5.5.79 5.5.77 5.5.76 5.5.75 5.5.73 5.5.72 5.5.22 5.5.23 5.5.29 5.5.3 5.5.31 5.5.32 5.5.34 5.5.35 5.5.36 5.5.37 5.5.4 5.5.40 5.5.41 5.5.42 All 160 releases
wp-data-access / WPDataAccess / Utilities / WPDA_Remote_Call.php

WPDA_Remote_Call.php in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 5.5.79, at WPDataAccess/Utilities/WPDA_Remote_Call.php

129 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPDataAccess\Utilities {
4
5 use WPDataAccess\WPDA;
6
7 class WPDA_Remote_Call {
8
9 public static function post(
10 $url,
11 $body,
12 $die = false,
13 $headers = array(),
14 $sslverify = true
15 ) {
16 $response = wp_remote_post(
17 $url,
18 array(
19 'headers' => $headers,
20 'body' => $body,
21 'timeout' => 60,
22 'sslverify' => $sslverify,
23 )
24 );
25
26 if ( 'on' === WPDA::get_option( WPDA::OPTION_PLUGIN_DEBUG ) ) {
27 // WPDA::wpda_log_wp_error( $response );
28 }
29
30 if ( is_wp_error( $response ) ) {
31 WPDA::wpda_log_wp_error( json_encode( $response ) );
32 if ( $die ) {
33 wp_die( 'ERROR: Remote call failed [' . json_encode( $response ) . ']' );
34 }
35
36 return $response->get_error_message();
37 }
38
39 if ( ! isset( $response['response'], $response['body'] ) ) {
40 WPDA::wpda_log_wp_error( json_encode( $response ) );
41 if ( $die ) {
42 wp_die( 'ERROR: Remote call failed [missing response|body]' );
43 }
44
45 return false;
46 }
47
48 return $response;
49 }
50
51 public static function get( $url, $args = array(), $die = false ) {
52 $response = wp_remote_get( $url, $args );
53
54 if ( 'on' === WPDA::get_option( WPDA::OPTION_PLUGIN_DEBUG ) ) {
55 // WPDA::wpda_log_wp_error( $response );
56 }
57
58 if ( is_wp_error( $response ) ) {
59 WPDA::wpda_log_wp_error( json_encode( $response ) );
60 if ( $die ) {
61 wp_die( 'ERROR: Remote call failed [' . json_encode( $response ) . ']' );
62 }
63
64 return false;
65 }
66
67 if ( ! isset( $response['response'], $response['body'] ) ) {
68 WPDA::wpda_log_wp_error( json_encode( $response ) );
69 if ( $die ) {
70 wp_die( 'ERROR: Remote call failed [missing response|body]' );
71 }
72
73 return false;
74 }
75
76 return $response;
77 }
78
79 public static function delete( $url, $args = array(), $headers = array(), $die = false ) {
80 $response = wp_remote_request(
81 $url,
82 array(
83 'method' => 'DELETE',
84 'headers' => $headers,
85 )
86 );
87
88 if ( 'on' === WPDA::get_option( WPDA::OPTION_PLUGIN_DEBUG ) ) {
89 // WPDA::wpda_log_wp_error( $response );
90 }
91
92 if ( is_wp_error( $response ) ) {
93 WPDA::wpda_log_wp_error( json_encode( $response ) );
94 if ( $die ) {
95 wp_die( 'ERROR: Remote DELETE failed [' . json_encode( $response ) . ']' );
96 }
97
98 return false;
99 }
100
101 $status_code = wp_remote_retrieve_response_code( $response );
102 if ( $status_code === 204 ) {
103 return true;
104 }
105
106 WPDA::wpda_log_wp_error("ERROR: Delete failed: HTTP $status_code");
107 return false;
108 }
109
110 public static function max_size() {
111 $max = ini_get('post_max_size');
112 $unit = $max[ strlen( $max ) - 1 ];
113 $max = substr( $max, 0, strlen( $max ) - 1 );
114
115 switch($unit) {
116 case 'G':
117 $max *= 1024;
118 case 'M':
119 $max *= 1024;
120 case 'K':
121 $max *= 1024;
122 }
123
124 return $max;
125 }
126
127 }
128
129 }