Created
July 18, 2014 00:44
-
-
Save generatepress/1c4b507dbc4080149ae1 to your computer and use it in GitHub Desktop.
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
function generate_get_fonts( $amount = 1000 ) | |
{ | |
if ( get_transient('generate_get_fonts') ) | |
return; | |
$selectDirectory = ''; | |
$selectDirectory = plugin_dir_path( __FILE__ ); | |
$fontFile = $selectDirectory . '/cache/google-web-fonts.txt'; | |
//Total time the file will be cached in seconds, set to a week | |
$cachetime = 86400 * 7; | |
if(file_exists($fontFile) && $cachetime < filemtime($fontFile)) | |
{ | |
$content = json_decode(file_get_contents($fontFile)); | |
} else { | |
$googleApi = 'https://www.googleapis.com/webfonts/v1/webfonts?sort=popularity&key=AIzaSyAfzHmLjE4RBF6kSi3KW8ZD-rzhxSJP9C4'; | |
$fontContent = wp_remote_get( $googleApi, array('sslverify' => false) ); | |
$fp = fopen($fontFile, 'w'); | |
fwrite($fp, $fontContent['body']); | |
fclose($fp); | |
$content = json_decode($fontContent['body']); | |
} | |
set_transient('generate_get_fonts', $content->items, WEEK_IN_SECONDS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment