Wenngleich BuddyBoss ein Community-Plugin ist und sich User finden sollen, kann es in seltenen Fällen dennoch Sinn machen, den Zugriff auf die Profile zu verweigern.
Dazu folgendes Script:
function bb_restrict_profile_access() {
if ( ! is_user_logged_in() || ! function_exists( 'bp_is_user' ) || ! bp_is_user() ) {
return;
}
$current_user_id = get_current_user_id();
$displayed_user_id = bp_displayed_user_id();
// If the current user is viewing their own profile, allow access.
if ( $current_user_id === $displayed_user_id ) {
return;
}
// Redirect non-admin users to their own profile page if they try to access another user's profile.
if ( ! current_user_can( 'manage_options' ) ) {
bp_core_redirect( bp_loggedin_user_domain() );
}
}
add_action( 'template_redirect', 'bb_restrict_profile_access' );