Skip to content

Instantly share code, notes, and snippets.

@scofennell
Created January 28, 2019 14:42
Show Gist options
  • Save scofennell/6266d07e0c6caba1e3ae591330bc8538 to your computer and use it in GitHub Desktop.
Save scofennell/6266d07e0c6caba1e3ae591330bc8538 to your computer and use it in GitHub Desktop.
php function for parsing a wp_remote_request into a wp_error
<?php
function call() {
$response = wp_remote_request( $this -> url, $this -> args );
$code = wp_remote_retrieve_response_code( $response );
$first_digit = $code[0];
$good_responses = array( 2, 3 );
if( ! in_array( $first_digit, $good_responses ) {
$body = wp_remote_retrieve_body( $response );
$out = new WP_Error( $code, $body );
} else {
$out = $response;
}
return $out;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment