Last Login Time
-
Is there a way to show the last login time in the user listing in WP admin?
-
Hello @deraxia,
Thank you for reaching out to us.
We are not allowed to offer support for our paid products here, so please send us your questions on our website:
https://www.cozmoslabs.com/support/open-ticket/
Thank you!
Kind regards,
Thanks for the reply. I’m using the free plugin. It has the option to save the last login time as metadata. Just wondering if it can be shown in the wp-admin user list through a function.
Hello @deraxia,
Please excuse me, I thought you were referring to something else at first.
In the back-end, it’s a little bit tricky since it will not work with a shortcode. Where do you want this to be displayed? In the Users table?
Kind regards,
Thanks for the reply. Yes, in the users table.
I know there are other plugins that can do this, but since Profile Builder already collects the metadata, it would be better if Profile Builder can do this instead of installing a second plugin to separately collect the same information and display it.
Hello @deraxia,
Sorry for the delayed response.
Here is a custom code example:
// Add custom column based on custom field, with sorting, to the back-end Users page //Modify Users Table function wppbc_users_table_columns( $column ) { $column['last_login_date'] = 'Last Login'; return $column; } add_filter( 'manage_users_columns', 'wppbc_users_table_columns' ); //Add column value function wppbc_users_table_row( $val, $column_name, $user_id ) { switch ($column_name) { case 'last_login_date' : return get_user_meta($user_id, 'last_login_date', true); break; default: } return $val; } add_filter( 'manage_users_custom_column', 'wppbc_users_table_row', 10, 3 );You can use this code by adding it to your theme’s ‘functions.php’ file or by creating a new plugin as described here.
You can also make the column sortable like so:
//Make it sortable function wppbc_users_table_sortable_column( $columns ) { $columns['last_login_date'] = 'Last Login'; return $columns; } add_filter( 'manage_users_sortable_columns', 'wppbc_users_table_sortable_column' ); //Handle sorting query function wppbc_users_table_query($users_query){ if($users_query->query_vars['orderby'] == 'Last Login') { global $wpdb; $users_query->query_from .= " LEFT OUTER JOIN $wpdb->usermeta AS alias ON ($wpdb->users.ID = alias.user_id) "; $users_query->query_where .= " AND alias.meta_key = 'last_login_date' "; $users_query->query_orderby = " ORDER BY alias.meta_value ".($users_query->query_vars["order"] == "ASC" ? "asc " : "desc "); } } add_action('pre_user_query', 'wppbc_users_table_query');Kind regards,
The topic ‘Last Login Time’ is closed to new replies.