Skip to content

Instantly share code, notes, and snippets.

@ahmad24
Created December 6, 2013 10:57
Show Gist options
  • Save ahmad24/7821958 to your computer and use it in GitHub Desktop.
Save ahmad24/7821958 to your computer and use it in GitHub Desktop.
wordpress : transient Skeleton
<?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