1

I have various users on a Drupal site.

Internally, I differentiate between users by user role (e.g. 'member', 'non-member').

Is it possible that if a user has a certain user role, that I prevent them from having a user page that is visible to the public?

E.g., if user 10018 has user role 'non-member', how can I prevent user page (site.com/user/10018/) from being visible to the public and users of role 'member'?

Basically, I don't want to delete 'non-member' users unless it's absolutely necessary - but I don't want them to have user pages that are visible to anyone other than site admins.

Thank you!

3 Answers 3

1

I suppose you could use the Rules module to create a redirect (possibly to 404) when someone tries to view the user page of a user with a specified role.

0

I would work with hook_node_access.

Something like, if user we are viewing does not have role Member or user looking isn't admin, prevent access.

0

You could use hook_page_build(&$page)

  1. get user id from url
  2. load user object using user_load()
  3. check the user role
  4. change the page content as you need

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.