WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For a plugin that communicates with somewhere else, I hear we're supposed to use wp_remote_post and wp_remote_get instead of PHP's Curl library.

Okay, but is there a fast and proper way on plugin execution to test for a blog's PHP/host OS to have the proper transport mechanism installed? I mean, I could attempt a test POST, but thought WP might have a better, faster mechanism that I can test for? Doing the following is unacceptable:

if (!function_exists('curl_exec')) {
    wp_die('The CURL API is not installed with PHP. You cannot use this plugin without that. Ask your web hosting provider to install it.');
share|improve this question
up vote 3 down vote accepted

I wouldn't cause the plugin to die like that. Just check for cURL each time you need to make a call or fall back on wp_remote_(post|get) (eg. write a wrapper function that takes care of the check and send the data/headers you want).

BUT, if you really really want to disable the plugin if cURL is not installed, you can use an activation hook to check for the curl_exec function and deactivate the plugin if not.

register_activation_hook(__FILE__, 'wpse51312_activation');
function wpse51312_activation()
        // Deactivate the plugin

        // Show the error page, Maybe this shouldn't happen?
            __('You must enable cURL support to use INSERT PLUGIN NAME'),

For what it's worth, I believe that the HTTP api tries to use cURL if it's available.

share|improve this answer
Yeah, I found in this case that die() rather than wp_die() is better if done on plugin activation. But anyway, wp_remote_post doesn't always use Curl. On some hosts, curl_exec() is disabled, yet file_get_contents() or fopen() with a remote host may be enabled. – Volomike May 6 '12 at 19:44
However, the real question is that I just want a quick way to test for the chance of failure with wp_remote_post() because none of the transport mechanisms might not be enabled. Checking simply for Curl stuff just won't cut it. – Volomike May 6 '12 at 19:45
The only way you're going to see if that happens is by making a request. wp_remote_post will return a WP_Error object if it fails. – chrisguitarguy May 6 '12 at 20:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.