Created
September 18, 2017 21:04
-
-
Save chuckreynolds/ed5b6aa52ca83abf3d89529e998a3ede to your computer and use it in GitHub Desktop.
Sample WordPress options with time-based cache flag
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
<?php | |
function get_twitter_followers() { | |
$ttl = 2 * HOUR_IN_SECONDS; | |
$cache = get_option( 'my_twitter_followers' ); | |
if ( empty( $cache['timeout'] ) || $cache['timeout'] < time() ) { | |
$followers = wp_remote_get( ... ); | |
$cache = array( | |
'count' => $followers, | |
'timeout' => time() + $ttl, | |
); | |
update_option( 'my_twitter_followers', $cache ); | |
} | |
return $cache['count']; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment