I’m trying to make an API call from within a theme’s functions file and am having some issues. I’m hooking in to Contact Form 7’s
wpcf7_mail_sent action to use some of that data when a form gets sent to make that call. I’m also using my code from a separate, non-wordpress part of the site to make the cURL statement, so I know that the chunk of code as well as the url are valid. Here’s the options that I have set for my cURL request:
curl_setopt($ch, CURLOPT_URL, 'API URL'); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'content-type: application/soap+xml' )); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_FILE, $fh); curl_exec($ch); curl_close($ch);
Some additional information:
$data is an xml string containing the information I’m pushing to the API
I have commented out the curl_exec() line and everything works fine, so it doesn’t seem like there’s a syntax error somewhere else, like a missing ; or anything like that.
Again, this is pretty much copy and pasted from a file whose request works
I know WordPress can do some strange things where using certain functions within WordPress need certain settings to work correctly, so I’m guessing its something like that? I’m just not sure where to start looking. Any help you might be able to provide would be great. Thanks for your time!
Read more here: cURL within a WordPress theme’s functions file not working