Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] show buddypress private message button


  • Masoud
    Participant

    @masoud1111

    hi.
    i am using latest version of BP and WordPress.
    and i am working on a food & recipe website.
    in this website, i’d like to show the “private message” button only on admin’s page.
    something with the help of:

    if (current_user_can(administrator) && is_admin())
    { \\show the button on his profile }
    else
    { \\hide the button on profiles }

    Or maybe:

    if(current_user_id == 1) \\for example user 1 is admin
    { \\show the message button on his profile for others to see }

    —–
    as an example: imagine you have 4 users. user A, user B, user C, user D.
    Role user A : admin
    Role user B & C & D : subscribers/or/authors/or/editor/or…
    subscribers can’t see the private message button on each others profile page to send each other message.
    but when they visit User A profile page, they can see the button , and can send message only to admins…

    i searched a lot, but all i found was how to hide that button, or remove it.
    but not show it only on some profiles for others to see .

    any help would be much appreciated.
    thanks a lot.

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

  • danbp
    Moderator

    @danbp

    hi @masoud1111,

    all i found was how to hide that button, or remove it.
    but not show it only on some profiles

    You just need to add some conditionnals.

    Try this (in bp-custom.php) and give feed back if it works.

    function bpex_private_message_button( $button ) {
    $user = bp_loggedin_user_id();
    
        if ( is_super_admin() ) { 
    		return $button;
    	}
    
    	if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
    
    		if ( $role == 'subscriber' || $role == 'contributor' || $role == 'author' || $role == 'editor' )  {
    			// hide button for these roles
    			$button = '';
    		}
    	}
    
    	// allow the button to appear on admin's profile only
    	if ( bp_is_active( 'xprofile' ) && bp_is_user() )  {	
    		$user_id = bp_displayed_user_id();	
    		// assuming admin's ID is 1
    		if ( $user_id == 1 ) {
    			return $button;
    		}
    
    	}
    
    }
    add_filter( 'bp_get_send_message_button', 'bpex_private_message_button', 1 , 1 );

    Masoud
    Participant

    @masoud1111

    hi @danbp , and so many manyyy thanks for your help.
    it worked like a charm ^_^

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] show buddypress private message button’ is closed to new replies.
Skip to toolbar