0

I'm searching for a way to let users chose if they want their user profile to be public or to be private (just the owner and admin). I'm not picky if this can se set for the whole profile or for every profile field.

I already looked at User Field Privacy but this one conflicts with Field Permissions (this site needs fields permissions). And I'd rather not use Profile2 for this functionality since I'm only using the standard profile fields.

I thought about using Field Conditional Formatters but this seams rather complicated to set up for every field.

Any ideas?

0

Easiest way would be to change the access callback to the user page (user/%user) via hook_menu_alter. The new access callback would use the value of a user field to determine or the page is accessible or not.

Code to give you an idea of the structure, not a fully functioning example

YOUR_MODULE_menu_alter(&$items){
  $items['user/%user']['access callback'] = 'user_profile_is_private'; 
}

function user_profile_is_private($user){
  // Check the content of the user field here and return true/false. 
}

This tells drupal to use the user_profile_is_private function to determine or people can access the user page or not. This function should return true/false. The user object is passed to this function via the core user module already.

You'll need to add the core user access function user_view_accessin there somehow to prevent this change to override all other access settings.

0

If you're looking for a ready to go solution, take a look at nodeaccess module:

Nodeaccess is a Drupal access control module which provides view, edit and delete access to nodes. Users with the 'grant node permissions' permission will have a grant tab on node pages which allows them to grant access to that node by user or role. Administrators can set default access controls per content type, and also define which roles are available to grant permissions to on the node grants tab.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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