Created
March 27, 2014 05:26
-
-
Save wokamoto/9800905 to your computer and use it in GitHub Desktop.
[WordPress] remote_get transient
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 | |
function transient_remote_get($url, $expiration = 3600) { | |
$transient = 'remote_get-' . md5($url); | |
if ( ! ($response_body = get_transient($transient)) ) { | |
$response = wp_remote_get($url); | |
if( !is_wp_error($response) && $response["response"]["code"] === 200 ) { | |
$response_body = $response["body"]; | |
set_transient($transient, $response_body, $expiration); | |
} else { | |
$response_body = false; | |
} | |
} | |
return $response_body; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool stuff! These snippets of yours are truly awesome.