Hello Tosin,
Thank you for the acknowledgment. Yes plugin is conflicting with our custom code. Please use the following code and let me know it works or not.
function buddydev_hide_buttons() { if ( ! is_user_logged_in() ) { return; } $restricted_user_ids = array( 5, 26, 10, 4 ); // Replace by yours user ids. if ( ! in_array( get_current_user_id(), $restricted_user_ids ) ) { return; } if ( function_exists( 'bp_profile_message_ux_init' ) ) { remove_all_filters('bp_get_send_public_message_button'); remove_all_filters('bp_get_send_message_button'); } add_filter( 'bp_get_send_public_message_button', '__return_false' ); add_filter( 'bp_get_send_message_button_args', '__return_false' ); } add_action( 'bp_init', 'buddydev_hide_buttons', 11 );
Regards
RaviHi Tosin,
I am sorry but we won’t be able to provide free support for 3rd part plugins except BuddyPress. If Ravi prefers, he may support you but I won’t be able to do it.If you want to implement the same with default BuddyPress message button, I will gladly help.
Regards
BrajeshHello Brajesh,
Thank you so much for you help I will do as instructed, I have deactivated the BP Profile Message UX plugin but I noticed that the same issue occurs even with the default buddypress message using the first code you sent
/** * 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, 4766838 ); // 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' );
1. The code only works for the admin and not all users
2. The code works but it hides the buttons for (all users) instead of just the specific ids
Thank you Tosin,
I will assist you with it today.Regards
BrajeshHi Tosin,
I will be assisting you now.I have tested the above code(from your last post) and here is what I found.
1. The code works. It limits restricted users from sending message.
is your goal to restrict the button for certain users to receive the message? If yes, Please let me know.
Regards
BrajeshSir I understand the problem better like you said your code limits restricted users from sending messages but what I’m trying to achieve is opposite, I want to limit the restricted users from RECEIVING messages (The buttons should be hidden for the restricted users)
Thank you very much
Hi Tosin,
Thank you for clarifying.Please remove the old code and use the following
/** * Is user restricted from receiving message. * * @param int $user_id user id. * * @return bool */ function buddydev_is_user_restricted( $user_id ) { // These user's won't be able to send the message. $restricted_user_ids = array( 2, 4766812, 4766806, 4766824, 4766786, 4766838 ); return in_array( $user_id, $restricted_user_ids ); } /** * Hide public message button if needed. * * @param array $r button args. * * @return array */ function buddydev_hide_public_button( $r ) { if ( bp_is_user() && buddydev_is_user_restricted( bp_displayed_user_id() ) ) { $r = array(); } return $r; } add_filter( 'bp_get_send_public_message_button', 'buddydev_hide_public_button' ); /** * Hide private message button if needed. * * @param array $r args. * * @return array */ function buddydev_hide_private_button( $r ) { if ( bp_is_user() && buddydev_is_user_restricted( bp_displayed_user_id() ) ) { $r = array(); } return $r; } add_filter( 'bp_get_send_message_button_args', 'buddydev_hide_private_button' );
Hope this helps. Please let me know if it works for you or not?
Regards
BrajeshHello,
The code worked perfectly thank you so much im very grateful.
Now that the buttons are hidden it is still possible to send public messages directly on the Activities page, will it be possible to disable (@usernames) for those specific restricted ids on Activity status form for posting updates.
Thanks
The topic ‘ [Resolved] How to disable public and private messages for specific users’ is closed to new replies.