AI Verified

Name

Show when a user last logged in

About

This snippet makes a separate column in Users > All users showing when a user last logged in to the website. Snippet only needs to run in admin area. Be aware that this requires the "Record users last login time and date" snippet to work.

Language

PHP

Rating

Voted: 0 by 0 user(s)

How to Setup Snippet

First you need to record and store when a user last logged in by adding the "Record users last login time and date" to your website (sitewide snippet). Second, add this snippet to run in the admin area. Next time a user logs in, the time and date will appear in Users > All users.

Codevault

Centoba

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.4

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

28/01/2024

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Show when a user last logged in

 
                    
1// Add a new column to the Users admin page
2function add_last_login_column( $columns ) {
3 $columns['last_login'] = 'Last logged in';
4 return $columns;
5}
6add_filter( 'manage_users_columns', 'add_last_login_column' );
7 
8// Populate the Last Login column with data
9function populate_last_login_column( $value, $column_name, $user_id ) {
10 if ( 'last_login' == $column_name ) {
11 return get_user_meta( $user_id, 'last_login', true );
12 }
13 return $value;
14}
15 
16add_action( 'manage_users_custom_column', 'populate_last_login_column', 10, 3 );

0

Related Snippets

Please see some snippets below related to this snippet..

General

AI Verified

0

changing leave a reply to leave a comment

Added: 1 year ago

Last Updated: 1 year ago

changing leave a reply to leave a comment in wordpress

General

AI Verified

0

Stop P tags

Added: 1 year ago

Last Updated: 1 year ago

Prevent wordpress from automatically adding p tags around everything

General

AI Verified

0

Display Post ID

Added: 9 months ago

Last Updated: 9 months ago

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

General

AI Verified

0

Record users last login time and date

Added: 7 months ago

Last Updated: 7 months ago

This snippet records when a user last logged in to your website. Information is stored in wp_usermeta in the SQL database.

General

AI Verified

0

Show when a user last logged in

Added: 7 months ago

Last Updated: 7 months ago

This snippet makes a separate column in Users > All users showing when a user last logged in to the website. Snippet only needs to run in admin area. Be aware that this requires the "Record users last...