Skip to:
Content
Pages
Categories
Search
Top
Bottom

Disable or Hide Private Message Button

  • Profile photo of namrons
    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 9 replies - 1 through 9 (of 9 total)
  • Profile photo of Henry Wright
    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 '';
        }
    } );
    Profile photo of namrons
    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?

    Profile photo of Henry Wright
    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;
        }
    } );
    Profile photo of Rosyteddy
    rosyteddy
    Participant

    @rosyteddy

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

    Profile photo of namrons
    namrons
    Participant

    @namrons

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

    Profile photo of koded1999
    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' );
    Profile photo of koded1999
    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

    Profile photo of maccast
    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?

    Profile photo of shtimatz
    shtimatz
    Participant

    @shtimatz

    Thanks for the tweak 😉

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