Last Login Column Across the Network
Records when each user last signed in anywhere on the network and shows it in Network Admin > Users, making inactive accounts easy to find.
Opens WPIDE on
Code
if ( ! is_multisite() ) {
return;
}
add_action( 'wp_login', function ( $login, $user ) {
update_user_meta( $user->ID, 'wpide_network_last_login', time() );
}, 10, 2 );
if ( ! is_admin() ) {
return;
}
add_filter( 'wpmu_users_columns', function ( $columns ) {
$columns['wpide_last_login'] = __( 'Last login' );
return $columns;
} );
add_filter( 'manage_users_custom_column', function ( $output, $column, $user_id ) {
if ( 'wpide_last_login' !== $column ) {
return $output;
}
$time = (int) get_user_meta( $user_id, 'wpide_network_last_login', true );
if ( ! $time ) {
return '—';
}
return sprintf(
'<span title="%1$s">%2$s</span>',
esc_attr( wp_date( 'Y-m-d H:i', $time ) ),
/* translators: %s: human time difference */
esc_html( sprintf( __( '%s ago' ), human_time_diff( $time ) ) )
);
}, 10, 3 );
Notes
The column fills in as people log in after you activate the snippet; earlier logins are not known.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.