Skip to content

Instantly share code, notes, and snippets.

@cre8tivediva
Last active August 30, 2025 12:58
Show Gist options
  • Save cre8tivediva/aecf5448e92187c2131162f17a77485c to your computer and use it in GitHub Desktop.
Save cre8tivediva/aecf5448e92187c2131162f17a77485c to your computer and use it in GitHub Desktop.
Add Online Status Indicate to User Screen in WordPress
// From ChatGPT on 8/29/2025 but updated 8/30/2025
// Check if an admin has an active session
function rtd_is_admin_online($user_id) {
if (!user_can($user_id, 'administrator')) {
return false;
}
if (!class_exists('WP_Session_Tokens')) {
return false; // safety check
}
// Get this user's sessions
$sessions = WP_Session_Tokens::get_instance($user_id);
$all_sessions = $sessions->get_all();
// Online if there is at least one active session
return !empty($all_sessions);
}
// Add "Online Status" column to Users list
add_filter('manage_users_columns', function($columns) {
$columns['online_status'] = 'Online Status';
return $columns;
});
// Populate the "Online Status" column
add_filter('manage_users_custom_column', function($value, $column_name, $user_id) {
if ($column_name === 'online_status') {
return rtd_is_admin_online($user_id)
? '<span style="color:green;font-weight:bold;">● Online</span>'
: '<span style="color:gray;">● Offline</span>';
}
return $value;
}, 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment