$latest = get_option( GLM_SERVERSTATS_PLUGIN_RELAY_LATEST, false );
$latest_data = unserialize( $latest );
- // echo '<div><pre>$latest_data: ' . print_r( $latest_data, true ) . '</pre></div>';
-
// check latest for time if too old then fetch latest and update time.
$stale_time = strtotime( '-' . GLM_SERVERSTATS_PLUGIN_RELAY_LATEST_TIMEOUT );
if ( $current_time <= $stale_time ) {
$message_data = wp_remote_retrieve_body( $response );
$status = wp_remote_retrieve_response_code( $response);
- // echo '<pre>$response: ' . print_r( $response, true ) . '</pre>';
if ( $status == 200 ) {
$messages = json_decode( $message_data, true );
- // echo '<pre>$messages: ' . print_r( $messages, true ) . '</pre>';
foreach ( $messages as $message ) {
$title = $message['title'];
$id = $message['id'];
} else {
$latest_version = false;
}
- // echo '<pre>$latest_version: ' . print_r( $latest_version, true ) . '</pre>';
if ( isset( $latest_data ) && isset( $latest_data['version'] ) && $latest_version == $latest_data['version'] ) {
// use the cached data
} else {
'version' => $id . '-' . $updated
);
- }
+ // Store as option
+ update_option( GLM_SERVERSTATS_PLUGIN_RELAY_LATEST, serialize( $latest_data ), true );
- // Store as option
- update_option( GLM_SERVERSTATS_PLUGIN_RELAY_LATEST, serialize( $latest_data ), true );
- if ( $latest_version ) {
- update_option( GLM_SERVERSTATS_PLUGIN_RELAY_LATEST_VERSION, $latest_version, true );
- }
+ if ( $latest_version ) {
+ update_option( GLM_SERVERSTATS_PLUGIN_RELAY_LATEST_VERSION, $latest_version, true );
+ }
+ }
// Reset the default timezone
date_default_timezone_set( $default_timezone );