我正在尝试创建一个wordpress插件,通过API获取Twitter推文,如果在页面上插入短代码[twitter],则会在页面上回显它们。
我收到错误:
“致命错误:在C:\ WAMP \ WWW \ WP \ WP-CONTENT \ PLUGINS \ PLOG \ PLUGIN.PHP第45行”中调用未定义的函数CURL_INIT()
代码中没有语法错误,也没有任何逻辑错误。
以下是代码:
<?php
/* Plugin Name: Testing a Plugin
* Plugin URI: http://www.wordpress.com
* Description: Just Testing out a plugin.
* Author: Knooww
* Author URI: http://www.wordpress.com
*/
?>
<?php
//limit calls to API..
// Save data in cache, refresh content after an hour
add_shortcode('twitter', function ($atts,$content){
$atts = shortcode_atts(array('username'=>'Default-Username',
'content' =>!empty($content) ? $content:'Follow me on twitter',
'show_tweets'=>'false',
'tweet_reset_time'=>10, //time to refresh fetch of tweets
'num_tweets'=>5
),$atts);
extract($atts);
if($show_tweets){
$tweets = fetch_tweets($num_tweets,$username,$tweet_reset_time);
}
//return '<a href="http://www.twitter.com/'.$username.'">'.$content.'</a>';
});// end add_shortcode
function fetch_tweets($num_tweets,$username,$tweet_reset_time){
$tweets = curl("https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name='$username'&count=2");
print_r($tweets);
}
function curl($url){
$c = curl_init($url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($c, CURLOPT_TIMEOUT, 5);
return json_decode(curl_exec($c));
}
?>
请让我知道我错过了什么。
答案 0 :(得分:2)
在Windows上激活PHP / CURL正在启动记事本(或类似)并从php.ini中的以下行中删除分号:
;extension=php_curl.dll
请阅读http://in1.php.net/manual/en/install.windows.extensions.php