There are two steps :
- Make your permission string (such as "administer nodes" in the admin/people/permissions page)
- Check if user has access to the defined string
- We will use hook_permission() to add your own "string" in the permission management page.
Now you can administer permissions for your module. Note that you can add many permissions strings in the array you return.function mymodulename_permission() { return array( 'my own permission string' => array( 'title' => t('Administer my module'), 'description' => t('Perform administration tasks for my module.'), ), ); }
You can now find your permission string at this page : admin/people/permissions
- When you're coding your page, you can user user_access() to check if the connected user has the given right.
$string = "
my own permission string
"; user_access($string)
You can use user_access in the hook_menu() function. Here is an example :
function mymodulename_menu() {
$items = array();
$items['mymodule-page-address'] = array(//this creates a URL that will call this form at "examples/form-example"
'title' => 'Menu link name', //page title
'description' => 'A form to mess around with.',
'page callback' => 'drupal_get_form', //this is the function that will be called when the page is accessed. for a form, use drupal_get_form
'page arguments' => array('my_callback_function'), //put the name of the form here
'access callback' => 'user_access',
'access arguments' => array('my own permission string
'),
);
return $items;
}