I’m not aware of a plugin that can do exactly that? Perhaps some of the guys on here know of one?
To do it manually, you could hook a function to init
and work from there. For example:
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' );
From that, you should be able to see how you can achieve what you’re trying to do without the need of a plugin.
Refs:
Template Tag Reference
https://codex.wordpress.org/Function_Reference/wp_redirect