Out of the box the 'Group members' and 'Latest group activity' blocks on the main page of a group are visible to all users regardless of whether one is a member of that group or not.

How can both blocks be displayed only when a user is a member of that group?

Thank you,



I had an urgent need to fix this issue quickly so I added a few lines of code to one of the Drupal Commons files directly. Once I have more time I plan to extract the functionality into a custom module. Until then this was my fix:

  1. Open file /profiles/drupal_commons/modules/features/common_core/commons_core.blocks.inc

  2. Locate functions '_commons_core_group_activity_block_view()' and '_commons_core_group_members_block_view()'.

  3. Add the following lines before the if statements:

    //Determine group nid $url_parameter = explode("/", $_GET['q']); $group_nid = $url_parameter[1];

    //Determine group membership, exclude Admins $is_group_member = og_is_group_member($group_nid,$include_admins = FALSE);

  4. Add && ($is_group_member != '') as second condition to each if statement

If you know a better way please share.


| improve this answer | |

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.