Community Documentation

hook_perm

5 core.php hook_perm()
6 core.php hook_perm()

Define user permissions.

This hook can supply permissions that the module defines, so that they can be selected on the user permissions page and used to grant or restrict access to actions the module performs.

Permissions are checked using user_access().

For a detailed usage example, see page_example.module.

Return value

An array of permission strings. The strings must not be wrapped with the t() function, since the string extractor takes care of extracting permission names defined in the perm hook for translation.

Related topics

▾ 23 functions implement hook_perm()

aggregator_perm in modules/aggregator/aggregator.module
Implementation of hook_perm().
block_perm in modules/block/block.module
Implementation of hook_perm().
blogapi_perm in modules/blogapi/blogapi.module
Implementation of hook_perm().
blog_perm in modules/blog/blog.module
Implementation of hook_perm().
book_perm in modules/book/book.module
Implementation of hook_perm().
comment_perm in modules/comment/comment.module
Implementation of hook_perm().
contact_perm in modules/contact/contact.module
Implementation of hook_perm
filter_perm in modules/filter/filter.module
Implementation of hook_perm().
forum_perm in modules/forum/forum.module
Implementation of hook_perm().
locale_perm in modules/locale/locale.module
Implementation of hook_perm().
menu_perm in modules/menu/menu.module
Implementation of hook_perm().
node_perm in modules/node/node.module
Implementation of hook_perm().
path_perm in modules/path/path.module
Implementation of hook_perm().
poll_perm in modules/poll/poll.module
Implementation of hook_perm().
search_perm in modules/search/search.module
Implementation of hook_perm().
statistics_perm in modules/statistics/statistics.module
Implementation of hook_perm().
system_perm in modules/system/system.module
Implementation of hook_perm().
taxonomy_perm in modules/taxonomy/taxonomy.module
Implementation of hook_perm().
theme_user_admin_perm in modules/user/user.admin.inc
Theme the administer permissions page.
translation_perm in modules/translation/translation.module
Implementation of hook_perm().
upload_perm in modules/upload/upload.module
Implementation of hook_perm().
user_admin_perm in modules/user/user.admin.inc
Menu callback: administer permissions.
user_perm in modules/user/user.module
Implementation of hook_perm().

File

developer/hooks/core.php, line 1741
These are the hooks that are invoked by the Drupal core.

Code

<?php
function hook_perm() {
  return array('administer my module');
}
?>

Comments

hook_permission() in Drupal 7

For the Drupal 7 version of this hook see http://api.drupal.org/api/function/hook_permission/7

Comma not allowed in perm string

Comma can't be used in perm string because permissions are stored in permission table with a comma as separator...

As a workaround, I use the Single low-9 quotation mark utf8 character "‚" instead of comma in my perm string when needed...

Perhaps that's not such a good idea..

If someone wants to do something that depends on having this permission, they'll use the user_access() function and need to type in the permission string. If you've put in a single low quotation mark, then the person will have great difficulty when they try to use user_access. Particularly as they'll be causing DB errors and whatnot.

Changing a users permission

Was looking at how to do it; here's how core does it
http://api.drupal.org/api/function/user_admin_perm_submit/6

Some permissions already set by node_perm()

Note to module developers who are creating their own content type:

Most of the common permissions are already set in node.module, so you don't need to add them to your own module. See the node_perm() page in the API documentation.

HTML tags

HTML tags such as <strong>, <em> etc. can't be used because it is being used in name and in the title tag.

HTML-Tags wie <strong>, <em> etc. können nicht verwendet werden da es auch in name und im title-Tag verwendet wird.

In Drupal 7 this has changed

In Drupal 7 this has changed to hook_permissions

link for page_example.module implementation

This documentation asks us to see page_example.module without providing a link. Try the page_example.module implementation of hook_perm to save you a few moments searching.

Can we introduce a new documentation principle "don't make me search" with apologies to Steve Krug? :)

[annotation: I now notice other examples of the same failure in the API docs, it's not just this one]

Login or register to post comments