Created
October 17, 2019 05:10
-
-
Save raviousprime/1a1cbf1ce75b63cae787495c7dc578db to your computer and use it in GitHub Desktop.
Restricted user to view other profile based on his role
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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() ); | |
} | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.