Show block only to Organic Group (OG) Admins or of a particular group type

Last modified: April 24, 2008 - 16:11

I use this to show a block:

1) only in a group;
2) only if the user has access (for example, block won't show if the node is unpublished, even if the user owns the node/group);
3) only in groups of a particular named type; and/or
4) only to group admins.

<?php
//check og module exists
if (module_exists('og')){

//check we've got a group, rights to view the group,
// and of type "group_type" - change this to whichever group you want to restrict the block to
//or remove the condition entirely
if (($group = og_get_group_context()) && node_access('view', $group) && ($group->type == 'group_type') ) {

//check current user is a team admin
if (og_is_node_admin($group))  return TRUE;
}
}
?>

different in Drupal 6

aschiwi - July 22, 2009 - 14:21

og_is_node_admin($group) is now og_is_group_admin($group)

<?php
//check og module exists
if (module_exists('og')){

//check we've got a group, rights to view the group,
// and of type "group_type" - change this to whichever group you want to restrict the block to
//or remove the condition entirely
if (($group = og_get_group_context()) && node_access('view', $group) && ($group->type == 'group_type') ) {

//check current user is a team admin
if (og_is_group_admin($group))  return TRUE;
}
}
?>

Membership requests

etcetera9 - July 27, 2009 - 20:47

I did a filtering for membership request type of a group (approved, invite-only etc.)

I just added ($group->og_selective == '2') to the if statement.

0 is for open, 1 is for moderated, 2 is for invite-only, 3 is for closed groups.

The final code was:

<?php
//check og module exists
if (module_exists('og')){

//check we've got a group, rights to view the group,
// and of type "group_type" - change this to whichever group you want to restrict the block to
//or remove the condition entirely
if (($group = og_get_group_context()) && node_access('view', $group) && ($group->type == 'group_type') && ($group->og_selective == '2')) {

//check current user is a team admin
if (og_is_node_admin($group))  return TRUE;
}
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.