Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

Last login column for users

Remembers when each user last logged in and shows it in the users list. Useful for finding accounts nobody uses any more.

  • Type PHP
  • Runs Everywhere (runs as WordPress loads)
  • Category Users
  • Tested with WordPress 7.1
PHP
<?php

add_action(
	'wp_login',
	static function ( $login, $user ) {
		update_user_meta( $user->ID, 'snipfire_last_login', time() );
	},
	10,
	2
);
add_filter(
	'manage_users_columns',
	static function ( $columns ) {
		$columns['snipfire_last_login'] = 'Last login';
		return $columns;
	}
);
add_filter(
	'manage_users_custom_column',
	static function ( $output, $column, $user_id ) {
		if ( 'snipfire_last_login' !== $column ) {
			return $output;
		}
		$time = (int) get_user_meta( $user_id, 'snipfire_last_login', true );
		return $time ? esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time ) ) : '—';
	},
	10,
	3
);

Good to know

Starts counting when you switch it on: earlier logins show as “—”.

In these packs

  • Users and profiles: Registration dates, last logins, social profile fields, longer sessions and stricter passwords.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.