Created
December 17, 2012 21:48
-
-
Save cjbell/4322604 to your computer and use it in GitHub Desktop.
Get Cached Wordpress Tweet
This file contains hidden or 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
<?php | |
function get_cached_tweet($name){ | |
$cache_name = $name . "_tweets"; | |
if ( false === ($tweet = get_transient($cache_name))) { | |
// Get tweets | |
$site = "https://api.twitter.com/1/statuses/user_timeline.json?screen_name=".$name."&count=1"; | |
$result = wp_remote_get($site); | |
$json = $result['body']; | |
if (!is_a($json, WP_Error)) { | |
$tweet = json_decode($json); | |
} | |
set_transient($cache_name, $tweet, 600); | |
} | |
return $tweet; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment