1

I am trying to make a wordpress plugin that fetches twitter tweets via API and echoes them on page if a shortcode [twitter] is inserted on a page.

I am getting an error:

"FATAL ERROR: CALL TO UNDEFINED FUNCTION CURL_INIT() IN C:\WAMP\WWW\WP\WP-CONTENT\PLUGINS\PLOG\PLUGIN.PHP ON LINE 45"

There is no syntax error in the code neither s there any logical error.

Here is the code:

<?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));



}


?>

Please let me know what I am missing.

1 Answer 1

2

Activation of PHP/CURL on windows is starting up notepad (or similar) and removing a semicolon from the following line in php.ini:

;extension=php_curl.dll

Please Read https://www.php.net/manual/en/install.windows.extensions.php

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.