// check latest for time if too old then fetch latest and update time.
$stale_time = strtotime( '-' . GLM_SERVERSTATS_PLUGIN_RELAY_LATEST_TIMEOUT );
- // trigger_error( '$stale_time: ' . $stale_time . ' ' . date( 'Y-m-d H:i:s', $stale_time ), E_USER_NOTICE );
- // if ( $current_time <= $stale_time ) {
- // trigger_error( 'state time occurred', E_USER_NOTICE );
- // $fetch_latest = true;
- // }
+ // If you have a cache then check to see if that cache is older than GLM_SERVERSTATS_PLUGIN_RELAY_LATEST_TIMEOUT.
+ // If it is then set fetch_latest to true.
if ( $latest ) {
if ( $latest_data['cached'] <= $stale_time ) {
// trigger_error( 'stale time occurred', E_USER_NOTICE );
$fetch_latest = true;
}
+ // If fetch_latest then grab the newest from Relay.
if ( $fetch_latest ) {
// Get the messages from the main plugin.
$response = wp_remote_get( GLM_SERVERSTATS_PLUGIN_RELAY_URL . '&option=latest' );
$message_data = wp_remote_retrieve_body( $response );
$status = wp_remote_retrieve_response_code( $response);
+ // If we get a good response.
if ( $status == 200 ) {
$messages = json_decode( $message_data, true );
// trigger_error( '$messages: ' . print_r( $messages, true ), E_USER_NOTICE );
$updated = $message['updated']['timestamp'];
}
} else {
- // echo '<pre>$status: ' . print_r( $status, true ) . '</pre>';
+ // Don't do anything here yet.
}
if ( $id && $updated ) {
$latest_version = $id . '-' . $updated;
} else {
$latest_version = false;
}
+ // trigger_error( '$latest_version: ' . $latest_version, E_USER_NOTICE );
+ // Need to check the latest version with what we have cached.
+ // If our version is the same then we're ok. Don't delete the dismiss option.
if ( isset( $latest_data ) && isset( $latest_data['version'] ) && $latest_version == $latest_data['version'] ) {
// use the cached data
} else {
+ // If there's a new update then delete the dismiss option.
delete_option( GLM_SERVERSTATS_PLUGIN_RELAY_DISMISS );
}
'version' => $id . '-' . $updated
);
- // Store as option
+ // Store the option fetched.
update_option( GLM_SERVERSTATS_PLUGIN_RELAY_LATEST, serialize( $latest_data ), true );
if ( $latest_version ) {
+ // If there's $latest_version then store it.
update_option( GLM_SERVERSTATS_PLUGIN_RELAY_LATEST_VERSION, $latest_version, true );
}