0

I am using this codes to add the column in the users listing page to show the last login by users. This codes are in my function file of my template:

function insert_last_login( $login ) {
global $user_id;
$user = get_userdatabylogin( $login );
update_user_meta( $user->ID, 'last_login', gmdate( 'Y-m-d H:i:s' ), the_time('Y-m-j') );
}
add_action( 'wp_login', 'insert_last_login' );
function add_last_login_column( $columns ) {
$columns['last_login'] = __( 'آخرين ورود', 'last_login' );
return $columns;
}
add_filter( 'manage_users_columns', 'add_last_login_column' );
function add_last_login_column_value( $value, $column_name, $user_id ) {
$user = get_userdata( $user_id );
if ( 'last_login' == $column_name && $user->last_login )
$value = jdate( 'Y/m/d g:ia', strtotime( $user->last_login ) );
return $value;
}
add_action( 'manage_users_custom_column', 'add_last_login_column_value', 10, 3 );

this codes is ok and no problem with it.

1- I want to show the date of last login by user in the template and frontend page according this codes.

2- and i want to sorting the columns of user listing page in order to last login by user.

can anyone help me to solve this problem.

Thankyou very much. 😘

1 Answer 1

0
  1. Create 1 user_meta field for each user.

  2. Upon login, fire an action of 'wp_login' that will update the new user_meta field for the current logged in user.

  3. (Optional) Before updating the user_meta field, make sure it hasn't been updated earlier today. This will help avoiding server abuse

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.