Skip to:
Content
Pages
Categories
Search
Top
Bottom

Disable or Hide Private Message Button


  • namrons
    Participant

    @namrons

    In an effort to prevent spam I would like to hide the “private message” button only if you are not already friends with someone. Can anyone suggest any code to achieve this?

Viewing 16 replies - 1 through 16 (of 16 total)

  • Henry Wright
    Moderator

    @henrywright

    Try this:

    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 '';
        }
    } );

    namrons
    Participant

    @namrons

    Thanks so much @henrywright that’s working! I’m thinking I should do the same for the “Public Message” button. Could you help me out with that too?


    Henry Wright
    Moderator

    @henrywright

    For public messages, try this:

    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;
        }
    } );

    rosyteddy
    Participant

    @rosyteddy

    @namrons in which file this code is to be added ?


    namrons
    Participant

    @namrons

    thanks @henrywright That’s perfect! @rosyteddy it’s in bp-custom


    koded1999
    Participant

    @koded1999

    @henrywright Please i will like to add private message button in post side bar. i used the code below it works but doesnt populate the author automatically. how can i fix this thanks in advance.

    function bpfr_message_shortcode() {	
    $author = get_the_author();
    $message = 'Login to contact advertiser!';
    
    if( is_user_logged_in() ) {
    	return '<a>MESSAGE ADVERTISER</a>';
     } else {
        return $message;
     }
    } 
    add_shortcode( 'ksam', 'bpfr_message_shortcode' );

    koded1999
    Participant

    @koded1999

    @henrywright i managed to fix that and is working perfectly.

    but i have another problem.

    i will like to populate the subject automatically when user click the private message button from post

    pls how can i achieve this.

    thank you


    maccast
    Participant

    @maccast

    This works and hides the button, but I’m curious. Can someone still send a private message to another user when they are “not” friends using URL manipulation or should the _wpnonce stop that?


    shtimatz
    Participant

    @shtimatz

    Thanks for the tweak 😉


    nomeansno
    Participant

    @nomeansno

    Hi! Thanks for the code!

    Is there a way to allow the admins and moderators to contact anyone, even if they’re not friends ?


    nomeansno
    Participant

    @nomeansno

    I suppose that’s a no? Well, too bad.


    Venutius
    Moderator

    @venutius

    You can do something like this:

    add_filter( 'bp_get_send_public_message_button', function( $r ) {
        if ( friends_check_friendship( bp_loggedin_user_id(), bp_displayed_user_id() ) || current_user_can('manage_options') ) {
            return $r;
        } else {
            $r['component'] = '';
            return $r;
        }
    } );

    excellins
    Participant

    @excellins

    Hi @henrywright, please where should i paste this?
    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 ”;
    }
    } );


    Venutius
    Moderator

    @venutius

    It can go in your child-themes function.php file or you can create a bp-custom.php file in the plugins directory and put the code in there.


    Abhishek
    Participant

    @abhishekshrm2001

    I wanted to hide reply button for only one group, can anyone please help me with that,


    rajibjoshi
    Participant

    @rajibjoshi

    Hi,
    I’ve built a custom user profile page using JetEngine. Is there a way to redirect visitors who click the “Profile” button on a BuddyPress profile page to my custom page, displaying their profile information?

    or please guide me as to how I can access buddypress all Meta_fields from Elementor ? Because i want to design my own profile page layout.

    Thanks in Advance

    Rajib

Viewing 16 replies - 1 through 16 (of 16 total)
  • You must be logged in to reply to this topic.