How do you use curl within wordpress plugins?

妖精的绣舞 提交于 2019-12-03 14:26:27

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!