Skip to content

Instantly share code, notes, and snippets.

@kurtpayne
Created March 10, 2012 03:17
Show Gist options
  • Save kurtpayne/2009924 to your computer and use it in GitHub Desktop.
Save kurtpayne/2009924 to your computer and use it in GitHub Desktop.
Use wp_remote_get instead of curl
Index: github_gist_wordpress_plugin.php
===================================================================
--- github_gist_wordpress_plugin.php (revision 517091)
+++ github_gist_wordpress_plugin.php (working copy)
@@ -46,13 +46,12 @@
}
function get_content_from_url($url) {
- $ch = curl_init();
- curl_setopt($ch,CURLOPT_URL,$url);
- curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1);
- $content = curl_exec($ch);
- curl_close($ch);
- return $content;
+ $response = wp_remote_get($url);
+ if( is_wp_error( $response ) ) {
+ return '';
+ } else {
+ return $response['body'];
+ }
}
function gist_raw($id, $file) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment