BuddyDev

Search

[Resolved] Restrict BP users from viewing other's profile based on role

  • Participant
    Level: Enlightened
    Posts: 23
    y2gabs on #25957

    Hi there! Hoping you might point me in the right direction. I’m trying to restrict a specific role from being able to view any profile other than their own. I feel like I’ve tried everything and every plugin out there but no solutions just yet. I’d ideally like to do this without modifying the theme’s profile page and rather as a function in the functions.php page.

    Any help would be wonderful!

    Thanks again!

  • Participant
    Level: Enlightened
    Posts: 23
    y2gabs on #25958

    This is what I’ve tried so far:

    add_action( ‘Prevent_Tenant_From_Others_profile’, function() {
    if ( bp_is_user_profile() ) {
    $user_meta = get_userdata( bp_loggedin_user_id() );

    if ( in_array( ‘tenant’, $user_meta->roles ) ) {
    wp_redirect( home_url() );
    exit;
    }
    }
    }, 1 );

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #25964

    Hello,

    Thank you for posting. Please refer the url:
    https://gist.github.com/raviousprime/1a1cbf1ce75b63cae787495c7dc578db

    It allows to restrict user to view others profile based on his role.

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 23
    y2gabs on #26001

    That worked !!

    Thanks!

    J.

The topic ‘ [Resolved] Restrict BP users from viewing other's profile based on role’ is closed to new replies.

This topic is: resolved