Skip to content

Instantly share code, notes, and snippets.

@roose
Created June 12, 2011 12:04
Show Gist options
  • Select an option

  • Save roose/1021488 to your computer and use it in GitHub Desktop.

Select an option

Save roose/1021488 to your computer and use it in GitHub Desktop.
Wordpress latest tweet
<?php
require_once(ABSPATH . 'wp-includes/class-snoopy.php');
$tweet = get_option("lasttweet");
$url = "http://twitter.com/statuses/user_timeline/mr_roose.json?count=20";
if ($tweet['lastcheck'] < ( mktime() - 60 ) ) {
$snoopy = new Snoopy;
$result = $snoopy->fetch($url);
if ($result) {
$twitterdata = json_decode($snoopy->results,true);
$i = 0;
while ($twitterdata[$i]['in_reply_to_user_id'] != '') {
$i++;
}
$pattern = '/\@([a-zA-Z]+)/';
$replace = '<a href="http://twitter.com/'.strtolower('\1').'">@\1</a>';
$output = preg_replace($pattern,$replace,$twitterdata[$i]["text"]);
$output = make_clickable($output);
$tweet['lastcheck'] = mktime();
$tweet['data'] = $output;
$tweet['rawdata'] = $twitterdata;
$tweet['followers'] = $twitterdata[0]['user']['followers_count'];
update_option('lasttweet',$tweet);
} else {
echo "Twitter API not responding.";
}
} else {
$output = $tweet['data'];
}
echo "<p>\"".$output."\"</p>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment