How do you use curl within wordpress plugins? How do you use curl within wordpress plugins? wordpress wordpress

How do you use curl within wordpress plugins?


You're not supposed to use CURL in WordPress Plugins.

Instead use the wp_ function for issuing HTTP requests, e.g.

function wp_plugin_event_handler () {    $url = 'http://your-end-point';      $foo = 'bar';    $post_data = array(         'email' => urlencode($foo));    $result = wp_remote_post( $url, array( 'body' => $post_data ) );}add_action("wp_plugin_event", "wp_plugin_event_handler");

In the past I've run into issues where WordPress plugins event handlers would hang with CURL. Using the WP_ functions instead worked as expected.


The admin section of the blog is password-protected, of course. You'll need to pass authentication data. Look up http authentication for details. Look specifically here:

http://www.php.net/manual/en/function.curl-setopt.php

You'll want to set the CURLOPT_USERPWD option and possibly CURLOPT_HTTPAUTH.