wp_remote_retrieve_response_code()
Gets the response code (status response) from the provided request object.
No Hooks.
Returns
Int|String. The response code as a number or an empty string if an invalid request object was provided.
Usage
wp_remote_retrieve_response_code( $response );
- $response(array) (required)
- The response object obtained using one of the HTTP API functions: wp_remote_get(), wp_remote_post(), wp_remote_head() or wp_remote_request().
Examples
#1 Get the response code of the server to our request
$response = wp_remote_get( 'http://httpbin.org/get?a=b&c=d' ); $code = wp_remote_retrieve_response_code( $response ); echo $code; //> 200
See the status_header() function description for possible response codes (response statuses) and their values.
Changelog
| Since 2.7.0 | Introduced. |
wp_remote_retrieve_response_code() wp remote retrieve response code code WP 6.8.3
function wp_remote_retrieve_response_code( $response ) {
if ( is_wp_error( $response ) || ! isset( $response['response'] ) || ! is_array( $response['response'] ) ) {
return '';
}
return $response['response']['code'];
}