PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.4
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.4
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 5.5.43 All 159 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.4, at WPDataAccess/Utilities/WPDA_Remote_Call.php

85 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 WPDataAccess\Utilities {
4
5 use WPDataAccess\WPDA;
6
7 class WPDA_Remote_Call {
8
9 public static function post( $url, $body, $die = false, $headers = array() ) {
10 $response = wp_remote_post(
11 $url,
12 array(
13 'headers' => $headers,
14 'body' => $body,
15 'timeout' => 60,
16 )
17 );
18 // var_dump($response);
19
20 if ( is_wp_error( $response ) ) {
21 WPDA::wpda_log_wp_error( json_encode( $response ) );
22 if ( $die ) {
23 wp_die( 'ERROR: Remote call failed [' . json_encode( $response ) . ']' );
24 }
25
26 return $response->get_error_message();
27 }
28
29 if ( ! isset( $response['response'], $response['body'] ) ) {
30 WPDA::wpda_log_wp_error( json_encode( $response ) );
31 if ( $die ) {
32 wp_die( 'ERROR: Remote call failed [missing response|body]' );
33 }
34
35 return false;
36 }
37
38 return $response;
39 }
40
41 public static function get( $url, $args = array(), $die = false ) {
42 $response = wp_remote_get( $url, $args );
43 // var_dump($response);
44
45 if ( is_wp_error( $response ) ) {
46 WPDA::wpda_log_wp_error( json_encode( $response ) );
47 if ( $die ) {
48 wp_die( 'ERROR: Remote call failed [' . json_encode( $response ) . ']' );
49 }
50
51 return false;
52 }
53
54 if ( ! isset( $response['response'], $response['body'] ) ) {
55 WPDA::wpda_log_wp_error( json_encode( $response ) );
56 if ( $die ) {
57 wp_die( 'ERROR: Remote call failed [missing response|body]' );
58 }
59
60 return false;
61 }
62
63 return $response;
64 }
65
66 public static function max_size() {
67 $max = ini_get('post_max_size');
68 $unit = $max[ strlen( $max ) - 1 ];
69 $max = substr( $max, 0, strlen( $max ) - 1 );
70
71 switch($unit) {
72 case 'G':
73 $max *= 1024;
74 case 'M':
75 $max *= 1024;
76 case 'K':
77 $max *= 1024;
78 }
79
80 return $max;
81 }
82
83 }
84
85 }