wp_remote_retrieve_response_code()WP 2.7.0

Retrieve only the response code from the raw response.

Will return an empty string if incorrect parameter value is given.

No Hooks.

Return

Int|String. The response code as an integer. Empty string if incorrect parameter given.

Usage

wp_remote_retrieve_response_code( $response );
$response(array|WP_Error) (required)
HTTP response.

Examples

0

#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() code WP 6.5.2

function wp_remote_retrieve_response_code( $response ) {
	if ( is_wp_error( $response ) || ! isset( $response['response'] ) || ! is_array( $response['response'] ) ) {
		return '';
	}

	return $response['response']['code'];
}