You are here

registration_role.module in Registration role 5

File

registration_role.module
View source
<?php

// untested Drupal 5 version
// auto-assign role at registration
// Registration Role

/* based on
   http://drupal.org/node/28379#comment-132430
   code snippet by Pauly Jura
   This module actually does less than the snippet
*/

/**
 * Implementation of hook_help().
 *
 */
function registration_role_help($section = '') {
  $output = '';
  switch ($section) {
    case "admin/modules#description":
      $output = t("Auto-assign role at registration.");
      break;
  }
  return $output;
}

/**
 * Implementation of hook_menu().
 *
 * This is the Drupal 5 way but it should work for 4.7 settings
 */
function registration_role_menu($may_cache) {
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => 'admin/user/registration_role',
      'title' => t('Registration role'),
      'description' => t('Assign users an extra role at signup.'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'registration_role_admin_settings',
      ),
      'access' => user_access('administer users'),
    );
  }
  return $items;
}

/**
 * Define the settings form.
 */
function registration_role_admin_settings() {
  $roles = user_roles(TRUE);
  unset($roles['2']);
  $form['registration_role_roles'] = array(
    '#type' => 'radios',
    '#title' => t('Select role to automatically assign to new users'),
    '#options' => $roles,
    '#default_value' => variable_get('registration_role_roles', ''),
    '#description' => t('The selected role will be assigned to new registrants from now on.  Be sure this role does not have any privileges you fear giving out without reviewing who receives it.'),
  );

  // $form['array_filter'] = array('#type' => 'hidden');
  // Drupal 5, mysterious, needed for multiple check box values using settings hook
  return system_settings_form($form);
}

/**
 * Implementation of hook_user().
 *
 * Catch every registration and insert role
 */
function registration_role_user($op, &$edit, &$user, $category = null) {
  if ($op == "insert" && ($rid = variable_get('registration_role_roles', ''))) {

    // below does not seem safe!  or necessary for insert. Commented out
    // clear first
    // db_query( 'DELETE FROM {users_roles} WHERE uid = %d', $user->uid );
    $edit['roles'][$rid] = array();
  }
}

Functions

Namesort descending Description
registration_role_admin_settings Define the settings form.
registration_role_help Implementation of hook_help().
registration_role_menu Implementation of hook_menu().
registration_role_user Implementation of hook_user().