-
-
Save krogsgard/5224775 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Twitter Feed | |
add_shortcode( 'tweet-tweet', 'infom_get_twitter_feed' ); | |
function infom_get_twitter_feed( $atts ) { | |
extract(shortcode_atts(array( | |
'handle' => 'krogsgard', | |
'count' => '1' | |
), $atts)); | |
$handle = sanitize_text_field( $handle ); | |
$count = intval( $count ); | |
// Check transients | |
$tweet_body = get_transient( 'infom_twitter_data' ); | |
if( empty( $tweet_body ) ) { | |
$twitter_url = 'https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=' . $handle . '&count=' . $count; | |
$data = wp_remote_get( $twitter_url ); | |
$tweet_body = wp_remote_retrieve_body( $data ); | |
if( empty( $tweet_body ) ) | |
return false; | |
$tweet_body = json_decode( $tweet_body, true ); | |
set_transient( 'infom_twitter_data', $tweet_body, 50 ); | |
} | |
//Begin Output | |
$output = '<aside class="twitter-feed">'; | |
// Work with decoded data | |
foreach( $tweet_body as $tweet ) { | |
$output .= '<div class="single-tweet">'; | |
// $output .= '<span class="twitter-meta"><time datetime="' . date( 'Y-m-d', strtotime( $tweet['created_at'] ) ) . '">' . date( 'd F, Y', strtotime( $tweet['created_at'] ) ) . '</time>'; | |
// $output .= ' - <a href="http://twitter.com/' . $tweet['user']['screen_name'] . '">@' . $tweet['user']['screen_name'] . '</a></span>'; | |
$output .= make_clickable( $tweet['text'] ); | |
$output .= '</div>'; | |
} | |
$output .= '</aside>'; | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment