create_user_permission.module in Create user permission 7
Same filename and directory in other branches
The create user permission module.
This module needs a core patch or else it is useless.
File
create_user_permission.moduleView source
<?php
/**
* @file
* The create user permission module.
*
* This module needs a core patch or else it is useless.
*
* @see https://www.drupal.org/project/issues/drupal/2922852
*/
/**
* Implements hook_menu_alter().
*
* Alters the 'admin/people/create' menu item: Replaces the access argument
* with a custom access callback function that is declared below.
*/
function create_user_permission_menu_alter(&$items) {
// The original hook, function user_menu(), is setting access argument
// 'administer users' to this menu item.
// Although the 'access arguments' element is an array:
// @see https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu/7.x
// it can only contain one element:
// @see https://www.drupal.org/forum/support/module-development-and-code-questions/2008-10-30/hook_menu-and-multiple-access
// @see https://www.drupal.org/node/368584
// Here the 'access argument' is getting unset, and instead an explicit
// 'access callback' function will be used. The unset 'administer users' will
// be checked into that function.
unset($items['admin/people/create']['access arguments']);
$items['admin/people/create']['access callback'] = 'create_user_permission_access_callback';
}
/**
* Implements hook_permission().
*
* Provides a permission to "Create users".
*/
function create_user_permission_permission() {
return array(
'create users' => array(
'title' => t('Create users'),
'description' => t('Allows users to create users, without necessarily being able to edit and delete.'),
),
);
}
/**
* Custom access callback function for the 'admin/people/create' menu item.
*
* Extends the default core 'administer users' permission by OR-adding the
* 'create users' permission which is provided by this module.
*
* @return bool
* Access result.
*/
function create_user_permission_access_callback() {
return user_access('administer users') || user_access('create users');
}
/**
* Implements hook_user_register_form_admin_access_alter().
*
* Alters the $admin variable, which determines whether the user will have
* access to the user registration form, by OR-adding the 'create users'
* permission which is provided by this module.
*/
function create_user_permission_user_register_form_admin_access_alter(&$admin) {
$admin = user_access('administer users') || user_access('create users');
}
Functions
Name | Description |
---|---|
create_user_permission_access_callback | Custom access callback function for the 'admin/people/create' menu item. |
create_user_permission_menu_alter | Implements hook_menu_alter(). |
create_user_permission_permission | Implements hook_permission(). |
create_user_permission_user_register_form_admin_access_alter | Implements hook_user_register_form_admin_access_alter(). |