Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: Resctrict private messages

@empressdianna

Participant

Thank you so much for this code! I’ve spent several hours trying to use other people’s code to hide the button and even tried to make my own but nothing worked until I found your code. I just switched it around because I only wanted one particular group to not be able to send messages while the rest can.

Posting in case someone in the future needs the opposite of your code:

add_filter( 'bp_get_send_message_button', function( $array ) {
    if ( pmpro_hasMembershipLevel('NAMEOFPMPLEVEL') ) {
        return '';
    } else {
        return $array;
    }
} );

Also, I am looking for the same code as you to restrict non-paying users from sending private messages. I found a code that looks promising but unfortunately doesn’t work. It sees if the user is logged in and if not redirects them. Then if the person is logged in it checks their role but if they’re not that role they’re supposed to be redirected. But it just breaks my whole site. Any ideas?

function my_function() {

    if ( ! is_user_logged_in() && bp_is_current_component( 'messages' ) ) {
        // Current user is not logged in so don't let them see stuff. In this case, private messages 
        wp_redirect( home_url() );
        exit;
    }
        
    $flag = false;
    // Get current user info.
    $user = wp_get_current_user();

    if ( ! in_array( 'student', $user->roles ) ) {
        // The current member is not a student.
        $flag = true;
    }

    if ( $flag && bp_is_current_component( 'messages' )  ) {
        The currently logged-in member is not a student and is trying to view private messaging. Let's redirect them away.
        wp_redirect( home_url() );
        exit;
    }
}
add_action( 'init', 'my_function' );
Skip to toolbar