wp_remote_retrieve_response_code() WordPress Function

The wp_remote_retrieve_response_code() function is used to get the HTTP response code from a remote request. This is useful for checking the status of a request, or for debugging purposes.

wp_remote_retrieve_response_code( array|WP_Error $response ) #

Retrieve only the response code from the raw response.


Description

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


Top ↑

Parameters

$response

(array|WP_Error)(Required)HTTP response.


Top ↑

Return

(int|string) The response code as an integer. Empty string on incorrect parameter given.


Top ↑

Source

File: wp-includes/http.php

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

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


Top ↑

Changelog

Changelog
VersionDescription
2.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.