From e1227255d3b0c48c62fbcce37e8159263d9f2d10 Mon Sep 17 00:00:00 2001 From: Luis Henrique Mulinari Date: Mon, 14 Aug 2023 16:23:26 -0300 Subject: [PATCH] Code review suggestions --- security/user-last-seen.php | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/security/user-last-seen.php b/security/user-last-seen.php index a8ee44c798..3c7eb3aca5 100644 --- a/security/user-last-seen.php +++ b/security/user-last-seen.php @@ -1,30 +1,28 @@ ID; + if ( ! $current_user->ID ) { + return; + } - try { - if ( wp_cache_get( $cache_key ) ) { - return; - } + $cache_key = LAST_SEEN_UPDATE_USER_META_CACHE_KEY_PREFIX . $current_user->ID; - update_user_meta( $current_user->ID, 'vip_last_seen', time() ); + if ( wp_cache_get( $cache_key, 'wpvip' ) ) { + // Last seen meta was updated recently, no need to update it again + return; + } - wp_cache_set( $cache_key, true, null, LAST_SEEN_UPDATE_USER_META_CACHE_TTL ); - } catch ( \Exception $e ) { - trigger_error( - sprintf( 'failed to update user last seen meta', esc_html( $e->getMessage() ) ), - E_USER_WARNING - ); + if ( wp_cache_add( $cache_key, true, 'wpvip', LAST_SEEN_UPDATE_USER_META_CACHE_TTL ) ) { + update_user_meta( $current_user->ID, 'wpvip_last_seen', time() ); } } @@ -35,7 +33,7 @@ function users_columns($cols) { function users_custom_column( $default, $column_name, $user_id ) { if ( 'last_seen' == $column_name ) { - $last_seen_timestamp = get_user_meta( $user_id, 'vip_last_seen', true ); + $last_seen_timestamp = get_user_meta( $user_id, 'wpvip_last_seen', true ); if ( $last_seen_timestamp ) { $formatted_date = sprintf(