Skip to main content

PHP Actions Reference

REQUIREMENTS

To be able to implement this guide, you need to learn how to insert PHP snippets to your website.

You can find guide here: WP Beginner

This page lists all PHP action hooks available in the Better Messages plugin. Actions allow you to execute custom code when specific events occur (messages sent, threads created, users joining, etc.).


Messages

better_messages_message_sent

Fires when a new message is sent successfully. The message object is already saved to the database at this point and contains all properties including sender ID, recipients, thread ID, content, and timestamps. Use this hook to trigger external notifications, log messages to analytics, sync with CRM systems, or perform any post-send processing.

Parameters:

  • $message (BM_Messages_Message) — The message object (passed by reference)
add_action( 'better_messages_message_sent', 'on_message_sent', 10, 1 );
function on_message_sent( $message ){
$user_id = (int) $message->sender_id; // Sender User ID
$recipients = (array) $message->recipients; // Recipients User IDs
$thread_id = $message->thread_id; // Conversation ID
$message_id = $message->id; // Message ID
$content = $message->message; // Message content
}

better_messages_before_message_send

Allows preventing message sending based on custom conditions. This action only prevents new replies — to restrict new conversations use better_messages_before_new_thread.

Parameters (by reference):

  • &$args (array) — Message arguments (sender_id, content, thread_id)
  • &$errors (array) — Error array. Add entries to prevent sending.
add_action( 'better_messages_before_message_send', 'custom_before_message_send', 20, 2 );
function custom_before_message_send( &$args, &$errors ){
$sender_id = isset($args['sender_id']) ? $args['sender_id'] : get_current_user_id();
$content = $args['content'];
$thread_id = $args['thread_id'];

$user_allowed_to_send = true; // Your custom logic

if( ! $user_allowed_to_send ){
$errors['my_custom_error'] = 'You are not allowed to send this message';
}
}

Error popup example


better_messages_message_reply

Fires when a message is sent as a reply to another message. Only triggers for non-pending messages that have a reply_to meta value.

Parameters:

  • $message (object) — The new reply message object
  • $replied_to_message (object) — The original message being replied to
add_action( 'better_messages_message_reply', 'on_message_reply', 10, 2 );
function on_message_reply( $message, $replied_to_message ){
$reply_id = $message->id;
$original_id = $replied_to_message->id;
$thread_id = $message->thread_id;
$replier_id = $message->sender_id;
$original_sender = $replied_to_message->sender_id;

// Example: notify the original sender that someone replied
}

better_messages_before_message_delete

Fires immediately before a message is deleted from the database. Use this to clean up associated data before removal.

Parameters:

  • $message_id (int) — The message ID being deleted
  • $thread_id (int|false) — The thread ID, or false if unknown
  • $deleteMethod (string)'delete' (hard delete) or 'softdelete' (soft delete)
add_action( 'better_messages_before_message_delete', 'before_message_delete', 10, 3 );
function before_message_delete( $message_id, $thread_id, $deleteMethod ){
if( $deleteMethod === 'delete' ){
// Clean up custom data associated with this message
delete_metadata( 'message', $message_id, 'my_custom_meta' );
}
}

bp_better_messages_message_deleted

Fires after a message has been completely deleted from the database. Unlike better_messages_before_message_delete, this fires after all cleanup is complete.

Parameters:

  • $message_id (int) — The deleted message ID
add_action( 'bp_better_messages_message_deleted', 'after_message_deleted', 10, 1 );
function after_message_deleted( $message_id ){
// Log deletion or update external systems
error_log( 'Message #' . $message_id . ' was deleted' );
}

better_messages_message_meta_updated

Fires when message metadata is updated (reactions, voice transcriptions, AI data, etc.). Used internally to broadcast metadata changes via WebSocket so participants see updates in real-time.

Parameters:

  • $thread_id (int) — The thread ID containing the message
  • $message_id (int) — The message ID whose meta was updated
  • $meta_key (string) — The meta key (e.g., 'bm_reactions', 'bm_voice_transcription')
  • $meta_value (mixed) — The new meta value
add_action( 'better_messages_message_meta_updated', 'on_message_meta_updated', 10, 4 );
function on_message_meta_updated( $thread_id, $message_id, $meta_key, $meta_value ){
if( $meta_key === 'bm_reactions' ){
// Custom logic when reactions are updated
}
}

better_messages_message_reported

Fires when a user reports a message for moderator review. The $reports array contains all reports filed against this message (keyed by user ID), allowing you to check the total report count. Use this hook to send admin notifications, integrate with external moderation tools, or trigger automated actions like auto-hiding messages after a threshold of reports.

Parameters:

  • $message_id (int) — The reported message ID
  • $thread_id (int) — The thread ID
  • $user_id (int) — The user who filed the report
  • $category (string) — Report category
  • $description (string) — Report description from user
  • $reports (array) — All reports on this message (keyed by user ID)
add_action( 'better_messages_message_reported', 'on_message_reported', 10, 6 );
function on_message_reported( $message_id, $thread_id, $user_id, $category, $description, $reports ){
// Send notification to admin
wp_mail( get_option('admin_email'), 'Message Reported',
sprintf( 'Message #%d reported by user #%d. Category: %s', $message_id, $user_id, $category )
);
}

better_messages_on_message_not_sent

Fires when a message fails to send due to validation errors, permission issues, or authentication failures.

Parameters:

  • $thread_id (int) — The thread ID where the message was intended
  • $temp_id (string) — Temporary message ID from the frontend
  • $errors (array) — Array of error messages preventing delivery
add_action( 'better_messages_on_message_not_sent', 'on_message_failed', 10, 3 );
function on_message_failed( $thread_id, $temp_id, $errors ){
error_log( sprintf( 'Message failed in thread #%d: %s', $thread_id, implode(', ', $errors) ) );
}

Threads

better_messages_before_new_thread

Allows preventing new conversation creation based on custom conditions.

Parameters (by reference):

  • &$args (array) — Thread arguments including recipients array
  • &$errors (array) — Error array. Add entries to prevent creation.
add_action( 'better_messages_before_new_thread', 'restrict_new_thread', 10, 2 );
function restrict_new_thread( &$args, &$errors ){
$user_id = Better_Messages()->functions->get_current_user_id();
$recipients = $args['recipients'];

$can_create = true; // Your custom logic

if( ! $can_create ){
$errors['custom_error'] = 'You cannot start new conversations at this time.';
}
}

Error message example


bp_better_messages_new_thread_created

Fires after a new conversation thread is successfully created. When created via the REST API, the first message has already been sent and E2E encryption processing is complete. The $message_id is null when the thread is created programmatically via batch operations without an initial message. Use this hook to log new conversations, notify moderators, or initialize thread-specific data.

Parameters:

  • $thread_id (int) — The newly created thread ID
  • $message_id (int|null) — The first message ID, or null when created via batch
add_action( 'bp_better_messages_new_thread_created', 'on_thread_created', 10, 2 );
function on_thread_created( $thread_id, $message_id ){
// Log new conversation
error_log( sprintf( 'New thread #%d created with message #%s', $thread_id, $message_id ?? 'none' ) );
}

better_messages_thread_updated

Generic thread update hook. Fires when thread state changes — metadata changes, messages deleted, participants added/removed, thread cleared, etc. Used internally to trigger WebSocket broadcasts.

Parameters:

  • $thread_id (int) — The updated thread ID
add_action( 'better_messages_thread_updated', 'on_thread_updated', 10, 1 );
function on_thread_updated( $thread_id ){
// Invalidate external cache for this thread
}

better_messages_info_changed

Fires when thread display info changes (subject, avatar, participant list, settings like allow_invite). Triggers UI refresh for participants.

Parameters:

  • $thread_id (int) — The thread ID
  • $user_ids (array, optional) — Specific user IDs affected by the change
add_action( 'better_messages_info_changed', 'on_info_changed', 10, 2 );
function on_info_changed( $thread_id, $user_ids = array() ){
// React to thread info changes
}

better_messages_thread_self_update

Fires when user-specific thread data is updated (e.g., last_update timestamp). Different from better_messages_thread_updated which is global — this is per-user.

Parameters:

  • $thread_id (int) — The thread ID
  • $user_id (int) — The user whose thread state was updated
add_action( 'better_messages_thread_self_update', 'on_thread_self_update', 10, 2 );
function on_thread_self_update( $thread_id, $user_id ){
// Handle per-user thread state change
}

better_messages_change_thread_meta

Fires when thread metadata is changed via the REST API (excludes allow_invite which is handled separately).

Parameters:

  • $thread_id (int) — The thread ID
  • $key (string) — The metadata key being changed
  • $value (mixed) — The new value
add_action( 'better_messages_change_thread_meta', 'on_thread_meta_change', 10, 3 );
function on_thread_meta_change( $thread_id, $key, $value ){
// React to specific meta changes
if( $key === 'my_custom_setting' ){
// Handle custom thread setting
}
}

better_messages_thread_cleared

Fires when all messages in a thread are deleted (cleared). Messages are hard-deleted and unread counters reset.

Parameters:

  • $thread_id (int) — The cleared thread ID
add_action( 'better_messages_thread_cleared', 'on_thread_cleared', 10, 1 );
function on_thread_cleared( $thread_id ){
// Clean up search indexes, archives, etc.
}

better_messages_thread_erased

Fires after an entire thread is completely deleted (all messages, metadata, and participant records removed).

Parameters:

  • $thread_id (int) — The erased thread ID
add_action( 'better_messages_thread_erased', 'on_thread_erased', 10, 1 );
function on_thread_erased( $thread_id ){
// Remove external references to this thread
}

better_messages_mark_thread_read

Fires after a specific thread is marked as read by a user.

Parameters:

  • $thread_id (int) — The thread marked as read
  • $user_id (int) — The user who marked it read
add_action( 'better_messages_mark_thread_read', 'on_thread_read', 10, 2 );
function on_thread_read( $thread_id, $user_id ){
// Update notification badges in external system
}

better_messages_mark_all_read

Fires when a user marks all conversations as read at once.

Parameters:

  • $user_id (int) — The user ID
add_action( 'better_messages_mark_all_read', 'on_all_read', 10, 1 );
function on_all_read( $user_id ){
// Clear all notification badges for this user
}

Participants

better_messages_participant_added

Fires when a single user is added to a thread via add_participant_to_thread(). The database insert has already succeeded at this point. Use this hook to send welcome notifications, initialize per-user thread settings, log membership changes, or sync with external group systems.

Parameters:

  • $thread_id (int) — The thread ID
  • $user_id (int) — The added user's ID
add_action( 'better_messages_participant_added', 'on_participant_added', 10, 2 );
function on_participant_added( $thread_id, $user_id ){
// Send welcome notification to new participant
}

better_messages_participant_removed

Fires when a single user is removed from a thread via remove_participant_from_thread(). The database delete has already succeeded at this point. Use this hook to clean up user-specific thread data, revoke access in external systems, or send departure notifications.

Parameters:

  • $thread_id (int) — The thread ID
  • $user_id (int) — The removed user's ID
add_action( 'better_messages_participant_removed', 'on_participant_removed', 10, 2 );
function on_participant_removed( $thread_id, $user_id ){
// Clean up user-specific thread data
}

better_messages_participants_added

Fires when multiple users are bulk-added to a thread (e.g., via BuddyPress/PeepSo/Ultimate Member group sync).

Parameters:

  • $thread_id (int) — The thread ID
  • $user_ids (array) — Array of added user IDs
add_action( 'better_messages_participants_added', 'on_participants_added', 10, 2 );
function on_participants_added( $thread_id, $user_ids ){
foreach( $user_ids as $user_id ){
// Initialize per-user settings for the thread
}
}

better_messages_participants_removed

Fires when multiple users are bulk-removed from a thread, typically during BuddyPress/PeepSo/Ultimate Member/Fluent Community group membership syncs. Use this hook for batch cleanup operations, updating member statistics, or notifying remaining participants.

Parameters:

  • $thread_id (int) — The thread ID
  • $removed_ids (array) — Array of removed user IDs
add_action( 'better_messages_participants_removed', 'on_participants_removed', 10, 2 );
function on_participants_removed( $thread_id, $removed_ids ){
// Batch cleanup for removed users
}

Chat Rooms

better_messages_after_chat_join

Fires after a user successfully joins a public/semi-public chat room.

Parameters:

  • $thread_id (int) — The message thread ID
  • $chat_id (int) — The chat room post ID (bpbm-chat post type)
add_action( 'better_messages_after_chat_join', 'on_chat_join', 10, 2 );
function on_chat_join( $thread_id, $chat_id ){
$user_id = get_current_user_id();
// Send welcome message, log join event, etc.
}

better_messages_after_chat_left

Fires after a user leaves a chat room and is removed from the recipients list. The thread cache has been cleared before this hook fires. Use this hook to log departure events, update member counts, or clean up user-specific chat room data.

Parameters:

  • $thread_id (int) — The message thread ID
  • $chat_id (int) — The chat room post ID
add_action( 'better_messages_after_chat_left', 'on_chat_left', 10, 2 );
function on_chat_left( $thread_id, $chat_id ){
$user_id = get_current_user_id();
// Log departure, update member counts
}

Calls

better_messages_call_created

WebSocket Version

This functionality is available only with the WebSocket version.

Fires when a user initiates a private call. This does not mean the call was answered — only that the call initiation started.

Parameters:

  • $message_id (int) — The call message ID
  • $thread_id (int) — The thread ID
  • $user_id (int) — The user who initiated the call
  • $type (string)'audio' or 'video'
add_action( 'better_messages_call_created', 'on_call_created', 10, 4 );
function on_call_created( $message_id, $thread_id, $user_id, $type ){
// Log call initiation
error_log( sprintf( 'User #%d started %s call in thread #%d', $user_id, $type, $thread_id ) );
}

better_messages_group_call_joined

WebSocket Version

This functionality is available only with the WebSocket version.

Fires when a user joins a group call, after receiving the LiveKit room token from the cloud server. The $is_started parameter indicates whether this user is creating a new call room or joining an existing one. Use this hook to track group call participation, enforce call duration limits, or log analytics.

Parameters:

  • $thread_id (int) — The group thread ID
  • $type (string)'audio' or 'video'
  • $user_id (int) — The user who joined
  • $is_started (bool)true if the user is starting a new call, false if joining an existing one
add_action( 'better_messages_group_call_joined', 'on_group_call_joined', 10, 4 );
function on_group_call_joined( $thread_id, $type, $user_id, $is_started ){
if( $is_started ){
// New group call started
} else {
// User joined existing call
}
}

better_messages_register_call_usage

WebSocket Version

This functionality is available only with the WebSocket version.

Fires during call lifecycle — when a call is accepted and when it ends. Use for tracking call duration and usage.

Parameters:

  • $message_id (int) — The call message ID
  • $thread_id (int) — The thread ID
  • $user_id (int) — The user accepting/ending the call
add_action( 'better_messages_register_call_usage', 'track_call_usage', 10, 3 );
function track_call_usage( $message_id, $thread_id, $user_id ){
// Track call usage for billing or analytics
}

Guests

better_messages_guest_registered

Fires when a new guest (non-WordPress user) successfully registers. The guest has been inserted into the database with a unique secret token, display name, and email. Use this hook to send welcome emails, initialize guest preferences, log signups for analytics, or trigger CRM integrations.

Parameters:

  • $guest_id (int) — The guest ID from the plugin's guests table
add_action( 'better_messages_guest_registered', 'on_guest_registered', 10, 1 );
function on_guest_registered( $guest_id ){
// Send welcome email, initialize preferences, log signup
}

better_messages_guest_updated

Fires when a guest's profile is updated (name, email, etc.). The WebSocket profile has already been rebuilt at this point, so real-time connections reflect the new data. Note that the user ID is a negative integer for guests. Use this hook to sync profile changes to external services or update cached data.

Parameters:

  • $user_id (int) — Negative integer representing the guest (e.g., -5 for guest ID 5)
add_action( 'better_messages_guest_updated', 'on_guest_updated', 10, 1 );
function on_guest_updated( $user_id ){
// Sync guest profile changes to external system
}

better_messages_guest_deleted

Fires after a guest is deleted from the guests table and removed from all conversation threads. All cleanup is complete at this point. Use this hook for final data removal, compliance logging, or notifying threads about the guest's departure.

Parameters:

  • $user_id (int) — The guest user ID
add_action( 'better_messages_guest_deleted', 'on_guest_deleted', 10, 1 );
function on_guest_deleted( $user_id ){
// Final cleanup for guest data
}

better_messages_user_updated

Generic hook that fires when any user (guest) profile changes or is deleted. Fires alongside better_messages_guest_updated and better_messages_guest_deleted.

Parameters:

  • $user_id (int) — The user ID (negative for guests)
add_action( 'better_messages_user_updated', 'on_user_updated', 10, 1 );
function on_user_updated( $user_id ){
// Invalidate user cache
wp_cache_delete( 'bm_user_' . $user_id );
}

Notifications

better_messages_send_pushs

Fires when push notifications are being sent to users. Allows integration with third-party push services.

Parameters:

  • $user_ids (array) — Array of user IDs receiving push notifications
  • $notification (array) — Notification data (title, body, icon, tag, URL, etc.)
  • $message (object, optional) — The message object that triggered the notification
  • $all_recipients (array, optional) — All thread recipients
add_action( 'better_messages_send_pushs', 'custom_push_handler', 10, 4 );
function custom_push_handler( $user_ids, $notification, $message = null, $all_recipients = array() ){
// Send push via Firebase, OneSignal, etc.
foreach( $user_ids as $user_id ){
// my_push_service_send( $user_id, $notification['title'], $notification['body'] );
}
}

better_messages_send_unread_notification

Fires during the email notification cron job, after recording the last email time for a user in a thread.

Parameters:

  • $user_id (int) — The user receiving the notification
  • $thread_id (int) — The thread with unread messages
add_action( 'better_messages_send_unread_notification', 'custom_unread_notification', 10, 2 );
function custom_unread_notification( $user_id, $thread_id ){
// Send SMS, Slack message, or custom notification
}

better_messages_set_user_thread_unread_count

Fires after updating a user's unread message count for a specific thread in the database. The count is always >= 0 and fires before the thread is marked as updated for the user. Use this hook to sync unread counts to external badge systems, mobile push badge numbers, or custom notification widgets.

Parameters:

  • $user_id (int) — The user ID
  • $thread_id (int) — The thread ID
  • $unread_count (int) — The new unread count
add_action( 'better_messages_set_user_thread_unread_count', 'on_unread_count_changed', 10, 3 );
function on_unread_count_changed( $user_id, $thread_id, $unread_count ){
// Sync unread count to external badge system
}

better_messages_user_emails_enabled_update

Fires when a user's email notification preference is updated via the settings panel. The preference is stored in user meta. Use this hook to sync email preferences to CRM systems, mailing list providers, or external notification services.

Parameters:

  • $user_id (int) — The user ID
  • $enabled (string) — New setting ('yes' or 'no')
add_action( 'better_messages_user_emails_enabled_update', 'on_email_pref_changed', 10, 2 );
function on_email_pref_changed( $user_id, $enabled ){
// Sync preference to CRM
}

AI

better_messages_ai_response_completed

WebSocket Version

This functionality is available only with the WebSocket version.

Fires after an AI bot response has been completed, saved to the database, and cost calculated. The $cost_data array structure varies by provider — OpenAI includes prompt_tokens, completion_tokens, and cost. Use this hook to track AI usage per user, deduct credits from a billing system, log interactions for analytics, or send webhooks to external systems.

Parameters:

  • $ai_message_id (int) — The AI response message ID
  • $message_id (int) — The user's original message ID
  • $cost_data (array) — Token counts and cost data (structure varies by provider)
  • $bot_id (int) — The AI bot ID
  • $recipient_user_id (int) — The user who received the AI response
add_action( 'better_messages_ai_response_completed', 'on_ai_response', 10, 5 );
function on_ai_response( $ai_message_id, $message_id, $cost_data, $bot_id, $recipient_user_id ){
// Track AI usage, deduct user credits, log interactions
$total_tokens = ($cost_data['prompt_tokens'] ?? 0) + ($cost_data['completion_tokens'] ?? 0);
}

File Uploads

better_messages_post_before_upload

Fires before a file is uploaded to WordPress media library, after file type and size validation has passed. Use this hook to log file uploads for audit purposes, enforce additional validation rules (e.g., virus scanning), or track upload activity per user.

Parameters:

  • $upload_meta (array) — Upload metadata (filename, filetype)
add_action( 'better_messages_post_before_upload', 'before_file_upload', 10, 1 );
function before_file_upload( $upload_meta ){
// Log upload, enforce additional rules
error_log( 'Uploading: ' . $upload_meta['filename'] . ' (' . $upload_meta['filetype'] . ')' );
}

better_messages_tus_before_finalize

Fires before a TUS (resumable upload protocol) file is finalized and attached to a message. The upload directory path is structured as {year}/{month}/{thread_id}/{uuid}. Use this hook for custom file processing, metadata enrichment, or logging before the attachment is created.

Parameters:

  • $meta (array) — File metadata including upload path
add_action( 'better_messages_tus_before_finalize', 'before_tus_finalize', 10, 1 );
function before_tus_finalize( $meta ){
// Custom processing before file attachment
}

Plugin Lifecycle

better_messages_activation

Fires at the end of plugin activation, after all database tables have been created and migrations have been run. Used internally to install BuddyPress email templates and set up database tables. Use this hook to initialize custom options, create data structures, or schedule cron events that depend on Better Messages being active.

Parameters: None

add_action( 'better_messages_activation', 'on_bm_activation' );
function on_bm_activation(){
// Initialize custom options, create data structures
}

better_messages_deactivation

Fires during plugin deactivation. Used internally to unschedule the better_messages_send_notifications cron event. Use this hook to clean up custom cron events, remove temporary data, or deactivate dependent features when Better Messages is turned off.

Parameters: None

add_action( 'better_messages_deactivation', 'on_bm_deactivation' );
function on_bm_deactivation(){
// Unschedule custom cron events, cleanup
wp_clear_scheduled_hook( 'my_custom_cron' );
}

better_messages_reset_database

Fires after the database has been completely reset (all tables dropped and recreated). Admin-only action.

Parameters: None

add_action( 'better_messages_reset_database', 'on_db_reset' );
function on_db_reset(){
// Rebuild custom data structures
}

better_messages_register_script_dependencies

Fires before registering core script dependencies. Allows registering additional scripts that Better Messages depends on.

Parameters: None (or 'mobile-app' context string when called from mobile app)

add_action( 'better_messages_register_script_dependencies', 'register_custom_deps' );
function register_custom_deps(){
wp_register_script( 'my-bm-addon', plugins_url( 'my-addon.js', __FILE__ ), array(), '1.0' );
}

Mobile App

better_messages_mobile_app_auth

WebSocket Version

This functionality is available only with the WebSocket version.

Fires after a mobile app device is successfully authenticated via JWT token verification. The device is already marked as active and the app scripts hash is prepared at this point. Use this hook to log mobile authentications, update user last-seen timestamps, or trigger device-specific initialization logic.

Parameters:

  • $user_id (int) — Authenticated user ID
  • $device (array) — Device info (device_id, user_id, device_public_key, etc.)
add_action( 'better_messages_mobile_app_auth', 'on_mobile_auth', 10, 2 );
function on_mobile_auth( $user_id, $device ){
// Log mobile authentication, update last-seen
update_user_meta( $user_id, 'last_mobile_auth', current_time('mysql') );
}

better_messages_mobile_app_web_auth

WebSocket Version

This functionality is available only with the WebSocket version.

Fires when a mobile app user authenticates for web access via OpenSSL signature verification. At this point, the user is already logged into WordPress (current user and auth cookie are set). Use this hook to log web-based mobile authentications or apply web-specific initialization for mobile users.

Parameters:

  • $user_id (int) — Authenticated user ID
  • $device (array) — Device info
add_action( 'better_messages_mobile_app_web_auth', 'on_mobile_web_auth', 10, 2 );
function on_mobile_web_auth( $user_id, $device ){
// Handle web-based mobile app authentication
}

Encryption

better_messages_e2e_wrap_task

WebSocket Version

This functionality is available only with the WebSocket version.

Fires when E2E encryption keys need to be re-wrapped for a user. Delegated to the WebSocket server for execution.

Parameters:

  • $pending_threads (array) — Thread IDs needing key re-wrapping
  • $user_id (int) — User who needs key wrapping
add_action( 'better_messages_e2e_wrap_task', 'on_e2e_wrap', 10, 2 );
function on_e2e_wrap( $pending_threads, $user_id ){
// Monitor E2E key distribution
}

Template Rendering

bp_better_messages_before_chat

Fires before rendering a chat widget HTML. Errors are cleared to a global $bpbm_errors array and CSS customizations are queued for footer output at this point. Use this hook to inject custom HTML before the chat, add error notices, or perform thread-specific setup.

Parameters:

  • $chat_id (string) — Unique chat instance identifier
  • $thread_id (int) — Thread ID
add_action( 'bp_better_messages_before_chat', 'before_chat_render', 10, 2 );
function before_chat_render( $chat_id, $thread_id ){
// Inject custom HTML or setup before chat renders
}

bp_better_messages_after_chat

Fires after the chat HTML has been generated and output buffering is complete. The minified HTML is returned after this hook. Use this hook to inject tracking code, add custom JavaScript, or modify the final chat output.

Parameters:

  • $chat_id (string) — Unique chat instance identifier
  • $thread_id (int) — Thread ID
add_action( 'bp_better_messages_after_chat', 'after_chat_render', 10, 2 );
function after_chat_render( $chat_id, $thread_id ){
// Add tracking code or custom modifications
}

bp_better_messages_before_main_template_rendered

Fires before the main messaging template begins rendering.

Parameters: None

add_action( 'bp_better_messages_before_main_template_rendered', 'before_main_template' );
function before_main_template(){
// Output custom HTML at the start of the messaging template
}

bp_better_messages_after_main_template_rendered

Fires after the main messaging template is rendered.

Parameters: None

add_action( 'bp_better_messages_after_main_template_rendered', 'after_main_template' );
function after_main_template(){
// Add modals, debug info, or other markup after the template
}

bp_better_messages_before_generation

Fires before generating the Ultimate Member group messaging template. Errors are reset and the template loading context is prepared at this point. Use this hook for Ultimate Member-specific initialization or custom error handling for group messaging.

Parameters: None

add_action( 'bp_better_messages_before_generation', 'before_um_generation' );
function before_um_generation(){
// Ultimate Member group-specific initialization
}

bp_better_messages_screen

Fires when setting up the BuddyPress messages screen/tab. Earliest hook point for the messages screen.

Parameters: None

add_action( 'bp_better_messages_screen', 'on_messages_screen' );
function on_messages_screen(){
// Register custom tabs or modify screen setup
}