Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Function to hide private message depending of user role pmpro level


  • Raphael.v
    Participant

    @raphaelv

    Hi !
    I’ve been looking for this function on the forum but did not find something about my pb on the forum. I need to disable private messaging for some members. My website runs PMPRO but if a function can help me doing this, I’m OK with it.

    For example, I need users only with the WP role “premium1” to be allowed to send private message;
    OR, it can be users only with pmpro membership level “6” to have access to this function and see the “Private message” button.

    Does someone has a solution for me ? (bp-custom or function.php from child-theme)

    Thanks !

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

  • Raphael.v
    Participant

    @raphaelv

    I forgot to give some informations about my website :
    Buddypress : 2.6.2
    WP : 4.6.1
    Thème : Kleo


    danbp
    Participant

    @danbp

    Hi,

    try this (goes to bp-custom.php)

    function bpex_remove_private_message_button( $button ) {
    $user = bp_loggedin_user_id();
    
        if ( $user == '4' || $user == '7' || $user == '25'  ) { // the allowed user ID's
    	 return $button;
    	}
    
    	if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
    
    		if ( $role == 'subscriber') {
    			$button = '';
    		}
    	}
    }
    add_filter( 'bp_get_send_message_button', 'bpex_remove_private_message_button', 1 , 1 );

    No idea how to get specifically a pmpro defined user ID – you have to check their doc to adjust the above snippet. Note that it works on a standart install – without pmpro.


    Raphael.v
    Participant

    @raphaelv

    Thank you @danbp, this work ! I’m pretty sure this will help a lot (and not only me).

    I’am asking something more : can this be adapt to allow only some user role to use private message ? (and not only some users ?) As the second part of the code you wrote, it remove the button to susbscriber.

    (I’m learning PHP, I’ve tried to change the code but did not succeed to have it work…)


    danbp
    Participant

    @danbp

    This topic is titled “Function to hide private message depending of user role”.

    and the snippet does that ! Subscribers have no access to the button. So far i remember it is also the default role in WordPress. You change that to your need.

    The first condition in the snippet allows some users (by ID) to access the button, whatever their role.

    If you want to add other WP roles, you simply copy the 2nd conditionnal if(role=='') and add another role if(role=='mamamouchi") { //do something }.

    Or you use only the user ID if you have only a few members allowed to access. I litle understanding of php is of course a + to do that.
    You have the basics in the snippet. Now, it’s to you now to make it work for your need.


    Raphael.v
    Participant

    @raphaelv

    Ok got it. Of course the code given does the job I asked. Few user to allow, can be done simply by changing the snippet quickly.

    I was just wondering if this was possible, my knowledge was not good enough to modify this. But, again, you gave the answer : thank you ! I’m learning , of course I tried before I asked. I will have a look and try again with what you just wrote.

    You gave me a great help on that !


    danbp
    Participant

    @danbp

    I hope so ! FYI, we all here learned by making mistakes, errors and asking around 🙂 :
    Check the history !
    JJJ, Boone & Ray, djpaul, mercime, hnla, shanebp, henrywright, me

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] Function to hide private message depending of user role pmpro level’ is closed to new replies.
Skip to toolbar