# wp-data-access/5.5.22/WPDataAccess/Utilities/WPDA_Remote_Call.php

WP Data Access – App Builder for Tables, Forms, Charts, Maps &amp; Dashboards, version 5.5.22. 85 lines.

- Page: https://pluginprobe.com/plugins/wp-data-access/5.5.22/code/WPDataAccess/Utilities/WPDA_Remote_Call.php
- Raw: https://pluginprobe.com/plugins/wp-data-access/5.5.22/raw/WPDataAccess/Utilities/WPDA_Remote_Call.php
- Modified: 2024-11-29T00:01:32+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/wp-data-access/5.5.22/code/WPDataAccess/Utilities/WPDA_Remote_Call.php#L10-L20`.

```php
<?php

namespace WPDataAccess\Utilities {

	use WPDataAccess\WPDA;

	class WPDA_Remote_Call {

		public static function post( $url, $body, $die = false, $headers = array() ) {
			$response = wp_remote_post(
				$url,
				array(
					'headers' => $headers,
					'body'    => $body,
					'timeout' => 60,
				)
			);
			// var_dump($response);

			if ( is_wp_error( $response ) ) {
				WPDA::wpda_log_wp_error( json_encode( $response ) );
				if ( $die ) {
					wp_die( 'ERROR: Remote call failed [' . json_encode( $response ) . ']' );
				}

				return $response->get_error_message();
			}

			if ( ! isset( $response['response'], $response['body'] ) ) {
				WPDA::wpda_log_wp_error( json_encode( $response ) );
				if ( $die ) {
					wp_die( 'ERROR: Remote call failed [missing response|body]' );
				}

				return false;
			}

			return $response;
		}

		public static function get( $url, $args = array(), $die = false ) {
			$response = wp_remote_get( $url, $args );
			// var_dump($response);

			if ( is_wp_error( $response ) ) {
				WPDA::wpda_log_wp_error( json_encode( $response ) );
				if ( $die ) {
					wp_die( 'ERROR: Remote call failed [' . json_encode( $response ) . ']' );
				}

				return false;
			}

			if ( ! isset( $response['response'], $response['body'] ) ) {
				WPDA::wpda_log_wp_error( json_encode( $response ) );
				if ( $die ) {
					wp_die( 'ERROR: Remote call failed [missing response|body]' );
				}

				return false;
			}

			return $response;
		}

		public static function max_size() {
			$max  = ini_get('post_max_size');
			$unit = $max[ strlen( $max ) - 1 ];
			$max  = substr( $max, 0, strlen( $max ) - 1 );

			switch($unit) {
				case 'G':
					$max *= 1024;
				case 'M':
					$max *= 1024;
				case 'K':
					$max *= 1024;
			}

			return $max;
		}

	}

}
```
