I have some code that that I only want to execute if curl_init() is present. I’m checking for it’s existence with this code:
if(function_exists('curl_init'))
{
$c = curl_init();
curl_setopt($c, CURLOPT_URL, 'http://www.my-site.ext/' . $data . '/');
curl_setopt($c, CURLOPT_HEADER, 0);
curl_exec($c);
curl_close($c);
}
The if() returns true, however the code inside throws this error:
Fatal error: Call to undefined function curl_init() in /var/www/wp-content/plugins/my-plugin-name/inc/myplugin_functions.php on line 15
How can I properly check whether curl_init() exists?
You can try
is_callable()like this: