[WordPress] remote_get transient
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
<?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.