Role based access to the chat
Gender role
It could be different roles. For example, it is role by gender for dating websites:
Need to divide users by gender to create a heterosexual Dating platform?
Usually, it means that users can start a conversation only with opposite gender user. And also, based on a social roles of women and men in the Dating chats, woman can reject or accept a conversation with a man, but man not.
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
Other role
Also, it can be useful for a Marketplace website. This code below also helps to prohibit sellers from writing to buyers. You can compare the status of your users and allow show chat button or disallow base on users role.
The feature code:
add_filter ('imbachat_open_dialog_filter', function ($parameter, $user_from, $user_to) {
$user_from_gender = xprofile_get_field_data (5, $user_from);
$user_to_gender = xprofile_get_field_data (5, $user_to);
// Users with the same gender cannot write to each other
if ($user_from_gender == $user_to_gender) {
return array ('status' => 'disallow');
}
// if a man writes to a woman, then the woman can reject / accept the request
if ($user_from_gender == 'Man') {
return array ('status' => 'need_access');
}
// A woman can write to a man without a request
if ($user_from_gender == 'Woman') {
return array ('status' => 'default');
}
return array ('status' => 'default');
}, 10, 3);