This repository is no longer actively maintained. The plugin still works, but does not receive any further updates other than community contributed fixes. |
---|
WordPress plugin to get latest tweets for user and/or hashtag.
Basically this plugin fetches tweets from Twitter, saves those to transient and next requests will be served from there. After transient has expired and deleted, new fetch from Twitter will be made and saved to transient. This implements very simple cache.
Handcrafted with love at Digitoimisto Dude Oy, a Finnish boutique digital agency in the center of Jyväskylä.
Plugin uses twitteroauth library made by Abraham Williams.
- Please note before using
- License
- Usage
- Usage example for displaying a Twitter user feed
- Limiting feed items
- Make tweet links clickable
- Hooks
- Composer
- Contributing
This plugin is not meant to be "plugin for everyone", it needs at least some basic knowledge about php and css to add it to your site and making it look beautiful.
This is a plugin in development for now, so it may update very often.
Dude Tweets feed is released under the GNU GPL 2 or later.
This plugin does not have settings page or provide anything visible on front-end. So it's basically dumb plugin if you don't use any filters listed below.
Use of authentication filters is mandatory.
Get user tweets by calling function dude_twitter_feed()->get_user_tweets()
, pass username as a only argument.
Get hashtag tweets by calling function dude_twitter_feed()->get_hashtag_tweets()
, pass hashtag as a only argument.
- Go to apps.twitter.com and create app for your WordPress site
- Get your Consumer Key (API Key) from Details tab and Consumer Secret (API Secret) from Keys and Access Tokens tab. In the bottom of Keys and Access Tokens, click Create my access token.
- Add this snippet to functions.php and copy your tokens accordingly:
/**
* Init Twitter
*/
add_filter( 'dude-twitter-feed/oauth_consumer_key', function() { return 'token_here'; } );
add_filter( 'dude-twitter-feed/oauth_consumer_secret', function() { return 'token_here'; } );
add_filter( 'dude-twitter-feed/oauth_access_token', function() { return 'token_here'; } );
add_filter( 'dude-twitter-feed/oauth_access_token_secret', function() { return 'token_here'; } );
- Then display tweets with this loop for example in front-page.php or wherever you want to display tweets:
<?php
if ( function_exists('dude_twitter_feed') ) :
$tweets = dude_twitter_feed()->get_user_tweets( 'mashable' );
if ($tweets) : ?>
<div class="feed twitter-feed">
<?php foreach ( $tweets as $tweet ) : ?>
<div class="item">
<?php echo linkify_tweet( $tweet->text ); ?>
<p class="link-to-tweet"><a target="_blank" href="https://twitter.com/mashable/status/<?php echo $tweet->id; ?>">View tweet</a></p>
</div><!-- .item -->
<?php endforeach; ?>
</div><!-- .feed -->
<?php endif;
endif; ?>
/**
* Tweet settings
*/
add_filter( 'dude-twitter-feed/user_tweets_parameters', function( $args ) {
$args['count'] = 4;
return $args;
});
/**
* Make tweet links clickable
*/
function linkify_tweet( $tweet ) {
$tweet = preg_replace('/([\w]+\:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/', '<a target="_blank" href="$1">$1</a>', $tweet);
$tweet = preg_replace('/#([A-Öa-z0-9\/\.]*)/', '<a target="_new" href="http://twitter.com/search?q=$1">#$1</a>', $tweet);
$tweet = preg_replace('/@([A-Öa-z0-9\/\.]*)/', '<a href="http://www.twitter.com/$1">@$1</a>', $tweet);
return $tweet;
}
All the settings are set with filters, and there is also few filters to change basic functionality and manipulate data before caching.
Authentication is made with four different strings, you can obtain all of those from Twitter application manager.
Filters are dude-twitter-feed/oauth_consumer_key
, dude-twitter-feed/oauth_consumer_secret
, dude-twitter-feed/oauth_access_token
and dude-twitter-feed/oauth_access_token_secret
.
Defaults to empty string.
Change name of the transient for user tweets, must be unique for every user. Passed arguments are default name and username.
Defaults to dude-twitter-user-$username
.
Change endpoint for user tweets fetch. Only passed argument is default endpoint.
Defaults to statuses/user_timeline
.
Modify api call parameters, example count of results. Only passed argument is array of default parameters.
Defaults to result count of five, retweet include and user information trimming.
Possible parameters are listed in Twitter documentation.
Manipulate or use data before it's cached to transient. Only passed argument is array of tweets.
Change activity cache lifetime. Only passed argument is default lifetime in seconds.
Defaults to 600 (= ten minutes).
Change name of the transient for hashtag tweets, must be unique for every hashtag. Passed arguments are default name and hashtag.
Defaults to dude-twitter-hashtag-$hashtag
.
Change endpoint for hashtag tweets fetch. Only passed argument is default endpoint.
Defaults to search/tweets
.
Modify api call parameters, example count of results. Only passed argument is array of default parameters.
Defaults to result count of five.
Possible parameters are listed in Twitter documentation.
Manipulate or use data before it's cached to transient. Only passed argument is array of tweets.
Change activity cache lifetime. Only passed argument is default lifetime in seconds.
Defaults to 600 (= ten minutes).
To use with composer, run composer require digitoimistodude/dude-twitter-feed dev-master
in your project directory or add "digitoimistodude/dude-twitter-feed":"dev-master"
to your composer.json require.
If you have ideas about the theme or spot an issue, please let us know. Before contributing ideas or reporting an issue about "missing" features or things regarding to the nature of that matter, please read Please note section. Thank you very much.