Add real-time features to messages

Could you please tell me correct hook or provide a snippet - just this once, pls🙏

FIXED :heavy_check_mark: in case someone else need it.

add_action('better_messages_before_message_send', 'custom_before_message_send', 20, 2);

function custom_before_message_send(&$args, &$errors) {
    // Sender User ID
    $sender_id = (isset($args['sender_id'])) ? $args['sender_id'] : get_current_user_id();
    // Message Content
    $content = $args['content'];
    // Conversation ID
    $thread_id = $args['thread_id'];

    // Check if the sender is allowed to send the message
    $user_allowed_to_send = is_user_allowed_to_send_message($sender_id, $content);

    if (!$user_allowed_to_send) {
        // Add new error to errors array. It will be displayed to the user with an error popup
        $errors['my_custom_error_message'] = 'Please keep communication within';

// Function to check if the user is allowed to send the message
function is_user_allowed_to_send_message($user_id, $message_content) {
    // Define the patterns to search for contact details
    $patterns = array(
        '/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/', // Email pattern
        '/\b\d{10,}\b/' // Phone number pattern

    // Loop through the patterns and check if any match is found in the message content
    foreach ($patterns as $pattern) {
        if (preg_match($pattern, $message_content)) {
            return false; // If any match is found, user is not allowed to send the message

    return true; // If no match is found, user is allowed to send the message

1 Like

@andrij please help me with the correct hook or filter to change the “Write your message” placeholder text.

Thank you

1 Like

I just updated to the latest version but, it’s throwning error on all pages: “t.padEnd is not a function”?

(post deleted by author)