-
-
Save tommcfarlin/648da0d8f306d0f17984beeed80039c7 to your computer and use it in GitHub Desktop.
[WordPress] Working with cURL, WordPress, and Valet
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 | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment