I am using the profile2 and the profile2 page modules. I have 2 profiles called user and advanced_user and corresponding roles associated to them. The advanced_user has more fields available in his profile.

The problem: when I strip an advanced_user of his role (aka demote him to user), the extra fields that he previously filled in his profile form remain in his profile page and so is the "Advanced User" title. How can I remove the additional information that was added in the advanced profile?

Note: I wouldn't mind if the extra fields' information was kept stored (so that if I ever "promote" her again she would have the fields already populated) but I definitely want to keep them from showing in the user's profile page.

1 Answer 1


Try implementing hook_profile2_view_alter(). Below is a sample code:

 * Implements hook_profile2_view_alter().
function example_profile2_view_alter(&$build) {
  global $user;
  $rid = <advance_user_role_id>;

  if (!array_key_exists($rid, $user->roles)) {

    $advance_fields = array(); // List of field ID's that should only be displayed
                               // for advance users.

    foreach (element_children($build) as $id) {
      if (in_array($id, $advance_fields)) {
        $build[$id]['#access'] = FALSE;

Your Answer

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