Skip to content

Instantly share code, notes, and snippets.

@zartgesotten
Created September 30, 2023 17:58
Show Gist options
  • Save zartgesotten/532c465c8bbd2031203da6ae26190f18 to your computer and use it in GitHub Desktop.
Save zartgesotten/532c465c8bbd2031203da6ae26190f18 to your computer and use it in GitHub Desktop.
<?php
/**
* Capture user login and add it as timestamp in user meta data
*
*/
function user_last_login( $user_login, $user ) {
update_user_meta( $user->ID, 'last_login', time() );
}
add_action( 'wp_login', 'user_last_login', 10, 2 );
/**
* Display last login time
*
*/
function wpb_lastlogin() {
$last_login = get_the_author_meta('last_login');
$the_login_date = human_time_diff($last_login);
return $the_login_date;
}
/**
* Add Shortcode lastlogin
*
*/
add_shortcode('lastlogin','wpb_lastlogin');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment