I have a custom module, saidbakr_tools and I want to apply permissions to access its administration page found admin/config/administration/saidbakr_tools. All what I have to got from the official module tutorial is to prevent access to it by preventing access to the admin pages.

The code I am using is the following one.

function saidbakr_tools_menu() {
  $items = array();

  $items['admin/config/administration/saidbakr_tools'] = array(
    'title' => 'SaidBakr Tools',
    'description' => 'Settings for SaidBakr Tools!',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('saidbakr_tools_form'),
    'access arguments' => array('administer saidbakr_tools'),
    'type' => MENU_NORMAL_ITEM,

 * Implements hook_permission().
function saidbakr_tools_permission() {
  return array(
    'administer saidbakr_tools' => array(
      'title' => t('Access content for the SaidBakr Tools module'),

I cannot prevent other users with access to administrative pages to access the configuration form for my module.

Is there any error in my code? How can I achieve what I am trying to do?


Since you're not declaring an access callback, the access callback defaults to the user_access() and passes your access argument into it based on the hook_menu().

Now, when we check the code of user_access(), we notice the following code.

// User #1 has all privileges:
if ($account->uid == 1) {
  return TRUE;

So the first created admin account will always have access. You then said:

But I could not able to prevent other Role's users that has access to admin pages from accessing its configurations,

If you added another user with the Administrator role, and the permission is unchecked for the Administrator role in the Permissions page, your code should work and I can confirm it. So please check if:

  1. You have the permission unchecked
  2. You have cleared all caches or maybe just the menu cache
  3. The admin user you are currently using to test the page's access is NOT the first admin user created

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.