You are here

function userprotect_add_user in User protect 5

Same name and namespace in other branches
  1. 6 userprotect.module \userprotect_add_user()
  2. 7 userprotect.module \userprotect_add_user()

Adds a user to the protections table.

Parameters

$uid The UID of the user to be added.:

2 calls to userprotect_add_user()
userprotect_protections_bypass_submit in ./userprotect.module
Processes the submitted user protection form.
userprotect_user in ./userprotect.module
Implementation of hook_user().

File

./userprotect.module, line 982

Code

function userprotect_add_user($uid, $type) {

  // Grab the default protections to enable for this user.
  $protections = variable_get('userprotect_protection_defaults', userprotect_user_protection_defaults());

  // Set initial values and args.
  $names = array(
    '%s',
  );
  $values = array(
    '%d',
  );
  $arg_names = array(
    'uid' => 'uid',
  );
  $arg_values = array(
    $uid,
  );

  // Add the protections.
  foreach ($protections as $protection => $value) {
    $names[] = '%s';
    $values[] = '%d';
    $arg_names[$protection] = $protection;
    $arg_values[] = $protections[$protection] ? 1 : 0;
  }

  // Append the type.
  $names[] = '%s';
  $values[] = "'%s'";
  $arg_names['up_type'] = 'up_type';
  $arg_values[] = $type;

  // Merge the args.
  $args = $arg_names + $arg_values;
  db_query('INSERT INTO {userprotect} (' . implode(', ', $names) . ') VALUES (' . implode(', ', $values) . ')', $args);
}