Skip to content

Instantly share code, notes, and snippets.

@jtsternberg
Forked from lswilson/content-author-tweet.php
Last active December 22, 2015 23:19
<?php
function prefix_show_latest_tweet() {
if ( ! class_exists( 'TwitterWP' ) )
require_once( 'path_to/TwitterWP.php' );
// get data for current post author
$curauth = get_userdata( $post->post_author );
$twitter_id = $curauth->twitter;
$app = array(
'consumer_key' => 'nbRYD9VZGOk8VDiqvuVg',
'consumer_secret' => 'MMtHXv9ErHjLEOcNJLjNWfC3WRVy1Qe3qHE4vl4Uo',
'access_token' => '1330201-jMrtoilTOGUCneecIV5yGYD6mUh8tmxbf5OWEUM',
'access_token_secret' => 'wzW875Vsj2xlGQivqvW1h35Zq7GkT6VqLVtBn0gJqY',
);
// initiate your app
$tw = TwitterWP::start( $app );
// bail here if the user doesn't exist
if ( ! $tw->user_exists( $twitter_id ) )
return;
$tweets = $tw->get_tweets( $twitter_id, 1 );
if ( is_wp_error( $tweets ) )
return;
foreach( $tweets as $chirp ) {
echo apply_filters( 'the_content', 'https://twitter.com/'. $twitter_id .'/status/'. $chirp->id_str );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment