From: Steve Sutton Date: Wed, 15 Aug 2018 17:39:48 +0000 (-0400) Subject: some comments and testing X-Git-Tag: v2.0.0~9 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=40ed802e3b8afeb922bb3cb67e02e1e7a56bfcb6;p=WP-Plugins%2Fglm-serverstats.git some comments and testing Only setting up trigger errors. Commenting them out now. --- diff --git a/setup/adminHooks.php b/setup/adminHooks.php index dfc61a2..4eb3bde 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -77,11 +77,8 @@ add_action( // 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 ); @@ -91,12 +88,14 @@ add_action( $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 ); @@ -107,16 +106,20 @@ add_action( $updated = $message['updated']['timestamp']; } } else { - // echo '
$status: ' . print_r( $status, true ) . '
'; + // 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 ); } @@ -128,10 +131,11 @@ add_action( '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 ); }