[Drupal 7] Create custom permission in Drupal using access callback

| | 1 min read

Drupal gives ability to access callback. The access callback is executed before the call 'page callback'. Here create custom permission using access callback. The access callback helpfull for specific permissions to users or roles.

The access callback function return TRUE or FALSE. If the function return TRUE then controll goes to the menu callback . Otherwise access denied to menu callback and showing access denied page.

$items['/item1/] = array(
  'access callback' => 'access_fuction_name',
  'access arguments' => array(1, 2),
  'page callback' => 'custom_function2',
  'page arguments' => array(1),
);
  
function hook_permission() {
  $permission['access permission name'] = array(
    'title' => t('Title Here'),
  );
  return $permission;
}

function access_fuction_name {
  
  if (user_access('access permission name')) {
    // custom code ...............
  }
  
}