Created
September 18, 2013 08:12
-
-
Save abfan1127/6606119 to your computer and use it in GitHub Desktop.
An update to the "Rotating Tweets" Wordpress plugin. Instead of taking a single twitter screen name, now I space-delimit as many as I wish. Then I loop around them. Finally I sort them by date via the usort function and its related callback.
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
$screen_names = explode(' ',$tw_screen_name); | |
$twitterjsons = array(); | |
foreach($screen_names as $screen_name) { | |
$apioptions = array('screen_name'=>$screen_name,'include_entities'=>1,'count'=>10,'include_rts'=>$tw_include_rts,'exclude_replies'=>$tw_exclude_replies); | |
if($tw_search) { | |
$apioptions['q']=$tw_search; | |
$twitterdata = rotatingtweets_call_twitter_API('search/tweets',$apioptions); | |
} elseif($tw_get_favorites) { | |
$twitterdata = rotatingtweets_call_twitter_API('favorites/list',$apioptions); | |
} elseif($tw_list) { | |
unset($apioptions['screen_name']); | |
$apioptions['slug']=$tw_list; | |
$apioptions['owner_screen_name']=$tw_screen_name; | |
$twitterdata = rotatingtweets_call_twitter_API('lists/statuses',$apioptions); | |
} else { | |
$twitterdata = rotatingtweets_call_twitter_API('statuses/user_timeline',$apioptions); | |
} | |
if(!is_wp_error($twitterdata)): | |
$twitterjson = json_decode($twitterdata['body'],TRUE); | |
if(WP_DEBUG): | |
echo "<!-- Rotating Tweets - got new data -->"; | |
endif; | |
else: | |
set_transient('rotatingtweets_wp_error',$twitterdata->get_error_messages(), 120); | |
endif; | |
$twitterjsons = array_merge($twitterjsons,$twitterjson); | |
} | |
usort($twitterjsons,'tweet_sort'); | |
$twitterjson = $twitterjsons; | |
function tweet_sort($a,$b) | |
{ | |
$a_date = strtotime($a['created_at']); | |
$b_date = strtotime($b['created_at']); | |
return ($a_date < $b_date); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Many thanks for this. Love the interface improvement so I've copied it. I've gone with an approach that uses the Twitter Search API to handle multiple accounts.