You are here

function userprotect_add_user in User protect 7

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

Adds a user to the protections table.

Parameters

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

string $type: The type of protection to add, either 'user', or 'admin'.

2 calls to userprotect_add_user()
userprotect_protections_bypass_submit in ./userprotect.admin.inc
Processes the submitted user protection form.
userprotect_user_insert in ./userprotect.module
Implements hook_user_insert().

File

./userprotect.module, line 775
Main module file for the userprotect module.

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 fields.
  $fields = array(
    'uid' => $uid,
    'up_type' => $type,
  );

  // Add the protections.
  foreach ($protections as $protection => $value) {
    $fields[$protection] = $protections[$protection] ? 1 : 0;
  }
  db_insert('userprotect')
    ->fields($fields)
    ->execute();
}