if (CRM_Core_Permission::check('access CiviCRM')) { // allow access to the CRM } else { // deny access }
// get the role object $roleId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Role', 'Volunteer', 'id', 'name'); $role = CRM_Core_DAO::getInstance('CRM_Core_DAO_Role', $roleId); // grant the permission $role->grantPermission('access CiviEvent'); $role->save();
if (CRM_Core_Permission::check('access CiviEvent', $eventId)) { // allow access to the event } else { // deny access }These examples demonstrate how the CRM_Core_Permission class can be used to manage permissions and access control in a CiviCRM installation. It is part of the CiviCRM core package library.