atomicsmash/twitter-feed-wordpress

There is no license information available for the latest version (0.2.1) of this package.

Atomic Smash - Twitter Feed for WordPress

0.2.1 2020-07-14 10:33 UTC

This package is auto-updated.

Last update: 2024-04-14 18:42:03 UTC


README

Installation

To make the class available, please add the following to your composer file:

"atomicsmash/twitter-feed-wordpress" : "*",

Next, create a twitter app and generate your API access keys here.

Then add these inside your environment specific constants to your wp-config file, filling in the values as appropriate:

define('TWITTER_CONSUMER_KEY','');
define('TWITTER_CONSUMER_SECRET','');
define('TWITTER_OAUTH_TOKEN','');
define('TWITTER_OAUTH_TOKEN_SECRET','');

At the current time you can only have one twitter feed per site however this may be changed in the future.

Pulling Tweets from a Specific User

Just add a constant specifying the username:

define('TWITTER_USERNAME','');

Don't worry about adding the '@' symbol. For example define('TWITTER_USERNAME','atomicsmash')

Using feed in theme

You can query the cached tweets simply by calling the get method of the twitterAPI class:

if( isset( $twitterAPI ) ){

	$tweets = $twitterAPI->get([
		'results_per_page'	=> 4, 		// int
		'order'			=> 'asc',	// 'asc|desc'
		'tweet_type'		=> 'all'	// 'all|tweet|retweet|reply'
	]);

}
Parameter Type Description
results_per_page int The number of results to show per page
order string desc for newest first, asc for oldest
tweet_type string One of all, tweet, retweet or reply. What kind of tweets should be returned.

Background syncing

To sync tweets in background, schedule a cron job to run the command:

wp twitter sync_tweets

If you are using composer in your project, then your WordPress core files might be inside a subfolder. Please modify the path to reflect this. The cron job might look like this:

/usr/local/bin/wp twitter sync_tweets --path=/path/to/www.website.co.uk/wp