user_load

Versions
4.6 – 6
user_load($array = array())
7
user_load($uid, $reset = FALSE)

Fetch a user object.

Parameters

$array An associative array of attributes to search for in selecting the user, such as user name or email address.

Return value

A fully-loaded $user object.

▾ 22 functions call user_load()

blog_feed_user in modules/blog.module
Displays an RSS feed containing recent blog entries of a given user.
blog_page_user in modules/blog.module
Displays a Drupal page containing recent blog entries of a given user.
contact_mail_user in modules/contact.module
drupal_login in modules/drupal.module
Callback function from drupal_xmlrpc() for authenticating remote clients.
node_access_grants in modules/node.module
Fetch an array of permission IDs granted to the given user ID.
node_preview in modules/node.module
Generate a node preview, including a form for further edits.
node_revision_overview in modules/node.module
Generate an overview table of older revisions of a node.
node_validate in modules/node.module
Perform validation checks on the given node.
profile_browse in modules/profile.module
Menu callback; display a list of user information.
queue_block in modules/queue.module
Implementation of hook_block().
statistics_user_tracker in modules/statistics.module
tracker_track_user in modules/tracker.module
Menu callback. Prints a listing of active nodes on the site.
update_108 in database/updates.inc
update_80 in database/updates.inc
user_authenticate in modules/user.module
user_block in modules/user.module
Implementation of hook_block().
user_edit in modules/user.module
user_edit_validate in modules/user.module
user_external_load in modules/user.module
user_pass in modules/user.module
user_save in modules/user.module
Save changes to a user account.
user_view in modules/user.module

Code

modules/user.module, line 44

<?php
function user_load($array = array()) {
  // Dynamically compose a SQL query:
  $query = '';

  $params = array();
  foreach ($array as $key => $value) {
    if ($key == 'pass') {
      $query .= "u.pass = '%s' AND ";
      $params[] = md5($value);
    }
    else if ($key == 'uid') {
      $query .= "u.uid = %d AND ";
      $params[] = $value;
    }
    else {
      $query .= "LOWER(u.$key) = '%s' AND ";
      $params[] = strtolower($value);
    }
  }
  $result = db_query_range("SELECT u.* FROM {users} u WHERE $query u.status < 3", $params, 0, 1);

  if (db_num_rows($result)) {
    $user = db_fetch_object($result);
    $user = drupal_unpack($user);

    $user->roles = array();
    $result = db_query('SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = %d', $user->uid);
    while ($role = db_fetch_object($result)) {
      $user->roles[$role->rid] = $role->name;
    }
    user_module_invoke('load', $array, $user);
  }
  else {
    $user = new StdClass();
  }

  return $user;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.