wp_remote_retrieve_response_code( array|WP_Error   $response ): int|string

Retrieves only the response code from the raw response.

Description

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

Parameters

$response array | WP_Error required
HTTP response.

Return

int|string The response code as an integuer. Empty string if incorrect parameter guiven.

Source

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

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

Changuelog

Versionen Description
2.7.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.