Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Last active February 19, 2019 23:24
Show Gist options
  • Save andrewlimaza/44695ec90e81be99cc2bdc6e0a7b27db to your computer and use it in GitHub Desktop.
Save andrewlimaza/44695ec90e81be99cc2bdc6e0a7b27db to your computer and use it in GitHub Desktop.
PMPRO show when user's last logged in in the member's list
<?php
/**
* Add this code to your active theme's function.php or custom plugin. (Copy lines 6 - 33 only)
*/
function my_pmpro_last_login( $user_login, $theusers ) {
//get user meta 'my_pmpro_last_login' on login and add time() to it.
update_user_meta( $theusers->ID, 'my_pmpro_last_login', time() );
}
add_action( 'wp_login', 'my_pmpro_last_login', 10, 2 );
function mypmpro_memberslist_last_login_header($theusers){
?>
<th><?php _e('Last Login', 'pmpro');?></th>
<?php
}
add_action('pmpro_memberslist_extra_cols_header', 'mypmpro_memberslist_last_login_header');
function my_pmpro_memberslist_last_login_body($theuser){
?>
<td>
<?php
if(!empty($theuser->my_pmpro_last_login)){
//display human readable text to the memberslist
echo human_time_diff($theuser->my_pmpro_last_login);
}else{
_e('Never', 'pmpro');
}
?>
</td>
<?php
}
add_action('pmpro_memberslist_extra_cols_body', 'my_pmpro_memberslist_last_login_body');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment