Disable or Hide Private Message Button
-
In an effort to prevent spam I would like to hide the “private message” button only if you are not already friends with someone. Can anyone suggest any code to achieve this?
-
Try this:
add_filter( 'bp_get_send_message_button', function( $array ) { if ( friends_check_friendship( bp_loggedin_user_id(), bp_displayed_user_id() ) ) { return $array; } else { return ''; } } );
Thanks so much @henrywright that’s working! I’m thinking I should do the same for the “Public Message” button. Could you help me out with that too?
For public messages, try this:
add_filter( 'bp_get_send_public_message_button', function( $r ) { if ( friends_check_friendship( bp_loggedin_user_id(), bp_displayed_user_id() ) ) { return $r; } else { $r['component'] = ''; return $r; } } );
@namrons in which file this code is to be added ?
thanks @henrywright That’s perfect! @rosyteddy it’s in bp-custom
@henrywright Please i will like to add private message button in post side bar. i used the code below it works but doesnt populate the author automatically. how can i fix this thanks in advance.
function bpfr_message_shortcode() { $author = get_the_author(); $message = 'Login to contact advertiser!'; if( is_user_logged_in() ) { return '<a>MESSAGE ADVERTISER</a>'; } else { return $message; } } add_shortcode( 'ksam', 'bpfr_message_shortcode' );
@henrywright i managed to fix that and is working perfectly.
but i have another problem.
i will like to populate the subject automatically when user click the private message button from post
pls how can i achieve this.
thank you
This works and hides the button, but I’m curious. Can someone still send a private message to another user when they are “not” friends using URL manipulation or should the
_wpnonce
stop that?Thanks for the tweak 😉
Hi! Thanks for the code!
Is there a way to allow the admins and moderators to contact anyone, even if they’re not friends ?
I suppose that’s a no? Well, too bad.
You can do something like this:
add_filter( 'bp_get_send_public_message_button', function( $r ) { if ( friends_check_friendship( bp_loggedin_user_id(), bp_displayed_user_id() ) || current_user_can('manage_options') ) { return $r; } else { $r['component'] = ''; return $r; } } );
Hi @henrywright, please where should i paste this?
add_filter( ‘bp_get_send_message_button’, function( $array ) {
if ( friends_check_friendship( bp_loggedin_user_id(), bp_displayed_user_id() ) ) {
return $array;
} else {
return ”;
}
} );It can go in your child-themes function.php file or you can create a bp-custom.php file in the plugins directory and put the code in there.
I wanted to hide reply button for only one group, can anyone please help me with that,
Hi,
I’ve built a custom user profile page using JetEngine. Is there a way to redirect visitors who click the “Profile” button on a BuddyPress profile page to my custom page, displaying their profile information?or please guide me as to how I can access buddypress all Meta_fields from Elementor ? Because i want to design my own profile page layout.
Thanks in Advance
Rajib
- You must be logged in to reply to this topic.