User Profile Field Privacy

After lots of Googling for the best way of applying privacy settings to user profile fields like Public, Private and Friends, I came up with a custom development for this.

Our need was to provide options for a user to decide their privacy setting for each profile field, whether it is Public (can be seen by anyone), Private (no one can see this except user), and Friends (can only be seen by friends of user and himself). Let's start with some code snipets in this module. First, define some constants for your settings.

Let's provide a form for the user to set their privacy settings for each field. Assuming you have implemented hook_menu() for this.

In the submit handler of this form, just save these values in $user->data['privacy_settings']. Now let's set some default setting for a new user.

Now let's check for field access.

I think, this works well if you want to implement Privacy Settings options in your site :-) 

Tanmay

Drupal Developer

Recent Blogs