Skip to content

Instantly share code, notes, and snippets.

@WerdsWords
Last active December 19, 2015 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WerdsWords/6037579 to your computer and use it in GitHub Desktop.
Save WerdsWords/6037579 to your computer and use it in GitHub Desktop.
#11: http_response
<?php
/**
* Return canned body content for invalid http requests
*
* @see WP_Http::request()
*
* @param array $response The http response.
* @param array $args An array of arguments.
* @param string $url The 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 );
@WerdsWords
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment