Skip to content

Instantly share code, notes, and snippets.

@jackgregory
Created September 25, 2017 10:46
Show Gist options
  • Save jackgregory/3e5a2a875d88011f488ad6867bfd8519 to your computer and use it in GitHub Desktop.
Save jackgregory/3e5a2a875d88011f488ad6867bfd8519 to your computer and use it in GitHub Desktop.
Display user last login time/date
/**
* Capture user login and add it as timestamp in user meta data
*
*/
function 12kdksd212_user_last_login( $user_login, $user ) {
update_user_meta( $user->ID, 'last_login', time() );
}
add_action( 'wp_login', '12kdksd212_user_last_login', 10, 2 );
/**
* Display last login time
*
*/
function 12kdksd212_lastlogin() {
$last_login = get_the_author_meta( 'last_login' );
$the_login_date = human_time_diff( $last_login );
return $the_login_date;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment