You are here

function user_badges_user_insert in User Badges 7

Implements hook_user_insert().

File

./user_badges.module, line 288
@brief User Badges module file

Code

function user_badges_user_insert(&$edit, $account, $category) {
  if (is_array($account->roles)) {

    // Get the list of role badges.
    $roles = user_badges_get_roles();
    $badges = user_badges_get_badges('select');
    $message = user_access('manage badges');
    $rids = array_keys($account->roles);
    foreach ($rids as $rid) {

      // If this role has a badge...
      if (key_exists($rid, $roles)) {

        // and user doesn't already have this badge.
        if (!key_exists($roles[$rid], $account->badges)) {

          // @TODO: Stop this nonsense and user role badges separately.
          $success = user_badges_user_add_badge($account->uid, $roles[$rid], 'role');
          if ($success && $message) {
            drupal_set_message(t('User assigned %name badge.', array(
              '%name' => $badges[$roles[$rid]],
            )));
          }
        }
      }
    }
  }
}