Giter Site home page Giter Site logo

dude-twitter-feed's Introduction

‼️ This repository is no longer actively maintained. The plugin still works, but does not receive any further updates other than community contributed fixes.

Dude Tweets feed

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.

Table of contents

  1. Please note before using
  2. License
  3. Usage
  4. Usage example for displaying a Twitter user feed
  5. Limiting feed items
  6. Make tweet links clickable
  7. Hooks
  8. Composer
  9. Contributing

Please note before using

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.

License

Dude Tweets feed is released under the GNU GPL 2 or later.

Usage

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.

Usage example for displaying a Twitter user feed

  1. Go to apps.twitter.com and create app for your WordPress site
  2. 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.
  3. 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'; } );
  1. 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; ?>

Limiting feed items

/**
 * Tweet settings
 */
add_filter( 'dude-twitter-feed/user_tweets_parameters', function( $args ) {
  $args['count'] = 4;

  return $args;
});

Make tweet links clickable

/**
 * 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;
}

Hooks

All the settings are set with filters, and there is also few filters to change basic functionality and manipulate data before caching.

Authentication

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.

dude-twitter-feed/user_tweets_transient

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.

dude-twitter-feed/user_tweets_endpoint

Change endpoint for user tweets fetch. Only passed argument is default endpoint.

Defaults to statuses/user_timeline.

dude-twitter-feed/user_tweets_parameters

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.

dude-twitter-feed/user_tweets

Manipulate or use data before it's cached to transient. Only passed argument is array of tweets.

dude-twitter-feed/user_tweets_lifetime

Change activity cache lifetime. Only passed argument is default lifetime in seconds.

Defaults to 600 (= ten minutes).

dude-twitter-feed/hashtag_tweets_transient

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.

dude-twitter-feed/user_tweets_endpoint

Change endpoint for hashtag tweets fetch. Only passed argument is default endpoint.

Defaults to search/tweets.

dude-twitter-feed/hashtag_tweets_parameters

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.

dude-twitter-feed/hashtag_tweets

Manipulate or use data before it's cached to transient. Only passed argument is array of tweets.

dude-twitter-feed/hashtag_tweets_lifetime

Change activity cache lifetime. Only passed argument is default lifetime in seconds.

Defaults to 600 (= ten minutes).

Composer

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.

Contributing

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.