Created
September 25, 2017 10:46
-
-
Save jackgregory/3e5a2a875d88011f488ad6867bfd8519 to your computer and use it in GitHub Desktop.
Display user last login time/date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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