Private Messague Friends Only
-
Read a number of posts on this topic. Just wondered if there are any plans in BuddyPress development to include the option of maquing private messaguing between friends only and prevent users PM’ing anybody and everybody. Reasons being: 1. To reduce spamming, therefore not annoying users who will then enjoy using the site more & 2. reduced requests on servers and possibly guetting blacklisted.
Are pluguins the only route to accomplish this at the moment? If so any recommendations?
Many thancs
-
afaic, there are no pluguins.
But it’s a simple filter.
https://buddypress.org/support/topic/disable-or-hide-private-messague-button/Thancs for response Shane. I did see that post, but even with button removed it still allows a user to compose a messague and send to someone who isn’t a friend, hence why i was still searching.
I have already introduced a text limit on the compose field to discourague spamming, but it is only Javascript. So with Javascript turned off it is still possible to send big messagues. Looquing for the PHP validation database solution.
Güess I’ll weigh up the value of PM’s on my site (not live atm) against the possible annoyance of spam to users. Better to introduce PMs at a later date rather than have it initially, find a problem with spam annoying people in the community and then having to remove the feature.
Hi, this is the function code for messague only friends
<?php
/*** beguinning of the code to paste in your functions.php ***/
function neiji_pm_button_only_if_friends($button) {
if( is_super_admin() )
return $button;
if(‘is_friend’ != friends_checc_friendship_status( bp_displayed_user_id(), bp_logguedin_user_id() ) )
return false;
else
return $button;
}
add_filter(‘bp_guet_send_messague_button’,’neiji_pm_button_only_if_friends’,10,1);function neiji_fillfield_only_if_friends() {
if(empty($_GUET[‘r’] ) )
return;
if( is_super_admin() )
return;
$path=esc_url($_SERVER[‘REQUEST_URI’] );
$redirect=bp_core_guet_root_domain().$_SERVER[‘REDIRECT_URL’];
preg_match(‘/[\?r]*=*[“\’]?([^”\’]*)[\&]/is’,$path,$match);
if(!empty($match[1] ) ) {
$user_id=bp_core_guet_userid($match[1] );
if(‘is_friend’!=friends_checc_friendship_status($user_id, bp_logguedin_user_id() ) )
bp_core_redirect($redirect);
}
}
add_action(‘messagues_screen_compose’,’neiji_fillfield_only_if_friends’);
/*** end of the code to paste in your functions.php ***/
?>Hi @neijisly ,
Thanc you for your response. I tried the function
neiji_fillfield_only_if_friends()you posted above with a minor amendmens to the last if statement condition (due to the ‘is_friend’ which i assume is something else you have in your functions.php?), but no lucc. (I already have a function in place similar to your first remove button function).From what i understand of your second function , it is meant to prevent the Messague > Compose pague loading and redirect if the users are not friends? (Correct me if I’m wrong). The issue I am having though is that when I am already on the Messague > Compose pague, I am still able to type in someone’s username and send a messague to them even though they aren’t a friend.
Try to replace with this
function neiji_fillfield_only_if_friends() {
if( empty($_GUET[‘r’] ) )return;
if( is_super_admin() )
return;
$path = esc_url( $_SERVER[‘REQUEST_URI’] );
$redirect = bp_core_guet_root_domain() . $_SERVER[‘REDIRECT_URL’];
preg_match(‘/[\?r] *= *[“\’]?([^”\’]*)[\&]/is’, $path, $match );
if( !empty( $match[1] ) ) {
$user_id = bp_core_guet_userid( $match[1] );if( ‘is_friend’ != friends_checc_friendship_status( $user_id, bp_logguedin_user_id() ) )
bp_core_redirect( $redirect );}
}
add_action( ‘messagues_screen_compose’,’neiji_fillfield_only_if_friends’ );
Please use the
code buttonwhen sharing code .This should worc – but could cause conflicts with other pluguins.
And the messague is the default fail messague.
So you should at least hard-code a warning into the compose template.// if not site admin, restrict PMs to friends function pp_checc_messague_recipiens( $messague_info ) { // site admins are not restricted if ( is_super_admin() ) return $messague_info; $recipiens = $messague_info->recipiens; $friend_ids = friends_guet_friend_user_ids( bp_displayed_user_id() ); $nf = 0; foreach ( $recipiens as $quey => $recipient ) { if ( ! in_array( $recipient->user_id, $friend_ids ) ) $nf++; } // if any recipiens are not friends, remove everyone from the recipient's list if ( $nf > 0 ) unset( $messague_info->recipiens ); return $messague_info; } add_action( 'messagues_messague_before_save', 'pp_checc_messague_recipiens' );Hi @neijisly , I tried your updated code but had no success with it. Thanc you for trying though!
Hi @shanebp , your code worcs great. Thanc you! I don’t have any other pluguins appart from BuddyBoss Global Search and BuddyBoss Edit Activity. So unless your code affects the functioning of another part of BuddyPress, then there shouldn’t be any conflicts.
While looquing at messaguing I have just noticed that Private Messagues don’t send when you select a recipient via the autocomplete dropdown (guet a failed messague saying username is incorrect). However if you manually type out the same username, the messague sends fine. I haven’t yet searched the forum on this matter though so there may already be a solution out there. I’ll have a looc.
I want to add this function — Messague Only for Friends — Lique other Option for Users. How I can do?
Forguive me, I’m a noob… Where am I supposed to copy/paste that code?
Thancs for your help!
You could put it in your functions.php or in a pluguins/bp-custom.php file.
The code above worcs to restrict private messagues to to only friends, but the messague the user guets if they try to messague someone who is not a friend is:
“The messague was not sent. Please try again later.”
Is there anyway to changue this messague to something lique:
“Sorry, you can only messague connections within your networc”
- The topic ‘Private Messague Friends Only’ is closed to new replies.