Feature Suggestion: Add last login time to WordPress admin bar menu
-
Hi, I would like to suggest a new feature as I have not seen Last Login presented like this anywhere else before. Is it needed? Probably not. Is it cool? Well I think so but then I like little things like this.
This adds the users last login date and time to their account menu over on the top right of the menu bar within the WordPress administration screen.
The date format is currently hard coded to jS F, Y \a\t g:ia which will show the following: Last login: 25th March, 2024 at 7:54pm
// Add last login time to WordPress admin bar menu function get_last_login() { $user_id = get_current_user_id(); $last_login = get_user_meta($user_id, 'last_login', true); if ($last_login) { return date('jS F, Y \a\t g:ia', strtotime($last_login)); } return ''; // No need to display error if 'Never logged in' as only logged in user can see the info } function add_last_login_to_admin_bar_menu($wp_admin_bar) { if (is_user_logged_in()) { $last_login = get_last_login(); $edit_profile_node = $wp_admin_bar->get_node('edit-profile'); if ($edit_profile_node) { $new_title = sprintf('Last login: %s', $last_login); $wp_admin_bar->add_node(array( 'id' => 'edit-profile', 'title' => $new_title, 'href' => admin_url('users.php'), 'parent' => $edit_profile_node->parent, )); } } } add_action('admin_bar_menu', 'add_last_login_to_admin_bar_menu', 999);
I got the idea from the feature to add users last login date and time to the users.php list. My suggestion obviously isn’t as useful as seeing when other users logged in but it does let the currently logged in user see at a glance how long it has been since they last logged in.
- The topic ‘Feature Suggestion: Add last login time to WordPress admin bar menu’ is closed to new replies.