Making WordPress.org

Changeset 13881


Ignore:
Timestamp:
07/05/2024 09:23:23 AM (5 months ago)
Author:
paulkevan
Message:

Profiles: add a user meta to track last activity.

As noted in https://github.com/WordPress/five-for-the-future/issues/247#issuecomment-2201746146 this will not catch everything, but should allow more accurate activity tracking.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/profiles.wordpress.org/public_html/wp-content/plugins/wporg-profiles-activity-handler/wporg-profiles-activity-handler.php

    r13364 r13881  
    264264                } elseif ( false === $activity_id || intval( $activity_id ) <= 0 ) {
    265265                    throw new Exception( '-1 Unable to save activity' );
     266                } else {
     267                    $this->maybe_update_last_activity();
    266268                }
    267269
     
    275277
    276278            die( $response );
     279        }
     280
     281        /**
     282         *
     283         * Adds/Updates user meta to track last activity.
     284         *
     285         */
     286        public static function maybe_update_last_activity() {
     287
     288            $user = self::get_user( $_POST['user'] );
     289           
     290            if ( ! $user ) {
     291                return;
     292            }
     293           
     294            $user_activity_cache_key = 'wporg-user-activity-logger-' . $user->ID;
     295
     296            // Adds some caching to avoid unnecessary updates since we only store day.
     297            $user_activity_cache = wp_cache_get( $user_activity_cache_key );
     298
     299            if ( $user_activity_cache ) {
     300                return;
     301            }
     302
     303            // Only store date since we aim to cache for a day.
     304            update_user_meta( $user->ID, 'last_activity_tracker', date( 'Y-m-d 00:00:00' ) );
     305            wp_cache_set( $user_activity_cache_key, '1', '', DAY_IN_SECONDS );
     306
     307            return;
     308
    277309        }
    278310
Note: See TracChangeset for help on using the changeset viewer.