User online status

I’d like to suggest a feature that display if the user/vendor currently is online or when the vendor was last active.

As a bonus suggestion. Showing statistic of average response time would also be amazing

Thanks, we’ll consider adding this feature.

Absolutely, exactly what I was thinking about as well.

2 Likes

Please this is really needed

2 Likes

Thanks for your feedback - please vote for the feature, the number of votes is one of the factors that define the feature priority. We have a long, long list of features so we have to decide which ones to implement first.

Last active would be even more useful I think!
Like, in the profile/listing i would say: “Last active 5h ago” or “Last seen on the platform 13 days ago” or something like this.

I have a solution that tracks when a user last logged on, and displays it in the user menu in the backend. It can also be shown on the front end with the shortcode.

The problem with this, and why I want a “last seen” and “currently online” instead of my solution “last logged in” is obviously that a current user stays logged in for some time, and that my solution just updates everytime the user actually logs in with a username and password, not when the user visits the website. Also the UX for customers when browsning vendors and seeing if they are active, and currently are online would be amazing, so they can engage in contant instantly.

Anyway. If you want the “last login” functionality, here it is:

//Record user's last login to custom meta
add_action('wp_login', 'smartwp_capture_login_time', 10, 2);

function smartwp_capture_login_time($user_login, $user)
{
	update_user_meta($user->ID, 'last_login', time());
}

//Register new custom column with last login time
add_filter('manage_users_columns', 'smartwp_user_last_login_column');
add_filter('manage_users_custom_column', 'smartwp_last_login_column', 10, 3);

function smartwp_user_last_login_column($columns)
{
	$columns['last_login'] = 'Last Login';
	return $columns;
}

function smartwp_last_login_column($output, $column_id, $user_id)
{
	if ($column_id == 'last_login') {
		$last_login = get_user_meta($user_id, 'last_login', true);
		$date_format = 'M j, Y';
		$hover_date_format = 'F j, Y, g:i a';

		$output = $last_login ? '<div title="Last login: ' . date($hover_date_format, $last_login) . '">' . human_time_diff($last_login) . '</div>' : 'No record';
	}

	return $output;
}

//Allow the last login columns to be sortable
add_filter('manage_users_sortable_columns', 'smartwp_sortable_last_login_column');
add_action('pre_get_users', 'smartwp_sort_last_login_column');

function smartwp_sortable_last_login_column($columns)
{
	return wp_parse_args(array(
		'last_login' => 'last_login'
	), $columns);
}

function smartwp_sort_last_login_column($query)
{
	if (!is_admin()) {
		return $query;
	}

	$screen = get_current_screen();

	if (isset($screen->base) && $screen->base !== 'users') {
		return $query;
	}

	if (isset($_GET['orderby']) && $_GET['orderby'] == 'last_login') {

		$query->query_vars['meta_key'] = 'last_login';
		$query->query_vars['orderby'] = 'meta_value';
	}

	return $query;
}

//Add [lastlogin] shortcode
function smartwp_lastlogin_shortcode($atts)
{
	$atts = shortcode_atts(
		array(
			'user_id' => false,
		),
		$atts,
		'lastlogin'
	);

	$last_login = get_the_author_meta('last_login', $atts['user_id']);
	if (empty($last_login)) {
		return false;
	};
	$the_login_date = human_time_diff($last_login);
	return $the_login_date;
}

add_shortcode('lastlogin', 'smartwp_lastlogin_shortcode');
4 Likes

Is this code something I can cut & paste with the code snippet plugin?

Yes, this works with snippet. You get a new column under users

1 Like

I copied and pasted it exactly as above. I don’t see anything new under the users tab. What did I miss?

Click the menu “users” and then, next to each username, there is a column showing when they last logged in. Probably alot of “no record” there. I can post a screenshot if you dont see it

1 Like

Thanks I finally saw it. I had the default view settings, but in order to see the extra column, you have to switch to Classic View. I appreciate your help!

Hi all.
I think this feature is very important so I contacted a freelancer on fiverr. He was very patient, accurate and effective and now my users can see who is online both in listings, in messages and on the sellers page. In addition, on the sellers page, they can be filtered by status.
I was very satisfied, so if you need it I recommend this freelancer: https://www.fiverr.com/expert2014?source=gig_page
I ordered through this gig: https://www.fiverr.com/expert2014/develop-or-fix-custom-wordpress-plugin-or-woocommerce-plugin?source=order_page_summary_gig_link_title&funnel=9adb1b4d14f54f7d43cdc2212d539f54f7d43cdc2212d539f

3 Likes

Thanks for sharing! We plan to launch the HivePress Experts program soon and we’ll contact this freelancer if he managed to customize HivePress.

1 Like