Save timestamp of user's last login to usermeta
|Reported by:||joelhardi||Owned by:|
Right now there's no way to tell when a user last logged in, or even if they've ever logged in.
My suggestion is to simply store a 'last_login' timestamp in usermeta (similar to the way bbPress stores a 'last_posted' timestamp when a user posts). The usermeta row would be initially absent, then be inserted when a user first logs in, and then be updated on every successful login.
I haven't written a patch but am happy to do so if this task is blessed or has a reasonable chance for inclusion in core. It should be very straightforward.
I see a wide range of possible uses for this small bit of user info. For instance, a plugin could delete, deactivate, email an "are you there? please come back" message or flag a user after a certain period of inactivity. Or, a plugin could add a column to the users screen, allowing the table to sort by login date so that site admins could check out who's been on the site. Community-type sites might choose to publicly display a list like "Users logged in today."
When WordPress is employed as a blog, it's easy to track how active users are by how often they comment (or post). However, I've talked to a bunch of site owners who use WordPress differently, requiring users to register and log in just to read certain pages -- their users never comment or post, but they have no way to tell what user accounts are being used or are abandoned.
There are plugins such as Login Logger that add this functionality, but I'm suggesting adding it to core because (a) it's trivial and (b) there's a big advantage to having this data live in a standard place so that all users and plugin authors can make use of it (vs. having plugins make up their own way to store and access this information). For instance, I'm the author of a plugin that deletes users after a certain period of inactivity, but I don't want my plugin to get into the business of hooking into logins and inserting into the database, I just want to make small use of this information.
Possible cons I can think of
- This would mean an INSERT or UPDATE to the database on every successful login, which could create load/contention issues on very busy sites, particularly with MyISAM. I don't believe that writes to the usermeta table are frequent enough to be a problem, but it's a possibility.
- There may be privacy issues to consider ... personally I think saving only last login time (vs. storing all logins) is pretty benign, but I thought I'd mention it. I think the average user already expects this sort of basic information is stored when they log into a website.
- For the above reasons you might prefer to make this an optional feature, disabled by default, which would mean adding a checkbox on one of the Settings pages. I know reducing clutter on these pages and avoiding featuritis are big WordPress goals, so that's a possible issue. I can code it either way, but I think it's simplest and most useful to just add the feature and not make it a settings option.
Thanks for considering my feature request!