apply_filters( 'http_response', array $response, array $r, string $url )

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


Description Description


Parameters Parameters

$response

(array) HTTP response.

$r

(array) HTTP request arguments.

$url

(string) The request URL.


Top ↑

Source Source

File: wp-includes/class-http.php

View on Trac


Top ↑

Changelog Changelog

Changelog
Version Description
2.9.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Drew Jaynes
    /**
     * 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.