Skip to content

Instantly share code, notes, and snippets.

@wokamoto
Created March 27, 2014 05:26
Embed
What would you like to do?
[WordPress] remote_get transient
<?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;
}
@maor
Copy link

maor commented Jan 26, 2015

Cool stuff! These snippets of yours are truly awesome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment