[wp-hackers] help understanding wp_remote_get function and fatal WP_Error

Andrew Nacin wp at andrewnacin.com
Tue Feb 26 02:42:48 UTC 2013


On Mon, Feb 25, 2013 at 9:30 PM, Dion Hulse (dd32) <wordpress at dd32.id.au>wrote:

> Firstly, you should have some kind of caching on that, wp_remote_get()
> will not cache the data and will fetch it every time you call it.
>
> Next, you should check the return from the function.
> It can return a WP_Error instance if an error occurs, you can check
> for that with the is_wp_error() function, so:
>

And also, there are helper functions for this.

wp_remote_retrieve_response_code()
wp_remote_retrieve_header()
wp_remote_retrieve_body()
etc.

If there is a failure and the response is a WP_Error, then these functions
return a zero-length string. Helpful when anything other than a 200 should
be considered an error.

Nacin


More information about the wp-hackers mailing list