[WordPress] Working with cURL, WordPress, and Valet
<?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