Skip to main content

Chat Rooms

Better Messages supports independent chat rooms that function as public or restricted group conversations.

How it works#

Chat rooms are created as a WordPress custom post type and can be embedded anywhere on your site using shortcodes. Unlike regular conversations that are initiated between specific users, chat rooms are persistent spaces that users can join and leave freely. Each chat room can have its own access rules, including which user roles can join and whether guest (non-registered) users are allowed to participate.

Key capabilities#

  • Persistent chat rooms that exist independently of specific users
  • Embed anywhere using the shortcode [better_messages_chat_room id="123"]
  • Configurable access by user role
  • Optional guest access for non-registered visitors
  • Unlimited number of participants
  • Auto-join settings for automatic participation
  • All messaging features available (file sharing, reactions, mentions, etc.)
  • Support for video and audio calls within chat rooms (WebSocket version)
  • Dedicated admin page for managing chat rooms with full CRUD operations and participant management
  • Online users sidebar panel showing currently online members in the chat room

Admin management#

Chat rooms have a dedicated administration page at WP AdminBetter MessagesChat Rooms where administrators can:

  • Create, edit, and delete chat rooms
  • Manage participants — add or remove users
  • Search users by name, login, or email when adding participants

Online users sidebar#

Chat rooms include an expandable/collapsible sidebar panel that shows currently online members. A toggle button in the chat header allows users to show or hide the panel.

Auto-remove inactive participants#

Chat rooms can automatically prune participants who have stopped engaging, keeping participant lists, unread counts, and notification fan-out focused on people who actually use the room. The job runs on the existing five-minute cleaner cron — no extra schedule to configure.

Enable it per chat room under WP AdminBetter MessagesChat RoomsChat Room Settings by toggling Auto-remove inactive users. Two more controls then appear:

  • Inactivity threshold (days) — how many days of inactivity before a participant is removed. Default 30, minimum 1.
  • Inactivity is measured by — pick one of three signals:
    • User has not visited the site — uses the user's last authenticated request anywhere on the site. Catches abandoned accounts.
    • User has not sent a message in this chat room — keys off messages posted in this thread only. Catches lurkers who are active site-wide but never participate here.
    • User has not opened this chat room — keys off the user's last visit to this specific chat. Catches uninterested participants.
  • Apply to roles — restrict cleanup to participants whose role matches one of the checked boxes. The list shows every editable WordPress role plus a synthetic Guests entry for unauthenticated visitors registered through the guest-chat flow. Leave everything unchecked to keep the original "remove anyone" behavior.
info

The most common case for Apply to roles is keeping auto-remove on but ticking only Guests — silent guest visitors get pruned and registered members are left alone.

info

Every participant gets a built-in grace period equal to the Inactivity threshold before they become eligible for removal. A user who was just added to a room — by clicking Join, by an admin invitation, or via Auto join users — will not be purged until they have been a member for at least that many days, even if their site-wide last activity is older than the threshold. This prevents brand-new joiners from being deleted on the very next cron run.

info

Removed users may rejoin if they meet the role requirements. If Auto join users is also enabled, an inactive user who later visits the page hosting the chat shortcode is auto-joined again automatically — that is the intended round trip: prune dormant, restore active.

AI chat bots are skipped automatically and never auto-removed.

Pin specific users#

To prevent specific users (admins, room owners, guests of honor) from ever being auto-removed, drop the following into your theme's functions.php or a custom plugin:

add_filter( 'better_messages_clean_inactive_chat_users_exclude_user_ids', function( $ids ) {
return array( 1, 42, 7 );
} );

Tune the per-cron batch size#

By default the job removes up to 100 inactive participants per chat room per cron tick. To raise or lower that:

add_filter( 'better_messages_clean_inactive_chat_users_batch_size', function() {
return 500;
} );

Setting the batch size to 0 disables the cleanup job entirely.

How to enable#

Chat rooms are managed through WP AdminBetter MessagesChat Rooms.

Creating a chat room:

  1. Click Add New to create a new chat room
  2. Set the chat room name
  3. Configure allowed roles (which user roles can join)
  4. Optionally enable guest access for non-registered users
  5. Publish the chat room

Embedding a chat room: Use the shortcode on any page or post:

[better_messages_chat_room id="123"]

Replace 123 with the actual chat room post ID.