How should custom permissions created by hook_civicrm_permission be properly checked?

Have defined custom permission like this:

function mymodulename_civicrm_permission(&$permissions) {
    $prefix = ts('SpecialPermissions') . ': '; // name of extension or module
    $permissions['SpecialPermissions'] = $prefix . ts('SpecialPermissions');

and checking it later on, same module, hook_civicrm_buildForm, have tried every option listed below:

* if (CRM_Core_Permission::check('SpecialPermissions')) {
* if (CRM_Core_Permission::check('Drupal: SpecialPermissions')) {
* if (CRM_Core_Permission::check('CiviCRM: SpecialPermissions')) {
* if (CRM_Core_Permission::check('cms: SpecialPermissions')) {

Code looks like exactly according to specs from: * http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_permission * http://wiki.civicrm.org/confluence/display/CRMDOC/Permission+Reference

However, both test user with a corresponded permission AND Drupal user 1 (UID=1) are being affected, even when Drupal User 1 doesn't have role with custom permissions attached. Not sure if it is by design or something wrong with my implementation of this? Please advice.

1 Answer 1


I may be misreading this, but it sounds like you're saying that you've got a new permission, and the user with the role that has the permission granted is working just fine. However, you're saying that Drupal user ID 1 is being treated as if it has the permission, even though it doesn't have any role with that permission.

If so, this is totally normal. Drupal user ID 1 gets all permissions, even when using CRM_Core_Permission::check('SpecialPermissions'). You should be able to confirm by creating another user without that permission and seeing that CRM_Core_Permission::check('SpecialPermissions') returns false.

  • Good to know, thanks; a bit unusual behaviour from a drupal user 1 point of view though.
    – yurg
    Jan 27, 2016 at 19:55

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.