wp_safe_remote_get()WP 3.6.0

Retrieve the raw response from a safe HTTP request using the GET method.

This function is ideal when the HTTP request is being made to an arbitrary URL. The URL is validated to avoid redirection and request forgery attacks.

No Hooks.

Return

Array|WP_Error. The response or WP_Error on failure.

Usage

wp_safe_remote_get( $url, $args );
$url(string) (required)
URL to retrieve.
$args(array)
Request arguments. See WP_Http::request() for information on accepted arguments.
Default: empty array

Notes

Changelog

Since 3.6.0 Introduced.

wp_safe_remote_get() code WP 6.4.3

function wp_safe_remote_get( $url, $args = array() ) {
	$args['reject_unsafe_urls'] = true;
	$http                       = _wp_http_get_object();
	return $http->get( $url, $args );
}