-
-
Save tommcfarlin/8762acc585d6b4987b23a1304615bd4d to your computer and use it in GitHub Desktop.
[WordPress] The Difference in cURL and WordPress Requests
This file contains 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 | |
try { | |
$curl = curl_init(); | |
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET'); | |
curl_setopt($curl, CURLOPT_URL, $url); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); | |
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); | |
$response = curl_exec($curl); | |
if (\is_object($response)) { | |
return false; | |
} | |
if (false === $response) { | |
throw new Exception(curl_error($curl), curl_errno($curl)); | |
} | |
curl_close($curl); | |
} catch (Exception $e) { | |
trigger_error( | |
sprintf( | |
'Curl failed with error #%d: %s', | |
$e->getCode(), | |
$e->getMessage() | |
), | |
E_USER_ERROR | |
); | |
} |
This file contains 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 | |
$response = wp_safe_remote_get($url); | |
if (is_wp_error($response)) { | |
return ''; | |
} | |
$response = $response['body']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment