Retrieves only the body from the raw response.
Parameters
$response
array|WP_Errorrequired- HTTP response.
Return
string The body of the response. Empty string if no body or incorrect parameter given.Source
function wp_remote_retrieve_body( $response ) {
if ( is_wp_error( $response ) || ! isset( $response['body'] ) ) {
return '';
}
return $response['body'];
}
Related
Uses | Description |
---|---|
is_wp_error()wp-includes/load.php | Checks whether the given variable is a WordPress Error. |
Used by | Description |
---|---|
WP_Automatic_Updater::has_fatal_error()wp-admin/includes/class-wp-automatic-updater.php | Performs a loopback request to check for potential fatal errors. |
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_get_https_detection_errors()wp-includes/https-detection.php | Runs a remote HTTPS request to detect whether HTTPS supported, and stores potential errors. |
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. |
WP_REST_Pattern_Directory_Controller::get_items()wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php | Search and retrieve block patterns metadata |
get_block_editor_theme_styles()wp-includes/block-editor.php | Creates an array of theme styles to load into the block editor. |
WP_Site_Health::wp_cron_scheduled_check()wp-admin/includes/class-wp-site-health.php | Runs the scheduled event to check and update the latest site health status for the website. |
WP_Site_Health::get_test_rest_availability()wp-admin/includes/class-wp-site-health.php | Tests if the REST API is accessible. |
wp_check_php_version()wp-admin/includes/misc.php | Checks if the user needs to update PHP. |
wp_edit_theme_plugin_file()wp-admin/includes/file.php | Attempts to edit a file for a theme or plugin. |
WP_Community_Events::get_events()wp-admin/includes/class-wp-community-events.php | Gets data about events near a particular location. |
translations_api()wp-admin/includes/translation-install.php | Retrieve translations from WordPress Translation API. |
network_step2()wp-admin/includes/network.php | Prints step 2 for Network installation process. |
themes_api()wp-admin/includes/theme.php | Retrieves theme installer pages from the WordPress.org Themes API. |
get_core_checksums()wp-admin/includes/update.php | Gets and caches the checksums for the given version of WordPress. |
wp_check_browser_version()wp-admin/includes/dashboard.php | Checks if the user needs a browser update. |
plugins_api()wp-admin/includes/plugin-install.php | Retrieves plugin installer pages from the WordPress.org Plugins API. |
download_url()wp-admin/includes/file.php | Downloads a URL to a local temporary file using the WordPress HTTP API. |
wp_get_popular_importers()wp-admin/includes/import.php | Returns a list from WordPress.org of popular importer plugins. |
wp_credits()wp-admin/includes/credits.php | Retrieves the contributor credits. |
wp_remote_fopen()wp-includes/functions.php | HTTP request for URI to retrieve content. |
wp_get_http()wp-includes/deprecated.php | Perform a HTTP HEAD or GET request. |
WP_SimplePie_File::__construct()wp-includes/class-wp-simplepie-file.php | Constructor. |
wp_version_check()wp-includes/update.php | Checks WordPress version against the newest version. |
wp_update_plugins()wp-includes/update.php | Checks for available updates to plugins based on the latest versions hosted on WordPress.org. |
wp_update_themes()wp-includes/update.php | Checks for available updates to themes based on the latest versions hosted on WordPress.org. |
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()wp-includes/class-wp-oembed.php | Fetches result from an oEmbed provider for a specific format and complete provider URL |
WP_HTTP_IXR_Client::query()wp-includes/class-wp-http-ixr-client.php | |
_fetch_remote_file()wp-includes/rss.php | Retrieve URL headers and content using WP HTTP Request API. |
wp_xmlrpc_server::pingback_ping()wp-includes/class-wp-xmlrpc-server.php | Retrieves a pingback and registers it. |
discover_pingback_server_uri()wp-includes/comment.php | Finds a pingback server URI based on the given URL. |
Changelog
Version | Description |
---|---|
2.7.0 | Introduced. |
Example
Retrieving data from a JSON API:
Better performance?
Skip the extra function call and get the body (or any other part of the returned array) from wp_remote_get() . That’s essentially what wp_remote_retrieve_body() is doing.
wp_remote_get()
returns (array|WP_Error) the response or WP_Error on failure. That means in your case you can have some PHP error notice if the response fails. That is bad practice and in any case you will not have any better performance. Maybe you can do something like:$body = wp_remote_get( esc_url_raw( $url ) )['body'] ?? NULL;
to avoid error notice.