Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created September 4, 2019 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommcfarlin/648da0d8f306d0f17984beeed80039c7 to your computer and use it in GitHub Desktop.
Save tommcfarlin/648da0d8f306d0f17984beeed80039c7 to your computer and use it in GitHub Desktop.
[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