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.
Source Source
Changelog Changelog
| Version | Description |
|---|---|
| 2.9.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
/** * 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 );Expand full source codeCollapse full source code