Skip to content

Instantly share code, notes, and snippets.

@aprakasa
Created December 12, 2012 02:38
Show Gist options
  • Save aprakasa/4264387 to your computer and use it in GitHub Desktop.
Save aprakasa/4264387 to your computer and use it in GitHub Desktop.
<?php
/**
* Using caching for theme options
* @link http://speckyboy.com/2011/12/14/website-speed-part-3-caching-wordpress/
* /
function my_get_cache_option($option_name = 'ThemeAdminOptions' ){
// get wanted transient
$value = get_transient( $option_name );
// check if it has any content
if(false === $value){
// if no content in the transient get new copy of wanted option
$value = get_option( $option_name );
// set new transient with a refresh of 1 day
set_transient( $option_name, $value, 60*60*24 );
}
// return the transient $value or newly created $value
return $value;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment