I don’t see anywhere in your code that the query is being modified. Just flagging a column to be sortable doesn’t mean it knows how to sort the data – it will just add the little up/down arrow and make the column clickable but you have to intercept the query var accordingly and tell WP what to do. You’ll want to hook into pre_get_users
and modify the query accordingly. Since you’re already storing the time using current_time( 'mysql' )
then the default ordering should work as intended.
This is untested but should work or at least get you started.
add_action( 'pre_get_users', 'wpse_filter_user_query' );
function wpse_filter_user_query( $user_query ) {
global $current_screen;
if ( !is_admin() || 'users' != $current_screen->id )
return;
if( 'lastlogin' == $user_query->get( 'orderby' ) )
{
$user_query->set( 'orderby', 'meta_value' );
$user_query->set( 'meta_key', 'last_login' );
}
}