BuddyDev

Search

[Resolved] How to disable public and private messages for specific users

  • Participant
    Level: Guru
    Posts: 885
    Tosin on #17908

    Hello Brajesh,

    Please how can I disable or hide public and private message function or button for specific users. I dont want user a, b and c to have the public message and private message button.

    Thanks

  • Keymaster
    (BuddyDev Team)
    Posts: 24231
    Brajesh Singh on #17911

    Hi Tosin,
    I will look into it coming Monday.

    Thank you
    Brajesh

  • Participant
    Level: Guru
    Posts: 885
    Tosin on #18016

    Awaiting your feedback sir

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2935
    Ravi on #18040

    Hello 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
    Ravi

  • Participant
    Level: Guru
    Posts: 885
    Tosin on #18043

    Hello Brajesh,

    Thanks but I wasn’t referring to roles and capabilities but specific user ids

    Thank you

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2935
    Ravi on #18046

    Hello 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
    Ravi

  • Keymaster
    (BuddyDev Team)
    Posts: 24231
    Brajesh Singh on #18052

    Hi Ravi,
    Thank you for the help here.


    @teeboy
    , I hope it works.

    Regards
    Brajesh

  • Participant
    Level: Guru
    Posts: 885
    Tosin on #18053

    Hello Brajesh,

    The code did not work the public and private message buttons are still visible for the specific user ids I selected.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2935
    Ravi on #18055

    Hello Tosin,

    Strange, This code is working for me. Can you please post me the code you are using.

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 885
    Tosin on #18056

    Hello,

    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.

This topic is: resolved