apply_filters( ‘http_response’, array $response, array $parsed_args, string $url )

Filters a successful HTTP API response immediately before the response is returned.

Parameters

$responsearray
HTTP response.
$parsed_argsarray
HTTP request arguments.
$urlstring
The request URL.

Source

return apply_filters( 'http_response', $response, $parsed_args, $url );

Changelog

VersionDescription
2.9.0Introduced.

User Contributed Notes

  1. Skip to note 2 content
    /**
     * Return canned body content for invalid HTTP requests.
     *
     * In this example, "invalid" would be defined as any status code other than
     * 200, 301, or 302.
     *
     * @see WP_Http::request()
     *
     * @param array  $response The HTTP response.
     * @param array  $args     Request arguments. 
     * @param string $url      Request URL.
     *
     * @return array The filtered HTTP response.
    */
    function wpdocs_invalid_request_response( $response, $args, $url ) {
    	if ( ! in_array( $response['response']['code'], array( 200, 301, 302 ) ) ) {
    		$response['body'] = __( 'No content found', 'yourtextdomain' );
    	}
    	return $response;
    }
    add_filter( 'http_response', 'wpdocs_invalid_request_response', 10, 3 );

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