This is a two-part post that will give you the code for plugins that will modify your WordPress user management page with some useful additional information
This post will give you the code for the highlighted area on the left. This code adds two bits of information for every user, their last login date and time, and the last date and time they were active. When you hover over the “Last login” and “Last active” text the tooltip shows you the exact date and time info.
<?php /** * Plugin Name: Last Login * Description: This plugin stores the last login time for every user and displays it on the Users page. * Version: 1.0.0 * Author: notonebit.com */ function notonebit_last_login( $user_login, $user ){ update_user_meta( $user->ID, 'notonebit_last_login', current_time( 'mysql' ) ); } function notonebit_last_active(){ $current_user = wp_get_current_user(); update_user_meta( $current_user->ID, 'notonebit_last_active', current_time( 'mysql' ) ); } add_action( 'wp_login', 'notonebit_last_login', 10, 2); add_action( 'admin_init', 'notonebit_last_active', 1); add_filter( 'manage_users_columns', function( $columns ) { return array_slice( $columns, 0, 2, true ) + [ 'mycol' => __( 'Name' ) ] + array_slice( $columns, 3, null, true ); } ); add_filter( 'manage_users_custom_column', function( $output, $column_name, $user_id ) { if( 'mycol' === $column_name ) { $u = new WP_User( $user_id ); if( $u instanceof \WP_User ) { // Default output $output .= "$u->first_name $u->last_name ($user_id)"; // Additional output $last_login = get_user_meta( $user_id, 'notonebit_last_login', true ); $last_active = get_user_meta( $user_id, 'notonebit_last_active', true ); $login_time = 'Never logged in'; if( !empty( $last_login ) ) { $login_time = human_time_diff( mysql2date( 'U', $last_login ), current_time('timestamp') ) . " ago"; $active_time = human_time_diff( mysql2date( 'U', $last_active ), current_time('timestamp') ) . " ago"; $output .= "<p style=\"font-size:11px; color:#999\">Last login: <span title=\"".mysql2date( 'l, F j, Y @ g:i a ', $last_login )."\">$login_time</span>\n"; $output .= "- Last active: <span title=\"".mysql2date( 'l, F j, Y @ g:i a ', $last_active )."\">$active_time</span></p>\n"; } else { $output .= "<p style=\"font-size:11px; color:#999\">Last login: <span title=\"".mysql2date( 'l, F j, Y @ g:i a ', $last_login )."\">$login_time</span>\n"; } // Housekeeping unset( $u ); } } return $output; }, 11, 3 ); add_filter( 'manage_users_sortable_columns', function( $columns ) { $columns['mycol'] = 'name'; return $columns; } ); ?>
My next post will focus on the other enhancement to the user’s page, a new column on the right that lists all the pages each user has, broken down by types, with links to each.
Thank you for sharing the code with us. I know this article is a bit old but do you have any idea if this still works?
I’m having trouble activating it.
Would also like to hear when this is again working
I’ll look into this and see what changed and post updates.
This plugin still works as of 4.9.1 so I’m not sure what issues you’re experiencing without further details.