Created
          September 30, 2023 17:58 
        
      - 
      
- 
        Save zartgesotten/532c465c8bbd2031203da6ae26190f18 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or 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
    
  
  
    
  | <?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