BuddyDev

Search

[Resolved] How to REMOVE name autocomplete and ability to message multiple people

Tagged: 

  • Participant
    Level: Enlightened
    Posts: 57
    Stephanie on #53885

    Hello

    I have some issues with the Buddypress messaging functionality, I’ve posted a question in the buddypress support forum but never got a reply, so I am wondering if anyone here can help.

    I need to remove the username autocomplete functionality where the names of recipients that match an input are suggested and autocompleted in the input box in Buddypress messaging. It is a big problem because currently, when someone types any letter in it, any name that matches it, shows up, for example, typing “A” will cause “Admin” and “Adam” and “Amanda” to show up. This is not good since as the admin, I do not want people to send messages to me via buddypress, they should be sending messages via a contact form. Also, I have users that register via other methods and not part of the Buddypress community, their username appears if it matches the input, even though they have nothing to do with Buddypress and will cause confusion for users. If this is not possible, I am looking for at least a way to hide certain user roles from showing up in the messaging “to” field. In case it helps anyone, the closest thing I found was this: https://www.buddyboss.com/resources/reference/functions/bp_core_get_suggestions/ but since I am not a developer, I have no idea how to implement this.

    I would also like to remove the ability for people to send messages to more than one recipient at the same time by entering more than one recipient. They should only be able to message one person at a time.

    Ideally, for both of the issues above, and especially for the first issue, the only way users can send messages should be by clicking on the “private message” button on the user’s profile instead of searching for a username (since searching for a username means the autocomplete function will show all users that match it).

    Thank you

  • Participant
    Level: Enlightened
    Posts: 57
    Stephanie on #53886

    For some reason I can’t edit my post, I get an error that says I can’t create new topics.

    I just wanted to mention, this is for Buddypress 14.3.3.

  • Keymaster
    (BuddyDev Team)
    Posts: 24694
    Brajesh Singh on #53894

    Hi Stephanie,
    Thank you for the question.

    If you are using BuddyPress legacy template pack, It is very easy to do

    
    
    /**
     * Disable auto complete for messages.
     */
    add_action( 'wp_ajax_messages_autocomplete_results', function () {
    	exit;
    }, 1 );
    
    

    In case of Nouveau, there is no way on server side to identify if the request came from message component or somewhere else. The client side code that enables it is hidden deep in the javascript. While it is certainly doable in nouveau too, It is very much prone to error.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 57
    Stephanie on #53896

    Thank you Brajesh for such a fast same day response.

    Yes, I should have mentioned that I am using Nouveau. I will have a look at the functional differences between Legacy and Nouveau.

    Is there also a way to stop people sending messages to more than one person at a time?

    Thank you
    Stephanie

  • Keymaster
    (BuddyDev Team)
    Posts: 24694
    Brajesh Singh on #53897

    Hi Stephanie,
    You are welcome.

    Yes, you can restrict to one participant.

    Here is the code for that.

    
    
    /**
     * Limit message to one participant
     */
    add_action( 'wp_ajax_messages_send_message', function () {
    	if ( empty( $_POST['send_to'] ) || ! is_array( $_POST['send_to'] ) ) {
    		return;
    	}
    
    	if ( count( $_POST['send_to'] ) > 1 ) {
    		wp_send_json_error( array(
    			'type'     => 'error',
    			'feedback' => 'Only one participant is allowed.'
    		) );
    	}
    
    }, 1 );
    
    

    Hope that helps.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 57
    Stephanie on #53898

    Thank you Brajesh, it works perfectly with Buddypress Nouveau!

    I will close this topic now.

  • Keymaster
    (BuddyDev Team)
    Posts: 24694
    Brajesh Singh on #53899

    Thank you for confirming.
    I am glad it worked!

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: resolved