Title: wp_safe_remote_get
Published: April 25, 2014
Last modified: February 24, 2026

---

# wp_safe_remote_get( string $url, array $args = array() ): array|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/?output_format=md#see-also)
 * [Parameters](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/?output_format=md#wp--skip-link--target)

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

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/?output_format=md#description)󠁿

This function is ideal when the HTTP request is being made to an arbitrary URL. 
The URL, and every URL it redirects to, are validated with [wp_http_validate_url()](https://developer.wordpress.org/reference/functions/wp_http_validate_url/)
to avoid Server Side Request Forgery attacks (SSRF).

The only supported protocols are `http` and `https`.

### 󠀁[See also](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/?output_format=md#see-also)󠁿

 * [wp_remote_request()](https://developer.wordpress.org/reference/functions/wp_remote_request/):
   For more information on the response array format.
 * [WP_Http::request()](https://developer.wordpress.org/reference/classes/WP_Http/request/):
   For default arguments information.
 * [wp_http_validate_url()](https://developer.wordpress.org/reference/functions/wp_http_validate_url/):
   For more information about how the URL is validated.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/?output_format=md#parameters)󠁿

 `$url`stringrequired

URL to retrieve.

`$args`arrayoptional

Request arguments. 
 See [WP_Http::request()](https://developer.wordpress.org/reference/classes/wp_http/request/)
for information on accepted arguments.

Default:`array()`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/?output_format=md#return)󠁿

 array|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) The
response or [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
on failure.
 See [WP_Http::request()](https://developer.wordpress.org/reference/classes/wp_http/request/)
for information on return value.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/?output_format=md#source)󠁿

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

[View all references](https://developer.wordpress.org/reference/files/wp-includes/http.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/http.php#L81)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/http.php#L81-L85)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/?output_format=md#related)󠁿

| Uses | Description | 
| [_wp_http_get_object()](https://developer.wordpress.org/reference/functions/_wp_http_get_object/)`wp-includes/http.php` |

Returns the initialized [WP_Http](https://developer.wordpress.org/reference/classes/wp_http/) Object

  |

| Used by | Description | 
| [WP_Font_Collection::load_from_url()](https://developer.wordpress.org/reference/classes/wp_font_collection/load_from_url/)`wp-includes/fonts/class-wp-font-collection.php` |

Loads the font collection data from a JSON file URL.

  | 
| [WP_REST_URL_Details_Controller::get_remote_url()](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/get_remote_url/)`wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php` |

Retrieves the document title from a remote URL.

  | 
| [download_url()](https://developer.wordpress.org/reference/functions/download_url/)`wp-admin/includes/file.php` |

Downloads a URL to a local temporary file using the WordPress HTTP API.

  | 
| [wp_remote_fopen()](https://developer.wordpress.org/reference/functions/wp_remote_fopen/)`wp-includes/functions.php` |

HTTP request for URI to retrieve content.

  | 
| [WP_oEmbed::discover()](https://developer.wordpress.org/reference/classes/wp_oembed/discover/)`wp-includes/class-wp-oembed.php` |

Attempts to discover link tags at the given URL for an oEmbed provider.

  | 
| [WP_oEmbed::_fetch_with_format()](https://developer.wordpress.org/reference/classes/wp_oembed/_fetch_with_format/)`wp-includes/class-wp-oembed.php` |

Fetches result from an oEmbed provider for a specific format and complete provider URL

  | 
| [wp_xmlrpc_server::pingback_ping()](https://developer.wordpress.org/reference/classes/wp_xmlrpc_server/pingback_ping/)`wp-includes/class-wp-xmlrpc-server.php` |

Retrieves a pingback and registers it.

  | 
| [discover_pingback_server_uri()](https://developer.wordpress.org/reference/functions/discover_pingback_server_uri/)`wp-includes/comment.php` |

Finds a pingback server URI based on the given URL.

  |

[Show 3 more](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.6.0](https://developer.wordpress.org/reference/since/3.6.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/?output_format=md#comment-content-2338)
 2.    [InfiWebs](https://profiles.wordpress.org/infiwebs/)  [  9 years ago  ](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/#comment-2338)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_safe_remote_get%2F%23comment-2338)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_safe_remote_get%2F%23comment-2338)
 4.  **Retrieving and decoding json file – **
 5.      ```php
         $request = wp_safe_remote_get( 'http://www.example.com/file.json' );
     
         if ( is_wp_error( $request ) ) {
         	return false;
         }
     
         $body = wp_remote_retrieve_body( $request );
         $json = json_decode( $body );
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_safe_remote_get%2F%3Freplytocom%3D2338%23feedback-editor-2338)
 7.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/?output_format=md#comment-content-3573)
 8.    [Mindaugas Jakubauskas](https://profiles.wordpress.org/meevly/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/#comment-3573)
 9.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_safe_remote_get%2F%23comment-3573)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_safe_remote_get%2F%23comment-3573)
 10. Request with authorization parameters
 11.     ```php
         $response = wp_safe_remote_get( 
         	'https://endpoint-uri.com/example', 
         	array(
         		'timeout'     => 45,
         		'redirection' => 5,
         		'headers'     => array(
         			'Content-Type' => 'application/json; charset=utf-8',
         			'Authorization'      => 'Basic AUTH_KEY_HERE',
         		),
         		'cookies'     => array(),
         	),
         );
         ```
     
 12.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_safe_remote_get%2F%3Freplytocom%3D3573%23feedback-editor-3573)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_safe_remote_get%2F)
before being able to contribute a note or feedback.