AI Verified

Name

Record users last login time and date

About

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

Language

PHP

Rating

Voted: 0 by 0 user(s)

How to Setup Snippet

This snippet needs to run sitewide. The snippet itself, only register the data to the SQL database. It doesn't show or print the information anywhere (this is better done in a separate snippet, unless you want it to run sitewide).

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

Record users last login time and date

 
                    
1// Function to record user's last login time
2function record_last_login( $login, $user ) {
3 $user = get_user_by( 'login', $login );
4 update_user_meta( $user->ID, 'last_login', current_time('mysql') );
5}
6 
7add_action( 'wp_login', 'record_last_login', 10, 2 );

0

Related Snippets

Please see some snippets below related to this snippet..

General

AI Verified

0

Old post banner

Added: 3 months ago

Last Updated: 3 months ago

Adds a banner to posts that are more than one year old informing users the post may be outdated.

General

AI Verified

0

Cerrar sesion - cliente

Added: 8 months ago

Last Updated: 8 months ago

General

Unverified

0

Disable Comments

Added: 9 months ago

Last Updated: 4 weeks 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...