PHP Filters Reference
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 filter hooks available in the Better Messages plugin. Filters allow you to modify data as it passes through the plugin โ changing permissions, content, display, and behavior.
Permissions & Access#
better_messages_can_send_message#
Filters whether a user can send a message in a thread. To display a custom error message when blocking, use the global $bp_better_messages_restrict_send_message array.
Parameters:
$allowed(bool) โ Whether the user is allowed$user_id(int) โ User attempting to send$thread_id(int) โ The thread ID
Returns: bool
add_filter( 'better_messages_can_send_message', 'restrict_sending', 10, 3 );
function restrict_sending( $allowed, $user_id, $thread_id ){
global $bp_better_messages_restrict_send_message;
$user_allowed_to_send = true; // Your custom logic
if( ! $user_allowed_to_send ){
// Add error message shown to user in the reply form area
$bp_better_messages_restrict_send_message['my_custom_error'] = 'You are not allowed to reply to this thread';
return false;
}
return $allowed;
}

better_messages_can_forward_message#
Filters whether a user can forward a message. Return null to allow, WP_Error to deny.
Parameters:
$error(null|WP_Error) โ Defaultnull$original_message(object) โ The message being forwarded$current_user_id(int) โ User forwarding the message
Returns: null|WP_Error
add_filter( 'better_messages_can_forward_message', 'restrict_forwarding', 10, 3 );
function restrict_forwarding( $error, $message, $user_id ){
if( ! user_can( $user_id, 'edit_posts' ) ){
return new WP_Error( 'no_forward', 'Forwarding is not allowed for your role' );
}
return $error;
}
better_messages_can_invite#
Filters whether a user can invite others to a thread. The default value is based on the thread's allow_invite setting and user permissions. Return true to allow inviting, false to deny.
Parameters:
$can_invite(bool) โ Default based on thread settings$user_id(int) โ User inviting$thread_id(int) โ The thread
Returns: bool
add_filter( 'better_messages_can_invite', 'custom_invite_rules', 10, 3 );
function custom_invite_rules( $can_invite, $user_id, $thread_id ){
// Only moderators can invite
if( user_can( $user_id, 'moderate_comments' ) ){
return true;
}
return false;
}
better_messages_can_pin_messages#
Filters whether a user can pin/unpin messages in a thread. Default is false โ pinning must be explicitly enabled. Only one message can be pinned per thread at a time.
Parameters:
$can_pin(bool) โ Defaultfalse$user_id(int) โ Current user$thread_id(int) โ The thread
Returns: bool
add_filter( 'better_messages_can_pin_messages', 'allow_pinning', 10, 3 );
function allow_pinning( $can_pin, $user_id, $thread_id ){
return user_can( $user_id, 'edit_posts' );
}
better_messages_chat_user_can_join#
Filters whether a user can join a chat room. The default is based on the room's role-based can_join setting. Receives both the chat room post ID and the associated thread ID for flexible permission logic.
Parameters:
$has_access(bool) โ Default based on user role check$user_id(int) โ User attempting to join$chat_id(int) โ Chat room post ID$thread_id(int) โ Associated thread ID
Returns: bool
add_filter( 'better_messages_chat_user_can_join', 'custom_chat_access', 10, 4 );
function custom_chat_access( $has_access, $user_id, $chat_id, $thread_id ){
// Allow all logged-in users
return is_user_logged_in();
}
better_messages_check_access_override#
Completely overrides the default access check for a thread. Return null to use default logic, or bool to override.
Parameters:
$override(null|bool) โ Defaultnull(use default checks)$thread_id(int) โ The thread$user_id(int) โ User checking access$access_type(string) โ Type of access ('read','reply', etc.)
Returns: null|bool
add_filter( 'better_messages_check_access_override', 'custom_access', 10, 4 );
function custom_access( $override, $thread_id, $user_id, $access_type ){
// Grant read access to all admins
if( $access_type === 'read' && user_can( $user_id, 'manage_options' ) ){
return true;
}
return null; // Use default logic
}
better_messages_has_access_to_group_chat#
Filters access to group chat threads (type 'group'). Default is false, meaning group chat access must be explicitly granted. BuddyPress, PeepSo, and other group plugins use this filter to integrate their membership checks.
Parameters:
$has_access(bool) โ Defaultfalse$thread_id(int) โ Group chat thread$user_id(int) โ User checking access
Returns: bool
add_filter( 'better_messages_has_access_to_group_chat', 'group_chat_access', 10, 3 );
function group_chat_access( $has_access, $thread_id, $user_id ){
// Integrate with custom group system
$group_id = Better_Messages()->functions->get_thread_meta( $thread_id, 'my_group_id' );
return my_is_group_member( $group_id, $user_id );
}
better_messages_is_moderation_enabled#
Filters whether message moderation (approval queue) is enabled for a user.
Parameters:
$enabled(bool) โ Default based on settings$user_id(int) โ The user$thread_id(int) โ The thread$is_new_conversation(bool) โ Whether this is the first message
Returns: bool
add_filter( 'better_messages_is_moderation_enabled', 'custom_moderation', 10, 4 );
function custom_moderation( $enabled, $user_id, $thread_id, $is_new_conversation ){
// Skip moderation for trusted users
if( user_can( $user_id, 'edit_posts' ) ){
return false;
}
return $enabled;
}
better_messages_guest_register_allowed#
Filters whether a guest is allowed to register for chat access. The default is based on the guest_access_enabled plugin setting. The $registerData array contains the submitted form data (name, email) for custom validation logic.
Parameters:
$allowed(bool) โ Default based onguest_access_enabledsetting$registerData(array|null) โ Registration form data
Returns: bool
add_filter( 'better_messages_guest_register_allowed', 'validate_guest', 10, 2 );
function validate_guest( $allowed, $data ){
if( $data && isset( $data['email'] ) ){
// Only allow specific email domains
if( ! str_ends_with( $data['email'], '@example.com' ) ){
return false;
}
}
return $allowed;
}
better_messages_rest_is_user_authorized#
Filters REST API authorization for non-logged-in users. Default is false โ logged-in users always pass automatically. Use this to implement API token authentication, JWT validation, or other custom auth systems for headless/mobile integrations.
Parameters:
$authorized(bool) โ Defaultfalse$request(WP_REST_Request) โ The REST request
Returns: bool
add_filter( 'better_messages_rest_is_user_authorized', 'api_token_auth', 10, 2 );
function api_token_auth( $authorized, $request ){
$token = $request->get_header('X-BM-Token');
if( $token && my_validate_token( $token ) ){
return true;
}
return $authorized;
}
bp_better_messages_can_block_user#
Filters whether a user can block another user.
Parameters:
$can_block(bool) โ Default based on role/immunity rules$user_id(int) โ User attempting to block$blocked_id(int) โ User to be blocked
Returns: bool
add_filter( 'bp_better_messages_can_block_user', 'prevent_blocking_staff', 10, 3 );
function prevent_blocking_staff( $can_block, $user_id, $blocked_id ){
if( user_can( $blocked_id, 'manage_options' ) ){
return false; // Cannot block admins
}
return $can_block;
}
bp_better_messages_can_unblock_user#
Filters whether a user can unblock a previously blocked user. Default is true.
Parameters:
$can_unblock(bool) โ Defaulttrue$user_id(int) โ User unblocking$blocked_id(int) โ User to unblock
Returns: bool
bp_better_messages_can_clear_thread#
Filters whether a user can clear all messages from a thread. Default: only users with bm_can_administrate capability.
Parameters:
$can_clear(bool) โ Default based onbm_can_administratecapability$user_id(int) โ The user$thread_id(int) โ The thread
Returns: bool
bp_better_messages_can_delete_thread#
Filters whether a user can delete a thread from their conversation list.
Parameters:
$has_access(bool) โ Whether user is a thread recipient$thread_id(int) โ The thread$user_id(int) โ The user
Returns: bool
bp_better_messages_can_erase_thread#
Filters whether a user can permanently erase a thread. Default: only bm_can_administrate.
Parameters:
$can_erase(bool) โ Default based on capability$user_id(int) โ The user$thread_id(int) โ The thread
Returns: bool
bp_better_messages_user_can_upload_files#
Filters whether a user can upload file attachments in a thread.
Parameters:
$can_upload(bool) โ Default based on reply access$user_id(int) โ The user$thread_id(int) โ The thread (or0for new messages)
Returns: bool
add_filter( 'bp_better_messages_user_can_upload_files', 'restrict_uploads', 10, 3 );
function restrict_uploads( $can_upload, $user_id, $thread_id ){
// Only premium users can upload
return my_is_premium_user( $user_id );
}
bp_better_messages_enable_groups_tab#
Filters whether the Messages tab is visible in BuddyPress group navigation. Default true.
Parameters:
$enabled(bool) โ Defaulttrue
Returns: bool
Message Content#
better_messages_allowed_tags#
Filters the allowed HTML tags in message content, used by wp_kses() sanitization. The default allows basic formatting: p, b, i, u, strong, br, strike, sub, sup. Add tags to this array to permit richer HTML in messages.
Parameters:
$tags(array) โ Default:p,b,i,u,strong,br,strike,sub,sup
Returns: array
add_filter( 'better_messages_allowed_tags', 'add_custom_tags' );
function add_custom_tags( $tags ){
$tags['a'] = array( 'href' => true, 'target' => true );
$tags['code'] = array();
return $tags;
}
better_messages_filter_message_content_overwrite#
Allows completely bypassing the default message content filtering pipeline. If you return a non-empty string, it replaces all default tag stripping and cleanup entirely. Return an empty string (default) to let the standard filtering proceed. Runs before any other content processing.
Parameters:
$overwrite(string) โ Default empty string$content(string) โ Raw message content
Returns: string โ Non-empty to override, empty to use default filtering
add_filter( 'better_messages_filter_message_content_overwrite', 'custom_filter', 10, 2 );
function custom_filter( $overwrite, $content ){
// Apply custom sanitization instead of default
return wp_kses_post( $content );
}
better_messages_message_content_before_save#
Filters message content immediately before it is inserted into the database. This is the last chance to modify the text after all sanitization has been applied. Called both when creating new messages and when editing existing ones.
Parameters:
$message(string) โ Message content$message_id(int) โ Message ID
Returns: string
add_filter( 'better_messages_message_content_before_save', 'modify_before_save', 10, 2 );
function modify_before_save( $message, $message_id ){
// Replace profanity
return str_replace( $bad_words, '***', $message );
}
better_messages_send_message_content#
Final filter for message content when sending a message via the REST API. Receives both the pre-filtered content and the original raw message, plus the thread ID. Use this for addon-specific content transformations that need access to the unfiltered input.
Parameters:
$filtered_content(string) โ Pre-filtered content$raw_message(string) โ Original raw message$thread_id(int) โ The thread
Returns: string
better_messages_moderation_message_content#
Filters the message content preview displayed in moderation notification emails sent to admins. The default is a 50-word trimmed, tag-stripped version of the message. Use this to customize or redact content in moderation alerts.
Parameters:
$content(string) โ Trimmed, tag-stripped message preview (50 words max)$message(object) โ Full message object
Returns: string
bp_better_messages_pre_format_message#
Filters message content at the very beginning of the formatting pipeline, before any HTML processing occurs. The $context parameter is 'stack' for message list rendering or 'site' for notification previews (which truncate to 100 characters).
Parameters:
$message(string) โ Message content$message_id(int) โ Message ID$context(string) โ'stack'or'site'$user_id(int|false) โ Current user orfalse
Returns: string
bp_better_messages_after_format_message#
Filters message content after all HTML formatting is complete but before URLs are converted to clickable links. This is the last stage of the format pipeline โ use it for final content transformations that should not affect link detection.
Parameters:
$message(string) โ Formatted message$message_id(int) โ Message ID$context(string) โ'stack'or'site'$user_id(int|false) โ Current user orfalse
Returns: string
better_messages_message_sender_id_before_save#
Filters the sender ID before the message is saved to the database. Use this to override who appears as the message sender, for example when sending messages on behalf of another user or a system account.
Parameters:
$sender_id(int) โ Sender user ID$message_id(int) โ Message ID
Returns: int
better_messages_message_thread_id_before_save#
Filters the thread ID before the message is saved to the database. Use this to redirect a message to a different thread than originally intended, for example in message routing or forwarding scenarios.
Parameters:
$thread_id(int) โ Thread ID$message_id(int) โ Message ID
Returns: int
better_messages_message_subject_before_save#
Filters the message subject/thread subject before the message is saved to the database. The subject is typically set when creating a new conversation thread.
Parameters:
$subject(string) โ Subject text$message_id(int) โ Message ID
Returns: string
better_messages_message_is_pending_before_save#
Filters the pending status flag before the message is saved. A value of 1 puts the message in the moderation queue for admin approval. A value of 0 delivers the message immediately. Custom moderation logic can use this to dynamically approve or hold messages.
Parameters:
$is_pending(int) โ Pending flag$message_id(int) โ Message ID
Returns: int
better_messages_message_get_recipient_ids#
Filters the array of recipient user IDs after usernames have been converted to IDs. Use this to dynamically add or remove recipients from a new conversation, for example to auto-include a support agent or exclude banned users.
Parameters:
$recipient_ids(array) โ Array of user IDs$recipient_usernames(array) โ Original usernames
Returns: array
better_messages_message_created_at_before_save#
Filters the message creation timestamp before saving to the database. The timestamp format is milliseconds ร 10 (i.e., Date.toMillis() * 10). To convert to a PHP DateTime: new DateTime('@' . ($value / 10000)).
Parameters:
$created_at(int) โ Timestamp (ms ร 10)$message_id(int) โ Message ID
Returns: int
better_messages_message_date_sent_before_save#
Filters the message sent date timestamp before saving to the database. This is the human-readable sent date, separate from the created_at internal timestamp.
Parameters:
$date_sent(int|string) โ Sent timestamp$message_id(int) โ Message ID
Returns: int|string
better_messages_message_updated_at_before_save#
Filters the message update timestamp before saving to the database. Stored in milliseconds ร 10 format, same as created_at. Updated when a message is edited.
Parameters:
$updated_at(int) โ Timestamp (ms ร 10)$message_id(int) โ Message ID
Returns: int
better_messages_message_temp_id_before_save#
Filters the temporary message ID (UUID) before saving. The temp_id is generated on the client for offline-first message tracking and is used to match sent messages with their server-assigned IDs.
Parameters:
$temp_id(string) โ UUID tracking identifier$message_id(int) โ Message ID
Returns: string
better_messages_change_subject_content#
Filters the thread subject text before it is saved to the database when changed via the REST API. Receives both the sanitized and original subject text, plus the thread ID, allowing custom sanitization or transformation rules.
Parameters:
$sanitized_subject(string) โ Sanitized subject$original_subject(string) โ Original input$thread_id(int) โ The thread
Returns: string
better_messages_embed_sandbox#
Available since Better Messages 2.15.26
Filters the sandbox attribute applied to the video player embedded when someone shares a YouTube, Vimeo, VideoPress, Dailymotion or Kickstarter link in a conversation.
The default value is allow-scripts allow-same-origin allow-presentation allow-popups allow-popups-to-escape-sandbox.
It deliberately leaves out allow-top-navigation, which is what stops the player from moving the page: YouTube draws the video title, the channel name and a Watch on YouTube button over the preview, and each of those is a link that takes the whole browser tab to YouTube. On a phone the preview is small enough that those links sit right next to the play button, so a slightly-off tap used to throw the viewer out of the conversation. Sandboxed, the conversation stays open. Playback and the full screen player are unaffected โ those are governed by the separate allowfullscreen attribute.
allow-popups and allow-popups-to-escape-sandbox (added in 2.15.27) are what keep those links useful: they are target="_blank" links, so they open the video on YouTube in a new tab and leave the conversation where it is. Without them the tap is swallowed and the title and logo look broken. A new tab is a separate browsing context, so this does not give the player any way back into the page.
Return an empty string to remove the sandbox entirely and restore the previous behaviour.
Parameters:
$sandbox(string) โ Space-separated sandbox tokens$provider(string) โ Lowercased provider name, for exampleyoutubeorvimeo
Returns: string
add_filter( 'better_messages_embed_sandbox', 'my_embed_sandbox', 10, 2 );
function my_embed_sandbox( $sandbox, $provider ){
if ( $provider === 'vimeo' ) {
return '';
}
return $sandbox . ' allow-popups allow-popups-to-escape-sandbox';
}
Adding allow-popups allow-popups-to-escape-sandbox, as above, is the middle ground: the title and Watch on YouTube button open in a new tab instead of being dead, and the conversation is left untouched in the original tab.
The attribute is applied when the message is rendered rather than when the link is first fetched, so changing this filter affects videos already sitting in existing conversations without clearing any cache.
better_messages_youtube_playsinline_fullscreen#
Available since Better Messages 2.15.25
Controls whether playsinline=0 is appended to the source of an embedded YouTube player.
iPhone and iPad have no full screen mode for embedded players, so YouTube's own expand button does nothing there. playsinline=0 asks YouTube to hand playback to the built-in iOS full screen video player instead, which is what makes a shared video open full screen on tap rather than staying locked at message size. Desktop browsers ignore the parameter and keep playing in place.
Return false to leave the player source untouched. A playsinline value already present in the source is always respected and never overwritten.
Parameters:
$enabled(bool) โtrueby default$src(string) โ The player URL about to be rewritten
Returns: bool
add_filter( 'better_messages_youtube_playsinline_fullscreen', '__return_false' );
REST API#
better_messages_rest_thread_item#
Filters thread/conversation data before it is returned in REST API responses. Each thread item includes properties like isHidden, subject, title, url, img, and threadInfo. Use this to add custom fields, modify display data, or hide specific threads.
Parameters:
$thread_item(array) โ Thread data$thread_id(int) โ Thread ID$type(string) โ'group'or'pm'$personal_data(bool) โ Whether personal data is included$current_user_id(int) โ Current user
Returns: array
Modifiable fields in $thread_item: isHidden, threadInfo, subject, title, url, img, participantOverrides (see the per-thread fake users guide), and more.
add_filter( 'better_messages_rest_thread_item', 'modify_thread_item', 10, 5 );
function modify_thread_item( $item, $thread_id, $type, $personal, $user_id ){
// Hide specific threads from the list
// $item['isHidden'] = 1;
// Override thread subject/title
// $item['subject'] = 'Custom Subject';
// $item['title'] = 'Custom Title';
// Set custom thread URL and image
// $item['url'] = 'https://example.com/thread/' . $thread_id;
// $item['img'] = 'https://example.com/avatar.png';
// Add custom data
$item['my_custom_field'] = get_post_meta( $thread_id, 'my_meta', true );
return $item;
}
better_messages_rest_user_item#
Filters user profile data before it is returned in REST API responses. Each user item includes url, avatar, name, canVideo, canAudio, and other properties. Use this to add custom user fields like badges, roles, or membership levels.
Parameters:
$item(array) โ User data (avatar, name, canVideo, canAudio, etc.)$user_id(int) โ User ID$include_personal(bool) โ Whether personal call preferences are included
Returns: array
Modifiable fields in $item: url, avatar, name, canVideo, canAudio, and more.
add_filter( 'better_messages_rest_user_item', 'modify_user_item', 10, 3 );
function modify_user_item( $item, $user_id, $include_personal ){
// Override profile URL
// $item['url'] = 'https://example.com/members/' . $user_id;
// Override avatar URL
// $item['avatar'] = 'https://example.com/avatars/' . $user_id . '.png';
// Override display name
// $item['name'] = 'Custom Name';
// Add custom data
$item['badge'] = get_user_meta( $user_id, 'membership_level', true );
return $item;
}
better_messages_rest_message_meta#
Filters the metadata object attached to each message in REST API responses. Default includes isPending and lastEdit fields. Addons use this to attach additional data like E2E encryption keys, read receipts, or custom annotations per message.
Parameters:
$meta(array) โ Message metadata$message_id(int) โ Message ID$thread_id(int) โ Thread ID$message_content(string) โ Message text
Returns: array
add_filter( 'better_messages_rest_message_meta', 'add_message_meta', 10, 4 );
function add_message_meta( $meta, $message_id, $thread_id, $content ){
$meta['priority'] = get_metadata( 'message', $message_id, 'priority', true );
return $meta;
}
better_messages_rest_response_headers#
Adds custom HTTP headers to all Better Messages REST API responses. Default is an empty array. Use this to add security headers, CORS headers, cache-control directives, or custom version headers for API clients.
Parameters:
$headers(array) โ Default empty array$result(WP_REST_Response) โ Response object$request(WP_REST_Request) โ Request object
Returns: array
add_filter( 'better_messages_rest_response_headers', 'add_custom_headers', 10, 3 );
function add_custom_headers( $headers, $result, $request ){
$headers['X-BM-Version'] = '2.10.0';
return $headers;
}
better_messages_rest_api_update_data#
Filters the complete response data for the main update/polling endpoint (checkNew and get_threads). The response includes threads, users, messages, and currentTime. Use this to inject additional data that the frontend needs during sync cycles.
Parameters:
$return(array) โ Response with threads, users, messages, currentTime, etc.$current_user_id(int) โ Current user$lastClient(int) โ Last client sync timestamp
Returns: array
better_messages_predefined_suggestions_user_ids#
Defines predefined user IDs to suggest as recipients when starting a new conversation. Return empty array for default behavior.
Parameters:
$user_ids(array) โ Default empty array
Returns: array
add_filter( 'better_messages_predefined_suggestions_user_ids', 'suggest_staff' );
function suggest_staff( $user_ids ){
// Always suggest support staff
return array( 1, 2, 3 ); // Staff user IDs
}
better_messages_get_unique_conversation#
Resolves a unique conversation key string to a thread ID for custom conversation routing. Default returns 0 (not found). The E2E encryption addon and custom integrations use this to map unique identifiers to specific conversations.
Parameters:
$thread_id(int) โ Default0(not found)$key(string) โ Unique key parameter$current_user_id(int) โ Current user
Returns: int
better_messages_new_thread_after_create#
Filters the result after a new thread is created via the REST API. The $sent array contains thread_id and message_id. Used by the E2E encryption addon to encrypt and send the initial thread data to the server.
Parameters:
$sent(array) โ Array withthread_idandmessage_id$request(WP_REST_Request) โ The request$current_user_id(int) โ Creator user ID
Returns: array
better_messages_new_thread_attachments#
Filters the array of uploaded file attachments before they are attached to a new thread's first message. Receives the file info array and the REST request object. Use this to validate, transform, or filter attachments during thread creation.
Parameters:
$uploaded_files(array) โ Attachment file info$request(WP_REST_Request) โ The request
Returns: array
better_messages_new_thread_e2e_init#
Allows E2E encryption addons to intercept content before default sanitization. Return array with subject and content keys to override.
Parameters:
$e2e_init(null|array) โ Defaultnull$request(WP_REST_Request) โ The request$recipients(array) โ Recipient user IDs
Returns: null|array
better_messages_private_thread_result#
Filters the result when getting or creating a private 1-on-1 thread via the suggest_thread endpoint. The result includes thread_id and a status string. Used by the E2E encryption addon to apply encryption setup to newly created PM threads.
Parameters:
$result(array) โ Result withthread_idandresultstatus$user_id(int) โ Other user$current_user_id(int) โ Current user
Returns: array
User Identity & Display#
better_messages_get_member_id#
Allows customization of the member ID used in shortcodes like [better_messages_pm_button], [better_messages_mini_chat_button], [better_messages_audio_call_button], and [better_messages_video_call_button].
Parameters:
$user_id(null|int) โ Defaultnull
Returns: int|null
add_filter( 'better_messages_get_member_id', 'custom_member_id' );
function custom_member_id( $user_id ){
if( is_singular('product') ){
// Return the product author as the message recipient
return get_post_field( 'post_author', get_the_ID() );
}
return $user_id;
}
better_messages_get_user_roles#
Filters user roles used by the plugin for role-based restrictions, limitations, and feature access. Returns ['bm-guest'] for guest users. Modify this to add custom roles or override WordPress roles for Better Messages-specific permission logic.
Parameters:
$roles(array) โ User roles array$user_id(int) โ User ID
Returns: array
add_filter( 'better_messages_get_user_roles', 'add_custom_role', 10, 2 );
function add_custom_role( $roles, $user_id ){
if( my_is_vip( $user_id ) ){
$roles[] = 'vip';
}
return $roles;
}
better_messages_is_verified#
Determines if a user is verified and should display a verification badge next to their name. Default is false โ verification must be implemented via this filter. Integrate with membership plugins, manual verification systems, or custom logic.
Parameters:
$verified(bool) โ Defaultfalse$user_id(int) โ User ID
Returns: bool
add_filter( 'better_messages_is_verified', 'verify_premium_users', 10, 2 );
function verify_premium_users( $verified, $user_id ){
return my_is_premium_user( $user_id );
}
better_messages_forced_current_user_id#
Forces a different user ID to be used instead of the currently logged-in WordPress user. Return null to use the default user detection logic. Useful for impersonation features, admin viewing as another user, or testing scenarios.
Parameters:
$user_id(null|int) โ Defaultnull(use WordPress current user)
Returns: int|null
better_messages_logged_in_user_id#
Filters the user ID returned for logged-in WordPress users. Default is get_current_user_id(). Use this to override user identity for specific contexts without affecting the WordPress session.
Parameters:
$user_id(int) โ Defaultget_current_user_id()
Returns: int
better_messages_guest_user_id#
Returns the user ID for non-logged-in (guest) users. Default is 0. Guest addon sets this to a negative number representing the guest's internal ID.
Parameters:
$user_id(int) โ Default0
Returns: int
better_messages_generated_guest_name#
Customizes the randomly generated display name for new guest users. The default uses an alliterative name generator (e.g., 'Cheerful Chipmunk'). Return a custom string to use your own naming convention.
Parameters:
$name(string) โ Generated alliterative name
Returns: string
add_filter( 'better_messages_generated_guest_name', 'custom_guest_name' );
function custom_guest_name( $name ){
return 'Guest #' . wp_rand( 1000, 9999 );
}
better_messages_guest_display_name#
Customizes the display name for guest users when their profile is loaded. Default is an empty string (the plugin uses the stored guest name). Override this to apply formatting or add prefixes like 'Guest: ' to guest names.
Parameters:
$name(string) โ Default empty string$user_id(int) โ Guest user ID (negative)
Returns: string
bp_better_messages_display_name#
Filters the display name for registered WordPress users throughout the messaging UI. The default is the user's fullname or display_name. Use this to add role badges, format names differently, or integrate with custom profile systems.
Parameters:
$name(string) โ User's display name$user_id(int) โ User ID
Returns: string
add_filter( 'bp_better_messages_display_name', 'add_role_badge', 10, 2 );
function add_role_badge( $name, $user_id ){
if( user_can( $user_id, 'manage_options' ) ){
return $name . ' [Admin]';
}
return $name;
}
bp_better_messages_avatar_extra_attr#
Adds custom HTML attributes to the <img> tag of user avatars. Default includes data-size and data-user-id attributes. Use this to add data-* attributes, aria- labels, or other custom HTML attributes for styling or JavaScript hooks.
Parameters:
$attributes(string) โ Default data attributes (size, user-id)$user_id(int) โ User ID$size(int) โ Avatar size in px
Returns: string
Thread Display#
better_messages_thread_title#
Customizes thread/conversation titles displayed in the UI. The default is the thread subject, or an auto-generated title from participant names when subjects are disabled. The $thread object provides full thread data for conditional logic.
Parameters:
$title(string) โ Thread subject or auto-generated title$thread_id(int) โ Thread ID$thread(object) โ Thread object
Returns: string
add_filter( 'better_messages_thread_title', 'custom_thread_title', 10, 3 );
function custom_thread_title( $title, $thread_id, $thread ){
$custom = Better_Messages()->functions->get_thread_meta( $thread_id, 'custom_title' );
return $custom ?: $title;
}
better_messages_thread_image#
Customizes the preview image/thumbnail for a conversation thread. Default is an empty string (no image). Return a URL to display a custom image next to the thread in the conversation list.
Parameters:
$image(string) โ Default empty string$thread_id(int) โ Thread ID$thread(object) โ Thread object
Returns: string โ Image URL