Main topic described: Permissions
Drupal hook described: hook_perm

The next function to write is the permissions function, using the _perm hook. This is where you will define the names of the permissions of your module. This function doesn't grant permission, it just specifies what permissions are available for this module. Access based on these permissions is defined later in the {module}_access function, later in the tutorial.

/**
* Valid permissions for this module
* @return array An array of valid permissions for the onthisdate module
*/

function onthisdate_perm() {
  return array('access onthisdate content');
} // function onthisdate_perm()

If you are going to write a module that needs to have finer control over the permissions, and you're going to do permission control (by checking permissions), you should expand this permission set. For example:


function onthisdate_perm() {

return array('access onthisdate content', 'administer onthisdate');

} // function onthisdate_perm

For this tutorial, start with the first one. We'll later move to the second version.

You'll need to adjust who has permission to view your module on the Administer » User management » Access control permissions page. We'll use the user_access function to check access permissions later (whoa, so many "laters!").

Your permission strings are arbitrary, but each must be unique among all installed modules. Otherwise, one occurrence of the name will take the permissions of the other. The permission strings should each usually contain your module name, since this helps avoid name space conflicts with other modules.

The suggested naming convention for permissions is "action_verb modulename". For example (this isn't a part of our example module):

function newmodule_perm() {

return array('access newmodule', 'create newmodule', 'administer newmodule');

} // function newmodule_perm

The setup of the module is now done. You can add the code above to your module file. Next, we'll start generating content.

More information about the permission hook: Drupal 5.x