Created
December 6, 2013 10:57
-
-
Save ahmad24/7821958 to your computer and use it in GitHub Desktop.
wordpress : transient Skeleton
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 | |
// Fetches from an online radio a song title currently on air | |
function boj_myplugin_fetch_song_title_from_radio() { | |
// ... code to fetch data from the remote website | |
return $title; | |
} | |
// Get song title from database, using a 3 minute transient, and return it | |
function boj_myplugin_get_song_title() { | |
// Get transient value | |
$title = get_transient( 'boj_myplugin_song' ); | |
// If the transient does not exists or has expired, refresh it | |
if( false === $title ) { | |
$title = boj_myplugin_fetch_song_title_from_radio(); | |
set_transient( 'boj_myplugin_song', $title, 180 ); | |
} | |
return $title; | |
}?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment