How to Hide Send Private Message and Send Public Message from the members profile view
Sometimes it becomes prudent to make it more difficult for site members to email other members, for example where you are suffering from spammers.
Where to put code Snippets
Code Snippets for BuddyPress can typically be placed in two locations:
/wp-content/themes/yourchildtheme/functions.php
/wp-content/plugins/bp-custom.php
The preference is to create a bp-custom.php file, since this is independent of the theme you happen to be using.
The code snippet must be wrapped in <?php and ?> tags in order to tell you server that it is to run the code as PHP.
Remove “Send Private Message” from users who are not friends of the member whose profile they are viewing
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 '';
}
} );
Remove “Send Public Message” from users who are not friends of the member whose profile they are viewing
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;
}
} );
These code snippets were originally posted by Henry Wright in the BuddyPress Forums:
https://buddypress.org/support/topic/disable-or-hide-private-message-button/
0 Comments