Skip to content

Instantly share code, notes, and snippets.

@emarket-design
Created March 16, 2016 16:08
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 emarket-design/a124ba38c53d7cdb61fb to your computer and use it in GitHub Desktop.
Save emarket-design/a124ba38c53d7cdb61fb to your computer and use it in GitHub Desktop.
When using WordPress HTTP API, if the connection fails you could use the below code to display the error message.
$response = wp_remote_post($url);
if (is_wp_error($response)) {
$error = $response->get_error_message();
echo $error;
} else {
$content = wp_remote_retrieve_body($response);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment