How do you use curl within wordpress plugins?
-
I’m creating a wordpress plugin and I’m having trouble getting a cURL call to function correctly.
Lets say I have a page http://www.domain.com/wp-admin/admin.php?page=orders
Within the orders page I have a function that looks to see if a button was clicked and if so it needs to do a cURL call to the same page (www.domain.com/wp-admin/admin.php?page=orders&dosomething=true) to kick off a different function. The reason I’m doing it this way is so I can have this cURL call be async.
I’m not getting any errors, but I’m also not getting any response back. If I change my url to google.com or example.com I will get a response. Is there an authentication issue or something of that nature possibly?
My code looks something like this.. I’m using gets, echos, and not doing async just for the ease of testing.
Also, sorry for the bad question title, if you have a suggestion let me know so I can edit it.
if(isset($_POST[‘somebutton’]))
{
curlRequest(“www.domain.com/wp-admin/admin.php?page=orders&dosomething=true”);
}if($_GET[‘dosomething’] == “true”)
{
echo(“do something”);
exit;
}function curlRequest($url) {
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
return($response);
}
The topic ‘How do you use curl within wordpress plugins?’ is closed to new replies.