Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raviousprime/1a1cbf1ce75b63cae787495c7dc578db to your computer and use it in GitHub Desktop.
Save raviousprime/1a1cbf1ce75b63cae787495c7dc578db to your computer and use it in GitHub Desktop.
Restricted user to view other profile based on his role
<?php
add_action( 'bp_template_redirect', function() {
if ( bp_is_user() && is_user_logged_in() && ! bp_is_my_profile() ) {
$user = wp_get_current_user();
$restricted_roles = array( 'editor' ); // Replace by your roles.
$has_restricted_role = array_intersect( $restricted_roles, $user->roles );
if ( ! empty( $has_restricted_role ) ) {
$message = sprintf( 'You are not allowed to view %s profile', bp_core_get_user_displayname( bp_displayed_user_id() ) );
bp_core_add_message( $message, 'error' );
bp_core_redirect( bp_loggedin_user_domain() );
}
}
} );
@gwamin0831
Copy link

I am a Buddypress beginner, so I don't know where to paste your code.
I am building a wordpress website which has profile page provided by Youzify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment