Restrict messaging only to authors
-
Hi everyone,
I want subscribers not to be able to send messages to each other but only to a specific user role. Lets say that this user role is authors.
So,
1. a subscriber can only send messages to authors or
2. a subscriber can send a message to anyone except if this user is another subscriberIs that possible?
Thank you in advance
-
I’m not aware of a plugin that will do that. There is one that does something similar, in that it restricts who can send messages to others. That’s BP Friends Only:
https://github.com/r-a-y/bp-pms-for-friends
Pretty sure that would serve as a sound basis for what you need to do, If you are able to fork it and carry out the required editing. You could then implement some checks for role relationships instead of checks for friend relationships.
Venutius Thanks for the reply,
I know about this plugin, but as you said it depends on friendship. I use php but I am not so familiar in order to do that. I would really apreciate if anyone could help on that!
Thanks again
I’ve had a look at the code, there’s three area’s that need to be changed the only issue is how to get the user roles in the context of the functions that they are sitting in, I might look at this tomorrow if I have time, I’m not expert though, it just seems like a useful exercise for someone of my skill.
But you need to map out your requirements in more detail. For example what other roles would your subscribers be able to message? admin of course? any others?
Venutius that would be awesome,
The ideal scenario is the following:
I want to prevent subscribers from sending messages to each other, but to be able to send a message to all other roles (eg admin/author/group leader etc).Thanks again, your help is valuable!
Hi billysgtr, I’ve done it, you need to make the following changes to bp-pms-for-friends.php:
Line 69 replace:
if ( ! friends_check_friendship( bp_loggedin_user_id(), $recipient->user_id ) ) { unset( $message_info->recipients[$key] ); $u++; }
With:
if ( current_user_can( 'subscriber' ) && user_can($recipient->user_id, 'subscriber') ) { unset( $message_info->recipients[$key] ); $u++; }
Line 98 edit:
$message = __( 'You are not authorized to message the person(s) you are attempting to send a message to. Your message has not been sent.', 'bp-pms' );
With you own messageLine 129 Replace:
$is_whitelisted = in_array( bp_displayed_user_id(), $this->whitelist_ids );
With:
`$is_whitelisted = true;
if ( current_user_can(‘subscriber’) && user_can( bp_displayed_user_id(), ‘subscriber’) ) {
$is_whitelisted = false;
}’This will deny any attempt to PM another subscriber and will remove the Private Message link from other subscribers profiles.
Ideally though, you should fork this by changing it’s name and plugin specific references to your own plugin references.
Venutius I just saw you answers, I am grateful to you for your help!
I will make the testing and I will let you know with the results,Thanks again 🙂
Yep open another thread 🙂
@billysgtr @venutius this is really cool news as i need the exact same feature (only authors can send private messages on buddypress) …..how do i go about getting the latest version? is it an official plugin now?
Hi @ds123,
You can use the above hooks in order to do that. You can work it on your own needs
Cheers!
- You must be logged in to reply to this topic.