public
Created

Use wp_remote_get instead of curl

  • Download Gist
wp_remote_get.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
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) {

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.