I have a plugin that needs to check for update. Function below - get_version_to_update is fired when someone enters plugin admin page. In theory after request is done, data should be cached via transients for 24h. And this works for most sites, but for some specific sites I get data that wp_remote_request fires over and over, which (as I think) means that transient isn't saving.
Why this might happen? Is there more reliable way to check this?
public function get_version_to_update(){
// I get the transient
$data = get_transient("my_plugin_remote_version");
// I check if it exists
if($data === false){
// here I get data from server using wp_remote_request, server return just version number, e.g. "2.0"
$data = wp_remote_request(...);
// I cache it for 24h
set_transient("my_plugin_remote_version", $data, 60 * 60 * 24);
}
// I check if returned data from server is correct
if ( !$data || is_wp_error( $data ) || 200 != $data['response']['code']) {
return false;
} else {
if( version_compare(MY_PLUGIN_VERSION, $new_version, '<') ) {
// return new version, if it's newer then current
return $data['body'];
} else {
return false;
}
}
}
This issue is killing me, thank you for any help!
false
return value is cached you might get that even when there are data in your transient. I run into this issue once, but it happened in a controlled environment, and I turned it off.