Chat permissions for users

Need to forbid access to video calls or sending files to some part of users?

For example, only administrators can start video calls or sending messages and others can only chatting.

So, based on that, we have prepared the PHP code for that functions. You should insert it in your website repository to the WP theme file "functions" at the bottom of the file.

Example of the path to the file for SweetDate:

\wp-content\themes\sweetdate\functions.php

The feature code:

add_filter( 'rest_request_before_callbacks', 'your_permission_access_function', 10, 3 ); 

function your_permission_access_function($response, $handler, $request)
    {
        /**
         * Here is example how you can control user's permissions.
         * This example of giving permissions by user role
         * admin - allowed to use all features of ImbaChat
         * user - allowed to write message and nothing else
         **/
        if (!isset($handler['imbachat_callback'])) {
            return $response;
        }
        if ($handler['imbachat_callback'] != 'get_users') {
            return $response;
        }
        $user_id = $response['user_id'];

        $user = get_user_by('id', $user_id);
        if ( in_array( 'administrator', (array) $user->roles ) ) {
            $role = 'admin';
        } else {
            $role = 'user';
        }

        if ($role == 'admin') {
            $permissions = [
                'send_message' => 1,
                'send_files' => 1,
                'send_geo' => 1,
                'audio_calls' => 1,
                'video_calls' => 1,
                'audio_message' => 1,
                'video_message' => 1
            ];
        } else {
            $permissions = [
                'send_message' => 1,
                'send_files' => 0,
                'send_geo' => 0,
                'audio_calls' => 0,
                'video_calls' => 0,
                'audio_message' => 0,
                'video_message' => 0
            ];
        }
        return [
            'permissions' => $permissions
        ];
    }

Permissions:

  1. send_message - Allowed you to send messages
  2. send_files - Allowed you to send files
  3. send_geo - Allowed you to send geo position
  4. audio_calls - Allowed you to start audio calls
  5. video_calls - Allowed you to start video calls
  6. audio_message - Allowed you to send audio messages
  7. video_message - Allowed you to send video messages

You can find more info about chat set up here:

How to customize widget appearance

ImbaChat troubleshooting

How to set up role-based access control for monetization