Created
January 28, 2019 14:42
-
-
Save scofennell/6266d07e0c6caba1e3ae591330bc8538 to your computer and use it in GitHub Desktop.
php function for parsing a wp_remote_request into a wp_error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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