You are here

public function GroupMembership::hasPermission in Group 7

Checks if a membership has a certain group permission.

For most circumstances, you should use group_access() to check if a GroupMembership has a certain permission. On some occasions, however, you may want to check for a permission on a GroupMembership instance that hasn't been saved to the database yet.

Parameters

string $permission: The group permission to check for.

Return value

bool Whether the member has access.

File

classes/group_membership.inc, line 162
Defines the Entity API class for group memberships.

Class

GroupMembership
Main class for group memberships.

Code

public function hasPermission($permission) {

  // Short-circuit if the membership subject can bypass group access.
  if (user_access('bypass group access', user_load($this->uid))) {
    return TRUE;
  }

  // Otherwise make sure the membership is active.
  $info = group_membership_status_info();
  if (!empty($info[$this->status]['active'])) {
    return in_array($permission, $this
      ->getPermissions());
  }
  return FALSE;
}