Skip to content

Instantly share code, notes, and snippets.

@KaineLabs
Created July 1, 2019 18:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KaineLabs/47523bad96fe9536c80611e4f74aca7b to your computer and use it in GitHub Desktop.
Save KaineLabs/47523bad96fe9536c80611e4f74aca7b to your computer and use it in GitHub Desktop.
Disable User Profiles By Role
<?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