You are here

function taxonomy_access_user in Taxonomy Access Control 5

Implementation of hook_user Hook_user is called when a user event occurs to check for new roles. It would make sense to have a hook_role instead. However, that hook doesn't exist so we rely on the hook_user to determine if new roles have been added.

File

./taxonomy_access.module, line 472
Allows administrators to specify how each category (in the taxonomy) can be used by various roles.

Code

function taxonomy_access_user($op, &$edit, &$user, $category = NULL) {
  if ($op == 'update' || $op == 'insert') {

    // Get list of existing roles
    $result = db_query('SELECT rid FROM {role}');
    while ($rids = db_fetch_array($result)) {
      $current_rids[] = $rids['rid'];
    }
    if (!in_array(0, $current_rids)) {
      $current_rids[] = 0;
    }

    // Get list of roles known to exist from term_access_defaults
    $known_rids = array();
    $result = db_query('SELECT DISTINCT rid FROM {term_access_defaults}');
    while ($rids = db_fetch_array($result)) {
      $known_rids[] = $rids['rid'];
    }
    if (!in_array(0, $known_rids)) {
      $known_rids[] = 0;
    }
    if (array_diff($current_rids, $known_rids)) {
      _taxonomy_access_update_db($current_rids, $known_rids);
    }
  }
}