Hi Tosin,
I will look into it coming Monday.Thank you
BrajeshHello Tosin,
Please try the following code to hide public and private buttons based on user capability. Please follow the following url for more user capabilities.
https://codex.wordpress.org/Roles_and_Capabilities
function buddydev_hide_public_button( $r ) { if ( ! current_user_can( 'publish_posts' ) ) { return false; } return $r; } add_filter( 'bp_get_send_public_message_button', 'buddydev_hide_public_button' ); add_filter( 'bp_get_send_message_button_args', 'buddydev_hide_public_button' );
Use this code in your “bp-custom.php file”
Thanks
RaviHello Tosin,
For user ids, you can use the following code.
function buddydev_hide_public_button( $r ) { if ( ! is_user_logged_in() ) { return $r; } $restricted_user_ids = array( 5, 26, 10, 4 ); // Replace by yours user ids. if ( in_array( get_current_user_id(), $restricted_user_ids ) ) { return false; } return $r; } add_filter( 'bp_get_send_public_message_button', 'buddydev_hide_public_button' ); add_filter( 'bp_get_send_message_button_args', 'buddydev_hide_public_button' );
Regards
RaviHello,
The code works when I deactivate this plugin (bp-profile-message-ux). This plugin is conflicting with your code https://wordpress.org/plugins/bp-profile-message-ux/ Is there any way you can make the code to be compatible with this plugin.
Also, when I deactivate the BP PROFILE MESSAGE UX plugin your code still hides the public and private message buttons for all my users instead of only the specific ids I stated.
This is the code im using/** * HIDE BUDDYPRESS PUBLIC AND PRIVATE MESSAGE BUTTON FOR SPECIFIC USERS. */ function buddydev_hide_public_button( $r ) { if ( ! is_user_logged_in() ) { return $r; } $restricted_user_ids = array( 2, 4766812, 4766806, 4766824, 4766786 ); // Replace by yours user ids. if ( in_array( get_current_user_id(), $restricted_user_ids ) ) { return false; } return $r; } add_filter( 'bp_get_send_public_message_button', 'buddydev_hide_public_button' ); add_filter( 'bp_get_send_message_button_args', 'buddydev_hide_public_button' );
Thanks
The topic ‘ [Resolved] How to disable public and private messages for specific users’ is closed to new replies.