Update the defines for checking on new udpdates.
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 26 Aug 2019 19:17:04 +0000 (15:17 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 26 Aug 2019 19:19:41 +0000 (15:19 -0400)
Have to know which update each user_id has received. Adding user_id to
the option for the cached data.

defines.php
setup/adminHooks.php

index b3d87f5..533c72d 100755 (executable)
@@ -24,16 +24,19 @@ if (!defined('ABSPATH')) {
     die();
 }
 
+// Get user id.
+// This is used for check for new updates.
+$user_id = get_current_user_id();
+
 define('GLM_SERVERSTATS_SITE_TITLE', get_bloginfo( 'name' ));
 define('GLM_SERVERSTATS_PLUGIN_NAME', 'Gaslight Media - Server Data Usage Plugin');
 define('GLM_SERVERSTATS_PLUGIN_SHORT_NAME', 'ServerStats');
 define('GLM_SERVERSTATS_PLUGIN_SLUG', 'glm-serverstats');
 define('GLM_SERVERSTATS_PLUGIN_RELAY_URL', 'https://www.gaslightmedia.com/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=relay');
 // define('GLM_SERVERSTATS_PLUGIN_RELAY_URL', 'http://develop.localhost/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=relay');
-define('GLM_SERVERSTATS_PLUGIN_RELAY_LATEST', 'glm_serverstats_relay_latest');
+define('GLM_SERVERSTATS_PLUGIN_RELAY_LATEST', 'glm_serverstats_relay_latest_' . $user_id);
 define('GLM_SERVERSTATS_PLUGIN_RELAY_LATEST_VERSION', 'glm_serverstats_relay_latest_version');
 define('GLM_SERVERSTATS_PLUGIN_RELAY_LATEST_TIMEOUT', '20 minutes');
-$user_id = get_current_user_id();
 define('GLM_SERVERSTATS_PLUGIN_RELAY_DISMISS', 'glm_info_notice_dismiss_' . $user_id );
 // Determine which system we're running on - If not provided, assume PRODUCTION
 $host = getenv('GLM_HOST_ID');
@@ -91,4 +94,4 @@ define('GLM_SERVERSTATS_PLUGIN_UPDATE_SERVER', 'http://www.gaslightmedia.com/upd
 // Other
 define('GLM_SERVERSTATS_PLUGIN_THRESHOLD_OPTION', 'glmServerStatsThreshold');
 define('GLM_SERVERSTATS_PLUGIN_SEND_OPTION', 'glmServerStatsSend');
-define('GLM_SERVERSTATS_PLUGIN_CONFIG_OPTION', 'glmServerStatsConfigData');
\ No newline at end of file
+define('GLM_SERVERSTATS_PLUGIN_CONFIG_OPTION', 'glmServerStatsConfigData');
index a8be7f9..0016e81 100644 (file)
@@ -61,10 +61,10 @@ $user_is_admin  = current_user_can( 'administrator' );
 $user_is_editor = current_user_can( 'editor' );
 
 // Get Configuration
-$serverstatsConfig = get_option(GLM_SERVERSTATS_PLUGIN_CONFIG_OPTION);
+$serverstatsConfig = get_option( GLM_SERVERSTATS_PLUGIN_CONFIG_OPTION );
 
 // If this site should show notifications and is a high-level user - Check for notifications
-if ( $serverstatsConfig['show_notifications'] && ($user_is_admin || $user_is_editor) ) {
+if ( $serverstatsConfig['show_notifications'] && ( $user_is_admin || $user_is_editor ) ) {
     add_action(
         'admin_init',
         function(){
@@ -77,12 +77,9 @@ if ( $serverstatsConfig['show_notifications'] && ($user_is_admin || $user_is_edi
 
             // Get current time
             $current_time = strtotime( 'now' );
-            // trigger_error( '$current_time: ' . $current_time . ' ' . date( 'Y-m-d H:i:s', $current_time ), E_USER_NOTICE );
 
             $latest = get_option( GLM_SERVERSTATS_PLUGIN_RELAY_LATEST, false );
-            // trigger_error( '$latest: ' . $latest, E_USER_NOTICE );
             $latest_data = unserialize( $latest );
-            // trigger_error( '$cached: ' . $latest_data['cached'] . ' ' . date( 'Y-m-d H:i:s', $latest_data['cached'] ), E_USER_NOTICE );
 
             // check latest for time if too old then fetch latest and update time.
             $stale_time   = strtotime( '-' . GLM_SERVERSTATS_PLUGIN_RELAY_LATEST_TIMEOUT );
@@ -90,7 +87,6 @@ if ( $serverstatsConfig['show_notifications'] && ($user_is_admin || $user_is_edi
             // 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;
                 }
             } else {
@@ -126,7 +122,6 @@ if ( $serverstatsConfig['show_notifications'] && ($user_is_admin || $user_is_edi
                 } 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'] ) {