Created
July 1, 2019 18:48
-
-
Save KaineLabs/47523bad96fe9536c80611e4f74aca7b to your computer and use it in GitHub Desktop.
Disable User Profiles By 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 | |
/** | |
* Disable User Profiles By Role | |
*/ | |
function yzc_disable_profiles_by_role() { | |
if ( bp_is_user() ) { | |
// Forbidden Roles ! Roles Like : administrator, editor | |
$forbidden_roles = array( 'role1', 'role2' ); | |
// Get Current User Data. | |
$user = get_userdata( bp_displayed_user_id() ); | |
// Get Roles. | |
$roles = (array) $user->roles; | |
foreach ( $forbidden_roles as $forbidden_role ) { | |
if ( in_array( $forbidden_role, $roles ) ) { | |
$redirect_url = home_url(); | |
wp_redirect( $redirect_url); | |
exit(); | |
break; | |
} | |
} | |
} | |
} | |
add_action( 'template_redirect', 'yzc_disable_profiles_by_role' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment