You are here

function user_limit_count_users in User Limit 7

Same name and namespace in other branches
  1. 6 user_limit.module \user_limit_count_users()

Counts the number of users on the site.

May or may not count inactive users and user 1 depending on settings. This is the "canonical" function for counting users in User Limit.

Return value

An int representing the number of relevant users.

3 calls to user_limit_count_users()
UserLimitUserTestCase::testProtectRegisterUserNormal in ./user_limit.test
Test user registration (anonymous users) and message on register page.
user_limit_form_user_register_form_alter in ./user_limit.module
Implements hook_FORM_ID_alter().
user_limit_reached in ./user_limit.module
Calculates whether the number of allowed users on the site has been reached.

File

./user_limit.module, line 124
The User Limit module limits the number of users that can be registered on a Drupal site.

Code

function user_limit_count_users() {
  $count_uid1 = variable_get('user_limit_uid1', 0);
  $active_only = variable_get('user_limit_active', 0);

  // Set up query to count all users.
  $query = db_select('users', 'u')
    ->fields('u')
    ->condition('uid', 0, '<>');

  // Optionally exclude UID1.
  if ($count_uid1 == 0) {
    $query
      ->condition('uid', 1, '<>');
  }

  // Optionally exclude banned users.
  if ($active_only) {
    $query
      ->condition('status', 1);
  }
  $user_count = $query
    ->countQuery()
    ->execute()
    ->fetchField();
  return $user_count;
}